aboutsummaryrefslogtreecommitdiff
path: root/src/platform/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/platform/gui')
-rw-r--r--src/platform/gui/sdl/UiApplication.cpp14
-rw-r--r--src/platform/gui/sdl/Window.cpp56
-rw-r--r--src/platform/gui/xcb/Window.cpp83
3 files changed, 42 insertions, 111 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
diff --git a/src/platform/gui/xcb/Window.cpp b/src/platform/gui/xcb/Window.cpp
index f85ec634..50f2c9aa 100644
--- a/src/platform/gui/xcb/Window.cpp
+++ b/src/platform/gui/xcb/Window.cpp
@@ -6,6 +6,7 @@
#include "cru/platform/graphics/NullPainter.h"
#include "cru/platform/graphics/Painter.h"
#include "cru/platform/graphics/cairo/CairoPainter.h"
+#include "cru/platform/gui/Window.h"
#include "cru/platform/gui/xcb/Cursor.h"
#include "cru/platform/gui/xcb/Input.h"
#include "cru/platform/gui/xcb/InputMethod.h"
@@ -46,7 +47,7 @@ XcbWindow::XcbWindow(XcbUiApplication* application)
input_method_ = new XcbXimInputMethodContext(
application->GetXcbXimInputMethodManager(), this);
- paint_event_.AddSpyOnlyHandler([this] {
+ PaintEvent_.AddSpyOnlyHandler([this] {
if (xcb_window_)
CRU_LOG_TAG_DEBUG("{:#x} Paint event triggered.", *xcb_window_);
});
@@ -288,8 +289,10 @@ void XcbWindow::RequestRepaint() {
if (!xcb_window_.has_value()) return;
CRU_LOG_TAG_DEBUG("{:#x} Repaint requested.", *xcb_window_);
// TODO: true throttle
- repaint_canceler_.Reset(
- application_->SetImmediate([this] { paint_event_.Raise(nullptr); }));
+ repaint_canceler_.Reset(application_->SetImmediate([this] {
+ PaintEvent_.Raise(nullptr);
+ Paint1Event_.Raise({{{}, GetClientSize()}});
+ }));
}
std::unique_ptr<graphics::IPainter> XcbWindow::BeginPaint() {
@@ -304,46 +307,6 @@ std::unique_ptr<graphics::IPainter> XcbWindow::BeginPaint() {
return std::unique_ptr<graphics::IPainter>(painter);
}
-IEvent<std::nullptr_t>* XcbWindow::CreateEvent() { return &create_event_; }
-
-IEvent<std::nullptr_t>* XcbWindow::DestroyEvent() { return &destroy_event_; }
-
-IEvent<std::nullptr_t>* XcbWindow::PaintEvent() { return &paint_event_; }
-
-IEvent<WindowVisibilityType>* XcbWindow::VisibilityChangeEvent() {
- return &visibility_change_event_;
-}
-
-IEvent<const Size&>* XcbWindow::ResizeEvent() { return &resize_event_; }
-
-IEvent<FocusChangeType>* XcbWindow::FocusEvent() { return &focus_event_; }
-
-IEvent<MouseEnterLeaveType>* XcbWindow::MouseEnterLeaveEvent() {
- return &mouse_enter_leave_event_;
-}
-
-IEvent<const Point&>* XcbWindow::MouseMoveEvent() { return &mouse_move_event_; }
-
-IEvent<const NativeMouseButtonEventArgs&>* XcbWindow::MouseDownEvent() {
- return &mouse_down_event_;
-}
-
-IEvent<const NativeMouseButtonEventArgs&>* XcbWindow::MouseUpEvent() {
- return &mouse_up_event_;
-}
-
-IEvent<const NativeMouseWheelEventArgs&>* XcbWindow::MouseWheelEvent() {
- return &mouse_wheel_event_;
-}
-
-IEvent<const NativeKeyEventArgs&>* XcbWindow::KeyDownEvent() {
- return &key_down_event_;
-}
-
-IEvent<const NativeKeyEventArgs&>* XcbWindow::KeyUpEvent() {
- return &key_up_event_;
-}
-
IInputMethodContext* XcbWindow::GetInputMethodContext() {
return input_method_;
}
@@ -415,8 +378,8 @@ xcb_window_t XcbWindow::DoCreateWindow() {
cairo_surface_ =
cairo_xcb_surface_create(connection, window, visual_type, width, height);
- create_event_.Raise(nullptr);
- resize_event_.Raise(current_size_);
+ CreateEvent_.Raise(nullptr);
+ ResizeEvent_.Raise(current_size_);
RequestRepaint();
return window;
@@ -429,7 +392,7 @@ void XcbWindow::HandleEvent(xcb_generic_event_t* event) {
break;
}
case XCB_DESTROY_NOTIFY: {
- destroy_event_.Raise(nullptr);
+ DestroyEvent_.Raise(nullptr);
cairo_surface_destroy(cairo_surface_);
cairo_surface_ = nullptr;
@@ -454,26 +417,26 @@ void XcbWindow::HandleEvent(xcb_generic_event_t* event) {
current_size_ = Size(width, height);
assert(cairo_surface_);
cairo_xcb_surface_set_size(cairo_surface_, width, height);
- resize_event_.Raise(current_size_);
+ ResizeEvent_.Raise(current_size_);
}
break;
}
case XCB_MAP_NOTIFY: {
- visibility_change_event_.Raise(WindowVisibilityType::Show);
+ VisibilityChangeEvent_.Raise(WindowVisibilityType::Show);
mapped_ = true;
break;
}
case XCB_UNMAP_NOTIFY: {
- visibility_change_event_.Raise(WindowVisibilityType::Hide);
+ VisibilityChangeEvent_.Raise(WindowVisibilityType::Hide);
mapped_ = false;
break;
}
case XCB_FOCUS_IN: {
- focus_event_.Raise(FocusChangeType::Gain);
+ FocusEvent_.Raise(FocusChangeType::Gain);
break;
}
case XCB_FOCUS_OUT: {
- focus_event_.Raise(FocusChangeType::Lose);
+ FocusEvent_.Raise(FocusChangeType::Lose);
break;
}
case XCB_BUTTON_PRESS: {
@@ -489,14 +452,14 @@ void XcbWindow::HandleEvent(xcb_generic_event_t* event) {
if (bp->detail == 6 || bp->detail == 7) {
args.horizontal = true;
}
- mouse_wheel_event_.Raise(std::move(args));
+ MouseWheelEvent_.Raise(std::move(args));
break;
}
NativeMouseButtonEventArgs args(ConvertMouseButton(bp->detail),
Point(bp->event_x, bp->event_y),
ConvertModifiersOfEvent(bp->state));
- mouse_down_event_.Raise(std::move(args));
+ MouseDownEvent_.Raise(std::move(args));
break;
}
case XCB_BUTTON_RELEASE: {
@@ -504,20 +467,20 @@ void XcbWindow::HandleEvent(xcb_generic_event_t* event) {
NativeMouseButtonEventArgs args(ConvertMouseButton(br->detail),
Point(br->event_x, br->event_y),
ConvertModifiersOfEvent(br->state));
- mouse_up_event_.Raise(std::move(args));
+ MouseUpEvent_.Raise(std::move(args));
break;
}
case XCB_MOTION_NOTIFY: {
xcb_motion_notify_event_t* motion = (xcb_motion_notify_event_t*)event;
Point point(motion->event_x, motion->event_y);
- mouse_move_event_.Raise(point);
+ MouseMoveEvent_.Raise(point);
break;
}
case XCB_ENTER_NOTIFY: {
xcb_enter_notify_event_t* enter = (xcb_enter_notify_event_t*)event;
- mouse_enter_leave_event_.Raise(MouseEnterLeaveType::Enter);
+ MouseEnterLeaveEvent_.Raise(MouseEnterLeaveType::Enter);
Point point(enter->event_x, enter->event_y);
- mouse_move_event_.Raise(point);
+ MouseMoveEvent_.Raise(point);
break;
}
case XCB_LEAVE_NOTIFY: {
@@ -525,21 +488,21 @@ void XcbWindow::HandleEvent(xcb_generic_event_t* event) {
// xcb_leave_notify_event_t *leave = (xcb_leave_notify_event_t *)event;
// Point point(leave->event_x, leave->event_y);
// mouse_move_event_.Raise(point);
- mouse_enter_leave_event_.Raise(MouseEnterLeaveType::Leave);
+ MouseEnterLeaveEvent_.Raise(MouseEnterLeaveType::Leave);
break;
}
case XCB_KEY_PRESS: {
xcb_key_press_event_t* kp = (xcb_key_press_event_t*)event;
NativeKeyEventArgs args(XorgKeycodeToCruKeyCode(application_, kp->detail),
ConvertModifiersOfEvent(kp->state));
- key_down_event_.Raise(std::move(args));
+ KeyDownEvent_.Raise(std::move(args));
break;
}
case XCB_KEY_RELEASE: {
xcb_key_release_event_t* kr = (xcb_key_release_event_t*)event;
NativeKeyEventArgs args(XorgKeycodeToCruKeyCode(application_, kr->detail),
ConvertModifiersOfEvent(kr->state));
- key_up_event_.Raise(std::move(args));
+ KeyUpEvent_.Raise(std::move(args));
break;
}
case XCB_CLIENT_MESSAGE: {