00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "CATRadioButton.h"
00016
00017
00018
00019
00020
00021
00022
00023
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
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
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
00066
00067
00068
00069 void CATRadioButton::Draw(CATImage* image, const CATRect& dirtyRect)
00070 {
00071 if (this->IsVisible() == false)
00072 {
00073 return;
00074 }
00075
00076
00077 CATRect imgRect(0,0,image->Width(), image->Height());
00078 CATASSERT(imgRect.Inside(dirtyRect), "Update rect is outside of img rect!");
00079
00080
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
00093 if (fImageOn)
00094 normal = fImageOn;
00095
00096
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
00120
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
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 }