Angel 3.2
A 2D Game Prototyping Engine
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Console Class Referenceabstract

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
 

Detailed Description

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.

Definition at line 55 of file Console.h.

Constructor & Destructor Documentation

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.

Member Function Documentation

void Console::Render ( )

Override of the Renderable::Render function that actually draws the console, if necessary.

Definition at line 399 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.

Parameters
dt

Definition at line 386 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.

Parameters
bEnableIf true, the Console is activate; if false, it's deactivated.

Definition at line 108 of file Console.cpp.

bool Console::IsEnabled ( )
inline

Whether the Console is currently being displayed and accepting input right now.

Returns
True if it's enabled, false if it's not

Definition at line 96 of file Console.h.

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.

Parameters
keyThe numeric representation of the key
Returns
Whether or not the key was added to the input string (false if the Console is currently disabled or that was the key which toggled it.)

Definition at line 113 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.

Parameters
keyThe numeric representation of the special key
Returns
Whether or not the input was accepted by the Console (false if the Console is currently disabled.)

Definition at line 141 of file Console.cpp.

void Console::ToggleConsole ( )

Switches the console from on to off, or from off to on.

Definition at line 366 of file Console.cpp.

unsigned char Console::GetToggleConsoleKey ( )
inline

Lets you know what key is set to toggle the Console. (Hard-coded to '`' at the moment.)

Returns
The toggle console key

Definition at line 129 of file Console.h.

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.

Parameters
outputThe string to be appended to the log area.

Definition at line 246 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.

Parameters
promptThe new prompt string

Definition at line 371 of file Console.cpp.

const unsigned int Console::GetTabWidth ( )

Get the width of tabs when output to this console.

Definition at line 381 of file Console.cpp.

void Console::SetTabWidth ( unsigned int  newTabWidth)

Get the width of tabs when output to this console. Defaults to 8.

Parameters
newTabWidthThe desired tab width in spaces

Definition at line 376 of file Console.cpp.

void Console::AdvanceInputHistory ( int  byVal)

Replaces the current input string with a value from the input history.

Parameters
byValThe offset from the current history. Negative numbers will go back in the history, positive ones will go forward.

Definition at line 338 of file Console.cpp.

void Console::AcceptAutocomplete ( )

Replaces the input string with the current top auto-complete choice.

Definition at line 302 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.

Parameters
inputThe 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.

Parameters
inputThe input string to try and match.
Returns
The list of potential matches

Implemented in TestConsole, and LuaConsole.


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