[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58595] branches/soc-2013-ui_replay: Added shortcut parameter to "operator" function and aligning icon on the left is a shortcut is to be shown, but no label.

Vincent Akkermans vincent at ack-err.net
Thu Jul 25 12:34:30 CEST 2013


Revision: 58595
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58595
Author:   ack-err
Date:     2013-07-25 10:34:30 +0000 (Thu, 25 Jul 2013)
Log Message:
-----------
Added shortcut parameter to "operator" function and aligning icon on the left is a shortcut is to be shown, but no label.

Modified Paths:
--------------
    branches/soc-2013-ui_replay/release/scripts/startup/bl_ui/space_view3d_toolbar.py
    branches/soc-2013-ui_replay/source/blender/editors/include/UI_interface.h
    branches/soc-2013-ui_replay/source/blender/editors/interface/interface_intern.h
    branches/soc-2013-ui_replay/source/blender/editors/interface/interface_layout.c
    branches/soc-2013-ui_replay/source/blender/editors/interface/interface_widgets.c
    branches/soc-2013-ui_replay/source/blender/makesrna/intern/rna_ui_api.c

Modified: branches/soc-2013-ui_replay/release/scripts/startup/bl_ui/space_view3d_toolbar.py
===================================================================
--- branches/soc-2013-ui_replay/release/scripts/startup/bl_ui/space_view3d_toolbar.py	2013-07-25 10:04:05 UTC (rev 58594)
+++ branches/soc-2013-ui_replay/release/scripts/startup/bl_ui/space_view3d_toolbar.py	2013-07-25 10:34:30 UTC (rev 58595)
@@ -36,8 +36,9 @@
 
     # TODO: doesn't work, try to not draw a header
     def draw_header(self, context):
-        print(dir(self))
-        print(dir(context))
+        pass
+        # print(dir(self))
+        # print(dir(context))
         # layout = self.layout
         # col = layout.column(align=True)
         # col.label("blub")
@@ -48,16 +49,16 @@
 
         col = layout.column(align=True)
         row = col.row(align=True)
-        row.operator("object.mode_set", text="", single_unit=True, icon='OBJECT_DATAMODE').mode = "OBJECT"
-        row.operator("object.mode_set", text="", single_unit=True, icon='EDITMODE_HLT').mode = "EDIT"
-        row.operator("object.mode_set", text="", single_unit=True, icon='SCULPTMODE_HLT').mode = "SCULPT"
+        row.operator("object.mode_set", text="", single_unit=False, shortcut=False, icon='OBJECT_DATAMODE').mode = "OBJECT"
+        row.operator("object.mode_set", text="", single_unit=False, shortcut=False, icon='EDITMODE_HLT').mode = "EDIT"
+        row.operator("object.mode_set", text="", single_unit=False, shortcut=False, icon='SCULPTMODE_HLT').mode = "SCULPT"
         #row.operator("object.mode_set", text="", single_unit=True, icon='POSE_HLT').mode = "POSE"
 
-        col = layout.column(align=True)
+        # col = layout.column(align=True)
         row = col.row(align=True)
-        row.operator("object.mode_set", text="", single_unit=True, icon='VPAINT_HLT').mode = "VERTEX_PAINT"
-        row.operator("object.mode_set", text="", single_unit=True, icon='TPAINT_HLT').mode = "TEXTURE_PAINT"
-        row.operator("object.mode_set", text="", single_unit=True, icon='WPAINT_HLT').mode = "WEIGHT_PAINT"
+        row.operator("object.mode_set", text="", single_unit=False, shortcut=False, icon='VPAINT_HLT').mode = "VERTEX_PAINT"
+        row.operator("object.mode_set", text="", single_unit=False, shortcut=False, icon='TPAINT_HLT').mode = "TEXTURE_PAINT"
+        row.operator("object.mode_set", text="", single_unit=False, shortcut=False, icon='WPAINT_HLT').mode = "WEIGHT_PAINT"
     
     # TODO: adapt the buttons to what items are selected
     #if active_object and active_object.type in {'MESH', 'CURVE', 'SURFACE'}:
@@ -122,18 +123,6 @@
         row.operator("transform.resize", text="", single_unit=False, icon='MAN_SCALE')
         col.operator("object.origin_set", text="Origin")
                 
