|
libmx2 2.2.1
C++20 multimedia and game-engine library (SDL2 / OpenGL / Vulkan)
|
OpenGL-rendered overlay console built on top of Console. More...
#include <console.hpp>
Public Member Functions | |
| GLConsole () | |
| ~GLConsole () | |
| GLConsole (const GLConsole &)=delete | |
| GLConsole & | operator= (const GLConsole &)=delete |
| GLConsole (GLConsole &&)=delete | |
| GLConsole & | operator= (GLConsole &&)=delete |
| void | release () |
| Destroy the GL texture and sprite resources. | |
| void | load (gl::GLWindow *win, const SDL_Rect &rc, const std::string &fnt, int size, const SDL_Color &col) |
| Load and position the console inside a specific rectangle. | |
| void | load (gl::GLWindow *win, const std::string &fnt, int size, const SDL_Color &col) |
| Load the console spanning the full window width. | |
| void | draw (gl::GLWindow *win) |
| Upload SDL_Surface and blit the GL texture each frame. | |
| void | handleEvent (SDL_Event &e) |
| Low-level SDL event handler (keyboard + mouse). | |
| void | event (gl::GLWindow *win, SDL_Event &e) |
| High-level event handler with window context. | |
| void | print (const std::string &data) |
| Append text to the console output. | |
| void | println (const std::string &data) |
| Append text followed by a newline. | |
| void | thread_safe_print (const std::string &data) |
| Thread-safe variant of print(). | |
| void | resize (gl::GLWindow *win, int w, int h) |
| Handle window resize — rebuilds GL texture at new dimensions. | |
| void | setPrompt (const std::string &prompt) |
| Change the prompt prefix string. | |
| void | setCallback (gl::GLWindow *window, std::function< bool(gl::GLWindow *win, const std::vector< std::string > &)> callback) |
| Register a command callback (same semantics as Console::setCallback()). | |
| void | setInputCallback (std::function< int(gl::GLWindow *window, const std::string &)> callback) |
| Register a raw-input callback (same semantics as Console::setInputCallback()). | |
| void | show () |
| Make console visible. | |
| void | hide () |
| Hide console. | |
| void | setStretch (bool stretch) |
| Enable/disable vertical stretch to fill the window height. | |
| void | setTextAttrib (const int size, const SDL_Color &col) |
| Change font size/colour (propagates to inner Console). | |
| int | getWidth () const |
| int | getHeight () const |
| void | setWindow (gl::GLWindow *win) |
| Update the inner Console's window pointer. | |
| bool | procDefaultCommands (const std::vector< std::string > &cmd) |
| Handle built-in commands (clear, quit, help, …). | |
| void | clear_callbacks () |
| Reset all registered callbacks to no-ops. | |
| template<typename... Args> | |
| void | printf (const char *format, Args... args) |
| printf-style helper that formats a string and calls print(). | |
| std::ostream & | bufferData () |
| std::istream & | inputData () |
| void | process_message_queue () |
| Flush the thread-safe message queue into the output buffer (call each frame). | |
| bool | isVisible () const |
| bool | isFading () const |
| void | setStretchHeight (int value) |
| Set an absolute height override for the stretch mode. | |
| void | clearText () |
| Clear the entire output buffer. | |
| void | refresh () |
| Drain the command queue and process pending messages (call each frame). | |
Protected Member Functions | |
| GLuint | loadTextFromSurface (SDL_Surface *surf) |
| void | updateTexture (GLuint tex, SDL_Surface *surf) |
Protected Attributes | |
| std::mutex | gl_mutex |
| Console | console |
| bool | stretch_value = true |
| SDL_Rect | rc |
| int | stretch_height = 0 |
| std::unique_ptr< gl::GLSprite > | sprite = nullptr |
| std::unique_ptr< gl::ShaderProgram > | shader |
| GLuint | texture = 0 |
| std::string | font |
| int | font_size = 16 |
| SDL_Color | color = {255, 255, 255, 255} |
Private Attributes | |
| std::istringstream | inputStream |
Friends | |
| class | Console |
OpenGL-rendered overlay console built on top of Console.
GLConsole manages a gl::GLSprite and uploads the Console's SDL_Surface to a GL texture every frame. It handles window resize, fade animation, and optional full-height stretching — making it easy to drop an interactive terminal into any GLWindow-based application.
Definition at line 396 of file console.hpp.
| console::GLConsole::GLConsole | ( | ) |
Definition at line 1086 of file console.cpp.
References rc.
Referenced by GLConsole(), GLConsole(), operator=(), and operator=().
| console::GLConsole::~GLConsole | ( | ) |
Definition at line 1090 of file console.cpp.
References release().
|
delete |
References GLConsole().
|
delete |
References GLConsole().
|
inline |
Definition at line 529 of file console.hpp.
|
inline |
Reset all registered callbacks to no-ops.
Definition at line 498 of file console.hpp.
| void console::GLConsole::clearText | ( | ) |
Clear the entire output buffer.
Definition at line 1094 of file console.cpp.
| void console::GLConsole::draw | ( | gl::GLWindow * | win | ) |
Upload SDL_Surface and blit the GL texture each frame.
| win | Current GL window (provides gl context). |
Definition at line 1184 of file console.cpp.
References console::FADE_NONE, shader, sprite, texture, and updateTexture().
| void console::GLConsole::event | ( | gl::GLWindow * | win, |
| SDL_Event & | e ) |
High-level event handler with window context.
| win | Parent GL window. |
| e | SDL event reference. |
Definition at line 1224 of file console.cpp.
References gl::GLWindow::console_visible, gl::GLWindow::quit(), and refresh().
| int console::GLConsole::getHeight | ( | ) | const |
Definition at line 1336 of file console.cpp.
| int console::GLConsole::getWidth | ( | ) | const |
Definition at line 1335 of file console.cpp.
| void console::GLConsole::handleEvent | ( | SDL_Event & | e | ) |
Low-level SDL event handler (keyboard + mouse).
| e | SDL event reference. |
| void console::GLConsole::hide | ( | ) |
Hide console.
Definition at line 1082 of file console.cpp.
| std::istream & console::GLConsole::inputData | ( | ) |
Definition at line 887 of file console.cpp.
References inputStream.
|
inline |
true while a fade animation is running. Definition at line 538 of file console.hpp.
|
inline |
true if the console is at least partially visible. Definition at line 537 of file console.hpp.
| void console::GLConsole::load | ( | gl::GLWindow * | win, |
| const SDL_Rect & | rc, | ||
| const std::string & | fnt, | ||
| int | size, | ||
| const SDL_Color & | col ) |
Load and position the console inside a specific rectangle.
| win | Parent GL window. |
| rc | Desired console rectangle in window-local pixels. |
| fnt | TTF font path. |
| size | Font point size. |
| col | Text colour. |
Definition at line 1127 of file console.cpp.
References color, font, font_size, gl::fSource, gl::GLWindow::h, loadTextFromSurface(), rc, shader, sprite, stretch_height, stretch_value, texture, gl::GLWindow::util, gl::vSource, and gl::GLWindow::w.
| void console::GLConsole::load | ( | gl::GLWindow * | win, |
| const std::string & | fnt, | ||
| int | size, | ||
| const SDL_Color & | col ) |
Load the console spanning the full window width.
| win | Parent GL window. |
| fnt | TTF font path. |
| size | Font point size. |
| col | Text colour. |
Definition at line 1159 of file console.cpp.
References color, font, font_size, gl::GLWindow::h, load(), rc, stretch_height, stretch_value, gl::GLWindow::util, and gl::GLWindow::w.
|
protected |
Definition at line 1110 of file console.cpp.
Referenced by load().
References GLConsole().
References GLConsole().
| void console::GLConsole::print | ( | const std::string & | data | ) |
Append text to the console output.
Definition at line 1214 of file console.cpp.
Referenced by printf(), println(), and procDefaultCommands().
|
inline |
printf-style helper that formats a string and calls print().
| Args | Variadic format arguments. |
| format | printf format string. |
| args | Format arguments. |
Definition at line 516 of file console.hpp.
References print().
| void console::GLConsole::println | ( | const std::string & | data | ) |
| bool console::GLConsole::procDefaultCommands | ( | const std::vector< std::string > & | cmd | ) |
Handle built-in commands (clear, quit, help, …).
| cmd | Tokenised command vector. |
true if the command was consumed. Definition at line 1338 of file console.cpp.
References color, print(), PROJECT_VERSION_MAJOR, PROJECT_VERSION_MINOR, and setTextAttrib().
| void console::GLConsole::process_message_queue | ( | ) |
Flush the thread-safe message queue into the output buffer (call each frame).
Definition at line 1102 of file console.cpp.
|
inline |
Drain the command queue and process pending messages (call each frame).
Definition at line 547 of file console.hpp.
Referenced by event().
| void console::GLConsole::release | ( | ) |
Destroy the GL texture and sprite resources.
Definition at line 893 of file console.cpp.
References shader, sprite, and texture.
Referenced by ~GLConsole().
| void console::GLConsole::resize | ( | gl::GLWindow * | win, |
| int | w, | ||
| int | h ) |
Handle window resize — rebuilds GL texture at new dimensions.
| win | Parent GL window. |
| w,h | New viewport size in pixels. |
Definition at line 1311 of file console.cpp.
References color, font, font_size, load(), rc, stretch_height, and stretch_value.
| void console::GLConsole::setCallback | ( | gl::GLWindow * | window, |
| std::function< bool(gl::GLWindow *win, const std::vector< std::string > &)> | callback ) |
Register a command callback (same semantics as Console::setCallback()).
Definition at line 1328 of file console.cpp.
| void console::GLConsole::setInputCallback | ( | std::function< int(gl::GLWindow *window, const std::string &)> | callback | ) |
Register a raw-input callback (same semantics as Console::setInputCallback()).
Definition at line 1106 of file console.cpp.
| void console::GLConsole::setPrompt | ( | const std::string & | prompt | ) |
Change the prompt prefix string.
Definition at line 1332 of file console.cpp.
|
inline |
Enable/disable vertical stretch to fill the window height.
Definition at line 479 of file console.hpp.
References stretch_value.
| void console::GLConsole::setStretchHeight | ( | int | value | ) |
Set an absolute height override for the stretch mode.
Definition at line 1307 of file console.cpp.
References stretch_height.
| void console::GLConsole::setTextAttrib | ( | const int | size, |
| const SDL_Color & | col ) |
Change font size/colour (propagates to inner Console).
Definition at line 1156 of file console.cpp.
Referenced by procDefaultCommands().
|
inline |
Update the inner Console's window pointer.
Definition at line 488 of file console.hpp.
| void console::GLConsole::show | ( | ) |
Make console visible.
Definition at line 1078 of file console.cpp.
| void console::GLConsole::thread_safe_print | ( | const std::string & | data | ) |
Thread-safe variant of print().
Definition at line 1098 of file console.cpp.
|
protected |
Definition at line 1177 of file console.cpp.
Referenced by draw().
|
friend |
|
protected |
Definition at line 565 of file console.hpp.
Referenced by load(), load(), procDefaultCommands(), and resize().
|
protected |
Definition at line 554 of file console.hpp.
|
protected |
Definition at line 563 of file console.hpp.
|
protected |
Definition at line 564 of file console.hpp.
|
mutableprotected |
Definition at line 553 of file console.hpp.
|
private |
Definition at line 567 of file console.hpp.
Referenced by inputData().
|
protected |
Definition at line 556 of file console.hpp.
Referenced by Console, GLConsole(), load(), load(), and resize().
|
protected |
Definition at line 559 of file console.hpp.
|
protected |
Definition at line 558 of file console.hpp.
|
protected |
Definition at line 557 of file console.hpp.
Referenced by load(), load(), resize(), and setStretchHeight().
|
protected |
Definition at line 555 of file console.hpp.
Referenced by load(), load(), resize(), and setStretch().
|
protected |
Definition at line 560 of file console.hpp.