nodesystem/src/node2d.c

47 lines
979 B
C
Raw Normal View History

2021-02-06 12:16:18 +00:00
#include "node2d.h"
2021-02-06 14:20:24 +00:00
NOD_Node2D *NOD_CreateNode2D(char *name){
NOD_Node2D *node = NULL;
NOD_Node *plain_node = NULL;
2021-02-07 07:41:57 +00:00
plain_node = NOD_CreateNodeEX(_NOD_2D_TYPE, name);
2021-02-06 14:20:24 +00:00
if(plain_node != NULL){
plain_node = realloc(plain_node, sizeof(NOD_Node2D));
if(plain_node != NULL){
node = (NOD_Node2D*)plain_node;
node->pos.x = 0;
node->pos.y = 0;
}
}
return node;
2021-02-06 12:16:18 +00:00
}
2021-02-07 07:41:57 +00:00
vector2Di NOD_GetAbsPosNode2D(NOD_Node2D *node){
vector2Di final_pos = {0, 0};
if(node != NULL){
final_pos = node->pos;
NOD_Node *parent = NOD(node)->parent;
/* Skip non Node2D nodes */
while(parent != NULL && strcmp(parent->type, _NOD_2D_TYPE) != 0){
parent = parent->parent;
}
/* Recurse to get the pos of the rest of the ascendence */
if(parent != NULL){
vector2Di parent_pos = NOD_GetAbsPosNode2D((NOD_Node2D *)parent);
final_pos.x += parent_pos.x;
final_pos.y += parent_pos.y;
}
}
return final_pos;
}