Support Forum       G3D Web Page     
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
G3D::GConsole Class Reference


Command-line console. More...

Inherits G3D::Widget.

Classes

class  Settings
 
class  Text
 

Public Types

typedef void(* Callback) (const string &, void *)
 
typedef String string
 To allow later change to std::wstring. More...
 

Public Member Functions

virtual ~GConsole ()
 
bool active () const
 
virtual Rect2D bounds () const override
 Inherited from Surface2D. More...
 
void clearBuffer ()
 Clear displayed text. More...
 
void clearHistory ()
 Clear command history. More...
 
virtual float depth () const override
 Inherited from Surface2D. More...
 
virtual void fireEvent (const GEvent &event)
 Fire an event on the containing window. More...
 
WidgetManagermanager () const
 
virtual void onAfterEvents ()
 Invoked after all onEvent handlers for the current frame and before onUserInput for any other Widget. More...
 
virtual void onAI () override
 
virtual void onBeforeGraphics ()
 Invoked by WidgetManager immediately before GApp::onGraphics runs. More...
 
virtual bool onEvent (const GEvent &event) override
 Pass all events to the console. More...
 
virtual void onNetwork () override
 
virtual void onPose (Array< shared_ptr< Surface > > &surfaceArray, Array< shared_ptr< Surface2D > > &surface2DArray)
 
Appends a posed model for this object to the array, if it has a graphic representation. More...
 
virtual void onPose (Array< shared_ptr< Surface > > &posedArray, Array< shared_ptr< Surface2D >> &posed2DArray) override
 
virtual void onSimulation (RealTime rdt, SimTime sdt, SimTime idt) override
 
virtual void onUserInput (UserInput *ui) override
 
void paste (const string &s)
 Insert the string as if it was typed at the command line. More...
 
virtual float positionalEventZ (const Point2 &pixel) const
 The camera-space z position that this Widget considers this pixel to be at. More...
 
void print (const string &s)
 
void printf (const char *fmt,...)
 Print to the buffer. More...
 
void render (RenderDevice *rd) const override
 Call to render the console. More...
 
void setActive (bool a)
 
void setCallback (Callback c, void *callbackData=nullptr)
 
virtual void setDepth (float d)
 Called by the WidgetManager. More...
 
virtual void setManager (WidgetManager *m)
 Called by the WidgetManager when this module is added to it. More...
 
void vprintf (const char *, va_list argPtr)
 Print to the buffer. More...
 
virtual OSWindowwindow () const
 Returns the operating system window that is currently rendering this Widget. More...
 

Static Public Member Functions

static GConsoleRef create (const shared_ptr< GFont > &f, const Settings &s=Settings(), Callback c=nullptr, void *callbackData=nullptr)
 
static void sort (Array< shared_ptr< Surface2D >> &array)
 Sorts from farthest to nearest. More...
 
static void sortAndRender (RenderDevice *rd, Array< shared_ptr< Surface2D >> &array)
 Calls sort, RenderDevice::push2D, and then render on all elements. More...
 

Public Attributes

Rect2D m_rect
 

Protected Member Functions

 GConsole (const shared_ptr< GFont > &f, const Settings &s, Callback c, void *callbackData)
 
virtual void addToCompletionHistory (const string &s)
 Parses the string and adds new tokens to the completion history. More...
 
void addTokenToCompletionHistory (const string &s)
 Only called from addToCompletionHistory. More...
 
void beginCompletion ()
 Called from processCompletion the first time TAB is pressed. More...
 
void completeCommand (int direction)
 Invoked from processRepeatKeysym to handle command completion keys. More...
 
void endCompletion ()
 Invoked from processRepeatKeysym when a non-completion key is pressed. More...
 
void generateFilenameCompletions (Array< string > &fcomplete)
 Called from beginCompletion to append filename and directory-based completions onto fcomplete. More...
 
void historySelect (int direction)
 Called from repeatKeysym on UP/DOWN. More...
 
void issueCommand ()
 Invoked when the user presses enter. More...
 
virtual void onCommand (const string &command)
 Invoked when the user presses enter. More...
 
virtual void print (const string &s, const Color4 &c)
 Issues text to the buffer. More...
 
void processRepeatKeysym ()
 Called from render and onEvent to enact the action triggered by the repeat key. More...
 
void setRepeatKeysym (GKeySym key)
 Called from onEvent when a key is pressed. More...
 
void unsetRepeatKeysym ()
 Called from onEvent when the repeat key is released. More...
 

Static Protected Member Functions

template<class T , class ... ArgTypes>
static shared_ptr< T > createShared (ArgTypes &&... args)
 Like std::make_shared, but works for protected constructors. More...
 

Protected Attributes

bool m_active
 True when the console is open and processing events. More...
 
Queue< Textm_buffer
 Previously displayed text. More...
 
