aboutsummaryrefslogtreecommitdiff
path: root/src/platform/gui/sdl
diff options
context:
space:
mode:
authorYuqian Yang <crupest@crupest.life>2025-11-27 17:39:31 +0800
committerYuqian Yang <crupest@crupest.life>2025-11-27 17:39:31 +0800
commit97ca464fc9e9da4e20e3320559a6f4ac3203fe84 (patch)
treefa23dd3d31fd6c86814ef4505ae2f7966b840ed2 /src/platform/gui/sdl
parent6e8d570e3d63b5bc4e24d258d2dd383530ace2a3 (diff)
downloadcru-97ca464fc9e9da4e20e3320559a6f4ac3203fe84.tar.gz
cru-97ca464fc9e9da4e20e3320559a6f4ac3203fe84.tar.bz2
cru-97ca464fc9e9da4e20e3320559a6f4ac3203fe84.zip
Clean code. Use event define macro of native window on linux.
Diffstat (limited to 'src/platform/gui/sdl')
-rw-r--r--src/platform/gui/sdl/UiApplication.cpp14
-rw-r--r--src/platform/gui/sdl/Window.cpp56
2 files changed, 19 insertions, 51 deletions
diff --git a/src/platform/gui/sdl/UiApplication.cpp b/src/platform/gui/sdl/UiApplication.cpp
index b448d8f0..c876ad19 100644
--- a/src/platform/gui/sdl/UiApplication.cpp
+++ b/src/platform/gui/sdl/UiApplication.cpp
@@ -25,6 +25,8 @@ SdlUiApplication::SdlUiApplication(graphics::IGraphicsFactory* graphics_factory,
SdlUiApplication::~SdlUiApplication() {
SDL_Quit();
+ delete_later_pool_.Clean();
+
if (release_graphics_factory_) {
delete graphics_factory_;
}
@@ -32,14 +34,12 @@ SdlUiApplication::~SdlUiApplication() {
int SdlUiApplication::Run() {
while (true) {
- auto now = std::chrono::steady_clock::now();
-
- if (auto result = timers_.Update(now)) {
+ if (auto result = timers_.Update(std::chrono::steady_clock::now())) {
result->data();
continue;
}
- auto timeout = timers_.NextTimeout(now);
+ auto timeout = timers_.NextTimeout(std::chrono::steady_clock::now());
SDL_Event event;
CheckSdlReturn(timeout ? SDL_WaitEventTimeout(&event, timeout->count())
@@ -47,6 +47,8 @@ int SdlUiApplication::Run() {
if (event.type == SDL_EVENT_QUIT) {
break;
}
+
+ delete_later_pool_.Clean();
}
for (const auto& handler : this->quit_handlers_) {
@@ -95,6 +97,10 @@ void SdlUiApplication::CancelTimer(long long id) {
return timers_.Remove(static_cast<int>(id));
}
+void SdlUiApplication::DeleteLater(Object* object) {
+ delete_later_pool_.Add(object);
+}
+
std::vector<INativeWindow*> SdlUiApplication::GetAllWindow() {
std::vector<INativeWindow*> windows(windows_.size());
std::ranges::copy(windows_, windows.begin());
diff --git a/src/platform/gui/sdl/Window.cpp b/src/platform/gui/sdl/Window.cpp
index 72ccc873..654ac4cd 100644
--- a/src/platform/gui/sdl/Window.cpp
+++ b/src/platform/gui/sdl/Window.cpp
@@ -15,7 +15,7 @@
namespace cru::platform::gui::sdl {
-SdlWindow::SdlWindow(SdlUiApplication *application)
+SdlWindow::SdlWindow(SdlUiApplication* application)
: application_(application), parent_(nullptr) {
application->RegisterWindow(this);
}
@@ -30,9 +30,9 @@ void SdlWindow::Close() {
}
}
-INativeWindow *SdlWindow::GetParent() { return parent_; }
+INativeWindow* SdlWindow::GetParent() { return parent_; }
-void SdlWindow::SetParent(INativeWindow *parent) {
+void SdlWindow::SetParent(INativeWindow* parent) {
parent_ = CheckPlatform<SdlWindow>(parent, GetPlatformId());
NotImplemented();
}
@@ -56,7 +56,7 @@ void SdlWindow::SetVisibility(WindowVisibilityType visibility) {
Size SdlWindow::GetClientSize() { return GetClientRect().GetSize(); }
-void SdlWindow::SetClientSize(const Size &size) {
+void SdlWindow::SetClientSize(const Size& size) {
auto rect = GetClientRect();
SetClientRect(Rect(rect.GetLeftTop(), size));
}
@@ -66,7 +66,7 @@ Rect SdlWindow::GetClientRect() {
NotImplemented();
}
-void SdlWindow::SetClientRect(const Rect &rect) {
+void SdlWindow::SetClientRect(const Rect& rect) {
if (!sdl_window_) return;
NotImplemented();
}
@@ -76,7 +76,7 @@ Rect SdlWindow::GetWindowRect() {
NotImplemented();
}
-void SdlWindow::SetWindowRect(const Rect &rect) {
+void SdlWindow::SetWindowRect(const Rect& rect) {
if (!sdl_window_) return;
NotImplemented();
}
@@ -121,48 +121,10 @@ std::unique_ptr<graphics::IPainter> SdlWindow::BeginPaint() {
NotImplemented();
}
-IEvent<std::nullptr_t> *SdlWindow::CreateEvent() { return &create_event_; }
+IInputMethodContext* SdlWindow::GetInputMethodContext() { NotImplemented(); }
-IEvent<std::nullptr_t> *SdlWindow::DestroyEvent() { return &destroy_event_; }
+std::optional<SDL_Window*> SdlWindow::GetSdlWindow() { return sdl_window_; }
-IEvent<std::nullptr_t> *SdlWindow::PaintEvent() { return &paint_event_; }
-
-IEvent<WindowVisibilityType> *SdlWindow::VisibilityChangeEvent() {
- return &visibility_change_event_;
-}
-
-IEvent<const Size&> *SdlWindow::ResizeEvent() { return &resize_event_; }
-
-IEvent<FocusChangeType> *SdlWindow::FocusEvent() { return &focus_event_; }
-
-IEvent<MouseEnterLeaveType> *SdlWindow::MouseEnterLeaveEvent() {
- return &mouse_enter_leave_event_;
-}
-
-IEvent<const Point&> *SdlWindow::MouseMoveEvent() { return &mouse_move_event_; }
-
-IEvent<const NativeMouseButtonEventArgs&> *SdlWindow::MouseDownEvent() {
- return &mouse_down_event_;
-}
-
-IEvent<const NativeMouseButtonEventArgs&> *SdlWindow::MouseUpEvent() {
- return &mouse_up_event_;
-}
-
-IEvent<const NativeMouseWheelEventArgs&> *SdlWindow::MouseWheelEvent() {
- return &mouse_wheel_event_;
-}
-
-IEvent<const NativeKeyEventArgs&> *SdlWindow::KeyDownEvent() {
- return &key_down_event_;
-}
-
-IEvent<const 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_; }
+SdlUiApplication* SdlWindow::GetSdlUiApplication() { return application_; }
} // namespace cru::platform::gui::sdl