GuiCanvas Class Reference

#include <guiCanvas.h>

Inheritance diagram for GuiCanvas:

Inheritance graph
[legend]
List of all members.

Detailed Description

A canvas on which rendering occurs.

What a GUICanvas Can Contain...

Content Control

A content control is the top level GuiControl for a screen. This GuiControl will be the parent control for all other GuiControls on that particular screen.

Dialogs

A dialog is essentially another screen, only it gets overlaid on top of the current content control, and all input goes to the dialog. This is most akin to the "Open File" dialog box found in most operating systems. When you choose to open a file, and the "Open File" dialog pops up, you can no longer send input to the application, and must complete or cancel the open file request. Torque keeps track of layers of dialogs. The dialog with the highest layer is on top and will get all the input, unless the dialog is modeless, which is a profile option.

See also:
GuiControlProfile

Dirty Rectangles

The GuiCanvas is based on dirty regions.

Every frame the canvas paints only the areas of the canvas that are 'dirty' or need updating. In most cases, this only is the area under the mouse cursor. This is why if you look in guiCanvas.cc the call to glClear is commented out. If you want a really good idea of what exactly dirty regions are and how they work, un-comment that glClear line in the renderFrame method of guiCanvas.cc

What you will see is a black screen, except in the dirty regions, where the screen will be painted normally. If you are making an animated GuiControl you need to add your control to the dirty areas of the canvas.


Cursor commands

A cursor can be on, but not be shown. If a cursor is not on, than it does not process input.

virtual void setCursor (GuiCursor *cursor)
 Sets the cursor for the canvas.
virtual bool isCursorON ()
 Returns true if the cursor is on.
virtual void setForceMouseToGUI (bool onOff)
 Sets if mouse events should be passed to the GUI even if the cursor is off.
virtual void setClampTorqueCursor (bool onOff)
 Sets if the Torque cursor should be clamped to the window.
virtual bool getClampTorqueCursor ()
 Returns if the Torque cursor is clamped to the window.
virtual void setCursorON (bool onOff)
 Turns the cursor on or off.
virtual void setCursorPos (const Point2I &pt)
 Sets the position of the cursor.
virtual Point2I getCursorPos ()
 Returns the point, in screenspace, at which the cursor is located.
virtual void showCursor (bool state)
 Enable/disable rendering of the cursor.
virtual bool isCursorShown ()
 Returns true if the cursor is being rendered.
S32 mCursorChanged

Mouse Input

virtual bool processKeyboardEvent (InputEventInfo &inputEvent)
 Processes keyboard input events.
virtual bool processMouseEvent (InputEventInfo &inputEvent)
 Processes mouse input events.
virtual bool processGamepadEvent (InputEventInfo &inputEvent)
 Processes gamepad input events.
virtual void findMouseControl (const GuiEvent &event)
virtual void refreshMouseControl ()
SimObjectPtr< GuiControlmMouseCapturedControl
 All mouse events will go to this ctrl only.
SimObjectPtr< GuiControlmMouseControl
 the control the mouse was last seen in unless some other one captured it
bool mMouseControlClicked
 whether the current ctrl has been clicked - used by helpctrl
U32 mPrevMouseTime
 this determines how long the mouse has been in the same control
U32 mNextMouseTime
 used for onMouseRepeat()
U32 mInitialMouseDelay
 also used for onMouseRepeat()
bool mMouseButtonDown
 Flag to determine if the button is depressed.
bool mMouseRightButtonDown
 bool to determine if the right button is depressed
bool mMouseMiddleButtonDown
 Middle button flag.
GuiEvent mLastEvent
U8 mLastMouseClickCount
S32 mLastMouseDownTime
bool mLeftMouseLast
bool mMiddleMouseLast
bool mRightMouseLast
Point2F mMouseDownPoint

Public Member Functions

 DECLARE_CONOBJECT (GuiCanvas)
 GuiCanvas ()
virtual ~GuiCanvas ()
virtual bool onAdd ()
 Called when this object is added to the scene.
virtual void onRemove ()
 Called when this object is removed.
virtual void setRenderFront (bool front)
 This turns on/off front-buffer rendering.
Point2I getCursorExtent ()
 used by the tooltip resource
