Color node creation added

This commit is contained in:
Peter Schulman 2023-04-13 07:02:29 +03:00
parent ea9bfef2b5
commit 52eff509b2
2 changed files with 19 additions and 28 deletions

View File

@ -72,6 +72,14 @@ struct node_editor {
};
static struct node_editor nodeEditor;
/* === PROTOTYPES === */
static struct node* node_editor_add(struct node_editor *editor, const char *name, struct nk_rect bounds,
struct nk_color col, int in_count, int out_count);
/* ================== */
#include "nodeeditor/node_type_color.c"
static void
@ -133,7 +141,7 @@ node_editor_find_link_by_output(struct node_editor *editor, struct node *output_
return NULL;
}
static void
static struct node*
node_editor_add(struct node_editor *editor, const char *name, struct nk_rect bounds,
struct nk_color col, int in_count, int out_count)
{
@ -179,6 +187,7 @@ node_editor_add(struct node_editor *editor, const char *name, struct nk_rect bou
node->bounds = bounds;
strcpy(node->name, name);
node_editor_push(editor, node);
return node;
}
static void
@ -204,9 +213,9 @@ node_editor_init(struct node_editor *editor)
memset(editor, 0, sizeof(*editor));
editor->begin = NULL;
editor->end = NULL;
node_editor_add(editor, "Source", nk_rect(40, 10, 180, 220), nk_rgb(255, 0, 0), 0, 1);
node_editor_add(editor, "Source", nk_rect(40, 260, 180, 220), nk_rgb(0, 255, 0), 0, 1);
node_editor_add(editor, "Combine", nk_rect(400, 100, 180, 220), nk_rgb(0,0,255), 2, 2);
node_editor_add(editor, "Dummy1", nk_rect(40, 10, 180, 220), nk_rgb(255, 0, 0), 0, 1);
node_editor_add(editor, "Dummy2", nk_rect(40, 260, 180, 220), nk_rgb(0, 255, 0), 0, 1);
node_editor_add(editor, "Dummy3", nk_rect(400, 100, 180, 220), nk_rgb(0,0,255), 2, 2);
//node_editor_link(editor, node_editor_find(&nodeEditor, 0), 0, node_editor_find(&nodeEditor, 2), 0);
//node_editor_link(editor, node_editor_find(&nodeEditor, 1), 0, node_editor_find(&nodeEditor, 2), 1);
editor->show_grid = nk_true;
@ -407,12 +416,14 @@ node_editor_main(struct nk_context *ctx)
}
/* contextual menu */
if (nk_contextual_begin(ctx, 0, nk_vec2(100, 220), nk_window_get_bounds(ctx))) {
if (nk_contextual_begin(ctx, 0, nk_vec2(150, 220), nk_window_get_bounds(ctx))) {
const char *grid_option[] = {"Show Grid", "Hide Grid"};
nk_layout_row_dynamic(ctx, 25, 1);
if (nk_contextual_item_label(ctx, "New", NK_TEXT_CENTERED))
node_editor_add(nodedit, "New", nk_rect(400, 260, 180, 220),
node_editor_add(nodedit, "New", nk_rect(in->mouse.pos.x, in->mouse.pos.y, 180, 220),
nk_rgb(255, 255, 255), 1, 2);
if (nk_contextual_item_label(ctx, "Add Color node", NK_TEXT_CENTERED))
node_color_create(nodedit, in->mouse.pos);
if (nk_contextual_item_label(ctx, grid_option[nodedit->show_grid],NK_TEXT_CENTERED))
nodedit->show_grid = !nodedit->show_grid;
nk_contextual_end(ctx);

View File

@ -40,27 +40,7 @@ static void node_color_draw(struct nk_context *ctx, struct node* node)
/* ====================================================*/
}
/*
struct node* node_color_init()
void node_color_create(struct node_editor* editor, struct nk_vec2 position)
{
struct node_type_color *colornode = (struct node_type_color*)malloc(sizeof(struct node_type_color));
colornode->node.input_count = 4;
colornode->node.output_count = 1;
colornode->node.inputs = (struct node_connector*)malloc(colornode->node.input_count * sizeof(struct node_connector));
for (int i = 0; i < colornode->node.input_count; i++) {
colornode->node.inputs[i].type = fValue;
}
colornode->inputVal = (float*)malloc(colornode->node.input_count * sizeof(float));
colornode->node.outputs = (struct node_connector*)malloc(colornode->node.output_count * sizeof(struct node_connector));
colornode->node.outputs->type = fColor;
colornode->outputVal = (struct nk_colorf*)malloc(colornode->node.input_count * sizeof(struct nk_colorf));
colornode->node.displayFunc = node_color_draw;
//colornode->node.evalFunc = get_nodetypes_color;
return (struct node*)colornode; // does this need to return (node*)(&colornode->node) ??
struct node *node = node_editor_add(editor, "Color", nk_rect(position.x, position.y, 180, 220), nk_rgb(255, 255, 255), 4, 1);
}
*/