aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/application.cpp6
-rw-r--r--src/application.h19
-rw-r--r--src/global_macros.h2
-rw-r--r--src/main.cpp4
-rw-r--r--src/ui/control.cpp37
-rw-r--r--src/ui/control.h5
-rw-r--r--src/ui/window.cpp8
-rw-r--r--src/ui/window.h12
8 files changed, 68 insertions, 25 deletions
diff --git a/src/application.cpp b/src/application.cpp
index af38116f..f53a002d 100644
--- a/src/application.cpp
+++ b/src/application.cpp
@@ -101,8 +101,10 @@ namespace cru {
god_window_ = std::make_unique<GodWindow>(this);
-#ifdef CRU_DEBUG_DRAW_CONTROL_BORDER
- debug_border_brush_ = graph::CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::Crimson));
+#ifdef CRU_DEBUG_LAYOUT
+ debug_layout_resource_.out_border_brush = graph::CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::Crimson));
+ debug_layout_resource_.margin_brush = graph::CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::LightCoral, 0.25f));
+ debug_layout_resource_.padding_brush = graph::CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::SkyBlue, 0.25f));
#endif
caret_info_.caret_blink_duration = std::chrono::milliseconds(::GetCaretBlinkTime());
diff --git a/src/application.h b/src/application.h
index 106e7171..b371c8f9 100644
--- a/src/application.h
+++ b/src/application.h
@@ -34,6 +34,15 @@ namespace cru
float half_caret_width;
};
+#ifdef CRU_DEBUG_LAYOUT
+ struct DebugLayoutResource
+ {
+ Microsoft::WRL::ComPtr<ID2D1Brush> out_border_brush;
+ Microsoft::WRL::ComPtr<ID2D1Brush> margin_brush;
+ Microsoft::WRL::ComPtr<ID2D1Brush> padding_brush;
+ };
+#endif
+
class GodWindow : public Object
{
public:
@@ -111,10 +120,10 @@ namespace cru
return caret_info_;
}
-#ifdef CRU_DEBUG_DRAW_CONTROL_BORDER
- Microsoft::WRL::ComPtr<ID2D1Brush> GetDebugBorderBrush() const
+#ifdef CRU_DEBUG_LAYOUT
+ const DebugLayoutResource* GetDebugLayoutResource() const
{
- return debug_border_brush_;
+ return &debug_layout_resource_;
}
#endif
@@ -128,8 +137,8 @@ namespace cru
std::unique_ptr<GodWindow> god_window_;
-#ifdef CRU_DEBUG_DRAW_CONTROL_BORDER
- Microsoft::WRL::ComPtr<ID2D1Brush> debug_border_brush_;
+#ifdef CRU_DEBUG_LAYOUT
+ DebugLayoutResource debug_layout_resource_;
#endif
CaretInfo caret_info_;
diff --git a/src/global_macros.h b/src/global_macros.h
index 696c5d2b..1d671e4a 100644
--- a/src/global_macros.h
+++ b/src/global_macros.h
@@ -7,5 +7,5 @@
#define GLOG_NO_ABBREVIATED_SEVERITIES
#ifdef CRU_DEBUG
-#define CRU_DEBUG_DRAW_CONTROL_BORDER
+#define CRU_DEBUG_LAYOUT
#endif
diff --git a/src/main.cpp b/src/main.cpp
index 06110457..b99709bf 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -104,7 +104,7 @@ int APIENTRY wWinMain(
const auto toggle_button = ToggleButton::Create();
toggle_button->toggle_event.AddHandler([&window](cru::ui::events::ToggleEventArgs& args)
{
- window.SetDebugDrawControlBorder(args.GetNewState());
+ window.SetDebugLayout(args.GetNewState());
});
inner_layout->AddChild(toggle_button);
@@ -161,7 +161,7 @@ int APIENTRY wWinMain(
window.AddChild(linear_layout);
- //window.SetDebugDrawControlBorder(true);
+ window.SetDebugLayout(true);
window.Show();
diff --git a/src/ui/control.cpp b/src/ui/control.cpp
index a75cab37..3aa8c7e2 100644
--- a/src/ui/control.cpp
+++ b/src/ui/control.cpp
@@ -2,6 +2,7 @@
#include "window.h"
#include "graph/graph.h"
+#include "exception.h"
namespace cru {
namespace ui {
@@ -390,11 +391,15 @@ namespace cru {
void Control::OnDraw(ID2D1DeviceContext* device_context)
{
-#ifdef CRU_DEBUG_DRAW_CONTROL_BORDER
- if (GetWindow()->GetDebugDrawControlBorder())
+#ifdef CRU_DEBUG_LAYOUT
+ if (GetWindow()->IsDebugLayout())
{
- auto brush = Application::GetInstance()->GetDebugBorderBrush();
- device_context->DrawRectangle(Convert(GetRect(RectRange::Margin)), brush.Get());
+ const auto resource = Application::GetInstance()->GetDebugLayoutResource();
+ if (padding_geometry_ != nullptr)
+ device_context->FillGeometry(padding_geometry_.Get(), resource->padding_brush.Get());
+ if (margin_geometry_ != nullptr)
+ device_context->FillGeometry(margin_geometry_.Get(), resource->margin_brush.Get());
+ device_context->DrawRectangle(Convert(GetRect(RectRange::Margin)), resource->out_border_brush.Get());
}
#endif
@@ -433,9 +438,31 @@ namespace cru {
}
- void Control::OnSizeChangedCore(SizeChangedEventArgs & args)
+ namespace
{
+ Microsoft::WRL::ComPtr<ID2D1Geometry> CalculateSquareRingGeometry(const Rect& out, const Rect& in)
+ {
+ const auto d2d1_factory = graph::GraphManager::GetInstance()->GetD2D1Factory();
+ Microsoft::WRL::ComPtr<ID2D1RectangleGeometry> out_geometry;
+ ThrowIfFailed(d2d1_factory->CreateRectangleGeometry(Convert(out), &out_geometry));
+ Microsoft::WRL::ComPtr<ID2D1RectangleGeometry> in_geometry;
+ ThrowIfFailed(d2d1_factory->CreateRectangleGeometry(Convert(in), &in_geometry));
+ Microsoft::WRL::ComPtr<ID2D1PathGeometry> result_geometry;
+ ThrowIfFailed(d2d1_factory->CreatePathGeometry(&result_geometry));
+ Microsoft::WRL::ComPtr<ID2D1GeometrySink> sink;
+ ThrowIfFailed(result_geometry->Open(&sink));
+ ThrowIfFailed(out_geometry->CombineWithGeometry(in_geometry.Get(), D2D1_COMBINE_MODE_EXCLUDE, D2D1::Matrix3x2F::Identity(), sink.Get()));
+ ThrowIfFailed(sink->Close());
+ return result_geometry;
+ }
+ }
+ void Control::OnSizeChangedCore(SizeChangedEventArgs & args)
+ {
+#ifdef CRU_DEBUG_LAYOUT
+ margin_geometry_ = CalculateSquareRingGeometry(GetRect(RectRange::Margin), GetRect(RectRange::FullBorder));
+ padding_geometry_ = CalculateSquareRingGeometry(GetRect(RectRange::Padding), GetRect(RectRange::Content));
+#endif
}
void Control::RaisePositionChangedEvent(PositionChangedEventArgs& args)
diff --git a/src/ui/control.h b/src/ui/control.h
index 18ca4b69..b2321e2b 100644
--- a/src/ui/control.h
+++ b/src/ui/control.h
@@ -399,6 +399,11 @@ namespace cru
std::unordered_map<String, std::any> additional_properties_{};
bool is_focus_on_pressed_ = true;
+
+#ifdef CRU_DEBUG_LAYOUT
+ Microsoft::WRL::ComPtr<ID2D1Geometry> margin_geometry_;
+ Microsoft::WRL::ComPtr<ID2D1Geometry> padding_geometry_;
+#endif
};
// Find the lowest common ancestor.
diff --git a/src/ui/window.cpp b/src/ui/window.cpp
index 2bebd7d4..8889e032 100644
--- a/src/ui/window.cpp
+++ b/src/ui/window.cpp
@@ -439,12 +439,12 @@ namespace cru
}
}
-#ifdef CRU_DEBUG_DRAW_CONTROL_BORDER
- void Window::SetDebugDrawControlBorder(const bool value)
+#ifdef CRU_DEBUG_LAYOUT
+ void Window::SetDebugLayout(const bool value)
{
- if (debug_draw_control_border_ != value)
+ if (debug_layout_ != value)
{
- debug_draw_control_border_ = value;
+ debug_layout_ = value;
Repaint();
}
}
diff --git a/src/ui/window.h b/src/ui/window.h
index b4433e85..e4e89776 100644
--- a/src/ui/window.h
+++ b/src/ui/window.h
@@ -184,13 +184,13 @@ namespace cru {
Control* ReleaseCurrentMouseCapture();
//*************** region: debug ***************
-#ifdef CRU_DEBUG_DRAW_CONTROL_BORDER
- bool GetDebugDrawControlBorder() const
+#ifdef CRU_DEBUG_LAYOUT
+ bool IsDebugLayout() const
{
- return debug_draw_control_border_;
+ return debug_layout_;
}
- void SetDebugDrawControlBorder(bool value);
+ void SetDebugLayout(bool value);
#endif
public:
@@ -276,8 +276,8 @@ namespace cru {
Control* mouse_capture_control_ = nullptr;
-#ifdef CRU_DEBUG_DRAW_CONTROL_BORDER
- bool debug_draw_control_border_ = false;
+#ifdef CRU_DEBUG_LAYOUT
+ bool debug_layout_ = false;
#endif
};
}