• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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_FLUTTER_RENDER_CALENDAR_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CALENDAR_FLUTTER_RENDER_CALENDAR_H
18 
19 #include "include/core/SkColor.h"
20 #include "third_party/txt/src/txt/text_style.h"
21 
22 #include "core/components/calendar/render_calendar.h"
23 #include "core/pipeline/layers/clip_layer.h"
24 #include "core/pipeline/layers/picture_layer.h"
25 
26 namespace OHOS::Ace {
27 
28 class ScopedCanvas;
29 
30 class FlutterRenderCalendar : public RenderCalendar {
31     DECLARE_ACE_TYPE(FlutterRenderCalendar, RenderCalendar);
32 
33 public:
34     FlutterRenderCalendar() = default;
35     ~FlutterRenderCalendar() override = default;
36 
37     RenderLayer GetRenderLayer() override;
38     void Update(const RefPtr<Component>& component) override;
39     void Paint(RenderContext& context, const Offset& offset) override;
40     void PerformLayout() override;
41 
42 private:
43     void DrawWeekAndDates(ScopedCanvas& canvas, Offset offset);
44     void DrawFocusedArea(ScopedCanvas& canvas, const Offset& offset, const CalendarDay& day, double x, double y) const;
45     void DrawWeek(ScopedCanvas& canvas, const Offset& offset) const;
46     void DrawBlurArea(ScopedCanvas& canvas, const Offset& offset, double x, double y) const;
47     void DrawTouchedArea(RenderContext& context, Offset offset) const;
48     void PaintDay(
49         ScopedCanvas& canvas, const Offset& offset, const CalendarDay& day, txt::TextStyle& textStyle) const;
50     void PaintLunarDay(
51         ScopedCanvas& canvas, const Offset& offset, const CalendarDay& day, const txt::TextStyle& textStyle) const;
52     void SetNonFocusStyle(const CalendarDay& day, txt::TextStyle& dateTextStyle, txt::TextStyle& lunarTextStyle);
53     void DrawCardCalendar(ScopedCanvas& canvas, const Offset& offset, const Offset& dayOffset, const CalendarDay& day,
54         int32_t dateNumber);
55     void DrawTvCalendar(ScopedCanvas& canvas, const Offset& offset, const Offset& dayOffset, const CalendarDay& day,
56         int32_t dateNumber);
57     void InitTextStyle(txt::TextStyle& dateTextStyle, txt::TextStyle& lunarTextStyle);
58     void PaintUnderscore(ScopedCanvas& canvas, const Offset& offset, const CalendarDay& day);
59     void PaintScheduleMarker(ScopedCanvas& canvas, const Offset& offset, const CalendarDay& day);
60     void InitWorkStateStyle(
61         const CalendarDay& day, const Offset& offset, txt::TextStyle& workStateStyle, Rect& boxRect) const;
62     void SetWorkStateStyle(
63         const CalendarDay& day, SkColor workColor, SkColor offColor, txt::TextStyle& workStateStyle) const;
64     void SetCalendarTheme();
65     bool IsOffDay(const CalendarDay& day) const;
66     void AddContentLayer();
67 
68     bool needShrink_ = false;
69     double weekFontSize_ = 0.0;
70     double dayFontSize_ = 0.0;
71     double lunarDayFontSize_ = 0.0;
72     double workDayMarkSize_ = 0.0;
73     double offDayMarkSize_ = 0.0;
74     double focusedAreaRadius_ = 0.0;
75     double topPadding_ = 0.0;
76     double weekWidth_ = 0.0;
77     double weekAndDayRowSpace_ = 0.0;
78     double gregorianCalendarHeight_ = 0.0;
79     double workStateWidth_ = 0.0;
80     double workStateHorizontalMovingDistance_ = 0.0;
81     double workStateVerticalMovingDistance_ = 0.0;
82     double touchCircleStrokeWidth_ = 0.0;
83 
84     SkColor weekColor_;
85     SkColor touchColor_;
86     SkColor dayColor_;
87     SkColor lunarColor_;
88     SkColor weekendDayColor_;
89     SkColor weekendLunarColor_;
90     SkColor todayDayColor_;
91     SkColor todayLunarColor_;
92     SkColor nonCurrentMonthDayColor_;
93     SkColor nonCurrentMonthLunarColor_;
94     SkColor workDayMarkColor_;
95     SkColor offDayMarkColor_;
96     SkColor nonCurrentMonthWorkDayMarkColor_;
97     SkColor nonCurrentMonthOffDayMarkColor_;
98     SkColor focusedDayColor_;
99     SkColor focusedLunarColor_;
100     SkColor focusedAreaBackgroundColor_;
101     SkColor blurAreaBackgroundColor_;
102     SkColor markLunarColor_;
103 
104     RefPtr<Flutter::ClipLayer> layer_;
105     RefPtr<Flutter::PictureLayer> contentLayer_;
106     Size lastLayoutSize_;
107     FontWeight dayFontWeight_ = FontWeight::W500;
108     FontWeight lunarDayFontWeight_ = FontWeight::W500;
109     FontWeight workStateFontWeight_ = FontWeight::W400;
110 };
111 
112 } // namespace OHOS::Ace
113 
114 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CALENDAR_FLUTTER_RENDER_CALENDAR_H
115