Merged changes in the trunk up to revision 49986.
[blender.git] / source / blender / editors / space_view3d / drawobject.c
index ff1b3e75d0848bc385154cd745646d9db8a4b297..a3041c969738fbb7c18d2190384fdf4a29e25d73 100644 (file)
@@ -193,6 +193,17 @@ static void drawcircle_size(float size);
 static void draw_empty_sphere(float size);
 static void draw_empty_cone(float size);
 
+static void ob_wire_color_blend_theme_id(const unsigned char ob_wire_col[4], const int theme_id, float fac)
+{
+       float col_wire[3], col_bg[3], col[3];
+
+       rgb_uchar_to_float(col_wire, ob_wire_col);
+
+       UI_GetThemeColor3fv(theme_id, col_bg);
+       interp_v3_v3v3(col, col_bg, col_wire, fac);
+       glColor3fv(col);
+}
+
 /* this condition has been made more complex since editmode can draw textures */
 static int check_object_draw_texture(Scene *scene, View3D *v3d, int drawtype)
 {
@@ -653,7 +664,7 @@ void drawaxes(float size, char drawtype)
 
 
 /* Function to draw an Image on a empty Object */
-static void draw_empty_image(Object *ob)
+static void draw_empty_image(Object *ob, const short dflag, const unsigned char ob_wire_col[4])
 {
        Image *ima = (Image *)ob->data;
        ImBuf *ibuf = ima ? BKE_image_get_ibuf(ima, NULL) : NULL;
@@ -726,15 +737,17 @@ static void draw_empty_image(Object *ob)
                glDisable(GL_BLEND);
        }
 
-       UI_ThemeColor((ob->flag & SELECT) ? TH_SELECT : TH_WIRE);
+       if ((dflag & DRAW_CONSTCOLOR) == 0) {
+               glColor3ubv(ob_wire_col);
 
-       /* Calculate the outline vertex positions */
-       glBegin(GL_LINE_LOOP);
-       glVertex2f(ofs_x, ofs_y);
-       glVertex2f(ofs_x + ima_x, ofs_y);
-       glVertex2f(ofs_x + ima_x, ofs_y + ima_y);
-       glVertex2f(ofs_x, ofs_y + ima_y);
-       glEnd();
+               /* Calculate the outline vertex positions */
+               glBegin(GL_LINE_LOOP);
+               glVertex2f(ofs_x, ofs_y);
+               glVertex2f(ofs_x + ima_x, ofs_y);
+               glVertex2f(ofs_x + ima_x, ofs_y + ima_y);
+               glVertex2f(ofs_x, ofs_y + ima_y);
+               glEnd();
+       }
 
        /* Reset GL settings */
        glMatrixMode(GL_MODELVIEW);
@@ -1559,17 +1572,18 @@ static void draw_bundle_sphere(void)
 
 static void draw_viewport_object_reconstruction(Scene *scene, Base *base, View3D *v3d,
                                                 MovieClip *clip, MovieTrackingObject *tracking_object,
-                                                const short dflag, int *global_track_index, int draw_selected)
+                                                const short dflag, const unsigned char ob_wire_col[4],
+                                                int *global_track_index, int draw_selected)
 {
        MovieTracking *tracking = &clip->tracking;
        MovieTrackingTrack *track;
        float mat[4][4], imat[4][4];
-       unsigned char col[4], scol[4];
+       unsigned char col_unsel[4], col_sel[4];
        int tracknr = *global_track_index;
        ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, tracking_object);
 
-       UI_GetThemeColor4ubv(TH_TEXT, col);
-       UI_GetThemeColor4ubv(TH_SELECT, scol);
+       UI_GetThemeColor4ubv(TH_TEXT, col_unsel);
+       UI_GetThemeColor4ubv(TH_SELECT, col_sel);
 
        BKE_tracking_get_camera_object_matrix(scene, base->object, mat);
 
