aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/cru/base/Base.h7
-rw-r--r--include/cru/base/Event.h7
-rw-r--r--include/cru/platform/gui/Window.h21
-rw-r--r--include/cru/platform/gui/win/Window.h50
-rw-r--r--src/base/Base.cpp2
-rw-r--r--src/platform/gui/Window.cpp5
-rw-r--r--src/platform/gui/win/Window.cpp39
-rw-r--r--src/ui/render/TextRenderObject.cpp2
8 files changed, 66 insertions, 67 deletions
diff --git a/include/cru/base/Base.h b/include/cru/base/Base.h
index fda45f66..3cd04f8c 100644
--- a/include/cru/base/Base.h
+++ b/include/cru/base/Base.h
@@ -137,12 +137,17 @@ class CRU_BASE_API Exception : public std::exception {
std::shared_ptr<std::exception> inner_;
};
+class CRU_BASE_API NotImplementedException : public Exception {
+ public:
+ using Exception::Exception; // inherit constructors
+};
+
class CRU_BASE_API PlatformException : public Exception {
public:
using Exception::Exception; // inherit constructors
};
-class ErrnoException : public Exception {
+class CRU_BASE_API ErrnoException : public Exception {
public:
ErrnoException();
explicit ErrnoException(int error_code);
diff --git a/include/cru/base/Event.h b/include/cru/base/Event.h
index bdaf3ea6..71c0ac6b 100644
--- a/include/cru/base/Event.h
+++ b/include/cru/base/Event.h
@@ -141,6 +141,13 @@ class Event : public EventBase, public IEvent<TEventArgs> {
public: \
::cru::IEvent<arg_type>* name##Event() { return &name##Event_; }
+#define CRU_DEFINE_EVENT_OVERRIDE(name, arg_type) \
+ private: \
+ ::cru::Event<arg_type> name##Event_; \
+ \
+ public: \
+ ::cru::IEvent<arg_type>* name##Event() override { return &name##Event_; }
+
namespace details {
struct EventHandlerRevokerCaller {
void operator()(const EventHandlerRevoker& revoker) { revoker(); }
diff --git a/include/cru/platform/gui/Window.h b/include/cru/platform/gui/Window.h
index b8973c5a..e04db448 100644
--- a/include/cru/platform/gui/Window.h
+++ b/include/cru/platform/gui/Window.h
@@ -23,6 +23,10 @@ struct WindowStyleFlags {
enum class WindowVisibilityType { Show, Hide, Minimize };
+struct NativePaintEventArgs {
+ Rect repaint_area;
+};
+
enum class FocusChangeType { Gain, Lose };
enum class MouseEnterLeaveType { Enter, Leave };
@@ -100,6 +104,7 @@ struct CRU_PLATFORM_GUI_API INativeWindow : virtual IPlatformResource {
virtual IEvent<std::nullptr_t>* CreateEvent() = 0;
virtual IEvent<std::nullptr_t>* DestroyEvent() = 0;
virtual IEvent<std::nullptr_t>* PaintEvent() = 0;
+ virtual IEvent<const NativePaintEventArgs&>* Paint1Event();
virtual IEvent<WindowVisibilityType>* VisibilityChangeEvent() = 0;
virtual IEvent<const Size&>* ResizeEvent() = 0;
@@ -116,3 +121,19 @@ struct CRU_PLATFORM_GUI_API INativeWindow : virtual IPlatformResource {
virtual IInputMethodContext* GetInputMethodContext() = 0;
};
} // namespace cru::platform::gui
+
+#define CRU_DEFINE_CRU_PLATFORM_GUI_I_NATIVE_WINDOW_OVERRIDE_EVENTS() \
+ CRU_DEFINE_EVENT_OVERRIDE(Create, std::nullptr_t) \
+ CRU_DEFINE_EVENT_OVERRIDE(Destroy, std::nullptr_t) \
+ CRU_DEFINE_EVENT_OVERRIDE(Paint, std::nullptr_t) \
+ CRU_DEFINE_EVENT_OVERRIDE(Paint1, const NativePaintEventArgs&) \
+ CRU_DEFINE_EVENT_OVERRIDE(VisibilityChange, WindowVisibilityType) \
+ CRU_DEFINE_EVENT_OVERRIDE(Resize, const Size&) \
+ CRU_DEFINE_EVENT_OVERRIDE(Focus, FocusChangeType) \
+ CRU_DEFINE_EVENT_OVERRIDE(MouseEnterLeave, MouseEnterLeaveType) \
+ CRU_DEFINE_EVENT_OVERRIDE(MouseMove, const Point&) \
+ CRU_DEFINE_EVENT_OVERRIDE(MouseDown, const NativeMouseButtonEventArgs&) \
+ CRU_DEFINE_EVENT_OVERRIDE(MouseUp, const NativeMouseButtonEventArgs&) \
+ CRU_DEFINE_EVENT_OVERRIDE(MouseWheel, const NativeMouseWheelEventArgs&) \
+ CRU_DEFINE_EVENT_OVERRIDE(KeyDown, const NativeKeyEventArgs&) \
+ CRU_DEFINE_EVENT_OVERRIDE(KeyUp, const NativeKeyEventArgs&)
diff --git a/include/cru/platform/gui/win/Window.h b/include/cru/platform/gui/win/Window.h
index c7d48ea9..e690ad4e 100644
--- a/include/cru/platform/gui/win/Window.h
+++ b/include/cru/platform/gui/win/Window.h
@@ -61,38 +61,8 @@ class CRU_WIN_GUI_API WinNativeWindow : public WinNativeResource,
void SetToForeground() override;
- IEvent<std::nullptr_t>* CreateEvent() override { return &create_event_; }
- IEvent<std::nullptr_t>* DestroyEvent() override { return &destroy_event_; }
- IEvent<std::nullptr_t>* PaintEvent() override { return &paint_event_; }
- IEvent<WindowVisibilityType>* VisibilityChangeEvent() override {
- return &visibility_change_event_;
- }
- IEvent<const Size&>* ResizeEvent() override { return &resize_event_; }
- IEvent<FocusChangeType>* FocusEvent() override { return &focus_event_; }
- IEvent<MouseEnterLeaveType>* MouseEnterLeaveEvent() override {
- return &mouse_enter_leave_event_;
- }
- IEvent<const Point&>* MouseMoveEvent() override { return &mouse_move_event_; }
- IEvent<const NativeMouseButtonEventArgs&>* MouseDownEvent() override {
- return &mouse_down_event_;
- }
- IEvent<const NativeMouseButtonEventArgs&>* MouseUpEvent() override {
- return &mouse_up_event_;
- }
- IEvent<const NativeMouseWheelEventArgs&>* MouseWheelEvent() override {
- return &mouse_wheel_event_;
- }
-
- IEvent<const NativeKeyEventArgs&>* KeyDownEvent() override {
- return &key_down_event_;
- }
- IEvent<const NativeKeyEventArgs&>* KeyUpEvent() override {
- return &key_up_event_;
- }
-
- IEvent<WindowNativeMessageEventArgs&>* NativeMessageEvent() {
- return &native_message_event_;
- }
+ CRU_DEFINE_CRU_PLATFORM_GUI_I_NATIVE_WINDOW_OVERRIDE_EVENTS()
+ CRU_DEFINE_EVENT(NativeMessage, WindowNativeMessageEventArgs&)
IInputMethodContext* GetInputMethodContext() override;
@@ -193,21 +163,5 @@ class CRU_WIN_GUI_API WinNativeWindow : public WinNativeResource,
std::shared_ptr<WinCursor> cursor_;
std::unique_ptr<WinInputMethodContext> input_method_context_;
-
- Event<std::nullptr_t> create_event_;
- Event<std::nullptr_t> destroy_event_;
- Event<std::nullptr_t> paint_event_;
- Event<const Size&> resize_event_;
- Event<WindowVisibilityType> visibility_change_event_;
- Event<FocusChangeType> focus_event_;
- Event<MouseEnterLeaveType> mouse_enter_leave_event_;
- Event<const Point&> mouse_move_event_;
- Event<const NativeMouseButtonEventArgs&> mouse_down_event_;
- Event<const NativeMouseButtonEventArgs&> mouse_up_event_;
- Event<const NativeMouseWheelEventArgs&> mouse_wheel_event_;
- Event<const NativeKeyEventArgs&> key_down_event_;
- Event<const NativeKeyEventArgs&> key_up_event_;
-
- Event<WindowNativeMessageEventArgs&> native_message_event_;
};
} // namespace cru::platform::gui::win
diff --git a/src/base/Base.cpp b/src/base/Base.cpp
index 7dd6337d..c97c53a5 100644
--- a/src/base/Base.cpp
+++ b/src/base/Base.cpp
@@ -7,7 +7,7 @@
namespace cru {
void UnreachableCode() { std::terminate(); }
-void NotImplemented() { std::terminate(); }
+void NotImplemented() { throw NotImplementedException(); }
Exception::Exception(std::string message, std::shared_ptr<std::exception> inner)
: message_(std::move(message)), inner_(std::move(inner)) {}
diff --git a/src/platform/gui/Window.cpp b/src/platform/gui/Window.cpp
index fdcfbae4..15a49b06 100644
--- a/src/platform/gui/Window.cpp
+++ b/src/platform/gui/Window.cpp
@@ -3,4 +3,9 @@
namespace cru::platform::gui {
bool INativeWindow::IsCreated() { NotImplemented(); }
+
+IEvent<const NativePaintEventArgs&>* INativeWindow::Paint1Event() {
+ NotImplemented();
+}
+
} // namespace cru::platform::gui
diff --git a/src/platform/gui/win/Window.cpp b/src/platform/gui/win/Window.cpp
index 2c0bc5a1..fb2ce024 100644
--- a/src/platform/gui/win/Window.cpp
+++ b/src/platform/gui/win/Window.cpp
@@ -312,7 +312,7 @@ bool WinNativeWindow::HandleNativeWindowMessage(HWND hwnd, UINT msg,
LRESULT* result) {
WindowNativeMessageEventArgs args{
WindowNativeMessage{hwnd, msg, w_param, l_param}};
- native_message_event_.Raise(args);
+ NativeMessageEvent_.Raise(args);
if (args.IsHandled()) {
*result = args.GetResult();
return true;
@@ -510,13 +510,13 @@ void WinNativeWindow::RecreateWindow() {
void WinNativeWindow::OnCreateInternal() {
CRU_LOG_TAG_DEBUG("A native window is created, hwnd {}.",
static_cast<void*>(GetWindowHandle()));
- create_event_.Raise(nullptr);
+ CreateEvent_.Raise(nullptr);
}
void WinNativeWindow::OnDestroyInternal() {
CRU_LOG_TAG_DEBUG("A native window is destroying, hwnd {}.",
static_cast<void*>(GetWindowHandle()));
- destroy_event_.Raise(nullptr);
+ DestroyEvent_.Raise(nullptr);
hwnd_ = nullptr;
if (application_->IsQuitOnAllWindowClosed() &&
@@ -529,8 +529,14 @@ void WinNativeWindow::OnDestroyInternal() {
}
void WinNativeWindow::OnPaintInternal() {
- paint_event_.Raise(nullptr);
- ValidateRect(hwnd_, nullptr);
+ PaintEvent_.Raise(nullptr);
+ NativePaintEventArgs args;
+ ::RECT rect;
+ if (::GetUpdateRect(hwnd_, &rect, FALSE)) {
+ args.repaint_area = PixelToDip(rect);
+ }
+ Paint1Event_.Raise(args);
+ ::ValidateRect(hwnd_, nullptr);
CRU_LOG_TAG_DEBUG("A repaint is finished.");
}
@@ -545,18 +551,18 @@ void WinNativeWindow::OnResizeInternal(const int new_width,
client_rect_.height = PixelToDip(new_height);
if (!(new_width == 0 && new_height == 0)) {
window_render_target_->ResizeBuffer(new_width, new_height);
- resize_event_.Raise(Size{PixelToDip(new_width), PixelToDip(new_height)});
+ ResizeEvent_.Raise(Size{PixelToDip(new_width), PixelToDip(new_height)});
}
}
void WinNativeWindow::OnSetFocusInternal() {
has_focus_ = true;
- focus_event_.Raise(FocusChangeType::Gain);
+ FocusEvent_.Raise(FocusChangeType::Gain);
}
void WinNativeWindow::OnKillFocusInternal() {
has_focus_ = false;
- focus_event_.Raise(FocusChangeType::Lose);
+ FocusEvent_.Raise(FocusChangeType::Lose);
}
void WinNativeWindow::OnMouseMoveInternal(const POINT point) {
@@ -571,43 +577,42 @@ void WinNativeWindow::OnMouseMoveInternal(const POINT point) {
TrackMouseEvent(&tme);
is_mouse_in_ = true;
- mouse_enter_leave_event_.Raise(MouseEnterLeaveType::Enter);
+ MouseEnterLeaveEvent_.Raise(MouseEnterLeaveType::Enter);
}
- mouse_move_event_.Raise(PixelToDip(point));
+ MouseMoveEvent_.Raise(PixelToDip(point));
}
void WinNativeWindow::OnMouseLeaveInternal() {
is_mouse_in_ = false;
- mouse_enter_leave_event_.Raise(MouseEnterLeaveType::Leave);
+ MouseEnterLeaveEvent_.Raise(MouseEnterLeaveType::Leave);
}
void WinNativeWindow::OnMouseDownInternal(platform::gui::MouseButton button,
POINT point) {
const auto dip_point = PixelToDip(point);
- mouse_down_event_.Raise({button, dip_point, RetrieveKeyModifier()});
+ MouseDownEvent_.Raise({button, dip_point, RetrieveKeyModifier()});
}
void WinNativeWindow::OnMouseUpInternal(platform::gui::MouseButton button,
POINT point) {
const auto dip_point = PixelToDip(point);
- mouse_up_event_.Raise({button, dip_point, RetrieveKeyModifier()});
+ MouseUpEvent_.Raise({button, dip_point, RetrieveKeyModifier()});
}
void WinNativeWindow::OnMouseWheelInternal(short delta, POINT point) {
const auto dip_point = PixelToDip(point);
const float d = -((float)delta / 120.f);
- mouse_wheel_event_.Raise({d, dip_point, RetrieveKeyModifier()});
+ MouseWheelEvent_.Raise({d, dip_point, RetrieveKeyModifier()});
}
void WinNativeWindow::OnKeyDownInternal(int virtual_code) {
- key_down_event_.Raise(
+ KeyDownEvent_.Raise(
{VirtualKeyToKeyCode(virtual_code), RetrieveKeyModifier()});
}
void WinNativeWindow::OnKeyUpInternal(int virtual_code) {
- key_up_event_.Raise(
- {VirtualKeyToKeyCode(virtual_code), RetrieveKeyModifier()});
+ KeyUpEvent_.Raise({VirtualKeyToKeyCode(virtual_code), RetrieveKeyModifier()});
}
void WinNativeWindow::OnActivatedInternal() {}
diff --git a/src/ui/render/TextRenderObject.cpp b/src/ui/render/TextRenderObject.cpp
index 44dee1aa..1fe8e652 100644
--- a/src/ui/render/TextRenderObject.cpp
+++ b/src/ui/render/TextRenderObject.cpp
@@ -54,12 +54,14 @@ void TextRenderObject::SetFont(
std::shared_ptr<platform::graphics::IFont> font) {
Expects(font);
text_layout_->SetFont(std::move(font));
+ InvalidateLayout();
}
bool TextRenderObject::IsEditMode() { return text_layout_->IsEditMode(); }
void TextRenderObject::SetEditMode(bool enable) {
text_layout_->SetEditMode(enable);
+ InvalidateLayout();
}
Index TextRenderObject::GetLineCount() { return text_layout_->GetLineCount(); }