virtual Point2I getWindowSize ()
virtual void enableKeyboardTranslation ()
virtual void disableKeyboardTranslation ()
virtual void setWindowTitle (const char *newTitle)
Rendering methods
virtual void renderFrame (bool preRenderOnly, bool bufferSwap=true)
 Repaints the dirty regions of the canvas.
void updateReflections ()
 Updates various reflective materials in the scenegraph.
virtual void paint ()
 Repaints the entire canvas by calling resetUpdateRegions() and then renderFrame().
virtual void addUpdateRegion (Point2I pos, Point2I ext)
 Adds a dirty area to the canvas so it will be updated on the next frame.
virtual void resetUpdateRegions ()
 Resets the update regions so that the next call to renderFrame will repaint the whole canvas.
void maintainSizing ()
 Resizes the content control to match the canvas size.
virtual void buildUpdateUnion (RectI *updateUnion)
 This builds a rectangle which encompasses all of the dirty regions to be repainted.
virtual void swapBuffers ()
 This will swap the buffers at the end of renderFrame.
Canvas Content Management
virtual PlatformWindowgetPlatformWindow ()
 This returns the PlatformWindow owned by this Canvas.
virtual void setContentControl (GuiControl *gui)
 This sets the content control to something different.
virtual GuiControlgetContentControl ()
 Returns the content control.
virtual void pushDialogControl (GuiControl *gui, S32 layer=0)
 Adds a dialog control onto the stack of dialogs.
virtual void popDialogControl (S32 layer=0)
 Removes a specific layer of dialogs.
virtual void popDialogControl (GuiControl *gui)
 Removes a specific dialog control.
Input Processing
virtual bool processInputEvent (InputEventInfo &inputEvent)
 Processes an input event.
Mouse Methods
virtual void mouseLock (GuiControl *lockingControl)
 When a control gets the mouse lock this means that that control gets ALL mouse input and no other control recieves any input.
virtual void mouseUnlock (GuiControl *lockingControl)
 Unlocks the mouse from a control.
virtual GuiControlgetMouseControl ()
 Returns the control which the mouse is over.
virtual GuiControlgetMouseLockedControl ()
 Returns the control which the mouse is locked to if any.
virtual bool mouseButtonDown (void)
 Returns true if the left mouse button is down.
virtual bool mouseRightButtonDown (void)
 Returns true if the right mouse button is down.
virtual void checkLockMouseMove (const GuiEvent &event)
Mouse input methods
These events process the events before passing them down to the controls they effect. This allows for things such as the input locking and such.

Each of these methods corosponds to the action in it's method name and processes the GuiEvent passd as a parameter

virtual void rootMouseUp (const GuiEvent &event)
virtual void rootMouseDown (const GuiEvent &event)
virtual void rootMouseMove (const GuiEvent &event)
virtual void rootMouseDragged (const GuiEvent &event)
virtual void rootRightMouseDown (const GuiEvent &event)
virtual void rootRightMouseUp (const GuiEvent &event)
virtual void rootRightMouseDragged (const GuiEvent &event)
virtual void rootMiddleMouseDown (const GuiEvent &event)
virtual void rootMiddleMouseUp (const GuiEvent &event)
virtual void rootMiddleMouseDragged (const GuiEvent &event)
virtual void rootMouseWheelUp (const GuiEvent &event)
virtual void rootMouseWheelDown (const GuiEvent &event)
Keyboard input methods
First responders

A first responder is a the GuiControl which responds first to input events before passing them off for further processing.

virtual bool tabNext (void)
 Moves the first responder to the next tabable controle.
virtual bool tabPrev (void)
 Moves the first responder to the previous tabable control.
virtual void addAcceleratorKey (GuiControl *ctrl, U32 index, U32 keyCode, U32 modifier)
 Setups a keyboard accelerator which maps to a GuiControl.
virtual void setFirstResponder (GuiControl *firstResponder)
 Sets the first responder.
virtual void setNativeAcceleratorsEnabled (bool enabled)
 This is used to toggle processing of native OS accelerators, not to be confused with the Torque accelerator key system, to keep them from swallowing up keystrokes.

Static Public Member Functions

static void initPersistFields ()
 Register dynamic fields in a subclass of ConsoleObject.

