1 /*
2  * Copyright (c) 2022-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_PATTERN_CALENDAR_CALENDAR_PAINT_METHOD_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_CALENDAR_CALENDAR_PAINT_METHOD_H
18 
19 #include <utility>
20 
21 #include "base/geometry/offset.h"
22 #include "base/memory/ace_type.h"
23 #include "base/utils/macros.h"
24 #include "core/components/calendar/calendar_data_adapter.h"
25 #include "core/components/calendar/calendar_theme.h"
26 #include "core/components_ng/pattern/calendar/calendar_paint_property.h"
27 #include "core/components_ng/render/canvas_image.h"
28 #include "core/components_ng/render/drawing.h"
29 #include "core/components_ng/render/node_paint_method.h"
30 
31 namespace OHOS::Ace::NG {
32 
33 class CalendarPaintMethod : public NodePaintMethod {
DECLARE_ACE_TYPE(CalendarPaintMethod,NodePaintMethod)34     DECLARE_ACE_TYPE(CalendarPaintMethod, NodePaintMethod)
35 
36 public:
37     CalendarPaintMethod(ObtainedMonth& obtainedMonth, CalendarDay& calendarDay, bool isCalendarDialog = false)
38         : obtainedMonth_(obtainedMonth), calendarDay_(calendarDay), isCalendarDialog_(isCalendarDialog) {};
39     ~CalendarPaintMethod() override = default;
40 
41     CanvasDrawFunction GetContentDrawFunction(PaintWrapper* paintWrapper) override;
42 
43 private:
44     void DrawWeekAndDates(RSCanvas& canvas, Offset offset);
45     void DrawWeek(RSCanvas& canvas, const Offset& offset) const;
46     void DrawDates(RSCanvas& canvas, const Offset& offset);
47     void SetCalendarTheme(const RefPtr<CalendarPaintProperty>& paintProperty);
48     void DrawCalendar(RSCanvas& canvas, const Offset& offset, const Offset& dayOffset, const CalendarDay& day);
49     void DrawTodayArea(RSCanvas& canvas, const Offset& offset, double x, double y) const;
50     void DrawFocusedArea(RSCanvas& canvas, const Offset& offset, double x, double y) const;
51     void DrawCalendarPickerBackgroundArea(const CalendarDay& day, RSCanvas& canvas, double x, double y) const;
52     void InitTextStyle(RSTextStyle& dateTextStyle, RSTextStyle& lunarTextStyle);
53     void SetDayTextStyle(RSTextStyle& dateTextStyle, RSTextStyle& lunarTextStyle, const CalendarDay& day);
54     void SetCalendarPickerDayTextStyle(RSTextStyle& dateTextStyle, const CalendarDay& day);
55     void SetOffWorkTextStyle(RSTextStyle& offWorkTextStyle, const CalendarDay& day) const;
56     void PaintDay(RSCanvas& canvas, const Offset& offset, const CalendarDay& day, RSTextStyle& textStyle) const;
57     void PaintLunarDay(
58         RSCanvas& canvas, const Offset& offset, const CalendarDay& day, const RSTextStyle& textStyle) const;
59     void PaintContent(RSCanvas& canvas, const RefPtr<CalendarPaintProperty>& paintProperty);
60     bool IsOffDay(const CalendarDay& dayInfo) const;
61     bool IsToday(const CalendarDay& day) const;
62 
63     Offset offset_;
64     std::string offDays_ = "5,6";
65     ObtainedMonth obtainedMonth_;
66     CalendarDay calendarDay_;
67     std::vector<std::string> weekNumbers_;
68     std::vector<CalendarDay> calendarDays_;
69     CalendarMonth currentMonth_;
70     TextDirection textDirection_ = TextDirection::LTR;
71     bool showHoliday_ = true;
72     bool showLunar_ = false;
73     bool isCalendarDialog_ = false;
74     int32_t startOfWeek_ = 64;
75 
76     // Default it exists 5 weeks in a month.
77     int32_t rowCount_ = 5;
78 
79     // Day style
80     double dayWidth_ = 0.0;
81     double dayHeight_ = 0.0;
82     double dayFontSize_ = 0.0;
83 
84     // Week style
85     double weekWidth_ = 0.0;
86     double weekHeight_ = 0.0;
87     double weekFontSize_ = 0.0;
88 
89     double lunarDayFontSize_ = 0.0;
90     double workDayMarkSize_ = 0.0;
91     double offDayMarkSize_ = 0.0;
92     double focusedAreaRadius_ = 0.0;
93     double topPadding_ = 0.0;
94     double weekAndDayRowSpace_ = 0.0;
95 
96     double workStateWidth_ = 0.0;
97     double workStateHorizontalMovingDistance_ = 0.0;
98     double workStateVerticalMovingDistance_ = 0.0;
99     double touchCircleStrokeWidth_ = 0.0;
100 
101     // GregorianDay YAxis Offset and Height.
102     double gregorianDayYAxisOffset_ = 0.0;
103     double gregorianDayHeight_ = 0.0;
104 
105     // LunarDay YAxis Offset and Height.
106     double lunarDayYAxisOffset_ = 0.0;
107     double lunarDayHeight_ = 0.0;
108 
109     // Space for days of calendar, when the days cross 5 weeks, it needs 6 rows.
110     // So use dailyFiveRowSpace_ for 5 rows and dailySixRowSpace_ for 6 rows.
111     // The column is always 7 from Monday to Sunday. So just set colSpace_.
112     double colSpace_ = 0.0;
113     double dailyFourRowSpace_ = 0.0;
114     double dailyFiveRowSpace_ = 0.0;
115     double dailySixRowSpace_ = 0.0;
116 
117     double dayRadius_ = 0.0;
118 
119     double calendarDayKeyFocusedWidth_ = 0.0;
120     double calendarDayKeyFocusedPenWidth_ = 0.0;
121 
122     RSColor weekColor_;
123     RSColor dayColor_;
124     RSColor lunarColor_;
125     RSColor weekendDayColor_;
126     RSColor weekendLunarColor_;
127     RSColor todayDayColor_;
128     RSColor todayLunarColor_;
129     RSColor nonCurrentMonthDayColor_;
130     RSColor nonCurrentMonthLunarColor_;
131     RSColor workDayMarkColor_;
132     RSColor offDayMarkColor_;
133     RSColor nonCurrentMonthWorkDayMarkColor_;
134     RSColor nonCurrentMonthOffDayMarkColor_;
135     RSColor focusedDayColor_;
136     RSColor focusedLunarColor_;
137     RSColor focusedAreaBackgroundColor_;
138     RSColor markLunarColor_;
139     RSColor textNonCurrentMonthColor_;
140     RSColor textSelectedDayColor_;
141     RSColor textCurrentDayColor_;
142     RSColor textCurrentMonthColor_;
143     RSColor backgroundKeyFocusedColor_;
144     RSColor backgroundSelectedTodayColor_;
145     RSColor backgroundSelectedNotTodayColor_;
146     RSColor backgroundHoverColor_;
147     RSColor backgroundPressColor_;
148     FontWeight dayFontWeight_ = FontWeight::W500;
149     FontWeight lunarDayFontWeight_ = FontWeight::W500;
150     FontWeight workStateFontWeight_ = FontWeight::W400;
151     SizeF frameSize_;
152 
153     std::vector<std::string> appFontFamilies_;
154 
155     ACE_DISALLOW_COPY_AND_MOVE(CalendarPaintMethod);
156 };
157 } // namespace OHOS::Ace::NG
158 
159 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_CALENDAR_CALENDAR_PAINT_METHOD_H
160