GuiCanvas

consoledoc.h

A canvas on which rendering occurs.

More...

Mouse Handling

bool

Deal with mouse buttons, even if the cursor is hidden.

Canvas Rendering

int

The number of GFX fences to use.

bool

Controls if the canvas window is rendered or not.

Public Functions

Point2I
clientToScreen(Point2I coordinate)

Translate a coordinate from canvas window-space to screen-space.

void
cursorClick(int buttonId, bool isDown)
void
cursorNudge(float x, float y)
void

Turns on the mouse off.

void

Turns on the mouse cursor.

int

Find the first monitor index that matches the given name.

int

Get the GuiControl which is being used as the content.

Point2I

Get the current position of the cursor in screen-space. Note that this position might be outside the Torque window. If you want to get the position within the Canvas, call screenToClient on the result.

Point2I

Returns the dimensions of the canvas.

string
getMode(int modeId)

Gets information on the specified mode of this device.

int

Gets the number of modes available on this device.

int

Gets the number of monitors attached to the system.

string
getMonitorDesktopMode(int monitorIndex)

Gets the current desktop mode for the selected monitor.

string
getMonitorMode(int monitorIndex, int modeIndex)

Gets a video mode string from the selected monitor.

int
getMonitorModeCount(int monitorIndex)

Gets the number of video modes available on the selected monitor.

string
getMonitorName(int index)

Gets the name of the requested monitor.

RectI
getMonitorRect(int index)

Gets the region of the requested monitor.

RectI

Use this function to get the usable desktop area represented by a display, with the primary display located at 0,0.

int

Gets the gui control under the mouse.

string

Gets the current screen mode as a string.

Point2I

Get the current position of the platform window associated with the canvas.

void

Disable rendering of the cursor.

void
bool

Determines if mouse cursor is enabled.

bool

Determines if mouse cursor is rendering.

bool

Is this canvas currently fullscreen?

bool
bool
void

maximize this canvas' window.

void

minimize this canvas' window.

void

Removes a dialog at the front most layer.

void

Removes a specific dialog control.

void

Removes the top most layer of dialogs.

void
popLayer(S32 layer)

Removes a specified layer of dialogs.

void
pushDialog(GuiControl ctrl, int layer, bool center)

Adds a dialog control onto the stack of dialogs.

void
renderFront(bool enable)

This turns on/off front-buffer rendering.

void
repaint(int elapsedMS)

Force canvas to redraw. If the elapsed time is greater than the time since the last paint then the repaint will be skipped.

void

Reset the update regions for the canvas.

void

restore this canvas' window.

Point2I
screenToClient(Point2I coordinate)

Translate a coordinate from screen-space to canvas window-space.

void

Set the content of the canvas to a specified control.

void

Sets the cursor for the canvas.

bool
setCursorPos(F32 posX, F32 posY)

Sets the position of the cursor.

bool
setCursorPos(Point2I pos)

Sets the position of the cursor.

void

Claim OS input focus for this canvas' window.

void

Translate a coordinate from canvas window-space to screen-space.

void
setVideoMode(uint width, uint height, bool fullscreen, uint bitDepth, uint refreshRate, uint antialiasLevel)

Change the video mode of this canvas. This method has the side effect of setting the $pref::Video::mode to the new values.

void
setWindowPosition(Point2I position)

Set the position of the platform window associated with the canvas.

void
setWindowTitle(string newTitle)

Change the title of the OS window.

void

Enable rendering of the cursor.

void
void

toggle canvas from fullscreen to windowed mode or back.

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.

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

Mouse Handling

bool alwaysHandleMouseButtons 

Deal with mouse buttons, even if the cursor is hidden.

Canvas Rendering

int numFences 

The number of GFX fences to use.

bool displayWindow 

Controls if the canvas window is rendered or not.

Public Functions

clientToScreen(Point2I coordinate)

Translate a coordinate from canvas window-space to screen-space.

Parameters:

coordinate

The coordinate in window-space.

return:

The given coordinate translated to screen-space.

