Game Accessibility Library logo SourceForge.net Logo
Game Accessibility Suite: CATGUI/CATGuiObj.h Source File

CATGuiObj.h

Go to the documentation of this file.
00001 //---------------------------------------------------------------------------
00002 /// \class CATGuiObj.h
00003 /// \brief GUI object base class
00004 /// \ingroup CATGUI
00005 /// 
00006 /// Copyright (c) 2003-2008 by Michael Ellison.
00007 /// See COPYING.txt for the \ref gaslicense License (MIT License).
00008 ///
00009 // $Author: mikeellison $
00010 // $Date: 2008-01-27 01:25:54 -0600 (Sun, 27 Jan 2008) $
00011 // $Revision:   $
00012 // $NoKeywords: $
00013 //
00014 //---------------------------------------------------------------------------
00015 #ifndef _CATGuiObj_H_
00016 #define _CATGuiObj_H_
00017 
00018 #include "CATGUIInternal.h"
00019 #include "CATGUIAccessDefs.h"
00020 
00021 class CATWindow;
00022 class CATControl;
00023 class CATAccessible;
00024 
00025 // Callback used for control enumeration. REturn true to continue enumeration.
00026 typedef bool (*CATCONTROLFUNCB)(CATControl* control, void* userParam);
00027 
00028 /// \class CATGuiObj
00029 /// \brief GUI object base class
00030 /// \ingroup CATGUI
00031 class CATGuiObj : public CATXMLObject
00032 {
00033 public:
00034     /// Constructor - mirrors CATXMLObject() constructor for now.
00035     CATGuiObj(  const CATString&               element, 
00036                 const CATString&               rootDir);
00037 
00038     virtual ~CATGuiObj();
00039 
00040     /// GetName() retrieves the name of the control.
00041     virtual CATString    GetName() const;
00042 
00043     /// GetHint() retrieves the hint text for the control
00044     virtual CATString    GetHint() const;
00045 
00046     /// OnEvent() is called when events occur that we should know about.
00047     virtual CATResult    OnEvent  (  const CATEvent&  event, CATInt32& retVal);
00048 
00049     /// MarkDirty() marks the control as dirty (needing to be redrawn)
00050     ///
00051     /// \param dirtyRect - if specified, marks only part of the rectangle
00052     /// \param force - if true, forces update even if object isn't visible
00053     virtual void         MarkDirty(CATRect* dirtyRect = 0, bool force = false){};
00054 
00055     /// GetRect() retrieves the rectangle of the GUI object.
00056     /// Skins will have a null rectangle.
00057     /// \return CATRect - rectangle of parent
00058     virtual CATRect      GetRect();
00059 
00060     /// GetRectAbs() retrieves the rect of the GUI object in
00061     /// absolute coordinates (e.g. w/o layer relocation).
00062     ///
00063     /// \param screenCoordinates - if true, returns the rect in screen
00064     ///                            coordinates. Otherwise, they are in
00065     ///                            client coordinates.
00066     virtual CATRect      GetRectAbs( bool screenCoordinates = false);
00067 
00068     /// Load() loads the skin in.
00069     virtual CATResult    Load(  CATPROGRESSCB   progressCB    = 0,
00070                                 void*           progressParam = 0,
00071                                 CATFloat32      progMin       = 0.0f,
00072                                 CATFloat32      progMax       = 1.0f);
00073 
00074 
00075     /// RectFromAttribs() recalculates the control's rectangle from
00076     /// the attributes.  This can only be called after ParseAttributes() has
00077     /// loaded the images.
00078     virtual CATResult    RectFromAttribs();
00079 
00080     /// Retrieve minimum and maximum size for the object.
00081     /// 
00082     /// If there is no minimum or maximum for a given parameter, then
00083     /// it will be set to 0.
00084     ///
00085     /// \param minWidth - ref to receive minimum width of the object
00086     /// \param minHeight - ref to receive minimum height of the object
00087     /// \param maxWidth - ref to receive maximum width of the object
00088     /// \param maxHeight - ref to receive maximum height of the object
00089     virtual void      GetMinMax   ( CATInt32& minWidth, 
00090                                     CATInt32& minHeight,
00091                                     CATInt32& maxWidth, 
00092                                     CATInt32& maxHeight);
00093 
00094     virtual bool      IsEnabled() const;
00095 
00096     virtual void      SetEnabled(bool enabled);
00097 
00098 
00099 
00100     /// IsVisible() returns true if the window is currently visible.
00101     /// \sa SetVisible()
00102     virtual bool      IsVisible    ( const CATGuiObj* object = 0  ) const;
00103     virtual void      SetVisible   ( bool             visible);
00104 
00105 
00106     /// GetWindow() retrieves the base window.
00107     /// By default, return a NULL pointer.
00108     virtual CATWindow*   GetWindow() const {return 0;}      
00109 
00110     // All widgets must be able to hit test.
00111     // Layers check all controls within themselves and return any that hit.
00112     // Controls just check if they're hitable, and return themself if so.
00113     virtual CATControl*  HitTest(        const CATPOINT&  point) {return 0;}
00114 
00115     /// ForEachControl() calls the callback with each control.
00116     /// Containers are not sent to the callback.
00117     virtual bool         ForEachControl( CATCONTROLFUNCB  callback,    
00118                                          void*            userParam);
00119 
00120     /// Recursively looks for the first object matching the name.
00121     /// Optionally, may also filter by object type.
00122     virtual CATGuiObj*   Find(           const CATString& objectName,
00123                                          const CATString& objectType = L"");
00124 
00125     /// Retrieve a stack of post rectangles from child controls for use in 
00126     /// clipping the main window's drawing routines.
00127     ///
00128     /// \param rectStack - a stack of rectangles to add Post-draw
00129     /// rects to when building up the clipping region.
00130     /// \return bool - true if any post rectangles are found.
00131     virtual bool GetPostRects(CATStack<CATRect>& rectStack);
00132 
00133     /// OnCommand() is called by child controls when they are pressed /
00134     /// changed.  
00135     ///
00136     /// Each clickable control has an XML-scripted
00137     /// command string and parameter, as well as the control's value.
00138     /// By default, commands are sent from the control to its parent, 
00139     /// then up to the window's parent skin, and from there to the
00140     /// application.
00141     ///
00142     /// \param command - the command 
00143     /// \param ctrl - the control that sent it, or 0.
00144     virtual void   OnCommand( CATCommand& command,
00145                               CATControl* ctrl);         
00146 
00147     /// ParseAttributes() parses the known attributes for an object.
00148     virtual CATResult ParseAttributes();
00149 
00150     /// Retrieve an accessible object, create one if needed.
00151     virtual CATAccessible*  GetAccessible();
00152 
00153     virtual CATUInt32       GetAccessRole();
00154     virtual CATUInt32       GetAccessState();
00155     
00156 protected:      
00157 
00158     /// LoadSkinImage() loads an image from the skin
00159     CATResult LoadSkinImage( const CATString&  filename, 
00160                              CATImage*&        imagePtr);
00161 
00162     //---------------------------------------------------------------------
00163     // Common data members for all objects in a skin
00164     //---------------------------------------------------------------------
00165     
00166     /// Accessible interface
00167     CATAccessible*  fAccessible;
00168 
00169     /// Root directory of skin
00170     CATString       fRootDir;
00171 
00172     /// Name of control
00173     CATString       fName;  
00174 
00175     /// Hint text for control (for status bar)
00176     CATString       fHintText;
00177 
00178     /// Normal image for control
00179     CATImage*       fImage;
00180 
00181     /// Control Rectangle - this is the current control rect
00182     /// Use RectFromAttribs() to set when the size of the window
00183     /// changes.
00184     CATRect         fRect;
00185 
00186     /// fMinWidth is the minimum width of the control.  Even if the control
00187     /// resizes itself as a result of the parent Window resizing, it will
00188     /// not go below this width.
00189     CATInt32        fMinWidth;
00190 
00191     /// fMinHeight is the minimum height of the control.  Even if the control
00192     /// resizes itself as a result of the parent Window resizing, it will
00193     /// not go below this height.
00194     CATInt32        fMinHeight;
00195 
00196     /// fMaxWidth is the maximum width of the control.  If it is set to 0,
00197     /// then no maximum width is enforced.
00198     CATInt32        fMaxWidth;
00199 
00200     /// fMaxHeight is the maximum height of the control.  If it is set to 0,
00201     /// then no maximum height is enforced.
00202     CATInt32        fMaxHeight;
00203     //--------------------------------------------------------------------
00204     // State controls
00205 
00206     /// fEnabled is true if the control is enabled, and false otherwise.
00207     bool            fEnabled;
00208 
00209     /// fVisible is true if the window is visible
00210     bool            fVisible;
00211 
00212     /// Show the value of the control in the hint?
00213     bool            fShowHintValue;      
00214 
00215     /// Foreground color
00216     CATColor        fForegroundColor;
00217 
00218     /// Background color
00219     CATColor        fBackgroundColor;
00220 };
00221 
00222 #endif // _CATGuiObj_H_
00223 
00224 

Generated on Mon Feb 11 04:09:53 2008 for Game Accessibility Suite by doxygen 1.5.4