1 #ifndef LH_BORDERS_H
2 #define LH_BORDERS_H
3 
4 #include "css_length.h"
5 #include "types.h"
6 
7 namespace litehtml
8 {
9 	struct css_border
10 	{
11 		css_length		width;
12 		border_style	style;
13 		web_color		color;
14 
css_bordercss_border15 		css_border()
16 		{
17 			style = border_style_none;
18 		}
19 
css_bordercss_border20 		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 
borderborder42 		border()
43 		{
44 			width = 0;
45 		}
borderborder46 		border(const border& val)
47 		{
48 			width = val.width;
49 			style = val.style;
50 			color = val.color;
51 		}
borderborder52 		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 
74 	struct border_radiuses
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 
border_radiusesborder_radiuses88 		border_radiuses()
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 		}
border_radiusesborder_radiuses99 		border_radiuses(const border_radiuses& val)
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 		}
fix_valuesborder_radiuses146 		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 (bottom_right_x < 0) bottom_right_x = 0;
152 			if (bottom_right_y < 0) bottom_right_y = 0;
153 			if (bottom_left_x < 0) bottom_left_x = 0;
154 			if (bottom_left_y < 0) bottom_left_y = 0;
155 		}
156 	};
157 
158 	struct css_border_radius
159 	{
160 		css_length	top_left_x;
161 		css_length	top_left_y;
162 
163 		css_length	top_right_x;
164 		css_length	top_right_y;
165 
166 		css_length	bottom_right_x;
167 		css_length	bottom_right_y;
168 
169 		css_length	bottom_left_x;
170 		css_length	bottom_left_y;
171 
css_border_radiuscss_border_radius172 		css_border_radius()
173 		{
174 
175 		}
176 
css_border_radiuscss_border_radius177 		css_border_radius(const css_border_radius& val)
178 		{
179 			top_left_x		= val.top_left_x;
180 			top_left_y		= val.top_left_y;
181 			top_right_x		= val.top_right_x;
182 			top_right_y		= val.top_right_y;
183 			bottom_left_x	= val.bottom_left_x;
184 			bottom_left_y	= val.bottom_left_y;
185 			bottom_right_x	= val.bottom_right_x;
186 			bottom_right_y	= val.bottom_right_y;
187 		}
188 
189 		css_border_radius& operator=(const css_border_radius& val)
190 		{
191 			top_left_x		= val.top_left_x;
192 			top_left_y		= val.top_left_y;
193 			top_right_x		= val.top_right_x;
194 			top_right_y		= val.top_right_y;
195 			bottom_left_x	= val.bottom_left_x;
196 			bottom_left_y	= val.bottom_left_y;
197 			bottom_right_x	= val.bottom_right_x;
198 			bottom_right_y	= val.bottom_right_y;
199 			return *this;
200 		}
calc_percentscss_border_radius201 		border_radiuses calc_percents(int width, int height)
202 		{
203 			border_radiuses ret;
204 			ret.bottom_left_x = bottom_left_x.calc_percent(width);
205 			ret.bottom_left_y = bottom_left_y.calc_percent(height);
206 			ret.top_left_x = top_left_x.calc_percent(width);
207 			ret.top_left_y = top_left_y.calc_percent(height);
208 			ret.top_right_x = top_right_x.calc_percent(width);
209 			ret.top_right_y = top_right_y.calc_percent(height);
210 			ret.bottom_right_x = bottom_right_x.calc_percent(width);
211 			ret.bottom_right_y = bottom_right_y.calc_percent(height);
212 			return ret;
213 		}
214 	};
215 
216 	struct css_borders
217 	{
218 		css_border			left;
219 		css_border			top;
220 		css_border			right;
221 		css_border			bottom;
222 		css_border_radius	radius;
223 
css_borderscss_borders224 		css_borders()
225 		{
226 
227 		}
228 
css_borderscss_borders229 		css_borders(const css_borders& val)
230 		{
231 			left	= val.left;
232 			right	= val.right;
233 			top		= val.top;
234 			bottom	= val.bottom;
235 			radius	= val.radius;
236 		}
237 
238 		css_borders& operator=(const css_borders& val)
239 		{
240 			left	= val.left;
241 			right	= val.right;
242 			top		= val.top;
243 			bottom	= val.bottom;
244 			radius	= val.radius;
245 			return *this;
246 		}
247 	};
248 
249 	struct borders
250 	{
251 		border			left;
252 		border			top;
253 		border			right;
254 		border			bottom;
255 		border_radiuses	radius;
256 
bordersborders257 		borders()
258 		{
259 
260 		}
261 
bordersborders262 		borders(const borders& val)
263 		{
264 			left = val.left;
265 			right = val.right;
266 			top = val.top;
267 			bottom = val.bottom;
268 			radius = val.radius;
269 		}
270 
bordersborders271 		borders(const css_borders& val)
272 		{
273 			left = val.left;
274 			right = val.right;
275 			top = val.top;
276 			bottom = val.bottom;
277 		}
278 
279 		borders& operator=(const borders& val)
280 		{
281 			left = val.left;
282 			right = val.right;
283 			top = val.top;
284 			bottom = val.bottom;
285 			radius = val.radius;
286 			return *this;
287 		}
288 
289 		borders& operator=(const css_borders& val)
290 		{
291 			left = val.left;
292 			right = val.right;
293 			top = val.top;
294 			bottom = val.bottom;
295 			return *this;
296 		}
297 	};
298 }
299 
300 #endif  // LH_BORDERS_H
301