int m_bufferShift
 Number of lines before the end of the buffer that are visible (affected by page up/page down). More...
 
Callback m_callback
 
void * m_callbackData
 
Array< stringm_completionArray
 Filled out by beginCompletion. More...
 
int m_completionArrayIndex
 Index of the current completion in the m_completionArray. More...
 
string m_completionBeginStr
 String to prepend onto the current completion list during scrolling. More...
 
string m_completionEndStr
 String to append onto the current completion list during scrolling. More...
 
Queue< stringm_completionHistory
 Buffer of identifiers to use for completions. More...
 
Set< stringm_completionHistorySet
 All the strings that are in m_completionHistory. More...
 
string m_currentLine
 Currently entered command. More...
 
int m_cursorPos
 Position of the cursor within m_currentLine (0 is the first slot) More...
 
float m_depth
 
shared_ptr< GFontm_font
 
Array< stringm_history
 Previously executed commands. More...
 
int m_historyIndex
 Current history line being retrieved when using UP/DOWN. More...
 
bool m_inCompletion
 True when we have already generated a list of potential completions and are now simply scrolling through them. More...
 
RealTime m_keyDownTime
 Time at which setRepeatKeysym was called. More...
 
RealTime m_keyRepeatTime
 Time at which the key will repeat (if down). More...
 
WidgetManagerm_manager
 The manager, set by setManager(). More...
 
GKeySym m_repeatKeysym
 Key that is currently auto-repeating. More...
 
bool m_resetHistoryIndexOnEnter
 When true, the history item has been modified since the last UP/DOWN. More...
 
Settings m_settings
 

Detailed Description


Command-line console.

When enter is pressed, onCommand is invoked. The default implementation calls the callback function; this allows you to add a command processor either by subclassing GConsole or by passing a function to the constructor.

Beta API

Future versions may support access to the constants for blink rate and key repeat, provide colored fonts and line wrapping.

Member Typedef Documentation

◆ Callback

typedef void(* G3D::GConsole::Callback) (const string &, void *)

◆ string

To allow later change to std::wstring.

Constructor & Destructor Documentation

◆ GConsole()

G3D::GConsole::GConsole ( const shared_ptr< GFont > &  f,
const Settings s,
Callback  c,
void *  callbackData 
)
protected

◆ ~GConsole()

virtual G3D::GConsole::~GConsole ( )
virtual

Member Function Documentation

◆ active()

bool G3D::GConsole::active ( ) const
inline

◆ addToCompletionHistory()

virtual void G3D::GConsole::addToCompletionHistory ( const string s)
protectedvirtual

Parses the string and adds new tokens to the completion history.

Called from issueCommand and print.

◆ addTokenToCompletionHistory()

void G3D::GConsole::addTokenToCompletionHistory ( const string s)
protected

Only called from addToCompletionHistory.

◆ beginCompletion()

void G3D::GConsole::beginCompletion ( )
protected

Called from processCompletion the first time TAB is pressed.

◆ bounds()

virtual Rect2D G3D::GConsole::bounds ( ) const
inlineoverridevirtual

Inherited from Surface2D.

Reimplemented from G3D::Widget.

◆ clearBuffer()

void G3D::GConsole::clearBuffer ( )

Clear displayed text.

◆ clearHistory()

void G3D::GConsole::clearHistory ( )

Clear command history.

◆ completeCommand()

void G3D::GConsole::completeCommand ( int  direction)
protected

Invoked from processRepeatKeysym to handle command completion keys.

◆ create()

static GConsoleRef G3D::GConsole::create ( const shared_ptr< GFont > &  f,
const Settings s = Settings(),
Callback  c = nullptr,
void *  callbackData = nullptr 
)
static

◆ createShared()

template<class T , class ... ArgTypes>
static shared_ptr<T> G3D::ReferenceCountedObject::createShared ( ArgTypes &&...  args)
inlinestaticprotectedinherited

Like std::make_shared, but works for protected constructors.

Call as createShared<myclass>.

◆ depth()

virtual float G3D::GConsole::depth ( ) const
inlineoverridevirtual

Inherited from Surface2D.

Controls the depth of objects when rendering. Subclasses may override this but it can interfere with the normal handling of rendering and event delivery. depth = 0 is usually the "top" widget and depth = 1 is usually the "bottom" widget.

Reimplemented from G3D::Widget.

◆ endCompletion()

void G3D::GConsole::endCompletion ( )
protected

Invoked from processRepeatKeysym when a non-completion key is pressed.

◆ fireEvent()

virtual void G3D::Widget::fireEvent ( const GEvent event)
virtualinherited

Fire an event on the containing window.

Reimplemented in G3D::WidgetManager.

◆ generateFilenameCompletions()

