MGUI::CANVAS Class Reference

Generic 'canvas' control supporting drawing and simple user input. More...

#include <mgui/canvas.h>

Inheritance diagram for MGUI::CANVAS:
Inheritance graph
[legend]

List of all members.

Public Types

typedef
fastdelegate::FastDelegate
< bool(MGUI::POINT,
MGUI::KEYCODE, MGUI::KEYSTATE)> 
DELEGATE_ONKEY
typedef
fastdelegate::FastDelegate
< void(MGD::CONTEXT *) 
DELEGATE_ONPAINT )
typedef
fastdelegate::FastDelegate
< bool(MGUI::POINT,
MGUI::POINTERBUTTON,
MGUI::KEYSTATE)> 
DELEGATE_ONPOINTER
typedef
fastdelegate::FastDelegate
< bool(MGUI::POINT,
MGUI::POINTERBUTTON,
MGUI::KEYSTATE, bool)> 
DELEGATE_ONPOINTERMOVE
typedef
fastdelegate::FastDelegate
< void(const LRECT2D &)> 
DELEGATE_ONUPDATERECT
typedef
fastdelegate::FastDelegate
< void(INT32)> 
DELEGATE_ONWHEEL
enum  DEVICETYPE { DEVICETYPE_Screen, DEVICETYPE_Pixmap, DEVICETYPE_Memory, DEVICETYPE_Stereo }
enum  STYLE {
  STYLE_Default = 0x00, STYLE_UsePixmap = 0x01, STYLE_UseMemory = 0x02, STYLE_NoBuffer = 0x04,
  STYLE_NoDelayResize = 0x08, STYLE_NotifyExpose = 0x10, STYLE_TraverseToOnPointerEnter = 0x20
}

Public Member Functions

 CANVAS (STYLE style=STYLE_Default)
virtual ~CANVAS ()
void AddDelegateOnPointerButtonDown (POINTERBUTTON buttons, DELEGATE_ONPOINTER delegate)
void AddDelegateOnPointerButtonUp (POINTERBUTTON buttons, DELEGATE_ONPOINTER delegate)
void Create (LAYOUT_PANE_BASE &ParentPane, int width, int height, LAYOUT_SIZEALIGN sizealign, CANVAS::STYLE style=STYLE_Default)
void CursorSetVisible (bool visible)
void Erase (const COLOR &color)
CURSORID GetCursor () const
MDLGPARENT GetDlgParent () const
MGD::CONTEXTGetDrawingContext (DEVICETYPE DeviceType, STEREOVIEW StereoView=STEREOVIEW_None) const
MGD::DEVICEGetDrawingDevice (DEVICETYPE DeviceType, bool AllowStereo)
MGD::DEVICEGetDrawingDevice (DEVICETYPE DeviceType=DEVICETYPE_Memory)
INT16 GetHeight () const
bool GetPointerLocation (MGUI::POINT &ptCanvas) const
void GetSize (INT16 &width, INT16 &height) const
STYLE GetStyle () const
INT16 GetWidth () const
bool IsPointerCaptured () const
void PanFromBuffer (INT32 dx, INT32 dy, const COLOR *pColorBG)
void ReleaseCapture ()
void Resize (INT16 width, INT16 height)
void RestoreFromBuffer (DEVICETYPE devtype, const LRECT2D &rect, bool UpdateNow=false)
void RestoreFromBuffer (DEVICETYPE devtype, bool UpdateNow=false)
void SetCursor (CURSORID cursorid)
void SetDelegateOnKey (DELEGATE_ONKEY delegate)
void SetDelegateOnPaint (DELEGATE_ONPAINT delegate)
void SetDelegateOnPointerDoubleClick (DELEGATE_ONPOINTER delegate)
void SetDelegateOnPointerEnter (DELEGATE_VOID_NOPARMS delegate)
void SetDelegateOnPointerLeave (DELEGATE_VOID_NOPARMS delegate)
void SetDelegateOnPointerMove (DELEGATE_ONPOINTERMOVE delegate)
void SetDelegateOnPointerWheel (DELEGATE_ONWHEEL delegate)
void SetDelegateOnSize (DELEGATE_ONSIZE delegate)
void SetDelegateOnUpdatePixmap (DELEGATE_ONUPDATERECT delegate)
void StereoDisable ()
void StereoDrawCursor (MGUI::POINT ptCanvasL, MGUI::POINT ptCanvasR, LRECT2D &CursorRectL, LRECT2D &CursorRectR)
void StereoEnable (const STEREODEVICE &StereoDevice)
const STEREODEVICEStereoGetDeviceHW () const
bool StereoIsEnabled () const
void StereoUpdateFromBuffer ()
void UpdateFromBuffer (DEVICETYPE DevTarget, DEVICETYPE DevSource, const LRECT2D *pRectSource=0)

