Revision: 33676
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=33676
Author:   campbellbarton
Date:     2010-12-15 06:42:23 +0100 (Wed, 15 Dec 2010)

Log Message:
-----------
Centralized operator UI drawing into a new function uiLayoutOperatorButs(),
  Operator drawing calls were duplicated in file selector panel, redo panels, 
redo & dialog popups.

note, uiDefAutoButsRNA's column's argument was misleading, renamed to 
label_align.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/include/UI_interface.h
    trunk/blender/source/blender/editors/interface/interface_layout.c
    trunk/blender/source/blender/editors/interface/interface_utils.c
    trunk/blender/source/blender/editors/space_file/file_panels.c
    trunk/blender/source/blender/editors/space_view3d/view3d_buttons.c
    trunk/blender/source/blender/editors/space_view3d/view3d_toolbar.c
    trunk/blender/source/blender/windowmanager/intern/wm_operators.c

Modified: trunk/blender/source/blender/editors/include/UI_interface.h
===================================================================
--- trunk/blender/source/blender/editors/include/UI_interface.h 2010-12-15 
04:06:19 UTC (rev 33675)
+++ trunk/blender/source/blender/editors/include/UI_interface.h 2010-12-15 
05:42:23 UTC (rev 33676)
@@ -496,7 +496,7 @@
 void uiBlockPickerButtons(struct uiBlock *block, float *col, float *hsv, float 
*old, char *hexcol, char mode, short retval);
 
 uiBut *uiDefAutoButR(uiBlock *block, struct PointerRNA *ptr, struct 
PropertyRNA *prop, int index, const char *name, int icon, int x1, int y1, int 
x2, int y2);
-void uiDefAutoButsRNA(uiLayout *layout, struct PointerRNA *ptr, int columns);
+int uiDefAutoButsRNA(uiLayout *layout, struct PointerRNA *ptr, int 
(*check_prop)(struct PropertyRNA *), const char label_align);
 
 /* Links
  *
@@ -633,6 +633,10 @@
 #define UI_ITEM_R_NO_BG                        128
 #define UI_ITEM_R_IMMEDIATE            256
 
+/* uiLayoutOperatorButs flags */
+#define UI_LAYOUT_OP_SHOW_TITLE 1
+#define UI_LAYOUT_OP_SHOW_EMPTY 2
+
 uiLayout *uiBlockLayout(uiBlock *block, int dir, int type, int x, int y, int 
size, int em, struct uiStyle *style);
 void uiBlockSetCurLayout(uiBlock *block, uiLayout *layout);
 void uiBlockLayoutResolve(uiBlock *block, int *x, int *y);
@@ -642,6 +646,7 @@
 void uiLayoutSetFunc(uiLayout *layout, uiMenuHandleFunc handlefunc, void 
*argv);
 void uiLayoutSetContextPointer(uiLayout *layout, const char *name, struct 
PointerRNA *ptr);
 const char *uiLayoutIntrospect(uiLayout *layout); // XXX - testing
+void uiLayoutOperatorButs(const struct bContext *C, struct uiLayout *layout, 
struct wmOperator *op, int (*check_prop)(struct PropertyRNA *), const char 
label_align, const short flag);
 
 void uiLayoutSetOperatorContext(uiLayout *layout, int opcontext);
 void uiLayoutSetActive(uiLayout *layout, int active);

Modified: trunk/blender/source/blender/editors/interface/interface_layout.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_layout.c   
2010-12-15 04:06:19 UTC (rev 33675)
+++ trunk/blender/source/blender/editors/interface/interface_layout.c   
2010-12-15 05:42:23 UTC (rev 33676)
@@ -2664,3 +2664,45 @@
 
        return str;
 }
