src/2d.c

changeset 214
9d460888a83e
parent 207
4d184a8706b1
child 215
a7c8e1727971
equal deleted inserted replaced
213:3d252dbd7c8e 214:9d460888a83e
26 */ 26 */
27 27
28 #include "ascension/2d.h" 28 #include "ascension/2d.h"
29 29
30 #include "ascension/constants.h" 30 #include "ascension/constants.h"
31 #include "ascension/context.h"
32 #include "ascension/error.h" 31 #include "ascension/error.h"
33 #include "ascension/shader.h" 32 #include "ascension/shader.h"
34 33
35 #include <assert.h> 34 #include <assert.h>
36 35
171 rectangle->size.width = (float) args.width; 170 rectangle->size.width = (float) args.width;
172 rectangle->size.height = (float) args.height; 171 rectangle->size.height = (float) args.height;
173 } 172 }
174 173
175 rectangle->radius = (float)args.radius; 174 rectangle->radius = (float)args.radius;
176 rectangle->color = asc_col_itof(asc_context.ink);
177 rectangle->border_color = asc_col_itof(args.border_color);
178 rectangle->filled = args.filled; 175 rectangle->filled = args.filled;
179 if (!args.filled && args.thickness == 0) { 176 if (!args.filled && args.thickness == 0) {
180 // when we do not fill the rectangle, we need a border 177 // when we do not fill the rectangle, we need a border
181 rectangle->thickness = 1; 178 rectangle->thickness = 1;
182 } else { 179 } else {
183 rectangle->thickness = args.thickness; 180 rectangle->thickness = args.thickness;
184 } 181 }
182
185 if (!args.filled && asc_memcmpz(&args.border_color, sizeof(args.border_color))) { 183 if (!args.filled && asc_memcmpz(&args.border_color, sizeof(args.border_color))) {
186 // convenience fallback: 184 // convenience fallback:
187 // when we are drawing an outline but have no explicit border color, 185 // when we are drawing an outline but have no explicit border color,
188 // use the active ink 186 // use the main color
189 rectangle->border_color = rectangle->color; 187 args.border_color = args.color;
190 } 188 }
189 rectangle->color = asc_col_itof(args.color);
190 rectangle->border_color = asc_col_itof(args.border_color);
191 191
192 asc_ptr_cast(AscSceneNode, node, rectangle); 192 asc_ptr_cast(AscSceneNode, node, rectangle);
193 asc_scene_node_init(node, 193 asc_scene_node_init(node,
194 ASC_SCENE_NODE_FUNCS(asc_rectangle), 194 ASC_SCENE_NODE_FUNCS(asc_rectangle),
195 .pos2d = ASC_VEC2I(pos_x, pos_y), 195 .pos2d = ASC_VEC2I(pos_x, pos_y),
196 .render_group = asc_context.ink.alpha < 255 196 .render_group = (args.filled && args.color.alpha < 255) || args.border_color.alpha < 255
197 ? ASC_RENDER_GROUP_2D_BLEND 197 ? ASC_RENDER_GROUP_2D_BLEND
198 : ASC_RENDER_GROUP_2D_OPAQUE 198 : ASC_RENDER_GROUP_2D_OPAQUE
199 ); 199 );
200 return node; 200 return node;
201 } 201 }
324 pos_y = (float) (cy-ry); 324 pos_y = (float) (cy-ry);
325 ellipsis->radii.x = (float) rx; 325 ellipsis->radii.x = (float) rx;
326 ellipsis->radii.y = (float) ry; 326 ellipsis->radii.y = (float) ry;
327 } 327 }
328 328
329 ellipsis->color = asc_col_itof(asc_context.ink);
330 ellipsis->border_color = asc_col_itof(args.border_color);
331 ellipsis->filled = args.filled; 329 ellipsis->filled = args.filled;
332 if (!args.filled && args.thickness == 0) { 330 if (!args.filled && args.thickness == 0) {
333 // when we do not fill the ellipsis, we need a border 331 // when we do not fill the ellipsis, we need a border
334 ellipsis->thickness = 1; 332 ellipsis->thickness = 1;
335 } else { 333 } else {
336 ellipsis->thickness = args.thickness; 334 ellipsis->thickness = args.thickness;
337 } 335 }
336
338 if (!args.filled && asc_memcmpz(&args.border_color, sizeof(args.border_color))) { 337 if (!args.filled && asc_memcmpz(&args.border_color, sizeof(args.border_color))) {
339 // convenience fallback: 338 // convenience fallback:
340 // when we are drawing an outline but have no explicit border color, 339 // when we are drawing an outline but have no explicit border color,
341 // use the active ink 340 // use the main color
342 ellipsis->border_color = ellipsis->color; 341 args.border_color = args.color;
343 } 342 }
343 ellipsis->color = asc_col_itof(args.color);
344 ellipsis->border_color = asc_col_itof(args.border_color);
344 345
345 asc_ptr_cast(AscSceneNode, node, ellipsis); 346 asc_ptr_cast(AscSceneNode, node, ellipsis);
346 asc_scene_node_init(node, 347 asc_scene_node_init(node,
347 ASC_SCENE_NODE_FUNCS(asc_ellipsis), 348 ASC_SCENE_NODE_FUNCS(asc_ellipsis),
348 .pos2d = ASC_VEC2I(pos_x, pos_y), 349 .pos2d = ASC_VEC2I(pos_x, pos_y),
349 .render_group = asc_context.ink.alpha < 255 350 .render_group = (args.filled && args.color.alpha < 255) || args.border_color.alpha < 255
350 ? ASC_RENDER_GROUP_2D_BLEND 351 ? ASC_RENDER_GROUP_2D_BLEND
351 : ASC_RENDER_GROUP_2D_OPAQUE 352 : ASC_RENDER_GROUP_2D_OPAQUE
352 ); 353 );
353 return node; 354 return node;
354 } 355 }

mercurial