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

CATControl.h

Go to the documentation of this file.
00001 //---------------------------------------------------------------------------
00002 /// \file CATControl.h
00003 /// \brief Basic Control 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-25 05:11:25 -0600 (Fri, 25 Jan 2008) $
00011 // $Revision:   $
00012 // $NoKeywords: $
00013 //
00014 //---------------------------------------------------------------------------
00015 #ifndef CATControl_H_
00016 #define CATControl_H_
00017 
00018 #include "CATColor.h"
00019 #include "CATCursor.h"
00020 #include "CATKeystroke.h"
00021 #include "CATWidget.h"
00022 
00023 class CATWindow;
00024 
00025 /// \class CATControl CATControl.h
00026 /// \brief Basic Control class
00027 /// \ingroup CATGUI
00028 class CATControl : public CATWidget
00029 {
00030 public:
00031     /// Constructor - mirrors CATXMLObject() constructor for now.
00032     CATControl(  const CATString&               element, 
00033                  const CATString&               rootDir);
00034     
00035     virtual ~CATControl();          
00036 
00037     /// GetWindow() retrieves the parent window.
00038     virtual CATWindow*  GetWindow() const;      
00039 
00040     /// GetValue() retrieves the value of the control.
00041     /// \return CATFloat32 - control value (0.0 - 1.0)
00042     virtual CATFloat32  GetValue() const;
00043 
00044     /// These by default try to convert to float. String-type controls override them.
00045     virtual void        SetString ( const CATString& text );
00046     virtual CATString   GetString () const;
00047 
00048     /// SetValue() sets the value of the control 
00049     /// \param newValue - float from 0 to 1 for new value.
00050     /// \param sendCommand - if true, will send a command with the new value.
00051     /// This is useful when you want to set a value w/o sending a command,
00052     /// for example when updating a control from another control's state.
00053     virtual void        SetValue(CATFloat32 newValue, bool sendCommand = true);
00054 
00055     /// ResetValue() resets the control to its default value
00056     virtual void        ResetValue();
00057 
00058     /// GetCommand() returns the command for the control.
00059     /// \return CATCommand - command from control
00060     virtual CATCommand  GetCommand() const;
00061 
00062     /// GetColorFore() retrieves the foreground color for the control
00063     /// \return CATColor - foreground color
00064     virtual CATColor    GetColorFore() const;
00065 
00066     /// GetColorBack() retrieves the background color for the control
00067     /// If control is disabled, returns the disabled color right now...
00068     /// \return CATColor - background color
00069     virtual CATColor    GetColorBack() const;
00070 
00071     /// SetColorFore() sets the foreground color for the control
00072     /// If control is disabled, returns the disabled color right now...
00073     /// \param color - new foreground color
00074     virtual void        SetColorFore(const CATColor& color);
00075 
00076     // As above, for disabled state
00077     virtual void        SetColorForeDisabled( const CATColor& color);
00078 
00079 
00080     /// SetColorBack() sets the backgroundcolor for the control
00081     /// This is rarely used...
00082     ///
00083     /// \param color - color to set the background to.
00084     virtual void        SetColorBack(const CATColor& color);
00085     // As above, for disabled state
00086     virtual void        SetColorBackDisabled( const CATColor& color);
00087 
00088     /// GetCursor() retrieves the object's mouse cursor.
00089     virtual CATCursor*  GetCursor();
00090 
00091     /// IsFocusable() returns true if the control can receive
00092     /// focus, and false otherwise.
00093     virtual bool        IsFocusable() const;
00094 
00095     /// SetFocused() sets the control's focused state.
00096     ///
00097     /// \param focused - if true, then the control is given focus.
00098     ///                  if false, focus is removed.      
00099     virtual void        SetFocused(bool focused);
00100 
00101     /// SetActive() sets the control's active state.
00102     ///
00103     /// \param active - if true, then the control is under the mouse
00104     ///                  if false, active flag is removed
00105     virtual void        SetActive(bool active);
00106 
00107     /// IsFocused() returns true if the control has the current focus.
00108     virtual bool        IsFocused() const;
00109     /// IsPressed() returns true ifthe control is currently pressed.
00110     virtual bool        IsPressed() const;
00111     // IsActive() returns true if the mouse is over it
00112     virtual bool        IsActive()  const;
00113 
00114     /// Draw() draws the control into the parent's image
00115     /// \param image - parent image to draw into
00116     /// \param dirtyRect - portion of control (in window coordinates)
00117     ///        that requires redrawing.
00118     virtual void Draw(CATImage* image, const CATRect& dirtyRect);
00119 
00120     /// Event handler
00121     virtual CATResult OnEvent(const CATEvent& event, CATInt32& retVal);
00122 
00123     /// PostDraw() draws any stuff that requires an OS-specific draw
00124     /// context.
00125     virtual void   PostDraw(CATDRAWCONTEXT drawContext, const CATRect& dirtyRect);
00126 
00127     /// Load() loads the skin in
00128     virtual        CATResult Load(  CATPROGRESSCB   progressCB    = 0,
00129                                     void*           progressParam = 0,
00130                                     CATFloat32      progMin       = 0.0f,
00131                                     CATFloat32      progMax       = 1.0f);
00132 
00133     /// OnMouseClick() is called if the mouse was pressed, then released within
00134     /// a control.
00135     virtual void   OnMouseClick();
00136 
00137     /// OnRightMouseClick is called if the right button was pressed, then released
00138     /// within a control.
00139     virtual void   OnRightMouseClick();
00140 
00141     /// OnMouseDoubleClick() is called the mouse is double clicked.
00142     ///
00143     /// \param modKey - Key state modifiers for ctrl/shift/alt/etc.
00144     virtual void         OnMouseDoubleClick(  CATMODKEY         modKey);
00145 
00146 
00147 
00148     /// Tracked mouse movements - only called when the mouse was initially
00149     /// pressed over this control.
00150     ///
00151     /// \param point - location of the mouse
00152     /// \param leftButton - true if left button is pressed
00153     /// \param modKey - Key state modifiers for ctrl/shift/alt/etc.
00154     virtual void   TrackMouseMove(  const CATPOINT& point, 
00155                                     bool            leftButton, 
00156                                     CATMODKEY       modKey);
00157 
00158     /// TrackMouseTimer() is called when no movement has been detected on
00159     /// the mouse to update filtered controls towards their resting point.
00160     /// \param modKey - Key state modifiers for ctrl/shift/alt/etc.
00161     virtual void   TrackMouseTimer(CATMODKEY modKey);
00162 
00163     /// TrackMouseWheel() is called if the mouse wheel is used while
00164     /// a button is down.
00165     ///
00166     /// The mouse wheel movement is set to where each 'notch' should be about
00167     /// 1.0 coming in from the OS.  Positive values are 'up' or away from the
00168     /// user, negative values are down or towards the user.
00169     ///
00170     /// \param point - location of the mouse pointer when the wheel is moved
00171     /// \param wheelMove - distance moved
00172     /// \param modKey - Key state modifiers for ctrl/shift/alt/etc.
00173     virtual void   TrackMouseWheel(  const CATPOINT& point,
00174                                      CATFloat32      wheelMove,
00175                                      CATMODKEY       modKey);
00176 
00177     /// TrackMouseDown() is called when a button is pressed inside the control.
00178     /// 
00179     /// Generally, this should toggle the control into a pressed state, but not
00180     /// register a click or anything yet until TrackMouseRelease() is released
00181     /// within the same control.
00182     ///
00183     /// After TrackMouseDown() is called, the control will begin receiving 
00184     /// TrackMouseMove() calls if the mouse pointer is moved.
00185     ///
00186     /// \param point - location the mouse was pressed
00187     /// \param modKey - Key state modifiers for ctrl/shift/alt/etc.
00188     virtual void   TrackMouseDown(  const CATPOINT& point, 
00189                                     CATMODKEY       modKey);      
00190 
00191 
00192     /// TrackMouseRelease() is called when a button is released 
00193     /// 
00194     /// IF the release is within the control, then it should generally register
00195     /// a mouse click by calling OnMouseClicked().  
00196     ///
00197     /// The control should also set its state to unpressed, but active if the mouse is 
00198     /// within the control (these are the default actions)
00199     ///
00200     /// \param point - location the mouse was pressed
00201     /// \param modKey - Key state modifiers for ctrl/shift/alt/etc.
00202     virtual void   TrackMouseRelease(const CATPOINT& point,
00203         CATMODKEY           modKey);      
00204 
00205     /// OnMouseWheel() is called when the mouse wheel is moved over control, 
00206     /// but the mouse is not already tracked - this is the usual case.
00207     ///
00208     /// The mouse wheel movement is set to where each 'notch' should be about
00209     /// 1.0 coming in from the OS.  Positive values are 'up' or away from the
00210     /// user, negative values are down or towards the user.
00211     ///
00212     /// \param point - location of the mouse pointer when the wheel is moved
00213     /// \param wheelMove - distance moved
00214     /// \param modKey - Key state modifiers for ctrl/shift/alt/etc.
00215     virtual void         OnMouseWheel(  const CATPOINT&   point,
00216                                         CATFloat32        wheelMove,
00217                                         CATMODKEY         modKey);
00218 
00219     /// OnKeyDown() is called when a key is depressed and the control has
00220     /// focus.
00221     ///
00222     /// The key may be a standard key, or it may be one of the special
00223     /// keys - see CATKeystroke.h for details.
00224     ///
00225     /// For most keys, you'll want to trap them here - that way you will
00226     /// receive repeats and such.  However, if you want just full key
00227     /// press/releases, use OnKeyPress() instead.
00228     ///
00229     /// \param keystroke - the key that was pressed
00230     /// \sa OnKeyUp(), OnKeyPress()
00231     virtual void   OnKeyDown(const CATKeystroke& keystroke);
00232 
00233     /// OnKeyUp() is called when a key is released and the control has
00234     /// focus.
00235     ///
00236     /// The key may be a standard key, or it may be one of the special
00237     /// keys - see CATKeystroke.h for details.
00238     ///
00239     /// For most keys, you'll want to trap them in OnKeyDown() instead.
00240     /// However, for certain keys such as SPACE that may be mapped to
00241     /// work like mouse buttons and the like, this is synonymous to
00242     /// the TrackMouseRelease() function.
00243     ///
00244     /// \param keystroke - the key that was pressed
00245     /// \sa OnKeyDown(), OnKeyPress()
00246     virtual void   OnKeyUp(const CATKeystroke& keystroke);
00247 
00248     /// OnKeyPress() is called when a key is pressed, then released and
00249     /// the control has focus.
00250     ///
00251     /// The key may be a standard key, or it may be one of the special
00252     /// keys - see CATKeystroke.h for details.
00253     ///
00254     /// Use this functoin to receive keystrokes where you only want
00255     /// to respond to full key press/releases.  You will not receive
00256     /// repeated calls if the key is held 
00257     /// 
00258     /// \param keystroke - the key that was pressed
00259     virtual void   OnKeyPress(const CATKeystroke& keystroke);
00260 
00261     /// OnParentCreate() is called when the parent window is created.
00262     /// 
00263     /// Most controls won't need this, but any that create their own
00264     /// windows should do so at this point.
00265     virtual void   OnParentCreate();
00266 
00267     /// OnParentDestroy() is called as the parent window is destroyed.
00268     ///
00269     /// Controls that create their own windows during OnParentCreate()
00270     /// should destroy them during OnParentDestroy()
00271     virtual void   OnParentDestroy();
00272 
00273     // Retrieve font info... need a set, but not now.
00274     virtual void   GetFontInfo(CATString& fontName, CATFloat32& fontSize);
00275 
00276     virtual CATControl* HitTest(const CATPOINT& point);
00277 
00278     virtual bool ForEachControl(CATCONTROLFUNCB callback, void* userParam);
00279 
00280     /// Platform-specific call to filter a string prior to it being used
00281     /// in the GUI.  For Windows, it doubles the '&' symbol to prevent
00282     /// unwanted menu/label mnemonics.
00283     static  CATString FilterGUIString( const CATString& unfiltered);
00284 
00285     virtual CATUInt32 GetAccessState();
00286 protected:      
00287     virtual bool BoundsCheckValue();
00288 
00289     // Retrieve the value in terms of percentage from min to max
00290     virtual CATFloat32 GetValPercent();
00291     virtual CATFloat32 GetValRange();
00292     virtual CATFloat32 GetMinValue();
00293     virtual CATFloat32 GetMaxValue();
00294     virtual void       SetMinMax  ( CATFloat32 minValue, 
00295                                     CATFloat32 maxValue);
00296 
00297     /// ResetCursorToDefault() restores the control's cursor to its
00298     /// configured default.
00299     ///
00300     /// This is mainly used on controls like knobs that have special
00301     /// cursor control while they are being manipulated.
00302     virtual void   ResetCursorToDefault();
00303 
00304     /// ParseAttributes() parses the known attributes for an object.
00305     virtual CATResult ParseAttributes();
00306 
00307 
00308     /// CheckImageSize() performs a sanity check on the image vs. the base
00309     /// image of the control.
00310     ///
00311     /// Many images in the framework are required to be the same size. For
00312     /// instance, the enabled and disabled images of any control should have
00313     /// the same dimensions - if they don't, then the drawing will be
00314     /// corrupted (or rather, it would, but CheckImageSize() works around
00315     /// that).
00316     ///
00317     /// By default, image is compared against the class' fImage. If the image
00318     /// sizes do not match, then image is destroyed and recreated in a size
00319     /// that will match - any extra space is filled with red.
00320     ///
00321     /// If baseImage is provided, then it is used as the point of reference
00322     /// instead of fImage.
00323     ///
00324     /// \param image - Image to check size of. If the size is not correct,
00325     /// it will be destroyed and recreated (hence the ref).
00326     /// \param baseImage - the image to check against, or null to use
00327     /// fImage of the control.
00328     virtual CATResult CheckImageSize( CATImage *&     image, 
00329                                       const CATImage* baseImage = 0);
00330 
00331     //---------------------------------------------------------------------
00332     // Common data members for all controls from skin
00333     //---------------------------------------------------------------------
00334 
00335     /// Value of the control 
00336     CATFloat32  fValue;
00337 
00338     /// Default value of control.
00339     CATFloat32  fDefValue;   
00340     CATFloat32  fMinValue;
00341     CATFloat32  fMaxValue;  
00342 
00343     /// Command to send when control is pressed/activated
00344     CATString   fCmdString;
00345 
00346     /// Target for command, if any. Empty for general commands.
00347     CATString   fTarget;
00348 
00349     /// Additional parameter to send when control is pressed/activated
00350     CATString   fCmdParam;
00351 
00352     /// Command Type (empty or "VSTParam" for vst parameters)
00353     CATString   fCmdType;
00354 
00355     /// Foreground disabled color
00356     CATColor    fFgDisColor;
00357 
00358     /// Background disabled color
00359     CATColor    fBgDisColor;
00360 
00361     /// Default Cursor for control
00362     CATCursor   fCursor;
00363 
00364     /// Inactive image for control
00365     CATImage*   fImageDisabled;
00366 
00367     /// Active/pressed  image for control
00368     CATImage*   fImagePressed;
00369 
00370     /// Focus image
00371     CATImage*   fImageFocus;
00372 
00373     /// MouseOver image for control
00374     CATImage*   fImageActive;
00375 
00376     CATString   fText;
00377     bool        fAutoScaleText;
00378     bool        fTextCentered;
00379     CATPOINT    fTextOffset;
00380     CATPOINT    fTextOffsetPressed;
00381     bool        fShowBg;
00382     bool        fMultiline;
00383     //--------------------------------------------------------------------
00384 
00385     CATString   fFontName;
00386     CATFloat32  fFontSize;
00387 
00388     // State controls
00389 
00390     /// Is the control pressed (mouse currently down on it) ?
00391     bool        fPressed;
00392 
00393     /// Is the control focused?
00394     bool        fFocused;
00395 
00396     /// Is the control active (mouse over)?
00397     bool        fActive;
00398 
00399 };
00400 
00401 #endif // CATControl_H_
00402 
00403 

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