AppEasy Core SDK  1.5.0
Cross platform mobile and desktop app and game development SDK - The easy way to make apps
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines
CzBrush.h
Go to the documentation of this file.
00001 // 
00002 //
00003 // AppEasy SDK - Cross Platform Multi-purpose Game and App Engine
00004 //
00005 // Developed by Matthew Hopwood of Pocketeers Limited - www.pocketeers.co.uk
00006 //
00007 // For updates, tutorials and more details check out www.appeasymobile.com
00008 //
00009 // This code is provided free of charge and without any warranty whatsoever. You must ensure that this whole notice is present in all files and derivatives, so the reader knows its origin.
00010 // If you use this SDK in your product then please ensure that you credit AppEasy's usage appropriately. Please see www.appeasymobile.com for licensing details and support
00011 //
00012 //
00013 
00014 #if !defined(_CCZ_BRUSH_H_)
00015 #define _CCZ_BRUSH_H_
00016 
00017 #include "CzUtil.h"
00018 #include "CzXoml.h"
00019 #include "CzImage.h"
00020 
00021 //
00022 //
00023 //
00024 //
00025 // IzBrush - Base class for all brushes
00026 //
00027 //
00028 //
00029 //
00030 class IzBrush : public IzXomlResource
00031 {
00032 public:
00033     enum eBrushType
00034     {
00035         BT_None, 
00036         BT_Solid, 
00037         BT_Gradient, 
00038         BT_Image, 
00039         BT_9Patch, 
00040     };
00041 
00042     // Properties
00043 protected:
00044     eBrushType          BrushType;
00045 public:
00046     void                setBrushType(eBrushType type)       { BrushType = type; }
00047     eBrushType          getBrushType() const                { return BrushType; }
00048     // Properties End
00049 protected:
00050 
00051 public:
00052     IzBrush() : IzXomlResource()    { setClassType("brush"); setBrushType(BT_None); }
00053     ~IzBrush() {}
00054 
00055     // Implementation of IzXomlResource interface
00056     int                 LoadFromXoml(IzXomlResource* parent, bool load_children, CzXmlNode* node);
00057 };
00058 
00059 //
00060 //
00061 //
00062 //
00063 // CzBrushSolid - Represents a solid colour brush
00064 //
00065 //
00066 //
00067 //
00068 class CzBrushSolid : public IzBrush
00069 {
00070     // Properties
00071 protected:
00072     CzColour        Colour;
00073 public:
00074     void            setColour(uint8 r, uint8 g, uint8 b, uint8 a)   { Colour.r = r; Colour.g = g; Colour.b = b; Colour.a = a; }
00075     void            setColour(const CzColour& colour)               { Colour = colour; }
00076     CzColour        getColour() const                               { return Colour; }
00077     // Properties End
00078 protected:
00079 
00080 public:
00081     CzBrushSolid() : IzBrush()  {  setBrushType(BT_Solid); }
00082 
00083 };
00084 
00085 //
00086 //
00087 //
00088 //
00089 // CzBrushGradient - Represents a gradient colour brush
00090 //
00091 //
00092 //
00093 //
00094 struct CzBrushGradientStop
00095 {
00096     CzColour        Colour;
00097     float           offset;
00098 };
00099 
00100 class CzBrushGradient : public IzBrush
00101 {
00102 public:
00103     // Public access to gradient stops iteration
00104     typedef CzList<CzBrushGradientStop*>::iterator _Iterator;
00105     _Iterator                   begin() { return Stops.begin(); }
00106     _Iterator                   end() { return Stops.end(); }
00107     // Properties
00108 protected:
00109     CzList<CzBrushGradientStop*>    Stops;
00110 public:
00111     void                        addStop(CzBrushGradientStop* stop)  { Stops.push_back(stop); }
00112     // Properties End
00113 protected:
00114 
00115 public:
00116     CzBrushGradient() : IzBrush()   { setBrushType(BT_Gradient); }
00117 
00118 };
00119 
00120 //
00121 //
00122 //
00123 //
00124 // CzBrushImage - Represents an image brush
00125 //
00126 //
00127 //
00128 //
00129 class CzBrushImage : public IzBrush
00130 {
00131     // Properties
00132 protected:
00133     CzImage*            Image;                  // Image used to render this brush
00134     CzIRect             SrcRect;                // Rectangular area od source image used to ggenerate UV coordinates
00135     CzVec2*             UVList;                 // UVList, if present then SrcRect is ignored
00136 public:
00137     void                setImage(CzImage* image)                { Image = image; }
00138     CzImage*            getImage()                              { return Image; }
00139     void                setSrcRect(int x, int y, int w, int h)  { SrcRect.x = x; SrcRect.y = y; SrcRect.w = w; SrcRect.h = h; }
00140     void                setSrcRect(const CzIRect& rect)         { SrcRect = rect; }
00141     CzIRect             getSrcRect() const                      { return SrcRect; }
00142     void                setUVList(CzVec2* uvs)                  { SAFE_DELETE_ARRAY(UVList); UVList = uvs; }
00143     CzVec2*             getUVList()                             { return UVList; }
00144     // Properties End
00145 protected:
00146 
00147 public:
00148     CzBrushImage() : IzBrush(), Image(NULL), UVList(NULL) { setBrushType(BT_Image); }
00149     ~CzBrushImage()
00150     {
00151         SAFE_DELETE_ARRAY(UVList);
00152     }
00153 
00154 };
00155 
00156 //
00157 //
00158 //
00159 //
00160 // CzBrushImage9 - Represents a 9 patch style image brush
00161 //
00162 //
00163 //
00164 //
00165 class CzBrushImage9 : public CzBrushImage
00166 {
00167     // Properties
00168 protected:
00169     CzIRect             ScaleArea;
00170 public:
00171     void                setScalableArea(int x, int y, int w, int h) { ScaleArea.x = x; ScaleArea.y = y; ScaleArea.w = w; ScaleArea.h = h; }
00172     void                setScalableArea(const CzIRect &rc)          { ScaleArea = rc; }
00173     CzIRect             getScalableArea() const                     { return ScaleArea; }
00174     // Properties End
00175 protected:
00176 
00177 public:
00178     CzBrushImage9() : CzBrushImage(), ScaleArea(0, 0, 0, 0) { setBrushType(BT_9Patch); }
00179 
00180 };
00181 
00182 
00183 
00184 //
00185 //  CzBrushCreator - Creates an instance of a brush object
00186 //
00187 class CzBrushCreator : public IzXomlClassCreator
00188 {
00189 public:
00190     CzBrushCreator()
00191     {
00192         setClassName("brush");
00193     }
00194     IzXomlResource* CreateInstance(IzXomlResource* parent)  { return new IzBrush(); }
00195 };
00196 
00197 //
00198 //
00199 //
00200 //
00201 //  Helper macros
00202 //
00203 //
00204 //
00205 //
00206 
00207 #define CZ_NEW_IMAGE_BRUSH(brush, name, image, src_rect)    \
00208     CzBrushImage* brush = new CzBrushImage();               \
00209     brush->setName(name);                                   \
00210     brush->setImage(image);                                 \
00211     brush->setSrcRect(src_rect);
00212     
00213 #define CZ_NEW_IMAGE9_BRUSH(brush, name, image, src_rect, scale_area)   \
00214     CzBrushImage9* brush = new CzBrushImage9();                         \
00215     brush->setName(name);                                               \
00216     brush->setImage(image);                                             \
00217     brush->setSrcRect(src_rect);                                        \
00218     brush->setScalableArea(scale_area);
00219 
00220 
00221 
00222 #endif  // _CCZ_BRUSH_H_