Etermal
Embeddable Terminal and shell for OpenGL
|
Build-in implementation of the ETerminal frontend. More...
#include <Terminal.h>
Public Types | |
typedef std::function< void()> | winActionCB_t |
Callback for a window action callback. More... | |
typedef std::function< void(const termError &error)> | errCallback_t |
Error callback function. More... | |
Public Member Functions | |
Terminal (bool postponeInit=false) | |
Creates a Terminal. More... | |
Terminal (const std::shared_ptr< EtmFont > &font, bool postponeInit=false) | |
Creates a Terminal. More... | |
Terminal (const errCallback_t &errorCallback, const std::shared_ptr< EtmFont > &font, bool postponeInit=false) | |
Creates a Terminal with a custom error callback. More... | |
~Terminal () | |
Destucts the terminal. | |
Terminal (Terminal &&other) | |
Initialize with moved object. More... | |
Terminal & | operator= (Terminal &&other) |
Set to moved object. More... | |
void | init () |
Initialize the terminal's openGL context resources. More... | |
void | deInit () |
Free the terminal's openGL context resources. More... | |
void | setFont (const std::shared_ptr< EtmFont > &font) |
Changes the in-use font. More... | |
void | invalidate () |
void | notifyScroll () |
void | postError (const termError &error) |
Pass an error to the current error callback. More... | |
void | setCursorDefault (const winActionCB_t &callback) |
Set the cursor default callback. More... | |
void | setCursorIBeam (const winActionCB_t &callback) |
Set the cursor i-beam callback. More... | |
void | setHovering (bool value) |
Set whether the mouse is hovering over the terminal. More... | |
void | setErrorCallback (const errCallback_t &callback) |
Sets the global error callback for this Terminal. More... | |
void | clearInput () override |
Clears the input area (the area after the cursor lock). | |
void | clear () override |
Clears the screen. More... | |
void | setBackgroundColor (const Color &color) |
Sets the background color of the terminal. More... | |
void | setTextColor (const Color &color) |
Sets the default foreground color of printed text. More... | |
void | setScrollSensitivity (float value) |
Sets the mouse scroll sensitivity. More... | |
void | setScrollCooldown (int millis) |
Time between scrolls when holding down the scrollbar arrow. More... | |
void | setScrollWait (int millis) |
Time to wait until doing scroll repeat from when user first presses scroll button. More... | |
void | setShell (EShell &shell) |
Sets the shell to which user input should be directed. More... | |
void | setTakeInput (bool value) override |
Sets whether the shell wants input. More... | |
void | requestInput (TermInput &callback) override |
Each call adds callback to the input queue. More... | |
void | cancelInputRequest (TermInput *callback) override |
Removes all instances of a callback from the input queue. More... | |
void | clearInputRequests () override |
Deletes all input requests. More... | |
std::string | pollInput () override |
Get the current input text. More... | |
void | dispText (const std::string &str) override |
Append text to the display buffer. More... | |
void | flush () override |
Pushes the display buffer to the display. More... | |
void | softFlush () override |
Pushes the display buffer to the display. More... | |
void | setX (float x) |
Set the x coordinate of the top-left corner of the terminal. More... | |
void | setY (float y) |
Set the y coordinate of the top-left corner of the terminal. More... | |
void | setWidth (int width) |
Sets the pixel width of the terminal. More... | |
void | setHeight (int height) |
Sets the pixel height of the terminal. More... | |
void | setRows (int rows, int margin=7) |
Sets the pixel height of the terminal based off of a desired number of rows, with one row being the height of a line of text. More... | |
void | setColumns (int columns) |
Sets the pixel width of the terminal based off of a desired number of columns, with one columns being the height of a single character. More... | |
void | setFontSize (unsigned int size) |
Sets the font pixel size. More... | |
void | setMaxLines (TextBuffer::lines_number_t count) |
Set the maximum number of lines. More... | |
void | updatePosition () |
Update element positioning. | |
void | inputChar (unsigned int codepoint) |
Input a char to the terminal, typically due to user input. More... | |
void | inputChar (const Line::codepoint &c) |
Input a char to the terminal, typically due to user input. More... | |
void | inputString (const std::string &text) |
Input a string to the terminal, typically due to a user pasting text. More... | |
void | inputActionKey (actionKey key) |
Inputs an "action" key, one that is not printable but represents some sort of command. More... | |
void | inputMouseScroll (float yOffset, float mouseX, float mouseY) |
Notify the terminal of user scroll input. More... | |
void | inputMouseClick (bool isPressed, float mouseX, float mouseY) |
Notify the terminal of user mouse button input. More... | |
void | inputMouseMove (float mouseX, float mouseY) |
Notify the terminal of user mouse movement. More... | |
void | render () |
Renders the terminal to the current framebuffer. More... | |
bool | isFocused () |
Gets if the terminal is focused by the user. More... | |
void | setFocused (bool val) |
Sets whether the terminal is focused or not. More... | |
std::string | getTextSelection () |
Gets the text highlighted by the user. More... | |
std::string | getText () |
Gets all the text in the terminal. More... | |
Protected Member Functions | |
int | sync () override |
Calls flush(). More... | |
std::streamsize | showmanyc () override |
Returns the size of the display buffer. More... | |
std::streamsize | xsgetn (char *c, std::streamsize n) override |
Extracts characters from the start of the display buffer. More... | |
int | underflow () override |
Get the first character in the display buffer. More... | |
int | uflow () override |
Extract the first character in the display buffer. More... | |
int | pbackfail (int c=EOF) override |
Put back a char. | |
std::streamsize | xsputn (const char *s, std::streamsize n) override |
Input chars. More... | |
int | overflow (int c=EOF) override |
Input a char. More... | |
Terminal (const errCallback_t &errorCallback, bool postponeInit) | |
Construct a terminal (internal). More... | |
Build-in implementation of the ETerminal frontend.
The multible constructors operate under the philosophy that there should be an option to construct the terminal so that is completely ready to render.
typedef std::function<void(const termError &error)> etm::Terminal::errCallback_t |
Error callback function.
[in] | error | An object with error information |
typedef std::function<void()> etm::Terminal::winActionCB_t |
Callback for a window action callback.
Used to allow user to supply their own procedures for interfacing with the window.
|
protected |
Construct a terminal (internal).
[in] | errorCallback | The error callback |
[in] | postponeInit | true to postpone OpenGL resource initialization |
etm::Terminal::Terminal | ( | bool | postponeInit = false | ) |
Creates a Terminal.
postponeInit
is set to false
. [in] | postponeInit | If this is set to true , the terminal WILL NOT initialize it's OpenGL resources right away, allowing you to later on generate the resources in the context you want to render to terminal to. NOTE WELL that you must call init() before you do any rendering. If set to false , you can still call init() later on when your desired context is bound, however bad things will happen if an OpenGL context isn't active. The bottom line is: if the context you want to render to is current, keep it at false . Otherwise, set it to true and call init() later on. |
etm::Terminal::Terminal | ( | const std::shared_ptr< EtmFont > & | font, |
bool | postponeInit = false |
||
) |
Creates a Terminal.
postponeInit
is set to false
. [in] | font | The initial font |
[in] | postponeInit | If this is set to true , the terminal WILL NOT initialize it's OpenGL resources right away, allowing you to later on generate the resources in the context you want to render to terminal to. NOTE WELL that you must call init() before you do any rendering. If set to false , you can still call init() later on when your desired context is bound, however bad things will happen if an OpenGL context isn't active. The bottom line is: if the context you want to render to is current, keep it at false . Otherwise, set it to true and call init() later on. |
etm::Terminal::Terminal | ( | const errCallback_t & | errorCallback, |
const std::shared_ptr< EtmFont > & | font, | ||
bool | postponeInit = false |
||
) |
Creates a Terminal with a custom error callback.
It's important to specify how you want errors handled on creation, as errors can occur during initialization.
postponeInit
is set to false
. [in] | errorCallback | The error callback |
[in] | font | The initial font (See Font and BmpFont) |
[in] | postponeInit | If this is set to true , the terminal WILL NOT initialize it's OpenGL resources right away, allowing you to later on generate the resources in the context you want to render to terminal to. NOTE WELL that you must call init() before you do any rendering. If set to false , you can still call init() later on when your desired context is bound, however bad things will happen if an OpenGL context isn't active. The bottom line is: if the context you want to render to is current, keep it at false . Otherwise, set it to true and call init() later on. |
etm::Terminal::Terminal | ( | Terminal && | other | ) |
Initialize with moved object.
[in,out] | other | The object to move |
|
overridevirtual |
Removes all instances of a callback from the input queue.
[in] | callback | pointer to the callback to be removed |
Implements etm::ETerminal.
|
overridevirtual |
Clears the screen.
Causes all caches and other data related to the text and screen to be cleared.
Implements etm::ETerminal.
|
overridevirtual |
Deletes all input requests.
Implements etm::ETerminal.
void etm::Terminal::deInit | ( | ) |
Free the terminal's openGL context resources.
|
overridevirtual |
Append text to the display buffer.
The buffer will not be displayed until flush() is called.
[in] | str | UTF-8 encoded string to be appended to the display buffer |
Implements etm::ETerminal.
|
overridevirtual |
Pushes the display buffer to the display.
Implements etm::ETerminal.
std::string etm::Terminal::getText | ( | ) |
Gets all the text in the terminal.
std::string etm::Terminal::getTextSelection | ( | ) |
Gets the text highlighted by the user.
Highlight is determined by where the user clicking and dragging.
This is useful for copy/paste operations - which is exectly what this fuction was made for.
void etm::Terminal::init | ( | ) |
Initialize the terminal's openGL context resources.
void etm::Terminal::inputActionKey | ( | actionKey | key | ) |
Inputs an "action" key, one that is not printable but represents some sort of command.
[in] | key | The pressed key |
void etm::Terminal::inputChar | ( | const Line::codepoint & | c | ) |
Input a char to the terminal, typically due to user input.
This function, however, takes an encoded codepoint.
[in] | c | The codepoint |
void etm::Terminal::inputChar | ( | unsigned int | codepoint | ) |
Input a char to the terminal, typically due to user input.
[in] | codepoint | A Unicode codepoint |
void etm::Terminal::inputMouseClick | ( | bool | isPressed, |
float | mouseX, | ||
float | mouseY | ||
) |
Notify the terminal of user mouse button input.
For simplicity, the terminal doesn't care what mouse button was pressed - however, it would probally be more intuitive if it was the left mouse button.
[in] | isPressed | Was the mouse button pressed? |
[in] | mouseX | Current x-coordinate of the mouse |
[in] | mouseY | Current y-coordinate of the mouse |
void etm::Terminal::inputMouseMove | ( | float | mouseX, |
float | mouseY | ||
) |
Notify the terminal of user mouse movement.
[in] | mouseX | New x-coordinate of the mouse |
[in] | mouseY | New y-coordinate of the mouse |
void etm::Terminal::inputMouseScroll | ( | float | yOffset, |
float | mouseX, | ||
float | mouseY | ||
) |
Notify the terminal of user scroll input.
[in] | yOffset | The difference from the last scroll position |
[in] | mouseX | Current x-coordinate of the mouse |
[in] | mouseY | Current y-coordinate of the mouse |
void etm::Terminal::inputString | ( | const std::string & | text | ) |
Input a string to the terminal, typically due to a user pasting text.
[in] | text | UTF-8 encoded string |
bool etm::Terminal::isFocused | ( | ) |
Gets if the terminal is focused by the user.
The default value is true
.
This is determined by the user clicking inside the terminal (true
) or elseware (false
).
true
if the terminal is focused. Set to moved object.
[in,out] | other | The object to move |
*this
|
overrideprotected |
Input a char.
[in] | c | The char. |
|
overridevirtual |
Get the current input text.
Implements etm::ETerminal.
void etm::Terminal::postError | ( | const termError & | error | ) |
Pass an error to the current error callback.
[in] | error | The error object |
void etm::Terminal::render | ( | ) |
Renders the terminal to the current framebuffer.
|
overridevirtual |
Each call adds callback
to the input queue.
Each time input is entered, the callback is called and removed. Be careful of multible calls to this, for you could become locked in.
[in] | callback | The callback to recieve the input text as a UTF-8 encoded string |
Implements etm::ETerminal.
void etm::Terminal::setBackgroundColor | ( | const Color & | color | ) |
Sets the background color of the terminal.
This also sets the default background color of text.
[in] | color | The color |
void etm::Terminal::setColumns | ( | int | columns | ) |
Sets the pixel width of the terminal based off of a desired number of columns, with one columns being the height of a single character.
This does not affect the scrollbar width or text width.
[in] | columns | The desired columns |
void etm::Terminal::setCursorDefault | ( | const winActionCB_t & | callback | ) |
Set the cursor default callback.
This is called whenever the terminal would like to set the cursor to its default state.
The callback does not have to be callable.
[in] | callback | The callback |
void etm::Terminal::setCursorIBeam | ( | const winActionCB_t & | callback | ) |
Set the cursor i-beam callback.
This is called whenever the terminal would like to set the cursor to i-beam (aka text input-mode).
The callback does not have to be callable.
[in] | callback | The callback |
void etm::Terminal::setErrorCallback | ( | const errCallback_t & | callback | ) |
Sets the global error callback for this Terminal.
All errors will be directed to this function.
callback
must be callable. If not, the error callback isn't changed [in] | callback | A new callable error callback |
void etm::Terminal::setFocused | ( | bool | val | ) |
Sets whether the terminal is focused or not.
The default value is true
.
While normally determined by user mouse clicks, if you feel the need you can manually set it yourself.
[in] | val | New focused status |
void etm::Terminal::setFont | ( | const std::shared_ptr< EtmFont > & | font | ) |
Changes the in-use font.
[in] | font | The font |
void etm::Terminal::setFontSize | ( | unsigned int | size | ) |
Sets the font pixel size.
[in] | size | The pixel size |
void etm::Terminal::setHeight | ( | int | height | ) |
Sets the pixel height of the terminal.
This does not affect the scrollbar height or text height.
[in] | height | The new height |
void etm::Terminal::setHovering | ( | bool | value | ) |
Set whether the mouse is hovering over the terminal.
If set to true and hovering
is false, will call the callback set by setCursorIBeam(const winActionCB_t &callback) (if it's callable), and vice versa with the callback set by setCursorDefault(const winActionCB_t &callback).
[in] | value | The value |
void etm::Terminal::setMaxLines | ( | TextBuffer::lines_number_t | count | ) |
Set the maximum number of lines.
If the limit is exceed, the oldest lines will be removed.
[in] | count | number of lines |
void etm::Terminal::setRows | ( | int | rows, |
int | margin = 7 |
||
) |
Sets the pixel height of the terminal based off of a desired number of rows, with one row being the height of a line of text.
This does not affect the scrollbar height or text height.
[in] | rows | The desired rows |
[in] | margin | Ammount of space at the bottom of the terminal, so that the input area doesn't feel so cramped. |
void etm::Terminal::setScrollCooldown | ( | int | millis | ) |
Time between scrolls when holding down the scrollbar arrow.
[in] | millis | Time in milliseconds |
void etm::Terminal::setScrollSensitivity | ( | float | value | ) |
Sets the mouse scroll sensitivity.
[in] | value | The sensitivity |
void etm::Terminal::setScrollWait | ( | int | millis | ) |
Time to wait until doing scroll repeat from when user first presses scroll button.
[in] | millis | Time in milliseconds |
void etm::Terminal::setShell | ( | EShell & | shell | ) |
Sets the shell to which user input should be directed.
[in] | shell | The shell object |
|
overridevirtual |
Sets whether the shell wants input.
If this is false and there are no queued input requests, the terminal will ignore input.
[in] | value | Whether the shell wants input |
Implements etm::ETerminal.
void etm::Terminal::setTextColor | ( | const Color & | color | ) |
Sets the default foreground color of printed text.
[in] | color | The color |
void etm::Terminal::setWidth | ( | int | width | ) |
Sets the pixel width of the terminal.
This does not affect the scrollbar width or text width.
[in] | width | The new width |
void etm::Terminal::setX | ( | float | x | ) |
Set the x coordinate of the top-left corner of the terminal.
[in] | x | The x coordinate |
void etm::Terminal::setY | ( | float | y | ) |
Set the y coordinate of the top-left corner of the terminal.
[in] | y | The y coordinate |
|
overrideprotected |
Returns the size of the display buffer.
|
overridevirtual |
Pushes the display buffer to the display.
Unlike flush(), does not move the cursor.
Implements etm::ETerminal.
|
overrideprotected |
Calls flush().
|
overrideprotected |
Extract the first character in the display buffer.
|
overrideprotected |
Get the first character in the display buffer.
|
overrideprotected |
Extracts characters from the start of the display buffer.
[out] | c | The output string |
[in] | n | Size of the output string |
|
overrideprotected |
Input chars.
[in] | s | The data |
[in] | n | Length of data |