cursorClick(int buttonId, bool isDown)

cursorNudge(float x, float y)

cursorOff()

Turns on the mouse off.

Canvas.cursorOff();

cursorOn()

Turns on the mouse cursor.

Canvas.cursorOn();

findFirstMatchingMonitor(string name)

Find the first monitor index that matches the given name.

The actual match algorithm depends on the implementation. Parameters:

name

The name to search for.

return:

The number of monitors attached to the system, including the default monoitor.

getContent()

Get the GuiControl which is being used as the content.

Canvas.getContent();

return:

ID of current content control

getCursorPos()

Get the current position of the cursor in screen-space. Note that this position might be outside the Torque window. If you want to get the position within the Canvas, call screenToClient on the result.

see:

Canvas::screenToClient()

Parameters:
param

Description

%cursorPos = Canvas.getCursorPos();

return:

Screen coordinates of mouse cursor, in format "X Y"

getExtent()

Returns the dimensions of the canvas.

%extent = Canvas.getExtent();

return:

Width and height of canvas. Formatted as numerical values in a single string "# #"

getMode(int modeId)

Gets information on the specified mode of this device.

Parameters:

modeId

Index of the mode to get data from.

return:

A video mode string given an adapter and mode index.

getModeCount()

Gets the number of modes available on this device.

Parameters:

param

Description

%modeCount = Canvas.getModeCount()

return:

The number of video modes supported by the device

getMonitorCount()

Gets the number of monitors attached to the system.

return:

The number of monitors attached to the system, including the default monoitor.

getMonitorDesktopMode(int monitorIndex)

Gets the current desktop mode for the selected monitor.

getMonitorMode(int monitorIndex, int modeIndex)

Gets a video mode string from the selected monitor.

getMonitorModeCount(int monitorIndex)

Gets the number of video modes available on the selected monitor.

getMonitorName(int index)

Gets the name of the requested monitor.

Parameters:

index

The monitor index.

return:

The name of the requested monitor.

getMonitorRect(int index)

Gets the region of the requested monitor.

Parameters:

index

The monitor index.

return:

The rectangular region of the requested monitor.

getMonitorUsableRect(int index)

Use this function to get the usable desktop area represented by a display, with the primary display located at 0,0.

This is the same area as Canvas.getMonitorRect() reports, but with portions reserved by the system removed. For example, on Apple Mac OS X, this subtracts the area occupied by the menu bar and dock. Setting a window to be fullscreen generally bypasses these unusable areas, so these are good guidelines for the maximum space available to a non - fullscreen window.Parameters:

index

The monitor index.

return:

The rectangular region of the requested monitor.

getMouseControl()

Gets the gui control under the mouse.

%underMouse = Canvas.getMouseControl();

return:

ID of the gui control, if one was found. NULL otherwise

getVideoMode()

Gets the current screen mode as a string.

The return string will contain 5 values (width, height, fullscreen, bitdepth, refreshRate). You will need to parse out each one for individual use.

%screenWidth = getWord(Canvas.getVideoMode(), 0);
%screenHeight = getWord(Canvas.getVideoMode(), 1);
%isFullscreen = getWord(Canvas.getVideoMode(), 2);
%bitdepth = getWord(Canvas.getVideoMode(), 3);
%refreshRate = getWord(Canvas.getVideoMode(), 4);

return:

String formatted with screen width, screen height, screen mode, bit depth, and refresh rate.

getWindowPosition()

Get the current position of the platform window associated with the canvas.

return:

The window position of the canvas in screen-space.

hideCursor()

Disable rendering of the cursor.

Canvas.hideCursor();

hideWindow()

isCursorOn()

Determines if mouse cursor is enabled.

// Is cursor on?
if(Canvas.isCursorOn())
  echo("Canvas cursor is on");

return:

Returns true if the cursor is on.

isCursorShown()

Determines if mouse cursor is rendering.

// Is cursor rendering?
if(Canvas.isCursorShown())
  echo("Canvas cursor is rendering");

return:

Returns true if the cursor is rendering.

isFullscreen()

