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 enum ACE_EXPORT DistributionType { UNIFORM = 0, GAUSSIAN }; 39 40 struct PointParticleParameter { 41 public: SetRadiusPointParticleParameter42 void SetRadius(float radius) 43 { 44 radius_ = radius; 45 } 46 GetRadiusPointParticleParameter47 float GetRadius() const 48 { 49 return radius_; 50 } 51 52 bool operator==(const PointParticleParameter& other) const 53 { 54 return NearEqual(radius_, other.GetRadius()); 55 } 56 ToStringPointParticleParameter57 std::string ToString() const 58 { 59 std::string str; 60 str.append("radius: [").append(std::to_string(radius_)).append("]"); 61 return str; 62 } 63 64 private: 65 float radius_ = 0.0f; 66 }; 67 68 struct ImageParticleParameter { 69 public: GetImageSourceImageParticleParameter70 const std::string& GetImageSource() const 71 { 72 return imageSource_; 73 } 74 SetImageSourceImageParticleParameter75 void SetImageSource(std::string& imageSource) 76 { 77 imageSource_ = imageSource; 78 } 79 GetSizeImageParticleParameter80 const std::pair<Dimension, Dimension>& GetSize() const 81 { 82 return size_; 83 } 84 SetSizeImageParticleParameter85 void SetSize(std::pair<Dimension, Dimension>& size) 86 { 87 size_ = size; 88 } 89 GetImageFitImageParticleParameter90 std::optional<ImageFit> GetImageFit() const 91 { 92 return imageFit_; 93 } 94 SetImageFitImageParticleParameter95 void SetImageFit(ImageFit& imageFit) 96 { 97 imageFit_ = imageFit; 98 } 99 100 bool operator==(const ImageParticleParameter& other) const 101 { 102 return (imageSource_ == other.GetImageSource()) && (size_ == other.GetSize()) && 103 (imageFit_ == other.GetImageFit()); 104 } 105 ToStringImageParticleParameter106 std::string ToString() const 107 { 108 std::string str; 109 str.append("imageSource: [").append(imageSource_).append("]"); 110 str.append("size: [").append(size_.first.ToString()).append(",").append(size_.second.ToString()).append("]"); 111 str.append("imageFit: [") 112 .append(imageFit_.has_value() ? std::to_string(static_cast<int32_t>(imageFit_.value())) : "NA") 113 .append("]"); 114 return str; 115 } 116 117 private: 118 std::string imageSource_; 119 std::pair<Dimension, Dimension> size_; 120 std::optional<ImageFit> imageFit_; 121 }; 122 123 struct ParticleConfig { 124 public: SetPointParticleParameterParticleConfig125 void SetPointParticleParameter(const PointParticleParameter& pointParticleParameter) 126 { 127 pointParameter_ = pointParticleParameter; 128 } GetPointParticleParameterParticleConfig129 const PointParticleParameter& GetPointParticleParameter() const 130 { 131 return pointParameter_; 132 } SetImageParticleParameterParticleConfig133 void SetImageParticleParameter(const ImageParticleParameter& imageParticleParameter) 134 { 135 imageParameter_ = imageParticleParameter; 136 } GetImageParticleParameterParticleConfig137 const ImageParticleParameter& GetImageParticleParameter() const 138 { 139 return imageParameter_; 140 } 141 142 bool operator==(const ParticleConfig& other) const 143 { 144 return (pointParameter_ == other.GetPointParticleParameter()) && 145 (imageParameter_ == other.GetImageParticleParameter()); 146 } 147 ToStringParticleConfig148 std::string ToString() const 149 { 150 std::string str; 151 str.append("pointParameter: [").append(pointParameter_.ToString()).append("]"); 152 str.append("imageParameter: [").append(imageParameter_.ToString()).append("]"); 153 return str; 154 } 155 156 private: 157 PointParticleParameter pointParameter_; 158 ImageParticleParameter imageParameter_; 159 }; 160 161 struct Particle { 162 public: GetParticleTypeParticle163 const ParticleType& GetParticleType() const 164 { 165 return particleType_; 166 } SetParticleTypeParticle167 void SetParticleType(const ParticleType& particleType) 168 { 169 particleType_ = particleType; 170 } GetConfigParticle171 const ParticleConfig& GetConfig() const 172 { 173 return config_; 174 } SetConfigParticle175 void SetConfig(const ParticleConfig& config) 176 { 177 config_ = config; 178 } GetCountParticle179 int32_t GetCount() const 180 { 181 return count_; 182 } SetCountParticle183 void SetCount(int32_t count) 184 { 185 count_ = count; 186 } SetLifeTimeParticle187 void SetLifeTime(int64_t lifetime) 188 { 189 lifeTime_ = lifetime; 190 } 191 GetLifeTimeParticle192 const std::optional<int64_t>& GetLifeTime() const 193 { 194 return lifeTime_; 195 } 196 SetLifeTimeRangeParticle197 void SetLifeTimeRange(int64_t lifetimeRange) 198 { 199 lifeTimeRange_ = lifetimeRange; 200 } 201 GetLifeTimeRangeParticle202 const std::optional<int64_t>& GetLifeTimeRange() const 203 { 204 return lifeTimeRange_; 205 } 206 207 bool operator==(const Particle& other) const 208 { 209 return (particleType_ == other.GetParticleType()) && (config_ == other.GetConfig()) && 210 (count_ == other.GetCount()) && (lifeTime_ == other.GetLifeTime()) && 211 (lifeTimeRange_ == other.GetLifeTimeRange()); 212 } 213 ToStringParticle214 std::string ToString() const 215 { 216 std::string str; 217 str.append("particleType: [").append(std::to_string(static_cast<int32_t>(particleType_))).append("]"); 218 str.append("config: [").append(config_.ToString()).append("]"); 219 str.append("count: [").append(std::to_string(count_)).append("]"); 220 str.append("lifeTime: [").append(lifeTime_.has_value() ? std::to_string(lifeTime_.value()) : "NA").append("]"); 221 str.append("lifeTimeRange: [") 222 .append(lifeTimeRange_.has_value() ? std::to_string(lifeTimeRange_.value()) : "NA") 223 .append("]"); 224 return str; 225 } 226 227 private: 228 ParticleType particleType_; 229 ParticleConfig config_; 230 int32_t count_ = DEFAULT_PARTICLE_COUNT; 231 std::optional<int64_t> lifeTime_; 232 std::optional<int64_t> lifeTimeRange_; 233 }; 234 235 struct EmitterOption { 236 public: GetParticleEmitterOption237 const Particle& GetParticle() const 238 { 239 return particle_; 240 } SetParticleEmitterOption241 void SetParticle(Particle& particle) 242 { 243 particle_ = particle; 244 } SetEmitterRateEmitterOption245 void SetEmitterRate(int32_t emitterRate) 246 { 247 emitterRate_ = emitterRate; 248 } 249 GetEmitterRateEmitterOption250 const std::optional<int32_t>& GetEmitterRate() const 251 { 252 return emitterRate_; 253 } 254 SetPositionEmitterOption255 void SetPosition(std::pair<Dimension, Dimension>& point) 256 { 257 position_ = point; 258 } 259 GetPositionEmitterOption260 const std::optional<std::pair<Dimension, Dimension>>& GetPosition() const 261 { 262 return position_; 263 } 264 SetSizeEmitterOption265 void SetSize(std::pair<Dimension, Dimension>& size) 266 { 267 size_ = size; 268 } 269 GetSizeEmitterOption270 const std::optional<std::pair<Dimension, Dimension>>& GetSize() const 271 { 272 return size_; 273 } 274 SetShapeEmitterOption275 void SetShape(ParticleEmitterShape& shape) 276 { 277 shape_ = shape; 278 } 279 GetShapeEmitterOption280 const std::optional<ParticleEmitterShape>& GetShape() const 281 { 282 return shape_; 283 } 284 285 bool operator==(const EmitterOption& other) const 286 { 287 return particle_ == other.GetParticle() && emitterRate_ == other.GetEmitterRate() && 288 position_ == other.GetPosition() && size_ == other.GetSize() && shape_ == other.GetShape(); 289 } 290 ToStringEmitterOption291 std::string ToString() const 292 { 293 std::string str; 294 str.append("particle: [").append(particle_.ToString()).append("]"); 295 str.append("emitterRate: [") 296 .append(emitterRate_.has_value() ? std::to_string(emitterRate_.value()) : "NA") 297 .append("]"); 298 if (position_.has_value()) { 299 str.append("position: [") 300 .append(position_->first.ToString()) 301 .append(",") 302 .append(position_->second.ToString()) 303 .append("]"); 304 } else { 305 str.append("position: [").append("NA").append("]"); 306 } 307 if (size_.has_value()) { 308 str.append("size: [") 309 .append(size_->first.ToString()) 310 .append(",") 311 .append(size_->second.ToString()) 312 .append("]"); 313 } else { 314 str.append("size: [").append("NA").append("]"); 315 } 316 str.append("shape: [") 317 .append(shape_.has_value() ? std::to_string(static_cast<int32_t>(shape_.value())) : "NA") 318 .append("]"); 319 return str; 320 } 321 322 private: 323 Particle particle_; 324 std::optional<int32_t> emitterRate_; 325 std::optional<std::pair<Dimension, Dimension>> position_; 326 std::optional<std::pair<Dimension, Dimension>> size_; 327 std::optional<ParticleEmitterShape> shape_; 328 }; 329 330 struct ParticleFloatPropertyUpdaterConfig { 331 public: SetRandomConfigParticleFloatPropertyUpdaterConfig332 void SetRandomConfig(const std::pair<float, float>& randomConfig) 333 { 334 randomConfig_ = randomConfig; 335 } 336 GetRandomConfigParticleFloatPropertyUpdaterConfig337 const std::pair<float, float>& GetRandomConfig() const 338 { 339 return randomConfig_; 340 } 341 SetAnimationsParticleFloatPropertyUpdaterConfig342 void SetAnimations(const std::list<ParticlePropertyAnimation<float>>& animations) 343 { 344 animations_ = animations; 345 } 346 GetAnimationsParticleFloatPropertyUpdaterConfig347 const std::list<ParticlePropertyAnimation<float>>& GetAnimations() const 348 { 349 return animations_; 350 } 351 SetNullStrParticleFloatPropertyUpdaterConfig352 void SetNullStr(const std::string noneValue) 353 { 354 noneValue_ = noneValue; 355 } 356 GetNullStrParticleFloatPropertyUpdaterConfig357 const std::string& GetNullStr() const 358 { 359 return noneValue_; 360 } 361 362 bool operator==(const ParticleFloatPropertyUpdaterConfig& other) const 363 { 364 return (noneValue_ == other.GetNullStr()) && NearEqual(randomConfig_.first, other.GetRandomConfig().first) && 365 NearEqual(randomConfig_.second, other.GetRandomConfig().second) && 366 (animations_ == other.GetAnimations()); 367 } 368 ToStringParticleFloatPropertyUpdaterConfig369 std::string ToString() const 370 { 371 std::string str; 372 str.append("noneValue: [").append(noneValue_).append("]"); 373 str.append("randomConfig: [") 374 .append(std::to_string(randomConfig_.first)) 375 .append(",") 376 .append(std::to_string(randomConfig_.second)) 377 .append("]"); 378 if (animations_.size() > 0) { 379 str.append("animations: ["); 380 for (auto& item : animations_) { 381 str.append("{").append(item.ToString()).append("}"); 382 } 383 str.append("]"); 384 } else { 385 str.append("animations: [").append("]"); 386 } 387 return str; 388 } 389 390 private: 391 std::string noneValue_; 392 std::pair<float, float> randomConfig_; 393 std::list<ParticlePropertyAnimation<float>> animations_; 394 }; 395 396 struct ParticleFloatPropertyUpdater { 397 public: GetUpdaterTypeParticleFloatPropertyUpdater398 const UpdaterType& GetUpdaterType() const 399 { 400 return updaterType_; 401 } 402 SetUpdaterTypeParticleFloatPropertyUpdater403 void SetUpdaterType(const UpdaterType& updateType) 404 { 405 updaterType_ = updateType; 406 } 407 GetConfigParticleFloatPropertyUpdater408 const ParticleFloatPropertyUpdaterConfig& GetConfig() const 409 { 410 return config_; 411 } 412 SetConfigParticleFloatPropertyUpdater413 void SetConfig(const ParticleFloatPropertyUpdaterConfig& config) 414 { 415 config_ = config; 416 } 417 418 bool operator==(const ParticleFloatPropertyUpdater& other) const 419 { 420 return (updaterType_ == other.GetUpdaterType()) && (config_ == other.GetConfig()); 421 } 422 ToStringParticleFloatPropertyUpdater423 std::string ToString() const 424 { 425 std::string str; 426 str.append("updaterType: [").append(std::to_string(static_cast<int32_t>(updaterType_))).append("]"); 427 str.append("config: [").append(config_.ToString()).append("]"); 428 return str; 429 } 430 431 private: 432 UpdaterType updaterType_ = UpdaterType::NONE_UPDATER; 433 ParticleFloatPropertyUpdaterConfig config_; 434 }; 435 436 struct ParticleFloatPropertyOption { 437 public: GetRangeParticleFloatPropertyOption438 const std::pair<float, float>& GetRange() const 439 { 440 return range_; 441 } 442 SetRangeParticleFloatPropertyOption443 void SetRange(const std::pair<float, float>& range) 444 { 445 range_ = range; 446 } 447 GetUpdaterParticleFloatPropertyOption448 const std::optional<ParticleFloatPropertyUpdater>& GetUpdater() const 449 { 450 return updater_; 451 } 452 SetUpdaterParticleFloatPropertyOption453 void SetUpdater(const ParticleFloatPropertyUpdater& updater) 454 { 455 updater_ = updater; 456 } 457 458 bool operator==(const ParticleFloatPropertyOption& other) const 459 { 460 return NearEqual(range_.first, other.GetRange().first) && NearEqual(range_.second, other.GetRange().second) && 461 (updater_ == other.GetUpdater()); 462 } 463 ToStringParticleFloatPropertyOption464 std::string ToString() const 465 { 466 std::string str; 467 str.append("range: [") 468 .append(std::to_string(range_.first)) 469 .append(",") 470 .append(std::to_string(range_.second)) 471 .append("]"); 472 str.append("updater: [").append(updater_.has_value() ? updater_->ToString() : "NA").append("]"); 473 return str; 474 } 475 476 private: 477 std::pair<float, float> range_; 478 std::optional<ParticleFloatPropertyUpdater> updater_; 479 }; 480 481 struct ColorParticleRandomUpdateConfig { 482 public: GetRedRandomColorParticleRandomUpdateConfig483 const std::pair<float, float>& GetRedRandom() const 484 { 485 return redRandom_; 486 } 487 SetRedRandomColorParticleRandomUpdateConfig488 void SetRedRandom(const std::pair<float, float>& redRandom) 489 { 490 redRandom_ = redRandom; 491 } 492 GetGreenRandomColorParticleRandomUpdateConfig493 const std::pair<float, float>& GetGreenRandom() const 494 { 495 return greenRandom_; 496 } 497 SetGreenRandomColorParticleRandomUpdateConfig498 void SetGreenRandom(const std::pair<float, float>& greenRandom) 499 { 500 greenRandom_ = greenRandom; 501 } 502 GetBlueRandomColorParticleRandomUpdateConfig503 const std::pair<float, float>& GetBlueRandom() const 504 { 505 return blueRandom_; 506 } 507 SetBlueRandomColorParticleRandomUpdateConfig508 void SetBlueRandom(const std::pair<float, float>& blueRandom) 509 { 510 blueRandom_ = blueRandom; 511 } 512 GetAlphaRandomColorParticleRandomUpdateConfig513 const std::pair<float, float>& GetAlphaRandom() const 514 { 515 return alphaRandom_; 516 } 517 SetAlphaRandomColorParticleRandomUpdateConfig518 void SetAlphaRandom(const std::pair<float, float>& alphaRandom) 519 { 520 alphaRandom_ = alphaRandom; 521 } 522 523 bool operator==(const ColorParticleRandomUpdateConfig& other) const 524 { 525 return NearEqual(redRandom_.first, other.GetRedRandom().first) && 526 NearEqual(redRandom_.second, other.GetRedRandom().second) && 527 NearEqual(greenRandom_.first, other.GetGreenRandom().first) && 528 NearEqual(greenRandom_.second, other.GetGreenRandom().second) && 529 NearEqual(blueRandom_.first, other.GetBlueRandom().first) && 530 NearEqual(blueRandom_.second, other.GetBlueRandom().second) && 531 NearEqual(alphaRandom_.first, other.GetAlphaRandom().first) && 532 NearEqual(alphaRandom_.second, other.GetAlphaRandom().second); 533 } 534 ToStringColorParticleRandomUpdateConfig535 std::string ToString() const 536 { 537 std::string str; 538 str.append("redRandom: [") 539 .append(std::to_string(redRandom_.first)) 540 .append(",") 541 .append(std::to_string(redRandom_.second)) 542 .append("]"); 543 str.append("greenRandom: [") 544 .append(std::to_string(greenRandom_.first)) 545 .append(",") 546 .append(std::to_string(greenRandom_.second)) 547 .append("]"); 548 str.append("blueRandom: [") 549 .append(std::to_string(blueRandom_.first)) 550 .append(",") 551 .append(std::to_string(blueRandom_.second)) 552 .append("]"); 553 str.append("alphaRandom: [") 554 .append(std::to_string(alphaRandom_.first)) 555 .append(",") 556 .append(std::to_string(alphaRandom_.second)) 557 .append("]"); 558 return str; 559 } 560 561 private: 562 std::pair<float, float> redRandom_; 563 std::pair<float, float> greenRandom_; 564 std::pair<float, float> blueRandom_; 565 std::pair<float, float> alphaRandom_; 566 }; 567 568 struct ParticleColorPropertyUpdaterConfig { 569 public: SetInValidParticleColorPropertyUpdaterConfig570 void SetInValid(int32_t inValid) 571 { 572 inValid_ = inValid; 573 } 574 GetInValidParticleColorPropertyUpdaterConfig575 int32_t GetInValid() const 576 { 577 return inValid_; 578 } 579 SetRandomConfigParticleColorPropertyUpdaterConfig580 void SetRandomConfig(const ColorParticleRandomUpdateConfig& randomConfig) 581 { 582 random_ = randomConfig; 583 } 584 GetRandomConfigParticleColorPropertyUpdaterConfig585 const ColorParticleRandomUpdateConfig& GetRandomConfig() const 586 { 587 return random_; 588 } 589 SetAnimationArrayParticleColorPropertyUpdaterConfig590 void SetAnimationArray(const std::list<ParticlePropertyAnimation<Color>>& animationArray) 591 { 592 animationArray_ = animationArray; 593 } 594 GetAnimationArrayParticleColorPropertyUpdaterConfig595 const std::list<ParticlePropertyAnimation<Color>>& GetAnimationArray() const 596 { 597 return animationArray_; 598 } 599 600 bool operator==(const ParticleColorPropertyUpdaterConfig& other) const 601 { 602 return (inValid_ == other.GetInValid()) && (random_ == other.GetRandomConfig()) && 603 (animationArray_ == other.GetAnimationArray()); 604 } 605 ToStringParticleColorPropertyUpdaterConfig606 std::string ToString() const 607 { 608 std::string str; 609 str.append("inValid: [").append(std::to_string(inValid_)).append("]"); 610 str.append("random: [").append(random_.ToString()).append("]"); 611 str.append("animationArray: ["); 612 if (animationArray_.size() > 0) { 613 for (auto& item : animationArray_) { 614 str.append("{").append(item.ToString()).append("}"); 615 } 616 } 617 str.append("]"); 618 return str; 619 } 620 621 private: 622 int32_t inValid_ = 0; 623 ColorParticleRandomUpdateConfig random_; 624 std::list<ParticlePropertyAnimation<Color>> animationArray_; 625 }; 626 627 struct ParticleColorPropertyUpdater { 628 public: GetUpdateTypeParticleColorPropertyUpdater629 const UpdaterType& GetUpdateType() const 630 { 631 return type_; 632 } 633 SetUpdateTypeParticleColorPropertyUpdater634 void SetUpdateType(UpdaterType type) 635 { 636 type_ = type; 637 } 638 GetConfigParticleColorPropertyUpdater639 const ParticleColorPropertyUpdaterConfig& GetConfig() const 640 { 641 return config_; 642 } 643 SetConfigParticleColorPropertyUpdater644 void SetConfig(const ParticleColorPropertyUpdaterConfig& config) 645 { 646 config_ = config; 647 } 648 649 bool operator==(const ParticleColorPropertyUpdater& other) const 650 { 651 return (type_ == other.GetUpdateType()) && (config_ == other.GetConfig()); 652 } 653 ToStringParticleColorPropertyUpdater654 std::string ToString() const 655 { 656 std::string str; 657 str.append("type: [").append(std::to_string(static_cast<int32_t>(type_))).append("]"); 658 str.append("config: [").append(config_.ToString()).append("]"); 659 return str; 660 } 661 662 private: 663 UpdaterType type_ = UpdaterType::NONE_UPDATER; 664 ParticleColorPropertyUpdaterConfig config_; 665 }; 666 667 struct ParticleColorPropertyOption { 668 public: GetRangeParticleColorPropertyOption669 const std::pair<Color, Color>& GetRange() const 670 { 671 return range_; 672 } SetRangeParticleColorPropertyOption673 void SetRange(std::pair<Color, Color>& range) 674 { 675 range_ = range; 676 } GetDistributionParticleColorPropertyOption677 const std::optional<DistributionType>& GetDistribution() const 678 { 679 return distribution_; 680 } SetDistributionParticleColorPropertyOption681 void SetDistribution(DistributionType& distribution) 682 { 683 distribution_ = distribution; 684 } GetUpdaterParticleColorPropertyOption685 const std::optional<ParticleColorPropertyUpdater>& GetUpdater() const 686 { 687 return updater_; 688 } SetUpdaterParticleColorPropertyOption689 void SetUpdater(ParticleColorPropertyUpdater& updater) 690 { 691 updater_ = updater; 692 } 693 694 bool operator==(const ParticleColorPropertyOption& other) const 695 { 696 return (range_ == other.GetRange()) && (updater_ == other.GetUpdater()) && 697 (distribution_ == other.GetDistribution()); 698 } 699 ToStringParticleColorPropertyOption700 std::string ToString() const 701 { 702 std::string str; 703 str.append("range: [") 704 .append(range_.first.ColorToString()) 705 .append(",") 706 .append(range_.second.ColorToString()) 707 .append("]"); 708 str.append("config: [").append(updater_.has_value() ? updater_->ToString() : "NA").append("]"); 709 return str; 710 } 711 712 private: 713 std::pair<Color, Color> range_; 714 std::optional<DistributionType> distribution_; 715 std::optional<ParticleColorPropertyUpdater> updater_; 716 }; 717 718 struct VelocityProperty { 719 public: GetSpeedRangeVelocityProperty720 const std::pair<float, float>& GetSpeedRange() const 721 { 722 return speed_; 723 } SetSpeedRangeVelocityProperty724 void SetSpeedRange(std::pair<float, float>& speed) 725 { 726 speed_ = speed; 727 } GetAngleRangeVelocityProperty728 const std::pair<float, float>& GetAngleRange() const 729 { 730 return angle_; 731 } SetAngleRangeVelocityProperty732 void SetAngleRange(std::pair<float, float>& angle) 733 { 734 angle_ = angle; 735 } 736 737 bool operator==(const VelocityProperty& other) const 738 { 739 return NearEqual(speed_.first, other.GetSpeedRange().first) && 740 NearEqual(speed_.second, other.GetSpeedRange().second) && 741 NearEqual(angle_.first, other.GetAngleRange().first) && 742 NearEqual(angle_.second, other.GetAngleRange().second); 743 } 744 ToStringVelocityProperty745 std::string ToString() const 746 { 747 std::string str; 748 str.append("speed: [") 749 .append(std::to_string(speed_.first)) 750 .append(",") 751 .append(std::to_string(speed_.second)) 752 .append("]"); 753 str.append("angle: [") 754 .append(std::to_string(angle_.first)) 755 .append(",") 756 .append(std::to_string(angle_.second)) 757 .append("]"); 758 return str; 759 } 760 761 private: 762 std::pair<float, float> speed_; 763 std::pair<float, float> angle_; 764 }; 765 766 struct AccelerationProperty { 767 public: GetSpeedAccelerationProperty768 const std::optional<ParticleFloatPropertyOption>& GetSpeed() const 769 { 770 return speed_; 771 } 772 SetSpeedAccelerationProperty773 void SetSpeed(const ParticleFloatPropertyOption& speed) 774 { 775 speed_ = speed; 776 } 777 GetAngleAccelerationProperty778 const std::optional<ParticleFloatPropertyOption>& GetAngle() const 779 { 780 return angle_; 781 } 782 SetAngleAccelerationProperty783 void SetAngle(ParticleFloatPropertyOption& angle) 784 { 785 angle_ = angle; 786 } 787 788 bool operator==(const AccelerationProperty& other) const 789 { 790 return (speed_ == other.GetSpeed()) && (angle_ == other.GetAngle()); 791 } 792 ToStringAccelerationProperty793 std::string ToString() const 794 { 795 std::string str; 796 str.append("speed: [").append(speed_.has_value() ? speed_->ToString() : "NA").append("]"); 797 str.append("angle: [").append(angle_.has_value() ? angle_->ToString() : "NA").append("]"); 798 return str; 799 } 800 801 private: 802 std::optional<ParticleFloatPropertyOption> speed_; 803 std::optional<ParticleFloatPropertyOption> angle_; 804 }; 805 806 struct ParticleOption { 807 public: 808 GetEmitterOptionParticleOption809 const EmitterOption& GetEmitterOption() const 810 { 811 return emitter_; 812 } 813 SetEmitterOptionParticleOption814 void SetEmitterOption(EmitterOption& emitter) 815 { 816 emitter_ = emitter; 817 } 818 GetParticleColorOptionParticleOption819 const std::optional<ParticleColorPropertyOption>& GetParticleColorOption() const 820 { 821 return colorOption_; 822 } 823 SetParticleColorOptionParticleOption824 void SetParticleColorOption(const ParticleColorPropertyOption& colorOption) 825 { 826 colorOption_ = colorOption; 827 } 828 GetParticleOpacityOptionParticleOption829 const std::optional<ParticleFloatPropertyOption>& GetParticleOpacityOption() const 830 { 831 return opacityOption_; 832 } 833 SetParticleOpacityOptionParticleOption834 void SetParticleOpacityOption(ParticleFloatPropertyOption& opacityOption) 835 { 836 opacityOption_ = opacityOption; 837 } 838 GetParticleScaleOptionParticleOption839 const std::optional<ParticleFloatPropertyOption>& GetParticleScaleOption() const 840 { 841 return scaleOption_; 842 } 843 SetParticleScaleOptionParticleOption844 void SetParticleScaleOption(ParticleFloatPropertyOption& scaleOption) 845 { 846 scaleOption_ = scaleOption; 847 } 848 GetParticleVelocityOptionParticleOption849 const std::optional<VelocityProperty>& GetParticleVelocityOption() const 850 { 851 return velocityOption_; 852 } 853 SetParticleVelocityOptionParticleOption854 void SetParticleVelocityOption(VelocityProperty& velocityOption) 855 { 856 velocityOption_ = velocityOption; 857 } 858 GetParticleAccelerationOptionParticleOption859 const std::optional<AccelerationProperty>& GetParticleAccelerationOption() const 860 { 861 return accelerationOption_; 862 } 863 SetParticleAccelerationOptionParticleOption864 void SetParticleAccelerationOption(AccelerationProperty& accelerationOption) 865 { 866 accelerationOption_ = accelerationOption; 867 } 868 GetParticleSpinOptionParticleOption869 const std::optional<ParticleFloatPropertyOption>& GetParticleSpinOption() const 870 { 871 return spinOption_; 872 } 873 SetParticleSpinOptionParticleOption874 void SetParticleSpinOption(ParticleFloatPropertyOption& spinOption) 875 { 876 spinOption_ = spinOption; 877 } 878 879 bool operator==(const ParticleOption& other) const 880 { 881 return (emitter_ == other.GetEmitterOption()) && (colorOption_ == other.GetParticleColorOption()) && 882 (opacityOption_ == other.GetParticleOpacityOption()) && 883 (scaleOption_ == other.GetParticleScaleOption()) && 884 (velocityOption_ == other.GetParticleVelocityOption()) && 885 (accelerationOption_ == other.GetParticleAccelerationOption()) && 886 (spinOption_ == other.GetParticleSpinOption()); 887 } 888 ToStringParticleOption889 std::string ToString() const 890 { 891 std::string str; 892 str.append("emitter: [").append(emitter_.ToString()).append("]"); 893 str.append("colorOption: [").append(colorOption_.has_value() ? colorOption_->ToString() : "NA").append("]"); 894 str.append("opacityOption: [") 895 .append(opacityOption_.has_value() ? opacityOption_->ToString() : "NA") 896 .append("]"); 897 str.append("scaleOption: [").append(scaleOption_.has_value() ? scaleOption_->ToString() : "NA").append("]"); 898 str.append("velocityOption: [") 899 .append(velocityOption_.has_value() ? velocityOption_->ToString() : "NA") 900 .append("]"); 901 str.append("accelerationOption: [") 902 .append(accelerationOption_.has_value() ? accelerationOption_->ToString() : "NA") 903 .append("]"); 904 str.append("spinOption: [").append(spinOption_.has_value() ? spinOption_->ToString() : "NA").append("]"); 905 return str; 906 } 907 908 private: 909 EmitterOption emitter_; 910 std::optional<ParticleColorPropertyOption> colorOption_; 911 std::optional<ParticleFloatPropertyOption> opacityOption_; 912 std::optional<ParticleFloatPropertyOption> scaleOption_; 913 std::optional<VelocityProperty> velocityOption_; 914 std::optional<AccelerationProperty> accelerationOption_; 915 std::optional<ParticleFloatPropertyOption> spinOption_; 916 }; 917 } // namespace OHOS::Ace::NG 918 #endif