From 4bcaa490e42a988978121c5edffc50cde33c758c Mon Sep 17 00:00:00 2001 From: wangtiantian Date: Tue, 27 Jul 2021 10:21:30 +0800 Subject: [PATCH] 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: wangtiantian --- frameworks/components/ui_checkbox.cpp | 16 ++++++++++++++- frameworks/components/ui_radio_button.cpp | 2 +- frameworks/components/ui_toggle_button.cpp | 14 +++++-------- interfaces/kits/components/ui_checkbox.h | 23 +++++++++++++++++++--- 4 files changed, 41 insertions(+), 14 deletions(-) diff --git a/frameworks/components/ui_checkbox.cpp b/frameworks/components/ui_checkbox.cpp index 8555ac8..fb93119 100755 --- a/frameworks/components/ui_checkbox.cpp +++ b/frameworks/components/ui_checkbox.cpp @@ -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 diff --git a/frameworks/components/ui_radio_button.cpp b/frameworks/components/ui_radio_button.cpp index 4ecc4b5..698ae18 100755 --- a/frameworks/components/ui_radio_button.cpp +++ b/frameworks/components/ui_radio_button.cpp @@ -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; diff --git a/frameworks/components/ui_toggle_button.cpp b/frameworks/components/ui_toggle_button.cpp index bbbf0dc..4b86d2b 100755 --- a/frameworks/components/ui_toggle_button.cpp +++ b/frameworks/components/ui_toggle_button.cpp @@ -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(); } diff --git a/interfaces/kits/components/ui_checkbox.h b/interfaces/kits/components/ui_checkbox.h index 56737ff..d1e58a7 100755 --- a/interfaces/kits/components/ui_checkbox.h +++ b/interfaces/kits/components/ui_checkbox.h @@ -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 -- GitLab