Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/gizmo_library')
-rw-r--r--source/blender/editors/gizmo_library/gizmo_types/arrow3d_gizmo.c35
1 files changed, 35 insertions, 0 deletions
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"
@@ -214,6 +217,37 @@ static void gizmo_arrow_draw(const bContext *UNUSED(C), wmGizmo *gz)
}
/**
+ * 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;