![]() |
Angel
A 2D Game Prototyping Engine
|
The on-screen console: handles input, history, and executing commands. More...
#include <Console.h>
Inheritance diagram for Console:Public Member Functions | |
| Console () | |
| virtual | ~Console () |
| void | Render () |
| void | Update (float) |
| void | Enable (bool bEnable=true) |
| bool | IsEnabled () |
| bool | GetInput (int key) |
| bool | GetSpecialInputDown (int key) |
| void | ToggleConsole () |
| unsigned char | GetToggleConsoleKey () |
| void | WriteToOutput (String output) |
| void | SetPrompt (const String &prompt) |
| const unsigned int | GetTabWidth () |
| void | SetTabWidth (unsigned int newTabWidth) |
| void | AdvanceInputHistory (int byVal) |
| void | AcceptAutocomplete () |
| virtual void | Execute (String input)=0 |
| virtual StringList | GetCompletions (const String &input)=0 |
Protected Member Functions | |
| bool | IsTextKey (unsigned char key) |
| void | AcceptCurrentInput () |
Protected Attributes | |
| String | _currentInput |
| StringList | _inputHistory |
| int | _inputHistoryPos |
| String | _prompt |
| StringList | _buffer |
| String | _unsplitBuffer |
| float | _lineHeight |
| StringList | _autoCompleteList |
| int | _cursorPos |
| unsigned int | _tabWidth |
This abstract base class contains everything you need to create your own console that responds to user input. The base class handles displaying and hiding the console, taking input, and recording command history.
To make a console, your subclass needs to implement the Execute function (which gets called with a string whenever the user enters input) and the GetCompletions function, which returns a StringList of potential auto-complete values.
Most of this is academic, as you'll probably use the Lua console, which has already implemented all of this for you.
There's also a TestConsole implementation that does nothing but echo your commands back at you. It's the default console, so if you ever see its prompt (::>), you know something has gone wrong with loading the real console.
| Console::Console | ( | ) |
The default constructor makes sure our console font (Inconsolata at) 18 points) is registered with the text rendering system.
Definition at line 44 of file Console.cpp.
| Console::~Console | ( | ) | [virtual] |
Does nothing in the base class, but you gotta have it
Definition at line 60 of file Console.cpp.
| void Console::Render | ( | ) |
Override of the Renderable::Render function that actually draws the console, if necessary.
Definition at line 408 of file Console.cpp.
| void Console::Update | ( | float | dt | ) |
Oddly enough, doesn't do anything. All the changes happen at user input instead of in the update loop.
| dt |
Definition at line 395 of file Console.cpp.
| void Console::Enable | ( | bool | bEnable = true | ) |
Turns the console on (or off), which makes it get drawn in the render loop and steals keyboard input from the rest of the game.
| bEnable | If true, the Console is activate; if false, it's deactivated. |
Definition at line 108 of file Console.cpp.
| bool Console::IsEnabled | ( | ) | [inline] |
| bool Console::GetInput | ( | int | key | ) |
Adds the given key to the Console's current input string. Should only be called by the input handling functions.
| key | The numeric representation of the key |
Definition at line 122 of file Console.cpp.
| bool Console::GetSpecialInputDown | ( | int | key | ) |
Handles special input like Enter, Escape, arrow keys, etc. Again, this should only be called by the input handling functions.
| key | The numeric representation of the special key |
Definition at line 150 of file Console.cpp.
| void Console::ToggleConsole | ( | ) |
Switches the console from on to off, or from off to on.
Definition at line 375 of file Console.cpp.
| unsigned char Console::GetToggleConsoleKey | ( | ) | [inline] |
| void Console::WriteToOutput | ( | String | output | ) |
Writes a string to the log area of the console. Used internally by Console implementations to display the results of commands.
| output | The string to be appended to the log area. |
Definition at line 255 of file Console.cpp.
| void Console::SetPrompt | ( | const String & | prompt | ) |
Set the prompt characters that users will see at the beginning of their input line. Some consoles like to change this to reflect their current state.
| prompt | The new prompt string |
Definition at line 380 of file Console.cpp.
| const unsigned int Console::GetTabWidth | ( | ) |
Get the width of tabs when output to this console.
Definition at line 390 of file Console.cpp.
| void Console::SetTabWidth | ( | unsigned int | newTabWidth | ) |
Get the width of tabs when output to this console. Defaults to 8.
| newTabWidth | The desired tab width in spaces |
Definition at line 385 of file Console.cpp.
| void Console::AdvanceInputHistory | ( | int | byVal | ) |
Replaces the current input string with a value from the input history.
| byVal | The offset from the current history. Negative numbers will go back in the history, positive ones will go forward. |
Definition at line 347 of file Console.cpp.
| void Console::AcceptAutocomplete | ( | ) |
Replaces the input string with the current top auto-complete choice.
Definition at line 311 of file Console.cpp.
| virtual void Console::Execute | ( | String | input | ) | [pure virtual] |
Process the current input string, work whatever magic is appropriate.
Pure virtual function; must be implemented in the subclass.
| input | The string to process in the Console |
Implemented in TestConsole, and LuaConsole.
| virtual StringList Console::GetCompletions | ( | const String & | input | ) | [pure virtual] |
Gets a set of strings that are potential auto-complete matches for the current input.
Pure virtual function; must be implemented in the subclass.
| input | The input string to try and match. |
Implemented in TestConsole, and LuaConsole.


1.7.5.1