[Bf-extensions-cvs] [754d05ac] master: Snap Utilities Line: consider UI scaling for drawing and snapping

Germano Cavalcante noreply at git.blender.org
Wed Apr 13 15:56:37 CEST 2022


Commit: 754d05ac7ebb78377bbe6d80068542c43d347974
Author: Germano Cavalcante
Date:   Wed Apr 13 03:21:34 2022 -0300
Branches: master
https://developer.blender.org/rBA754d05ac7ebb78377bbe6d80068542c43d347974

Snap Utilities Line: consider UI scaling for drawing and snapping

Better match between monitors with different DPI.

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

M	mesh_snap_utilities_line/__init__.py
M	mesh_snap_utilities_line/common_classes.py
M	mesh_snap_utilities_line/common_utilities.py
M	mesh_snap_utilities_line/drawing_utilities.py

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

diff --git a/mesh_snap_utilities_line/__init__.py b/mesh_snap_utilities_line/__init__.py
index 6dd6b842..c424a342 100644
--- a/mesh_snap_utilities_line/__init__.py
+++ b/mesh_snap_utilities_line/__init__.py
@@ -6,7 +6,7 @@
 bl_info = {
     "name": "Snap_Utilities_Line",
     "author": "Germano Cavalcante",
-    "version": (6, 9, 7),
+    "version": (6, 9, 8),
     "blender": (3, 2, 0),
     "location": "View3D > TOOLS > Line Tool",
     "description": "Extends Blender Snap controls",
diff --git a/mesh_snap_utilities_line/common_classes.py b/mesh_snap_utilities_line/common_classes.py
index 949646ad..274c8f35 100644
--- a/mesh_snap_utilities_line/common_classes.py
+++ b/mesh_snap_utilities_line/common_classes.py
@@ -431,7 +431,8 @@ class SnapUtilities:
 
         #Create Snap Context
         self.sctx = global_snap_context_get(context.evaluated_depsgraph_get(), context.region, context.space_data)
-        self.sctx.set_pixel_dist(12)
+        ui_scale = context.preferences.system.ui_scale
+        self.sctx.set_pixel_dist(12 * ui_scale)
 
         if SnapUtilities.snapwidgets:
             widget = SnapUtilities.snapwidgets[-1]
@@ -469,7 +470,8 @@ class SnapUtilities:
                 tuple(context.preferences.themes[0].user_interface.axis_x) + (1.0,),
                 tuple(context.preferences.themes[0].user_interface.axis_y) + (1.0,),
                 tuple(context.preferences.themes[0].user_interface.axis_z) + (1.0,),
-                self.sctx.rv3d)
+                self.sctx.rv3d,
+                ui_scale)
 
         self.snap_vert = self.snap_edge = snap_edge_and_vert
 
diff --git a/mesh_snap_utilities_line/common_utilities.py b/mesh_snap_utilities_line/common_utilities.py
index 447265d8..d992141a 100644
--- a/mesh_snap_utilities_line/common_utilities.py
+++ b/mesh_snap_utilities_line/common_utilities.py
@@ -232,11 +232,11 @@ def snap_utilities(
             r_loc = t_loc[0]
 
         elif _snap_cache.edge.v2dperp and\
-            abs(_snap_cache.edge.v2dperp[0] - mcursor[0]) < 10 and abs(_snap_cache.edge.v2dperp[1] - mcursor[1]) < 10:
+            abs(_snap_cache.edge.v2dperp[0] - mcursor[0]) < sctx._dist_px and abs(_snap_cache.edge.v2dperp[1] - mcursor[1]) < sctx._dist_px:
                 r_type = 'PERPENDICULAR'
                 r_loc = _snap_cache.edge.vperp
 
-        elif abs(_snap_cache.edge.v2dmid[0] - mcursor[0]) < 10 and abs(_snap_cache.edge.v2dmid[1] - mcursor[1]) < 10:
+        elif abs(_snap_cache.edge.v2dmid[0] - mcursor[0]) < sctx._dist_px and abs(_snap_cache.edge.v2dmid[1] - mcursor[1]) < sctx._dist_px:
                 r_type = 'CENTER'
                 r_loc = _snap_cache.edge.vmid
 
diff --git a/mesh_snap_utilities_line/drawing_utilities.py b/mesh_snap_utilities_line/drawing_utilities.py
index 920e64c5..7f3fba39 100644
--- a/mesh_snap_utilities_line/drawing_utilities.py
+++ b/mesh_snap_utilities_line/drawing_utilities.py
@@ -16,6 +16,8 @@ class SnapDrawn():
         'axis_y_color',
         'axis_z_color',
         'rv3d',
+        '_point_size',
+        '_line_width',
         '_format_pos',
         '_format_pos_and_color',
         '_program_unif_col',
@@ -26,7 +28,7 @@ class SnapDrawn():
     def __init__(self, out_color, face_color,
                  edge_color, vert_color, center_color,
                  perpendicular_color, constrain_shift_color,
-                 axis_x_color, axis_y_color, axis_z_color, rv3d):
+                 axis_x_color, axis_y_color, axis_z_color, rv3d, ui_scale):
 
         import gpu
 
@@ -44,6 +46,9 @@ class SnapDrawn():
 
         self.rv3d = rv3d
 
+        self._point_size = 5 * ui_scale
+        self._line_width = 3 * ui_scale
+
         self._format_pos = gpu.types.GPUVertFormat()
         self._format_pos.attr_add(id="pos", comp_type='F32', len=3, fetch_mode='FLOAT')
 
@@ -164,7 +169,7 @@ class SnapDrawn():
             winmat[3][2] -= 0.0001
             gpu.matrix.push_projection()
             gpu.matrix.load_projection_matrix(winmat)
-            gpu.state.line_width_set(3.0)
+            gpu.state.line_width_set(self._line_width)
 
             batch = self.batch_line_strip_create([v.to_tuple() for v in list_verts_co] + [location.to_tuple()])
 
@@ -180,7 +185,7 @@ class SnapDrawn():
         point_batch = self.batch_point_get()
         if vector_constrain:
             if prevloc:
-                gpu.state.point_size_set(5.0)
+                gpu.state.point_size_set(self._point_size)
                 gpu.matrix.translate(prevloc)
 
                 self._program_unif_col.bind()
@@ -213,7 +218,7 @@ class SnapDrawn():
             else: # type == None
                 Color4f = self.out_color
 
-        gpu.state.point_size_set(10.0)
+        gpu.state.point_size_set(2 * self._point_size)
 
         gpu.matrix.translate(location)
         self._program_unif_col.bind()
@@ -252,7 +257,7 @@ class SnapDrawn():
                 edges.shape = -1
 
                 self._program_smooth_col.bind()
-                gpu.state.line_width_set(3.0)
+                gpu.state.line_width_set(self._line_width)
                 batch = self.batch_lines_smooth_color_create(edges["pos"], edges["color"])
                 batch.draw(self._program_smooth_col)
                 gpu.state.line_width_set(1.0)
@@ -261,7 +266,7 @@ class SnapDrawn():
                 self._program_unif_col.bind()
                 self._program_unif_col.uniform_float("color", self.edge_color)
 
-                gpu.state.line_width_set(3.0)
+                gpu.state.line_width_set(self._line_width)
                 batch = self.batch_line_strip_create([v.co for v in elem.verts])
                 batch.draw(self._program_unif_col)
                 gpu.state.line_width_set(1.0)



More information about the Bf-extensions-cvs mailing list