nodesystem/node2d/node2d.c

47 lines
979 B
C

#include "node2d.h"
NOD_Node2D *NOD_CreateNode2D(char *name){
NOD_Node2D *node = NULL;
NOD_Node *plain_node = NULL;
plain_node = NOD_CreateNodeEX(_NOD_2D_TYPE, name);
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;
}
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;
}