diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-03-09 12:17:45 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-03-09 12:17:45 +0300 |
commit | b7a73f9e5b74062d4498a5061281c0d0af9fb026 (patch) | |
tree | 1175ff8ca1cff5bd90d5449d7014b4f32c454780 | |
parent | 6a4b39ed2ce9e44139e91a4daab9ccf6caff0375 (diff) |
mtex buffer copy & paste back for materials.
-rw-r--r-- | release/scripts/ui/properties_texture.py | 13 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_material.h | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/material.c | 70 | ||||
-rw-r--r-- | source/blender/editors/render/render_intern.h | 3 | ||||
-rw-r--r-- | source/blender/editors/render/render_ops.c | 3 | ||||
-rw-r--r-- | source/blender/editors/render/render_shading.c | 56 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_init_exit.c | 6 |
7 files changed, 153 insertions, 2 deletions
diff --git a/release/scripts/ui/properties_texture.py b/release/scripts/ui/properties_texture.py index 8794b19bd4d..de42cdef040 100644 --- a/release/scripts/ui/properties_texture.py +++ b/release/scripts/ui/properties_texture.py @@ -23,6 +23,16 @@ from rna_prop_ui import PropertyPanel narrowui = 180 +class TEXTURE_MT_specials(bpy.types.Menu): + bl_label = "Texture Specials" + + def draw(self, context): + layout = self.layout + + layout.operator("material.mtex_copy", icon='COPYDOWN') + layout.operator("material.mtex_paste", icon='PASTEDOWN') + + def active_node_mat(mat): if mat: mat_node = mat.active_node_material @@ -103,6 +113,7 @@ class TEXTURE_PT_context_texture(TextureButtonsPanel): col = row.column(align=True) col.operator("texture.slot_move", text="", icon='TRIA_UP').type = 'UP' col.operator("texture.slot_move", text="", icon='TRIA_DOWN').type = 'DOWN' + col.menu("TEXTURE_MT_specials", icon='DOWNARROW_HLT', text="") if wide_ui: split = layout.split(percentage=0.65) @@ -958,6 +969,8 @@ class TEXTURE_PT_pointdensity_turbulence(TextureButtonsPanel): classes = [ + TEXTURE_MT_specials, + TEXTURE_PT_context_texture, TEXTURE_PT_preview, diff --git a/source/blender/blenkernel/BKE_material.h b/source/blender/blenkernel/BKE_material.h index 7ec5d172130..07ca5a1c0ee 100644 --- a/source/blender/blenkernel/BKE_material.h +++ b/source/blender/blenkernel/BKE_material.h @@ -83,6 +83,10 @@ void free_matcopybuf(void); void copy_matcopybuf(struct Material *ma); void paste_matcopybuf(struct Material *ma); +void clear_mat_mtex_copybuf(void); +void copy_mat_mtex_copybuf(struct ID *id); +void paste_mat_mtex_copybuf(struct ID *id); + #ifdef __cplusplus } #endif diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index 27b46c40d28..05f0f20feff 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -1247,6 +1247,7 @@ static short matcopied=0; void clear_matcopybuf(void) { memset(&matcopybuf, 0, sizeof(Material)); + matcopied= 0; } void free_matcopybuf(void) @@ -1273,6 +1274,8 @@ void free_matcopybuf(void) matcopybuf.nodetree= NULL; } // default_mtex(&mtexcopybuf); + + matcopied= 0; } void copy_matcopybuf(Material *ma) @@ -1346,3 +1349,70 @@ void paste_matcopybuf(Material *ma) scrarea_queue_winredraw(curarea); */ } + + +static short mtexcopied=0; /* must be reset on file load */ +static MTex mtexcopybuf; + +void clear_mat_mtex_copybuf(void) +{ /* use for file reload */ + mtexcopied= 0; +} + +void copy_mat_mtex_copybuf(ID *id) +{ + MTex **mtex= NULL; + + switch(GS(id->name)) { + case ID_MA: + mtex= &(((Material *)id)->mtex[(int)((Material *)id)->texact]); + break; + case ID_LA: + // la->mtex[(int)la->texact] // TODO + break; + case ID_WO: + // mtex= wrld->mtex[(int)wrld->texact]; // TODO + break; + } + + if(mtex && *mtex) { + memcpy(&mtexcopybuf, *mtex, sizeof(MTex)); + mtexcopied= 1; + } + else { + mtexcopied= 0; + } +} + +void paste_mat_mtex_copybuf(ID *id) +{ + MTex **mtex= NULL; + + if(mtexcopied == 0 || mtexcopybuf.tex==NULL) + return; + + switch(GS(id->name)) { + case ID_MA: + mtex= &(((Material *)id)->mtex[(int)((Material *)id)->texact]); + break; + case ID_LA: + // la->mtex[(int)la->texact] // TODO + break; + case ID_WO: + // mtex= wrld->mtex[(int)wrld->texact]; // TODO + break; + } + + if(mtex) { + if(*mtex==NULL) { + *mtex= MEM_mallocN(sizeof(MTex), "mtex copy"); + } + else if((*mtex)->tex) { + (*mtex)->tex->id.us--; + } + + memcpy(*mtex, &mtexcopybuf, sizeof(MTex)); + + id_us_plus((ID *)mtexcopybuf.tex); + } +} diff --git a/source/blender/editors/render/render_intern.h b/source/blender/editors/render/render_intern.h index cb72182dff9..cb1f143d826 100644 --- a/source/blender/editors/render/render_intern.h +++ b/source/blender/editors/render/render_intern.h @@ -48,6 +48,9 @@ void WORLD_OT_new(struct wmOperatorType *ot); void MATERIAL_OT_copy(struct wmOperatorType *ot); void MATERIAL_OT_paste(struct wmOperatorType *ot); +void MATERIAL_OT_mtex_copy(struct wmOperatorType *ot); +void MATERIAL_OT_mtex_paste(struct wmOperatorType *ot); + void SCENE_OT_render_layer_add(struct wmOperatorType *ot); void SCENE_OT_render_layer_remove(struct wmOperatorType *ot); diff --git a/source/blender/editors/render/render_ops.c b/source/blender/editors/render/render_ops.c index e23531d3c8f..9dc442665fb 100644 --- a/source/blender/editors/render/render_ops.c +++ b/source/blender/editors/render/render_ops.c @@ -55,6 +55,9 @@ void ED_operatortypes_render(void) WM_operatortype_append(MATERIAL_OT_copy); WM_operatortype_append(MATERIAL_OT_paste); + + WM_operatortype_append(MATERIAL_OT_mtex_copy); + WM_operatortype_append(MATERIAL_OT_mtex_paste); WM_operatortype_append(SCENE_OT_render_layer_add); WM_operatortype_append(SCENE_OT_render_layer_remove); diff --git a/source/blender/editors/render/render_shading.c b/source/blender/editors/render/render_shading.c index 21e3b55ba0f..7eeff31141b 100644 --- a/source/blender/editors/render/render_shading.c +++ b/source/blender/editors/render/render_shading.c @@ -820,3 +820,59 @@ void MATERIAL_OT_paste(wmOperatorType *ot) /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } + +static int copy_material_mtex_exec(bContext *C, wmOperator *op) +{ + Material *ma= CTX_data_pointer_get_type(C, "material", &RNA_Material).data; + + if(ma==NULL) + return OPERATOR_CANCELLED; + + copy_mat_mtex_copybuf(&ma->id); + + WM_event_add_notifier(C, NC_MATERIAL, ma); + + return OPERATOR_FINISHED; +} + +void MATERIAL_OT_mtex_copy(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Copy Material Texture Settings"; + ot->idname= "MATERIAL_OT_mtex_copy"; + ot->description="Copy the material texture settings and nodes"; + + /* api callbacks */ + ot->exec= copy_material_mtex_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + +static int paste_material_mtex_exec(bContext *C, wmOperator *op) +{ + Material *ma= CTX_data_pointer_get_type(C, "material", &RNA_Material).data; + + if(ma==NULL) + return OPERATOR_CANCELLED; + + paste_mat_mtex_copybuf(&ma->id); + + WM_event_add_notifier(C, NC_MATERIAL|ND_SHADING_DRAW, ma); + + return OPERATOR_FINISHED; +} + +void MATERIAL_OT_mtex_paste(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Paste Material Texture Settings"; + ot->idname= "MATERIAL_OT_mtex_paste"; + ot->description="Copy the material texture settings and nodes"; + + /* api callbacks */ + ot->exec= paste_material_mtex_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c index 449c586c178..f825bb28547 100644 --- a/source/blender/windowmanager/intern/wm_init_exit.c +++ b/source/blender/windowmanager/intern/wm_init_exit.c @@ -54,6 +54,7 @@ #include "BKE_utildefines.h" #include "BKE_packedFile.h" #include "BKE_sequencer.h" /* free seq clipboard */ +#include "BKE_material.h" /* clear_matcopybuf */ #include "BLI_blenlib.h" @@ -154,8 +155,9 @@ void WM_init(bContext *C, int argc, char **argv) UI_init(); } - // clear_matcopybuf(); /* XXX */ - + clear_matcopybuf(); + clear_mat_mtex_copybuf(); + // glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); // init_node_butfuncs(); |