Classes:HUDFont
HUDFont is an internal class in ZScript, for use in ZScript status bars.
Note: This feature is for ZScript only. |
This class is used in text-drawing functions as the font to use when drawing text. It also controls how the text is displayed, such as spacing and shadows.
Members
The following are members of the HUDFont. These must be accessed by using a . (period) between the HUDFont's name and the member.
Type | Variables | Use |
---|---|---|
Font | mFont | The Font object that the HUDFont is using for drawing text. |
Functions
Return Type | Function | Arguments (first to last) | Use/Arguments |
---|---|---|---|
HUDFont | Create |
|
Initializes the HUDFont.
Note: this function is static and should be called off the class name, i.e. HUDFont.Create(...). |
Example
In this example, 3 strings will be drawn to the screen, each in a different fashion.
version "2.5" // See Object scopes and versions Class MyStatusBar : BaseStatusBar { HUDFont noMonospaceSmallfont; HUDFont monospaceSmallfont; HUDFont shadowSmallfont; override void Init() { Super.Init(); SetSize(32, 320, 200); // smallfont is a built in Font object in ZScript - if you have your own font // and want to use that instead, you should initialize it like this: // Font myFont = "<FONT NAME>"; // this font will not be monospaced when drawn noMonospaceSmallfont = HUDFont.Create(smallfont); // this font will be monospaced when drawn, // and each character will be spaced based on the width of the "0" character monospaceSmallfont = HUDFont.Create(smallfont, smallfont.GetCharWidth("0"), true); // this font will not be monospaced, but will cast a shadow 8 pixels to the right and 8 pixels to the left shadowSmallfont = HUDFont.Create(smallfont, 0, false, 8, 8); } override void Draw (int state, double TicFrac) { Super.Draw (state, TicFrac); if (state == HUD_StatusBar) { BeginStatusBar(); DrawMainBar(); } else if (state == HUD_Fullscreen) { BeginHUD(); DrawFullScreenStuff(); } } void DrawMainBar() { DrawSomeText(); } void DrawFullScreenStuff() { DrawSomeText(); } void DrawSomeText() { // get the height of the font (we could get the height of any of the 3 HUDFonts we defined, // but they all use the same font internally so it shouldn't matter) // this is used to position each string below the last one int fontHeight = noMonospaceSmallfont.mFont.GetHeight(); // this string will have no monospacing - the "I" will be far skinnier than other characters. DrawString(noMonospaceSmallfont, "TEXT DISPLAY", (0, 0 * fontHeight)); // this string will be monospaced - the "I" will be displayed very awkwardly DrawString(monospaceSmallfont, "TEXT DISPLAY", (0, 1 * fontHeight)); // this string will have a shadow 8 pixels to the right and 8 pixels to the bottom DrawString(shadowSmallfont, "TEXT DISPLAY", (0, 2 * fontHeight)); } }
This article is issued from Zdoom. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.