TermOx
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
ox::System Class Reference

Organizes the highest level of the TUI framework. More...

#include <system.hpp>

Public Member Functions

 System (Mouse_mode mouse_mode=Mouse_mode::Basic, Key_mode key_mode=Key_mode::Normal, Signals signals=Signals::On)
 Initializes the terminal screen into curses mode. More...
 
 System (System const &)=delete
 
Systemoperator= (System const &)=delete
 
 System (System &&)=default
 
Systemoperator= (System &&)=default
 
template<typename Widget_t , typename... Args>
auto run (Args &&... args) -> int
 Create a Widget_t object, set it as head widget and call System::run(). More...
 
auto run (Widget &head) -> int
 Set head as head widget and call System::run(). More...
 

Static Public Member Functions

static auto focus_widget () -> Widget *
 Return a pointer to the currently focused Widget.
 
static void set_focus (Widget &w)
 Give program focus to w. More...
 
static void clear_focus ()
 Removes focus from the currently in focus Widget.
 
static void enable_tab_focus ()
 Enable Tab/Back_tab keys to change the focus Widget.
 
static void disable_tab_focus ()
 Disable Tab/Back_tab keys from changing focus Widget.
 
static void set_head (Widget *new_head)
 Set a new head Widget for the entire system. More...
 
static auto head () -> Widget *
 Return a pointer to the head Widget. More...
 
static auto run () -> int
 Launch the main Event_loop and start processing Events. More...
 
static auto send_event (Event e) -> bool
 Immediately send the event filters and then to the intended receiver. More...
 
static auto send_event (Paint_event e) -> bool
 
static auto send_event (Delete_event e) -> bool
 
static void post_event (Event e)
 Append the event to the Event_queue for the thread it was called on. More...
 
static void exit ()
 Sets the exit flag for the user input event loop. More...
 
static void enable_animation (Widget &w, Animation_engine::Duration_t interval)
 Enable animation for the given Widget w at interval. More...
 
static void enable_animation (Widget &w, FPS fps)
 Enable animation for the given Widget w at fps. More...
 
static void disable_animation (Widget &w)
 Disable animation for the given Widget w. More...
 
static void set_cursor (Cursor cursor, Point offset)
 Set the terminal cursor via cursor parameters and offset applied.
 
static void set_current_queue (Event_queue &queue)
 Set the Event_queue that will be used by post_event. More...
 

Static Public Attributes

static sl::Slot< void()> quit = [] { System::exit(); }
 

Detailed Description

Organizes the highest level of the TUI framework.

Constructing an instance of this class initializes the display system. Manages the head Widget and the main User_input_event_loop.

Constructor & Destructor Documentation

◆ System()

ox::System::System ( Mouse_mode  mouse_mode = Mouse_mode::Basic,
Key_mode  key_mode = Key_mode::Normal,
Signals  signals = Signals::On 
)

Initializes the terminal screen into curses mode.

Must be called before any input/output can occur. No-op if initialized. Mouse_mode - - Off: Generates no Mouse Events. Basic: Generate Mouse Press and Release Events for all buttons and the scroll wheel. Drag: Basic, plus Mouse Move Events while a button is pressed. Move: Basic, plus Mouse Move Events are generated with or without a button pressed.

Key_mode - Normal: Key_press Events generated and auto-repeated if key is held down. Raw: Key_press and Key_release Events are generated, the shift key is not applied with other keys, each key press and release is its own event. Useful for games and where you need to keep track of multiple keys held down at once. All keys returned in Raw mode are lower-case. Has only been tested on a single laptop keyboard.

Signals - - - On: Signals can be generated from ctrl-[key] presses, for instance ctrl-c will send SIGINT instead of byte 3. Off: Signals will not be generated on ctrl-[key] presses, sending the byte value of the ctrl character instead.

Member Function Documentation

◆ disable_animation()

void ox::System::disable_animation ( Widget w)
static

Disable animation for the given Widget w.

Does not stop the animation_engine, even if its empty.

◆ enable_animation() [1/2]

void ox::System::enable_animation ( Widget w,
Animation_engine::Duration_t  interval 
)
static

Enable animation for the given Widget w at interval.

Starts the animation_engine if not started yet.

◆ enable_animation() [2/2]

void ox::System::enable_animation ( Widget w,
FPS  fps 
)
static

Enable animation for the given Widget w at fps.

Starts the animation_engine if not started yet.

◆ exit()

void ox::System::exit ( )
static

Sets the exit flag for the user input event loop.

Only call from the main user input event loop, not animation loop. This is because shutdown will be blocked until more user input is entered. This calls std::_Exit, does not clean up with destructors. TODO threading design makes this difficult to do properly.

◆ head()

auto ox::System::head ( ) -> Widget*
static

Return a pointer to the head Widget.

This Widget is the ancestor of every other widget that will be displayed on the screen.

◆ post_event()

void ox::System::post_event ( Event  e)
static

Append the event to the Event_queue for the thread it was called on.

The Event_queue is processed once per iteration of the Event_loop. When the Event is pulled from the Event_queue, it is processed by System::send_event()

◆ run() [1/3]

auto ox::System::run ( ) -> int
static

Launch the main Event_loop and start processing Events.

Blocks until System::exit() is called, returns the exit code. Will throw a std::runtime_error if screen cannot be initialized. Enables and sets focus to the head Widget.

◆ run() [2/3]

template<typename Widget_t , typename... Args>
auto ox::System::run ( Args &&...  args) -> int
inline

Create a Widget_t object, set it as head widget and call System::run().

args... are passed on to the Widget_t constructor. Blocks until System::exit() is called, returns the exit code. Will throw a std::runtime_error if screen cannot be initialized.

◆ run() [3/3]

auto ox::System::run ( Widget head) -> int

Set head as head widget and call System::run().

Will throw a std::runtime_error if screen cannot be initialized.

◆ send_event() [1/3]

auto ox::System::send_event ( Delete_event  e) -> bool
static

Return true if the event was actually sent.

◆ send_event() [2/3]

auto ox::System::send_event ( Event  e) -> bool
static

Immediately send the event filters and then to the intended receiver.

Return true if the event was actually sent.

◆ send_event() [3/3]

auto ox::System::send_event ( Paint_event  e) -> bool
static

Return true if the event was actually sent.

◆ set_current_queue()

void ox::System::set_current_queue ( Event_queue queue)
static

Set the Event_queue that will be used by post_event.

Set by Event_queue::send_all.

◆ set_focus()

void ox::System::set_focus ( Widget w)
static

Give program focus to w.

Sends Focus_out_event to Widget in focus, and Focus_in_event to w.

◆ set_head()

void ox::System::set_head ( Widget new_head)
static

Set a new head Widget for the entire system.

Will disable the previous head widget if not nullptr. Only valid to call before System::run or after System::exit.


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