From 74bb9cd27242b9320f99ff4d2b50c3051576cc14 Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 8 Feb 2022 16:53:51 +0800 Subject: ... --- include/cru/platform/gui/Window.h | 112 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 include/cru/platform/gui/Window.h (limited to 'include/cru/platform/gui/Window.h') diff --git a/include/cru/platform/gui/Window.h b/include/cru/platform/gui/Window.h new file mode 100644 index 00000000..d3f0daad --- /dev/null +++ b/include/cru/platform/gui/Window.h @@ -0,0 +1,112 @@ +#pragma once +#include "Base.h" + +#include "Keyboard.h" + +#include "cru/common/Event.h" + +#include + +namespace cru::platform::gui { +namespace details { +struct WindowStyleFlagTag; +} + +using WindowStyleFlag = Bitmask; + +struct WindowStyleFlags { + static constexpr WindowStyleFlag NoCaptionAndBorder{0b1}; +}; + +enum class WindowVisibilityType { Show, Hide, Minimize }; + +enum class FocusChangeType { Gain, Lose }; + +enum class MouseEnterLeaveType { Enter, Leave }; + +struct NativeMouseButtonEventArgs { + MouseButton button; + Point point; + KeyModifier modifier; +}; + +struct NativeMouseWheelEventArgs { + // Positive means down. Negative means up. + float delta; + Point point; + KeyModifier modifier; + bool horizontal; // true if horizontal wheel. +}; + +struct NativeKeyEventArgs { + KeyCode key; + KeyModifier modifier; +}; + +// Represents a native window, which exposes some low-level events and +// operations. +struct INativeWindow : virtual IPlatformResource { + virtual void Close() = 0; + + virtual INativeWindow* GetParent() = 0; + virtual void SetParent(INativeWindow* parent) = 0; + + virtual WindowStyleFlag GetStyleFlag() = 0; + virtual void SetStyleFlag(WindowStyleFlag flag) = 0; + + virtual String GetTitle() = 0; + virtual void SetTitle(String title) = 0; + + virtual WindowVisibilityType GetVisibility() = 0; + virtual void SetVisibility(WindowVisibilityType visibility) = 0; + + virtual Size GetClientSize() = 0; + virtual void SetClientSize(const Size& size) = 0; + + virtual Rect GetClientRect() = 0; + virtual void SetClientRect(const Rect& rect) = 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; + + virtual bool RequestFocus() = 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 SetToForeground() = 0; + + virtual void RequestRepaint() = 0; + + // Remember to call EndDraw on return value and destroy it. + virtual std::unique_ptr BeginPaint() = 0; + + virtual IEvent* CreateEvent() = 0; + virtual IEvent* DestroyEvent() = 0; + virtual IEvent* PaintEvent() = 0; + + virtual IEvent* VisibilityChangeEvent() = 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* MouseWheelEvent() = 0; + virtual IEvent* KeyDownEvent() = 0; + virtual IEvent* KeyUpEvent() = 0; + + virtual IInputMethodContext* GetInputMethodContext() = 0; +}; +} // namespace cru::platform::gui -- cgit v1.2.3