[Bf-blender-cvs] [e463d2c16f7] master: UI: Change node editor grid into a dot grid

Hans Goudey noreply at git.blender.org
Tue Oct 26 04:50:13 CEST 2021


Commit: e463d2c16f72e976ed1c886aca3f8efe396978fb
Author: Hans Goudey
Date:   Mon Oct 25 21:46:39 2021 -0500
Branches: master
https://developer.blender.org/rBe463d2c16f72e976ed1c886aca3f8efe396978fb

UI: Change node editor grid into a dot grid

This patch makes the background grid of the node editor a grid of dots
instead of lines. This makes the background look a bit more subtle and
reduces visual complexity. The dots are meant to provide a reference
when panning and zooming. Based on the design of @pablovazquez, and
a patch originally authored by @fabian_schempp.

The "Grid Levels" controls how many levels of dots are drawn. As the
editor zooms in, the higher levels of dots fade in, making them closer
together visually. The zoom factor at which each grid starts and ends
fading in is controllable in the code, and could be tweaked further
in the future. The new default value is 7, out of a range from 0 to 9.

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

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

M	release/datafiles/userdef/userdef_default_theme.c
M	release/scripts/presets/interface_theme/Blender_Light.xml
M	source/blender/blenkernel/BKE_blender_version.h
M	source/blender/blenloader/intern/versioning_userdef.c
M	source/blender/editors/include/ED_node.h
M	source/blender/editors/include/UI_view2d.h
M	source/blender/editors/interface/view2d.c
M	source/blender/editors/space_node/node_draw.cc
M	source/blender/makesrna/intern/rna_userdef.c

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

diff --git a/release/datafiles/userdef/userdef_default_theme.c b/release/datafiles/userdef/userdef_default_theme.c
index ad93f87e962..867a4c8f56b 100644
--- a/release/datafiles/userdef/userdef_default_theme.c
+++ b/release/datafiles/userdef/userdef_default_theme.c
@@ -817,7 +817,7 @@ const bTheme U_theme_default = {
       .sub_back = RGBA(0x0000003e),
     },
     .shade2 = RGBA(0x7f707064),
-    .grid = RGBA(0x23232300),
+    .grid = RGBA(0x3d3d3d00),
     .wire = RGBA(0x232323ff),
     .select = RGBA(0xed5700ff),
     .active = RGBA(0xffffffff),
