neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
i_mouse.hpp
Go to the documentation of this file.
1 // i_mouse.hpp
2/*
3 neogfx C++ App/Game Engine
4 Copyright (c) 2015, 2020 Leigh Johnston. All Rights Reserved.
5
6 This program 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 3 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, see <http://www.gnu.org/licenses/>.
18*/
19
20#pragma once
21
22#include <neogfx/neogfx.hpp>
25#include <neogfx/core/event.hpp>
27
28namespace neogfx
29{
30 enum class mouse_button : uint32_t
31 {
32 None = 0x00,
33 Left = 0x01,
34 Right = 0x02,
35 Middle = 0x04,
36 X1 = 0x08,
37 X2 = 0x10,
38 Other = 0x20
39 };
40
41 enum class mouse_wheel : uint32_t
42 {
43 None = 0x00,
44 Vertical = 0x01,
45 Horizontal = 0x02
46 };
47
49 {
50 Arrow,
51 IBeam,
52 Wait,
57 SizeWE,
58 SizeNS,
59 SizeAll,
60 No,
61 Hand
62 };
63
65 {
66 public:
68 /* todo: support for custom mouse cursors. */
69 public:
70 struct wrong_type : std::logic_error { wrong_type() : std::logic_error("neogfx::mouse_cursor::wrong_type") {} };
71 public:
72 mouse_cursor(mouse_system_cursor aSystemCursor) : iType(aSystemCursor)
73 {
74 }
75 public:
76 bool is_system_cursor() const
77 {
78 return std::holds_alternative<mouse_system_cursor>(iType);
79 }
81 {
82 if (is_system_cursor())
83 return std::get<mouse_system_cursor>(iType);
84 throw wrong_type();
85 }
86 public:
88 };
89
91 {
92 return static_cast<mouse_button>(static_cast<uint32_t>(aLhs) | static_cast<uint32_t>(aRhs));
93 }
94
96 {
97 return static_cast<mouse_button>(static_cast<uint32_t>(aLhs)& static_cast<uint32_t>(aRhs));
98 }
99
101 {
102 return static_cast<mouse_button>(~static_cast<uint32_t>(aLhs));
103 }
104
106 {
107 aLhs = aLhs | aRhs;
108 return aLhs;
109 }
110
112 {
113 aLhs = aLhs & aRhs;
114 return aLhs;
115 }
116
118 {
119 return static_cast<mouse_wheel>(static_cast<uint32_t>(aLhs) | static_cast<uint32_t>(aRhs));
120 }
121
123 {
124 return static_cast<mouse_wheel>(static_cast<uint32_t>(aLhs)& static_cast<uint32_t>(aRhs));
125 }
126
128 {
129 return static_cast<mouse_wheel>(~static_cast<uint32_t>(aLhs));
130 }
131
132 class i_surface;
133
134 enum class mouse_capture_type : uint32_t
135 {
136 None,
137 Normal,
138 Raw
139 };
140
142 {
143 public:
144 virtual bool mouse_wheel_scrolled(mouse_wheel aWheel, const point& aPosition, delta aDelta, key_modifiers_e aKeyModifiers) = 0;
145 };
146
147 class i_mouse : public i_hid_device, public i_service
148 {
149 public:
151 public:
153 declare_event(button_released, mouse_button)
154 public:
155 struct not_capturing : std::logic_error { not_capturing() : std::logic_error{ "neogfx::i_mouse::not_capturing" } {} };
156 struct already_capturing : std::logic_error { already_capturing() : std::logic_error{ "neogfx::i_mouse::already_capturing" } {} };
157 struct bad_surface : std::logic_error { bad_surface() : std::logic_error{ "neogfx::i_mouse::bad_surface" } {} };
158 struct no_grab : std::logic_error { no_grab() : std::logic_error("neogfx::i_mouse::no_grab") {} };
159 struct already_grabbed : std::logic_error { already_grabbed() : std::logic_error("neogfx::i_mouse::already_grabbed") {} };
160 public:
161 virtual point position() const = 0;
162 virtual mouse_button button_state() const = 0;
163 public:
164 virtual bool capturing() const = 0;
165 virtual i_surface& capture_target() const = 0;
166 virtual mouse_capture_type capture_type() const = 0;
167 virtual void capture(i_surface& aTarget) = 0;
168 virtual void capture_raw(i_surface& aTarget) = 0;
169 virtual void release_capture() = 0;
170 public:
171 virtual bool is_mouse_grabbed() const = 0;
172 virtual bool is_mouse_grabbed_by(i_mouse_handler& aMouseHandler) const = 0;
173 virtual bool is_front_grabber(i_mouse_handler& aMouseHandler) const = 0;
174 virtual void grab_mouse(i_mouse_handler& aMouseHandler) = 0;
175 virtual void ungrab_mouse(i_mouse_handler& aMouseHandler) = 0;
176 virtual i_mouse_handler& grabber() const = 0;
177 public:
178 bool is_button_pressed(mouse_button aButton) const
179 {
180 return (button_state() & aButton) == aButton;
181 }
182 public:
183 static uuid const& iid() { static uuid const sIid{ 0xe974988, 0xcfe0, 0x46e8, 0xaad0, { 0xaf, 0xaa, 0x7a, 0x92, 0x7a, 0xf6 } }; return sIid; }
184 };
185}
virtual bool mouse_wheel_scrolled(mouse_wheel aWheel, const point &aPosition, delta aDelta, key_modifiers_e aKeyModifiers)=0
virtual bool is_mouse_grabbed_by(i_mouse_handler &aMouseHandler) const =0
virtual void release_capture()=0
i_mouse abstract_type
Definition i_mouse.hpp:150
virtual bool capturing() const =0
static uuid const & iid()
Definition i_mouse.hpp:183
bool is_button_pressed(mouse_button aButton) const
Definition i_mouse.hpp:178
virtual mouse_capture_type capture_type() const =0
virtual i_mouse_handler & grabber() const =0
virtual mouse_button button_state() const =0
virtual point position() const =0
virtual void capture(i_surface &aTarget)=0
declare_event(button_pressed, mouse_button) declare_event(button_released
virtual void capture_raw(i_surface &aTarget)=0
virtual void grab_mouse(i_mouse_handler &aMouseHandler)=0
virtual void ungrab_mouse(i_mouse_handler &aMouseHandler)=0
virtual bool is_mouse_grabbed() const =0
virtual bool is_front_grabber(i_mouse_handler &aMouseHandler) const =0
virtual i_surface & capture_target() const =0
cursor_type iType
Definition i_mouse.hpp:87
bool is_system_cursor() const
Definition i_mouse.hpp:76
mouse_cursor(mouse_system_cursor aSystemCursor)
Definition i_mouse.hpp:72
neolib::variant< mouse_system_cursor > cursor_type
Definition i_mouse.hpp:67
mouse_system_cursor system_cursor() const
Definition i_mouse.hpp:80
constexpr font_style & operator&=(font_style &aLhs, font_style aRhs)
Definition font.hpp:81
constexpr style_aspect operator&(style_aspect aLhs, style_aspect aRhs)
Definition i_style.hpp:60
mouse_wheel
Definition i_mouse.hpp:42
audio_channel operator~(audio_channel lhs)
mouse_capture_type
Definition i_mouse.hpp:135
constexpr font_style & operator|=(font_style &aLhs, font_style aRhs)
Definition font.hpp:76
mouse_system_cursor
Definition i_mouse.hpp:49
mouse_button
Definition i_mouse.hpp:31
constexpr style_aspect operator|(style_aspect aLhs, style_aspect aRhs)
Definition i_style.hpp:55
#define declare_event(declName,...)
Definition i_event.hpp:305