Boost.UI
User Interface Boost library
event.hpp
Go to the documentation of this file.
1 // Copyright (c) 2017 Kolya Kosenko
2 
3 // Distributed under the Boost Software License, Version 1.0.
4 // See http://www.boost.org/LICENSE_1_0.txt
5 
7 
8 #ifndef BOOST_UI_EVENT_HPP
9 #define BOOST_UI_EVENT_HPP
10 
11 #include <boost/ui/config.hpp>
12 
13 #ifdef BOOST_HAS_PRAGMA_ONCE
14 #pragma once
15 #endif
16 
17 #include <boost/ui/coord.hpp>
18 
19 #include <boost/function.hpp>
20 
21 namespace boost {
22 namespace ui {
23 
24 #ifndef DOXYGEN
25 namespace native {
26 
27 template <class NativeEvent, class UIEvent>
28 class event_functor_event;
29 
30 } // namespace native
31 #endif
32 
36 
37 class event
38 {
39 public:
40  virtual ~event() {}
41 };
42 
45 typedef int index_type;
46 //typedef std::size_t index_type;
47 
50 const index_type nindex = -1;
51 
54 
55 class index_event : public event
56 {
57 public:
60 
61  index_event() : m_index(nindex) {}
62 
64  size_type index() const { return m_index; }
65 
66 private:
67  size_type m_index;
68 
69 #ifndef DOXYGEN
70  template <class NativeEvent, class UIEvent>
71  friend class native::event_functor_event;
72 #endif
73 };
74 
77 
79 {
80 public:
81  keyboard_state() : m_ctrl(false), m_shift(false), m_alt(false), m_meta(false) {}
82 
84  bool ctrl() const { return m_ctrl; }
85 
87  bool shift() const { return m_shift; }
88 
90  bool alt() const { return m_alt; }
91 
93  bool meta() const { return m_meta; }
94 
95 private:
96  bool m_ctrl;
97  bool m_shift;
98  bool m_alt;
99  bool m_meta;
100 
101 #ifndef DOXYGEN
102  template <class NativeEvent, class UIEvent>
103  friend class native::event_functor_event;
104 #endif
105 };
106 
112 
113 class key_event : public event, public keyboard_state
114 {
115 public:
116  key_event() : m_code(0), m_char(0) {}
117 
119  int key_code() const { return m_code; }
120 
122 #ifndef BOOST_NO_CXX11_CHAR32_T
123  char32_t
124 #else
125  int
126 #endif
127  get_char() const { return m_char; }
128 
129 private:
130  int m_code;
131  int m_char;
132 
133 #ifndef DOXYGEN
134  template <class NativeEvent, class UIEvent>
135  friend class native::event_functor_event;
136 #endif
137 };
138 
143 
144 class mouse_event : public event
145 {
146 public:
147  mouse_event();
148 
150  coord_type x() const { return m_x; }
151 
153  coord_type y() const { return m_y; }
154 
156  point pos() const { return point(x(), y()); }
157 
159  bool left() const { return m_left; }
160  bool right() const { return m_right; }
161  bool middle() const { return m_middle; }
163 
164 private:
165  coord_type m_x;
166  coord_type m_y;
167  bool m_left;
168  bool m_right;
169  bool m_middle;
170 
171 #ifndef DOXYGEN
172  template <class NativeEvent, class UIEvent>
173  friend class native::event_functor_event;
174 #endif
175 };
176 
180 class wheel_event : public mouse_event
181 {
182 public:
183  wheel_event() : m_horizontal(false), m_delta(0) {}
184 
186  bool horizontal() const { return m_horizontal; }
187 
189  bool vertical() const { return !m_horizontal; }
190 
192  coord_type delta_x() const { return horizontal() ? m_delta : 0; }
193 
195  coord_type delta_y() const { return vertical() ? m_delta : 0; }
196 
197 private:
198  bool m_horizontal;
199  coord_type m_delta;
200 
201 #ifndef DOXYGEN
202  template <class NativeEvent, class UIEvent>
203  friend class native::event_functor_event;
204 #endif
205 };
206 
207 } // namespace ui
208 } // namespace boost
209 
210 #endif // BOOST_UI_EVENT_HPP
boost::ui::mouse_event::y
coord_type y() const
Returns y mouse coordinate relative to the parent widget client area.
Definition: event.hpp:153
boost::ui::basic_point
2D point data structure with custom coordinates type
Definition: coord.hpp:119
boost::ui::mouse_event::right
bool right() const
Returns true if mouse button is pressed or was unpressed in this event.
Definition: event.hpp:160
config.hpp
Configuration options.
boost::ui::keyboard_state::ctrl
bool ctrl() const
Returns true only if Control key is pressed.
Definition: event.hpp:84
boost::ui::wheel_event::delta_y
coord_type delta_y() const
Returns wheel vertical move delta.
Definition: event.hpp:195
boost::ui::index_event
Event class that holds some index in container.
Definition: event.hpp:55
boost::ui::keyboard_state::alt
bool alt() const
Returns true only if Alt key is pressed.
Definition: event.hpp:90
boost
Boost C++ libraries namespace.
Definition: window.hpp:19
boost::ui::key_event::key_code
int key_code() const
Returns associated key code.
Definition: event.hpp:119
boost::ui::wheel_event::delta_x
coord_type delta_x() const
Returns wheel horizontal move delta.
Definition: event.hpp:192
boost::ui::mouse_event
Mouse event class that holds information about mouse when event was generated.
Definition: event.hpp:144
boost::ui::mouse_event::left
bool left() const
Returns true if mouse button is pressed or was unpressed in this event.
Definition: event.hpp:159
boost::ui::keyboard_state::shift
bool shift() const
Returns true only if Shift key is pressed.
Definition: event.hpp:87
boost::ui::event
Base class for all events.
Definition: event.hpp:37
boost::ui::nindex
const index_type nindex
Invalid index value.
Definition: event.hpp:50
boost::ui::wheel_event::vertical
bool vertical() const
Returns true only if wheel move is vertical.
Definition: event.hpp:189
boost::ui::point
basic_point< coord_type > point
2D point coordinates
Definition: coord.hpp:420
boost::ui::mouse_event::pos
point pos() const
Returns mouse position relative to the parent widget client area.
Definition: event.hpp:156
boost::ui::coord_type
int coord_type
Widget coordinates signed number type.
Definition: coord.hpp:412
boost::ui::mouse_event::x
coord_type x() const
Returns x mouse coordinate relative to the parent widget client area.
Definition: event.hpp:150
boost::ui::wheel_event
Mouse wheel event class.
Definition: event.hpp:180
boost::ui::key_event
Keyboard event class that holds information about keyboard when event was generated.
Definition: event.hpp:113
boost::ui::index_event::index
size_type index() const
Returns index of the associated item in the container.
Definition: event.hpp:64
boost::ui::index_event::size_type
index_type size_type
Integral type.
Definition: event.hpp:59
boost::ui::keyboard_state::meta
bool meta() const
Returns true only if Meta key is pressed.
Definition: event.hpp:93
boost::ui::index_type
int index_type
Integral type for indexing items.
Definition: event.hpp:45
boost::ui::wheel_event::horizontal
bool horizontal() const
Returns true only if wheel move is horizontal.
Definition: event.hpp:186
boost::ui::keyboard_state
Keyboard state class.
Definition: event.hpp:78
boost::ui::mouse_event::middle
bool middle() const
Returns true if mouse button is pressed or was unpressed in this event.
Definition: event.hpp:161
coord.hpp
Coordinates classes.
boost::ui::key_event::get_char
char32_t get_char() const
Returns associated character.
Definition: event.hpp:127