@@ -1612,13 +1626,13 @@ static void draw_viewport_object_reconstruction(Scene *scene, Base *base, View3D
                if (v3d->drawtype == OB_WIRE) {
                        glDisable(GL_LIGHTING);
 
-                       if (selected) {
-                               if (base == BASACT) UI_ThemeColor(TH_ACTIVE);
-                               else UI_ThemeColor(TH_SELECT);
-                       }
-                       else {
-                               if (track->flag & TRACK_CUSTOMCOLOR) glColor3fv(track->color);
-                               else UI_ThemeColor(TH_WIRE);
+                       if ((dflag & DRAW_CONSTCOLOR) == 0) {
+                               if (selected && (track->flag & TRACK_CUSTOMCOLOR) == 0) {
+                                       glColor3ubv(ob_wire_col);
+                               }
+                               else {
+                                       glColor3fv(track->color);
+                               }
                        }
 
                        drawaxes(0.05f, v3d->bundle_drawtype);
@@ -1629,8 +1643,9 @@ static void draw_viewport_object_reconstruction(Scene *scene, Base *base, View3D
                        if (v3d->bundle_drawtype == OB_EMPTY_SPHERE) {
                                /* selection outline */
                                if (selected) {
-                                       if (base == BASACT) UI_ThemeColor(TH_ACTIVE);
-                                       else UI_ThemeColor(TH_SELECT);
+                                       if ((dflag & DRAW_CONSTCOLOR) == 0) {
+                                               glColor3ubv(ob_wire_col);
+                                       }
 
                                        glLineWidth(2.f);
                                        glDisable(GL_LIGHTING);
@@ -1643,21 +1658,24 @@ static void draw_viewport_object_reconstruction(Scene *scene, Base *base, View3D
                                        glLineWidth(1.f);
                                }
 
-                               if (track->flag & TRACK_CUSTOMCOLOR) glColor3fv(track->color);
-                               else UI_ThemeColor(TH_BUNDLE_SOLID);
+                               if ((dflag & DRAW_CONSTCOLOR) == 0) {
+                                       if (track->flag & TRACK_CUSTOMCOLOR) glColor3fv(track->color);
+                                       else UI_ThemeColor(TH_BUNDLE_SOLID);
+                               }
 
                                draw_bundle_sphere();
                        }
                        else {
                                glDisable(GL_LIGHTING);
 
-                               if (selected) {
-                                       if (base == BASACT) UI_ThemeColor(TH_ACTIVE);
-                                       else UI_ThemeColor(TH_SELECT);
-                               }
-                               else {
-                                       if (track->flag & TRACK_CUSTOMCOLOR) glColor3fv(track->color);
-                                       else UI_ThemeColor(TH_WIRE);
+                               if ((dflag & DRAW_CONSTCOLOR) == 0) {
+                                       if (selected) {
+                                               glColor3ubv(ob_wire_col);
+                                       }
+                                       else {
+                                               if (track->flag & TRACK_CUSTOMCOLOR) glColor3fv(track->color);
+                                               else UI_ThemeColor(TH_WIRE);
+                                       }
                                }
 
                                drawaxes(0.05f, v3d->bundle_drawtype);
@@ -1670,13 +1688,9 @@ static void draw_viewport_object_reconstruction(Scene *scene, Base *base, View3D
 
                if ((dflag & DRAW_PICKING) == 0 && (v3d->flag2 & V3D_SHOW_BUNDLENAME)) {
                        float pos[3];
-                       unsigned char tcol[4];
-
-                       if (selected) memcpy(tcol, scol, sizeof(tcol));
-                       else memcpy(tcol, col, sizeof(tcol));
 
                        mul_v3_m4v3(pos, mat, track->bundle_pos);
-                       view3d_cached_text_draw_add(pos, track->name, 10, V3D_CACHE_TEXT_GLOBALSPACE, tcol);
+                       view3d_cached_text_draw_add(pos, track->name, 10, V3D_CACHE_TEXT_GLOBALSPACE, selected ? col_sel : col_unsel);
                }
 
                tracknr++;
@@ -1734,7 +1748,7 @@ static void draw_viewport_reconstruction(Scene *scene, Base *base, View3D *v3d,
        tracking_object = tracking->objects.first;
        while (tracking_object) {
                draw_viewport_object_reconstruction(scene, base, v3d, clip, tracking_object,
-                                                   dflag, &global_track_index, draw_selected);
+                                                   dflag, ob_wire_col, &global_track_index, draw_selected);
 
                tracking_object = tracking_object->next;
        }
@@ -3384,7 +3398,7 @@ static void draw_mesh_object_outline(View3D *v3d, Object *ob, DerivedMesh *dm)
 }
 
 static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D *rv3d, Base *base,
-                            const short dt, const short dflag)
+                            const short dt, const unsigned char ob_wire_col[4], const short dflag)
 {
        Object *ob = base->object;
        Mesh *me = ob->data;
@@ -3458,13 +3472,12 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
                }
 
                if (!(draw_flags & DRAW_FACE_SELECT)) {
-                       if (base->flag & SELECT)
-                               UI_ThemeColor(is_obact ? TH_ACTIVE : TH_SELECT);
-                       else
-                               UI_ThemeColor(TH_WIRE);
-
-                       if ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0)
+                       if ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) {
+                               if ((dflag & DRAW_CONSTCOLOR) == 0) {
+                                       glColor3ubv(ob_wire_col);
+                               }
                                dm->drawLooseEdges(dm);
+                       }
                }
        }
        else if (dt == OB_SOLID) {
@@ -3548,14 +3561,12 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
 
                        glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
 
-                       if (base->flag & SELECT) {
-                               UI_ThemeColor(is_obact ? TH_ACTIVE : TH_SELECT);
-                       }
-                       else {
-                               UI_ThemeColor(TH_WIRE);
-                       }
-                       if (!ob->sculpt && (v3d->flag2 & V3D_RENDER_OVERRIDE) == 0)
+                       if (!ob->sculpt && (v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) {
+                               if ((dflag & DRAW_CONSTCOLOR) == 0) {
+                                       glColor3ubv(ob_wire_col);
+                               }
                                dm->drawLooseEdges(dm);
+                       }
                }
        }
        else if (dt == OB_PAINT) {
@@ -3564,42 +3575,22 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
                /* since we already draw wire as wp guide, don't draw over the top */
                draw_wire = OBDRAW_WIRE_OFF;
        }
-       
-       /* set default draw color back for wire or for draw-extra later on */
-       if (dt != OB_WIRE) {
-               if (base->flag & SELECT) {
-                       if (is_obact && ob->flag & OB_FROMGROUP)
-                               UI_ThemeColor(TH_GROUP_ACTIVE);
-                       else if (ob->flag & OB_FROMGROUP)
-                               UI_ThemeColorShade(TH_GROUP_ACTIVE, -16);
-                       else if (dflag != DRAW_CONSTCOLOR)
-                               UI_ThemeColor(is_obact ? TH_ACTIVE : TH_SELECT);
-                       else
-                               glColor3ub(80, 80, 80);
-               }
-               else {
-                       if (ob->flag & OB_FROMGROUP)
-                               UI_ThemeColor(TH_GROUP);
-                       else {
-                               if (ob->dtx & OB_DRAWWIRE && dflag == DRAW_CONSTCOLOR)
-                                       glColor3ub(80, 80, 80);
-                               else
-                                       UI_ThemeColor(TH_WIRE);
-                       }
-               }
-       }
-       if (draw_wire != OBDRAW_WIRE_OFF) {
 
+       if ((draw_wire != OBDRAW_WIRE_OFF) &&  /* draw extra wire */
+           /* when overriding with render only, don't bother  */
+           (((v3d->flag2 & V3D_RENDER_OVERRIDE) && v3d->drawtype >= OB_SOLID) == 0))
+       {
                /* When using wireframe object draw in particle edit mode
                 * the mesh gets in the way of seeing the particles, fade the wire color
                 * with the background. */
-               if (is_obact && (ob->mode & OB_MODE_PARTICLE_EDIT)) {
-                       float col_wire[4], col_bg[4], col[3];
 
-                       UI_GetThemeColor3fv(TH_BACK, col_bg);
-                       glGetFloatv(GL_CURRENT_COLOR, col_wire);
-                       interp_v3_v3v3(col, col_bg, col_wire, 0.15);
-                       glColor3fv(col);
+               if ((dflag & DRAW_CONSTCOLOR) == 0) {
+                       if (is_obact && (ob->mode & OB_MODE_PARTICLE_EDIT)) {
+                               ob_wire_color_blend_theme_id(ob_wire_col, TH_BACK, 0.15f);
+                       }
+                       else {
+                               glColor3ubv(ob_wire_col);
+                       }
                }
 
                /* If drawing wire and drawtype is not OB_WIRE then we are
@@ -3616,8 +3607,7 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
                        glDepthMask(0);  /* disable write in zbuffer, selected edge wires show better */
                }
                
-               if (((v3d->flag2 & V3D_RENDER_OVERRIDE) && v3d->drawtype >= OB_SOLID) == 0)
-                       dm->drawEdges(dm, (dt == OB_WIRE || totface == 0), me->drawflag & ME_ALLEDGES);
+               dm->drawEdges(dm, (dt == OB_WIRE || totface == 0), me->drawflag & ME_ALLEDGES);
 
                if (dt != OB_WIRE && (draw_wire == OBDRAW_WIRE_ON_DEPTH)) {
                        glDepthMask(1);
@@ -3639,7 +3629,7 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
 
 /* returns 1 if nothing was drawn, for detecting to draw an object center */
 static int draw_mesh_object(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D *rv3d, Base *base,
-                            const short dt, const short dflag)
+                            const short dt, const unsigned char ob_wire_col[4], const short dflag)
 {
        Object *ob = base->object;
        Object *obedit = scene->obedit;
@@ -3703,7 +3693,7 @@ static int draw_mesh_object(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
                                                           (check_alpha) ? &do_alpha_after : NULL);
                        }
 
-                       draw_mesh_fancy(scene, ar, v3d, rv3d, base, dt, dflag);
+                       draw_mesh_fancy(scene, ar, v3d, rv3d, base, dt, ob_wire_col, dflag);
 
                        GPU_end_object_materials();
                        
@@ -5943,9 +5933,9 @@ static void drawcone(const float vec[3], float radius, float height, float tmat[
        glVertex3f(cur[0], cur[1] - radius, cur[2]);
        glEnd();
 }
-/* return 1 if nothing was drawn */
+/* return TRUE if nothing was drawn */
 static int drawmball(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
-                     const short dt, const unsigned char ob_wire_col[4])
+                     const short dt, const short dflag, const unsigned char ob_wire_col[4])
 {
        Object *ob = base->object;
        MetaBall *mb;
@@ -5972,27 +5962,32 @@ static int drawmball(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
                ml = mb->elems.first;
        }
 
-       if (ml == NULL) return 1;
+       if (ml == NULL) {
+               return TRUE;
+       }
 
-       if (v3d->flag2 & V3D_RENDER_OVERRIDE) return 0;
-       
-       /* in case solid draw, reset wire colors */
-       if (ob->flag & SELECT) {
-               if (ob == OBACT) UI_ThemeColor(TH_ACTIVE);
-               else UI_ThemeColor(TH_SELECT);
+       if (v3d->flag2 & V3D_RENDER_OVERRIDE) {
+               return FALSE;
        }
-       else UI_ThemeColor(TH_WIRE);
 
        invert_m4_m4(imat, rv3d->viewmatob);
        normalize_v3(imat[0]);
        normalize_v3(imat[1]);
+
+       if (mb->editelems == NULL) {
+               if ((dflag & DRAW_CONSTCOLOR) == 0) {
+                       glColor3ubv(ob_wire_col);
+               }
+       }
        
        while (ml) {
 
                /* draw radius */
                if (mb->editelems) {
-                       if ((ml->flag & SELECT) && (ml->flag & MB_SCALE_RAD)) cpack(0xA0A0F0);
-                       else cpack(0x3030A0);
+                       if ((dflag & DRAW_CONSTCOLOR) == 0) {
+                               if ((ml->flag & SELECT) && (ml->flag & MB_SCALE_RAD)) cpack(0xA0A0F0);
+                               else cpack(0x3030A0);
+                       }
                        
                        if (G.f & G_PICKSEL) {
                                ml->selcol1 = code;
@@ -6003,8 +5998,10 @@ static int drawmball(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
 
                /* draw stiffness */
                if (mb->editelems) {
-                       if ((ml->flag & SELECT) && !(ml->flag & MB_SCALE_RAD)) cpack(0xA0F0A0);
-                       else cpack(0x30A030);
+                       if ((dflag & DRAW_CONSTCOLOR) == 0) {
+                               if ((ml->flag & SELECT) && !(ml->flag & MB_SCALE_RAD)) cpack(0xA0F0A0);
+                               else cpack(0x30A030);
+                       }
                        
                        if (G.f & G_PICKSEL) {
                                ml->selcol2 = code;
@@ -6015,23 +6012,16 @@ static int drawmball(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
                
                ml = ml->next;
        }
-       return 0;
+       return FALSE;
 }
 
-static void draw_forcefield(Scene *scene, Object *ob, RegionView3D *rv3d)
+static void draw_forcefield(Object *ob, RegionView3D *rv3d,
+                            const short dflag, const unsigned char ob_wire_col[4])
 {
        PartDeflect *pd = ob->pd;
        float imat[4][4], tmat[4][4];
        float vec[3] = {0.0, 0.0, 0.0};
-       int curcol;
        float size;
-
-       /* XXX why? */
-       if (ob != scene->obedit && (ob->flag & SELECT)) {
-               if (ob == OBACT) curcol = TH_ACTIVE;
-               else curcol = TH_SELECT;
-       }
-       else curcol = TH_EMPTY;
        
        /* scale size of circle etc with the empty drawsize */
        if (ob->type == OB_EMPTY) size = ob->empty_drawsize;
@@ -6044,16 +6034,19 @@ static void draw_forcefield(Scene *scene, Object *ob, RegionView3D *rv3d)
        
        if (pd->forcefield == PFIELD_WIND) {
                float force_val;
-               
-               unit_m4(tmat);
-               UI_ThemeColorBlend(curcol, TH_BACK, 0.5);
-               
+
+               if ((dflag & DRAW_CONSTCOLOR) == 0) {
+                       ob_wire_color_blend_theme_id(ob_wire_col, TH_BACK, 0.5f);
+               }
+
                //if (has_ipo_code(ob->ipo, OB_PD_FSTR))
                //      force_val = IPO_GetFloatValue(ob->ipo, OB_PD_FSTR, scene->r.cfra);
                //else
                {
                        force_val = pd->f_strength;
                }
+
+               unit_m4(tmat);
                force_val *= 0.1f;
                drawcircball(GL_LINE_LOOP, vec, size, tmat);
                vec[2] = 0.5f * force_val;
@@ -6075,11 +6068,11 @@ static void draw_forcefield(Scene *scene, Object *ob, RegionView3D *rv3d)
                        ffall_val = pd->f_power;
                }
 
-               UI_ThemeColorBlend(curcol, TH_BACK, 0.5);
+               if ((dflag & DRAW_CONSTCOLOR) == 0) ob_wire_color_blend_theme_id(ob_wire_col, TH_BACK, 0.5f);
                drawcircball(GL_LINE_LOOP, vec, size, imat);
-               UI_ThemeColorBlend(curcol, TH_BACK, 0.9f - 0.4f / powf(1.5f, ffall_val));
+               if ((dflag & DRAW_CONSTCOLOR) == 0) ob_wire_color_blend_theme_id(ob_wire_col, TH_BACK, 0.9f - 0.4f / powf(1.5f, ffall_val));
                drawcircball(GL_LINE_LOOP, vec, size * 1.5f, imat);
-               UI_ThemeColorBlend(curcol, TH_BACK, 0.9f - 0.4f / powf(2.0f, ffall_val));
+               if ((dflag & DRAW_CONSTCOLOR) == 0) ob_wire_color_blend_theme_id(ob_wire_col, TH_BACK, 0.9f - 0.4f / powf(2.0f, ffall_val));
                drawcircball(GL_LINE_LOOP, vec, size * 2.0f, imat);
        }
        else if (pd->forcefield == PFIELD_VORTEX) {
@@ -6098,7 +6091,10 @@ static void draw_forcefield(Scene *scene, Object *ob, RegionView3D *rv3d)
                        force_val = pd->f_strength;
                }
 
-               UI_ThemeColorBlend(curcol, TH_BACK, 0.7f);
+               if ((dflag & DRAW_CONSTCOLOR) == 0) {
+                       ob_wire_color_blend_theme_id(ob_wire_col, TH_BACK, 0.7f);
+               }
+
                if (force_val < 0) {
                        drawspiral(vec, size, tmat, 1);
                        drawspiral(vec, size, tmat, 16);
@@ -6120,16 +6116,18 @@ static void draw_forcefield(Scene *scene, Object *ob, RegionView3D *rv3d)
                                mindist = pd->f_strength;
                        }
 
+                       if ((dflag & DRAW_CONSTCOLOR) == 0) {
+                               ob_wire_color_blend_theme_id(ob_wire_col, TH_BACK, 0.5f);
+                       }
+
                        /*path end*/
                        setlinestyle(3);
                        where_on_path(ob, 1.0f, guidevec1, guidevec2, NULL, NULL, NULL);
-                       UI_ThemeColorBlend(curcol, TH_BACK, 0.5);
                        drawcircball(GL_LINE_LOOP, guidevec1, mindist, imat);
 
                        /*path beginning*/
                        setlinestyle(0);
                        where_on_path(ob, 0.0f, guidevec1, guidevec2, NULL, NULL, NULL);
-                       UI_ThemeColorBlend(curcol, TH_BACK, 0.5);
                        drawcircball(GL_LINE_LOOP, guidevec1, mindist, imat);
                        
                        copy_v3_v3(vec, guidevec1); /* max center */
@@ -6137,7 +6135,10 @@ static void draw_forcefield(Scene *scene, Object *ob, RegionView3D *rv3d)
        }
 
        setlinestyle(3);
-       UI_ThemeColorBlend(curcol, TH_BACK, 0.5);
+
+       if ((dflag & DRAW_CONSTCOLOR) == 0) {
+               ob_wire_color_blend_theme_id(ob_wire_col, TH_BACK, 0.5f);
+       }
 
        if (pd->falloff == PFIELD_FALL_SPHERE) {
                /* as last, guide curve alters it */
@@ -6387,59 +6388,46 @@ static void drawObjectSelect(Scene *scene, View3D *v3d, ARegion *ar, Base *base,
        glDepthMask(1);
 }
 
-static void drawWireExtra(Scene *scene, RegionView3D *rv3d, Object *ob) 
+static void draw_wire_extra(Scene *scene, RegionView3D *rv3d, Object *ob, unsigned char ob_wire_col[4])
 {
-       if (ob != scene->obedit && (ob->flag & SELECT)) {
-               if (ob == OBACT) {
-                       if (ob->flag & OB_FROMGROUP) UI_ThemeColor(TH_GROUP_ACTIVE);
-                       else UI_ThemeColor(TH_ACTIVE);
+       if (ELEM4(ob->type, OB_FONT, OB_CURVE, OB_SURF, OB_MBALL)) {
+
+               if (scene->obedit == ob) {
+                       UI_ThemeColor(TH_WIRE);
                }
-               else if (ob->flag & OB_FROMGROUP)
-                       UI_ThemeColorShade(TH_GROUP_ACTIVE, -16);
-               else
-                       UI_ThemeColor(TH_SELECT);
-       }
-       else {
-               if (ob->flag & OB_FROMGROUP)
-                       UI_ThemeColor(TH_GROUP);
                else {
-                       if (ob->dtx & OB_DRAWWIRE) {
-                               glColor3ub(80, 80, 80);
-                       }
-                       else {
-                               UI_ThemeColor(TH_WIRE);
-                       }
+                       glColor3ubv(ob_wire_col);
                }
-       }
-       
-       bglPolygonOffset(rv3d->dist, 1.0);
-       glDepthMask(0);  /* disable write in zbuffer, selected edge wires show better */
 
-       if (ELEM3(ob->type, OB_FONT, OB_CURVE, OB_SURF)) {
-               Curve *cu = ob->data;
-               if (ED_view3d_boundbox_clip(rv3d, ob->obmat, ob->bb ? ob->bb : cu->bb)) {
-                       if (ob->type == OB_CURVE)
-                               draw_index_wire = 0;
+               bglPolygonOffset(rv3d->dist, 1.0);
+               glDepthMask(0);  /* disable write in zbuffer, selected edge wires show better */
+
+               if (ELEM3(ob->type, OB_FONT, OB_CURVE, OB_SURF)) {
+                       Curve *cu = ob->data;
+                       if (ED_view3d_boundbox_clip(rv3d, ob->obmat, ob->bb ? ob->bb : cu->bb)) {
+                               if (ob->type == OB_CURVE)
+                                       draw_index_wire = 0;
+
+                               if (ob->derivedFinal) {
+                                       drawCurveDMWired(ob);
+                               }
+                               else {
+                                       drawDispListwire(&ob->disp);
+                               }
 
-                       if (ob->derivedFinal) {
-                               drawCurveDMWired(ob);
+                               if (ob->type == OB_CURVE)
+                                       draw_index_wire = 1;
                        }
-                       else {
+               }
+               else if (ob->type == OB_MBALL) {
+                       if (BKE_mball_is_basis(ob)) {
                                drawDispListwire(&ob->disp);
                        }
-
-                       if (ob->type == OB_CURVE)
-                               draw_index_wire = 1;
-               }
-       }
-       else if (ob->type == OB_MBALL) {
-               if (BKE_mball_is_basis(ob)) {
-                       drawDispListwire(&ob->disp);
                }
-       }
 
-       glDepthMask(1);
-       bglPolygonOffset(rv3d->dist, 0.0);
+               glDepthMask(1);
+               bglPolygonOffset(rv3d->dist, 0.0);
+       }
 }
 
 /* should be called in view space */
@@ -6580,7 +6568,10 @@ static void draw_object_wire_color(Scene *scene, Base *base, unsigned char r_ob_
        r_ob_wire_col[3] = 255;
 }
 
-/* flag can be DRAW_PICKING    and/or DRAW_CONSTCOLOR, DRAW_SCENESET */
+/**
+ * main object drawing function, draws in selection
+ * \param dflag (draw flag) can be DRAW_PICKING and/or DRAW_CONSTCOLOR, DRAW_SCENESET
+ */
 void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, const short dflag)
 {
        static int warning_recursive = 0;
@@ -6722,7 +6713,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, const short
 
        switch (ob->type) {
                case OB_MESH:
-                       empty_object = draw_mesh_object(scene, ar, v3d, rv3d, base, dt, dflag);
+                       empty_object = draw_mesh_object(scene, ar, v3d, rv3d, base, dt, ob_wire_col, dflag);
                        if (dflag != DRAW_CONSTCOLOR) dtx &= ~OB_DRAWWIRE;  // mesh draws wire itself
 
                        break;
@@ -6842,20 +6833,20 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, const short
                        MetaBall *mb = ob->data;
                        
                        if (mb->editelems)
-                               drawmball(scene, v3d, rv3d, base, dt, ob_wire_col);
+                               drawmball(scene, v3d, rv3d, base, dt, dflag, ob_wire_col);
                        else if (dt == OB_BOUNDBOX) {
                                if (((v3d->flag2 & V3D_RENDER_OVERRIDE) && (v3d->drawtype >= OB_WIRE)) == 0) {
                                        draw_bounding_volume(scene, ob, ob->boundtype);
                                }
                        }
                        else
-                               empty_object = drawmball(scene, v3d, rv3d, base, dt, ob_wire_col);
+                               empty_object = drawmball(scene, v3d, rv3d, base, dt, dflag, ob_wire_col);
                        break;
                }
                case OB_EMPTY:
                        if ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) {
                                if (ob->empty_drawtype == OB_EMPTY_IMAGE) {
-                                       draw_empty_image(ob);
+                                       draw_empty_image(ob, dflag, ob_wire_col);
                                }
                                else {
                                        drawaxes(ob->empty_drawsize, ob->empty_drawtype);
@@ -6927,7 +6918,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, const short
                }
 
                if (ob->pd && ob->pd->forcefield) {
-                       draw_forcefield(scene, ob, rv3d);
+                       draw_forcefield(ob, rv3d, dflag, ob_wire_col);
                }
        }
 
@@ -7134,7 +7125,9 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, const short
                        }
                        /*if (dtx & OB_DRAWIMAGE) drawDispListwire(&ob->disp);*/
                        if ((dtx & OB_DRAWWIRE) && dt >= OB_SOLID) {
-                               drawWireExtra(scene, rv3d, ob);
+                               if ((dflag & DRAW_CONSTCOLOR) == 0) {
+                                       draw_wire_extra(scene, rv3d, ob, ob_wire_col);
+                               }
                        }
                }
        }
@@ -7307,7 +7300,7 @@ static void bbs_obmode_mesh_verts__mapFunc(void *userData, int index, const floa
        int offset = (intptr_t) data->offset;
 
        if (!(mv->flag & ME_HIDE)) {
-               WM_set_framebuffer_index_color(offset + index);
+               WM_framebuffer_index_set(offset + index);
                bglVertex3fv(co);
        }
 }
@@ -7334,7 +7327,7 @@ static void bbs_mesh_verts__mapFunc(void *userData, int index, const float co[3]
        BMVert *eve = EDBM_vert_at_index(ptrs[1], index);
 
        if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) {
-               WM_set_framebuffer_index_color(offset + index);
+               WM_framebuffer_index_set(offset + index);
                bglVertex3fv(co);
        }
 }
@@ -7356,7 +7349,7 @@ static DMDrawOption bbs_mesh_wire__setDrawOptions(void *userData, int index)
        BMEdge *eed = EDBM_edge_at_index(ptrs[1], index);
 
        if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) {
-               WM_set_framebuffer_index_color(offset + index);
+               WM_framebuffer_index_set(offset + index);
                return DM_DRAW_OPTION_NORMAL;
        }
        else {
@@ -7375,7 +7368,7 @@ static DMDrawOption bbs_mesh_solid__setSolidDrawOptions(void *userData, int inde
        
        if (efa && !BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
                if (((void **)userData)[1]) {
-                       WM_set_framebuffer_index_color(index + 1);
+                       WM_framebuffer_index_set(index + 1);
                }
                return DM_DRAW_OPTION_NORMAL;
        }
@@ -7389,7 +7382,7 @@ static void bbs_mesh_solid__drawCenter(void *userData, int index, const float ce
        BMFace *efa = EDBM_face_at_index(((void **)userData)[0], index);
 
        if (!BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
-               WM_set_framebuffer_index_color(index + 1);
+               WM_framebuffer_index_set(index + 1);
 
                bglVertex3fv(cent);
        }
@@ -7422,7 +7415,7 @@ static void bbs_mesh_solid_EM(BMEditMesh *em, Scene *scene, View3D *v3d,
 
 static DMDrawOption bbs_mesh_solid__setDrawOpts(void *UNUSED(userData), int index)
 {
-       WM_set_framebuffer_index_color(index + 1);
+       WM_framebuffer_index_set(index + 1);
        return DM_DRAW_OPTION_NORMAL;
 }
 
@@ -7431,7 +7424,7 @@ static DMDrawOption bbs_mesh_solid_hide__setDrawOpts(void *userData, int index)
        Mesh *me = userData;
 
        if (!(me->mpoly[index].flag & ME_HIDE)) {
-               WM_set_framebuffer_index_color(index + 1);
+               WM_framebuffer_index_set(index + 1);
                return DM_DRAW_OPTION_NORMAL;
        }
        else {
@@ -7439,7 +7432,7 @@ static DMDrawOption bbs_mesh_solid_hide__setDrawOpts(void *userData, int index)
        }
 }
 
-/* must have called WM_set_framebuffer_index_color beforehand */
+/* must have called WM_framebuffer_index_set beforehand */
 static DMDrawOption bbs_mesh_solid_hide2__setDrawOpts(void *userData, int index)
 {
        Mesh *me = userData;
@@ -7606,7 +7599,8 @@ void draw_object_instance(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object
                        break;
                case OB_EMPTY:
                        if (ob->empty_drawtype == OB_EMPTY_IMAGE) {
-                               draw_empty_image(ob);
+                               /* CONSTCOLOR == no wire outline */
+                               draw_empty_image(ob, DRAW_CONSTCOLOR, NULL);
                        }
                        else {
                                drawaxes(ob->empty_drawsize, ob->empty_drawtype);