1 /* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_PROPERTIES_DECORATION_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_PROPERTIES_DECORATION_H 18 19 #include <memory> 20 #include <optional> 21 #include <regex> 22 #include <vector> 23 24 #include "base/geometry/dimension.h" 25 #include "base/geometry/rect.h" 26 #include "base/image/pixel_map.h" 27 #include "base/json/json_util.h" 28 #include "base/memory/ace_type.h" 29 #include "base/utils/macros.h" 30 #include "base/utils/utils.h" 31 #include "core/components/common/properties/alignment.h" 32 #include "core/components/common/properties/animatable_color.h" 33 #include "core/components/common/properties/background_image.h" 34 #include "core/components/common/properties/blend_mode.h" 35 #include "core/components/common/properties/blur_style_option.h" 36 #include "core/components/common/properties/border.h" 37 #include "core/components/common/properties/border_image.h" 38 #include "core/components/common/properties/brightness_option.h" 39 #include "core/components/common/properties/color.h" 40 #include "core/components/common/properties/blur_style_option.h" 41 #include "core/components/common/properties/edge.h" 42 #include "core/components/common/properties/effect_option.h" 43 #include "core/components/common/properties/invert.h" 44 #include "core/components/common/properties/outline_style.h" 45 #include "core/components/common/properties/shadow.h" 46 #include "core/components/theme/theme_utils.h" 47 #include "core/components_ng/base/inspector_filter.h" 48 49 namespace OHOS::Ace { 50 51 class PipelineContext; 52 53 constexpr double CENTER_OFFSET = 50.0; 54 constexpr double BOX_BEGIN_SIZE = 0.0; 55 constexpr double BOX_END_SIZE = 100.0; 56 constexpr double PERCENT_TRANSLATE = 100.0; 57 58 enum class GradientDirection { 59 LEFT = 0, 60 TOP, 61 RIGHT, 62 BOTTOM, 63 LEFT_TOP, 64 LEFT_BOTTOM, 65 RIGHT_TOP, 66 RIGHT_BOTTOM, 67 NONE, 68 START_TO_END, 69 END_TO_START, 70 }; 71 72 enum class GradientType { 73 LINEAR, 74 RADIAL, 75 SWEEP, 76 CONIC, 77 }; 78 79 enum class RadialSizeType { 80 CLOSEST_SIDE, 81 CLOSEST_CORNER, 82 FARTHEST_SIDE, 83 FARTHEST_CORNER, 84 NONE, 85 }; 86 87 enum class RadialShapeType { 88 CIRCLE, 89 ELLIPSE, 90 NONE, 91 }; 92 93 enum class SpreadMethod { 94 PAD, 95 REFLECT, 96 REPEAT, 97 }; 98 99 enum class HapticFeedbackMode { 100 DISABLED, 101 ENABLED, 102 AUTO, 103 }; 104 105 struct SysOptions { 106 bool disableSystemAdaptation = true; 107 bool operator==(const SysOptions& other) const 108 { 109 return disableSystemAdaptation == other.disableSystemAdaptation; 110 } 111 }; 112 113 struct MenuPreviewAnimationOptions { 114 float scaleFrom { -1.0f }; 115 float scaleTo { -1.0f }; 116 }; 117 118 struct LinearGradientInfo { 119 double x1 = 0.0; 120 double x2 = 0.0; 121 double y1 = 0.0; 122 double y2 = 0.0; 123 }; 124 125 struct RadialGradientInfo { 126 double r = 0.0; 127 double cx = 0.0; 128 double cy = 0.0; 129 double fx = 0.0; 130 double fy = 0.0; 131 }; 132 133 class GradientColor final { 134 public: 135 GradientColor() = default; 136 ~GradientColor() = default; 137 GradientColor(const Color & color)138 explicit GradientColor(const Color& color) 139 { 140 color_ = color; 141 } 142 143 void SetDimension(double value, DimensionUnit unit = DimensionUnit::PERCENT) 144 { 145 if (value < 0.0) { 146 return; 147 } 148 if (unit == DimensionUnit::PERCENT && value > BOX_END_SIZE) { 149 return; 150 } 151 dimension_ = Dimension(value, unit); 152 } 153 SetDimension(const Dimension & dimension)154 void SetDimension(const Dimension& dimension) 155 { 156 if (dimension.Value() < 0.0) { 157 return; 158 } 159 if (dimension.Unit() == DimensionUnit::PERCENT && dimension.Value() > BOX_END_SIZE) { 160 return; 161 } 162 dimension_ = dimension; 163 } 164 SetHasValue(bool hasValue)165 void SetHasValue(bool hasValue) 166 { 167 hasValue_ = hasValue; 168 } 169 SetColor(const Color & color)170 void SetColor(const Color& color) 171 { 172 color_ = color; 173 } 174 GetColor()175 const Color& GetColor() const 176 { 177 return color_; 178 } 179 GetDimension()180 const Dimension& GetDimension() const 181 { 182 return dimension_; 183 } 184 GetHasValue()185 bool GetHasValue() const 186 { 187 return hasValue_; 188 } 189 SetOpacity(double opacity)190 void SetOpacity(double opacity) 191 { 192 opacity_ = opacity; 193 } 194 GetOpacity()195 double GetOpacity() const 196 { 197 return opacity_; 198 } 199 200 private: 201 bool hasValue_ = true; 202 Color color_ { Color::TRANSPARENT }; 203 Dimension dimension_ { BOX_END_SIZE, DimensionUnit::PERCENT }; 204 double opacity_ = 1.0; 205 }; 206 207 struct ACE_EXPORT RadialGradient { 208 // size type 209 std::optional<RadialSizeType> radialSizeType; 210 // shape circle or ellipse 211 std::optional<RadialShapeType> radialShape; 212 // size in x-axis 213 std::optional<AnimatableDimension> radialHorizontalSize; 214 // size in y-axis 215 std::optional<AnimatableDimension> radialVerticalSize; 216 // center of shape 217 std::optional<AnimatableDimension> radialCenterX; 218 std::optional<AnimatableDimension> radialCenterY; 219 220 std::optional<Dimension> fRadialCenterX; 221 std::optional<Dimension> fRadialCenterY; 222 }; 223 224 struct ACE_EXPORT LinearGradient { 225 // direction in x-axis 226 std::optional<GradientDirection> linearX; 227 // direction in y-axis 228 std::optional<GradientDirection> linearY; 229 // angle of gradient line in bearing angle 230 std::optional<AnimatableDimension> angle; 231 232 std::optional<Dimension> x1; 233 std::optional<Dimension> y1; 234 std::optional<Dimension> x2; 235 std::optional<Dimension> y2; 236 237 // is direction in x-axis IsXAxisLinearGradient238 static bool IsXAxis(GradientDirection direction) 239 { 240 return (direction == GradientDirection::LEFT || direction == GradientDirection::RIGHT || 241 direction == GradientDirection::START_TO_END || direction == GradientDirection::END_TO_START); 242 } 243 }; 244 245 struct ACE_EXPORT SweepGradient { 246 // center of x-axis 247 std::optional<AnimatableDimension> centerX; 248 // center of y-axis 249 std::optional<AnimatableDimension> centerY; 250 // startAngle in degree 251 std::optional<AnimatableDimension> startAngle; 252 // endAngle in degree 253 std::optional<AnimatableDimension> endAngle; 254 // rotation in degree 255 std::optional<AnimatableDimension> rotation; 256 }; 257 258 struct ACE_EXPORT ConicGradient { 259 // center of x-axis 260 std::optional<AnimatableDimension> centerX; 261 // center of y-axis 262 std::optional<AnimatableDimension> centerY; 263 // startAngle in radian 264 std::optional<AnimatableDimension> startAngle; 265 }; 266 267 class ACE_FORCE_EXPORT Gradient final { 268 public: 269 void AddColor(const GradientColor& color); 270 271 void ClearColors(); 272 IsSweepGradientValid()273 bool IsSweepGradientValid() const 274 { 275 if (sweepGradient_.startAngle.has_value() && sweepGradient_.endAngle.has_value()) { 276 return LessOrEqual(sweepGradient_.startAngle.value().Value(), sweepGradient_.endAngle.value().Value()); 277 } 278 if (sweepGradient_.startAngle.has_value() && !sweepGradient_.endAngle.has_value()) { 279 return LessOrEqual(sweepGradient_.startAngle.value().Value(), 0.0); 280 } 281 if (!sweepGradient_.startAngle.has_value() && sweepGradient_.endAngle.has_value()) { 282 return LessOrEqual(0.0, sweepGradient_.endAngle.value().Value()); 283 } 284 return true; 285 } 286 IsValid()287 bool IsValid() const 288 { 289 if (GetType() == GradientType::SWEEP) { 290 return IsSweepGradientValid() && colors_.size() > 1; 291 } 292 return colors_.size() > 1; 293 } 294 SetRepeat(bool repeat)295 void SetRepeat(bool repeat) 296 { 297 repeat_ = repeat; 298 } 299 GetRepeat()300 bool GetRepeat() const 301 { 302 return repeat_; 303 } 304 GetColors()305 const std::vector<GradientColor>& GetColors() const 306 { 307 return colors_; 308 } 309 GetBeginOffset()310 const Offset& GetBeginOffset() const 311 { 312 return beginOffset_; 313 } 314 SetBeginOffset(const Offset & beginOffset)315 void SetBeginOffset(const Offset& beginOffset) 316 { 317 beginOffset_ = beginOffset; 318 } 319 GetEndOffset()320 const Offset& GetEndOffset() const 321 { 322 return endOffset_; 323 } 324 SetEndOffset(const Offset & endOffset)325 void SetEndOffset(const Offset& endOffset) 326 { 327 endOffset_ = endOffset; 328 } 329 GetInnerRadius()330 double GetInnerRadius() const 331 { 332 return innerRadius_; 333 } 334 SetInnerRadius(double innerRadius)335 void SetInnerRadius(double innerRadius) 336 { 337 innerRadius_ = innerRadius; 338 } 339 GetOuterRadius()340 double GetOuterRadius() const 341 { 342 return outerRadius_; 343 } 344 SetOuterRadius(double outerRadius)345 void SetOuterRadius(double outerRadius) 346 { 347 outerRadius_ = outerRadius; 348 } 349 GetType()350 GradientType GetType() const 351 { 352 return type_; 353 } 354 SetType(GradientType type)355 void SetType(GradientType type) 356 { 357 type_ = type; 358 } 359 ToString()360 std::string ToString() const 361 { 362 return std::string("Gradient (") 363 .append(beginOffset_.ToString()) 364 .append(",") 365 .append(std::to_string(innerRadius_)) 366 .append(" --- ") 367 .append(endOffset_.ToString()) 368 .append(",") 369 .append(std::to_string(outerRadius_)) 370 .append(")"); 371 } 372 GetSweepGradient()373 SweepGradient& GetSweepGradient() 374 { 375 return sweepGradient_; 376 } 377 GetSweepGradient()378 const SweepGradient& GetSweepGradient() const 379 { 380 return sweepGradient_; 381 } 382 SetSweepGradient(const SweepGradient & sweepGradient)383 void SetSweepGradient(const SweepGradient& sweepGradient) 384 { 385 sweepGradient_ = sweepGradient; 386 } 387 GetConicGradient()388 ConicGradient& GetConicGradient() 389 { 390 return conicGradient_; 391 } 392 GetConicGradient()393 const ConicGradient& GetConicGradient() const 394 { 395 return conicGradient_; 396 } 397 SetConicGradient(const ConicGradient & conicGradient)398 void SetConicGradient(const ConicGradient& conicGradient) 399 { 400 conicGradient_ = conicGradient; 401 } 402 GetRadialGradient()403 RadialGradient& GetRadialGradient() 404 { 405 return radialGradient_; 406 } 407 GetRadialGradient()408 const RadialGradient& GetRadialGradient() const 409 { 410 return radialGradient_; 411 } 412 SetRadialGradient(const RadialGradient & radialGradient)413 void SetRadialGradient(const RadialGradient& radialGradient) 414 { 415 radialGradient_ = radialGradient; 416 } 417 GetLinearGradient()418 LinearGradient& GetLinearGradient() 419 { 420 return linearGradient_; 421 } 422 GetLinearGradient()423 const LinearGradient& GetLinearGradient() const 424 { 425 return linearGradient_; 426 } 427 SetLinearGradient(const LinearGradient & linearGradient)428 void SetLinearGradient(const LinearGradient& linearGradient) 429 { 430 linearGradient_ = linearGradient; 431 } 432 SetDirection(const GradientDirection & direction)433 void SetDirection(const GradientDirection& direction) 434 { 435 if (LinearGradient::IsXAxis(direction)) { 436 linearGradient_.linearX = direction; 437 } else { 438 linearGradient_.linearY = direction; 439 } 440 } 441 SetSpreadMethod(SpreadMethod spreadMethod)442 void SetSpreadMethod(SpreadMethod spreadMethod) 443 { 444 spreadMethod_ = spreadMethod; 445 } 446 SetGradientTransform(const std::string & gradientTransform)447 void SetGradientTransform(const std::string& gradientTransform) 448 { 449 gradientTransform_ = gradientTransform; 450 } 451 GetSpreadMethod()452 SpreadMethod GetSpreadMethod() const 453 { 454 return spreadMethod_; 455 } 456 GetGradientTransform()457 const std::string& GetGradientTransform() const 458 { 459 return gradientTransform_; 460 } 461 GetRadialGradientInfo()462 const RadialGradientInfo& GetRadialGradientInfo() const 463 { 464 return radialGradientInfo_; 465 } 466 SetRadialGradientInfo(const RadialGradientInfo & radialGradientInfo)467 void SetRadialGradientInfo(const RadialGradientInfo& radialGradientInfo) 468 { 469 radialGradientInfo_ = radialGradientInfo; 470 } 471 GetLinearGradientInfo()472 const LinearGradientInfo& GetLinearGradientInfo() const 473 { 474 return linearGradientInfo_; 475 } 476 SetLinearGradientInfo(const LinearGradientInfo & linearGradientInfo)477 void SetLinearGradientInfo(const LinearGradientInfo& linearGradientInfo) 478 { 479 linearGradientInfo_ = linearGradientInfo; 480 } 481 SetHref(const std::string & href)482 void SetHref(const std::string& href) 483 { 484 href_ = href; 485 } 486 GetHref()487 std::string GetHref() const 488 { 489 return href_; 490 } 491 492 private: 493 GradientType type_ = GradientType::LINEAR; 494 bool repeat_ = false; 495 std::vector<GradientColor> colors_; 496 // for RadialGradient 497 RadialGradient radialGradient_; 498 // for LinearGradient 499 LinearGradient linearGradient_; 500 // for SweepGradient 501 SweepGradient sweepGradient_; 502 // for ConicGradient 503 ConicGradient conicGradient_; 504 // used for CanvasLinearGradient 505 Offset beginOffset_; 506 Offset endOffset_; 507 // used for CanvasRadialGradient 508 double innerRadius_ = 0.0; 509 double outerRadius_ = 0.0; 510 SpreadMethod spreadMethod_ = SpreadMethod::PAD; 511 std::string gradientTransform_; 512 LinearGradientInfo linearGradientInfo_; 513 RadialGradientInfo radialGradientInfo_; 514 std::string href_; 515 }; 516 517 class ArcBackground final : public AceType { 518 DECLARE_ACE_TYPE(ArcBackground, AceType); 519 520 public: 521 ~ArcBackground() override = default; ArcBackground(Point center,double radius)522 ArcBackground(Point center, double radius) 523 { 524 SetCenter(center); 525 SetRadius(radius); 526 } 527 GetCenter()528 const Point& GetCenter() const 529 { 530 return center_; 531 } 532 GetRadius()533 double GetRadius() const 534 { 535 return radius_; 536 } 537 SetCenter(const Point & center)538 void SetCenter(const Point& center) 539 { 540 center_ = center; 541 } 542 SetRadius(double radius)543 void SetRadius(double radius) 544 { 545 radius_ = radius; 546 } 547 SetColor(const Color & color)548 void SetColor(const Color& color) 549 { 550 color_ = color; 551 } 552 GetColor()553 const Color& GetColor() const 554 { 555 return color_; 556 } 557 558 private: 559 Point center_; 560 double radius_ = 0.0; 561 Color color_; 562 }; 563 564 class Decoration final : public AceType { 565 DECLARE_ACE_TYPE(Decoration, AceType); 566 567 public: 568 Decoration() = default; 569 ~Decoration() override = default; 570 571 void SetContextAndCallback(const WeakPtr<PipelineContext>& context, const RenderNodeAnimationCallback& callback); 572 573 void AddShadow(const Shadow& shadow); 574 575 void ClearAllShadow(); 576 577 void SetBackgroundColor(const Color& backgroundColor, const AnimationOption& option = AnimationOption()) 578 { 579 backgroundColor_ = AnimatableColor(backgroundColor, option); 580 } 581 SetBackgroundColor(const AnimatableColor & backgroundColor)582 void SetBackgroundColor(const AnimatableColor& backgroundColor) 583 { 584 backgroundColor_ = backgroundColor; 585 } 586 SetAnimationColor(const Color & animationColor)587 void SetAnimationColor(const Color& animationColor) 588 { 589 animationColor_ = animationColor; 590 } 591 592 void SetGradient(const Gradient& gradient, const WeakPtr<PipelineContext>& context = nullptr, 593 const RenderNodeAnimationCallback& callback = nullptr); 594 SetBorderImageGradient(const Gradient & gradient)595 void SetBorderImageGradient(const Gradient& gradient) 596 { 597 gradientBorderImage_ = gradient; 598 } SetImage(const RefPtr<BackgroundImage> & image)599 void SetImage(const RefPtr<BackgroundImage>& image) 600 { 601 image_ = image; 602 } 603 SetBorderImage(const RefPtr<BorderImage> & borderImage)604 void SetBorderImage(const RefPtr<BorderImage>& borderImage) 605 { 606 borderImage_ = borderImage; 607 } 608 SetHasBorderImageSource(const bool tag)609 void SetHasBorderImageSource(const bool tag) 610 { 611 hasBorderImageSource_ = tag; 612 } 613 SetHasBorderImageSlice(const bool tag)614 void SetHasBorderImageSlice(const bool tag) 615 { 616 hasBorderImageSlice_ = tag; 617 } 618 SetHasBorderImageWidth(const bool tag)619 void SetHasBorderImageWidth(const bool tag) 620 { 621 hasBorderImageWidth_ = tag; 622 } 623 SetHasBorderImageOutset(const bool tag)624 void SetHasBorderImageOutset(const bool tag) 625 { 626 hasBorderImageOutset_ = tag; 627 } 628 SetHasBorderImageRepeat(const bool tag)629 void SetHasBorderImageRepeat(const bool tag) 630 { 631 hasBorderImageRepeat_ = tag; 632 } 633 SetHasBorderImageGradient(const bool tag)634 void SetHasBorderImageGradient(const bool tag) 635 { 636 hasBorderImageGradient_ = tag; 637 } 638 SetPadding(const Edge & padding)639 void SetPadding(const Edge& padding) 640 { 641 padding_ = padding; 642 } 643 SetBorderRadius(const Radius & radius)644 void SetBorderRadius(const Radius& radius) 645 { 646 border_.SetBorderRadius(radius); 647 } 648 SetBorder(const Border & border)649 void SetBorder(const Border& border) 650 { 651 border_ = border; 652 } 653 SetArcBackground(const RefPtr<ArcBackground> & arcBG)654 void SetArcBackground(const RefPtr<ArcBackground>& arcBG) 655 { 656 arcBG_ = arcBG; 657 } 658 SetBlurRadius(const Dimension & radius)659 void SetBlurRadius(const Dimension& radius) 660 { 661 blurRadius_ = radius; 662 } 663 SetBlurRadius(const AnimatableDimension & radius)664 void SetBlurRadius(const AnimatableDimension& radius) 665 { 666 blurRadius_ = radius; 667 } 668 GetColorBlend(void)669 const Color& GetColorBlend(void) const 670 { 671 return colorBlend; 672 } 673 SetColorBlend(const Color & color)674 void SetColorBlend(const Color& color) 675 { 676 colorBlend = color; 677 } 678 SetWindowBlurProgress(float progress)679 void SetWindowBlurProgress(float progress) 680 { 681 windowBlurProgress_ = progress; 682 } 683 SetWindowBlurStyle(WindowBlurStyle style)684 void SetWindowBlurStyle(WindowBlurStyle style) 685 { 686 windowBlurStyle_ = style; 687 } 688 SetBlurStyle(const BlurStyleOption & style)689 void SetBlurStyle(const BlurStyleOption& style) 690 { 691 blurStyle_ = style; 692 } 693 GetBorder()694 const Border& GetBorder() const 695 { 696 return border_; 697 } 698 GetPadding()699 const Edge& GetPadding() const 700 { 701 return padding_; 702 } 703 GetImage()704 const RefPtr<BackgroundImage>& GetImage() const 705 { 706 return image_; 707 } 708 GetBorderImage()709 const RefPtr<BorderImage>& GetBorderImage() const 710 { 711 return borderImage_; 712 } 713 GetGradient()714 const Gradient& GetGradient() const 715 { 716 return gradient_; 717 } 718 GetBorderImageGradient()719 const Gradient& GetBorderImageGradient() const 720 { 721 return gradientBorderImage_; 722 } 723 GetHasBorderImageSource()724 bool GetHasBorderImageSource() 725 { 726 return hasBorderImageSource_; 727 } 728 GetHasBorderImageSlice()729 bool GetHasBorderImageSlice() 730 { 731 return hasBorderImageSlice_; 732 } 733 GetHasBorderImageWidth()734 bool GetHasBorderImageWidth() 735 { 736 return hasBorderImageWidth_; 737 } 738 GetHasBorderImageOutset()739 bool GetHasBorderImageOutset() 740 { 741 return hasBorderImageOutset_; 742 } 743 GetHasBorderImageRepeat()744 bool GetHasBorderImageRepeat() 745 { 746 return hasBorderImageRepeat_; 747 } 748 GetHasBorderImageGradient()749 bool GetHasBorderImageGradient() 750 { 751 return hasBorderImageGradient_; 752 } 753 GetBackgroundColor()754 const AnimatableColor& GetBackgroundColor() const 755 { 756 return backgroundColor_; 757 } 758 GetAnimationColor()759 const Color& GetAnimationColor() const 760 { 761 return animationColor_; 762 } 763 GetShadows()764 const std::vector<Shadow>& GetShadows() const 765 { 766 return shadows_; 767 } 768 SetShadows(const std::vector<Shadow> & shadows)769 void SetShadows(const std::vector<Shadow>& shadows) 770 { 771 shadows_.assign(shadows.begin(), shadows.end()); 772 } 773 GetBlendMode()774 BlendMode GetBlendMode() const 775 { 776 return blendMode_; 777 } 778 SetBlendMode(BlendMode blendMode)779 void SetBlendMode(BlendMode blendMode) 780 { 781 blendMode_ = blendMode; 782 } 783 GetBlendApplyType()784 BlendApplyType GetBlendApplyType() const 785 { 786 return blendApplyType_; 787 } 788 SetBlendApplyType(BlendApplyType blendApplyType)789 void SetBlendApplyType(BlendApplyType blendApplyType) 790 { 791 blendApplyType_ = blendApplyType; 792 } 793 GetGrayScale(void)794 const Dimension& GetGrayScale(void) const 795 { 796 return grayScale_; 797 } 798 SetGrayScale(const Dimension & grayScale)799 void SetGrayScale(const Dimension& grayScale) 800 { 801 grayScale_ = grayScale; 802 } 803 SetBrightness(const Dimension & brightness)804 void SetBrightness(const Dimension& brightness) 805 { 806 brightness_ = brightness; 807 } 808 GetBrightness()809 const Dimension& GetBrightness() const 810 { 811 return brightness_; 812 } 813 GetContrast(void)814 const Dimension& GetContrast(void) const 815 { 816 return contrast_; 817 } 818 SetContrast(const Dimension & contrast)819 void SetContrast(const Dimension& contrast) 820 { 821 contrast_ = contrast; 822 } 823 GetSaturate(void)824 const Dimension& GetSaturate(void) const 825 { 826 return saturate_; 827 } 828 SetSaturate(const Dimension & saturate)829 void SetSaturate(const Dimension& saturate) 830 { 831 saturate_ = saturate; 832 } 833 GetSepia(void)834 const Dimension& GetSepia(void) const 835 { 836 return sepia_; 837 } 838 SetSepia(const Dimension & sepia)839 void SetSepia(const Dimension& sepia) 840 { 841 sepia_ = sepia; 842 } 843 SetInvert(const Dimension & invert)844 void SetInvert(const Dimension& invert) 845 { 846 invert_ = invert; 847 } 848 GetInvert(void)849 const Dimension& GetInvert(void) const 850 { 851 return invert_; 852 } 853 GetHueRotate(void)854 float GetHueRotate(void) const 855 { 856 return hueRotate_; 857 } 858 SetHueRotate(const float & hueRotate)859 void SetHueRotate(const float& hueRotate) 860 { 861 hueRotate_ = hueRotate; 862 } 863 GetArcBackground()864 const RefPtr<ArcBackground>& GetArcBackground() const 865 { 866 return arcBG_; 867 } 868 NeedReloadImage(const RefPtr<Decoration> & lastDecoration)869 bool NeedReloadImage(const RefPtr<Decoration>& lastDecoration) const 870 { 871 if (!image_) { 872 return false; 873 } 874 875 if (!lastDecoration || !(lastDecoration->GetImage())) { 876 return true; 877 } 878 879 return (*image_) != (*(lastDecoration->GetImage())); 880 } 881 GetBlurRadius()882 const AnimatableDimension& GetBlurRadius() const 883 { 884 return blurRadius_; 885 } 886 GetWindowBlurProgress()887 float GetWindowBlurProgress() const 888 { 889 return windowBlurProgress_; 890 } 891 GetWindowBlurStyle()892 WindowBlurStyle GetWindowBlurStyle() const 893 { 894 return windowBlurStyle_; 895 } 896 GetBlurStyle()897 const BlurStyleOption& GetBlurStyle() const 898 { 899 return blurStyle_; 900 } 901 902 // Indicate how much size the decoration taken, excluding the content size. 903 Size GetOccupiedSize(double dipScale) const; 904 double HorizontalSpaceOccupied(double dipScale) const; 905 double VerticalSpaceOccupied(double dipScale) const; 906 907 Offset GetOffset(double dipScale) const; 908 909 private: 910 bool hasBorderImageSource_ = false; 911 bool hasBorderImageSlice_ = false; 912 bool hasBorderImageWidth_ = false; 913 bool hasBorderImageOutset_ = false; 914 bool hasBorderImageRepeat_ = false; 915 bool hasBorderImageGradient_ = false; 916 917 // padding is zero 918 Edge padding_; 919 // border contains black color and 1.0f thickness as default 920 Border border_; 921 // shadow vector is empty 922 std::vector<Shadow> shadows_; 923 // blendMode 924 BlendMode blendMode_ = BlendMode::NONE; 925 BlendApplyType blendApplyType_ = BlendApplyType::FAST; 926 Dimension grayScale_; 927 // Brightness (1.0 as default), range = (0, 2) 928 Dimension brightness_ = 1.0_px; 929 // hueRotate 930 float hueRotate_ = 0.0f; 931 // Contrast (1.0 as default), complete gray at 0 932 Dimension contrast_ = 1.0_px; 933 // Saturate 934 Dimension saturate_ = 1.0_px; 935 // Sepia 936 Dimension sepia_; 937 // invert 938 Dimension invert_; 939 // color is transparent 940 AnimatableColor backgroundColor_ { Color::TRANSPARENT }; 941 Color animationColor_ = Color::TRANSPARENT; 942 // Gradient is not implemented 943 Gradient gradient_ = Gradient(); 944 Gradient gradientBorderImage_ = Gradient(); 945 RefPtr<BackgroundImage> image_; 946 RefPtr<BorderImage> borderImage_; 947 RefPtr<ArcBackground> arcBG_; 948 // Blur radius 949 AnimatableDimension blurRadius_; 950 // window blur progress 951 float windowBlurProgress_ = 0.0f; 952 // window blur style; 953 WindowBlurStyle windowBlurStyle_ = WindowBlurStyle::STYLE_BACKGROUND_SMALL_LIGHT; 954 Color colorBlend; 955 // blur from rosen 956 BlurStyleOption blurStyle_; 957 }; 958 959 class Pattern final : std::enable_shared_from_this<Pattern> { 960 public: IsValid()961 bool IsValid() const 962 { 963 return (!imgSrc_.empty() || pixelMap_); 964 } 965 GetImgSrc()966 const std::string& GetImgSrc() const 967 { 968 return imgSrc_; 969 } 970 SetImgSrc(const std::string & imgSrc)971 void SetImgSrc(const std::string& imgSrc) 972 { 973 imgSrc_ = imgSrc; 974 } 975 GetRepetition()976 const std::string& GetRepetition() const 977 { 978 return repetition_; 979 } 980 SetRepetition(const std::string & repetition)981 void SetRepetition(const std::string& repetition) 982 { 983 repetition_ = repetition; 984 } 985 GetImageWidth()986 double GetImageWidth() const 987 { 988 return imageWidth_; 989 } 990 SetImageWidth(double imageWidth)991 void SetImageWidth(double imageWidth) 992 { 993 imageWidth_ = imageWidth; 994 } 995 GetImageHeight()996 double GetImageHeight() const 997 { 998 return imageHeight_; 999 } 1000 SetImageHeight(double imageHeight)1001 void SetImageHeight(double imageHeight) 1002 { 1003 imageHeight_ = imageHeight; 1004 } 1005 GetScaleX()1006 double GetScaleX() const 1007 { 1008 return scaleX_; 1009 } 1010 SetScaleX(double scaleX)1011 void SetScaleX(double scaleX) 1012 { 1013 transformable_ = true; 1014 scaleX_ = scaleX; 1015 } 1016 GetScaleY()1017 double GetScaleY() const 1018 { 1019 return scaleY_; 1020 } 1021 SetScaleY(double scaleY)1022 void SetScaleY(double scaleY) 1023 { 1024 transformable_ = true; 1025 scaleY_ = scaleY; 1026 } 1027 GetSkewX()1028 double GetSkewX() const 1029 { 1030 return skewX_; 1031 } 1032 SetSkewX(double skewX)1033 void SetSkewX(double skewX) 1034 { 1035 transformable_ = true; 1036 skewX_ = skewX; 1037 } 1038 GetSkewY()1039 double GetSkewY() const 1040 { 1041 return skewY_; 1042 } 1043 SetSkewY(double skewY)1044 void SetSkewY(double skewY) 1045 { 1046 transformable_ = true; 1047 skewY_ = skewY; 1048 } 1049 GetTranslateX()1050 double GetTranslateX() const 1051 { 1052 return translateX_; 1053 } 1054 SetTranslateX(double translateX)1055 void SetTranslateX(double translateX) 1056 { 1057 transformable_ = true; 1058 translateX_ = translateX; 1059 } 1060 GetTranslateY()1061 double GetTranslateY() const 1062 { 1063 return translateY_; 1064 } 1065 SetTranslateY(double translateY)1066 void SetTranslateY(double translateY) 1067 { 1068 transformable_ = true; 1069 translateY_ = translateY; 1070 } 1071 IsTransformable()1072 bool IsTransformable() const 1073 { 1074 return transformable_; 1075 } 1076 SetPixelMap(const RefPtr<PixelMap> & pixelMap)1077 void SetPixelMap(const RefPtr<PixelMap>& pixelMap) 1078 { 1079 pixelMap_ = pixelMap; 1080 } 1081 GetPixelMap()1082 RefPtr<PixelMap> GetPixelMap() const 1083 { 1084 return pixelMap_; 1085 } 1086 1087 private: 1088 double imageWidth_ = 0.0; 1089 double imageHeight_ = 0.0; 1090 double scaleX_ = 0.0; 1091 double skewX_ = 0.0; 1092 double skewY_ = 0.0; 1093 double scaleY_ = 0.0; 1094 double translateX_ = 0.0; 1095 double translateY_ = 0.0; 1096 bool transformable_ = false; 1097 std::string imgSrc_; 1098 std::string repetition_; 1099 RefPtr<PixelMap> pixelMap_; 1100 }; 1101 1102 enum class PathCmd { 1103 CMDS, 1104 TRANSFORM, 1105 MOVE_TO, 1106 LINE_TO, 1107 ARC, 1108 ARC_TO, 1109 QUADRATIC_CURVE_TO, 1110 BEZIER_CURVE_TO, 1111 ELLIPSE, 1112 RECT, 1113 CLOSE_PATH, 1114 }; 1115 1116 struct PathArgs { 1117 std::string cmds; 1118 double para1 = 0.0; 1119 double para2 = 0.0; 1120 double para3 = 0.0; 1121 double para4 = 0.0; 1122 double para5 = 0.0; 1123 double para6 = 0.0; 1124 double para7 = 0.0; 1125 double para8 = 0.0; 1126 }; 1127 1128 class ACE_FORCE_EXPORT CanvasPath2D : virtual public AceType { 1129 DECLARE_ACE_TYPE(CanvasPath2D, AceType) 1130 public: 1131 CanvasPath2D() = default; 1132 ~CanvasPath2D() = default; 1133 explicit CanvasPath2D(const std::string& cmds); 1134 explicit CanvasPath2D(const RefPtr<CanvasPath2D>& path); 1135 void AddPath(const RefPtr<CanvasPath2D>& path); 1136 void SetTransform(double a, double b, double c, double d, double e, double f); 1137 void MoveTo(double x, double y); 1138 void LineTo(double x, double y); 1139 void Arc(double x, double y, double radius, double startAngle, double endAngle, double ccw); 1140 void ArcTo(double x1, double y1, double x2, double y2, double radius); 1141 void QuadraticCurveTo(double cpx, double cpy, double x, double y); 1142 void BezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y); 1143 void Ellipse(double x, double y, double radiusX, double radiusY, double rotation, double startAngle, 1144 double endAngle, double ccw); 1145 void Rect(double x, double y, double width, double height); 1146 void ClosePath(); 1147 const std::vector<std::pair<PathCmd, PathArgs>>& GetCaches() const; 1148 std::string ToString() const; 1149 1150 private: 1151 std::vector<std::pair<PathCmd, PathArgs>> caches_; 1152 }; 1153 1154 } // namespace OHOS::Ace 1155 1156 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_PROPERTIES_DECORATION_H 1157