Protected Types

typedef GuiControl Parent

Protected Member Functions

void handleResize (WindowId did, S32 width, S32 height)
void handleAppEvent (WindowId did, S32 event)
void handlePaintEvent (WindowId did)
virtual void setupFences ()

Static Protected Member Functions

static bool setProtectedNumFences (void *obj, const char *data)

Protected Attributes

PlatformWindowmPlatformWindow
GFXFence ** mFences
S32 mNextFenceIdx
S32 mNumFences
Rendering
RectI mOldUpdateRects [2]
RectI mCurUpdateRect
Cursor Properties
bool mCursorEnabled
bool mShowCursor
bool mRenderFront
Point2F mCursorPt
Point2I mLastCursorPt
GuiCursormDefaultCursor
GuiCursormLastCursor
bool mLastCursorEnabled
bool mForceMouseToGUI
bool mClampTorqueCursor
Keyboard Input
Vector< AccKeyMapmAcceleratorMap
U32 mHoverControlStart
GuiControlmHoverControl
Point2I mHoverPosition
bool mHoverPositionSet
U32 mHoverLeftControlTime

Static Private Attributes

static const U32 MAX_GAMEPADS = 4
 The maximum number of supported gamepads.

Classes

struct  AccKeyMap
 Accelerator key map. More...


Member Typedef Documentation

typedef GuiControl GuiCanvas::Parent [protected]

Reimplemented from GuiControl.


Constructor & Destructor Documentation

GuiCanvas::GuiCanvas (  ) 

virtual GuiCanvas::~GuiCanvas (  )  [virtual]


Member Function Documentation

virtual bool GuiCanvas::processKeyboardEvent ( InputEventInfo inputEvent  )  [protected, virtual]

Processes keyboard input events.

Helper method for processInputEvent

Parameters:
inputEvent Information on the input even to be processed.
Returns:
True if the event was handled or false if it was not.

virtual bool GuiCanvas::processMouseEvent ( InputEventInfo inputEvent  )  [protected, virtual]

Processes mouse input events.

Helper method for processInputEvent

Parameters:
inputEvent Information on the input even to be processed.
Returns:
True if the event was handled or false if it was not.

virtual bool GuiCanvas::processGamepadEvent ( InputEventInfo inputEvent  )  [protected, virtual]

Processes gamepad input events.

Helper method for processInputEvent

Parameters:
inputEvent Information on the input even to be processed.
Returns:
True if the event was handled or false if it was not.

virtual void GuiCanvas::findMouseControl ( const GuiEvent event  )  [protected, virtual]

virtual void GuiCanvas::refreshMouseControl (  )  [protected, virtual]

void GuiCanvas::handleResize ( WindowId  did,
S32  width,
S32  height 
) [protected]

void GuiCanvas::handleAppEvent ( WindowId  did,
S32  event 
) [protected]

void GuiCanvas::handlePaintEvent ( WindowId  did  )  [protected]

static bool GuiCanvas::setProtectedNumFences ( void obj,
const char *  data 
) [static, protected]

virtual void GuiCanvas::setupFences (  )  [protected, virtual]

GuiCanvas::DECLARE_CONOBJECT ( GuiCanvas   ) 

virtual bool GuiCanvas::onAdd (  )  [virtual]

Called when this object is added to the scene.

Reimplemented from GuiControl.

virtual void GuiCanvas::onRemove (  )  [virtual]

Called when this object is removed.

Reimplemented from GuiControl.

static void GuiCanvas::initPersistFields (  )  [static]

Register dynamic fields in a subclass of ConsoleObject.

See also:
addField(), addFieldV(), addDeprecatedField(), addGroup(), endGroup()

Reimplemented from GuiControl.

virtual void GuiCanvas::renderFrame ( bool  preRenderOnly,
bool  bufferSwap = true 
) [virtual]

Repaints the dirty regions of the canvas.

Parameters:
preRenderOnly If set to true, only the onPreRender methods of all the GuiControls will be called
bufferSwap If set to true, it will swap buffers at the end. This is to support canvas-subclassing.

void GuiCanvas::updateReflections (  ) 

Updates various reflective materials in the scenegraph.

virtual void GuiCanvas::paint (  )  [virtual]

