00001 #ifndef CS_MESSAGE_H 00002 #define CS_MESSAGE_H 00003 00004 #include <vector> 00005 00006 class CSMessageDispatchable; 00007 00008 class CSTile; 00009 class CSSprite; 00010 00011 class CSMessage; 00012 class ActionMessage; 00013 class GameMessage; 00014 class SDLMessage; 00015 class InputMessage; 00016 class SpriteMessage; 00017 class GuiMessage; 00018 00019 //! Message Types 00020 const int ACTION_MESSAGE = 1; 00021 const int GAME_MESSAGE = 2; 00022 const int SDL_MESSAGE = 3; 00023 const int INPUT_MESSAGE = 4; 00024 const int SPRITE_MESSAGE = 5; 00025 const int GUI_MESSAGE = 6; 00026 00027 //! Message Sub-Types (SDL) 00028 const int SCREEN_CHANGED_MESSAGE = 1; 00029 00030 //! Message Sub-Types (Game) 00031 const int END_MESSAGE = 1; 00032 const int PAUSE_MESSAGE = 2; 00033 const int TOGGLE_FULLSCREEN_MESSAGE = 3; 00034 const int SPRITE_TILE_COLLISION_MESSAGE = 4; 00035 const int SPRITE_SPRITE_COLLISION_MESSAGE = 5; 00036 const int SPRITE_OUT_OF_BOUNDS_MESSAGE = 6; 00037 const int TOGGLE_GUI_MESSAGE = 7; 00038 const int LAST_GAME_MESSAGE = 10; 00039 00040 //! Message Sub-Types (Action) 00041 //! following must correspond to type definition 00042 //! in action file! 00043 const int DEFAULT_MESSAGE = 0; 00044 const int UP_MESSAGE = 1; 00045 const int DOWN_MESSAGE = 2; 00046 const int RIGHT_MESSAGE = 3; 00047 const int LEFT_MESSAGE = 4; 00048 const int FIRE_MESSAGE = 5; 00049 const int DEATH_MESSAGE = 6; 00050 00051 //! Message Sub-Types (INPUT) 00052 const int KEY_UP_MESSAGE = 1; 00053 const int KEY_DOWN_MESSAGE = 2; 00054 const int KEY_RIGHT_MESSAGE = 3; 00055 const int KEY_LEFT_MESSAGE = 4; 00056 const int KEY_FIRE_MESSAGE = 5; 00057 00058 //! Message SubSubType SPRITE_OUT_OF_BOUNDS_MESSAGE 00059 const int X_LOWER = 0; 00060 const int X_HIGHER = 1; 00061 const int Y_LOWER = 2; 00062 const int Y_HIGHER = 3; 00063 00064 //! Message Sub-Types (Sprite) 00065 const int SPRITE_STATE_CHANGE_MESSAGE = 1; 00066 const int SPRITE_ACTION_CHANGE_MESSAGE = 2; 00067 00068 //! Message Sub-Types (GUI_MESSAGE) 00069 const int MOUSE_MOTION_MESSAGE = 1; 00070 const int MOUSE_MOTION_LOST_MESSAGE = 2; 00071 const int MOUSE_BUTTON_PRESSED_MESSAGE = 3; 00072 const int MOUSE_BUTTON_RELEASED_MESSAGE = 4; 00073 00074 const int KEY_PRESSED_MESSAGE = 5; 00075 const int KEY_RELEASED_MESSAGE = 6; 00076 00077 const int FOCUS_LOST_MESSAGE = 7; 00078 const int FOCUS_GAINED_MESSAGE = 8; 00079 const int WINDOW_OPEN_MESSAGE = 9; 00080 const int WINDOW_CLOSE_MESSAGE = 10; 00081 00082 const int BUTTON_PRESSED_MESSAGE = 11; 00083 const int BUTTON_RELEASED_MESSAGE = 12; 00084 const int BUTTON_DRAGGED_MESSAGE = 13; 00085 const int CHECKBOX_CHANGED_MESSAGE = 14; 00086 00087 const int SCROLLBAR_POSITION_CHANGED_MESSAGE = 15; 00088 const int LIST_ITEM_SELECTED_MESSAGE = 16; 00089 const int COMBOBOX_ITEM_SELECTED_MESSAGE = 17; 00090 00091 const int MENUITEM_ACTIVATED_MESSAGE = 18; 00092 const int TEXT_CHANGED_MESSAGE = 19; 00093 00094 const int CLOSE_ACTION_ID = 0x1000; 00095 const int SCROLL_BUTTON_LESS_ACTION_ID = 0x1100; 00096 const int SCROLL_BUTTON_MORE_ACTION_ID = 0x1101; 00097 const int SCROLL_BUTTON_DRAG_ACTION_ID = 0x1102; 00098 00099 const int COMBOBOX_BUTTON_MORE_ACTION_ID = 0x1200; 00100 00101 /** 00102 The CSMessage class is the base class for messages. 00103 It might have been possible to use this class as an 00104 overall massage system. but due to non inheritable 00105 friend relations and data consistency 00106 (most set methods should only be accessable from the 00107 message initiator) the actual use of the class is like: 00108 00109 (Example from CSSprite) 00110 <PRE> 00111 class CSSprite : ... 00112 { 00113 ... 00114 public: 00115 class SpriteMessage: public CSMessage 00116 { 00117 friend CSSprite; 00118 }; 00119 SpriteMessage MESSAGE_SPRITE_NEXT_DEFAULT; 00120 ... 00121 }; 00122 </PRE> 00123 In the constructor of the message using class fixed messages 00124 might be pre-defined. 00125 That also meens, that messages are owned by the message - Source. 00126 And should never be freed from any place else! 00127 00128 ###################### 00129 00130 Also message types are defined here! 00131 (for now) 00132 */ 00133 class CSMessage 00134 { 00135 friend CSMessageDispatchable; 00136 protected: 00137 00138 CSMessageDispatchable *mOrigin; 00139 int mType; 00140 int mSubtype; 00141 int mSubsubtype; 00142 int mPriority; 00143 bool mIsDispatchAtOnce; 00144 bool mSuccess; 00145 00146 virtual void setType(int type){mType = type;} 00147 00148 public: 00149 bool mIsHandled; 00150 CSMessage() 00151 { 00152 mIsHandled = false; 00153 mSuccess = false; 00154 mOrigin = 0; 00155 mSubtype = 0; 00156 mSubsubtype = 0; 00157 mType = 0; 00158 mPriority = 0; 00159 mIsDispatchAtOnce = true; 00160 } 00161 00162 virtual ~CSMessage() {} 00163 00164 virtual void setSuccess(bool b) {mSuccess = b;} 00165 virtual void setOrigin(CSMessageDispatchable *origin) {mOrigin = origin;} 00166 virtual void setSubtype(int subtype){mSubtype = subtype;} 00167 virtual void setSubsubtype(int type){mSubsubtype = type;} 00168 virtual void setPriority(int priority){mPriority = priority;} 00169 virtual void setDispatchAtOnce(bool dispatchAtOnce){mIsDispatchAtOnce = dispatchAtOnce;} 00170 00171 virtual bool isSuccess() {return mSuccess;} 00172 virtual CSMessageDispatchable *getOrigin(){return mOrigin;} 00173 virtual int getSubtype(){return mSubtype;} 00174 virtual int getSubsubtype(){return mSubsubtype;} 00175 virtual int getType(){return mType;} 00176 virtual int getPriority(){return mPriority;} 00177 virtual bool isDispatchAtOnce(){return mIsDispatchAtOnce;} 00178 virtual void setHandled(bool isHandled){mIsHandled = isHandled;} 00179 bool isHandled(){return mIsHandled;} 00180 }; 00181 00182 class ActionMessage: public CSMessage 00183 { 00184 public: 00185 ActionMessage() {mType = ACTION_MESSAGE;} 00186 }; 00187 00188 class GameMessage: public CSMessage 00189 { 00190 public: 00191 CSSprite *sprite; 00192 CSSprite *other; 00193 std::vector<CSTile*> tiles; 00194 CSTile* tile; 00195 int pixels; 00196 int layer; 00197 00198 GameMessage() 00199 { 00200 mType = GAME_MESSAGE; 00201 sprite = 0; 00202 other = 0; 00203 pixels = 0; 00204 tile = 0; 00205 layer = -1; 00206 } 00207 }; 00208 00209 class SDLMessage: public CSMessage 00210 { 00211 public: 00212 SDLMessage() {mType = SDL_MESSAGE;} 00213 }; 00214 00215 class SpriteMessage: public CSMessage 00216 { 00217 public: 00218 int state; 00219 SpriteMessage() {mType = SPRITE_MESSAGE;} 00220 }; 00221 00222 class InputMessage: public CSMessage 00223 { 00224 public: 00225 InputMessage() {mType = INPUT_MESSAGE;} 00226 }; 00227 00228 class CSGrafikElement; 00229 class GuiMessage: public CSMessage 00230 { 00231 public: 00232 int selected; 00233 int start; 00234 int end; 00235 int screenX; 00236 int screenY; 00237 int receiverX; 00238 int receiverY; 00239 int deltaX; 00240 int deltaY; 00241 int button; 00242 int actionId; 00243 int keySymbolic; 00244 int keyUnicodeChar; 00245 bool newCheckBoxState; 00246 CSGrafikElement *sender; 00247 CSGrafikElement *receiver; 00248 CSGrafikElement *downReceiver; 00249 GuiMessage() 00250 { 00251 mType = GUI_MESSAGE; 00252 selected = 0; 00253 start = 0; 00254 end = 0; 00255 screenX = 0; 00256 screenY = 0; 00257 receiverX = 0; 00258 receiverY = 0; 00259 deltaX = 0; 00260 deltaY = 0; 00261 button = 0; 00262 actionId = 0; 00263 keySymbolic = 0; 00264 keyUnicodeChar = 0; 00265 newCheckBoxState = false; 00266 sender = 0; 00267 receiver = 0; 00268 downReceiver = 0; 00269 } 00270 }; 00271 00272 #endif // CS_MESSAGE_H 00273 00274