提交 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)
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();
if (dc_.mapBufferInfo == nullptr) {
return;
......@@ -717,6 +714,10 @@ void RootView::InitMapBufferInfo(BufferInfo* bufferInfo)
dc_.mapBufferInfo = nullptr;
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 =
BaseGfxEngine::GetInstance()->AllocBuffer(bufferSize, BUFFER_MAP_SURFACE);
}
......
......@@ -30,7 +30,7 @@ constexpr uint8_t DEFAULT_ROTATE_THRESHOLD = 4;
namespace OHOS {
#if DEFAULT_ANIMATION
class BarEaseInOutAnimator final : private AnimatorCallback {
class BarEaseInOutAnimator final : public AnimatorCallback {
public:
BarEaseInOutAnimator() = delete;
BarEaseInOutAnimator(const BarEaseInOutAnimator&) = delete;
......
......@@ -35,6 +35,7 @@ UIButton::UIButton()
state_(RELEASED),
styleState_(RELEASED),
#if DEFAULT_ANIMATION
enableAnimation_(true),
animator_(*this),
#endif
buttonStyleAllocFlag_(false)
......@@ -175,7 +176,9 @@ bool UIButton::OnPressEvent(const PressEvent& event)
Resize(contentWidth_, contentHeight_);
Invalidate();
#if DEFAULT_ANIMATION
if (enableAnimation_) {
animator_.Start();
}
#endif
return UIView::OnPressEvent(event);
}
......@@ -187,7 +190,9 @@ bool UIButton::OnReleaseEvent(const ReleaseEvent& event)
Resize(contentWidth_, contentHeight_);
Invalidate();
#if DEFAULT_ANIMATION
if (enableAnimation_) {
animator_.Start();
}
#endif
return UIView::OnReleaseEvent(event);
}
......@@ -199,7 +204,9 @@ bool UIButton::OnCancelEvent(const CancelEvent& event)
Resize(contentWidth_, contentHeight_);
Invalidate();
#if DEFAULT_ANIMATION
if (enableAnimation_) {
animator_.Start();
}
#endif
return UIView::OnCancelEvent(event);
}
......@@ -296,7 +303,7 @@ bool UIButton::OnPreDraw(Rect& invalidatedArea) const
#if DEFAULT_ANIMATION
void UIButton::OnPostDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea)
{
if (state_ == ButtonState::PRESSED) {
if (state_ == ButtonState::PRESSED && enableAnimation_) {
animator_.DrawMask(gfxDstBuffer, invalidatedArea);
}
UIView::OnPostDraw(gfxDstBuffer, invalidatedArea);
......
......@@ -395,6 +395,12 @@ public:
styleState_ = state;
}
#if DEFAULT_ANIMATION
void EnableButtonAnimation(bool enable)
{
enableAnimation_ = enable;
}
#endif
protected:
Image* defaultImgSrc_;
Image* triggeredImgSrc_;
......@@ -410,6 +416,7 @@ protected:
ButtonState styleState_;
Style* buttonStyles_[BTN_STATE_NUM];
#if DEFAULT_ANIMATION
bool enableAnimation_;
friend class ButtonAnimator;
class ButtonAnimator final : public AnimatorCallback {
public:
......
......@@ -129,6 +129,14 @@ void UITestBUTTON::TearDown()
delete clickSmallListener_;
clickSmallListener_ = nullptr;
}
if (enableAnimationListener_ != nullptr) {
delete enableAnimationListener_;
enableAnimationListener_ = nullptr;
}
if (disableAnimationListener_ != nullptr) {
delete disableAnimationListener_;
disableAnimationListener_ = nullptr;
}
DeleteChildren(container_);
container_ = nullptr;
}
......@@ -566,6 +574,27 @@ private:
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)
{
if (titlename == nullptr) {
......@@ -669,6 +698,26 @@ void UITestBUTTON::UIKit_Button_Test_002(UIScrollView* container, UIButton* butt
container->Add(button13);
container->Add(button14);
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()
......
......@@ -98,6 +98,8 @@ private:
UIView::OnClickListener* clickUpListener_ = nullptr;
UIView::OnClickListener* clickDownListener_ = nullptr;
UIView::OnClickListener* clickSmallListener_ = nullptr;
UIView::OnClickListener* enableAnimationListener_ = nullptr;
UIView::OnClickListener* disableAnimationListener_ = nullptr;
};
} // namespace OHOS
#endif // UI_TEST_BUTTON_H
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册