From 127c39b8a44df962b1ac20578497b387319efe87 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Sun, 12 May 2013 13:16:11 +0000 Subject: Fix for [#35224] Transform Orientation - order inconsistency Fix turned out to remove as much "manual UI" from 3D view header as possible. Mode selector and all transform manipulators/orientations stuff are now RNA-based UI (leaving basically only edit mesh select modes with custom handlers, as they have some quite specific features). To achieve this, four main modifications were done: * enum-operator-generated menus are now MENU (i.e. dropdown lists) in headers too. * All bit-flag enums expanded in ROW buttons now have a handling consistent with e.g. layers, or what we already have for transform manipulators, i.e. clicking select only one element, shift-click to select multiple ones. * Consequently, the three RNA booleans manipulators flags are merged into a single bit-flag enum (yes, this is also an API change, though I doubt many scripts use it). * Now the width of enum-based dropdown lists is computed from longest item name in enum, no more from a dummy place holder string (when no label/name is given). All this allows to remove some code from 3DView/transform areas, that was actually mostly duplicating RNA/operator one. Also done a few optimizations here and there (among others, do not pass &numitems to RNA_property_enum_items() when you do not need it, saves at least an iteration over enum items to count them). Many thanks to Brecht for the reviews! --- source/blender/editors/include/ED_transform.h | 4 - source/blender/editors/include/UI_interface.h | 4 +- source/blender/editors/interface/interface.c | 16 +- .../blender/editors/interface/interface_layout.c | 176 +++++++++++++-------- .../blender/editors/interface/interface_regions.c | 9 +- source/blender/editors/object/object_edit.c | 39 ++--- .../blender/editors/space_view3d/view3d_header.c | 161 +++---------------- source/blender/editors/transform/transform.c | 29 +--- .../editors/transform/transform_orientations.c | 69 -------- 9 files changed, 166 insertions(+), 341 deletions(-) (limited to 'source/blender/editors') diff --git a/source/blender/editors/include/ED_transform.h b/source/blender/editors/include/ED_transform.h index 256ff2d53ed..74c150d9a00 100644 --- a/source/blender/editors/include/ED_transform.h +++ b/source/blender/editors/include/ED_transform.h @@ -129,14 +129,10 @@ void BIF_selectTransformOrientationValue(struct bContext *C, int orientation); void ED_getTransformOrientationMatrix(const struct bContext *C, float orientation_mat[3][3], const bool activeOnly); -struct EnumPropertyItem *BIF_enumTransformOrientation(struct bContext *C); -const char *BIF_menustringTransformOrientation(const struct bContext *C, const char *title); /* the returned value was allocated and needs to be freed after use */ int BIF_countTransformOrientation(const struct bContext *C); void BIF_TransformSetUndo(const char *str); -void BIF_selectOrientation(void); - /* to be able to add operator properties to other operators */ #define P_MIRROR (1 << 0) diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index a97f1689db9..d8d9c56bed3 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -217,7 +217,7 @@ typedef enum { TOGR = (8 << 9), TOGN = (9 << 9), LABEL = (10 << 9), - MENU = (11 << 9), + MENU = (11 << 9), /* Dropdown list, actually! */ ICONROW = (12 << 9), ICONTOG = (13 << 9), NUMSLI = (14 << 9), @@ -233,7 +233,7 @@ typedef enum { KEYEVT = (24 << 9), ICONTEXTROW = (25 << 9), HSVCUBE = (26 << 9), - PULLDOWN = (27 << 9), + PULLDOWN = (27 << 9), /* Menu, actually! */ ROUNDBOX = (28 << 9), CHARTAB = (29 << 9), BUT_COLORBAND = (30 << 9), diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 87281ab7819..59a5f169f9b 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -2880,15 +2880,15 @@ static uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, const char *s freestr = 1; } else if (ELEM(type, ROW, LISTROW) && proptype == PROP_ENUM) { - EnumPropertyItem *item; - int i, totitem, free; + EnumPropertyItem *item, *item_array = NULL; + int free; /* get untranslated, then translate the single string we need */ - RNA_property_enum_items(block->evil_C, ptr, prop, &item, &totitem, &free); - for (i = 0; i < totitem; i++) { - if (item[i].identifier[0] && item[i].value == (int)max) { - str = CTX_IFACE_(RNA_property_translation_context(prop), item[i].name); - icon = item[i].icon; + RNA_property_enum_items(block->evil_C, ptr, prop, &item_array, NULL, &free); + for (item = item_array; item->identifier; item++) { + if (item->identifier[0] && item->value == (int)max) { + str = CTX_IFACE_(RNA_property_translation_context(prop), item->name); + icon = item->icon; break; } } @@ -2897,7 +2897,7 @@ static uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, const char *s str = RNA_property_ui_name(prop); } if (free) { - MEM_freeN(item); + MEM_freeN(item_array); } } else { diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index 8e5d5740444..184477ab38f 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -482,14 +482,33 @@ static void ui_item_array(uiLayout *layout, uiBlock *block, const char *name, in uiBlockSetCurLayout(block, layout); } -static void ui_item_enum_expand(uiLayout *layout, uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, const char *uiname, int h, int icon_only) +static void ui_item_enum_expand_handle(bContext *C, void *arg1, void *arg2) +{ + wmWindow *win = CTX_wm_window(C); + + if (!win->eventstate->shift) { + uiBut *but = (uiBut *)arg1; + int enum_value = GET_INT_FROM_POINTER(arg2); + + int current_value = RNA_property_enum_get(&but->rnapoin, but->rnaprop); + if (!(current_value & enum_value)) { + current_value = enum_value; + } + else { + current_value &= enum_value; + } + RNA_property_enum_set(&but->rnapoin, but->rnaprop, current_value); + } +} +static void ui_item_enum_expand(uiLayout *layout, uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, + const char *uiname, int h, int icon_only) { uiBut *but; - EnumPropertyItem *item; + EnumPropertyItem *item, *item_array; const char *name; - int a, totitem, itemw, icon, value, free; + int itemw, icon, value, free; - RNA_property_enum_items_gettexted(block->evil_C, ptr, prop, &item, &totitem, &free); + RNA_property_enum_items_gettexted(block->evil_C, ptr, prop, &item_array, NULL, &free); /* we dont want nested rows, cols in menus */ if (layout->root->type != UI_LAYOUT_MENU) { @@ -499,13 +518,13 @@ static void ui_item_enum_expand(uiLayout *layout, uiBlock *block, PointerRNA *pt uiBlockSetCurLayout(block, layout); } - for (a = 0; a < totitem; a++) { - if (!item[a].identifier[0]) + for (item = item_array; item->identifier; item++) { + if (!item->identifier[0]) continue; - name = (!uiname || uiname[0]) ? item[a].name : ""; - icon = item[a].icon; - value = item[a].value; + name = (!uiname || uiname[0]) ? item->name : ""; + icon = item->icon; + value = item->value; itemw = ui_text_icon_width(block->curlayout, name, icon, 0); if (icon && name[0] && !icon_only) @@ -515,13 +534,17 @@ static void ui_item_enum_expand(uiLayout *layout, uiBlock *block, PointerRNA *pt else but = uiDefButR_prop(block, ROW, 0, name, 0, 0, itemw, h, ptr, prop, -1, 0, value, -1, -1, NULL); + if (RNA_property_flag(prop) & PROP_ENUM_FLAG) { + uiButSetFunc(but, ui_item_enum_expand_handle, but, SET_INT_IN_POINTER(value)); + } + if (ui_layout_local_dir(layout) != UI_LAYOUT_HORIZONTAL) but->flag |= UI_TEXT_LEFT; } uiBlockSetCurLayout(block, layout); if (free) { - MEM_freeN(item); + MEM_freeN(item_array); } } @@ -736,10 +759,10 @@ PointerRNA uiItemFullO(uiLayout *layout, const char *opname, const char *name, i static const char *ui_menu_enumpropname(uiLayout *layout, PointerRNA *ptr, PropertyRNA *prop, int retval) { EnumPropertyItem *item; - int totitem, free; + int free; const char *name; - RNA_property_enum_items(layout->root->block->evil_C, ptr, prop, &item, &totitem, &free); + RNA_property_enum_items(layout->root->block->evil_C, ptr, prop, &item, NULL, &free); if (RNA_enum_name(item, retval, &name)) { name = CTX_IFACE_(RNA_property_translation_context(prop), name); } @@ -754,18 +777,6 @@ static const char *ui_menu_enumpropname(uiLayout *layout, PointerRNA *ptr, Prope return name; } -/* same as below but 'prop' is already known */ -static void uiItemEnumO_ptr__internal(uiLayout *layout, wmOperatorType *ot, const char *name, int icon, PropertyRNA *prop, int value) -{ - PointerRNA ptr; - WM_operator_properties_create_ptr(&ptr, ot); - RNA_property_enum_set(&ptr, prop, value); - - if (!name) - name = ui_menu_enumpropname(layout, &ptr, prop, value); - - uiItemFullO_ptr(layout, ot, name, icon, ptr.data, layout->root->opcontext, 0); -} void uiItemEnumO_ptr(uiLayout *layout, wmOperatorType *ot, const char *name, int icon, const char *propname, int value) { PointerRNA ptr; @@ -802,13 +813,13 @@ void uiItemEnumO(uiLayout *layout, const char *opname, const char *name, int ico } -void uiItemsFullEnumO(uiLayout *layout, const char *opname, const char *propname, IDProperty *properties, int context, int flag) +void uiItemsFullEnumO(uiLayout *layout, const char *opname, const char *propname, IDProperty *properties, + int context, int flag) { wmOperatorType *ot = WM_operatortype_find(opname, 0); /* print error next */ PointerRNA ptr; PropertyRNA *prop; - uiBut *bt; uiBlock *block = layout->root->block; if (!ot || !ot->srna) { @@ -817,62 +828,59 @@ void uiItemsFullEnumO(uiLayout *layout, const char *opname, const char *propname return; } - RNA_pointer_create(NULL, ot->srna, NULL, &ptr); + WM_operator_properties_create_ptr(&ptr, ot); + /* so the context is passed to itemf functions (some need it) */ + WM_operator_properties_sanitize(&ptr, false); prop = RNA_struct_find_property(&ptr, propname); /* don't let bad properties slip through */ BLI_assert((prop == NULL) || (RNA_property_type(prop) == PROP_ENUM)); if (prop && RNA_property_type(prop) == PROP_ENUM) { - EnumPropertyItem *item; - int totitem, i, free; + EnumPropertyItem *item, *item_array = NULL; + int free; uiLayout *split = uiLayoutSplit(layout, 0.0f, FALSE); uiLayout *column = uiLayoutColumn(split, FALSE); - RNA_property_enum_items_gettexted(block->evil_C, &ptr, prop, &item, &totitem, &free); + RNA_property_enum_items_gettexted(block->evil_C, &ptr, prop, &item_array, NULL, &free); + for (item = item_array; item->identifier; item++) { + if (item->identifier[0]) { + PointerRNA tptr; - for (i = 0; i < totitem; i++) { - if (item[i].identifier[0]) { + WM_operator_properties_create_ptr(&tptr, ot); if (properties) { - PointerRNA tptr; - - WM_operator_properties_create_ptr(&tptr, ot); if (tptr.data) { IDP_FreeProperty(tptr.data); MEM_freeN(tptr.data); } tptr.data = IDP_CopyProperty(properties); - RNA_property_enum_set(&tptr, prop, item[i].value); - - uiItemFullO_ptr(column, ot, item[i].name, item[i].icon, tptr.data, context, flag); - } - else { - uiItemEnumO_ptr__internal(column, ot, item[i].name, item[i].icon, prop, item[i].value); } - ui_but_tip_from_enum_item(block->buttons.last, &item[i]); + RNA_property_enum_set(&tptr, prop, item->value); + + uiItemFullO_ptr(column, ot, item->name, item->icon, tptr.data, context, flag); + ui_but_tip_from_enum_item(block->buttons.last, item); } else { - if (item[i].name) { - if (i != 0) { + if (item->name) { + uiBut *but; + if (item != item_array) { column = uiLayoutColumn(split, FALSE); /* inconsistent, but menus with labels do not look good flipped */ block->flag |= UI_BLOCK_NO_FLIP; } - uiItemL(column, item[i].name, ICON_NONE); - bt = block->buttons.last; - bt->flag = UI_TEXT_LEFT; - - ui_but_tip_from_enum_item(bt, &item[i]); + uiItemL(column, item->name, ICON_NONE); + but = block->buttons.last; + but->flag = UI_TEXT_LEFT; + ui_but_tip_from_enum_item(but, item); } else { /* XXX bug here, colums draw bottom item badly */ uiItemS(column); } } } - if (free) { - MEM_freeN(item); + MEM_freeN(item_array); } } else if (prop && RNA_property_type(prop) != PROP_ENUM) { @@ -1021,23 +1029,44 @@ void uiItemO(uiLayout *layout, const char *name, int icon, const char *opname) /* RNA property items */ -static void ui_item_rna_size(uiLayout *layout, const char *name, int icon, PointerRNA *ptr, PropertyRNA *prop, int index, int icon_only, int *r_w, int *r_h) +static void ui_item_rna_size(uiLayout *layout, const char *name, int icon, PointerRNA *ptr, PropertyRNA *prop, + int index, int icon_only, int *r_w, int *r_h) { PropertyType type; PropertySubType subtype; - int len, w, h; + int len, w = 0, h; /* arbitrary extended width by type */ type = RNA_property_type(prop); subtype = RNA_property_subtype(prop); len = RNA_property_array_length(ptr, prop); - if (ELEM3(type, PROP_STRING, PROP_POINTER, PROP_ENUM) && !name[0] && !icon_only) - name = "non-empty text"; - else if (type == PROP_BOOLEAN && !name[0] && !icon_only) - icon = ICON_DOT; + if (!name[0] && !icon_only) { + if (ELEM(type, PROP_STRING, PROP_POINTER)) { + name = "non-empty text"; + } + else if (type == PROP_BOOLEAN) { + icon = ICON_DOT; + } + else if (type == PROP_ENUM) { + /* Find the longest enum item name, instead of using a dummy text! */ + EnumPropertyItem *item, *item_array; + int free; + + RNA_property_enum_items_gettexted(layout->root->block->evil_C, ptr, prop, &item_array, NULL, &free); + for (item = item_array; item->identifier; item++) { + if (item->identifier[0]) { + w = max_ii(w, ui_text_icon_width(layout, item->name, icon, 0)); + } + } + if (free) { + MEM_freeN(item_array); + } + } + } - w = ui_text_icon_width(layout, name, icon, 0); + if (!w) + w = ui_text_icon_width(layout, name, icon, 0); h = UI_UNIT_Y; /* increase height for arrays */ @@ -1509,7 +1538,8 @@ static void ui_item_menutype_func(bContext *C, uiLayout *layout, void *arg_mt) CTX_store_set(C, NULL); } -static void ui_item_menu(uiLayout *layout, const char *name, int icon, uiMenuCreateFunc func, void *arg, void *argN, const char *tip) +static void ui_item_menu(uiLayout *layout, const char *name, int icon, uiMenuCreateFunc func, void *arg, void *argN, + const char *tip, bool force_menu) { uiBlock *block = layout->root->block; uiBut *but; @@ -1528,8 +1558,12 @@ static void ui_item_menu(uiLayout *layout, const char *name, int icon, uiMenuCre w = ui_text_icon_width(layout, name, icon, 1); h = UI_UNIT_Y; - if (layout->root->type == UI_LAYOUT_HEADER) /* ugly .. */ - w -= UI_UNIT_Y / 2; + if (layout->root->type == UI_LAYOUT_HEADER) { /* ugly .. */ + if (force_menu) + w += UI_UNIT_Y; + else + w -= UI_UNIT_Y / 2; + } if (name[0] && icon) but = uiDefIconTextMenuBut(block, func, arg, icon, name, 0, 0, w, h, tip); @@ -1543,9 +1577,12 @@ static void ui_item_menu(uiLayout *layout, const char *name, int icon, uiMenuCre but->func_argN = argN; } - if (layout->root->type == UI_LAYOUT_HEADER) + if (layout->root->type == UI_LAYOUT_HEADER) { uiBlockSetEmboss(block, UI_EMBOSS); - else if (ELEM(layout->root->type, UI_LAYOUT_PANEL, UI_LAYOUT_TOOLBAR)) { + } + if (ELEM(layout->root->type, UI_LAYOUT_PANEL, UI_LAYOUT_TOOLBAR) || + (force_menu && layout->root->type != UI_LAYOUT_MENU)) /* We never want a dropdown in menu! */ + { but->type = MENU; but->flag |= UI_TEXT_LEFT; } @@ -1569,7 +1606,7 @@ void uiItemM(uiLayout *layout, bContext *UNUSED(C), const char *menuname, const if (layout->root->type == UI_LAYOUT_MENU && !icon) icon = ICON_BLANK1; - ui_item_menu(layout, name, icon, ui_item_menutype_func, mt, NULL, TIP_(mt->description)); + ui_item_menu(layout, name, icon, ui_item_menutype_func, mt, NULL, TIP_(mt->description), false); } /* label item */ @@ -1661,7 +1698,7 @@ void uiItemMenuF(uiLayout *layout, const char *name, int icon, uiMenuCreateFunc if (!func) return; - ui_item_menu(layout, name, icon, func, arg, NULL, ""); + ui_item_menu(layout, name, icon, func, arg, NULL, "", false); } typedef struct MenuItemLevel { @@ -1710,15 +1747,16 @@ void uiItemMenuEnumO(uiLayout *layout, bContext *C, const char *opname, const ch /* add hotkey here, lower UI code can't detect it */ if (layout->root->block->flag & UI_BLOCK_LOOP) { - if (ot->prop && WM_key_event_operator_string(C, ot->idname, - layout->root->opcontext, NULL, false, keybuf, sizeof(keybuf))) + if (ot->prop && + WM_key_event_operator_string(C, ot->idname, layout->root->opcontext, NULL, false, keybuf, sizeof(keybuf))) { strncat(namestr, "|", sizeof(namestr) - 1); strncat(namestr, keybuf, sizeof(namestr) - 1); } } - ui_item_menu(layout, namestr, icon, menu_item_enum_opname_menu, NULL, lvl, RNA_struct_ui_description(ot->srna)); + ui_item_menu(layout, namestr, icon, menu_item_enum_opname_menu, NULL, lvl, RNA_struct_ui_description(ot->srna), + true); } static void menu_item_enum_rna_menu(bContext *UNUSED(C), uiLayout *layout, void *arg) @@ -1751,7 +1789,7 @@ void uiItemMenuEnumR(uiLayout *layout, struct PointerRNA *ptr, const char *propn BLI_strncpy(lvl->propname, propname, sizeof(lvl->propname)); lvl->opcontext = layout->root->opcontext; - ui_item_menu(layout, name, icon, menu_item_enum_rna_menu, NULL, lvl, RNA_property_description(prop)); + ui_item_menu(layout, name, icon, menu_item_enum_rna_menu, NULL, lvl, RNA_property_description(prop), false); } /**************************** Layout Items ***************************/ diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c index 887f1cb32ad..a5f96f98949 100644 --- a/source/blender/editors/interface/interface_regions.c +++ b/source/blender/editors/interface/interface_regions.c @@ -447,7 +447,14 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but) /* Tip */ if (but_tip.strinfo) { - BLI_strncpy(data->lines[data->totline], but_tip.strinfo, sizeof(data->lines[0])); + /* Expanded Bit-flag enums have a specific way to select multiple... */ + if ((but->type & ROW) && but->rnaprop && RNA_property_flag(but->rnaprop) & PROP_ENUM_FLAG) { + BLI_snprintf(data->lines[data->totline], sizeof(data->lines[0]), + "%s %s", but_tip.strinfo, IFACE_("(Shift-click to select multiple)")); + } + else { + BLI_strncpy(data->lines[data->totline], but_tip.strinfo, sizeof(data->lines[0])); + } data->color_id[data->totline] = UI_TIP_LC_MAIN; data->totline++; } diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c index f2bd1ff5a93..714de5251c6 100644 --- a/source/blender/editors/object/object_edit.c +++ b/source/blender/editors/object/object_edit.c @@ -1438,31 +1438,34 @@ static void UNUSED_FUNCTION(image_aspect) (Scene *scene, View3D *v3d) } - static EnumPropertyItem *object_mode_set_itemsf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), int *free) -{ +{ EnumPropertyItem *input = object_mode_items; EnumPropertyItem *item = NULL; Object *ob; int totitem = 0; - + if (!C) /* needed for docs */ return object_mode_items; - - ob = CTX_data_active_object(C); - while (ob && input->identifier) { - if ((input->value == OB_MODE_EDIT && OB_TYPE_SUPPORT_EDITMODE(ob->type)) || - (input->value == OB_MODE_POSE && (ob->type == OB_ARMATURE)) || - (input->value == OB_MODE_PARTICLE_EDIT && ob->particlesystem.first) || - ((input->value == OB_MODE_SCULPT || input->value == OB_MODE_VERTEX_PAINT || - input->value == OB_MODE_WEIGHT_PAINT || input->value == OB_MODE_TEXTURE_PAINT) && (ob->type == OB_MESH)) || - (input->value == OB_MODE_OBJECT)) - { - RNA_enum_item_add(&item, &totitem, input); + if (ob) { + while (input->identifier) { + if ((input->value == OB_MODE_EDIT && OB_TYPE_SUPPORT_EDITMODE(ob->type)) || + (input->value == OB_MODE_POSE && (ob->type == OB_ARMATURE)) || + (input->value == OB_MODE_PARTICLE_EDIT && ob->particlesystem.first) || + ((input->value == OB_MODE_SCULPT || input->value == OB_MODE_VERTEX_PAINT || + input->value == OB_MODE_WEIGHT_PAINT || input->value == OB_MODE_TEXTURE_PAINT) && (ob->type == OB_MESH)) || + (input->value == OB_MODE_OBJECT)) + { + RNA_enum_item_add(&item, &totitem, input); + } + input++; } - input++; + } + else { + /* We need at least this one! */ + RNA_enum_items_add_value(&item, &totitem, input, OB_MODE_OBJECT); } RNA_enum_item_end(&item, &totitem); @@ -1559,8 +1562,6 @@ static int object_mode_set_exec(bContext *C, wmOperator *op) void OBJECT_OT_mode_set(wmOperatorType *ot) { - PropertyRNA *prop; - /* identifiers */ ot->name = "Set Object Mode"; ot->description = "Sets the object interaction mode"; @@ -1574,8 +1575,8 @@ void OBJECT_OT_mode_set(wmOperatorType *ot) /* flags */ ot->flag = 0; /* no register/undo here, leave it to operators being called */ - prop = RNA_def_enum(ot->srna, "mode", object_mode_items, OB_MODE_OBJECT, "Mode", ""); - RNA_def_enum_funcs(prop, object_mode_set_itemsf); + ot->prop = RNA_def_enum(ot->srna, "mode", object_mode_items, OB_MODE_OBJECT, "Mode", ""); + RNA_def_enum_funcs(ot->prop, object_mode_set_itemsf); RNA_def_boolean(ot->srna, "toggle", 0, "Toggle", ""); } diff --git a/source/blender/editors/space_view3d/view3d_header.c b/source/blender/editors/space_view3d/view3d_header.c index 2d6d004a318..6ff837111e6 100644 --- a/source/blender/editors/space_view3d/view3d_header.c +++ b/source/blender/editors/space_view3d/view3d_header.c @@ -86,14 +86,9 @@ static void do_view3d_header_buttons(bContext *C, void *arg, int event); -#define B_MODESELECT 108 #define B_SEL_VERT 110 #define B_SEL_EDGE 111 #define B_SEL_FACE 112 -#define B_MAN_TRANS 116 -#define B_MAN_ROT 117 -#define B_MAN_SCALE 118 -#define B_MAN_MODE 120 /* XXX quickly ported across */ static void handle_view3d_lock(bContext *C) @@ -251,81 +246,14 @@ void VIEW3D_OT_layers(wmOperatorType *ot) RNA_def_boolean(ot->srna, "toggle", 1, "Toggle", "Toggle the layer"); } -static int modeselect_addmode(char *str, const char *title, int id, int icon) -{ - static char formatstr[] = "|%s %%x%d %%i%d"; - - return sprintf(str, formatstr, IFACE_(title), id, icon); -} - -static char *view3d_modeselect_pup(Scene *scene) -{ - Object *ob = OBACT; - static char string[512]; - const char *title = IFACE_("Mode: %t"); - char *str = string; - - BLI_strncpy(str, title, sizeof(string)); - - str += modeselect_addmode(str, N_("Object Mode"), OB_MODE_OBJECT, ICON_OBJECT_DATA); - - if (ob == NULL || ob->data == NULL) return string; - if (ob->id.lib) return string; - - if (!((ID *)ob->data)->lib) { - /* if active object is editable */ - if (ob->type == OB_ARMATURE) { - if (ob->mode & OB_MODE_POSE) - str += modeselect_addmode(str, N_("Edit Mode"), OB_MODE_EDIT | OB_MODE_POSE, ICON_EDITMODE_HLT); - else - str += modeselect_addmode(str, N_("Edit Mode"), OB_MODE_EDIT, ICON_EDITMODE_HLT); - } - else if (OB_TYPE_SUPPORT_EDITMODE(ob->type)) { - str += modeselect_addmode(str, N_("Edit Mode"), OB_MODE_EDIT, ICON_EDITMODE_HLT); - } - - if (ob->type == OB_MESH) { - - str += modeselect_addmode(str, N_("Sculpt Mode"), OB_MODE_SCULPT, ICON_SCULPTMODE_HLT); - str += modeselect_addmode(str, N_("Vertex Paint"), OB_MODE_VERTEX_PAINT, ICON_VPAINT_HLT); - str += modeselect_addmode(str, N_("Texture Paint"), OB_MODE_TEXTURE_PAINT, ICON_TPAINT_HLT); - str += modeselect_addmode(str, N_("Weight Paint"), OB_MODE_WEIGHT_PAINT, ICON_WPAINT_HLT); - } - } - - /* if active object is an armature */ - if (ob->type == OB_ARMATURE) { - str += modeselect_addmode(str, N_("Pose Mode"), OB_MODE_POSE, ICON_POSE_HLT); - } - - if (ob->particlesystem.first || - modifiers_findByType(ob, eModifierType_Cloth) || - modifiers_findByType(ob, eModifierType_Softbody)) - { - str += modeselect_addmode(str, N_("Particle Mode"), OB_MODE_PARTICLE_EDIT, ICON_PARTICLEMODE); - } - (void)str; - return (string); -} - static void do_view3d_header_buttons(bContext *C, void *UNUSED(arg), int event) { wmWindow *win = CTX_wm_window(C); - ScrArea *sa = CTX_wm_area(C); - View3D *v3d = sa->spacedata.first; const int ctrl = win->eventstate->ctrl, shift = win->eventstate->shift; - PointerRNA props_ptr; /* watch it: if sa->win does not exist, check that when calling direct drawing routines */ switch (event) { - case B_MODESELECT: - WM_operator_properties_create(&props_ptr, "OBJECT_OT_mode_set"); - RNA_enum_set(&props_ptr, "mode", v3d->modeselect); - WM_operator_name_call(C, "OBJECT_OT_mode_set", WM_OP_EXEC_REGION_WIN, &props_ptr); - WM_operator_properties_free(&props_ptr); - break; - case B_SEL_VERT: if (EDBM_selectmode_toggle(C, SCE_SELECT_VERTEX, -1, shift, ctrl)) { ED_undo_push(C, "Selectmode Set: Vertex"); @@ -341,48 +269,11 @@ static void do_view3d_header_buttons(bContext *C, void *UNUSED(arg), int event) ED_undo_push(C, "Selectmode Set: Face"); } break; - - case B_MAN_TRANS: - if (shift == 0 || v3d->twtype == 0) { - v3d->twtype = V3D_MANIP_TRANSLATE; - } - ED_area_tag_redraw(sa); - break; - case B_MAN_ROT: - if (shift == 0 || v3d->twtype == 0) { - v3d->twtype = V3D_MANIP_ROTATE; - } - ED_area_tag_redraw(sa); - break; - case B_MAN_SCALE: - if (shift == 0 || v3d->twtype == 0) { - v3d->twtype = V3D_MANIP_SCALE; - } - ED_area_tag_redraw(sa); - break; - case B_MAN_MODE: - ED_area_tag_redraw(sa); - break; default: break; } } -/* Returns the icon associated with an object mode */ -static int object_mode_icon(int mode) -{ - EnumPropertyItem *item = object_mode_items; - - while (item->name != NULL) { - if (item->value == mode) { - return item->icon; - } - item++; - } - - return ICON_OBJECT_DATAMODE; -} - void uiTemplateEditModeSelection(uiLayout *layout, struct bContext *C) { Object *obedit = CTX_data_edit_object(C); @@ -419,9 +310,7 @@ void uiTemplateHeader3D(uiLayout *layout, struct bContext *C) Object *ob = OBACT; Object *obedit = CTX_data_edit_object(C); uiBlock *block; - uiBut *but; uiLayout *row; - const float dpi_fac = UI_DPI_FAC; int is_paint = 0; RNA_pointer_create(&screen->id, &RNA_SpaceView3D, v3d, &v3dptr); @@ -443,10 +332,24 @@ void uiTemplateHeader3D(uiLayout *layout, struct bContext *C) v3d->modeselect = OB_MODE_OBJECT; } - row = uiLayoutRow(layout, TRUE); - uiDefIconTextButS(block, MENU, B_MODESELECT, object_mode_icon(v3d->modeselect), view3d_modeselect_pup(scene), - 0, 0, 126 * dpi_fac, UI_UNIT_Y, &(v3d->modeselect), 0, 0, 0, 0, TIP_("Mode")); - + row = uiLayoutRow(layout, FALSE); + { + EnumPropertyItem *item = object_mode_items; + const char *name = ""; + int icon = ICON_OBJECT_DATAMODE; + + while (item->identifier) { + if (item->value == v3d->modeselect && item->identifier[0]) { + name = IFACE_(item->name); + icon = item->icon; + break; + } + item++; + } + + uiItemMenuEnumO(row, C, "OBJECT_OT_mode_set", "mode", name, icon); + } + /* Draw type */ uiItemR(layout, &v3dptr, "viewport_shade", UI_ITEM_R_ICON_ONLY, "", ICON_NONE); @@ -475,8 +378,6 @@ void uiTemplateHeader3D(uiLayout *layout, struct bContext *C) } } else { - const char *str_menu; - row = uiLayoutRow(layout, TRUE); uiItemR(row, &v3dptr, "pivot_point", UI_ITEM_R_ICON_ONLY, "", ICON_NONE); @@ -491,32 +392,10 @@ void uiTemplateHeader3D(uiLayout *layout, struct bContext *C) /* Transform widget / manipulators */ row = uiLayoutRow(layout, TRUE); uiItemR(row, &v3dptr, "show_manipulator", UI_ITEM_R_ICON_ONLY, "", ICON_NONE); - block = uiLayoutGetBlock(row); - if (v3d->twflag & V3D_USE_MANIPULATOR) { - but = uiDefIconButBitC(block, TOG, V3D_MANIP_TRANSLATE, B_MAN_TRANS, ICON_MAN_TRANS, - 0, 0, UI_UNIT_X, UI_UNIT_Y, &v3d->twtype, 1.0, 0.0, 0, 0, - TIP_("Translate manipulator - Shift-Click for multiple modes")); - uiButClearFlag(but, UI_BUT_UNDO); /* skip undo on screen buttons */ - but = uiDefIconButBitC(block, TOG, V3D_MANIP_ROTATE, B_MAN_ROT, ICON_MAN_ROT, - 0, 0, UI_UNIT_X, UI_UNIT_Y, &v3d->twtype, 1.0, 0.0, 0, 0, - TIP_("Rotate manipulator - Shift-Click for multiple modes")); - uiButClearFlag(but, UI_BUT_UNDO); /* skip undo on screen buttons */ - but = uiDefIconButBitC(block, TOG, V3D_MANIP_SCALE, B_MAN_SCALE, ICON_MAN_SCALE, - 0, 0, UI_UNIT_X, UI_UNIT_Y, &v3d->twtype, 1.0, 0.0, 0, 0, - TIP_("Scale manipulator - Shift-Click for multiple modes")); - uiButClearFlag(but, UI_BUT_UNDO); /* skip undo on screen buttons */ + uiItemR(row, &v3dptr, "transform_manipulators", UI_ITEM_R_ICON_ONLY, "", ICON_NONE); } - - if (v3d->twmode > (BIF_countTransformOrientation(C) - 1) + V3D_MANIP_CUSTOM) { - v3d->twmode = 0; - } - - str_menu = BIF_menustringTransformOrientation(C, "Orientation"); - but = uiDefButC(block, MENU, B_MAN_MODE, str_menu, 0, 0, 70 * dpi_fac, UI_UNIT_Y, &v3d->twmode, 0, 0, 0, 0, - TIP_("Transform Orientation")); - uiButClearFlag(but, UI_BUT_UNDO); /* skip undo on screen buttons */ - MEM_freeN((void *)str_menu); + uiItemR(row, &v3dptr, "transform_orientation", 0, "", ICON_NONE); } if (obedit == NULL && v3d->localvd == NULL) { diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index dedf4d30f70..d440dc1fe9e 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -589,20 +589,6 @@ static void viewRedrawPost(bContext *C, TransInfo *t) /* ************************** TRANSFORMATIONS **************************** */ -void BIF_selectOrientation(void) -{ -#if 0 // TRANSFORM_FIX_ME - short val; - char *str_menu = BIF_menustringTransformOrientation("Orientation"); - val = pupmenu(str_menu); - MEM_freeN(str_menu); - - if (val >= 0) { - G.vd->twmode = val; - } -#endif -} - static void view_editmove(unsigned short UNUSED(event)) { #if 0 // TRANSFORM_FIX_ME @@ -1164,20 +1150,7 @@ int transformEvent(TransInfo *t, const wmEvent *event) break; case SPACEKEY: - if ((t->spacetype == SPACE_VIEW3D) && event->alt) { -#if 0 // TRANSFORM_FIX_ME - int mval[2]; - - getmouseco_sc(mval); - BIF_selectOrientation(); - calc_manipulator_stats(curarea); - copy_m3_m4(t->spacemtx, G.vd->twmat); - warp_pointer(mval[0], mval[1]); -#endif - } - else { - t->state = TRANS_CONFIRM; - } + t->state = TRANS_CONFIRM; break; case MIDDLEMOUSE: diff --git a/source/blender/editors/transform/transform_orientations.c b/source/blender/editors/transform/transform_orientations.c index 6090c2f2700..343592d4501 100644 --- a/source/blender/editors/transform/transform_orientations.c +++ b/source/blender/editors/transform/transform_orientations.c @@ -359,75 +359,6 @@ void BIF_selectTransformOrientationValue(bContext *C, int orientation) v3d->twmode = orientation; } -EnumPropertyItem *BIF_enumTransformOrientation(bContext *C) -{ - Scene *scene; - ListBase *transform_spaces; - TransformOrientation *ts = NULL; - - EnumPropertyItem global = {V3D_MANIP_GLOBAL, "GLOBAL", 0, "Global", ""}; - EnumPropertyItem normal = {V3D_MANIP_NORMAL, "NORMAL", 0, "Normal", ""}; - EnumPropertyItem local = {V3D_MANIP_LOCAL, "LOCAL", 0, "Local", ""}; - EnumPropertyItem view = {V3D_MANIP_VIEW, "VIEW", 0, "View", ""}; - EnumPropertyItem tmp = {0, "", 0, "", ""}; - EnumPropertyItem *item = NULL; - int i = V3D_MANIP_CUSTOM, totitem = 0; - - RNA_enum_item_add(&item, &totitem, &global); - RNA_enum_item_add(&item, &totitem, &normal); - RNA_enum_item_add(&item, &totitem, &local); - RNA_enum_item_add(&item, &totitem, &view); - - if (C) { - scene = CTX_data_scene(C); - - if (scene) { - transform_spaces = &scene->transform_spaces; - ts = transform_spaces->first; - } - } - - if (ts) - RNA_enum_item_add_separator(&item, &totitem); - - for (; ts; ts = ts->next) { - tmp.identifier = "CUSTOM"; - tmp.name = ts->name; - tmp.value = i++; - RNA_enum_item_add(&item, &totitem, &tmp); - } - - RNA_enum_item_end(&item, &totitem); - - return item; -} - -const char *BIF_menustringTransformOrientation(const bContext *C, const char *title) -{ - const char *menu = IFACE_("%t|Global %x0|Local %x1|Gimbal %x4|Normal %x2|View %x3"); - ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces; - TransformOrientation *ts; - int i = V3D_MANIP_CUSTOM; - char *str_menu, *p; - const int elem_size = MAX_NAME + 4; - size_t str_menu_size; - - title = IFACE_(title); - - str_menu_size = strlen(menu) + strlen(title) + 1 + (elem_size * BIF_countTransformOrientation(C)); - str_menu = MEM_callocN(str_menu_size, "UserTransSpace from matrix"); - - p = str_menu; - p += BLI_strncpy_rlen(p, title, str_menu_size); - p += BLI_strncpy_rlen(p, menu, str_menu_size - (p - str_menu)); - - for (ts = transform_spaces->first; ts; ts = ts->next) { - p += sprintf(p, "|%s %%x%d", ts->name, i++); - } - - return str_menu; -} - int BIF_countTransformOrientation(const bContext *C) { ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces; -- cgit v1.2.3