Blender V2.61 - r43446

node_buttons.c

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version. 
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2009 Blender Foundation.
00019  * All rights reserved.
00020  *
00021  * 
00022  * Contributor(s): Blender Foundation
00023  *
00024  * ***** END GPL LICENSE BLOCK *****
00025  */
00026 
00032 #include <string.h>
00033 #include <stdio.h>
00034 #include <math.h>
00035 #include <float.h>
00036 
00037 #include "MEM_guardedalloc.h"
00038 
00039 #include "DNA_node_types.h"
00040 #include "DNA_scene_types.h"
00041 
00042 #include "BLI_math.h"
00043 #include "BLI_blenlib.h"
00044 #include "BLI_rand.h"
00045 #include "BLI_utildefines.h"
00046 
00047 #include "BKE_context.h"
00048 #include "BKE_global.h"
00049 #include "BKE_node.h"
00050 #include "BKE_screen.h"
00051 
00052 #include "WM_api.h"
00053 #include "WM_types.h"
00054 
00055 #include "RNA_access.h"
00056 
00057 #include "ED_gpencil.h"
00058 #include "ED_screen.h"
00059 
00060 #include "UI_interface.h"
00061 #include "UI_resources.h"
00062 
00063 #include "node_intern.h"    // own include
00064 
00065 
00066 /* ******************* node space & buttons ************** */
00067 #define B_NOP       1
00068 #define B_REDR      2
00069 
00070 static void do_node_region_buttons(bContext *C, void *UNUSED(arg), int event)
00071 {
00072     //SpaceNode *snode= CTX_wm_space_node(C);
00073     
00074     switch(event) {
00075     case B_REDR:
00076         ED_area_tag_redraw(CTX_wm_area(C));
00077         return; /* no notifier! */
00078     }
00079 }
00080 
00081 /* poll callback for active node */
00082 static int active_node_poll(const bContext *C, PanelType *UNUSED(pt))
00083 {
00084     SpaceNode *snode= CTX_wm_space_node(C);
00085     
00086     // TODO: include check for whether there is an active node...
00087     return (snode && snode->nodetree);
00088 }
00089 
00090 /* active node */
00091 static void active_node_panel(const bContext *C, Panel *pa)
00092 {
00093     SpaceNode *snode= CTX_wm_space_node(C);
00094     bNodeTree *ntree= (snode) ? snode->edittree : NULL;
00095     bNode *node = (ntree) ? nodeGetActive(ntree) : NULL; // xxx... for editing group nodes
00096     uiLayout *layout= pa->layout;
00097     uiBlock *block;
00098     PointerRNA ptr;
00099     
00100     /* verify pointers, and create RNA pointer for the node */
00101     if ELEM(NULL, ntree, node)
00102         return;
00103     //if (node->id) /* for group nodes */
00104     //  RNA_pointer_create(node->id, &RNA_Node, node, &ptr);
00105     //else
00106         RNA_pointer_create(&ntree->id, &RNA_Node, node, &ptr); 
00107     
00108     /* set update callback */
00109     // xxx is this really needed
00110     block= uiLayoutGetBlock(layout);
00111     uiBlockSetHandleFunc(block, do_node_region_buttons, NULL);
00112     
00113     /* draw this node's name, etc. */
00114     uiItemR(layout, &ptr, "label", 0, NULL, ICON_NODE);
00115     uiItemS(layout);
00116     uiItemR(layout, &ptr, "name", 0, NULL, ICON_NODE);
00117     uiItemS(layout);
00118     
00119     uiItemO(layout, NULL, 0, "NODE_OT_hide_socket_toggle");
00120     uiItemS(layout);
00121 
00122     /* draw this node's settings */
00123     if (node->typeinfo && node->typeinfo->uifuncbut)
00124         node->typeinfo->uifuncbut(layout, (bContext *)C, &ptr);
00125     else if (node->typeinfo && node->typeinfo->uifunc)
00126         node->typeinfo->uifunc(layout, (bContext *)C, &ptr);
00127 }
00128 
00129 static int node_sockets_poll(const bContext *C, PanelType *UNUSED(pt))
00130 {
00131     SpaceNode *snode= CTX_wm_space_node(C);
00132     
00133     return (snode && snode->nodetree && G.rt == 777);
00134 }
00135 
00136 static void node_sockets_panel(const bContext *C, Panel *pa)
00137 {
00138     SpaceNode *snode= CTX_wm_space_node(C);
00139     bNodeTree *ntree= (snode) ? snode->edittree : NULL;
00140     bNode *node = (ntree) ? nodeGetActive(ntree) : NULL;
00141     bNodeSocket *sock;
00142     uiLayout *layout= pa->layout, *split;
00143     char name[UI_MAX_NAME_STR];
00144     
00145     if(ELEM(NULL, ntree, node))
00146         return;
00147     
00148     for(sock=node->inputs.first; sock; sock=sock->next) {
00149         BLI_snprintf(name, sizeof(name), "%s:", sock->name);
00150 
00151         split = uiLayoutSplit(layout, 0.35f, 0);
00152         uiItemL(split, name, ICON_NONE);
00153         uiTemplateNodeLink(split, ntree, node, sock);
00154     }
00155 }
00156 
00157 /* ******************* node buttons registration ************** */
00158 
00159 void node_buttons_register(ARegionType *art)
00160 {
00161     PanelType *pt;
00162     
00163     pt= MEM_callocN(sizeof(PanelType), "spacetype node panel active node");
00164     strcpy(pt->idname, "NODE_PT_item");
00165     strcpy(pt->label, "Active Node");
00166     pt->draw= active_node_panel;
00167     pt->poll= active_node_poll;
00168     BLI_addtail(&art->paneltypes, pt);
00169 
00170     pt= MEM_callocN(sizeof(PanelType), "spacetype node panel node sockets");
00171     strcpy(pt->idname, "NODE_PT_sockets");
00172     strcpy(pt->label, "Sockets");
00173     pt->draw= node_sockets_panel;
00174     pt->poll= node_sockets_poll;
00175     pt->flag |= PNL_DEFAULT_CLOSED;
00176     BLI_addtail(&art->paneltypes, pt);
00177     
00178     pt= MEM_callocN(sizeof(PanelType), "spacetype node panel gpencil");
00179     strcpy(pt->idname, "NODE_PT_gpencil");
00180     strcpy(pt->label, "Grease Pencil");
00181     pt->draw= gpencil_panel_standard;
00182     BLI_addtail(&art->paneltypes, pt);
00183 }
00184 
00185 static int node_properties(bContext *C, wmOperator *UNUSED(op))
00186 {
00187     ScrArea *sa= CTX_wm_area(C);
00188     ARegion *ar= node_has_buttons_region(sa);
00189     
00190     if(ar)
00191         ED_region_toggle_hidden(C, ar);
00192 
00193     return OPERATOR_FINISHED;
00194 }
00195 
00196 /* non-standard poll operator which doesn't care if there are any nodes */
00197 static int node_properties_poll(bContext *C)
00198 {
00199     ScrArea *sa= CTX_wm_area(C);
00200     return (sa && (sa->spacetype == SPACE_NODE));
00201 }
00202 
00203 void NODE_OT_properties(wmOperatorType *ot)
00204 {
00205     ot->name= "Properties";
00206     ot->description= "Toggles the properties panel display";
00207     ot->idname= "NODE_OT_properties";
00208     
00209     ot->exec= node_properties;
00210     ot->poll= node_properties_poll;
00211     
00212     /* flags */
00213     ot->flag= 0;
00214 }