2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2005 Blender Foundation.
19 * All rights reserved.
21 * The Original Code is: all of this file.
23 * Contributor(s): David Millan Escriva, Juho Vepsäläinen, Bob Holcomb, Thomas Dinges
25 * ***** END GPL LICENSE BLOCK *****
28 /** \file blender/editors/space_node/drawnode.c
37 #include "BLI_blenlib.h"
39 #include "BLI_utildefines.h"
41 #include "DNA_node_types.h"
42 #include "DNA_material_types.h"
43 #include "DNA_object_types.h"
44 #include "DNA_scene_types.h"
45 #include "DNA_space_types.h"
46 #include "DNA_screen_types.h"
48 #include "BKE_context.h"
49 #include "BKE_curve.h"
50 #include "BKE_global.h"
51 #include "BKE_image.h"
52 #include "BKE_library.h"
57 #include "BLF_translation.h"
59 #include "NOD_composite.h"
60 #include "NOD_shader.h"
63 #include "BIF_glutil.h"
67 #include "MEM_guardedalloc.h"
70 #include "RNA_access.h"
77 #include "UI_interface.h"
78 #include "UI_resources.h"
80 #include "IMB_imbuf.h"
81 #include "IMB_imbuf_types.h"
83 #include "node_intern.h"
86 extern void ui_dropshadow(rctf *rct, float radius, float aspect, float alpha, int select);
88 /* ****************** SOCKET BUTTON DRAW FUNCTIONS ***************** */
90 static void node_sync_cb(bContext *UNUSED(C), void *snode_v, void *node_v)
92 SpaceNode *snode = snode_v;
94 if (snode->treetype == NTREE_SHADER) {
95 nodeShaderSynchronizeID(node_v, 1);
96 // allqueue(REDRAWBUTSSHADING, 0);
100 static void node_socket_button_label(const bContext *UNUSED(C), uiBlock *block,
101 bNodeTree *UNUSED(ntree), bNode *UNUSED(node), bNodeSocket *sock,
102 const char *UNUSED(name), int x, int y, int width)
104 uiDefBut(block, LABEL, 0, IFACE_(sock->name), x, y, width, NODE_DY, NULL, 0, 0, 0, 0, "");
107 static void node_socket_button_default(const bContext *C, uiBlock *block,
108 bNodeTree *ntree, bNode *node, bNodeSocket *sock,
109 const char *name, int x, int y, int width)
111 if (sock->link || (sock->flag & SOCK_HIDE_VALUE))
112 node_socket_button_label(C, block, ntree, node, sock, name, x, y, width);
117 RNA_pointer_create(&ntree->id, &RNA_NodeSocket, sock, &ptr);
119 bt = uiDefButR(block, NUM, B_NODE_EXEC, IFACE_(name),
120 x, y + 1, width, NODE_DY - 2,
121 &ptr, "default_value", 0, 0, 0, -1, -1, NULL);
123 uiButSetFunc(bt, node_sync_cb, CTX_wm_space_node(C), node);
127 typedef struct SocketComponentMenuArgs {
132 } SocketComponentMenuArgs;
133 /* NOTE: this is a block-menu, needs 0 events, otherwise the menu closes */
134 static uiBlock *socket_component_menu(bContext *C, ARegion *ar, void *args_v)
136 SocketComponentMenuArgs *args = (SocketComponentMenuArgs *)args_v;
140 block = uiBeginBlock(C, ar, __func__, UI_EMBOSS);
141 uiBlockSetFlag(block, UI_BLOCK_KEEP_OPEN);
143 layout = uiLayoutColumn(uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, args->x, args->y + 2, args->width, NODE_DY, UI_GetStyle()), 0);
145 uiItemR(layout, &args->ptr, "default_value", UI_ITEM_R_EXPAND, "", ICON_NONE);
149 static void node_socket_button_components(const bContext *C, uiBlock *block,
150 bNodeTree *ntree, bNode *node, bNodeSocket *sock,
151 const char *name, int x, int y, int width)
153 if (sock->link || (sock->flag & SOCK_HIDE_VALUE))
154 node_socket_button_label(C, block, ntree, node, sock, name, x, y, width);
157 SocketComponentMenuArgs *args;
159 RNA_pointer_create(&ntree->id, &RNA_NodeSocket, sock, &ptr);
161 args = MEM_callocN(sizeof(SocketComponentMenuArgs), "SocketComponentMenuArgs");
167 args->cb = node_sync_cb;
168 args->arg1 = CTX_wm_space_node(C);
171 uiDefBlockButN(block, socket_component_menu, args, IFACE_(name), x, y + 1, width, NODE_DY - 2, "");
175 static void node_socket_button_color(const bContext *C, uiBlock *block,
176 bNodeTree *ntree, bNode *node, bNodeSocket *sock,
177 const char *name, int x, int y, int width)
179 if (sock->link || (sock->flag & SOCK_HIDE_VALUE))
180 node_socket_button_label(C, block, ntree, node, sock, IFACE_(name), x, y, width);
184 int labelw = width - 40;
185 RNA_pointer_create(&ntree->id, &RNA_NodeSocket, sock, &ptr);
187 bt = uiDefButR(block, COL, B_NODE_EXEC, "",
188 x, y + 2, (labelw > 0 ? 40 : width), NODE_DY - 2,
189 &ptr, "default_value", 0, 0, 0, -1, -1, NULL);
191 uiButSetFunc(bt, node_sync_cb, CTX_wm_space_node(C), node);
193 if (name[0] != '\0' && labelw > 0)
194 uiDefBut(block, LABEL, 0, IFACE_(name), x + 40, y + 2, labelw, NODE_DY - 2, NULL, 0, 0, 0, 0, "");
198 /* standard draw function, display the default input value */
199 static void node_draw_input_default(const bContext *C, uiBlock *block,
200 bNodeTree *ntree, bNode *node, bNodeSocket *sock,
201 const char *name, int x, int y, int width)
203 bNodeSocketType *stype = ntreeGetSocketType(sock->type);
204 if (stype->buttonfunc)
205 stype->buttonfunc(C, block, ntree, node, sock, name, x, y, width);
207 node_socket_button_label(C, block, ntree, node, sock, IFACE_(name), x, y, width);
210 static void node_draw_output_default(const bContext *C, uiBlock *block,
211 bNodeTree *UNUSED(ntree), bNode *node, bNodeSocket *sock,
212 const char *name, int UNUSED(x), int UNUSED(y), int UNUSED(width))
214 SpaceNode *snode = CTX_wm_space_node(C);
217 const char *ui_name = IFACE_(name);
218 UI_ThemeColor(TH_TEXT);
219 slen = snode->aspect * UI_GetStringWidth(ui_name);
220 while (slen > node->width) {
222 slen = snode->aspect * UI_GetStringWidth(ui_name + ofs);
224 uiDefBut(block, LABEL, 0, ui_name + ofs, (short)(sock->locx - 15.0f - slen), (short)(sock->locy - 9.0f),
225 (short)(node->width - NODE_DY), NODE_DY, NULL, 0, 0, 0, 0, "");
228 /* ****************** BASE DRAW FUNCTIONS FOR NEW OPERATOR NODES ***************** */
231 static void node_draw_socket_new(bNodeSocket *sock, float size)
233 float x = sock->locx, y = sock->locy;
235 /* 16 values of sin function */
236 static float si[16] = {
237 0.00000000f, 0.39435585f, 0.72479278f, 0.93775213f,
238 0.99871650f, 0.89780453f, 0.65137248f, 0.29936312f,
239 -0.10116832f, -0.48530196f, -0.79077573f, -0.96807711f,
240 -0.98846832f, -0.84864425f, -0.57126821f, -0.20129852f
242 /* 16 values of cos function */
243 static float co[16] = {
244 1.00000000f, 0.91895781f, 0.68896691f, 0.34730525f,
245 -0.05064916f, -0.44039415f, -0.75875812f, -0.95413925f,
246 -0.99486932f, -0.87434661f, -0.61210598f, -0.25065253f,
247 0.15142777f, 0.52896401f, 0.82076344f, 0.97952994f,
251 glColor3ub(180, 180, 180);
254 for (a = 0; a < 16; a++)
255 glVertex2f(x + size * si[a], y + size * co[a]);
258 glColor4ub(0, 0, 0, 150);
260 glEnable(GL_LINE_SMOOTH);
261 glBegin(GL_LINE_LOOP);
262 for (a = 0; a < 16; a++)
263 glVertex2f(x + size * si[a], y + size * co[a]);
265 glDisable(GL_LINE_SMOOTH);
270 /* ****************** BUTTON CALLBACKS FOR ALL TREES ***************** */
272 static void node_buts_value(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
277 /* first socket stores value */
278 prop = RNA_struct_find_property(ptr, "outputs");
279 RNA_property_collection_lookup_int(ptr, prop, 0, &sockptr);
281 uiItemR(layout, &sockptr, "default_value", 0, "", ICON_NONE);
284 static void node_buts_rgb(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
290 /* first socket stores value */
291 prop = RNA_struct_find_property(ptr, "outputs");
292 RNA_property_collection_lookup_int(ptr, prop, 0, &sockptr);
294 col = uiLayoutColumn(layout, 0);
295 uiTemplateColorWheel(col, &sockptr, "default_value", 1, 0, 0, 0);
296 uiItemR(col, &sockptr, "default_value", 0, "", ICON_NONE);
299 static void node_buts_mix_rgb(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
303 bNodeTree *ntree = (bNodeTree *)ptr->id.data;
305 row = uiLayoutRow(layout, 1);
306 uiItemR(row, ptr, "blend_type", 0, "", ICON_NONE);
307 if (ntree->type == NTREE_COMPOSIT)
308 uiItemR(row, ptr, "use_alpha", 0, "", ICON_IMAGE_RGB_ALPHA);
311 static void node_buts_time(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
315 /* XXX no context access here .. */
316 bNode *node = ptr->data;
317 CurveMapping *cumap = node->storage;
320 cumap->flag |= CUMA_DRAW_CFRA;
321 if (node->custom1 < node->custom2)
322 cumap->sample[0] = (float)(CFRA - node->custom1) / (float)(node->custom2 - node->custom1);
326 uiTemplateCurveMapping(layout, ptr, "curve", 's', 0, 0);
328 row = uiLayoutRow(layout, 1);
329 uiItemR(row, ptr, "frame_start", 0, IFACE_("Sta"), ICON_NONE);
330 uiItemR(row, ptr, "frame_end", 0, IFACE_("End"), ICON_NONE);
333 static void node_buts_colorramp(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
335 uiTemplateColorRamp(layout, ptr, "color_ramp", 0);
338 static void node_buts_curvevec(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
340 uiTemplateCurveMapping(layout, ptr, "mapping", 'v', 0, 0);
343 static float *_sample_col = NULL; // bad bad, 2.5 will do better?
345 static void node_curvemap_sample(float *col)
351 static void node_buts_curvecol(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
353 bNode *node = ptr->data;
354 CurveMapping *cumap = node->storage;
357 cumap->flag |= CUMA_DRAW_SAMPLE;
358 copy_v3_v3(cumap->sample, _sample_col);
361 cumap->flag &= ~CUMA_DRAW_SAMPLE;
363 uiTemplateCurveMapping(layout, ptr, "mapping", 'c', 0, 0);
366 static void node_normal_cb(bContext *C, void *ntree_v, void *node_v)
368 Main *bmain = CTX_data_main(C);
370 ED_node_generic_update(bmain, ntree_v, node_v);
371 WM_event_add_notifier(C, NC_NODE | NA_EDITED, ntree_v);
374 static void node_buts_normal(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
376 uiBlock *block = uiLayoutAbsoluteBlock(layout);
377 bNodeTree *ntree = ptr->id.data;
378 bNode *node = ptr->data;
379 rctf *butr = &node->butr;
380 bNodeSocket *sock = node->outputs.first; /* first socket stores normal */
381 float *nor = ((bNodeSocketValueVector *)sock->default_value)->value;
384 bt = uiDefButF(block, BUT_NORMAL, B_NODE_EXEC, "",
385 (short)butr->xmin, (short)butr->xmin,
386 butr->xmax - butr->xmin, butr->xmax - butr->xmin,
387 nor, 0.0f, 1.0f, 0, 0, "");
388 uiButSetFunc(bt, node_normal_cb, ntree, node);
390 #if 0 // not used in 2.5x yet
391 static void node_browse_tex_cb(bContext *C, void *ntree_v, void *node_v)
393 Main *bmain = CTX_data_main(C);
394 bNodeTree *ntree = ntree_v;
395 bNode *node = node_v;
398 if (node->menunr < 1) return;
404 tex = BLI_findlink(&bmain->tex, node->menunr - 1);
407 id_us_plus(node->id);
408 BLI_strncpy(node->name, node->id->name + 2, sizeof(node->name));
410 nodeSetActive(ntree, node);
412 if (ntree->type == NTREE_TEXTURE)
413 ntreeTexCheckCyclics(ntree);
415 // allqueue(REDRAWBUTSSHADING, 0);
416 // allqueue(REDRAWNODE, 0);
417 NodeTagChanged(ntree, node);
423 static void node_buts_texture(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
425 bNode *node = ptr->data;
429 ((Tex *)node->id)->use_nodes &&
430 (node->type != CMP_NODE_TEXTURE) &&
431 (node->type != TEX_NODE_TEXTURE)
434 uiItemR(layout, ptr, "texture", 0, "", ICON_NONE);
437 /* Number Drawing not optimal here, better have a list*/
438 uiItemR(layout, ptr, "node_output", 0, "", ICON_NONE);
442 static void node_buts_math(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
444 uiItemR(layout, ptr, "operation", 0, "", ICON_NONE);
447 static int node_resize_area_default(bNode *node, int x, int y)
449 if (node->flag & NODE_HIDDEN) {
450 rctf totr = node->totr;
451 /* right part of node */
452 totr.xmin = node->totr.xmax - 20.0f;
453 if (BLI_in_rctf(&totr, x, y))
454 return NODE_RESIZE_RIGHT;
459 const float size = 10.0f;
460 rctf totr = node->totr;
463 if (x >= totr.xmax - size && x < totr.xmax && y >= totr.ymin && y < totr.ymax)
464 dir |= NODE_RESIZE_RIGHT;
465 if (x >= totr.xmin && x < totr.xmin + size && y >= totr.ymin && y < totr.ymax)
466 dir |= NODE_RESIZE_LEFT;
471 /* ****************** BUTTON CALLBACKS FOR COMMON NODES ***************** */
473 /* width of socket columns in group display */
474 #define NODE_GROUP_FRAME 120
476 /* based on settings in node, sets drawing rect info. each redraw! */
477 /* note: this assumes only 1 group at a time is drawn (linked data) */
478 /* in node->totr the entire boundbox for the group is stored */
479 static void node_update_group(const bContext *C, bNodeTree *ntree, bNode *gnode)
481 if (!(gnode->flag & NODE_GROUP_EDIT)) {
482 node_update_default(C, ntree, gnode);
485 bNodeTree *ngroup = (bNodeTree *)gnode->id;
487 bNodeSocket *sock, *gsock;
489 rctf *rect = &gnode->totr;
490 float node_group_frame = U.dpi * NODE_GROUP_FRAME / 72;
491 float group_header = 26 * U.dpi / 72;
495 /* get "global" coords */
496 nodeToView(gnode, 0.0f, 0.0f, &locx, &locy);
498 /* center them, is a bit of abuse of locx and locy though */
499 node_update_nodetree(C, ngroup, locx, locy);
501 rect->xmin = rect->xmax = locx;
502 rect->ymin = rect->ymax = locy;
505 for (node = ngroup->nodes.first; node; node = node->next) {
511 BLI_union_rctf(rect, &node->totr);
514 /* add some room for links to group sockets */
515 rect->xmin -= 4 * NODE_DY;
516 rect->xmax += 4 * NODE_DY;
517 rect->ymin -= NODE_DY;
518 rect->ymax += NODE_DY;
521 dy = 0.5f * (rect->ymin + rect->ymax) + NODE_DY * (BLI_countlist(&gnode->inputs) - 1);
522 gsock = ngroup->inputs.first;
523 sock = gnode->inputs.first;
524 while (gsock || sock) {
525 while (sock && !sock->groupsock) {
526 sock->locx = rect->xmin - node_group_frame;
529 /* prevent long socket lists from growing out of the group box */
530 if (dy - 3 * NODE_DYS < rect->ymin)
531 rect->ymin = dy - 3 * NODE_DYS;
532 if (dy + 3 * NODE_DYS > rect->ymax)
533 rect->ymax = dy + 3 * NODE_DYS;
538 while (gsock && (!sock || sock->groupsock != gsock)) {
539 gsock->locx = rect->xmin;
542 /* prevent long socket lists from growing out of the group box */
543 if (dy - 3 * NODE_DYS < rect->ymin)
544 rect->ymin = dy - 3 * NODE_DYS;
545 if (dy + 3 * NODE_DYS > rect->ymax)
546 rect->ymax = dy + 3 * NODE_DYS;
551 while (sock && gsock && sock->groupsock == gsock) {
552 gsock->locx = rect->xmin;
553 sock->locx = rect->xmin - node_group_frame;
554 sock->locy = gsock->locy = dy;
556 /* prevent long socket lists from growing out of the group box */
557 if (dy - 3 * NODE_DYS < rect->ymin)
558 rect->ymin = dy - 3 * NODE_DYS;
559 if (dy + 3 * NODE_DYS > rect->ymax)
560 rect->ymax = dy + 3 * NODE_DYS;
569 dy = 0.5f * (rect->ymin + rect->ymax) + NODE_DY * (BLI_countlist(&gnode->outputs) - 1);
570 gsock = ngroup->outputs.first;
571 sock = gnode->outputs.first;
572 while (gsock || sock) {
573 while (sock && !sock->groupsock) {
574 sock->locx = rect->xmax + node_group_frame;
575 sock->locy = dy - NODE_DYS;
577 /* prevent long socket lists from growing out of the group box */
578 if (dy - 3 * NODE_DYS < rect->ymin)
579 rect->ymin = dy - 3 * NODE_DYS;
580 if (dy + 3 * NODE_DYS > rect->ymax)
581 rect->ymax = dy + 3 * NODE_DYS;
586 while (gsock && (!sock || sock->groupsock != gsock)) {
587 gsock->locx = rect->xmax;
588 gsock->locy = dy - NODE_DYS;
590 /* prevent long socket lists from growing out of the group box */
591 if (dy - 3 * NODE_DYS < rect->ymin)
592 rect->ymin = dy - 3 * NODE_DYS;
593 if (dy + 3 * NODE_DYS > rect->ymax)
594 rect->ymax = dy + 3 * NODE_DYS;
599 while (sock && gsock && sock->groupsock == gsock) {
600 gsock->locx = rect->xmax;
601 sock->locx = rect->xmax + node_group_frame;
602 sock->locy = gsock->locy = dy - NODE_DYS;
604 /* prevent long socket lists from growing out of the group box */
605 if (dy - 3 * NODE_DYS < rect->ymin)
606 rect->ymin = dy - 3 * NODE_DYS;
607 if (dy + 3 * NODE_DYS > rect->ymax)
608 rect->ymax = dy + 3 * NODE_DYS;
616 /* Set the block bounds to clip mouse events from underlying nodes.
617 * Add margin for header and input/output columns.
619 uiExplicitBoundsBlock(gnode->block,
620 rect->xmin - node_group_frame,
622 rect->xmax + node_group_frame,
623 rect->ymax + group_header);
627 static void update_group_input_cb(bContext *UNUSED(C), void *UNUSED(snode_v), void *ngroup_v)
629 bNodeTree *ngroup = (bNodeTree *)ngroup_v;
631 ngroup->update |= NTREE_UPDATE_GROUP_IN;
632 ntreeUpdateTree(ngroup);
635 static void update_group_output_cb(bContext *UNUSED(C), void *UNUSED(snode_v), void *ngroup_v)
637 bNodeTree *ngroup = (bNodeTree *)ngroup_v;
639 ngroup->update |= NTREE_UPDATE_GROUP_OUT;
640 ntreeUpdateTree(ngroup);
643 static void draw_group_socket_name(SpaceNode *snode, bNode *gnode, bNodeSocket *sock, int in_out, float xoffset, float yoffset)
645 bNodeTree *ngroup = (bNodeTree *)gnode->id;
647 const char *ui_name = IFACE_(sock->name);
649 if (sock->flag & SOCK_DYNAMIC) {
650 bt = uiDefBut(gnode->block, TEX, 0, "",
651 sock->locx + xoffset, sock->locy + 1 + yoffset, 72, NODE_DY,
652 sock->name, 0, sizeof(sock->name), 0, 0, "");
653 if (in_out == SOCK_IN)
654 uiButSetFunc(bt, update_group_input_cb, snode, ngroup);
656 uiButSetFunc(bt, update_group_output_cb, snode, ngroup);
659 uiDefBut(gnode->block, LABEL, 0, ui_name,
660 sock->locx + xoffset, sock->locy + 1 + yoffset, 72, NODE_DY,
661 NULL, 0, sizeof(ui_name), 0, 0, "");
665 static void draw_group_socket(const bContext *C, SpaceNode *snode, bNodeTree *ntree, bNode *gnode, bNodeSocket *sock, bNodeSocket *gsock, int index, int in_out)
667 bNodeTree *ngroup = (bNodeTree *)gnode->id;
668 bNodeSocketType *stype = ntreeGetSocketType(gsock ? gsock->type : sock->type);
672 float node_group_frame = U.dpi * NODE_GROUP_FRAME / 72;
673 float socket_size = NODE_SOCKSIZE * U.dpi / 72;
674 float arrowbutw = 0.8f * UI_UNIT_X;
675 /* layout stuff for buttons on group left frame */
676 float colw = 0.6f * node_group_frame;
677 float col1 = 6 - node_group_frame;
678 float col2 = col1 + colw + 6;
679 float col3 = -arrowbutw - 6;
680 /* layout stuff for buttons on group right frame */
682 float cor2 = cor1 + arrowbutw + 6;
683 float cor3 = cor2 + arrowbutw + 6;
685 /* node and group socket circles */
687 node_socket_circle_draw(ntree, sock, socket_size, sock->flag & SELECT);
689 node_socket_circle_draw(ngroup, gsock, socket_size, gsock->flag & SELECT);
692 offset = (in_out == SOCK_IN ? col1 : cor3);
694 offset += (in_out == SOCK_IN ? node_group_frame : -node_group_frame);
696 /* draw both name and value button if:
697 * 1) input: not internal
698 * 2) output: (node type uses const outputs) and (group output is unlinked)
703 draw_value = !(gsock && (gsock->flag & SOCK_INTERNAL));
706 if (gnode->typeinfo->flag & NODE_CONST_OUTPUT)
707 draw_value = !(gsock && gsock->link);
711 /* both name and value buttons */
713 draw_group_socket_name(snode, gnode, gsock, in_out, offset, 0);
714 if (stype->buttonfunc)
715 stype->buttonfunc(C, gnode->block, ngroup, NULL, gsock, "", gsock->locx + offset, gsock->locy - NODE_DY, colw);
718 draw_group_socket_name(snode, gnode, sock, in_out, offset, 0);
719 if (stype->buttonfunc)
720 stype->buttonfunc(C, gnode->block, ngroup, NULL, sock, "", sock->locx + offset, sock->locy - NODE_DY, colw);
724 /* only name, no value button */
726 draw_group_socket_name(snode, gnode, gsock, in_out, offset, -NODE_DYS);
728 draw_group_socket_name(snode, gnode, sock, in_out, offset, -NODE_DYS);
731 if (gsock && (gsock->flag & SOCK_DYNAMIC)) {
732 /* up/down buttons */
733 offset = (in_out == SOCK_IN ? col2 : cor2);
734 uiBlockSetDirection(gnode->block, UI_TOP);
735 uiBlockBeginAlign(gnode->block);
736 bt = uiDefIconButO(gnode->block, BUT, "NODE_OT_group_socket_move_up", 0, ICON_TRIA_UP,
737 gsock->locx + offset, gsock->locy, arrowbutw, arrowbutw, "");
738 if (!gsock->prev || !(gsock->prev->flag & SOCK_DYNAMIC))
739 uiButSetFlag(bt, UI_BUT_DISABLED);
740 RNA_int_set(uiButGetOperatorPtrRNA(bt), "index", index);
741 RNA_enum_set(uiButGetOperatorPtrRNA(bt), "in_out", in_out);
742 bt = uiDefIconButO(gnode->block, BUT, "NODE_OT_group_socket_move_down", 0, ICON_TRIA_DOWN,
743 gsock->locx + offset, gsock->locy - arrowbutw, arrowbutw, arrowbutw, "");
744 if (!gsock->next || !(gsock->next->flag & SOCK_DYNAMIC))
745 uiButSetFlag(bt, UI_BUT_DISABLED);
746 RNA_int_set(uiButGetOperatorPtrRNA(bt), "index", index);
747 RNA_enum_set(uiButGetOperatorPtrRNA(bt), "in_out", in_out);
748 uiBlockEndAlign(gnode->block);
749 uiBlockSetDirection(gnode->block, 0);
752 offset = (in_out == SOCK_IN ? col3 : cor1);
753 uiBlockSetEmboss(gnode->block, UI_EMBOSSN);
754 bt = uiDefIconButO(gnode->block, BUT, "NODE_OT_group_socket_remove", 0, ICON_X,
755 gsock->locx + offset, gsock->locy - 0.5f * arrowbutw, arrowbutw, arrowbutw, "");
756 RNA_int_set(uiButGetOperatorPtrRNA(bt), "index", index);
757 RNA_enum_set(uiButGetOperatorPtrRNA(bt), "in_out", in_out);
758 uiBlockSetEmboss(gnode->block, UI_EMBOSS);
762 /* groups are, on creation, centered around 0,0 */
763 static void node_draw_group(const bContext *C, ARegion *ar, SpaceNode *snode, bNodeTree *ntree, bNode *gnode)
765 if (!(gnode->flag & NODE_GROUP_EDIT)) {
766 node_draw_default(C, ar, snode, ntree, gnode);
769 bNodeTree *ngroup = (bNodeTree *)gnode->id;
770 bNodeSocket *sock, *gsock;
773 rctf rect = gnode->totr;
774 float node_group_frame = U.dpi * NODE_GROUP_FRAME / 72;
775 float group_header = 26 * U.dpi / 72;
779 /* backdrop header */
781 uiSetRoundBox(UI_CNR_TOP_LEFT | UI_CNR_TOP_RIGHT);
782 UI_ThemeColorShadeAlpha(TH_NODE_GROUP, 0, -70);
783 uiDrawBox(GL_POLYGON, rect.xmin - node_group_frame, rect.ymax, rect.xmax + node_group_frame, rect.ymax + group_header, BASIS_RAD);
786 UI_ThemeColorShadeAlpha(TH_BACK, -8, -70);
787 uiSetRoundBox(UI_CNR_NONE);
788 uiDrawBox(GL_POLYGON, rect.xmin, rect.ymin, rect.xmax, rect.ymax, BASIS_RAD);
791 UI_ThemeColorShadeAlpha(TH_BACK, 10, -50);
792 uiSetRoundBox(UI_CNR_BOTTOM_LEFT);
793 uiDrawBox(GL_POLYGON, rect.xmin - node_group_frame, rect.ymin, rect.xmin, rect.ymax, BASIS_RAD);
796 UI_ThemeColorShadeAlpha(TH_BACK, 10, -50);
797 uiSetRoundBox(UI_CNR_BOTTOM_RIGHT);
798 uiDrawBox(GL_POLYGON, rect.xmax, rect.ymin, rect.xmax + node_group_frame, rect.ymax, BASIS_RAD);
800 /* input column separator */
801 glColor4ub(200, 200, 200, 140);
803 glVertex2f(rect.xmin, rect.ymin);
804 glVertex2f(rect.xmin, rect.ymax);
807 /* output column separator */
808 glColor4ub(200, 200, 200, 140);
810 glVertex2f(rect.xmax, rect.ymin);
811 glVertex2f(rect.xmax, rect.ymax);
814 /* group node outline */
815 uiSetRoundBox(UI_CNR_ALL);
816 glColor4ub(200, 200, 200, 140);
817 glEnable(GL_LINE_SMOOTH);
818 uiDrawBox(GL_LINE_LOOP, rect.xmin - node_group_frame, rect.ymin, rect.xmax + node_group_frame, rect.ymax + group_header, BASIS_RAD);
819 glDisable(GL_LINE_SMOOTH);
823 UI_ThemeColor(TH_TEXT_HI);
825 layout = uiBlockLayout(gnode->block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, (short)(rect.xmin + 15), (short)(rect.ymax + group_header),
826 MIN2((int)(rect.xmax - rect.xmin - 18.0f), node_group_frame + 20), group_header, UI_GetStyle());
827 RNA_pointer_create(&ntree->id, &RNA_Node, gnode, &ptr);
828 uiTemplateIDBrowse(layout, (bContext *)C, &ptr, "node_tree", NULL, NULL, NULL);
829 uiBlockLayoutResolve(gnode->block, NULL, NULL);
831 /* draw the internal tree nodes and links */
832 node_draw_nodetree(C, ar, snode, ngroup);
835 gsock = ngroup->inputs.first;
836 sock = gnode->inputs.first;
838 while (gsock || sock) {
839 while (sock && !sock->groupsock) {
840 draw_group_socket(C, snode, ntree, gnode, sock, NULL, index, SOCK_IN);
843 while (gsock && (!sock || sock->groupsock != gsock)) {
844 draw_group_socket(C, snode, ntree, gnode, NULL, gsock, index, SOCK_IN);
848 while (sock && gsock && sock->groupsock == gsock) {
849 draw_group_socket(C, snode, ntree, gnode, sock, gsock, index, SOCK_IN);
855 gsock = ngroup->outputs.first;
856 sock = gnode->outputs.first;
858 while (gsock || sock) {
859 while (sock && !sock->groupsock) {
860 draw_group_socket(C, snode, ntree, gnode, sock, NULL, index, SOCK_OUT);
863 while (gsock && (!sock || sock->groupsock != gsock)) {
864 draw_group_socket(C, snode, ntree, gnode, NULL, gsock, index, SOCK_OUT);
868 while (sock && gsock && sock->groupsock == gsock) {
869 draw_group_socket(C, snode, ntree, gnode, sock, gsock, index, SOCK_OUT);
876 uiEndBlock(C, gnode->block);
877 uiDrawBlock(C, gnode->block);
882 void node_uifunc_group(uiLayout *layout, bContext *C, PointerRNA *ptr)
884 uiTemplateIDBrowse(layout, C, ptr, "node_tree", NULL, NULL, NULL);
887 static void node_common_buts_whileloop(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
889 uiItemR(layout, ptr, "max_iterations", 0, NULL, 0);
892 /* XXX Does a bounding box update by iterating over all children.
893 * Not ideal to do this in every draw call, but doing as transform callback doesn't work,
894 * since the child node totr rects are not updated properly at that point.
896 static void node_update_frame(const bContext *UNUSED(C), bNodeTree *ntree, bNode *node)
898 const float margin = 30.0f;
899 NodeFrame *data = (NodeFrame *)node->storage;
905 /* init rect from current frame size */
906 nodeToView(node, node->offsetx, node->offsety, &rect.xmin, &rect.ymax);
907 nodeToView(node, node->offsetx + node->width, node->offsety - node->height, &rect.xmax, &rect.ymin);
909 /* frame can be resized manually only if shrinking is disabled or no children are attached */
910 data->flag |= NODE_FRAME_RESIZEABLE;
911 /* for shrinking bbox, initialize the rect from first child node */
912 bbinit = (data->flag & NODE_FRAME_SHRINK);
913 /* fit bounding box to all children */
914 for (tnode = ntree->nodes.first; tnode; tnode = tnode->next) {
915 if (tnode->parent != node)
918 /* add margin to node rect */
919 noderect = tnode->totr;
920 noderect.xmin -= margin;
921 noderect.xmax += margin;
922 noderect.ymin -= margin;
923 noderect.ymax += margin;
925 /* first child initializes frame */
929 data->flag &= ~NODE_FRAME_RESIZEABLE;
932 BLI_union_rctf(&rect, &noderect);
935 /* now adjust the frame size from view-space bounding box */
936 nodeFromView(node, rect.xmin, rect.ymax, &node->offsetx, &node->offsety);
937 nodeFromView(node, rect.xmax, rect.ymin, &xmax, &ymax);
938 node->width = xmax - node->offsetx;
939 node->height = -ymax + node->offsety;
944 static void node_draw_frame_label(bNode *node)
946 /* XXX font id is crap design */
947 const int fontid = blf_mono_font;
948 NodeFrame *data = (NodeFrame *)node->storage;
949 rctf *rct = &node->totr;
950 int color_id = node_get_colorid(node);
952 /* XXX a bit hacky, should use separate align values for x and y */
953 float width, ascender;
956 BLI_strncpy(label, nodeLabel(node), sizeof(label));
957 BLF_size(fontid, data->label_size, U.dpi);
960 UI_ThemeColorBlendShade(TH_TEXT, color_id, 0.8f, 10);
962 width = BLF_width(fontid, label);
963 ascender = BLF_ascender(fontid);
965 x = 0.5f * (rct->xmin + rct->xmax) - 0.5f * width;
966 y = rct->ymax - NODE_DYS - ascender;
968 BLF_position(fontid, x, y, 0);
969 BLF_draw(fontid, label, BLF_DRAW_STR_DUMMY_MAX);
972 static void node_draw_frame(const bContext *C, ARegion *ar, SpaceNode *snode, bNodeTree *UNUSED(ntree), bNode *node)
974 rctf *rct = &node->totr;
975 int color_id = node_get_colorid(node);
976 unsigned char color[4];
979 UI_GetThemeColor4ubv(TH_NODE_FRAME, color);
980 alpha = (float)(color[3])/255.0f;
982 /* skip if out of view */
983 if (node->totr.xmax < ar->v2d.cur.xmin || node->totr.xmin > ar->v2d.cur.xmax ||
984 node->totr.ymax < ar->v2d.cur.ymin || node->totr.ymin > ar->v2d.cur.ymax) {
986 uiEndBlock(C, node->block);
992 node_draw_shadow(snode, node, BASIS_RAD, alpha);
995 if (node->flag & NODE_CUSTOM_COLOR)
996 glColor4f(node->color[0], node->color[1], node->color[2], alpha);
998 UI_ThemeColor4(TH_NODE_FRAME);
1000 uiSetRoundBox(UI_CNR_ALL);
1001 uiRoundBox(rct->xmin, rct->ymin, rct->xmax, rct->ymax, BASIS_RAD);
1002 glDisable(GL_BLEND);
1004 /* outline active and selected emphasis */
1005 if (node->flag & (NODE_ACTIVE | SELECT) ) {
1007 glEnable(GL_LINE_SMOOTH);
1009 if (node->flag & NODE_ACTIVE)
1010 UI_ThemeColorShadeAlpha(TH_ACTIVE, 0, -40);
1012 UI_ThemeColorShadeAlpha(TH_SELECT, 0, -40);
1013 uiSetRoundBox(UI_CNR_ALL);
1014 uiDrawBox(GL_LINE_LOOP, rct->xmin, rct->ymin, rct->xmax, rct->ymax, BASIS_RAD);
1016 glDisable(GL_LINE_SMOOTH);
1017 glDisable(GL_BLEND);
1021 node_draw_frame_label(node);
1023 UI_ThemeClearColor(color_id);
1025 uiEndBlock(C, node->block);
1026 uiDrawBlock(C, node->block);
1030 static int node_resize_area_frame(bNode *node, int x, int y)
1032 const float size = 10.0f;
1033 NodeFrame *data = (NodeFrame *)node->storage;
1034 rctf totr = node->totr;
1037 /* shrinking frame size is determined by child nodes */
1038 if (!(data->flag & NODE_FRAME_RESIZEABLE))
1041 if (x >= totr.xmax - size && x < totr.xmax && y >= totr.ymin && y < totr.ymax)
1042 dir |= NODE_RESIZE_RIGHT;
1043 if (x >= totr.xmin && x < totr.xmin + size && y >= totr.ymin && y < totr.ymax)
1044 dir |= NODE_RESIZE_LEFT;
1045 if (x >= totr.xmin && x < totr.xmax && y >= totr.ymax - size && y < totr.ymax)
1046 dir |= NODE_RESIZE_TOP;
1047 if (x >= totr.xmin && x < totr.xmax && y >= totr.ymin && y < totr.ymin + size)
1048 dir |= NODE_RESIZE_BOTTOM;
1053 static void node_buts_frame_details(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1055 uiItemR(layout, ptr, "label_size", 0, IFACE_("Label Size"), ICON_NONE);
1056 uiItemR(layout, ptr, "shrink", 0, IFACE_("Shrink"), ICON_NONE);
1060 #define NODE_REROUTE_SIZE 8.0f
1062 static void node_update_reroute(const bContext *UNUSED(C), bNodeTree *UNUSED(ntree), bNode *node)
1066 float size = NODE_REROUTE_SIZE;
1068 /* get "global" coords */
1069 nodeToView(node, 0.0f, 0.0f, &locx, &locy);
1071 /* reroute node has exactly one input and one output, both in the same place */
1072 nsock= node->outputs.first;
1076 nsock= node->inputs.first;
1080 node->width = size*2;
1081 node->totr.xmin= locx - size;
1082 node->totr.xmax= locx + size;
1083 node->totr.ymax= locy + size;
1084 node->totr.ymin= locy - size;
1087 static void node_draw_reroute(const bContext *C, ARegion *ar, SpaceNode *UNUSED(snode), bNodeTree *ntree, bNode *node)
1091 rctf *rct= &node->totr;
1092 float size = NODE_REROUTE_SIZE;
1094 float socket_size= NODE_SOCKSIZE;
1096 /* skip if out of view */
1097 if (node->totr.xmax < ar->v2d.cur.xmin || node->totr.xmin > ar->v2d.cur.xmax ||
1098 node->totr.ymax < ar->v2d.cur.ymin || node->totr.ymin > ar->v2d.cur.ymax) {
1100 uiEndBlock(C, node->block);
1105 /* XXX only kept for debugging
1106 * selection state is indicated by socket outline below!
1111 UI_ThemeColor4(TH_NODE);
1113 uiRoundBox(rct->xmin, rct->ymin, rct->xmax, rct->ymax, size);
1114 glDisable(GL_BLEND);
1116 /* outline active and selected emphasis */
1117 if( node->flag & (NODE_ACTIVE|SELECT) ) {
1119 glEnable( GL_LINE_SMOOTH );
1120 /* using different shades of TH_TEXT_HI for the empasis, like triangle */
1121 if( node->flag & NODE_ACTIVE )
1122 UI_ThemeColorShadeAlpha(TH_TEXT_HI, 0, -40);
1124 UI_ThemeColorShadeAlpha(TH_TEXT_HI, -20, -120);
1125 uiDrawBox(GL_LINE_LOOP, rct->xmin, rct->ymin, rct->xmax, rct->ymax, size);
1127 glDisable( GL_LINE_SMOOTH );
1128 glDisable(GL_BLEND);
1132 /* only draw input socket. as they all are placed on the same position.
1133 * highlight also if node itself is selected, since we don't display the node body separately!
1135 for(sock= node->inputs.first; sock; sock= sock->next) {
1136 node_socket_circle_draw(ntree, sock, socket_size, (sock->flag & SELECT) || (node->flag & SELECT));
1139 uiEndBlock(C, node->block);
1140 uiDrawBlock(C, node->block);
1144 /* Special tweak area for reroute node.
1145 * Since this node is quite small, we use a larger tweak area for grabbing than for selection.
1147 static int node_tweak_area_reroute(bNode *node, int x, int y)
1149 /* square of tweak radius */
1150 static const float tweak_radius_sq = 576; /* 24*24 */
1152 bNodeSocket *sock = node->inputs.first;
1153 float dx = sock->locx - x;
1154 float dy = sock->locy - y;
1155 return (dx*dx + dy*dy <= tweak_radius_sq);
1158 static void node_common_set_butfunc(bNodeType *ntype)
1160 switch (ntype->type) {
1162 ntype->uifunc = node_uifunc_group;
1163 ntype->drawfunc = node_draw_group;
1164 ntype->drawupdatefunc = node_update_group;
1167 // ntype->uifunc= node_common_buts_group;
1168 ntype->drawfunc = node_draw_group;
1169 ntype->drawupdatefunc = node_update_group;
1171 case NODE_WHILELOOP:
1172 ntype->uifunc = node_common_buts_whileloop;
1173 ntype->drawfunc = node_draw_group;
1174 ntype->drawupdatefunc = node_update_group;
1177 ntype->drawfunc = node_draw_frame;
1178 ntype->drawupdatefunc = node_update_frame;
1179 ntype->uifuncbut = node_buts_frame_details;
1180 ntype->resize_area_func = node_resize_area_frame;
1183 ntype->drawfunc= node_draw_reroute;
1184 ntype->drawupdatefunc= node_update_reroute;
1185 ntype->tweak_area_func= node_tweak_area_reroute;
1190 /* ****************** BUTTON CALLBACKS FOR SHADER NODES ***************** */
1191 static void node_shader_buts_material(uiLayout *layout, bContext *C, PointerRNA *ptr)
1193 bNode *node = ptr->data;
1196 uiTemplateID(layout, C, ptr, "material", "MATERIAL_OT_new", NULL, NULL);
1198 if (!node->id) return;
1200 col = uiLayoutColumn(layout, 0);
1201 uiItemR(col, ptr, "use_diffuse", 0, NULL, ICON_NONE);
1202 uiItemR(col, ptr, "use_specular", 0, NULL, ICON_NONE);
1203 uiItemR(col, ptr, "invert_normal", 0, NULL, ICON_NONE);
1206 static void node_shader_buts_mapping(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1210 uiItemL(layout, IFACE_("Location:"), ICON_NONE);
1211 row = uiLayoutRow(layout, 1);
1212 uiItemR(row, ptr, "translation", 0, "", ICON_NONE);
1214 uiItemL(layout, IFACE_("Rotation:"), ICON_NONE);
1215 row = uiLayoutRow(layout, 1);
1216 uiItemR(row, ptr, "rotation", 0, "", ICON_NONE);
1218 uiItemL(layout, IFACE_("Scale:"), ICON_NONE);
1219 row = uiLayoutRow(layout, 1);
1220 uiItemR(row, ptr, "scale", 0, "", ICON_NONE);
1222 row = uiLayoutRow(layout, 1);
1223 uiItemR(row, ptr, "use_min", 0, "Min", ICON_NONE);
1224 uiItemR(row, ptr, "min", 0, "", ICON_NONE);
1226 row = uiLayoutRow(layout, 1);
1227 uiItemR(row, ptr, "use_max", 0, "Max", ICON_NONE);
1228 uiItemR(row, ptr, "max", 0, "", ICON_NONE);
1231 static void node_shader_buts_vect_math(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1233 uiItemR(layout, ptr, "operation", 0, "", ICON_NONE);
1236 static void node_shader_buts_geometry(uiLayout *layout, bContext *C, PointerRNA *ptr)
1238 PointerRNA obptr = CTX_data_pointer_get(C, "active_object");
1241 col = uiLayoutColumn(layout, 0);
1243 if (obptr.data && RNA_enum_get(&obptr, "type") == OB_MESH) {
1244 PointerRNA dataptr = RNA_pointer_get(&obptr, "data");
1246 uiItemPointerR(col, ptr, "uv_layer", &dataptr, "uv_textures", "", ICON_NONE);
1247 uiItemPointerR(col, ptr, "color_layer", &dataptr, "vertex_colors", "", ICON_NONE);
1250 uiItemR(col, ptr, "uv_layer", 0, IFACE_("UV"), ICON_NONE);
1251 uiItemR(col, ptr, "color_layer", 0, IFACE_("VCol"), ICON_NONE);
1255 static void node_shader_buts_attribute(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1257 uiItemR(layout, ptr, "attribute_name", 0, IFACE_("Name"), ICON_NONE);
1260 static void node_shader_buts_tex_image(uiLayout *layout, bContext *C, PointerRNA *ptr)
1262 uiTemplateID(layout, C, ptr, "image", NULL, "IMAGE_OT_open", NULL);
1263 uiItemR(layout, ptr, "color_space", 0, "", ICON_NONE);
1267 static void node_shader_buts_tex_environment(uiLayout *layout, bContext *C, PointerRNA *ptr)
1269 uiTemplateID(layout, C, ptr, "image", NULL, "IMAGE_OT_open", NULL);
1270 uiItemR(layout, ptr, "color_space", 0, "", ICON_NONE);
1271 uiItemR(layout, ptr, "projection", 0, "", ICON_NONE);
1274 static void node_shader_buts_tex_sky(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1276 uiItemR(layout, ptr, "sun_direction", 0, "", ICON_NONE);
1277 uiItemR(layout, ptr, "turbidity", 0, NULL, ICON_NONE);
1280 static void node_shader_buts_tex_gradient(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1282 uiItemR(layout, ptr, "gradient_type", 0, "", ICON_NONE);
1285 static void node_shader_buts_tex_magic(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1287 uiItemR(layout, ptr, "turbulence_depth", 0, NULL, ICON_NONE);
1290 static void node_shader_buts_tex_wave(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1292 uiItemR(layout, ptr, "wave_type", 0, "", ICON_NONE);
1295 static void node_shader_buts_tex_musgrave(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1297 uiItemR(layout, ptr, "musgrave_type", 0, "", ICON_NONE);
1300 static void node_shader_buts_tex_voronoi(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1302 uiItemR(layout, ptr, "coloring", 0, "", ICON_NONE);
1305 static void node_shader_buts_glossy(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1307 uiItemR(layout, ptr, "distribution", 0, "", ICON_NONE);
1310 /* only once called */
1311 static void node_shader_set_butfunc(bNodeType *ntype)
1313 switch (ntype->type) {
1314 /* case NODE_GROUP: note, typeinfo for group is generated... see "XXX ugly hack" */
1316 case SH_NODE_MATERIAL:
1317 case SH_NODE_MATERIAL_EXT:
1318 ntype->uifunc = node_shader_buts_material;
1320 case SH_NODE_TEXTURE:
1321 ntype->uifunc = node_buts_texture;
1323 case SH_NODE_NORMAL:
1324 ntype->uifunc = node_buts_normal;
1326 case SH_NODE_CURVE_VEC:
1327 ntype->uifunc = node_buts_curvevec;
1329 case SH_NODE_CURVE_RGB:
1330 ntype->uifunc = node_buts_curvecol;
1332 case SH_NODE_MAPPING:
1333 ntype->uifunc = node_shader_buts_mapping;
1336 ntype->uifunc = node_buts_value;
1339 ntype->uifunc = node_buts_rgb;
1341 case SH_NODE_MIX_RGB:
1342 ntype->uifunc = node_buts_mix_rgb;
1344 case SH_NODE_VALTORGB:
1345 ntype->uifunc = node_buts_colorramp;
1348 ntype->uifunc = node_buts_math;
1350 case SH_NODE_VECT_MATH:
1351 ntype->uifunc = node_shader_buts_vect_math;
1353 case SH_NODE_GEOMETRY:
1354 ntype->uifunc = node_shader_buts_geometry;
1356 case SH_NODE_ATTRIBUTE:
1357 ntype->uifunc = node_shader_buts_attribute;
1359 case SH_NODE_TEX_SKY:
1360 ntype->uifunc = node_shader_buts_tex_sky;
1362 case SH_NODE_TEX_IMAGE:
1363 ntype->uifunc = node_shader_buts_tex_image;
1365 case SH_NODE_TEX_ENVIRONMENT:
1366 ntype->uifunc = node_shader_buts_tex_environment;
1368 case SH_NODE_TEX_GRADIENT:
1369 ntype->uifunc = node_shader_buts_tex_gradient;
1371 case SH_NODE_TEX_MAGIC:
1372 ntype->uifunc = node_shader_buts_tex_magic;
1374 case SH_NODE_TEX_WAVE:
1375 ntype->uifunc = node_shader_buts_tex_wave;
1377 case SH_NODE_TEX_MUSGRAVE:
1378 ntype->uifunc = node_shader_buts_tex_musgrave;
1380 case SH_NODE_TEX_VORONOI:
1381 ntype->uifunc = node_shader_buts_tex_voronoi;
1383 case SH_NODE_BSDF_GLOSSY:
1384 case SH_NODE_BSDF_GLASS:
1385 ntype->uifunc = node_shader_buts_glossy;
1390 /* ****************** BUTTON CALLBACKS FOR COMPOSITE NODES ***************** */
1392 static void node_composit_buts_image(uiLayout *layout, bContext *C, PointerRNA *ptr)
1395 bNode *node = ptr->data;
1400 uiTemplateID(layout, C, ptr, "image", NULL, "IMAGE_OT_open", NULL);
1402 if (!node->id) return;
1404 prop = RNA_struct_find_property(ptr, "image");
1405 if (!prop || RNA_property_type(prop) != PROP_POINTER) return;
1406 imaptr = RNA_property_pointer_get(ptr, prop);
1408 col = uiLayoutColumn(layout, 0);
1410 uiItemR(col, &imaptr, "source", 0, NULL, ICON_NONE);
1412 source = RNA_enum_get(&imaptr, "source");
1414 if (source == IMA_SRC_SEQUENCE) {
1415 /* don't use iuser->framenr directly because it may not be updated if auto-refresh is off */
1416 Scene *scene = CTX_data_scene(C);
1417 ImageUser *iuser = node->storage;
1419 const int framenr = BKE_image_user_frame_get(iuser, CFRA, 0);
1420 BLI_snprintf(numstr, sizeof(numstr), IFACE_("Frame: %d"), framenr);
1421 uiItemL(layout, numstr, ICON_NONE);
1424 if (ELEM(source, IMA_SRC_SEQUENCE, IMA_SRC_MOVIE)) {
1425 col = uiLayoutColumn(layout, 1);
1426 uiItemR(col, ptr, "frame_duration", 0, NULL, ICON_NONE);
1427 uiItemR(col, ptr, "frame_start", 0, NULL, ICON_NONE);
1428 uiItemR(col, ptr, "frame_offset", 0, NULL, ICON_NONE);
1429 uiItemR(col, ptr, "use_cyclic", 0, NULL, ICON_NONE);
1430 uiItemR(col, ptr, "use_auto_refresh", UI_ITEM_R_ICON_ONLY, NULL, ICON_NONE);
1433 col = uiLayoutColumn(layout, 0);
1435 if (RNA_enum_get(&imaptr, "type") == IMA_TYPE_MULTILAYER)
1436 uiItemR(col, ptr, "layer", 0, NULL, ICON_NONE);
1439 static void node_composit_buts_renderlayers(uiLayout *layout, bContext *C, PointerRNA *ptr)
1441 bNode *node = ptr->data;
1442 uiLayout *col, *row;
1446 const char *layer_name;
1447 char scene_name[MAX_ID_NAME - 2];
1448 wmOperatorType *ot = WM_operatortype_find("RENDER_OT_render", 1);
1450 BLI_assert(ot != 0);
1452 uiTemplateID(layout, C, ptr, "scene", NULL, NULL, NULL);
1454 if (!node->id) return;
1456 col = uiLayoutColumn(layout, 0);
1457 row = uiLayoutRow(col, 0);
1458 uiItemR(row, ptr, "layer", 0, "", ICON_NONE);
1460 prop = RNA_struct_find_property(ptr, "layer");
1461 if (!(RNA_property_enum_identifier(C, ptr, prop, RNA_property_enum_get(ptr, prop), &layer_name)))
1464 scn_ptr = RNA_pointer_get(ptr, "scene");
1465 RNA_string_get(&scn_ptr, "name", scene_name);
1467 WM_operator_properties_create_ptr(&op_ptr, ot);
1468 RNA_string_set(&op_ptr, "layer", layer_name);
1469 RNA_string_set(&op_ptr, "scene", scene_name);
1470 uiItemFullO_ptr(row, ot, "", ICON_RENDER_STILL, op_ptr.data, WM_OP_INVOKE_DEFAULT, 0);
1475 static void node_composit_buts_blur(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1477 uiLayout *col, *row;
1479 col = uiLayoutColumn(layout, 0);
1481 uiItemR(col, ptr, "filter_type", 0, "", ICON_NONE);
1482 if (RNA_enum_get(ptr, "filter_type") != R_FILTER_FAST_GAUSS) {
1483 uiItemR(col, ptr, "use_bokeh", 0, NULL, ICON_NONE);
1484 uiItemR(col, ptr, "use_gamma_correction", 0, NULL, ICON_NONE);
1487 uiItemR(col, ptr, "use_relative", 0, NULL, ICON_NONE);
1489 if (RNA_boolean_get(ptr, "use_relative")) {
1490 uiItemL(col, IFACE_("Aspect Correction"), 0);
1491 row = uiLayoutRow(layout, 1);
1492 uiItemR(row, ptr, "aspect_correction", UI_ITEM_R_EXPAND, NULL, 0);
1494 col = uiLayoutColumn(layout, 1);
1495 uiItemR(col, ptr, "factor_x", 0, IFACE_("X"), ICON_NONE);
1496 uiItemR(col, ptr, "factor_y", 0, IFACE_("Y"), ICON_NONE);
1499 col = uiLayoutColumn(layout, 1);
1500 uiItemR(col, ptr, "size_x", 0, IFACE_("X"), ICON_NONE);
1501 uiItemR(col, ptr, "size_y", 0, IFACE_("Y"), ICON_NONE);
1505 static void node_composit_buts_dblur(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1509 uiItemR(layout, ptr, "iterations", 0, NULL, ICON_NONE);
1510 uiItemR(layout, ptr, "use_wrap", 0, NULL, ICON_NONE);
1512 col = uiLayoutColumn(layout, 1);
1513 uiItemL(col, IFACE_("Center:"), ICON_NONE);
1514 uiItemR(col, ptr, "center_x", 0, IFACE_("X"), ICON_NONE);
1515 uiItemR(col, ptr, "center_y", 0, IFACE_("Y"), ICON_NONE);
1519 col = uiLayoutColumn(layout, 1);
1520 uiItemR(col, ptr, "distance", 0, NULL, ICON_NONE);
1521 uiItemR(col, ptr, "angle", 0, NULL, ICON_NONE);
1525 uiItemR(layout, ptr, "spin", 0, NULL, ICON_NONE);
1526 uiItemR(layout, ptr, "zoom", 0, NULL, ICON_NONE);
1529 static void node_composit_buts_bilateralblur(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1533 col = uiLayoutColumn(layout, 1);
1534 uiItemR(col, ptr, "iterations", 0, NULL, ICON_NONE);
1535 uiItemR(col, ptr, "sigma_color", 0, NULL, ICON_NONE);
1536 uiItemR(col, ptr, "sigma_space", 0, NULL, ICON_NONE);
1539 static void node_composit_buts_defocus(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1541 uiLayout *sub, *col;
1543 col = uiLayoutColumn(layout, 0);
1544 uiItemL(col, IFACE_("Bokeh Type:"), ICON_NONE);
1545 uiItemR(col, ptr, "bokeh", 0, "", ICON_NONE);
1546 uiItemR(col, ptr, "angle", 0, NULL, ICON_NONE);
1548 uiItemR(layout, ptr, "use_gamma_correction", 0, NULL, ICON_NONE);
1550 col = uiLayoutColumn(layout, 0);
1551 uiLayoutSetActive(col, RNA_boolean_get(ptr, "use_zbuffer") == TRUE);
1552 uiItemR(col, ptr, "f_stop", 0, NULL, ICON_NONE);
1554 uiItemR(layout, ptr, "blur_max", 0, NULL, ICON_NONE);
1555 uiItemR(layout, ptr, "threshold", 0, NULL, ICON_NONE);
1557 col = uiLayoutColumn(layout, 0);
1558 uiItemR(col, ptr, "use_preview", 0, NULL, ICON_NONE);
1559 sub = uiLayoutColumn(col, 0);
1560 uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_preview"));
1561 uiItemR(sub, ptr, "samples", 0, NULL, ICON_NONE);
1563 col = uiLayoutColumn(layout, 0);
1564 uiItemR(col, ptr, "use_zbuffer", 0, NULL, ICON_NONE);
1565 sub = uiLayoutColumn(col, 0);
1566 uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_zbuffer") == FALSE);
1567 uiItemR(sub, ptr, "z_scale", 0, NULL, ICON_NONE);
1570 /* qdn: glare node */
1571 static void node_composit_buts_glare(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1573 uiItemR(layout, ptr, "glare_type", 0, "", ICON_NONE);
1574 uiItemR(layout, ptr, "quality", 0, "", ICON_NONE);
1576 if (RNA_enum_get(ptr, "glare_type") != 1) {
1577 uiItemR(layout, ptr, "iterations", 0, NULL, ICON_NONE);
1579 if (RNA_enum_get(ptr, "glare_type") != 0)
1580 uiItemR(layout, ptr, "color_modulation", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1583 uiItemR(layout, ptr, "mix", 0, NULL, ICON_NONE);
1584 uiItemR(layout, ptr, "threshold", 0, NULL, ICON_NONE);
1586 if (RNA_enum_get(ptr, "glare_type") == 2) {
1587 uiItemR(layout, ptr, "streaks", 0, NULL, ICON_NONE);
1588 uiItemR(layout, ptr, "angle_offset", 0, NULL, ICON_NONE);
1590 if (RNA_enum_get(ptr, "glare_type") == 0 || RNA_enum_get(ptr, "glare_type") == 2) {
1591 uiItemR(layout, ptr, "fade", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1593 if (RNA_enum_get(ptr, "glare_type") == 0)
1594 uiItemR(layout, ptr, "use_rotate_45", 0, NULL, ICON_NONE);
1596 if (RNA_enum_get(ptr, "glare_type") == 1) {
1597 uiItemR(layout, ptr, "size", 0, NULL, ICON_NONE);
1601 static void node_composit_buts_tonemap(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1605 col = uiLayoutColumn(layout, 0);
1606 uiItemR(col, ptr, "tonemap_type", 0, "", ICON_NONE);
1607 if (RNA_enum_get(ptr, "tonemap_type") == 0) {
1608 uiItemR(col, ptr, "key", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1609 uiItemR(col, ptr, "offset", 0, NULL, ICON_NONE);
1610 uiItemR(col, ptr, "gamma", 0, NULL, ICON_NONE);
1613 uiItemR(col, ptr, "intensity", 0, NULL, ICON_NONE);
1614 uiItemR(col, ptr, "contrast", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1615 uiItemR(col, ptr, "adaptation", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1616 uiItemR(col, ptr, "correction", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1620 static void node_composit_buts_lensdist(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1624 col = uiLayoutColumn(layout, 0);
1625 uiItemR(col, ptr, "use_projector", 0, NULL, ICON_NONE);
1627 col = uiLayoutColumn(col, 0);
1628 uiLayoutSetActive(col, RNA_boolean_get(ptr, "use_projector") == FALSE);
1629 uiItemR(col, ptr, "use_jitter", 0, NULL, ICON_NONE);
1630 uiItemR(col, ptr, "use_fit", 0, NULL, ICON_NONE);
1633 static void node_composit_buts_vecblur(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1637 col = uiLayoutColumn(layout, 0);
1638 uiItemR(col, ptr, "samples", 0, NULL, ICON_NONE);
1639 uiItemR(col, ptr, "factor", 0, IFACE_("Blur"), ICON_NONE);
1641 col = uiLayoutColumn(layout, 1);
1642 uiItemL(col, IFACE_("Speed:"), ICON_NONE);
1643 uiItemR(col, ptr, "speed_min", 0, IFACE_("Min"), ICON_NONE);
1644 uiItemR(col, ptr, "speed_max", 0, IFACE_("Max"), ICON_NONE);
1646 uiItemR(layout, ptr, "use_curved", 0, NULL, ICON_NONE);
1649 static void node_composit_buts_filter(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1651 uiItemR(layout, ptr, "filter_type", 0, "", ICON_NONE);
1654 static void node_composit_buts_flip(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1656 uiItemR(layout, ptr, "axis", 0, "", ICON_NONE);
1659 static void node_composit_buts_crop(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1663 uiItemR(layout, ptr, "use_crop_size", 0, NULL, ICON_NONE);
1664 uiItemR(layout, ptr, "relative", 0, NULL, ICON_NONE);
1666 col = uiLayoutColumn(layout, 1);
1667 if (RNA_boolean_get(ptr, "relative")) {
1668 uiItemR(col, ptr, "rel_min_x", 0, IFACE_("Left"), ICON_NONE);
1669 uiItemR(col, ptr, "rel_max_x", 0, IFACE_("Right"), ICON_NONE);
1670 uiItemR(col, ptr, "rel_min_y", 0, IFACE_("Up"), ICON_NONE);
1671 uiItemR(col, ptr, "rel_max_y", 0, IFACE_("Down"), ICON_NONE);
1674 uiItemR(col, ptr, "min_x", 0, IFACE_("Left"), ICON_NONE);
1675 uiItemR(col, ptr, "max_x", 0, IFACE_("Right"), ICON_NONE);
1676 uiItemR(col, ptr, "min_y", 0, IFACE_("Up"), ICON_NONE);
1677 uiItemR(col, ptr, "max_y", 0, IFACE_("Down"), ICON_NONE);
1681 static void node_composit_buts_splitviewer(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1683 uiLayout *row, *col;
1685 col = uiLayoutColumn(layout, 0);
1686 row = uiLayoutRow(col, 0);
1687 uiItemR(row, ptr, "axis", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
1688 uiItemR(col, ptr, "factor", 0, NULL, ICON_NONE);
1691 static void node_composit_buts_double_edge_mask(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1695 col = uiLayoutColumn(layout, 0);
1697 uiItemL(col, IFACE_("Inner Edge:"), ICON_NONE);
1698 uiItemR(col, ptr, "inner_mode", 0, "", ICON_NONE);
1699 uiItemL(col, IFACE_("Buffer Edge:"), ICON_NONE);
1700 uiItemR(col, ptr, "edge_mode", 0, "", ICON_NONE);
1703 static void node_composit_buts_map_value(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1705 uiLayout *sub, *col;
1707 col = uiLayoutColumn(layout, 1);
1708 uiItemR(col, ptr, "offset", 0, NULL, ICON_NONE);
1709 uiItemR(col, ptr, "size", 0, NULL, ICON_NONE);
1711 col = uiLayoutColumn(layout, 1);
1712 uiItemR(col, ptr, "use_min", 0, NULL, ICON_NONE);
1713 sub = uiLayoutColumn(col, 0);
1714 uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_min"));
1715 uiItemR(sub, ptr, "min", 0, "", ICON_NONE);
1717 col = uiLayoutColumn(layout, 1);
1718 uiItemR(col, ptr, "use_max", 0, NULL, ICON_NONE);
1719 sub = uiLayoutColumn(col, 0);
1720 uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_max"));
1721 uiItemR(sub, ptr, "max", 0, "", ICON_NONE);
1724 static void node_composit_buts_alphaover(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1728 col = uiLayoutColumn(layout, 1);
1729 uiItemR(col, ptr, "use_premultiply", 0, NULL, ICON_NONE);
1730 uiItemR(col, ptr, "premul", 0, NULL, ICON_NONE);
1733 static void node_composit_buts_zcombine(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1737 col = uiLayoutColumn(layout, 1);
1738 uiItemR(col, ptr, "use_alpha", 0, NULL, ICON_NONE);
1742 static void node_composit_buts_hue_sat(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1746 col = uiLayoutColumn(layout, 0);
1747 uiItemR(col, ptr, "color_hue", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1748 uiItemR(col, ptr, "color_saturation", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1749 uiItemR(col, ptr, "color_value", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1752 static void node_composit_buts_dilateerode(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1754 uiItemR(layout, ptr, "type", 0, NULL, ICON_NONE);
1755 uiItemR(layout, ptr, "distance", 0, NULL, ICON_NONE);
1756 if (RNA_enum_get(ptr, "type") == CMP_NODE_DILATEERODE_DISTANCE_THRESH) {
1757 uiItemR(layout, ptr, "edge", 0, NULL, ICON_NONE);
1761 static void node_composit_buts_diff_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1765 col = uiLayoutColumn(layout, 1);
1766 uiItemR(col, ptr, "tolerance", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1767 uiItemR(col, ptr, "falloff", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1770 static void node_composit_buts_distance_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1772 uiLayout *col, *row;
1774 col = uiLayoutColumn(layout, 1);
1776 uiItemL(layout, IFACE_("Color Space:"), ICON_NONE);
1777 row = uiLayoutRow(layout, 0);
1778 uiItemR(row, ptr, "channel", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
1780 uiItemR(col, ptr, "tolerance", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1781 uiItemR(col, ptr, "falloff", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1784 static void node_composit_buts_color_spill(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1786 uiLayout *row, *col;
1788 uiItemL(layout, IFACE_("Despill Channel:"), ICON_NONE);
1789 row = uiLayoutRow(layout, 0);
1790 uiItemR(row, ptr, "channel", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
1792 col = uiLayoutColumn(layout, 0);
1793 uiItemR(col, ptr, "limit_method", 0, NULL, ICON_NONE);
1795 if (RNA_enum_get(ptr, "limit_method") == 0) {
1796 uiItemL(col, IFACE_("Limiting Channel:"), ICON_NONE);
1797 row = uiLayoutRow(col, 0);
1798 uiItemR(row, ptr, "limit_channel", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
1801 uiItemR(col, ptr, "ratio", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1802 uiItemR(col, ptr, "use_unspill", 0, NULL, ICON_NONE);
1803 if (RNA_boolean_get(ptr, "use_unspill") == TRUE) {
1804 uiItemR(col, ptr, "unspill_red", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1805 uiItemR(col, ptr, "unspill_green", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1806 uiItemR(col, ptr, "unspill_blue", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1810 static void node_composit_buts_chroma_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1814 col = uiLayoutColumn(layout, 0);
1815 uiItemR(col, ptr, "tolerance", 0, NULL, ICON_NONE);
1816 uiItemR(col, ptr, "threshold", 0, NULL, ICON_NONE);
1818 col = uiLayoutColumn(layout, 1);
1819 /*uiItemR(col, ptr, "lift", UI_ITEM_R_SLIDER, NULL, ICON_NONE); Removed for now */
1820 uiItemR(col, ptr, "gain", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1821 /*uiItemR(col, ptr, "shadow_adjust", UI_ITEM_R_SLIDER, NULL, ICON_NONE); Removed for now*/
1824 static void node_composit_buts_color_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1828 col = uiLayoutColumn(layout, 1);
1829 uiItemR(col, ptr, "color_hue", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1830 uiItemR(col, ptr, "color_saturation", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1831 uiItemR(col, ptr, "color_value", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1834 static void node_composit_buts_channel_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1836 uiLayout *col, *row;
1838 uiItemL(layout, IFACE_("Color Space:"), ICON_NONE);
1839 row = uiLayoutRow(layout, 0);
1840 uiItemR(row, ptr, "color_space", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
1842 col = uiLayoutColumn(layout, 0);
1843 uiItemL(col, IFACE_("Key Channel:"), ICON_NONE);
1844 row = uiLayoutRow(col, 0);
1845 uiItemR(row, ptr, "matte_channel", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
1847 col = uiLayoutColumn(layout, 0);
1849 uiItemR(col, ptr, "limit_method", 0, NULL, ICON_NONE);
1850 if (RNA_enum_get(ptr, "limit_method") == 0) {
1851 uiItemL(col, IFACE_("Limiting Channel:"), ICON_NONE);
1852 row = uiLayoutRow(col, 0);
1853 uiItemR(row, ptr, "limit_channel", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
1856 uiItemR(col, ptr, "limit_max", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1857 uiItemR(col, ptr, "limit_min", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1860 static void node_composit_buts_luma_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1864 col = uiLayoutColumn(layout, 1);
1865 uiItemR(col, ptr, "limit_max", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1866 uiItemR(col, ptr, "limit_min", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
1869 static void node_composit_buts_map_uv(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1871 uiItemR(layout, ptr, "alpha", 0, NULL, ICON_NONE);
1874 static void node_composit_buts_id_mask(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1876 uiItemR(layout, ptr, "index", 0, NULL, ICON_NONE);
1877 uiItemR(layout, ptr, "use_smooth_mask", 0, NULL, ICON_NONE);
1880 /* draw function for file output node sockets, displays only sub-path and format, no value button */
1881 static void node_draw_input_file_output(const bContext *C, uiBlock *block,
1882 bNodeTree *ntree, bNode *node, bNodeSocket *sock,
1883 const char *UNUSED(name), int x, int y, int width)
1885 uiLayout *layout, *row;
1886 PointerRNA nodeptr, inputptr, imfptr;
1889 RNA_pointer_create(&ntree->id, &RNA_Node, node, &nodeptr);
1891 layout = uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, x, y + NODE_DY, width, 20, UI_GetStyle());
1892 row = uiLayoutRow(layout, 0);
1894 imfptr = RNA_pointer_get(&nodeptr, "format");
1895 imtype = RNA_enum_get(&imfptr, "file_format");
1896 if (imtype == R_IMF_IMTYPE_MULTILAYER) {
1897 NodeImageMultiFileSocket *input = sock->storage;
1898 RNA_pointer_create(&ntree->id, &RNA_NodeOutputFileSlotLayer, input, &inputptr);
1900 uiItemL(row, input->layer, 0);
1903 NodeImageMultiFileSocket *input = sock->storage;
1904 PropertyRNA *imtype_prop;
1905 const char *imtype_name;
1906 RNA_pointer_create(&ntree->id, &RNA_NodeOutputFileSlotFile, input, &inputptr);
1908 uiItemL(row, input->path, 0);
1910 if (!RNA_boolean_get(&inputptr, "use_node_format"))
1911 imfptr = RNA_pointer_get(&inputptr, "format");
1913 imtype_prop = RNA_struct_find_property(&imfptr, "file_format");
1914 RNA_property_enum_name((bContext *)C, &imfptr, imtype_prop, RNA_property_enum_get(&imfptr, imtype_prop), &imtype_name);
1915 uiBlockSetEmboss(block, UI_EMBOSSP);
1916 uiItemL(row, imtype_name, 0);
1917 uiBlockSetEmboss(block, UI_EMBOSSN);
1920 uiBlockLayoutResolve(block, &rx, &ry);
1922 static void node_composit_buts_file_output(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
1924 PointerRNA imfptr = RNA_pointer_get(ptr, "format");
1925 int multilayer = (RNA_enum_get(&imfptr, "file_format") == R_IMF_IMTYPE_MULTILAYER);
1928 uiItemL(layout, IFACE_("Path:"), 0);
1930 uiItemL(layout, IFACE_("Base Path:"), 0);
1931 uiItemR(layout, ptr, "base_path", 0, "", ICON_NONE);
1933 static void node_composit_buts_file_output_details(uiLayout *layout, bContext *C, PointerRNA *ptr)
1935 PointerRNA imfptr = RNA_pointer_get(ptr, "format");
1936 PointerRNA active_input_ptr, op_ptr;
1939 int multilayer = (RNA_enum_get(&imfptr, "file_format") == R_IMF_IMTYPE_MULTILAYER);
1941 node_composit_buts_file_output(layout, C, ptr);
1942 uiTemplateImageSettings(layout, &imfptr);
1946 uiItemO(layout, IFACE_("Add Input"), ICON_ZOOMIN, "NODE_OT_output_file_add_socket");
1948 active_index = RNA_int_get(ptr, "active_input_index");
1949 /* using different collection properties if multilayer format is enabled */
1951 uiTemplateList(layout, C, ptr, "layer_slots", ptr, "active_input_index", NULL, 0, 0, 0);
1952 RNA_property_collection_lookup_int(ptr, RNA_struct_find_property(ptr, "layer_slots"), active_index, &active_input_ptr);
1955 uiTemplateList(layout, C, ptr, "file_slots", ptr, "active_input_index", NULL, 0, 0, 0);
1956 RNA_property_collection_lookup_int(ptr, RNA_struct_find_property(ptr, "file_slots"), active_index, &active_input_ptr);
1958 /* XXX collection lookup does not return the ID part of the pointer, setting this manually here */
1959 active_input_ptr.id.data = ptr->id.data;
1961 row = uiLayoutRow(layout, 1);
1962 op_ptr = uiItemFullO(row, "NODE_OT_output_file_move_active_socket", "", ICON_TRIA_UP, NULL, WM_OP_INVOKE_DEFAULT, UI_ITEM_O_RETURN_PROPS);
1963 RNA_enum_set(&op_ptr, "direction", 1);
1964 op_ptr = uiItemFullO(row, "NODE_OT_output_file_move_active_socket", "", ICON_TRIA_DOWN, NULL, WM_OP_INVOKE_DEFAULT, UI_ITEM_O_RETURN_PROPS);
1965 RNA_enum_set(&op_ptr, "direction", 2);
1967 if (active_input_ptr.data) {
1969 uiLayout *row, *col;
1970 col = uiLayoutColumn(layout, 1);
1972 uiItemL(col, IFACE_("Layer:"), 0);
1973 row = uiLayoutRow(col, 0);
1974 uiItemR(row, &active_input_ptr, "name", 0, "", 0);
1975 uiItemFullO(row, "NODE_OT_output_file_remove_active_socket", "", ICON_X, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_R_ICON_ONLY);
1978 uiLayout *row, *col;
1979 col = uiLayoutColumn(layout, 1);
1981 uiItemL(col, IFACE_("File Path:"), 0);
1982 row = uiLayoutRow(col, 0);
1983 uiItemR(row, &active_input_ptr, "path", 0, "", 0);
1984 uiItemFullO(row, "NODE_OT_output_file_remove_active_socket", "", ICON_X, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_R_ICON_ONLY);
1986 /* format details for individual files */
1987 imfptr = RNA_pointer_get(&active_input_ptr, "format");
1989 col = uiLayoutColumn(layout, 1);
1990 uiItemL(col, IFACE_("Format:"), 0);
1991 uiItemR(col, &active_input_ptr, "use_node_format", 0, NULL, 0);
1993 col = uiLayoutColumn(layout, 0);
1994 uiLayoutSetActive(col, RNA_boolean_get(&active_input_ptr, "use_node_format") == FALSE);
1995 uiTemplateImageSettings(col, &imfptr);
2000 static void node_composit_buts_scale(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2002 uiItemR(layout, ptr, "space", 0, "", ICON_NONE);
2005 static void node_composit_buts_rotate(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2007 uiItemR(layout, ptr, "filter_type", 0, "", ICON_NONE);
2010 static void node_composit_buts_invert(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2014 col = uiLayoutColumn(layout, 0);
2015 uiItemR(col, ptr, "invert_rgb", 0, NULL, ICON_NONE);
2016 uiItemR(col, ptr, "invert_alpha", 0, NULL, ICON_NONE);
2019 static void node_composit_buts_premulkey(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2021 uiItemR(layout, ptr, "mapping", 0, "", ICON_NONE);
2024 static void node_composit_buts_view_levels(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2026 uiItemR(layout, ptr, "channel", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
2029 static void node_composit_buts_colorbalance(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2031 uiLayout *split, *col, *row;
2033 uiItemR(layout, ptr, "correction_method", 0, NULL, ICON_NONE);
2035 if (RNA_enum_get(ptr, "correction_method") == 0) {
2037 split = uiLayoutSplit(layout, 0, 0);
2038 col = uiLayoutColumn(split, 0);
2039 uiTemplateColorWheel(col, ptr, "lift", 1, 1, 0, 1);
2040 row = uiLayoutRow(col, 0);
2041 uiItemR(row, ptr, "lift", 0, NULL, ICON_NONE);
2043 col = uiLayoutColumn(split, 0);
2044 uiTemplateColorWheel(col, ptr, "gamma", 1, 1, 1, 1);
2045 row = uiLayoutRow(col, 0);
2046 uiItemR(row, ptr, "gamma", 0, NULL, ICON_NONE);
2048 col = uiLayoutColumn(split, 0);
2049 uiTemplateColorWheel(col, ptr, "gain", 1, 1, 1, 1);
2050 row = uiLayoutRow(col, 0);
2051 uiItemR(row, ptr, "gain", 0, NULL, ICON_NONE);
2056 split = uiLayoutSplit(layout, 0, 0);
2057 col = uiLayoutColumn(split, 0);
2058 uiTemplateColorWheel(col, ptr, "offset", 1, 1, 0, 1);
2059 row = uiLayoutRow(col, 0);
2060 uiItemR(row, ptr, "offset", 0, NULL, ICON_NONE);
2062 col = uiLayoutColumn(split, 0);
2063 uiTemplateColorWheel(col, ptr, "power", 1, 1, 0, 1);
2064 row = uiLayoutRow(col, 0);
2065 uiItemR(row, ptr, "power", 0, NULL, ICON_NONE);
2067 col = uiLayoutColumn(split, 0);
2068 uiTemplateColorWheel(col, ptr, "slope", 1, 1, 0, 1);
2069 row = uiLayoutRow(col, 0);
2070 uiItemR(row, ptr, "slope", 0, NULL, ICON_NONE);
2074 static void node_composit_buts_colorbalance_but(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2076 uiItemR(layout, ptr, "correction_method", 0, NULL, ICON_NONE);
2078 if (RNA_enum_get(ptr, "correction_method") == 0) {
2080 uiTemplateColorWheel(layout, ptr, "lift", 1, 1, 0, 1);
2081 uiItemR(layout, ptr, "lift", 0, NULL, ICON_NONE);
2083 uiTemplateColorWheel(layout, ptr, "gamma", 1, 1, 1, 1);
2084 uiItemR(layout, ptr, "gamma", 0, NULL, ICON_NONE);
2086 uiTemplateColorWheel(layout, ptr, "gain", 1, 1, 1, 1);
2087 uiItemR(layout, ptr, "gain", 0, NULL, ICON_NONE);
2090 uiTemplateColorWheel(layout, ptr, "offset", 1, 1, 0, 1);
2091 uiItemR(layout, ptr, "offset", 0, NULL, ICON_NONE);
2093 uiTemplateColorWheel(layout, ptr, "power", 1, 1, 0, 1);
2094 uiItemR(layout, ptr, "power", 0, NULL, ICON_NONE);
2096 uiTemplateColorWheel(layout, ptr, "slope", 1, 1, 0, 1);
2097 uiItemR(layout, ptr, "slope", 0, NULL, ICON_NONE);
2102 static void node_composit_buts_huecorrect(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2104 uiTemplateCurveMapping(layout, ptr, "mapping", 'h', 0, 0);
2107 static void node_composit_buts_ycc(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2109 uiItemR(layout, ptr, "mode", 0, "", ICON_NONE);
2112 static void node_composit_buts_movieclip(uiLayout *layout, bContext *C, PointerRNA *ptr)
2114 uiTemplateID(layout, C, ptr, "clip", NULL, "CLIP_OT_open", NULL);
2117 static void node_composit_buts_stabilize2d(uiLayout *layout, bContext *C, PointerRNA *ptr)
2119 bNode *node = ptr->data;
2121 uiTemplateID(layout, C, ptr, "clip", NULL, "CLIP_OT_open", NULL);
2126 uiItemR(layout, ptr, "filter_type", 0, "", 0);
2129 static void node_composit_buts_transform(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2131 uiItemR(layout, ptr, "filter_type", 0, "", 0);
2134 static void node_composit_buts_moviedistortion(uiLayout *layout, bContext *C, PointerRNA *ptr)
2136 bNode *node = ptr->data;
2138 uiTemplateID(layout, C, ptr, "clip", NULL, "CLIP_OT_open", NULL);
2143 uiItemR(layout, ptr, "distortion_type", 0, "", 0);
2146 static void node_composit_buts_colorcorrection(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2150 row = uiLayoutRow(layout, 0);
2151 uiItemR(row, ptr, "red", 0, NULL, ICON_NONE);
2152 uiItemR(row, ptr, "green", 0, NULL, ICON_NONE);
2153 uiItemR(row, ptr, "blue", 0, NULL, ICON_NONE);
2155 row = uiLayoutRow(layout, 0);
2156 uiItemL(row, "", 0);
2157 uiItemL(row, IFACE_("Saturation"), 0);
2158 uiItemL(row, IFACE_("Contrast"), 0);
2159 uiItemL(row, IFACE_("Gamma"), 0);
2160 uiItemL(row, IFACE_("Gain"), 0);
2161 uiItemL(row, IFACE_("Lift"), 0);
2163 row = uiLayoutRow(layout, 0);
2164 uiItemL(row, IFACE_("Master"), 0);
2165 uiItemR(row, ptr, "master_saturation", UI_ITEM_R_SLIDER, "", ICON_NONE);
2166 uiItemR(row, ptr, "master_contrast", UI_ITEM_R_SLIDER, "", ICON_NONE);
2167 uiItemR(row, ptr, "master_gamma", UI_ITEM_R_SLIDER, "", ICON_NONE);
2168 uiItemR(row, ptr, "master_gain", UI_ITEM_R_SLIDER, "", ICON_NONE);
2169 uiItemR(row, ptr, "master_lift", UI_ITEM_R_SLIDER, "", ICON_NONE);
2171 row = uiLayoutRow(layout, 0);
2172 uiItemL(row, IFACE_("Highlights"), 0);
2173 uiItemR(row, ptr, "highlights_saturation", UI_ITEM_R_SLIDER, "", ICON_NONE);
2174 uiItemR(row, ptr, "highlights_contrast", UI_ITEM_R_SLIDER, "", ICON_NONE);
2175 uiItemR(row, ptr, "highlights_gamma", UI_ITEM_R_SLIDER, "", ICON_NONE);
2176 uiItemR(row, ptr, "highlights_gain", UI_ITEM_R_SLIDER, "", ICON_NONE);
2177 uiItemR(row, ptr, "highlights_lift", UI_ITEM_R_SLIDER, "", ICON_NONE);
2179 row = uiLayoutRow(layout, 0);
2180 uiItemL(row, IFACE_("Midtones"), 0);
2181 uiItemR(row, ptr, "midtones_saturation", UI_ITEM_R_SLIDER, "", ICON_NONE);
2182 uiItemR(row, ptr, "midtones_contrast", UI_ITEM_R_SLIDER, "", ICON_NONE);
2183 uiItemR(row, ptr, "midtones_gamma", UI_ITEM_R_SLIDER, "", ICON_NONE);
2184 uiItemR(row, ptr, "midtones_gain", UI_ITEM_R_SLIDER, "", ICON_NONE);
2185 uiItemR(row, ptr, "midtones_lift", UI_ITEM_R_SLIDER, "", ICON_NONE);
2187 row = uiLayoutRow(layout, 0);
2188 uiItemL(row, IFACE_("Shadows"), 0);
2189 uiItemR(row, ptr, "shadows_saturation", UI_ITEM_R_SLIDER, "", ICON_NONE);
2190 uiItemR(row, ptr, "shadows_contrast", UI_ITEM_R_SLIDER, "", ICON_NONE);
2191 uiItemR(row, ptr, "shadows_gamma", UI_ITEM_R_SLIDER, "", ICON_NONE);
2192 uiItemR(row, ptr, "shadows_gain", UI_ITEM_R_SLIDER, "", ICON_NONE);
2193 uiItemR(row, ptr, "shadows_lift", UI_ITEM_R_SLIDER, "", ICON_NONE);
2195 row = uiLayoutRow(layout, 0);
2196 uiItemR(row, ptr, "midtones_start", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2197 uiItemR(row, ptr, "midtones_end", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2200 static void node_composit_buts_colorcorrection_but(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2204 row = uiLayoutRow(layout, 0);
2205 uiItemR(row, ptr, "red", 0, NULL, ICON_NONE);
2206 uiItemR(row, ptr, "green", 0, NULL, ICON_NONE);
2207 uiItemR(row, ptr, "blue", 0, NULL, ICON_NONE);
2209 uiItemL(row, IFACE_("Saturation"), 0);
2210 uiItemR(row, ptr, "master_saturation", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2211 uiItemR(row, ptr, "highlights_saturation", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2212 uiItemR(row, ptr, "midtones_saturation", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2213 uiItemR(row, ptr, "shadows_saturation", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2215 uiItemL(row, IFACE_("Contrast"), 0);
2216 uiItemR(row, ptr, "master_contrast", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2217 uiItemR(row, ptr, "highlights_contrast", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2218 uiItemR(row, ptr, "midtones_contrast", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2219 uiItemR(row, ptr, "shadows_contrast", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2221 uiItemL(row, IFACE_("Gamma"), 0);
2222 uiItemR(row, ptr, "master_gamma", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2223 uiItemR(row, ptr, "highlights_gamma", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2224 uiItemR(row, ptr, "midtones_gamma", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2225 uiItemR(row, ptr, "shadows_gamma", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2227 uiItemL(row, IFACE_("Gain"), 0);
2228 uiItemR(row, ptr, "master_gain", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2229 uiItemR(row, ptr, "highlights_gain", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2230 uiItemR(row, ptr, "midtones_gain", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2231 uiItemR(row, ptr, "shadows_gain", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2233 uiItemL(row, IFACE_("Lift"), 0);
2234 uiItemR(row, ptr, "master_lift", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2235 uiItemR(row, ptr, "highlights_lift", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2236 uiItemR(row, ptr, "midtones_lift", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2237 uiItemR(row, ptr, "shadows_lift", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2239 row = uiLayoutRow(layout, 0);
2240 uiItemR(row, ptr, "midtones_start", 0, NULL, ICON_NONE);
2241 uiItemR(row, ptr, "midtones_end", 0, NULL, ICON_NONE);
2244 static void node_composit_buts_switch(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2246 uiItemR(layout, ptr, "check", 0, NULL, ICON_NONE);
2249 static void node_composit_buts_boxmask(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2253 row = uiLayoutRow(layout, 1);
2254 uiItemR(row, ptr, "x", 0, NULL, ICON_NONE);
2255 uiItemR(row, ptr, "y", 0, NULL, ICON_NONE);
2257 row = uiLayoutRow(layout, 1);
2258 uiItemR(row, ptr, "width", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2259 uiItemR(row, ptr, "height", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2261 uiItemR(layout, ptr, "rotation", 0, NULL, ICON_NONE);
2262 uiItemR(layout, ptr, "mask_type", 0, NULL, ICON_NONE);
2265 static void node_composit_buts_bokehimage(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2267 uiItemR(layout, ptr, "flaps", 0, NULL, ICON_NONE);
2268 uiItemR(layout, ptr, "angle", 0, NULL, ICON_NONE);
2269 uiItemR(layout, ptr, "rounding", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2270 uiItemR(layout, ptr, "catadioptric", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2271 uiItemR(layout, ptr, "shift", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2274 void node_composit_backdrop_viewer(SpaceNode *snode, ImBuf *backdrop, bNode *node, int x, int y)
2276 // node_composit_backdrop_canvas(snode, backdrop, node, x, y);
2277 if (node->custom1 == 0) { /// @todo: why did we need this one?
2278 const float backdropWidth = backdrop->x;
2279 const float backdropHeight = backdrop->y;
2280 const float cx = x + snode->zoom * backdropWidth * node->custom3;
2281 const float cy = y + snode->zoom * backdropHeight * node->custom4;
2283 glColor3f(1.0, 1.0, 1.0);
2286 glVertex2f(cx - 25, cy - 25);
2287 glVertex2f(cx + 25, cy + 25);
2288 glVertex2f(cx + 25, cy - 25);
2289 glVertex2f(cx - 25, cy + 25);
2294 void node_composit_backdrop_boxmask(SpaceNode *snode, ImBuf *backdrop, bNode *node, int x, int y)
2296 NodeBoxMask *boxmask = node->storage;
2297 const float backdropWidth = backdrop->x;
2298 const float backdropHeight = backdrop->y;
2299 const float aspect = backdropWidth / backdropHeight;
2300 const float rad = DEG2RADF(-boxmask->rotation);
2301 const float cosine = cosf(rad);
2302 const float sine = sinf(rad);
2303 const float halveBoxWidth = backdropWidth * (boxmask->width / 2.0f);
2304 const float halveBoxHeight = backdropHeight * (boxmask->height / 2.0f) * aspect;
2306 float cx, cy, x1, x2, x3, x4;
2307 float y1, y2, y3, y4;
2310 /* keep this, saves us from a version patch */
2311 if (snode->zoom == 0.0f) snode->zoom = 1.0f;
2313 glColor3f(1.0, 1.0, 1.0);
2315 cx = x + snode->zoom * backdropWidth * boxmask->x;
2316 cy = y + snode->zoom * backdropHeight * boxmask->y;
2318 x1 = cx - (cosine * halveBoxWidth + sine * halveBoxHeight) * snode->zoom;
2319 x2 = cx - (cosine * -halveBoxWidth + sine * halveBoxHeight) * snode->zoom;
2320 x3 = cx - (cosine * -halveBoxWidth + sine * -halveBoxHeight) * snode->zoom;
2321 x4 = cx - (cosine * halveBoxWidth + sine * -halveBoxHeight) * snode->zoom;
2322 y1 = cy - (-sine * halveBoxWidth + cosine * halveBoxHeight) * snode->zoom;
2323 y2 = cy - (-sine * -halveBoxWidth + cosine * halveBoxHeight) * snode->zoom;
2324 y3 = cy - (-sine * -halveBoxWidth + cosine * -halveBoxHeight) * snode->zoom;
2325 y4 = cy - (-sine * halveBoxWidth + cosine * -halveBoxHeight) * snode->zoom;
2327 glBegin(GL_LINE_LOOP);
2335 void node_composit_backdrop_ellipsemask(SpaceNode *snode, ImBuf *backdrop, bNode *node, int x, int y)
2337 NodeEllipseMask *ellipsemask = node->storage;
2338 const float backdropWidth = backdrop->x;
2339 const float backdropHeight = backdrop->y;
2340 const float aspect = backdropWidth / backdropHeight;
2341 const float rad = DEG2RADF(-ellipsemask->rotation);
2342 const float cosine = cosf(rad);
2343 const float sine = sinf(rad);
2344 const float halveBoxWidth = backdropWidth * (ellipsemask->width / 2.0f);
2345 const float halveBoxHeight = backdropHeight * (ellipsemask->height / 2.0f) * aspect;
2347 float cx, cy, x1, x2, x3, x4;
2348 float y1, y2, y3, y4;
2351 /* keep this, saves us from a version patch */
2352 if (snode->zoom == 0.0f) snode->zoom = 1.0f;
2354 glColor3f(1.0, 1.0, 1.0);
2356 cx = x + snode->zoom * backdropWidth * ellipsemask->x;
2357 cy = y + snode->zoom * backdropHeight * ellipsemask->y;
2359 x1 = cx - (cosine * halveBoxWidth + sine * halveBoxHeight) * snode->zoom;
2360 x2 = cx - (cosine * -halveBoxWidth + sine * halveBoxHeight) * snode->zoom;
2361 x3 = cx - (cosine * -halveBoxWidth + sine * -halveBoxHeight) * snode->zoom;
2362 x4 = cx - (cosine * halveBoxWidth + sine * -halveBoxHeight) * snode->zoom;
2363 y1 = cy - (-sine * halveBoxWidth + cosine * halveBoxHeight) * snode->zoom;
2364 y2 = cy - (-sine * -halveBoxWidth + cosine * halveBoxHeight) * snode->zoom;
2365 y3 = cy - (-sine * -halveBoxWidth + cosine * -halveBoxHeight) * snode->zoom;
2366 y4 = cy - (-sine * halveBoxWidth + cosine * -halveBoxHeight) * snode->zoom;
2368 glBegin(GL_LINE_LOOP);
2377 static void node_composit_buts_ellipsemask(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2380 row = uiLayoutRow(layout, 1);
2381 uiItemR(row, ptr, "x", 0, NULL, ICON_NONE);
2382 uiItemR(row, ptr, "y", 0, NULL, ICON_NONE);
2383 row = uiLayoutRow(layout, 1);
2384 uiItemR(row, ptr, "width", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2385 uiItemR(row, ptr, "height", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
2387 uiItemR(layout, ptr, "rotation", 0, NULL, ICON_NONE);
2388 uiItemR(layout, ptr, "mask_type", 0, NULL, ICON_NONE);
2391 static void node_composit_buts_viewer_but(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2395 uiItemR(layout, ptr, "tile_order", 0, NULL, ICON_NONE);
2396 if (RNA_enum_get(ptr, "tile_order") == 0) {
2397 col = uiLayoutColumn(layout, 1);
2398 uiItemR(col, ptr, "center_x", 0, NULL, ICON_NONE);
2399 uiItemR(col, ptr, "center_y", 0, NULL, ICON_NONE);
2403 static void node_composit_buts_mask(uiLayout *layout, bContext *C, PointerRNA *ptr)
2405 uiTemplateID(layout, C, ptr, "mask", NULL, NULL, NULL);
2408 static void node_composit_buts_keyingscreen(uiLayout *layout, bContext *C, PointerRNA *ptr)
2410 bNode *node= ptr->data;
2412 uiTemplateID(layout, C, ptr, "clip", NULL, NULL, NULL);
2415 MovieClip *clip = (MovieClip *) node->id;
2417 PointerRNA tracking_ptr;
2419 RNA_pointer_create(&clip->id, &RNA_MovieTracking, &clip->tracking, &tracking_ptr);
2421 col = uiLayoutColumn(layout, 1);
2422 uiItemPointerR(col, ptr, "tracking_object", &tracking_ptr, "objects", "", ICON_OBJECT_DATA);
2426 static void node_composit_buts_keying(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2428 /* bNode *node= ptr->data; */ /* UNUSED */
2430 uiItemR(layout, ptr, "blur_pre", 0, NULL, ICON_NONE);
2431 uiItemR(layout, ptr, "despill_factor", 0, NULL, ICON_NONE);
2432 uiItemR(layout, ptr, "clip_black", 0, NULL, ICON_NONE);
2433 uiItemR(layout, ptr, "clip_white", 0, NULL, ICON_NONE);
2434 uiItemR(layout, ptr, "dilate_distance", 0, NULL, ICON_NONE);
2435 uiItemR(layout, ptr, "blur_post", 0, NULL, ICON_NONE);
2438 /* only once called */
2439 static void node_composit_set_butfunc(bNodeType *ntype)
2441 switch (ntype->type) {
2442 /* case NODE_GROUP: note, typeinfo for group is generated... see "XXX ugly hack" */
2444 case CMP_NODE_IMAGE:
2445 ntype->uifunc = node_composit_buts_image;
2447 case CMP_NODE_R_LAYERS:
2448 ntype->uifunc = node_composit_buts_renderlayers;
2450 case CMP_NODE_NORMAL:
2451 ntype->uifunc = node_buts_normal;
2453 case CMP_NODE_CURVE_VEC:
2454 ntype->uifunc = node_buts_curvevec;
2456 case CMP_NODE_CURVE_RGB:
2457 ntype->uifunc = node_buts_curvecol;
2459 case CMP_NODE_VALUE:
2460 ntype->uifunc = node_buts_value;
2463 ntype->uifunc = node_buts_rgb;
2466 ntype->uifunc = node_composit_buts_flip;
2468 case CMP_NODE_SPLITVIEWER:
2469 ntype->uifunc = node_composit_buts_splitviewer;
2471 case CMP_NODE_MIX_RGB:
2472 ntype->uifunc = node_buts_mix_rgb;
2474 case CMP_NODE_VALTORGB:
2475 ntype->uifunc = node_buts_colorramp;
2478 ntype->uifunc = node_composit_buts_crop;
2481 ntype->uifunc = node_composit_buts_blur;
2483 case CMP_NODE_DBLUR:
2484 ntype->uifunc = node_composit_buts_dblur;
2486 case CMP_NODE_BILATERALBLUR:
2487 ntype->uifunc = node_composit_buts_bilateralblur;
2489 case CMP_NODE_DEFOCUS:
2490 ntype->uifunc = node_composit_buts_defocus;
2492 case CMP_NODE_GLARE:
2493 ntype->uifunc = node_composit_buts_glare;
2495 case CMP_NODE_TONEMAP:
2496 ntype->uifunc = node_composit_buts_tonemap;
2498 case CMP_NODE_LENSDIST:
2499 ntype->uifunc = node_composit_buts_lensdist;
2501 case CMP_NODE_VECBLUR:
2502 ntype->uifunc = node_composit_buts_vecblur;
2504 case CMP_NODE_FILTER:
2505 ntype->uifunc = node_composit_buts_filter;
2507 case CMP_NODE_MAP_VALUE:
2508 ntype->uifunc = node_composit_buts_map_value;
2511 ntype->uifunc = node_buts_time;
2513 case CMP_NODE_ALPHAOVER:
2514 ntype->uifunc = node_composit_buts_alphaover;
2516 case CMP_NODE_HUE_SAT:
2517 ntype->uifunc = node_composit_buts_hue_sat;
2519 case CMP_NODE_TEXTURE:
2520 ntype->uifunc = node_buts_texture;
2522 case CMP_NODE_DILATEERODE:
2523 ntype->uifunc = node_composit_buts_dilateerode;
2525 case CMP_NODE_OUTPUT_FILE:
2526 ntype->uifunc = node_composit_buts_file_output;
2527 ntype->uifuncbut = node_composit_buts_file_output_details;
2528 ntype->drawinputfunc = node_draw_input_file_output;
2530 case CMP_NODE_DIFF_MATTE:
2531 ntype->uifunc = node_composit_buts_diff_matte;
2533 case CMP_NODE_DIST_MATTE:
2534 ntype->uifunc = node_composit_buts_distance_matte;
2536 case CMP_NODE_COLOR_SPILL:
2537 ntype->uifunc = node_composit_buts_color_spill;
2539 case CMP_NODE_CHROMA_MATTE:
2540 ntype->uifunc = node_composit_buts_chroma_matte;
2542 case CMP_NODE_COLOR_MATTE:
2543 ntype->uifunc = node_composit_buts_color_matte;
2545 case CMP_NODE_SCALE:
2546 ntype->uifunc = node_composit_buts_scale;
2548 case CMP_NODE_ROTATE:
2549 ntype->uifunc = node_composit_buts_rotate;
2551 case CMP_NODE_CHANNEL_MATTE:
2552 ntype->uifunc = node_composit_buts_channel_matte;
2554 case CMP_NODE_LUMA_MATTE:
2555 ntype->uifunc = node_composit_buts_luma_matte;
2557 case CMP_NODE_MAP_UV:
2558 ntype->uifunc = node_composit_buts_map_uv;
2560 case CMP_NODE_ID_MASK:
2561 ntype->uifunc = node_composit_buts_id_mask;
2563 case CMP_NODE_DOUBLEEDGEMASK:
2564 ntype->uifunc = node_composit_buts_double_edge_mask;
2567 ntype->uifunc = node_buts_math;
2569 case CMP_NODE_INVERT:
2570 ntype->uifunc = node_composit_buts_invert;
2572 case CMP_NODE_PREMULKEY:
2573 ntype->uifunc = node_composit_buts_premulkey;
2575 case CMP_NODE_VIEW_LEVELS:
2576 ntype->uifunc = node_composit_buts_view_levels;
2578 case CMP_NODE_COLORBALANCE:
2579 ntype->uifunc = node_composit_buts_colorbalance;
2580 ntype->uifuncbut = node_composit_buts_colorbalance_but;
2582 case CMP_NODE_HUECORRECT:
2583 ntype->uifunc = node_composit_buts_huecorrect;
2585 case CMP_NODE_ZCOMBINE:
2586 ntype->uifunc = node_composit_buts_zcombine;
2588 case CMP_NODE_COMBYCCA:
2589 case CMP_NODE_SEPYCCA:
2590 ntype->uifunc = node_composit_buts_ycc;
2592 case CMP_NODE_MOVIECLIP:
2593 ntype->uifunc = node_composit_buts_movieclip;
2595 case CMP_NODE_STABILIZE2D:
2596 ntype->uifunc = node_composit_buts_stabilize2d;
2598 case CMP_NODE_TRANSFORM:
2599 ntype->uifunc = node_composit_buts_transform;
2601 case CMP_NODE_MOVIEDISTORTION:
2602 ntype->uifunc = node_composit_buts_moviedistortion;
2604 case CMP_NODE_COLORCORRECTION:
2605 ntype->uifunc = node_composit_buts_colorcorrection;
2606 ntype->uifuncbut = node_composit_buts_colorcorrection_but;
2608 case CMP_NODE_SWITCH:
2609 ntype->uifunc = node_composit_buts_switch;
2611 case CMP_NODE_MASK_BOX:
2612 ntype->uifunc = node_composit_buts_boxmask;
2613 ntype->uibackdropfunc = node_composit_backdrop_boxmask;
2615 case CMP_NODE_MASK_ELLIPSE:
2616 ntype->uifunc = node_composit_buts_ellipsemask;
2617 ntype->uibackdropfunc = node_composit_backdrop_ellipsemask;
2619 case CMP_NODE_BOKEHIMAGE:
2620 ntype->uifunc = node_composit_buts_bokehimage;
2622 case CMP_NODE_VIEWER:
2623 ntype->uifunc = NULL;
2624 ntype->uifuncbut = node_composit_buts_viewer_but;
2625 ntype->uibackdropfunc = node_composit_backdrop_viewer;
2628 ntype->uifunc= node_composit_buts_mask;
2630 case CMP_NODE_KEYINGSCREEN:
2631 ntype->uifunc = node_composit_buts_keyingscreen;
2633 case CMP_NODE_KEYING:
2634 ntype->uifunc = node_composit_buts_keying;
2637 ntype->uifunc = NULL;
2641 /* ****************** BUTTON CALLBACKS FOR TEXTURE NODES ***************** */
2643 static void node_texture_buts_bricks(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2647 col = uiLayoutColumn(layout, 1);
2648 uiItemR(col, ptr, "offset", 0, IFACE_("Offset"), ICON_NONE);
2649 uiItemR(col, ptr, "offset_frequency", 0, IFACE_("Frequency"), ICON_NONE);
2651 col = uiLayoutColumn(layout, 1);
2652 uiItemR(col, ptr, "squash", 0, IFACE_("Squash"), ICON_NONE);
2653 uiItemR(col, ptr, "squash_frequency", 0, IFACE_("Frequency"), ICON_NONE);
2656 static void node_texture_buts_proc(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2659 bNode *node = ptr->data;
2660 ID *id = ptr->id.data;
2661 Tex *tex = (Tex *)node->storage;
2662 uiLayout *col, *row;
2664 RNA_pointer_create(id, &RNA_Texture, tex, &tex_ptr);
2666 col = uiLayoutColumn(layout, 0);
2668 switch (tex->type) {
2670 uiItemR(col, &tex_ptr, "progression", 0, "", ICON_NONE);
2671 row = uiLayoutRow(col, 0);
2672 uiItemR(row, &tex_ptr, "use_flip_axis", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
2676 row = uiLayoutRow(col, 0);
2677 uiItemR(row, &tex_ptr, "marble_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
2678 row = uiLayoutRow(col, 0);
2679 uiItemR(row, &tex_ptr, "noise_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
2680 row = uiLayoutRow(col, 0);
2681 uiItemR(row, &tex_ptr, "noise_basis", 0, "", ICON_NONE);
2682 row = uiLayoutRow(col, 0);
2683 uiItemR(row, &tex_ptr, "noise_basis_2", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
2687 uiItemR(col, &tex_ptr, "noise_depth", 0, NULL, ICON_NONE);
2691 row = uiLayoutRow(col, 0);
2692 uiItemR(row, &tex_ptr, "stucci_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
2693 row = uiLayoutRow(col, 0);
2694 uiItemR(row, &tex_ptr, "noise_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
2695 uiItemR(col, &tex_ptr, "noise_basis", 0, "", ICON_NONE);
2699 uiItemR(col, &tex_ptr, "noise_basis", 0, "", ICON_NONE);
2700 uiItemR(col, &tex_ptr, "wood_type", 0, "", ICON_NONE);
2701 row = uiLayoutRow(col, 0);
2702 uiItemR(row, &tex_ptr, "noise_basis_2", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
2703 row = uiLayoutRow(col, 0);
2704 uiLayoutSetActive(row, !(RNA_enum_get(&tex_ptr, "wood_type") == TEX_BAND || RNA_enum_get(&tex_ptr, "wood_type") == TEX_RING));
2705 uiItemR(row, &tex_ptr, "noise_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
2709 uiItemR(col, &tex_ptr, "noise_basis", 0, "", ICON_NONE);
2710 row = uiLayoutRow(col, 0);
2711 uiItemR(row, &tex_ptr, "cloud_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
2712 row = uiLayoutRow(col, 0);
2713 uiItemR(row, &tex_ptr, "noise_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
2714 uiItemR(col, &tex_ptr, "noise_depth", UI_ITEM_R_EXPAND, IFACE_("Depth"), ICON_NONE);
2718 uiItemR(col, &tex_ptr, "noise_basis", 0, "", ICON_NONE);
2719 uiItemR(col, &tex_ptr, "noise_distortion", 0, "", ICON_NONE);
2723 uiItemR(col, &tex_ptr, "musgrave_type", 0, "", ICON_NONE);
2724 uiItemR(col, &tex_ptr, "noise_basis", 0, "", ICON_NONE);
2727 uiItemR(col, &tex_ptr, "distance_metric", 0, "", ICON_NONE);
2728 if (tex->vn_distm == TEX_MINKOVSKY) {
2729 uiItemR(col, &tex_ptr, "minkovsky_exponent", 0, NULL, ICON_NONE);
2731 uiItemR(col, &tex_ptr, "color_mode", 0, "", ICON_NONE);
2736 static void node_texture_buts_image(uiLayout *layout, bContext *C, PointerRNA *ptr)
2738 uiTemplateID(layout, C, ptr, "image", NULL, "IMAGE_OT_open", NULL);
2741 static void node_texture_buts_output(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
2743 uiItemR(layout, ptr, "filepath", 0, "", ICON_NONE);
2746 /* only once called */
2747 static void node_texture_set_butfunc(bNodeType *ntype)
2749 if (ntype->type >= TEX_NODE_PROC && ntype->type < TEX_NODE_PROC_MAX) {
2750 ntype->uifunc = node_texture_buts_proc;
2753 switch (ntype->type) {
2756 ntype->uifunc = node_buts_math;
2759 case TEX_NODE_MIX_RGB:
2760 ntype->uifunc = node_buts_mix_rgb;
2763 case TEX_NODE_VALTORGB:
2764 ntype->uifunc = node_buts_colorramp;
2767 case TEX_NODE_CURVE_RGB:
2768 ntype->uifunc = node_buts_curvecol;
2771 case TEX_NODE_CURVE_TIME:
2772 ntype->uifunc = node_buts_time;
2775 case TEX_NODE_TEXTURE:
2776 ntype->uifunc = node_buts_texture;
2779 case TEX_NODE_BRICKS:
2780 ntype->uifunc = node_texture_buts_bricks;
2783 case TEX_NODE_IMAGE:
2784 ntype->uifunc = node_texture_buts_image;
2787 case TEX_NODE_OUTPUT:
2788 ntype->uifunc = node_texture_buts_output;
2794 /* ******* init draw callbacks for all tree types, only called in usiblender.c, once ************* */
2796 void ED_init_node_butfuncs(void)
2798 bNodeTreeType *treetype;
2800 bNodeSocketType *stype;
2803 /* node type ui functions */
2804 for (i = 0; i < NUM_NTREE_TYPES; ++i) {
2805 treetype = ntreeGetType(i);
2807 for (ntype = treetype->node_types.first; ntype; ntype = ntype->next) {
2808 /* default ui functions */
2809 ntype->drawfunc = node_draw_default;
2810 ntype->drawupdatefunc = node_update_default;
2811 ntype->select_area_func = node_select_area_default;
2812 ntype->tweak_area_func = node_tweak_area_default;
2813 ntype->uifunc = NULL;
2814 ntype->uifuncbut = NULL;
2815 ntype->drawinputfunc = node_draw_input_default;
2816 ntype->drawoutputfunc = node_draw_output_default;
2817 ntype->resize_area_func = node_resize_area_default;
2819 node_common_set_butfunc(ntype);
2822 case NTREE_COMPOSIT:
2823 node_composit_set_butfunc(ntype);
2826 node_shader_set_butfunc(ntype);
2829 node_texture_set_butfunc(ntype);
2836 /* socket type ui functions */
2837 for (i = 0; i < NUM_SOCKET_TYPES; ++i) {
2838 stype = ntreeGetSocketType(i);
2840 switch (stype->type) {
2844 stype->buttonfunc = node_socket_button_default;
2847 stype->buttonfunc = node_socket_button_components;
2850 stype->buttonfunc = node_socket_button_color;
2853 stype->buttonfunc = node_socket_button_label;
2856 stype->buttonfunc = NULL;
2862 /* ************** Generic drawing ************** */
2864 void draw_nodespace_back_pix(ARegion *ar, SpaceNode *snode, int color_manage)
2867 if ((snode->flag & SNODE_BACKDRAW) && snode->treetype == NTREE_COMPOSIT) {
2868 Image *ima = BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node");
2870 ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock);
2874 glMatrixMode(GL_PROJECTION);
2876 glMatrixMode(GL_MODELVIEW);
2879 /* keep this, saves us from a version patch */
2880 if (snode->zoom == 0.0f) snode->zoom = 1.0f;
2882 /* somehow the offset has to be calculated inverse */
2884 glaDefine2DArea(&ar->winrct);
2885 /* ortho at pixel level curarea */
2886 wmOrtho2(-0.375, ar->winx - 0.375, -0.375, ar->winy - 0.375);
2888 x = (ar->winx - snode->zoom * ibuf->x) / 2 + snode->xof;
2889 y = (ar->winy - snode->zoom * ibuf->y) / 2 + snode->yof;
2893 ibuf->profile = IB_PROFILE_LINEAR_RGB;
2895 ibuf->profile = IB_PROFILE_NONE;
2896 IMB_rect_from_float(ibuf);
2900 if (snode->flag & SNODE_SHOW_ALPHA) {
2901 glPixelZoom(snode->zoom, snode->zoom);
2902 /* swap bytes, so alpha is most significant one, then just draw it as luminance int */
2903 if (ENDIAN_ORDER == B_ENDIAN)
2904 glPixelStorei(GL_UNPACK_SWAP_BYTES, 1);
2906 glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_LUMINANCE, GL_UNSIGNED_INT, ibuf->rect);
2908 glPixelStorei(GL_UNPACK_SWAP_BYTES, 0);
2909 glPixelZoom(1.0f, 1.0f);
2911 else if (snode->flag & SNODE_USE_ALPHA) {
2913 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2914 glPixelZoom(snode->zoom, snode->zoom);
2916 glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
2918 glPixelZoom(1.0f, 1.0f);
2919 glDisable(GL_BLEND);
2922 glPixelZoom(snode->zoom, snode->zoom);
2924 glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
2926 glPixelZoom(1.0f, 1.0f);
2930 /// @note draw selected info on backdrop
2931 if (snode->edittree) {
2932 bNode *node = snode->edittree->nodes.first;
2934 if (node->flag & NODE_SELECT) {
2935 if (node->typeinfo->uibackdropfunc) {
2936 node->typeinfo->uibackdropfunc(snode, ibuf, node, x, y);
2943 glMatrixMode(GL_PROJECTION);
2945 glMatrixMode(GL_MODELVIEW);
2949 BKE_image_release_ibuf(ima, lock);
2954 /* note: needs to be userpref or opengl profile option */
2955 static void draw_nodespace_back_tex(ScrArea *sa, SpaceNode *snode)
2958 draw_nodespace_grid(snode);
2960 if (snode->flag & SNODE_BACKDRAW) {
2961 Image *ima = BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node");
2962 ImBuf *ibuf = BKE_image_get_ibuf(ima, NULL);
2967 glMatrixMode(GL_PROJECTION);
2969 glMatrixMode(GL_MODELVIEW);
2972 glaDefine2DArea(&sa->winrct);
2974 if (ibuf->x > sa->winx || ibuf->y > sa->winy) {
2976 zoomx = (float)sa->winx / ibuf->x;
2977 zoomy = (float)sa->winy / ibuf->y;
2978 zoom = MIN2(zoomx, zoomy);
2981 x = (sa->winx - zoom * ibuf->x) / 2 + snode->xof;
2982 y = (sa->winy - zoom * ibuf->y) / 2 + snode->yof;
2984 glPixelZoom(zoom, zoom);
2986 glColor4f(1.0, 1.0, 1.0, 1.0);
2988 glaDrawPixelsTex(x, y, ibuf->x, ibuf->y, GL_UNSIGNED_BYTE, ibuf->rect);
2989 else if (ibuf->channels == 4)
2990 glaDrawPixelsTex(x, y, ibuf->x, ibuf->y, GL_FLOAT, ibuf->rect_float);
2992 glPixelZoom(1.0, 1.0);
2994 glMatrixMode(GL_PROJECTION);
2996 glMatrixMode(GL_MODELVIEW);
3003 /* if v2d not NULL, it clips and returns 0 if not visible */
3004 int node_link_bezier_points(View2D *v2d, SpaceNode *snode, bNodeLink *link, float coord_array[][2], int resol)
3006 float dist, vec[4][2];
3007 float deltax, deltay;
3008 int toreroute, fromreroute;
3009 /* in v0 and v3 we put begin/end points */
3010 if (link->fromsock) {
3011 vec[0][0] = link->fromsock->locx;
3012 vec[0][1] = link->fromsock->locy;
3013 fromreroute = (link->fromnode && link->fromnode->type == NODE_REROUTE);
3016 if (snode == NULL) return 0;
3017 vec[0][0] = snode->mx;
3018 vec[0][1] = snode->my;
3022 vec[3][0] = link->tosock->locx;
3023 vec[3][1] = link->tosock->locy;
3024 toreroute = (link->tonode && link->tonode->type == NODE_REROUTE);
3027 if (snode == NULL) return 0;
3028 vec[3][0] = snode->mx;
3029 vec[3][1] = snode->my;
3033 dist = UI_GetThemeValue(TH_NODE_CURVING) * 0.10f * ABS(vec[0][0] - vec[3][0]);
3034 deltax = vec[3][0] - vec[0