aboutsummaryrefslogtreecommitdiff
path: root/src/platform/gui/sdl/Window.cpp
diff options
context:
space:
mode:
authorYuqian Yang <crupest@crupest.life>2025-10-16 23:57:23 +0800
committerYuqian Yang <crupest@crupest.life>2025-10-16 23:57:23 +0800
commit2a9118d137b411b3871073bb6ab18ba98c225d34 (patch)
treeb5fbcf4d6ca1023efd1f3a9383ae8b242b9aadf6 /src/platform/gui/sdl/Window.cpp
parent0b0a8a4087bd3843d4aa9140a9f302423ad5fde8 (diff)
downloadcru-2a9118d137b411b3871073bb6ab18ba98c225d34.tar.gz
cru-2a9118d137b411b3871073bb6ab18ba98c225d34.tar.bz2
cru-2a9118d137b411b3871073bb6ab18ba98c225d34.zip
Bootstrap sdl.
Diffstat (limited to 'src/platform/gui/sdl/Window.cpp')
-rw-r--r--src/platform/gui/sdl/Window.cpp170
1 files changed, 170 insertions, 0 deletions
diff --git a/src/platform/gui/sdl/Window.cpp b/src/platform/gui/sdl/Window.cpp
new file mode 100644
index 00000000..e802b82f
--- /dev/null
+++ b/src/platform/gui/sdl/Window.cpp
@@ -0,0 +1,170 @@
+#include "cru/platform/gui/sdl/Window.h"
+#include "cru/base/Base.h"
+#include "cru/platform/Check.h"
+#include "cru/platform/GraphicsBase.h"
+#include "cru/platform/graphics/NullPainter.h"
+#include "cru/platform/graphics/Painter.h"
+#include "cru/platform/gui/Base.h"
+#include "cru/platform/gui/Window.h"
+#include "cru/platform/gui/sdl/UiApplication.h"
+
+#include <SDL_video.h>
+#include <cairo-xcb.h>
+#include <cairo.h>
+#include <cassert>
+#include <memory>
+#include <optional>
+
+namespace cru::platform::gui::sdl {
+
+SdlWindow::SdlWindow(SdlUiApplication *application)
+ : application_(application), parent_(nullptr) {
+ application->RegisterWindow(this);
+}
+
+SdlWindow::~SdlWindow() { application_->UnregisterWindow(this); }
+
+bool SdlWindow::IsCreated() { return sdl_window_.has_value(); }
+
+void SdlWindow::Close() {
+ if (sdl_window_) {
+ SDL_DestroyWindow(*sdl_window_);
+ }
+}
+
+INativeWindow *SdlWindow::GetParent() { return parent_; }
+
+void SdlWindow::SetParent(INativeWindow *parent) {
+ parent_ = CheckPlatform<SdlWindow>(parent, GetPlatformIdUtf8());
+ NotImplemented();
+}
+
+WindowStyleFlag SdlWindow::GetStyleFlag() { return style_; }
+
+void SdlWindow::SetStyleFlag(WindowStyleFlag flag) {
+ style_ = flag;
+ NotImplemented();
+}
+
+String SdlWindow::GetTitle() { NotImplemented(); }
+
+void SdlWindow::SetTitle(String title) { NotImplemented(); }
+
+WindowVisibilityType SdlWindow::GetVisibility() { NotImplemented(); }
+
+void SdlWindow::SetVisibility(WindowVisibilityType visibility) {
+ NotImplemented();
+}
+
+Size SdlWindow::GetClientSize() { return GetClientRect().GetSize(); }
+
+void SdlWindow::SetClientSize(const Size &size) {
+ auto rect = GetClientRect();
+ SetClientRect(Rect(rect.GetLeftTop(), size));
+}
+
+Rect SdlWindow::GetClientRect() {
+ if (!sdl_window_) return {};
+ NotImplemented();
+}
+
+void SdlWindow::SetClientRect(const Rect &rect) {
+ if (!sdl_window_) return;
+ NotImplemented();
+}
+
+Rect SdlWindow::GetWindowRect() {
+ if (!sdl_window_) return {};
+ NotImplemented();
+}
+
+void SdlWindow::SetWindowRect(const Rect &rect) {
+ if (!sdl_window_) return;
+ NotImplemented();
+}
+
+bool SdlWindow::RequestFocus() {
+ if (!sdl_window_) return false;
+ NotImplemented();
+}
+
+Point SdlWindow::GetMousePosition() { NotImplemented(); }
+
+bool SdlWindow::CaptureMouse() {
+ if (!sdl_window_) return false;
+ NotImplemented();
+}
+
+bool SdlWindow::ReleaseMouse() {
+ if (!sdl_window_) return false;
+ NotImplemented();
+}
+
+void SdlWindow::SetCursor(std::shared_ptr<ICursor> cursor) {
+ if (!sdl_window_) return;
+ NotImplemented();
+}
+
+void SdlWindow::SetToForeground() {
+ SetVisibility(WindowVisibilityType::Show);
+ NotImplemented();
+}
+
+void SdlWindow::RequestRepaint() {
+ if (!sdl_window_) return;
+ NotImplemented();
+}
+
+std::unique_ptr<graphics::IPainter> SdlWindow::BeginPaint() {
+ if (!sdl_window_.has_value()) {
+ return std::make_unique<graphics::NullPainter>();
+ }
+
+ NotImplemented();
+}
+
+IEvent<std::nullptr_t> *SdlWindow::CreateEvent() { return &create_event_; }
+
+IEvent<std::nullptr_t> *SdlWindow::DestroyEvent() { return &destroy_event_; }
+
+IEvent<std::nullptr_t> *SdlWindow::PaintEvent() { return &paint_event_; }
+
+IEvent<WindowVisibilityType> *SdlWindow::VisibilityChangeEvent() {
+ return &visibility_change_event_;
+}
+
+IEvent<Size> *SdlWindow::ResizeEvent() { return &resize_event_; }
+
+IEvent<FocusChangeType> *SdlWindow::FocusEvent() { return &focus_event_; }
+
+IEvent<MouseEnterLeaveType> *SdlWindow::MouseEnterLeaveEvent() {
+ return &mouse_enter_leave_event_;
+}
+
+IEvent<Point> *SdlWindow::MouseMoveEvent() { return &mouse_move_event_; }
+
+IEvent<NativeMouseButtonEventArgs> *SdlWindow::MouseDownEvent() {
+ return &mouse_down_event_;
+}
+
+IEvent<NativeMouseButtonEventArgs> *SdlWindow::MouseUpEvent() {
+ return &mouse_up_event_;
+}
+
+IEvent<NativeMouseWheelEventArgs> *SdlWindow::MouseWheelEvent() {
+ return &mouse_wheel_event_;
+}
+
+IEvent<NativeKeyEventArgs> *SdlWindow::KeyDownEvent() {
+ return &key_down_event_;
+}
+
+IEvent<NativeKeyEventArgs> *SdlWindow::KeyUpEvent() { return &key_up_event_; }
+
+IInputMethodContext *SdlWindow::GetInputMethodContext() { NotImplemented(); }
+
+std::optional<SDL_Window *> SdlWindow::GetSdlWindow() { return sdl_window_; }
+
+SdlUiApplication *SdlWindow::GetSdlUiApplication() { return application_; }
+
+} // namespace cru::platform::gui::sdl