1 /* 2 * Copyright (c) 2023 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_NG_PROPERTIES_PARTICLE_PROPERTIES_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PROPERTIES_PARTICLE_PROPERTIES_H 18 #include <cstdint> 19 #include <list> 20 #include <optional> 21 #include <string> 22 #include <utility> 23 24 #include "base/geometry/dimension.h" 25 #include "core/components/common/layout/constants.h" 26 #include "core/components/common/properties/color.h" 27 #include "core/components_ng/property/particle_property_animation.h" 28 namespace OHOS::Ace::NG { 29 namespace { 30 constexpr int32_t DEFAULT_PARTICLE_COUNT = 5; 31 } 32 enum ACE_EXPORT UpdaterType { NONE_UPDATER = 0, RANDOM, CURVE }; 33 34 enum ACE_EXPORT ParticleType { POINT = 0, IMAGE }; 35 36 enum ACE_EXPORT ParticleEmitterShape { RECTANGLE = 0, CIRCLE, ELLIPSE }; 37 38 struct PointParticleParameter { 39 public: SetRadiusPointParticleParameter40 void SetRadius(float radius) 41 { 42 radius_ = radius; 43 } 44 GetRadiusPointParticleParameter45 float GetRadius() const 46 { 47 return radius_; 48 } 49 50 bool operator==(const PointParticleParameter& other) const 51 { 52 return NearEqual(radius_, other.GetRadius()); 53 } 54 ToStringPointParticleParameter55 std::string ToString() const 56 { 57 std::string str; 58 str.append("radius: [").append(std::to_string(radius_)).append("]"); 59 return str; 60 } 61 62 private: 63 float radius_ = 0.0f; 64 }; 65 66 struct ImageParticleParameter { 67 public: GetImageSourceImageParticleParameter68 const std::string& GetImageSource() const 69 { 70 return imageSource_; 71 } 72 SetImageSourceImageParticleParameter73 void SetImageSource(std::string& imageSource) 74 { 75 imageSource_ = imageSource; 76 } 77 GetSizeImageParticleParameter78 const std::pair<Dimension, Dimension>& GetSize() const 79 { 80 return size_; 81 } 82 SetSizeImageParticleParameter83 void SetSize(std::pair<Dimension, Dimension>& size) 84 { 85 size_ = size; 86 } 87 GetImageFitImageParticleParameter88 std::optional<ImageFit> GetImageFit() const 89 { 90 return imageFit_; 91 } 92 SetImageFitImageParticleParameter93 void SetImageFit(ImageFit& imageFit) 94 { 95 imageFit_ = imageFit; 96 } 97 98 bool operator==(const ImageParticleParameter& other) const 99 { 100 return (imageSource_ == other.GetImageSource()) && (size_ == other.GetSize()) && 101 (imageFit_ == other.GetImageFit()); 102 } 103 ToStringImageParticleParameter104 std::string ToString() const 105 { 106 std::string str; 107 str.append("imageSource: [").append(imageSource_).append("]"); 108 str.append("size: [").append(size_.first.ToString()).append(",").append(size_.second.ToString()).append("]"); 109 str.append("imageFit: [") 110 .append(imageFit_.has_value() ? std::to_string(static_cast<int32_t>(imageFit_.value())) : "NA") 111 .append("]"); 112 return str; 113 } 114 115 private: 116 std::string imageSource_; 117 std::pair<Dimension, Dimension> size_; 118 std::optional<ImageFit> imageFit_; 119 }; 120 121 struct ParticleConfig { 122 public: SetPointParticleParameterParticleConfig123 void SetPointParticleParameter(const PointParticleParameter& pointParticleParameter) 124 { 125 pointParameter_ = pointParticleParameter; 126 } GetPointParticleParameterParticleConfig127 const PointParticleParameter& GetPointParticleParameter() const 128 { 129 return pointParameter_; 130 } SetImageParticleParameterParticleConfig131 void SetImageParticleParameter(const ImageParticleParameter& imageParticleParameter) 132 { 133 imageParameter_ = imageParticleParameter; 134 } GetImageParticleParameterParticleConfig135 const ImageParticleParameter& GetImageParticleParameter() const 136 { 137 return imageParameter_; 138 } 139 140 bool operator==(const ParticleConfig& other) const 141 { 142 return (pointParameter_ == other.GetPointParticleParameter()) && 143 (imageParameter_ == other.GetImageParticleParameter()); 144 } 145 ToStringParticleConfig146 std::string ToString() const 147 { 148 std::string str; 149 str.append("pointParameter: [").append(pointParameter_.ToString()).append("]"); 150 str.append("imageParameter: [").append(imageParameter_.ToString()).append("]"); 151 return str; 152 } 153 154 private: 155 PointParticleParameter pointParameter_; 156 ImageParticleParameter imageParameter_; 157 }; 158 159 struct Particle { 160 public: GetParticleTypeParticle161 const ParticleType& GetParticleType() const 162 { 163 return particleType_; 164 } SetParticleTypeParticle165 void SetParticleType(const ParticleType& particleType) 166 { 167 particleType_ = particleType; 168 } GetConfigParticle169 const ParticleConfig& GetConfig() const 170 { 171 return config_; 172 } SetConfigParticle173 void SetConfig(const ParticleConfig& config) 174 { 175 config_ = config; 176 } GetCountParticle177 int32_t GetCount() const 178 { 179 return count_; 180 } SetCountParticle181 void SetCount(int32_t count) 182 { 183 count_ = count; 184 } SetLifeTimeParticle185 void SetLifeTime(int64_t lifetime) 186 { 187 lifeTime_ = lifetime; 188 } 189 GetLifeTimeParticle190 const std::optional<int64_t>& GetLifeTime() const 191 { 192 return lifeTime_; 193 } 194 195 bool operator==(const Particle& other) const 196 { 197 return (particleType_ == other.GetParticleType()) && (config_ == other.GetConfig()) && 198 (count_ == other.GetCount()) && (lifeTime_ == other.GetLifeTime()); 199 } 200 ToStringParticle201 std::string ToString() const 202 { 203 std::string str; 204 str.append("particleType: [").append(std::to_string(static_cast<int32_t>(particleType_))).append("]"); 205 str.append("config: [").append(config_.ToString()).append("]"); 206 str.append("count: [").append(std::to_string(count_)).append("]"); 207 str.append("lifeTime: [").append(lifeTime_.has_value() ? std::to_string(lifeTime_.value()) : "NA").append("]"); 208 return str; 209 } 210 211 private: 212 ParticleType particleType_; 213 ParticleConfig config_; 214 int32_t count_ = DEFAULT_PARTICLE_COUNT; 215 std::optional<int64_t> lifeTime_; 216 }; 217 218 struct EmitterOption { 219 public: GetParticleEmitterOption220 const Particle& GetParticle() const 221 { 222 return particle_; 223 } SetParticleEmitterOption224 void SetParticle(Particle& particle) 225 { 226 particle_ = particle; 227 } SetEmitterRateEmitterOption228 void SetEmitterRate(int32_t emitterRate) 229 { 230 emitterRate_ = emitterRate; 231 } 232 GetEmitterRateEmitterOption233 const std::optional<int32_t>& GetEmitterRate() const 234 { 235 return emitterRate_; 236 } 237 SetPositionEmitterOption238 void SetPosition(std::pair<Dimension, Dimension>& point) 239 { 240 position_ = point; 241 } 242 GetPositionEmitterOption243 const std::optional<std::pair<Dimension, Dimension>>& GetPosition() const 244 { 245 return position_; 246 } 247 SetSizeEmitterOption248 void SetSize(std::pair<Dimension, Dimension>& size) 249 { 250 size_ = size; 251 } 252 GetSizeEmitterOption253 const std::optional<std::pair<Dimension, Dimension>>& GetSize() const 254 { 255 return size_; 256 } 257 SetShapeEmitterOption258 void SetShape(ParticleEmitterShape& shape) 259 { 260 shape_ = shape; 261 } 262 GetShapeEmitterOption263 const std::optional<ParticleEmitterShape>& GetShape() const 264 { 265 return shape_; 266 } 267 268 bool operator==(const EmitterOption& other) const 269 { 270 return particle_ == other.GetParticle() && emitterRate_ == other.GetEmitterRate() && 271 position_ == other.GetPosition() && size_ == other.GetSize() && shape_ == other.GetShape(); 272 } 273 ToStringEmitterOption274 std::string ToString() const 275 { 276 std::string str; 277 str.append("particle: [").append(particle_.ToString()).append("]"); 278 str.append("emitterRate: [") 279 .append(emitterRate_.has_value() ? std::to_string(emitterRate_.value()) : "NA") 280 .append("]"); 281 if (position_.has_value()) { 282 str.append("position: [") 283 .append(position_->first.ToString()) 284 .append(",") 285 .append(position_->second.ToString()) 286 .append("]"); 287 } else { 288 str.append("position: [").append("NA").append("]"); 289 } 290 if (size_.has_value()) { 291 str.append("size: [") 292 .append(size_->first.ToString()) 293 .append(",") 294 .append(size_->second.ToString()) 295 .append("]"); 296 } else { 297 str.append("size: [").append("NA").append("]"); 298 } 299 str.append("shape: [") 300 .append(shape_.has_value() ? std::to_string(static_cast<int32_t>(shape_.value())) : "NA") 301 .append("]"); 302 return str; 303 } 304 305 private: 306 Particle particle_; 307 std::optional<int32_t> emitterRate_; 308 std::optional<std::pair<Dimension, Dimension>> position_; 309 std::optional<std::pair<Dimension, Dimension>> size_; 310 std::optional<ParticleEmitterShape> shape_; 311 }; 312 313 struct ParticleFloatPropertyUpdaterConfig { 314 public: SetRandomConfigParticleFloatPropertyUpdaterConfig315 void SetRandomConfig(const std::pair<float, float>& randomConfig) 316 { 317 randomConfig_ = randomConfig; 318 } 319 GetRandomConfigParticleFloatPropertyUpdaterConfig320 const std::pair<float, float>& GetRandomConfig() const 321 { 322 return randomConfig_; 323 } 324 SetAnimationsParticleFloatPropertyUpdaterConfig325 void SetAnimations(const std::list<ParticlePropertyAnimation<float>>& animations) 326 { 327 animations_ = animations; 328 } 329 GetAnimationsParticleFloatPropertyUpdaterConfig330 const std::list<ParticlePropertyAnimation<float>>& GetAnimations() const 331 { 332 return animations_; 333 } 334 SetNullStrParticleFloatPropertyUpdaterConfig335 void SetNullStr(const std::string noneValue) 336 { 337 noneValue_ = noneValue; 338 } 339 GetNullStrParticleFloatPropertyUpdaterConfig340 const std::string& GetNullStr() const 341 { 342 return noneValue_; 343 } 344 345 bool operator==(const ParticleFloatPropertyUpdaterConfig& other) const 346 { 347 return (noneValue_ == other.GetNullStr()) && NearEqual(randomConfig_.first, other.GetRandomConfig().first) && 348 NearEqual(randomConfig_.second, other.GetRandomConfig().second) && 349 (animations_ == other.GetAnimations()); 350 } 351 ToStringParticleFloatPropertyUpdaterConfig352 std::string ToString() const 353 { 354 std::string str; 355 str.append("noneValue: [").append(noneValue_).append("]"); 356 str.append("randomConfig: [") 357 .append(std::to_string(randomConfig_.first)) 358 .append(",") 359 .append(std::to_string(randomConfig_.second)) 360 .append("]"); 361 if (animations_.size() > 0) { 362 str.append("animations: ["); 363 for (auto& item : animations_) { 364 str.append("{").append(item.ToString()).append("}"); 365 } 366 str.append("]"); 367 } else { 368 str.append("animations: [").append("]"); 369 } 370 return str; 371 } 372 373 private: 374 std::string noneValue_; 375 std::pair<float, float> randomConfig_; 376 std::list<ParticlePropertyAnimation<float>> animations_; 377 }; 378 379 struct ParticleFloatPropertyUpdater { 380 public: GetUpdaterTypeParticleFloatPropertyUpdater381 const UpdaterType& GetUpdaterType() const 382 { 383 return updaterType_; 384 } 385 SetUpdaterTypeParticleFloatPropertyUpdater386 void SetUpdaterType(const UpdaterType& updateType) 387 { 388 updaterType_ = updateType; 389 } 390 GetConfigParticleFloatPropertyUpdater391 const ParticleFloatPropertyUpdaterConfig& GetConfig() const 392 { 393 return config_; 394 } 395 SetConfigParticleFloatPropertyUpdater396 void SetConfig(const ParticleFloatPropertyUpdaterConfig& config) 397 { 398 config_ = config; 399 } 400 401 bool operator==(const ParticleFloatPropertyUpdater& other) const 402 { 403 return (updaterType_ == other.GetUpdaterType()) && (config_ == other.GetConfig()); 404 } 405 ToStringParticleFloatPropertyUpdater406 std::string ToString() const 407 { 408 std::string str; 409 str.append("updaterType: [").append(std::to_string(static_cast<int32_t>(updaterType_))).append("]"); 410 str.append("config: [").append(config_.ToString()).append("]"); 411 return str; 412 } 413 414 private: 415 UpdaterType updaterType_ = UpdaterType::NONE_UPDATER; 416 ParticleFloatPropertyUpdaterConfig config_; 417 }; 418 419 struct ParticleFloatPropertyOption { 420 public: GetRangeParticleFloatPropertyOption421 const std::pair<float, float>& GetRange() const 422 { 423 return range_; 424 } 425 SetRangeParticleFloatPropertyOption426 void SetRange(const std::pair<float, float>& range) 427 { 428 range_ = range; 429 } 430 GetUpdaterParticleFloatPropertyOption431 const std::optional<ParticleFloatPropertyUpdater>& GetUpdater() const 432 { 433 return updater_; 434 } 435 SetUpdaterParticleFloatPropertyOption436 void SetUpdater(const ParticleFloatPropertyUpdater& updater) 437 { 438 updater_ = updater; 439 } 440 441 bool operator==(const ParticleFloatPropertyOption& other) const 442 { 443 return NearEqual(range_.first, other.GetRange().first) && NearEqual(range_.second, other.GetRange().second) && 444 (updater_ == other.GetUpdater()); 445 } 446 ToStringParticleFloatPropertyOption447 std::string ToString() const 448 { 449 std::string str; 450 str.append("range: [") 451 .append(std::to_string(range_.first)) 452 .append(",") 453 .append(std::to_string(range_.second)) 454 .append("]"); 455 str.append("updater: [").append(updater_.has_value() ? updater_->ToString() : "NA").append("]"); 456 return str; 457 } 458 459 private: 460 std::pair<float, float> range_; 461 std::optional<ParticleFloatPropertyUpdater> updater_; 462 }; 463 464 struct ColorParticleRandomUpdateConfig { 465 public: GetRedRandomColorParticleRandomUpdateConfig466 const std::pair<float, float>& GetRedRandom() const 467 { 468 return redRandom_; 469 } 470 SetRedRandomColorParticleRandomUpdateConfig471 void SetRedRandom(const std::pair<float, float>& redRandom) 472 { 473 redRandom_ = redRandom; 474 } 475 GetGreenRandomColorParticleRandomUpdateConfig476 const std::pair<float, float>& GetGreenRandom() const 477 { 478 return greenRandom_; 479 } 480 SetGreenRandomColorParticleRandomUpdateConfig481 void SetGreenRandom(const std::pair<float, float>& greenRandom) 482 { 483 greenRandom_ = greenRandom; 484 } 485 GetBlueRandomColorParticleRandomUpdateConfig486 const std::pair<float, float>& GetBlueRandom() const 487 { 488 return blueRandom_; 489 } 490 SetBlueRandomColorParticleRandomUpdateConfig491 void SetBlueRandom(const std::pair<float, float>& blueRandom) 492 { 493 blueRandom_ = blueRandom; 494 } 495 GetAlphaRandomColorParticleRandomUpdateConfig496 const std::pair<float, float>& GetAlphaRandom() const 497 { 498 return alphaRandom_; 499 } 500 SetAlphaRandomColorParticleRandomUpdateConfig501 void SetAlphaRandom(const std::pair<float, float>& alphaRandom) 502 { 503 alphaRandom_ = alphaRandom; 504 } 505 506 bool operator==(const ColorParticleRandomUpdateConfig& other) const 507 { 508 return NearEqual(redRandom_.first, other.GetRedRandom().first) && 509 NearEqual(redRandom_.second, other.GetRedRandom().second) && 510 NearEqual(greenRandom_.first, other.GetGreenRandom().first) && 511 NearEqual(greenRandom_.second, other.GetGreenRandom().second) && 512 NearEqual(blueRandom_.first, other.GetBlueRandom().first) && 513 NearEqual(blueRandom_.second, other.GetBlueRandom().second) && 514 NearEqual(alphaRandom_.first, other.GetAlphaRandom().first) && 515 NearEqual(alphaRandom_.second, other.GetAlphaRandom().second); 516 } 517 ToStringColorParticleRandomUpdateConfig518 std::string ToString() const 519 { 520 std::string str; 521 str.append("redRandom: [") 522 .append(std::to_string(redRandom_.first)) 523 .append(",") 524 .append(std::to_string(redRandom_.second)) 525 .append("]"); 526 str.append("greenRandom: [") 527 .append(std::to_string(greenRandom_.first)) 528 .append(",") 529 .append(std::to_string(greenRandom_.second)) 530 .append("]"); 531 str.append("blueRandom: [") 532 .append(std::to_string(blueRandom_.first)) 533 .append(",") 534 .append(std::to_string(blueRandom_.second)) 535 .append("]"); 536 str.append("alphaRandom: [") 537 .append(std::to_string(alphaRandom_.first)) 538 .append(",") 539 .append(std::to_string(alphaRandom_.second)) 540 .append("]"); 541 return str; 542 } 543 544 private: 545 std::pair<float, float> redRandom_; 546 std::pair<float, float> greenRandom_; 547 std::pair<float, float> blueRandom_; 548 std::pair<float, float> alphaRandom_; 549 }; 550 551 struct ParticleColorPropertyUpdaterConfig { 552 public: SetInValidParticleColorPropertyUpdaterConfig553 void SetInValid(int32_t inValid) 554 { 555 inValid_ = inValid; 556 } 557 GetInValidParticleColorPropertyUpdaterConfig558 int32_t GetInValid() const 559 { 560 return inValid_; 561 } 562 SetRandomConfigParticleColorPropertyUpdaterConfig563 void SetRandomConfig(const ColorParticleRandomUpdateConfig& randomConfig) 564 { 565 random_ = randomConfig; 566 } 567 GetRandomConfigParticleColorPropertyUpdaterConfig568 const ColorParticleRandomUpdateConfig& GetRandomConfig() const 569 { 570 return random_; 571 } 572 SetAnimationArrayParticleColorPropertyUpdaterConfig573 void SetAnimationArray(const std::list<ParticlePropertyAnimation<Color>>& animationArray) 574 { 575 animationArray_ = animationArray; 576 } 577 GetAnimationArrayParticleColorPropertyUpdaterConfig578 const std::list<ParticlePropertyAnimation<Color>>& GetAnimationArray() const 579 { 580 return animationArray_; 581 } 582 583 bool operator==(const ParticleColorPropertyUpdaterConfig& other) const 584 { 585 return (inValid_ == other.GetInValid()) && (random_ == other.GetRandomConfig()) && 586 (animationArray_ == other.GetAnimationArray()); 587 } 588 ToStringParticleColorPropertyUpdaterConfig589 std::string ToString() const 590 { 591 std::string str; 592 str.append("inValid: [").append(std::to_string(inValid_)).append("]"); 593 str.append("random: [").append(random_.ToString()).append("]"); 594 str.append("animationArray: ["); 595 if (animationArray_.size() > 0) { 596 for (auto& item : animationArray_) { 597 str.append("{").append(item.ToString()).append("}"); 598 } 599 } 600 str.append("]"); 601 return str; 602 } 603 604 private: 605 int32_t inValid_ = 0; 606 ColorParticleRandomUpdateConfig random_; 607 std::list<ParticlePropertyAnimation<Color>> animationArray_; 608 }; 609 610 struct ParticleColorPropertyUpdater { 611 public: GetUpdateTypeParticleColorPropertyUpdater612 const UpdaterType& GetUpdateType() const 613 { 614 return type_; 615 } 616 SetUpdateTypeParticleColorPropertyUpdater617 void SetUpdateType(UpdaterType type) 618 { 619 type_ = type; 620 } 621 GetConfigParticleColorPropertyUpdater622 const ParticleColorPropertyUpdaterConfig& GetConfig() const 623 { 624 return config_; 625 } 626 SetConfigParticleColorPropertyUpdater627 void SetConfig(const ParticleColorPropertyUpdaterConfig& config) 628 { 629 config_ = config; 630 } 631 632 bool operator==(const ParticleColorPropertyUpdater& other) const 633 { 634 return (type_ == other.GetUpdateType()) && (config_ == other.GetConfig()); 635 } 636 ToStringParticleColorPropertyUpdater637 std::string ToString() const 638 { 639 std::string str; 640 str.append("type: [").append(std::to_string(static_cast<int32_t>(type_))).append("]"); 641 str.append("config: [").append(config_.ToString()).append("]"); 642 return str; 643 } 644 645 private: 646 UpdaterType type_ = UpdaterType::NONE_UPDATER; 647 ParticleColorPropertyUpdaterConfig config_; 648 }; 649 650 struct ParticleColorPropertyOption { 651 public: GetRangeParticleColorPropertyOption652 const std::pair<Color, Color>& GetRange() const 653 { 654 return range_; 655 } SetRangeParticleColorPropertyOption656 void SetRange(std::pair<Color, Color>& range) 657 { 658 range_ = range; 659 } GetUpdaterParticleColorPropertyOption660 const std::optional<ParticleColorPropertyUpdater>& GetUpdater() const 661 { 662 return updater_; 663 } SetUpdaterParticleColorPropertyOption664 void SetUpdater(ParticleColorPropertyUpdater& updater) 665 { 666 updater_ = updater; 667 } 668 669 bool operator==(const ParticleColorPropertyOption& other) const 670 { 671 return (range_ == other.GetRange()) && (updater_ == other.GetUpdater()); 672 } 673 ToStringParticleColorPropertyOption674 std::string ToString() const 675 { 676 std::string str; 677 str.append("range: [") 678 .append(range_.first.ColorToString()) 679 .append(",") 680 .append(range_.second.ColorToString()) 681 .append("]"); 682 str.append("config: [").append(updater_.has_value() ? updater_->ToString() : "NA").append("]"); 683 return str; 684 } 685 686 private: 687 std::pair<Color, Color> range_; 688 std::optional<ParticleColorPropertyUpdater> updater_; 689 }; 690 691 struct VelocityProperty { 692 public: GetSpeedRangeVelocityProperty693 const std::pair<float, float>& GetSpeedRange() const 694 { 695 return speed_; 696 } SetSpeedRangeVelocityProperty697 void SetSpeedRange(std::pair<float, float>& speed) 698 { 699 speed_ = speed; 700 } GetAngleRangeVelocityProperty701 const std::pair<float, float>& GetAngleRange() const 702 { 703 return angle_; 704 } SetAngleRangeVelocityProperty705 void SetAngleRange(std::pair<float, float>& angle) 706 { 707 angle_ = angle; 708 } 709 710 bool operator==(const VelocityProperty& other) const 711 { 712 return NearEqual(speed_.first, other.GetSpeedRange().first) && 713 NearEqual(speed_.second, other.GetSpeedRange().second) && 714 NearEqual(angle_.first, other.GetAngleRange().first) && 715 NearEqual(angle_.second, other.GetAngleRange().second); 716 } 717 ToStringVelocityProperty718 std::string ToString() const 719 { 720 std::string str; 721 str.append("speed: [") 722 .append(std::to_string(speed_.first)) 723 .append(",") 724 .append(std::to_string(speed_.second)) 725 .append("]"); 726 str.append("angle: [") 727 .append(std::to_string(angle_.first)) 728 .append(",") 729 .append(std::to_string(angle_.second)) 730 .append("]"); 731 return str; 732 } 733 734 private: 735 std::pair<float, float> speed_; 736 std::pair<float, float> angle_; 737 }; 738 739 struct AccelerationProperty { 740 public: GetSpeedAccelerationProperty741 const std::optional<ParticleFloatPropertyOption>& GetSpeed() const 742 { 743 return speed_; 744 } 745 SetSpeedAccelerationProperty746 void SetSpeed(const ParticleFloatPropertyOption& speed) 747 { 748 speed_ = speed; 749 } 750 GetAngleAccelerationProperty751 const std::optional<ParticleFloatPropertyOption>& GetAngle() const 752 { 753 return angle_; 754 } 755 SetAngleAccelerationProperty756 void SetAngle(ParticleFloatPropertyOption& angle) 757 { 758 angle_ = angle; 759 } 760 761 bool operator==(const AccelerationProperty& other) const 762 { 763 return (speed_ == other.GetSpeed()) && (angle_ == other.GetAngle()); 764 } 765 ToStringAccelerationProperty766 std::string ToString() const 767 { 768 std::string str; 769 str.append("speed: [").append(speed_.has_value() ? speed_->ToString() : "NA").append("]"); 770 str.append("angle: [").append(angle_.has_value() ? angle_->ToString() : "NA").append("]"); 771 return str; 772 } 773 774 private: 775 std::optional<ParticleFloatPropertyOption> speed_; 776 std::optional<ParticleFloatPropertyOption> angle_; 777 }; 778 779 struct ParticleOption { 780 public: 781 GetEmitterOptionParticleOption782 const EmitterOption& GetEmitterOption() const 783 { 784 return emitter_; 785 } 786 SetEmitterOptionParticleOption787 void SetEmitterOption(EmitterOption& emitter) 788 { 789 emitter_ = emitter; 790 } 791 GetParticleColorOptionParticleOption792 const std::optional<ParticleColorPropertyOption>& GetParticleColorOption() const 793 { 794 return colorOption_; 795 } 796 SetParticleColorOptionParticleOption797 void SetParticleColorOption(const ParticleColorPropertyOption& colorOption) 798 { 799 colorOption_ = colorOption; 800 } 801 GetParticleOpacityOptionParticleOption802 const std::optional<ParticleFloatPropertyOption>& GetParticleOpacityOption() const 803 { 804 return opacityOption_; 805 } 806 SetParticleOpacityOptionParticleOption807 void SetParticleOpacityOption(ParticleFloatPropertyOption& opacityOption) 808 { 809 opacityOption_ = opacityOption; 810 } 811 GetParticleScaleOptionParticleOption812 const std::optional<ParticleFloatPropertyOption>& GetParticleScaleOption() const 813 { 814 return scaleOption_; 815 } 816 SetParticleScaleOptionParticleOption817 void SetParticleScaleOption(ParticleFloatPropertyOption& scaleOption) 818 { 819 scaleOption_ = scaleOption; 820 } 821 GetParticleVelocityOptionParticleOption822 const std::optional<VelocityProperty>& GetParticleVelocityOption() const 823 { 824 return velocityOption_; 825 } 826 SetParticleVelocityOptionParticleOption827 void SetParticleVelocityOption(VelocityProperty& velocityOption) 828 { 829 velocityOption_ = velocityOption; 830 } 831 GetParticleAccelerationOptionParticleOption832 const std::optional<AccelerationProperty>& GetParticleAccelerationOption() const 833 { 834 return accelerationOption_; 835 } 836 SetParticleAccelerationOptionParticleOption837 void SetParticleAccelerationOption(AccelerationProperty& accelerationOption) 838 { 839 accelerationOption_ = accelerationOption; 840 } 841 GetParticleSpinOptionParticleOption842 const std::optional<ParticleFloatPropertyOption>& GetParticleSpinOption() const 843 { 844 return spinOption_; 845 } 846 SetParticleSpinOptionParticleOption847 void SetParticleSpinOption(ParticleFloatPropertyOption& spinOption) 848 { 849 spinOption_ = spinOption; 850 } 851 852 bool operator==(const ParticleOption& other) const 853 { 854 return (emitter_ == other.GetEmitterOption()) && (colorOption_ == other.GetParticleColorOption()) && 855 (opacityOption_ == other.GetParticleOpacityOption()) && 856 (scaleOption_ == other.GetParticleScaleOption()) && 857 (velocityOption_ == other.GetParticleVelocityOption()) && 858 (accelerationOption_ == other.GetParticleAccelerationOption()) && 859 (spinOption_ == other.GetParticleSpinOption()); 860 } 861 ToStringParticleOption862 std::string ToString() const 863 { 864 std::string str; 865 str.append("emitter: [").append(emitter_.ToString()).append("]"); 866 str.append("colorOption: [").append(colorOption_.has_value() ? colorOption_->ToString() : "NA").append("]"); 867 str.append("opacityOption: [") 868 .append(opacityOption_.has_value() ? opacityOption_->ToString() : "NA") 869 .append("]"); 870 str.append("scaleOption: [").append(scaleOption_.has_value() ? scaleOption_->ToString() : "NA").append("]"); 871 str.append("velocityOption: [") 872 .append(velocityOption_.has_value() ? velocityOption_->ToString() : "NA") 873 .append("]"); 874 str.append("accelerationOption: [") 875 .append(accelerationOption_.has_value() ? accelerationOption_->ToString() : "NA") 876 .append("]"); 877 str.append("spinOption: [").append(spinOption_.has_value() ? spinOption_->ToString() : "NA").append("]"); 878 return str; 879 } 880 881 private: 882 EmitterOption emitter_; 883 std::optional<ParticleColorPropertyOption> colorOption_; 884 std::optional<ParticleFloatPropertyOption> opacityOption_; 885 std::optional<ParticleFloatPropertyOption> scaleOption_; 886 std::optional<VelocityProperty> velocityOption_; 887 std::optional<AccelerationProperty> accelerationOption_; 888 std::optional<ParticleFloatPropertyOption> spinOption_; 889 }; 890 } // namespace OHOS::Ace::NG 891 #endif