+
+/* this function does not initialize the layout, functions can be called on 
the layout before and after */
+void uiLayoutOperatorButs(const bContext *C, uiLayout *layout, wmOperator 
*op,int (*check_prop)(struct PropertyRNA *), const char label_align, const 
short flag)
+{
+       if(!op->properties) {
+               IDPropertyTemplate val = {0};
+               op->properties= IDP_New(IDP_GROUP, val, "wmOperatorProperties");
+       }
+
+       if(flag & UI_LAYOUT_OP_SHOW_TITLE) {
+               uiItemL(layout, op->type->name, 0);
+       }
+
+       /* poll() on this operator may still fail, at the moment there is no 
nice feedback when this happens
+        * just fails silently */
+       if(!WM_operator_repeat_check(C, op)) {
+               uiBlockSetButLock(uiLayoutGetBlock(layout), TRUE, "Operator 
cannot redo");
+               uiItemL(layout, "* Redo Unsupported *", 0); // XXX, could give 
some nicer feedback or not show redo panel at all?
+       }
+
+       if(op->type->ui) {
+               op->layout= layout;
+               op->type->ui((bContext*)C, op);
+               op->layout= NULL;
+
+               /* UI_LAYOUT_OP_SHOW_EMPTY ignored */
+       }
+       else {
+               wmWindowManager *wm= CTX_wm_manager(C);
+               PointerRNA ptr;
+               int empty;
+
+               RNA_pointer_create(&wm->id, op->type->srna, op->properties, 
&ptr);
+               
+               /* main draw call */
+               empty= uiDefAutoButsRNA(layout, &ptr, check_prop, label_align) 
== 0;
+
+               if(empty && (flag & UI_LAYOUT_OP_SHOW_EMPTY)) {
+                       uiItemL(layout, "No Properties.", 0);
+               }
+       }
+}

Modified: trunk/blender/source/blender/editors/interface/interface_utils.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_utils.c    
2010-12-15 04:06:19 UTC (rev 33675)
+++ trunk/blender/source/blender/editors/interface/interface_utils.c    
2010-12-15 05:42:23 UTC (rev 33676)
@@ -26,6 +26,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <assert.h>
 
 #include "DNA_object_types.h"
 
@@ -131,35 +132,50 @@
        return but;
 }
 
-void uiDefAutoButsRNA(uiLayout *layout, PointerRNA *ptr, int columns)
+int uiDefAutoButsRNA(uiLayout *layout, PointerRNA *ptr, int 
(*check_prop)(PropertyRNA *), const char label_align)
 {
        uiLayout *split, *col;
        int flag;
-       char *name;
+       const char *name;
+       int tot= 0;
 
+       assert(ELEM3(label_align, '\0', 'H', 'V'));
+
        RNA_STRUCT_BEGIN(ptr, prop) {
                flag= RNA_property_flag(prop);
-               if(flag & PROP_HIDDEN)
+               if(flag & PROP_HIDDEN || (check_prop && 
check_prop(prop)==FALSE))
                        continue;
 
-               name= (char*)RNA_property_ui_name(prop);
+               if(label_align != '\0') {
+                       name= RNA_property_ui_name(prop);
 
-               if(columns == 1) {
-                       col= uiLayoutColumn(layout, 1);
-                       uiItemL(col, name, 0);
-               }
-               else if(columns == 2) {
-                       split = uiLayoutSplit(layout, 0.5f, 0);
+                       if(label_align=='V') {
+                               col= uiLayoutColumn(layout, 1);
+                               uiItemL(col, name, 0);
+                       }
+                       else if(label_align=='H') {
+                               split = uiLayoutSplit(layout, 0.5f, 0);
 
-                       uiItemL(uiLayoutColumn(split, 0), name, 0);
-                       col= uiLayoutColumn(split, 0);
+                               uiItemL(uiLayoutColumn(split, 0), name, 0);
+                               col= uiLayoutColumn(split, 0);
+                       }
+                       else {
+                               col= NULL;
+                       }
+
+                       name= ""; /* name is shown above, empty name for button 
below */
                }
-               else
-                       col= NULL;
+               else {
+                       col= layout;
+                       name= NULL; /* no smart label alignment, show default 
name with button */
+               }
 
-               uiItemFullR(col, ptr, prop, -1, 0, 0, "", 0);
+               uiItemFullR(col, ptr, prop, -1, 0, 0, name, 0);
+               tot++;
        }
        RNA_STRUCT_END;
+
+       return tot;
 }
 
 /***************************** ID Utilities *******************************/

Modified: trunk/blender/source/blender/editors/space_file/file_panels.c
===================================================================
--- trunk/blender/source/blender/editors/space_file/file_panels.c       
2010-12-15 04:06:19 UTC (rev 33675)
+++ trunk/blender/source/blender/editors/space_file/file_panels.c       
2010-12-15 05:42:23 UTC (rev 33676)
@@ -171,41 +171,25 @@
        BLI_strncpy(pa->drawname, op->type->name, sizeof(pa->drawname));
 }
 
