1 /* 2 * Copyright (c) 2021-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_BUTTON_ROSEN_RENDER_BUTTON_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BUTTON_ROSEN_RENDER_BUTTON_H 18 19 #ifndef USE_ROSEN_DRAWING 20 #include "include/core/SkCanvas.h" 21 #include "include/core/SkPoint.h" 22 #else 23 #include "core/components_ng/render/drawing.h" 24 #endif 25 26 #include "core/components/button/render_button.h" 27 28 namespace OHOS::Ace { 29 30 class RosenRenderButton : public RenderButton { 31 DECLARE_ACE_TYPE(RosenRenderButton, RenderButton); 32 33 public: 34 RosenRenderButton() = default; 35 ~RosenRenderButton() override = default; 36 37 bool HasEffectiveTransform() const override; 38 void Paint(RenderContext& context, const Offset& offset) override; 39 void PerformLayout() override; 40 41 private: 42 Size Measure() override; 43 void SyncFocusGeometryProperties(); 44 void UpdateLayer(); 45 void PaintButtonAnimation(); 46 void MeasureButtonSize(); 47 void MeasureCircle(); 48 void MeasureCapsule(); 49 void ResetBoxRadius(); 50 #ifndef USE_ROSEN_DRAWING 51 void PaintLayer(SkCanvas* canvas); 52 void DrawShape(SkCanvas* canvas, const Offset& offset, bool isStroke = false); 53 void DrawArc(SkCanvas* canvas, const Offset& offset); 54 void DrawLineProgress(SkCanvas* canvas, const Offset& offset); 55 void DrawLineProgressAnimation(SkCanvas* canvas, const Offset& offset); 56 void DrawCircleProgress(SkCanvas* canvas, const Offset& offset); 57 void DrawDownloadButton(SkCanvas* canvas, const Offset& offset); 58 void DrawButton(SkCanvas* canvas, const Offset& offset); 59 void ConvertToSkVector(const std::array<Radius, 4>& radii, SkVector* skRadii); 60 #else 61 void PaintLayer(RSCanvas* canvas); 62 void DrawShape(RSCanvas* canvas, const Offset& offset, bool isStroke = false); 63 void DrawArc(RSCanvas* canvas, const Offset& offset); 64 void DrawLineProgress(RSCanvas* canvas, const Offset& offset); 65 void DrawLineProgressAnimation(RSCanvas* canvas, const Offset& offset); 66 void DrawCircleProgress(RSCanvas* canvas, const Offset& offset); 67 void DrawDownloadButton(RSCanvas* canvas, const Offset& offset); 68 void DrawButton(RSCanvas* canvas, const Offset& offset); 69 void ConvertToVector(const std::array<Radius, 4>& radii, std::vector<RSPoint>& pRadii); 70 #endif 71 void PaintFocus(RenderContext& context, const Offset& offset); 72 void PaintPopupFocus(RenderContext& context); 73 uint32_t GetStateColor(); 74 bool NeedClickedColor(const Color& backgroundColor); 75 76 #ifndef USE_ROSEN_DRAWING 77 SkVector radii_[4] = { { 0.0, 0.0 }, { 0.0, 0.0 }, { 0.0, 0.0 }, { 0.0, 0.0 } }; 78 #else 79 std::vector<RSPoint> radii_ = { { 0.0, 0.0 }, { 0.0, 0.0 }, { 0.0, 0.0 }, { 0.0, 0.0 } }; 80 #endif 81 Matrix4 transformLayer_ = Matrix4::CreateIdentity(); 82 float opacityLayer_ = 1.0f; 83 }; 84 85 } // namespace OHOS::Ace 86 87 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BUTTON_ROSEN_RENDER_BUTTON_H 88