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

Generated on Tue Dec 14 13:18:15 2004 for TNTsdk by  doxygen 1.3.8-20040913