1 /* 2 * Copyright (c) 2024 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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_PROPERTIES_COMMON_DECORATION_H 16 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_PROPERTIES_COMMON_DECORATION_H 17 18 #include "core/components/common/properties/color.h" 19 20 namespace OHOS::Ace { 21 enum class BlurStyle { 22 NO_MATERIAL = 0, 23 THIN, 24 REGULAR, 25 THICK, 26 BACKGROUND_THIN, 27 BACKGROUND_REGULAR, 28 BACKGROUND_THICK, 29 BACKGROUND_ULTRA_THICK, 30 COMPONENT_ULTRA_THIN, 31 COMPONENT_THIN, 32 COMPONENT_REGULAR, 33 COMPONENT_THICK, 34 COMPONENT_ULTRA_THICK, 35 }; 36 37 enum class AdaptiveColor { 38 DEFAULT = 0, 39 AVERAGE, 40 }; 41 42 enum class TransitionHierarchyStrategy { 43 NONE = 0, 44 ADAPTIVE, 45 }; 46 47 struct BlurOption { 48 std::vector<float> grayscale; 49 }; 50 51 struct EffectOption { 52 Dimension radius; 53 double saturation { 1.0f }; 54 double brightness { 1.0f }; 55 Color color { Color::TRANSPARENT }; 56 AdaptiveColor adaptiveColor = AdaptiveColor::DEFAULT; 57 BlurOption blurOption; 58 bool operator == (const EffectOption &other) const 59 { 60 return radius == other.radius && NearEqual(saturation, other.saturation) && 61 NearEqual(brightness, other.brightness) && color == other.color && adaptiveColor == other.adaptiveColor; 62 } 63 ToJsonValueEffectOption64 void ToJsonValue(std::unique_ptr<JsonValue> &json, const NG::InspectorFilter &filter) const 65 { 66 json->PutExtAttr("backgroundEffect", ToJsonValue(), filter); 67 } 68 ToJsonValueEffectOption69 std::unique_ptr<JsonValue> ToJsonValue() const 70 { 71 static const char* ADAPTIVE_COLOR[] = { "AdaptiveColor.Default", "AdaptiveColor.Average" }; 72 auto jsonEffect = JsonUtil::Create(true); 73 auto jsonBrightnessOption = JsonUtil::Create(true); 74 jsonBrightnessOption->Put("radius", radius.Value()); 75 jsonBrightnessOption->Put("saturation", saturation); 76 jsonBrightnessOption->Put("brightness", brightness); 77 jsonBrightnessOption->Put("color", color.ColorToString().c_str()); 78 jsonBrightnessOption->Put("adaptiveColor", ADAPTIVE_COLOR[static_cast<int32_t>(adaptiveColor)]); 79 auto grayscale = "[0,0]"; 80 if (blurOption.grayscale.size() > 1) { 81 grayscale = 82 ("[" + std::to_string(blurOption.grayscale[0]) + "," + std::to_string(blurOption.grayscale[1]) + "]") 83 .c_str(); 84 } 85 jsonBrightnessOption->Put("blurOption", grayscale); 86 jsonEffect->Put("options", jsonBrightnessOption); 87 return jsonEffect; 88 } 89 }; 90 } // namespace OHOS::Ace 91 92 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_PROPERTIES_COMMON_DECORATION_H