From 06d1d0442276a05b6caad6e3468f4afb1e8ee5df Mon Sep 17 00:00:00 2001 From: crupest Date: Sun, 28 Jun 2020 00:03:11 +0800 Subject: ... --- include/cru/platform/native/Base.hpp | 52 ++++++++++++++ include/cru/platform/native/Cursor.hpp | 15 ++++ include/cru/platform/native/Keyboard.hpp | 120 +++++++++++++++++++++++++++++++ include/cru/platform/native/Window.hpp | 67 +++++++++++++++++ include/cru/platform/native/base.hpp | 52 -------------- include/cru/platform/native/cursor.hpp | 15 ---- include/cru/platform/native/keyboard.hpp | 120 ------------------------------- include/cru/platform/native/window.hpp | 67 ----------------- 8 files changed, 254 insertions(+), 254 deletions(-) create mode 100644 include/cru/platform/native/Base.hpp create mode 100644 include/cru/platform/native/Cursor.hpp create mode 100644 include/cru/platform/native/Keyboard.hpp create mode 100644 include/cru/platform/native/Window.hpp delete mode 100644 include/cru/platform/native/base.hpp delete mode 100644 include/cru/platform/native/cursor.hpp delete mode 100644 include/cru/platform/native/keyboard.hpp delete mode 100644 include/cru/platform/native/window.hpp (limited to 'include/cru/platform/native') diff --git a/include/cru/platform/native/Base.hpp b/include/cru/platform/native/Base.hpp new file mode 100644 index 00000000..bba7b960 --- /dev/null +++ b/include/cru/platform/native/Base.hpp @@ -0,0 +1,52 @@ +#pragma once +#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; +struct ICursorManager; +struct IUiApplication; +struct INativeWindow; +struct INativeWindowResolver; +struct IInputMethodManager; +struct IInputMethodContext; + +struct Dpi { + float x; + float y; +}; + +namespace details { +struct TagMouseButton {}; +} // namespace details + +using MouseButton = Bitmask; + +namespace mouse_buttons { +constexpr MouseButton left{0b1}; +constexpr MouseButton middle{0b10}; +constexpr MouseButton right{0b100}; +} // namespace mouse_buttons + +enum class SystemCursorType { + Arrow, + Hand, +}; + +struct NativeMouseButtonEventArgs { + MouseButton button; + Point point; + KeyModifier modifier; +}; + +struct NativeKeyEventArgs { + KeyCode key; + KeyModifier modifier; +}; + +enum class FocusChangeType { Gain, Lost }; + +enum class MouseEnterLeaveType { Enter, Leave }; +} // namespace cru::platform::native diff --git a/include/cru/platform/native/Cursor.hpp b/include/cru/platform/native/Cursor.hpp new file mode 100644 index 00000000..6c8f8068 --- /dev/null +++ b/include/cru/platform/native/Cursor.hpp @@ -0,0 +1,15 @@ +#pragma once +#include "../Resource.hpp" +#include "Base.hpp" + +#include + +namespace cru::platform::native { +struct ICursor : virtual INativeResource {}; + +struct ICursorManager : virtual INativeResource { + virtual std::shared_ptr GetSystemCursor(SystemCursorType type) = 0; + + // TODO: Add method to create cursor. +}; +} // namespace cru::platform::native diff --git a/include/cru/platform/native/Keyboard.hpp b/include/cru/platform/native/Keyboard.hpp new file mode 100644 index 00000000..26a1409d --- /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; + +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 new file mode 100644 index 00000000..1fcac1fc --- /dev/null +++ b/include/cru/platform/native/Window.hpp @@ -0,0 +1,67 @@ +#pragma once +#include "../Resource.hpp" +#include "Base.hpp" +#include "cru/common/Event.hpp" + +#include + +namespace cru::platform::native { +// Represents a native window, which exposes some low-level events and +// operations. +// +// Usually you save an INativeWindowResolver after creating a window. Because +// window may be destroyed when user do certain actions like click the close +// button. Then the INativeWindow instance is destroyed and +// INativeWindowResolver::Resolve return nullptr to indicate the fact. +struct INativeWindow : virtual INativeResource { + virtual std::shared_ptr GetResolver() = 0; + + virtual void Close() = 0; + + virtual INativeWindow* GetParent() = 0; + + virtual bool IsVisible() = 0; + virtual void SetVisible(bool is_visible) = 0; + + virtual Size GetClientSize() = 0; + virtual void SetClientSize(const Size& size) = 0; + + // Get the rect of the window containing frame. + // The lefttop of the rect is relative to screen lefttop. + virtual Rect GetWindowRect() = 0; + + // Set the rect of the window containing frame. + // The lefttop of the rect is relative to screen lefttop. + virtual void SetWindowRect(const Rect& rect) = 0; + + // Relative to client lefttop. + virtual Point GetMousePosition() = 0; + + virtual bool CaptureMouse() = 0; + virtual bool ReleaseMouse() = 0; + + virtual void SetCursor(std::shared_ptr cursor) = 0; + + virtual void RequestRepaint() = 0; + + // Remember to call EndDraw on return value and destroy it. + virtual std::unique_ptr BeginPaint() = 0; + + virtual IEvent* DestroyEvent() = 0; + virtual IEvent* PaintEvent() = 0; + virtual IEvent* ResizeEvent() = 0; + virtual IEvent* FocusEvent() = 0; + virtual IEvent* MouseEnterLeaveEvent() = 0; + virtual IEvent* MouseMoveEvent() = 0; + virtual IEvent* MouseDownEvent() = 0; + virtual IEvent* MouseUpEvent() = 0; + virtual IEvent* KeyDownEvent() = 0; + virtual IEvent* KeyUpEvent() = 0; +}; + +// See INativeWindow for more info. +struct INativeWindowResolver : virtual INativeResource { + // Think twice before you save the return value. + virtual INativeWindow* Resolve() = 0; +}; +} // namespace cru::platform::native diff --git a/include/cru/platform/native/base.hpp b/include/cru/platform/native/base.hpp deleted file mode 100644 index bba7b960..00000000 --- a/include/cru/platform/native/base.hpp +++ /dev/null @@ -1,52 +0,0 @@ -#pragma once -#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; -struct ICursorManager; -struct IUiApplication; -struct INativeWindow; -struct INativeWindowResolver; -struct IInputMethodManager; -struct IInputMethodContext; - -struct Dpi { - float x; - float y; -}; - -namespace details { -struct TagMouseButton {}; -} // namespace details - -using MouseButton = Bitmask; - -namespace mouse_buttons { -constexpr MouseButton left{0b1}; -constexpr MouseButton middle{0b10}; -constexpr MouseButton right{0b100}; -} // namespace mouse_buttons - -enum class SystemCursorType { - Arrow, - Hand, -}; - -struct NativeMouseButtonEventArgs { - MouseButton button; - Point point; - KeyModifier modifier; -}; - -struct NativeKeyEventArgs { - KeyCode key; - KeyModifier modifier; -}; - -enum class FocusChangeType { Gain, Lost }; - -enum class MouseEnterLeaveType { Enter, Leave }; -} // namespace cru::platform::native diff --git a/include/cru/platform/native/cursor.hpp b/include/cru/platform/native/cursor.hpp deleted file mode 100644 index 6c8f8068..00000000 --- a/include/cru/platform/native/cursor.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once -#include "../Resource.hpp" -#include "Base.hpp" - -#include - -namespace cru::platform::native { -struct ICursor : virtual INativeResource {}; - -struct ICursorManager : virtual INativeResource { - virtual std::shared_ptr GetSystemCursor(SystemCursorType type) = 0; - - // TODO: Add method to create cursor. -}; -} // namespace cru::platform::native diff --git a/include/cru/platform/native/keyboard.hpp b/include/cru/platform/native/keyboard.hpp deleted file mode 100644 index 26a1409d..00000000 --- a/include/cru/platform/native/keyboard.hpp +++ /dev/null @@ -1,120 +0,0 @@ -#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; - -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 deleted file mode 100644 index 1fcac1fc..00000000 --- a/include/cru/platform/native/window.hpp +++ /dev/null @@ -1,67 +0,0 @@ -#pragma once -#include "../Resource.hpp" -#include "Base.hpp" -#include "cru/common/Event.hpp" - -#include - -namespace cru::platform::native { -// Represents a native window, which exposes some low-level events and -// operations. -// -// Usually you save an INativeWindowResolver after creating a window. Because -// window may be destroyed when user do certain actions like click the close -// button. Then the INativeWindow instance is destroyed and -// INativeWindowResolver::Resolve return nullptr to indicate the fact. -struct INativeWindow : virtual INativeResource { - virtual std::shared_ptr GetResolver() = 0; - - virtual void Close() = 0; - - virtual INativeWindow* GetParent() = 0; - - virtual bool IsVisible() = 0; - virtual void SetVisible(bool is_visible) = 0; - - virtual Size GetClientSize() = 0; - virtual void SetClientSize(const Size& size) = 0; - - // Get the rect of the window containing frame. - // The lefttop of the rect is relative to screen lefttop. - virtual Rect GetWindowRect() = 0; - - // Set the rect of the window containing frame. - // The lefttop of the rect is relative to screen lefttop. - virtual void SetWindowRect(const Rect& rect) = 0; - - // Relative to client lefttop. - virtual Point GetMousePosition() = 0; - - virtual bool CaptureMouse() = 0; - virtual bool ReleaseMouse() = 0; - - virtual void SetCursor(std::shared_ptr cursor) = 0; - - virtual void RequestRepaint() = 0; - - // Remember to call EndDraw on return value and destroy it. - virtual std::unique_ptr BeginPaint() = 0; - - virtual IEvent* DestroyEvent() = 0; - virtual IEvent* PaintEvent() = 0; - virtual IEvent* ResizeEvent() = 0; - virtual IEvent* FocusEvent() = 0; - virtual IEvent* MouseEnterLeaveEvent() = 0; - virtual IEvent* MouseMoveEvent() = 0; - virtual IEvent* MouseDownEvent() = 0; - virtual IEvent* MouseUpEvent() = 0; - virtual IEvent* KeyDownEvent() = 0; - virtual IEvent* KeyUpEvent() = 0; -}; - -// See INativeWindow for more info. -struct INativeWindowResolver : virtual INativeResource { - // Think twice before you save the return value. - virtual INativeWindow* Resolve() = 0; -}; -} // namespace cru::platform::native -- cgit v1.2.3