aboutsummaryrefslogtreecommitdiff
path: root/include/cru/win
diff options
context:
space:
mode:
Diffstat (limited to 'include/cru/win')
-rw-r--r--include/cru/win/WinPreConfig.hpp1
-rw-r--r--include/cru/win/graphics/direct/Painter.hpp10
-rw-r--r--include/cru/win/graphics/direct/TextLayout.hpp1
-rw-r--r--include/cru/win/gui/InputMethod.hpp4
-rw-r--r--include/cru/win/gui/UiApplication.hpp14
-rw-r--r--include/cru/win/gui/Window.hpp51
6 files changed, 67 insertions, 14 deletions
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_;