void G3D::GConsole::generateFilenameCompletions ( Array< string > &  fcomplete)
protected

Called from beginCompletion to append filename and directory-based completions onto fcomplete.

◆ historySelect()

void G3D::GConsole::historySelect ( int  direction)
protected

Called from repeatKeysym on UP/DOWN.

◆ issueCommand()

void G3D::GConsole::issueCommand ( )
protected

Invoked when the user presses enter.

◆ manager()

WidgetManager* G3D::Widget::manager ( ) const
inlineinherited

◆ onAfterEvents()

virtual void G3D::Widget::onAfterEvents ( )
inlinevirtualinherited

Invoked after all onEvent handlers for the current frame and before onUserInput for any other Widget.

Reimplemented in G3D::WidgetManager, and G3D::GameController.

◆ onAI()

virtual void G3D::GConsole::onAI ( )
overridevirtual

Reimplemented from G3D::Widget.

◆ onBeforeGraphics()

virtual void G3D::Widget::onBeforeGraphics ( )
inlinevirtualinherited

Invoked by WidgetManager immediately before GApp::onGraphics runs.

Reimplemented in G3D::WidgetManager, G3D::CallbackWidget, and G3D::XRWidget.

◆ onCommand()

virtual void G3D::GConsole::onCommand ( const string command)
protectedvirtual

Invoked when the user presses enter.

Default implementation calls m_callback.

◆ onEvent()

virtual bool G3D::GConsole::onEvent ( const GEvent event)
overridevirtual

Pass all events to the console.

It returns true if it processed (consumed) the event.

Reimplemented from G3D::Widget.

◆ onNetwork()

virtual void G3D::GConsole::onNetwork ( )
overridevirtual

Reimplemented from G3D::Widget.

◆ onPose() [1/2]

virtual void G3D::Widget::onPose ( Array< shared_ptr< Surface > > &  surfaceArray,
Array< shared_ptr< Surface2D > > &  surface2DArray 
)
inlinevirtualinherited


Appends a posed model for this object to the array, if it has a graphic representation.

The posed model appended is allowed to reference the agent and is allowed to mutate if the agent is mutated.

Reimplemented in G3D::GuiWindow, G3D::WidgetManager, G3D::Discovery::Client, G3D::SceneEditorWindow, G3D::CallbackWidget, G3D::FullScreenWidget, G3D::UprightSplineManipulator, and G3D::ControlPointEditor.

◆ onPose() [2/2]

virtual void G3D::GConsole::onPose ( Array< shared_ptr< Surface > > &  posedArray,
Array< shared_ptr< Surface2D >> &  posed2DArray 
)
overridevirtual

◆ onSimulation()

virtual void G3D::GConsole::onSimulation ( RealTime  rdt,
SimTime  sdt,
SimTime  idt 
)
overridevirtual

Reimplemented from G3D::Widget.

◆ onUserInput()

virtual void G3D::GConsole::onUserInput ( UserInput ui)
overridevirtual

Reimplemented from G3D::Widget.

◆ paste()

void G3D::GConsole::paste ( const string s)

Insert the string as if it was typed at the command line.

If the string contains newlines they will cause commands to issue.

◆ positionalEventZ()

virtual float G3D::Widget::positionalEventZ ( const Point2 pixel) const
inlinevirtualinherited

The camera-space z position that this Widget considers this pixel to be at.

Used for positional event (e.g., mouse click) delivery. Higher means closer.

Large negative values are far away. 0 is the closest 3D object. Values greater than zero are used for 2D objects. Returning fnan() [the default] requests the WidgetManager to set hte positionalEventZ to the object's normal event zorder.

See the implementation of ControlPointEditor::positionalEventZ for an example of how to use this with a 3D object.

Reimplemented in G3D::ControlPointEditor.

◆ print() [1/2]

virtual void G3D::GConsole::print ( const string s,
const Color4 c 
)
protectedvirtual

Issues text to the buffer.

◆ print() [2/2]

void G3D::GConsole::print ( const string s)

◆ printf()

void G3D::GConsole::printf ( const char *  fmt,
  ... 
)

Print to the buffer.

◆ processRepeatKeysym()

void G3D::GConsole::processRepeatKeysym ( )
protected

Called from render and onEvent to enact the action triggered by the repeat key.

◆ render()

void G3D::GConsole::render ( RenderDevice rd) const
overridevirtual

Call to render the console.

Reimplemented from G3D::Widget.

◆ setActive()

void G3D::GConsole::setActive ( bool  a)

◆ setCallback()

void G3D::GConsole::setCallback ( Callback  c,
void *  callbackData = nullptr 
)

◆ setDepth()

virtual void G3D::Widget::setDepth ( float  d)
inlinevirtualinherited

Called by the WidgetManager.

