doodle  0.2
Intended to support teaching C++, doodle is a simple library that helps make a window and makes it easy to do some drawing.
input.hpp
Go to the documentation of this file.
1 /*--------------------------------------------------------------*
2  Copyright (C) 2021 Rudy Castan
3 
4  This file is distributed WITHOUT ANY WARRANTY. See the file
5  `License.md' for details.
6 *--------------------------------------------------------------*/
7 #pragma once
8 
9 #include <doodle/eventhook.hpp>
10 
11 #include <functional>
12 #include <string>
13 
14 namespace doodle
15 {
16  enum class MouseButtons
17  {
18  None,
19  Left,
20  Middle,
21  Right,
22  Count
23  };
24 
25  enum class KeyboardButtons
26  {
27  None,
28  _0,
29  _1,
30  _2,
31  _3,
32  _4,
33  _5,
34  _6,
35  _7,
36  _8,
37  _9,
38  A,
39  B,
40  C,
41  D,
42  E,
43  F,
44  G,
45  H,
46  I,
47  J,
48  K,
49  L,
50  M,
51  N,
52  O,
53  P,
54  Q,
55  R,
56  S,
57  T,
58  U,
59  V,
60  W,
61  X,
62  Y,
63  Z,
64  NumPad_0,
65  NumPad_1,
66  NumPad_2,
67  NumPad_3,
68  NumPad_4,
69  NumPad_5,
70  NumPad_6,
71  NumPad_7,
72  NumPad_8,
73  NumPad_9,
74  Escape,
75  Control,
76  Shift,
77  CapsLock,
78  LeftSystem,
79  RightSystem,
80  Menu,
81  LeftBracket,
82  RightBracket,
83  Semicolon,
84  Comma,
85  Period,
86  Quote,
87  Slash,
88  Backslash,
89  Tilde,
90  Equal,
91  Hyphen,
92  Space,
93  Enter,
94  Backspace,
95  Tab,
96  PageUp,
97  PageDown,
98  End,
99  Home,
100  PrintScreen,
101  Insert,
102  Delete,
103  Add,
104  Subtract,
105  Multiply,
106  Divide,
107  Left,
108  Right,
109  Up,
110  Down,
111  F1,
112  F2,
113  F3,
114  F4,
115  F5,
116  F6,
117  F7,
118  F8,
119  F9,
120  Pause,
121  Count
122  };
123 
124 
135  std::string to_string(MouseButtons button) noexcept;
141  std::string to_string(KeyboardButtons button) noexcept;
147  std::wstring to_wstring(MouseButtons button) noexcept;
153  std::wstring to_wstring(KeyboardButtons button) noexcept;
197  extern bool MouseIsPressed;
235  extern bool KeyIsPressed;
260  extern KeyboardButtons Key;
297  extern MouseButtons MouseButton;
327  int get_mouse_x() noexcept;
328 
351  int get_mouse_y() noexcept;
383  int get_previous_mouse_x() noexcept;
407  int get_previous_mouse_y() noexcept;
452  void set_callback_key_pressed(std::function<void(KeyboardButtons)>&& callback) noexcept;
511  void set_callback_key_released(std::function<void(KeyboardButtons)>&& callback) noexcept;
570  void set_callback_mouse_moved(std::function<void(int, int)>&& callback) noexcept;
636  void set_callback_mouse_pressed(std::function<void(MouseButtons)>&& callback) noexcept;
702  void set_callback_mouse_released(std::function<void(MouseButtons)>&& callback) noexcept;
751  void set_callback_mouse_wheel(std::function<void(int)>&& callback) noexcept;
753 }
754 
804 EVENT_HOOK void on_key_pressed(doodle::KeyboardButtons button);
845 EVENT_HOOK void on_key_released(doodle::KeyboardButtons button);
888 EVENT_HOOK void on_mouse_moved(int mouse_x, int mouse_y);
937 EVENT_HOOK void on_mouse_pressed(doodle::MouseButtons button);
987 EVENT_HOOK void on_mouse_released(doodle::MouseButtons button);
1019 EVENT_HOOK void on_mouse_wheel(int scroll_amount);
void set_callback_key_pressed(std::function< void(KeyboardButtons)> &&callback) noexcept
The provided callback function is called once every time a key is pressed.
int get_mouse_x() noexcept
Get the mouse's X position relative to the currently set doodle::FrameOfReference.
EVENT_HOOK void on_key_released(doodle::KeyboardButtons button)
The declaration of the optional on_key_released function to implement in your doodle program.
bool KeyIsPressed
The boolean system variable KeyIsPressed is true if any key is pressed and false if no keys are press...
EVENT_HOOK void on_mouse_released(doodle::MouseButtons button)
The declaration of the optional on_mouse_released function to implement in your doodle program.
void set_callback_key_released(std::function< void(KeyboardButtons)> &&callback) noexcept
The provided callback function is called once every time a key is released.
EVENT_HOOK void on_mouse_moved(int mouse_x, int mouse_y)
The declaration of the optional on_mouse_moved function to implement in your doodle program.
MouseButtons MouseButton
doodle automatically tracks if the mouse button is pressed and which button is pressed....
void set_callback_mouse_pressed(std::function< void(MouseButtons)> &&callback) noexcept
The provided callback is called whenever a mouse button is pressed.
int get_previous_mouse_x() noexcept
Get the previous mouse's X position relative to the currently set doodle::FrameOfReference.
KeyboardButtons Key
The system variable key always contains the value of the most recent key on the keyboard that was typ...
int get_previous_mouse_y() noexcept
Get the previous mouse's Y position relative to the currently set doodle::FrameOfReference.
void set_callback_mouse_released(std::function< void(MouseButtons)> &&callback) noexcept
The provided callback is called whenever a mouse button is released.
bool MouseIsPressed
The boolean system variable MouseIsPressed is true if the mouse is pressed and false if not.
EVENT_HOOK void on_mouse_pressed(doodle::MouseButtons button)
The declaration of the optional on_mouse_pressed function to implement in your doodle program.
void set_callback_mouse_moved(std::function< void(int, int)> &&callback) noexcept
The provided callback function is called every time the mouse moves.
void set_callback_mouse_wheel(std::function< void(int)> &&callback) noexcept
The provided callback is called whenever the mouse wheel is scrolled.
EVENT_HOOK void on_key_pressed(doodle::KeyboardButtons button)
The declaration of the optional on_key_pressed function to implement in your doodle program.
EVENT_HOOK void on_mouse_wheel(int scroll_amount)
The declaration of the optional on_mouse_wheel function to implement in your doodle program.
int get_mouse_y() noexcept
Get the mouse's Y position relative to the currently set doodle::FrameOfReference.
std::string to_string(MouseButtons button) noexcept
Convert MouseButtons enum to std::string.
std::wstring to_wstring(MouseButtons button) noexcept
Convert MouseButtons enum to std::wstring.
Definition: angle.hpp:11
MouseButtons
Definition: input.hpp:17
@ None
Unhandled Button.
@ Right
Right Mouse Button.
@ Left
Left Mouse Button.
@ Middle
Middle Mouse Button.
@ Count
the total number of mouse button keys
KeyboardButtons
Definition: input.hpp:26
@ Escape
The Escape key.
@ Pause
The Pause key.
@ NumPad_0
The numpad 0 key.
@ Subtract
The - key (minus, usually from numpad)
@ NumPad_1
The numpad 1 key.
@ NumPad_8
The numpad 8 key.
@ NumPad_9
The numpad 9 key.
@ Tab
The Tabulation key.
@ None
Unhandled key.
@ NumPad_4
The numpad 4 key.
@ Hyphen
The - key (hyphen)
@ Shift
The Shift key.
@ LeftSystem
The left OS specific key: window (Windows and Linux), apple (MacOS X), ...
@ CapsLock
The Caps Lock key.
@ PageUp
The Page up key.
@ NumPad_7
The numpad 7 key.
@ Control
The Control key.
@ Insert
The Insert key.
@ PrintScreen
The Print Screen key.
@ NumPad_3
The numpad 3 key.
@ NumPad_2
The numpad 2 key.
@ Backspace
The Backspace key.
@ Space
The Space key.
@ RightSystem
The right OS specific key: window (Windows and Linux), apple (MacOS X), ...
@ NumPad_5
The numpad 5 key.
@ Count
the total number of keyboard keys
@ PageDown
The Page down key.
@ Enter
The Enter/Return keys.
@ Delete
The Delete key.
@ NumPad_6
The numpad 6 key.