Small DrawText addition

BlitzMax Forums/BlitzMax Module Tweaks/Small DrawText addition

N(Posted 2004) [#1]
Rem
bbdoc: Draw text
about:
#DrawText prints strings at position @x,@y of the graphics display using
the current image font specified by the #SetImageFont command.  The text will be centered based on your use of @centerx and @centery .<p>
Other commands that affect #DrawText include #SetColor, #SetHandle, 
#SetScale, #SetRotation, #SetOrigin, #SetViewPort, #SetBlend and #SetAlpha.
End Rem
Function DrawText( t$,x#,y#, centerx%=0, centery%=0 )
	If centerx Then x :- TextWidth(t$)*.5
	If centery Then y :- TextHeight(t$)*.5
	image_font.Draw t,..
	x+origin_x+handle_x*tform_ix+handle_y*tform_iy,..
	y+origin_y+handle_x*tform_jx+handle_y*tform_jy,..
	tform_ix,tform_iy,tform_jx,tform_jy
End Function


You can probably figure out where to put this if you decide to use it.


fredborg(Posted 2004) [#2]
And more from the same drawer:
Rem
bbdoc: Draw text
about:
#DrawText prints strings at position @x,@y of the graphics display using
the current image font specified by the #SetImageFont command.  The text will be aligned based on your use of @alignx and @aligny. Possible values for @alignx are:<br>
ALIGN_LEFT - Aligns the text so the left most edge is at @x (Default)<br>
ALIGN_CENTER - Centers the text horizontaly at @x<br>
ALIGN_RIGHT - Aligns the text so the right most edge is at @x<br>
Possible values for @aligny are:<br>
ALIGN_TOP - Aligns the text so the top is at @y (Default)<br>
ALIGN_MIDDLE - Centers the text verticaly at @y<br>
ALIGN_BOTTOM - Aligns the text so the bottom edge is at @y<p>
Other commands that affect #DrawText include #SetColor, #SetHandle, 
#SetScale, #SetRotation, #SetOrigin, #SetViewPort, #SetBlend and #SetAlpha.
End Rem
Const ALIGN_LEFT   = 0
Const ALIGN_CENTER = 1
Const ALIGN_RIGHT  = 2
Const ALIGN_TOP    = 0
Const ALIGN_MIDDLE = 1
Const ALIGN_BOTTOM = 2
Function DrawText( t$,x#,y#, alignx%=0, aligny%=0 )
	If alignx = ALIGN_CENTER
		x :- TextWidth(t$)*.5
	ElseIf alignx = ALIGN_RIGHT
		x :- TextWidth(t$)
	EndIf
	If aligny = ALIGN_MIDDLE
		y :- TextHeight(t$)*.5
	ElseIf aligny = ALIGN_BOTTOM
		y :- TextHeight(t$)
	EndIf
	image_font.Draw t,..
	x+origin_x+handle_x*tform_ix+handle_y*tform_iy,..
	y+origin_y+handle_x*tform_jx+handle_y*tform_jy,..
	tform_ix,tform_iy,tform_jx,tform_jy
End Function



skidracer(Posted 2004) [#3]
I would prefer DrawText x,y,w=0,h=0,align=0 where align is a combination of horizontal and vertical flags and w,h where specified are a rectangle area that produce multiline input when overflow occurs or when the text includes ~n characters.


Difference(Posted 2004) [#4]
Sometimes you don't want multiline, even if the text is too wide to fit. (Lists and such)


fredborg(Posted 2004) [#5]
This is a bit more advanced, but not perfect...

Peter, it works just like the regular DrawText if you omit the w# parameter or set it to 0.

Here's the code (place in 'max2d.bmx'):

And a small example:


I really like the way you can access a string like an array, great stuff!


Bot Builder(Posted 2004) [#6]
Cool. Comments for the module entry:
Rem
bbdoc: Draw text
about:
#DrawText prints strings at position @x,@y of the graphics display using
the current image font specified by the #SetImageFont command.  The text 
will be aligned based on applying binary ORs (| operator) of 2 flags,
one from the top 3, one from the bottom. The flags for @align are:<br>
ALIGN_LEFT - Aligns the text so the left most edge is at @x (Default)<br>
ALIGN_CENTER - Centers the text horizontaly at @x<br>
ALIGN_RIGHT - Aligns the text so the right most edge is at @x<br>
ALIGN_TOP - Aligns the text so the top is at @y (Default)<br>
ALIGN_MIDDLE - Centers the text verticaly at @y<br>
ALIGN_BOTTOM - Aligns the text so the bottom edge is at @y<p>
Other commands that affect #DrawText include #SetColor, #SetHandle, 
#SetScale, #SetRotation, #SetOrigin, #SetViewPort, #SetBlend and #SetAlpha.
End Rem



Red(Posted 2006) [#7]
bug fixed: SetRotation




N(Posted 2006) [#8]
It's over a year old, Ed.