[Bf-blender-cvs] [ded9484925e] master: UI: Viewport Navigate Gizmo Refactor

Harley Acheson noreply at git.blender.org
Sat Jan 23 22:11:10 CET 2021


Commit: ded9484925edd768cb80e1ca1c32c964fd941800
Author: Harley Acheson
Date:   Sat Jan 23 13:10:07 2021 -0800
Branches: master
https://developer.blender.org/rBded9484925edd768cb80e1ca1c32c964fd941800

UI: Viewport Navigate Gizmo Refactor

Simplification and changes to the Navigation gizmo. Better indication of negative axes, consistent use of color and size to indicate orientation, ability to be resized.

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

Reviewed by Campbell Barton

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

M	release/datafiles/userdef/userdef_default.c
M	release/scripts/startup/bl_ui/space_userpref.py
M	source/blender/blenloader/intern/versioning_userdef.c
M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface_draw.c
M	source/blender/editors/space_view3d/view3d_gizmo_navigate.c
M	source/blender/editors/space_view3d/view3d_gizmo_navigate_type.c
M	source/blender/makesdna/DNA_userdef_types.h
M	source/blender/makesrna/intern/rna_userdef.c

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

diff --git a/release/datafiles/userdef/userdef_default.c b/release/datafiles/userdef/userdef_default.c
index b448a230da8..471a14d8aac 100644
--- a/release/datafiles/userdef/userdef_default.c
+++ b/release/datafiles/userdef/userdef_default.c
@@ -131,6 +131,7 @@ const UserDef U_default = {
 
     .prefetchframes = 0,
     .pad_rot_angle = 15,
+    .gizmo_size_navigate_v3d = 80,
     .rvisize = 25,
     .rvibright = 8,
     .recent_files = 10,
diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py
index 4b30266a5fe..a0b5355e64d 100644
--- a/release/scripts/startup/bl_ui/space_userpref.py
+++ b/release/scripts/startup/bl_ui/space_userpref.py
@@ -691,6 +691,9 @@ class USERPREF_PT_viewport_display(ViewportPanel, CenterAlignMixIn, Panel):
             col.prop(view, "mini_axis_size", text="Size")
             col.prop(view, "mini_axis_brightness", text="Brightness")
 
+        if view.mini_axis_type == 'GIZMO':
+            col.prop(view, "gizmo_size_navigate_v3d", text="Size")
+
 
 class USERPREF_PT_viewport_quality(ViewportPanel, CenterAlignMixIn, Panel):
     bl_label = "Quality"
diff --git a/source/blender/blenloader/intern/versioning_userdef.c b/source/blender/blenloader/intern/versioning_userdef.c
index 9af2dee296b..2275084d53b 100644
--- a/source/blender/blenloader/intern/versioning_userdef.c
+++ b/source/blender/blenloader/intern/versioning_userdef.c
@@ -844,6 +844,9 @@ void blo_do_versions_userdef(UserDef *userdef)
    */
   {
     /* Keep this block, even when empty. */
+    if (userdef->gizmo_size_navigate_v3d == 0) {
+      userdef->gizmo_size_navigate_v3d = 80;
+    }
   }
 
   LISTBASE_FOREACH (bTheme *, btheme, &userdef->themes) {
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index ec2cb93a89f..2dc20973b1b 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -443,6 +443,16 @@ void UI_draw_roundbox_shade_x(bool filled,
                               float shadetop,
                               float shadedown,
                               const float col[4]);
+void UI_draw_roundbox_4fv_ex(float minx,
+                             float miny,
+                             float maxx,
+                             float maxy,
+                             const float inner1[4],
+                             const float inner2[4],
+                             float shade_dir,
+                             float outline[4],
+                             float outline_width,
+                             float rad);
 
 #if 0 /* unused */
 int UI_draw_roundbox_corner_get(void);
diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c
index 5bb6b0f21e7..6a55421f013 100644
--- a/source/blender/editors/interface/interface_draw.c
+++ b/source/blender/editors/interface/interface_draw.c
@@ -81,6 +81,57 @@ int UI_draw_roundbox_corner_get(void)
 }
 #endif
 
+void UI_draw_roundbox_4fv_ex(float minx,
+                             float miny,
+                             float maxx,
+                             float maxy,
+                             const float inner1[4],
+                             const float inner2[4],
+                             float shade_dir,
+                             float outline[4],
+                             float outline_width,
+                             float rad)
+{
+  /* WATCH: This is assuming the ModelViewProjectionMatrix is area pixel space.
+   * If it has been scaled, then it's no longer valid. */
+  uiWidgetBaseParameters widget_params = {
+      .recti.xmin = minx + outline_width,
+      .recti.ymin = miny + outline_width,
+      .recti.xmax = maxx - outline_width,
+      .recti.ymax = maxy - outline_width,
+      .rect.xmin = minx,
+      .rect.ymin = miny,
+      .rect.xmax = maxx,
+      .rect.ymax = maxy,
+      .radi = rad,
+      .rad = rad,
+      .round_corners[0] = (roundboxtype & UI_CNR_BOTTOM_LEFT) ? 1.0f : 0.0f,
+      .round_corners[1] = (roundboxtype & UI_CNR_BOTTOM_RIGHT) ? 1.0f : 0.0f,
+      .round_corners[2] = (roundboxtype & UI_CNR_TOP_RIGHT) ? 1.0f : 0.0f,
+      .round_corners[3] = (roundboxtype & UI_CNR_TOP_LEFT) ? 1.0f : 0.0f,
+      .color_inner1[0] = inner1 ? inner1[0] : 0.0f,
+      .color_inner1[1] = inner1 ? inner1[1] : 0.0f,
+      .color_inner1[2] = inner1 ? inner1[2] : 0.0f,
+      .color_inner1[3] = inner1 ? inner1[3] : 0.0f,
+      .color_inner2[0] = inner2 ? inner2[0] : inner1 ? inner1[0] : 0.0f,
+      .color_inner2[1] = inner2 ? inner2[1] : inner1 ? inner1[1] : 0.0f,
+      .color_inner2[2] = inner2 ? inner2[2] : inner1 ? inner1[2] : 0.0f,
+      .color_inner2[3] = inner2 ? inner2[3] : inner1 ? inner1[3] : 0.0f,
+      .color_outline[0] = outline ? outline[0] : inner1 ? inner1[0] : 0.0f,
+      .color_outline[1] = outline ? outline[1] : inner1 ? inner1[1] : 0.0f,
+      .color_outline[2] = outline ? outline[2] : inner1 ? inner1[2] : 0.0f,
+      .color_outline[3] = outline ? outline[3] : inner1 ? inner1[3] : 0.0f,
+      .shade_dir = shade_dir,
+      .alpha_discard = 1.0f,
+  };
+  GPUBatch *batch = ui_batch_roundbox_widget_get();
+  GPU_batch_program_set_builtin(batch, GPU_SHADER_2D_WIDGET_BASE);
+  GPU_batch_uniform_4fv_array(batch, "parameters", 11, (float(*)[4]) & widget_params);
+  GPU_blend(GPU_BLEND_ALPHA);
+  GPU_batch_draw(batch);
+  GPU_blend(GPU_BLEND_NONE);
+}
+
 void UI_draw_roundbox_3ub_alpha(bool filled,
                                 float minx,
                                 float miny,
diff --git a/source/blender/editors/space_view3d/view3d_gizmo_navigate.c b/source/blender/editors/space_view3d/view3d_gizmo_navigate.c
index 7a201d8841c..c145497fa09 100644
--- a/source/blender/editors/space_view3d/view3d_gizmo_navigate.c
+++ b/source/blender/editors/space_view3d/view3d_gizmo_navigate.c
@@ -45,14 +45,17 @@
 /** \name View3D Navigation Gizmo Group
  * \{ */
 
-/* Offset from screen edge. */
-#define GIZMO_OFFSET_FAC 1.2f
 /* Size of main icon. */
-#define GIZMO_SIZE 80
-/* Factor for size of smaller button. */
-#define GIZMO_MINI_FAC 0.35f
-/* How much mini buttons offset from the primary. */
-#define GIZMO_MINI_OFFSET_FAC 0.38f
+#define GIZMO_SIZE U.gizmo_size_navigate_v3d
+
+/* Main gizmo offset from screen edges in unscaled pixels. */
+#define GIZMO_OFFSET 10.0f
+
+/* Width of smaller buttons in unscaled pixels. */
+#define GIZMO_MINI_SIZE 28.0f
+
+/* Margin around the smaller buttons. */
+#define GIZMO_MINI_OFFSET 2.0f
 
 enum {
   GZ_INDEX_MOVE = 0,
@@ -174,7 +177,7 @@ static void WIDGETGROUP_navigate_setup(const bContext *C, wmGizmoGroup *gzgroup)
     }
 
     /* may be overwritten later */
-    gz->scale_basis = (GIZMO_SIZE * GIZMO_MINI_FAC) / 2;
+    gz->scale_basis = GIZMO_MINI_SIZE / 2.0f;
     if (info->icon != 0) {
       PropertyRNA *prop = RNA_struct_find_property(gz->ptr, "icon");
       RNA_property_enum_set(gz->ptr, prop, info->icon);
@@ -212,7 +215,7 @@ static void WIDGETGROUP_navigate_setup(const bContext *C, wmGizmoGroup *gzgroup)
 
   {
     wmGizmo *gz = navgroup->gz_array[GZ_INDEX_ROTATE];
-    gz->scale_basis = GIZMO_SIZE / 2;
+    gz->scale_basis = GIZMO_SIZE / 2.0f;
     const char mapping[6] = {
         RV3D_VIEW_LEFT,
         RV3D_VIEW_RIGHT,
@@ -263,9 +266,8 @@ static void WIDGETGROUP_navigate_draw_prepare(const bContext *C, wmGizmoGroup *g
 
   const bool show_navigate = (U.uiflag & USER_SHOW_GIZMO_NAVIGATE) != 0;
   const bool show_rotate_gizmo = (U.mini_axis_type == USER_MINI_AXIS_TYPE_GIZMO);
-  const float icon_size = GIZMO_SIZE;
-  const float icon_offset = (icon_size * 0.52f) * GIZMO_OFFSET_FAC * UI_DPI_FAC;
-  const float icon_offset_mini = icon_size * GIZMO_MINI_OFFSET_FAC * UI_DPI_FAC;
+  const float icon_offset = ((GIZMO_SIZE / 2.0f) + GIZMO_OFFSET) * UI_DPI_FAC;
+  const float icon_offset_mini = (GIZMO_MINI_SIZE + GIZMO_MINI_OFFSET) * UI_DPI_FAC;
   const float co_rotate[2] = {
       rect_visible->xmax - icon_offset,
       rect_visible->ymax - icon_offset,
diff --git a/source/blender/editors/space_view3d/view3d_gizmo_navigate_type.c b/source/blender/editors/space_view3d/view3d_gizmo_navigate_type.c
index 8f3d40584aa..4d0f0586696 100644
--- a/source/blender/editors/space_view3d/view3d_gizmo_navigate_type.c
+++ b/source/blender/editors/space_view3d/view3d_gizmo_navigate_type.c
@@ -40,6 +40,8 @@
 #include "GPU_matrix.h"
 #include "GPU_state.h"
 
+#include "BLF_api.h"
+
 #include "RNA_access.h"
 #include "RNA_define.h"
 
@@ -53,169 +55,34 @@
 
 #include "view3d_intern.h"
 
-#define USE_AXIS_FONT
-#define USE_FADE_BACKGROUND
-
-#ifdef USE_AXIS_FONT
-#  include "BLF_api.h"
-#endif
-
-#define DIAL_RESOLUTION 32
-
-/* Sizes of axis spheres containing XYZ characters. */
-#define AXIS_HANDLE_SIZE_FG 0.19f
-/* When pointing away from the view. */
-#define AXIS_HANDLE_SIZE_BG 0.15f
-/* How far axis handles are away from the center. */
-#define AXIS_HANDLE_OFFSET (1.0f - AXIS_HANDLE_SIZE_FG)
-
-struct AxisDrawInfo {
-  /* Matrix is needed for screen-aligned font drawing. */
-#ifdef USE_AXIS_FONT
-  float matrix_final[4][4];
-#endif
-#ifdef USE_FADE_BACKGROUND
-  float color_bg[3];
-#endif
-};
-
-#ifndef USE_AXIS_FONT
-/**
- * \param viewmat_local_unit: is typically the 'rv3d->viewmatob'
- * copied into a 3x3 matrix and normalized.
- */
-static void draw_xyz_wire(
-    uint pos_id, const float viewmat_local_unit[3][3], const float c[3], float size, int axis)
-{
-  int line_type;
-  float buffer[4][3];
-  int n = 0;
-
-  float v1[3] = {0.0f, 0.0f, 0.0f}, v2[3] = {0.0f, 0.0f, 0.0f};
-  float dim = size * 0.1f;
-  float dx[3], dy[3];
-
-  dx[0] = dim;
-  dx[1] = 0.0f;
-  dx[2] = 0.0f;
-  dy[0] = 0.0f;
-  dy[1] = dim;
-  dy[2] = 0.0f;
-
-  switch (axis) {
-    case 0: /* x axis */
-      line_type = GPU_PRIM_LINES;
-
-      /* bottom left to top right */
-      negate_v3_v3(v1, dx);
-      sub_v3_v3(v1, dy);
-      copy_v3_v3(v2, dx);
-      add_v3_v3(v2, dy);
-
-      copy_v3_v3(buffer[n++], v1);
-      copy_v3_v3(buffer[n++], v2);
-
-      /* top left to bottom right */
-      mul_v3_fl(dy, 2.0f);
-      add_v3_v3(v1, dy);
-      sub_v3_v3(v2, dy);
-
-      copy_v3_v3(buffer[n

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list