提交 1d5e643d 编写于 作者: Y YueBiang

fix slider bugs

上级 6441b10a
......@@ -107,31 +107,71 @@ void UIBoxProgress::DrawRoundCap(const Image* image, const Point& imgPos, const
Style capStyle = style;
capStyle.lineWidth_ = radius;
capStyle.lineColor_ = style.bgColor_;
capStyle.lineOpa_ = style.bgOpa_;
if ((image != nullptr) && (image->GetSrcType() != IMG_SRC_UNKNOWN)) {
capStyle.lineOpa_ = style.imageOpa_;
} else {
capStyle.lineOpa_ = style.bgOpa_;
}
ArcInfo arcInfo = {{0}};
arcInfo.radius = radius;
arcInfo.imgPos = imgPos;
arcInfo.imgSrc = image;
arcInfo.center = leftTop;
arcInfo.startAngle = THREE_QUARTER_IN_DEGREE;
arcInfo.endAngle = 0;
DrawArc::GetInstance()->Draw(arcInfo, invalidatedArea, capStyle, opaScale_, CapType::CAP_NONE);
arcInfo.center = leftBottom;
arcInfo.startAngle = SEMICIRCLE_IN_DEGREE;
arcInfo.endAngle = THREE_QUARTER_IN_DEGREE;
DrawArc::GetInstance()->Draw(arcInfo, invalidatedArea, capStyle, opaScale_, CapType::CAP_NONE);
arcInfo.center = rightTop;
arcInfo.startAngle = 0;
arcInfo.endAngle = THREE_QUARTER_IN_DEGREE;
DrawArc::GetInstance()->Draw(arcInfo, invalidatedArea, capStyle, opaScale_, CapType::CAP_NONE);
arcInfo.center = rightBottom;
arcInfo.startAngle = THREE_QUARTER_IN_DEGREE;
arcInfo.endAngle = SEMICIRCLE_IN_DEGREE;
DrawArc::GetInstance()->Draw(arcInfo, invalidatedArea, capStyle, opaScale_, CapType::CAP_NONE);
if (rect.GetWidth() % 2 == 0) { // 2: determine the odd or even number of the width
arcInfo.center = leftTop;
arcInfo.startAngle = THREE_QUARTER_IN_DEGREE;
arcInfo.endAngle = 0;
DrawArc::GetInstance()->Draw(arcInfo, invalidatedArea, capStyle, opaScale_, CapType::CAP_NONE);
arcInfo.center = leftBottom;
arcInfo.startAngle = SEMICIRCLE_IN_DEGREE;
arcInfo.endAngle = THREE_QUARTER_IN_DEGREE;
DrawArc::GetInstance()->Draw(arcInfo, invalidatedArea, capStyle, opaScale_, CapType::CAP_NONE);
arcInfo.center = rightTop;
arcInfo.startAngle = 0;
arcInfo.endAngle = QUARTER_IN_DEGREE;
DrawArc::GetInstance()->Draw(arcInfo, invalidatedArea, capStyle, opaScale_, CapType::CAP_NONE);
arcInfo.center = rightBottom;
arcInfo.startAngle = QUARTER_IN_DEGREE;
arcInfo.endAngle = SEMICIRCLE_IN_DEGREE;
DrawArc::GetInstance()->Draw(arcInfo, invalidatedArea, capStyle, opaScale_, CapType::CAP_NONE);
} else {
switch (direction_) {
case Direction::DIR_LEFT_TO_RIGHT:
case Direction::DIR_RIGHT_TO_LEFT: {
arcInfo.center = leftTop;
arcInfo.startAngle = SEMICIRCLE_IN_DEGREE;
arcInfo.endAngle = 0;
DrawArc::GetInstance()->Draw(arcInfo, invalidatedArea, capStyle, opaScale_, CapType::CAP_NONE);
arcInfo.center = leftBottom;
arcInfo.startAngle = 0;
arcInfo.endAngle = SEMICIRCLE_IN_DEGREE;
DrawArc::GetInstance()->Draw(arcInfo, invalidatedArea, capStyle, opaScale_, CapType::CAP_NONE);
break;
}
case Direction::DIR_TOP_TO_BOTTOM:
case Direction::DIR_BOTTOM_TO_TOP: {
arcInfo.center = leftTop;
arcInfo.startAngle = THREE_QUARTER_IN_DEGREE;
arcInfo.endAngle = QUARTER_IN_DEGREE;
DrawArc::GetInstance()->Draw(arcInfo, invalidatedArea, capStyle, opaScale_, CapType::CAP_NONE);
arcInfo.center = leftBottom;
arcInfo.startAngle = QUARTER_IN_DEGREE;
arcInfo.endAngle = THREE_QUARTER_IN_DEGREE;
DrawArc::GetInstance()->Draw(arcInfo, invalidatedArea, capStyle, opaScale_, CapType::CAP_NONE);
break;
}
default:
GRAPHIC_LOGE("UIBoxProgress: DrawRoundCap direction Err!\n");
break;
}
}
}
void UIBoxProgress::GetBackgroundParam(Point& startPoint, int16_t& width, int16_t& height, uint16_t& radius,
......
......@@ -30,16 +30,16 @@ UISlider::UISlider()
touchable_ = true;
draggable_ = true;
dragParentInstead_ = false;
SetCapType(CapType::CAP_ROUND);
Theme* theme = ThemeManager::GetInstance().GetCurrent();
if (theme != nullptr) {
knobStyle_ = &(theme->GetSliderKnobStyle());
} else {
knobStyle_ = &(StyleDefault::GetSliderKnobStyle());
}
#if ENABLE_FOCUS_MANAGER
focusable_ = true;
#endif
SetBackgroundStyle(STYLE_LINE_CAP, CapType::CAP_ROUND);
SetBackgroundStyle(STYLE_BACKGROUND_OPA, BACKGROUND_OPA);
SetBackgroundStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
SetForegroundStyle(STYLE_LINE_CAP, CapType::CAP_ROUND);
SetForegroundStyle(STYLE_BACKGROUND_COLOR,
Color::GetColorFromRGB(FOREGROUND_COLOR_R, FOREGROUND_COLOR_G, FOREGROUND_COLOR_B).full);
}
UISlider::~UISlider()
......@@ -220,7 +220,7 @@ void UISlider::DrawForeground(const Rect& invalidatedArea, Rect& coords)
switch (direction_) {
case Direction::DIR_LEFT_TO_RIGHT: {
length = GetCurrentPos(progressWidth_ - 1);
length = GetCurrentPos(progressWidth_ + 1);
coords.SetRect(startPoint.x, startPoint.y, startPoint.x + progressWidth - 1,
startPoint.y + progressHeight_ - 1);
......@@ -230,7 +230,7 @@ void UISlider::DrawForeground(const Rect& invalidatedArea, Rect& coords)
break;
}
case Direction::DIR_RIGHT_TO_LEFT: {
length = GetCurrentPos(progressWidth_ - 1);
length = GetCurrentPos(progressWidth_ + 1);
coords.SetRect(startPoint.x, startPoint.y, startPoint.x + progressWidth - 1,
startPoint.y + progressHeight_ - 1);
......@@ -240,17 +240,17 @@ void UISlider::DrawForeground(const Rect& invalidatedArea, Rect& coords)
break;
}
case Direction::DIR_TOP_TO_BOTTOM: {
length = GetCurrentPos(progressHeight_ - 1);
length = GetCurrentPos(progressHeight_ + 1);
coords.SetRect(startPoint.x, startPoint.y, startPoint.x + progressWidth_ - 1,
startPoint.y + progressHeight - 1);
top = startPoint.y - radius + 1;
top = startPoint.y - radius - 1;
bottom = top + length;
rect = Rect(startPoint.x, top, startPoint.x + progressWidth_ - 1, bottom);
break;
}
case Direction::DIR_BOTTOM_TO_TOP: {
length = GetCurrentPos(progressHeight_ - 1);
length = GetCurrentPos(progressHeight_ + 1);
coords.SetRect(startPoint.x, startPoint.y, startPoint.x + progressWidth_ - 1,
startPoint.y + progressHeight - 1);
......
......@@ -343,6 +343,10 @@ protected:
bool InitImage() override;
private:
static constexpr int8_t BACKGROUND_OPA = 38;
static constexpr uint8_t FOREGROUND_COLOR_R = 0x1f;
static constexpr uint8_t FOREGROUND_COLOR_G = 0x71;
static constexpr uint8_t FOREGROUND_COLOR_B = 0xff;
#if ENABLE_SLIDER_KNOB
void DrawKnob(const Rect& invalidatedArea, const Rect& foregroundRect);
#else
......
......@@ -479,30 +479,33 @@ bool UITestSlider::ExpandClick1(UIView& view, const ClickEvent& event)
g_height = DEFAULT_WIDTH;
slider_->SetValidHeight(g_height);
slider_->SetValidWidth(g_width);
slider_->LayoutCenterOfParent();
slider_->Resize(g_width, g_height);
slider_->SetDirection(UISlider::Direction::DIR_LEFT_TO_RIGHT);
slider_->LayoutCenterOfParent();
} else if (&view == dirR2LBtn_) {
g_width = DEFAULT_HEIGHT;
g_height = DEFAULT_WIDTH;
slider_->SetValidHeight(g_height);
slider_->SetValidWidth(g_width);
slider_->LayoutCenterOfParent();
slider_->Resize(g_width, g_height);
slider_->SetDirection(UISlider::Direction::DIR_RIGHT_TO_LEFT);
slider_->LayoutCenterOfParent();
} else if (&view == dirT2BBtn_) {
g_width = DEFAULT_WIDTH;
g_height = DEFAULT_HEIGHT;
slider_->SetValidHeight(g_height);
slider_->SetValidWidth(g_width);
slider_->Resize(g_width, g_height);
slider_->SetDirection(UISlider::Direction::DIR_TOP_TO_BOTTOM);
slider_->LayoutCenterOfParent();
} else if (&view == dirB2TBtn_) {
g_width = DEFAULT_WIDTH;
g_height = DEFAULT_HEIGHT;
slider_->SetValidHeight(g_height);
slider_->SetValidWidth(g_width);
slider_->LayoutCenterOfParent();
slider_->Resize(g_width, g_height);
slider_->SetDirection(UISlider::Direction::DIR_BOTTOM_TO_TOP);
slider_->LayoutCenterOfParent();
} else {
ExpandClick2(view, event);
}
......@@ -529,9 +532,9 @@ bool UITestSlider::ExpandClick2(UIView& view, const ClickEvent& event)
#endif
} else if (&view == setStyleBtn_) {
Style style = StyleDefault::GetDefaultStyle();
style.bgColor_ = Color::White();
style.bgColor_ = Color::Green();
slider_->SetBackgroundStyle(style);
style.bgColor_ = Color::Blue();
style.bgColor_ = Color::Red();
slider_->SetForegroundStyle(style);
style.bgColor_ = Color::Gray();
#if ENABLE_SLIDER_KNOB
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册