Fix #27849: 3D manipulator widget lost on mesh in edge mode.
[blender.git] / source / blender / editors / transform / transform_manipulator.c
index 2fa094c6b8b78969c1ff1517cdf149cb18fea606..d62227a122d7081ebc5efc36bd031206b32ef3a5 100644 (file)
@@ -278,6 +278,7 @@ int calc_manipulator_stats(const bContext *C)
        ARegion *ar= CTX_wm_region(C);
        Scene *scene= CTX_data_scene(C);
        Object *obedit= CTX_data_edit_object(C);
+       ToolSettings *ts = CTX_data_tool_settings(C);
        View3D *v3d= sa->spacedata.first;
        RegionView3D *rv3d= ar->regiondata;
        Base *base;
@@ -309,11 +310,63 @@ int calc_manipulator_stats(const bContext *C)
                                calc_tw_center(scene, vec);
                                totsel= 1;
                        } else {
-                               /* do vertices for center, and if still no normal found, use vertex normals */
-                               for(eve= em->verts.first; eve; eve= eve->next) {
-                                       if(eve->f & SELECT) {
-                                               totsel++;
-                                               calc_tw_center(scene, eve->co);
+                               /* do vertices/edges/faces for center depending on selection
+                                  mode. note we can't use just vertex selection flag because
+                                  it is not flush down on changes */
+                               if(ts->selectmode & SCE_SELECT_VERTEX) {
+                                       for(eve= em->verts.first; eve; eve= eve->next) {
+                                               if(eve->f & SELECT) {
+                                                       totsel++;
+                                                       calc_tw_center(scene, eve->co);
+                                               }
+                                       }
+                               }
+                               else if(ts->selectmode & SCE_SELECT_EDGE) {
+                                       EditEdge *eed;
+
+                                       for(eve= em->verts.first; eve; eve= eve->next) eve->f1= 0;
+                                       for(eed= em->edges.first; eed; eed= eed->next) {
+                                               if(eed->h==0 && (eed->f & SELECT)) {
+                                                       if(!eed->v1->f1) {
+                                                               eed->v1->f1= 1;
+                                                               totsel++;
+                                                               calc_tw_center(scene, eed->v1->co);
+                                                       }
+                                                       if(!eed->v2->f1) {
+                                                               eed->v2->f1= 1;
+                                                               totsel++;
+                                                               calc_tw_center(scene, eed->v2->co);
+                                                       }
+                                               }
+                                       }
+                               }
+                               else {
+                                       EditFace *efa;
+
+                                       for(eve= em->verts.first; eve; eve= eve->next) eve->f1= 0;
+                                       for(efa= em->faces.first; efa; efa= efa->next) {
+                                               if(efa->h==0 && (efa->f & SELECT)) {
+                                                       if(!efa->v1->f1) {
+                                                               efa->v1->f1= 1;
+                                                               totsel++;
+                                                               calc_tw_center(scene, efa->v1->co);
+                                                       }
+                                                       if(!efa->v2->f1) {
+                                                               efa->v2->f1= 1;
+                                                               totsel++;
+                                                               calc_tw_center(scene, efa->v2->co);
+                                                       }
+                                                       if(!efa->v3->f1) {
+                                                               efa->v3->f1= 1;
+                                                               totsel++;
+                                                               calc_tw_center(scene, efa->v3->co);
+                                                       }
+                                                       if(efa->v4 && !efa->v4->f1) {
+                                                               efa->v4->f1= 1;
+                                                               totsel++;
+                                                               calc_tw_center(scene, efa->v4->co);
+                                                       }
+                                               }
                                        }
                                }
                        }
@@ -557,7 +610,7 @@ static void test_manipulator_axis(const bContext *C)
        float angle;
        float vec[3];
 
-       viewvector(rv3d, rv3d->twmat[3], vec);
+       ED_view3d_global_to_vector(rv3d, rv3d->twmat[3], vec);
 
        angle = fabs(angle_v3v3(rv3d->twmat[0], vec));
        if (angle > (float)M_PI / 2.0f) {
@@ -1457,7 +1510,7 @@ void BIF_draw_manipulator(const bContext *C)
                        break;
                }
 
-               mul_mat3_m4_fl(rv3d->twmat, view3d_pixel_size(rv3d, rv3d->twmat[3]) * U.tw_size * 5.0f);
+               mul_mat3_m4_fl(rv3d->twmat, ED_view3d_pixel_size(rv3d, rv3d->twmat[3]) * U.tw_size * 5.0f);
        }
 
        test_manipulator_axis(C);
@@ -1487,7 +1540,7 @@ void BIF_draw_manipulator(const bContext *C)
        }
 }
 
-static int manipulator_selectbuf(ScrArea *sa, ARegion *ar, const short mval[2], float hotspot)
+static int manipulator_selectbuf(ScrArea *sa, ARegion *ar, const int mval[2], float hotspot)
 {
        View3D *v3d= sa->spacedata.first;
        RegionView3D *rv3d= ar->regiondata;