]> git.mxchange.org Git - simgear.git/blob - simgear/canvas/events/CustomEvent.hxx
Add simple keyboard event demo application.
[simgear.git] / simgear / canvas / events / CustomEvent.hxx
1 ///@file
2 /// Canvas user defined event
3 //
4 // Copyright (C) 2014  Thomas Geymayer <tomgey@gmail.com>
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Library General Public
8 // License as published by the Free Software Foundation; either
9 // version 2 of the License, or (at your option) any later version.
10 //
11 // This library 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 GNU
14 // Library General Public License for more details.
15 //
16 // You should have received a copy of the GNU Library General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA
19
20 #ifndef CANVAS_CUSTOM_EVENT_HXX_
21 #define CANVAS_CUSTOM_EVENT_HXX_
22
23 #include <simgear/canvas/CanvasEvent.hxx>
24 #include <simgear/structure/map.hxx>
25
26 namespace simgear
27 {
28 namespace canvas
29 {
30
31   /**
32    * User defined event (optionally carrying additional context information or
33    * data).
34    */
35   class CustomEvent:
36     public Event
37   {
38     public:
39
40       /**
41        *
42        * @param type_str    Event type name (if name does not exist yet it will
43        *                    be registered as new event type)
44        * @param bubbles     If this event should take part in the bubbling phase
45        * @param data        Optional user data stored in event
46        */
47       CustomEvent( std::string const& type_str,
48                    bool bubbles = false,
49                    StringMap const& data = StringMap() );
50
51       /**
52        *
53        * @param type_id     Event type id
54        * @param bubbles     If this event should take part in the bubbling phase
55        * @param data        Optional user data stored in event
56        */
57       CustomEvent( int type_id,
58                    bool bubbles = false,
59                    StringMap const& data = StringMap() );
60
61       /**
62        * Set user data
63        */
64       void setDetail(StringMap const& data);
65
66       /**
67        * Get user data
68        */
69       StringMap const& getDetail() const { return detail; }
70
71       /**
72        * Get whether this event supports bubbling.
73        *
74        * @see #bubbles
75        * @see CustomEvent()
76        */
77       virtual bool canBubble() const { return bubbles; }
78
79       StringMap detail; //!< User data map
80       bool bubbles;     //!< Whether the event supports bubbling
81   };
82
83 } // namespace canvas
84 } // namespace simgear
85
86 #endif /* CANVAS_CUSTOM_EVENT_HXX_ */