src/2d.c

changeset 189
2c063b225183
parent 175
e5544920377e
equal deleted inserted replaced
188:5ece6e3acc84 189:2c063b225183
155 } 155 }
156 156
157 AscSceneNode *asc_rectangle_create(struct asc_rectangle_create_args args) { 157 AscSceneNode *asc_rectangle_create(struct asc_rectangle_create_args args) {
158 AscRectangle *rectangle = cxZallocDefault(sizeof(AscRectangle)); 158 AscRectangle *rectangle = cxZallocDefault(sizeof(AscRectangle));
159 159
160 float pos_x, pos_y;
160 if (args.bounds.size.width + args.bounds.size.height > 0) { 161 if (args.bounds.size.width + args.bounds.size.height > 0) {
161 rectangle->node.position.x = (float) args.bounds.pos.x; 162 pos_x = (float) args.bounds.pos.x;
162 rectangle->node.position.y = (float) args.bounds.pos.y; 163 pos_y = (float) args.bounds.pos.y;
163 rectangle->size.width = (float) args.bounds.size.width; 164 rectangle->size.width = (float) args.bounds.size.width;
164 rectangle->size.height = (float) args.bounds.size.height; 165 rectangle->size.height = (float) args.bounds.size.height;
165 } else { 166 } else {
166 rectangle->node.position.x = (float) args.x; 167 pos_x = (float) args.x;
167 rectangle->node.position.y = (float) args.y; 168 pos_y = (float) args.y;
168 rectangle->size.width = (float) args.width; 169 rectangle->size.width = (float) args.width;
169 rectangle->size.height = (float) args.height; 170 rectangle->size.height = (float) args.height;
170 } 171 }
171 172
172 rectangle->radius = (float)args.radius; 173 rectangle->radius = (float)args.radius;
185 // use the active ink 186 // use the active ink
186 rectangle->border_color = rectangle->color; 187 rectangle->border_color = rectangle->color;
187 } 188 }
188 189
189 AscSceneNode *node = &rectangle->node; 190 AscSceneNode *node = &rectangle->node;
190 node->position.z = ASC_SCENE_2D_DEPTH_OFFSET; 191 asc_transform_identity(node->transform);
191 node->scale = ASC_VEC3F_1; 192 asc_transform_translate3f(node->transform,
193 ASC_VEC3F(pos_x, pos_y, ASC_SCENE_2D_DEPTH_OFFSET));
192 node->render_group = asc_context.ink.alpha < 255 194 node->render_group = asc_context.ink.alpha < 255
193 ? ASC_RENDER_GROUP_2D_BLEND 195 ? ASC_RENDER_GROUP_2D_BLEND
194 : ASC_RENDER_GROUP_2D_OPAQUE; 196 : ASC_RENDER_GROUP_2D_OPAQUE;
195 node->update_func = asc_rectangle_update; 197 node->update_func = asc_rectangle_update;
196 node->destroy_func = asc_rectangle_destroy; 198 node->destroy_func = asc_rectangle_destroy;
306 } 308 }
307 309
308 AscSceneNode *asc_ellipsis_create(struct asc_ellipsis_create_args args) { 310 AscSceneNode *asc_ellipsis_create(struct asc_ellipsis_create_args args) {
309 AscEllipsis *ellipsis = cxZallocDefault(sizeof(AscEllipsis)); 311 AscEllipsis *ellipsis = cxZallocDefault(sizeof(AscEllipsis));
310 312
313 float pos_x, pos_y;
311 if (args.bounds.size.width + args.bounds.size.height > 0) { 314 if (args.bounds.size.width + args.bounds.size.height > 0) {
312 ellipsis->node.position.x = (float) args.bounds.pos.x; 315 pos_x = (float) args.bounds.pos.x;
313 ellipsis->node.position.y = (float) args.bounds.pos.y; 316 pos_y = (float) args.bounds.pos.y;
314 ellipsis->radii.x = (float) args.bounds.size.width / 2.f; 317 ellipsis->radii.x = (float) args.bounds.size.width / 2.f;
315 ellipsis->radii.y = (float) args.bounds.size.height / 2.f; 318 ellipsis->radii.y = (float) args.bounds.size.height / 2.f;
316 } else { 319 } else {
317 const unsigned cx = ASC_NONZERO_OR(args.x, args.center.x); 320 const unsigned cx = ASC_NONZERO_OR(args.x, args.center.x);
318 const unsigned cy = ASC_NONZERO_OR(args.y, args.center.y); 321 const unsigned cy = ASC_NONZERO_OR(args.y, args.center.y);
319 const unsigned rx = ASC_NONZERO_OR(args.radius, args.radius_x); 322 const unsigned rx = ASC_NONZERO_OR(args.radius, args.radius_x);
320 const unsigned ry = ASC_NONZERO_OR(args.radius, args.radius_y); 323 const unsigned ry = ASC_NONZERO_OR(args.radius, args.radius_y);
321 ellipsis->node.position.x = (float) (cx-rx); 324 pos_x = (float) (cx-rx);
322 ellipsis->node.position.y = (float) (cy-ry); 325 pos_y = (float) (cy-ry);
323 ellipsis->radii.x = (float) rx; 326 ellipsis->radii.x = (float) rx;
324 ellipsis->radii.y = (float) ry; 327 ellipsis->radii.y = (float) ry;
325 } 328 }
326 329
327 ellipsis->color = asc_col_itof(asc_context.ink); 330 ellipsis->color = asc_col_itof(asc_context.ink);
339 // use the active ink 342 // use the active ink
340 ellipsis->border_color = ellipsis->color; 343 ellipsis->border_color = ellipsis->color;
341 } 344 }
342 345
343 AscSceneNode *node = &ellipsis->node; 346 AscSceneNode *node = &ellipsis->node;
344 node->position.z = ASC_SCENE_2D_DEPTH_OFFSET; 347 asc_transform_identity(node->transform);
345 node->scale = ASC_VEC3F_1; 348 asc_transform_translate3f(node->transform,
349 ASC_VEC3F(pos_x, pos_y, ASC_SCENE_2D_DEPTH_OFFSET));
346 node->render_group = asc_context.ink.alpha < 255 350 node->render_group = asc_context.ink.alpha < 255
347 ? ASC_RENDER_GROUP_2D_BLEND 351 ? ASC_RENDER_GROUP_2D_BLEND
348 : ASC_RENDER_GROUP_2D_OPAQUE; 352 : ASC_RENDER_GROUP_2D_OPAQUE;
349 node->update_func = asc_ellipsis_update; 353 node->update_func = asc_ellipsis_update;
350 node->destroy_func = asc_ellipsis_destroy; 354 node->destroy_func = asc_ellipsis_destroy;

mercurial