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