00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "CATPictureMulti.h"
00016 #include "CATApp.h"
00017
00018
00019
00020
00021
00022
00023
00024 CATPictureMulti::CATPictureMulti(const CATString& element,
00025 const CATString& rootDir)
00026 : CATControl(element, rootDir)
00027 {
00028 fBackgroundColor = CATColor(0,0,255);
00029 fNumImages = 0;
00030 fValue = 0.0f;
00031 }
00032
00033
00034
00035 bool CATPictureMulti::IsFocusable() const
00036 {
00037 return false;
00038 }
00039
00040
00041
00042 CATPictureMulti::~CATPictureMulti()
00043 {
00044
00045 CATImage *tmpImage = 0;
00046 while (CATSUCCEEDED(fMasterSet.Pop(tmpImage)))
00047 {
00048 CATImage::ReleaseImage(tmpImage);
00049 }
00050 }
00051
00052
00053 CATResult CATPictureMulti::ParseAttributes()
00054 {
00055 CATResult result = CATControl::ParseAttributes();
00056 CATString attrib;
00057
00058 fNumImages = GetAttribute(L"NumImage",fNumImages);
00059 CATUInt32 actualImages = 0;
00060
00061 for (CATUInt32 i = 0; i < fNumImages; i++)
00062 {
00063 CATResult tmpResult;
00064 CATString attribName;
00065 CATImage* tmpImage = 0;
00066
00067 attribName.Format(L"Image_%d",i+1);
00068 attrib = GetAttribute(attribName);
00069 if (!attrib.IsEmpty())
00070 {
00071 tmpResult = LoadSkinImage(attrib,tmpImage);
00072 if (CATFAILED(tmpResult))
00073 {
00074 result = tmpResult;
00075 }
00076 else
00077 {
00078 actualImages++;
00079 fImageList.push_back(tmpImage);
00080
00081 if (fImage == 0)
00082 fImage = tmpImage;
00083 else
00084 fMasterSet.Push(tmpImage);
00085 }
00086 }
00087 }
00088
00089 if (actualImages != fNumImages)
00090 {
00091 CATTRACE("Warning: Multi-Picture didn't have specified number of images.");
00092 fNumImages = actualImages;
00093 }
00094
00095 return result;
00096 }
00097
00098
00099
00100
00101
00102
00103 void CATPictureMulti::Draw(CATImage* image, const CATRect& dirtyRect)
00104 {
00105 if (this->IsVisible() == false)
00106 {
00107 return;
00108 }
00109
00110
00111 CATRect imgRect(0,0,image->Width(), image->Height());
00112 CATASSERT(imgRect.Inside(dirtyRect), "Update rect is outside of img rect!");
00113
00114
00115 CATRect drawRect;
00116 bool drawn = false;
00117
00118 CATUInt32 index = (CATUInt32)fValue;
00119
00120 if (index >= fNumImages)
00121 {
00122 CATASSERT(false,"Invalid value for PictureMulti.");
00123 index = 0;
00124 }
00125
00126 CATImage* normal = fImageList[index];
00127
00128 CATResult result = CAT_SUCCESS;
00129
00130
00131 if (this->fRect.Intersect(dirtyRect, &drawRect))
00132 {
00133 if (normal)
00134 {
00135 if ((normal->Width() == fRect.Width()) &&
00136 (normal->Height() == fRect.Height()))
00137 {
00138 CATRect ourRect = drawRect;
00139 ourRect.Offset(-fRect.left, -fRect.top);
00140
00141
00142 result = image->Overlay(normal,drawRect.left,drawRect.top,ourRect.left,ourRect.top,drawRect.Width(),drawRect.Height());
00143 }
00144 else
00145 {
00146
00147
00148 CATInt32 yPos = drawRect.top;
00149 CATInt32 totalHeight = drawRect.Height();
00150 CATInt32 offsetY = (yPos - fRect.top) % normal->Height();
00151
00152 while (totalHeight > 0)
00153 {
00154 CATInt32 xPos = drawRect.left;
00155 CATInt32 copyHeight = CATMin(normal->Height() - offsetY, totalHeight);
00156 CATInt32 totalWidth = drawRect.Width();
00157 CATInt32 offsetX = (xPos - fRect.left) % normal->Width();
00158
00159 while (totalWidth > 0)
00160 {
00161 CATInt32 copyWidth = CATMin(normal->Width() - offsetX, totalWidth);
00162 result = image->Overlay(normal,xPos,yPos,offsetX,offsetY,copyWidth,copyHeight);
00163 xPos += copyWidth;
00164 totalWidth -= copyWidth;
00165 offsetX = 0;
00166 }
00167
00168 offsetY = 0;
00169 yPos += copyHeight;
00170 totalHeight -= copyHeight;
00171 }
00172 }
00173 }
00174 else
00175 {
00176
00177 result = image->FillRect(drawRect,this->fBackgroundColor);
00178 }
00179 }
00180 }
00181