aboutsummaryrefslogtreecommitdiff
path: root/src/ui/control.cpp
diff options
context:
space:
mode:
authorYuqian Yang <crupest@outlook.com>2018-10-06 15:51:36 +0000
committerYuqian Yang <crupest@outlook.com>2018-10-06 15:51:36 +0000
commitb0057dc911f96258c7280b89c8f4da828ecc283c (patch)
treeccdc237b84423c9564458df3fae036f08815dda6 /src/ui/control.cpp
parent7e870dd16e2f5b41fa6c6f687723aaa50c16274d (diff)
parent2261a4bc348a6017a0f31233f969bdf31ae35679 (diff)
downloadcru-b0057dc911f96258c7280b89c8f4da828ecc283c.tar.gz
cru-b0057dc911f96258c7280b89c8f4da828ecc283c.tar.bz2
cru-b0057dc911f96258c7280b89c8f4da828ecc283c.zip
Merge branch '13-debug-layout' into 'master'
Resolve "Add debug layout visual effect." Closes #13 See merge request crupest/CruUI!13
Diffstat (limited to 'src/ui/control.cpp')
-rw-r--r--src/ui/control.cpp38
1 files changed, 32 insertions, 6 deletions
diff --git a/src/ui/control.cpp b/src/ui/control.cpp
index 4acdd8f1..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,12 +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();
- const auto size = GetSize();
- 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
@@ -434,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)