Mercurial > fife-parpg
comparison engine/core/eventchannel/base/ec_event.h @ 0:4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
author | mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sun, 29 Jun 2008 18:44:17 +0000 |
parents | |
children | 90005975cdbb |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4a0efb7baf70 |
---|---|
1 /*************************************************************************** | |
2 * Copyright (C) 2005-2008 by the FIFE team * | |
3 * http://www.fifengine.de * | |
4 * This file is part of FIFE. * | |
5 * * | |
6 * FIFE is free software; you can redistribute it and/or modify * | |
7 * it under the terms of the GNU General Public License as published by * | |
8 * the Free Software Foundation; either version 2 of the License, or * | |
9 * (at your option) any later version. * | |
10 * * | |
11 * This program is distributed in the hope that it will be useful, * | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
14 * GNU General Public License for more details. * | |
15 * * | |
16 * You should have received a copy of the GNU General Public License * | |
17 * along with this program; if not, write to the * | |
18 * Free Software Foundation, Inc., * | |
19 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * | |
20 ***************************************************************************/ | |
21 /*************************************************************************** | |
22 * Note! FIFE event channel borrows heavily from ideas pf Guichan library * | |
23 * version 0.6 * | |
24 ***************************************************************************/ | |
25 | |
26 | |
27 #ifndef FIFE_EVENTCHANNEL_EVENT_H | |
28 #define FIFE_EVENTCHANNEL_EVENT_H | |
29 | |
30 // Standard C++ library includes | |
31 // | |
32 #include <string> | |
33 #include <sstream> | |
34 | |
35 // 3rd party library includes | |
36 // | |
37 #include <SDL.h> | |
38 | |
39 // FIFE includes | |
40 // These includes are split up in two parts, separated by one empty line | |
41 // First block: files included from the FIFE root src directory | |
42 // Second block: files included from the same folder | |
43 // | |
44 #include "eventchannel/source/ec_ieventsource.h" | |
45 | |
46 namespace gcn { | |
47 class Widget; | |
48 } | |
49 | |
50 namespace FIFE { | |
51 /** Base class for all events | |
52 */ | |
53 class Event { | |
54 public: | |
55 /** Constructor. | |
56 */ | |
57 Event(): | |
58 m_isconsumed(false), | |
59 m_eventsource(NULL), | |
60 m_timestamp(SDL_GetTicks()) {} | |
61 | |
62 /** Destructor. | |
63 */ | |
64 virtual ~Event() {} | |
65 | |
66 /** Marks the event as consumed. | |
67 */ | |
68 virtual void consume() { m_isconsumed = true; } | |
69 | |
70 /** Checks if the event is consumed. | |
71 * @return true if the event is consumed, false otherwise. | |
72 */ | |
73 virtual bool isConsumed() const { return m_isconsumed; } | |
74 | |
75 /** Gets the source of the event. | |
76 */ | |
77 virtual IEventSource* getSource() { return m_eventsource; } | |
78 | |
79 /** Sets the source of the event. | |
80 */ | |
81 virtual void setSource(IEventSource* source) { m_eventsource = source; } | |
82 | |
83 /** Get the source of the (widget) event. Null for non-widget. | |
84 * FIXME: This is a bit of a hack, using forward declared guichan pointer | |
85 * Should use something non-guichan specific | |
86 */ | |
87 virtual gcn::Widget* getSourceWidget() { return m_sourcewidget; } | |
88 | |
89 /** Set the source of the (widget) event. @see getSourceWidget | |
90 */ | |
91 virtual void setSourceWidget(gcn::Widget* widget) { m_sourcewidget = widget; } | |
92 | |
93 /** Gets the timestamp of the event | |
94 */ | |
95 virtual int getTimeStamp() const { return m_timestamp; } | |
96 | |
97 /** Sets the timestamp of the event | |
98 */ | |
99 virtual void setTimeStamp(int timestamp ) { m_timestamp = timestamp; } | |
100 | |
101 /** Gets the name of the event | |
102 */ | |
103 virtual const std::string& getName() const { | |
104 const static std::string eventName("Event"); | |
105 return eventName; | |
106 } | |
107 | |
108 /** Gets attribute string of the event | |
109 */ | |
110 virtual std::string getAttrStr() const { | |
111 std::stringstream ss; | |
112 ss << "consumed = " << m_isconsumed << ", "; | |
113 ss << "src = " << m_eventsource << ", "; | |
114 ss << "timestamp = " << m_timestamp; | |
115 return ss.str(); | |
116 } | |
117 | |
118 /** Gets the debugstring of the event | |
119 */ | |
120 virtual std::string getDebugString() const { | |
121 std::stringstream ss; | |
122 ss << getName() << std::endl; | |
123 ss << getAttrStr() << std::endl; | |
124 return ss.str(); | |
125 } | |
126 | |
127 private: | |
128 bool m_isconsumed; | |
129 IEventSource* m_eventsource; | |
130 gcn::Widget* m_sourcewidget; | |
131 int m_timestamp; | |
132 }; | |
133 | |
134 } //FIFE | |
135 | |
136 #endif |