Is this canvas currently fullscreen?

isMaximized()

isMinimized()

maximizeWindow()

maximize this canvas' window.

minimizeWindow()

minimize this canvas' window.

popDialog()

Removes a dialog at the front most layer.

// Pops whatever is on layer 0
Canvas.popDialog();

popDialog(GuiControl ctrl)

Removes a specific dialog control.

Parameters:

ctrl

Dialog to pop

Canvas.popDialog(RecordingsDlg);

popLayer()

Removes the top most layer of dialogs.

Canvas.popLayer();

popLayer(S32 layer)

Removes a specified layer of dialogs.

Parameters:

layer

Number of the layer to pop

Canvas.popLayer(1);

pushDialog(GuiControl ctrl, int layer, bool center)

Adds a dialog control onto the stack of dialogs.

Parameters:

ctrl

Dialog to add

layer

Layer to put dialog on (optional)

center

True to center dialog on canvas (optional)

Canvas.pushDialog(RecordingsDlg);

renderFront(bool enable)

This turns on/off front-buffer rendering.

Parameters:

enable

True if all rendering should be done to the front buffer

Canvas.renderFront(false);

repaint(int elapsedMS)

Force canvas to redraw. If the elapsed time is greater than the time since the last paint then the repaint will be skipped.

Parameters:

elapsedMS

The optional elapsed time in milliseconds.

Canvas.repaint();

reset()

Reset the update regions for the canvas.

Canvas.reset();

resetVideoMode()

restoreWindow()

restore this canvas' window.

screenToClient(Point2I coordinate)

Translate a coordinate from screen-space to canvas window-space.

Parameters:

coordinate

The coordinate in screen-space.

return:

The given coordinate translated to window-space.

setContent(GuiControl ctrl)

Set the content of the canvas to a specified control.

Parameters:

ctrl

ID or name of GuiControl to set content to

Canvas.setContent(PlayGui);

setCursor(GuiCursor cursor)

Sets the cursor for the canvas.

Parameters:

cursor

Name of the GuiCursor to use

Canvas.setCursor("DefaultCursor");

setCursorPos(F32 posX, F32 posY)

Sets the position of the cursor.

Parameters:

posX

X-coordinate, in screenspace for the cursor.

posY

Y-coordinate, in screenspace for the cursor.

Canvas.setCursorPos(0,0);

setCursorPos(Point2I pos)

Sets the position of the cursor.

Parameters:

pos

Point, in screenspace for the cursor. Formatted as ("x y")

Canvas.setCursorPos("0 0");

setFocus()

Claim OS input focus for this canvas' window.

setMenuBar(GuiControl menu)

Translate a coordinate from canvas window-space to screen-space.

Parameters:

coordinate

The coordinate in window-space.

return:

The given coordinate translated to screen-space.

setVideoMode(uint width, uint height, bool fullscreen, uint bitDepth, uint refreshRate, uint antialiasLevel)

Change the video mode of this canvas. This method has the side effect of setting the $pref::Video::mode to the new values.

Parameters:

width

The screen width to set.

height

The screen height to set.

fullscreen

Specify true to run fullscreen or false to run in a window

bitDepth

[optional] The desired bit-depth. Defaults to the current setting. This parameter is ignored if you are running in a window.

refreshRate

[optional] The desired refresh rate. Defaults to the current setting. This parameter is ignored if you are running in a window

antialiasLevel

[optional] The level of anti-aliasing to apply 0 = none

setWindowPosition(Point2I position)

Set the position of the platform window associated with the canvas.

Parameters:

position

The new position of the window in screen-space.

setWindowTitle(string newTitle)

Change the title of the OS window.

Parameters:

newTitle

String containing the new name

Canvas.setWindowTitle("Documentation Rocks!");

showCursor()

Enable rendering of the cursor.

Canvas.showCursor();

showWindow()

toggleFullscreen()

toggle canvas from fullscreen to windowed mode or back.

// If we are in windowed mode, the following will put is in fullscreen
Canvas.toggleFullscreen();