提交 e952186f 编写于 作者: Y YueBiang

IssueNo:#I40TE4

Description:fix animation bugs
Sig:graphic
Feature or Bugfix:Bugfix
Binary Source:No
Signed-off-by: NYueBiang <suyue7@huawei.com>
上级 9f199e77
...@@ -704,9 +704,6 @@ bool RootView::FindSubView(const UIView& parentView, const UIView* subView) ...@@ -704,9 +704,6 @@ bool RootView::FindSubView(const UIView& parentView, const UIView* subView)
void RootView::InitMapBufferInfo(BufferInfo* bufferInfo) void RootView::InitMapBufferInfo(BufferInfo* bufferInfo)
{ {
uint32_t bufferSize = bufferInfo->width * bufferInfo->height *
(DrawUtils::GetPxSizeByColorMode(bufferInfo->mode) >> 3); // 3: Shift right 3 bits
dc_.mapBufferInfo = new BufferInfo(); dc_.mapBufferInfo = new BufferInfo();
if (dc_.mapBufferInfo == nullptr) { if (dc_.mapBufferInfo == nullptr) {
return; return;
...@@ -717,6 +714,10 @@ void RootView::InitMapBufferInfo(BufferInfo* bufferInfo) ...@@ -717,6 +714,10 @@ void RootView::InitMapBufferInfo(BufferInfo* bufferInfo)
dc_.mapBufferInfo = nullptr; dc_.mapBufferInfo = nullptr;
return; return;
} }
dc_.mapBufferInfo->mode = ARGB8888;
dc_.mapBufferInfo->stride = dc_.mapBufferInfo->width *
(DrawUtils::GetPxSizeByColorMode(dc_.mapBufferInfo->mode) >> 3); // 3: Shift right 3 bits
uint32_t bufferSize = dc_.mapBufferInfo->stride * dc_.mapBufferInfo->height;
dc_.mapBufferInfo->virAddr = dc_.mapBufferInfo->phyAddr = dc_.mapBufferInfo->virAddr = dc_.mapBufferInfo->phyAddr =
BaseGfxEngine::GetInstance()->AllocBuffer(bufferSize, BUFFER_MAP_SURFACE); BaseGfxEngine::GetInstance()->AllocBuffer(bufferSize, BUFFER_MAP_SURFACE);
} }
......
...@@ -30,7 +30,7 @@ constexpr uint8_t DEFAULT_ROTATE_THRESHOLD = 4; ...@@ -30,7 +30,7 @@ constexpr uint8_t DEFAULT_ROTATE_THRESHOLD = 4;
namespace OHOS { namespace OHOS {
#if DEFAULT_ANIMATION #if DEFAULT_ANIMATION
class BarEaseInOutAnimator final : private AnimatorCallback { class BarEaseInOutAnimator final : public AnimatorCallback {
public: public:
BarEaseInOutAnimator() = delete; BarEaseInOutAnimator() = delete;
BarEaseInOutAnimator(const BarEaseInOutAnimator&) = delete; BarEaseInOutAnimator(const BarEaseInOutAnimator&) = delete;
......
...@@ -35,6 +35,7 @@ UIButton::UIButton() ...@@ -35,6 +35,7 @@ UIButton::UIButton()
state_(RELEASED), state_(RELEASED),
styleState_(RELEASED), styleState_(RELEASED),
#if DEFAULT_ANIMATION #if DEFAULT_ANIMATION
enableAnimation_(true),
animator_(*this), animator_(*this),
#endif #endif
buttonStyleAllocFlag_(false) buttonStyleAllocFlag_(false)
...@@ -175,7 +176,9 @@ bool UIButton::OnPressEvent(const PressEvent& event) ...@@ -175,7 +176,9 @@ bool UIButton::OnPressEvent(const PressEvent& event)
Resize(contentWidth_, contentHeight_); Resize(contentWidth_, contentHeight_);
Invalidate(); Invalidate();
#if DEFAULT_ANIMATION #if DEFAULT_ANIMATION
animator_.Start(); if (enableAnimation_) {
animator_.Start();
}
#endif #endif
return UIView::OnPressEvent(event); return UIView::OnPressEvent(event);
} }
...@@ -187,7 +190,9 @@ bool UIButton::OnReleaseEvent(const ReleaseEvent& event) ...@@ -187,7 +190,9 @@ bool UIButton::OnReleaseEvent(const ReleaseEvent& event)
Resize(contentWidth_, contentHeight_); Resize(contentWidth_, contentHeight_);
Invalidate(); Invalidate();
#if DEFAULT_ANIMATION #if DEFAULT_ANIMATION
animator_.Start(); if (enableAnimation_) {
animator_.Start();
}
#endif #endif
return UIView::OnReleaseEvent(event); return UIView::OnReleaseEvent(event);
} }
...@@ -199,7 +204,9 @@ bool UIButton::OnCancelEvent(const CancelEvent& event) ...@@ -199,7 +204,9 @@ bool UIButton::OnCancelEvent(const CancelEvent& event)
Resize(contentWidth_, contentHeight_); Resize(contentWidth_, contentHeight_);
Invalidate(); Invalidate();
#if DEFAULT_ANIMATION #if DEFAULT_ANIMATION
animator_.Start(); if (enableAnimation_) {
animator_.Start();
}
#endif #endif
return UIView::OnCancelEvent(event); return UIView::OnCancelEvent(event);
} }
...@@ -296,7 +303,7 @@ bool UIButton::OnPreDraw(Rect& invalidatedArea) const ...@@ -296,7 +303,7 @@ bool UIButton::OnPreDraw(Rect& invalidatedArea) const
#if DEFAULT_ANIMATION #if DEFAULT_ANIMATION
void UIButton::OnPostDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) void UIButton::OnPostDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea)
{ {
if (state_ == ButtonState::PRESSED) { if (state_ == ButtonState::PRESSED && enableAnimation_) {
animator_.DrawMask(gfxDstBuffer, invalidatedArea); animator_.DrawMask(gfxDstBuffer, invalidatedArea);
} }
UIView::OnPostDraw(gfxDstBuffer, invalidatedArea); UIView::OnPostDraw(gfxDstBuffer, invalidatedArea);
...@@ -371,4 +378,4 @@ void UIButton::ButtonAnimator::OnStop(UIView& view) ...@@ -371,4 +378,4 @@ void UIButton::ButtonAnimator::OnStop(UIView& view)
} }
} }
#endif #endif
} // namespace OHOS } // namespace OHOS
\ No newline at end of file
...@@ -395,6 +395,12 @@ public: ...@@ -395,6 +395,12 @@ public:
styleState_ = state; styleState_ = state;
} }
#if DEFAULT_ANIMATION
void EnableButtonAnimation(bool enable)
{
enableAnimation_ = enable;
}
#endif
protected: protected:
Image* defaultImgSrc_; Image* defaultImgSrc_;
Image* triggeredImgSrc_; Image* triggeredImgSrc_;
...@@ -410,6 +416,7 @@ protected: ...@@ -410,6 +416,7 @@ protected:
ButtonState styleState_; ButtonState styleState_;
Style* buttonStyles_[BTN_STATE_NUM]; Style* buttonStyles_[BTN_STATE_NUM];
#if DEFAULT_ANIMATION #if DEFAULT_ANIMATION
bool enableAnimation_;
friend class ButtonAnimator; friend class ButtonAnimator;
class ButtonAnimator final : public AnimatorCallback { class ButtonAnimator final : public AnimatorCallback {
public: public:
......
...@@ -129,6 +129,14 @@ void UITestBUTTON::TearDown() ...@@ -129,6 +129,14 @@ void UITestBUTTON::TearDown()
delete clickSmallListener_; delete clickSmallListener_;
clickSmallListener_ = nullptr; clickSmallListener_ = nullptr;
} }
if (enableAnimationListener_ != nullptr) {
delete enableAnimationListener_;
enableAnimationListener_ = nullptr;
}
if (disableAnimationListener_ != nullptr) {
delete disableAnimationListener_;
disableAnimationListener_ = nullptr;
}
DeleteChildren(container_); DeleteChildren(container_);
container_ = nullptr; container_ = nullptr;
} }
...@@ -566,6 +574,27 @@ private: ...@@ -566,6 +574,27 @@ private:
bool touchable_; bool touchable_;
}; };
#if DEFAULT_ANIMATION
class TestBtnAnimationListener : public UIView::OnClickListener {
public:
TestBtnAnimationListener(UIView* uiView, bool enableAnimation)
: uiView_(uiView),
enableAnimation_(enableAnimation) {}
~TestBtnAnimationListener() {}
bool OnClick(UIView& view, const ClickEvent& event) override
{
static_cast<UIButton*>(uiView_)->EnableButtonAnimation(enableAnimation_);
return true;
}
private:
UIView* uiView_;
bool enableAnimation_;
};
#endif
UILabel* GetTestUILabel(const char* titlename) UILabel* GetTestUILabel(const char* titlename)
{ {
if (titlename == nullptr) { if (titlename == nullptr) {
...@@ -669,6 +698,26 @@ void UITestBUTTON::UIKit_Button_Test_002(UIScrollView* container, UIButton* butt ...@@ -669,6 +698,26 @@ void UITestBUTTON::UIKit_Button_Test_002(UIScrollView* container, UIButton* butt
container->Add(button13); container->Add(button13);
container->Add(button14); container->Add(button14);
container->Add(button15); container->Add(button15);
#if DEFAULT_ANIMATION
UILabelButton* button16 = GetTestUIButton("开启动效", 340, 1040, button); // 340: x-coordinate, 1040: y-coordinate
if (enableAnimationListener_ == nullptr) {
enableAnimationListener_ =
static_cast<UIView::OnClickListener*>(new TestBtnAnimationListener((UIView*)button, true));
}
button16->SetOnClickListener(enableAnimationListener_);
UILabelButton* button17 = GetTestUIButton("关闭动效", 340, 1090, button); // 340: x-coordinate, 1090: y-coordinate
if (disableAnimationListener_ == nullptr) {
disableAnimationListener_ =
static_cast<UIView::OnClickListener*>(new TestBtnAnimationListener((UIView*)button, false));
}
button17->EnableButtonAnimation(false);
button17->SetOnClickListener(disableAnimationListener_);
container->Add(button16);
container->Add(button17);
#endif
} }
void UITestBUTTON::UIKit_Button_Test_001() void UITestBUTTON::UIKit_Button_Test_001()
......
...@@ -98,6 +98,8 @@ private: ...@@ -98,6 +98,8 @@ private:
UIView::OnClickListener* clickUpListener_ = nullptr; UIView::OnClickListener* clickUpListener_ = nullptr;
UIView::OnClickListener* clickDownListener_ = nullptr; UIView::OnClickListener* clickDownListener_ = nullptr;
UIView::OnClickListener* clickSmallListener_ = nullptr; UIView::OnClickListener* clickSmallListener_ = nullptr;
UIView::OnClickListener* enableAnimationListener_ = nullptr;
UIView::OnClickListener* disableAnimationListener_ = nullptr;
}; };
} // namespace OHOS } // namespace OHOS
#endif // UI_TEST_BUTTON_H #endif // UI_TEST_BUTTON_H
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册