canvas.h

Go to the documentation of this file.
00001 /**
00002  * \file mgui/canvas.h
00003  * \brief MGUI "canvas" control definitions.
00004  *
00005  * \if NODOC
00006  * $Id: canvas.h_v 1.10 2005/03/31 16:57:07 fileserver!dwilliss Exp $
00007  *
00008  * $Log: canvas.h_v $
00009  * Revision 1.10  2005/03/31 16:57:07  fileserver!dwilliss
00010  * Rename one of our types to MIUNICODE because it conflicted with a Microsoft #define
00011  *
00012  * Revision 1.9  2003/10/03 19:58:19  linux32build!build
00013  * Doxygen
00014  *
00015  * Revision 1.8  2003/09/15 13:49:32  fileserver!dwilliss
00016  * Doxygen
00017  *
00018  * Revision 1.7  2003/04/09 20:48:40  dwilliss
00019  * never mind
00020  *
00021  * Revision 1.6  2003/04/09 20:46:28  dwilliss
00022  * Don't use _T in templates. Mac ctype.h defines a global _T
00023  *
00024  * Revision 1.5  2003/01/10 23:07:20  mju
00025  * Now working for tools.
00026  *
00027  * Revision 1.4  2003/01/07 18:25:31  mju
00028  * Add GetDlgParent.
00029  * Add v_OnKey.
00030  *
00031  * Revision 1.3  2003/01/07 15:03:23  mju
00032  * Use v_ for virtual methods.
00033  *
00034  * Revision 1.2  2002/10/14 13:46:38  mju
00035  * Rename ctrl_canvas as canvas.
00036  *
00037  * Revision 1.1  2002/10/11 20:32:18  mju
00038  * Initial revision
00039  * \endif
00040 **/
00041 
00042 #ifndef  INC_MGUI_CANVAS_H
00043 #define  INC_MGUI_CANVAS_H
00044 
00045 #ifndef INC_MGUI_CTRL_H
00046 #include <mgui/ctrl.h>
00047 #endif
00048 
00049 #ifndef INC_MGUI_KEYCODE_H
00050 #include <mgui/keycode.h>
00051 #endif
00052 
00053 #ifndef INC_MGUI_CURSORID_H
00054 #include <mgui/cursorid.h>
00055 #endif
00056 
00057 
00058 #ifndef GENERATING_DOXYGEN_OUTPUT
00059 namespace MGD {
00060    class DEVICE_X;
00061    class DEVICE_MEM24;
00062    class DEVICE_MEM32;
00063    class CONTEXT;
00064    }
00065 #endif // GENERATING_DOXYGEN_OUTPUT
00066 
00067 
00068 namespace MGUI {
00069 
00070 #ifndef GENERATING_DOXYGEN_OUTPUT
00071 //! Window derived from CWnd for MFC.
00072 //! Not nested because MFC macros have problems with nested classes.
00073 #ifdef WIN32_MFC
00074 class WNDCANVAS;
00075 #endif
00076 #endif // GENERATING_DOXYGEN_OUTPUT
00077 
00078 //===================================================================================================================
00079 //!   Generic 'canvas' control supporting drawing and simple user input.
00080 //! To avoid unnecessary overhead there is at present no 'template' (_CT) version of this class
00081 //! due to the large number of virtual methods.
00082 class CANVAS : public CTRL {
00083    public:
00084 
00085       enum DCTYPE {
00086          DCTYPE_Buffer,
00087          DCTYPE_Screen
00088          };
00089 
00090       enum STYLE {
00091          STYLE_Default =         0x00,
00092          STYLE_EnableOverlay =   0x01,
00093          STYLE_NoBuffer =        0x02
00094          };
00095 
00096       //! Constructor.
00097       CANVAS (
00098          STYLE style = STYLE_Default
00099          );
00100 
00101       //! Destructor.
00102       virtual ~CANVAS (
00103          );
00104 
00105       //! Create canvas control
00106       void Create (
00107          LAYOUT_PANE_BASE& ParentPane,    //!< Parent pane
00108          int width,                       //!< Desired width in pixels
00109          int height,                      //!< Desired height in pixels
00110          LAYOUT_SIZEALIGN sizealign,      //!< Sizing and alignment options
00111          CANVAS::STYLE style = STYLE_Default
00112          );
00113 
00114       //! Get suitable parent for dialog launched from canvas.
00115       MDLGPARENT GetDlgParent (
00116          ) const;
00117 
00118       //! Get drawing context for buffer or direct display.
00119       //! Do not delete the returned CONTEXT as it is internal to the CANVAS.
00120       MGD::CONTEXT* GetDrawingContext (
00121          DCTYPE dctype = DCTYPE_Buffer    //!< Drawing context type
00122          );
00123 
00124       //! Get dimensions of canvas.
00125       void GetSize (
00126          INT16& width,                    //!< Width in pixels returned
00127          INT16& height                    //!< Height in pixels returned
00128          );
00129 
00130       //! Invalidate entire canvas.
00131       //! This will restore from off-screen buffer (if available) and/or
00132       //! generate OnPaint notification depending on canvas style.
00133       void Invalidate (
00134          bool UpdateNow = false           //!< Perform immediate update before returning
00135          );
00136 
00137       //! Invalidate specified portion of canvas.
00138       //! This will restore from off-screen buffer (if available) and/or
00139       //! generate OnPaint notification depending on canvas style.
00140       void Invalidate (
00141          const LRECT2D& rect,
00142          bool UpdateNow = false           //!< Perform immediate update before returning
00143          );
00144 
00145       //! Determine if mouse is "captured" by this canvas.
00146       bool IsMouseCaptured (
00147          ) const;
00148 
00149       //! Determine if canvas set for delayed redraw.
00150 //!      bool IsRedrawDelayed (
00151 //!         ) const { return (m_RedrawTimerID != 0); }
00152 
00153       //! Schedule redraw of canvas after specified delay.
00154       void RedrawDelayed (
00155          int delay = 1000                 //!< Delay in milliseconds
00156          );
00157 
00158       //! Set mouse cursor to show while in canvas.
00159       void SetCursor (
00160          CURSORID cursorid
00161          );
00162 
00163    private:
00164 
00165       #ifndef GENERATING_DOXYGEN_OUTPUT
00166    #ifdef WIN32_MFC
00167       WNDCANVAS *m_pctrl;
00168       friend class WNDCANVAS;
00169       class BUFDEVICE;
00170       BUFDEVICE *m_BufDev;
00171    #endif
00172 
00173    #ifdef X_NATIVE
00174       MGD::DEVICE_MEM24 *m_BufDev;
00175       MGD::DEVICE_X *m_DispDev;
00176       bool m_MouseCaptured;
00177       static void CB_Expose (Widget, CANVAS*, void*);
00178       static void CB_Resize (Widget, CANVAS*, void*);
00179       static void EH_Input (Widget, CANVAS*, XEvent*, Boolean*);
00180       void RestoreRect (const LRECT2D& rect);
00181    #endif
00182 
00183       MGD::CONTEXT *m_BufDC;
00184       MGD::CONTEXT *m_DispDC;
00185       CANVAS::STYLE m_style;
00186 
00187       void CreateBufDev ();
00188       CANVAS (const CANVAS&);
00189       CANVAS& operator= (const CANVAS&);
00190       #endif // GENERATING_DOXYGEN_OUTPUT
00191 
00192       // New overridables.
00193 
00194       //! Called when cursor "capture" is changed (lost).
00195       virtual void v_OnCaptureChanged (
00196          );
00197 
00198       //! Called when key "pressed".
00199       //! @return 'true' if key handled, 'false' if not.
00200       virtual bool v_OnKey (
00201          MGUI::POINT point,               //!< Point in canvas coordinates where button event occurred
00202          MGUI::KEYCODE keycode,           //!< Processed key code, equivalent to MIUNICODE for alphanumeric keys.
00203          MGUI::KEYSTATE keystate          //!< Modifier key state
00204          );
00205 
00206       //! Called when left mouse button pressed.
00207       virtual void v_OnLeftDown (
00208          MGUI::POINT point,               //!< Point in canvas coordinates where button event occurred
00209          KEYSTATE keystate                //!< Modifier key state at time of event
00210          );
00211 
00212       //! Called when left mouse button released.
00213       virtual void v_OnLeftUp (
00214          MGUI::POINT point,               //!< Point in canvas coordinates where button event occurred
00215          KEYSTATE keystate                //!< Modifier key state at time of event
00216          );
00217 
00218       //! Called when mouse cursor is moved.
00219       virtual void v_OnMouseMove (
00220          MGUI::POINT point,               //!< Point in canvas coordinates where button event occurred
00221          KEYSTATE keystate                //!< Modifier key state at time of event
00222          );
00223 
00224       //! Called when canvas needs to be redrawn, do not call directly.
00225       //! This is called after the buffer is updated to the screen.  If no overlay and not unbuffered
00226       //! then this method does not need to be overridden.
00227       virtual void v_OnPaint (
00228          MGD::CONTEXT *gc                 //!< Drawing context for unbuffered/overlay.
00229          );
00230 
00231       //! Called when right mouse button pressed.
00232       virtual void v_OnRightDown (
00233          MGUI::POINT point,               //!< Point in canvas coordinates where button event occurred
00234          KEYSTATE keystate                //!< Modifier key state at time of event
00235          );
00236 
00237       //! Called when right mouse button released.
00238       virtual void v_OnRightUp (
00239          MGUI::POINT point,               //!< Point in canvas coordinates where button event occurred
00240          KEYSTATE keystate                //!< Modifier key state at time of event
00241          );
00242 
00243       //! Called when canvas size changes.
00244       //! Note, this is NOT called repeatedly while the user resizes the window, but instead will be
00245       //! called after the user releases the mouse or pauses for a nominal period of time (.5 second).
00246       virtual void v_OnSize (
00247          int width,                       //!< New canvas width in pixels
00248          int height                       //!< New canvas height in pixels
00249          );
00250 
00251    };
00252 
00253 DEFINE_ENUM_OP_BITWISE(CANVAS::STYLE);
00254 
00255 //===================================================================================================================
00256 
00257 }  // End namespace MGUI
00258 
00259 
00260 #endif   // INC_MGUI_CANVAS_H

Generated on Wed May 31 15:26:43 2006 for TNTsdk by  doxygen 1.3.8-20040913