Compare commits
	
		
			2 Commits
		
	
	
		
			dacc3be970
			...
			10ff46cfe4
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 10ff46cfe4 | |||
| fc0e3524fe | 
@@ -1,6 +1,7 @@
 | 
				
			|||||||
#ifndef NODES_H
 | 
					#ifndef NODES_H
 | 
				
			||||||
#define NODES_H
 | 
					#define NODES_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "aliases/aliases.h"
 | 
				
			||||||
#include "window.h"
 | 
					#include "window.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define MAX_NODES 1024
 | 
					#define MAX_NODES 1024
 | 
				
			||||||
@@ -13,20 +14,27 @@
 | 
				
			|||||||
#define OP_NODE_FILL_COLOUR ((colour_t){.abgr = 0xffad6c3a})
 | 
					#define OP_NODE_FILL_COLOUR ((colour_t){.abgr = 0xffad6c3a})
 | 
				
			||||||
#define OP_NODE_BORDER_COLOUR ((colour_t){.abgr = 0xff8e4a33})
 | 
					#define OP_NODE_BORDER_COLOUR ((colour_t){.abgr = 0xff8e4a33})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef i32 (*node_func_t)(i32 a, i32 b);
 | 
				
			||||||
 | 
					typedef enum node_type node_type_t;
 | 
				
			||||||
 | 
					typedef union node_data node_data_t;
 | 
				
			||||||
typedef struct node node_t;
 | 
					typedef struct node node_t;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
enum comp_ops {
 | 
					enum node_type {
 | 
				
			||||||
  COMP_OP_ADD,
 | 
					  NODE_TYPE_IO,
 | 
				
			||||||
  COMP_OP_SUB,
 | 
					  NODE_TYPE_OP,
 | 
				
			||||||
  COMP_OP_MUL,
 | 
					 | 
				
			||||||
  COMP_OP_DIV,
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  COUNT_COMP_OPS,
 | 
					  COUNT_NODE_TYPES,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					union node_data {
 | 
				
			||||||
 | 
					  const char *path;
 | 
				
			||||||
 | 
					  node_func_t func;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct node {
 | 
					struct node {
 | 
				
			||||||
  rect_t rect;
 | 
					  rect_t rect;
 | 
				
			||||||
  const char *path;
 | 
					  node_type_t type;
 | 
				
			||||||
 | 
					  node_data_t data;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool aabb(const node_t *node, i32 x, i32 y);
 | 
					bool aabb(const node_t *node, i32 x, i32 y);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -36,6 +36,7 @@ struct rect {
 | 
				
			|||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct window {
 | 
					struct window {
 | 
				
			||||||
 | 
					  u32 id;
 | 
				
			||||||
  u64 width;
 | 
					  u64 width;
 | 
				
			||||||
  u64 height;
 | 
					  u64 height;
 | 
				
			||||||
  const char *title;
 | 
					  const char *title;
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										24
									
								
								src/nodes.c
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								src/nodes.c
									
									
									
									
									
								
							@@ -1,13 +1,33 @@
 | 
				
			|||||||
#include "nodes.h"
 | 
					#include "nodes.h"
 | 
				
			||||||
#include "aliases/aliases.h"
 | 
					#include "aliases/aliases.h"
 | 
				
			||||||
 | 
					#include "window.h"
 | 
				
			||||||
#include <stdbool.h>
 | 
					#include <stdbool.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef struct node_colours node_colours_t;
 | 
				
			||||||
 | 
					struct node_colours {
 | 
				
			||||||
 | 
					  colour_t fill;
 | 
				
			||||||
 | 
					  colour_t border;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					INTERNAL node_colours_t colours[COUNT_NODE_TYPES] = {
 | 
				
			||||||
 | 
					    [NODE_TYPE_IO] =
 | 
				
			||||||
 | 
					        (node_colours_t){
 | 
				
			||||||
 | 
					            .fill = IO_NODE_FILL_COLOUR,
 | 
				
			||||||
 | 
					            .border = IO_NODE_BORDER_COLOUR,
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					    [NODE_TYPE_OP] =
 | 
				
			||||||
 | 
					        (node_colours_t){
 | 
				
			||||||
 | 
					            .fill = OP_NODE_FILL_COLOUR,
 | 
				
			||||||
 | 
					            .border = OP_NODE_BORDER_COLOUR,
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool aabb(const node_t *node, i32 x, i32 y) {
 | 
					bool aabb(const node_t *node, i32 x, i32 y) {
 | 
				
			||||||
  return x > node->rect.topleft.x && x <= node->rect.topleft.x + node->rect.w &&
 | 
					  return x > node->rect.topleft.x && x <= node->rect.topleft.x + node->rect.w &&
 | 
				
			||||||
         y > node->rect.topleft.y && y <= node->rect.topleft.y + node->rect.h;
 | 
					         y > node->rect.topleft.y && y <= node->rect.topleft.y + node->rect.h;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void draw_node(const window_t *wnd, const node_t *node) {
 | 
					void draw_node(const window_t *wnd, const node_t *node) {
 | 
				
			||||||
  fill_rect(wnd, &(node->rect), IO_NODE_FILL_COLOUR);
 | 
					  fill_rect(wnd, &(node->rect), colours[node->type].fill);
 | 
				
			||||||
  draw_rect(wnd, &(node->rect), IO_NODE_BORDER_COLOUR);
 | 
					  draw_rect(wnd, &(node->rect), colours[node->type].border);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -20,6 +20,7 @@ bool init_window(window_t *wnd, const char *title, u64 width, u64 height) {
 | 
				
			|||||||
    return false;
 | 
					    return false;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  wnd->id = SDL_GetWindowID(wnd->window);
 | 
				
			||||||
  wnd->title = title;
 | 
					  wnd->title = title;
 | 
				
			||||||
  wnd->width = width;
 | 
					  wnd->width = width;
 | 
				
			||||||
  wnd->height = height;
 | 
					  wnd->height = height;
 | 
				
			||||||
@@ -38,7 +39,7 @@ void cleanup_window(window_t *wnd) {
 | 
				
			|||||||
    wnd->window = NULL;
 | 
					    wnd->window = NULL;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  wnd->width = wnd->height = 0;
 | 
					  wnd->width = wnd->height = wnd->id = 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void set_colour(const window_t *wnd, colour_t colour) {
 | 
					void set_colour(const window_t *wnd, colour_t colour) {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user