Protected Member Functions

virtual void v_OnCaptureChanged ()
virtual bool v_OnKey (MGUI::POINT point, MGUI::KEYCODE keycode, MGUI::KEYSTATE keystate)
virtual void v_OnPaint (MGD::CONTEXT *gc)
virtual void v_OnPointerButtonDown (MGUI::POINT point, POINTERBUTTON button, KEYSTATE keystate)
virtual void v_OnPointerButtonUp (MGUI::POINT point, POINTERBUTTON button, KEYSTATE keystate)
virtual void v_OnPointerEnter ()
virtual void v_OnPointerLeave ()
virtual void v_OnPointerMove (MGUI::POINT point, POINTERBUTTON button, KEYSTATE keystate, bool hasmore)
virtual void v_OnPointerWheel (INT32 direction)
virtual void v_OnSize (int width, int height)

Private Member Functions

virtual void v_OnUpdatePixmap (const LRECT2D &rect)

Detailed Description

Generic 'canvas' control supporting drawing and simple user input.


Member Typedef Documentation

typedef fastdelegate::FastDelegate<bool(MGUI::POINT,MGUI::KEYCODE,MGUI::KEYSTATE)> MGUI::CANVAS::DELEGATE_ONKEY
typedef fastdelegate::FastDelegate<void(MGD::CONTEXT*) MGUI::CANVAS::DELEGATE_ONPAINT)
typedef fastdelegate::FastDelegate<void(const LRECT2D&)> MGUI::CANVAS::DELEGATE_ONUPDATERECT
typedef fastdelegate::FastDelegate<void(INT32)> MGUI::CANVAS::DELEGATE_ONWHEEL

Member Enumeration Documentation

Enumerator:
DEVICETYPE_Screen 

Screen device associated with canvas window.

DEVICETYPE_Pixmap 

Pixmap buffer, set as background for window.

DEVICETYPE_Memory 

Memory buffer device, size will match canvas window.

DEVICETYPE_Stereo 

Stereo buffer, will have 2 frame buffers.

Enumerator:
STYLE_Default 
STYLE_UsePixmap 

Use "background pixmap" for off-screen buffering.

STYLE_UseMemory 

Use "memory" for off-screen buffering.

STYLE_NoBuffer 

Don't use buffer unless specifically requested via STYLE_UsePixmap or STYLE_UseMemory.

STYLE_NoDelayResize 

Don't use delayed notification of resize.

STYLE_NotifyExpose 

Notify via v_OnPaint when area exposed for redrawing (automatic if using delegate).

STYLE_TraverseToOnPointerEnter 

Traverse (make input for keypress) when pointer enters canvas.

Reimplemented in MGUI::CTRL_ANGLE, and MGUI::CTRL_MAGNIFIER.


Constructor & Destructor Documentation

MGUI::CANVAS::CANVAS ( STYLE  style = STYLE_Default  ) 

Constructor.

virtual MGUI::CANVAS::~CANVAS (  )  [virtual]

Destructor.


Member Function Documentation

void MGUI::CANVAS::AddDelegateOnPointerButtonDown ( POINTERBUTTON  buttons,
DELEGATE_ONPOINTER  delegate 
)

Add delegate to call when pointer button pressed.

The delegate gets passed the same parameters as v_OnPointerButtonDown(). Delegate must return 'true' if it processed the message, false to continue processing.

Parameters:
buttons Button(s) for which to call delegate
delegate Delegate to call
void MGUI::CANVAS::AddDelegateOnPointerButtonUp ( POINTERBUTTON  buttons,
DELEGATE_ONPOINTER  delegate 
)

Add delegate to call when pointer button released.

The delegate gets passed the same parameters as v_OnPointerButtonUp(). Delegate must return 'true' if it processed the message, false to continue processing.

