aboutsummaryrefslogtreecommitdiff
path: root/src/ui/control.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2018-11-10 20:36:02 +0800
committercrupest <crupest@outlook.com>2018-11-10 20:36:02 +0800
commita465a23bdccff1680f056f61b321be717627601e (patch)
tree9f8af7f26a94105adab5c91ce87f64b5b8ad141e /src/ui/control.cpp
parent0e9e897d306c71ab46fd9b5371d811950124ee27 (diff)
downloadcru-a465a23bdccff1680f056f61b321be717627601e.tar.gz
cru-a465a23bdccff1680f056f61b321be717627601e.tar.bz2
cru-a465a23bdccff1680f056f61b321be717627601e.zip
Add foreground/background support.
Diffstat (limited to 'src/ui/control.cpp')
-rw-r--r--src/ui/control.cpp54
1 files changed, 42 insertions, 12 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)
{