pointer_event.h Source File - ClanLib SDK
Description: pointer_event.h Source File

pointer_event.h
1/*
2** ClanLib SDK
3** Copyright (c) 1997-2020 The ClanLib Team
4**
5** This software is provided 'as-is', without any express or implied
6** warranty. In no event will the authors be held liable for any damages
7** arising from the use of this software.
8**
9** Permission is granted to anyone to use this software for any purpose,
10** including commercial applications, and to alter it and redistribute it
11** freely, subject to the following restrictions:
12**
13** 1. The origin of this software must not be misrepresented; you must not
14** claim that you wrote the original software. If you use this software
15** in a product, an acknowledgment in the product documentation would be
16** appreciated but is not required.
17** 2. Altered source versions must be plainly marked as such, and must not be
18** misrepresented as being the original software.
19** 3. This notice may not be removed or altered from any source distribution.
20**
21** Note: Some of the libraries ClanLib may link to may have additional
22** requirements or restrictions.
23**
24** File Author(s):
25**
26** Magnus Norddahl
27*/
28
29#pragma once
30
31#include "event.h"
32#include "../../Core/Math/point.h"
33
34namespace clan
35{
37 enum class PointerButton
38 {
39 none,
40 left,
41 right,
42 middle,
43 wheel_up,
44 wheel_down,
45 xbutton1,
46 xbutton2,
47 xbutton3,
48 xbutton4,
49 xbutton5,
50 xbutton6
51 };
52
54 enum class PointerEventType
55 {
56 none,
57 enter,
58 leave,
59 move,
60 press,
61 release,
62 double_click,
63 promixity_change
64 };
65
67 class PointerEvent : public EventUI
68 {
69 public:
70 PointerEvent(PointerEventType type, PointerButton button, const Pointf &pos, bool alt_down, bool shift_down, bool ctrl_down, bool cmd_down) :
71 _type(type), _button(button), _pos(pos), _alt_down(alt_down), _shift_down(shift_down), _ctrl_down(ctrl_down), _cmd_down(cmd_down)
72 {
73 }
74
76 PointerEventType type() const { return _type; }
77
79 PointerButton button() const { return _button; }
80
82 Pointf pos(View *view) const;
83 Pointf pos(const std::shared_ptr<View> &view) const;
84
86 void set_pos(View *view, const Pointf &pos);
87
89 bool alt_down() const { return _alt_down; }
90
92 bool shift_down() const { return _shift_down; }
93
95 bool ctrl_down() const { return _ctrl_down; }
96
98 bool cmd_down() const { return _cmd_down; }
99
100 private:
101 PointerEventType _type = PointerEventType::enter;
102 PointerButton _button = PointerButton::none;
103 Pointf _pos;
104 bool _alt_down = false;
105 bool _shift_down = false;
106 bool _ctrl_down = false;
107 bool _cmd_down = false;
108 };
109}
clan::EventUI
Base class for events being dispatched through the view hiarchy.
Definition UI/Events/event.h:48
clan::PointerEvent
Pointer event.
Definition pointer_event.h:68
clan::PointerEvent::pos
Pointf pos(const std::shared_ptr< View > &view) const
clan::PointerEvent::PointerEvent
PointerEvent(PointerEventType type, PointerButton button, const Pointf &pos, bool alt_down, bool shift_down, bool ctrl_down, bool cmd_down)
Definition pointer_event.h:70
clan::PointerEvent::pos
Pointf pos(View *view) const
Pointer position relative to local view content coordinates.
clan::PointerEvent::button
PointerButton button() const
Pointer button relevant for the event.
Definition pointer_event.h:79
clan::PointerEvent::shift_down
bool shift_down() const
True if the shift key was down.
Definition pointer_event.h:92
clan::PointerEvent::ctrl_down
bool ctrl_down() const
True if the control key was down.
Definition pointer_event.h:95
clan::PointerEvent::alt_down
bool alt_down() const
True if the alt key was down.
Definition pointer_event.h:89
clan::PointerEvent::set_pos
void set_pos(View *view, const Pointf &pos)
Set event pointer position relative to local view content coordinates.
clan::PointerEvent::cmd_down
bool cmd_down() const
True if the command key was down.
Definition pointer_event.h:98
clan::PointerEvent::type
PointerEventType type() const
Pointer event type.
Definition pointer_event.h:76
clan::Pointf
2D (x,y) point structure - Float
Definition point.h:72
clan::View
View for an area of the user interface.
Definition view.h:66
clan::Handedness::right
@ right
clan::Handedness::left
@ left
clan::DrawBuffer::none
@ none
clan
Definition clanapp.h:36
clan::PointerEventType
PointerEventType
Pointer event type.
Definition pointer_event.h:55
clan::PointerEventType::move
@ move
Pointer left area.
clan::PointerEventType::leave
@ leave
Pointer entered area.
clan::PointerEventType::promixity_change
@ promixity_change
Pointer double click pressed.
clan::PointerEventType::double_click
@ double_click
Pointer released.
clan::PointerEventType::enter
@ enter
No event type specified.
clan::PointerButton
PointerButton
Pointer button.
Definition pointer_event.h:38
clan::PointerButton::xbutton4
@ xbutton4
Extra button 3.
clan::PointerButton::xbutton5
@ xbutton5
Extra button 4.
clan::PointerButton::wheel_up
@ wheel_up
Middle/wheel button.
clan::PointerButton::xbutton3
@ xbutton3
Extra button 2.
clan::PointerButton::none
@ none
clan::PointerButton::middle
@ middle
Right button.
clan::PointerButton::wheel_down
@ wheel_down
Wheel up tick.
clan::PointerButton::xbutton1
@ xbutton1
Wheel down tick.
clan::PointerButton::xbutton6
@ xbutton6
Extra button 5.
clan::PointerButton::xbutton2
@ xbutton2
Extra button 1.
clan::KeyEventType::release
@ release
clan::KeyEventType::press
@ press