aboutsummaryrefslogtreecommitdiff
path: root/include/cru/platform/gui/sdl/Window.h
blob: 0fd9b8e6c5040555c955f0bf5f26eb89581b8e09 (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
#pragma once
#include "../../GraphicsBase.h"
#include "../Window.h"
#include "Base.h"

#include <SDL3/SDL_video.h>
#include <optional>

namespace cru::platform::gui::sdl {
class SdlUiApplication;

class SdlWindow : public SdlResource, public virtual INativeWindow {
  CRU_DEFINE_CLASS_LOG_TAG("cru::platform::gui::xcb::SdlWindow")

  friend SdlUiApplication;

 public:
  explicit SdlWindow(SdlUiApplication* application);
  ~SdlWindow() override;

  bool IsCreated() override;
  void Close() override;

  INativeWindow* GetParent() override;
  void SetParent(INativeWindow* parent) override;

  WindowStyleFlag GetStyleFlag() override;
  void SetStyleFlag(WindowStyleFlag flag) override;

  std::string GetTitle() override;
  void SetTitle(std::string title) override;

  WindowVisibilityType GetVisibility() override;
  void SetVisibility(WindowVisibilityType visibility) override;

  Size GetClientSize() override;
  void SetClientSize(const Size& size) override;

  Rect GetClientRect() override;
  void SetClientRect(const Rect& rect) override;

  Rect GetWindowRect() override;
  void SetWindowRect(const Rect& rect) override;

  bool RequestFocus() override;

  Point GetMousePosition() override;

  bool CaptureMouse() override;
  bool ReleaseMouse() override;

  void SetCursor(std::shared_ptr<ICursor> cursor) override;

  void SetToForeground() override;

  void RequestRepaint() override;

  std::unique_ptr<graphics::IPainter> BeginPaint() override;

  CRU_DEFINE_CRU_PLATFORM_GUI_I_NATIVE_WINDOW_OVERRIDE_EVENTS()

  IInputMethodContext* GetInputMethodContext() override;

 public:
  std::optional<SDL_Window*> GetSdlWindow();
  SdlUiApplication* GetSdlUiApplication();
  float GetDisplayScale();
  Thickness GetBorderThickness();

  private:
  void DoCreateWindow();
  void DoUpdateClientRect();
  void DoUpdateParent();
  void DoUpdateStyleFlag();
  void DoUpdateTitle();

 private:
  SdlUiApplication* application_;
  std::optional<SDL_Window*> sdl_window_;
  Rect client_rect_;
  SdlWindow* parent_;
  EventHandlerRevokerGuard parent_create_guard_;
  WindowStyleFlag style_;
  std::string title_;
};
}  // namespace cru::platform::gui::sdl