提交 04ac2c0e 编写于 作者: N niulihua 提交者: Gitee

!23 support checkbox software drawing

Merge pull request !23 from wangtiantian/master
...@@ -16,13 +16,16 @@ ...@@ -16,13 +16,16 @@
#include "common/image.h" #include "common/image.h"
#include "components/ui_checkbox.h" #include "components/ui_checkbox.h"
#include "default_resource/check_box_res.h" #include "default_resource/check_box_res.h"
#include "draw/draw_arc.h"
#include "draw/draw_image.h" #include "draw/draw_image.h"
#include "draw/draw_line.h"
#include "draw/draw_rect.h" #include "draw/draw_rect.h"
#include "imgdecode/cache_manager.h" #include "imgdecode/cache_manager.h"
namespace OHOS { namespace OHOS {
UICheckBox::UICheckBox() UICheckBox::UICheckBox()
: state_(UNSELECTED), onStateChangeListener_(nullptr) : state_(UNSELECTED), onStateChangeListener_(nullptr), width_(DEFAULT_HOT_WIDTH), height_(DEFAULT_HOT_HEIGHT),
borderWidth_(DEFAULT_BORDER_WIDTH)
{ {
touchable_ = true; touchable_ = true;
style_ = &(StyleDefault::GetBackgroundTransparentStyle()); style_ = &(StyleDefault::GetBackgroundTransparentStyle());
...@@ -72,24 +75,107 @@ void UICheckBox::SetImages(const ImageInfo* selectedImageSrc, const ImageInfo* u ...@@ -72,24 +75,107 @@ void UICheckBox::SetImages(const ImageInfo* selectedImageSrc, const ImageInfo* u
image_[UNSELECTED].SetSrc(unselectedImageSrc); image_[UNSELECTED].SetSrc(unselectedImageSrc);
} }
void UICheckBox::OnDraw(const Rect& invalidatedArea) void UICheckBox::CalculateSize()
{
int16_t width = GetWidth();
int16_t height = GetHeight();
if ((width_ == width) && (height_ == height)) {
return;
}
width_ = width;
height_ = height;
int16_t minValue = (width_ > height_) ? height_ : width_;
borderWidth_ = DEFAULT_BORDER_WIDTH * minValue / DEFAULT_HOT_WIDTH;
}
void UICheckBox::SelectedStateSoftwareDrawing(Rect rect, Rect trunc, int16_t borderRadius, int16_t rectLineWidth)
{ {
ImageHeader header = {0}; Style styleSelect = StyleDefault::GetBackgroundTransparentStyle();
image_[state_].GetHeader(header); styleSelect.borderRadius_ = borderRadius;
int16_t imgWidth = header.width; styleSelect.bgColor_ = Color::GetColorFromRGB(0x1F, 0x71, 0xFF);
int16_t imgHeight = header.height; styleSelect.bgOpa_ = OPA_OPAQUE;
Rect coords = GetContentRect(); Rect contentRect = GetContentRect();
coords.SetWidth(imgWidth); bool isIntersect = trunc.Intersect(trunc, contentRect);
coords.SetHeight(imgHeight); if (isIntersect) {
DrawRect::Draw(GetRect(), invalidatedArea, *style_, opaScale_); DrawRect::Draw(rect, trunc, styleSelect, opaScale_);
}
int16_t dx = borderWidth_ * 0.22; // 0.22 : coefficient,
int16_t dy = borderWidth_ * 0.5; // 0.5 : coefficient,
Point start = { static_cast<int16_t>(rect.GetX() + dx), static_cast<int16_t>(rect.GetY() + dy) };
dx = borderWidth_ * 0.2; // 0.2 : coefficient
Point mid = { static_cast<int16_t>(start.x + dx), static_cast<int16_t>(start.y + dx) };
dx = borderWidth_ * 0.38; // 0.38 : coefficient
Point end = { static_cast<int16_t>(mid.x + dx), static_cast<int16_t>(mid.y - dx) };
const int16_t half = 2; // 2 :half
ArcInfo arcInfoLeft = {
start, { 0, 0 }, static_cast<uint16_t>(rectLineWidth), SEMICIRCLE_IN_DEGREE + QUARTER_IN_DEGREE / half,
QUARTER_IN_DEGREE / half, nullptr
};
ArcInfo arcInfoMid = {
mid, { 0, 0 }, static_cast<uint16_t>(rectLineWidth), SEMICIRCLE_IN_DEGREE - QUARTER_IN_DEGREE / half,
SEMICIRCLE_IN_DEGREE + QUARTER_IN_DEGREE / half, nullptr
};
ArcInfo arcInfoRight = {
end, { 0, 0 }, static_cast<uint16_t>(rectLineWidth), CIRCLE_IN_DEGREE - QUARTER_IN_DEGREE / half,
SEMICIRCLE_IN_DEGREE - QUARTER_IN_DEGREE / half, nullptr
};
styleSelect.lineColor_ = Color::White();
if (isIntersect) {
DrawArc::GetInstance()->Draw(arcInfoLeft, trunc, styleSelect, OPA_OPAQUE, CapType::CAP_NONE);
DrawLine::Draw(start, mid, trunc, rectLineWidth * 2, Color::White(), opaScale_); // 2 : double
DrawArc::GetInstance()->Draw(arcInfoMid, trunc, styleSelect, OPA_OPAQUE, CapType::CAP_NONE);
DrawLine::Draw(mid, end, trunc, rectLineWidth * 2, Color::White(), opaScale_); // 2 : double
DrawArc::GetInstance()->Draw(arcInfoRight, trunc, styleSelect, OPA_OPAQUE, CapType::CAP_NONE);
}
}
int16_t offsetLeft = (GetWidth() - imgWidth) / 2; // 2 : half void UICheckBox::OnDraw(const Rect& invalidatedArea)
int16_t offsetTop = (GetHeight() - imgHeight) / 2; // 2 : half {
coords.SetX(coords.GetX() + offsetLeft);
coords.SetY(coords.GetY() + offsetTop);
Rect trunc = invalidatedArea; Rect trunc = invalidatedArea;
if (trunc.Intersect(trunc, coords)) { if ((image_[SELECTED].GetSrcType() != IMG_SRC_UNKNOWN) && (image_[UNSELECTED].GetSrcType() != IMG_SRC_UNKNOWN)) {
image_[state_].DrawImage(coords, trunc, *style_, opaScale_); ImageHeader header = {0};
image_[state_].GetHeader(header);
int16_t imgWidth = header.width;
int16_t imgHeight = header.height;
Rect coords = GetContentRect();
coords.SetWidth(imgWidth);
coords.SetHeight(imgHeight);
DrawRect::Draw(GetRect(), invalidatedArea, *style_, opaScale_);
int16_t offsetLeft = (GetWidth() - imgWidth) / 2; // 2 : half
int16_t offsetTop = (GetHeight() - imgHeight) / 2; // 2 : half
coords.SetX(coords.GetX() + offsetLeft);
coords.SetY(coords.GetY() + offsetTop);
if (trunc.Intersect(trunc, coords)) {
image_[state_].DrawImage(coords, trunc, *style_, opaScale_);
}
} else {
CalculateSize();
int16_t rectLineWidth = borderWidth_ / DEFAULT_BORDER_WIDTH;
int16_t borderRadius = rectLineWidth * 4; // 4 : coefficient
DrawRect::Draw(GetRect(), invalidatedArea, *style_, opaScale_);
Rect contentRect = GetContentRect();
int16_t x = contentRect.GetX() + (width_ - borderWidth_) / 2; // 2: half
int16_t y = contentRect.GetY() + (height_ - borderWidth_) / 2; // 2: half
Rect rect(x, y, x + borderWidth_, y + borderWidth_);
switch (state_) {
case SELECTED: {
SelectedStateSoftwareDrawing(rect, trunc, borderRadius, rectLineWidth);
break;
}
case UNSELECTED: {
Style styleUnSelect = StyleDefault::GetBackgroundTransparentStyle();
styleUnSelect.borderWidth_ = rectLineWidth;
styleUnSelect.borderRadius_ = borderRadius;
styleUnSelect.borderColor_ = Color::White();
styleUnSelect.borderOpa_ = 0xa8; // 0xa8: opacity
if (trunc.Intersect(trunc, contentRect)) {
DrawRect::Draw(rect, trunc, styleUnSelect, opaScale_);
}
break;
}
default:
break;
}
} }
} }
} // namespace OHOS } // namespace OHOS
...@@ -25,8 +25,7 @@ ...@@ -25,8 +25,7 @@
#include "securec.h" #include "securec.h"
namespace OHOS { namespace OHOS {
UIRadioButton::UIRadioButton() : name_(nullptr), width_(DEFAULT_HOT_WIDTH), height_(DEFAULT_HOT_HEIGHT), UIRadioButton::UIRadioButton() : name_(nullptr), radiusBig_(DEFAULT_RADIUS_BIG), radiusSmall_(DEFAULT_RADIUS_SMALL),
radiusBig_(DEFAULT_RADIUS_BIG), radiusSmall_(DEFAULT_RADIUS_SMALL),
lineWidth_(DEFAULT_LINE_WIDTH) lineWidth_(DEFAULT_LINE_WIDTH)
{ {
image_[UNSELECTED].SetSrc(""); image_[UNSELECTED].SetSrc("");
...@@ -34,8 +33,7 @@ UIRadioButton::UIRadioButton() : name_(nullptr), width_(DEFAULT_HOT_WIDTH), heig ...@@ -34,8 +33,7 @@ UIRadioButton::UIRadioButton() : name_(nullptr), width_(DEFAULT_HOT_WIDTH), heig
Resize(width_, height_); Resize(width_, height_);
} }
UIRadioButton::UIRadioButton(const char* name) : name_(nullptr), width_(DEFAULT_HOT_WIDTH), UIRadioButton::UIRadioButton(const char* name) : name_(nullptr), radiusBig_(DEFAULT_RADIUS_BIG),
height_(DEFAULT_HOT_HEIGHT), radiusBig_(DEFAULT_RADIUS_BIG),
radiusSmall_(DEFAULT_RADIUS_SMALL), lineWidth_(DEFAULT_LINE_WIDTH) radiusSmall_(DEFAULT_RADIUS_SMALL), lineWidth_(DEFAULT_LINE_WIDTH)
{ {
SetName(name); SetName(name);
......
...@@ -20,8 +20,7 @@ ...@@ -20,8 +20,7 @@
#include "imgdecode/cache_manager.h" #include "imgdecode/cache_manager.h"
namespace OHOS { namespace OHOS {
UIToggleButton::UIToggleButton() : width_(DEFAULT_HOT_WIDTH), height_(DEFAULT_HOT_WIDTH), UIToggleButton::UIToggleButton() : corner_(DEFAULT_CORNER_RADIUS), radius_(DEFAULT_CORNER_RADIUS - DEAFULT_RADIUS_DIFF),
corner_(DEFAULT_CORNER_RADIUS), radius_(DEFAULT_CORNER_RADIUS - DEAFULT_RADIUS_DIFF),
rectWidth_(DEFAULT_WIDTH) rectWidth_(DEFAULT_WIDTH)
{ {
image_[UNSELECTED].SetSrc(""); image_[UNSELECTED].SetSrc("");
......
...@@ -217,8 +217,17 @@ public: ...@@ -217,8 +217,17 @@ public:
protected: protected:
virtual void ReverseState(); virtual void ReverseState();
virtual void CalculateSize();
void SelectedStateSoftwareDrawing(Rect rect, Rect trunc, int16_t borderRadius, int16_t rectLineWidth);
static constexpr int16_t DEFAULT_HOT_WIDTH = 46;
static constexpr int16_t DEFAULT_HOT_HEIGHT = 46;
static constexpr int16_t DEFAULT_BORDER_WIDTH = 22;
UICheckBoxState state_; UICheckBoxState state_;
OnChangeListener* onStateChangeListener_; OnChangeListener* onStateChangeListener_;
int16_t width_;
int16_t height_;
int16_t borderWidth_;
Image image_[MAX_STATUS_NUM]; Image image_[MAX_STATUS_NUM];
}; };
} // namespace OHOS } // namespace OHOS
......
...@@ -132,22 +132,19 @@ public: ...@@ -132,22 +132,19 @@ public:
return name_; return name_;
} }
protected:
void CalculateSize() override;
private: private:
void FindRadioButtonAndChangeState(UIView* view); void FindRadioButtonAndChangeState(UIView* view);
static constexpr int16_t DEFAULT_HOT_WIDTH = 46;
static constexpr int16_t DEFAULT_HOT_HEIGHT = 46;
static constexpr int16_t DEFAULT_RADIUS_BIG = 11; static constexpr int16_t DEFAULT_RADIUS_BIG = 11;
static constexpr int16_t DEFAULT_RADIUS_SMALL = 6; static constexpr int16_t DEFAULT_RADIUS_SMALL = 6;
static constexpr int16_t DEFAULT_LINE_WIDTH = 1; static constexpr int16_t DEFAULT_LINE_WIDTH = 1;
char* name_; char* name_;
int16_t width_;
int16_t height_;
uint16_t radiusBig_; uint16_t radiusBig_;
uint16_t radiusSmall_; uint16_t radiusSmall_;
int16_t lineWidth_; int16_t lineWidth_;
void CalculateSize();
}; };
} // namespace OHOS } // namespace OHOS
#endif // GRAPHIC_LITE_UI_RADIO_BUTTON_H #endif // GRAPHIC_LITE_UI_RADIO_BUTTON_H
...@@ -105,9 +105,10 @@ public: ...@@ -105,9 +105,10 @@ public:
return (state_ != UNSELECTED); return (state_ != UNSELECTED);
} }
protected:
void CalculateSize() override;
private: private:
static constexpr int16_t DEFAULT_HOT_WIDTH = 46;
static constexpr int16_t DEFAULT_HOT_HEIGHT = 46;
static constexpr int16_t DEFAULT_WIDTH = 32; static constexpr int16_t DEFAULT_WIDTH = 32;
static constexpr int16_t DEFAULT_CORNER_RADIUS = 11; static constexpr int16_t DEFAULT_CORNER_RADIUS = 11;
static constexpr int16_t DEAFULT_RADIUS_DIFF = 2; static constexpr int16_t DEAFULT_RADIUS_DIFF = 2;
...@@ -116,13 +117,9 @@ private: ...@@ -116,13 +117,9 @@ private:
static constexpr uint8_t DEFAULT_BG_GREEN = 113; static constexpr uint8_t DEFAULT_BG_GREEN = 113;
static constexpr uint8_t DEFAULT_BG_BLUE = 255; static constexpr uint8_t DEFAULT_BG_BLUE = 255;
int16_t width_;
int16_t height_;
uint16_t corner_; uint16_t corner_;
uint16_t radius_; uint16_t radius_;
int16_t rectWidth_; int16_t rectWidth_;
void CalculateSize();
}; // class UIToggleButton }; // class UIToggleButton
} // namespace OHOS } // namespace OHOS
#endif // GRAPHIC_LITE_UI_TOGGLE_BUTTON_H #endif // GRAPHIC_LITE_UI_TOGGLE_BUTTON_H
...@@ -70,7 +70,8 @@ void UITestBUTTON::UIKit_Check_Box_Test_001() const ...@@ -70,7 +70,8 @@ void UITestBUTTON::UIKit_Check_Box_Test_001() const
checkbox2->SetPosition(100, 30); // 100: x-coordinate, 30: y-coordinate checkbox2->SetPosition(100, 30); // 100: x-coordinate, 30: y-coordinate
UICheckBox* checkbox3 = new UICheckBox(); UICheckBox* checkbox3 = new UICheckBox();
checkbox3->SetPosition(170, 30); // 170: x-coordinate, 30: y-coordinate checkbox3->SetImages("", "");
checkbox3->SetPosition(170, 30, 100, 100); // 170: x-coordinate, 30: y-coordinate, 100 : width, 100 : height
container_->Add(checkbox); container_->Add(checkbox);
container_->Add(checkbox2); container_->Add(checkbox2);
...@@ -668,4 +669,4 @@ void UITestBUTTON::UIKit_Button_Test_001() const ...@@ -668,4 +669,4 @@ void UITestBUTTON::UIKit_Button_Test_001() const
UIKit_BUTTON_TEST_002(container_, button); UIKit_BUTTON_TEST_002(container_, button);
} }
} }
} // namespace OHOS } // namespace OHOS
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册