Drawing of node as a separate function
This commit is contained in:
parent
da00363fb1
commit
ea9bfef2b5
|
@ -36,7 +36,7 @@ struct node {
|
|||
struct node *prev; /* Z ordering only */
|
||||
|
||||
void* (*evalFunc)(struct node*, int oIndex);
|
||||
void (*displayFunc)(struct node*, struct nk_context *ctx);
|
||||
void (*displayFunc)(struct nk_context*, struct node*);
|
||||
};
|
||||
|
||||
struct node_link {
|
||||
|
@ -72,6 +72,8 @@ struct node_editor {
|
|||
};
|
||||
static struct node_editor nodeEditor;
|
||||
|
||||
#include "nodeeditor/node_type_color.c"
|
||||
|
||||
static void
|
||||
node_editor_push(struct node_editor *editor, struct node *node)
|
||||
{
|
||||
|
@ -135,23 +137,43 @@ static void
|
|||
node_editor_add(struct node_editor *editor, const char *name, struct nk_rect bounds,
|
||||
struct nk_color col, int in_count, int out_count)
|
||||
{
|
||||
|
||||
/*
|
||||
|
||||
Handle generic node creation things such as:
|
||||
- create panel
|
||||
- create connectors
|
||||
- add node to node tree
|
||||
|
||||
This should probably be called by the node type-specific init function?
|
||||
*/
|
||||
|
||||
static int IDs = 0; /* static duration */
|
||||
struct node *node;
|
||||
NK_ASSERT((nk_size)editor->node_count < NK_LEN(editor->node_buf));
|
||||
node = &editor->node_buf[editor->node_count++]; /* next node in buffer */
|
||||
node->ID = IDs++; /* increment IDs and set as node ID */
|
||||
|
||||
node->value = 0; /* unused? */
|
||||
node->color = nk_rgb(255, 0, 0);
|
||||
|
||||
node->input_count = in_count;
|
||||
node->output_count = out_count;
|
||||
|
||||
node->inputs = (struct node_connector*)malloc(node->input_count * sizeof(struct node_connector));
|
||||
node->outputs = (struct node_connector*)malloc(node->output_count * sizeof(struct node_connector));
|
||||
|
||||
for (int i = 0; i < node->input_count; i++)
|
||||
for (int i = 0; i < node->input_count; i++) {
|
||||
node->inputs[i].isConnected = nk_false;
|
||||
for (i = 0; i < node->output_count; i++)
|
||||
node->inputs[i].type = fValue;
|
||||
}
|
||||
for (i = 0; i < node->output_count; i++) {
|
||||
node->outputs[i].isConnected = nk_false;
|
||||
node->outputs[i].type = fValue;
|
||||
}
|
||||
|
||||
// this should be in the node type-specific initializer
|
||||
node->displayFunc = node_color_draw;
|
||||
|
||||
node->color = col;
|
||||
node->bounds = bounds;
|
||||
|
@ -249,14 +271,10 @@ node_editor_main(struct nk_context *ctx)
|
|||
updated = it;
|
||||
}
|
||||
|
||||
/* ================= NODE CONTENT =====================*/
|
||||
nk_layout_row_dynamic(ctx, 25, 1);
|
||||
nk_button_color(ctx, it->color);
|
||||
it->color.r = (nk_byte)nk_propertyi(ctx, "#R:", 0, it->color.r, 255, 1,1);
|
||||
it->color.g = (nk_byte)nk_propertyi(ctx, "#G:", 0, it->color.g, 255, 1,1);
|
||||
it->color.b = (nk_byte)nk_propertyi(ctx, "#B:", 0, it->color.b, 255, 1,1);
|
||||
it->color.a = (nk_byte)nk_propertyi(ctx, "#A:", 0, it->color.a, 255, 1,1);
|
||||
/* ====================================================*/
|
||||
/* ================= NODE CONTENT ===================== */
|
||||
it->displayFunc(ctx, it);
|
||||
/* ==================================================== */
|
||||
|
||||
nk_group_end(ctx);
|
||||
}
|
||||
{
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
struct node_type_color {
|
||||
struct node node;
|
||||
float *inputVal;
|
||||
struct nk_colorf *outputVal;
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
static void* node_color_get(struct node* self, int oIndex)
|
||||
{
|
||||
struct node_type_color *node = ((struct node_type_color*)self);
|
||||
for (int i = 0; i < self->input_count; i++)
|
||||
{
|
||||
if (self->inputs[i].isConnected)
|
||||
{
|
||||
/*
|
||||
call getter func of connected node and assign to ((node_type_color*)self)->inputVal[i]
|
||||
*//*
|
||||
}
|
||||
}
|
||||
node->outputVal->r = node->inputVal[0];
|
||||
node->outputVal->g = node->inputVal[1];
|
||||
node->outputVal->b = node->inputVal[2];
|
||||
node->outputVal->a = node->inputVal[3];
|
||||
|
||||
struct nk_colorf *returnpointer = ((struct node_type_color*)self)->outputVal;
|
||||
return (void*) returnpointer;
|
||||
}*/
|
||||
|
||||
|
||||
static void node_color_draw(struct nk_context *ctx, struct node* node)
|
||||
{
|
||||
/* ================= NODE CONTENT =====================*/
|
||||
nk_layout_row_dynamic(ctx, 25, 1);
|
||||
nk_button_color(ctx, node->color);
|
||||
node->color.r = (nk_byte)nk_propertyi(ctx, "#R:", 0, node->color.r, 255, 1,1);
|
||||
node->color.g = (nk_byte)nk_propertyi(ctx, "#G:", 0, node->color.g, 255, 1,1);
|
||||
node->color.b = (nk_byte)nk_propertyi(ctx, "#B:", 0, node->color.b, 255, 1,1);
|
||||
node->color.a = (nk_byte)nk_propertyi(ctx, "#A:", 0, node->color.a, 255, 1,1);
|
||||
/* ====================================================*/
|
||||
}
|
||||
|
||||
/*
|
||||
struct node* node_color_init()
|
||||
{
|
||||
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) ??
|
||||
}
|
||||
*/
|
Loading…
Reference in New Issue