diff options
author | crupest <crupest@outlook.com> | 2018-11-10 20:56:03 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2018-11-10 20:56:03 +0800 |
commit | cfcd03f564e82419345a7a6900fdc17c5b8c2631 (patch) | |
tree | fb944f2081047e7898ed1f558fb08b40aa5f6ed9 /src | |
parent | 370ed80687ac9758b21335d3951828838796f9b3 (diff) | |
parent | 7c2fb4578b6997b5ab0d98121cda253f734139c1 (diff) | |
download | cru-cfcd03f564e82419345a7a6900fdc17c5b8c2631.tar.gz cru-cfcd03f564e82419345a7a6900fdc17c5b8c2631.tar.bz2 cru-cfcd03f564e82419345a7a6900fdc17c5b8c2631.zip |
Merge branch 'master' into listitem
Diffstat (limited to 'src')
-rw-r--r-- | src/ui/control.cpp | 54 | ||||
-rw-r--r-- | src/ui/control.hpp | 8 |
2 files changed, 48 insertions, 14 deletions
diff --git a/src/ui/control.cpp b/src/ui/control.cpp index 63d322b3..5d15e287 100644 --- a/src/ui/control.cpp +++ b/src/ui/control.cpp @@ -202,16 +202,7 @@ namespace cru::ui const auto position = GetPositionRelative(); device_context->SetTransform(old_transform * D2D1::Matrix3x2F::Translation(position.x, position.y)); - OnDraw(device_context); - - const auto rect = GetRect(RectRange::Content); - graph::WithTransform(device_context, D2D1::Matrix3x2F::Translation(rect.left, rect.top), - [this](ID2D1DeviceContext* device_context) - { - OnDrawContent(device_context); - DrawEventArgs args(this, this, device_context); - draw_event.Raise(args); - }); + OnDrawCore(device_context); for (auto child : GetChildren()) child->Draw(device_context); @@ -385,14 +376,15 @@ namespace cru::ui window_ = nullptr; } + inline D2D1_RECT_F Convert(const Rect& rect) { return D2D1::RectF(rect.left, rect.top, rect.left + rect.width, rect.top + rect.height); } - void Control::OnDraw(ID2D1DeviceContext* device_context) + void Control::OnDrawCore(ID2D1DeviceContext* device_context) { -#ifdef CRU_DEBUG_LAYOUT + #ifdef CRU_DEBUG_LAYOUT if (GetWindow()->IsDebugLayout()) { if (padding_geometry_ != nullptr) @@ -417,6 +409,34 @@ namespace cru::ui GetBorderProperty().GetStrokeStyle().Get() ); } + + //draw background. + const auto padding_rect = GetRect(RectRange::Padding); + graph::WithTransform(device_context, D2D1::Matrix3x2F::Translation(padding_rect.left, padding_rect.top), + [this](ID2D1DeviceContext* device_context) + { + OnDrawBackground(device_context); + DrawEventArgs args(this, this, device_context); + draw_background_event.Raise(args); + }); + + + const auto rect = GetRect(RectRange::Content); + graph::WithTransform(device_context, D2D1::Matrix3x2F::Translation(rect.left, rect.top), + [this](ID2D1DeviceContext* device_context) + { + OnDrawContent(device_context); + DrawEventArgs args(this, this, device_context); + draw_content_event.Raise(args); + }); + + graph::WithTransform(device_context, D2D1::Matrix3x2F::Translation(padding_rect.left, padding_rect.top), + [this](ID2D1DeviceContext* device_context) + { + OnDrawForeground(device_context); + DrawEventArgs args(this, this, device_context); + draw_foreground_event.Raise(args); + }); } void Control::OnDrawContent(ID2D1DeviceContext * device_context) @@ -424,6 +444,16 @@ namespace cru::ui } + void Control::OnDrawForeground(ID2D1DeviceContext* device_context) + { + + } + + void Control::OnDrawBackground(ID2D1DeviceContext* device_context) + { + + } + void Control::OnPositionChanged(PositionChangedEventArgs & args) { diff --git a/src/ui/control.hpp b/src/ui/control.hpp index 8ac9ae72..7afc0c4e 100644 --- a/src/ui/control.hpp +++ b/src/ui/control.hpp @@ -221,7 +221,9 @@ namespace cru::ui events::FocusChangeEvent get_focus_event; events::FocusChangeEvent lose_focus_event; - events::DrawEvent draw_event; + events::DrawEvent draw_content_event; + events::DrawEvent draw_background_event; + events::DrawEvent draw_foreground_event; events::PositionChangedEvent position_changed_event; events::SizeChangedEvent size_changed_event; @@ -238,10 +240,12 @@ namespace cru::ui virtual void OnDetachToWindow(Window* window); private: - void OnDraw(ID2D1DeviceContext* device_context); + void OnDrawCore(ID2D1DeviceContext* device_context); protected: virtual void OnDrawContent(ID2D1DeviceContext* device_context); + virtual void OnDrawForeground(ID2D1DeviceContext* device_context); + virtual void OnDrawBackground(ID2D1DeviceContext* device_context); // For a event, the window event system will first dispatch event to core functions. // Therefore for particular controls, you should do essential actions in core functions, |