Commit: a4e07aa825d75c98d277ef0a01c744674ffc8294
Author: Campbell Barton
Date:   Thu Jan 16 20:22:45 2014 +1100
https://developer.blender.org/rBa4e07aa825d75c98d277ef0a01c744674ffc8294

Code Cleanup: outliner used magic numbers for active items and selecting

Replace with enums to make it more obvious whats happening

===================================================================

M       source/blender/editors/space_outliner/outliner_draw.c
M       source/blender/editors/space_outliner/outliner_intern.h
M       source/blender/editors/space_outliner/outliner_select.c

===================================================================

diff --git a/source/blender/editors/space_outliner/outliner_draw.c 
b/source/blender/editors/space_outliner/outliner_draw.c
index 2f877e5..b5d4734 100644
--- a/source/blender/editors/space_outliner/outliner_draw.c
+++ b/source/blender/editors/space_outliner/outliner_draw.c
@@ -480,8 +480,8 @@ static void namebutton_cb(bContext *C, void *tsep, char 
*oldname)
                                        Object *ob;
                                        char newname[sizeof(bone->name)];
                                        
-                                       // always make current object active
-                                       tree_element_active(C, scene, soops, 
te, 1); // was set_active_object()
+                                       /* always make current object active */
+                                       tree_element_active(C, scene, soops, 
te, OL_SETSEL_NORMAL);
                                        ob = OBACT;
                                        
                                        /* restore bone name */
@@ -497,8 +497,8 @@ static void namebutton_cb(bContext *C, void *tsep, char 
*oldname)
                                        Object *ob;
                                        char newname[sizeof(pchan->name)];
                                        
-                                       // always make current object active
-                                       tree_element_active(C, scene, soops, 
te, 1); // was set_active_object()
+                                       /* always make current pose-bone active 
*/
+                                       tree_element_active(C, scene, soops, 
te, OL_SETSEL_NORMAL);
                                        ob = OBACT;
                                        
                                        /* restore bone name */