Repaints the entire canvas by calling resetUpdateRegions() and then renderFrame().

virtual void GuiCanvas::addUpdateRegion ( Point2I  pos,
Point2I  ext 
) [virtual]

Adds a dirty area to the canvas so it will be updated on the next frame.

Parameters:
pos Screen-coordinates of the upper-left hand corner of the dirty area
ext Width/height of the dirty area

virtual void GuiCanvas::resetUpdateRegions (  )  [virtual]

Resets the update regions so that the next call to renderFrame will repaint the whole canvas.

void GuiCanvas::maintainSizing (  ) 

Resizes the content control to match the canvas size.

virtual void GuiCanvas::buildUpdateUnion ( RectI updateUnion  )  [virtual]

This builds a rectangle which encompasses all of the dirty regions to be repainted.

Parameters:
updateUnion (out) Rectangle which surrounds all dirty areas

virtual void GuiCanvas::swapBuffers (  )  [virtual]

This will swap the buffers at the end of renderFrame.

It was added for canvas sub-classes in case they wanted to do some custom code before the buffer flip occured.

virtual PlatformWindow* GuiCanvas::getPlatformWindow (  )  [inline, virtual]

This returns the PlatformWindow owned by this Canvas.

virtual void GuiCanvas::setContentControl ( GuiControl gui  )  [virtual]

This sets the content control to something different.

Parameters:
gui New content control

virtual GuiControl* GuiCanvas::getContentControl (  )  [virtual]

Returns the content control.

virtual void GuiCanvas::pushDialogControl ( GuiControl gui,
S32  layer = 0 
) [virtual]

Adds a dialog control onto the stack of dialogs.

Parameters:
gui Dialog to add
layer Layer to put dialog on

virtual void GuiCanvas::popDialogControl ( S32  layer = 0  )  [virtual]

Removes a specific layer of dialogs.

Parameters:
layer Layer to pop off from

virtual void GuiCanvas::popDialogControl ( GuiControl gui  )  [virtual]

Removes a specific dialog control.

Parameters:
gui Dialog to remove from the dialog stack

virtual void GuiCanvas::setRenderFront ( bool  front  )  [inline, virtual]

This turns on/off front-buffer rendering.

Parameters:
front True if all rendering should be done to the front buffer

virtual void GuiCanvas::setCursor ( GuiCursor cursor  )  [virtual]

Sets the cursor for the canvas.

Parameters:
cursor New cursor to use.

virtual bool GuiCanvas::isCursorON (  )  [inline, virtual]

Returns true if the cursor is on.

virtual void GuiCanvas::setForceMouseToGUI ( bool  onOff  )  [virtual]

Sets if mouse events should be passed to the GUI even if the cursor is off.

Parameters:
onOff True if events should be passed to the GUI if the cursor is off

virtual void GuiCanvas::setClampTorqueCursor ( bool  onOff  )  [virtual]

Sets if the Torque cursor should be clamped to the window.

Parameters:
onOff True if the Torque cursor should be clamped against the window

virtual bool GuiCanvas::getClampTorqueCursor (  )  [inline, virtual]

Returns if the Torque cursor is clamped to the window.

virtual void GuiCanvas::setCursorON ( bool  onOff  )  [virtual]

Turns the cursor on or off.

Parameters:
onOff True if the cursor should be on.

virtual void GuiCanvas::setCursorPos ( const Point2I pt  )  [virtual]

Sets the position of the cursor.

Parameters:
pt Point, in screenspace for the cursor

virtual Point2I GuiCanvas::getCursorPos (  )  [inline, virtual]

Returns the point, in screenspace, at which the cursor is located.

virtual void GuiCanvas::showCursor ( bool  state  )  [inline, virtual]

Enable/disable rendering of the cursor.

Parameters:
state True if we should render cursor

virtual bool GuiCanvas::isCursorShown (  )  [inline, virtual]

Returns true if the cursor is being rendered.

Point2I GuiCanvas::getCursorExtent (  )  [inline]

used by the tooltip resource

virtual bool GuiCanvas::processInputEvent ( InputEventInfo inputEvent  )  [virtual]

Processes an input event.

See also:
InputEvent
Parameters:
event Input event to process

Implements IProcessInput.

