src/2d.c

changeset 244
ceab8a9f0366
parent 239
3b78ad115ccd
equal deleted inserted replaced
243:b06168253818 244:ceab8a9f0366
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/shader.h" 31 #include "ascension/shader.h"
32 #include "ascension/util.h"
32 33
33 #include <assert.h> 34 #include <assert.h>
34 35
35 typedef struct asc_rectangle_shader_s { 36 typedef struct asc_rectangle_shader_s {
36 AscShaderProgram program; 37 AscShaderProgram program;
127 AscSceneNode *asc_rectangle_create(struct asc_rectangle_create_args args) { 128 AscSceneNode *asc_rectangle_create(struct asc_rectangle_create_args args) {
128 AscRectangle *rectangle = cxZallocDefault(sizeof(AscRectangle)); 129 AscRectangle *rectangle = cxZallocDefault(sizeof(AscRectangle));
129 130
130 float pos_x, pos_y; 131 float pos_x, pos_y;
131 if (args.bounds.size.width + args.bounds.size.height > 0) { 132 if (args.bounds.size.width + args.bounds.size.height > 0) {
133 // TODO: this is probably bugged, because it does not respect the origin
132 pos_x = (float) args.bounds.pos.x; 134 pos_x = (float) args.bounds.pos.x;
133 pos_y = (float) args.bounds.pos.y; 135 pos_y = (float) args.bounds.pos.y;
134 rectangle->size.width = (float) args.bounds.size.width; 136 rectangle->size.width = (float) args.bounds.size.width;
135 rectangle->size.height = (float) args.bounds.size.height; 137 rectangle->size.height = (float) args.bounds.size.height;
136 } else { 138 } else {
167 ? ASC_RENDER_GROUP_2D_BLEND 169 ? ASC_RENDER_GROUP_2D_BLEND
168 : ASC_RENDER_GROUP_2D_OPAQUE 170 : ASC_RENDER_GROUP_2D_OPAQUE
169 ); 171 );
170 return node; 172 return node;
171 } 173 }
174
175 void asc_rectangle_set_bounds(AscRectangle *rect, asc_rect bounds) {
176 // TODO: check how this harmonizes with a different origin
177 float x = (float) bounds.pos.x;
178 float y = (float) bounds.pos.y;
179 float width = (float) bounds.size.width;
180 float height = (float) bounds.size.height;
181 bool update_transform = false;
182 bool update_mesh = false;
183 update_transform |= asc_util_check_and_set(rect->node.position.x, x);
184 update_transform |= asc_util_check_and_set(rect->node.position.y, y);
185 update_mesh |= asc_util_check_and_set(rect->size.width, width);
186 update_mesh |= asc_util_check_and_set(rect->size.height, height);
187 if (update_mesh) {
188 asc_scene_node_update(&rect->node);
189 }
190 if (update_transform) {
191 asc_scene_node_update_transform(&rect->node);
192 }
193 }
194
172 195
173 static void asc_ellipsis_destroy(AscSceneNode *node) { 196 static void asc_ellipsis_destroy(AscSceneNode *node) {
174 asc_ptr_cast(AscEllipsis, ellipsis, node); 197 asc_ptr_cast(AscEllipsis, ellipsis, node);
175 asc_mesh_destroy(&ellipsis->mesh); 198 asc_mesh_destroy(&ellipsis->mesh);
176 } 199 }

mercurial