@@ -827,7 +827,7 @@ const bTheme U_theme_default = {
     .outline_width = 1,
     .facedot_size = 4,
     .noodle_curving = 4,
-    .grid_levels = 2,
+    .grid_levels = 7,
     .dash_alpha = 0.5f,
     .syntaxl = RGBA(0x565656ff),
     .syntaxs = RGBA(0x975b5bff),
diff --git a/release/scripts/presets/interface_theme/Blender_Light.xml b/release/scripts/presets/interface_theme/Blender_Light.xml
index 8074371c450..f4188e83e34 100644
--- a/release/scripts/presets/interface_theme/Blender_Light.xml
+++ b/release/scripts/presets/interface_theme/Blender_Light.xml
@@ -939,7 +939,7 @@
     </text_editor>
     <node_editor>
       <ThemeNodeEditor
-        grid="#353535"
+        grid="#1B1B1B"
         node_selected="#f15800"
         node_active="#f15800"
         wire="#191919"
@@ -955,7 +955,7 @@
         matte_node="#977474"
         distor_node="#749797"
         noodle_curving="4"
-        grid_levels="2"
+        grid_levels="7"
         dash_alpha="0.5"
         input_node="#cb3d4a"
         output_node="#cb3d4a"
diff --git a/source/blender/blenkernel/BKE_blender_version.h b/source/blender/blenkernel/BKE_blender_version.h
index 3f8b56b2736..d39dc8bc406 100644
--- a/source/blender/blenkernel/BKE_blender_version.h
+++ b/source/blender/blenkernel/BKE_blender_version.h
@@ -39,7 +39,7 @@ extern "C" {
 
 /* Blender file format version. */
 #define BLENDER_FILE_VERSION BLENDER_VERSION
-#define BLENDER_FILE_SUBVERSION 38
+#define BLENDER_FILE_SUBVERSION 39
 
 /* Minimum Blender version that supports reading file written with the current
  * version. Older Blender versions will test this and show a warning if the file
diff --git a/source/blender/blenloader/intern/versioning_userdef.c b/source/blender/blenloader/intern/versioning_userdef.c
index 170e6be715a..9b81d8b19aa 100644
--- a/source/blender/blenloader/intern/versioning_userdef.c
+++ b/source/blender/blenloader/intern/versioning_userdef.c
@@ -314,6 +314,11 @@ static void do_versions_theme(const UserDef *userdef, bTheme *btheme)
     btheme->space_node.dash_alpha = 0.5f;
   }
 
+  if (!USER_VERSION_ATLEAST(300, 39)) {
+    FROM_DEFAULT_V4_UCHAR(space_node.grid);
+    btheme->space_node.grid_levels = 7;
+  }
+
   /**
    * Versioning code until next subversion bump goes here.
    *
diff --git a/source/blender/editors/include/ED_node.h b/source/blender/editors/include/ED_node.h
index 1d51a3e77cf..1ba52552902 100644
--- a/source/blender/editors/include/ED_node.h
+++ b/source/blender/editors/include/ED_node.h
@@ -49,7 +49,7 @@ typedef enum {
   NODE_RIGHT = 8,
 } NodeBorder;
 
-#define NODE_GRID_STEPS 5
+#define NODE_GRID_STEP_SIZE 10
 #define NODE_EDGE_PAN_INSIDE_PAD 2
 #define NODE_EDGE_PAN_OUTSIDE_PAD 0 /* Disable clamping for node panning, use whole screen. */
 #define NODE_EDGE_PAN_SPEED_RAMP 1
diff --git a/source/blender/editors/include/UI_view2d.h b/source/blender/editors/include/UI_view2d.h
index 13895879f01..e959f9ae7ce 100644
--- a/source/blender/editors/include/UI_view2d.h
+++ b/source/blender/editors/include/UI_view2d.h
@@ -147,6 +147,10 @@ void UI_view2d_view_restore(const struct bContext *C);
 /* grid drawing */
 void UI_view2d_multi_grid_draw(
     const struct View2D *v2d, int colorid, float step, int level_size, int totlevels);
+void UI_view2d_dot_grid_draw(const struct View2D *v2d,
+                             int grid_color_id,
+                             float step,
+                             int grid_levels);
 
 void UI_view2d_draw_lines_y__values(const struct View2D *v2d);
 void UI_view2d_draw_lines_x__values(const struct View2D *v2d);
diff --git a/source/blender/editors/interface/view2d.c b/source/blender/editors/interface/view2d.c
index ca96fde9810..30483f11c45 100644
--- a/source/blender/editors/interface/view2d.c
+++ b/source/blender/editors/interface/view2d.c
@@ -32,6 +32,7 @@
 #include "DNA_userdef_types.h"
 
 #include "BLI_array.h"
+#include "BLI_easing.h"
 #include "BLI_link_utils.h"
 #include "BLI_listbase.h"
 #include "BLI_math.h"
@@ -1291,6 +1292,114 @@ void UI_view2d_multi_grid_draw(
   immUnbindProgram();
 }
 
+static void grid_axis_start_and_count(
+    const float step, const float min, const float max, float *r_start, int *r_count)
+{
+  *r_start = min;
+  if (*r_start < 0.0f) {
+    *r_start += -(float)fmod(min, step);
+  }
+  else {
+    *r_start += step - (float)fabs(fmod(min, step));
+  }
+
+  if (*r_start > max) {
+    *r_count = 0;
+  }
+  else {
+    *r_count = (max - *r_start) / step + 1;
+  }
+}
+
+typedef struct DotGridLevelInfo {
+  /* The factor applied to the #min_step argument. This could be easily computed in runtime,
+   * but seeing it together with the other values is helpful. */
+  float step_factor;
+  /* The normalized zoom level at which the grid level starts to fade in.
+   * At lower zoom levels, the points will not be visible and the level will be skipped. */
+  float fade_in_start_zoom;
+  /* The normalized zoom level at which the grid finishes fading in.
+   * At higher zoom levels, the points will be opaque. */
+  float fade_in_end_zoom;
+} DotGridLevelInfo;
+
+static const DotGridLevelInfo level_info[9] = {
+    {128.0f, -0.1f, 0.01f},
+    {64.0f, 0.0f, 0.025f},
+    {32.0f, 0.025f, 0.15f},
+    {16.0f, 0.05f, 0.2f},
+    {8.0f, 0.1f, 0.25f},
+    {4.0f, 0.125f, 0.3f},
+    {2.0f, 0.25f, 0.5f},
+    {1.0f, 0.7f, 0.9f},
+    {0.5f, 0.6f, 0.9f},
+};
+
+/**
+ * Draw a multi-level grid of dots, with a dynamic number of levels based on the fading.
+ *
+ * \param grid_color_id: The theme color used for the points. Faded dynamically based on zoom.
+ * \param min_step: The base size of the grid. At different zoom levels, the visible grid may have
+ * a larger step size.
+ * \param grid_levels: The maximum grid depth. Larger grid levels will subdivide the grid more.
+ */
+void UI_view2d_dot_grid_draw(const View2D *v2d,
+                             const int grid_color_id,
+                             const float min_step,
+                             const int grid_levels)
+{
+  BLI_assert(grid_levels > 0 && grid_levels < 10);
+  const float zoom_x = (float)(BLI_rcti_size_x(&v2d->mask) + 1) / BLI_rctf_size_x(&v2d->cur);
+  const float zoom_normalized = (zoom_x - v2d->minzoom) / (v2d->maxzoom - v2d->minzoom);
+
+  GPUVertFormat *format = immVertexFormat();
+  const uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+  const uint color_id = GPU_vertformat_attr_add(format, "color", GPU_COMP_F32, 4, GPU_FETCH_FLOAT);
+  immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR);
+  GPU_point_size(3.0f * UI_DPI_FAC);
+
+  float color[4];
+  UI_GetThemeColor3fv(grid_color_id, color);
+
+  for (int level = 0; level < grid_levels; level++) {
+    const DotGridLevelInfo *info = &level_info[level];
+    const float step = min_step * info->step_factor;
+
+    const float alpha_factor = (zoom_normalized - info->fade_in_start_zoom) /
+                               (info->fade_in_end_zoom - info->fade_in_start_zoom);
+    color[3] = clamp_f(BLI_easing_cubic_ease_in_out(alpha_factor, 0.0f, 1.0f, 1.0f), 0.0f, 1.0f);
+    if (color[3] == 0.0f) {
+      break;
+    }
+
+    int count_x;
+    float start_x;
+    grid_axis_start_and_count(step, v2d->cur.xmin, v2d->cur.xmax, &start_x, &count_x);
+    int count_y;
+    float start_y;
+    grid_axis_start_and_count(step, v2d->cur.ymin, v2d->cur.ymax, &start_y, &count_y);
+    if (count_x == 0 || count_y == 0) {
+      continue;
+    }
+
+    immBegin(GPU_PRIM_POINTS, count_x * count_y);
+
+    /* Theoretically drawing on top of lower grid levels could be avoided, but it would also
+     * increase the complexity of this loop, which isn't worth the time at the moment. */
+    for (int i_y = 0; i_y < count_y; i_y++) {
+      const float y = start_y + step * i_y;
+      for (int i_x = 0; i_x < count_x; i_x++) {
+        const float x = start_x + step * i_x;
+        immAttr4fv(color_id, color);
+        immVertex2f(pos, x, y);
+      }
+    }
+
+    immEnd();
+  }
+
+  immUnbindProgram();
+}
 /** \} */
 
 /* -------------------------------------------------------------------- */
diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc
index 97655080192..8029eb5e0fa 100644
--- a/source/blender/editors/space_node/node_draw.cc
+++ b/source/blender/editors/space_node/node_draw.cc
@@ -2227,8 +2227,6 @@ void node_draw_space(const bContext *C, ARegion *region)
   snode->runtime->cursor[0] /= UI_DPI_FAC;
   snode->runtime->cursor[1] /= UI_DPI_FAC;
 
-  int grid_levels = UI_GetThemeValueType(TH_NODE_GRID_LEVELS, SPACE_NODE);
-
   ED_region_draw_cb_draw(C, region, REGION_DRAW_PRE_VIEW);
 
   /* Only set once. */
@@ -2259,14 +2257,14 @@ void node_draw_space(const bContext *C, ARegion *region)
       copy_v2_v2(snode->edittree->view_center, center);
     }
 
+    const int grid_levels = UI_GetThemeValueType(TH_NODE_GRID_LEVELS, SPACE_NODE);
+    UI_view2d_dot_grid_draw(v2d, TH_GRID, NODE_GRID_STEP_SIZE, grid_levels);
+
     /* Top-level edit tree. */
     bNodeTree *ntree = path->nodetree;
     if (ntree) {
       snode_setup_v2d(snode, region, center);
 
-      /* Grid. */
-      UI_view2d_multi_grid_draw(v2d, TH_GRID, ED_node_grid_size(), NODE_GRID_STEPS, grid_levels);
-
       /* Backdrop. */
       draw_nodespace_back_pix(C, region, snode, path->parent_key);
 
@@ -2305,8 +2303,6 @@ void node_draw_space(const bContext *C, ARegion *region)
     }
   }
   else {
-    /* Default grid. */
-    UI_view2d_multi_grid_draw(v2d, TH_GRID, ED_node_grid_size(), NODE_GRID_STEPS, grid_levels);
 
     /* Backdrop. */
     draw_nodespace_back_pix(C, region, snode, NODE_INSTANCE_KEY_NONE);
diff --git a/source/blender/m

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list