From cda36e0fe4e4c87b6090bfdf72891f767b857927 Mon Sep 17 00:00:00 2001 From: luoying_ace_admin Date: Sat, 2 Apr 2022 14:51:29 +0800 Subject: [PATCH] add hoverrect of rating Signed-off-by: luoying_ace_admin --- .../core/components/rating/render_rating.cpp | 30 +++++++++++++++++++ .../core/components/rating/render_rating.h | 8 +++++ .../components/rating/rosen_render_rating.cpp | 2 +- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/frameworks/core/components/rating/render_rating.cpp b/frameworks/core/components/rating/render_rating.cpp index 77e271bb..72b38c00 100644 --- a/frameworks/core/components/rating/render_rating.cpp +++ b/frameworks/core/components/rating/render_rating.cpp @@ -502,6 +502,31 @@ void RenderRating::ConstrainScore(double& score, double lowerBoundary, double up } } +WeakPtr RenderRating::CheckHoverNode() +{ + return AceType::WeakClaim(this); +} + +bool RenderRating::HandleMouseEvent(const MouseEvent& event) +{ + OnMouseHoverEnterTest(); + if (NearZero(singleWidth_)) { + return false; + } + auto localPoint = event.GetScreenOffset() - GetGlobalOffset(); + double offsetDeltaX = (GetLayoutSize().Width() - ratingSize_.Width()) / 2.0; + int32_t starIndex = (int32_t)floor((localPoint.GetX() - offsetDeltaX) / singleWidth_); + if (onHover_) { + PlayEventEffectAnimation(starIndex); + } + return true; +} + +void RenderRating::AnimateMouseHoverEnter() +{ + OnMouseHoverEnterTest(); +} + void RenderRating::OnMouseHoverEnterTest() { operationEvent_ = OperationEvent::RATING_MOUSE_EVENT; @@ -511,6 +536,11 @@ void RenderRating::OnMouseHoverEnterTest() onHover_ = true; } +void RenderRating::AnimateMouseHoverExit() +{ + OnMouseHoverExitTest(); +} + void RenderRating::OnMouseHoverExitTest() { operationEvent_ = OperationEvent::RATING_TOUCH_EVENT; diff --git a/frameworks/core/components/rating/render_rating.h b/frameworks/core/components/rating/render_rating.h index 23f58671..880295f7 100644 --- a/frameworks/core/components/rating/render_rating.h +++ b/frameworks/core/components/rating/render_rating.h @@ -95,6 +95,10 @@ public: { return SystemProperties::GetDeviceType() == DeviceType::PHONE; } + bool IsTablet() const + { + return SystemProperties::GetDeviceType() == DeviceType::TABLET; + } void CalculateRatingSize(); void FireChangeEvent(); void SetFocusAnimation(const RefPtr& focusAnimation) @@ -134,6 +138,10 @@ protected: void OnMouseHoverEnterTest() override; void OnMouseHoverExitTest() override; bool MouseHoverTest(const Point& parentLocalPoint) override; + void AnimateMouseHoverEnter() override; + void AnimateMouseHoverExit() override; + WeakPtr CheckHoverNode() override; + virtual bool HandleMouseEvent(const MouseEvent& event) override; virtual void PaintFocus( const Offset& offset, double rrectRadius, const Size& boardSize, RenderContext& context) {} virtual void PaintFocus( diff --git a/frameworks/core/components/rating/rosen_render_rating.cpp b/frameworks/core/components/rating/rosen_render_rating.cpp index f04746ce..07f809f9 100644 --- a/frameworks/core/components/rating/rosen_render_rating.cpp +++ b/frameworks/core/components/rating/rosen_render_rating.cpp @@ -44,7 +44,7 @@ void RosenRenderRating::Paint(RenderContext& context, const Offset& offset) double focusRadius = singleWidth_ - imageVerticalOffset * 2; RequestFocusAnimation(animationOffset + GetGlobalOffset(), Size(focusRadius, focusRadius), focusRadius); } - if (IsPhone() && !isIndicator_) { + if ((IsPhone() || IsTablet()) && !isIndicator_) { PaintHoverRect(canvas); } PaintRatingBar(context, canvas);