Orange; tweaks for further integrating node editing in UI

- Previews inside groups now get updated too
- Activating nodes inside of groups updates UI and preview render correctly
- Entering/leaving groups updates UI and previewrender
- Material Node: now draws socket name next to colorpicker for inputs
This commit is contained in:
2006-01-03 11:34:28 +00:00
parent 85f089f3b9
commit 4bc4eac1e5
9 changed files with 126 additions and 73 deletions

View File

@@ -56,7 +56,6 @@ ID *material_from(struct Object *ob, int act);
void assign_material(struct Object *ob, struct Material *ma, int act);
void new_material_to_objectdata(struct Object *ob);
struct Material *get_active_matlayer(struct Material *);
void init_render_material(struct Material *);
void init_render_materials(void);
void end_render_material(struct Material *);

View File

@@ -579,29 +579,6 @@ void new_material_to_objectdata(Object *ob)
ob->actcol= ob->totcol;
}
/* will be renamed... now easy to re-use for nodes! */
Material *get_active_matlayer(Material *ma)
{
if(ma==NULL) return NULL;
if(ma->use_nodes) {
bNode *node= nodeGetActiveID(ma->nodetree, ID_MA);
if(node && node->id) {
return (Material *)node->id;
}
return NULL;
}
else {
MaterialLayer *ml;
for(ml= ma->layers.first; ml; ml= ml->next)
if(ml->flag & ML_ACTIVE) break;
if(ml)
return ml->mat;
}
return ma;
}
static void do_init_render_material(Material *ma)
{
MTex *mtex;

View File

@@ -1141,9 +1141,14 @@ void ntreeInitPreview(bNodeTree *ntree, int xsize, int ysize)
{
bNode *node;
if(ntree==NULL)
return;
for(node= ntree->nodes.first; node; node= node->next) {
if(node->typeinfo->flag & NODE_PREVIEW) /* hrms, check for closed nodes? */
nodeInitPreview(node, xsize, ysize);
if(node->type==NODE_GROUP && (node->flag & NODE_GROUP_EDIT))
ntreeInitPreview((bNodeTree *)node->id, xsize, ysize);
}
}

View File

@@ -40,10 +40,17 @@
struct SpaceNode;
struct bNode;
struct bNodeTree;
struct Material;
struct ID;
/* ************* API for editnode.c *********** */
/* helper calls to retreive active context for buttons, does groups */
struct Material *editnode_get_active_material(struct Material *ma);
struct bNode *editnode_get_active_idnode(struct bNodeTree *ntree, short id_code);
struct bNode *editnode_get_active(struct bNodeTree *ntree);
void snode_tag_dirty(struct SpaceNode *snode);
void snode_set_context(struct SpaceNode *snode);

View File

@@ -1390,7 +1390,7 @@ void do_radiobuts(unsigned short event)
case B_RAD_FAC:
set_radglobal();
if(phase & RAD_PHASE_FACES) make_face_tab();
else make_node_display();
else make_node_display(); /* radio solver also uses nodes, different ones :) */
allqueue(REDRAWVIEW3D, 0);
break;
case B_RAD_NODELIM:
@@ -2362,7 +2362,7 @@ void do_matbuts(unsigned short event)
/* but this also gets called for lamp and world... */
ma= G.buts->lockpoin;
if(ma && GS(ma->id.name)==ID_MA)
ma = get_active_matlayer(ma);
ma = editnode_get_active_material(ma);
else
ma= NULL;
@@ -3378,10 +3378,10 @@ static void material_panel_nodes(Material *ma)
uiNewPanelTabbed("Links", "Material");
if(uiNewPanel(curarea, block, "Nodes", "Material", 640, 0, 318, 204)==0) return;
node= nodeGetActive(ma->nodetree);
node= editnode_get_active(ma->nodetree);
if(node==NULL) return;
/* we dont display the buttons here for the active material, is in links panel */
if(node==nodeGetActiveID(ma->nodetree, ID_MA)) return;
if(node==editnode_get_active_idnode(ma->nodetree, ID_MA)) return;
if(node->typeinfo->butfunc) {
rctf rct;
@@ -3453,9 +3453,9 @@ static void material_panel_links(Object *ob, Material *ma)
uiDefBut(block, ROUNDBOX, 0, "", 5, 40, 310, 75, NULL, 7.0, 0.0, 15 , 20, "");
uiDefBut(block, LABEL, B_DIFF, "Active Material Node", 10, 95, 300, 20, 0, 0, 0, 0, 0, "");
if(ma) node= nodeGetActiveID(ma->nodetree, ID_MA);
if(ma) node= editnode_get_active_idnode(ma->nodetree, ID_MA);
if(node==NULL) {
node= nodeGetActive(ma->nodetree);
node= editnode_get_active(ma->nodetree);
if(node==NULL || node->type!=SH_NODE_MATERIAL)
return;
}
@@ -3519,9 +3519,8 @@ void material_panels()
if(ma && ma->use_nodes) {
material_panel_nodes(ma);
}
//material_panel_layers(ma);
ma= get_active_matlayer(ma); // checks nodes too
ma= editnode_get_active_material(ma);
if(ma) {
material_panel_material(ma);
material_panel_ramps(ma);
@@ -3604,14 +3603,16 @@ void texture_panels()
if(G.buts->texfrom==0) {
if(ob) {
ma= give_current_material(ob, ob->actcol);
if(ma && ma->use_nodes)
node= nodeGetActiveID(ma->nodetree, ID_TE);
if(ma && ma->use_nodes) {
node= editnode_get_active_idnode(ma->nodetree, ID_TE);
if(node)
ma= NULL;
else {
ma= get_active_matlayer(ma);
if(ma) mtex= ma->mtex[ ma->texact ];
if(node)
ma= NULL;
else {
ma= editnode_get_active_material(ma);
if(ma) mtex= ma->mtex[ ma->texact ];
}
}
}
}

View File

@@ -928,10 +928,18 @@ static void node_draw_basis(ScrArea *sa, SpaceNode *snode, bNode *node)
"");
}
else if(node->block && sock->type==SOCK_RGBA) {
short labelw= node->width-NODE_DY-40, width;
if(labelw>0) width= 40; else width= node->width-NODE_DY;
bt= uiDefButF(node->block, COL, B_NODE_EXEC, "",
(short)(sock->locx+NODE_DYS), (short)sock->locy-8, (short)(node->width-NODE_DY), 15,
(short)(sock->locx+NODE_DYS), (short)sock->locy-8, width, 15,
butpoin, 0, 0, 0, 0, "");
uiButSetFunc(bt, node_sync_cb, snode, node);
if(labelw>0) uiDefBut(node->block, LABEL, 0, sock->name,
(short)(sock->locx+NODE_DYS) + 40, (short)sock->locy-8, labelw, 15,
NULL, 0, 0, 0, 0, "");
}
}
else {

View File

@@ -76,6 +76,7 @@
#include "PIL_time.h"
#include "mydevice.h"
/* currently called from BIF_preview_changed */
void snode_tag_dirty(SpaceNode *snode)
{
@@ -211,6 +212,27 @@ void snode_set_context(SpaceNode *snode)
snode->edittree= snode->nodetree;
}
static void node_set_active(SpaceNode *snode, bNode *node)
{
nodeSetActive(snode->edittree, node);
if(node->type!=NODE_GROUP) {
/* tree specific activate calls */
if(snode->treetype==NTREE_SHADER) {
/* when we select a material, active texture is cleared, for buttons */
if(node->id && GS(node->id->name)==ID_MA)
nodeClearActiveID(snode->edittree, ID_TE);
if(node->id)
BIF_preview_changed(-1); /* temp hack to force texture preview to update */
allqueue(REDRAWBUTSSHADING, 1);
}
}
}
static bNode *snode_get_editgroup(SpaceNode *snode)
{
bNode *gnode;
@@ -222,7 +244,7 @@ static bNode *snode_get_editgroup(SpaceNode *snode)
return gnode;
}
static void node_make_group_editable(SpaceNode *snode, bNode *gnode)
static void snode_make_group_editable(SpaceNode *snode, bNode *gnode)
{
bNode *node;
@@ -249,6 +271,13 @@ static void node_make_group_editable(SpaceNode *snode, bNode *gnode)
else
snode->edittree= snode->nodetree;
/* finally send out events for new active node */
if(snode->treetype==NTREE_SHADER) {
allqueue(REDRAWBUTSSHADING, 0);
BIF_preview_changed(-1); /* temp hack to force texture preview to update */
}
allqueue(REDRAWNODE, 0);
}
@@ -605,6 +634,50 @@ static void scale_node(SpaceNode *snode, bNode *node)
/* ********************** select ******************** */
/* used in buttons to check context, also checks for edited groups */
bNode *editnode_get_active_idnode(bNodeTree *ntree, short id_code)
{
bNode *node;
/* check for edited group */
for(node= ntree->nodes.first; node; node= node->next)
if(node->flag & NODE_GROUP_EDIT)
break;
if(node)
return nodeGetActiveID((bNodeTree *)node->id, id_code);
else
return nodeGetActiveID(ntree, id_code);
}
/* used in buttons to check context, also checks for edited groups */
Material *editnode_get_active_material(Material *ma)
{
if(ma && ma->use_nodes && ma->nodetree) {
bNode *node= editnode_get_active_idnode(ma->nodetree, ID_MA);
if(node)
return (Material *)node->id;
else
return NULL;
}
return ma;
}
/* used in buttons to check context, also checks for edited groups */
bNode *editnode_get_active(bNodeTree *ntree)
{
bNode *node;
/* check for edited group */
for(node= ntree->nodes.first; node; node= node->next)
if(node->flag & NODE_GROUP_EDIT)
break;
if(node)
return nodeGetActive((bNodeTree *)node->id);
else
return nodeGetActive(ntree);
}
/* no undo here! */
void node_deselectall(SpaceNode *snode, int swap)
{
@@ -629,27 +702,6 @@ void node_deselectall(SpaceNode *snode, int swap)
allqueue(REDRAWNODE, 0);
}
void node_set_active(SpaceNode *snode, bNode *node)
{
nodeSetActive(snode->edittree, node);
if(node->type!=NODE_GROUP) {
/* tree specific activate calls */
if(snode->treetype==NTREE_SHADER) {
/* when we select a material, active texture is cleared, for buttons */
if(node->id && GS(node->id->name)==ID_MA)
nodeClearActiveID(snode->edittree, ID_TE);
if(node->id)
BIF_preview_changed(-1); /* temp hack to force texture preview to update */
allqueue(REDRAWBUTSSHADING, 1);
}
}
}
int node_has_hidden_sockets(bNode *node)
{
bNodeSocket *sock;
@@ -734,7 +786,7 @@ static int do_header_node(SpaceNode *snode, bNode *node, float mx, float my)
}
if(node->type == NODE_GROUP) {
if(BLI_in_rctf(&totr, mx, my)) {
node_make_group_editable(snode, node);
snode_make_group_editable(snode, node);
return 1;
}
totr.xmin-=18.0f;
@@ -855,7 +907,7 @@ static int node_mouse_groupheader(SpaceNode *snode)
rect.ymax += NODE_DY;
if(BLI_in_rctf(&rect, mx, my)==0)
node_make_group_editable(snode, NULL); /* toggles, so exits editmode */
snode_make_group_editable(snode, NULL); /* toggles, so exits editmode */
else
transform_nodes(snode->nodetree, 'g', "Move group");
@@ -1461,7 +1513,7 @@ void winqreadnodespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
doredraw= 1;
break;
case TABKEY:
node_make_group_editable(snode, NULL);
snode_make_group_editable(snode, NULL);
break;
case AKEY:

View File

@@ -71,7 +71,9 @@
#include "BKE_node.h"
#include "BKE_texture.h"
#include "BKE_utildefines.h"
#include "BSE_drawipo.h"
#include "BSE_node.h"
#include "BSE_headerbuttons.h"
#include "MEM_guardedalloc.h"
@@ -286,13 +288,14 @@ void buttons_active_id(ID **id, ID **idfrom)
ma= give_current_material(ob, ob->actcol);
if(ma && ma->use_nodes)
node= nodeGetActiveID(ma->nodetree, ID_TE);
node= editnode_get_active_idnode(ma->nodetree, ID_TE);
if(node) {
*idfrom= NULL;
*id= node->id;
}
else {
ma= get_active_matlayer(ma);
ma= editnode_get_active_material(ma);
*idfrom= (ID *)ma;
if(ma) {
mtex= ma->mtex[ ma->texact ];

View File

@@ -150,6 +150,7 @@
#include "BSE_edit.h"
#include "BSE_filesel.h"
#include "BSE_headerbuttons.h"
#include "BSE_node.h"
#include "BSE_view.h"
#include "BSE_sequence.h"
#include "BSE_editipo.h"
@@ -723,7 +724,7 @@ void do_global_buttons(unsigned short event)
else {
if(G.buts->texfrom==0) { /* from mat */
ma= give_current_material(ob, ob->actcol);
ma= get_active_matlayer(ma);
ma= editnode_get_active_material(ma);
if(ma) {
mtex= ma->mtex[ ma->texact ];
if(mtex) {
@@ -776,7 +777,7 @@ void do_global_buttons(unsigned short event)
if(event==B_EXTEXBROWSE) {
id= NULL;
ma= give_current_material(ob, ob->actcol);
ma= get_active_matlayer(ma);
ma= editnode_get_active_material(ma);
if(ma) {
mtex= ma->mtex[ ma->texact ];
if(mtex) id= (ID *)mtex->tex;
@@ -795,7 +796,7 @@ void do_global_buttons(unsigned short event)
id= NULL;
ma= give_current_material(ob, ob->actcol);
ma= get_active_matlayer(ma);
ma= editnode_get_active_material(ma);
if(ma) {
mtex= ma->mtex[ ma->texact ];
if(mtex) id= (ID *)mtex->tex;
@@ -1713,7 +1714,7 @@ void do_global_buttons2(short event)
if(G.buts->texfrom==0) { /* from mat */
if(ob==0) return;
ma= give_current_material(ob, ob->actcol);
ma= get_active_matlayer(ma);
ma= editnode_get_active_material(ma);
if(ma && ma->id.lib==0) {
mtex= ma->mtex[ ma->texact ];
if(mtex->tex && mtex->tex->id.us>1) {
@@ -1754,7 +1755,7 @@ void do_global_buttons2(short event)
if(G.buts->texfrom==0) { /* from mat */
if(ob==0) return;
ma= give_current_material(ob, ob->actcol);
ma= get_active_matlayer(ma);
ma= editnode_get_active_material(ma);
if(ma && ma->id.lib==0) {
mtex= ma->mtex[ ma->texact ];
if(mtex->tex && mtex->tex->id.lib) {