-class VIEW3D_PT_tools_objectmode_adjust(View3DPanel, Panel):
-    bl_context = "objectmode"
-    bl_label = "Adjust"
-
-    def draw(self, context):
-        layout = self.layout
-        #active_object = context.active_object
-        #if active_object and active_object.type in {'MESH', 'CURVE', 'SURFACE'}:
-        col = layout.column(align=True)
-        col.operator("object.shade_smooth", text="Shade smooth")
-        col.operator("object.shade_flat", text="Shade flat")
-
 class VIEW3D_PT_tools_objectmode_add(View3DPanel, Panel):
     bl_context = "objectmode"
     bl_label = "Add & Delete"
@@ -143,16 +132,27 @@
 
         col = layout.column(align=True)
         row = col.row(align=True, button_height=2)
-        # TODO: wrong operators in these two lines
-        row.operator("wm.call_menu", text="", single_unit=False, icon='MAN_ROT').name = 'INFO_MT_add'
-        row.operator("object.delete", text="", single_unit=False, icon='MAN_TRANS')
+        row.operator("wm.call_menu", text="", shortcut=False, single_unit=False, icon='MAN_ROT').name = 'INFO_MT_add'
+        row.operator("object.delete", text="", shortcut=False, single_unit=False, icon='MAN_TRANS')
         
         col = layout.column(align=True)
         row = col.row(align=True)
-        row.operator("object.duplicate_move", text="", single_unit=False, icon='MAN_ROT')
-        row.operator("object.duplicate_move_linked", text="", single_unit=False, icon='MAN_TRANS')
+        row.operator("object.duplicate_move", text="", shortcut=False, single_unit=False, icon='MAN_ROT')
+        row.operator("object.duplicate_move_linked", text="", shortcut=False, single_unit=False, icon='MAN_TRANS')
         row = col.row(align=True)
         col.operator("object.join")
+
+class VIEW3D_PT_tools_objectmode_adjust(View3DPanel, Panel):
+    bl_context = "objectmode"
+    bl_label = "Adjust"
+
+    def draw(self, context):
+        layout = self.layout
+        #active_object = context.active_object
+        #if active_object and active_object.type in {'MESH', 'CURVE', 'SURFACE'}:
+        col = layout.column(align=True)
+        col.operator("object.shade_smooth", text="Shade smooth")
+        col.operator("object.shade_flat", text="Shade flat")
         
 VIEW3D_PT_tools_objectmode_grease = grease_panel("objectmode")
 

Modified: branches/soc-2013-ui_replay/source/blender/editors/include/UI_interface.h
===================================================================
--- branches/soc-2013-ui_replay/source/blender/editors/include/UI_interface.h	2013-07-25 10:04:05 UTC (rev 58594)
+++ branches/soc-2013-ui_replay/source/blender/editors/include/UI_interface.h	2013-07-25 10:34:30 UTC (rev 58595)
@@ -179,6 +179,9 @@
 #define UI_BUT_VEC_SIZE_LOCK (1 << 30) /* used to flag if color hsv-circle should keep luminance */
 #define UI_BUT_COLOR_CUBIC   (1 << 31) /* cubic saturation for the color wheel */
 
+#define UI_BUT2_EXTRA_TEXT	 (1 << 0)
+
+
 #define UI_PANEL_WIDTH          340
 #define UI_COMPACT_PANEL_WIDTH  160
 
@@ -724,6 +727,7 @@
 #define UI_ITEM_R_NO_BG         (1 << 7)
 #define UI_ITEM_R_IMMEDIATE     (1 << 8)
 #define UI_ITEM_O_SINGLE_UNIT	(1 << 9)
+#define UI_ITEM_O_SHORTCUT		(1 << 10)
 
 /* uiLayoutOperatorButs flags */
 #define UI_LAYOUT_OP_SHOW_TITLE 1

