aboutsummaryrefslogtreecommitdiff
path: root/include/cru/platform/gui/Window.hpp
blob: a1816e4a7ecee0f2f973bd3229d5c69e8e5d4cb2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#pragma once
#include "Base.hpp"

#include "Keyboard.hpp"

#include "cru/common/Event.hpp"

#include <string_view>

namespace cru::platform::gui {
enum class FocusChangeType { Gain, Lost };

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;
};

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 bool IsVisible() = 0;
  virtual void SetVisible(bool is_visible) = 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<ICursor> cursor) = 0;

  virtual void RequestRepaint() = 0;

  // Remember to call EndDraw on return value and destroy it.
  virtual std::unique_ptr<graphics::IPainter> BeginPaint() = 0;

  // Don't use this instance after receive this event.
  virtual IEvent<std::nullptr_t>* CreateEvent() = 0;
  virtual IEvent<std::nullptr_t>* DestroyEvent() = 0;
  virtual IEvent<std::nullptr_t>* PaintEvent() = 0;
  virtual IEvent<Size>* ResizeEvent() = 0;
  virtual IEvent<FocusChangeType>* FocusEvent() = 0;
  virtual IEvent<MouseEnterLeaveType>* MouseEnterLeaveEvent() = 0;
  virtual IEvent<Point>* MouseMoveEvent() = 0;
  virtual IEvent<NativeMouseButtonEventArgs>* MouseDownEvent() = 0;
  virtual IEvent<NativeMouseButtonEventArgs>* MouseUpEvent() = 0;
  virtual IEvent<NativeMouseWheelEventArgs>* MouseWheelEvent() = 0;
  virtual IEvent<NativeKeyEventArgs>* KeyDownEvent() = 0;
  virtual IEvent<NativeKeyEventArgs>* KeyUpEvent() = 0;

  virtual IInputMethodContext* GetInputMethodContext() = 0;
};
}  // namespace cru::platform::gui