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
CzActorImage.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(_CZ_ACTOR_IMAGE_H_)
00015 #define _CZ_ACTOR_IMAGE_H_
00016 
00017 #include "CzActor.h"
00018 #include "CzGeometry.h"
00019 
00020 /**
00021  @addtogroup Actors
00022  @{
00023  */
00024 
00025 /**
00026  @class CzActorImage
00027 
00028  @brief An image based game actor that can display a bitmap or portion of a bitmap.
00029 
00030  Image actors or actors derived from them form the backbone of most of the games and apps developed with XOML. An image actor is an actor that represents itself on screen using an image or
00031  portion of an image. All of the user interface actors are derived from an image actor. Image actors have the following specific properties:
00032  - Brush (brush) - Specifies a brush that is used to define the image and source rectangle
00033  - Image (image) - The image that is to be used as the actors visual (deprecated, use brushes instead, with exception to particle actors)
00034  - Size (x, y) - The world size of the actor
00035  - SrcRect (x, y, width, height) - The position and source of the source rectangle in the image atlas (x, y, w, h rect). Used for panning the portion of a sprite atlas shown allowing frame based animation. (deprecated, use brushes instead, with exception to particle actors)
00036  - Tiling (x, y) - Sets the UV tiling factor for this actor (default is 1,1), if tiling factor is > 1.0 on either axis then Tiled will automatically be set to true
00037  - Tiled (x, y) - Informs the system that this actor should be rendered with tiling enabled
00038  - FlipX (boolean) - If true then this actor is horizontally flipped
00039  - FlipY (boolean) - If true then this actor is vertically flipped
00040  - Skew (top, bottom, left, right) - Four parameter skewing, which allows the actor to be skewed in four different directions
00041  - BeforeChildren (boolean) - When set to true this actor will be rendered before its children, otherwise it will be rendered afterwards (default is true)
00042  - Filter (boolean) - When set to true this actor will rendered using filtering (default is true)
00043  - AlphaMode (alpha_mode) - Sets the mode to use when mixing transparency (alpha) from the image. AlphaMode can be one of none, half, add, sub and blend (default mode is blend)
00044  - AspectLock (lock_mode) - Locks the aspect ratio of the actor to fit to the screens aspect ratio lock_mode can be one of x, y or none (default is none) Notes:
00045  - Anchor (topleft or centre) - Sets the draw anchor (topleft causes the actor to be displayed relative to its top-left cornr whilst centre will use the actors centre)
00046 
00047  An image actor requires an Image or a Brush to be defined
00048  Because an image actor inherits from a basic actor, it inherits all of the basic actors properties as well as those properties shown above. Lets take a look at an image actor definition:
00049 
00050  @par XOML Example using brushes:
00051  @code
00052  <ActorImage Brush=”Brush1” Position="10, 20" Size="-100, -100" />
00053  @endcode
00054 
00055  @par XOML Example using image and src rectangle:
00056  @code
00057  <ActorImage Image=”Image1” SrcRect="0, 0, 64, 64" Position="10, 20" Size="-100, -100" />
00058  @endcode
00059 
00060  Note that it is usually much more convenient and better practice to define and use brushes instead of using image and bitmap source ractangles (the area opf the bitmap that will be drawn 
00061  onto the actor) as they can be re-used and easily modified later.
00062 
00063  */
00064 
00065 class CzActorImage : public CzActor
00066 {
00067     // Properties
00068 protected:
00069     CzGeometry*         Geometry;               ///< Visual geometry
00070 public:
00071     bool                setProperty(unsigned int property_name, const CzXomlProperty& data, bool delta);
00072     bool                setProperty(unsigned int property_name, const CzString& data, bool delta);
00073     bool                getProperty(unsigned int property_name, CzXomlProperty& prop);
00074     // Properties end
00075 protected:
00076     CzIVec2             OldSrcSize;
00077     bool                InitWithImage(CzImage* image, int width, int height);
00078     bool                InitWithBrush(IzBrush* brush, int width, int height);
00079     bool                UpdateBinding(unsigned int property_name, CzXomlVariable* var);
00080     void                UpdateAspect();
00081 public:
00082     CzActorImage() : CzActor(), Geometry(NULL)  { setActualClassType("actorimage"); }
00083     virtual ~CzActorImage()         {}
00084 
00085     virtual bool        Init(IzBrush* brush, int width, int height);
00086     virtual bool        Init(CzImage* image, int width, int height);
00087     virtual bool        Init(CzImage* image, CzIRect* src_rect);
00088     virtual bool        Init(CzImage* image, int x, int y, int w, int h);
00089     bool                UpdateVisual();
00090 
00091     void                SetSrcDest(int x, int y, int w, int h);
00092     void                SetSrcRect(int x, int y, int w, int h);
00093     void                SetDestSize(int w, int h);
00094     virtual void        SetImage(CzImage* image);
00095     virtual void        SetFromBrush(IzBrush* brush, bool resize = true);
00096     CzGeometry*         getGeometry()           { return Geometry; }
00097     void                setGeometry(CzGeometry* geom);
00098 
00099     // Event handlers
00100     virtual void        NotifyOrientationChange(CzScene::eOrientation old_orientation, CzScene::eOrientation new_orientation);
00101 
00102     // Implementation of IzXomlClass interface
00103     int                 LoadFromXoml(IzXomlResource* parent, bool load_children, CzXmlNode* node);
00104 
00105     // Implementation of IzAnimTarget interface
00106     bool                UpdateFromAnimation(CzAnimInstance *animation);
00107 
00108     // Internal (used by XOML system to setup and cleanup the XOML class properties system
00109 protected:
00110     static CzXomlClassDef*  ActorImageClassDef;                             // XOML class definition
00111 
00112 public:
00113     static void             InitClass();
00114     static void             ReleaseClass();
00115 
00116     static bool             _setSize(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00117     static CzXomlProperty   _getSize(IzXomlResource* target);
00118     static bool             _setSrcRect(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00119     static CzXomlProperty   _getSrcRect(IzXomlResource* target);
00120     static bool             _setSrcTiling(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00121     static CzXomlProperty   _getSrcTiling(IzXomlResource* target);
00122     static bool             _setSrcTiled(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00123     static CzXomlProperty   _getSrcTiled(IzXomlResource* target);
00124     static bool             _setImage(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00125     static CzXomlProperty   _getImage(IzXomlResource* target);
00126     static bool             _setBrush(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00127     static CzXomlProperty   _getBrush(IzXomlResource* target);
00128     static bool             _setFlipX(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00129     static CzXomlProperty   _getFlipX(IzXomlResource* target);
00130     static bool             _setFlipY(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00131     static CzXomlProperty   _getFlipY(IzXomlResource* target);
00132     static bool             _setSkew(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00133     static CzXomlProperty   _getSkew(IzXomlResource* target);
00134     static bool             _setBeforeChildren(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00135     static CzXomlProperty   _getBeforeChildren(IzXomlResource* target);
00136     static bool             _setFilter(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00137     static CzXomlProperty   _getFilter(IzXomlResource* target);
00138     static bool             _setAspectLock(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00139     static CzXomlProperty   _getAspectLock(IzXomlResource* target);
00140     static bool             _setAlphaMode(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00141     static CzXomlProperty   _getAlphaMode(IzXomlResource* target);
00142     static bool             _setGeometry(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00143     static CzXomlProperty   _getGeometry(IzXomlResource* target);
00144 };
00145 
00146 /// @}
00147 
00148 
00149 /**
00150  @class CzActorImageCreator
00151 
00152  @brief Creates an instance of an image based actor object.
00153 
00154  Used by the XOML system to instantiate a CzActorImage object.
00155 
00156  */
00157 
00158 class CzActorImageCreator : public IzXomlClassCreator
00159 {
00160 public:
00161     CzActorImageCreator()
00162     {
00163         setClassName("actorimage");
00164     }
00165     IzXomlResource* CreateInstance(IzXomlResource* parent)  { return new CzActorImage(); }
00166 };
00167 
00168 
00169 
00170 #endif // _CZ_ACTOR_IMAGE_H_