Game Accessibility Library logo SourceForge.net Logo
Game Accessibility Suite: CATGUI/CATRadioButton.cpp Source File

CATRadioButton.cpp

Go to the documentation of this file.
00001 //---------------------------------------------------------------------------
00002 /// \file CATRadioButton.cpp
00003 /// \brief Momentary push button for GUI
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-23 01:43:25 -0600 (Wed, 23 Jan 2008) $
00011 // $Revision:   $
00012 // $NoKeywords: $
00013 //
00014 //---------------------------------------------------------------------------
00015 #include "CATRadioButton.h"
00016 
00017 
00018 //---------------------------------------------------------------------------
00019 /// CATRadioButton constructor (inherited from CATControl->CATXMLObject)
00020 /// \param element - Type name ("Button")
00021 /// \param attribs - attribute information for the window
00022 /// \param parent - parent XML object (should be a "Window" element)
00023 /// \param rootDir - root directory of skin
00024 //---------------------------------------------------------------------------
00025 CATRadioButton::CATRadioButton(  const CATString&             element, 
00026                                const CATString&             rootDir)
00027                                : CATSwitch(element,  rootDir)
00028 {
00029     fValue      = 0.0f;
00030     fRadioValue = 0.0f;
00031     fMinValue   = 0.0f;
00032     fMaxValue   = (CATFloat32)kGGMAXRADIOBUTTONS;
00033 }
00034 
00035 
00036 /// ParseAttributes() parses the known attributes for an object.
00037 CATResult CATRadioButton::ParseAttributes()
00038 {
00039     CATResult result = CATSwitch::ParseAttributes();
00040     CATString attrib;
00041 
00042     fRadioValue = GetAttribute(L"RadioValue",fRadioValue);
00043 
00044     return result;   
00045 }
00046 
00047 //---------------------------------------------------------------------------
00048 /// CATRadioButton destructor
00049 //---------------------------------------------------------------------------
00050 CATRadioButton::~CATRadioButton()
00051 {
00052 }
00053 
00054 
00055 CATResult CATRadioButton::Load( CATPROGRESSCB               progressCB,
00056                                void*                            progressParam,
00057                                CATFloat32                       progMin,
00058                                CATFloat32                       progMax)
00059 {
00060     CATResult result = CATSwitch::Load(progressCB, progressParam, progMin, progMax);  
00061     return result;
00062 }
00063 
00064 //---------------------------------------------------------------------------
00065 // Draw() draws the control into the parent window
00066 // \param dirtyRect - portion of control (in window coordinates)
00067 //        that requires redrawing.
00068 //---------------------------------------------------------------------------
00069 void CATRadioButton::Draw(CATImage* image, const CATRect& dirtyRect)
00070 {
00071     if (this->IsVisible() == false)
00072     {
00073         return;
00074     }
00075 
00076     // sanity check parent image / dirty rectangle
00077     CATRect imgRect(0,0,image->Width(), image->Height());
00078     CATASSERT(imgRect.Inside(dirtyRect), "Update rect is outside of img rect!");
00079 
00080     // Find intersection between dirty rect and us
00081     CATRect drawRect;
00082     bool   drawn = false;
00083 
00084     CATImage* disabled = fImageDisabled;
00085     CATImage* normal   = fImage;
00086     CATImage* pressed  = fImagePressed;
00087     CATImage* focus    = fImageFocus;
00088     CATImage* active   = fImageActive;
00089 
00090     if ((int)fValue == (int)fRadioValue)
00091     {
00092         // All on...
00093         if (fImageOn)
00094             normal      = fImageOn;
00095 
00096         // Fallback to on-state with radio button.
00097         if (fImagePressedOn)
00098             pressed     = fImagePressedOn;
00099         else if (fImageOn)
00100             pressed     = fImageOn;
00101 
00102         if (fImageFocusOn)
00103             focus       = fImageFocusOn;
00104         else if (fImageOn)
00105             focus       = fImageOn;
00106 
00107         if (fImageActiveOn)
00108             active      = fImageActiveOn;
00109         else if (fImageOn)
00110             active      = fImageOn;
00111 
00112         if (fImageDisabledOn)
00113             disabled    = fImageDisabledOn;
00114         else if (fImageOn)
00115             disabled    = fImageOn;
00116     }
00117 
00118 
00119     // Gracefully degrade depending on flags and whether the images are
00120     // available.
00121     if (this->fRect.Intersect(dirtyRect, &drawRect))
00122     {  
00123         CATRect ourRect;
00124         if ( (this->IsEnabled() == false) && (disabled))
00125         {
00126             if (drawRect.Intersect(CATRect(fRect.left, 
00127                 fRect.top, 
00128                 fRect.left + disabled->Width(),
00129                 fRect.top  + disabled->Height()),
00130                 &ourRect))
00131             {
00132                 ourRect.Offset(-fRect.left, -fRect.top);
00133 
00134                 image->Overlay(   disabled,
00135                     drawRect.left, 
00136                     drawRect.top, 
00137                     ourRect.left,
00138                     ourRect.top,
00139                     ourRect.Width(),
00140                     ourRect.Height());
00141                 drawn = true;
00142             }        
00143         }
00144         else 
00145         {
00146             if (this->IsPressed() && (pressed))
00147             {
00148                 if (drawRect.Intersect(CATRect(fRect.left, 
00149                     fRect.top, 
00150                     fRect.left + pressed->Width(),
00151                     fRect.top  + pressed->Height()),
00152                     &ourRect))
00153                 {
00154                     ourRect.Offset(-fRect.left, -fRect.top);
00155 
00156                     image->Overlay(   pressed,
00157                         drawRect.left,
00158                         drawRect.top,
00159                         ourRect.left,
00160                         ourRect.top,
00161                         ourRect.Width(),
00162                         ourRect.Height());
00163                     drawn = true;
00164                 }
00165             }
00166 
00167             if ((!drawn) && (IsFocused() || IsPressed()) && (focus))
00168             {
00169                 if (drawRect.Intersect(CATRect(fRect.left, 
00170                     fRect.top, 
00171                     fRect.left + focus->Width(),
00172                     fRect.top  + focus->Height()),
00173                     &ourRect))
00174                 {
00175                     ourRect.Offset(-fRect.left, -fRect.top);
00176 
00177                     image->Overlay(   focus,
00178                         drawRect.left,
00179                         drawRect.top,
00180                         ourRect.left,
00181                         ourRect.top,
00182                         ourRect.Width(),
00183                         ourRect.Height());
00184                     drawn = true;
00185                 }
00186             }
00187 
00188             if ((!drawn) && (IsActive()) && (active))
00189             {
00190                 if (drawRect.Intersect(CATRect(fRect.left, 
00191                     fRect.top, 
00192                     fRect.left + active->Width(),
00193                     fRect.top  + active->Height()),
00194                     &ourRect))
00195                 {
00196                     ourRect.Offset(-fRect.left, -fRect.top);
00197 
00198                     image->Overlay(   active,
00199                         drawRect.left,
00200                         drawRect.top,
00201                         ourRect.left,
00202                         ourRect.top,
00203                         ourRect.Width(),
00204                         ourRect.Height());
00205                     drawn = true;
00206                 }
00207             }
00208         }
00209 
00210         if ((!drawn) && (normal != 0))
00211         {
00212             if (drawRect.Intersect(CATRect(fRect.left, 
00213                 fRect.top, 
00214                 fRect.left + normal->Width(),
00215                 fRect.top  + normal->Height()),
00216                 &ourRect))
00217             {
00218                 ourRect.Offset(-fRect.left, -fRect.top);
00219 
00220                 image->Overlay(   normal,
00221                     drawRect.left,
00222                     drawRect.top,
00223                     ourRect.left,
00224                     ourRect.top,
00225                     ourRect.Width(),
00226                     ourRect.Height());
00227                 drawn = true;
00228             }
00229         }
00230 
00231         if (!drawn)
00232         {
00233 
00234             // Right now, just make a big red rectangle where we should go.
00235             image->FillRect(drawRect, fBackgroundColor);
00236         }
00237     }
00238 }
00239 
00240 void CATRadioButton::OnMouseClick()
00241 {
00242     if (fValue != fRadioValue)
00243     {
00244         fValue = fRadioValue;
00245         CATControl::OnMouseClick();
00246     }
00247 }

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