提交 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 ...@@ -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_DX = 0.2; // middle point: y-cordinate offset
constexpr float DEFAULT_COEFFICIENT_MID_DY = 0.38; // 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 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 #if DEFAULT_ANIMATION
constexpr int16_t DEFAULT_ANIMATOR_TIME = 200; constexpr int16_t DEFAULT_ANIMATOR_TIME = 200;
constexpr float BEZIER_CONTROL_POINT_X_1 = 0.33; constexpr float BEZIER_CONTROL_POINT_X_1 = 0.33;
...@@ -52,6 +55,7 @@ UICheckBox::UICheckBox() ...@@ -52,6 +55,7 @@ UICheckBox::UICheckBox()
runTime_ = 0; runTime_ = 0;
checkBoxAnimator_ = Animator(this, this, DEFAULT_ANIMATOR_TIME, false); checkBoxAnimator_ = Animator(this, this, DEFAULT_ANIMATOR_TIME, false);
#endif #endif
selectedStateColor_ = Color::GetColorFromRGB(DEFAULT_BG_RED, DEFAULT_BG_GREEN, DEFAULT_BG_BLUE);
} }
void UICheckBox::SetState(UICheckBoxState state, bool needAnimater) void UICheckBox::SetState(UICheckBoxState state, bool needAnimater)
...@@ -130,7 +134,7 @@ void UICheckBox::SelectedStateSoftwareDrawing(BufferInfo& gfxDstBuffer, ...@@ -130,7 +134,7 @@ void UICheckBox::SelectedStateSoftwareDrawing(BufferInfo& gfxDstBuffer,
} }
Style styleSelect = StyleDefault::GetBackgroundTransparentStyle(); Style styleSelect = StyleDefault::GetBackgroundTransparentStyle();
styleSelect.borderRadius_ = borderRadius; styleSelect.borderRadius_ = borderRadius;
styleSelect.bgColor_ = Color::GetColorFromRGB(DEFAULT_BG_RED, DEFAULT_BG_GREEN, DEFAULT_BG_BLUE); styleSelect.bgColor_ = selectedStateColor_;
styleSelect.bgOpa_ = backgroundOpacity_; styleSelect.bgOpa_ = backgroundOpacity_;
BaseGfxEngine::GetInstance()->DrawRect(gfxDstBuffer, rect, trunc, styleSelect, opaScale_); BaseGfxEngine::GetInstance()->DrawRect(gfxDstBuffer, rect, trunc, styleSelect, opaScale_);
int16_t dx = borderWidth_ * DEFAULT_COEFFICIENT_START_DX; int16_t dx = borderWidth_ * DEFAULT_COEFFICIENT_START_DX;
...@@ -255,4 +259,14 @@ void UICheckBox::OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) ...@@ -255,4 +259,14 @@ void UICheckBox::OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea)
#endif #endif
} }
} }
void UICheckBox::SetSelectedStateColor(ColorType color)
{
selectedStateColor_ = color;
}
ColorType UICheckBox::GetSelectedStateColor() const
{
return selectedStateColor_;
}
} // namespace OHOS } // namespace OHOS
...@@ -106,7 +106,7 @@ void UIRadioButton::OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea ...@@ -106,7 +106,7 @@ void UIRadioButton::OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea
BaseGfxEngine::GetInstance()->DrawArc(gfxDstBuffer, arcInfoBig, trunc, style, 0xa8, CapType::CAP_NONE); BaseGfxEngine::GetInstance()->DrawArc(gfxDstBuffer, arcInfoBig, trunc, style, 0xa8, CapType::CAP_NONE);
} }
style.lineWidth_ = arcInfoBig.radius; style.lineWidth_ = arcInfoBig.radius;
style.lineColor_ = Color::GetColorFromRGB(0x1F, 0x71, 0xFF); style.lineColor_ = selectedStateColor_;
BaseGfxEngine::GetInstance()->DrawArc(gfxDstBuffer, arcInfoBig, trunc, style, backgroundOpacity_, BaseGfxEngine::GetInstance()->DrawArc(gfxDstBuffer, arcInfoBig, trunc, style, backgroundOpacity_,
CapType::CAP_NONE); CapType::CAP_NONE);
style.lineWidth_ = arcInfoSmall.radius; style.lineWidth_ = arcInfoSmall.radius;
......
...@@ -75,14 +75,12 @@ void UIToggleButton::CalculateSize() ...@@ -75,14 +75,12 @@ void UIToggleButton::CalculateSize()
if (checkBoxAnimator_.GetState() != Animator::START) { if (checkBoxAnimator_.GetState() != Animator::START) {
currentCenter_ = (state_ == SELECTED) ? rightCenter_ : leftCenter_; currentCenter_ = (state_ == SELECTED) ? rightCenter_ : leftCenter_;
backgroundOpacity_ = (state_ == SELECTED) ? OPA_OPAQUE : TOGGLE_BTN_UNSELECTED_OPA; backgroundOpacity_ = (state_ == SELECTED) ? OPA_OPAQUE : TOGGLE_BTN_UNSELECTED_OPA;
bgColor_ = (state_ == SELECTED) ? Color::GetColorFromRGB(DEFAULT_BG_RED, DEFAULT_BG_GREEN, DEFAULT_BG_BLUE) : bgColor_ = (state_ == SELECTED) ? selectedStateColor_ : Color::White();
Color::White();
} }
#else #else
currentCenter_ = (state_ == SELECTED) ? rightCenter_ : leftCenter_; currentCenter_ = (state_ == SELECTED) ? rightCenter_ : leftCenter_;
backgroundOpacity_ = (state_ == SELECTED) ? OPA_OPAQUE : TOGGLE_BTN_UNSELECTED_OPA; backgroundOpacity_ = (state_ == SELECTED) ? OPA_OPAQUE : TOGGLE_BTN_UNSELECTED_OPA;
bgColor_ = (state_ == SELECTED) ? Color::GetColorFromRGB(DEFAULT_BG_RED, DEFAULT_BG_GREEN, DEFAULT_BG_BLUE) : bgColor_ = (state_ == SELECTED) ? selectedStateColor_ : Color::White();
Color::White();
#endif #endif
rectMid_.SetRect(x, y, x + rectWidth_, y + (corner_ << 1) + 1); rectMid_.SetRect(x, y, x + rectWidth_, y + (corner_ << 1) + 1);
} }
...@@ -122,14 +120,12 @@ void UIToggleButton::Callback(UIView* view) ...@@ -122,14 +120,12 @@ void UIToggleButton::Callback(UIView* view)
currentCenter_.y = rightCenter_.y; currentCenter_.y = rightCenter_.y;
currentCenter_.x = (rightCenter_.x - leftCenter_.x) * coefficient + leftCenter_.x; currentCenter_.x = (rightCenter_.x - leftCenter_.x) * coefficient + leftCenter_.x;
backgroundOpacity_ = TOGGLE_BTN_UNSELECTED_OPA + (OPA_OPAQUE - TOGGLE_BTN_UNSELECTED_OPA) * coefficient; 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), bgColor_ = Color::GetMixColor(selectedStateColor_, Color::White(), OPA_OPAQUE * coefficient);
Color::White(), OPA_OPAQUE * coefficient);
} else { } else {
currentCenter_.y = leftCenter_.y; currentCenter_.y = leftCenter_.y;
currentCenter_.x = rightCenter_.x - (rightCenter_.x - leftCenter_.x) * coefficient; currentCenter_.x = rightCenter_.x - (rightCenter_.x - leftCenter_.x) * coefficient;
backgroundOpacity_ = OPA_OPAQUE - (OPA_OPAQUE - TOGGLE_BTN_UNSELECTED_OPA) * 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), bgColor_ = Color::GetMixColor(selectedStateColor_, Color::White(), OPA_OPAQUE * (1 - coefficient));
Color::White(), OPA_OPAQUE * (1 - coefficient));
} }
Invalidate(); Invalidate();
} }
...@@ -137,7 +133,7 @@ void UIToggleButton::Callback(UIView* view) ...@@ -137,7 +133,7 @@ void UIToggleButton::Callback(UIView* view)
void UIToggleButton::OnStop(UIView& view) void UIToggleButton::OnStop(UIView& view)
{ {
if (state_ == SELECTED) { if (state_ == SELECTED) {
bgColor_ = Color::GetColorFromRGB(DEFAULT_BG_RED, DEFAULT_BG_GREEN, DEFAULT_BG_BLUE); bgColor_ = selectedStateColor_;
} else { } else {
bgColor_ = Color::White(); bgColor_ = Color::White();
} }
......
...@@ -223,6 +223,25 @@ public: ...@@ -223,6 +223,25 @@ public:
*/ */
void SetState(UICheckBoxState state, bool needAnimater = false); 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: protected:
void ReverseState(); void ReverseState();
virtual void CalculateSize(); virtual void CalculateSize();
...@@ -244,9 +263,6 @@ protected: ...@@ -244,9 +263,6 @@ protected:
static constexpr int16_t DEFAULT_HOT_WIDTH = 46; static constexpr int16_t DEFAULT_HOT_WIDTH = 46;
static constexpr int16_t DEFAULT_HOT_HEIGHT = 46; static constexpr int16_t DEFAULT_HOT_HEIGHT = 46;
static constexpr int16_t DEFAULT_BORDER_WIDTH = 22; 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_; UICheckBoxState state_;
OnChangeListener* onStateChangeListener_; OnChangeListener* onStateChangeListener_;
...@@ -259,6 +275,7 @@ protected: ...@@ -259,6 +275,7 @@ protected:
Animator checkBoxAnimator_; Animator checkBoxAnimator_;
uint32_t runTime_; uint32_t runTime_;
#endif #endif
ColorType selectedStateColor_;
}; };
} // namespace OHOS } // namespace OHOS
#endif // GRAPHIC_LITE_UI_CHECKBOX_H #endif // GRAPHIC_LITE_UI_CHECKBOX_H
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册