00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "CATSwitchMulti.h"
00017 #include "CATApp.h"
00018 #include "CATWindow.h"
00019
00020
00021
00022
00023
00024
00025
00026 CATSwitchMulti::CATSwitchMulti( const CATString& element,
00027 const CATString& rootDir)
00028 : CATControl(element, rootDir)
00029 {
00030 fValue = 0.0f;
00031 fNumImages = 0;
00032 fAutoIncrement = true;
00033 }
00034
00035
00036
00037 CATSwitchMulti::~CATSwitchMulti()
00038 {
00039 CATImage* tmpImage = 0;
00040
00041 while (CATSUCCEEDED(fMasterSet.Pop(tmpImage)))
00042 {
00043 CATImage::ReleaseImage(tmpImage);
00044 }
00045 }
00046
00047 void CATSwitchMulti::OnMouseClick()
00048 {
00049 if (fAutoIncrement)
00050 {
00051 fValue = fValue + 1;
00052
00053 if (fValue >= fNumImages)
00054 {
00055 fValue = 0.0f;
00056 }
00057 }
00058
00059 CATControl::OnMouseClick();
00060 }
00061
00062
00063 CATResult CATSwitchMulti::ParseAttributes()
00064 {
00065 CATResult result = CATControl::ParseAttributes();
00066 CATString attrib;
00067
00068 CATImage* tmpImage = 0;
00069
00070 fNumImages = GetAttribute(L"NumImage", fNumImages);
00071
00072 CATUInt32 actualImages = 0;
00073 for (CATUInt32 i = 0; i < fNumImages; i++)
00074 {
00075 CATResult tmpResult;
00076 CATString attribName;
00077
00078 attribName.Format("Image_%d",i+1);
00079 attrib = GetAttribute(attribName);
00080 if (!attrib.IsEmpty())
00081 {
00082 tmpResult = LoadSkinImage(attrib,tmpImage);
00083
00084 if (CATFAILED(tmpResult))
00085 {
00086 result = tmpResult;
00087 }
00088 else
00089 {
00090 actualImages++;
00091
00092 fImageList.push_back(tmpImage);
00093
00094 if (fImage == 0)
00095 fImage = tmpImage;
00096 else
00097 fMasterSet.Push(tmpImage);
00098 }
00099 }
00100
00101 attribName.Format(L"ImageDisabled_%d",i+1);
00102 attrib = GetAttribute(attribName);
00103 if (!attrib.IsEmpty())
00104 {
00105 tmpResult = LoadSkinImage(attrib,tmpImage);
00106
00107 if (CATFAILED(tmpResult))
00108 {
00109 result = tmpResult;
00110 }
00111 else
00112 {
00113 fImageDisabledList.push_back(tmpImage);
00114 fMasterSet.Push(tmpImage);
00115 }
00116 }
00117
00118 attribName.Format("ImagePressed_%d",i+1);
00119 attrib = GetAttribute(attribName);
00120 if (!attrib.IsEmpty())
00121 {
00122 tmpResult = LoadSkinImage(attrib,tmpImage);
00123
00124 if (CATFAILED(tmpResult))
00125 {
00126 result = tmpResult;
00127 }
00128 else
00129 {
00130 fImagePressedList.push_back(tmpImage);
00131 fMasterSet.Push(tmpImage);
00132 }
00133 }
00134
00135 attribName.Format("ImageFocus_%d",i+1);
00136 attrib = GetAttribute(attribName);
00137 if (!attrib.IsEmpty())
00138 {
00139 tmpResult = LoadSkinImage(attrib,tmpImage);
00140
00141 if (CATFAILED(tmpResult))
00142 {
00143 result = tmpResult;
00144 }
00145 else
00146 {
00147 fImageFocusList.push_back(tmpImage);
00148 fMasterSet.Push(tmpImage);
00149 }
00150 }
00151
00152 attribName.Format("ImageActive_%d",i+1);
00153 attrib = GetAttribute(attribName);
00154 if (!attrib.IsEmpty())
00155 {
00156 tmpResult = LoadSkinImage(attrib,tmpImage);
00157
00158 if (CATFAILED(tmpResult))
00159 {
00160 result = tmpResult;
00161 }
00162 else
00163 {
00164 fImageActiveList.push_back(tmpImage);
00165 fMasterSet.Push(tmpImage);
00166 }
00167 }
00168 }
00169
00170 if (actualImages != fNumImages)
00171 {
00172 CATTRACE("Warning: actual images != NumImages");
00173 fNumImages = actualImages;
00174 }
00175
00176 fAutoIncrement = GetAttribute(L"AutoIncrement", fAutoIncrement);
00177
00178 return result;
00179 }
00180
00181
00182
00183
00184
00185
00186 void CATSwitchMulti::Draw(CATImage* image, const CATRect& dirtyRect)
00187 {
00188 if (this->IsVisible() == false)
00189 {
00190 return;
00191 }
00192
00193
00194 CATRect imgRect(0,0,image->Width(), image->Height());
00195 CATASSERT(imgRect.Inside(dirtyRect), "Update rect is outside of img rect!");
00196
00197
00198 CATRect drawRect;
00199 bool drawn = false;
00200
00201 CATUInt32 index = (CATUInt32)fValue;
00202
00203 if (index >= fNumImages)
00204 {
00205 CATTRACE("Invalid value for multiswitch");
00206 index = 0;
00207 }
00208
00209
00210 CATImage* disabled = 0;
00211 CATImage* normal = 0;
00212 CATImage* pressed = 0;
00213 CATImage* focus = 0;
00214 CATImage* active = 0;
00215
00216
00217 if (index < fImageDisabledList.size())
00218 disabled = fImageDisabledList[index];
00219 if (index < fImageList.size())
00220 normal = fImageList[index];
00221 if (index < fImagePressedList.size())
00222 pressed = fImagePressedList[index];
00223 if (index < fImageFocusList.size())
00224 focus = fImageFocusList[index];
00225 if (index < fImageActiveList.size())
00226 active = fImageFocusList[index];
00227
00228
00229
00230
00231 if (this->fRect.Intersect(dirtyRect, &drawRect))
00232 {
00233 CATRect ourRect;
00234 if ( (this->IsEnabled() == false) && (disabled))
00235 {
00236 if (drawRect.Intersect(CATRect(fRect.left,
00237 fRect.top,
00238 fRect.left + disabled->Width(),
00239 fRect.top + disabled->Height()),
00240 &ourRect))
00241 {
00242 ourRect.Offset(-fRect.left, -fRect.top);
00243
00244 image->Overlay( disabled,
00245 drawRect.left,
00246 drawRect.top,
00247 ourRect.left,
00248 ourRect.top,
00249 ourRect.Width(),
00250 ourRect.Height());
00251 drawn = true;
00252 }
00253 }
00254 else
00255 {
00256 if (this->IsPressed() && (pressed))
00257 {
00258 if (drawRect.Intersect(CATRect(fRect.left,
00259 fRect.top,
00260 fRect.left + pressed->Width(),
00261 fRect.top + pressed->Height()),
00262 &ourRect))
00263 {
00264 ourRect.Offset(-fRect.left, -fRect.top);
00265
00266 image->Overlay( pressed,
00267 drawRect.left,
00268 drawRect.top,
00269 ourRect.left,
00270 ourRect.top,
00271 ourRect.Width(),
00272 ourRect.Height());
00273 drawn = true;
00274 }
00275 }
00276
00277 if ((!drawn) && (IsFocused() || IsPressed()) && (focus))
00278 {
00279 if (drawRect.Intersect(CATRect(fRect.left,
00280 fRect.top,
00281 fRect.left + focus->Width(),
00282 fRect.top + focus->Height()),
00283 &ourRect))
00284 {
00285 ourRect.Offset(-fRect.left, -fRect.top);
00286
00287 image->Overlay( focus,
00288 drawRect.left,
00289 drawRect.top,
00290 ourRect.left,
00291 ourRect.top,
00292 ourRect.Width(),
00293 ourRect.Height());
00294 drawn = true;
00295 }
00296 }
00297 if ((!drawn) && ( IsActive() ) && (active))
00298 {
00299 if (drawRect.Intersect(CATRect(fRect.left,
00300 fRect.top,
00301 fRect.left + active->Width(),
00302 fRect.top + active->Height()),
00303 &ourRect))
00304 {
00305 ourRect.Offset(-fRect.left, -fRect.top);
00306
00307 image->Overlay( active,
00308 drawRect.left,
00309 drawRect.top,
00310 ourRect.left,
00311 ourRect.top,
00312 ourRect.Width(),
00313 ourRect.Height());
00314 drawn = true;
00315 }
00316 }
00317 }
00318
00319 if ((!drawn) && (normal != 0))
00320 {
00321 if (drawRect.Intersect(CATRect(fRect.left,
00322 fRect.top,
00323 fRect.left + normal->Width(),
00324 fRect.top + normal->Height()),
00325 &ourRect))
00326 {
00327 ourRect.Offset(-fRect.left, -fRect.top);
00328
00329 image->Overlay( normal,
00330 drawRect.left,
00331 drawRect.top,
00332 ourRect.left,
00333 ourRect.top,
00334 ourRect.Width(),
00335 ourRect.Height());
00336 drawn = true;
00337 }
00338 }
00339
00340 if (!drawn)
00341 {
00342
00343
00344 image->FillRect(drawRect, fBackgroundColor);
00345 }
00346 }
00347 }
00348
00349 CATResult CATSwitchMulti::Load(CATPROGRESSCB progressCB,
00350 void* progressParam,
00351 CATFloat32 progMin,
00352 CATFloat32 progMax)
00353 {
00354 CATResult result = CATControl::Load(progressCB, progressParam, progMin, progMax);
00355 return result;
00356 }
00357
00358 CATString CATSwitchMulti::GetHint() const
00359 {
00360 CATString retString;
00361 retString = CATControl::GetHint();
00362 if (fShowHintValue)
00363 {
00364 retString << "( " << (CATUInt32)fValue << " )";
00365 }
00366 return retString;
00367 }
00368