Revision: 59849
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59849
Author:   ack-err
Date:     2013-09-05 17:25:26 +0000 (Thu, 05 Sep 2013)
Log Message:
-----------
Started to implement operator to icon pairing. 

* wmOperatorType has an extra icon() method that is used to determine which 
icon to use based on the operator properties set for a button.
* wmOperatorType has a default_icon field, exposed to python as bl_icon, that 
is used if the icon() function is not set.
* Buttons have to have a but->icon value of ICON_AUTOMATIC, which is -1.

Modified Paths:
--------------
    branches/soc-2013-ui_replay/source/blender/editors/gpencil/gpencil_buttons.c
    branches/soc-2013-ui_replay/source/blender/editors/gpencil/gpencil_paint.c
    branches/soc-2013-ui_replay/source/blender/editors/include/UI_icons.h
    
branches/soc-2013-ui_replay/source/blender/editors/interface/interface_handlers.c
    
branches/soc-2013-ui_replay/source/blender/editors/interface/interface_widgets.c
    
branches/soc-2013-ui_replay/source/blender/editors/space_view3d/view3d_toolbar.c
    branches/soc-2013-ui_replay/source/blender/makesrna/intern/rna_wm.c
    branches/soc-2013-ui_replay/source/blender/windowmanager/WM_types.h

Modified: 
branches/soc-2013-ui_replay/source/blender/editors/gpencil/gpencil_buttons.c
===================================================================
--- 
branches/soc-2013-ui_replay/source/blender/editors/gpencil/gpencil_buttons.c    
    2013-09-05 17:13:43 UTC (rev 59848)
+++ 
branches/soc-2013-ui_replay/source/blender/editors/gpencil/gpencil_buttons.c    
    2013-09-05 17:25:26 UTC (rev 59849)
@@ -295,16 +295,16 @@
        ot = WM_operatortype_find("GPENCIL_OT_draw", 0);
        row = uiLayoutRowWithButtonHeight(layout, TRUE, 1.5f);
        
-       ptr = uiItemFullO_ptr(row, ot, "", ICON_GREASE_DRAW, NULL, 
uiLayoutGetOperatorContext(layout), UI_ITEM_O_RETURN_PROPS);
+       ptr = uiItemFullO_ptr(row, ot, "", ICON_AUTOMATIC, NULL, 
uiLayoutGetOperatorContext(layout), UI_ITEM_O_RETURN_PROPS);
        RNA_enum_set(&ptr, "mode", GP_PAINTMODE_DRAW);
        
-       ptr = uiItemFullO_ptr(row, WM_operatortype_find("GPENCIL_OT_draw", 0), 
"", ICON_GREASE_LINE, NULL, uiLayoutGetOperatorContext(layout), 
UI_ITEM_O_RETURN_PROPS);
+       ptr = uiItemFullO_ptr(row, WM_operatortype_find("GPENCIL_OT_draw", 0), 
"", ICON_AUTOMATIC, NULL, uiLayoutGetOperatorContext(layout), 
UI_ITEM_O_RETURN_PROPS);
        RNA_enum_set(&ptr, "mode", GP_PAINTMODE_DRAW_STRAIGHT);
        
-       ptr = uiItemFullO_ptr(row, WM_operatortype_find("GPENCIL_OT_draw", 0), 
"", ICON_GREASE_POLY, NULL, uiLayoutGetOperatorContext(layout), 
UI_ITEM_O_RETURN_PROPS);
+       ptr = uiItemFullO_ptr(row, WM_operatortype_find("GPENCIL_OT_draw", 0), 
"", ICON_AUTOMATIC, NULL, uiLayoutGetOperatorContext(layout), 
UI_ITEM_O_RETURN_PROPS);
        RNA_enum_set(&ptr, "mode", GP_PAINTMODE_DRAW_POLY);
        
-       ptr = uiItemFullO_ptr(row, WM_operatortype_find("GPENCIL_OT_draw", 0), 
"", ICON_GREASE_ERASE, NULL, uiLayoutGetOperatorContext(layout), 
UI_ITEM_O_RETURN_PROPS);
+       ptr = uiItemFullO_ptr(row, WM_operatortype_find("GPENCIL_OT_draw", 0), 
"", ICON_AUTOMATIC, NULL, uiLayoutGetOperatorContext(layout), 
UI_ITEM_O_RETURN_PROPS);
        RNA_enum_set(&ptr, "mode", GP_PAINTMODE_ERASER);
        
        row = uiLayoutRow(layout, TRUE);

