setting font alignment

BlitzMax Forums/BlitzMax Beginners Area/setting font alignment

Ryan Burnside(Posted 2006) [#1]
OK I've searched the wiki, documentation and forums but I can't find any referance to setting font alignment for strings. I want to center my string on a point. Is there a function for this?

sidequestion: Is there an IRC chat channel for blitzmax users?


Grey Alien(Posted 2006) [#2]
there is no built in way to align strings. Try this method from my BlitzMax Framework:

Function ccDrawTextCentred(text$,x#,y#)
Local w# = TextWidth(text)
DrawText(text,x-(w/2),y)
End Function


Diablo(Posted 2006) [#3]
heres a function I did. You can draw aligned text with it:
SuperStrict

Rem
	The Draw Al Text Function :: Can be used just like drawtext
EndRem
Function DrawAlText(text$, x#, y#, w# = 0, h# = 0, xAl# = 0, yAl# = 0, xoff# = 0, yoff# = 0)
	
	Local tx#, ty#
	
	Select xAl
		
		Case 0
			tx = x + xoff
				
		Case 1
			tx = (x + (w / 2)) - (TextWidth(text) / 2) + xoff
				
		Case 2
			tx = (w - TextWidth(text)) + xoff
		
	End Select
	
	Select yAl
	
		Case 0
			ty = y + yoff
			
		Case 1
			ty = (y + (h / 2)) - (TextHeight(text) / 2) + yoff
			
		Case 2
			ty = (y + (h - TextHeight(text))) + yoff
			
	End Select
	
	DrawText text, tx, ty
		
End Function

Rem
	===========================================================================
	D	E	M	O
	===========================================================================
EndRem
Graphics 800 , 600

Global curXAl#, curYAl#

While Not KeyDown(KEY_ESCAPE)
	
	Cls
	
	If KeyHit(KEY_RIGHT) Then curXAl:+ 1; If curXAl > 2 Then curXAl = 0
	If KeyHit(KEY_LEFT) Then curXAl:- 1; If curXAl < 0 Then curXAl = 2
	
	If KeyHit(KEY_DOWN) Then curYAl:+ 1; If curYAl > 2 Then curYAl = 0
	If KeyHit(KEY_UP) Then curYAl:- 1; If curYAl < 0 Then curYAl = 2
	
	DrawAlText("Hello" , 0 , 0 , 800 , 600 , curXAl , curYAl , 0) 
	
	Select curXAl
		
		Case 0
			DrawAlText("X :: Left" , 10 , 10) 
			
		Case 1
			DrawAlText("X :: Center" , 10 , 10) 
			
		Case 2
			DrawAlText("X :: Right" , 10 , 10) 
			
	End Select
	
	Select curYAl
		
		Case 0
			DrawAlText("Y :: Top" , 10 , 20) 
			
		Case 1
			DrawAlText("Y :: Center" , 10 , 20) 
			
		Case 2
			DrawAlText("Y :: Bottom" , 10 , 20) 
			
	End Select
	
	Flip
	
Wend



GfK(Posted 2006) [#4]
sidequestion: Is there an IRC chat channel for blitzmax users?
irc.blitzed.org, port 6667 or 7000, join #blitzbasic. You can also try #blitzcoder on the same server, but the dialog has been a little... odd... in there for a while now - its not often you see any chat about programming.


Ryan Burnside(Posted 2006) [#5]
Thanks, I thought i'd need to write a function for this. Good examples for referance!