1 /* GG is a GUI for OpenGL.
2 Copyright (C) 2003-2008 T. Zachary Laine
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public License
6 as published by the Free Software Foundation; either version 2.1
7 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 02111-1307 USA
18
19 If you do not wish to comply with the terms of the LGPL please
20 contact the author as other terms are available for a fee.
21
22 Zach Laine
23 whatwasthataddress@gmail.com */
24
25 #include <GG/WndEvent.h>
26
27
28 using namespace GG;
29
30 ///////////////////////////////////////
31 // ModKeys
32 ///////////////////////////////////////
33 const ModKey GG::MOD_KEY_NONE (0x0000);
34 const ModKey GG::MOD_KEY_LSHIFT (0x0001);
35 const ModKey GG::MOD_KEY_RSHIFT (0x0002);
36 const ModKey GG::MOD_KEY_LCTRL (0x0040);
37 const ModKey GG::MOD_KEY_RCTRL (0x0080);
38 const ModKey GG::MOD_KEY_LALT (0x0100);
39 const ModKey GG::MOD_KEY_RALT (0x0200);
40 const ModKey GG::MOD_KEY_LMETA (0x0400);
41 const ModKey GG::MOD_KEY_RMETA (0x0800);
42 const ModKey GG::MOD_KEY_NUM (0x1000);
43 const ModKey GG::MOD_KEY_CAPS (0x2000);
44 const ModKey GG::MOD_KEY_MODE (0x4000);
45
46 namespace {
RegisterModKeys()47 bool RegisterModKeys()
48 {
49 FlagSpec<ModKey>& spec = FlagSpec<ModKey>::instance();
50 spec.insert(MOD_KEY_NONE, "MOD_KEY_NONE", true);
51 spec.insert(MOD_KEY_LSHIFT, "MOD_KEY_LSHIFT", true);
52 spec.insert(MOD_KEY_RSHIFT, "MOD_KEY_RSHIFT", true);
53 spec.insert(MOD_KEY_LCTRL, "MOD_KEY_LCTRL", true);
54 spec.insert(MOD_KEY_RCTRL, "MOD_KEY_RCTRL", true);
55 spec.insert(MOD_KEY_LALT, "MOD_KEY_LALT", true);
56 spec.insert(MOD_KEY_RALT, "MOD_KEY_RALT", true);
57 spec.insert(MOD_KEY_LMETA, "MOD_KEY_LMETA", true);
58 spec.insert(MOD_KEY_RMETA, "MOD_KEY_RMETA", true);
59 spec.insert(MOD_KEY_NUM, "MOD_KEY_NUM", true);
60 spec.insert(MOD_KEY_CAPS, "MOD_KEY_CAPS", true);
61 spec.insert(MOD_KEY_MODE, "MOD_KEY_MODE", true);
62 return true;
63 }
64 bool dummy = RegisterModKeys();
65 }
66
67 const Flags<ModKey> GG::MOD_KEY_CTRL ((MOD_KEY_LCTRL | MOD_KEY_RCTRL));
68 const Flags<ModKey> GG::MOD_KEY_SHIFT ((MOD_KEY_LSHIFT | MOD_KEY_RSHIFT));
69 const Flags<ModKey> GG::MOD_KEY_ALT ((MOD_KEY_LALT | MOD_KEY_RALT));
70 const Flags<ModKey> GG::MOD_KEY_META ((MOD_KEY_LMETA | MOD_KEY_RMETA));
71
72 GG_FLAGSPEC_IMPL(ModKey);
73
74
75 ///////////////////////////////////////
76 // class GG::WndEvent
77 ///////////////////////////////////////
WndEvent(EventType type,const Pt & pt,Flags<ModKey> mod_keys)78 WndEvent::WndEvent(EventType type, const Pt& pt, Flags<ModKey> mod_keys) :
79 m_type(type),
80 m_point(pt),
81 m_mod_keys(mod_keys)
82 {}
83
WndEvent(EventType type,const Pt & pt,const Pt & move,Flags<ModKey> mod_keys)84 WndEvent::WndEvent(EventType type, const Pt& pt, const Pt& move, Flags<ModKey> mod_keys) :
85 m_type(type),
86 m_point(pt),
87 m_mod_keys(mod_keys),
88 m_drag_move(move)
89 {}
90
WndEvent(EventType type,const Pt & pt,int move,Flags<ModKey> mod_keys)91 WndEvent::WndEvent(EventType type, const Pt& pt, int move, Flags<ModKey> mod_keys) :
92 m_type(type),
93 m_point(pt),
94 m_mod_keys(mod_keys),
95 m_wheel_move(move)
96 {}
97
WndEvent(EventType type,const Pt & pt,const std::map<std::shared_ptr<Wnd>,Pt> & drag_drop_wnds,Flags<ModKey> mod_keys)98 WndEvent::WndEvent(EventType type, const Pt& pt, const std::map<std::shared_ptr<Wnd>, Pt>& drag_drop_wnds, Flags<ModKey> mod_keys) :
99 m_type(type),
100 m_point(pt),
101 m_mod_keys(mod_keys)
102 {
103 // initialize storage for acceptable Wnds
104 for (const auto& drag_drop_wnd : drag_drop_wnds) {
105 m_drag_drop_wnds[drag_drop_wnd.first.get()] = drag_drop_wnd.second;
106 m_acceptable_drop_wnds[drag_drop_wnd.first.get()] = false;
107 }
108 }
109
WndEvent(EventType type,const Pt & pt,const std::vector<std::shared_ptr<Wnd>> & drag_drop_wnds,Flags<ModKey> mod_keys)110 WndEvent::WndEvent(EventType type, const Pt& pt, const std::vector<std::shared_ptr<Wnd>>& drag_drop_wnds, Flags<ModKey> mod_keys) :
111 m_type(type),
112 m_point(pt),
113 m_mod_keys(mod_keys),
114 m_dropped_wnds(drag_drop_wnds)
115 {}
116
WndEvent(EventType type,const Pt & pt,const Wnd * const drag_wnd,Flags<ModKey> mod_keys)117 WndEvent::WndEvent(EventType type, const Pt& pt, const Wnd* const drag_wnd, Flags<ModKey> mod_keys) :
118 m_type(type),
119 m_point(pt),
120 m_mod_keys(mod_keys)
121 {
122 // initialize storage for single dragged Wnd
123 m_drag_drop_wnds[drag_wnd] = pt;
124 m_acceptable_drop_wnds[drag_wnd] = false;
125 }
126
WndEvent(EventType type,Key key,std::uint32_t code_point,Flags<ModKey> mod_keys)127 WndEvent::WndEvent(EventType type, Key key, std::uint32_t code_point, Flags<ModKey> mod_keys) :
128 m_type(type),
129 m_key(key),
130 m_key_code_point(code_point),
131 m_mod_keys(mod_keys)
132 {}
133
WndEvent(EventType type,unsigned int ticks,Timer * timer)134 WndEvent::WndEvent(EventType type, unsigned int ticks, Timer* timer) :
135 m_type(type),
136 m_ticks(ticks),
137 m_timer(timer)
138 {}
139
WndEvent(WndEvent::EventType type,const std::string * text)140 WndEvent::WndEvent (WndEvent::EventType type, const std::string* text):
141 m_type(type),
142 m_text(text)
143 {}
144
WndEvent(EventType type)145 WndEvent::WndEvent(EventType type) :
146 m_type(type)
147 {}
148
Type() const149 WndEvent::EventType WndEvent::Type() const
150 { return m_type; }
151
Point() const152 const Pt& WndEvent::Point() const
153 { return m_point; }
154
GetKey() const155 Key WndEvent::GetKey() const
156 { return m_key; }
157
KeyCodePoint() const158 std::uint32_t WndEvent::KeyCodePoint() const
159 { return m_key_code_point; }
160
ModKeys() const161 Flags<ModKey> WndEvent::ModKeys() const
162 { return m_mod_keys; }
163
DragMove() const164 const Pt& WndEvent::DragMove() const
165 { return m_drag_move; }
166
WheelMove() const167 int WndEvent::WheelMove() const
168 { return m_wheel_move; }
169
DragDropWnds() const170 const std::map<const Wnd* const, Pt>& WndEvent::DragDropWnds() const
171 { return m_drag_drop_wnds; }
172
GetDragDropWnds() const173 std::vector<std::shared_ptr<Wnd>>& WndEvent::GetDragDropWnds() const
174 { return m_dropped_wnds; }
175
GetAcceptableDropWnds() const176 std::map<const Wnd*, bool>& WndEvent::GetAcceptableDropWnds() const
177 { return m_acceptable_drop_wnds; }
178
Ticks() const179 unsigned int WndEvent::Ticks() const
180 { return m_ticks; }
181
GetTimer() const182 Timer* WndEvent::GetTimer() const
183 { return m_timer; }
184
GetText() const185 const std::string* WndEvent::GetText() const
186 { return m_text; }
187
EventTypeName(const WndEvent & event)188 std::string EventTypeName(const WndEvent& event) {
189 switch (event.Type()) {
190 case WndEvent::LButtonDown: return "(LButtonDown)";
191 case WndEvent::LDrag: return "(LDrag)";
192 case WndEvent::LButtonUp: return "(LButtonUp)";
193 case WndEvent::LClick: return "(LClick)";
194 case WndEvent::LDoubleClick: return "(LDoubleClick)";
195 case WndEvent::MButtonDown: return "(MButtonDown)";
196 case WndEvent::MDrag: return "(MDrag)";
197 case WndEvent::MButtonUp: return "(MButtonUp)";
198 case WndEvent::MClick: return "(MClick)";
199 case WndEvent::MDoubleClick: return "(MDoubleClick)";
200 case WndEvent::RButtonDown: return "(RButtonDown)";
201 case WndEvent::RDrag: return "(RDrag)";
202 case WndEvent::RButtonUp: return "(RButtonUp)";
203 case WndEvent::RClick: return "(RClick)";
204 case WndEvent::RDoubleClick: return "(RDoubleClick)";
205 case WndEvent::MouseEnter: return "(MouseEnter)";
206 case WndEvent::MouseHere: return "(MouseHere)";
207 case WndEvent::MouseLeave: return "(MouseLeave)";
208 case WndEvent::MouseWheel: return "(MouseWheel)";
209 case WndEvent::DragDropEnter: return "(DragDropEnter)";
210 case WndEvent::DragDropHere: return "(DragDropHere)";
211 case WndEvent::CheckDrops: return "(CheckDrops)";
212 case WndEvent::DragDropLeave: return "(DragDropLeave)";
213 case WndEvent::DragDroppedOn: return "(DragDroppedOn)";
214 case WndEvent::KeyPress: return "(KeyPress)";
215 case WndEvent::KeyRelease: return "(KeyRelease)";
216 case WndEvent::TextInput: return "(TextInput)";
217 case WndEvent::GainingFocus: return "(GainingFocus)";
218 case WndEvent::LosingFocus: return "(LosingFocus)";
219 case WndEvent::TimerFiring: return "(TimerFiring)";
220 default: return "(Unknown Event Type)";
221 }
222 }
223