Parameters:
buttons Button(s) for which to call delegate
delegate Delegate to call
void MGUI::CANVAS::Create ( LAYOUT_PANE_BASE ParentPane,
int  width,
int  height,
LAYOUT_SIZEALIGN  sizealign,
CANVAS::STYLE  style = STYLE_Default 
)

Create canvas control.

Parameters:
ParentPane Parent pane
width Desired width in pixels
height Desired height in pixels
sizealign Sizing and alignment options
void MGUI::CANVAS::CursorSetVisible ( bool  visible  ) 

Set cursor visibility.

Parameters:
visible Whether visible or not
void MGUI::CANVAS::Erase ( const COLOR color  ) 

Erase canvas to specified color.

Parameters:
color Color to erase to
CURSORID MGUI::CANVAS::GetCursor (  )  const

Get current cursor ID.

MDLGPARENT MGUI::CANVAS::GetDlgParent (  )  const

Get suitable parent for dialog launched from canvas.

Reimplemented from MGUI::CTRL.

MGD::CONTEXT* MGUI::CANVAS::GetDrawingContext ( DEVICETYPE  DeviceType,
STEREOVIEW  StereoView = STEREOVIEW_None 
) const

Get shared drawing context.

Returns:
Drawing Context, do not delete as is internal to CANVAS. Typically used for graphic tools and overlays. Copy of pointer should not be retained as it may become invalid based on user action or use of StereoDisable/Enable.
Parameters:
StereoView Stereo view, ignored unless stereo enabled
MGD::DEVICE* MGUI::CANVAS::GetDrawingDevice ( DEVICETYPE  DeviceType,
bool  AllowStereo 
)

Get drawing device for buffer or direct display with control over whether to allow stereo.

Do not delete the returned DEVICE as it is internal to the CANVAS.

Parameters:
DeviceType Drawing device type
AllowStereo Whether to allow stereo left/right frames (if supported)
MGD::DEVICE* MGUI::CANVAS::GetDrawingDevice ( DEVICETYPE  DeviceType = DEVICETYPE_Memory  ) 

Get drawing device for buffer or direct display.

Do not delete the returned DEVICE as it is internal to the CANVAS.

Parameters:
DeviceType Drawing device type
INT16 MGUI::CANVAS::GetHeight (  )  const

Get height of canvas in pixels.

bool MGUI::CANVAS::GetPointerLocation ( MGUI::POINT ptCanvas  )  const

Get current pointer location relative to canvas.

Returns:
'true' if within canvas extent, 'false' if not. If returns false, ptCanvas will have coordinates of INT16_MIN if could not determine location at all.
Parameters:
ptCanvas Location relative to canvas returned
void MGUI::CANVAS::GetSize ( INT16 width,
INT16 height 
) const

Get dimensions of canvas.

Parameters:
width Width in pixels returned
height Height in pixels returned
STYLE MGUI::CANVAS::GetStyle (  )  const

Get canvas style flags.

INT16 MGUI::CANVAS::GetWidth (  )  const

Get width of canvas in pixels.

bool MGUI::CANVAS::IsPointerCaptured (  )  const

Determine if pointer is "captured" by this canvas.

void MGUI::CANVAS::PanFromBuffer ( INT32  dx,
INT32  dy,
const COLOR pColorBG 
)

Pan view by specified amount by copying from background buffer.

Will update screen display.

Parameters:
dx X offset in pixels
dy Y offset in pixels
pColorBG Color to fill portions where no data available to copy
void MGUI::CANVAS::ReleaseCapture (  ) 

Release capture on pointer.

Use with care, typically used if buttonpress pops up a menu.

void MGUI::CANVAS::Resize ( INT16  width,
INT16  height 
)

Resize canvas.

Parameters:
width New width requested
height New height requested
void MGUI::CANVAS::RestoreFromBuffer ( DEVICETYPE  devtype,
const LRECT2D rect,
bool  UpdateNow = false 
)

Restore portion of canvas from specific off-screen buffer.

Will generate OnPaint notifications if STYLE_NotifyExpose was specified in constructor or Create. Note that if DEVICETYPE_Stereo is specified the actual area(s) restored may differ from the specified rectangle.

Parameters:
devtype Buffer device type
rect Portion of canvas to restore
UpdateNow Perform immediate update before returning
void MGUI::CANVAS::RestoreFromBuffer ( DEVICETYPE  devtype,
bool  UpdateNow = false 
)

Restore entire canvas from specific off-screen buffer.

