mojo2 Fontmachine version

Monkey Forums/Monkey Programming/mojo2 Fontmachine version

ziggy(Posted 2015) [#1]
Hello!

Just to let you know there's a working port of the FontMachine module to be used with mojo2.

I haven't really updated the documentation, but there are no api changes from previous version, except one new public field in the BitmapFont class, that can be used to set the DrawList where draw operations are done.

All in all, you can load a font, set its DrawingTarget (which is its associated DrawList), and you're good to go.

Example code:
Import mojo2fontmachine

'Start the program:
Function Main()
	New Tutorial
End


Class Tutorial extends App

	Field font:BitmapFont
	Field canvas:Canvas

	Method OnCreate()

		font = New BitmapFont("bluesky/bluesky.txt")
		canvas = New Canvas()
		font.DrawingTarget = canvas
	End

	Method OnRender()

		canvas.Reset
		canvas.SetColor(1, 0, 0)
		canvas.DrawRect(0, 0, canvas.Width, canvas.Height)
		canvas.SetColor(1, 1, 1)
		'We just draw some text: 
		font.DrawText("Hello world!~nThis is~na sample.", 210, 10, eDrawAlign.CENTER)
		canvas.Flush
	End
	
	Method OnUpdate()
		If KeyDown(KEY_A) Then font.Kerning.x-=.4
		If KeyDown(KEY_D) Then font.Kerning.x+=.4
		If KeyDown(KEY_W) Then font.Kerning.y-=.4
		If KeyDown(KEY_S) Then font.Kerning.y+=.4
		if KeyDown(KEY_SPACE) Then DebugStop()
	End
End


Current dev version can be downloaded here:
https://github.com/ziggybcn/FontMachine-for-Mojo-2

Future plans:

a) Decouple the BitmapFont class from the BitmapFont loader, so futher loaders for other Font formats can be added, so this Font module can be used with AngelFont, Ignition one, or any other bitmapfont system.

b) Improve internal module architecture (there are lots of things that could be done much much better to make the module easier to maintain)

c) Improve performance where needed.

Now, regarding repository, I haven't bothered creating a dev branch and a stable/master branch in GitHub, whenever this all is stable, I will. Feel free to contribute.


