Any advice on centering bitmap text inside a screen?
Posted: Sun Jan 26, 2020 1:02 am
I made a patcher a couple of years ago and am now working on an open source tool for creating patchers with a fair deal of customization, one of those being user defined bitmap fonts.
However, I never did get around to working out a proper solution for aligning bitmap font based text, so I figured I would go ahead and see if anyone here had any suggestions.
To compensate for this, I simply used spaces in my original patcher. Not very pretty, but it's one of the first things I ever made with PureBasic and I wanted to finish it quickly.
This piece of code was for optimization to avoid having to draw each character individually; on startup, this sprite is created so that only a single sprite needs to be drawn to the screen later.
I've considered doing some calculations based on the screen width, character sizes, and space between characters in order to determine the center, left, right, etc. of the final text to be displayed, but I'm curious to know whether or not there's a better way.
For anyone that might be curious, this is the old patcher I made in use.
Thanks!
However, I never did get around to working out a proper solution for aligning bitmap font based text, so I figured I would go ahead and see if anyone here had any suggestions.
To compensate for this, I simply used spaces in my original patcher. Not very pretty, but it's one of the first things I ever made with PureBasic and I wanted to finish it quickly.
This piece of code was for optimization to avoid having to draw each character individually; on startup, this sprite is created so that only a single sprite needs to be drawn to the screen later.
Code: Select all
Procedure CreateHeader()
Protected Header.s, Character.s, X.i = 11, OriginalX.i = X, Y.i = 16, OriginalY.i = Y
Header = " asio link pro patcher #"
Header + "<~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~> #"
Header + " brought to you by g.a. collective 2018#"
Header + "<~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~>"
CreateSprite(#SpriteHeader, #ScreenWidth, #ScreenHeight)
ClearScreen(FastRGB(255, 0, 255))
For i = 1 To Len(Header)
Character = LCase(Mid(Header, i, 1))
If FindMapElement(Font(), Character)
ClipSprite(#SpriteFont, Font(Character)\X, Font(Character)\Y, Font(Character)\W, Font(Character)\H)
ZoomSprite(#SpriteFont, SpriteWidth(#SpriteFont) * 2, SpriteHeight(#SpriteFont) * 2)
DisplayTransparentSprite(#SpriteFont, X, Y)
X + ((Font(Character)\W * 2) - 2)
Else
If Character = "#"
Y + 22
X = OriginalX
Else
X + 8
EndIf
EndIf
Next
GrabSprite(#SpriteHeader, 0, 0, #ScreenWidth, #ScreenHeight, #PB_Sprite_AlphaBlending)
TransparentSpriteColor(#SpriteHeader, FastRGB(255, 0, 255))
ClearScreen(FastRGB(28, 28, 28))
EndProcedureFor anyone that might be curious, this is the old patcher I made in use.
Thanks!