This is the depth that the Widget is expected to use when posed as a Surface2D. Subclasses may override or ignore this but it can interfere with the normal handling of rendering.

◆ setManager()

virtual void G3D::Widget::setManager ( WidgetManager m)
inlinevirtualinherited

◆ setRepeatKeysym()

void G3D::GConsole::setRepeatKeysym ( GKeySym  key)
protected

Called from onEvent when a key is pressed.

◆ sort()

static void G3D::Surface2D::sort ( Array< shared_ptr< Surface2D >> &  array)
staticinherited

Sorts from farthest to nearest.

◆ sortAndRender()

static void G3D::Surface2D::sortAndRender ( RenderDevice rd,
Array< shared_ptr< Surface2D >> &  array 
)
staticinherited

Calls sort, RenderDevice::push2D, and then render on all elements.

◆ unsetRepeatKeysym()

void G3D::GConsole::unsetRepeatKeysym ( )
protected

Called from onEvent when the repeat key is released.

◆ vprintf()

void G3D::GConsole::vprintf ( const char *  ,
va_list  argPtr 
)

Print to the buffer.

◆ window()

virtual OSWindow* G3D::Widget::window ( ) const
virtualinherited

Returns the operating system window that is currently rendering this Widget.

Reimplemented in G3D::WidgetManager.

Referenced by G3D::FullScreenWidget::bounds().

Member Data Documentation

◆ m_active

bool G3D::GConsole::m_active
protected

True when the console is open and processing events.

Referenced by active().

◆ m_buffer

Queue<Text> G3D::GConsole::m_buffer
protected

Previously displayed text.

◆ m_bufferShift

int G3D::GConsole::m_bufferShift
protected

Number of lines before the end of the buffer that are visible (affected by page up/page down).

◆ m_callback

Callback G3D::GConsole::m_callback
protected

◆ m_callbackData

void* G3D::GConsole::m_callbackData
protected

◆ m_completionArray

Array<string> G3D::GConsole::m_completionArray
protected

Filled out by beginCompletion.

◆ m_completionArrayIndex

int G3D::GConsole::m_completionArrayIndex
protected

Index of the current completion in the m_completionArray.

◆ m_completionBeginStr

string G3D::GConsole::m_completionBeginStr
protected

String to prepend onto the current completion list during scrolling.

◆ m_completionEndStr

string G3D::GConsole::m_completionEndStr
protected

String to append onto the current completion list during scrolling.

◆ m_completionHistory

Queue<string> G3D::GConsole::m_completionHistory
protected

Buffer of identifiers to use for completions.

Updated by print and by issueCommand.

◆ m_completionHistorySet

Set<string> G3D::GConsole::m_completionHistorySet
protected

All the strings that are in m_completionHistory.

◆ m_currentLine

string G3D::GConsole::m_currentLine
protected

Currently entered command.

◆ m_cursorPos

int G3D::GConsole::m_cursorPos
mutableprotected

Position of the cursor within m_currentLine (0 is the first slot)

◆ m_depth

float G3D::Widget::m_depth
protectedinherited

◆ m_font

shared_ptr<GFont> G3D::GConsole::m_font
protected

◆ m_history

Array<string> G3D::GConsole::m_history
protected

Previously executed commands.

◆ m_historyIndex

int G3D::GConsole::m_historyIndex
protected

Current history line being retrieved when using UP/DOWN.

When a history command is used unmodified, the history index sticks. Otherwise it resets to the end of the list on Enter.

◆ m_inCompletion

bool G3D::GConsole::m_inCompletion
protected

True when we have already generated a list of potential completions and are now simply scrolling through them.

◆ m_keyDownTime

RealTime G3D::GConsole::m_keyDownTime
mutableprotected

Time at which setRepeatKeysym was called.

◆ m_keyRepeatTime

RealTime G3D::GConsole::m_keyRepeatTime
mutableprotected

Time at which the key will repeat (if down).

◆ m_manager

WidgetManager* G3D::Widget::m_manager
protectedinherited

The manager, set by setManager().

This cannot be a reference counted pointer because that would create a cycle between the Widget and its manager.

Referenced by G3D::Widget::manager(), G3D::GuiWindow::manager(), G3D::Widget::setManager(), and G3D::GuiWindow::setVisible().

◆ m_rect

Rect2D G3D::GConsole::m_rect
mutable

Referenced by bounds().

◆ m_repeatKeysym

GKeySym G3D::GConsole::m_repeatKeysym
protected

Key that is currently auto-repeating.

◆ m_resetHistoryIndexOnEnter

bool G3D::GConsole::m_resetHistoryIndexOnEnter
protected

When true, the history item has been modified since the last UP/DOWN.

◆ m_settings

Settings G3D::GConsole::m_settings
protected

documentation generated on Wed Nov 24 2021 08:01:56 using doxygen 1.8.15