diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/cru/common/String.hpp | 2 | ||||
-rw-r--r-- | include/cru/platform/graphics/NullPainter.hpp | 4 | ||||
-rw-r--r-- | include/cru/platform/graphics/Painter.hpp | 3 | ||||
-rw-r--r-- | include/cru/platform/gui/Window.hpp | 1 | ||||
-rw-r--r-- | include/cru/win/WinPreConfig.hpp | 1 | ||||
-rw-r--r-- | include/cru/win/graphics/direct/Painter.hpp | 10 | ||||
-rw-r--r-- | include/cru/win/graphics/direct/TextLayout.hpp | 1 | ||||
-rw-r--r-- | include/cru/win/gui/InputMethod.hpp | 4 | ||||
-rw-r--r-- | include/cru/win/gui/UiApplication.hpp | 14 | ||||
-rw-r--r-- | include/cru/win/gui/Window.hpp | 51 |
10 files changed, 71 insertions, 20 deletions
diff --git a/include/cru/common/String.hpp b/include/cru/common/String.hpp index 88dd06f0..dd3da52f 100644 --- a/include/cru/common/String.hpp +++ b/include/cru/common/String.hpp @@ -80,6 +80,8 @@ class CRU_BASE_API String { } } + String(size_type size, value_type ch = 0); + String(std::initializer_list<value_type> l); explicit String(StringView str); diff --git a/include/cru/platform/graphics/NullPainter.hpp b/include/cru/platform/graphics/NullPainter.hpp index 5586120b..7889f99e 100644 --- a/include/cru/platform/graphics/NullPainter.hpp +++ b/include/cru/platform/graphics/NullPainter.hpp @@ -42,11 +42,9 @@ class NullPainter : public Object, public virtual IPainter { CRU_UNUSED(brush) CRU_UNUSED(width) } - void FillEllipse(const Rect& outline_rect, IBrush* brush, - float width) override { + void FillEllipse(const Rect& outline_rect, IBrush* brush) override { CRU_UNUSED(outline_rect) CRU_UNUSED(brush) - CRU_UNUSED(width) } void StrokeGeometry(IGeometry* geometry, IBrush* brush, diff --git a/include/cru/platform/graphics/Painter.hpp b/include/cru/platform/graphics/Painter.hpp index 4f1724ec..552a3307 100644 --- a/include/cru/platform/graphics/Painter.hpp +++ b/include/cru/platform/graphics/Painter.hpp @@ -18,8 +18,7 @@ struct IPainter : virtual IPlatformResource { virtual void FillRectangle(const Rect& rectangle, IBrush* brush) = 0; virtual void StrokeEllipse(const Rect& outline_rect, IBrush* brush, float width) = 0; - virtual void FillEllipse(const Rect& outline_rect, IBrush* brush, - float width) = 0; + virtual void FillEllipse(const Rect& outline_rect, IBrush* brush) = 0; virtual void StrokeGeometry(IGeometry* geometry, IBrush* brush, float width) = 0; diff --git a/include/cru/platform/gui/Window.hpp b/include/cru/platform/gui/Window.hpp index bab5e8fe..9f17b976 100644 --- a/include/cru/platform/gui/Window.hpp +++ b/include/cru/platform/gui/Window.hpp @@ -85,7 +85,6 @@ struct INativeWindow : virtual IPlatformResource { // Remember to call EndDraw on return value and destroy it. virtual std::unique_ptr<graphics::IPainter> BeginPaint() = 0; - // Don't use this instance after receive this event. virtual IEvent<std::nullptr_t>* CreateEvent() = 0; virtual IEvent<std::nullptr_t>* DestroyEvent() = 0; virtual IEvent<std::nullptr_t>* PaintEvent() = 0; diff --git a/include/cru/win/WinPreConfig.hpp b/include/cru/win/WinPreConfig.hpp index 1613da95..1bd494f2 100644 --- a/include/cru/win/WinPreConfig.hpp +++ b/include/cru/win/WinPreConfig.hpp @@ -8,6 +8,7 @@ #undef CreateWindow #undef DrawText #undef CreateFont +#undef CreateEvent #include <d2d1_2.h> #include <d3d11.h> diff --git a/include/cru/win/graphics/direct/Painter.hpp b/include/cru/win/graphics/direct/Painter.hpp index b34c1563..d7b90d19 100644 --- a/include/cru/win/graphics/direct/Painter.hpp +++ b/include/cru/win/graphics/direct/Painter.hpp @@ -24,6 +24,7 @@ class D2DPainter : public DirectResource, public: Matrix GetTransform() override; void SetTransform(const platform::Matrix& matrix) override; + void ConcatTransform(const Matrix& matrix) override; void Clear(const Color& color) override; @@ -32,6 +33,9 @@ class D2DPainter : public DirectResource, void StrokeRectangle(const Rect& rectangle, IBrush* brush, float width) override; void FillRectangle(const Rect& rectangle, IBrush* brush) override; + void StrokeEllipse(const Rect& outline_rect, IBrush* brush, + float width) override; + void FillEllipse(const Rect& outline_rect, IBrush* brush) override; void StrokeGeometry(IGeometry* geometry, IBrush* brush, float width) override; void FillGeometry(IGeometry* geometry, IBrush* brush) override; @@ -40,9 +44,11 @@ class D2DPainter : public DirectResource, IBrush* brush) override; void PushLayer(const Rect& bounds) override; - void PopLayer() override; + void PushState() override; + void PopState() override; + void EndDraw() override final; protected: @@ -56,6 +62,8 @@ class D2DPainter : public DirectResource, ID2D1RenderTarget* render_target_; std::vector<Microsoft::WRL::ComPtr<ID2D1Layer>> layers_; + std::vector<Microsoft::WRL::ComPtr<ID2D1DrawingStateBlock>> + drawing_state_stack_; bool is_drawing_ = true; }; diff --git a/include/cru/win/graphics/direct/TextLayout.hpp b/include/cru/win/graphics/direct/TextLayout.hpp index 1ac56a9d..b1843dd7 100644 --- a/include/cru/win/graphics/direct/TextLayout.hpp +++ b/include/cru/win/graphics/direct/TextLayout.hpp @@ -52,6 +52,7 @@ class DWriteTextLayout : public DirectGraphicsResource, TextHitTestResult HitTest(const Point& point) override; private: + bool edit_mode_ = false; String text_; std::shared_ptr<DWriteFont> font_; float max_width_ = std::numeric_limits<float>::max(); diff --git a/include/cru/win/gui/InputMethod.hpp b/include/cru/win/gui/InputMethod.hpp index df687617..3784dcda 100644 --- a/include/cru/win/gui/InputMethod.hpp +++ b/include/cru/win/gui/InputMethod.hpp @@ -70,7 +70,7 @@ class WinInputMethodContext : public WinNativeResource, private: void OnWindowNativeMessage(WindowNativeMessageEventArgs& args); - std::u16string GetResultString(); + String GetResultString(); AutoHIMC GetHIMC(); @@ -82,6 +82,6 @@ class WinInputMethodContext : public WinNativeResource, Event<std::nullptr_t> composition_start_event_; Event<std::nullptr_t> composition_end_event_; Event<std::nullptr_t> composition_event_; - Event<std::u16string_view> text_event_; + Event<StringView> text_event_; }; } // namespace cru::platform::gui::win diff --git a/include/cru/win/gui/UiApplication.hpp b/include/cru/win/gui/UiApplication.hpp index daf72795..4b972fee 100644 --- a/include/cru/win/gui/UiApplication.hpp +++ b/include/cru/win/gui/UiApplication.hpp @@ -33,6 +33,13 @@ class WinUiApplication : public WinNativeResource, void AddOnQuitHandler(std::function<void()> handler) override; + bool IsQuitOnAllWindowClosed() override { + return is_quit_on_all_window_closed_; + } + void SetQuitOnAllWindowClosed(bool quit_on_all_window_closed) override { + is_quit_on_all_window_closed_ = quit_on_all_window_closed; + } + long long SetImmediate(std::function<void()> action) override; long long SetTimeout(std::chrono::milliseconds milliseconds, std::function<void()> action) override; @@ -45,12 +52,15 @@ class WinUiApplication : public WinNativeResource, cru::platform::graphics::IGraphicsFactory* GetGraphicsFactory() override; - cru::platform::graphics::win::direct::DirectGraphicsFactory* GetDirectFactory() { + cru::platform::graphics::win::direct::DirectGraphicsFactory* + GetDirectFactory() { return graph_factory_.get(); } ICursorManager* GetCursorManager() override; + IClipboard* GetClipboard() override; + HINSTANCE GetInstanceHandle() const { return instance_handle_; } GodWindow* GetGodWindow() const { return god_window_.get(); } @@ -60,6 +70,8 @@ class WinUiApplication : public WinNativeResource, private: HINSTANCE instance_handle_; + bool is_quit_on_all_window_closed_ = true; + std::unique_ptr<cru::platform::graphics::win::direct::DirectGraphicsFactory> graph_factory_; diff --git a/include/cru/win/gui/Window.hpp b/include/cru/win/gui/Window.hpp index 9f241b0a..5ce3ed25 100644 --- a/include/cru/win/gui/Window.hpp +++ b/include/cru/win/gui/Window.hpp @@ -13,8 +13,7 @@ class WinNativeWindow : public WinNativeResource, public virtual INativeWindow { CRU_DEFINE_CLASS_LOG_TAG(u"cru::platform::gui::win::WinNativeWindow") public: - WinNativeWindow(WinUiApplication* application, WindowClass* window_class, - DWORD window_style, WinNativeWindow* parent); + explicit WinNativeWindow(WinUiApplication* application); CRU_DELETE_COPY(WinNativeWindow) CRU_DELETE_MOVE(WinNativeWindow) @@ -25,19 +24,31 @@ class WinNativeWindow : public WinNativeResource, public virtual INativeWindow { void Close() override; WinNativeWindow* GetParent() override { return parent_window_; } + void SetParent(INativeWindow* parent) override; + WindowStyleFlag GetStyleFlag() override { return style_flag_; } + void SetStyleFlag(WindowStyleFlag flag) override; + + WindowVisibilityType GetVisibility() override { return visibility_; } + void SetVisibility(WindowVisibilityType visibility) override; Size GetClientSize() override; void SetClientSize(const Size& size) override; + Rect GetClientRect() override; + void SetClientRect(const Rect& rect) override; + // Get the rect of the window containing frame. // The lefttop of the rect is relative to screen lefttop. Rect GetWindowRect() override; // Set the rect of the window containing frame. // The lefttop of the rect is relative to screen lefttop. + // TODO: Known limitation: can't calc client rect and save. void SetWindowRect(const Rect& rect) override; + bool RequestFocus() override; + Point GetMousePosition() override; bool CaptureMouse() override; @@ -48,8 +59,12 @@ class WinNativeWindow : public WinNativeResource, public virtual INativeWindow { void SetCursor(std::shared_ptr<ICursor> cursor) 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<Size>* ResizeEvent() override { return &resize_event_; } IEvent<FocusChangeType>* FocusEvent() override { return &focus_event_; } IEvent<MouseEnterLeaveType>* MouseEnterLeaveEvent() override { @@ -103,6 +118,15 @@ class WinNativeWindow : public WinNativeResource, public virtual INativeWindow { return result; } + inline RECT DipToPixel(const Rect& dip_rect) { + RECT result; + result.left = DipToPixel(dip_rect.left); + result.top = DipToPixel(dip_rect.top); + result.right = DipToPixel(dip_rect.GetRight()); + result.bottom = DipToPixel(dip_rect.GetBottom()); + return result; + } + inline float PixelToDip(const int pixel) { return static_cast<float>(pixel) * 96.0f / GetDpi(); } @@ -111,10 +135,18 @@ class WinNativeWindow : public WinNativeResource, public virtual INativeWindow { return Point(PixelToDip(pi_point.x), PixelToDip(pi_point.y)); } + inline Rect PixelToDip(const RECT& pi_rect) { + return Rect::FromVertices(PixelToDip(pi_rect.left), PixelToDip(pi_rect.top), + PixelToDip(pi_rect.right), + PixelToDip(pi_rect.bottom)); + } + private: // Get the client rect in pixel. RECT GetClientRectPixel(); + void RecreateWindow(); + //*************** region: native messages *************** void OnDestroyInternal(); @@ -139,15 +171,12 @@ class WinNativeWindow : public WinNativeResource, public virtual INativeWindow { private: WinUiApplication* application_; - // when delete is called first, it set this to true to indicate - // destroy message handler not to double delete this instance; - // when destroy handler is called first (by user action or method - // Close), it set this to true to indicate delete not call Close - // again. - bool sync_flag_ = false; + WindowStyleFlag style_flag_{}; + WindowVisibilityType visibility_{}; + Rect client_rect_; - HWND hwnd_; - WinNativeWindow* parent_window_; + HWND hwnd_ = nullptr; + WinNativeWindow* parent_window_ = nullptr; float dpi_; @@ -161,9 +190,11 @@ class WinNativeWindow : public WinNativeResource, public virtual INativeWindow { 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<Size> resize_event_; + Event<WindowVisibilityType> visibility_change_event_; Event<FocusChangeType> focus_event_; Event<MouseEnterLeaveType> mouse_enter_leave_event_; Event<Point> mouse_move_event_; |