• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020-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 #include "gfx_utils/style.h"
17 
18 namespace OHOS {
19 Style StyleDefault::defaultStyle_;
20 Style StyleDefault::brightStyle_;
21 Style StyleDefault::brightColorStyle_;
22 Style StyleDefault::buttonReleasedStyle_;
23 Style StyleDefault::buttonPressedStyle_;
24 Style StyleDefault::buttonInactiveStyle_;
25 Style StyleDefault::labelStyle_;
26 Style StyleDefault::editTextStyle_;
27 Style StyleDefault::backgroundTransparentStyle_;
28 Style StyleDefault::progressBackgroundStyle_;
29 Style StyleDefault::progressForegroundStyle_;
30 Style StyleDefault::sliderKnobStyle_;
31 Style StyleDefault::pickerBackgroundStyle_;
32 Style StyleDefault::pickerHighlightStyle_;
33 Style StyleDefault::scrollBarBackgroundStyle_;
34 Style StyleDefault::scrollBarForegroundStyle_;
35 
Style()36 Style::Style()
37     : bgColor_(Color::Black()),
38       bgOpa_(OPA_OPAQUE),
39       borderOpa_(OPA_OPAQUE),
40       borderWidth_(0),
41       borderRadius_(0),
42       borderColor_(Color::Black()),
43       paddingLeft_(0),
44       paddingRight_(0),
45       paddingTop_(0),
46       paddingBottom_(0),
47       marginLeft_(0),
48       marginRight_(0),
49       marginTop_(0),
50       marginBottom_(0),
51       imageOpa_(OPA_OPAQUE),
52       textOpa_(OPA_OPAQUE),
53       font_(16), // 16 : default font size
54       lineSpace_(2), // 2 : default line space
55       letterSpace_(0),
56       lineHeight_(0),
57       textColor_(Color::White()),
58       lineColor_(Color::GetColorFromRGB(0x20, 0x20, 0x20)),
59       lineOpa_(OPA_OPAQUE),
60       lineCap_(CapType::CAP_NONE),
61       lineWidth_(2) // 2 : default line width
62 {
63 }
64 
GetStyle(uint8_t key) const65 int64_t Style::GetStyle(uint8_t key) const
66 {
67     switch (key) {
68         case STYLE_BACKGROUND_COLOR:
69             return bgColor_.full;
70         case STYLE_BACKGROUND_OPA:
71             return bgOpa_;
72         case STYLE_BORDER_RADIUS:
73             return borderRadius_;
74         case STYLE_BORDER_COLOR:
75             return borderColor_.full;
76         case STYLE_BORDER_OPA:
77             return borderOpa_;
78         case STYLE_BORDER_WIDTH:
79             return borderWidth_;
80         case STYLE_PADDING_LEFT:
81             return paddingLeft_;
82         case STYLE_PADDING_RIGHT:
83             return paddingRight_;
84         case STYLE_PADDING_TOP:
85             return paddingTop_;
86         case STYLE_PADDING_BOTTOM:
87             return paddingBottom_;
88         case STYLE_MARGIN_LEFT:
89             return marginLeft_;
90         case STYLE_MARGIN_RIGHT:
91             return marginRight_;
92         case STYLE_MARGIN_TOP:
93             return marginTop_;
94         case STYLE_MARGIN_BOTTOM:
95             return marginBottom_;
96         case STYLE_IMAGE_OPA:
97             return imageOpa_;
98         case STYLE_TEXT_COLOR:
99             return textColor_.full;
100         case STYLE_TEXT_FONT:
101             return font_;
102         case STYLE_LINE_SPACE:
103             return lineSpace_;
104         case STYLE_LETTER_SPACE:
105             return letterSpace_;
106         case STYLE_LINE_HEIGHT:
107             return lineHeight_;
108         case STYLE_TEXT_OPA:
109             return textOpa_;
110         case STYLE_LINE_COLOR:
111             return lineColor_.full;
112         case STYLE_LINE_WIDTH:
113             return lineWidth_;
114         case STYLE_LINE_OPA:
115             return lineOpa_;
116         case STYLE_LINE_CAP:
117             return lineCap_;
118         default:
119             return 0;
120     }
121 }
122 
SetStyle(uint8_t key,int64_t value)123 void Style::SetStyle(uint8_t key, int64_t value)
124 {
125     switch (key) {
126         case STYLE_BACKGROUND_COLOR:
127             bgColor_.full = value;
128             break;
129         case STYLE_BACKGROUND_OPA:
130             bgOpa_ = value;
131             break;
132         case STYLE_BORDER_RADIUS:
133             borderRadius_ = value;
134             break;
135         case STYLE_BORDER_COLOR:
136             borderColor_.full = value;
137             break;
138         case STYLE_BORDER_OPA:
139             borderOpa_ = value;
140             break;
141         case STYLE_BORDER_WIDTH:
142             borderWidth_ = value;
143             break;
144         case STYLE_PADDING_LEFT:
145             paddingLeft_ = value;
146             break;
147         case STYLE_PADDING_RIGHT:
148             paddingRight_ = value;
149             break;
150         case STYLE_PADDING_TOP:
151             paddingTop_ = value;
152             break;
153         case STYLE_PADDING_BOTTOM:
154             paddingBottom_ = value;
155             break;
156         case STYLE_MARGIN_LEFT:
157             marginLeft_ = value;
158             break;
159         case STYLE_MARGIN_RIGHT:
160             marginRight_ = value;
161             break;
162         case STYLE_MARGIN_TOP:
163             marginTop_ = value;
164             break;
165         case STYLE_MARGIN_BOTTOM:
166             marginBottom_ = value;
167             break;
168         case STYLE_IMAGE_OPA:
169             imageOpa_ = value;
170             break;
171         case STYLE_TEXT_COLOR:
172             textColor_.full = value;
173             break;
174         case STYLE_TEXT_FONT:
175             font_ = value;
176             break;
177         case STYLE_LINE_SPACE:
178             lineSpace_ = value;
179             break;
180         case STYLE_LETTER_SPACE:
181             letterSpace_ = value;
182             break;
183         case STYLE_LINE_HEIGHT:
184             lineHeight_ = value;
185             break;
186         case STYLE_TEXT_OPA:
187             textOpa_ = value;
188             break;
189         case STYLE_LINE_COLOR:
190             lineColor_.full = value;
191             break;
192         case STYLE_LINE_WIDTH:
193             lineWidth_ = value;
194             break;
195         case STYLE_LINE_OPA:
196             lineOpa_ = value;
197             break;
198         case STYLE_LINE_CAP:
199             lineCap_ = value;
200             break;
201         default:
202             break;
203     }
204 }
205 
Init()206 void StyleDefault::Init()
207 {
208     InitStyle();
209     InitButtonStyle();
210     InitLabelStyle();
211     InitEditTextStyle();
212     InitBackgroundTransparentStyle();
213     InitProgressStyle();
214     InitPickerStyle();
215     InitScrollBarStyle();
216 }
217 
InitStyle()218 void StyleDefault::InitStyle()
219 {
220     brightStyle_ = defaultStyle_;
221     brightStyle_.SetStyle(STYLE_BACKGROUND_COLOR, Color::White().full);
222     brightStyle_.SetStyle(STYLE_BORDER_RADIUS, 3); // 3: rect radius
223     brightStyle_.SetStyle(STYLE_BORDER_COLOR, Color::GetColorFromRGB(0x40, 0x40, 0x40).full);
224     brightStyle_.SetStyle(STYLE_BORDER_WIDTH, 3); // 3: rect border width
225     brightStyle_.SetStyle(STYLE_BORDER_OPA, 76); // 76: default opa
226     brightStyle_.SetStyle(STYLE_TEXT_COLOR, Color::GetColorFromRGB(0x20, 0x20, 0x20).full);
227     brightStyle_.SetStyle(STYLE_LINE_COLOR, Color::GetColorFromRGB(0x20, 0x20, 0x20).full);
228 
229     brightColorStyle_ = brightStyle_;
230     brightColorStyle_.SetStyle(STYLE_TEXT_COLOR, Color::GetColorFromRGB(0xe0, 0xe0, 0xe0).full);
231     brightColorStyle_.SetStyle(STYLE_LINE_COLOR, Color::GetColorFromRGB(0xc0, 0xc0, 0xc0).full);
232     brightColorStyle_.SetStyle(STYLE_BACKGROUND_COLOR, Color::GetColorFromRGB(0x6b, 0x9a, 0xc7).full);
233     brightColorStyle_.SetStyle(STYLE_BORDER_COLOR, Color::GetColorFromRGB(0x15, 0x2c, 0x42).full);
234 }
235 
InitButtonStyle()236 void StyleDefault::InitButtonStyle()
237 {
238     /* Button released style */
239     buttonReleasedStyle_ = defaultStyle_;
240     buttonReleasedStyle_.SetStyle(STYLE_BACKGROUND_COLOR, Color::GetColorFromRGB(0x00, 0x7d, 0xff).full);
241     buttonReleasedStyle_.SetStyle(STYLE_BORDER_RADIUS, 200); // 200: button radius
242     buttonReleasedStyle_.SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE);
243 
244     buttonReleasedStyle_.SetStyle(STYLE_BORDER_COLOR, Color::GetColorFromRGB(0x0b, 0x19, 0x28).full);
245     buttonReleasedStyle_.SetStyle(STYLE_BORDER_WIDTH, 0);
246     buttonReleasedStyle_.SetStyle(STYLE_BORDER_OPA, 178); // 178: default opa
247 
248     /* Button pressed style */
249     buttonPressedStyle_ = buttonReleasedStyle_;
250     buttonPressedStyle_.SetStyle(STYLE_BACKGROUND_COLOR, Color::GetColorFromRGB(0x19, 0x96, 0xff).full);
251     buttonPressedStyle_.SetStyle(STYLE_BORDER_COLOR, Color::GetColorFromRGB(0x0b, 0x19, 0x28).full);
252 
253     /* Button inactive style */
254     buttonInactiveStyle_ = buttonReleasedStyle_;
255     buttonInactiveStyle_.SetStyle(STYLE_BACKGROUND_COLOR, Color::GetColorFromRGB(0x61, 0x7e, 0x9d).full);
256     buttonInactiveStyle_.SetStyle(STYLE_BORDER_COLOR, Color::GetColorFromRGB(0x90, 0x90, 0x90).full);
257 }
258 
InitLabelStyle()259 void StyleDefault::InitLabelStyle()
260 {
261     labelStyle_ = defaultStyle_;
262     labelStyle_.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT);
263 }
264 
InitEditTextStyle()265 void StyleDefault::InitEditTextStyle()
266 {
267     editTextStyle_ = defaultStyle_;
268     editTextStyle_.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT);
269     editTextStyle_.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT);
270     editTextStyle_.SetStyle(STYLE_BORDER_COLOR, Color::White().full);
271     editTextStyle_.SetStyle(STYLE_BORDER_WIDTH, 2); // 2: border width
272     editTextStyle_.SetStyle(STYLE_BORDER_RADIUS, 5); // 5: border radius
273     editTextStyle_.SetStyle(STYLE_BORDER_OPA, OPA_OPAQUE);
274 }
275 
InitBackgroundTransparentStyle()276 void StyleDefault::InitBackgroundTransparentStyle()
277 {
278     backgroundTransparentStyle_ = defaultStyle_;
279     backgroundTransparentStyle_.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT);
280 }
281 
InitPickerStyle()282 void StyleDefault::InitPickerStyle()
283 {
284     pickerBackgroundStyle_ = defaultStyle_;
285     pickerBackgroundStyle_.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT);
286     pickerBackgroundStyle_.SetStyle(STYLE_TEXT_COLOR, Color::Gray().full);
287 
288     pickerHighlightStyle_ = defaultStyle_;
289     pickerHighlightStyle_.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT);
290     pickerHighlightStyle_.SetStyle(STYLE_TEXT_FONT, 18); // 18: font value
291     pickerHighlightStyle_.SetStyle(STYLE_TEXT_COLOR, Color::GetColorFromRGB(0x45, 0xa5, 0xff).full);
292 }
293 
InitProgressStyle()294 void StyleDefault::InitProgressStyle()
295 {
296     progressBackgroundStyle_ = defaultStyle_;
297     progressBackgroundStyle_.SetStyle(STYLE_BORDER_WIDTH, 0);
298     progressBackgroundStyle_.SetStyle(STYLE_BORDER_RADIUS, 0);
299 
300     progressForegroundStyle_ = brightStyle_;
301     progressForegroundStyle_.SetStyle(STYLE_BORDER_WIDTH, 0);
302     progressForegroundStyle_.SetStyle(STYLE_BORDER_RADIUS, 0);
303     progressForegroundStyle_.SetStyle(STYLE_LINE_COLOR, Color::GetColorFromRGB(0x45, 0xa5, 0xff).full);
304 
305     sliderKnobStyle_ = brightColorStyle_;
306     sliderKnobStyle_.SetStyle(STYLE_BORDER_WIDTH, 0);
307 }
308 
InitScrollBarStyle()309 void StyleDefault::InitScrollBarStyle()
310 {
311     scrollBarBackgroundStyle_.SetStyle(STYLE_BACKGROUND_COLOR,
312         Color::GetColorFromRGB(0x7f, 0x7f, 0x7f).full); // 0x7f: default color
313     scrollBarBackgroundStyle_.SetStyle(STYLE_BACKGROUND_OPA, 128); // 128: default opa
314     scrollBarBackgroundStyle_.SetStyle(STYLE_LINE_COLOR,
315         Color::GetColorFromRGB(0x7f, 0x7f, 0x7f).full); // 0x7f: default color
316     scrollBarBackgroundStyle_.SetStyle(STYLE_LINE_OPA, 128); // 128: default opa
317     scrollBarBackgroundStyle_.SetStyle(STYLE_LINE_WIDTH, 8); // 8: default width
318 
319     scrollBarForegroundStyle_.SetStyle(STYLE_BACKGROUND_COLOR, Color::White().full);
320     scrollBarForegroundStyle_.SetStyle(STYLE_BACKGROUND_OPA, 168); // 168: default opa
321     scrollBarForegroundStyle_.SetStyle(STYLE_LINE_COLOR, Color::White().full);
322     scrollBarForegroundStyle_.SetStyle(STYLE_LINE_OPA, 168); // 168: default opa
323     scrollBarForegroundStyle_.SetStyle(STYLE_LINE_WIDTH, 6); // 6: default width
324 }
325 } // namespace OHOS
326