diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-06-07 17:36:12 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-06-07 17:36:12 +0400 |
commit | eecf7722b635545f0f5c51b74a15418e3cc9f47e (patch) | |
tree | 9d74c4603411f4aa6d527d229d2ea05220f81aec /source/blender/editors | |
parent | 0a9dea9d7d2db373b47395d4b5d564e559da5229 (diff) |
UI Buttons:
* Context now allows pinning a datablock, independent of
selection.
* Initial ID browse buttons for most buttons tabs.
* Browsing from world to texture now displays world textures
again, but is a bit of a hack, not sure there is a right
way to do this.
* There's a button to switch between active materials and
textures now, only temporary though.
* There's some code to put context part in own region,
disabled still because it doesn't work that well yet.
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/space_buttons/buttons_context.c | 324 | ||||
-rw-r--r-- | source/blender/editors/space_buttons/buttons_header.c | 102 | ||||
-rw-r--r-- | source/blender/editors/space_buttons/buttons_intern.h | 11 | ||||
-rw-r--r-- | source/blender/editors/space_buttons/buttons_ops.c | 194 | ||||
-rw-r--r-- | source/blender/editors/space_buttons/space_buttons.c | 81 | ||||
-rw-r--r-- | source/blender/editors/space_image/image_header.c | 9 |
6 files changed, 560 insertions, 161 deletions
diff --git a/source/blender/editors/space_buttons/buttons_context.c b/source/blender/editors/space_buttons/buttons_context.c index 17b8a5a39bb..d3653efd9f2 100644 --- a/source/blender/editors/space_buttons/buttons_context.c +++ b/source/blender/editors/space_buttons/buttons_context.c @@ -50,9 +50,12 @@ #include "BKE_particle.h" #include "BKE_screen.h" #include "BKE_utildefines.h" +#include "BKE_world.h" #include "RNA_access.h" +#include "ED_screen.h" + #include "UI_interface.h" #include "UI_resources.h" @@ -61,8 +64,41 @@ typedef struct ButsContextPath { PointerRNA ptr[8]; int len; + int worldtex; } ButsContextPath; +static int set_pointer_type(ButsContextPath *path, bContextDataResult *result, StructRNA *type) +{ + PointerRNA *ptr; + int a; + + for(a=0; a<path->len; a++) { + ptr= &path->ptr[a]; + + if(RNA_struct_is_a(ptr->type, type)) { + CTX_data_pointer_set(result, ptr->id.data, ptr->type, ptr->data); + return 1; + } + } + + return 0; +} + +static PointerRNA *get_pointer_type(ButsContextPath *path, StructRNA *type) +{ + PointerRNA *ptr; + int a; + + for(a=0; a<path->len; a++) { + ptr= &path->ptr[a]; + + if(RNA_struct_is_a(ptr->type, type)) + return ptr; + } + + return NULL; +} + /************************* Creating the Path ************************/ static int buttons_context_path_scene(ButsContextPath *path) @@ -99,12 +135,19 @@ static int buttons_context_path_world(ButsContextPath *path) // XXX - place holder, need to get this working static int buttons_context_path_sequencer(ButsContextPath *path) { - PointerRNA *ptr= &path->ptr[path->len-1]; + Scene *scene; - /* this one just verifies */ - return RNA_struct_is_a(ptr->type, &RNA_Scene); -} + if(buttons_context_path_scene(path)) { + scene= path->ptr[path->len-1].data; + RNA_pointer_create(&scene->id, &RNA_SequenceEditor, scene->ed, &path->ptr[path->len]); + path->len++; + + return 1; + } + + return 0; +} static int buttons_context_path_object(ButsContextPath *path) { @@ -136,12 +179,21 @@ static int buttons_context_path_object(ButsContextPath *path) static int buttons_context_path_data(ButsContextPath *path, int type) { Object *ob; + PointerRNA *ptr= &path->ptr[path->len-1]; + /* if we already have a data, we're done */ + if(RNA_struct_is_a(ptr->type, &RNA_Mesh) && (type == -1 || type == OB_MESH)) return 1; + else if(RNA_struct_is_a(ptr->type, &RNA_Curve) && (type == -1 || ELEM3(type, OB_CURVE, OB_SURF, OB_FONT))) return 1; + else if(RNA_struct_is_a(ptr->type, &RNA_Armature) && (type == -1 || type == OB_ARMATURE)) return 1; + else if(RNA_struct_is_a(ptr->type, &RNA_MetaBall) && (type == -1 || type == OB_MBALL)) return 1; + else if(RNA_struct_is_a(ptr->type, &RNA_Lattice) && (type == -1 || type == OB_LATTICE)) return 1; + else if(RNA_struct_is_a(ptr->type, &RNA_Camera) && (type == -1 || type == OB_CAMERA)) return 1; + else if(RNA_struct_is_a(ptr->type, &RNA_Lamp) && (type == -1 || type == OB_LAMP)) return 1; /* try to get an object in the path, no pinning supported here */ - if(buttons_context_path_object(path)) { + else if(buttons_context_path_object(path)) { ob= path->ptr[path->len-1].data; - if(type == -1 || type == ob->type) { + if(ob && (type == -1 || type == ob->type)) { RNA_id_pointer_create(ob->data, &path->ptr[path->len]); path->len++; @@ -153,10 +205,25 @@ static int buttons_context_path_data(ButsContextPath *path, int type) return 0; } +static int buttons_context_path_modifier(ButsContextPath *path) +{ + Object *ob; + + if(buttons_context_path_object(path)) { + ob= path->ptr[path->len-1].data; + + if(ob && ELEM4(ob->type, OB_MESH, OB_CURVE, OB_FONT, OB_SURF)) + return 1; + } + + return 0; +} + static int buttons_context_path_material(ButsContextPath *path) { Object *ob; PointerRNA *ptr= &path->ptr[path->len-1]; + Material *ma; /* if we already have a (pinned) material, we're done */ if(RNA_struct_is_a(ptr->type, &RNA_Material)) { @@ -167,7 +234,8 @@ static int buttons_context_path_material(ButsContextPath *path) ob= path->ptr[path->len-1].data; if(ob && ob->type && (ob->type<OB_LAMP)) { - RNA_pointer_create(&ob->id, &RNA_MaterialSlot, ob->mat+ob->actcol-1, &path->ptr[path->len]); + ma= give_current_material(ob, ob->actcol); + RNA_id_pointer_create(&ma->id, &path->ptr[path->len]); path->len++; return 1; } @@ -222,11 +290,14 @@ static int buttons_context_path_particle(ButsContextPath *path) /* if we have an object, get the active particle system */ if(buttons_context_path_object(path)) { ob= path->ptr[path->len-1].data; - psys= psys_get_current(ob); - RNA_pointer_create(&ob->id, &RNA_ParticleSystem, psys, &path->ptr[path->len]); - path->len++; - return 1; + if(ob && ob->type == OB_MESH) { + psys= psys_get_current(ob); + + RNA_pointer_create(&ob->id, &RNA_ParticleSystem, psys, &path->ptr[path->len]); + path->len++; + return 1; + } } /* no path to a particle system possible */ @@ -235,58 +306,70 @@ static int buttons_context_path_particle(ButsContextPath *path) static int buttons_context_path_texture(ButsContextPath *path) { - Object *ob; - Lamp *la; Material *ma; + Lamp *la; + World *wo; + MTex *mtex; + Tex *tex; PointerRNA *ptr= &path->ptr[path->len-1]; /* if we already have a (pinned) texture, we're done */ if(RNA_struct_is_a(ptr->type, &RNA_Texture)) { return 1; } - /* try to get the active material */ - else if(buttons_context_path_material(path)) { - ptr= &path->ptr[path->len-1]; + /* try world */ + else if(path->worldtex && buttons_context_path_world(path)) { + wo= path->ptr[path->len-1].data; - if(RNA_struct_is_a(ptr->type, &RNA_Material)) { - ma= ptr->data; - } - else if(RNA_struct_is_a(ptr->type, &RNA_MaterialSlot)) { - ob= ptr->id.data; - ma= give_current_material(ob, (Material**)ptr->data - ob->mat); + if(wo) { + mtex= wo->mtex[(int)wo->texact]; + tex= (mtex)? mtex->tex: NULL; + + RNA_id_pointer_create(&tex->id, &path->ptr[path->len]); + path->len++; + return 1; } - else - ma= NULL; + } + /* try material */ + else if(buttons_context_path_material(path)) { + ma= path->ptr[path->len-1].data; if(ma) { - RNA_pointer_create(&ma->id, &RNA_TextureSlot, ma->mtex[(int)ma->texact], &path->ptr[path->len]); + mtex= ma->mtex[(int)ma->texact]; + tex= (mtex)? mtex->tex: NULL; + + RNA_id_pointer_create(&tex->id, &path->ptr[path->len]); path->len++; return 1; } } - /* try to get the active lamp */ + /* try lamp */ else if(buttons_context_path_data(path, OB_LAMP)) { la= path->ptr[path->len-1].data; if(la) { - RNA_pointer_create(&la->id, &RNA_TextureSlot, la->mtex[(int)la->texact], &path->ptr[path->len]); + mtex= la->mtex[(int)la->texact]; + tex= (mtex)? mtex->tex: NULL; + + RNA_id_pointer_create(&tex->id, &path->ptr[path->len]); path->len++; return 1; } } - /* TODO: world, brush */ + /* TODO: material nodes, brush */ /* no path to a particle system possible */ return 0; } -static int buttons_context_path(const bContext *C, ButsContextPath *path) +static int buttons_context_path(const bContext *C, ButsContextPath *path, int mainb, int worldtex) { SpaceButs *sbuts= (SpaceButs*)CTX_wm_space_data(C); ID *id; int found; memset(path, 0, sizeof(*path)); + path->worldtex= worldtex; /* if some ID datablock is pinned, set the root pointer */ if(sbuts->pinid) { @@ -305,7 +388,7 @@ static int buttons_context_path(const bContext *C, ButsContextPath *path) /* now for each buttons context type, we try to construct a path, * tracing back recursively */ - switch(sbuts->mainb) { + switch(mainb) { case BCONTEXT_SCENE: found= buttons_context_path_scene(path); break; @@ -318,9 +401,11 @@ static int buttons_context_path(const bContext *C, ButsContextPath *path) case BCONTEXT_OBJECT: case BCONTEXT_PHYSICS: case BCONTEXT_CONSTRAINT: - case BCONTEXT_MODIFIER: found= buttons_context_path_object(path); break; + case BCONTEXT_MODIFIER: + found= buttons_context_path_modifier(path); + break; case BCONTEXT_DATA: found= buttons_context_path_data(path, -1); break; @@ -346,46 +431,63 @@ static int buttons_context_path(const bContext *C, ButsContextPath *path) void buttons_context_compute(const bContext *C, SpaceButs *sbuts) { + ButsContextPath *path; + PointerRNA *ptr; + int a, worldtex, flag= 0; + if(!sbuts->path) sbuts->path= MEM_callocN(sizeof(ButsContextPath), "ButsContextPath"); - buttons_context_path(C, sbuts->path); -} - -/************************* Context Callback ************************/ - -static int set_pointer_type(ButsContextPath *path, bContextDataResult *result, StructRNA *type) -{ - PointerRNA *ptr; - int a; - - for(a=0; a<path->len; a++) { - ptr= &path->ptr[a]; - - if(RNA_struct_is_a(ptr->type, type)) { - CTX_data_pointer_set(result, ptr->id.data, ptr->type, ptr->data); - return 1; + path= sbuts->path; + worldtex= (sbuts->flag & SB_WORLD_TEX); + + /* for each context, see if we can compute a valid path to it, if + * this is the case, we know we have to display the button */ + for(a=0; a<BCONTEXT_TOT; a++) { + if(buttons_context_path(C, path, a, worldtex)) { + flag |= (1<<a); + + /* setting icon for data context */ + if(a == BCONTEXT_DATA) { + ptr= &path->ptr[path->len-1]; + + if(ptr->type) + sbuts->dataicon= RNA_struct_ui_icon(ptr->type); + else + sbuts->dataicon= ICON_EMPTY_DATA; + } } } - return 0; -} - -static PointerRNA *get_pointer_type(ButsContextPath *path, StructRNA *type) -{ - PointerRNA *ptr; - int a; + /* in case something becomes invalid, change */ + if((flag & (1 << sbuts->mainb)) == 0) { + if(flag & BCONTEXT_OBJECT) { + sbuts->mainb= BCONTEXT_OBJECT; + } + else { + for(a=0; a<BCONTEXT_TOT; a++) { + if(flag & (1 << a)) { + sbuts->mainb= a; + break; + } + } + } + } - for(a=0; a<path->len; a++) { - ptr= &path->ptr[a]; + buttons_context_path(C, path, sbuts->mainb, worldtex); - if(RNA_struct_is_a(ptr->type, type)) - return ptr; + if(!(flag & (1 << sbuts->mainb))) { + if(flag & (1 << BCONTEXT_OBJECT)) + sbuts->mainb= BCONTEXT_OBJECT; + else + sbuts->mainb= BCONTEXT_SCENE; } - return NULL; + sbuts->pathflag= flag; } +/************************* Context Callback ************************/ + int buttons_context(const bContext *C, const char *member, bContextDataResult *result) { SpaceButs *sbuts= (SpaceButs*)CTX_wm_space_data(C); @@ -433,34 +535,53 @@ int buttons_context(const bContext *C, const char *member, bContextDataResult *r return 1; } else if(CTX_data_equals(member, "material")) { - if(!set_pointer_type(path, result, &RNA_Material)) { - PointerRNA *ptr= get_pointer_type(path, &RNA_MaterialSlot); - - if(ptr && ptr->data) { - Object *ob= ptr->id.data; - Material *ma= give_current_material(ob, (Material**)ptr->data - ob->mat); - CTX_data_id_pointer_set(result, &ma->id); - } - } - + set_pointer_type(path, result, &RNA_Material); return 1; } else if(CTX_data_equals(member, "texture")) { - if(!set_pointer_type(path, result, &RNA_Texture)) { - PointerRNA *ptr= get_pointer_type(path, &RNA_TextureSlot); - - if(ptr && ptr->data) - CTX_data_id_pointer_set(result, &((MTex*)ptr->data)->tex->id); - } - + set_pointer_type(path, result, &RNA_Texture); return 1; } else if(CTX_data_equals(member, "material_slot")) { - set_pointer_type(path, result, &RNA_MaterialSlot); + PointerRNA *ptr= get_pointer_type(path, &RNA_Object); + + if(ptr) { + Object *ob= ptr->data; + + if(ob && ob->type && (ob->type<OB_LAMP)) + CTX_data_pointer_set(result, &ob->id, &RNA_MaterialSlot, ob->mat+ob->actcol-1); + } + return 1; } else if(CTX_data_equals(member, "texture_slot")) { - set_pointer_type(path, result, &RNA_TextureSlot); + PointerRNA *ptr; + + if((ptr=get_pointer_type(path, &RNA_Material))) { + Material *ma= ptr->data; + + if(ma) + CTX_data_pointer_set(result, &ma->id, &RNA_TextureSlot, ma->mtex[(int)ma->texact]); + } + else if((ptr=get_pointer_type(path, &RNA_Lamp))) { + Lamp *la= ptr->data; + + if(la) + CTX_data_pointer_set(result, &la->id, &RNA_TextureSlot, la->mtex[(int)la->texact]); + } + else if((ptr=get_pointer_type(path, &RNA_World))) { + World *wo= ptr->data; + + if(wo) + CTX_data_pointer_set(result, &wo->id, &RNA_TextureSlot, wo->mtex[(int)wo->texact]); + } + else if((ptr=get_pointer_type(path, &RNA_Brush))) { /* how to get this into context? */ + Brush *br= ptr->data; + + if(br) + CTX_data_pointer_set(result, &br->id, &RNA_TextureSlot, br->mtex[(int)br->texact]); + } + return 1; } else if(CTX_data_equals(member, "bone")) { @@ -500,11 +621,38 @@ int buttons_context(const bContext *C, const char *member, bContextDataResult *r /************************* Drawing the Path ************************/ -static void buttons_panel_context(const bContext *C, Panel *pa) +static void pin_cb(bContext *C, void *arg1, void *arg2) +{ + SpaceButs *sbuts= (SpaceButs*)CTX_wm_space_data(C); + ButsContextPath *path= sbuts->path; + PointerRNA *ptr; + int a; + + if(sbuts->flag & SB_PIN_CONTEXT) { + if(path->len) { + for(a=path->len-1; a>=0; a--) { + ptr= &path->ptr[a]; + + if(ptr->id.data) { + sbuts->pinid= ptr->id.data; + break; + } + } + } + } + else + sbuts->pinid= NULL; + + ED_area_tag_redraw(CTX_wm_area(C)); +} + +void buttons_context_draw(const bContext *C, uiLayout *layout) { SpaceButs *sbuts= (SpaceButs*)CTX_wm_space_data(C); ButsContextPath *path= sbuts->path; uiLayout *row; + uiBlock *block; + uiBut *but; PointerRNA *ptr; PropertyRNA *nameprop; char namebuf[128], *name; @@ -513,9 +661,14 @@ static void buttons_panel_context(const bContext *C, Panel *pa) if(!path) return; - row= uiLayoutRow(pa->layout, 0); + row= uiLayoutRow(layout, 0); uiLayoutSetAlignment(row, UI_LAYOUT_ALIGN_LEFT); + block= uiLayoutGetBlock(row); + uiBlockSetEmboss(block, UI_EMBOSSN); + but= uiDefIconButBitC(block, ICONTOG, SB_PIN_CONTEXT, 0, (sbuts->flag & SB_PIN_CONTEXT)? ICON_PINNED: ICON_UNPINNED, 0, 0, UI_UNIT_X, UI_UNIT_Y, &sbuts->flag, 0, 0, 0, 0, "Follow context or keep fixed datablock displayed."); + uiButSetFunc(but, pin_cb, NULL, NULL); + for(a=0; a<path->len; a++) { ptr= &path->ptr[a]; @@ -523,6 +676,12 @@ static void buttons_panel_context(const bContext *C, Panel *pa) icon= RNA_struct_ui_icon(ptr->type); nameprop= RNA_struct_name_property(ptr->type); +#if 0 + if(sbuts->mainb != BCONTEXT_SCENE && ptr->type == &RNA_Scene) { + uiItemL(row, "", icon); /* save some space */ + } + else +#endif if(nameprop) { name= RNA_property_string_get_alloc(ptr, nameprop, namebuf, sizeof(namebuf)); @@ -537,6 +696,11 @@ static void buttons_panel_context(const bContext *C, Panel *pa) } } +static void buttons_panel_context(const bContext *C, Panel *pa) +{ + buttons_context_draw(C, pa->layout); +} + void buttons_context_register(ARegionType *art) { PanelType *pt; diff --git a/source/blender/editors/space_buttons/buttons_header.c b/source/blender/editors/space_buttons/buttons_header.c index 444db92265d..73f161e1130 100644 --- a/source/blender/editors/space_buttons/buttons_header.c +++ b/source/blender/editors/space_buttons/buttons_header.c @@ -114,6 +114,8 @@ static uiBlock *dummy_viewmenu(bContext *C, ARegion *ar, void *arg_unused) static void do_buttons_buttons(bContext *C, void *arg, int event) { + SpaceButs *sbuts= (SpaceButs*)CTX_wm_space_data(C); + switch(event) { case B_NEWFRAME: WM_event_add_notifier(C, NC_SCENE|ND_FRAME, NULL); @@ -121,18 +123,25 @@ static void do_buttons_buttons(bContext *C, void *arg, int event) case B_CONTEXT_SWITCH: case B_BUTSPREVIEW: ED_area_tag_redraw(CTX_wm_area(C)); + + /* silly exception */ + if(sbuts->mainb == BCONTEXT_WORLD) + sbuts->flag |= SB_WORLD_TEX; + else if(sbuts->mainb != BCONTEXT_TEXTURE) + sbuts->flag &= ~SB_WORLD_TEX; + break; } } - void buttons_header_buttons(const bContext *C, ARegion *ar) { ScrArea *sa= CTX_wm_area(C); SpaceButs *sbuts= (SpaceButs*)CTX_wm_space_data(C); - Object *ob= CTX_data_active_object(C); uiBlock *block; - int xco, yco= 3, dataicon= ICON_OBJECT_DATA; + int xco, yco= 3; + + buttons_context_compute(C, sbuts); block= uiBeginBlock(C, ar, "header buttons", UI_EMBOSS); uiBlockSetHandleFunc(block, do_buttons_buttons, NULL); @@ -148,70 +157,38 @@ void buttons_header_buttons(const bContext *C, ARegion *ar) xco+=xmax; } - // DATA Icons - if(ob) { - switch(ob->type) { - case OB_EMPTY: dataicon= ICON_EMPTY_DATA; break; - case OB_MESH: dataicon= ICON_MESH_DATA; break; - case OB_CURVE: dataicon= ICON_CURVE_DATA; break; - case OB_SURF: dataicon= ICON_SURFACE_DATA; break; - case OB_FONT: dataicon= ICON_FONT_DATA; break; - case OB_MBALL: dataicon= ICON_META_DATA; break; - case OB_LAMP: dataicon= ICON_LAMP_DATA; break; - case OB_CAMERA: dataicon= ICON_CAMERA_DATA; break; - case OB_LATTICE: dataicon= ICON_LATTICE_DATA; break; - case OB_ARMATURE: dataicon= ICON_ARMATURE_DATA; break; - default: break; - } - } uiBlockSetEmboss(block, UI_EMBOSS); - // if object selection changed, validate button selection - if(ob && (ob->type == OB_LAMP) && ELEM3(sbuts->mainb, (float)BCONTEXT_MATERIAL, (float)BCONTEXT_PARTICLE, (float)BCONTEXT_PHYSICS)) - sbuts->mainb = (float)BCONTEXT_DATA; - - if(ob && (ob->type == OB_EMPTY) && ELEM3(sbuts->mainb, (float)BCONTEXT_MATERIAL, (float)BCONTEXT_TEXTURE, (float)BCONTEXT_PARTICLE)) - sbuts->mainb = (float)BCONTEXT_DATA; - - if((ob && ELEM(ob->type, OB_CAMERA, OB_ARMATURE)) && ELEM4(sbuts->mainb, (float)BCONTEXT_MATERIAL, (float)BCONTEXT_TEXTURE, (float)BCONTEXT_PARTICLE, (float)BCONTEXT_PHYSICS)) - sbuts->mainb = (float)BCONTEXT_DATA; - - if((ob && (ob->type != OB_ARMATURE)) && (sbuts->mainb == (float)BCONTEXT_BONE)) - sbuts->mainb = (float)BCONTEXT_DATA; - - if(!ob && !ELEM3(sbuts->mainb, (float)BCONTEXT_SCENE, (float)BCONTEXT_WORLD, (float)BCONTEXT_SEQUENCER)) - sbuts->mainb = (float)BCONTEXT_WORLD; - - if((ob && ELEM5(ob->type, OB_EMPTY, OB_MBALL, OB_LAMP, OB_CAMERA, OB_ARMATURE)) && (sbuts->mainb == (float) BCONTEXT_MODIFIER)) - sbuts->mainb = (float)BCONTEXT_DATA; + xco -= XIC; // Default panels uiBlockBeginAlign(block); - uiDefIconButS(block, ROW, B_CONTEXT_SWITCH, ICON_SCENE, xco, yco, XIC, YIC, &(sbuts->mainb), 0.0, (float)BCONTEXT_SCENE, 0, 0, "Scene"); - uiDefIconButS(block, ROW, B_CONTEXT_SWITCH, ICON_WORLD, xco+=XIC, yco, XIC, YIC, &(sbuts->mainb), 0.0, (float)BCONTEXT_WORLD, 0, 0, "World"); - uiDefIconButS(block, ROW, B_CONTEXT_SWITCH, ICON_SEQUENCE, xco+=XIC, yco, XIC, YIC, &(sbuts->mainb), 0.0, (float)BCONTEXT_SEQUENCER, 0, 0, "Sequencer"); - - // Specific panels, check on active object seletion - if(ob) { + if(sbuts->pathflag & (1<<BCONTEXT_SCENE)) + uiDefIconButS(block, ROW, B_CONTEXT_SWITCH, ICON_SCENE, xco+=XIC, yco, XIC, YIC, &(sbuts->mainb), 0.0, (float)BCONTEXT_SCENE, 0, 0, "Scene"); + if(sbuts->pathflag & (1<<BCONTEXT_WORLD)) + uiDefIconButS(block, ROW, B_CONTEXT_SWITCH, ICON_WORLD, xco+=XIC, yco, XIC, YIC, &(sbuts->mainb), 0.0, (float)BCONTEXT_WORLD, 0, 0, "World"); + if(sbuts->pathflag & (1<<BCONTEXT_SEQUENCER)) + uiDefIconButS(block, ROW, B_CONTEXT_SWITCH, ICON_SEQUENCE, xco+=XIC, yco, XIC, YIC, &(sbuts->mainb), 0.0, (float)BCONTEXT_SEQUENCER, 0, 0, "Sequencer"); + if(sbuts->pathflag & (1<<BCONTEXT_OBJECT)) uiDefIconButS(block, ROW, B_CONTEXT_SWITCH, ICON_OBJECT_DATA, xco+=XIC, yco, XIC, YIC, &(sbuts->mainb), 0.0, (float)BCONTEXT_OBJECT, 0, 0, "Object"); - uiDefIconButS(block, ROW, B_CONTEXT_SWITCH, ICON_CONSTRAINT, xco+=XIC, yco, XIC, YIC, &(sbuts->mainb), 0.0, (float)BCONTEXT_CONSTRAINT, 0, 0, "Constraint"); - - if(ELEM5(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_LATTICE)) - uiDefIconButS(block, ROW, B_CONTEXT_SWITCH, ICON_MODIFIER, xco+=XIC, yco, XIC, YIC, &(sbuts->mainb), 0.0, (float)BCONTEXT_MODIFIER, 0, 0, "Modifier"); - - uiDefIconButS(block, ROW, B_CONTEXT_SWITCH, dataicon, xco+=XIC, yco, XIC, YIC, &(sbuts->mainb), 0.0, (float)BCONTEXT_DATA, 0, 0, "Object Data"); - if((ob->type == OB_ARMATURE)) - uiDefIconButS(block, ROW, B_CONTEXT_SWITCH, ICON_BONE_DATA, xco+=XIC, yco, XIC, YIC, &(sbuts->mainb), 0.0, (float)BCONTEXT_BONE, 0, 0, "Bone"); - if(ELEM5(ob->type, OB_MESH, OB_SURF, OB_MBALL, OB_CURVE, OB_FONT)) - uiDefIconButS(block, ROW, B_BUTSPREVIEW, ICON_MATERIAL, xco+=XIC, yco, XIC, YIC, &(sbuts->mainb), 0.0, (float)BCONTEXT_MATERIAL, 0, 0, "Material"); - if(ELEM6(ob->type, OB_MESH, OB_SURF, OB_MBALL, OB_CURVE, OB_FONT, OB_LAMP)) - uiDefIconButS(block, ROW, B_BUTSPREVIEW, ICON_TEXTURE, xco+=XIC, yco, XIC, YIC, &(sbuts->mainb), 0.0, (float)BCONTEXT_TEXTURE, 0, 0, "Texture"); - if(ELEM5(ob->type, OB_MESH, OB_SURF, OB_MBALL, OB_CURVE, OB_FONT)) - uiDefIconButS(block, ROW, B_CONTEXT_SWITCH, ICON_PARTICLES, xco+=XIC, yco, XIC, YIC, &(sbuts->mainb), 0.0, (float)BCONTEXT_PARTICLE, 0, 0, "Particles"); - if(ELEM6(ob->type, OB_MESH, OB_SURF, OB_MBALL, OB_CURVE, OB_FONT, OB_EMPTY)) - uiDefIconButS(block, ROW, B_CONTEXT_SWITCH, ICON_PHYSICS, xco+=XIC, yco, XIC, YIC, &(sbuts->mainb), 0.0, (float)BCONTEXT_PHYSICS, 0, 0, "Physics"); - } + if(sbuts->pathflag & (1<<BCONTEXT_CONSTRAINT)) + uiDefIconButS(block, ROW, B_CONTEXT_SWITCH, ICON_CONSTRAINT, xco+=XIC, yco, XIC, YIC, &(sbuts->mainb), 0.0, (float)BCONTEXT_CONSTRAINT, 0, 0, "Modifier"); + if(sbuts->pathflag & (1<<BCONTEXT_DATA)) + uiDefIconButS(block, ROW, B_CONTEXT_SWITCH, sbuts->dataicon, xco+=XIC, yco, XIC, YIC, &(sbuts->mainb), 0.0, (float)BCONTEXT_DATA, 0, 0, "Object Data"); + if(sbuts->pathflag & (1<<BCONTEXT_MODIFIER)) + uiDefIconButS(block, ROW, B_CONTEXT_SWITCH, ICON_MODIFIER, xco+=XIC, yco, XIC, YIC, &(sbuts->mainb), 0.0, (float)BCONTEXT_MODIFIER, 0, 0, "Modifier"); + if(sbuts->pathflag & (1<<BCONTEXT_BONE)) + uiDefIconButS(block, ROW, B_CONTEXT_SWITCH, ICON_BONE_DATA, xco+=XIC, yco, XIC, YIC, &(sbuts->mainb), 0.0, (float)BCONTEXT_BONE, 0, 0, "Bone"); + if(sbuts->pathflag & (1<<BCONTEXT_MATERIAL)) + uiDefIconButS(block, ROW, B_CONTEXT_SWITCH, ICON_MATERIAL, xco+=XIC, yco, XIC, YIC, &(sbuts->mainb), 0.0, (float)BCONTEXT_MATERIAL, 0, 0, "Material"); + if(sbuts->pathflag & (1<<BCONTEXT_TEXTURE)) + uiDefIconButS(block, ROW, B_BUTSPREVIEW, ICON_TEXTURE, xco+=XIC, yco, XIC, YIC, &(sbuts->mainb), 0.0, (float)BCONTEXT_TEXTURE, 0, 0, "Texture"); + if(sbuts->pathflag & (1<<BCONTEXT_PARTICLE)) + uiDefIconButS(block, ROW, B_CONTEXT_SWITCH, ICON_PARTICLES, xco+=XIC, yco, XIC, YIC, &(sbuts->mainb), 0.0, (float)BCONTEXT_PARTICLE, 0, 0, "Particles"); + if(sbuts->pathflag & (1<<BCONTEXT_PHYSICS)) + uiDefIconButS(block, ROW, B_CONTEXT_SWITCH, ICON_PHYSICS, xco+=XIC, yco, XIC, YIC, &(sbuts->mainb), 0.0, (float)BCONTEXT_PHYSICS, 0, 0, "Physics"); + xco+= XIC; uiBlockEndAlign(block); @@ -220,11 +197,6 @@ void buttons_header_buttons(const bContext *C, ARegion *ar) uiDefButI(block, NUM, B_NEWFRAME, "", (xco+20),yco,60,YIC, &(CTX_data_scene(C)->r.cfra), 1.0, MAXFRAMEF, 0, 0, "Displays Current Frame of animation. Click to change."); xco+= 80; -// XXX buttons_active_id(&id, &idfrom); -// sbuts->lockpoin= id; - - - /* always as last */ UI_view2d_totRect_set(&ar->v2d, xco+XIC+80, ar->v2d.tot.ymax-ar->v2d.tot.ymin); diff --git a/source/blender/editors/space_buttons/buttons_intern.h b/source/blender/editors/space_buttons/buttons_intern.h index 04c7241c465..196647a3750 100644 --- a/source/blender/editors/space_buttons/buttons_intern.h +++ b/source/blender/editors/space_buttons/buttons_intern.h @@ -32,6 +32,9 @@ struct ARegion; struct ARegionType; struct bContext; struct bContextDataResult; +struct SpaceButs; +struct uiLayout; +struct wmOperatorType; /* buts->scaflag */ #define BUTS_SENS_SEL 1 @@ -52,9 +55,15 @@ struct bContextDataResult; void buttons_header_buttons(const struct bContext *C, struct ARegion *ar); /* buttons_context.c */ -void buttons_context_compute(const struct bContext *C, SpaceButs *sbuts); +void buttons_context_compute(const struct bContext *C, struct SpaceButs *sbuts); int buttons_context(const struct bContext *C, const char *member, struct bContextDataResult *result); +void buttons_context_draw(const struct bContext *C, struct uiLayout *layout); void buttons_context_register(struct ARegionType *art); +/* buttons_ops.c */ +void MATERIAL_OT_new(struct wmOperatorType *ot); +void TEXTURE_OT_new(struct wmOperatorType *ot); +void WORLD_OT_new(struct wmOperatorType *ot); + #endif /* ED_BUTTONS_INTERN_H */ diff --git a/source/blender/editors/space_buttons/buttons_ops.c b/source/blender/editors/space_buttons/buttons_ops.c new file mode 100644 index 00000000000..63469a8294d --- /dev/null +++ b/source/blender/editors/space_buttons/buttons_ops.c @@ -0,0 +1,194 @@ +/** + * $Id: + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2009 Blender Foundation. + * All rights reserved. + * + * Contributor(s): Blender Foundation + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include <stdlib.h> +#include <string.h> + +#include "MEM_guardedalloc.h" + +#include "DNA_object_types.h" +#include "DNA_material_types.h" +#include "DNA_texture_types.h" +#include "DNA_scene_types.h" +#include "DNA_world_types.h" + +#include "BKE_context.h" +#include "BKE_library.h" +#include "BKE_material.h" +#include "BKE_texture.h" +#include "BKE_world.h" + +#include "RNA_access.h" + +#include "WM_api.h" +#include "WM_types.h" + +#include "buttons_intern.h" // own include + +/********************** new material operator *********************/ + +static int new_material_exec(bContext *C, wmOperator *op) +{ + PointerRNA ptr; + Material *ma; + Object *ob; + int index; + + /* add or copy material */ + ptr= CTX_data_pointer_get(C, "material"); + ma= (RNA_struct_is_a(ptr.type, &RNA_Material))? ptr.data: NULL; + + if(ma) + ma= copy_material(ma); + else + ma= add_material("Material"); + + ma->id.us--; /* compensating for us++ in assign_material */ + + /* attempt to assign to material slot */ + ptr= CTX_data_pointer_get(C, "material_slot"); + + if(RNA_struct_is_a(ptr.type, &RNA_MaterialSlot)) { + ob= ptr.id.data; + index= (Material**)ptr.data - ob->mat; + + assign_material(ob, ma, index+1); + + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); + } + + return OPERATOR_FINISHED; +} + +void MATERIAL_OT_new(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "New Material"; + ot->idname= "MATERIAL_OT_new"; + + /* api callbacks */ + ot->exec= new_material_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + +/********************** new texture operator *********************/ + +static int new_texture_exec(bContext *C, wmOperator *op) +{ + PointerRNA ptr; + ID *id; + Tex *tex; + MTex *mtex; + + /* add or copy texture */ + ptr= CTX_data_pointer_get(C, "texture"); + tex= (RNA_struct_is_a(ptr.type, &RNA_Texture))? ptr.data: NULL; + + if(tex) + tex= copy_texture(tex); + else + tex= add_texture("Texture"); + + id_us_min(&tex->id); + + /* attempt to assign to texture slot */ + ptr= CTX_data_pointer_get(C, "texture_slot"); + + if(RNA_struct_is_a(ptr.type, &RNA_TextureSlot)) { + id= ptr.id.data; + mtex= ptr.data; + + if(mtex) { + if(mtex->tex) + id_us_min(&mtex->tex->id); + mtex->tex= tex; + id_us_plus(&tex->id); + } + + /* XXX nodes, notifier .. */ + } + + return OPERATOR_FINISHED; +} + +void TEXTURE_OT_new(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "New Texture"; + ot->idname= "TEXTURE_OT_new"; + + /* api callbacks */ + ot->exec= new_texture_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + +/********************** new world operator *********************/ + +static int new_world_exec(bContext *C, wmOperator *op) +{ + PointerRNA ptr; + Scene *scene; + World *wo; + + /* add or copy world */ + ptr= CTX_data_pointer_get(C, "world"); + wo= (RNA_struct_is_a(ptr.type, &RNA_World))? ptr.data: NULL; + + if(wo) + wo= copy_world(wo); + else + wo= add_world("World"); + + /* assign to scene */ + scene= CTX_data_scene(C); + + if(scene->world) + id_us_min(&scene->world->id); + scene->world= wo; + + // XXX notifier + + return OPERATOR_FINISHED; +} + +void WORLD_OT_new(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "New World"; + ot->idname= "WORLD_OT_new"; + + /* api callbacks */ + ot->exec= new_world_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + diff --git a/source/blender/editors/space_buttons/space_buttons.c b/source/blender/editors/space_buttons/space_buttons.c index a6487fd5f63..291519e9632 100644 --- a/source/blender/editors/space_buttons/space_buttons.c +++ b/source/blender/editors/space_buttons/space_buttons.c @@ -33,6 +33,7 @@ #include "DNA_space_types.h" #include "DNA_scene_types.h" #include "DNA_screen_types.h" +#include "DNA_userdef_types.h" #include "MEM_guardedalloc.h" @@ -79,6 +80,14 @@ static SpaceLink *buttons_new(const bContext *C) ar->regiontype= RGN_TYPE_HEADER; ar->alignment= RGN_ALIGN_BOTTOM; +#if 0 + /* context area */ + ar= MEM_callocN(sizeof(ARegion), "context area for buts"); + BLI_addtail(&sbuts->regionbase, ar); + ar->regiontype= RGN_TYPE_CHANNELS; + ar->alignment= RGN_ALIGN_TOP; +#endif + /* main area */ ar= MEM_callocN(sizeof(ARegion), "main area for buts"); @@ -203,7 +212,9 @@ static void buttons_main_area_draw(const bContext *C, ARegion *ar) void buttons_operatortypes(void) { - + WM_operatortype_append(MATERIAL_OT_new); + WM_operatortype_append(TEXTURE_OT_new); + WM_operatortype_append(WORLD_OT_new); } void buttons_keymap(struct wmWindowManager *wm) @@ -239,6 +250,58 @@ static void buttons_header_area_draw(const bContext *C, ARegion *ar) UI_view2d_view_restore(C); } +#if 0 +/* add handlers, stuff you only do once or on area/region changes */ +static void buttons_context_area_init(wmWindowManager *wm, ARegion *ar) +{ + UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy); +} + +#define CONTEXTY 30 + +static void buttons_context_area_draw(const bContext *C, ARegion *ar) +{ + SpaceButs *sbuts= (SpaceButs*)CTX_wm_space_data(C); + uiStyle *style= U.uistyles.first; + uiBlock *block; + uiLayout *layout; + View2D *v2d= &ar->v2d; + float col[3]; + int x, y, w, h; + + buttons_context_compute(C, sbuts); + + w= v2d->cur.xmax - v2d->cur.xmin; + h= v2d->cur.ymax - v2d->cur.ymin; + UI_view2d_view_ortho(C, v2d); + + /* create UI */ + block= uiBeginBlock(C, ar, "buttons_context", UI_EMBOSS); + layout= uiBlockLayout(block, UI_LAYOUT_HORIZONTAL, UI_LAYOUT_PANEL, + style->panelspace, h - (h-UI_UNIT_Y)/2, w, 20, style); + + buttons_context_draw(C, layout); + + uiBlockLayoutResolve(C, block, &x, &y); + uiEndBlock(C, block); + + /* draw */ + UI_SetTheme(SPACE_BUTS, RGN_TYPE_WINDOW); /* XXX */ + + UI_GetThemeColor3fv(TH_BACK, col); + glClearColor(col[0], col[1], col[2], 0.0); + glClear(GL_COLOR_BUFFER_BIT); + + UI_view2d_totRect_set(v2d, x, -y); + UI_view2d_view_ortho(C, v2d); + + uiDrawBlock(C, block); + + /* restore view matrix */ + UI_view2d_view_restore(C); +} +#endif + /* reused! */ static void buttons_area_listener(ScrArea *sa, wmNotifier *wmn) { @@ -328,17 +391,19 @@ void ED_spacetype_buttons(void) art->init= buttons_header_area_init; art->draw= buttons_header_area_draw; BLI_addhead(&st->regiontypes, art); - - /* regions: channels */ + +#if 0 + /* regions: context */ art= MEM_callocN(sizeof(ARegionType), "spacetype buttons region"); art->regionid = RGN_TYPE_CHANNELS; - art->minsizex= 80; - art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D; - -// art->init= buttons_channel_area_init; -// art->draw= buttons_channel_area_draw; + art->minsizey= CONTEXTY; + art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_FRAMES; + art->init= buttons_context_area_init; + art->draw= buttons_context_area_draw;; + art->listener= buttons_area_listener; BLI_addhead(&st->regiontypes, art); +#endif BKE_spacetype_register(st); } diff --git a/source/blender/editors/space_image/image_header.c b/source/blender/editors/space_image/image_header.c index 9a61d3a7081..adf4772efde 100644 --- a/source/blender/editors/space_image/image_header.c +++ b/source/blender/editors/space_image/image_header.c @@ -140,13 +140,8 @@ static void image_viewmenu(bContext *C, uiLayout *layout, void *arg_unused) show_uvedit= ED_space_image_show_uvedit(sima, CTX_data_edit_object(C)); /* create menu */ - uiItemO(layout, NULL, ICON_MENU_PANEL, "IMAGE_OT_toggle_view_properties_panel"); // View Properties... - uiItemO(layout, NULL, ICON_MENU_PANEL, "IMAGE_OT_toggle_image_properties_panel"); // Image Properties...|N - uiItemO(layout, NULL, ICON_MENU_PANEL, "IMAGE_OT_toggle_realtime_properties_panel"); // Real-time properties... - if(show_paint) uiItemO(layout, NULL, ICON_MENU_PANEL, "IMAGE_OT_toggle_paint_panel"); // Paint Tool...|C - uiItemO(layout, NULL, ICON_MENU_PANEL, "IMAGE_OT_toggle_curves_panel"); // Curves Tool... - if(show_render) uiItemO(layout, NULL, ICON_MENU_PANEL, "IMAGE_OT_toggle_compositing_preview_panel"); // Compositing Preview...|Shift P - uiItemO(layout, NULL, ICON_MENU_PANEL, "IMAGE_OT_toggle_grease_pencil_panel"); // Grease Pencil... + uiItemO(layout, NULL, ICON_MENU_PANEL, "IMAGE_OT_properties"); + //if(show_render) uiItemO(layout, NULL, ICON_MENU_PANEL, "IMAGE_OT_toggle_compositing_preview_panel"); // Compositing Preview...|Shift P uiItemS(layout); |