Modified: 
branches/soc-2013-ui_replay/source/blender/editors/gpencil/gpencil_paint.c
===================================================================
--- branches/soc-2013-ui_replay/source/blender/editors/gpencil/gpencil_paint.c  
2013-09-05 17:13:43 UTC (rev 59848)
+++ branches/soc-2013-ui_replay/source/blender/editors/gpencil/gpencil_paint.c  
2013-09-05 17:25:26 UTC (rev 59849)
@@ -70,6 +70,8 @@
 #include "WM_api.h"
 #include "WM_types.h"
 
+#include "UI_resources.h"
+
 #include "gpencil_intern.h"
 
 /* ******************************************* */
@@ -2030,6 +2032,23 @@
        {0, NULL, 0, NULL, NULL}
 };
 
+
+static int gpencil_draw_icon(const bContext *UNUSED(C), PointerRNA *opptr)
+{
+       if (opptr) {
+               switch (RNA_enum_get(opptr, "mode")) {
+                       case GP_PAINTMODE_DRAW: return ICON_GREASE_DRAW;
+                       case GP_PAINTMODE_DRAW_STRAIGHT: return 
ICON_GREASE_LINE;
+                       case GP_PAINTMODE_DRAW_POLY:
+                               return ICON_GREASE_POLY;
+                       case GP_PAINTMODE_ERASER:
+                               return ICON_GREASE_ERASE;
+               }
+       }
+               
+       return ICON_GREASEPENCIL;
+}
+
 void GPENCIL_OT_draw(wmOperatorType *ot)
 {
        /* identifiers */
@@ -2043,6 +2062,7 @@
        ot->modal = gpencil_draw_modal;
        ot->cancel = gpencil_draw_cancel;
        ot->poll = gpencil_draw_poll;
+       ot->icon = gpencil_draw_icon;
        
        /* flags */
        ot->flag = OPTYPE_UNDO | OPTYPE_BLOCKING;

Modified: branches/soc-2013-ui_replay/source/blender/editors/include/UI_icons.h
===================================================================
--- branches/soc-2013-ui_replay/source/blender/editors/include/UI_icons.h       
2013-09-05 17:13:43 UTC (rev 59848)
+++ branches/soc-2013-ui_replay/source/blender/editors/include/UI_icons.h       
2013-09-05 17:25:26 UTC (rev 59849)
@@ -32,6 +32,10 @@
  * once from UI_resources.h for the internal icon enum and
  * once for interface_api.c for the definition of the RNA enum for the icons */
 
+#ifndef ICON_AUTOMATIC
+#define ICON_AUTOMATIC -1
+#endif
+
 /* ICON_ prefix added */
 DEF_ICON(NONE)
 DEF_ICON(QUESTION)

Modified: 
branches/soc-2013-ui_replay/source/blender/editors/interface/interface_handlers.c
===================================================================
--- 
branches/soc-2013-ui_replay/source/blender/editors/interface/interface_handlers.c
   2013-09-05 17:13:43 UTC (rev 59848)
+++ 
branches/soc-2013-ui_replay/source/blender/editors/interface/interface_handlers.c
   2013-09-05 17:25:26 UTC (rev 59849)
@@ -5065,11 +5065,11 @@
        uiPupBlock(C, menu_add_shortcut, but);
 }
 
