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_CALENDAR_ROSEN_RENDER_CALENDAR_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CALENDAR_ROSEN_RENDER_CALENDAR_H 18 19 #ifndef USE_ROSEN_DRAWING 20 #ifndef USE_GRAPHIC_TEXT_GINE 21 #include "include/core/SkCanvas.h" 22 #include "include/core/SkColor.h" 23 #else 24 #include "third_party/skia/include/core/SkCanvas.h" 25 #include "third_party/skia/include/core/SkColor.h" 26 #endif 27 #endif 28 29 #ifndef USE_GRAPHIC_TEXT_GINE 30 #include "third_party/txt/src/txt/text_style.h" 31 #else 32 #include "rosen_text/text_style.h" 33 #endif 34 35 #include "core/components/calendar/render_calendar.h" 36 #ifdef USE_ROSEN_DRAWING 37 #include "core/components_ng/render/drawing.h" 38 #endif 39 40 namespace OHOS::Rosen { 41 class DrawCmdList; 42 } 43 namespace OHOS::Ace { 44 45 class ScopedCanvas; 46 47 class RosenRenderCalendar : public RenderCalendar { 48 DECLARE_ACE_TYPE(RosenRenderCalendar, RenderCalendar); 49 50 public: 51 RosenRenderCalendar() = default; 52 ~RosenRenderCalendar() override = default; 53 54 void Update(const RefPtr<Component>& component) override; 55 void Paint(RenderContext& context, const Offset& offset) override; 56 void PerformLayout() override; 57 58 private: 59 #ifndef USE_ROSEN_DRAWING 60 void DrawWeekAndDates(SkCanvas* canvas, Offset offset); 61 void DrawFocusedArea(SkCanvas* canvas, const Offset& offset, const CalendarDay& day, double x, double y) const; 62 void DrawWeek(SkCanvas* canvas, const Offset& offset) const; 63 void DrawBlurArea(SkCanvas* canvas, const Offset& offset, double x, double y) const; 64 #else 65 void DrawWeekAndDates(RSCanvas* canvas, Offset offset); 66 void DrawFocusedArea( 67 RSCanvas* canvas, const Offset& offset, const CalendarDay& day, double x, double y) const; 68 void DrawWeek(RSCanvas* canvas, const Offset& offset) const; 69 void DrawBlurArea(RSCanvas* canvas, const Offset& offset, double x, double y) const; 70 #endif 71 void DrawTouchedArea(RenderContext& context, Offset offset) const; 72 #ifndef USE_ROSEN_DRAWING 73 #ifndef USE_GRAPHIC_TEXT_GINE 74 void PaintDay(SkCanvas* canvas, const Offset& offset, const CalendarDay& day, txt::TextStyle& textStyle) const; 75 void PaintLunarDay( 76 SkCanvas* canvas, const Offset& offset, const CalendarDay& day, const txt::TextStyle& textStyle) const; 77 #else 78 void PaintDay(SkCanvas* canvas, const Offset& offset, const CalendarDay& day, Rosen::TextStyle& textStyle) const; 79 void PaintLunarDay( 80 SkCanvas* canvas, const Offset& offset, const CalendarDay& day, const Rosen::TextStyle& textStyle) const; 81 #endif 82 #else 83 #ifndef USE_GRAPHIC_TEXT_GINE 84 void PaintDay( 85 RSCanvas* canvas, const Offset& offset, const CalendarDay& day, txt::TextStyle& textStyle) const; 86 void PaintLunarDay(RSCanvas* canvas, const Offset& offset, const CalendarDay& day, 87 const txt::TextStyle& textStyle) const; 88 #else 89 void PaintDay( 90 RSCanvas* canvas, const Offset& offset, const CalendarDay& day, Rosen::TextStyle& textStyle) const; 91 void PaintLunarDay(RSCanvas* canvas, const Offset& offset, const CalendarDay& day, 92 const Rosen::TextStyle& textStyle) const; 93 #endif 94 #endif 95 #ifndef USE_GRAPHIC_TEXT_GINE 96 void SetNonFocusStyle(const CalendarDay& day, txt::TextStyle& dateTextStyle, txt::TextStyle& lunarTextStyle); 97 #else 98 void SetNonFocusStyle(const CalendarDay& day, Rosen::TextStyle& dateTextStyle, Rosen::TextStyle& lunarTextStyle); 99 #endif 100 #ifndef USE_ROSEN_DRAWING 101 void DrawCardCalendar( 102 SkCanvas* canvas, const Offset& offset, const Offset& dayOffset, const CalendarDay& day, int32_t dateNumber); 103 void DrawTvCalendar( 104 SkCanvas* canvas, const Offset& offset, const Offset& dayOffset, const CalendarDay& day, int32_t dateNumber); 105 #else 106 void DrawCardCalendar(RSCanvas* canvas, const Offset& offset, const Offset& dayOffset, 107 const CalendarDay& day, int32_t dateNumber); 108 void DrawTvCalendar(RSCanvas* canvas, const Offset& offset, const Offset& dayOffset, 109 const CalendarDay& day, int32_t dateNumber); 110 #endif 111 #ifndef USE_GRAPHIC_TEXT_GINE 112 void InitTextStyle(txt::TextStyle& dateTextStyle, txt::TextStyle& lunarTextStyle); 113 #else 114 void InitTextStyle(Rosen::TextStyle& dateTextStyle, Rosen::TextStyle& lunarTextStyle); 115 #endif 116 #ifndef USE_ROSEN_DRAWING 117 void PaintUnderscore(SkCanvas* canvas, const Offset& offset, const CalendarDay& day); 118 void PaintScheduleMarker(SkCanvas* canvas, const Offset& offset, const CalendarDay& day); 119 #else 120 void PaintUnderscore(RSCanvas* canvas, const Offset& offset, const CalendarDay& day); 121 void PaintScheduleMarker(RSCanvas* canvas, const Offset& offset, const CalendarDay& day); 122 #endif 123 #ifndef USE_GRAPHIC_TEXT_GINE 124 void InitWorkStateStyle( 125 const CalendarDay& day, const Offset& offset, txt::TextStyle& workStateStyle, Rect& boxRect) const; 126 #else 127 void InitWorkStateStyle( 128 const CalendarDay& day, const Offset& offset, Rosen::TextStyle& workStateStyle, Rect& boxRect) const; 129 #endif 130 #ifndef USE_ROSEN_DRAWING 131 #ifndef USE_GRAPHIC_TEXT_GINE 132 void SetWorkStateStyle( 133 const CalendarDay& day, SkColor workColor, SkColor offColor, txt::TextStyle& workStateStyle) const; 134 #else 135 void SetWorkStateStyle( 136 const CalendarDay& day, SkColor workColor, SkColor offColor, Rosen::TextStyle& workStateStyle) const; 137 #endif 138 #else 139 #ifndef USE_GRAPHIC_TEXT_GINE 140 void SetWorkStateStyle(const CalendarDay& day, RSColorQuad workColor, 141 RSColorQuad offColor, txt::TextStyle& workStateStyle) const; 142 #else 143 void SetWorkStateStyle(const CalendarDay& day, RSColorQuad workColor, 144 RSColorQuad offColor, Rosen::TextStyle& workStateStyle) const; 145 #endif 146 #endif 147 void SetCalendarTheme(); 148 bool IsOffDay(const CalendarDay& day) const; 149 void AddContentLayer(RenderContext& context); 150 151 bool needShrink_ = false; 152 double weekFontSize_ = 0.0; 153 double dayFontSize_ = 0.0; 154 double lunarDayFontSize_ = 0.0; 155 double workDayMarkSize_ = 0.0; 156 double offDayMarkSize_ = 0.0; 157 double focusedAreaRadius_ = 0.0; 158 double topPadding_ = 0.0; 159 double weekWidth_ = 0.0; 160 double weekAndDayRowSpace_ = 0.0; 161 double gregorianCalendarHeight_ = 0.0; 162 double workStateWidth_ = 0.0; 163 double workStateHorizontalMovingDistance_ = 0.0; 164 double workStateVerticalMovingDistance_ = 0.0; 165 double touchCircleStrokeWidth_ = 0.0; 166 167 #ifndef USE_ROSEN_DRAWING 168 SkColor weekColor_; 169 SkColor touchColor_; 170 SkColor dayColor_; 171 SkColor lunarColor_; 172 SkColor weekendDayColor_; 173 SkColor weekendLunarColor_; 174 SkColor todayDayColor_; 175 SkColor todayLunarColor_; 176 SkColor nonCurrentMonthDayColor_; 177 SkColor nonCurrentMonthLunarColor_; 178 SkColor workDayMarkColor_; 179 SkColor offDayMarkColor_; 180 SkColor nonCurrentMonthWorkDayMarkColor_; 181 SkColor nonCurrentMonthOffDayMarkColor_; 182 SkColor focusedDayColor_; 183 SkColor focusedLunarColor_; 184 SkColor focusedAreaBackgroundColor_; 185 SkColor blurAreaBackgroundColor_; 186 SkColor markLunarColor_; 187 #else 188 RSColorQuad weekColor_; 189 RSColorQuad touchColor_; 190 RSColorQuad dayColor_; 191 RSColorQuad lunarColor_; 192 RSColorQuad weekendDayColor_; 193 RSColorQuad weekendLunarColor_; 194 RSColorQuad todayDayColor_; 195 RSColorQuad todayLunarColor_; 196 RSColorQuad nonCurrentMonthDayColor_; 197 RSColorQuad nonCurrentMonthLunarColor_; 198 RSColorQuad workDayMarkColor_; 199 RSColorQuad offDayMarkColor_; 200 RSColorQuad nonCurrentMonthWorkDayMarkColor_; 201 RSColorQuad nonCurrentMonthOffDayMarkColor_; 202 RSColorQuad focusedDayColor_; 203 RSColorQuad focusedLunarColor_; 204 RSColorQuad focusedAreaBackgroundColor_; 205 RSColorQuad blurAreaBackgroundColor_; 206 RSColorQuad markLunarColor_; 207 #endif 208 209 Size lastLayoutSize_; 210 FontWeight dayFontWeight_ = FontWeight::W500; 211 FontWeight lunarDayFontWeight_ = FontWeight::W500; 212 FontWeight workStateFontWeight_ = FontWeight::W400; 213 #ifndef USE_ROSEN_DRAWING 214 std::shared_ptr<Rosen::DrawCmdList> drawCmdList_; 215 #else 216 std::shared_ptr<RSDrawCmdList> drawCmdList_; 217 #endif 218 }; 219 220 } // namespace OHOS::Ace 221 222 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CALENDAR_ROSEN_RENDER_CALENDAR_H 223