Ooops
March 01, 2021, 11:09:18 PM

Author Topic: [bmx] Screen-centered text by BlitzSupport [ 1+ years ago ]  (Read 428 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : Screen-centered text
Author : BlitzSupport
Posted : 1+ years ago

Description : Nothing fancy, but I had a need for this, so here it is...

Just pass it a string, specifying new lines using the "|" (pipe) character, eg. "Hello|world" will become:

Code: [Select]
Hello
world


You can specify a different 'splitter' character/string via the second parameter, eg. it'll work with the C-style "
" if you pass that. [/i]

Code :
Code: BlitzMax
  1. Function ScreenCenteredText (t:String, splitter:String = "|")
  2.  
  3.         ' Turn t$ into an array of strings...
  4.  
  5.         Local line:String [] = t.Split (splitter)
  6.        
  7.         Local lineheight:Int = TextHeight (t)
  8.         Local totalheight:Int = lineheight * line.length
  9.        
  10.         For Local loop:Int = 0 Until line.length
  11.  
  12.                 DrawText line [loop],   GraphicsWidth () / 2 - TextWidth (line [loop]) / 2,..                                   ' X
  13.                                                                 GraphicsHeight () / 2 + (loop * lineheight) - (totalheight / 2) ' Y
  14.         Next
  15.        
  16. End Function
  17.  
  18. Graphics 640, 480
  19.  
  20. Local msg:String = "Hello, here is some screen-centered text,|which is conveniently split onto several|lines using the ~qpipe~q character,|though you can specify which character to use!"
  21.  
  22. Repeat
  23.  
  24.         Cls
  25.        
  26.         ScreenCenteredText msg
  27.        
  28.         Flip
  29.        
  30. Until KeyHit (KEY_ESCAPE)
  31.  
  32. End


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal