draw_rect.cpp 30.5 KB
Newer Older
M
mamingshuai 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728
/*
 * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "draw/draw_rect.h"
#include "draw/draw_arc.h"
#include "draw/draw_utils.h"
#include "graphic_log.h"
#include "graphic_math.h"
#include "style.h"

namespace OHOS {
void DrawRect::Draw(const Rect& rect, const Rect& dirtyRect, const Style& style, OpacityType opaScale)
{
    if ((rect.GetWidth() <= 0) || (rect.GetHeight() <= 0)) {
        GRAPHIC_LOGD("DrawRect::Draw width or height is zero\n");
        return;
    }

    /**
     * no border
     *      radius = 0 (1/4)
     *      radius > 0 (2/4)
     *          rect width > rect height
     *              radius >= rect height / 2
     *              radius < rect height / 2
     *          rect width <= rect height
     *              radius >= rect width / 2
     *              radius < rect width / 2
     * have border
     *      radius = 0 (3/4)
     *      radius > 0 (4/4)
     *          radius < border width (4.1/4)
     *          radius = border width (4.2/4)
     *          radius > border width (4.3/4)
     *             rect width <= rect height
     *                  radius >= border width + rect height / 2
     *                  radius < border width + rect height / 2
     *             rect width > rect height
     *                  radius >= border width + rect height / 2
     *                  radius < border width + rect height / 2
     */
    if (style.borderWidth_ == 0) {
        if (style.borderRadius_ == 0) {
            /* no border no radius (1/4) */
            OpacityType opa = DrawUtils::GetMixOpacity(opaScale, style.bgOpa_);
            DrawUtils::GetInstance()->DrawColorArea(rect, dirtyRect, style.bgColor_, opa);
            return;
        } else {
            /* [2/4] no border with radius (2/4) */
            DrawRectRadiusWithoutBorder(rect, dirtyRect, style, opaScale);
        }
    } else {
        if (style.borderRadius_ == 0) {
            /* [3/4] border without radius (3/4) */
            DrawRectBorderWithoutRadius(rect, dirtyRect, style, opaScale);
        } else if (style.borderRadius_ < style.borderWidth_) {
            /* [4.1/4] radius < border width */
            DrawRectRadiusSmallThanBorder(rect, dirtyRect, style, opaScale);
        } else if (style.borderRadius_ == style.borderWidth_) {
            /* [4.2/4] radius = border width */
            DrawRectRadiusEqualBorder(rect, dirtyRect, style, opaScale);
        } else {
            /* [4.3/4] radius >= border width + rect height_or_width / 2 */
            DrawRectRadiusBiggerThanBorder(rect, dirtyRect, style, opaScale);
        }
    }
}

void DrawRect::DrawRectRadiusWithoutBorder(const Rect& rect, const Rect& dirtyRect, const Style& style,
                                           OpacityType opaScale)
{
    // 2 : half
    if ((rect.GetWidth() > rect.GetHeight()) && (style.borderRadius_ >= rect.GetHeight() / 2)) {
        DrawRectRadiusWithoutBorderCon1(rect, dirtyRect, style, opaScale);
    } else if ((rect.GetWidth() < rect.GetHeight()) && (style.borderRadius_ >= rect.GetWidth() / 2)) {
        DrawRectRadiusWithoutBorderCon2(rect, dirtyRect, style, opaScale);
    } else if ((rect.GetWidth() == rect.GetHeight()) && (style.borderRadius_ >= rect.GetWidth() / 2)) {
        DrawRectRadiusWithoutBorderCon3(rect, dirtyRect, style, opaScale);
    } else {
        DrawRectRadiusWithoutBorderCon4(rect, dirtyRect, style, opaScale);
    }
}

void DrawRect::DrawRectRadiusWithoutBorderCon1(const Rect& rect, const Rect& dirtyRect, const Style& style,
                                               OpacityType opaScale)
{
    int16_t radius = rect.GetHeight() / 2;
    int16_t col2X = rect.GetLeft() + radius - 1;
    int16_t col3X = rect.GetRight() - radius + 1;

    int16_t row1Y = rect.GetTop();
    int16_t row2Y = rect.GetTop() + radius - 1;
    int16_t row3Y = rect.GetBottom();

    Style arcStyle = style;
    arcStyle.lineWidth_ = radius;
    arcStyle.lineColor_ = style.bgColor_;
    arcStyle.lineOpa_ = style.bgOpa_;
    // draw left sector
    ArcInfo arcInfo;
    arcInfo.center = {col2X, row2Y};
    arcInfo.radius = radius;
    arcInfo.startAngle = SEMICIRCLE_IN_DEGREE;
    arcInfo.endAngle = CIRCLE_IN_DEGREE;
    arcInfo.imgPos = {0, 0};
    arcInfo.imgSrc = nullptr;
    DrawArc::GetInstance()->Draw(arcInfo, dirtyRect, arcStyle, opaScale, CapType::CAP_NONE);

    // draw right sector
    arcInfo.center = {col3X, row2Y};
    arcInfo.startAngle = 0;
    arcInfo.endAngle = SEMICIRCLE_IN_DEGREE;
    DrawArc::GetInstance()->Draw(arcInfo, dirtyRect, arcStyle, opaScale, CapType::CAP_NONE);

    // draw top rectangle
    Rect topRect(col2X, row1Y, col3X - 1, row2Y - 1);
    OpacityType opa = DrawUtils::GetMixOpacity(opaScale, style.bgOpa_);
    DrawUtils::GetInstance()->DrawColorArea(topRect, dirtyRect, style.bgColor_, opa);

    // draw bottom rectangle
    Rect bottomRect(col2X + 1, row2Y, col3X - 1, row3Y);
    DrawUtils::GetInstance()->DrawColorArea(bottomRect, dirtyRect, style.bgColor_, opa);
}

void DrawRect::DrawRectRadiusWithoutBorderCon2(const Rect& rect, const Rect& dirtyRect, const Style& style,
                                               OpacityType opaScale)
{
    int16_t radius = rect.GetWidth() / 2;
    int16_t col1X = rect.GetLeft();
    int16_t col2X = rect.GetLeft() + radius - 1;
    int16_t col3X = rect.GetRight();

    int16_t row2Y = rect.GetTop() + radius - 1;
    int16_t row3Y = rect.GetBottom() - radius + 1;

    Style arcStyle = style;
    arcStyle.lineWidth_ = radius;
    arcStyle.lineColor_ = style.bgColor_;
    arcStyle.lineOpa_ = style.bgOpa_;
    // draw top sector
    ArcInfo arcInfo;
    arcInfo.center = {col2X, row2Y};
    arcInfo.startAngle = THREE_QUARTER_IN_DEGREE;
    arcInfo.endAngle = QUARTER_IN_DEGREE;
    arcInfo.radius = radius;
    arcInfo.imgPos = {0, 0};
    arcInfo.imgSrc = nullptr;
    DrawArc::GetInstance()->Draw(arcInfo, dirtyRect, arcStyle, opaScale, CapType::CAP_NONE);

    // draw bottom sector
    arcInfo.center = {col2X, row3Y};
    arcInfo.startAngle = QUARTER_IN_DEGREE;
    arcInfo.endAngle = THREE_QUARTER_IN_DEGREE;
    DrawArc::GetInstance()->Draw(arcInfo, dirtyRect, arcStyle, opaScale, CapType::CAP_NONE);

    // draw middle rectangle
    Rect middleRect(col1X, row2Y + 1, col3X, row3Y - 1);
    OpacityType opa = DrawUtils::GetMixOpacity(opaScale, style.bgOpa_);
    DrawUtils::GetInstance()->DrawColorArea(middleRect, dirtyRect, style.bgColor_, opa);
}

void DrawRect::DrawRectRadiusWithoutBorderCon3(const Rect& rect, const Rect& dirtyRect, const Style& style,
                                               OpacityType opaScale)
{
    int16_t radius = rect.GetWidth() / 2;
    int16_t col1X = rect.GetLeft() + radius - 1;
    int16_t row1Y = rect.GetTop() + radius - 1;

    Style arcStyle = style;
    arcStyle.lineWidth_ = radius;
    arcStyle.lineColor_ = style.bgColor_;
    arcStyle.lineOpa_ = style.bgOpa_;
    // draw circle
    ArcInfo arcInfo;
    arcInfo.center = {col1X, row1Y};
    arcInfo.startAngle = 0;
    arcInfo.endAngle = CIRCLE_IN_DEGREE;
    arcInfo.radius = radius;
    arcInfo.imgPos = {0, 0};
    arcInfo.imgSrc = nullptr;
    DrawArc::GetInstance()->Draw(arcInfo, dirtyRect, arcStyle, opaScale, CapType::CAP_NONE);
}

void DrawRect::DrawRectRadiusWithoutBorderCon4(const Rect& rect, const Rect& dirtyRect, const Style& style,
                                               OpacityType opaScale)
{
    int16_t radius = style.borderRadius_;
    int16_t col1X = rect.GetLeft();
    int16_t col2X = rect.GetLeft() + radius - 1;
    int16_t col3X = rect.GetRight() - radius + 1;
    int16_t col4X = rect.GetRight();

    int16_t row1Y = rect.GetTop();
    int16_t row2Y = rect.GetTop() + radius - 1;
    int16_t row3Y = rect.GetBottom() - radius + 1;
    int16_t row4Y = rect.GetBottom();

    OpacityType opa = DrawUtils::GetMixOpacity(opaScale, style.bgOpa_);
    // draw top rectangle
    Rect topRect(col2X, row1Y, col3X - 1, row2Y);
    DrawUtils::GetInstance()->DrawColorArea(topRect, dirtyRect, style.bgColor_, opa);

    // draw middle rectangle
    Rect middleRect(col1X, row2Y + 1, col4X, row3Y - 1);
    DrawUtils::GetInstance()->DrawColorArea(middleRect, dirtyRect, style.bgColor_, opa);

    // draw bottom rectangle
    Rect bottomRect(col2X + 1, row3Y, col3X - 1, row4Y);
    DrawUtils::GetInstance()->DrawColorArea(bottomRect, dirtyRect, style.bgColor_, opa);

    Style arcStyle = style;
    arcStyle.lineWidth_ = radius;
    arcStyle.lineColor_ = style.bgColor_;
    arcStyle.lineOpa_ = style.bgOpa_;
    // top left sector
    ArcInfo arcInfo;
    arcInfo.center = {col2X, row2Y};
    arcInfo.startAngle = THREE_QUARTER_IN_DEGREE;
    arcInfo.endAngle = CIRCLE_IN_DEGREE;
    arcInfo.radius = radius;
    arcInfo.imgPos = {0, 0};
    arcInfo.imgSrc = nullptr;
    DrawArc::GetInstance()->Draw(arcInfo, dirtyRect, arcStyle, opaScale, CapType::CAP_NONE);

    // top right sector
    arcInfo.center = {col3X, row2Y};
    arcInfo.startAngle = 0;
    arcInfo.endAngle = QUARTER_IN_DEGREE;
    DrawArc::GetInstance()->Draw(arcInfo, dirtyRect, arcStyle, opaScale, CapType::CAP_NONE);

    // bottom left sector
    arcInfo.center = {col2X, row3Y};
    arcInfo.startAngle = SEMICIRCLE_IN_DEGREE;
    arcInfo.endAngle = THREE_QUARTER_IN_DEGREE;
    DrawArc::GetInstance()->Draw(arcInfo, dirtyRect, arcStyle, opaScale, CapType::CAP_NONE);

    // bottom right sector
    arcInfo.center = {col3X, row3Y};
    arcInfo.startAngle = QUARTER_IN_DEGREE;
    arcInfo.endAngle = SEMICIRCLE_IN_DEGREE;
    DrawArc::GetInstance()->Draw(arcInfo, dirtyRect, arcStyle, opaScale, CapType::CAP_NONE);
}

void DrawRect::DrawRectBorderWithoutRadius(const Rect& rect, const Rect& dirtyRect, const Style& style,
                                           OpacityType opaScale)
{
    int16_t col1X = rect.GetLeft();
    int16_t col2X = rect.GetLeft() + style.borderWidth_ - 1;
    int16_t col3X = rect.GetRight() - style.borderWidth_ + 1;
    int16_t col4X = rect.GetRight();

    int16_t row1Y = rect.GetTop();
    int16_t row2Y = rect.GetTop() + style.borderWidth_ - 1;
    int16_t row3Y = rect.GetBottom() - style.borderWidth_ + 1;
    int16_t row4Y = rect.GetBottom();

    OpacityType opa = DrawUtils::GetMixOpacity(opaScale, style.borderOpa_);
    // draw top border
    Rect topRect(col1X, row1Y, col4X, row2Y);
    DrawUtils::GetInstance()->DrawColorArea(topRect, dirtyRect, style.borderColor_, opa);

    // draw left border
    Rect leftRect(col1X, row2Y + 1, col2X, row3Y - 1);
    DrawUtils::GetInstance()->DrawColorArea(leftRect, dirtyRect, style.borderColor_, opa);

    OpacityType opaBg = DrawUtils::GetMixOpacity(opaScale, style.bgOpa_);
    // draw middle rectangle
    Rect middleRect(col2X + 1, row2Y + 1, col3X - 1, row3Y - 1);
    DrawUtils::GetInstance()->DrawColorArea(middleRect, dirtyRect, style.bgColor_, opaBg);

    // draw right border
    Rect rightRect(col3X, row2Y + 1, col4X, row3Y - 1);
    DrawUtils::GetInstance()->DrawColorArea(rightRect, dirtyRect, style.borderColor_, opa);

    // draw bottom border
    Rect bottomRect(col1X, row3Y, col4X, row4Y);
    DrawUtils::GetInstance()->DrawColorArea(bottomRect, dirtyRect, style.borderColor_, opa);
}

void DrawRect::DrawRectRadiusEqualBorder(const Rect& rect, const Rect& dirtyRect, const Style& style,
                                         OpacityType opaScale)
{
    int16_t col1X = rect.GetLeft();
    int16_t col2X = rect.GetLeft() + style.borderRadius_ - 1;
    int16_t col3X = rect.GetRight() - style.borderRadius_ + 1;
    int16_t col4X = rect.GetRight();

    int16_t row1Y = rect.GetTop();
    int16_t row2Y = rect.GetTop() + style.borderRadius_ - 1;
    int16_t row3Y = rect.GetBottom() - style.borderRadius_ + 1;
    int16_t row4Y = rect.GetBottom();

    Style arcStyle = style;
    arcStyle.lineWidth_ = style.borderWidth_;
    arcStyle.lineColor_ = style.borderColor_;
    arcStyle.lineOpa_ = style.borderOpa_;
    // draw top left sector in border
    ArcInfo arcInfo;
    arcInfo.center = {col2X, row2Y};
    arcInfo.startAngle = THREE_QUARTER_IN_DEGREE;
    arcInfo.endAngle = CIRCLE_IN_DEGREE;
    arcInfo.radius = style.borderRadius_;
    arcInfo.imgPos = {0, 0};
    arcInfo.imgSrc = nullptr;
    DrawArc::GetInstance()->Draw(arcInfo, dirtyRect, arcStyle, opaScale, CapType::CAP_NONE);

    // draw top right sector in border
    arcInfo.center = {col3X, row2Y};
    arcInfo.startAngle = 0;
    arcInfo.endAngle = QUARTER_IN_DEGREE;
    DrawArc::GetInstance()->Draw(arcInfo, dirtyRect, arcStyle, opaScale, CapType::CAP_NONE);

    // draw bottom left sector in border
    arcInfo.center = {col2X, row3Y};
    arcInfo.startAngle = SEMICIRCLE_IN_DEGREE;
    arcInfo.endAngle = THREE_QUARTER_IN_DEGREE;
    DrawArc::GetInstance()->Draw(arcInfo, dirtyRect, arcStyle, opaScale, CapType::CAP_NONE);

    // draw bottom right sector in border
    arcInfo.center = {col3X, row3Y};
    arcInfo.startAngle = QUARTER_IN_DEGREE;
    arcInfo.endAngle = SEMICIRCLE_IN_DEGREE;
    DrawArc::GetInstance()->Draw(arcInfo, dirtyRect, arcStyle, opaScale, CapType::CAP_NONE);

    OpacityType opa = DrawUtils::GetMixOpacity(opaScale, style.borderOpa_);
    // draw top rectangle in border
    Rect topRect(col2X, row1Y, col3X - 1, row2Y);
    DrawUtils::GetInstance()->DrawColorArea(topRect, dirtyRect, style.borderColor_, opa);

    // draw left rectangle in border
    Rect leftRect(col1X, row2Y + 1, col2X, row3Y - 1);
    DrawUtils::GetInstance()->DrawColorArea(leftRect, dirtyRect, style.borderColor_, opa);

    OpacityType opaBg = DrawUtils::GetMixOpacity(opaScale, style.bgOpa_);
    // draw middle rectangle
    Rect middleRect(col2X + 1, row2Y + 1, col3X - 1, row3Y - 1);
    DrawUtils::GetInstance()->DrawColorArea(middleRect, dirtyRect, style.bgColor_, opaBg);

    // draw right rectangle in border
    Rect rightRect(col3X, row2Y + 1, col4X, row3Y - 1);
    DrawUtils::GetInstance()->DrawColorArea(rightRect, dirtyRect, style.borderColor_, opa);

    // draw bottom rectangle in border
    Rect bottomRect(col2X + 1, row3Y, col3X - 1, row4Y);
    DrawUtils::GetInstance()->DrawColorArea(bottomRect, dirtyRect, style.borderColor_, opa);
}

void DrawRect::DrawRectRadiusSmallThanBorder(const Rect& rect, const Rect& dirtyRect, const Style& style,
                                             OpacityType opaScale)
{
    int16_t radiusCol1X = rect.GetLeft();
    int16_t radiusCol2X = rect.GetLeft() + style.borderRadius_ - 1;
    int16_t radiusCol3X = rect.GetRight() - style.borderRadius_ + 1;
    int16_t radiusCol4X = rect.GetRight();

    int16_t radiusRow1Y = rect.GetTop();
    int16_t radiusRow2Y = rect.GetTop() + style.borderRadius_ - 1;
    int16_t radiusRow3Y = rect.GetBottom() - style.borderRadius_ + 1;
    int16_t radiusRow4Y = rect.GetBottom();

    int16_t rectCol1X = radiusCol1X;
    int16_t rectCol2X = rect.GetLeft() + style.borderWidth_ - 1;
    int16_t rectCol3X = rect.GetRight() - style.borderWidth_ + 1;
    int16_t rectCol4X = radiusCol4X;

    int16_t rectRow1Y = radiusRow2Y;
    int16_t rectRow2Y = rect.GetTop() + style.borderWidth_ - 1;
    int16_t rectRow3Y = rect.GetBottom() - style.borderWidth_ + 1;

    Style arcStyle = style;
    arcStyle.lineWidth_ = style.borderWidth_;
    arcStyle.lineColor_ = style.borderColor_;
    arcStyle.lineOpa_ = style.borderOpa_;
    // draw top left sector in border
    ArcInfo arcInfo;
    arcInfo.center = {radiusCol2X, radiusRow2Y};
    arcInfo.startAngle = THREE_QUARTER_IN_DEGREE;
    arcInfo.endAngle = CIRCLE_IN_DEGREE;
    arcInfo.radius = style.borderRadius_;
    arcInfo.imgPos = {0, 0};
    arcInfo.imgSrc = nullptr;
    DrawArc::GetInstance()->Draw(arcInfo, dirtyRect, arcStyle, opaScale, CapType::CAP_NONE);

    // draw top right sector in border
    arcInfo.center = {radiusCol3X, radiusRow2Y};
    arcInfo.startAngle = 0;
    arcInfo.endAngle = QUARTER_IN_DEGREE;
    DrawArc::GetInstance()->Draw(arcInfo, dirtyRect, arcStyle, opaScale, CapType::CAP_NONE);

    // draw bottom left sector in border
    arcInfo.center = {radiusCol2X, radiusRow3Y};
    arcInfo.startAngle = SEMICIRCLE_IN_DEGREE;
    arcInfo.endAngle = THREE_QUARTER_IN_DEGREE;
    DrawArc::GetInstance()->Draw(arcInfo, dirtyRect, arcStyle, opaScale, CapType::CAP_NONE);

    // draw bottom right sector in border
    arcInfo.center = {radiusCol3X, radiusRow3Y};
    arcInfo.startAngle = QUARTER_IN_DEGREE;
    arcInfo.endAngle = SEMICIRCLE_IN_DEGREE;
    DrawArc::GetInstance()->Draw(arcInfo, dirtyRect, arcStyle, opaScale, CapType::CAP_NONE);

    OpacityType opa = DrawUtils::GetMixOpacity(opaScale, style.borderOpa_);
    // draw top rectangle in border
    Rect topRect(radiusCol2X, radiusRow1Y, radiusCol3X - 1, radiusRow2Y);
    DrawUtils::GetInstance()->DrawColorArea(topRect, dirtyRect, style.borderColor_, opa);
    Rect topRect2(rectCol1X, rectRow1Y + 1, rectCol4X, rectRow2Y);
    DrawUtils::GetInstance()->DrawColorArea(topRect2, dirtyRect, style.borderColor_, opa);

    // draw left rectangle in border
    Rect leftRect(rectCol1X, rectRow2Y + 1, rectCol2X, rectRow3Y - 1);
    DrawUtils::GetInstance()->DrawColorArea(leftRect, dirtyRect, style.borderColor_, opa);

    OpacityType opaBg = DrawUtils::GetMixOpacity(opaScale, style.bgOpa_);
    // draw middle rectangle
    Rect middleRect(rectCol2X + 1, rectRow2Y + 1, rectCol3X - 1, rectRow3Y - 1);
    DrawUtils::GetInstance()->DrawColorArea(middleRect, dirtyRect, style.bgColor_, opaBg);

    // draw right rectangle in border
    Rect rightRect(rectCol3X, rectRow2Y + 1, rectCol4X, rectRow3Y - 1);
    DrawUtils::GetInstance()->DrawColorArea(rightRect, dirtyRect, style.borderColor_, opa);

    // draw bottom rectangle in border
    Rect bottomRect(radiusCol2X + 1, radiusRow3Y, radiusCol3X - 1, radiusRow4Y);
    DrawUtils::GetInstance()->DrawColorArea(bottomRect, dirtyRect, style.borderColor_, opa);
    Rect bottomRect2(rectCol1X, rectRow3Y, rectCol4X, radiusRow3Y - 1);
    DrawUtils::GetInstance()->DrawColorArea(bottomRect2, dirtyRect, style.borderColor_, opa);
}

void DrawRect::DrawRectRadiusBiggerThanBorder(const Rect& rect, const Rect& dirtyRect, const Style& style,
                                              OpacityType opaScale)
{
    // 2 : half
    if ((rect.GetWidth() > rect.GetHeight()) && (style.borderRadius_ >= rect.GetHeight() / 2)) {
        DrawRectRadiusBiggerThanBorderCon1(rect, dirtyRect, style, opaScale);
    } else if ((rect.GetWidth() < rect.GetHeight()) && (style.borderRadius_ >= rect.GetWidth() / 2)) {
        DrawRectRadiusBiggerThanBorderCon2(rect, dirtyRect, style, opaScale);
    } else if ((rect.GetWidth() == rect.GetHeight()) && (style.borderRadius_ >= rect.GetWidth() / 2)) {
        DrawRectRadiusBiggerThanBorderCon3(rect, dirtyRect, style, opaScale);
    } else {
        DrawRectRadiusBiggerThanBorderCon4(rect, dirtyRect, style, opaScale);
    }
}

void DrawRect::DrawRectRadiusBiggerThanBorderCon1(const Rect& rect, const Rect& dirtyRect, const Style& style,
                                                  OpacityType opaScale)
{
    int16_t radius = rect.GetHeight() / 2;
    int16_t borderWidth = style.borderWidth_;
    int16_t col2X = rect.GetLeft() + radius - 1;
    int16_t col3X = rect.GetRight() - radius + 1;

    int16_t row1Y = rect.GetTop();
    int16_t row2Y = rect.GetTop() + borderWidth - 1;
    int16_t row3Y = rect.GetTop() + radius - 1;
    int16_t row4Y = rect.GetBottom() - borderWidth + 1;
    int16_t row5Y = rect.GetBottom();

    Style arcStyle = style;
    arcStyle.lineWidth_ = borderWidth;
    arcStyle.lineColor_ = style.borderColor_;
    arcStyle.lineOpa_ = style.borderOpa_;
    // draw left arc in border
    ArcInfo arcInfo;
    arcInfo.center = {col2X, row3Y};
    arcInfo.startAngle = SEMICIRCLE_IN_DEGREE;
    arcInfo.endAngle = CIRCLE_IN_DEGREE;
    arcInfo.radius = radius;
    arcInfo.imgPos = {0, 0};
    arcInfo.imgSrc = nullptr;
    DrawArc::GetInstance()->Draw(arcInfo, dirtyRect, arcStyle, opaScale, CapType::CAP_NONE);
    // draw right arc in border
    arcInfo.center = {col3X, row3Y};
    arcInfo.startAngle = 0;
    arcInfo.endAngle = SEMICIRCLE_IN_DEGREE;
    DrawArc::GetInstance()->Draw(arcInfo, dirtyRect, arcStyle, opaScale, CapType::CAP_NONE);

    radius = radius - borderWidth;
    arcStyle.lineWidth_ = radius;
    arcStyle.lineColor_ = style.bgColor_;
    arcStyle.lineOpa_ = style.bgOpa_;

    // draw left sector in rectangle
    arcInfo.center = {col2X, row3Y};
    arcInfo.startAngle = SEMICIRCLE_IN_DEGREE;
    arcInfo.endAngle = CIRCLE_IN_DEGREE;
    arcInfo.radius = radius;
    DrawArc::GetInstance()->Draw(arcInfo, dirtyRect, arcStyle, opaScale, CapType::CAP_NONE);
    // draw right sector in rectangle
    arcInfo.center = {col3X, row3Y};
    arcInfo.startAngle = 0;
    arcInfo.endAngle = SEMICIRCLE_IN_DEGREE;
    DrawArc::GetInstance()->Draw(arcInfo, dirtyRect, arcStyle, opaScale, CapType::CAP_NONE);

    OpacityType opa = DrawUtils::GetMixOpacity(opaScale, style.borderOpa_);
    // top rectangle in border
    Rect topBorderRect(col2X, row1Y, col3X - 1, row2Y);
    DrawUtils::GetInstance()->DrawColorArea(topBorderRect, dirtyRect, style.borderColor_, opa);
    OpacityType opaBg = DrawUtils::GetMixOpacity(opaScale, style.bgOpa_);
    // middle rectangle inner
    Rect middleInnerRect(col2X, row2Y + 1, col3X - 1, row3Y);
    DrawUtils::GetInstance()->DrawColorArea(middleInnerRect, dirtyRect, style.bgColor_, opaBg);
    Rect middleInnerRect2(col2X + 1, row3Y + 1, col3X - 1, row4Y - 1);
    DrawUtils::GetInstance()->DrawColorArea(middleInnerRect2, dirtyRect, style.bgColor_, opaBg);

    // bottom rectangle in border
    Rect bottomBorderRect(col2X + 1, row4Y, col3X - 1, row5Y);
    DrawUtils::GetInstance()->DrawColorArea(bottomBorderRect, dirtyRect, style.borderColor_, opa);
}

void DrawRect::DrawRectRadiusBiggerThanBorderCon2(const Rect& rect, const Rect& dirtyRect, const Style& style,
                                                  OpacityType opaScale)
{
    int16_t radius = rect.GetWidth() / 2;
    int16_t borderWidth = style.borderWidth_;
    int16_t col1X = rect.GetLeft();
    int16_t col2X = rect.GetLeft() + borderWidth - 1;
    int16_t col3X = rect.GetLeft() + radius - 1;
    int16_t col4X = rect.GetRight() - borderWidth + 1;
    int16_t col5X = rect.GetRight();

    int16_t row2Y = rect.GetTop() + radius - 1;
    int16_t row3Y = rect.GetBottom() - radius + 1;

    Style arcStyle = style;
    arcStyle.lineWidth_ = borderWidth;
    arcStyle.lineColor_ = style.borderColor_;
    arcStyle.lineOpa_ = style.borderOpa_;
    // draw top arc in border
    ArcInfo arcInfo;
    arcInfo.center = {col3X, row2Y};
    arcInfo.startAngle = THREE_QUARTER_IN_DEGREE;
    arcInfo.endAngle = QUARTER_IN_DEGREE;
    arcInfo.radius = radius;
    arcInfo.imgPos = {0, 0};
    arcInfo.imgSrc = nullptr;
    DrawArc::GetInstance()->Draw(arcInfo, dirtyRect, arcStyle, opaScale, CapType::CAP_NONE);
    // draw bottom arc in border
    arcInfo.center = {col3X, row3Y};
    arcInfo.startAngle = QUARTER_IN_DEGREE;
    arcInfo.endAngle = THREE_QUARTER_IN_DEGREE;
    DrawArc::GetInstance()->Draw(arcInfo, dirtyRect, arcStyle, opaScale, CapType::CAP_NONE);

    radius = radius - borderWidth;
    arcStyle.lineWidth_ = radius;
    arcStyle.lineColor_ = style.bgColor_;
    arcStyle.lineOpa_ = style.bgOpa_;

    // draw top sector in rectangle
    arcInfo.center = {col3X, row2Y};
    arcInfo.startAngle = THREE_QUARTER_IN_DEGREE;
    arcInfo.endAngle = QUARTER_IN_DEGREE;
    arcInfo.radius = radius;
    DrawArc::GetInstance()->Draw(arcInfo, dirtyRect, arcStyle, opaScale, CapType::CAP_NONE);
    // draw bottom sector in rectangle
    arcInfo.center = {col3X, row3Y};
    arcInfo.startAngle = QUARTER_IN_DEGREE;
    arcInfo.endAngle = THREE_QUARTER_IN_DEGREE;
    DrawArc::GetInstance()->Draw(arcInfo, dirtyRect, arcStyle, opaScale, CapType::CAP_NONE);

    OpacityType opa = DrawUtils::GetMixOpacity(opaScale, style.borderOpa_);
    // left rectangle in border
    Rect topBorderRect(col1X, row2Y + 1, col2X, row3Y - 1);
    DrawUtils::GetInstance()->DrawColorArea(topBorderRect, dirtyRect, style.borderColor_, opa);

    OpacityType opaBg = DrawUtils::GetMixOpacity(opaScale, style.bgOpa_);
    // middle rectangle inner
    Rect middleInnerRect(col2X + 1, row2Y + 1, col4X - 1, row3Y - 1);
    DrawUtils::GetInstance()->DrawColorArea(middleInnerRect, dirtyRect, style.bgColor_, opaBg);

    // right rectangle in border
    Rect bottomBorderRect(col4X, row2Y + 1, col5X, row3Y - 1);
    DrawUtils::GetInstance()->DrawColorArea(bottomBorderRect, dirtyRect, style.borderColor_, opa);
}

void DrawRect::DrawRectRadiusBiggerThanBorderCon3(const Rect& rect, const Rect& dirtyRect, const Style& style,
                                                  OpacityType opaScale)
{
    int16_t radius = rect.GetWidth() / 2;
    int16_t borderWidth = style.borderWidth_;
    int16_t col2X = rect.GetLeft() + radius - 1;
    int16_t row2Y = rect.GetTop() + radius - 1;

    Style arcStyle = style;
    arcStyle.lineWidth_ = borderWidth;
    arcStyle.lineColor_ = style.borderColor_;
    arcStyle.lineOpa_ = style.borderOpa_;
    // draw circle in border
    ArcInfo arcInfo;
    arcInfo.center = {col2X, row2Y};
    arcInfo.startAngle = 0;
    arcInfo.endAngle = CIRCLE_IN_DEGREE;
    arcInfo.radius = radius;
    arcInfo.imgPos = {0, 0};
    arcInfo.imgSrc = nullptr;
    DrawArc::GetInstance()->Draw(arcInfo, dirtyRect, arcStyle, opaScale, CapType::CAP_NONE);

    radius = radius - borderWidth;
    arcStyle.lineWidth_ = radius;
    arcStyle.lineColor_ = style.bgColor_;
    arcStyle.lineOpa_ = style.bgOpa_;

    // draw circle in rectangle
    arcInfo.center = {col2X, row2Y};
    arcInfo.startAngle = 0;
    arcInfo.endAngle = CIRCLE_IN_DEGREE;
    arcInfo.radius = radius;
    DrawArc::GetInstance()->Draw(arcInfo, dirtyRect, arcStyle, opaScale, CapType::CAP_NONE);
}

