提交 4bcaa490 编写于 作者: W wangtiantian

IssueNo:https://gitee.com/openharmony/graphic_ui/issues/I42IVJ

Description:add set selected state color for UICheckBox
Sig:graphic
Feature or Bugfix:Bugfix
Binary Source:No
Signed-off-by: Nwangtiantian <wangtiantian19@huawei.com>
上级 b7ad581f
......@@ -27,6 +27,9 @@ constexpr float DEFAULT_COEFFICIENT_START_DY = 0.5; // start point: y-cordinate
constexpr float DEFAULT_COEFFICIENT_MID_DX = 0.2; // middle point: y-cordinate offset
constexpr float DEFAULT_COEFFICIENT_MID_DY = 0.38; // middle point: y-cordinate offset
constexpr int16_t DEFAULT_RATIO_BORDER_RADIUS_LINE_WIDTH = 4;
constexpr uint8_t DEFAULT_BG_RED = 31;
constexpr uint8_t DEFAULT_BG_GREEN = 113;
constexpr uint8_t DEFAULT_BG_BLUE = 255;
#if DEFAULT_ANIMATION
constexpr int16_t DEFAULT_ANIMATOR_TIME = 200;
constexpr float BEZIER_CONTROL_POINT_X_1 = 0.33;
......@@ -52,6 +55,7 @@ UICheckBox::UICheckBox()
runTime_ = 0;
checkBoxAnimator_ = Animator(this, this, DEFAULT_ANIMATOR_TIME, false);
#endif
selectedStateColor_ = Color::GetColorFromRGB(DEFAULT_BG_RED, DEFAULT_BG_GREEN, DEFAULT_BG_BLUE);
}
void UICheckBox::SetState(UICheckBoxState state, bool needAnimater)
......@@ -130,7 +134,7 @@ void UICheckBox::SelectedStateSoftwareDrawing(BufferInfo& gfxDstBuffer,
}
Style styleSelect = StyleDefault::GetBackgroundTransparentStyle();
styleSelect.borderRadius_ = borderRadius;
styleSelect.bgColor_ = Color::GetColorFromRGB(DEFAULT_BG_RED, DEFAULT_BG_GREEN, DEFAULT_BG_BLUE);
styleSelect.bgColor_ = selectedStateColor_;
styleSelect.bgOpa_ = backgroundOpacity_;
BaseGfxEngine::GetInstance()->DrawRect(gfxDstBuffer, rect, trunc, styleSelect, opaScale_);
int16_t dx = borderWidth_ * DEFAULT_COEFFICIENT_START_DX;
......@@ -255,4 +259,14 @@ void UICheckBox::OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea)
#endif
}
}
void UICheckBox::SetSelectedStateColor(ColorType color)
{
selectedStateColor_ = color;
}
ColorType UICheckBox::GetSelectedStateColor() const
{
return selectedStateColor_;
}
} // namespace OHOS
......@@ -106,7 +106,7 @@ void UIRadioButton::OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea
BaseGfxEngine::GetInstance()->DrawArc(gfxDstBuffer, arcInfoBig, trunc, style, 0xa8, CapType::CAP_NONE);
}
style.lineWidth_ = arcInfoBig.radius;
style.lineColor_ = Color::GetColorFromRGB(0x1F, 0x71, 0xFF);
style.lineColor_ = selectedStateColor_;
BaseGfxEngine::GetInstance()->DrawArc(gfxDstBuffer, arcInfoBig, trunc, style, backgroundOpacity_,
CapType::CAP_NONE);
style.lineWidth_ = arcInfoSmall.radius;
......
......@@ -75,14 +75,12 @@ void UIToggleButton::CalculateSize()
if (checkBoxAnimator_.GetState() != Animator::START) {
currentCenter_ = (state_ == SELECTED) ? rightCenter_ : leftCenter_;
backgroundOpacity_ = (state_ == SELECTED) ? OPA_OPAQUE : TOGGLE_BTN_UNSELECTED_OPA;
bgColor_ = (state_ == SELECTED) ? Color::GetColorFromRGB(DEFAULT_BG_RED, DEFAULT_BG_GREEN, DEFAULT_BG_BLUE) :
Color::White();
bgColor_ = (state_ == SELECTED) ? selectedStateColor_ : Color::White();
}
#else
currentCenter_ = (state_ == SELECTED) ? rightCenter_ : leftCenter_;
backgroundOpacity_ = (state_ == SELECTED) ? OPA_OPAQUE : TOGGLE_BTN_UNSELECTED_OPA;
bgColor_ = (state_ == SELECTED) ? Color::GetColorFromRGB(DEFAULT_BG_RED, DEFAULT_BG_GREEN, DEFAULT_BG_BLUE) :
Color::White();
bgColor_ = (state_ == SELECTED) ? selectedStateColor_ : Color::White();
#endif
rectMid_.SetRect(x, y, x + rectWidth_, y + (corner_ << 1) + 1);
}
......@@ -122,14 +120,12 @@ void UIToggleButton::Callback(UIView* view)
currentCenter_.y = rightCenter_.y;
currentCenter_.x = (rightCenter_.x - leftCenter_.x) * coefficient + leftCenter_.x;
backgroundOpacity_ = TOGGLE_BTN_UNSELECTED_OPA + (OPA_OPAQUE - TOGGLE_BTN_UNSELECTED_OPA) * coefficient;
bgColor_ = Color::GetMixColor(Color::GetColorFromRGB(DEFAULT_BG_RED, DEFAULT_BG_GREEN, DEFAULT_BG_BLUE),
Color::White(), OPA_OPAQUE * coefficient);
bgColor_ = Color::GetMixColor(selectedStateColor_, Color::White(), OPA_OPAQUE * coefficient);
} else {
currentCenter_.y = leftCenter_.y;
currentCenter_.x = rightCenter_.x - (rightCenter_.x - leftCenter_.x) * coefficient;
backgroundOpacity_ = OPA_OPAQUE - (OPA_OPAQUE - TOGGLE_BTN_UNSELECTED_OPA) * coefficient;
bgColor_ = Color::GetMixColor(Color::GetColorFromRGB(DEFAULT_BG_RED, DEFAULT_BG_GREEN, DEFAULT_BG_BLUE),
Color::White(), OPA_OPAQUE * (1 - coefficient));
bgColor_ = Color::GetMixColor(selectedStateColor_, Color::White(), OPA_OPAQUE * (1 - coefficient));
}
Invalidate();
}
......@@ -137,7 +133,7 @@ void UIToggleButton::Callback(UIView* view)
void UIToggleButton::OnStop(UIView& view)
{
if (state_ == SELECTED) {
bgColor_ = Color::GetColorFromRGB(DEFAULT_BG_RED, DEFAULT_BG_GREEN, DEFAULT_BG_BLUE);
bgColor_ = selectedStateColor_;
} else {
bgColor_ = Color::White();
}
......
......@@ -223,6 +223,25 @@ public:
*/
void SetState(UICheckBoxState state, bool needAnimater = false);
/**
* @brief Sets the selected state color for this check box.
*
* @param color Indicates the selected state color of this check box.
*
* @since 5.0
* @version 3.0
*/
void SetSelectedStateColor(ColorType color);
/**
* @brief Obtains the selected state color of this check box.
*
* @return Returns the selected state color of this check box
* @since 5.0
* @version 3.0
*/
ColorType GetSelectedStateColor() const;
protected:
void ReverseState();
virtual void CalculateSize();
......@@ -244,9 +263,6 @@ protected:
static constexpr int16_t DEFAULT_HOT_WIDTH = 46;
static constexpr int16_t DEFAULT_HOT_HEIGHT = 46;
static constexpr int16_t DEFAULT_BORDER_WIDTH = 22;
static constexpr uint8_t DEFAULT_BG_RED = 31;
static constexpr uint8_t DEFAULT_BG_GREEN = 113;
static constexpr uint8_t DEFAULT_BG_BLUE = 255;
UICheckBoxState state_;
OnChangeListener* onStateChangeListener_;
......@@ -259,6 +275,7 @@ protected:
Animator checkBoxAnimator_;
uint32_t runTime_;
#endif
ColorType selectedStateColor_;
};
} // namespace OHOS
#endif // GRAPHIC_LITE_UI_CHECKBOX_H
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册