TEXT OBJECTS
|
|
Sprite Candy text objects are very customizable: you can set an auto-wrapping width, text-flow direction, screen alignment and more. Like all objects, texts can be colorized, too. To save texture memory, you can load a white colored font only and colorize each text object individually. Of course you can add shadows, a colored background or borders to text objects, too.
The included Font Candy Studio Editor has been especially designed for use with Sprite Candy and makes it very easy to create and export nice looking font textures.
NOTE:
Changing the text of a text object will rebuild the complete layer -so you should place text objects that need to be updated frequently into a seperate layer. It's a good practice to use two different layers here: one for the static texts and another one for dynamic texts that will change often. However, this is only neccessary when it comes to speed-critical situations and you won't have to care about when creating a title screen only, for example.
Text objects containing many letters can cause a high vertex count (four vertices per char). You should keep an eye on it. Do not use too large texts in speed-critical situations.
Before creating text objects, you have to load at least one font texture and its font metrics file into memory (as created with the included Font Editor, for example). A font texture and it's data file can be loaded by HUD_LoadFont( ).
|
|
TEXT OBJECT COMMANDS
|
|
|
HUD_LoadFont
|
|
|
Font_Handle% =
HUD_LoadFont (
textureFile$,
dataFile$,
[textureMode%],
[maskR%],
[maskG%],
[maskB%]
)
|
Before you can create text objects, you have to load one ore more fonts into memory. This command will load a font texture and its metrics file (as exported from Font Candy Studio) and return a handle to this font.
Once a font or texture has been loaded, it can be used on as many layers and as many times as you like, there's no reloading neccessary.
textureFile$
Path and file name of a font texture (exported by Font Candy Studio).
dataFile$
Path and file name of a char metrics file (usually a .bin file, exported together with the font texture image).
textureMode%
Optional texture settings to be applied to the texture loaded:
1: Color
2: Alpha
4: Masked (default - black color will be set to transparent)
8: Mipmapped
16: Clamp U
32: Clamp V
64: Spherical environment map
128: Cubic environment map
256: Store texture in vram
512: Force the use of high color textures
- Also see Blitz3D online manual found here.
maskR% , maskG% , maskB%
Used with textureMode 4 only. You can optionally specify a mask color. All pixels using the specified RGB color will be masked (become transparent) then when using textureMode 4. If not specified, all black pixels will be masked by default.
|
|
HUD_GetTextureHandle
|
|
|
Texture_Handle% =
HUD_GetTextureHandle (
Font_Handle%
)
|
Sprite Candy commands like HUD_LoadImageResource or HUD_LoadFont do return internal Sprite Candy ID's, not Blitz texture handles. If you want to modify a texture directly, you can use this command to get the Blitz texture handle of a loaded image or font.
Font_Handle%
The handle of a font loaded with HUD_LoadFont( ).
|
|
HUD_CreateText
|
|
Example:
; CREATE A HUD, LOAD A FONT (ONCE ONLY)
HUD1% = HUD_Create (Cam)
Font1% = HUD_LoadFont ("font.bmp","font.dat", 4)
; THEN CREATE A LAYER USING THAT FONT:
Layer1% = HUD_CreateLayer (HUD1, Font1)
; CREATE AS MANY TEXTS ON IT AS YOU LIKE:
Text1% = HUD_CreateText (Layer1, 0,0, "SAMPLE TEXT", "LEFT", 0, "CENTER","BOTTOM")
Text2% = HUD_CreateText (Layer1, 0,0, "ANOTHER TEXT", "LEFT", 0, "CENTER","TOP+50")
|
Text_Handle% =
HUD_CreateText (
Layer_Handle%,
x%,
y%,
text$,
[textFlow$],
[wrapWidth%],
[xAlign$],
[yAlign$],
[zOrder%],
)
|
This command creates a text object on the specified layer. A font texture must have been attached to this layer first. Most of a text object's parameters can be changed and updated on-the-fly.
Layer_Handle%
The handle of a layer as created with HUD_CreateLayer( ). A loaded font must have been attached to this layer.
x% , y%
The screen x- and y-postion where the created text should be placed, where x may range between 0 (left) and the screen width and y may range between 0 (top) and the height of the screen. These parameters will be ignored, when xAlign$ or yAlign$ have been set (see below).
text$
A string to print. All chars of this string must be contained on the font texture specified with FontID. You can use chr(13) or | (upright slash) to force a line break anywhere inside the string.
textFlow$
"LEFT"
"CENTER" (default)
"RIGHT"
Sets the text alignment (flow direction). Note: by default, the origin (center point) of all HUD objects is placed at the center of the object. However, there are two exceptions: when the text-flow of a text has been set to "LEFT", the origin will be placed on the left side of the text object. When set to "RIGHT", the object origin will be placed on the right side of the text object. You will see the difference when trying to rotate or position a text object.
wrapWidth%
The text will be automatically wrapped when exceeding the specified wrap width. Setting the wrap width to 0 disables automatic text wrapping (default).
xAlign$
" " (empty) - The specified x-coordinate will be used.
"LEFT" - Object will be placed at the left screen border, regardless to the current screen resolution.
"CENTER" - Object will be centered on screen horizontally, regardless to the current screen resolution.
"RIGHT" - Object will be placed at the right screen border, regardless to the current screen resolution.
Hint: You can also use offsets: "CENTER+50" or "RIGHT-25", for example!
yAlign$
" " (empty) - The specified y-coordinate will be used.
"TOP" - Object will be placed at the top screen border, regardless to the current screen resolution.
"CENTER" - Object will be centered on screen vertically, regardless to the current screen resolution.
"BOTTOM" - Object will be placed at the bottom screen border, regardless to the current screen resolution.
Hint: You can also use offsets: "CENTER+50" or "BOTTOM-50", for example!
zOrder%
The depth order of this object. When not specified, a new object will be placed on top of existing ones. An object's depth order can be changed at any time. Use values from 0 to ... , where higher values will place it on top of other objects and lower values will place it behind other objects.
|
|
HUD_GetFontID
|
|
|
Font_Handle% =
HUD_GetFontID (
Text_Handle%
)
|
This command returns the ID (Sprite Candy handle) of the font used by the specified text object, so you can check what font has been used to create it.
Text_Handle%
The handle of a text object created with HUD_CreateText( )
|
|
HUD_SetText
|
|
|
HUD_SetText (
Text_Handle%,
text$
)
|
This command changes the text of a text object. You can use it at any time.
Handle%
The handle of a text object created with HUD_CreateText( )
text$
A string to print. All chars of this string must be contained on the font texture. You can use chr(13) or | (upright slash) to force a line break anywhere inside the string.
|
|
HUD_GetText
|
|
|
text$ =
HUD_GetText (
Text_Handle%
)
|
Returns the current text of a text object.
Text_Handle%
The handle of a text object created with HUD_CreateText( )
|
|
HUD_SetTextFlow
|
|
|
HUD_SetTextFlow (
Text_Handle%,
textFlow$
)
|
This command changes the text-flow direction of a text object at any time.
NOTE: By default, an object's origin (center point) is placed at the center (middle) of an object. There are two exceptions: when you set the text-flow of a text object to "LEFT", the origin is placed on the left side of the object, when text-flow is set to "RIGHT", the origin is placed on the right side of the object.
ObjectHandle%
The handle of a text object created with HUD_CreateText( )
textFlow$
"LEFT"
"CENTER"
"RIGHT"
|
|
HUD_GetTextFlow
|
|
|
textFlow$ =
HUD_GetTextFlow (
Text_Handle%
)
|
Returns the current text-flow (text-alignment) of a text object. Possible values are:
"LEFT"
"CENTER"
"RIGHT"
Text_Handle%
The handle of a text object created with HUD_CreateText( )
|
|
HUD_SetWrapWidth
|
|
|
HUD_SetWrapWidth (
Text_Handle%,
wrapWidth%
)
|
This command will set the maximum width (wrapping width) of a text object. You can use it at any time. When a text exceeds the given width, it will be wrapped automatically. You can disable the auto-wrapping by setting a text's wrapping width to 0.
Text_Handle%
The handle of a text object created with HUD_CreateText( )
wrapWidth%
The maximum width of the text (in pixels). Using 0 disables text wrapping for this text. You can always force new lines (line breaks) by using chr(13) or | (upright slash) anywhere inside the text.
|
|
HUD_GetWrapWidth
|
|
|
wrapWidth% =
HUD_GetWrapWidth (
Text_Handle%
)
|
Returns the wrapping width of the specified text object.
Text_Handle%
The handle of a text object created with HUD_CreateText( )
|
|
HUD_SetCharSpacing
|
|
|
HUD_SetCharSpacing (
Text_Handle%,
spacing%
)
|
This command modifies the character spacing (also called 'kerning') of a text object.
Text_Handle%
The handle of a text object created with HUD_CreateText( )
spacing%
The specified value will be added to the default character spacing of the text object. Default value is '0' (the normal character spacing as saved with the font's metrics file will be used then). You can specify negative and positive values, where negative values will shrink the spacing between the chars and positive values will enlarge the spacing.
Note: negative values should be used carefully, otherwise it may happen that the text will be printed reversed (from the right to the left).
|
|
HUD_GetCharSpacing
|
|
|
spacing% =
HUD_GetCharSpacing (
Text_Handle%
)
|
Returns the character spacing value as specified with HUD_SetCharSpacing.
Text_Handle%
The handle of a text object created with HUD_CreateText( )
|
|
HUD_CountLines
|
|
|
num_lines% =
HUD_CountLines (
Text_Handle%
)
|
Returns the current number of lines of a text object (after wrapping, for example).
Text_Handle%
The handle of a text object created with HUD_CreateText( )
|
|
HUD_GetTextWidth
|
|
|
width% =
HUD_GetTextWidth (
Font_Handle%,
text$
)
|
Returns the width that a given text would use on screen with a specified font.
Font_Handle%
The handle of a font loaded with HUD_LoadFont( ).
text$
A string containing any text (single line only, no line breaks).
|
|
HUD_GetCharWidth
|
|
|
charWidth% =
HUD_GetCharWidth (
Font_Handle%,
char$
)
|
Returns the width of char when using a specified font.
Font_Handle%
The retrieved handle of a font loaded with HUD_LoadFont( ).
text$
A text string containing a single char.
|
|
HUD_GetLineHeight
|
|
|
lineHeight% =
HUD_GetLineHeight (
Font_Handle%
)
|
Returns the line height (vertical char spacing) of a loaded font. This is usually the same for all characters of a font.
Font_Handle%
The retrieved handle of a font loaded with HUD_LoadFont( ).
|
|
HUD_GetLines
|
|
|
numberOfLines% =
HUD_GetLines (
Font_Handle%,
text$,
wrapWidth%
)
|
Returns the number of lines a text would have on screen when using the specified font and wrapping width.
Font_Handle%
The retrieved handle of a font loaded with HUD_LoadFont( ).
text$
Any text string.
wrapWidth%
The maximum width of the text.
|
|
HUD_SetTextLineColor
|
|
|
HUD_SetTextLineColor (
Text_Handle%,
line_number%,
R%, G%, B%,
[Alpha#]
)
|
Using this command, you can easily colorize a specified line of a text. This command uses HUD_SetVertexColor. This effect will disappear if the text object is altered again (changing its text, for example). In this case you'll have to apply it again.
Text_Handle%
The handle of a text object created with HUD_CreateText( )
line_number%
The line number of the text's line that should be colorized, starting with 1 (first line).
R%, G%, B%
Specify a color here using a red, green and blue color value (0-255 each).
Alpha#
Specifies the alpha value (transparency). 0.0 means completely transparent (invisible), 1.0 is fully opaque.
|
|
SCROLLABLE TEXTS |
HUD_SetScrollText
|
|
|
HUD_SetScrollText (
Text_Handle%,
text$,
start_line%,
number_lines%
)
|
Similar to HUD_SetText( ), but this command can be used to show certain lines of a text only. Use this command if you want to create a scrollable text. This command takes a string, containing the complete text you want to use with the text object, and displays the wanted lines only. You can define a line number to start and the amount of lines that should be visible. All other lines of the specified text will not be shown. The specified text will be wrapped automatically, using the text object's current wrap width.
Text_Handle%
The handle of a text object created with HUD_CreateText( )
text$
A text string that contains the complete text you want to use. Only the specified lines will be shown.
start_line% , number_lines%
Specifies the number of lines that will be visible and the line to start with. If start_line has been set to 1, for example, and number_lines to 5, only the lines 1 to 5 of the complete text will be shown. You can scroll a text by using this command at any time -simply increase or decrease the start line number.
The minimum value that can be used for start_line is 1 (will start at the first line).
|
|
HUD_GetCurrentScroll
|
|
|
lines_scrolled% =
HUD_GetCurrentScroll (
Text_Handle%
)
|
If you use HUD_SetScrollText( ) to fill a text object, you can use this command to check what line is currently the top-most line that is visible. If you get a value of 1, for example, you know that the first line is still visible (the text has not been scrolled down then). A value of 2 will mean that the second line of the complete text is currently displayed as the topmost line and so on...
Text_Handle%
The handle of a text object that has been filled using HUD_SetScrollText( )
|
|
HUD_GetMaxScroll
|
|
|
max_lines_to_scroll% =
HUD_GetMaxScroll (
Text_Handle%
)
|
If you use HUD_SetScrollText( ) to fill a text object, you can use this command to find out, how many lines a text can be scrolled down until the last line has been reached. You know that a text has been scrolled down completely, for example, if HUD_GetMaxScroll( ) and HUD_GetCurrentScroll( ) are the same.
Text_Handle%
The handle of a text object that has been filled using HUD_SetScrollText( )
|
|
HUD_AttachScrollbar
|
|
|
HUD_AttachScrollbar (
Text_Handle%,
Slider_Handle%,
x-offset%,
[Bar_Handle%]
)
|
To make text scrolling more comfortable, you can add a scroll bar to a text that is filled using HUD_SetScrollText( ). You can specify the object handle of an existing shape (a rectangle is quite useful) or an image object. The specified object will then be resized and positioned automatically to work as a scroll bar that can be used to scroll the text up or down.
Some things to keep in mind when working with scroll bars:
Texts should not be scaled or rotated when a scroll bar has been attached.
Both layers, the scroll bar's layer and the text object's layer should not be scaled or rotated.
You should not change text properties like text-align or wrap width while a scroll bar is attached.
If you want to change a text's text-flow or wrap-width while a scroll bar is attached, remove it first, change the text's properties and re-attach the scroll bar.
Text_Handle%
The handle of a text object that has been filled using HUD_SetScrollText( )
Slider_Handle%
The handle of an existing shape (rectangle, for example) or image object that you want to use as a scroll slider. The specified object will then be resized and positioned automatically to work as a scroll slider that can be used to scroll the text up or down.
x-offset%
Sets the horizontal position of the scroll bar object, counted from the text's current x-coordinate.
Bar_Handle%
Optional handle of an existing shape (rectangle, for example) or image object that you want to use as a scroll bar (the bar behind the slider button). The specified object will then be resized and positioned automatically.
|
|
HUD_DetachScrollbar
|
|
|
HUD_DetachScrollbar (
Text_Handle%
)
|
Detaches (unlinks) a currently attached scroll bar object from the text. The object you used as a scroll bar will not be deleted, it will lose it's scroll bar functionality only and can then be used like a common object again.
Text_Handle%
The handle of a text object that has been filled using HUD_SetScrollText( ) and has a scroll bar object attached.
|
|
INPUT TEXTS |
HUD_EnableTextInput
|
|
|
HUD_EnableTextInput (
Text_Handle%,
maxChars%,
cursor$,
allowedChars$,
[uppercase%],
[SoundHandle%],
)
|
Use this command with an existing text object to enable dynamic text input. A blinking cursor will appear within the text field and the user will be able to enter some text. You can define a custom cursor, as well as the maximum length of the input text or what chars are allowed (any other chars will be ignored). A typing sound can be set, too.
Notes:
Only one input text can be active at the same time. If you enable an input text, Sprite Candy will disable any current input text automatically.
While an input text is active, it receives keyboard input. Keep this in mind.
This feature uses the Blitz command GetKey ( ). Since GetKey ( ) returns a char code ONCE only, you should not use GetKey ( ) within your program at the same time you're using Sprite Candy's input texts. This would cause that either Sprite Candy or your program would not receive key strokes.
Input texts will be de-activated again when:
any button has been clicked
the text object has been set to 'hidden'
another text object has been set to input mode
the user hits the ENTER key
You can de-activate an input text manually at any time using HUD_DisableTextInput ( )
Text_Handle%
The handle of a text object
maxChars%
The maximum amount of chars allowed to enter.
cursor$
Any char that will be used as a blinking cursor (for example '_'). The char used as cursor may NOT be inlcuded within the string of allowed chars.
allowedChars$
A string that contains all chars that a user may enter. Any other chars will be ignored. Note, that you must also include a space char if spaces should be included, too.
Example string: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 "
With this example, the user may enter upper- and lowercase letters, numbers and spaces.
uppercase%
TRUE: All text input will changed to uppercase automatically
FALSE: (Default) - text input will not be set to uppercase.
SoundHandle%
You can specify the handle of a sound that should be played when the text changes (a typewriter sound, for example).
|
|
HUD_DisableTextInput
|
|
Use this command to disable a currently active input text manually. Sprite Candy will also disable an input text automatically when a button has been clicked, another text object has been set to input mode, the text object has been set to 'hidden' or the user has used the ENTER key.
|
|
HUD_GetActiveInputText
|
|
|
Handle% =
HUD_GetActiveInputText (
)
|
If an input text is currently active, this command will return the text object's handle, otherwise '0'. Use this command to check if and what input text is currently active.
|
|
HUD_InputTextClosed
|
|
|
Handle% =
HUD_InputTextClosed (
)
|
If an active input text has been closed (the user has pressed ENTER, for example), this command will return the handle of the regarding text object. Use this command to detect the last recently changed input text. You can use this command to do some text verifications on the regarding text, for example).
Note:
This command returns the text handle of a recently closed input text ONCE only. By using this command, the regarding flag will be set to '0' again until the next time an active input text has been closed.
Text_Handle%
Handle of a text object
|
|
©2004,2005 Mike Dogan / X-PRESSIVE.COM
X-PRESSIVE.COM is a label and working title of Mike Dogan, est. 1999
All artwork, including graphics, text, images and sounds are property of Mike Dogan, X-PRESSIVE.COM. Trademarks belong to their respective owners. All rights reserved.
|