void DrawRect::DrawRectRadiusBiggerThanBorderCon4(const Rect& rect, const Rect& dirtyRect, const Style& style,
                                                  OpacityType opaScale)
{
    int16_t radius = style.borderRadius_;
    int16_t borderWidth = style.borderWidth_;
    int16_t col1X = rect.GetLeft();
    int16_t col2X = rect.GetLeft() + borderWidth - 1;
    int16_t col3X = rect.GetLeft() + radius - 1;
    int16_t col4X = rect.GetRight() - radius + 1;
    int16_t col5X = rect.GetRight() - borderWidth + 1;
    int16_t col6X = rect.GetRight();

    int16_t row1Y = rect.GetTop();
    int16_t row2Y = rect.GetTop() + borderWidth - 1;
    int16_t row3Y = rect.GetTop() + radius - 1;
    int16_t row4Y = rect.GetBottom() - radius + 1;
    int16_t row5Y = rect.GetBottom() - borderWidth + 1;
    int16_t row6Y = rect.GetBottom();

    Style arcStyle = style;
    arcStyle.lineWidth_ = borderWidth;
    arcStyle.lineColor_ = style.borderColor_;
    arcStyle.lineOpa_ = style.borderOpa_;

    // draw top left arc in border
    ArcInfo arcInfo;
    arcInfo.center = {col3X, row3Y};
    arcInfo.startAngle = THREE_QUARTER_IN_DEGREE;
    arcInfo.endAngle = CIRCLE_IN_DEGREE;
    arcInfo.radius = radius;
    arcInfo.imgPos = {0, 0};
    arcInfo.imgSrc = nullptr;
    DrawArc::GetInstance()->Draw(arcInfo, dirtyRect, arcStyle, opaScale, CapType::CAP_NONE);
    // draw top right arc in border
    arcInfo.center = {col4X, row3Y};
    arcInfo.startAngle = 0;
    arcInfo.endAngle = QUARTER_IN_DEGREE;
    DrawArc::GetInstance()->Draw(arcInfo, dirtyRect, arcStyle, opaScale, CapType::CAP_NONE);
    // draw bottom left arc in border
    arcInfo.center = {col3X, row4Y};
    arcInfo.startAngle = SEMICIRCLE_IN_DEGREE;
    arcInfo.endAngle = THREE_QUARTER_IN_DEGREE;
    DrawArc::GetInstance()->Draw(arcInfo, dirtyRect, arcStyle, opaScale, CapType::CAP_NONE);
    // draw bottom right arc in border
    arcInfo.center = {col4X, row4Y};
    arcInfo.startAngle = QUARTER_IN_DEGREE;
    arcInfo.endAngle = SEMICIRCLE_IN_DEGREE;
    DrawArc::GetInstance()->Draw(arcInfo, dirtyRect, arcStyle, opaScale, CapType::CAP_NONE);

    radius = radius - borderWidth;
    arcStyle.lineWidth_ = radius;
    arcStyle.lineColor_ = style.bgColor_;
    arcStyle.lineOpa_ = style.bgOpa_;

    // draw top left sector in rectangle
    arcInfo.center = {col3X, row3Y};
    arcInfo.startAngle = THREE_QUARTER_IN_DEGREE;
    arcInfo.endAngle = CIRCLE_IN_DEGREE;
    arcInfo.radius = radius;
    DrawArc::GetInstance()->Draw(arcInfo, dirtyRect, arcStyle, opaScale, CapType::CAP_NONE);
    // draw top right sector in rectangle
    arcInfo.center = {col4X, row3Y};
    arcInfo.startAngle = 0;
    arcInfo.endAngle = QUARTER_IN_DEGREE;
    DrawArc::GetInstance()->Draw(arcInfo, dirtyRect, arcStyle, opaScale, CapType::CAP_NONE);
    // draw bottom left sector in rectangle
    arcInfo.center = {col3X, row4Y};
    arcInfo.startAngle = SEMICIRCLE_IN_DEGREE;
    arcInfo.endAngle = THREE_QUARTER_IN_DEGREE;
    DrawArc::GetInstance()->Draw(arcInfo, dirtyRect, arcStyle, opaScale, CapType::CAP_NONE);
    // draw bottom right sector in rectangle
    arcInfo.center = {col4X, row4Y};
    arcInfo.startAngle = QUARTER_IN_DEGREE;
    arcInfo.endAngle = SEMICIRCLE_IN_DEGREE;
    DrawArc::GetInstance()->Draw(arcInfo, dirtyRect, arcStyle, opaScale, CapType::CAP_NONE);

    OpacityType opa = DrawUtils::GetMixOpacity(opaScale, style.borderOpa_);
    // top rectangle in border
    Rect topBorderRect(col3X, row1Y, col4X - 1, row2Y);
    DrawUtils::GetInstance()->DrawColorArea(topBorderRect, dirtyRect, style.borderColor_, opa);

    OpacityType opaBg = DrawUtils::GetMixOpacity(opaScale, style.bgOpa_);
    // top rectangle inner
    Rect topInnerRect(col3X, row2Y + 1, col4X - 1, row3Y);
    DrawUtils::GetInstance()->DrawColorArea(topInnerRect, dirtyRect, style.bgColor_, opaBg);

    // left rectangle in border
    Rect leftBorderRect(col1X, row3Y + 1, col2X, row4Y - 1);
    DrawUtils::GetInstance()->DrawColorArea(leftBorderRect, dirtyRect, style.borderColor_, opa);

    // middle rectangle inner
    Rect middleInnerRect(col2X + 1, row3Y + 1, col5X - 1, row4Y - 1);
    DrawUtils::GetInstance()->DrawColorArea(middleInnerRect, dirtyRect, style.bgColor_, opaBg);

    // right rectangle in border
    Rect rightBorderRect(col5X, row3Y + 1, col6X, row4Y - 1);
    DrawUtils::GetInstance()->DrawColorArea(rightBorderRect, dirtyRect, style.borderColor_, opa);

    // bottom rectangle inner
    Rect bottomInnerRect(col3X + 1, row4Y, col4X - 1, row5Y - 1);
    DrawUtils::GetInstance()->DrawColorArea(bottomInnerRect, dirtyRect, style.bgColor_, opaBg);

    // bottom rectangle in border
    Rect bottomBorderRect(col3X + 1, row5Y, col4X - 1, row6Y);
    DrawUtils::GetInstance()->DrawColorArea(bottomBorderRect, dirtyRect, style.borderColor_, opa);
}
} // namespace OHOS