+static int file_panel_check_prop(PropertyRNA *prop)
+{
+       const char *prop_id= RNA_property_identifier(prop);
+       return !(       strcmp(prop_id, "filepath") == 0 ||
+                               strcmp(prop_id, "directory") == 0 ||
+                               strcmp(prop_id, "filename") == 0
+       );
+}
+
 static void file_panel_operator(const bContext *C, Panel *pa)
 {
        SpaceFile *sfile= CTX_wm_space_file(C);
        wmOperator *op= sfile->op;
-       int empty= 1, flag;
+       // int empty= 1, flag;
        
        uiBlockSetFunc(uiLayoutGetBlock(pa->layout), file_draw_check_cb, NULL, 
NULL);
-       
-       if(op->type->ui) {
-               op->layout= pa->layout;
-               op->type->ui((bContext*)C, op);
-               op->layout= NULL;
-       }
-       else {
-               RNA_STRUCT_BEGIN(op->ptr, prop) {
-                       flag= RNA_property_flag(prop);
 
-                       if(flag & PROP_HIDDEN)
-                               continue;
-                       if(strcmp(RNA_property_identifier(prop), "filepath") == 
0)
-                               continue;
-                       if(strcmp(RNA_property_identifier(prop), "directory") 
== 0)
-                               continue;
-                       if(strcmp(RNA_property_identifier(prop), "filename") == 
0)
-                               continue;
+       uiLayoutOperatorButs(C, pa->layout, op, file_panel_check_prop, '\0', 
UI_LAYOUT_OP_SHOW_EMPTY);
 
-                       uiItemFullR(pa->layout, op->ptr, prop, -1, 0, 0, NULL, 
0);
-                       empty= 0;
-               }
-               RNA_STRUCT_END;
-
-               if(empty)
-                       uiItemL(pa->layout, "No properties.", 0);
-       }
-       
        uiBlockSetFunc(uiLayoutGetBlock(pa->layout), NULL, NULL, NULL);
 }
 

Modified: trunk/blender/source/blender/editors/space_view3d/view3d_buttons.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_buttons.c  
2010-12-15 04:06:19 UTC (rev 33675)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_buttons.c  
2010-12-15 05:42:23 UTC (rev 33676)
@@ -1392,33 +1392,6 @@
        uiBlockEndAlign(block);
 }
 
-static void view3d_panel_operator_redo(const bContext *C, Panel *pa)
-{
-       wmWindowManager *wm= CTX_wm_manager(C);
-       wmOperator *op;
-       PointerRNA ptr;
-       uiBlock *block;
-       
-       block= uiLayoutGetBlock(pa->layout);
-
-       /* only for operators that are registered and did an undo push */
-       for(op= wm->operators.last; op; op= op->prev)
-               if((op->type->flag & OPTYPE_REGISTER) && (op->type->flag & 
OPTYPE_UNDO))
-                       break;
-       
-       if(op==NULL)
-               return;
-       
-       uiBlockSetFunc(block, ED_undo_operator_repeat_cb, op, NULL);
-       
-       if(!op->properties) {
-               IDPropertyTemplate val = {0};
-               op->properties= IDP_New(IDP_GROUP, val, "wmOperatorProperties");
-       }
-       
-       RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr);
-       uiDefAutoButsRNA(pa->layout, &ptr, 2);
-}
 #endif // XXX not used
 
 void view3d_buttons_register(ARegionType *art)

Modified: trunk/blender/source/blender/editors/space_view3d/view3d_toolbar.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_toolbar.c  
2010-12-15 04:06:19 UTC (rev 33675)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_toolbar.c  
2010-12-15 05:42:23 UTC (rev 33676)
@@ -78,29 +78,7 @@
 
 static void view3d_panel_operator_redo_buts(const bContext *C, Panel *pa, 
wmOperator *op)
 {
-       wmWindowManager *wm= CTX_wm_manager(C);
-       PointerRNA ptr;
-       
-       if(!op->properties) {
-               IDPropertyTemplate val = {0};
-               op->properties= IDP_New(IDP_GROUP, val, "wmOperatorProperties");
-       }
-       
-       /* poll() on this operator may still fail, at the moment there is no 
nice feedback when this happens
-        * just fails silently */
-       if(!WM_operator_repeat_check(C, op)) {
-               uiBlockSetButLock(uiLayoutGetBlock(pa->layout), TRUE, "Operator 
cannot redo");
-               uiItemL(pa->layout, "* Redo Unsupported *", 0); // XXX, could 
give some nicer feedback or not show redo panel at all?
-       }
-
-       RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr);
-       if(op->type->ui) {
-               op->layout= pa->layout;
-               op->type->ui((bContext*)C, op);
-               op->layout= NULL;
-       }
-       else
-               uiDefAutoButsRNA(pa->layout, &ptr, 1);
+       uiLayoutOperatorButs(C, pa->layout, op, NULL, 'V', 0);
 }
 
 static void view3d_panel_operator_redo_header(const bContext *C, Panel *pa)

Modified: trunk/blender/source/blender/windowmanager/intern/wm_operators.c
===================================================================
--- trunk/blender/source/blender/windowmanager/intern/wm_operators.c    
2010-12-15 04:06:19 UTC (rev 33675)

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to