2008-12-13 18:09:49 +00:00
|
|
|
/**
|
|
|
|
|
* $Id$
|
|
|
|
|
*
|
|
|
|
|
* ***** 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,
|
|
|
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2008 Blender Foundation.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* Contributor(s): Blender Foundation
|
|
|
|
|
*
|
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
#include "DNA_space_types.h"
|
2008-12-24 10:33:10 +00:00
|
|
|
#include "DNA_node_types.h"
|
2008-12-25 20:41:14 +00:00
|
|
|
#include "DNA_material_types.h"
|
|
|
|
|
#include "DNA_texture_types.h"
|
2008-12-13 18:09:49 +00:00
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
|
#include "DNA_screen_types.h"
|
|
|
|
|
#include "DNA_windowmanager_types.h"
|
|
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
|
|
2008-12-18 02:56:48 +00:00
|
|
|
#include "BKE_context.h"
|
2008-12-13 18:09:49 +00:00
|
|
|
#include "BKE_screen.h"
|
2008-12-25 18:29:56 +00:00
|
|
|
#include "BKE_node.h"
|
|
|
|
|
#include "BKE_main.h"
|
2009-08-19 00:55:30 +00:00
|
|
|
#include "BKE_utildefines.h"
|
2008-12-13 18:09:49 +00:00
|
|
|
|
|
|
|
|
#include "ED_screen.h"
|
2008-12-19 12:48:30 +00:00
|
|
|
#include "ED_types.h"
|
2008-12-13 18:09:49 +00:00
|
|
|
#include "ED_util.h"
|
|
|
|
|
|
|
|
|
|
#include "WM_api.h"
|
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
|
|
|
|
|
#include "BIF_gl.h"
|
|
|
|
|
#include "BIF_glutil.h"
|
|
|
|
|
|
|
|
|
|
#include "UI_interface.h"
|
|
|
|
|
#include "UI_resources.h"
|
|
|
|
|
#include "UI_view2d.h"
|
|
|
|
|
|
|
|
|
|
#include "node_intern.h"
|
|
|
|
|
|
2009-08-19 00:55:30 +00:00
|
|
|
/* ************************ add menu *********************** */
|
2008-12-13 18:09:49 +00:00
|
|
|
|
2009-08-19 00:55:30 +00:00
|
|
|
static void do_node_add(bContext *C, void *arg, int event)
|
2008-12-13 18:09:49 +00:00
|
|
|
{
|
2009-07-28 16:33:02 +00:00
|
|
|
SpaceNode *snode= CTX_wm_space_node(C);
|
2008-12-25 18:29:56 +00:00
|
|
|
bNode *node;
|
|
|
|
|
|
|
|
|
|
/* store selection in temp test flag */
|
|
|
|
|
for(node= snode->edittree->nodes.first; node; node= node->next) {
|
|
|
|
|
if(node->flag & NODE_SELECT) node->flag |= NODE_TEST;
|
|
|
|
|
else node->flag &= ~NODE_TEST;
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-14 13:18:18 +00:00
|
|
|
node= node_add_node(snode, CTX_data_scene(C), event, snode->mx, snode->my);
|
2008-12-25 18:29:56 +00:00
|
|
|
|
2010-01-05 06:49:29 +00:00
|
|
|
/* select previous selection before autoconnect */
|
|
|
|
|
for(node= snode->edittree->nodes.first; node; node= node->next) {
|
|
|
|
|
if(node->flag & NODE_TEST) node->flag |= NODE_SELECT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
snode_autoconnect(snode, 1, 0);
|
|
|
|
|
|
|
|
|
|
/* deselect after autoconnection */
|
|
|
|
|
for(node= snode->edittree->nodes.first; node; node= node->next) {
|
|
|
|
|
if(node->flag & NODE_TEST) node->flag &= ~NODE_SELECT;
|
|
|
|
|
}
|
2008-12-25 18:29:56 +00:00
|
|
|
|
2010-01-21 01:42:28 +00:00
|
|
|
snode_notify(C, snode);
|
2008-12-25 18:29:56 +00:00
|
|
|
}
|
|
|
|
|
|
2009-08-19 00:55:30 +00:00
|
|
|
static void node_auto_add_menu(bContext *C, uiLayout *layout, void *arg_nodeclass)
|
2008-12-25 18:29:56 +00:00
|
|
|
{
|
|
|
|
|
Main *bmain= CTX_data_main(C);
|
2009-07-28 16:33:02 +00:00
|
|
|
SpaceNode *snode= CTX_wm_space_node(C);
|
2008-12-25 18:29:56 +00:00
|
|
|
bNodeTree *ntree;
|
2009-08-19 00:55:30 +00:00
|
|
|
int nodeclass= GET_INT_FROM_POINTER(arg_nodeclass);
|
2008-12-25 18:29:56 +00:00
|
|
|
int tot= 0, a;
|
|
|
|
|
|
|
|
|
|
ntree = snode->nodetree;
|
2009-08-19 00:55:30 +00:00
|
|
|
|
|
|
|
|
if(!ntree) {
|
|
|
|
|
uiItemS(layout);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* mostly taken from toolbox.c, node_add_sublevel() */
|
|
|
|
|
if(nodeclass==NODE_CLASS_GROUP) {
|
|
|
|
|
bNodeTree *ngroup= bmain->nodetree.first;
|
|
|
|
|
for(; ngroup; ngroup= ngroup->id.next)
|
|
|
|
|
if(ngroup->type==ntree->type)
|
|
|
|
|
tot++;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
bNodeType *type = ntree->alltypes.first;
|
|
|
|
|
while(type) {
|
|
|
|
|
if(type->nclass == nodeclass)
|
|
|
|
|
tot++;
|
|
|
|
|
type= type->next;
|
2008-12-25 18:29:56 +00:00
|
|
|
}
|
2009-08-19 00:55:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(tot==0) {
|
|
|
|
|
uiItemS(layout);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uiLayoutSetFunc(layout, do_node_add, NULL);
|
|
|
|
|
|
|
|
|
|
if(nodeclass==NODE_CLASS_GROUP) {
|
|
|
|
|
bNodeTree *ngroup= bmain->nodetree.first;
|
|
|
|
|
|
|
|
|
|
for(tot=0, a=0; ngroup; ngroup= ngroup->id.next, tot++) {
|
|
|
|
|
if(ngroup->type==ntree->type) {
|
|
|
|
|
uiItemV(layout, ngroup->id.name+2, 0, NODE_GROUP_MENU+tot);
|
|
|
|
|
a++;
|
2008-12-25 18:29:56 +00:00
|
|
|
}
|
|
|
|
|
}
|
2009-08-19 00:55:30 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
bNodeType *type;
|
|
|
|
|
int script=0;
|
|
|
|
|
|
|
|
|
|
for(a=0, type= ntree->alltypes.first; type; type=type->next) {
|
|
|
|
|
if(type->nclass == nodeclass && type->name) {
|
|
|
|
|
if(type->type == NODE_DYNAMIC) {
|
|
|
|
|
uiItemV(layout, type->name, 0, NODE_DYNAMIC_MENU+script);
|
|
|
|
|
script++;
|
2008-12-25 18:29:56 +00:00
|
|
|
}
|
2009-08-19 00:55:30 +00:00
|
|
|
else
|
|
|
|
|
uiItemV(layout, type->name, 0, type->type);
|
|
|
|
|
|
|
|
|
|
a++;
|
2008-12-25 18:29:56 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-19 00:55:30 +00:00
|
|
|
static void node_menu_add(const bContext *C, Menu *menu)
|
2008-12-25 18:29:56 +00:00
|
|
|
{
|
2009-08-19 00:55:30 +00:00
|
|
|
uiLayout *layout= menu->layout;
|
|
|
|
|
SpaceNode *snode= CTX_wm_space_node(C);
|
2008-12-25 18:29:56 +00:00
|
|
|
|
2009-08-19 00:55:30 +00:00
|
|
|
if(!snode->nodetree)
|
|
|
|
|
uiLayoutSetActive(layout, 0);
|
2008-12-25 18:29:56 +00:00
|
|
|
|
|
|
|
|
if(snode->treetype==NTREE_SHADER) {
|
2009-08-19 00:55:30 +00:00
|
|
|
uiItemMenuF(layout, "Input", 0, node_auto_add_menu, SET_INT_IN_POINTER(NODE_CLASS_INPUT));
|
|
|
|
|
uiItemMenuF(layout, "Output", 0, node_auto_add_menu, SET_INT_IN_POINTER(NODE_CLASS_OUTPUT));
|
|
|
|
|
uiItemMenuF(layout, "Color", 0, node_auto_add_menu, SET_INT_IN_POINTER(NODE_CLASS_OP_COLOR));
|
|
|
|
|
uiItemMenuF(layout, "Vector", 0, node_auto_add_menu, SET_INT_IN_POINTER(NODE_CLASS_OP_VECTOR));
|
|
|
|
|
uiItemMenuF(layout, "Convertor", 0, node_auto_add_menu, SET_INT_IN_POINTER(NODE_CLASS_CONVERTOR));
|
|
|
|
|
uiItemMenuF(layout, "Group", 0, node_auto_add_menu, SET_INT_IN_POINTER(NODE_CLASS_GROUP));
|
|
|
|
|
uiItemMenuF(layout, "Dynamic", 0, node_auto_add_menu, SET_INT_IN_POINTER(NODE_CLASS_OP_DYNAMIC));
|
2008-12-25 18:29:56 +00:00
|
|
|
}
|
|
|
|
|
else if(snode->treetype==NTREE_COMPOSIT) {
|
2009-08-19 00:55:30 +00:00
|
|
|
uiItemMenuF(layout, "Input", 0, node_auto_add_menu, SET_INT_IN_POINTER(NODE_CLASS_INPUT));
|
|
|
|
|
uiItemMenuF(layout, "Output", 0, node_auto_add_menu, SET_INT_IN_POINTER(NODE_CLASS_OUTPUT));
|
|
|
|
|
uiItemMenuF(layout, "Color", 0, node_auto_add_menu, SET_INT_IN_POINTER(NODE_CLASS_OP_COLOR));
|
|
|
|
|
uiItemMenuF(layout, "Vector", 0, node_auto_add_menu, SET_INT_IN_POINTER(NODE_CLASS_OP_VECTOR));
|
|
|
|
|
uiItemMenuF(layout, "Filter", 0, node_auto_add_menu, SET_INT_IN_POINTER(NODE_CLASS_OP_FILTER));
|
|
|
|
|
uiItemMenuF(layout, "Convertor", 0, node_auto_add_menu, SET_INT_IN_POINTER(NODE_CLASS_CONVERTOR));
|
|
|
|
|
uiItemMenuF(layout, "Matte", 0, node_auto_add_menu, SET_INT_IN_POINTER(NODE_CLASS_MATTE));
|
|
|
|
|
uiItemMenuF(layout, "Distort", 0, node_auto_add_menu, SET_INT_IN_POINTER(NODE_CLASS_DISTORT));
|
|
|
|
|
uiItemMenuF(layout, "Group", 0, node_auto_add_menu, SET_INT_IN_POINTER(NODE_CLASS_GROUP));
|
2008-12-25 18:29:56 +00:00
|
|
|
}
|
2009-08-19 00:55:30 +00:00
|
|
|
else if(snode->treetype==NTREE_TEXTURE) {
|
|
|
|
|
uiItemMenuF(layout, "Input", 0, node_auto_add_menu, SET_INT_IN_POINTER(NODE_CLASS_INPUT));
|
|
|
|
|
uiItemMenuF(layout, "Output", 0, node_auto_add_menu, SET_INT_IN_POINTER(NODE_CLASS_OUTPUT));
|
|
|
|
|
uiItemMenuF(layout, "Color", 0, node_auto_add_menu, SET_INT_IN_POINTER(NODE_CLASS_OP_COLOR));
|
|
|
|
|
uiItemMenuF(layout, "Patterns", 0, node_auto_add_menu, SET_INT_IN_POINTER(NODE_CLASS_PATTERN));
|
|
|
|
|
uiItemMenuF(layout, "Textures", 0, node_auto_add_menu, SET_INT_IN_POINTER(NODE_CLASS_TEXTURE));
|
|
|
|
|
uiItemMenuF(layout, "Convertor", 0, node_auto_add_menu, SET_INT_IN_POINTER(NODE_CLASS_CONVERTOR));
|
|
|
|
|
uiItemMenuF(layout, "Distort", 0, node_auto_add_menu, SET_INT_IN_POINTER(NODE_CLASS_DISTORT));
|
|
|
|
|
uiItemMenuF(layout, "Group", 0, node_auto_add_menu, SET_INT_IN_POINTER(NODE_CLASS_GROUP));
|
2008-12-25 18:29:56 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-19 00:55:30 +00:00
|
|
|
void node_menus_register(ARegionType *art)
|
|
|
|
|
{
|
|
|
|
|
MenuType *mt;
|
|
|
|
|
|
|
|
|
|
mt= MEM_callocN(sizeof(MenuType), "spacetype node menu add");
|
|
|
|
|
strcpy(mt->idname, "NODE_MT_add");
|
|
|
|
|
strcpy(mt->label, "Add");
|
|
|
|
|
mt->draw= node_menu_add;
|
2009-10-08 19:06:32 +00:00
|
|
|
WM_menutype_add(mt);
|
2009-08-19 00:55:30 +00:00
|
|
|
}
|
|
|
|
|
|