00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "CATProgress.h"
00017 #include "CATApp.h"
00018 #include "CATWindow.h"
00019
00020
00021
00022
00023
00024
00025
00026
00027 CATProgress::CATProgress( const CATString& element,
00028 const CATString& rootDir)
00029 : CATControl(element, rootDir)
00030 {
00031 fImageOn = 0;
00032 fProgressStyle = CATPROGRESS_HORIZONTAL;
00033 }
00034
00035
00036
00037 bool CATProgress::IsFocusable() const
00038 {
00039 return false;
00040 }
00041
00042
00043
00044 CATProgress::~CATProgress()
00045 {
00046 if (fImageOn)
00047 {
00048 CATImage::ReleaseImage(fImageOn);
00049 }
00050 }
00051
00052
00053 CATResult CATProgress::ParseAttributes()
00054 {
00055 CATResult result = CATControl::ParseAttributes();
00056 CATResult tmpResult;
00057 CATString attrib;
00058
00059 attrib = GetAttribute(L"ImageOn");
00060 if (!attrib.IsEmpty())
00061 {
00062 tmpResult = LoadSkinImage(attrib,fImageOn);
00063 if (CATFAILED(tmpResult))
00064 result = tmpResult;
00065 }
00066
00067 attrib = GetAttribute(L"ProgressStyle");
00068 if (!attrib.IsEmpty())
00069 {
00070 if ( (attrib.GetWChar(0) | (char)0x20) == 'v')
00071 {
00072 fProgressStyle = CATPROGRESS_VERTICAL;
00073 }
00074 else
00075 {
00076 fProgressStyle = CATPROGRESS_HORIZONTAL;
00077 }
00078 }
00079
00080 return result;
00081 }
00082
00083
00084
00085
00086
00087
00088 void CATProgress::Draw(CATImage* image, const CATRect& dirtyRect)
00089 {
00090 if (this->IsVisible() == false)
00091 {
00092 return;
00093 }
00094
00095
00096 CATRect imgRect(0,0,image->Width(), image->Height());
00097 CATASSERT(imgRect.Inside(dirtyRect), "Update rect is outside of img rect!");
00098
00099
00100 CATRect drawRect;
00101 bool drawn = false;
00102
00103
00104
00105 if (this->fRect.Intersect(dirtyRect, &drawRect))
00106 {
00107 CATRect ourRect;
00108 if ( (this->IsEnabled() == false) && (this->fImageDisabled))
00109 {
00110 if (drawRect.Intersect(CATRect(fRect.left,
00111 fRect.top,
00112 fRect.left + this->fImageDisabled->Width(),
00113 fRect.top + this->fImageDisabled->Height()),
00114 &ourRect))
00115 {
00116 ourRect.Offset(-fRect.left, -fRect.top);
00117
00118 image->Overlay( this->fImageDisabled,
00119 drawRect.left,
00120 drawRect.top,
00121 ourRect.left,
00122 ourRect.top,
00123 ourRect.Width(),
00124 ourRect.Height());
00125 drawn = true;
00126 }
00127 }
00128
00129 if (!drawn)
00130 {
00131 CATRect normalRect = fRect;
00132 CATRect onRect = fRect;
00133
00134 if (this->fImage != 0)
00135 {
00136 if (drawRect.Intersect(normalRect,&ourRect))
00137 {
00138 ourRect.Offset(-fRect.left, -fRect.top);
00139
00140 image->Overlay( this->fImage,
00141 drawRect.left,
00142 drawRect.top,
00143 ourRect.left,
00144 ourRect.top,
00145 ourRect.Width(),
00146 ourRect.Height());
00147 drawn = true;
00148 }
00149 }
00150
00151
00152 if (this->fImageOn != 0)
00153 {
00154 CATRect tmpRect = drawRect;
00155 CATFloat32 drawPercent = this->GetValPercent();
00156
00157
00158 if (this->fProgressStyle == CATPROGRESS_HORIZONTAL)
00159 {
00160 onRect.right = (CATInt32)(onRect.left +
00161 ( CATMin(onRect.Width(), fImageOn->Width()) * drawPercent));
00162 }
00163 else
00164 {
00165 CATInt32 offset = (CATInt32)(fImageOn->Height() - (fImageOn->Height() * drawPercent));
00166 onRect.top += offset;
00167 tmpRect.top += offset;
00168 if (tmpRect.top > tmpRect.bottom)
00169 tmpRect.top = tmpRect.bottom;
00170 }
00171
00172 if (tmpRect.Intersect(onRect,&ourRect))
00173 {
00174 ourRect.Offset(-fRect.left, -fRect.top);
00175
00176 image->Overlay( this->fImageOn,
00177 tmpRect.left,
00178 tmpRect.top,
00179 ourRect.left,
00180 ourRect.top,
00181 ourRect.Width(),
00182 ourRect.Height());
00183 drawn = true;
00184 }
00185 }
00186 }
00187
00188 if (!drawn)
00189 {
00190
00191
00192 image->FillRect(drawRect, fBackgroundColor);
00193 }
00194 }
00195 }
00196
00197 CATResult CATProgress::Load( CATPROGRESSCB progressCB,
00198 void* progressParam,
00199 CATFloat32 progMin,
00200 CATFloat32 progMax)
00201 {
00202 CATResult result = CATControl::Load(progressCB, progressParam, progMin, progMax);
00203
00204 if (CATFAILED(result))
00205 {
00206 return result;
00207 }
00208
00209
00210 if (fImage != 0)
00211 {
00212 CATResult testResult = CAT_SUCCESS;
00213
00214 if (fImageOn)
00215 {
00216 testResult = CheckImageSize(fImageOn);
00217 if (testResult != CAT_SUCCESS)
00218 result = testResult;
00219 }
00220 }
00221
00222 return result;
00223 }
00224
00225
00226 void CATProgress::SetImages( CATImage* imageOn, CATImage* imageOff, CATImage* imageDisabled)
00227 {
00228 if (fImage)
00229 {
00230 CATImage::ReleaseImage(fImage);
00231 }
00232
00233 if (fImageOn)
00234 {
00235 CATImage::ReleaseImage(fImageOn);
00236 }
00237
00238 if (fImageDisabled)
00239 {
00240 CATImage::ReleaseImage(fImageDisabled);
00241 }
00242
00243 fImage = imageOff;
00244 fImageOn = imageOn;
00245 fImageDisabled = imageDisabled;
00246
00247 this->RectFromAttribs();
00248 this->MarkDirty();
00249 }
00250