libmx2 2.2.1
C++20 multimedia and game-engine library (SDL2 / OpenGL / Vulkan)
Loading...
Searching...
No Matches
console::GLConsole Class Reference

OpenGL-rendered overlay console built on top of Console. More...

#include <console.hpp>

Collaboration diagram for console::GLConsole:
[legend]

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

Detailed Description

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.

Constructor & Destructor Documentation

◆ GLConsole() [1/3]

console::GLConsole::GLConsole ( )

Definition at line 1086 of file console.cpp.

References rc.

Referenced by GLConsole(), GLConsole(), operator=(), and operator=().

◆ ~GLConsole()

console::GLConsole::~GLConsole ( )

Definition at line 1090 of file console.cpp.

References release().

◆ GLConsole() [2/3]

console::GLConsole::GLConsole ( const GLConsole & )
delete

References GLConsole().

◆ GLConsole() [3/3]

console::GLConsole::GLConsole ( GLConsole && )
delete

References GLConsole().

Member Function Documentation

◆ bufferData()

std::ostream & console::GLConsole::bufferData ( )
inline
Returns
Stream reference to the inner output buffer.

Definition at line 529 of file console.hpp.

◆ clear_callbacks()

void console::GLConsole::clear_callbacks ( )
inline

Reset all registered callbacks to no-ops.

Definition at line 498 of file console.hpp.

◆ clearText()

void console::GLConsole::clearText ( )

Clear the entire output buffer.

Definition at line 1094 of file console.cpp.

◆ draw()

void console::GLConsole::draw ( gl::GLWindow * win)

Upload SDL_Surface and blit the GL texture each frame.

Parameters
winCurrent GL window (provides gl context).

Definition at line 1184 of file console.cpp.

References console::FADE_NONE, shader, sprite, texture, and updateTexture().

◆ event()

void console::GLConsole::event ( gl::GLWindow * win,
SDL_Event & e )

High-level event handler with window context.

Parameters
winParent GL window.
eSDL event reference.

Definition at line 1224 of file console.cpp.

References gl::GLWindow::console_visible, gl::GLWindow::quit(), and refresh().

◆ getHeight()

int console::GLConsole::getHeight ( ) const
Returns
Console pixel height.

Definition at line 1336 of file console.cpp.

◆ getWidth()

int console::GLConsole::getWidth ( ) const
Returns
Console pixel width.

Definition at line 1335 of file console.cpp.

◆ handleEvent()

void console::GLConsole::handleEvent ( SDL_Event & e)

Low-level SDL event handler (keyboard + mouse).

Parameters
eSDL event reference.

◆ hide()

void console::GLConsole::hide ( )

Hide console.

Definition at line 1082 of file console.cpp.

◆ inputData()

std::istream & console::GLConsole::inputData ( )
Returns
Stream containing the last submitted input line.

Definition at line 887 of file console.cpp.

References inputStream.

◆ isFading()

bool console::GLConsole::isFading ( ) const
inline
Returns
true while a fade animation is running.

Definition at line 538 of file console.hpp.

◆ isVisible()

bool console::GLConsole::isVisible ( ) const
inline
Returns
true if the console is at least partially visible.

Definition at line 537 of file console.hpp.

◆ load() [1/2]

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.

Parameters
winParent GL window.
rcDesired console rectangle in window-local pixels.
fntTTF font path.
sizeFont point size.
colText 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.

Referenced by load(), and resize().

◆ load() [2/2]

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.

Parameters
winParent GL window.
fntTTF font path.
sizeFont point size.
colText 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.

◆ loadTextFromSurface()

GLuint console::GLConsole::loadTextFromSurface ( SDL_Surface * surf)
protected

Definition at line 1110 of file console.cpp.

Referenced by load().

◆ operator=() [1/2]

GLConsole & console::GLConsole::operator= ( const GLConsole & )
delete

References GLConsole().

◆ operator=() [2/2]

GLConsole & console::GLConsole::operator= ( GLConsole && )
delete

References GLConsole().

◆ print()

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().

◆ printf()

template<typename... Args>
void console::GLConsole::printf ( const char * format,
Args... args )
inline

printf-style helper that formats a string and calls print().

Template Parameters
ArgsVariadic format arguments.
Parameters
formatprintf format string.
argsFormat arguments.

