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

CATPictureMulti.cpp

Go to the documentation of this file.
00001 //---------------------------------------------------------------------------
00002 /// \file CATPictureMulti.cpp
00003 /// \brief Multiple pictures (like switch multi, but no mouse interaction)
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 "CATPictureMulti.h"
00016 #include "CATApp.h"
00017 //---------------------------------------------------------------------------
00018 // CATPictureMulti constructor (inherited from CATControl->CATXMLObject)
00019 // \param element - Type name ("Picture")
00020 // \param attribs - attribute information for the window
00021 // \param parent - parent XML object (should be a "Window" element)
00022 // \param rootDir - root directory of skin for bin/png loads
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 /// IsFocusable() returns true if the control can receive
00034 /// focus, and false otherwise.
00035 bool CATPictureMulti::IsFocusable() const
00036 {
00037     return false;
00038 }
00039 //---------------------------------------------------------------------------
00040 /// CATPictureMulti destructor
00041 //---------------------------------------------------------------------------
00042 CATPictureMulti::~CATPictureMulti()
00043 {
00044     // Let parent release fImage!
00045     CATImage *tmpImage = 0;
00046     while (CATSUCCEEDED(fMasterSet.Pop(tmpImage)))
00047     {
00048         CATImage::ReleaseImage(tmpImage);
00049     }
00050 }
00051 
00052 /// ParseAttributes() parses the known attributes for an object.
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 // Draw() draws the control into the parent window
00100 // \param dirtyRect - portion of control (in window coordinates)
00101 //        that requires redrawing.
00102 //---------------------------------------------------------------------------
00103 void CATPictureMulti::Draw(CATImage* image, const CATRect& dirtyRect)
00104 {
00105     if (this->IsVisible() == false)
00106     {
00107         return;
00108     }
00109 
00110     // sanity check parent image / dirty rectangle
00111     CATRect imgRect(0,0,image->Width(), image->Height());
00112     CATASSERT(imgRect.Inside(dirtyRect), "Update rect is outside of img rect!");
00113 
00114     // Find intersection between dirty rect and us
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     // By default, CATPictureMulti tiles similarly to the window background if the
00130     // rectangles don't fit.
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                 // Picture is the size of the rect, so just draw the
00141                 // portion that's dirty.
00142                 result = image->Overlay(normal,drawRect.left,drawRect.top,ourRect.left,ourRect.top,drawRect.Width(),drawRect.Height());
00143             }
00144             else
00145             {
00146                 // OK... gotta do tiling of the picture, but only within the
00147                 // rectangle.
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             // No image - 
00177             result = image->FillRect(drawRect,this->fBackgroundColor);
00178         }
00179     }
00180 }
00181 

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