[Bf-blender-cvs] [0d67eb277f9] master: Gizmo: support 3D arrow gizmos in 2D spaces

Campbell Barton noreply at git.blender.org
Mon Jan 6 13:24:51 CET 2020


Commit: 0d67eb277f9bcf01ab6781ae27816caf690eb671
Author: Campbell Barton
Date:   Mon Jan 6 22:42:49 2020 +1100
Branches: master
https://developer.blender.org/rB0d67eb277f9bcf01ab6781ae27816caf690eb671

Gizmo: support 3D arrow gizmos in 2D spaces

Allows 2D arrows to be removed, since they work slightly differently
and don't support offset matrices.

Use these in the UV editor.

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

M	source/blender/editors/gizmo_library/gizmo_types/arrow3d_gizmo.c
M	source/blender/editors/transform/transform_gizmo_2d.c

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

diff --git a/source/blender/editors/gizmo_library/gizmo_types/arrow3d_gizmo.c b/source/blender/editors/gizmo_library/gizmo_types/arrow3d_gizmo.c
index 6a28c626a81..c19613e4d8d 100644
--- a/source/blender/editors/gizmo_library/gizmo_types/arrow3d_gizmo.c
+++ b/source/blender/editors/gizmo_library/gizmo_types/arrow3d_gizmo.c
@@ -33,6 +33,7 @@
  */
 
 #include "BLI_math.h"
+#include "BLI_utildefines.h"
 
 #include "DNA_view3d_types.h"
 
@@ -56,6 +57,8 @@
 #include "ED_screen.h"
 #include "ED_gizmo_library.h"
 
+#include "UI_interface.h"
+
 /* own includes */
 #include "../gizmo_geometry.h"
 #include "../gizmo_library_intern.h"
@@ -213,6 +216,37 @@ static void gizmo_arrow_draw(const bContext *UNUSED(C), wmGizmo *gz)
   arrow_draw_intern((ArrowGizmo3D *)gz, false, (gz->state & WM_GIZMO_STATE_HIGHLIGHT) != 0);
 }
 
+/**
+ * Selection for 2D views.
+ */
+static int gizmo_arrow_test_select(bContext *UNUSED(C), wmGizmo *gz, const int mval[2])
+{
+  /* Project into 2D space since it simplifies pixel threshold tests. */
+  ArrowGizmo3D *arrow = (ArrowGizmo3D *)gz;
+  const float arrow_length = RNA_float_get(arrow->gizmo.ptr, "length");
+
+  float matrix_final[4][4];
+  WM_gizmo_calc_matrix_final(gz, matrix_final);
+
+  /* Arrow in pixel space. */
+  float arrow_start[2] = {matrix_final[3][0], matrix_final[3][1]};
+  float arrow_end[2];
+  {
+    float co[3] = {0, 0, arrow_length};
+    mul_m4_v3(matrix_final, co);
+    copy_v2_v2(arrow_end, co);
+  }
+
+  const float mval_fl[2] = {UNPACK2(mval)};
+  const float arrow_stem_threshold_px = 5 * UI_DPI_FAC;
+  const float arrow_head_threshold_px = 10 * UI_DPI_FAC;
+  if (dist_squared_to_line_v2(mval_fl, arrow_start, arrow_end) < SQUARE(arrow_stem_threshold_px) ||
+      len_squared_v2v2(mval_fl, arrow_end) < SQUARE(arrow_head_threshold_px)) {
+    return 0;
+  }
+  return -1;
+}
+
 /**
  * Calculate arrow offset independent from prop min value,
  * meaning the range will not be offset by min value first.
@@ -427,6 +461,7 @@ static void GIZMO_GT_arrow_3d(wmGizmoType *gzt)
   /* api callbacks */
   gzt->draw = gizmo_arrow_draw;
   gzt->draw_select = gizmo_arrow_draw_select;
+  gzt->test_select = gizmo_arrow_test_select;
   gzt->matrix_basis_get = gizmo_arrow_matrix_basis_get;
   gzt->modal = gizmo_arrow_modal;
   gzt->setup = gizmo_arrow_setup;
diff --git a/source/blender/editors/transform/transform_gizmo_2d.c b/source/blender/editors/transform/transform_gizmo_2d.c
index 43deb768f52..131345f7285 100644
--- a/source/blender/editors/transform/transform_gizmo_2d.c
+++ b/source/blender/editors/transform/transform_gizmo_2d.c
@@ -115,7 +115,7 @@ static void gizmo2d_get_axis_color(const int axis_idx, float *r_col, float *r_co
 
 static GizmoGroup2D *gizmogroup2d_init(wmGizmoGroup *gzgroup)
 {
-  const wmGizmoType *gzt_arrow = WM_gizmotype_find("GIZMO_GT_arrow_2d", true);
+  const wmGizmoType *gzt_arrow = WM_gizmotype_find("GIZMO_GT_arrow_3d", true);
   const wmGizmoType *gzt_cage = WM_gizmotype_find("GIZMO_GT_cage_2d", true);
   const wmGizmoType *gzt_button = WM_gizmotype_find("GIZMO_GT_button_2d", true);
 
@@ -214,8 +214,11 @@ void ED_widgetgroup_gizmo2d_xform_setup(const bContext *UNUSED(C), wmGizmoGroup
       gizmo2d_get_axis_color(i, color, color_hi);
 
       /* set up widget data */
-      RNA_float_set(gz->ptr, "angle", -M_PI_2 * i);
       RNA_float_set(gz->ptr, "length", 0.8f);
+      float axis[3] = {0.0f};
+      axis[(i + 1) % 2] = 1.0f;
+      WM_gizmo_set_matrix_rotation_from_z_axis(gz, axis);
+
       WM_gizmo_set_matrix_offset_location(gz, offset);
       WM_gizmo_set_line_width(gz, GIZMO_AXIS_LINE_WIDTH);
       WM_gizmo_set_color(gz, color);
@@ -453,7 +456,7 @@ typedef struct GizmoGroup_Resize2D {
 
 static GizmoGroup_Resize2D *gizmogroup2d_resize_init(wmGizmoGroup *gzgroup)
 {
-  const wmGizmoType *gzt_arrow = WM_gizmotype_find("GIZMO_GT_arrow_2d", true);
+  const wmGizmoType *gzt_arrow = WM_gizmotype_find("GIZMO_GT_arrow_3d", true);
   const wmGizmoType *gzt_button = WM_gizmotype_find("GIZMO_GT_button_2d", true);
 
   GizmoGroup_Resize2D *ggd = MEM_callocN(sizeof(GizmoGroup_Resize2D), __func__);
@@ -521,8 +524,11 @@ void ED_widgetgroup_gizmo2d_resize_setup(const bContext *UNUSED(C), wmGizmoGroup
       gizmo2d_get_axis_color(i, color, color_hi);
 
       /* set up widget data */
-      RNA_float_set(gz->ptr, "angle", -M_PI_2 * i);
       RNA_float_set(gz->ptr, "length", 0.8f);
+      float axis[3] = {0.0f};
+      axis[(i + 1) % 2] = 1.0f;
+      WM_gizmo_set_matrix_rotation_from_z_axis(gz, axis);
+
       RNA_enum_set(gz->ptr, "draw_style", ED_GIZMO_ARROW_STYLE_BOX);
 
       WM_gizmo_set_matrix_offset_location(gz, offset);



More information about the Bf-blender-cvs mailing list