aboutsummaryrefslogtreecommitdiff
path: root/src/ui/control.cpp
diff options
context:
space:
mode:
author杨宇千 <crupest@outlook.com>2018-11-13 22:44:07 +0800
committerGitHub <noreply@github.com>2018-11-13 22:44:07 +0800
commitb08ba6c83902d140fb14131b3f01837985d39c17 (patch)
tree98719593d5854f2162ea8d87b7fecdc3472968bc /src/ui/control.cpp
parent91dda866a0919f9e6cfb5e7857ac0466572d96d8 (diff)
parent6d0a44597eb6e35993b46642ebf85abd94bca2d7 (diff)
downloadcru-b08ba6c83902d140fb14131b3f01837985d39c17.tar.gz
cru-b08ba6c83902d140fb14131b3f01837985d39c17.tar.bz2
cru-b08ba6c83902d140fb14131b3f01837985d39c17.zip
Merge pull request #18 from crupest/bound
Add support for enhanced bound check.
Diffstat (limited to 'src/ui/control.cpp')
-rw-r--r--src/ui/control.cpp48
1 files changed, 46 insertions, 2 deletions
diff --git a/src/ui/control.cpp b/src/ui/control.cpp
index 2d368673..42e5f71f 100644
--- a/src/ui/control.cpp
+++ b/src/ui/control.cpp
@@ -191,8 +191,24 @@ 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)
+ {
+ if (IsBordered())
+ {
+ 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;
+ }
+ else
+ {
+ BOOL contains;
+ border_geometry_->FillContainsPoint(Convert(point), D2D1::Matrix3x2F::Identity(), &contains);
+ return contains != 0;
+ }
+ }
+ return false;
}
void Control::Draw(ID2D1DeviceContext* device_context)
@@ -319,6 +335,7 @@ namespace cru::ui
void Control::InvalidateBorder()
{
+ RegenerateBorderGeometry();
InvalidateLayout();
Repaint();
}
@@ -486,6 +503,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));
@@ -506,6 +524,32 @@ namespace cru::ui
size_changed_event.Raise(args);
}
+ void Control::RegenerateBorderGeometry()
+ {
+ if (IsBordered())
+ {
+ 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);
+ }
+ else
+ {
+ const auto bound_rect = GetRect(RectRange::Padding);
+ Microsoft::WRL::ComPtr<ID2D1RectangleGeometry> geometry;
+ ThrowIfFailed(
+ graph::GraphManager::GetInstance()->GetD2D1Factory()->CreateRectangleGeometry(Convert(bound_rect), &geometry)
+ );
+ border_geometry_ = std::move(geometry);
+ }
+ }
+
void Control::OnMouseEnter(MouseEventArgs & args)
{
}