This repository has been archived on 2023-10-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
blender-archive/source/blender/src/header_node.c
Ton Roosendaal 8d35213990 More node goodies!
First note; this is a WIP project, some commits might change things that
make formerly saved situations not to work identically... like now!

------ New Material integration ------

Until now, the Node system worked on top of the 'current' Material, just
like how the Material Layers worked. That's quite confusing in practice,
especially to see what Material is a Node, or what is the "base material"

Best solution is to completely separate the two. This has been implemented
as follows now;

- The confusing "Input" node has been removed.
- When choosing a Material in Blender, you can define this Material to be
  either 'normal' (default) or be the root of a Node tree.
- If a Material is a Node tree, you have to add Nodes in the tree to see
  something happen. An empty Node tree doesn't do anything (black).
- If a Material is a Node Tree, the 'data browse' menus show it with an
  'N' mark before the name. The 'data block' buttons display it with the
  suffix 'NT' (instead of 'MA').
- In a Node Tree, any Material can be inserted, including itself. Only in
  that case the Material is being used itself for shading.

UI changes:

Added a new Panel "Links", which shows:
- where the Material is linked to (Object, Mesh, etc)
- if the Material is a NodeTree or not
- the actual active Material in the Tree

The "Node" Panel itself now only shows buttons from the other nodes, when
they are active.

Further the Material Nodes themselves allow browsing and renaming or adding
new Materials now too.

Second half of today's work was cleaning up selection when the Nodes
overlap... it was possible to drag links from invisible sockets, or click
headers for invisible nodes, etc. This because the mouse input code was
not checking for visibility yet.
Works now even for buttons. :)
2005-12-29 18:08:01 +00:00

163 lines
4.1 KiB
C

/**
*
* $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) 2005 Blender Foundation.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "DNA_ID.h"
#include "DNA_material_types.h"
#include "DNA_node_types.h"
#include "DNA_object_types.h"
#include "DNA_screen_types.h"
#include "DNA_scene_types.h"
#include "DNA_space_types.h"
#include "DNA_view2d_types.h"
#include "DNA_userdef_types.h"
#include "BIF_gl.h"
#include "BIF_interface.h"
#include "BIF_previewrender.h"
#include "BIF_resources.h"
#include "BIF_screen.h"
#include "BIF_space.h"
#include "BIF_toolbox.h"
#include "BIF_butspace.h"
#include "BKE_global.h"
#include "BKE_main.h"
#include "BKE_material.h"
#include "BSE_headerbuttons.h"
#include "BSE_node.h"
#include "blendef.h"
#include "butspace.h"
#include "mydevice.h"
void do_node_buttons(ScrArea *sa, unsigned short event)
{
SpaceNode *snode= sa->spacedata.first;
Material *ma;
switch(event) {
case B_NODE_USEMAT:
ma= (Material *)snode->id;
if(ma) {
if(ma->use_nodes && ma->nodetree==NULL) {
node_shader_default(ma);
snode_set_context(snode);
}
BIF_preview_changed(ID_MA);
allqueue(REDRAWNODE, 0);
allqueue(REDRAWBUTSSHADING, 0);
}
break;
}
}
void node_buttons(ScrArea *sa)
{
SpaceNode *snode= sa->spacedata.first;
uiBlock *block;
short xco;
char name[256];
sprintf(name, "header %d", sa->headwin);
block= uiNewBlock(&sa->uiblocks, name, UI_EMBOSS, UI_HELV, sa->headwin);
if(area_is_active_area(sa)) uiBlockSetCol(block, TH_HEADER);
else uiBlockSetCol(block, TH_HEADERDESEL);
sa->butspacetype= SPACE_NODE;
xco = 8;
uiDefIconTextButC(block, ICONTEXTROW,B_NEWSPACE, ICON_VIEW3D,
windowtype_pup(), xco, 0, XIC+10, YIC,
&(sa->butspacetype), 1.0, SPACEICONMAX, 0, 0,
"Displays Current Window Type. "
"Click for menu of available types.");
xco += XIC + 14;
uiBlockSetEmboss(block, UI_EMBOSSN);
if (sa->flag & HEADER_NO_PULLDOWN) {
uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, B_FLIPINFOMENU,
ICON_DISCLOSURE_TRI_RIGHT,
xco,2,XIC,YIC-2,
&(sa->flag), 0, 0, 0, 0,
"Show pulldown menus");
}
else {
uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, B_FLIPINFOMENU,
ICON_DISCLOSURE_TRI_DOWN,
xco,2,XIC,YIC-2,
&(sa->flag), 0, 0, 0, 0,
"Hide pulldown menus");
}
xco+=XIC;
if((sa->flag & HEADER_NO_PULLDOWN)==0) {
/* pull down menus */
uiBlockSetEmboss(block, UI_EMBOSSP);
// xmax= GetButStringLength("View");
// uiDefPulldownBut(block, time_viewmenu, NULL,
// "View", xco, -2, xmax-3, 24, "");
// xco+= xmax;
}
uiBlockSetEmboss(block, UI_EMBOSS);
/* find and set the context */
snode_set_context(snode);
if(snode->treetype==NTREE_SHADER) {
if(snode->from) {
/* 0, NULL -> pin */
xco= std_libbuttons(block, xco, 0, 0, NULL, B_MATBROWSE, ID_MA, 1, snode->id, snode->from, &(snode->menunr),
B_MATALONE, B_MATLOCAL, B_MATDELETE, B_AUTOMATNAME, B_KEEPDATA);
if(snode->id) {
Material *ma= (Material *)snode->id;
uiDefButC(block, TOG, B_NODE_USEMAT, "Use Nodes", xco+5,0,70,19, &ma->use_nodes, 0.0f, 0.0f, 0, 0, "");
xco+=80;
}
}
}
/* always as last */
sa->headbutlen= xco+2*XIC;
uiDrawBlock(block);
}