[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [56706] trunk/blender/source/blender: Fix for [#35224] Transform Orientation - order inconsistency
Bastien Montagne
montagne29 at wanadoo.fr
Sun May 12 15:16:11 CEST 2013
Revision: 56706
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=56706
Author: mont29
Date: 2013-05-12 13:16:11 +0000 (Sun, 12 May 2013)
Log Message:
-----------
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!
Modified Paths:
--------------
trunk/blender/source/blender/editors/include/ED_transform.h
trunk/blender/source/blender/editors/include/UI_interface.h
trunk/blender/source/blender/editors/interface/interface.c
trunk/blender/source/blender/editors/interface/interface_layout.c
trunk/blender/source/blender/editors/interface/interface_regions.c
trunk/blender/source/blender/editors/object/object_edit.c
trunk/blender/source/blender/editors/space_view3d/view3d_header.c
trunk/blender/source/blender/editors/transform/transform.c
trunk/blender/source/blender/editors/transform/transform_orientations.c
trunk/blender/source/blender/makesrna/intern/rna_object.c
trunk/blender/source/blender/makesrna/intern/rna_space.c
Modified: trunk/blender/source/blender/editors/include/ED_transform.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_transform.h 2013-05-12 13:15:41 UTC (rev 56705)
+++ trunk/blender/source/blender/editors/include/ED_transform.h 2013-05-12 13:16:11 UTC (rev 56706)
@@ -129,14 +129,10 @@
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)
Modified: trunk/blender/source/blender/editors/include/UI_interface.h
===================================================================
--- trunk/blender/source/blender/editors/include/UI_interface.h 2013-05-12 13:15:41 UTC (rev 56705)
+++ trunk/blender/source/blender/editors/include/UI_interface.h 2013-05-12 13:16:11 UTC (rev 56706)
@@ -217,7 +217,7 @@
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 @@
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),
Modified: trunk/blender/source/blender/editors/interface/interface.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface.c 2013-05-12 13:15:41 UTC (rev 56705)
+++ trunk/blender/source/blender/editors/interface/interface.c 2013-05-12 13:16:11 UTC (rev 56706)
@@ -2880,15 +2880,15 @@
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 @@
str = RNA_property_ui_name(prop);
}
if (free) {
- MEM_freeN(item);
+ MEM_freeN(item_array);
}
}
else {
Modified: trunk/blender/source/blender/editors/interface/interface_layout.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_layout.c 2013-05-12 13:15:41 UTC (rev 56705)
+++ trunk/blender/source/blender/editors/interface/interface_layout.c 2013-05-12 13:16:11 UTC (rev 56706)
@@ -482,14 +482,33 @@
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 @@
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 @@
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 @@
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 @@
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 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 @@
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);
+ }
+ RNA_property_enum_set(&tptr, prop, item->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]);
+ 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 @@
/* RNA property items */
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list