|
Wrath of Zeus
Made by Torchlight Games for CSE 125 SP24
|
#include <gui.hpp>
Public Member Functions | |
| GUI (Client *client, const GameConfig &config) | |
| Stores the client pointer as a data member. More... | |
| bool | init () |
| Initializes all of the necessary file loading for all of the GUI elements, and registers all of the static shader variables for each of the derived widget classes that need a shader. More... | |
| void | beginFrame () |
| ================================================================================ More... | |
| void | layoutFrame (GUIState state) |
| Adds widgets to the layout depending on the specified GUI state. More... | |
| void | handleInputs (float mouse_xpos, float mouse_ypos, bool &is_left_mouse_down, bool &is_right_mouse_down) |
| Takes the current relevant input information and alters the GUI based on the how the inputs interact with all of the handlers assigned to the Widgets. More... | |
| void | renderFrame () |
| widget::Handle | addWidget (widget::Widget::Ptr &&widget) |
| ============================================================================== More... | |
| widget::Widget::Ptr | removeWidget (widget::Handle handle) |
| Removes the specified widget from the GUI. More... | |
| template<typename W > | |
| W * | borrowWidget (widget::Handle handle) |
| Borrows the specified widget from the GUI. This is especially useful inside of callback functions for widgets as you will already have the handle needed to initiate a borrow. More... | |
| bool | shouldCaptureKeystrokes () const |
| ============================================================================== More... | |
| void | setCaptureKeystrokes (bool should_capture) |
| Toggles whether or not the GUI should be capturing keyboard input. More... | |
| void | captureKeystroke (char c) |
| Captures a keystroke as an ASCII char. More... | |
| void | captureBackspace () |
| If the GUI is capturing backspaces, then records a backspace press. This deletes the most recently captured keystroke in the GUI. More... | |
| void | clearCapturedKeyboardInput () |
| Wipes all of the captured keyboard input from the internal state. More... | |
| void | displayControl () |
| Displays controls for the player. More... | |
| std::string | getCapturedKeyboardInput () const |
| Returns all of the captured keyboard input without clearing it. More... | |
| std::shared_ptr< font::Loader > | getFonts () |
| ============================================================================== More... | |
Class which wraps around all of the GUI elements that should be rendered to the screen.
The GUI can essentially be thought of as a collection of "Widgets" which all have "Handles" (or IDs). Each widget has all of the logic it needs to know its size, location, and how to render it. The GUI class acts as a container for all of these widgets and provides a helpful abstraction layer allowing the rest of the code to think in terms of "GUIState", since you can just tell the GUI to render a specific state, and it will do so.
|
explicit |
Stores the client pointer as a data member.
=<SETUP>========================================================================
These are the functions that need to be called to setup a GUI object. Doing anything else before calling these will probably cause a crash.
Constructor for a GUI. This really does nothing except store a pointer to the Client object so that the GUI functions can easily access Client data members, due to the friend relationship of Client -> GUI.
| widget::Handle gui::GUI::addWidget | ( | widget::Widget::Ptr && | widget | ) |
==============================================================================
=<WIDGET MANIPULATION>========================================================
These functions are concerned with adding, removing, and getting widgets to/from the GUI.
Adds the specified widget to the GUI.
NOTE: the widget that is being passed in is of the type Widget::Ptr, which is a typedef for a std::unique_ptr<Widget>. To easily get a unique_ptr for a Widget, you can use the corresponding static make function provided by each widget implementation.
| widget | Widget to add |
| void gui::GUI::beginFrame | ( | ) |
================================================================================
=<RENDERING>====================================================================
These series of functions are what you actually use to do the displaying and rendering of the GUI. They should be called in the order they are listed in this file.
Wipes all of the previous frame's state
Function that should be called at the beginning of a frame. Essentially it wipes all of the previous frame's widget data.
|
inline |
Borrows the specified widget from the GUI. This is especially useful inside of callback functions for widgets as you will already have the handle needed to initiate a borrow.
NOTE: This function essentially returns the raw pointer for the specified widget. Technically you could do unspeakable things to this pointer, but as we are all bound by societal conventions so shall you too not break this taboo.
NOTE: You should not attempt to save this pointer elsewhere. This pointer can be thought of as a "temporary" reference to the Widget, which will go out of scope between the time of calling and the next frame.
NOTE: The template argument you specify essentially performs a dynamic cast on the returned pointer. You should not make your template argument a pointer itself, since the function return type already adds a pointer to it. You should only specify a specific kind of Widget if you are confident in what kind of widget it is (i.e. in an event handler). Otherwise, it is safe to just specify a widget::Widget as the template argument
Example use: // Precondition: We know that handle is a valid handle to a widget::DynText auto widget = gui.borrowWidget<widget::DynText>(handle); // widget is of type widget::DynText*
If you mess up and pass in the wrong template argument, then the pointer will end up being nullptr.
| Type | of the widget that you are trying to borrow. |
| handle | Handle to the widget you want to borrow |
| void gui::GUI::captureBackspace | ( | ) |
| void gui::GUI::captureKeystroke | ( | char | c | ) |
Captures a keystroke as an ASCII char.
Takes a keystroke as captured by the client's GLFW code, and adds it into the GUI. Internally, this will check that the ASCII value is between [32, 126], which is the set of meaningful ASCII values that we care about.
NOTE: this function internally checks whether or not the GUI is capturing keyboard input. If the GUI is not currently capturing keyboard input, then this will do nothing. This means that you don't need to check shouldCaptureKeystrokes before calling this function.
NOTE: This function does not handle backspaces. To handle backspaces, the captureBackspace function should be used instead.
| c | ASCII char to capture |
| void gui::GUI::clearCapturedKeyboardInput | ( | ) |
Wipes all of the captured keyboard input from the internal state.
| void gui::GUI::displayControl | ( | ) |
Displays controls for the player.
| std::string gui::GUI::getCapturedKeyboardInput | ( | ) | const |
Returns all of the captured keyboard input without clearing it.
| std::shared_ptr< font::Loader > gui::GUI::getFonts | ( | ) |
==============================================================================
=<GETTERS>====================================================================
Getters for various private data members
Getter for the font loader
| void gui::GUI::handleInputs | ( | float | mouse_xpos, |
| float | mouse_ypos, | ||
| bool & | is_left_mouse_down, | ||
| bool & | is_right_mouse_down | ||
| ) |
Takes the current relevant input information and alters the GUI based on the how the inputs interact with all of the handlers assigned to the Widgets.
NOTE: this must be called after adding all of the widgets to the screen, otherwise no event handling will work on those widgets added after calling this function.
NOTE: currently this function takes a reference to the mouse down boolean because if it "captures" a mouse click then it sets that boolean to false, to prevent continued event triggers if the mouse is held down. In other words, we want "onClick" events to happen only on the initial click, not continually while the mouse is held down.
NOTE: both of the x and y coordinates of the mouse passed into this function are in the GLFW coordinate space. In GLFW coordinates, the top left corner of the screen is (x=0,y=0). However, in the GUI world all of our coordinates are based off of (x=0,y=0) being in the bottom left corner. This is the only GUI function that takes GLFW coordinates,
| mouse_xpos | x position of the mouse, in GLFW Coordinates |
| mouse_ypos | y position of the mouse, in GLFW Coordinates |
| is_left_mouse_down | reference to flag which stores whether or not the left mouse is down. Note: this is a reference so that if a click is captured it can toggle the mouse down flag to false, so that click doesn't get "double counted" in subsequent frames. |
| is_right_mouse_down | reference to flag which stores whether or not the right mouse is down. Note: this is a reference so that if a click is captured it can toggle the mouse down flag to false, so that click doesn't get "double counted" in subsequent frames. |
| bool gui::GUI::init | ( | ) |
Initializes all of the necessary file loading for all of the GUI elements, and registers all of the static shader variables for each of the derived widget classes that need a shader.
| widget::Widget::Ptr gui::GUI::removeWidget | ( | widget::Handle | handle | ) |
| void gui::GUI::renderFrame | ( | ) |
Renders the current state of the GUI to the screen, based on all of the widgets that have been added and any changes caused by inputs.
| void gui::GUI::setCaptureKeystrokes | ( | bool | should_capture | ) |
| bool gui::GUI::shouldCaptureKeystrokes | ( | ) | const |
==============================================================================
=<KEYBOARD INPUT>=============================================================
These functions are concerned with keyboard input for the TextInput widget. Because of the way this is implemented, there can only be one TextInput widget on the screen at one time. If there are more, they will end up sharing all of the inputted text.
Checks to see if the GUI is currently capturing keyboard input.
NOTE: This shouldn't be called as a precondition for captureKeystroke because captureKeystroke will internally also check whether or not the GUI is capturing keystrokes.