Modified: branches/soc-2013-ui_replay/source/blender/editors/interface/interface_intern.h
===================================================================
--- branches/soc-2013-ui_replay/source/blender/editors/interface/interface_intern.h	2013-07-25 10:04:05 UTC (rev 58594)
+++ branches/soc-2013-ui_replay/source/blender/editors/interface/interface_intern.h	2013-07-25 10:34:30 UTC (rev 58595)
@@ -163,7 +163,7 @@
 
 struct uiBut {
 	struct uiBut *next, *prev;
-	int flag, drawflag;
+	int flag, flag2, drawflag;
 	eButType         type;
 	eButPointerType  pointype;
 	short bit, bitnr, retval, strwidth, alignnr;

Modified: branches/soc-2013-ui_replay/source/blender/editors/interface/interface_layout.c
===================================================================
--- branches/soc-2013-ui_replay/source/blender/editors/interface/interface_layout.c	2013-07-25 10:04:05 UTC (rev 58594)
+++ branches/soc-2013-ui_replay/source/blender/editors/interface/interface_layout.c	2013-07-25 10:34:30 UTC (rev 58595)
@@ -698,7 +698,8 @@
 	/* Make sure that if it is indicated a button shouldn't be truncated to a 
 	   single X unit, and a shortcut should be shown, then make sure we get 
 	   the right width. */
-	if(!(flag & UI_ITEM_O_SINGLE_UNIT) && block->flag & UI_BLOCK_SHORTCUTS)
+	if ((!(flag & UI_ITEM_O_SINGLE_UNIT) || flag & UI_ITEM_O_SHORTCUT)
+		&& block->flag & UI_BLOCK_SHORTCUTS)
 		w = ui_text_icon_width(layout, "|", icon, 0);
 	else
 		w = ui_text_icon_width(layout, name, icon, 0);
@@ -724,12 +725,19 @@
 	else {
 		but = uiDefButO_ptr(block, BUT, ot, context, name, 0, 0, w, UI_UNIT_Y, NULL);
 	}
+	
+	/* Only show extra text when we're in a shortcut block and it was
+	   indicated the shortcut should be shown */
+	if (flag & UI_ITEM_O_SHORTCUT && block->flag & UI_BLOCK_SHORTCUTS)
+		but->flag2 |= UI_BUT2_EXTRA_TEXT;
 
 	assert(but->optype != NULL);
 
 	/* text alignment for toolbar buttons */
-	if ((layout->root->type == UI_LAYOUT_TOOLBAR) && !icon)
+	if ((layout->root->type == UI_LAYOUT_TOOLBAR) && (!icon || flag & UI_ITEM_O_SHORTCUT)) {
 		but->flag |= UI_TEXT_LEFT;
+		but->flag |= UI_ICON_LEFT;
+	}
 
 	if (flag & UI_ITEM_R_NO_BG)
 		uiBlockSetEmboss(block, UI_EMBOSS);

Modified: branches/soc-2013-ui_replay/source/blender/editors/interface/interface_widgets.c
===================================================================
--- branches/soc-2013-ui_replay/source/blender/editors/interface/interface_widgets.c	2013-07-25 10:04:05 UTC (rev 58594)
+++ branches/soc-2013-ui_replay/source/blender/editors/interface/interface_widgets.c	2013-07-25 10:34:30 UTC (rev 58595)
@@ -1260,7 +1260,7 @@
 
 	/* part text right aligned 
 	 * only draw if there's enough space */
-	if (cpoin &&
+	if (but->flag2 & UI_BUT2_EXTRA_TEXT && cpoin &&
 		(BLI_rcti_size_x(rect) - BLF_width(fstyle->uifont_id, but->str)) >= 5) {
 		
 		fstyle->align = UI_STYLE_TEXT_RIGHT;

Modified: branches/soc-2013-ui_replay/source/blender/makesrna/intern/rna_ui_api.c
===================================================================
--- branches/soc-2013-ui_replay/source/blender/makesrna/intern/rna_ui_api.c	2013-07-25 10:04:05 UTC (rev 58594)
+++ branches/soc-2013-ui_replay/source/blender/makesrna/intern/rna_ui_api.c	2013-07-25 10:34:30 UTC (rev 58595)
@@ -174,7 +174,7 @@
 }
 
 static PointerRNA rna_uiItemO(uiLayout *layout, const char *opname, const char *name, const char *text_ctxt,
-                              int translate, int icon, int emboss, int single_unit)
+                              int translate, int icon, int emboss, int single_unit, int shortcut)
 {
 	wmOperatorType *ot;
 	int flag;
@@ -192,6 +192,7 @@
 	flag |= (emboss) ? 0 : UI_ITEM_R_NO_BG;
 	
 	if (single_unit) flag |= UI_ITEM_O_SINGLE_UNIT;
+	if (shortcut)	 flag |= UI_ITEM_O_SHORTCUT;
 
 	return uiItemFullO_ptr(layout, ot, name, icon, NULL, uiLayoutGetOperatorContext(layout), flag);
 }
@@ -543,6 +544,7 @@
 	api_ui_item_op_common(func);
 	RNA_def_boolean(func, "emboss", 1, "", "Draw the button itself, just the icon/text");
 	RNA_def_boolean(func, "single_unit", 1, "", "Truncate the button width to a single unit if there is no text");
+	RNA_def_boolean(func, "shortcut", 1, "", "Show the shortcut on the button if there is one");
 	parm = RNA_def_pointer(func, "properties", "OperatorProperties", "",

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list