From 38a523be0085a9b529043bddc61e4aee04a6768d Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 13 Nov 2018 22:24:17 +0800 Subject: Add enhanced bound check. --- src/ui/control.cpp | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'src/ui/control.cpp') diff --git a/src/ui/control.cpp b/src/ui/control.cpp index 2d368673..9d0afe06 100644 --- a/src/ui/control.cpp +++ b/src/ui/control.cpp @@ -191,8 +191,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) @@ -319,6 +326,7 @@ namespace cru::ui void Control::InvalidateBorder() { + RegenerateBorderGeometry(); InvalidateLayout(); Repaint(); } @@ -486,6 +494,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 +515,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 geometry; + ThrowIfFailed( + graph::GraphManager::GetInstance()->GetD2D1Factory()->CreateRoundedRectangleGeometry(bound_rounded_rect, &geometry) + ); + border_geometry_ = std::move(geometry); + } + void Control::OnMouseEnter(MouseEventArgs & args) { } -- cgit v1.2.3 From 6d0a44597eb6e35993b46642ebf85abd94bca2d7 Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 13 Nov 2018 22:36:40 +0800 Subject: Add check for IsBordered. --- CruUI-Generate/cru_ui.cpp | 49 ++++++++++++++++++++++++++++++++------------- CruUI-Generate/cru_ui.hpp | 2 +- src/ui/control.cpp | 51 +++++++++++++++++++++++++++++++++-------------- src/ui/control.hpp | 2 +- 4 files changed, 73 insertions(+), 31 deletions(-) (limited to 'src/ui/control.cpp') diff --git a/CruUI-Generate/cru_ui.cpp b/CruUI-Generate/cru_ui.cpp index 418d2498..252dfd9a 100644 --- a/CruUI-Generate/cru_ui.cpp +++ b/CruUI-Generate/cru_ui.cpp @@ -982,11 +982,20 @@ namespace cru::ui { 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; + 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; } @@ -1306,16 +1315,28 @@ namespace cru::ui void Control::RegenerateBorderGeometry() { - const auto bound_rect = GetRect(RectRange::HalfBorder); - const auto bound_rounded_rect = D2D1::RoundedRect(Convert(bound_rect), - GetBorderProperty().GetRadiusX(), - GetBorderProperty().GetRadiusY()); + 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 geometry; - ThrowIfFailed( - graph::GraphManager::GetInstance()->GetD2D1Factory()->CreateRoundedRectangleGeometry(bound_rounded_rect, &geometry) - ); - border_geometry_ = std::move(geometry); + Microsoft::WRL::ComPtr 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 geometry; + ThrowIfFailed( + graph::GraphManager::GetInstance()->GetD2D1Factory()->CreateRectangleGeometry(Convert(bound_rect), &geometry) + ); + border_geometry_ = std::move(geometry); + } } void Control::OnMouseEnter(MouseEventArgs & args) diff --git a/CruUI-Generate/cru_ui.hpp b/CruUI-Generate/cru_ui.hpp index 2196c918..302ce611 100644 --- a/CruUI-Generate/cru_ui.hpp +++ b/CruUI-Generate/cru_ui.hpp @@ -1851,7 +1851,7 @@ namespace cru::ui bool is_bordered_ = false; BorderProperty border_property_; - Microsoft::WRL::ComPtr border_geometry_ = nullptr; + Microsoft::WRL::ComPtr border_geometry_ = nullptr; AnyMap additional_property_map_{}; diff --git a/src/ui/control.cpp b/src/ui/control.cpp index 9d0afe06..42e5f71f 100644 --- a/src/ui/control.cpp +++ b/src/ui/control.cpp @@ -193,11 +193,20 @@ namespace cru::ui { 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; + 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; } @@ -517,16 +526,28 @@ namespace cru::ui 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 geometry; - ThrowIfFailed( - graph::GraphManager::GetInstance()->GetD2D1Factory()->CreateRoundedRectangleGeometry(bound_rounded_rect, &geometry) - ); - border_geometry_ = std::move(geometry); + 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 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 geometry; + ThrowIfFailed( + graph::GraphManager::GetInstance()->GetD2D1Factory()->CreateRectangleGeometry(Convert(bound_rect), &geometry) + ); + border_geometry_ = std::move(geometry); + } } void Control::OnMouseEnter(MouseEventArgs & args) diff --git a/src/ui/control.hpp b/src/ui/control.hpp index 75c10c04..776eacb0 100644 --- a/src/ui/control.hpp +++ b/src/ui/control.hpp @@ -372,7 +372,7 @@ namespace cru::ui bool is_bordered_ = false; BorderProperty border_property_; - Microsoft::WRL::ComPtr border_geometry_ = nullptr; + Microsoft::WRL::ComPtr border_geometry_ = nullptr; AnyMap additional_property_map_{}; -- cgit v1.2.3