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

CATPicture.cpp

Go to the documentation of this file.
00001 //---------------------------------------------------------------------------
00002 /// \file CATPicture.cpp
00003 /// \brief Static picture for GUI
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 "CATPicture.h"
00016 
00017 //---------------------------------------------------------------------------
00018 // CATPicture 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 CATPicture::CATPicture(const CATString&             element, 
00025                        const CATString&             rootDir)
00026                        : CATControl(element,  rootDir)
00027 {
00028     fBackgroundColor = CATColor(0,0,255);
00029     fValue = 0.0f;  
00030 }
00031 
00032 /// IsFocusable() returns true if the control can receive
00033 /// focus, and false otherwise.
00034 bool CATPicture::IsFocusable() const
00035 {
00036     return false;
00037 }
00038 //---------------------------------------------------------------------------
00039 /// CATPicture destructor
00040 //---------------------------------------------------------------------------
00041 CATPicture::~CATPicture()
00042 {
00043 
00044 }
00045 
00046 //---------------------------------------------------------------------------
00047 // Draw() draws the control into the parent window
00048 // \param dirtyRect - portion of control (in window coordinates)
00049 //        that requires redrawing.
00050 //---------------------------------------------------------------------------
00051 void CATPicture::Draw(CATImage* image, const CATRect& dirtyRect)
00052 {
00053     if (this->IsVisible() == false)
00054     {
00055         return;
00056     }
00057 
00058     // sanity check parent image / dirty rectangle
00059     CATRect imgRect(0,0,image->Width(), image->Height());
00060     CATASSERT(imgRect.Inside(dirtyRect), "Update rect is outside of img rect!");
00061 
00062     // Find intersection between dirty rect and us
00063     CATRect drawRect;
00064     bool   drawn = false;
00065 
00066     CATResult result = CAT_SUCCESS;
00067     // By default, CATPicture tiles similarly to the window background if the
00068     // rectangles don't fit.
00069     if (this->fRect.Intersect(dirtyRect, &drawRect))
00070     {  
00071         if (fImage)
00072         {
00073             if ((fImage->Width() == fRect.Width()) && 
00074                 (fImage->Height() == fRect.Height()))
00075             {
00076                 CATRect ourRect = drawRect;
00077                 ourRect.Offset(-fRect.left, -fRect.top);
00078                 // Picture is the size of the rect, so just draw the
00079                 // portion that's dirty.
00080                 result = image->Overlay(fImage,drawRect.left,drawRect.top,ourRect.left,ourRect.top,drawRect.Width(),drawRect.Height());
00081             }
00082             else
00083             {
00084                 // OK... gotta do tiling of the picture, but only within the
00085                 // rectangle.
00086                 CATInt32 yPos = drawRect.top;
00087                 CATInt32 totalHeight = drawRect.Height();
00088                 CATInt32 offsetY = (yPos - fRect.top) % fImage->Height();
00089 
00090                 while (totalHeight > 0)
00091                 {
00092                     CATInt32 xPos = drawRect.left;
00093                     CATInt32 copyHeight = CATMin(fImage->Height() - offsetY, totalHeight);
00094                     CATInt32 totalWidth = drawRect.Width();
00095                     CATInt32 offsetX = (xPos - fRect.left) % fImage->Width();
00096 
00097                     while (totalWidth > 0)
00098                     {
00099                         CATInt32 copyWidth = CATMin(fImage->Width() - offsetX, totalWidth);               
00100                         result = image->Overlay(fImage,xPos,yPos,offsetX,offsetY,copyWidth,copyHeight);
00101                         xPos += copyWidth;
00102                         totalWidth -= copyWidth;
00103                         offsetX = 0;
00104                     }
00105 
00106                     offsetY = 0;
00107                     yPos += copyHeight;
00108                     totalHeight -= copyHeight;
00109                 }
00110             }
00111         }
00112         else
00113         {
00114             // No image - 
00115             result = image->FillRect(drawRect,this->fBackgroundColor);
00116         }
00117     }
00118 }
00119 

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