aboutsummaryrefslogtreecommitdiff
path: root/include/cru/platform/native
diff options
context:
space:
mode:
Diffstat (limited to 'include/cru/platform/native')
-rw-r--r--include/cru/platform/native/base.hpp7
-rw-r--r--include/cru/platform/native/key_code.hpp89
-rw-r--r--include/cru/platform/native/keyboard.hpp120
-rw-r--r--include/cru/platform/native/window.hpp4
4 files changed, 129 insertions, 91 deletions
diff --git a/include/cru/platform/native/base.hpp b/include/cru/platform/native/base.hpp
index d62dc56b..5ebd98d6 100644
--- a/include/cru/platform/native/base.hpp
+++ b/include/cru/platform/native/base.hpp
@@ -2,6 +2,7 @@
#include "cru/common/base.hpp"
#include "cru/common/bitmask.hpp"
#include "cru/platform/graph/base.hpp"
+#include "keyboard.hpp"
namespace cru::platform::native {
struct ICursor;
@@ -35,6 +36,12 @@ enum class SystemCursorType {
struct NativeMouseButtonEventArgs {
MouseButton button;
Point point;
+ KeyModifier modifier;
+};
+
+struct NativeKeyEventArgs {
+ KeyCode key;
+ KeyModifier modifier;
};
enum class FocusChangeType { Gain, Lost };
diff --git a/include/cru/platform/native/key_code.hpp b/include/cru/platform/native/key_code.hpp
deleted file mode 100644
index d4e1ee8f..00000000
--- a/include/cru/platform/native/key_code.hpp
+++ /dev/null
@@ -1,89 +0,0 @@
-#pragma once
-
-namespace cru::platform::native {
-enum class KeyCode {
- LeftButton,
- MiddleButton,
- RightButton,
- Escape,
- F1,
- F2,
- F3,
- F4,
- F5,
- F6,
- F7,
- F8,
- F9,
- F10,
- F11,
- F12,
- N1,
- N2,
- N3,
- N4,
- N5,
- N6,
- N7,
- N8,
- N9,
- N0,
- A,
- B,
- C,
- D,
- E,
- F,
- G,
- H,
- I,
- J,
- K,
- L,
- M,
- N,
- O,
- P,
- Q,
- R,
- S,
- T,
- U,
- V,
- W,
- X,
- Y,
- Z,
- GraveAccent,
- Tab,
- CapsLock,
- LeftShift,
- LeftControl,
- Win,
- LeftAlt,
- Minus,
- Equal,
- Backspace,
- LeftSquareBracket,
- RightSquareBracket,
- BackSlash,
- Semicolon,
- Quote,
- Comma,
- Point,
- Slash,
- RightShift,
- RightAlt,
- RightCtrl,
- Insert,
- Delete,
- Home,
- End,
- PageUp,
- PageDown,
- Up,
- Left,
- Down,
- Right
-};
-}
diff --git a/include/cru/platform/native/keyboard.hpp b/include/cru/platform/native/keyboard.hpp
new file mode 100644
index 00000000..8b5e6162
--- /dev/null
+++ b/include/cru/platform/native/keyboard.hpp
@@ -0,0 +1,120 @@
+#pragma once
+#include "cru/common/bitmask.hpp"
+
+namespace cru::platform::native {
+// Because of the complexity of keyboard layout, I only add code in US keyboard
+// layout, the most widely used layout in China. We should try to make it easy
+// to add new keyboard layout.
+enum class KeyCode {
+ Unknown,
+ LeftButton,
+ MiddleButton,
+ RightButton,
+ Escape,
+ F1,
+ F2,
+ F3,
+ F4,
+ F5,
+ F6,
+ F7,
+ F8,
+ F9,
+ F10,
+ F11,
+ F12,
+ N0,
+ N1,
+ N2,
+ N3,
+ N4,
+ N5,
+ N6,
+ N7,
+ N8,
+ N9,
+ A,
+ B,
+ C,
+ D,
+ E,
+ F,
+ G,
+ H,
+ I,
+ J,
+ K,
+ L,
+ M,
+ N,
+ O,
+ P,
+ Q,
+ R,
+ S,
+ T,
+ U,
+ V,
+ W,
+ X,
+ Y,
+ Z,
+ GraveAccent,
+ Tab,
+ CapsLock,
+ LeftShift,
+ LeftCtrl,
+ LeftSuper,
+ LeftAlt,
+ Minus,
+ Equal,
+ Backspace,
+ LeftSquareBracket,
+ RightSquareBracket,
+ BackSlash,
+ Semicolon,
+ Quote,
+ Comma,
+ Period,
+ Slash,
+ RightShift,
+ RightCtrl,
+ RightSuper,
+ RightAlt,
+ Insert,
+ Delete,
+ Home,
+ End,
+ PageUp,
+ PageDown,
+ Up,
+ Left,
+ Down,
+ Right,
+ PrintScreen,
+ ScrollLock,
+ Pause,
+ NumPad0,
+ NumPad1,
+ NumPad2,
+ NumPad3,
+ NumPad4,
+ NumPad5,
+ NumPad6,
+ NumPad7,
+ NumPad8,
+ NumPad9
+};
+
+namespace details {
+struct TagKeyModifier {};
+} // namespace details
+
+using KeyModifier = Bitmask<details::TagKeyModifier>;
+
+namespace key_modifiers {
+constexpr KeyModifier shift{0b1};
+constexpr KeyModifier ctrl{0b10};
+constexpr KeyModifier alt{0b100};
+} // namespace key_modifiers
+} // namespace cru::platform::native
diff --git a/include/cru/platform/native/window.hpp b/include/cru/platform/native/window.hpp
index 0d40702f..dcb9effa 100644
--- a/include/cru/platform/native/window.hpp
+++ b/include/cru/platform/native/window.hpp
@@ -55,8 +55,8 @@ struct INativeWindow : virtual INativeResource {
virtual IEvent<Point>* MouseMoveEvent() = 0;
virtual IEvent<NativeMouseButtonEventArgs>* MouseDownEvent() = 0;
virtual IEvent<NativeMouseButtonEventArgs>* MouseUpEvent() = 0;
- virtual IEvent<int>* KeyDownEvent() = 0;
- virtual IEvent<int>* KeyUpEvent() = 0;
+ virtual IEvent<NativeKeyEventArgs>* KeyDownEvent() = 0;
+ virtual IEvent<NativeKeyEventArgs>* KeyUpEvent() = 0;
virtual IEvent<std::string>* CharEvent() = 0;
};