-static void ui_but_menu_set_last_properties(bContext *UNUSED(C), void *arg_op, 
int UNUSED(arg_event))
-{
-       wmOperator *op = (wmOperator*)arg_op;
-       WM_operator_default_properties_store(op);
-}
+//static void ui_but_menu_set_last_properties(bContext *UNUSED(C), void 
*arg_op, int UNUSED(arg_event))
+//{
+//     wmOperator *op = (wmOperator*)arg_op;
+//     WM_operator_default_properties_store(op);
+//}
 
 static void remove_from_custom_panel(bContext *UNUSED(C), void *arg_pa, void 
*arg_optype)
 {
@@ -5284,7 +5284,7 @@
                wmKeyMap *km;
                wmKeyMapItem *kmi = NULL;
                int kmi_id = WM_key_event_operator_id(C, but->optype->idname, 
but->opcontext, prop, 1, &km);
-               wmOperator *op;
+//             wmOperator *op;
                
                uiItemS(layout);
                

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-09-05 17:13:43 UTC (rev 59848)
+++ 
branches/soc-2013-ui_replay/source/blender/editors/interface/interface_widgets.c
    2013-09-05 17:25:26 UTC (rev 59849)
@@ -54,6 +54,8 @@
 
 #include "BLF_api.h"
 
+#include "WM_types.h"
+
 #include "UI_interface.h"
 #include "UI_interface_icons.h"
 
@@ -3212,6 +3214,21 @@
        ThemeUI *tui = &btheme->tui;
        uiFontStyle *fstyle = &style->widget;
        uiWidgetType *wt = NULL;
+       
+       /* in case we have an automatic icon, let's set it here */
+       if (but->icon && but->icon == ICON_AUTOMATIC) {
+               int icon = ICON_NONE;
+               
+               if (but->optype) {
+                       if (but->optype->icon && but->opptr) {
+                               icon = but->optype->icon(C, but->opptr);
+                       }
+                       else if (but->optype->default_icon) {
+                               icon = but->optype->default_icon;
+                       }
+               }
+               but->icon = icon;
+       }
 
        /* handle menus separately */
        if (but->dt == UI_EMBOSSP) {

Modified: 
branches/soc-2013-ui_replay/source/blender/editors/space_view3d/view3d_toolbar.c
===================================================================
--- 
branches/soc-2013-ui_replay/source/blender/editors/space_view3d/view3d_toolbar.c
    2013-09-05 17:13:43 UTC (rev 59848)
+++ 
branches/soc-2013-ui_replay/source/blender/editors/space_view3d/view3d_toolbar.c
    2013-09-05 17:25:26 UTC (rev 59849)
@@ -165,10 +165,8 @@
                        || (pa->type->poll && !pa->type->poll(C, pa->type)))
                        continue;
                
-               // TODO: sort order
-               
                uiLayoutRow(col, TRUE);
-               but = uiDefButBitI(block, OPTIONN, 1, 0, pa->drawname, 0, 0, 
width, UI_UNIT_Y, (int*)&pa->hidden, 0, 0, 0, 0, "Check to hide panel");
+               but = uiDefButBitI(block, OPTIONN, 1, 0, pa->drawname, 0, 0, 
width, UI_UNIT_Y, (int*)&pa->hidden, 0, 0, 0, 0, "Uncheck to hide panel");
        }
        CTX_wm_region_set(C, cur_ar);
        

Modified: branches/soc-2013-ui_replay/source/blender/makesrna/intern/rna_wm.c
===================================================================
--- branches/soc-2013-ui_replay/source/blender/makesrna/intern/rna_wm.c 
2013-09-05 17:13:43 UTC (rev 59848)
+++ branches/soc-2013-ui_replay/source/blender/makesrna/intern/rna_wm.c 
2013-09-05 17:25:26 UTC (rev 59849)
@@ -1424,6 +1424,12 @@
        RNA_def_property_enum_items(prop, operator_flag_items);
        RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL | PROP_ENUM_FLAG);
        RNA_def_property_ui_text(prop, "Options",  "Options for this operator 
type");
+       
+       prop = RNA_def_property(srna, "bl_icon", PROP_ENUM, PROP_NONE);
+       RNA_def_property_enum_sdna(prop, NULL, "type->default_icon");
+       RNA_def_property_enum_items(prop, icon_items); /* TODO: 
operator_icon_items */
+       RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL | PROP_ENUM_FLAG);
+       RNA_def_property_ui_text(prop, "Icon",  "Default icon for this operator 
type");
 
        RNA_api_operator(srna);
 

Modified: branches/soc-2013-ui_replay/source/blender/windowmanager/WM_types.h
===================================================================
--- branches/soc-2013-ui_replay/source/blender/windowmanager/WM_types.h 
2013-09-05 17:13:43 UTC (rev 59848)
+++ branches/soc-2013-ui_replay/source/blender/windowmanager/WM_types.h 
2013-09-05 17:25:26 UTC (rev 59849)
@@ -545,6 +545,9 @@
 
        /* optional panel for redo and repeat, autogenerated if not set */
        void (*ui)(struct bContext *, struct wmOperator *);
+       
+       /* optional function to decide which icon to use based on operator 
properties */
+       int (*icon)(const struct bContext *, PointerRNA *);
 
        /* rna for properties */
        struct StructRNA *srna;
@@ -576,6 +579,7 @@
 
        /* Flag last for padding */
        short flag;
+       int default_icon;
 
 } wmOperatorType;
 

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to