Main Page   Class Hierarchy   Compound List   File List   Compound Members  

gfxWindow.h

00001 //////////////////////////////////////////////////////////////////////
00002 // Copyright (c) 2001-2002 David Pritchard <drpritch@alumni.uwaterloo.ca>
00003 // 
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public License
00006 // as published by the Free Software Foundation; either
00007 // version 2 of the License, or (at your option) any later
00008 // version.
00009 // 
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU Lesser General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU Lesser General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 
00019 #ifndef freecloth_gfx_gfxWindow_h
00020 #define freecloth_gfx_gfxWindow_h
00021 
00022 #ifndef freecloth_gfx_package_h
00023 #include <freecloth/gfx/package.h>
00024 #endif
00025 
00026 #ifndef freecloth_resmgt_rcBase_h
00027 #include <freecloth/resmgt/rcBase.h>
00028 #endif
00029 
00030 #ifndef freecloth_base_list
00031 #include <freecloth/base/list>
00032 #endif
00033 
00034 ////////////////////////////////////////////////////////////////////////////////
00035 // FORWARD DECLARATIONS
00036 
00037 class GfxWindowObserver;
00038 
00039 ////////////////////////////////////////////////////////////////////////////////
00040 /*!
00041  * \class GfxWindow freecloth/gfx/gfxWindow.h
00042  * \brief Interface for window creation and messages.
00043  *
00044  */
00045 class GfxWindow : public RCBase {
00046 public:
00047 
00048     //----- types and enumerations -----
00049 
00050     //! Key definitions.
00051     enum KeyID {
00052 
00053         // The only pattern here is to follow the ASCII conventions as
00054         // much as possible.
00055 
00056         KB_NONE = 0,
00057 
00058         KB_BACKSPACE = 0x08,
00059         KB_TAB = '\t',      // 0x09
00060         KB_RETURN = '\n',   // 0x0d
00061         KB_ENTER = KB_RETURN,
00062         KB_ESCAPE = 0x1B,
00063         KB_SPACE = ' ',     // 0x20
00064 
00065         KB_LEFT,
00066         KB_RIGHT,
00067         KB_UP,
00068         KB_DOWN,
00069 
00070         // 0x30 - 0x39
00071         KB_0 = '0', KB_1 = '1', KB_2 = '2', KB_3 = '3',
00072         KB_4 = '4', KB_5 = '5', KB_6 = '6', KB_7 = '7',
00073         KB_8 = '8', KB_9 = '9',
00074 
00075         // 0x41 - 0x5a
00076         KB_A = 'A', KB_B = 'B', KB_C = 'C', KB_D = 'D',
00077         KB_E = 'E', KB_F = 'F', KB_G = 'G', KB_H = 'H',
00078         KB_I = 'I', KB_J = 'J', KB_K = 'K', KB_L = 'L',
00079         KB_M = 'M', KB_N = 'N', KB_O = 'O', KB_P = 'P',
00080         KB_Q = 'Q', KB_R = 'R', KB_S = 'S', KB_T = 'T',
00081         KB_U = 'U', KB_V = 'V', KB_W = 'W', KB_X = 'X',
00082         KB_Y = 'Y', KB_Z = 'Z'
00083     };
00084     //! Modifiers, combined in a bitfield.
00085     enum {
00086         KBM_ALT = 0x01,
00087         KBM_CONTROL = 0x02,
00088         KBM_SHIFT = 0x04
00089     };
00090     //! Mouse button ids
00091     //! Sadly, MB_ prefix conflicts with Win32 constants
00092     enum ButtonID {
00093         MBN_NONE = 0,
00094 
00095         MBN_LEFT,
00096         MBN_RIGHT,
00097         MBN_MIDDLE
00098     };
00099     //! Modifier bitfield. (Not the same as the enum since it can contain
00100     //! arbitrary combinations of the above enum entries.)
00101     typedef UInt32  ModBitfield;
00102 
00103     //----- static member functions -----
00104 
00105     //! Add a static observer.
00106     //! The observer must live longer than window.
00107     // FIXME: use a shared-pointer to assure that this condition is
00108     // satisfied.
00109     // FIXME: kill these off; they're an awful hack.
00110     static void addStaticObserver( GfxWindowObserver& );
00111     static void removeStaticObserver( GfxWindowObserver& );
00112 
00113     //----- member functions -----
00114 
00115     //! Constructor.
00116     GfxWindow();
00117     //! Destructor.
00118     virtual ~GfxWindow();
00119 
00120     virtual UInt32 getWidth() const = 0;
00121     virtual UInt32 getHeight() const = 0;
00122     Float getAspectRatio() const;
00123     virtual void close() = 0;
00124 
00125     //! Add an observer.
00126     //! The observer must live longer than window.
00127     // FIXME: use a shared-pointer to assure that this condition is
00128     // satisfied.
00129     virtual void addObserver( GfxWindowObserver& );
00130     virtual void removeObserver( GfxWindowObserver& );
00131 
00132 protected:
00133     //----- member functions -----
00134 
00135     //! Just prior to closing the window. Not sent to static observers.
00136     void closeReceived();
00137     //! Redraw requested...
00138     void displayReceived();
00139     void idleReceived();
00140     void keyPressed( KeyID, ModBitfield );
00141     void keyDownReceived( KeyID, ModBitfield );
00142     void keyUpReceived( KeyID, ModBitfield );
00143     void mouseDownReceived( UInt32 x, UInt32 y, ButtonID );
00144     void mouseUpReceived( UInt32 x, UInt32 y, ButtonID );
00145     void mouseMoveReceived( UInt32 x, UInt32 y );
00146     void windowResized( UInt32 x, UInt32 y, UInt32 width, UInt32 height );
00147     void uiReceived( UInt32 uid );
00148 
00149 private:
00150 
00151     //----- classes -----
00152     class ObserverIterator;
00153 
00154     //----- friends -----
00155     friend class ObserverIterator;
00156 
00157     //----- types and enumerations -----
00158     typedef std::list<GfxWindowObserver*> ObserverList;
00159 
00160     //----- member functions -----
00161     ObserverIterator allObserversBegin();
00162     ObserverIterator allObserversEnd();
00163 
00164     //----- data members -----
00165 
00166     // @{
00167     //! Prohibited.
00168     GfxWindow( GfxWindow const& );
00169     GfxWindow& operator=( GfxWindow const& );
00170     // @}
00171 
00172     ObserverList    _observers;
00173 
00174     //----- static data members -----
00175 
00176     static ObserverList _staticObservers;
00177 };
00178 #endif

Generated on Fri May 2 16:51:13 2003 for Freecloth by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002