- Main Page
- Classes
- Files
- Directories
- Related Pages

# boxresource.h

    00001 /*--License:
    00002         Kyra Sprite Engine
    00003         Copyright Lee Thomason (Grinning Lizard Software) 2001-2005
    00004         www.grinninglizard.com/kyra
    00005         www.sourceforge.net/projects/kyra
    00006
    00007         Kyra is provided under the LGPL.
    00008
    00009         I kindly request you display a splash screen (provided in the HTML documentation)
    00010         to promote Kyra and acknowledge the software and everyone who has contributed to it,
    00011         but it is not required by the license.
    00012
    00013 --- LGPL License --
    00014
    00015     This library is free software; you can redistribute it and/or
    00016     modify it under the terms of the GNU Lesser General Public
    00017     License as published by the Free Software Foundation; either
    00018     version 2.1 of the License, or (at your option) any later version.
    00019
    00020     This library is distributed in the hope that it will be useful,
    00021     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00022     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00023     Lesser General Public License for more details.
    00024
    00025     You should have received a copy of the GNU Lesser General Public
    00026     License along with this library; if not, write to the Free Software
    00027     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00028
    00029         The full text of the license can be found in lgpl.txt
    00030 */
    00031
    00032 #ifndef KYRA_BOXRESOURCE_INCLUDED
    00033 #define KYRA_BOXRESOURCE_INCLUDED
    00034
    00035 #include "kyraresource.h"
    00036 #include "../engine/krmath.h"
    00037 #include "../util/glcirclelist.h"
    00038 #include "color.h"
    00039
    00040 class KrBox;
    00041 struct KrPaintInfo;
    00042
    00043
    00049 class KrBoxResource : public KrResource
    00050 {
    00051   public:
    00069         KrBoxResource(  const std::string& name,
    00070                                         int width,
    00071                                         int height,
    00072                                         const KrRGBA* colorArray,
    00073                                         int numColors,
    00074                                         int boxtype );
    00075
    00076         virtual ~KrBoxResource()                                {}
    00077
    00078         enum
    00079         {
    00080                 OUTLINE,
    00081                 FILL,
    00082                 CROSSHAIR
    00083         };
    00084
    00085         enum {
    00086                 COLOR_ARRAY_SIZE = 4,
    00087                 MASK = 3,
    00088         };
    00089
    00090         virtual U32 Type()                                              { return KYRATAG_BOX; }
    00091         virtual const std::string&      TypeName()      { return boxName; }
    00092         virtual KrBoxResource* ToBoxResource()  { return this; }
    00093
    00094         int     Width() const                           { return width; }
    00095         int             Height() const                          { return height; }
    00096         const KrRGBA* ColorArray() const        { return colorArray; }
    00097         int             BoxType() const                         { return boxtype; }
    00098
    00099         /*  Draw a box resource.
    00100                 @param  paintInfo       Information about the target surface for drawing (optimizing).
    00101                 @param  x                       X location in pixels.
    00102                 @param  y                       Y location in pixels.
    00103                 @param  cForm           Color transformation applied to the drawing.
    00104                 @param  clip            A clipping rectangle, which can be null.
    00105         */
    00106         void Draw( KrPaintInfo* paintInfo,
    00107                            const KrMatrix2& matrix,
    00108                            const KrColorTransform& cForm,
    00109                            const grinliz::Rectangle2I& clipping );
    00110
    00111         /*  Do a HitTest (see KrImageTree::HitTest) in transformed
    00112                 coordinates. So the tree object that made this call
    00113                 has already transformed the x and y into local pixel coords.
    00114         */
    00115         bool HitTestTransformed( int x, int y, int hitFlags );
    00116
    00117         /*      Given a hotspot x and y, and scale factors,
    00118                 return the bounding box for the box resource.
    00119         */
    00120         void CalculateBounds( const KrMatrix2& matrix,
    00121                                                   grinliz::Rectangle2I* bounds ) const;
    00122
    00123   private:
    00124         void DrawOpenGL(KrPaintInfo* paintInfo,
    00125                                         const KrMatrix2& matrix,
    00126                                         const KrColorTransform& cForm,
    00127                                         const grinliz::Rectangle2I& clipping );
    00128
    00129         static const std::string boxName;
    00130         static int boxId;
    00131
    00132         KrRGBA  colorArray[COLOR_ARRAY_SIZE];
    00133         int             width;
    00134         int             height;
    00135         int             boxtype;
    00136         bool    sourceAlpha;    // is there alpha in our colorArray?
    00137 };
    00138
    00139
    00140 #endif