- Joined
- Jan 2, 2020
- Messages
- 568
This gives you precision-designed boxes around any kind of text that both looks and feels good. Animation is also added.
Cerberus X:
Strict
Import mojo2
Function Main:Int()
New CGame()
Return 0
End
Class CGame Extends App
Field canvas:Canvas
Field str:String
Field myFont:Font
Method OnCreate:Int()
canvas = New Canvas
SetSwapInterval 1
SetUpdateRate 0
myFont = Font.Load( "mojo_font.png", 32, 96, True )
Return 0
End
Method OnUpdate:Int()
Return 0
End
Method OnRender:Int()
canvas.Clear
canvas.SetFont myFont
DrawBoxedText "This one has a box around it",100,150,4,False, False
DrawBoxedText "Very important!",100,200,4,True, True
canvas.Flush
Return 0
End
Method DrawBoxedText:Void(s:String,x:Int,y:Int, p:Int=2, b:Bool=False, flash:Bool=True)
canvas.DrawText s,x,y,0,0
Local h := myFont.TextHeight(s)
Local w :=myFont.TextWidth(s)
If b Then p = p + 10+Int(Sin(Millisecs() / 2.0) * 10.0)
If flash Then canvas.SetColor (128+Int(Sin(Millisecs() / 2.0) * 128.0))/255.0,0,0
Local p1 := p + 1
canvas.DrawLine x-p1,y-p1,x+w+p,y-p1
canvas.DrawLine x-p1,y+h+p,x+w+p,y+h+p
canvas.DrawLine x-p1,y-p1,x-p1,y+h+p
canvas.DrawLine x+w+p,y-p1,x+w+p,y+h+p
canvas.SetColor 1,1,1
End
Method CheckRectangle:Bool(x : Int,y : Int, x1:Int, y1:Int, w:Int,h:Int)
Return (x >= x1) And (y >= y1) And (x <= x1 + w) And (y <= y1 + h)
End Method
End