AppEasy Core SDK
1.5.0
Cross platform mobile and desktop app and game development SDK - The easy way to make apps
|
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_EVENTS_H_) 00015 #define _CZ_EVENTS_H_ 00016 00017 #include "CzUtil.h" 00018 #include "CzXoml.h" 00019 00020 /** 00021 @addtogroup Core 00022 @{ 00023 */ 00024 00025 /** 00026 @struct CzEvent 00027 00028 @brief Represents a named event with an actions list. 00029 00030 An event is something that occurs in your app that you may or may not want to know about and act upon. For example, when the scene is first created the OnCreate event is raised. 00031 Using actions (explained in CzAction) you can react to these events and modify your apps behaviour. 00032 00033 CzEvent binds a named event with an actions list that will be called when the event takes place. All classes that benefit from receiving events from XOML contain a CzEventManager 00034 which handles the binding of named events to actions lists. Lets take a look at q quick XOML example: 00035 00036 @code 00037 <Label Position="-200, 0" Size="150, 75" Font="serif" Background="Button1Brush" Text="Rock" OnTapped="Selected"> 00038 <Actions Name="Selected"> 00039 <Action Method="SetVar" Param1="Selected" Param2="0"/> 00040 <Action Method="ChangeProgram" Param1="Main" Param2="start"/> 00041 </Actions> 00042 </Label> 00043 @endcode 00044 00045 In the above example we create a label actor that handles the OnTapped event. When the user taps this label actor it will raise the OnTapped event from CzActor::NotifyTapped) by 00046 calling ProcessEventActions(CzHashes::OnTapped_Hash). CzActor::ProcessEventActions() will search the actors events list to see if it is subsribed to the OnTapped event in XOML and 00047 if it is then the asociated actions list will be called. In the above example it has the "Selected" actions list mapped to the OnTapped event so this will be called. 00048 00049 Note that any class that can raise an OnXXXX event implements a method to raise the event called NotifyXXXX. 00050 00051 00052 */ 00053 00054 struct CzEvent 00055 { 00056 unsigned int EventName; ///< Event method name as a string hash 00057 unsigned int ActionsName; ///< Name of Actions collection as a string hash, to perform when event occurs 00058 //#if defined(_DEBUG) 00059 CzString _EventName; ///< Event method name (e.g. OnResume, OnTapped) 00060 CzString _ActionsName; ///< Name of Actions collection to perform when event occurs 00061 //#endif //_DEBUG 00062 }; 00063 00064 /** 00065 @class CzEventManager 00066 00067 @brief Manages a collection of events. 00068 00069 An events manager handles the mapping of a collection of events to action lists. Any XOML object that can potentially raise an event has an events manager, this includes: 00070 - CzActor derived actors - Raises events such as OnTapped, OnCreate etc.. 00071 - CzScene derived scenes - Raises events such as OnCreate, OnOrientationChange etc.. 00072 - CzAnimInstance - Raises events such as OnStart, OnEnd etc.. 00073 - CzRemoteReq - Raises events such as OnResponse, OnError etc.. 00074 - CzVideoCam - Raises events such as OnError 00075 - CzMarket - Raises events such as OnComplete, OnBillingDisabled etc.. 00076 00077 00078 */ 00079 00080 class CzEventManager 00081 { 00082 public: 00083 // Public access to event iteration 00084 typedef CzList<CzEvent*>::iterator _Iterator; 00085 _Iterator begin() { return Events.begin(); } 00086 _Iterator end() { return Events.end(); } 00087 protected: 00088 CzList<CzEvent*> Events; 00089 public: 00090 CzEventManager() {} 00091 virtual ~CzEventManager(); 00092 00093 void addEvent(const char* event_name, const char* actions_name, bool replace = false); 00094 void addEvent(CzEvent* evt); 00095 CzEvent* findEvent(unsigned int event_name_hash); 00096 }; 00097 00098 /// @} 00099 00100 00101 #endif // _CZ_EVENTS_H_