aboutsummaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2018-10-06 23:49:17 +0800
committercrupest <crupest@outlook.com>2018-10-06 23:49:17 +0800
commit2261a4bc348a6017a0f31233f969bdf31ae35679 (patch)
treeccdc237b84423c9564458df3fae036f08815dda6 /src/ui
parentbeb6cfa6b3492f5a9d89ba99c03358c22598e7aa (diff)
downloadcru-2261a4bc348a6017a0f31233f969bdf31ae35679.tar.gz
cru-2261a4bc348a6017a0f31233f969bdf31ae35679.tar.bz2
cru-2261a4bc348a6017a0f31233f969bdf31ae35679.zip
Add debug layout visual effects.
Diffstat (limited to 'src/ui')
-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
4 files changed, 47 insertions, 15 deletions
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
};
}