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
CzActorConnector.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_CONNECTOR_H_)
00015 #define _CZ_ACTOR_CONNECTOR_H_
00016 
00017 #include "CzActorImage.h"
00018 
00019 /**
00020  @addtogroup Actors
00021  @{
00022  */
00023 
00024 /**
00025  @class CzActorConnector
00026 
00027  @brief An actor that connects two points or two actors together like a string.
00028 
00029  A connector actor is an image actor that connects either two actors together or an actor to an anchor point. Connector actors are useful for creating all sorts of objects such as 
00030  strings and ropes.
00031 
00032  A connector actor is declared using the ActorConnector XOML tag. The ActorConnector example has been provided to show how they work. Lets take a quick look at some example XOML:
00033 
00034  @par XOML Example
00035  @code
00036 <ActorConnector Name="Joiner1" Size="100, 20" Brush="Button1Brush" TargetA="Box1" TargetB="Box2" />
00037  @endcode
00038 
00039  The above XOML creates a connector actor that connects Box1 and Box2 actors together using a visual connector that is 20 units in width and covers 100% of the length of the connector.
00040 
00041  In addition to basic actor properties connector actors have a number of new or changed properties, which include:
00042  - Size (length, width) - Size defines the width of the connector as well as the length as apercentage of the distance between the two end points of the connector. For example, if the 
00043  length is set to 100% then the actor will stretch from the centre of target A to the centre of target B. If the length is less than 100% then the actor will fall short of the centre 
00044  points of targets A and B;
00045  - TargetA (actor) - Defines the actor to fix the start point of the connector actor
00046  - TargetB (actor) - Defines the actor to fix the end point of the connector actor
00047  - OffsetA (x, y) - An amount to offset the connection point from Target A. If TargetA actor is not specified then this will be classed as a static scene position
00048  - OffsetB (x, y) - An amount to offset the connection point from Target B. If TargetB actor is not specified then this will be classed as a static scene position
00049 
00050  */
00051 
00052 class CzActorConnector : public CzActorImage
00053 {
00054 public:
00055 
00056 protected:
00057     // Properties
00058     CzActor*                TargetA;        ///< Target actor A
00059     CzActor*                TargetB;        ///< Target actor B
00060     CzVec2                  OffsetA;        ///< Target A offset
00061     CzVec2                  OffsetB;        ///< Target B offset
00062 public:
00063     void                    setTargetA(CzActor* target)             { TargetA = target; }
00064     CzActor*                getTargetA()                            { return TargetA; }
00065     void                    setTargetB(CzActor* target)             { TargetB = target; }
00066     CzActor*                getTargetB()                            { return TargetB; }
00067     void                    setOffsetA(float x, float y)            { OffsetA.x = x; OffsetA.y = y; }
00068     CzVec2                  getOffsetA() const                      { return OffsetA; }
00069     void                    setOffsetB(float x, float y)            { OffsetB.x = x; OffsetB.y = y; }
00070     CzVec2                  getOffsetB() const                      { return OffsetB; }
00071     bool                    getProperty(unsigned int property_name, CzXomlProperty& prop);
00072     bool                    setProperty(unsigned int property_name, const CzXomlProperty& data, bool delta);
00073     bool                    setProperty(unsigned int property_name, const CzString& data, bool delta);
00074     // Properties end
00075 
00076 protected:
00077     bool                    UpdateBinding(unsigned int property_name, CzXomlVariable* var);
00078 public:
00079     CzActorConnector() : CzActorImage(), TargetA(NULL), TargetB(NULL), OffsetA(0, 0), OffsetB(0, 0) {  setActualClassType("actorconnector"); }
00080 
00081     bool                    Update(float dt);
00082 
00083     // Implementation of IzXomlClass interface
00084     int                     LoadFromXoml(IzXomlResource* parent, bool load_children, CzXmlNode* node);
00085 
00086     bool                    UpdateFromAnimation(CzAnimInstance *animation);
00087 
00088     // Internal (used by XOML system to setup and cleanup the XOML class properties system
00089 protected:
00090     static CzXomlClassDef*  ActorConnectorClassDef;                             // XOML class definition
00091 
00092 public:
00093     static void             InitClass();
00094     static void             ReleaseClass();
00095     static bool             _setTargetA(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00096     static CzXomlProperty   _getTargetA(IzXomlResource* target);
00097     static bool             _setTargetB(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00098     static CzXomlProperty   _getTargetB(IzXomlResource* target);
00099     static bool             _setOffsetA(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00100     static CzXomlProperty   _getOffsetA(IzXomlResource* target);
00101     static bool             _setOffsetB(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00102     static CzXomlProperty   _getOffsetB(IzXomlResource* target);
00103 };
00104 
00105 /// @}
00106 
00107 
00108 /**
00109  @class CzActorConnectorCreator
00110 
00111  @brief Creates an instance of a CzActorConnctor object.
00112 
00113  Used by the XOML system to instantiate a CzActorConnector object.
00114 
00115  */
00116 
00117 class CzActorConnectorCreator : public IzXomlClassCreator
00118 {
00119 public:
00120     CzActorConnectorCreator()
00121     {
00122         setClassName("actorconnector");
00123     }
00124     IzXomlResource* CreateInstance(IzXomlResource* parent)  { return new CzActorConnector(); }
00125 };
00126 
00127 
00128 
00129 #endif // _CZ_ACTOR_CONNECTOR_H_