@@ -1123,7 +1123,7 @@ static void outliner_draw_iconrow(bContext *C, uiBlock 
*block, Scene *scene, Spa
 {
        TreeElement *te;
        TreeStoreElem *tselem;
-       int active;
+       eOLDrawState active;
 
        for (te = lb->first; te; te = te->next) {
                
@@ -1139,20 +1139,20 @@ static void outliner_draw_iconrow(bContext *C, uiBlock 
*block, Scene *scene, Spa
                        /* active blocks get white circle */
                        if (tselem->type == 0) {
                                if (te->idcode == ID_OB) {
-                                       active = (OBACT == (Object 
*)tselem->id);
+                                       active = (OBACT == (Object 
*)tselem->id) ? OL_DRAWSEL_NORMAL : OL_DRAWSEL_NONE;
                                }
                                else if (scene->obedit && scene->obedit->data 
== tselem->id) {
-                                       active = 1;  // XXX use context?
+                                       active = OL_DRAWSEL_NORMAL;
                                }
                                else {
-                                       active = tree_element_active(C, scene, 
soops, te, 0);
+                                       active = tree_element_active(C, scene, 
soops, te, OL_SETSEL_NONE);
                                }
                        }
                        else {
-                               active = tree_element_type_active(NULL, scene, 
soops, te, tselem, 0, false);
+                               active = tree_element_type_active(NULL, scene, 
soops, te, tselem, OL_SETSEL_NONE, false);
                        }
 
-                       if (active) {
+                       if (active != OL_DRAWSEL_NONE) {
                                float ufac = UI_UNIT_X / 20.0f;
 
                                uiSetRoundBox(UI_CNR_ALL);
@@ -1202,7 +1202,8 @@ static void outliner_draw_tree_element(bContext *C, 
uiBlock *block, Scene *scene
        TreeElement *ten;
        TreeStoreElem *tselem;
        float ufac = UI_UNIT_X / 20.0f;
-       int offsx = 0, active = 0; // active=1 active obj, else active data
+       int offsx = 0;
+       eOLDrawState active = OL_DRAWSEL_NONE;
        
        tselem = TREESTORE(te);
 
@@ -1240,7 +1241,7 @@ static void outliner_draw_tree_element(bContext *C, 
uiBlock *block, Scene *scene
                        if (te->idcode == ID_SCE) {
                                if (tselem->id == (ID *)scene) {
                                        glColor4ub(255, 255, 255, alpha);
-                                       active = 2;
+                                       active = OL_DRAWSEL_ACTIVE;
                                }
                        }
                        else if (te->idcode == ID_GR) {
@@ -1251,7 +1252,7 @@ static void outliner_draw_tree_element(bContext *C, 
uiBlock *block, Scene *scene
                                        col[3] = alpha;
                                        glColor4ubv((GLubyte *)col);
                                        
-                                       active = 2;
+                                       active = OL_DRAWSEL_ACTIVE;
                                }
                        }
                        else if (te->idcode == ID_OB) {
@@ -1262,14 +1263,14 @@ static void outliner_draw_tree_element(bContext *C, 
uiBlock *block, Scene *scene
                                        
                                        /* outliner active ob: always white 
text, circle color now similar to view3d */
                                        
-                                       active = 2; /* means it draws a color 
circle */
+                                       active = OL_DRAWSEL_ACTIVE;
                                        if (ob == OBACT) {
                                                if (ob->flag & SELECT) {
                                                        
UI_GetThemeColorType4ubv(TH_ACTIVE, SPACE_VIEW3D, col);
                                                        col[3] = alpha;
                                                }
                                                
-                                               active = 1; /* means it draws 
white text */
+                                               active = OL_DRAWSEL_NORMAL;
                                        }
                                        else if (ob->flag & SELECT) {
                                                
UI_GetThemeColorType4ubv(TH_SELECT, SPACE_VIEW3D, col);
@@ -1282,22 +1283,24 @@ static void outliner_draw_tree_element(bContext *C, 
uiBlock *block, Scene *scene
                        }
                        else if (scene->obedit && scene->obedit->data == 
tselem->id) {
                                glColor4ub(255, 255, 255, alpha);
-                               active = 2;
+                               active = OL_DRAWSEL_ACTIVE;
                        }
                        else {
-                               if (tree_element_active(C, scene, soops, te, 
0)) {
+                               if (tree_element_active(C, scene, soops, te, 
OL_SETSEL_NONE)) {
                                        glColor4ub(220, 220, 255, alpha);
-                                       active = 2;
+                                       active = OL_DRAWSEL_ACTIVE;
                                }
                        }
                }
                else {
-                       if (tree_element_type_active(NULL, scene, soops, te, 
tselem, 0, false)) active = 2;
+                       if (tree_element_type_active(NULL, scene, soops, te, 
tselem, OL_SETSEL_NONE, false) != OL_DRAWSEL_NONE) {
+                               active = OL_DRAWSEL_ACTIVE;
+                       }
                        glColor4ub(220, 220, 255, alpha);
                }
                
                /* active circle */
-               if (active) {
+               if (active != OL_DRAWSEL_NONE) {
                        uiSetRoundBox(UI_CNR_ALL);
                        uiRoundBox((float)startx + UI_UNIT_X,
                                   (float)*starty + 1.0f * ufac,
@@ -1348,7 +1351,7 @@ static void outliner_draw_tree_element(bContext *C, 
uiBlock *block, Scene *scene
                glDisable(GL_BLEND);
                
                /* name */
-               if (active == 1) UI_ThemeColor(TH_TEXT_HI);
+               if (active == OL_DRAWSEL_NORMAL) UI_ThemeColor(TH_TEXT_HI);
                else if (ELEM(tselem->type, TSE_RNA_PROPERTY, 
TSE_RNA_ARRAY_ELEM)) UI_ThemeColorBlend(TH_BACK, TH_TEXT, 0.75f);
                else UI_ThemeColor(TH_TEXT);
                
diff --git a/source/blender/editors/space_outliner/outliner_intern.h 
b/source/blender/editors/space_outliner/outliner_intern.h
index 015d8d6..34d7f87 100644
--- a/source/blender/editors/space_outliner/outliner_intern.h
+++ b/source/blender/editors/space_outliner/outliner_intern.h
@@ -108,6 +108,18 @@ typedef struct TreeElement {
 /* button events */
 #define OL_NAMEBUTTON       1
 
+typedef enum {
+       OL_DRAWSEL_NONE    = 0,  /* inactive (regular black text) */
+       OL_DRAWSEL_NORMAL  = 1,  /* active object (draws white text) */
+       OL_DRAWSEL_ACTIVE  = 2,  /* active obdata (draws a circle around the 
icon) */
+} eOLDrawState;
+
+typedef enum {
+       OL_SETSEL_NONE     = 0,  /* don't change the selection state */
+       OL_SETSEL_NORMAL   = 1,  /* select the item */
+       OL_SETSEL_EXTEND   = 2,  /* select the item and extend (also toggles 
selection) */
+} eOLSetState;
+
 /* get TreeStoreElem associated with a TreeElement 
  * < a: (TreeElement) tree element to find stored element for
  */
@@ -166,8 +178,12 @@ void draw_outliner(const struct bContext *C);
 void restrictbutton_gr_restrict_flag(void *poin, void *poin2, int flag);
 
 /* outliner_select.c -------------------------------------------- */
-int tree_element_type_active(struct bContext *C, struct Scene *scene, struct 
SpaceOops *soops, TreeElement *te, TreeStoreElem *tselem, int set, bool 
recursive);
-int tree_element_active(struct bContext *C, struct Scene *scene, SpaceOops 
*soops, TreeElement *te, int set);
+eOLDrawState tree_element_type_active(
+        struct bContext *C, struct Scene *scene, struct SpaceOops *soops,
+        TreeElement *te, TreeStoreElem *tselem, const eOLSetState set, bool 
recursive);
+eOLDrawState tree_element_active(
+        struct bContext *C, struct Scene *scene, SpaceOops *soops,
+        TreeElement *te, const eOLSetState set);
 int outliner_item_do_activate(struct bContext *C, int x, int y, bool extend, 
bool recursive);
 
 /* outliner_edit.c ---------------------------------------------- */
@@ -177,7 +193,7 @@ void outliner_do_object_operation(struct bContext *C, 
struct Scene *scene, struc
 
 int common_restrict_check(struct bContext *C, struct Object *ob);
 
-bool outliner_has_one_flag(struct SpaceOops *soops, ListBase *lb, short flag, 
const int curlevel);
+int outliner_has_one_flag(struct SpaceOops *soops, ListBase *lb, short flag, 
const int curlevel);
 void outliner_set_flag(struct SpaceOops *soops, ListBase *lb, short flag, 
short set);
 
 void object_toggle_visibility_cb(struct bContext *C, struct Scene *scene, 
TreeElement *te, struct TreeStoreElem *tsep, struct TreeStoreElem *tselem);
diff --git a/source/blender/editors/space_outliner/outliner_select.c 
b/source/blender/editors/space_outliner/outliner_select.c
index b10b8a4..688695e 100644
--- a/source/blender/editors/space_outliner/outliner_select.c
+++ b/source/blender/editors/space_outliner/outliner_select.c
@@ -124,23 +124,24 @@ static int outliner_select(SpaceOops *soops, ListBase 
*lb, int *index, short *se
 /* ****************************************************** */
 /* Outliner Element Selection/Activation on Click */
 
-static int tree_element_active_renderlayer(bContext *C, TreeElement *te, 
TreeStoreElem *tselem, int set)
+static eOLDrawState tree_element_active_renderlayer(
+        bContext *C, TreeElement *te, TreeStoreElem *tselem, const eOLSetState 
set)
 {
        Scene *sce;
        
        /* paranoia check */
        if (te->idcode != ID_SCE)
-               return 0;
+               return OL_DRAWSEL_NONE;
        sce = (Scene *)tselem->id;
        
-       if (set) {
+       if (set != OL_SETSEL_NONE) {
                sce->r.actlay = tselem->nr;
                WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, sce);
        }
        else {
                return sce->r.actlay == tselem->nr;
        }
-       return 0;
+       return OL_DRAWSEL_NONE;
 }
 
 /**
@@ -185,8 +186,9 @@ static void do_outliner_ebone_select_recursive(bArmature 
*arm, EditBone *ebone_p
        }
 }
 
-static int  tree_element_set_active_object(bContext *C, Scene *scene, 
SpaceOops *soops,
-                                           TreeElement *te, int set, bool 
recursive)
+static eOLDrawState tree_element_set_active_object(
+        bContext *C, Scene *scene, SpaceOops *soops,
+        TreeElement *te, const eOLSetState set, bool recursive)
 {
        TreeStoreElem *tselem = TREESTORE(te);
        Scene *sce;
@@ -199,9 +201,13 @@ static int  tree_element_set_active_object(bContext *C, 
Scene *scene, SpaceOops
        }
        else {
                ob = (Object *)outliner_search_back(soops, te, ID_OB);
-               if (ob == OBACT) return 0;
+               if (ob == OBACT) {
+                       return OL_DRAWSEL_NONE;
+               }
+       }
+       if (ob == NULL) {
+               return OL_DRAWSEL_NONE;
        }
-       if (ob == NULL) return 0;
        
        sce = (Scene *)outliner_search_back(soops, te, ID_SCE);
        if (sce && scene != sce) {
@@ -213,7 +219,7 @@ static int  tree_element_set_active_object(bContext *C, 
Scene *scene, SpaceOops
        base = BKE_scene_base_find(scene, ob);
 
        if (base) {
-               if (set == 2) {
+               if (set == OL_SETSEL_EXTEN

@@ 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