Tramway SDK
|
Immediate mode GUI system. More...
Classes | |
struct | FrameObject |
Typedefs | |
typedef uint32_t | font_t |
typedef uint32_t | glyph_t |
Functions | |
void | SetSelectedText (char *text) |
Sets the text which is selected in a textbox. More... | |
void | SetColor (Render::color_t color, GlyphType type) |
Sets the color. More... | |
void | SetFont (font_t font, GlyphType type) |
Sets the font. More... | |
void | RestoreColor (GlyphType type) |
Restores previous glyph color. More... | |
void | RestoreFont (GlyphType type) |
Restores previous glyph font. More... | |
void | SetGlyphDefaults (Render::color_t color, font_t font, GlyphType type) |
Overrides glyph default colors and fonts. More... | |
void | SetScaling (uint32_t scale) |
Sets the scaling factor. More... | |
uint32_t | GetScaling () |
Returns the scaling factor. More... | |
void | SetCursorDelayed (UI::CursorType cursor) |
Sets the cursor. More... | |
void | Init () |
Performs initialization of the GUI system. More... | |
void | UpdateDrawListFonts () |
Submits registered fonts to the renderer. More... | |
void | Update () |
Submits all of the glyphs for rendering. More... | |
font_t | RegisterFont (Render::Sprite *sprite) |
Registers a font. More... | |
void | SetGlyph (float x, float y, float z, float w, float h, float tex_x, float tex_y, float tex_w, float tex_h, const vec3 &color, font_t font) |
Adds a glyph to rendering list. More... | |
uint32_t | GlyphWidth (font_t font, glyph_t glyph) |
uint32_t | GlyphHeight (font_t font, glyph_t glyph) |
uint32_t | GlyphBorderV (font_t font, glyph_t glyph) |
void | DrawGlyph (font_t font, glyph_t glyph, const vec3 &color, uint32_t x, uint32_t y, uint32_t w=0, uint32_t h=0) |
void | Glyph (font_t font, glyph_t glyph) |
Draws a glyph from a font. More... | |
void | DrawBox (font_t font, glyph_t glyph, uint32_t x, uint32_t y, uint32_t w, uint32_t h) |
Draws a glyph box. More... | |
uint32_t | TextWidth (font_t font, const char *text) |
void | Text (const char *text, uint32_t orientation) |
Draws text on the screen. More... | |
void | DrawBoxHorizontal (font_t font, glyph_t glyph, uint32_t x, uint32_t y, uint32_t w) |
Draws a horizontal bar. More... | |
void | PushFrame (uint32_t x, uint32_t y, uint32_t w, uint32_t h) |
Pushes a frame. More... | |
void | PushFrameRelative (uint32_t orientation, uint32_t offset) |
Pushes a frame releative to the previous. More... | |
void | PopFrame () |
Removes a frame from the frame stack. More... | |
void | PushFrameRelativeKeepCursor (uint32_t orientation, uint32_t offset, bool keep_x, bool keep_y) |
Pushes a frame, but keeps the cursor in place. More... | |
void | PopFrameKeepCursor (bool keep_x, bool keep_y) |
bool | CursorOver (uint32_t x, uint32_t y, uint32_t w, uint32_t h) |
bool | ClickHandled () |
bool | ClickHandledLate () |
bool | Clicked () |
bool | Button (const char *text, bool enabled, uint32_t width) |
Draws a button. More... | |
bool | RadioButton (uint32_t index, uint32_t &selected, const char *text, bool enabled) |
Draws a radio button. More... | |
bool | CheckBox (bool &selected, const char *text, bool enabled) |
Draws a checkbox. More... | |
bool | Slider (float &value, bool enabled, uint32_t width) |
Draws a horizontal slider. More... | |
void | NewLine (uint32_t line) |
Draws a new line. More... | |
void | HorizontalDivider () |
Draws a horizontal divider. More... | |
void | FillFrame (glyph_t glyph) |
Fills the frame with a glyph. More... | |
bool | TextBox (char *text, uint32_t length, bool enabled, uint32_t w, uint32_t h) |
Draws a textbox. More... | |
void | TextBox (const char *text, uint32_t w, uint32_t h) |
Draws a textbox. More... | |
void | Begin () |
Begins the GUI commands for the frame. More... | |
void | End () |
Ends the GUI commands for the frame. More... | |
void | Glyph (glyph_t glyph) |
Variables | |
uint32_t | last_update_frame = 0 |
bool | beginned = false |
bool | mouse_click_not_handled = true |
bool | mouse_click_not_handled_late = true |
Immediate mode GUI system.
If you don't like it, you can always integrate imgui, but I personally very much prefer this way of building GUIs.
First you need to register fonts, which are just Sprites. The glyphs are just sprite frame indices. There are some default fonts in the Ext::Menu system, if you don't want to make your own fonts.
To draw widgets, just call their respective functions once per frame.
To position the widgets, use the frame pushing and popping functions.
typedef uint32_t tram::GUI::font_t |
typedef uint32_t tram::GUI::glyph_t |
enum tram::GUI::GlyphType |
enum tram::GUI::orientation : uint32_t |
enum tram::GUI::widget : glyph_t |
void tram::GUI::Begin | ( | ) |
Begins the GUI commands for the frame.
Pushes the first frame to the frame stack. This function has to be called first, before the End() and the Update() functions. You can call Begin() as much as you want, you just have to call an End() before you can call Begin() again. This should help dealing a bit with the global state that the system has.
bool tram::GUI::Button | ( | const char * | text, |
bool | enabled, | ||
uint32_t | width | ||
) |
Draws a button.
text | Text of the button. |
enabled | If set to false, the button won't be clickable. |
width | Width of the button, in pixels. |
bool tram::GUI::CheckBox | ( | bool & | selected, |
const char * | text, | ||
bool | enabled | ||
) |
Draws a checkbox.
selected | If set to true, the button will be drawn checked. |
text | Text of the button. |
enabled | If set to false, the button won't be clickable. |
bool tram::GUI::Clicked | ( | ) |
bool tram::GUI::ClickHandled | ( | ) |
bool tram::GUI::ClickHandledLate | ( | ) |
bool tram::GUI::CursorOver | ( | uint32_t | x, |
uint32_t | y, | ||
uint32_t | w, | ||
uint32_t | h | ||
) |
void tram::GUI::DrawBox | ( | font_t | font, |
glyph_t | glyph, | ||
uint32_t | x, | ||
uint32_t | y, | ||
uint32_t | w, | ||
uint32_t | h | ||
) |
Draws a glyph box.
Glyph boxes are set up so that the first glyph, i.e. the one that you pass in the glyph parameter is the top-left corner. Then the numerically next glyph is take as the top-middle glpyh, then the top-right. This continues going left-to-right, top-to-bottom until all 9 squares are covered. If you are using a default widget layout font, you can use the enum values WIDGET_WINDOW, WIDGET_REVERSE_WINDOW, WIDGET_BUTTON, WIDGET_SELECT_BOX or WIDGET_BORDER for the glyph index.
void tram::GUI::DrawBoxHorizontal | ( | font_t | font, |
glyph_t | glyph, | ||
uint32_t | x, | ||
uint32_t | y, | ||
uint32_t | w | ||
) |
Draws a horizontal bar.
Similar to how DrawBox() is used, except we only have 3 squares, the left, middle and right.
void tram::GUI::DrawGlyph | ( | font_t | font, |
glyph_t | glyph, | ||
const vec3 & | color, | ||
uint32_t | x, | ||
uint32_t | y, | ||
uint32_t | w = 0 , |
||
uint32_t | h = 0 |
||
) |
void tram::GUI::End | ( | ) |
void tram::GUI::FillFrame | ( | glyph_t | glyph | ) |
Fills the frame with a glyph.
Uses the DrawBox() function internally, so it works just like it, except that it uses the topmost frame to determine the position and sixze of the box.
uint32_t tram::GUI::GetScaling | ( | ) |
Returns the scaling factor.
See SetScaling().
void tram::GUI::Glyph | ( | glyph_t | glyph | ) |
void tram::GUI::HorizontalDivider | ( | ) |
Draws a horizontal divider.
void tram::GUI::Init | ( | ) |
void tram::GUI::NewLine | ( | uint32_t | line | ) |
Draws a new line.
Essentially just moves the cursor down a little bit and resets it to the left side of the frame. Sort of like a line break.
line | Line type. Either LINE_LOW, LINE_NORMAL or LINE_HIGH. |
void tram::GUI::PopFrame | ( | ) |
Removes a frame from the frame stack.
void tram::GUI::PopFrameKeepCursor | ( | bool | keep_x, |
bool | keep_y | ||
) |
void tram::GUI::PushFrame | ( | uint32_t | x, |
uint32_t | y, | ||
uint32_t | w, | ||
uint32_t | h | ||
) |
Pushes a frame.
The coordinates are in absolute screen cooordinates. This function could be useful for something, I just can't think of anything.
void tram::GUI::PushFrameRelative | ( | uint32_t | orientation, |
uint32_t | offset | ||
) |
Pushes a frame releative to the previous.
Check the regulat HTML docs on the website for a graphical description with, i.e. with images, to see how this works. But essentially what this function does, is it takes the previous frame and measures out the offset from the specified orientation and then pushes a new frame with the are from the offset. Initially the first frame is pushed, and it takes up the whole screen. If you wanted to use make the topmost 200px part of the screen a frame, you would set the orientation to FRAME_TOP and offset to 200.
void tram::GUI::PushFrameRelativeKeepCursor | ( | uint32_t | orientation, |
uint32_t | offset, | ||
bool | keep_x, | ||
bool | keep_y | ||
) |
Pushes a frame, but keeps the cursor in place.
Identical to PushFrameRelative(), except this function will not reset the cursor to the top-left corner of the frame.
bool tram::GUI::RadioButton | ( | uint32_t | index, |
uint32_t & | selected, | ||
const char * | text, | ||
bool | enabled | ||
) |
Draws a radio button.
index | Index of this button. |
selected | Index of the selected button. |
text | Text next to the button. |
enable | If set to true, the button won't be clickable |
font_t tram::GUI::RegisterFont | ( | Render::Sprite * | sprite | ) |
Registers a font.
void tram::GUI::RestoreColor | ( | GlyphType | type | ) |
Restores previous glyph color.
See SetColor().
void tram::GUI::SetColor | ( | Render::color_t | color, |
GlyphType | type | ||
) |
Sets the color.
Pushes color to color stack. Each glyph type gets its own color stack. The previously set color can be restored using RestoreColor(). GlyphType::TEXT will set the text rendering color of the Text() function, as well as the text that is drawn by the RadioButton() and CheckBox() functions, on top of all Button() buttons and in TextBox() textboxes. GlyphType::WIDGET will set the color that will be used when drawing non-text widget glyphs. By default it is Render::COLOR_WHITE. This stack is reset every time the GUI::Begin() function is called. The default values can be overriden with SetGlyphDefaults().
color | RGB color that will be set. Take a look at the Render system's header or docs to see what kinds of predefined colors are available. |
type | The type of the glyph that this color will be applied to. |
void tram::GUI::SetCursorDelayed | ( | UI::CursorType | cursor | ) |
Sets the cursor.
The difference between using this function and the cursor setting function in the UI system, is that this function will only switch the cursor if it has been changed, i.e. it will issue the UI::SetCursor() command only if this function receives a new parameter. This means that GUI widgets can change the cursor, but the it is also possible to change it using the UI function and this function will not override it, except if the cursor is placed over a widget.
Sets the font.
Works the same as SetColor(), except for fonts. A font needs to be registered with RegisterFont() first. Widget fonts need to use the widget font layout to be displayed properly.
void tram::GUI::SetGlyph | ( | float | x, |
float | y, | ||
float | z, | ||
float | w, | ||
float | h, | ||
float | tex_x, | ||
float | tex_y, | ||
float | tex_w, | ||
float | tex_h, | ||
const vec3 & | color, | ||
font_t | font | ||
) |
Adds a glyph to rendering list.
Triangularizes a glyph from its params and then it get sent off to rendering via the glyph rendering list.
void tram::GUI::SetGlyphDefaults | ( | Render::color_t | color, |
font_t | font, | ||
GlyphType | type | ||
) |
Overrides glyph default colors and fonts.
Whenever GUI::Begin() is called, the color and font passed to this function will be set as the color and font used for the glyph drawing functions. If you are using the Ext::Menu extension and its default fonts, you don't need to call this function.
void tram::GUI::SetScaling | ( | uint32_t | scale | ) |
Sets the scaling factor.
If set to 1
, the GUI will be drawn normally. If set to 2
, then everything will be drawn twice as large. If set to 3
, then everything will be drawn three times as large. I don't recommend going above that.
void tram::GUI::SetSelectedText | ( | char * | text | ) |
Sets the text which is selected in a textbox.
The way the framework remembers which TextBox you have clicked on and are editing is that once a TextBox is clicked on, the framework remembers the pointer of the text that is being edited. The actual TextBox string is updated only when the TextBox() function is called. If you want to deselect any TextBox, call this function with a nullptr
.
bool tram::GUI::Slider | ( | float & | value, |
bool | enabled, | ||
uint32_t | width | ||
) |
Draws a horizontal slider.
value | Value of the slider, between 0.0f and 1.0f. |
enabled | If set to false, the slider won't be draggable. |
width | Width of the slider, in pixels. |
void tram::GUI::Text | ( | const char * | text, |
uint32_t | orientation | ||
) |
Draws text on the screen.
orientation | Either TEXT_LEFT, TEXT_CENTER, TEXT_RIGHT or TEXT_JUSTIFIED. The default is TEXT_LEFT. |
text | The text that will drawn to screen. |
bool tram::GUI::TextBox | ( | char * | text, |
uint32_t | length, | ||
bool | enabled, | ||
uint32_t | w, | ||
uint32_t | h | ||
) |
Draws a textbox.
text | Text in the textbox. This will be editable. |
length | Length of the text buffer. |
enabled | If false, the textbox won't be editable. |
w,h | Dimensions of the textbox, in pixels. |
void tram::GUI::TextBox | ( | const char * | text, |
uint32_t | w, | ||
uint32_t | h | ||
) |
Draws a textbox.
Essentially identical to the other TextBox() function, except this one accepts a const char*
text. This also means that the text in the textbox won't be editable and it will be drawn as disabled.
uint32_t tram::GUI::TextWidth | ( | font_t | font, |
const char * | text | ||
) |
void tram::GUI::Update | ( | ) |
Submits all of the glyphs for rendering.
Also updates cursor, if needed by SetCursorDelayed().
void tram::GUI::UpdateDrawListFonts | ( | ) |
Submits registered fonts to the renderer.
bool tram::GUI::beginned = false |
uint32_t tram::GUI::last_update_frame = 0 |
bool tram::GUI::mouse_click_not_handled = true |
bool tram::GUI::mouse_click_not_handled_late = true |