Cogs.Core
borders.h
1#ifndef LH_BORDERS_H
2#define LH_BORDERS_H
3
4#include "css_length.h"
5#include "types.h"
6
7namespace litehtml
8{
9 struct css_border
10 {
11 css_length width;
12 border_style style;
13 web_color color;
14
16 {
17 style = border_style_none;
18 }
19
20 css_border(const css_border& val)
21 {
22 width = val.width;
23 style = val.style;
24 color = val.color;
25 }
26
27 css_border& operator=(const css_border& val)
28 {
29 width = val.width;
30 style = val.style;
31 color = val.color;
32 return *this;
33 }
34 };
35
36 struct border
37 {
38 int width;
39 border_style style;
40 web_color color;
41
42 border()
43 {
44 width = 0;
45 }
46 border(const border& val)
47 {
48 width = val.width;
49 style = val.style;
50 color = val.color;
51 }
52 border(const css_border& val)
53 {
54 width = (int) val.width.val();
55 style = val.style;
56 color = val.color;
57 }
58 border& operator=(const border& val)
59 {
60 width = val.width;
61 style = val.style;
62 color = val.color;
63 return *this;
64 }
65 border& operator=(const css_border& val)
66 {
67 width = (int) val.width.val();
68 style = val.style;
69 color = val.color;
70 return *this;
71 }
72 };
73
75 {
76 int top_left_x;
77 int top_left_y;
78
79 int top_right_x;
80 int top_right_y;
81
82 int bottom_right_x;
83 int bottom_right_y;
84
85 int bottom_left_x;
86 int bottom_left_y;
87
89 {
90 top_left_x = 0;
91 top_left_y = 0;
92 top_right_x = 0;
93 top_right_y = 0;
94 bottom_right_x = 0;
95 bottom_right_y = 0;
96 bottom_left_x = 0;
97 bottom_left_y = 0;
98 }
100 {
101 top_left_x = val.top_left_x;
102 top_left_y = val.top_left_y;
103 top_right_x = val.top_right_x;
104 top_right_y = val.top_right_y;
105 bottom_right_x = val.bottom_right_x;
106 bottom_right_y = val.bottom_right_y;
107 bottom_left_x = val.bottom_left_x;
108 bottom_left_y = val.bottom_left_y;
109 }
110 border_radiuses& operator = (const border_radiuses& val)
111 {
112 top_left_x = val.top_left_x;
113 top_left_y = val.top_left_y;
114 top_right_x = val.top_right_x;
115 top_right_y = val.top_right_y;
116 bottom_right_x = val.bottom_right_x;
117 bottom_right_y = val.bottom_right_y;
118 bottom_left_x = val.bottom_left_x;
119 bottom_left_y = val.bottom_left_y;
120 return *this;
121 }
122 void operator += (const margins& mg)
123 {
124 top_left_x += mg.left;
125 top_left_y += mg.top;
126 top_right_x += mg.right;
127 top_right_y += mg.top;
128 bottom_right_x += mg.right;
129 bottom_right_y += mg.bottom;
130 bottom_left_x += mg.left;
131 bottom_left_y += mg.bottom;
132 fix_values();
133 }
134 void operator -= (const margins& mg)
135 {
136 top_left_x -= mg.left;
137 top_left_y -= mg.top;
138 top_right_x -= mg.right;
139 top_right_y -= mg.top;
140 bottom_right_x -= mg.right;
141 bottom_right_y -= mg.bottom;
142 bottom_left_x -= mg.left;
143 bottom_left_y -= mg.bottom;
144 fix_values();
145 }
146 void fix_values()
147 {
148 if (top_left_x < 0) top_left_x = 0;
149 if (top_left_y < 0) top_left_y = 0;
150 if (top_right_x < 0) top_right_x = 0;
151 if (top_right_y < 0) top_right_y = 0;
152 if (bottom_right_x < 0) bottom_right_x = 0;
153 if (bottom_right_y < 0) bottom_right_y = 0;
154 if (bottom_left_x < 0) bottom_left_x = 0;
155 if (bottom_left_y < 0) bottom_left_y = 0;
156 }
157 };
158
160 {
161 css_length top_left_x;
162 css_length top_left_y;
163
164 css_length top_right_x;
165 css_length top_right_y;
166
167 css_length bottom_right_x;
168 css_length bottom_right_y;
169
170 css_length bottom_left_x;
171 css_length bottom_left_y;
172
174 {
175
176 }
177
179 {
180 top_left_x = val.top_left_x;
181 top_left_y = val.top_left_y;
182 top_right_x = val.top_right_x;
183 top_right_y = val.top_right_y;
184 bottom_left_x = val.bottom_left_x;
185 bottom_left_y = val.bottom_left_y;
186 bottom_right_x = val.bottom_right_x;
187 bottom_right_y = val.bottom_right_y;
188 }
189
190 css_border_radius& operator=(const css_border_radius& val)
191 {
192 top_left_x = val.top_left_x;
193 top_left_y = val.top_left_y;
194 top_right_x = val.top_right_x;
195 top_right_y = val.top_right_y;
196 bottom_left_x = val.bottom_left_x;
197 bottom_left_y = val.bottom_left_y;
198 bottom_right_x = val.bottom_right_x;
199 bottom_right_y = val.bottom_right_y;
200 return *this;
201 }
202 border_radiuses calc_percents(int width, int height)
203 {
204 border_radiuses ret;
205 ret.bottom_left_x = bottom_left_x.calc_percent(width);
206 ret.bottom_left_y = bottom_left_y.calc_percent(height);
207 ret.top_left_x = top_left_x.calc_percent(width);
208 ret.top_left_y = top_left_y.calc_percent(height);
209 ret.top_right_x = top_right_x.calc_percent(width);
210 ret.top_right_y = top_right_y.calc_percent(height);
211 ret.bottom_right_x = bottom_right_x.calc_percent(width);
212 ret.bottom_right_y = bottom_right_y.calc_percent(height);
213 return ret;
214 }
215 };
216
218 {
219 css_border left;
220 css_border top;
221 css_border right;
222 css_border bottom;
223 css_border_radius radius;
224
226 {
227
228 }
229
230 css_borders(const css_borders& val)
231 {
232 left = val.left;
233 right = val.right;
234 top = val.top;
235 bottom = val.bottom;
236 radius = val.radius;
237 }
238
239 css_borders& operator=(const css_borders& val)
240 {
241 left = val.left;
242 right = val.right;
243 top = val.top;
244 bottom = val.bottom;
245 radius = val.radius;
246 return *this;
247 }
248 };
249
250 struct borders
251 {
252 border left;
253 border top;
254 border right;
255 border bottom;
256 border_radiuses radius;
257
258 borders()
259 {
260
261 }
262
263 borders(const borders& val)
264 {
265 left = val.left;
266 right = val.right;
267 top = val.top;
268 bottom = val.bottom;
269 radius = val.radius;
270 }
271
272 borders(const css_borders& val)
273 {
274 left = val.left;
275 right = val.right;
276 top = val.top;
277 bottom = val.bottom;
278 }
279
280 borders& operator=(const borders& val)
281 {
282 left = val.left;
283 right = val.right;
284 top = val.top;
285 bottom = val.bottom;
286 radius = val.radius;
287 return *this;
288 }
289
290 borders& operator=(const css_borders& val)
291 {
292 left = val.left;
293 right = val.right;
294 top = val.top;
295 bottom = val.bottom;
296 return *this;
297 }
298 };
299}
300
301#endif // LH_BORDERS_H