Definition at line 516 of file console.hpp.

References print().

◆ println()

void console::GLConsole::println ( const std::string & data)

Append text followed by a newline.

Definition at line 1220 of file console.cpp.

References print().

◆ procDefaultCommands()

bool console::GLConsole::procDefaultCommands ( const std::vector< std::string > & cmd)

Handle built-in commands (clear, quit, help, …).

Parameters
cmdTokenised command vector.
Returns
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().

◆ process_message_queue()

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.

◆ refresh()

void console::GLConsole::refresh ( )
inline

Drain the command queue and process pending messages (call each frame).

Definition at line 547 of file console.hpp.

Referenced by event().

◆ release()

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().

◆ resize()

void console::GLConsole::resize ( gl::GLWindow * win,
int w,
int h )

Handle window resize — rebuilds GL texture at new dimensions.

Parameters
winParent GL window.
w,hNew viewport size in pixels.

Definition at line 1311 of file console.cpp.

References color, font, font_size, load(), rc, stretch_height, and stretch_value.

◆ setCallback()

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.

◆ setInputCallback()

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.

◆ setPrompt()

void console::GLConsole::setPrompt ( const std::string & prompt)

Change the prompt prefix string.

Definition at line 1332 of file console.cpp.

◆ setStretch()

void console::GLConsole::setStretch ( bool stretch)
inline

Enable/disable vertical stretch to fill the window height.

Definition at line 479 of file console.hpp.

References stretch_value.

◆ setStretchHeight()

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.

◆ setTextAttrib()

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().

◆ setWindow()

void console::GLConsole::setWindow ( gl::GLWindow * win)
inline

Update the inner Console's window pointer.

Definition at line 488 of file console.hpp.

◆ show()

void console::GLConsole::show ( )

Make console visible.

Definition at line 1078 of file console.cpp.

◆ thread_safe_print()

void console::GLConsole::thread_safe_print ( const std::string & data)

Thread-safe variant of print().

Definition at line 1098 of file console.cpp.

◆ updateTexture()

void console::GLConsole::updateTexture ( GLuint tex,
SDL_Surface * surf )
protected

Definition at line 1177 of file console.cpp.

Referenced by draw().

◆ Console

friend class Console
friend

Definition at line 409 of file console.hpp.

References Console, and rc.

Referenced by Console.

Member Data Documentation

◆ color

SDL_Color console::GLConsole::color = {255, 255, 255, 255}
protected

Definition at line 565 of file console.hpp.

Referenced by load(), load(), procDefaultCommands(), and resize().

◆ console

Console console::GLConsole::console
protected

Definition at line 554 of file console.hpp.

◆ font

std::string console::GLConsole::font
protected

Definition at line 563 of file console.hpp.

Referenced by load(), load(), and resize().

◆ font_size

int console::GLConsole::font_size = 16
protected

Definition at line 564 of file console.hpp.

Referenced by load(), load(), and resize().

◆ gl_mutex

std::mutex console::GLConsole::gl_mutex
mutableprotected

Definition at line 553 of file console.hpp.

◆ inputStream

std::istringstream console::GLConsole::inputStream
private

Definition at line 567 of file console.hpp.

Referenced by inputData().

◆ rc

SDL_Rect console::GLConsole::rc
protected

Definition at line 556 of file console.hpp.

Referenced by Console, GLConsole(), load(), load(), and resize().

◆ shader

std::unique_ptr<gl::ShaderProgram> console::GLConsole::shader
protected

Definition at line 559 of file console.hpp.

Referenced by draw(), load(), and release().

◆ sprite

std::unique_ptr<gl::GLSprite> console::GLConsole::sprite = nullptr
protected

Definition at line 558 of file console.hpp.

Referenced by draw(), load(), and release().

◆ stretch_height

int console::GLConsole::stretch_height = 0
protected

Definition at line 557 of file console.hpp.

Referenced by load(), load(), resize(), and setStretchHeight().

◆ stretch_value

bool console::GLConsole::stretch_value = true
protected

Definition at line 555 of file console.hpp.

Referenced by load(), load(), resize(), and setStretch().

◆ texture

GLuint console::GLConsole::texture = 0
protected

Definition at line 560 of file console.hpp.

Referenced by draw(), load(), and release().


The documentation for this class was generated from the following files: