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:
authorCampbell Barton <ideasman42@gmail.com>2020-01-06 14:42:49 +0300
committerCampbell Barton <ideasman42@gmail.com>2020-01-06 15:21:45 +0300
commit0d67eb277f9bcf01ab6781ae27816caf690eb671 (patch)
tree9a42dd57f5051cb1adc8592395addd15dc74d016
parent98e4fbc7cc9e9bd6492e7bbb82e48dcf7b4d0bac (diff)
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.
-rw-r--r--source/blender/editors/gizmo_library/gizmo_types/arrow3d_gizmo.c35
-rw-r--r--source/blender/editors/transform/transform_gizmo_2d.c14
2 files changed, 45 insertions, 4 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;
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);