2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2009-11-11 08:12:54 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-11-11 08:12:54 +00:00
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2009 Blender Foundation.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* Contributor(s): Blender Foundation
|
|
|
|
|
*
|
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
|
*/
|
|
|
|
|
|
2011-02-27 20:29:51 +00:00
|
|
|
/** \file blender/editors/space_node/node_buttons.c
|
|
|
|
|
* \ingroup spnode
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2009-11-11 08:12:54 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <math.h>
|
|
|
|
|
#include <float.h>
|
|
|
|
|
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
2009-11-11 08:12:54 +00:00
|
|
|
#include "DNA_node_types.h"
|
|
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
|
|
|
|
|
|
#include "BLI_math.h"
|
|
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
|
#include "BLI_rand.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2009-11-11 08:12:54 +00:00
|
|
|
|
Fixed another bunch of i18n bugs (thx to Leon Cheung for spotting them), among which:
* Drag'n'drop translation in Outliner
* "Execute" button in file window
* "Labels" of spacing elements, in multi-column enums
* A glitch with nodes "Value to RGB", they where called "ColorRamp" in node_type_base() call. This is not definitive, though, as it appears that UI node names are determined by this call, while it should be by "defines" in rna_nodetrre_types.h, I guess... Anyway, not good to have such things in two different places!
Also moved default context name under BLF_translation.h, much better to have those all in one place, accessible from whole Blender code!
2012-04-14 15:06:41 +00:00
|
|
|
#include "BLF_translation.h"
|
|
|
|
|
|
2009-11-11 08:12:54 +00:00
|
|
|
#include "BKE_context.h"
|
2011-11-07 22:28:49 +00:00
|
|
|
#include "BKE_global.h"
|
2009-11-11 10:51:40 +00:00
|
|
|
#include "BKE_node.h"
|
2009-11-11 08:12:54 +00:00
|
|
|
#include "BKE_screen.h"
|
|
|
|
|
|
|
|
|
|
#include "WM_api.h"
|
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
|
|
|
|
|
#include "RNA_access.h"
|
|
|
|
|
|
|
|
|
|
#include "ED_gpencil.h"
|
|
|
|
|
#include "ED_screen.h"
|
|
|
|
|
|
|
|
|
|
#include "UI_interface.h"
|
|
|
|
|
#include "UI_resources.h"
|
|
|
|
|
|
|
|
|
|
#include "node_intern.h" // own include
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* ******************* node space & buttons ************** */
|
2009-11-11 10:51:40 +00:00
|
|
|
|
2012-04-13 11:58:16 +00:00
|
|
|
/* poll for active nodetree */
|
|
|
|
|
static int active_nodetree_poll(const bContext *C, PanelType *UNUSED(pt))
|
|
|
|
|
{
|
|
|
|
|
SpaceNode *snode= CTX_wm_space_node(C);
|
|
|
|
|
|
|
|
|
|
return (snode && snode->nodetree);
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-11 10:51:40 +00:00
|
|
|
/* poll callback for active node */
|
2010-10-16 08:03:28 +00:00
|
|
|
static int active_node_poll(const bContext *C, PanelType *UNUSED(pt))
|
2009-11-11 10:51:40 +00:00
|
|
|
{
|
|
|
|
|
SpaceNode *snode= CTX_wm_space_node(C);
|
|
|
|
|
|
2012-04-13 11:58:16 +00:00
|
|
|
return (snode && snode->edittree && nodeGetActive(snode->edittree));
|
2009-11-11 10:51:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* active node */
|
|
|
|
|
static void active_node_panel(const bContext *C, Panel *pa)
|
|
|
|
|
{
|
|
|
|
|
SpaceNode *snode= CTX_wm_space_node(C);
|
2009-11-20 04:19:57 +00:00
|
|
|
bNodeTree *ntree= (snode) ? snode->edittree : NULL;
|
|
|
|
|
bNode *node = (ntree) ? nodeGetActive(ntree) : NULL; // xxx... for editing group nodes
|
2012-05-22 19:16:20 +00:00
|
|
|
uiLayout *layout, *row, *col, *sub;
|
2012-05-22 14:13:33 +00:00
|
|
|
PointerRNA ptr, opptr;
|
2009-11-11 10:51:40 +00:00
|
|
|
|
|
|
|
|
/* verify pointers, and create RNA pointer for the node */
|
2012-03-25 22:35:18 +00:00
|
|
|
if (ELEM(NULL, ntree, node))
|
2009-11-11 10:51:40 +00:00
|
|
|
return;
|
2009-11-20 04:19:57 +00:00
|
|
|
//if (node->id) /* for group nodes */
|
|
|
|
|
// RNA_pointer_create(node->id, &RNA_Node, node, &ptr);
|
|
|
|
|
//else
|
|
|
|
|
RNA_pointer_create(&ntree->id, &RNA_Node, node, &ptr);
|
2009-11-11 10:51:40 +00:00
|
|
|
|
2012-05-02 07:18:51 +00:00
|
|
|
layout = uiLayoutColumn(pa->layout, 0);
|
|
|
|
|
uiLayoutSetContextPointer(layout, "node", &ptr);
|
|
|
|
|
|
2009-11-11 10:51:40 +00:00
|
|
|
/* draw this node's name, etc. */
|
2011-03-17 10:11:12 +00:00
|
|
|
uiItemR(layout, &ptr, "label", 0, NULL, ICON_NODE);
|
2011-03-17 10:31:20 +00:00
|
|
|
uiItemS(layout);
|
|
|
|
|
uiItemR(layout, &ptr, "name", 0, NULL, ICON_NODE);
|
|
|
|
|
uiItemS(layout);
|
2011-12-19 11:55:35 +00:00
|
|
|
|
|
|
|
|
uiItemO(layout, NULL, 0, "NODE_OT_hide_socket_toggle");
|
|
|
|
|
uiItemS(layout);
|
2012-05-22 19:16:20 +00:00
|
|
|
uiItemS(layout);
|
2011-09-05 21:01:50 +00:00
|
|
|
|
2012-05-22 14:13:33 +00:00
|
|
|
row = uiLayoutRow(layout, 0);
|
2012-05-22 19:16:20 +00:00
|
|
|
|
|
|
|
|
col = uiLayoutColumn(row, 1);
|
|
|
|
|
uiItemM(col, (bContext *)C, "NODE_MT_node_color_presets", NULL, 0);
|
|
|
|
|
uiItemR(col, &ptr, "use_custom_color", UI_ITEM_R_ICON_ONLY, NULL, ICON_NONE);
|
|
|
|
|
sub = uiLayoutRow(col, 0);
|
2012-05-22 14:13:33 +00:00
|
|
|
if (!(node->flag & NODE_CUSTOM_COLOR))
|
2012-05-22 19:16:20 +00:00
|
|
|
uiLayoutSetEnabled(sub, 0);
|
|
|
|
|
uiItemR(sub, &ptr, "color", 0, "", 0);
|
|
|
|
|
|
|
|
|
|
col = uiLayoutColumn(row, 1);
|
|
|
|
|
uiItemO(col, "", ICON_ZOOMIN, "node.node_color_preset_add");
|
|
|
|
|
opptr = uiItemFullO(col, "node.node_color_preset_add", "", ICON_ZOOMOUT, NULL, WM_OP_INVOKE_DEFAULT, UI_ITEM_O_RETURN_PROPS);
|
|
|
|
|
RNA_boolean_set(&opptr, "remove_active", 1);
|
|
|
|
|
uiItemM(col, (bContext *)C, "NODE_MT_node_color_specials", "", ICON_BLANK1);
|
|
|
|
|
|
2009-11-11 10:51:40 +00:00
|
|
|
/* draw this node's settings */
|
2012-05-22 19:16:20 +00:00
|
|
|
if (node->typeinfo && node->typeinfo->uifuncbut) {
|
|
|
|
|
uiItemS(layout);
|
|
|
|
|
uiItemS(layout);
|
2011-07-04 19:22:37 +00:00
|
|
|
node->typeinfo->uifuncbut(layout, (bContext *)C, &ptr);
|
2012-05-22 19:16:20 +00:00
|
|
|
}
|
|
|
|
|
else if (node->typeinfo && node->typeinfo->uifunc) {
|
|
|
|
|
uiItemS(layout);
|
|
|
|
|
uiItemS(layout);
|
2011-09-05 21:01:50 +00:00
|
|
|
node->typeinfo->uifunc(layout, (bContext *)C, &ptr);
|
2012-05-22 19:16:20 +00:00
|
|
|
}
|
2009-11-11 10:51:40 +00:00
|
|
|
}
|
2009-11-11 08:12:54 +00:00
|
|
|
|
2011-11-07 22:28:49 +00:00
|
|
|
static int node_sockets_poll(const bContext *C, PanelType *UNUSED(pt))
|
|
|
|
|
{
|
|
|
|
|
SpaceNode *snode= CTX_wm_space_node(C);
|
|
|
|
|
|
|
|
|
|
return (snode && snode->nodetree && G.rt == 777);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void node_sockets_panel(const bContext *C, Panel *pa)
|
|
|
|
|
{
|
|
|
|
|
SpaceNode *snode= CTX_wm_space_node(C);
|
|
|
|
|
bNodeTree *ntree= (snode) ? snode->edittree : NULL;
|
|
|
|
|
bNode *node = (ntree) ? nodeGetActive(ntree) : NULL;
|
|
|
|
|
bNodeSocket *sock;
|
|
|
|
|
uiLayout *layout= pa->layout, *split;
|
|
|
|
|
char name[UI_MAX_NAME_STR];
|
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ELEM(NULL, ntree, node))
|
2011-11-07 22:28:49 +00:00
|
|
|
return;
|
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
for (sock=node->inputs.first; sock; sock=sock->next) {
|
2011-11-07 22:28:49 +00:00
|
|
|
BLI_snprintf(name, sizeof(name), "%s:", sock->name);
|
|
|
|
|
|
|
|
|
|
split = uiLayoutSplit(layout, 0.35f, 0);
|
|
|
|
|
uiItemL(split, name, ICON_NONE);
|
|
|
|
|
uiTemplateNodeLink(split, ntree, node, sock);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-11 08:12:54 +00:00
|
|
|
/* ******************* node buttons registration ************** */
|
|
|
|
|
|
|
|
|
|
void node_buttons_register(ARegionType *art)
|
|
|
|
|
{
|
|
|
|
|
PanelType *pt;
|
|
|
|
|
|
2009-11-11 10:51:40 +00:00
|
|
|
pt= MEM_callocN(sizeof(PanelType), "spacetype node panel active node");
|
|
|
|
|
strcpy(pt->idname, "NODE_PT_item");
|
Fixed another bunch of i18n bugs (thx to Leon Cheung for spotting them), among which:
* Drag'n'drop translation in Outliner
* "Execute" button in file window
* "Labels" of spacing elements, in multi-column enums
* A glitch with nodes "Value to RGB", they where called "ColorRamp" in node_type_base() call. This is not definitive, though, as it appears that UI node names are determined by this call, while it should be by "defines" in rna_nodetrre_types.h, I guess... Anyway, not good to have such things in two different places!
Also moved default context name under BLF_translation.h, much better to have those all in one place, accessible from whole Blender code!
2012-04-14 15:06:41 +00:00
|
|
|
strcpy(pt->label, IFACE_("Active Node"));
|
2009-11-11 10:51:40 +00:00
|
|
|
pt->draw= active_node_panel;
|
|
|
|
|
pt->poll= active_node_poll;
|
|
|
|
|
BLI_addtail(&art->paneltypes, pt);
|
2011-11-07 22:28:49 +00:00
|
|
|
|
|
|
|
|
pt= MEM_callocN(sizeof(PanelType), "spacetype node panel node sockets");
|
|
|
|
|
strcpy(pt->idname, "NODE_PT_sockets");
|
|
|
|
|
strcpy(pt->label, "Sockets");
|
|
|
|
|
pt->draw= node_sockets_panel;
|
|
|
|
|
pt->poll= node_sockets_poll;
|
|
|
|
|
pt->flag |= PNL_DEFAULT_CLOSED;
|
|
|
|
|
BLI_addtail(&art->paneltypes, pt);
|
2009-11-11 08:12:54 +00:00
|
|
|
|
|
|
|
|
pt= MEM_callocN(sizeof(PanelType), "spacetype node panel gpencil");
|
|
|
|
|
strcpy(pt->idname, "NODE_PT_gpencil");
|
|
|
|
|
strcpy(pt->label, "Grease Pencil");
|
|
|
|
|
pt->draw= gpencil_panel_standard;
|
2012-04-13 11:58:16 +00:00
|
|
|
pt->poll= active_nodetree_poll;
|
2009-11-11 08:12:54 +00:00
|
|
|
BLI_addtail(&art->paneltypes, pt);
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-15 01:36:14 +00:00
|
|
|
static int node_properties(bContext *C, wmOperator *UNUSED(op))
|
2009-11-11 08:12:54 +00:00
|
|
|
{
|
|
|
|
|
ScrArea *sa= CTX_wm_area(C);
|
|
|
|
|
ARegion *ar= node_has_buttons_region(sa);
|
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ar)
|
2009-11-11 08:12:54 +00:00
|
|
|
ED_region_toggle_hidden(C, ar);
|
|
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* non-standard poll operator which doesn't care if there are any nodes */
|
|
|
|
|
static int node_properties_poll(bContext *C)
|
|
|
|
|
{
|
|
|
|
|
ScrArea *sa= CTX_wm_area(C);
|
|
|
|
|
return (sa && (sa->spacetype == SPACE_NODE));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NODE_OT_properties(wmOperatorType *ot)
|
|
|
|
|
{
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Properties";
|
|
|
|
|
ot->description = "Toggles the properties panel display";
|
|
|
|
|
ot->idname = "NODE_OT_properties";
|
2009-11-11 08:12:54 +00:00
|
|
|
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = node_properties;
|
|
|
|
|
ot->poll = node_properties_poll;
|
2009-11-11 08:12:54 +00:00
|
|
|
|
|
|
|
|
/* flags */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->flag = 0;
|
2009-11-11 08:12:54 +00:00
|
|
|
}
|