texture slots up/down back
authorCampbell Barton <ideasman42@gmail.com>
Mon, 12 Oct 2009 16:00:39 +0000 (16:00 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 12 Oct 2009 16:00:39 +0000 (16:00 +0000)
release/scripts/ui/buttons_texture.py
source/blender/blenkernel/BKE_texture.h
source/blender/blenkernel/intern/texture.c
source/blender/editors/render/render_intern.h
source/blender/editors/render/render_ops.c
source/blender/editors/render/render_shading.c

index b8b46b257df24a8e2e133439834796c3c6e43302..a748a7ea155120bb5ac0ef5a25fdaa0354332100 100644 (file)
@@ -75,6 +75,10 @@ class TEXTURE_PT_context_texture(TextureButtonsPanel):
                        split.template_ID(idblock, "active_texture", new="texture.new")
                elif tex:
                        split.template_ID(space, "pin_id")
+               
+               row = split.row(align=True)
+               row.item_enumO("texture.slot_move", "type", 'UP', text="", icon='ICON_TRIA_UP')
+               row.item_enumO("texture.slot_move", "type", 'DOWN', text="", icon='ICON_TRIA_DOWN')
 
                if (not space.pin_id) and (
                        context.sculpt_object or
index c7a6e20cc8bf18b14a7410de1f4d5640c45d1567..b9dc5916e69ea2fa5c6bc4052b2131eeada7bda7 100644 (file)
@@ -75,6 +75,9 @@ struct Tex *give_current_lamp_texture(struct Lamp *la);
 struct Tex *give_current_world_texture(struct World *world);
 struct Tex *give_current_brush_texture(struct Brush *br);
 
+int                     give_active_mtex(struct ID *id, struct MTex ***mtex_ar, short *act);
+void            set_active_mtex(struct ID *id, short act);
+
 void set_current_brush_texture(struct Brush *br, struct Tex *tex);
 void set_current_world_texture(struct World *wo, struct Tex *tex);
 void set_current_material_texture(struct Material *ma, struct Tex *tex);
index d1c26b5a1b4caf6ca19486220e8d89766164f815..33dfcfca76ea63578e6781c9823068460e19c8aa 100644 (file)
@@ -889,6 +889,55 @@ Tex *give_current_material_texture(Material *ma)
        return tex;
 }
 
+int give_active_mtex(ID *id, MTex ***mtex_ar, short *act)
+{
+       switch(GS(id->name)) {
+       case ID_MA:
+               *mtex_ar=               ((Material *)id)->mtex;
+               if(act) *act=   (((Material *)id)->texact);
+               break;
+       case ID_WO:
+               *mtex_ar=               ((World *)id)->mtex;
+               if(act) *act=   (((World *)id)->texact);
+               break;
+       case ID_LA:
+               *mtex_ar=               ((Lamp *)id)->mtex;
+               if(act) *act=   (((Lamp *)id)->texact);
+               break;
+       case ID_BR:
+               *mtex_ar=               ((Brush *)id)->mtex;
+               if(act) *act=   (((Brush *)id)->texact);
+               break;
+       default:
+               *mtex_ar = NULL;
+               if(act) *act=   0;
+               return FALSE;
+       }
+
+       return TRUE;
+}
+
+void set_active_mtex(ID *id, short act)
+{
+       if(act<0)                               act= 0;
+       else if(act>=MAX_MTEX)  act= MAX_MTEX-1;
+
+       switch(GS(id->name)) {
+       case ID_MA:
+               ((Material *)id)->texact= act;
+               break;
+       case ID_WO:
+               ((World *)id)->texact= act;
+               break;
+       case ID_LA:
+               ((Lamp *)id)->texact= act;
+               break;
+       case ID_BR:
+               ((Brush *)id)->texact= act;
+               break;
+       }
+}
+
 void set_current_material_texture(Material *ma, Tex *newtex)
 {
        Tex *tex= NULL;
index d3ecbbc56e8c0cdbbbc86d3b2102b28519ac7083..7b4c0194c5d9e217a0979065cfc3302dcd81e3e0 100644 (file)
@@ -46,5 +46,8 @@ void WORLD_OT_new(struct wmOperatorType *ot);
 void SCENE_OT_render_layer_add(struct wmOperatorType *ot);
 void SCENE_OT_render_layer_remove(struct wmOperatorType *ot);
 
+void TEXTURE_OT_slot_move(struct wmOperatorType *ot);
+
+
 #endif /* RENDER_INTERN_H */
 
index 7d35dff74935f486dd3dcfd0b9b108596302113e..8c0c1b18fca0ec5ffad111b2e7c0be1c7ad492dc 100644 (file)
@@ -51,5 +51,7 @@ void ED_operatortypes_render(void)
 
        WM_operatortype_append(SCENE_OT_render_layer_add);
        WM_operatortype_append(SCENE_OT_render_layer_remove);
+
+       WM_operatortype_append(TEXTURE_OT_slot_move);
 }
 
index 26df0df935b9f8bf8835d3dbeb9644bd67f385fa..4a2c88f54a701111a5b853b4772835470c9d25c0 100644 (file)
@@ -681,3 +681,58 @@ void SCENE_OT_render_layer_remove(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
+static int texture_slot_move(bContext *C, wmOperator *op)
+{
+       ID *id= CTX_data_pointer_get_type(C, "texture_slot", &RNA_TextureSlot).id.data;
+
+       if(id) {
+               MTex **mtex_ar, *mtexswap;
+               short act;
+               int type= RNA_enum_get(op->ptr, "type");
+
+               give_active_mtex(id, &mtex_ar, &act);
+
+               if(type == -1) { /* Up */
+                       if(act > 0) {
+                               mtexswap = mtex_ar[act];
+                               mtex_ar[act] = mtex_ar[act-1];
+                               mtex_ar[act-1] = mtexswap;
+                               set_active_mtex(id, act-1);
+                       }
+               }
+               else { /* Down */
+                       if(act < MAX_MTEX-1) {
+                               mtexswap = mtex_ar[act];
+                               mtex_ar[act] = mtex_ar[act+1];
+                               mtex_ar[act+1] = mtexswap;
+                               set_active_mtex(id, act+1);
+                       }
+               }
+
+               WM_event_add_notifier(C, NC_TEXTURE, CTX_data_scene(C));
+       }
+
+       return OPERATOR_FINISHED;
+}
+
+void TEXTURE_OT_slot_move(wmOperatorType *ot)
+{
+       static EnumPropertyItem slot_move[] = {
+               {-1, "UP", 0, "Up", ""},
+               {1, "DOWN", 0, "Down", ""},
+               {0, NULL, 0, NULL, NULL}
+       };
+
+       /* identifiers */
+       ot->name= "Move Texture Slot";
+       ot->idname= "TEXTURE_OT_slot_move";
+       ot->description="Move texture slots up and down.";
+
+       /* api callbacks */
+       ot->exec= texture_slot_move;
+
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+       RNA_def_enum(ot->srna, "type", slot_move, 0, "Type", "");
+}