aboutsummaryrefslogtreecommitdiff
path: root/CruUI-Generate/cru_ui.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2018-11-13 22:24:17 +0800
committercrupest <crupest@outlook.com>2018-11-13 22:24:17 +0800
commit38a523be0085a9b529043bddc61e4aee04a6768d (patch)
tree4003c4795f111631f1df07e0b1fdd1c2b626b608 /CruUI-Generate/cru_ui.cpp
parent91dda866a0919f9e6cfb5e7857ac0466572d96d8 (diff)
downloadcru-38a523be0085a9b529043bddc61e4aee04a6768d.tar.gz
cru-38a523be0085a9b529043bddc61e4aee04a6768d.tar.bz2
cru-38a523be0085a9b529043bddc61e4aee04a6768d.zip
Add enhanced bound check.
Diffstat (limited to 'CruUI-Generate/cru_ui.cpp')
-rw-r--r--CruUI-Generate/cru_ui.cpp32
1 files changed, 30 insertions, 2 deletions
diff --git a/CruUI-Generate/cru_ui.cpp b/CruUI-Generate/cru_ui.cpp
index 3036989d..418d2498 100644
--- a/CruUI-Generate/cru_ui.cpp
+++ b/CruUI-Generate/cru_ui.cpp
@@ -980,8 +980,15 @@ namespace cru::ui
bool Control::IsPointInside(const Point & point)
{
- const auto size = GetSize();
- return point.x >= 0.0f && point.x < size.width && point.y >= 0.0f && point.y < size.height;
+ if (border_geometry_ != nullptr)
+ {
+ BOOL contains;
+ border_geometry_->FillContainsPoint(Convert(point), D2D1::Matrix3x2F::Identity(), &contains);
+ if (!contains)
+ border_geometry_->StrokeContainsPoint(Convert(point), GetBorderProperty().GetStrokeWidth(), nullptr, D2D1::Matrix3x2F::Identity(), &contains);
+ return contains != 0;
+ }
+ return false;
}
void Control::Draw(ID2D1DeviceContext* device_context)
@@ -1108,6 +1115,7 @@ namespace cru::ui
void Control::InvalidateBorder()
{
+ RegenerateBorderGeometry();
InvalidateLayout();
Repaint();
}
@@ -1275,6 +1283,7 @@ namespace cru::ui
void Control::OnSizeChangedCore(SizeChangedEventArgs & args)
{
+ RegenerateBorderGeometry();
#ifdef CRU_DEBUG_LAYOUT
margin_geometry_ = CalculateSquareRingGeometry(GetRect(RectRange::Margin), GetRect(RectRange::FullBorder));
padding_geometry_ = CalculateSquareRingGeometry(GetRect(RectRange::Padding), GetRect(RectRange::Content));
@@ -1295,6 +1304,20 @@ namespace cru::ui
size_changed_event.Raise(args);
}
+ void Control::RegenerateBorderGeometry()
+ {
+ const auto bound_rect = GetRect(RectRange::HalfBorder);
+ const auto bound_rounded_rect = D2D1::RoundedRect(Convert(bound_rect),
+ GetBorderProperty().GetRadiusX(),
+ GetBorderProperty().GetRadiusY());
+
+ Microsoft::WRL::ComPtr<ID2D1RoundedRectangleGeometry> geometry;
+ ThrowIfFailed(
+ graph::GraphManager::GetInstance()->GetD2D1Factory()->CreateRoundedRectangleGeometry(bound_rounded_rect, &geometry)
+ );
+ border_geometry_ = std::move(geometry);
+ }
+
void Control::OnMouseEnter(MouseEventArgs & args)
{
}
@@ -2495,6 +2518,11 @@ namespace cru::ui
}
+ bool Window::IsPointInside(const Point& point)
+ {
+ return Rect(Point::Zero(), GetClientSize()).IsPointInside(point);
+ }
+
void Window::WindowInvalidateLayout()
{
if (is_layout_invalid_)