]> git.mxchange.org Git - simgear.git/blob - simgear/canvas/CanvasEvent.hxx
canvas::Text: add heightForWidth method.
[simgear.git] / simgear / canvas / CanvasEvent.hxx
1 // Canvas Event for event model similar to DOM Level 3 Event Model
2 //
3 // Copyright (C) 2012  Thomas Geymayer <tomgey@gmail.com>
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Library General Public
7 // License as published by the Free Software Foundation; either
8 // version 2 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 // Library General Public License for more details.
14 //
15 // You should have received a copy of the GNU Library General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA
18
19 #ifndef CANVAS_EVENT_HXX_
20 #define CANVAS_EVENT_HXX_
21
22 #include "canvas_fwd.hxx"
23 #include <boost/bimap.hpp>
24
25 namespace simgear
26 {
27 namespace canvas
28 {
29
30   class Event:
31     public SGReferenced
32   {
33     public:
34
35       enum Type
36       {
37         UNKNOWN,
38 #       define ENUM_MAPPING(name, str) name,
39 #         include "CanvasEventTypes.hxx"
40 #       undef ENUM_MAPPING
41         CUSTOM_EVENT ///< all user defined event types share the same id. They
42                      ///  are just differentiated by using the type string.
43       };
44
45       int               type;
46       ElementWeakPtr    target,
47                         current_target;
48       double            time;
49       bool              propagation_stopped;
50
51       Event();
52
53       // We need a vtable to allow nasal::Ghost to determine the dynamic type
54       // of the actual event instances.
55       virtual ~Event();
56
57       /**
58        * Get whether this events support bubbling
59        */
60       virtual bool canBubble() const;
61
62       /**
63        * Set type of event.
64        *
65        * If no such type exists it is registered.
66        */
67       void setType(const std::string& type);
68
69       int getType() const;
70       std::string getTypeString() const;
71
72       ElementWeakPtr getTarget() const;
73       ElementWeakPtr getCurrentTarget() const;
74
75       double getTime() const;
76
77       void stopPropagation();
78
79       static int getOrRegisterType(const std::string& type);
80       static int strToType(const std::string& type);
81       static std::string typeToStr(int type);
82
83     protected:
84       struct name {};
85       struct id {};
86       typedef boost::bimaps::bimap<
87         boost::bimaps::tagged<std::string, name>,
88         boost::bimaps::tagged<int, id>
89       > TypeMap;
90
91       static TypeMap& getTypeMap();
92
93   };
94
95 } // namespace canvas
96 } // namespace simgear
97
98 #endif /* CANVAS_EVENT_HXX_ */