mjcamerer(Posted 2015) [#2]
This makes me so happy! Thank you!


ziggy(Posted 2015) [#3]
Small update:
* Fixed a memory leak
* splitted the loader from the BitmapFont class, so now it's very easy to add support for other font formats.


hub(Posted 2015) [#4]
my first try to use fontmachine for mojo2
ziggy i've an error :

Field BitmapFont.borderChars:BitMapChar[] is private.

at Method LoadPacked:Bool(tmpFont:BitmapFont, info:String, fontName:String, dynamicLoad:bool)
line :
tmpFont.faceChars = New BitMapChar[65536]

Thanks !


ziggy(Posted 2015) [#5]
Are you using the right repository? It seems like a FontMachine for mojo (not mojo2). At which file does the issue show?


hub(Posted 2015) [#6]
file : fontmachineloader.monkey

i just use : Import mojo2fontmachine

from your link, i juste place the files inside : MonkeyXPro84e\modules_ext\mojo2fontmachine\


Duke87(Posted 2015) [#7]
Same here.
I just put in a public keyword in front of Field borderChars:BitMapChar[] within bitmapfont.monkey (about line 436) and now it works.

I'm using MonkeyX85a.

Bye Duke


ziggy(Posted 2015) [#8]
Thanks!
Feel free to make any pull request to Git!


hub(Posted 2015) [#9]
With Duke87 update , it's compile now but i've these errors with android target :

(85a)



With this code :



ziggy(Posted 2015) [#10]
@hub: If it only fails with Android, it could very well be a Monkey X bug. Anyone else?


hub(Posted 2015) [#11]
yes it's possible.
I've no problem for html5 target.
Perhaps an android guru (java) have idea about this !


strange line of code.

Thanks.


hub(Posted 2015) [#12]
from the MonkeyGame.java :


Monkey bug for me, hope Mark see this post !


Duke87(Posted 2015) [#13]
same here. i have no idea what to do.
damn. i wanted to switch to mojo2 & fontmachine today as my new standard, but android is one of the must targets.
Let's hope this will be fixed by next Monkey Version.

I checked my SDK,JDK & co, everything is fine.

Edit: I now tried the mojo2 bananas to run with android, and none of them run properly.
Always the "Unfortunately, MonkeyGame has been stopped"

BUILD SUCCESSFUL
Total time: 14 seconds
Starting: Intent { cmp=com.monkeycoder.monkeygame/.MonkeyGame }
E/AndroidRuntime(  835): FATAL EXCEPTION: GLThread 100
E/AndroidRuntime(  835): java.lang.IllegalArgumentException: No configs match configSpec
E/AndroidRuntime(  835): 	at android.opengl.GLSurfaceView$BaseConfigChooser.chooseConfig(GLSurfaceView.java:838)
E/AndroidRuntime(  835): 	at android.opengl.GLSurfaceView$EglHelper.start(GLSurfaceView.java:994)
E/AndroidRuntime(  835): 	at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1348)
E/AndroidRuntime(  835): 	at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1202)


anything wrong with OpenGL or something?


MikeHart(Posted 2015) [#14]
Right now you can get it to compile with

YourArray = YourArray.Resize(yourValue)


Not sure if it is a bug that showed up recently or has to be done now. When you look at the docs, the return type is Void[] which is weird.


Duke87(Posted 2015) [#15]
first of all, now i had a little closer look at your fontmachine, and i Like it very much. Very good work so far!
But i have 2 little questions.#
1. Is it possible to switch the font on runtime? like
...OnUpdate()
    myFont.switchFontTo(_newFont)
....

i tried to, but compiler always complains "memory access..."

My first attempt to this:
If KeyHit(KEY_1)
    myFont = BitmapFont.Load("SportsFont/SportsFont.txt",false)
    wrappedtext.Font = myFont
Endif

... if you're working on this, please tell me, otherwise I'll try to add a Method like
myFont.switchToFont(_font:String) or something alike.
Or do you recommend using an object for every Font and just switch the Object on runtime?
My usecase: I'd like to switch through the fonts on Runtime, so i can see which font fits best to the game, or the user can switch on Runtime.

Second Question:
is it Possible to let the wrappedText write like a typewriter? (character after character) Didn't find it now.
I have a real one at home (Adler Mod. 32 from the 30'ies from Frankfurt from my Grandparents). I'll ask a friend of mine to record the sounds (he has 1000$ microphone equipment + a little recording studio so i hope to get some real sounds for 'Type a Character, changeing the line, switch uppercase and so on).
I would like to add this feature to your module.
I may see my friend this evening so i can ask him to help me. Then maybe i could work on this.

Tomorrow I'll think about that feature. at the moment i think i'd need to add kind of "CharacterWriteTime","ChangeLineWriteTime" ... and then add Method like
wrappedText.DrawTypewriter(_posX:int,_posY:int,_align:int,_speed:float)
*Edit*
or better:
wrappedText.DrawTypewriter(_posX:int,_posY:int,_align:int,_characterCount:int)

_characterCount should then increase extern like
if Millisecs()-lastTyped > TypeTime
   charCounter +=1
   lastTyped = Millisecs()
endif 

or something like that.

Bye Duke.


ziggy(Posted 2015) [#16]
Or do you recommend using an object for every Font and just switch the Object on runtime?
Yes! Also, changing the font object of a WrappedText class forces wrapping to be recalculated, so it's even better to have a single wrappedtext object for each wrappedtext need using a single font, if possible. Obviously all this can be just ignored if performance is not a top must priority


Duke87(Posted 2015) [#17]
thanks for your fast answer.

For my 2. Question:
I just found Method DrawText(text:String, x:Float, y:Float, align:Int, initChar:Int, endChar:Int). got it working as i want. Now I'll work on a second wrappedText Class to combine typewriting feature with wrapping the text.


hub(Posted 2015) [#18]
Ziggy, any news about the java compile bug with android ?


APC(Posted 2015) [#19]
Hello Ziggy,

i just installed mojo2fontmachine and ran the firstsample.monkey the performance is slower compared to the mojofontmachine on HTML 5.

I runs well on iOS and GLFW3 (OSX El Capitan) targets.

M.Hartlef (MikeHart) Regarding your quote below could you be more specific which mojo2fontmachine source are you referring to? want to make it work on Android.
Right now you can get it to compile with

YourArray = YourArray.Resize(yourValue)



MikeHart(Posted 2015) [#20]
@APC: i didn't chec the source files, but i got the same error in my own code, so i posted what i did when i fixed it for my code. Just do a Find in Files on the fontmachine modules with .Resize. It should bring up all the locations.


marksibly(Posted 2015) [#21]
Hi,

Just did a quick bit of find in files debugging and found this in fontmachineloader.monkey:

font.borderChars.Resize(0)
font.faceChars.Resize(0)
font.shadowChars.Resize(0)

This will have no effect, as Resize() returns a new array which needs to be assigned somewhere. Replace with 'font.borderChars=[ ]' etc to clear arrays.

Bit bummed out this is confusing Android though, thought I'd fixed that!