Will generate OnPaint notifications if STYLE_NotifyExpose was specified in constructor or Create.

Parameters:
devtype Buffer device type
UpdateNow Perform immediate update before returning
void MGUI::CANVAS::SetCursor ( CURSORID  cursorid  ) 

Set pointer cursor to show while in canvas.

void MGUI::CANVAS::SetDelegateOnKey ( DELEGATE_ONKEY  delegate  ) 

Set delegate to call when key "pressed".

Delegate should

Returns:
'true' if key handled, 'false' if not. The delegate gets passed the same parameters as v_OnKey()
void MGUI::CANVAS::SetDelegateOnPaint ( DELEGATE_ONPAINT  delegate  ) 

Set delegate to call when canvas needs to be redrawn.

This delegate is called after the buffer is updated to the screen. If no overlay and not unbuffered then this delegate does not need to be set. The delegate gets passed the same parameters as v_OnPaint()

void MGUI::CANVAS::SetDelegateOnPointerDoubleClick ( DELEGATE_ONPOINTER  delegate  ) 

Set delegate to call for double-click on any button.

void MGUI::CANVAS::SetDelegateOnPointerEnter ( DELEGATE_VOID_NOPARMS  delegate  ) 

Set delegate to call when pointer enters canvas area.

void MGUI::CANVAS::SetDelegateOnPointerLeave ( DELEGATE_VOID_NOPARMS  delegate  ) 

Set delegate to call when pointer leaves canvas area.

void MGUI::CANVAS::SetDelegateOnPointerMove ( DELEGATE_ONPOINTERMOVE  delegate  ) 

Set delegate to call when pointer is moved.

The delegate gets passed the same parameters as v_OnPointerMove()

void MGUI::CANVAS::SetDelegateOnPointerWheel ( DELEGATE_ONWHEEL  delegate  ) 

Set delegate to call when the user scrolls the pointer wheel.

The delegate is passed an integer parameter which will be positive if the wheel was scrolled up and negative if scrolled down.

void MGUI::CANVAS::SetDelegateOnSize ( DELEGATE_ONSIZE  delegate  ) 

Set delegate to call when canvas size changes.

Note, this is NOT called repeatedly while the user resizes the window, but instead will be called after the user releases the pointer or pauses for a nominal period of time (.5 second). The delegate gets passed the same parameters as v_OnSize()

void MGUI::CANVAS::SetDelegateOnUpdatePixmap ( DELEGATE_ONUPDATERECT  delegate  ) 

Set delegate to call when Pixmap updated from Memory buffer.

Only applies if both STYLE_UsePixmap and STYLE_UseMemory specified in construction/creation.

void MGUI::CANVAS::StereoDisable (  ) 

Disable stereo buffering.

void MGUI::CANVAS::StereoDrawCursor ( MGUI::POINT  ptCanvasL,
MGUI::POINT  ptCanvasR,
LRECT2D CursorRectL,
LRECT2D CursorRectR 
)

Draw stereo cursor using specified left/right points.

Parameters:
ptCanvasL Left canvas coordinate
ptCanvasR Right canvas coordinate
CursorRectL Left rectangle returned
CursorRectR Right rectangle returned
void MGUI::CANVAS::StereoEnable ( const STEREODEVICE StereoDevice  ) 

Enable stereo buffering.

Parameters:
StereoDevice Stereo device hardware description
const STEREODEVICE* MGUI::CANVAS::StereoGetDeviceHW (  )  const

Get stereo device hardware description.

Returns:
pointer to hardware description, NULL if not available (ie, disabled).
bool MGUI::CANVAS::StereoIsEnabled (  )  const

Determine if stereo buffering is enabled.

void MGUI::CANVAS::StereoUpdateFromBuffer (  ) 

Update buffer/screen from stereo buffer if enabled and available.

void MGUI::CANVAS::UpdateFromBuffer ( DEVICETYPE  DevTarget,
DEVICETYPE  DevSource,
const LRECT2D pRectSource = 0 
)

Update specified target device buffer from specified source buffer.

Parameters:
DevTarget Target device type to update to
DevSource Source device type to update from
pRectSource Rectangle in source buffer, NULL for entire extent
virtual void MGUI::CANVAS::v_OnCaptureChanged (  )  [protected, virtual]

Called when cursor "capture" is changed (lost).

Default implementation calls the delegate.

