GetScale

Monkey Forums/Monkey Programming/GetScale

degac(Posted 2011) [#1]
If I understood correctly with the command GetMatrix it is possible to retrieve info about scale factor x# and y# (among other things).

This is a quick test to draw a text 'centered' in the middle of the screen/canvas.

Unfortunately I'm doing something wrong, because the text string is not 'centered' at all.
Where is my error?

Function DrawCenterText:Int(text:String,x:Float,y:Float,vx:Int=1,vy:Int=0)
	Local fnt:Image=GetFont()
	Local sw:Int=text.Length()*fnt.Width()
	
	Local m:Float[]=GetMatrix()
	
'	For Local i:Int=0 Until m.Length()
'		Print i+" "+m[i]
'	next
	
	If vx=1
		x=SCREEN_WIDTH/2-sw/2
	End If
	If vy=1
		y=SCREEN_HEIGHT/2-fnt.Height()/2
	End If
	x/=m[0]
	y/=m[3]
	DrawText text.ToUpper(),x,y
	Return 0
End Function



degac(Posted 2011) [#2]
Just discovered that DrawText has built in 'center' function...


DruggedBunny(Posted 2011) [#3]
Wow, you learn something every day!


degac(Posted 2011) [#4]
Ok, I should read all the help info...

But, DrawText's center function is implemented in 'half-way'
You need to 'center' the X,Y coordinates by yourself
DrawText "This is centered",SCREEN_W/2,100,.5

Otherwise it doesnt' work properly.
Maybe I'm wrong but to me it's more logic this
Function DrawText2:Int( text$,x#,y#,xalign#=0,yalign#=0 )
	Local m:Float[]=GetMatrix()
	If xalign<>0 x=DeviceWidth()/(2*m[0])-TextWidth(text)/2
	If yalign<>0 y=DeviceHeight()/(2*m[2])-TextHeight()/2
	DrawText text,x,y
	Return 0
End


Cheers