virtual void GuiCanvas::mouseLock ( GuiControl lockingControl  )  [virtual]

When a control gets the mouse lock this means that that control gets ALL mouse input and no other control recieves any input.

Parameters:
lockingControl Control to lock mouse to

Reimplemented from GuiControl.

virtual void GuiCanvas::mouseUnlock ( GuiControl lockingControl  )  [virtual]

Unlocks the mouse from a control.

Parameters:
lockingControl Control to unlock from

virtual GuiControl* GuiCanvas::getMouseControl (  )  [inline, virtual]

Returns the control which the mouse is over.

virtual GuiControl* GuiCanvas::getMouseLockedControl (  )  [inline, virtual]

Returns the control which the mouse is locked to if any.

virtual bool GuiCanvas::mouseButtonDown ( void   )  [inline, virtual]

Returns true if the left mouse button is down.

virtual bool GuiCanvas::mouseRightButtonDown ( void   )  [inline, virtual]

Returns true if the right mouse button is down.

virtual void GuiCanvas::checkLockMouseMove ( const GuiEvent event  )  [virtual]

virtual void GuiCanvas::rootMouseUp ( const GuiEvent event  )  [virtual]

virtual void GuiCanvas::rootMouseDown ( const GuiEvent event  )  [virtual]

virtual void GuiCanvas::rootMouseMove ( const GuiEvent event  )  [virtual]

virtual void GuiCanvas::rootMouseDragged ( const GuiEvent event  )  [virtual]

virtual void GuiCanvas::rootRightMouseDown ( const GuiEvent event  )  [virtual]

virtual void GuiCanvas::rootRightMouseUp ( const GuiEvent event  )  [virtual]

virtual void GuiCanvas::rootRightMouseDragged ( const GuiEvent event  )  [virtual]

virtual void GuiCanvas::rootMiddleMouseDown ( const GuiEvent event  )  [virtual]

virtual void GuiCanvas::rootMiddleMouseUp ( const GuiEvent event  )  [virtual]

virtual void GuiCanvas::rootMiddleMouseDragged ( const GuiEvent event  )  [virtual]

virtual void GuiCanvas::rootMouseWheelUp ( const GuiEvent event  )  [virtual]

virtual void GuiCanvas::rootMouseWheelDown ( const GuiEvent event  )  [virtual]

virtual bool GuiCanvas::tabNext ( void   )  [virtual]

Moves the first responder to the next tabable controle.

virtual bool GuiCanvas::tabPrev ( void   )  [virtual]

Moves the first responder to the previous tabable control.

virtual void GuiCanvas::addAcceleratorKey ( GuiControl ctrl,
U32  index,
U32  keyCode,
U32  modifier 
) [virtual]

Setups a keyboard accelerator which maps to a GuiControl.

Parameters:
ctrl GuiControl to map to.
index 
keyCode Key code.
modifier Shift, ctrl, etc.

virtual void GuiCanvas::setFirstResponder ( GuiControl firstResponder  )  [virtual]

Sets the first responder.

Parameters:
firstResponder Control to designate as first responder

Reimplemented from GuiControl.

virtual void GuiCanvas::setNativeAcceleratorsEnabled ( bool  enabled  )  [virtual]

This is used to toggle processing of native OS accelerators, not to be confused with the Torque accelerator key system, to keep them from swallowing up keystrokes.

Both GuiTextEditCtrl and GuiTextPadCtrl use this method.

virtual Point2I GuiCanvas::getWindowSize (  )  [virtual]

virtual void GuiCanvas::enableKeyboardTranslation (  )  [virtual]

virtual void GuiCanvas::disableKeyboardTranslation (  )  [virtual]

virtual void GuiCanvas::setWindowTitle ( const char *  newTitle  )  [virtual]


Member Data Documentation

All mouse events will go to this ctrl only.

the control the mouse was last seen in unless some other one captured it

whether the current ctrl has been clicked - used by helpctrl

this determines how long the mouse has been in the same control

used for onMouseRepeat()

also used for onMouseRepeat()

Flag to determine if the button is depressed.

bool to determine if the right button is depressed

Middle button flag.

const U32 GuiCanvas::MAX_GAMEPADS = 4 [static, private]

The maximum number of supported gamepads.