Reimplemented in MGUI::TOOLCANVAS.

virtual bool MGUI::CANVAS::v_OnKey ( MGUI::POINT  point,
MGUI::KEYCODE  keycode,
MGUI::KEYSTATE  keystate 
) [protected, virtual]

Called when key "pressed".

Override must call base for proper behavior if does not handle key itself.

Returns:
'true' if key handled, 'false' if not. Default implementation calls the delegate.
Parameters:
point Point in canvas coordinates where button event occurred
keycode Processed key code, equivalent to MIUNICODE for alphanumeric keys.
keystate Modifier key state

Reimplemented in MGUI::TOOLCANVAS.

virtual void MGUI::CANVAS::v_OnPaint ( MGD::CONTEXT gc  )  [protected, virtual]

Called when canvas needs to be redrawn, do not call directly except from derived implementation.

Override must call base for proper behavior. This is called after the buffer is updated to the screen. If no overlay and not unbuffered then this method does not need to be overridden. Default implementation calls the delegate.

Parameters:
gc Drawing context for unbuffered/overlay.

Reimplemented in MGUI::TOOLCANVAS.

virtual void MGUI::CANVAS::v_OnPointerButtonDown ( MGUI::POINT  point,
POINTERBUTTON  button,
KEYSTATE  keystate 
) [protected, virtual]

Called when pointer button pressed.

Override must call base for proper behavior if it does not handle the button itself. Default implementation calls the delegate(s) associated with the button.

Parameters:
point Point in canvas coordinates where button event occurred
button Button that was pressed
keystate Modifier key state at time of event

Reimplemented in MGUI::TOOLCANVAS.

virtual void MGUI::CANVAS::v_OnPointerButtonUp ( MGUI::POINT  point,
POINTERBUTTON  button,
KEYSTATE  keystate 
) [protected, virtual]

Called when pointer button released.

Return 'true' if it processed the message, false to continue processing. Default implementation calls the delegate(s) associated with the button.

Parameters:
point Point in canvas coordinates where button event occurred
button Button that was released
keystate Modifier key state at time of original button press

Reimplemented in MGUI::TOOLCANVAS.

virtual void MGUI::CANVAS::v_OnPointerEnter (  )  [protected, virtual]

Called when pointer enters canvas area.

Override must call base for proper behavior. Default implementation calls the delegate.

Reimplemented in MGUI::TOOLCANVAS.

virtual void MGUI::CANVAS::v_OnPointerLeave (  )  [protected, virtual]

Called when pointer leaves canvas area.

Override must call base for proper behavior. Default implementation calls the delegate.

Reimplemented in MGUI::TOOLCANVAS.

virtual void MGUI::CANVAS::v_OnPointerMove ( MGUI::POINT  point,
POINTERBUTTON  button,
KEYSTATE  keystate,
bool  hasmore 
) [protected, virtual]

Called when pointer cursor is moved.

Override must call base for proper behavior. Default implementation calls the delegate.

Parameters:
point Point in canvas coordinates where button event occurred
button Current button state
keystate Modifier key state at time of event
hasmore Indicates whether more "move" events follow with same button/key state

Reimplemented in MGUI::TOOLCANVAS.

virtual void MGUI::CANVAS::v_OnPointerWheel ( INT32  direction  )  [protected, virtual]

Called when the user scrolls the pointer wheel Override must call base for proper behavior.

Default implementation calls the delegate.

Parameters:
direction positive for up, negative for down
virtual void MGUI::CANVAS::v_OnSize ( int  width,
int  height 
) [protected, virtual]

Called when canvas size changes.

Override must call base for proper behavior. Note, this is NOT called repeatedly while the user resizes the window, but instead will be called after the user releases the pointer or pauses for a nominal period of time (.5 second). Default implementation calls the delegate.

Parameters:
width New canvas width in pixels
height New canvas height in pixels

Reimplemented in MGUI::TOOLCANVAS.

virtual void MGUI::CANVAS::v_OnUpdatePixmap ( const LRECT2D rect  )  [private, virtual]

Called when Pixmap updated from Memory buffer.

Only used if both STYLE_UsePixmap and STYLE_UseMemory specified in construction/creation. Default implementation does nothing.

Parameters:
rect Rectangle that was updated

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

Generated on Sun Oct 7 21:35:27 2012 for TNTsdk 2012 by  doxygen 1.6.1