Fix T61286: Viewport grid units not visible
authormano-wii <germano.costa@ig.com.br>
Tue, 20 Aug 2019 11:56:48 +0000 (08:56 -0300)
committermano-wii <germano.costa@ig.com.br>
Tue, 20 Aug 2019 11:58:07 +0000 (08:58 -0300)
The original code was commented on.
Unlike blender 2.79, the grid units are now displayed only when RV3D_VIEW_IS_AXIS.
The visible subdivisions in the grid are made by the GPU and depending on the pixel.
The code used here only mimics this behavior and adds a bit of overhead.

Reviewers: fclem, campbellbarton

Subscribers: FloridaJo, zlsa, rl.amorato, EitanSomething

Differential Revision: https://developer.blender.org/D4325

source/blender/editors/space_view3d/view3d_draw.c

index 038d32c4d20b121863d48af4d855d3c41391fa46..aa4b92062a30bcbc47705fa81a6b25f2733cbac8 100644 (file)
@@ -920,12 +920,23 @@ float ED_view3d_grid_view_scale(Scene *scene,
     float min_dist = 0.38f * (rv3d->dist / v3d->lens);
     float grid_steps[8];
     ED_view3d_grid_steps(scene, v3d, rv3d, grid_steps);
-    for (int i = 0; i < ARRAY_SIZE(grid_steps); i++) {
+    int i;
+    for (i = 0; i < ARRAY_SIZE(grid_steps); i++) {
       grid_scale = grid_steps[i];
       if (grid_scale > min_dist) {
         break;
       }
     }
+
+    if (grid_unit) {
+      const void *usys;
+      int len;
+      bUnit_GetSystem(scene->unit.system, B_UNIT_LENGTH, &usys, &len);
+
+      if (usys) {
+        *grid_unit = bUnit_GetNameDisplay(usys, len - i - 1);
+      }
+    }
   }
   else {
     grid_scale = ED_view3d_grid_scale(scene, v3d, grid_unit);
@@ -1405,6 +1416,25 @@ static void draw_selected_name(
   BLF_disable(font_id, BLF_SHADOW);
 }
 
+static void draw_grid_unit_name(
+    Scene *scene, RegionView3D *rv3d, View3D *v3d, int xoffset, int *yoffset)
+{
+  if (!rv3d->is_persp && RV3D_VIEW_IS_AXIS(rv3d->view)) {
+    char numstr[32] = "";
+    const char *grid_unit;
+    ED_view3d_grid_view_scale(scene, v3d, rv3d, &grid_unit);
+
+    UI_FontThemeColor(BLF_default(), TH_TEXT_HI);
+    if (v3d->grid != 1.0f) {
+      BLI_snprintf(numstr, sizeof(numstr), "%s x %.4g", grid_unit, v3d->grid);
+    }
+
+    *yoffset -= U.widget_unit;
+    BLF_draw_default_ascii(
+        xoffset, *yoffset, 0.0f, numstr[0] ? numstr : grid_unit, sizeof(numstr));
+  }
+}
+
 /**
  * Information drawn on top of the solid plates and composed data
  */
@@ -1466,19 +1496,10 @@ void view3d_draw_region_info(const bContext *C, ARegion *ar)
       draw_selected_name(scene, view_layer, ob, xoffset, &yoffset);
     }
 
-#if 0 /* TODO */
-    if (grid_unit) { /* draw below the viewport name */
-      char numstr[32] = "";
-
-      UI_FontThemeColor(BLF_default(), TH_TEXT_HI);
-      if (v3d->grid != 1.0f) {
-        BLI_snprintf(numstr, sizeof(numstr), "%s x %.4g", grid_unit, v3d->grid);
-      }
-
-      *yoffset -= U.widget_unit;
-      BLF_draw_default_ascii(xoffset, *yoffset, numstr[0] ? numstr : grid_unit, sizeof(numstr));
+    if (v3d->gridflag & (V3D_SHOW_FLOOR | V3D_SHOW_X | V3D_SHOW_Y | V3D_SHOW_Z)) {
+      /* draw below the viewport name */
+      draw_grid_unit_name(scene, rv3d, v3d, xoffset, &yoffset);
     }
-#endif
   }
 
   if ((v3d->overlay.flag & V3D_OVERLAY_HIDE_TEXT) == 0) {