key_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#include "../../Display/Window/keys.h"
34#include <string>
35
36namespace clan
37{
39 enum class KeyEventType
40 {
41 none, // No key event type specified
42 press, // Key was pressed
43 release // Key was released
44 };
45
47 class KeyEvent : public EventUI
48 {
49 public:
50 KeyEvent(KeyEventType type, Key key, int repeat_count, const std::string &text, const Pointf &pointer_pos, bool alt_down, bool shift_down, bool ctrl_down, bool cmd_down) :
51 _type(type), _key(key), _repeat_count(repeat_count), _text(text), _pointer_pos(pointer_pos), _alt_down(alt_down), _shift_down(shift_down), _ctrl_down(ctrl_down), _cmd_down(cmd_down)
52 {
53 }
54
56 KeyEventType type() const { return _type; }
57
59 Key key() const { return _key; }
60
62 int repeat_count() const { return _repeat_count; }
63
65 const std::string &text() const { return _text; }
66
68 Pointf pointer_pos(View *view) const;
69
71 bool alt_down() const { return _alt_down; }
72
74 bool shift_down() const { return _shift_down; }
75
77 bool ctrl_down() const { return _ctrl_down; }
78
80 bool cmd_down() const { return _cmd_down; }
81
82 private:
84 Key _key = Key::none;
85 int _repeat_count = 0;
86 std::string _text;
87 Pointf _pointer_pos;
88 bool _alt_down = false;
89 bool _shift_down = false;
90 bool _ctrl_down = false;
91 bool _cmd_down = false;
92 };
93}
Base class for events being dispatched through the view hiarchy.
Definition: UI/Events/event.h:48
Keyboard key event.
Definition: key_event.h:48
Pointf pointer_pos(View *view) const
Cursor position returned in local content coordinates for the view specified.
KeyEvent(KeyEventType type, Key key, int repeat_count, const std::string &text, const Pointf &pointer_pos, bool alt_down, bool shift_down, bool ctrl_down, bool cmd_down)
Definition: key_event.h:50
int repeat_count() const
Key press repeat counter for key being held down.
Definition: key_event.h:62
KeyEventType type() const
Key event type.
Definition: key_event.h:56
Key key() const
Key relevant for the event.
Definition: key_event.h:59
bool ctrl_down() const
True if the control key was down.
Definition: key_event.h:77
bool alt_down() const
True if the alt key was down.
Definition: key_event.h:71
const std::string & text() const
Unicode characters generated by this event.
Definition: key_event.h:65
bool shift_down() const
True if the shift key was down.
Definition: key_event.h:74
bool cmd_down() const
True if the command key was down.
Definition: key_event.h:80
2D (x,y) point structure - Float
Definition: point.h:72
View for an area of the user interface.
Definition: view.h:66
Definition: clanapp.h:36
KeyEventType
Keyboard key event type.
Definition: key_event.h:40
Key
Enumeration of keyboard keys recognized on ClanLib.
Definition: keys.h:38