Spelling Cleanup
[blender.git] / source / blender / editors / space_node / space_node.c
index 1ac745b8c0ec63edf6101257d9fe2527c068b59e..93d3b22e09234679f5a243014ef5f58f2ad00cb7 100644 (file)
@@ -1,6 +1,4 @@
-/**
- * $Id$
- *
+/*
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
  * ***** END GPL LICENSE BLOCK *****
  */
 
+/** \file blender/editors/space_node/space_node.c
+ *  \ingroup spnode
+ */
+
+
 #include <string.h>
 #include <stdio.h>
 
+#include "DNA_lamp_types.h"
+#include "DNA_material_types.h"
 #include "DNA_node_types.h"
 #include "DNA_object_types.h"
-#include "DNA_material_types.h"
 #include "DNA_scene_types.h"
+#include "DNA_world_types.h"
 
 #include "MEM_guardedalloc.h"
 
@@ -45,6 +50,7 @@
 #include "BKE_screen.h"
 #include "BKE_node.h"
 
+#include "ED_space_api.h"
 #include "ED_render.h"
 #include "ED_screen.h"
 
 ARegion *node_has_buttons_region(ScrArea *sa)
 {
        ARegion *ar, *arnew;
-       
-       for(ar= sa->regionbase.first; ar; ar= ar->next)
-               if(ar->regiontype==RGN_TYPE_UI)
-                       return ar;
+
+       ar= BKE_area_find_region_type(sa, RGN_TYPE_UI);
+       if(ar) return ar;
        
        /* add subdiv level; after header */
-       for(ar= sa->regionbase.first; ar; ar= ar->next)
-               if(ar->regiontype==RGN_TYPE_HEADER)
-                       break;
-       
+       ar= BKE_area_find_region_type(sa, RGN_TYPE_HEADER);
+
        /* is error! */
        if(ar==NULL) return NULL;
        
@@ -166,6 +169,7 @@ static void node_area_listener(ScrArea *sa, wmNotifier *wmn)
        /* note, ED_area_tag_refresh will re-execute compositor */
        SpaceNode *snode= sa->spacedata.first;
        int type= snode->treetype;
+       short shader_type = snode->shaderfrom;
        
        /* preview renders */
        switch(wmn->category) {
@@ -175,6 +179,9 @@ static void node_area_listener(ScrArea *sa, wmNotifier *wmn)
                                case ND_FRAME:
                                        ED_area_tag_refresh(sa);
                                        break;
+                               case ND_COMPO_RESULT:
+                                       ED_area_tag_redraw(sa);
+                                       break;
                                case ND_TRANSFORM_DONE:
                                        if(type==NTREE_COMPOSIT) {
                                                if(snode->flag & SNODE_AUTO_RENDER) {
@@ -197,6 +204,9 @@ static void node_area_listener(ScrArea *sa, wmNotifier *wmn)
                                        ED_area_tag_refresh(sa);
                                else if(wmn->data==ND_SHADING_DRAW)
                                        ED_area_tag_refresh(sa);
+                               else if(wmn->action==NA_ADDED && snode->edittree)
+                                       nodeSetActiveID(snode->edittree, ID_MA, wmn->reference);
+                                       
                        }
                        break;
                case NC_TEXTURE:
@@ -205,6 +215,17 @@ static void node_area_listener(ScrArea *sa, wmNotifier *wmn)
                                        ED_area_tag_refresh(sa);
                        }
                        break;
+               case NC_WORLD:
+                       if(type==NTREE_SHADER && shader_type==SNODE_SHADER_WORLD) {
+                               ED_area_tag_refresh(sa);        
+                       }
+                       break;
+               case NC_OBJECT:
+                       if(type==NTREE_SHADER) {
+                               if(wmn->data==ND_OB_SHADING)
+                                       ED_area_tag_refresh(sa);
+                       }
+                       break;
                case NC_TEXT:
                        /* pynodes */
                        if(wmn->data==ND_SHADING)
@@ -219,17 +240,24 @@ static void node_area_listener(ScrArea *sa, wmNotifier *wmn)
                case NC_NODE:
                        if (wmn->action == NA_EDITED)
                                ED_area_tag_refresh(sa);
+                       else if (wmn->action == NA_SELECTED)
+                               ED_area_tag_redraw(sa);
+                       break;
+               case NC_SCREEN:
+                       switch(wmn->data) {
+                               case ND_ANIMPLAY:
+                                       ED_area_tag_refresh(sa);
+                                       break;
+                       }
                        break;
 
                case NC_IMAGE:
                        if (wmn->action == NA_EDITED) {
                                if(type==NTREE_COMPOSIT) {
-                                       Scene *scene= wmn->window->screen->scene;
-                                       
-                                       /* note that NodeTagIDChanged is alredy called by BKE_image_signal() on all
+                                       /* note that nodeUpdateID is already called by BKE_image_signal() on all
                                         * scenes so really this is just to know if the images is used in the compo else
                                         * painting on images could become very slow when the compositor is open. */
-                                       if(NodeTagIDChanged(scene->nodetree, wmn->reference))
+                                       if(nodeUpdateID(snode->nodetree, wmn->reference))
                                                ED_area_tag_refresh(sa);
                                }
                        }
@@ -246,9 +274,21 @@ static void node_area_refresh(const struct bContext *C, struct ScrArea *sa)
        
        if(snode->nodetree) {
                if(snode->treetype==NTREE_SHADER) {
-                       Material *ma= (Material *)snode->id;
-                       if(ma->use_nodes)
-                               ED_preview_shader_job(C, sa, snode->id, NULL, NULL, 100, 100, PR_NODE_RENDER);
+                       if(GS(snode->id->name) == ID_MA) {
+                               Material *ma= (Material *)snode->id;
+                               if(ma->use_nodes)
+                                       ED_preview_shader_job(C, sa, snode->id, NULL, NULL, 100, 100, PR_NODE_RENDER);
+                       }
+                       else if(GS(snode->id->name) == ID_LA) {
+                               Lamp *la= (Lamp *)snode->id;
+                               if(la->use_nodes)
+                                       ED_preview_shader_job(C, sa, snode->id, NULL, NULL, 100, 100, PR_NODE_RENDER);
+                       }
+                       else if(GS(snode->id->name) == ID_WO) {
+                               World *wo= (World *)snode->id;
+                               if(wo->use_nodes)
+                                       ED_preview_shader_job(C, sa, snode->id, NULL, NULL, 100, 100, PR_NODE_RENDER);
+                       }
                }
                else if(snode->treetype==NTREE_COMPOSIT) {
                        Scene *scene= (Scene *)snode->id;
@@ -277,6 +317,7 @@ static SpaceLink *node_duplicate(SpaceLink *sl)
        
        /* clear or remove stuff from old */
        snoden->nodetree= NULL;
+       snoden->linkdrag.first= snoden->linkdrag.last= NULL;
        
        return (SpaceLink *)snoden;
 }
@@ -298,7 +339,7 @@ static void node_buttons_area_draw(const bContext *C, ARegion *ar)
        ED_region_panels(C, ar, 1, NULL, -1);
 }
 
-/* Initialise main area, setting handlers. */
+/* Initialize main area, setting handlers. */
 static void node_main_area_init(wmWindowManager *wm, ARegion *ar)
 {
        wmKeyMap *keymap;
@@ -403,6 +444,10 @@ static void node_region_listener(ARegion *ar, wmNotifier *wmn)
                case NC_NODE:
                        ED_region_tag_redraw(ar);
                        break;
+               case NC_OBJECT:
+                       if(wmn->data==ND_OB_SHADING)
+                               ED_region_tag_redraw(ar);
+                       break;
                case NC_ID:
                        if(wmn->action == NA_RENAME)
                                ED_region_tag_redraw(ar);
@@ -410,26 +455,43 @@ static void node_region_listener(ARegion *ar, wmNotifier *wmn)
        }
 }
 
+const char *node_context_dir[] = {"selected_nodes", NULL};
+
 static int node_context(const bContext *C, const char *member, bContextDataResult *result)
 {
        SpaceNode *snode= CTX_wm_space_node(C);
        
        if(CTX_data_dir(member)) {
-               static const char *dir[] = {"selected_nodes", NULL};
-               CTX_data_dir_set(result, dir);
+               CTX_data_dir_set(result, node_context_dir);
                return 1;
        }
        else if(CTX_data_equals(member, "selected_nodes")) {
                bNode *node;
                
-               for(next_node(snode->edittree); (node=next_node(NULL));) {
-                       if(node->flag & SELECT) {
-                               CTX_data_list_add(result, &snode->edittree->id, &RNA_Node, node);
+               if(snode->edittree) {
+                       for(node=snode->edittree->nodes.last; node; node=node->prev) {
+                               if(node->flag & NODE_SELECT) {
+                                       CTX_data_list_add(result, &snode->edittree->id, &RNA_Node, node);
+                               }
                        }
                }
                CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
                return 1;
        }
+       else if(CTX_data_equals(member, "active_node")) {
+               bNode *node;
+               
+               if(snode->edittree) {
+                       for(node=snode->edittree->nodes.last; node; node=node->prev) {
+                               if(node->flag & NODE_ACTIVE) {
+                                       CTX_data_pointer_set(result, &snode->edittree->id, &RNA_Node, node);
+                                       break;
+                               }
+                       }
+               }
+               CTX_data_type_set(result, CTX_DATA_TYPE_POINTER);
+               return 1;
+       }
        
        return 0;
 }