Spelling Cleanup
[blender.git] / source / blender / editors / space_node / space_node.c
index 96ce19b76018242f0c06adb4fb2cda2c57f62679..93d3b22e09234679f5a243014ef5f58f2ad00cb7 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id$
- *
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
 #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"
 
@@ -169,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) {
@@ -178,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) {
@@ -200,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:
@@ -208,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)
@@ -222,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 already 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);
                                }
                        }
@@ -249,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;
@@ -302,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;
@@ -407,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);
@@ -427,14 +468,30 @@ static int node_context(const bContext *C, const char *member, bContextDataResul
        else if(CTX_data_equals(member, "selected_nodes")) {
                bNode *node;
                
-               for(next_node(snode->edittree); (node=next_node(NULL));) {
-                       if(node->flag & NODE_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;
 }