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/gizmo_types')
-rw-r--r--source/blender/editors/gizmo_library/gizmo_types/arrow2d_gizmo.c229
-rw-r--r--source/blender/editors/gizmo_library/gizmo_types/arrow3d_gizmo.c641
-rw-r--r--source/blender/editors/gizmo_library/gizmo_types/blank3d_gizmo.c34
-rw-r--r--source/blender/editors/gizmo_library/gizmo_types/button2d_gizmo.c401
-rw-r--r--source/blender/editors/gizmo_library/gizmo_types/cage2d_gizmo.c1925
-rw-r--r--source/blender/editors/gizmo_library/gizmo_types/cage3d_gizmo.c1011
-rw-r--r--source/blender/editors/gizmo_library/gizmo_types/dial3d_gizmo.c955
-rw-r--r--source/blender/editors/gizmo_library/gizmo_types/move3d_gizmo.c648
-rw-r--r--source/blender/editors/gizmo_library/gizmo_types/primitive3d_gizmo.c165
-rw-r--r--source/blender/editors/gizmo_library/gizmo_types/value2d_gizmo.c188
10 files changed, 3169 insertions, 3028 deletions
diff --git a/source/blender/editors/gizmo_library/gizmo_types/arrow2d_gizmo.c b/source/blender/editors/gizmo_library/gizmo_types/arrow2d_gizmo.c
index b4bf4c6726c..c175bfb90ab 100644
--- a/source/blender/editors/gizmo_library/gizmo_types/arrow2d_gizmo.c
+++ b/source/blender/editors/gizmo_library/gizmo_types/arrow2d_gizmo.c
@@ -31,7 +31,6 @@
#include "BKE_context.h"
-
#include "GPU_draw.h"
#include "GPU_immediate.h"
#include "GPU_matrix.h"
@@ -54,133 +53,130 @@
static void arrow2d_draw_geom(wmGizmo *gz, const float matrix[4][4], const float color[4])
{
- const float size = 0.11f;
- const float size_breadth = size / 2.0f;
- const float size_length = size * 1.7f;
- /* Subtract the length so the arrow fits in the hotspot. */
- const float arrow_length = RNA_float_get(gz->ptr, "length") - size_length;
- const float arrow_angle = RNA_float_get(gz->ptr, "angle");
+ const float size = 0.11f;
+ const float size_breadth = size / 2.0f;
+ const float size_length = size * 1.7f;
+ /* Subtract the length so the arrow fits in the hotspot. */
+ const float arrow_length = RNA_float_get(gz->ptr, "length") - size_length;
+ const float arrow_angle = RNA_float_get(gz->ptr, "angle");
- uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+ uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
- GPU_matrix_push();
- GPU_matrix_mul(matrix);
- GPU_matrix_rotate_2d(RAD2DEGF(arrow_angle));
+ GPU_matrix_push();
+ GPU_matrix_mul(matrix);
+ GPU_matrix_rotate_2d(RAD2DEGF(arrow_angle));
- immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
- immUniformColor4fv(color);
+ immUniformColor4fv(color);
- immBegin(GPU_PRIM_LINES, 2);
- immVertex2f(pos, 0.0f, 0.0f);
- immVertex2f(pos, 0.0f, arrow_length);
- immEnd();
+ immBegin(GPU_PRIM_LINES, 2);
+ immVertex2f(pos, 0.0f, 0.0f);
+ immVertex2f(pos, 0.0f, arrow_length);
+ immEnd();
- immBegin(GPU_PRIM_TRIS, 3);
- immVertex2f(pos, size_breadth, arrow_length);
- immVertex2f(pos, -size_breadth, arrow_length);
- immVertex2f(pos, 0.0f, arrow_length + size_length);
- immEnd();
+ immBegin(GPU_PRIM_TRIS, 3);
+ immVertex2f(pos, size_breadth, arrow_length);
+ immVertex2f(pos, -size_breadth, arrow_length);
+ immVertex2f(pos, 0.0f, arrow_length + size_length);
+ immEnd();
- immUnbindProgram();
+ immUnbindProgram();
- GPU_matrix_pop();
+ GPU_matrix_pop();
}
static void gizmo_arrow2d_draw(const bContext *UNUSED(C), wmGizmo *gz)
{
- float color[4];
+ float color[4];
- float matrix_final[4][4];
+ float matrix_final[4][4];
- gizmo_color_get(gz, gz->state & WM_GIZMO_STATE_HIGHLIGHT, color);
+ gizmo_color_get(gz, gz->state & WM_GIZMO_STATE_HIGHLIGHT, color);
- GPU_line_width(gz->line_width);
+ GPU_line_width(gz->line_width);
- WM_gizmo_calc_matrix_final(gz, matrix_final);
+ WM_gizmo_calc_matrix_final(gz, matrix_final);
- GPU_blend(true);
- arrow2d_draw_geom(gz, matrix_final, color);
- GPU_blend(false);
+ GPU_blend(true);
+ arrow2d_draw_geom(gz, matrix_final, color);
+ GPU_blend(false);
- if (gz->interaction_data) {
- GizmoInteraction *inter = gz->interaction_data;
+ if (gz->interaction_data) {
+ GizmoInteraction *inter = gz->interaction_data;
- GPU_blend(true);
- arrow2d_draw_geom(gz, inter->init_matrix_final, (const float[4]){0.5f, 0.5f, 0.5f, 0.5f});
- GPU_blend(false);
- }
+ GPU_blend(true);
+ arrow2d_draw_geom(gz, inter->init_matrix_final, (const float[4]){0.5f, 0.5f, 0.5f, 0.5f});
+ GPU_blend(false);
+ }
}
static void gizmo_arrow2d_setup(wmGizmo *gz)
{
- gz->flag |= WM_GIZMO_DRAW_MODAL;
+ gz->flag |= WM_GIZMO_DRAW_MODAL;
}
-static int gizmo_arrow2d_invoke(
- bContext *UNUSED(C), wmGizmo *gz, const wmEvent *UNUSED(event))
+static int gizmo_arrow2d_invoke(bContext *UNUSED(C), wmGizmo *gz, const wmEvent *UNUSED(event))
{
- GizmoInteraction *inter = MEM_callocN(sizeof(GizmoInteraction), __func__);
+ GizmoInteraction *inter = MEM_callocN(sizeof(GizmoInteraction), __func__);
- copy_m4_m4(inter->init_matrix_basis, gz->matrix_basis);
- WM_gizmo_calc_matrix_final(gz, inter->init_matrix_final);
+ copy_m4_m4(inter->init_matrix_basis, gz->matrix_basis);
+ WM_gizmo_calc_matrix_final(gz, inter->init_matrix_final);
- gz->interaction_data = inter;
+ gz->interaction_data = inter;
- return OPERATOR_RUNNING_MODAL;
+ return OPERATOR_RUNNING_MODAL;
}
-static int gizmo_arrow2d_test_select(
- bContext *UNUSED(C), wmGizmo *gz, const int mval[2])
+static int gizmo_arrow2d_test_select(bContext *UNUSED(C), wmGizmo *gz, const int mval[2])
{
- const float mval_fl[2] = {UNPACK2(mval)};
- const float arrow_length = RNA_float_get(gz->ptr, "length");
- const float arrow_angle = RNA_float_get(gz->ptr, "angle");
- const float line_len = arrow_length * gz->scale_final;
- float mval_local[2];
-
- copy_v2_v2(mval_local, mval_fl);
- sub_v2_v2(mval_local, gz->matrix_basis[3]);
-
- float line[2][2];
- line[0][0] = line[0][1] = line[1][0] = 0.0f;
- line[1][1] = line_len;
-
- /* rotate only if needed */
- if (arrow_angle != 0.0f) {
- float rot_point[2];
- copy_v2_v2(rot_point, line[1]);
- rotate_v2_v2fl(line[1], rot_point, arrow_angle);
- }
-
- /* arrow line intersection check */
- float isect_1[2], isect_2[2];
- const int isect = isect_line_sphere_v2(
- line[0], line[1], mval_local, GIZMO_HOTSPOT + gz->line_width * 0.5f,
- isect_1, isect_2);
-
- if (isect > 0) {
- float line_ext[2][2]; /* extended line for segment check including hotspot */
- copy_v2_v2(line_ext[0], line[0]);
- line_ext[1][0] = line[1][0] + GIZMO_HOTSPOT * ((line[1][0] - line[0][0]) / line_len);
- line_ext[1][1] = line[1][1] + GIZMO_HOTSPOT * ((line[1][1] - line[0][1]) / line_len);
-
- const float lambda_1 = line_point_factor_v2(isect_1, line_ext[0], line_ext[1]);
- if (isect == 1) {
- if (IN_RANGE_INCL(lambda_1, 0.0f, 1.0f)) {
- return 0;
- }
- }
- else {
- BLI_assert(isect == 2);
- const float lambda_2 = line_point_factor_v2(isect_2, line_ext[0], line_ext[1]);
- if (IN_RANGE_INCL(lambda_1, 0.0f, 1.0f) && IN_RANGE_INCL(lambda_2, 0.0f, 1.0f)) {
- return 0;
- }
- }
- }
-
- return -1;
+ const float mval_fl[2] = {UNPACK2(mval)};
+ const float arrow_length = RNA_float_get(gz->ptr, "length");
+ const float arrow_angle = RNA_float_get(gz->ptr, "angle");
+ const float line_len = arrow_length * gz->scale_final;
+ float mval_local[2];
+
+ copy_v2_v2(mval_local, mval_fl);
+ sub_v2_v2(mval_local, gz->matrix_basis[3]);
+
+ float line[2][2];
+ line[0][0] = line[0][1] = line[1][0] = 0.0f;
+ line[1][1] = line_len;
+
+ /* rotate only if needed */
+ if (arrow_angle != 0.0f) {
+ float rot_point[2];
+ copy_v2_v2(rot_point, line[1]);
+ rotate_v2_v2fl(line[1], rot_point, arrow_angle);
+ }
+
+ /* arrow line intersection check */
+ float isect_1[2], isect_2[2];
+ const int isect = isect_line_sphere_v2(
+ line[0], line[1], mval_local, GIZMO_HOTSPOT + gz->line_width * 0.5f, isect_1, isect_2);
+
+ if (isect > 0) {
+ float line_ext[2][2]; /* extended line for segment check including hotspot */
+ copy_v2_v2(line_ext[0], line[0]);
+ line_ext[1][0] = line[1][0] + GIZMO_HOTSPOT * ((line[1][0] - line[0][0]) / line_len);
+ line_ext[1][1] = line[1][1] + GIZMO_HOTSPOT * ((line[1][1] - line[0][1]) / line_len);
+
+ const float lambda_1 = line_point_factor_v2(isect_1, line_ext[0], line_ext[1]);
+ if (isect == 1) {
+ if (IN_RANGE_INCL(lambda_1, 0.0f, 1.0f)) {
+ return 0;
+ }
+ }
+ else {
+ BLI_assert(isect == 2);
+ const float lambda_2 = line_point_factor_v2(isect_2, line_ext[0], line_ext[1]);
+ if (IN_RANGE_INCL(lambda_1, 0.0f, 1.0f) && IN_RANGE_INCL(lambda_2, 0.0f, 1.0f)) {
+ return 0;
+ }
+ }
+ }
+
+ return -1;
}
/* -------------------------------------------------------------------- */
@@ -190,27 +186,34 @@ static int gizmo_arrow2d_test_select(
static void GIZMO_GT_arrow_2d(wmGizmoType *gzt)
{
- /* identifiers */
- gzt->idname = "GIZMO_GT_arrow_2d";
-
- /* api callbacks */
- gzt->draw = gizmo_arrow2d_draw;
- gzt->setup = gizmo_arrow2d_setup;
- gzt->invoke = gizmo_arrow2d_invoke;
- gzt->test_select = gizmo_arrow2d_test_select;
-
- gzt->struct_size = sizeof(wmGizmo);
-
- /* rna */
- RNA_def_float(gzt->srna, "length", 1.0f, 0.0f, FLT_MAX, "Arrow Line Length", "", 0.0f, FLT_MAX);
- RNA_def_float_rotation(
- gzt->srna, "angle", 0, NULL, DEG2RADF(-360.0f), DEG2RADF(360.0f),
- "Roll", "", DEG2RADF(-360.0f), DEG2RADF(360.0f));
+ /* identifiers */
+ gzt->idname = "GIZMO_GT_arrow_2d";
+
+ /* api callbacks */
+ gzt->draw = gizmo_arrow2d_draw;
+ gzt->setup = gizmo_arrow2d_setup;
+ gzt->invoke = gizmo_arrow2d_invoke;
+ gzt->test_select = gizmo_arrow2d_test_select;
+
+ gzt->struct_size = sizeof(wmGizmo);
+
+ /* rna */
+ RNA_def_float(gzt->srna, "length", 1.0f, 0.0f, FLT_MAX, "Arrow Line Length", "", 0.0f, FLT_MAX);
+ RNA_def_float_rotation(gzt->srna,
+ "angle",
+ 0,
+ NULL,
+ DEG2RADF(-360.0f),
+ DEG2RADF(360.0f),
+ "Roll",
+ "",
+ DEG2RADF(-360.0f),
+ DEG2RADF(360.0f));
}
void ED_gizmotypes_arrow_2d(void)
{
- WM_gizmotype_append(GIZMO_GT_arrow_2d);
+ WM_gizmotype_append(GIZMO_GT_arrow_2d);
}
/** \} */
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 3e3aa13f184..d23965269ab 100644
--- a/source/blender/editors/gizmo_library/gizmo_types/arrow3d_gizmo.c
+++ b/source/blender/editors/gizmo_library/gizmo_types/arrow3d_gizmo.c
@@ -32,7 +32,6 @@
* - `matrix[2]` is the arrow direction (for all arrowes).
*/
-
#include "BLI_math.h"
#include "DNA_view3d_types.h"
@@ -66,329 +65,323 @@
//#define USE_GIZMO_CUSTOM_ARROWS
typedef struct ArrowGizmo3D {
- wmGizmo gizmo;
- GizmoCommonData data;
+ wmGizmo gizmo;
+ GizmoCommonData data;
} ArrowGizmo3D;
-
/* -------------------------------------------------------------------- */
static void gizmo_arrow_matrix_basis_get(const wmGizmo *gz, float r_matrix[4][4])
{
- ArrowGizmo3D *arrow = (ArrowGizmo3D *)gz;
+ ArrowGizmo3D *arrow = (ArrowGizmo3D *)gz;
- copy_m4_m4(r_matrix, arrow->gizmo.matrix_basis);
- madd_v3_v3fl(r_matrix[3], arrow->gizmo.matrix_basis[2], arrow->data.offset);
+ copy_m4_m4(r_matrix, arrow->gizmo.matrix_basis);
+ madd_v3_v3fl(r_matrix[3], arrow->gizmo.matrix_basis[2], arrow->data.offset);
}
static void arrow_draw_geom(const ArrowGizmo3D *arrow, const bool select, const float color[4])
{
- uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
- bool unbind_shader = true;
- const int draw_style = RNA_enum_get(arrow->gizmo.ptr, "draw_style");
- const int draw_options = RNA_enum_get(arrow->gizmo.ptr, "draw_options");
-
- immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
-
- if (draw_style == ED_GIZMO_ARROW_STYLE_CROSS) {
- immUniformColor4fv(color);
-
- immBegin(GPU_PRIM_LINES, 4);
- immVertex3f(pos, -1.0f, 0.0f, 0.0f);
- immVertex3f(pos, 1.0f, 0.0f, 0.0f);
- immVertex3f(pos, 0.0f, -1.0f, 0.0f);
- immVertex3f(pos, 0.0f, 1.0f, 0.0f);
- immEnd();
- }
- else if (draw_style == ED_GIZMO_ARROW_STYLE_CONE) {
- float aspect[2];
- RNA_float_get_array(arrow->gizmo.ptr, "aspect", aspect);
- const float unitx = aspect[0];
- const float unity = aspect[1];
- const float vec[4][3] = {
- {-unitx, -unity, 0},
- { unitx, -unity, 0},
- { unitx, unity, 0},
- {-unitx, unity, 0},
- };
-
- GPU_line_width(arrow->gizmo.line_width);
- wm_gizmo_vec_draw(color, vec, ARRAY_SIZE(vec), pos, GPU_PRIM_LINE_LOOP);
- }
- else {
+ uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
+ bool unbind_shader = true;
+ const int draw_style = RNA_enum_get(arrow->gizmo.ptr, "draw_style");
+ const int draw_options = RNA_enum_get(arrow->gizmo.ptr, "draw_options");
+
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+
+ if (draw_style == ED_GIZMO_ARROW_STYLE_CROSS) {
+ immUniformColor4fv(color);
+
+ immBegin(GPU_PRIM_LINES, 4);
+ immVertex3f(pos, -1.0f, 0.0f, 0.0f);
+ immVertex3f(pos, 1.0f, 0.0f, 0.0f);
+ immVertex3f(pos, 0.0f, -1.0f, 0.0f);
+ immVertex3f(pos, 0.0f, 1.0f, 0.0f);
+ immEnd();
+ }
+ else if (draw_style == ED_GIZMO_ARROW_STYLE_CONE) {
+ float aspect[2];
+ RNA_float_get_array(arrow->gizmo.ptr, "aspect", aspect);
+ const float unitx = aspect[0];
+ const float unity = aspect[1];
+ const float vec[4][3] = {
+ {-unitx, -unity, 0},
+ {unitx, -unity, 0},
+ {unitx, unity, 0},
+ {-unitx, unity, 0},
+ };
+
+ GPU_line_width(arrow->gizmo.line_width);
+ wm_gizmo_vec_draw(color, vec, ARRAY_SIZE(vec), pos, GPU_PRIM_LINE_LOOP);
+ }
+ else {
#ifdef USE_GIZMO_CUSTOM_ARROWS
- wm_gizmo_geometryinfo_draw(&wm_gizmo_geom_data_arrow, select, color);
+ wm_gizmo_geometryinfo_draw(&wm_gizmo_geom_data_arrow, select, color);
#else
- const float arrow_length = RNA_float_get(arrow->gizmo.ptr, "length");
-
- const float vec[2][3] = {
- {0.0f, 0.0f, 0.0f},
- {0.0f, 0.0f, arrow_length},
- };
-
- if (draw_options & ED_GIZMO_ARROW_DRAW_FLAG_STEM) {
- GPU_line_width(arrow->gizmo.line_width);
- wm_gizmo_vec_draw(color, vec, ARRAY_SIZE(vec), pos, GPU_PRIM_LINE_STRIP);
- }
- else {
- immUniformColor4fv(color);
- }
-
- /* *** draw arrow head *** */
-
- GPU_matrix_push();
-
- if (draw_style == ED_GIZMO_ARROW_STYLE_BOX) {
- const float size = 0.05f;
-
- /* translate to line end with some extra offset so box starts exactly where line ends */
- GPU_matrix_translate_3f(0.0f, 0.0f, arrow_length + size);
- /* scale down to box size */
- GPU_matrix_scale_3f(size, size, size);
-
- /* draw cube */
- immUnbindProgram();
- unbind_shader = false;
- wm_gizmo_geometryinfo_draw(&wm_gizmo_geom_data_cube, select, color);
- }
- else {
- BLI_assert(draw_style == ED_GIZMO_ARROW_STYLE_NORMAL);
-
- const float len = 0.25f;
- const float width = 0.06f;
-
- /* translate to line end */
- GPU_matrix_translate_3f(0.0f, 0.0f, arrow_length);
-
- imm_draw_circle_fill_3d(pos, 0.0, 0.0, width, 8);
- imm_draw_cylinder_fill_3d(pos, width, 0.0, len, 8, 1);
- }
-
- GPU_matrix_pop();
-#endif /* USE_GIZMO_CUSTOM_ARROWS */
- }
-
- if (unbind_shader) {
- immUnbindProgram();
- }
+ const float arrow_length = RNA_float_get(arrow->gizmo.ptr, "length");
+
+ const float vec[2][3] = {
+ {0.0f, 0.0f, 0.0f},
+ {0.0f, 0.0f, arrow_length},
+ };
+
+ if (draw_options & ED_GIZMO_ARROW_DRAW_FLAG_STEM) {
+ GPU_line_width(arrow->gizmo.line_width);
+ wm_gizmo_vec_draw(color, vec, ARRAY_SIZE(vec), pos, GPU_PRIM_LINE_STRIP);
+ }
+ else {
+ immUniformColor4fv(color);
+ }
+
+ /* *** draw arrow head *** */
+
+ GPU_matrix_push();
+
+ if (draw_style == ED_GIZMO_ARROW_STYLE_BOX) {
+ const float size = 0.05f;
+
+ /* translate to line end with some extra offset so box starts exactly where line ends */
+ GPU_matrix_translate_3f(0.0f, 0.0f, arrow_length + size);
+ /* scale down to box size */
+ GPU_matrix_scale_3f(size, size, size);
+
+ /* draw cube */
+ immUnbindProgram();
+ unbind_shader = false;
+ wm_gizmo_geometryinfo_draw(&wm_gizmo_geom_data_cube, select, color);
+ }
+ else {
+ BLI_assert(draw_style == ED_GIZMO_ARROW_STYLE_NORMAL);
+
+ const float len = 0.25f;
+ const float width = 0.06f;
+
+ /* translate to line end */
+ GPU_matrix_translate_3f(0.0f, 0.0f, arrow_length);
+
+ imm_draw_circle_fill_3d(pos, 0.0, 0.0, width, 8);
+ imm_draw_cylinder_fill_3d(pos, width, 0.0, len, 8, 1);
+ }
+
+ GPU_matrix_pop();
+#endif /* USE_GIZMO_CUSTOM_ARROWS */
+ }
+
+ if (unbind_shader) {
+ immUnbindProgram();
+ }
}
static void arrow_draw_intern(ArrowGizmo3D *arrow, const bool select, const bool highlight)
{
- wmGizmo *gz = &arrow->gizmo;
- float color[4];
- float matrix_final[4][4];
+ wmGizmo *gz = &arrow->gizmo;
+ float color[4];
+ float matrix_final[4][4];
- gizmo_color_get(gz, highlight, color);
+ gizmo_color_get(gz, highlight, color);
- WM_gizmo_calc_matrix_final(gz, matrix_final);
+ WM_gizmo_calc_matrix_final(gz, matrix_final);
- GPU_matrix_push();
- GPU_matrix_mul(matrix_final);
- GPU_blend(true);
- arrow_draw_geom(arrow, select, color);
- GPU_blend(false);
+ GPU_matrix_push();
+ GPU_matrix_mul(matrix_final);
+ GPU_blend(true);
+ arrow_draw_geom(arrow, select, color);
+ GPU_blend(false);
- GPU_matrix_pop();
+ GPU_matrix_pop();
- if (gz->interaction_data) {
- GizmoInteraction *inter = gz->interaction_data;
+ if (gz->interaction_data) {
+ GizmoInteraction *inter = gz->interaction_data;
- GPU_matrix_push();
- GPU_matrix_mul(inter->init_matrix_final);
+ GPU_matrix_push();
+ GPU_matrix_mul(inter->init_matrix_final);
+ GPU_blend(true);
+ arrow_draw_geom(arrow, select, (const float[4]){0.5f, 0.5f, 0.5f, 0.5f});
+ GPU_blend(false);
- GPU_blend(true);
- arrow_draw_geom(arrow, select, (const float[4]){0.5f, 0.5f, 0.5f, 0.5f});
- GPU_blend(false);
-
- GPU_matrix_pop();
- }
+ GPU_matrix_pop();
+ }
}
-static void gizmo_arrow_draw_select(
- const bContext *UNUSED(C), wmGizmo *gz,
- int select_id)
+static void gizmo_arrow_draw_select(const bContext *UNUSED(C), wmGizmo *gz, int select_id)
{
- GPU_select_load_id(select_id);
- arrow_draw_intern((ArrowGizmo3D *)gz, true, false);
+ GPU_select_load_id(select_id);
+ arrow_draw_intern((ArrowGizmo3D *)gz, true, false);
}
static void gizmo_arrow_draw(const bContext *UNUSED(C), wmGizmo *gz)
{
- arrow_draw_intern((ArrowGizmo3D *)gz, false, (gz->state & WM_GIZMO_STATE_HIGHLIGHT) != 0);
+ arrow_draw_intern((ArrowGizmo3D *)gz, false, (gz->state & WM_GIZMO_STATE_HIGHLIGHT) != 0);
}
/**
* Calculate arrow offset independent from prop min value,
* meaning the range will not be offset by min value first.
*/
-static int gizmo_arrow_modal(
- bContext *C, wmGizmo *gz, const wmEvent *event,
- eWM_GizmoFlagTweak tweak_flag)
+static int gizmo_arrow_modal(bContext *C,
+ wmGizmo *gz,
+ const wmEvent *event,
+ eWM_GizmoFlagTweak tweak_flag)
{
- if (event->type != MOUSEMOVE) {
- return OPERATOR_RUNNING_MODAL;
- }
- ArrowGizmo3D *arrow = (ArrowGizmo3D *)gz;
- GizmoInteraction *inter = gz->interaction_data;
- ARegion *ar = CTX_wm_region(C);
- RegionView3D *rv3d = ar->regiondata;
-
- float offset[3];
- float facdir = 1.0f;
-
- /* (src, dst) */
- struct {
- float mval[2];
- float ray_origin[3], ray_direction[3];
- float location[3];
- } proj[2] = {
- {.mval = {UNPACK2(inter->init_mval)}},
- {.mval = {UNPACK2(event->mval)}},
- };
-
- float arrow_co[3];
- float arrow_no[3];
- copy_v3_v3(arrow_co, inter->init_matrix_basis[3]);
- normalize_v3_v3(arrow_no, arrow->gizmo.matrix_basis[2]);
-
- int ok = 0;
-
- for (int j = 0; j < 2; j++) {
- ED_view3d_win_to_ray(
- ar, proj[j].mval,
- proj[j].ray_origin, proj[j].ray_direction);
- /* Force Y axis if we're view aligned */
- if (j == 0) {
- if (RAD2DEGF(acosf(dot_v3v3(proj[j].ray_direction, arrow->gizmo.matrix_basis[2]))) < 5.0f) {
- normalize_v3_v3(arrow_no, rv3d->viewinv[1]);
- }
- }
-
- float arrow_no_proj[3];
- project_plane_v3_v3v3(arrow_no_proj, arrow_no, proj[j].ray_direction);
-
- normalize_v3(arrow_no_proj);
-
- float plane[4];
- plane_from_point_normal_v3(plane, proj[j].ray_origin, arrow_no_proj);
-
- float lambda;
- if (isect_ray_plane_v3(arrow_co, arrow_no, plane, &lambda, false)) {
- madd_v3_v3v3fl(proj[j].location, arrow_co, arrow_no, lambda);
- ok++;
- }
- }
-
- if (ok != 2) {
- return OPERATOR_RUNNING_MODAL;
- }
-
- sub_v3_v3v3(offset, proj[1].location, proj[0].location);
- facdir = dot_v3v3(arrow_no, offset) < 0.0f ? -1 : 1;
-
- GizmoCommonData *data = &arrow->data;
- const float ofs_new = facdir * len_v3(offset);
-
- wmGizmoProperty *gz_prop = WM_gizmo_target_property_find(gz, "offset");
-
- /* set the property for the operator and call its modal function */
- if (WM_gizmo_target_property_is_valid(gz_prop)) {
- const int transform_flag = RNA_enum_get(arrow->gizmo.ptr, "transform");
- const bool constrained = (transform_flag & ED_GIZMO_ARROW_XFORM_FLAG_CONSTRAINED) != 0;
- const bool inverted = (transform_flag & ED_GIZMO_ARROW_XFORM_FLAG_INVERTED) != 0;
- const bool use_precision = (tweak_flag & WM_GIZMO_TWEAK_PRECISE) != 0;
- float value = gizmo_value_from_offset(data, inter, ofs_new, constrained, inverted, use_precision);
-
- WM_gizmo_target_property_float_set(C, gz, gz_prop, value);
- /* get clamped value */
- value = WM_gizmo_target_property_float_get(gz, gz_prop);
-
- data->offset = gizmo_offset_from_value(data, value, constrained, inverted);
- }
- else {
- data->offset = ofs_new;
- }
-
- /* tag the region for redraw */
- ED_region_tag_redraw(ar);
- WM_event_add_mousemove(C);
-
- return OPERATOR_RUNNING_MODAL;
+ if (event->type != MOUSEMOVE) {
+ return OPERATOR_RUNNING_MODAL;
+ }
+ ArrowGizmo3D *arrow = (ArrowGizmo3D *)gz;
+ GizmoInteraction *inter = gz->interaction_data;
+ ARegion *ar = CTX_wm_region(C);
+ RegionView3D *rv3d = ar->regiondata;
+
+ float offset[3];
+ float facdir = 1.0f;
+
+ /* (src, dst) */
+ struct {
+ float mval[2];
+ float ray_origin[3], ray_direction[3];
+ float location[3];
+ } proj[2] = {
+ {.mval = {UNPACK2(inter->init_mval)}},
+ {.mval = {UNPACK2(event->mval)}},
+ };
+
+ float arrow_co[3];
+ float arrow_no[3];
+ copy_v3_v3(arrow_co, inter->init_matrix_basis[3]);
+ normalize_v3_v3(arrow_no, arrow->gizmo.matrix_basis[2]);
+
+ int ok = 0;
+
+ for (int j = 0; j < 2; j++) {
+ ED_view3d_win_to_ray(ar, proj[j].mval, proj[j].ray_origin, proj[j].ray_direction);
+ /* Force Y axis if we're view aligned */
+ if (j == 0) {
+ if (RAD2DEGF(acosf(dot_v3v3(proj[j].ray_direction, arrow->gizmo.matrix_basis[2]))) < 5.0f) {
+ normalize_v3_v3(arrow_no, rv3d->viewinv[1]);
+ }
+ }
+
+ float arrow_no_proj[3];
+ project_plane_v3_v3v3(arrow_no_proj, arrow_no, proj[j].ray_direction);
+
+ normalize_v3(arrow_no_proj);
+
+ float plane[4];
+ plane_from_point_normal_v3(plane, proj[j].ray_origin, arrow_no_proj);
+
+ float lambda;
+ if (isect_ray_plane_v3(arrow_co, arrow_no, plane, &lambda, false)) {
+ madd_v3_v3v3fl(proj[j].location, arrow_co, arrow_no, lambda);
+ ok++;
+ }
+ }
+
+ if (ok != 2) {
+ return OPERATOR_RUNNING_MODAL;
+ }
+
+ sub_v3_v3v3(offset, proj[1].location, proj[0].location);
+ facdir = dot_v3v3(arrow_no, offset) < 0.0f ? -1 : 1;
+
+ GizmoCommonData *data = &arrow->data;
+ const float ofs_new = facdir * len_v3(offset);
+
+ wmGizmoProperty *gz_prop = WM_gizmo_target_property_find(gz, "offset");
+
+ /* set the property for the operator and call its modal function */
+ if (WM_gizmo_target_property_is_valid(gz_prop)) {
+ const int transform_flag = RNA_enum_get(arrow->gizmo.ptr, "transform");
+ const bool constrained = (transform_flag & ED_GIZMO_ARROW_XFORM_FLAG_CONSTRAINED) != 0;
+ const bool inverted = (transform_flag & ED_GIZMO_ARROW_XFORM_FLAG_INVERTED) != 0;
+ const bool use_precision = (tweak_flag & WM_GIZMO_TWEAK_PRECISE) != 0;
+ float value = gizmo_value_from_offset(
+ data, inter, ofs_new, constrained, inverted, use_precision);
+
+ WM_gizmo_target_property_float_set(C, gz, gz_prop, value);
+ /* get clamped value */
+ value = WM_gizmo_target_property_float_get(gz, gz_prop);
+
+ data->offset = gizmo_offset_from_value(data, value, constrained, inverted);
+ }
+ else {
+ data->offset = ofs_new;
+ }
+
+ /* tag the region for redraw */
+ ED_region_tag_redraw(ar);
+ WM_event_add_mousemove(C);
+
+ return OPERATOR_RUNNING_MODAL;
}
static void gizmo_arrow_setup(wmGizmo *gz)
{
- ArrowGizmo3D *arrow = (ArrowGizmo3D *)gz;
+ ArrowGizmo3D *arrow = (ArrowGizmo3D *)gz;
- arrow->gizmo.flag |= WM_GIZMO_DRAW_MODAL;
+ arrow->gizmo.flag |= WM_GIZMO_DRAW_MODAL;
- arrow->data.range_fac = 1.0f;
+ arrow->data.range_fac = 1.0f;
}
-static int gizmo_arrow_invoke(
- bContext *UNUSED(C), wmGizmo *gz, const wmEvent *event)
+static int gizmo_arrow_invoke(bContext *UNUSED(C), wmGizmo *gz, const wmEvent *event)
{
- ArrowGizmo3D *arrow = (ArrowGizmo3D *)gz;
- GizmoInteraction *inter = MEM_callocN(sizeof(GizmoInteraction), __func__);
- wmGizmoProperty *gz_prop = WM_gizmo_target_property_find(gz, "offset");
+ ArrowGizmo3D *arrow = (ArrowGizmo3D *)gz;
+ GizmoInteraction *inter = MEM_callocN(sizeof(GizmoInteraction), __func__);
+ wmGizmoProperty *gz_prop = WM_gizmo_target_property_find(gz, "offset");
- /* Some gizmos don't use properties. */
- if (WM_gizmo_target_property_is_valid(gz_prop)) {
- inter->init_value = WM_gizmo_target_property_float_get(gz, gz_prop);
- }
+ /* Some gizmos don't use properties. */
+ if (WM_gizmo_target_property_is_valid(gz_prop)) {
+ inter->init_value = WM_gizmo_target_property_float_get(gz, gz_prop);
+ }
- inter->init_offset = arrow->data.offset;
+ inter->init_offset = arrow->data.offset;
- inter->init_mval[0] = event->mval[0];
- inter->init_mval[1] = event->mval[1];
+ inter->init_mval[0] = event->mval[0];
+ inter->init_mval[1] = event->mval[1];
- gizmo_arrow_matrix_basis_get(gz, inter->init_matrix_basis);
- WM_gizmo_calc_matrix_final(gz, inter->init_matrix_final);
+ gizmo_arrow_matrix_basis_get(gz, inter->init_matrix_basis);
+ WM_gizmo_calc_matrix_final(gz, inter->init_matrix_final);
- gz->interaction_data = inter;
+ gz->interaction_data = inter;
- return OPERATOR_RUNNING_MODAL;
+ return OPERATOR_RUNNING_MODAL;
}
static void gizmo_arrow_property_update(wmGizmo *gz, wmGizmoProperty *gz_prop)
{
- ArrowGizmo3D *arrow = (ArrowGizmo3D *)gz;
- const int transform_flag = RNA_enum_get(arrow->gizmo.ptr, "transform");
- const bool constrained = (transform_flag & ED_GIZMO_ARROW_XFORM_FLAG_CONSTRAINED) != 0;
- const bool inverted = (transform_flag & ED_GIZMO_ARROW_XFORM_FLAG_INVERTED) != 0;
- gizmo_property_data_update(gz, &arrow->data, gz_prop, constrained, inverted);
+ ArrowGizmo3D *arrow = (ArrowGizmo3D *)gz;
+ const int transform_flag = RNA_enum_get(arrow->gizmo.ptr, "transform");
+ const bool constrained = (transform_flag & ED_GIZMO_ARROW_XFORM_FLAG_CONSTRAINED) != 0;
+ const bool inverted = (transform_flag & ED_GIZMO_ARROW_XFORM_FLAG_INVERTED) != 0;
+ gizmo_property_data_update(gz, &arrow->data, gz_prop, constrained, inverted);
}
static void gizmo_arrow_exit(bContext *C, wmGizmo *gz, const bool cancel)
{
- ArrowGizmo3D *arrow = (ArrowGizmo3D *)gz;
- GizmoCommonData *data = &arrow->data;
- wmGizmoProperty *gz_prop = WM_gizmo_target_property_find(gz, "offset");
- const bool is_prop_valid = WM_gizmo_target_property_is_valid(gz_prop);
-
- if (!cancel) {
- /* Assign incase applying the operation needs an updated offset
- * editmesh bisect needs this. */
- if (is_prop_valid) {
- const int transform_flag = RNA_enum_get(arrow->gizmo.ptr, "transform");
- const bool constrained = (transform_flag & ED_GIZMO_ARROW_XFORM_FLAG_CONSTRAINED) != 0;
- const bool inverted = (transform_flag & ED_GIZMO_ARROW_XFORM_FLAG_INVERTED) != 0;
- const float value = WM_gizmo_target_property_float_get(gz, gz_prop);
- data->offset = gizmo_offset_from_value(data, value, constrained, inverted);
- }
- return;
- }
-
- GizmoInteraction *inter = gz->interaction_data;
- if (is_prop_valid) {
- gizmo_property_value_reset(C, gz, inter, gz_prop);
- }
- data->offset = inter->init_offset;
+ ArrowGizmo3D *arrow = (ArrowGizmo3D *)gz;
+ GizmoCommonData *data = &arrow->data;
+ wmGizmoProperty *gz_prop = WM_gizmo_target_property_find(gz, "offset");
+ const bool is_prop_valid = WM_gizmo_target_property_is_valid(gz_prop);
+
+ if (!cancel) {
+ /* Assign incase applying the operation needs an updated offset
+ * editmesh bisect needs this. */
+ if (is_prop_valid) {
+ const int transform_flag = RNA_enum_get(arrow->gizmo.ptr, "transform");
+ const bool constrained = (transform_flag & ED_GIZMO_ARROW_XFORM_FLAG_CONSTRAINED) != 0;
+ const bool inverted = (transform_flag & ED_GIZMO_ARROW_XFORM_FLAG_INVERTED) != 0;
+ const float value = WM_gizmo_target_property_float_get(gz, gz_prop);
+ data->offset = gizmo_offset_from_value(data, value, constrained, inverted);
+ }
+ return;
+ }
+
+ GizmoInteraction *inter = gz->interaction_data;
+ if (is_prop_valid) {
+ gizmo_property_value_reset(C, gz, inter, gz_prop);
+ }
+ data->offset = inter->init_offset;
}
-
/* -------------------------------------------------------------------- */
/** \name Arrow Gizmo API
*
@@ -401,16 +394,16 @@ static void gizmo_arrow_exit(bContext *C, wmGizmo *gz, const bool cancel)
*/
void ED_gizmo_arrow3d_set_ui_range(wmGizmo *gz, const float min, const float max)
{
- ArrowGizmo3D *arrow = (ArrowGizmo3D *)gz;
+ ArrowGizmo3D *arrow = (ArrowGizmo3D *)gz;
- BLI_assert(min < max);
- BLI_assert(!(WM_gizmo_target_property_is_valid(WM_gizmo_target_property_find(gz, "offset")) &&
- "Make sure this function is called before WM_gizmo_target_property_def_rna"));
+ BLI_assert(min < max);
+ BLI_assert(!(WM_gizmo_target_property_is_valid(WM_gizmo_target_property_find(gz, "offset")) &&
+ "Make sure this function is called before WM_gizmo_target_property_def_rna"));
- arrow->data.range = max - min;
- arrow->data.min = min;
- arrow->data.max = max;
- arrow->data.is_custom_range_set = true;
+ arrow->data.range = max - min;
+ arrow->data.min = min;
+ arrow->data.max = max;
+ arrow->data.is_custom_range_set = true;
}
/**
@@ -420,70 +413,72 @@ void ED_gizmo_arrow3d_set_ui_range(wmGizmo *gz, const float min, const float max
*/
void ED_gizmo_arrow3d_set_range_fac(wmGizmo *gz, const float range_fac)
{
- ArrowGizmo3D *arrow = (ArrowGizmo3D *)gz;
- BLI_assert(!(WM_gizmo_target_property_is_valid(WM_gizmo_target_property_find(gz, "offset")) &&
- "Make sure this function is called before WM_gizmo_target_property_def_rna"));
+ ArrowGizmo3D *arrow = (ArrowGizmo3D *)gz;
+ BLI_assert(!(WM_gizmo_target_property_is_valid(WM_gizmo_target_property_find(gz, "offset")) &&
+ "Make sure this function is called before WM_gizmo_target_property_def_rna"));
- arrow->data.range_fac = range_fac;
+ arrow->data.range_fac = range_fac;
}
static void GIZMO_GT_arrow_3d(wmGizmoType *gzt)
{
- /* identifiers */
- gzt->idname = "GIZMO_GT_arrow_3d";
-
- /* api callbacks */
- gzt->draw = gizmo_arrow_draw;
- gzt->draw_select = gizmo_arrow_draw_select;
- gzt->matrix_basis_get = gizmo_arrow_matrix_basis_get;
- gzt->modal = gizmo_arrow_modal;
- gzt->setup = gizmo_arrow_setup;
- gzt->invoke = gizmo_arrow_invoke;
- gzt->property_update = gizmo_arrow_property_update;
- gzt->exit = gizmo_arrow_exit;
-
- gzt->struct_size = sizeof(ArrowGizmo3D);
-
- /* rna */
- static EnumPropertyItem rna_enum_draw_style_items[] = {
- {ED_GIZMO_ARROW_STYLE_NORMAL, "NORMAL", 0, "Normal", ""},
- {ED_GIZMO_ARROW_STYLE_CROSS, "CROSS", 0, "Cross", ""},
- {ED_GIZMO_ARROW_STYLE_BOX, "BOX", 0, "Box", ""},
- {ED_GIZMO_ARROW_STYLE_CONE, "CONE", 0, "Cone", ""},
- {0, NULL, 0, NULL, NULL},
- };
- static EnumPropertyItem rna_enum_draw_options_items[] = {
- {ED_GIZMO_ARROW_DRAW_FLAG_STEM, "STEM", 0, "Stem", ""},
- {0, NULL, 0, NULL, NULL},
- };
- static EnumPropertyItem rna_enum_transform_items[] = {
- {ED_GIZMO_ARROW_XFORM_FLAG_INVERTED, "INVERT", 0, "Inverted", ""},
- {ED_GIZMO_ARROW_XFORM_FLAG_CONSTRAINED, "CONSTRAIN", 0, "Constrained", ""},
- {0, NULL, 0, NULL, NULL},
- };
-
- RNA_def_enum(
- gzt->srna, "draw_style", rna_enum_draw_style_items,
- ED_GIZMO_ARROW_STYLE_NORMAL,
- "Draw Style", "");
- RNA_def_enum_flag(
- gzt->srna, "draw_options", rna_enum_draw_options_items,
- ED_GIZMO_ARROW_DRAW_FLAG_STEM,
- "Draw Options", "");
- RNA_def_enum_flag(
- gzt->srna, "transform", rna_enum_transform_items,
- 0,
- "Transform", "");
-
- RNA_def_float(gzt->srna, "length", 1.0f, 0.0f, FLT_MAX, "Arrow Line Length", "", 0.0f, FLT_MAX);
- RNA_def_float_vector(gzt->srna, "aspect", 2, NULL, 0, FLT_MAX, "Aspect", "Cone/box style only", 0.0f, FLT_MAX);
-
- WM_gizmotype_target_property_def(gzt, "offset", PROP_FLOAT, 1);
+ /* identifiers */
+ gzt->idname = "GIZMO_GT_arrow_3d";
+
+ /* api callbacks */
+ gzt->draw = gizmo_arrow_draw;
+ gzt->draw_select = gizmo_arrow_draw_select;
+ gzt->matrix_basis_get = gizmo_arrow_matrix_basis_get;
+ gzt->modal = gizmo_arrow_modal;
+ gzt->setup = gizmo_arrow_setup;
+ gzt->invoke = gizmo_arrow_invoke;
+ gzt->property_update = gizmo_arrow_property_update;
+ gzt->exit = gizmo_arrow_exit;
+
+ gzt->struct_size = sizeof(ArrowGizmo3D);
+
+ /* rna */
+ static EnumPropertyItem rna_enum_draw_style_items[] = {
+ {ED_GIZMO_ARROW_STYLE_NORMAL, "NORMAL", 0, "Normal", ""},
+ {ED_GIZMO_ARROW_STYLE_CROSS, "CROSS", 0, "Cross", ""},
+ {ED_GIZMO_ARROW_STYLE_BOX, "BOX", 0, "Box", ""},
+ {ED_GIZMO_ARROW_STYLE_CONE, "CONE", 0, "Cone", ""},
+ {0, NULL, 0, NULL, NULL},
+ };
+ static EnumPropertyItem rna_enum_draw_options_items[] = {
+ {ED_GIZMO_ARROW_DRAW_FLAG_STEM, "STEM", 0, "Stem", ""},
+ {0, NULL, 0, NULL, NULL},
+ };
+ static EnumPropertyItem rna_enum_transform_items[] = {
+ {ED_GIZMO_ARROW_XFORM_FLAG_INVERTED, "INVERT", 0, "Inverted", ""},
+ {ED_GIZMO_ARROW_XFORM_FLAG_CONSTRAINED, "CONSTRAIN", 0, "Constrained", ""},
+ {0, NULL, 0, NULL, NULL},
+ };
+
+ RNA_def_enum(gzt->srna,
+ "draw_style",
+ rna_enum_draw_style_items,
+ ED_GIZMO_ARROW_STYLE_NORMAL,
+ "Draw Style",
+ "");
+ RNA_def_enum_flag(gzt->srna,
+ "draw_options",
+ rna_enum_draw_options_items,
+ ED_GIZMO_ARROW_DRAW_FLAG_STEM,
+ "Draw Options",
+ "");
+ RNA_def_enum_flag(gzt->srna, "transform", rna_enum_transform_items, 0, "Transform", "");
+
+ RNA_def_float(gzt->srna, "length", 1.0f, 0.0f, FLT_MAX, "Arrow Line Length", "", 0.0f, FLT_MAX);
+ RNA_def_float_vector(
+ gzt->srna, "aspect", 2, NULL, 0, FLT_MAX, "Aspect", "Cone/box style only", 0.0f, FLT_MAX);
+
+ WM_gizmotype_target_property_def(gzt, "offset", PROP_FLOAT, 1);
}
void ED_gizmotypes_arrow_3d(void)
{
- WM_gizmotype_append(GIZMO_GT_arrow_3d);
+ WM_gizmotype_append(GIZMO_GT_arrow_3d);
}
/** \} */
diff --git a/source/blender/editors/gizmo_library/gizmo_types/blank3d_gizmo.c b/source/blender/editors/gizmo_library/gizmo_types/blank3d_gizmo.c
index 55054d1b4ad..e36ab0a0610 100644
--- a/source/blender/editors/gizmo_library/gizmo_types/blank3d_gizmo.c
+++ b/source/blender/editors/gizmo_library/gizmo_types/blank3d_gizmo.c
@@ -25,7 +25,6 @@
* \brief Gizmo to use as a fallback (catch events).
*/
-
#include "BKE_context.h"
#include "ED_view3d.h"
@@ -38,22 +37,23 @@
#include "../gizmo_geometry.h"
#include "../gizmo_library_intern.h"
-
static void gizmo_blank_draw(const bContext *UNUSED(C), wmGizmo *UNUSED(gz))
{
- /* pass */
+ /* pass */
}
-static int gizmo_blank_invoke(
- bContext *UNUSED(C), wmGizmo *UNUSED(gz), const wmEvent *UNUSED(event))
+static int gizmo_blank_invoke(bContext *UNUSED(C),
+ wmGizmo *UNUSED(gz),
+ const wmEvent *UNUSED(event))
{
- return OPERATOR_RUNNING_MODAL;
+ return OPERATOR_RUNNING_MODAL;
}
-static int gizmo_blank_test_select(
- bContext *UNUSED(C), wmGizmo *UNUSED(gz), const int UNUSED(mval[2]))
+static int gizmo_blank_test_select(bContext *UNUSED(C),
+ wmGizmo *UNUSED(gz),
+ const int UNUSED(mval[2]))
{
- return 0;
+ return 0;
}
/* -------------------------------------------------------------------- */
@@ -63,20 +63,20 @@ static int gizmo_blank_test_select(
static void GIZMO_GT_blank_3d(wmGizmoType *gzt)
{
- /* identifiers */
- gzt->idname = "GIZMO_GT_blank_3d";
+ /* identifiers */
+ gzt->idname = "GIZMO_GT_blank_3d";
- /* api callbacks */
- gzt->draw = gizmo_blank_draw;
- gzt->invoke = gizmo_blank_invoke;
- gzt->test_select = gizmo_blank_test_select;
+ /* api callbacks */
+ gzt->draw = gizmo_blank_draw;
+ gzt->invoke = gizmo_blank_invoke;
+ gzt->test_select = gizmo_blank_test_select;
- gzt->struct_size = sizeof(wmGizmo);
+ gzt->struct_size = sizeof(wmGizmo);
}
void ED_gizmotypes_blank_3d(void)
{
- WM_gizmotype_append(GIZMO_GT_blank_3d);
+ WM_gizmotype_append(GIZMO_GT_blank_3d);
}
/** \} */
diff --git a/source/blender/editors/gizmo_library/gizmo_types/button2d_gizmo.c b/source/blender/editors/gizmo_library/gizmo_types/button2d_gizmo.c
index 542b9aa19e3..1a132c2957a 100644
--- a/source/blender/editors/gizmo_library/gizmo_types/button2d_gizmo.c
+++ b/source/blender/editors/gizmo_library/gizmo_types/button2d_gizmo.c
@@ -32,7 +32,6 @@
#include "BKE_context.h"
-
#include "GPU_immediate.h"
#include "GPU_immediate_util.h"
#include "GPU_matrix.h"
@@ -61,218 +60,216 @@
#include "../gizmo_library_intern.h"
typedef struct ButtonGizmo2D {
- wmGizmo gizmo;
- bool is_init;
- /* Use an icon or shape */
- int icon;
- GPUBatch *shape_batch[2];
+ wmGizmo gizmo;
+ bool is_init;
+ /* Use an icon or shape */
+ int icon;
+ GPUBatch *shape_batch[2];
} ButtonGizmo2D;
#define CIRCLE_RESOLUTION 32
/* -------------------------------------------------------------------- */
-static void button2d_geom_draw_backdrop(
- const wmGizmo *gz, const float color[4], const bool select)
+static void button2d_geom_draw_backdrop(const wmGizmo *gz, const float color[4], const bool select)
{
- GPU_line_width(gz->line_width);
+ GPU_line_width(gz->line_width);
- GPUVertFormat *format = immVertexFormat();
- uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+ GPUVertFormat *format = immVertexFormat();
+ uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
- immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
- immUniformColor4fv(color);
+ immUniformColor4fv(color);
- /* TODO, other draw styles */
- imm_draw_circle_fill_2d(pos, 0, 0, 1.0f, CIRCLE_RESOLUTION);
+ /* TODO, other draw styles */
+ imm_draw_circle_fill_2d(pos, 0, 0, 1.0f, CIRCLE_RESOLUTION);
- immUnbindProgram();
+ immUnbindProgram();
- UNUSED_VARS(select);
+ UNUSED_VARS(select);
}
-static void button2d_draw_intern(
- const bContext *C, wmGizmo *gz,
- const bool select, const bool highlight)
+static void button2d_draw_intern(const bContext *C,
+ wmGizmo *gz,
+ const bool select,
+ const bool highlight)
{
- ButtonGizmo2D *button = (ButtonGizmo2D *)gz;
-
- const int draw_options = RNA_enum_get(gz->ptr, "draw_options");
- if (button->is_init == false) {
- button->is_init = true;
- PropertyRNA *prop = RNA_struct_find_property(gz->ptr, "icon");
- if (RNA_property_is_set(gz->ptr, prop)) {
- button->icon = RNA_property_enum_get(gz->ptr, prop);
- }
- else {
- prop = RNA_struct_find_property(gz->ptr, "shape");
- const uint polys_len = RNA_property_string_length(gz->ptr, prop);
- /* We shouldn't need the +1, but a NULL char is set. */
- char *polys = MEM_mallocN(polys_len + 1, __func__);
- RNA_property_string_get(gz->ptr, prop, polys);
- button->shape_batch[0] = GPU_batch_tris_from_poly_2d_encoded((uchar *)polys, polys_len, NULL);
- button->shape_batch[1] = GPU_batch_wire_from_poly_2d_encoded((uchar *)polys, polys_len, NULL);
- MEM_freeN(polys);
- }
- }
-
- float color[4];
- float matrix_final[4][4];
-
- gizmo_color_get(gz, highlight, color);
- WM_gizmo_calc_matrix_final(gz, matrix_final);
-
-
- bool is_3d = (gz->parent_gzgroup->type->flag & WM_GIZMOGROUPTYPE_3D) != 0;
-
- if ((select == false) &&
- (draw_options & ED_GIZMO_BUTTON_SHOW_HELPLINE))
- {
- float matrix_final_no_offset[4][4];
- WM_gizmo_calc_matrix_final_no_offset(gz, matrix_final_no_offset);
- uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
- immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
- immUniformColor4fv(color);
- GPU_line_width(gz->line_width);
- immUniformColor4fv(color);
- immBegin(GPU_PRIM_LINE_STRIP, 2);
- immVertex3fv(pos, matrix_final[3]);
- immVertex3fv(pos, matrix_final_no_offset[3]);
- immEnd();
- immUnbindProgram();
- }
-
- bool need_to_pop = true;
- GPU_matrix_push();
- GPU_matrix_mul(matrix_final);
-
- if (is_3d) {
- RegionView3D *rv3d = CTX_wm_region_view3d(C);
- float matrix_align[4][4];
- float matrix_final_unit[4][4];
- normalize_m4_m4(matrix_final_unit, matrix_final);
- mul_m4_m4m4(matrix_align, rv3d->viewmat, matrix_final_unit);
- zero_v3(matrix_align[3]);
- transpose_m4(matrix_align);
- GPU_matrix_mul(matrix_align);
- }
-
- if (select) {
- BLI_assert(is_3d);
- button2d_geom_draw_backdrop(gz, color, select);
- }
- else {
-
- GPU_blend(true);
- if (button->shape_batch[0] != NULL) {
- GPU_line_smooth(true);
- GPU_polygon_smooth(false);
- GPU_line_width(1.0f);
- for (uint i = 0; i < ARRAY_SIZE(button->shape_batch) && button->shape_batch[i]; i++) {
- /* Invert line color for wire. */
- GPU_batch_program_set_builtin(button->shape_batch[i], GPU_SHADER_2D_UNIFORM_COLOR);
- GPU_batch_uniform_4f(button->shape_batch[i], "color", UNPACK4(color));
- GPU_batch_draw(button->shape_batch[i]);
-
- if (draw_options & ED_GIZMO_BUTTON_SHOW_OUTLINE) {
- color[0] = 1.0f - color[0];
- color[1] = 1.0f - color[1];
- color[2] = 1.0f - color[2];
- }
- }
- GPU_line_smooth(false);
- GPU_polygon_smooth(true);
- }
- else if (button->icon != ICON_NONE) {
- if (draw_options & ED_GIZMO_BUTTON_SHOW_BACKDROP) {
- button2d_geom_draw_backdrop(gz, color, select);
- }
-
- float pos[2];
- if (is_3d) {
- const float fac = 2.0f;
- GPU_matrix_translate_2f(-(fac / 2), -(fac / 2));
- GPU_matrix_scale_2f(fac / (ICON_DEFAULT_WIDTH * UI_DPI_FAC), fac / (ICON_DEFAULT_HEIGHT * UI_DPI_FAC));
- pos[0] = 1.0f;
- pos[1] = 1.0f;
- }
- else {
- pos[0] = gz->matrix_basis[3][0] - (ICON_DEFAULT_WIDTH / 2.0) * UI_DPI_FAC;
- pos[1] = gz->matrix_basis[3][1] - (ICON_DEFAULT_HEIGHT / 2.0) * UI_DPI_FAC;
- GPU_matrix_pop();
- need_to_pop = false;
- }
-
- float alpha = (highlight) ? 1.0f : 0.8f;
- GPU_polygon_smooth(false);
- UI_icon_draw_alpha(pos[0], pos[1], button->icon, alpha);
- GPU_polygon_smooth(true);
- }
- GPU_blend(false);
- }
-
- if (need_to_pop) {
- GPU_matrix_pop();
- }
+ ButtonGizmo2D *button = (ButtonGizmo2D *)gz;
+
+ const int draw_options = RNA_enum_get(gz->ptr, "draw_options");
+ if (button->is_init == false) {
+ button->is_init = true;
+ PropertyRNA *prop = RNA_struct_find_property(gz->ptr, "icon");
+ if (RNA_property_is_set(gz->ptr, prop)) {
+ button->icon = RNA_property_enum_get(gz->ptr, prop);
+ }
+ else {
+ prop = RNA_struct_find_property(gz->ptr, "shape");
+ const uint polys_len = RNA_property_string_length(gz->ptr, prop);
+ /* We shouldn't need the +1, but a NULL char is set. */
+ char *polys = MEM_mallocN(polys_len + 1, __func__);
+ RNA_property_string_get(gz->ptr, prop, polys);
+ button->shape_batch[0] = GPU_batch_tris_from_poly_2d_encoded(
+ (uchar *)polys, polys_len, NULL);
+ button->shape_batch[1] = GPU_batch_wire_from_poly_2d_encoded(
+ (uchar *)polys, polys_len, NULL);
+ MEM_freeN(polys);
+ }
+ }
+
+ float color[4];
+ float matrix_final[4][4];
+
+ gizmo_color_get(gz, highlight, color);
+ WM_gizmo_calc_matrix_final(gz, matrix_final);
+
+ bool is_3d = (gz->parent_gzgroup->type->flag & WM_GIZMOGROUPTYPE_3D) != 0;
+
+ if ((select == false) && (draw_options & ED_GIZMO_BUTTON_SHOW_HELPLINE)) {
+ float matrix_final_no_offset[4][4];
+ WM_gizmo_calc_matrix_final_no_offset(gz, matrix_final_no_offset);
+ uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+ immUniformColor4fv(color);
+ GPU_line_width(gz->line_width);
+ immUniformColor4fv(color);
+ immBegin(GPU_PRIM_LINE_STRIP, 2);
+ immVertex3fv(pos, matrix_final[3]);
+ immVertex3fv(pos, matrix_final_no_offset[3]);
+ immEnd();
+ immUnbindProgram();
+ }
+
+ bool need_to_pop = true;
+ GPU_matrix_push();
+ GPU_matrix_mul(matrix_final);
+
+ if (is_3d) {
+ RegionView3D *rv3d = CTX_wm_region_view3d(C);
+ float matrix_align[4][4];
+ float matrix_final_unit[4][4];
+ normalize_m4_m4(matrix_final_unit, matrix_final);
+ mul_m4_m4m4(matrix_align, rv3d->viewmat, matrix_final_unit);
+ zero_v3(matrix_align[3]);
+ transpose_m4(matrix_align);
+ GPU_matrix_mul(matrix_align);
+ }
+
+ if (select) {
+ BLI_assert(is_3d);
+ button2d_geom_draw_backdrop(gz, color, select);
+ }
+ else {
+
+ GPU_blend(true);
+ if (button->shape_batch[0] != NULL) {
+ GPU_line_smooth(true);
+ GPU_polygon_smooth(false);
+ GPU_line_width(1.0f);
+ for (uint i = 0; i < ARRAY_SIZE(button->shape_batch) && button->shape_batch[i]; i++) {
+ /* Invert line color for wire. */
+ GPU_batch_program_set_builtin(button->shape_batch[i], GPU_SHADER_2D_UNIFORM_COLOR);
+ GPU_batch_uniform_4f(button->shape_batch[i], "color", UNPACK4(color));
+ GPU_batch_draw(button->shape_batch[i]);
+
+ if (draw_options & ED_GIZMO_BUTTON_SHOW_OUTLINE) {
+ color[0] = 1.0f - color[0];
+ color[1] = 1.0f - color[1];
+ color[2] = 1.0f - color[2];
+ }
+ }
+ GPU_line_smooth(false);
+ GPU_polygon_smooth(true);
+ }
+ else if (button->icon != ICON_NONE) {
+ if (draw_options & ED_GIZMO_BUTTON_SHOW_BACKDROP) {
+ button2d_geom_draw_backdrop(gz, color, select);
+ }
+
+ float pos[2];
+ if (is_3d) {
+ const float fac = 2.0f;
+ GPU_matrix_translate_2f(-(fac / 2), -(fac / 2));
+ GPU_matrix_scale_2f(fac / (ICON_DEFAULT_WIDTH * UI_DPI_FAC),
+ fac / (ICON_DEFAULT_HEIGHT * UI_DPI_FAC));
+ pos[0] = 1.0f;
+ pos[1] = 1.0f;
+ }
+ else {
+ pos[0] = gz->matrix_basis[3][0] - (ICON_DEFAULT_WIDTH / 2.0) * UI_DPI_FAC;
+ pos[1] = gz->matrix_basis[3][1] - (ICON_DEFAULT_HEIGHT / 2.0) * UI_DPI_FAC;
+ GPU_matrix_pop();
+ need_to_pop = false;
+ }
+
+ float alpha = (highlight) ? 1.0f : 0.8f;
+ GPU_polygon_smooth(false);
+ UI_icon_draw_alpha(pos[0], pos[1], button->icon, alpha);
+ GPU_polygon_smooth(true);
+ }
+ GPU_blend(false);
+ }
+
+ if (need_to_pop) {
+ GPU_matrix_pop();
+ }
}
static void gizmo_button2d_draw_select(const bContext *C, wmGizmo *gz, int select_id)
{
- GPU_select_load_id(select_id);
- button2d_draw_intern(C, gz, true, false);
+ GPU_select_load_id(select_id);
+ button2d_draw_intern(C, gz, true, false);
}
static void gizmo_button2d_draw(const bContext *C, wmGizmo *gz)
{
- const bool is_highlight = (gz->state & WM_GIZMO_STATE_HIGHLIGHT) != 0;
+ const bool is_highlight = (gz->state & WM_GIZMO_STATE_HIGHLIGHT) != 0;
- GPU_blend(true);
- button2d_draw_intern(C, gz, false, is_highlight);
- GPU_blend(false);
+ GPU_blend(true);
+ button2d_draw_intern(C, gz, false, is_highlight);
+ GPU_blend(false);
}
-static int gizmo_button2d_test_select(
- bContext *C, wmGizmo *gz, const int mval[2])
+static int gizmo_button2d_test_select(bContext *C, wmGizmo *gz, const int mval[2])
{
- float point_local[2];
-
- if (0) {
- /* correct, but unnecessarily slow. */
- if (gizmo_window_project_2d(
- C, gz, (const float[2]){UNPACK2(mval)}, 2, true, point_local) == false)
- {
- return -1;
- }
- }
- else {
- copy_v2_v2(point_local, (float[2]){UNPACK2(mval)});
- sub_v2_v2(point_local, gz->matrix_basis[3]);
- mul_v2_fl(point_local, 1.0f / (gz->scale_basis * UI_DPI_FAC));
- }
- /* The 'gz->scale_final' is already applied when projecting. */
- if (len_squared_v2(point_local) < 1.0f) {
- return 0;
- }
-
- return -1;
+ float point_local[2];
+
+ if (0) {
+ /* correct, but unnecessarily slow. */
+ if (gizmo_window_project_2d(C, gz, (const float[2]){UNPACK2(mval)}, 2, true, point_local) ==
+ false) {
+ return -1;
+ }
+ }
+ else {
+ copy_v2_v2(point_local, (float[2]){UNPACK2(mval)});
+ sub_v2_v2(point_local, gz->matrix_basis[3]);
+ mul_v2_fl(point_local, 1.0f / (gz->scale_basis * UI_DPI_FAC));
+ }
+ /* The 'gz->scale_final' is already applied when projecting. */
+ if (len_squared_v2(point_local) < 1.0f) {
+ return 0;
+ }
+
+ return -1;
}
static int gizmo_button2d_cursor_get(wmGizmo *gz)
{
- if (RNA_boolean_get(gz->ptr, "show_drag")) {
- return BC_NSEW_SCROLLCURSOR;
- }
- return CURSOR_STD;
+ if (RNA_boolean_get(gz->ptr, "show_drag")) {
+ return BC_NSEW_SCROLLCURSOR;
+ }
+ return CURSOR_STD;
}
static void gizmo_button2d_free(wmGizmo *gz)
{
- ButtonGizmo2D *shape = (ButtonGizmo2D *)gz;
+ ButtonGizmo2D *shape = (ButtonGizmo2D *)gz;
- for (uint i = 0; i < ARRAY_SIZE(shape->shape_batch); i++) {
- GPU_BATCH_DISCARD_SAFE(shape->shape_batch[i]);
- }
+ for (uint i = 0; i < ARRAY_SIZE(shape->shape_batch); i++) {
+ GPU_BATCH_DISCARD_SAFE(shape->shape_batch[i]);
+ }
}
/** \} */
@@ -284,42 +281,42 @@ static void gizmo_button2d_free(wmGizmo *gz)
static void GIZMO_GT_button_2d(wmGizmoType *gzt)
{
- /* identifiers */
- gzt->idname = "GIZMO_GT_button_2d";
+ /* identifiers */
+ gzt->idname = "GIZMO_GT_button_2d";
- /* api callbacks */
- gzt->draw = gizmo_button2d_draw;
- gzt->draw_select = gizmo_button2d_draw_select;
- gzt->test_select = gizmo_button2d_test_select;
- gzt->cursor_get = gizmo_button2d_cursor_get;
- gzt->free = gizmo_button2d_free;
+ /* api callbacks */
+ gzt->draw = gizmo_button2d_draw;
+ gzt->draw_select = gizmo_button2d_draw_select;
+ gzt->test_select = gizmo_button2d_test_select;
+ gzt->cursor_get = gizmo_button2d_cursor_get;
+ gzt->free = gizmo_button2d_free;
- gzt->struct_size = sizeof(ButtonGizmo2D);
+ gzt->struct_size = sizeof(ButtonGizmo2D);
- /* rna */
- static EnumPropertyItem rna_enum_draw_options[] = {
- {ED_GIZMO_BUTTON_SHOW_OUTLINE, "OUTLINE", 0, "Outline", ""},
- {ED_GIZMO_BUTTON_SHOW_BACKDROP, "BACKDROP", 0, "Backdrop", ""},
- {ED_GIZMO_BUTTON_SHOW_HELPLINE, "HELPLINE", 0, "Help Line", ""},
- {0, NULL, 0, NULL, NULL},
- };
- PropertyRNA *prop;
+ /* rna */
+ static EnumPropertyItem rna_enum_draw_options[] = {
+ {ED_GIZMO_BUTTON_SHOW_OUTLINE, "OUTLINE", 0, "Outline", ""},
+ {ED_GIZMO_BUTTON_SHOW_BACKDROP, "BACKDROP", 0, "Backdrop", ""},
+ {ED_GIZMO_BUTTON_SHOW_HELPLINE, "HELPLINE", 0, "Help Line", ""},
+ {0, NULL, 0, NULL, NULL},
+ };
+ PropertyRNA *prop;
- RNA_def_enum_flag(gzt->srna, "draw_options", rna_enum_draw_options, 0, "Draw Options", "");
+ RNA_def_enum_flag(gzt->srna, "draw_options", rna_enum_draw_options, 0, "Draw Options", "");
- prop = RNA_def_property(gzt->srna, "icon", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_items(prop, rna_enum_icon_items);
+ prop = RNA_def_property(gzt->srna, "icon", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_items(prop, rna_enum_icon_items);
- /* Passed to 'GPU_batch_tris_from_poly_2d_encoded' */
- RNA_def_property(gzt->srna, "shape", PROP_STRING, PROP_BYTESTRING);
+ /* Passed to 'GPU_batch_tris_from_poly_2d_encoded' */
+ RNA_def_property(gzt->srna, "shape", PROP_STRING, PROP_BYTESTRING);
- /* Currently only used for cursor display. */
- RNA_def_boolean(gzt->srna, "show_drag", true, "Show Drag", "");
+ /* Currently only used for cursor display. */
+ RNA_def_boolean(gzt->srna, "show_drag", true, "Show Drag", "");
}
void ED_gizmotypes_button_2d(void)
{
- WM_gizmotype_append(GIZMO_GT_button_2d);
+ WM_gizmotype_append(GIZMO_GT_button_2d);
}
-/** \} */ // Button Gizmo API
+/** \} */ // Button Gizmo API
diff --git a/source/blender/editors/gizmo_library/gizmo_types/cage2d_gizmo.c b/source/blender/editors/gizmo_library/gizmo_types/cage2d_gizmo.c
index 45b7b37eb8d..77658b8495e 100644
--- a/source/blender/editors/gizmo_library/gizmo_types/cage2d_gizmo.c
+++ b/source/blender/editors/gizmo_library/gizmo_types/cage2d_gizmo.c
@@ -36,7 +36,6 @@
#include "BKE_context.h"
-
#include "GPU_matrix.h"
#include "GPU_shader.h"
#include "GPU_immediate.h"
@@ -60,75 +59,106 @@
#define GIZMO_RESIZER_SIZE 10.0f
#define GIZMO_MARGIN_OFFSET_SCALE 1.5f
-static bool gizmo_calc_rect_view_scale(
- const wmGizmo *gz, const float dims[2], float scale[2])
+static bool gizmo_calc_rect_view_scale(const wmGizmo *gz, const float dims[2], float scale[2])
{
- float matrix_final_no_offset[4][4];
- float asp[2] = {1.0f, 1.0f};
- if (dims[0] > dims[1]) {
- asp[0] = dims[1] / dims[0];
- }
- else {
- asp[1] = dims[0] / dims[1];
- }
- float x_axis[3], y_axis[3];
- WM_gizmo_calc_matrix_final_no_offset(gz, matrix_final_no_offset);
- mul_v3_mat3_m4v3(x_axis, matrix_final_no_offset, gz->matrix_offset[0]);
- mul_v3_mat3_m4v3(y_axis, matrix_final_no_offset, gz->matrix_offset[1]);
-
- mul_v2_v2(x_axis, asp);
- mul_v2_v2(y_axis, asp);
-
- float len_x_axis = len_v3(x_axis);
- float len_y_axis = len_v3(y_axis);
-
- if (len_x_axis == 0.0f || len_y_axis == 0.0f) {
- return false;
- }
-
- scale[0] = 1.0f / len_x_axis;
- scale[1] = 1.0f / len_y_axis;
- return true;
+ float matrix_final_no_offset[4][4];
+ float asp[2] = {1.0f, 1.0f};
+ if (dims[0] > dims[1]) {
+ asp[0] = dims[1] / dims[0];
+ }
+ else {
+ asp[1] = dims[0] / dims[1];
+ }
+ float x_axis[3], y_axis[3];
+ WM_gizmo_calc_matrix_final_no_offset(gz, matrix_final_no_offset);
+ mul_v3_mat3_m4v3(x_axis, matrix_final_no_offset, gz->matrix_offset[0]);
+ mul_v3_mat3_m4v3(y_axis, matrix_final_no_offset, gz->matrix_offset[1]);
+
+ mul_v2_v2(x_axis, asp);
+ mul_v2_v2(y_axis, asp);
+
+ float len_x_axis = len_v3(x_axis);
+ float len_y_axis = len_v3(y_axis);
+
+ if (len_x_axis == 0.0f || len_y_axis == 0.0f) {
+ return false;
+ }
+
+ scale[0] = 1.0f / len_x_axis;
+ scale[1] = 1.0f / len_y_axis;
+ return true;
}
-static bool gizmo_calc_rect_view_margin(
- const wmGizmo *gz, const float dims[2], float margin[2])
+static bool gizmo_calc_rect_view_margin(const wmGizmo *gz, const float dims[2], float margin[2])
{
- float handle_size;
- if (gz->parent_gzgroup->type->flag & WM_GIZMOGROUPTYPE_3D) {
- handle_size = 0.15f;
- }
- else {
- handle_size = GIZMO_RESIZER_SIZE;
- }
- handle_size *= gz->scale_final;
- float scale_xy[2];
- if (!gizmo_calc_rect_view_scale(gz, dims, scale_xy)) {
- return false;
- }
- margin[0] = ((handle_size * scale_xy[0]));
- margin[1] = ((handle_size * scale_xy[1]));
- return true;
+ float handle_size;
+ if (gz->parent_gzgroup->type->flag & WM_GIZMOGROUPTYPE_3D) {
+ handle_size = 0.15f;
+ }
+ else {
+ handle_size = GIZMO_RESIZER_SIZE;
+ }
+ handle_size *= gz->scale_final;
+ float scale_xy[2];
+ if (!gizmo_calc_rect_view_scale(gz, dims, scale_xy)) {
+ return false;
+ }
+ margin[0] = ((handle_size * scale_xy[0]));
+ margin[1] = ((handle_size * scale_xy[1]));
+ return true;
}
/* -------------------------------------------------------------------- */
static void gizmo_rect_pivot_from_scale_part(int part, float r_pt[2], bool r_constrain_axis[2])
{
- bool x = true, y = true;
- switch (part) {
- case ED_GIZMO_CAGE2D_PART_SCALE_MIN_X: { ARRAY_SET_ITEMS(r_pt, 0.5, 0.0); x = false; break; }
- case ED_GIZMO_CAGE2D_PART_SCALE_MAX_X: { ARRAY_SET_ITEMS(r_pt, -0.5, 0.0); x = false; break; }
- case ED_GIZMO_CAGE2D_PART_SCALE_MIN_Y: { ARRAY_SET_ITEMS(r_pt, 0.0, 0.5); y = false; break; }
- case ED_GIZMO_CAGE2D_PART_SCALE_MAX_Y: { ARRAY_SET_ITEMS(r_pt, 0.0, -0.5); y = false; break; }
- case ED_GIZMO_CAGE2D_PART_SCALE_MIN_X_MIN_Y: { ARRAY_SET_ITEMS(r_pt, 0.5, 0.5); x = y = false; break; }
- case ED_GIZMO_CAGE2D_PART_SCALE_MIN_X_MAX_Y: { ARRAY_SET_ITEMS(r_pt, 0.5, -0.5); x = y = false; break; }
- case ED_GIZMO_CAGE2D_PART_SCALE_MAX_X_MIN_Y: { ARRAY_SET_ITEMS(r_pt, -0.5, 0.5); x = y = false; break; }
- case ED_GIZMO_CAGE2D_PART_SCALE_MAX_X_MAX_Y: { ARRAY_SET_ITEMS(r_pt, -0.5, -0.5); x = y = false; break; }
- default: BLI_assert(0);
- }
- r_constrain_axis[0] = x;
- r_constrain_axis[1] = y;
+ bool x = true, y = true;
+ switch (part) {
+ case ED_GIZMO_CAGE2D_PART_SCALE_MIN_X: {
+ ARRAY_SET_ITEMS(r_pt, 0.5, 0.0);
+ x = false;
+ break;
+ }
+ case ED_GIZMO_CAGE2D_PART_SCALE_MAX_X: {
+ ARRAY_SET_ITEMS(r_pt, -0.5, 0.0);
+ x = false;
+ break;
+ }
+ case ED_GIZMO_CAGE2D_PART_SCALE_MIN_Y: {
+ ARRAY_SET_ITEMS(r_pt, 0.0, 0.5);
+ y = false;
+ break;
+ }
+ case ED_GIZMO_CAGE2D_PART_SCALE_MAX_Y: {
+ ARRAY_SET_ITEMS(r_pt, 0.0, -0.5);
+ y = false;
+ break;
+ }
+ case ED_GIZMO_CAGE2D_PART_SCALE_MIN_X_MIN_Y: {
+ ARRAY_SET_ITEMS(r_pt, 0.5, 0.5);
+ x = y = false;
+ break;
+ }
+ case ED_GIZMO_CAGE2D_PART_SCALE_MIN_X_MAX_Y: {
+ ARRAY_SET_ITEMS(r_pt, 0.5, -0.5);
+ x = y = false;
+ break;
+ }
+ case ED_GIZMO_CAGE2D_PART_SCALE_MAX_X_MIN_Y: {
+ ARRAY_SET_ITEMS(r_pt, -0.5, 0.5);
+ x = y = false;
+ break;
+ }
+ case ED_GIZMO_CAGE2D_PART_SCALE_MAX_X_MAX_Y: {
+ ARRAY_SET_ITEMS(r_pt, -0.5, -0.5);
+ x = y = false;
+ break;
+ }
+ default:
+ BLI_assert(0);
+ }
+ r_constrain_axis[0] = x;
+ r_constrain_axis[1] = y;
}
/* -------------------------------------------------------------------- */
@@ -137,315 +167,324 @@ static void gizmo_rect_pivot_from_scale_part(int part, float r_pt[2], bool r_con
* Useful for 3D views, see: #ED_GIZMO_CAGE2D_STYLE_BOX
* \{ */
-static void cage2d_draw_box_corners(
- const rctf *r, const float margin[2], const float color[3])
+static void cage2d_draw_box_corners(const rctf *r, const float margin[2], const float color[3])
{
- uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+ uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
- immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
- immUniformColor3fv(color);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformColor3fv(color);
- immBegin(GPU_PRIM_LINES, 16);
+ immBegin(GPU_PRIM_LINES, 16);
- immVertex2f(pos, r->xmin, r->ymin + margin[1]);
- immVertex2f(pos, r->xmin, r->ymin);
- immVertex2f(pos, r->xmin, r->ymin);
- immVertex2f(pos, r->xmin + margin[0], r->ymin);
+ immVertex2f(pos, r->xmin, r->ymin + margin[1]);
+ immVertex2f(pos, r->xmin, r->ymin);
+ immVertex2f(pos, r->xmin, r->ymin);
+ immVertex2f(pos, r->xmin + margin[0], r->ymin);
- immVertex2f(pos, r->xmax, r->ymin + margin[1]);
- immVertex2f(pos, r->xmax, r->ymin);
- immVertex2f(pos, r->xmax, r->ymin);
- immVertex2f(pos, r->xmax - margin[0], r->ymin);
+ immVertex2f(pos, r->xmax, r->ymin + margin[1]);
+ immVertex2f(pos, r->xmax, r->ymin);
+ immVertex2f(pos, r->xmax, r->ymin);
+ immVertex2f(pos, r->xmax - margin[0], r->ymin);
- immVertex2f(pos, r->xmax, r->ymax - margin[1]);
- immVertex2f(pos, r->xmax, r->ymax);
- immVertex2f(pos, r->xmax, r->ymax);
- immVertex2f(pos, r->xmax - margin[0], r->ymax);
+ immVertex2f(pos, r->xmax, r->ymax - margin[1]);
+ immVertex2f(pos, r->xmax, r->ymax);
+ immVertex2f(pos, r->xmax, r->ymax);
+ immVertex2f(pos, r->xmax - margin[0], r->ymax);
- immVertex2f(pos, r->xmin, r->ymax - margin[1]);
- immVertex2f(pos, r->xmin, r->ymax);
- immVertex2f(pos, r->xmin, r->ymax);
- immVertex2f(pos, r->xmin + margin[0], r->ymax);
+ immVertex2f(pos, r->xmin, r->ymax - margin[1]);
+ immVertex2f(pos, r->xmin, r->ymax);
+ immVertex2f(pos, r->xmin, r->ymax);
+ immVertex2f(pos, r->xmin + margin[0], r->ymax);
- immEnd();
+ immEnd();
- immUnbindProgram();
+ immUnbindProgram();
}
-static void cage2d_draw_box_interaction(
- const float color[4], const int highlighted,
- const float size[2], const float margin[2],
- const float line_width, const bool is_solid, const int draw_options)
+static void cage2d_draw_box_interaction(const float color[4],
+ const int highlighted,
+ const float size[2],
+ const float margin[2],
+ const float line_width,
+ const bool is_solid,
+ const int draw_options)
{
- /* 4 verts for translate, otherwise only 3 are used. */
- float verts[4][2];
- uint verts_len = 0;
- GPUPrimType prim_type = GPU_PRIM_NONE;
-
- switch (highlighted) {
- case ED_GIZMO_CAGE2D_PART_SCALE_MIN_X:
- {
- rctf r = {
- .xmin = -size[0], .xmax = -size[0] + margin[0],
- .ymin = -size[1] + margin[1], .ymax = size[1] - margin[1],
- };
- ARRAY_SET_ITEMS(verts[0], r.xmin, r.ymin);
- ARRAY_SET_ITEMS(verts[1], r.xmin, r.ymax);
- verts_len = 2;
- if (is_solid) {
- ARRAY_SET_ITEMS(verts[2], r.xmax, r.ymax);
- ARRAY_SET_ITEMS(verts[3], r.xmax, r.ymin);
- verts_len += 2;
- prim_type = GPU_PRIM_TRI_FAN;
- }
- else {
- prim_type = GPU_PRIM_LINE_STRIP;
- }
- break;
- }
- case ED_GIZMO_CAGE2D_PART_SCALE_MAX_X:
- {
- rctf r = {
- .xmin = size[0] - margin[0], .xmax = size[0],
- .ymin = -size[1] + margin[1], .ymax = size[1] - margin[1],
- };
- ARRAY_SET_ITEMS(verts[0], r.xmax, r.ymin);
- ARRAY_SET_ITEMS(verts[1], r.xmax, r.ymax);
- verts_len = 2;
- if (is_solid) {
- ARRAY_SET_ITEMS(verts[2], r.xmin, r.ymax);
- ARRAY_SET_ITEMS(verts[3], r.xmin, r.ymin);
- verts_len += 2;
- prim_type = GPU_PRIM_TRI_FAN;
- }
- else {
- prim_type = GPU_PRIM_LINE_STRIP;
- }
- break;
- }
- case ED_GIZMO_CAGE2D_PART_SCALE_MIN_Y:
- {
- rctf r = {
- .xmin = -size[0] + margin[0], .xmax = size[0] - margin[0],
- .ymin = -size[1], .ymax = -size[1] + margin[1],
- };
- ARRAY_SET_ITEMS(verts[0], r.xmin, r.ymin);
- ARRAY_SET_ITEMS(verts[1], r.xmax, r.ymin);
- verts_len = 2;
- if (is_solid) {
- ARRAY_SET_ITEMS(verts[2], r.xmax, r.ymax);
- ARRAY_SET_ITEMS(verts[3], r.xmin, r.ymax);
- verts_len += 2;
- prim_type = GPU_PRIM_TRI_FAN;
- }
- else {
- prim_type = GPU_PRIM_LINE_STRIP;
- }
- break;
- }
- case ED_GIZMO_CAGE2D_PART_SCALE_MAX_Y:
- {
- rctf r = {
- .xmin = -size[0] + margin[0], .xmax = size[0] - margin[0],
- .ymin = size[1] - margin[1], .ymax = size[1],
- };
- ARRAY_SET_ITEMS(verts[0], r.xmin, r.ymax);
- ARRAY_SET_ITEMS(verts[1], r.xmax, r.ymax);
- verts_len = 2;
- if (is_solid) {
- ARRAY_SET_ITEMS(verts[2], r.xmax, r.ymin);
- ARRAY_SET_ITEMS(verts[3], r.xmin, r.ymin);
- verts_len += 2;
- prim_type = GPU_PRIM_TRI_FAN;
- }
- else {
- prim_type = GPU_PRIM_LINE_STRIP;
- }
- break;
- }
- case ED_GIZMO_CAGE2D_PART_SCALE_MIN_X_MIN_Y:
- {
- rctf r = {
- .xmin = -size[0], .xmax = -size[0] + margin[0],
- .ymin = -size[1], .ymax = -size[1] + margin[1],
- };
- ARRAY_SET_ITEMS(verts[0], r.xmax, r.ymin);
- ARRAY_SET_ITEMS(verts[1], r.xmax, r.ymax);
- ARRAY_SET_ITEMS(verts[2], r.xmin, r.ymax);
- verts_len = 3;
- if (is_solid) {
- ARRAY_SET_ITEMS(verts[3], r.xmin, r.ymin);
- verts_len += 1;
- prim_type = GPU_PRIM_TRI_FAN;
- }
- else {
- prim_type = GPU_PRIM_LINE_STRIP;
- }
- break;
- }
- case ED_GIZMO_CAGE2D_PART_SCALE_MIN_X_MAX_Y:
- {
- rctf r = {
- .xmin = -size[0], .xmax = -size[0] + margin[0],
- .ymin = size[1] - margin[1], .ymax = size[1],
- };
- ARRAY_SET_ITEMS(verts[0], r.xmax, r.ymax);
- ARRAY_SET_ITEMS(verts[1], r.xmax, r.ymin);
- ARRAY_SET_ITEMS(verts[2], r.xmin, r.ymin);
- verts_len = 3;
- if (is_solid) {
- ARRAY_SET_ITEMS(verts[3], r.xmin, r.ymax);
- verts_len += 1;
- prim_type = GPU_PRIM_TRI_FAN;
- }
- else {
- prim_type = GPU_PRIM_LINE_STRIP;
- }
- break;
- }
- case ED_GIZMO_CAGE2D_PART_SCALE_MAX_X_MIN_Y:
- {
- rctf r = {
- .xmin = size[0] - margin[0], .xmax = size[0],
- .ymin = -size[1], .ymax = -size[1] + margin[1],
- };
- ARRAY_SET_ITEMS(verts[0], r.xmin, r.ymin);
- ARRAY_SET_ITEMS(verts[1], r.xmin, r.ymax);
- ARRAY_SET_ITEMS(verts[2], r.xmax, r.ymax);
- verts_len = 3;
- if (is_solid) {
- ARRAY_SET_ITEMS(verts[3], r.xmax, r.ymin);
- verts_len += 1;
- prim_type = GPU_PRIM_TRI_FAN;
- }
- else {
- prim_type = GPU_PRIM_LINE_STRIP;
- }
- break;
- }
- case ED_GIZMO_CAGE2D_PART_SCALE_MAX_X_MAX_Y:
- {
- rctf r = {
- .xmin = size[0] - margin[0], .xmax = size[0],
- .ymin = size[1] - margin[1], .ymax = size[1],
- };
- ARRAY_SET_ITEMS(verts[0], r.xmin, r.ymax);
- ARRAY_SET_ITEMS(verts[1], r.xmin, r.ymin);
- ARRAY_SET_ITEMS(verts[2], r.xmax, r.ymin);
- verts_len = 3;
- if (is_solid) {
- ARRAY_SET_ITEMS(verts[3], r.xmax, r.ymax);
- verts_len += 1;
- prim_type = GPU_PRIM_TRI_FAN;
- }
- else {
- prim_type = GPU_PRIM_LINE_STRIP;
- }
- break;
- }
- case ED_GIZMO_CAGE2D_PART_ROTATE:
- {
- const float rotate_pt[2] = {0.0f, size[1] + margin[1]};
- const rctf r_rotate = {
- .xmin = rotate_pt[0] - margin[0] / 2.0f,
- .xmax = rotate_pt[0] + margin[0] / 2.0f,
- .ymin = rotate_pt[1] - margin[1] / 2.0f,
- .ymax = rotate_pt[1] + margin[1] / 2.0f,
- };
-
- ARRAY_SET_ITEMS(verts[0], r_rotate.xmin, r_rotate.ymin);
- ARRAY_SET_ITEMS(verts[1], r_rotate.xmin, r_rotate.ymax);
- ARRAY_SET_ITEMS(verts[2], r_rotate.xmax, r_rotate.ymax);
- ARRAY_SET_ITEMS(verts[3], r_rotate.xmax, r_rotate.ymin);
- verts_len = 4;
- if (is_solid) {
- prim_type = GPU_PRIM_TRI_FAN;
- }
- else {
- prim_type = GPU_PRIM_LINE_STRIP;
- }
- break;
- }
-
- case ED_GIZMO_CAGE2D_PART_TRANSLATE:
- if (draw_options & ED_GIZMO_CAGE2D_DRAW_FLAG_XFORM_CENTER_HANDLE) {
- ARRAY_SET_ITEMS(verts[0], -margin[0] / 2, -margin[1] / 2);
- ARRAY_SET_ITEMS(verts[1], margin[0] / 2, margin[1] / 2);
- ARRAY_SET_ITEMS(verts[2], -margin[0] / 2, margin[1] / 2);
- ARRAY_SET_ITEMS(verts[3], margin[0] / 2, -margin[1] / 2);
- verts_len = 4;
- if (is_solid) {
- prim_type = GPU_PRIM_TRI_FAN;
- }
- else {
- prim_type = GPU_PRIM_LINES;
- }
- }
- else {
- /* Only used for 3D view selection, never displayed to the user. */
- ARRAY_SET_ITEMS(verts[0], -size[0], -size[1]);
- ARRAY_SET_ITEMS(verts[1], -size[0], size[1]);
- ARRAY_SET_ITEMS(verts[2], size[0], size[1]);
- ARRAY_SET_ITEMS(verts[3], size[0], -size[1]);
- verts_len = 4;
- if (is_solid) {
- prim_type = GPU_PRIM_TRI_FAN;
- }
- else {
- /* unreachable */
- BLI_assert(0);
- prim_type = GPU_PRIM_LINE_STRIP;
- }
- }
- break;
- default:
- return;
- }
-
- BLI_assert(prim_type != GPU_PRIM_NONE);
-
- GPUVertFormat *format = immVertexFormat();
- struct {
- uint pos, col;
- } attr_id = {
- .pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT),
- .col = GPU_vertformat_attr_add(format, "color", GPU_COMP_F32, 3, GPU_FETCH_FLOAT),
- };
- immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR);
-
- {
- if (is_solid) {
- BLI_assert(ELEM(prim_type, GPU_PRIM_TRI_FAN));
- immBegin(prim_type, verts_len);
- immAttr3f(attr_id.col, 0.0f, 0.0f, 0.0f);
- for (uint i = 0; i < verts_len; i++) {
- immVertex2fv(attr_id.pos, verts[i]);
- }
- immEnd();
- }
- else {
- BLI_assert(ELEM(prim_type, GPU_PRIM_LINE_STRIP, GPU_PRIM_LINES));
- GPU_line_width(line_width + 3.0f);
-
- immBegin(prim_type, verts_len);
- immAttr3f(attr_id.col, 0.0f, 0.0f, 0.0f);
- for (uint i = 0; i < verts_len; i++) {
- immVertex2fv(attr_id.pos, verts[i]);
- }
- immEnd();
-
- GPU_line_width(line_width);
-
- immBegin(prim_type, verts_len);
- immAttr3fv(attr_id.col, color);
- for (uint i = 0; i < verts_len; i++) {
- immVertex2fv(attr_id.pos, verts[i]);
- }
- immEnd();
- }
- }
-
- immUnbindProgram();
+ /* 4 verts for translate, otherwise only 3 are used. */
+ float verts[4][2];
+ uint verts_len = 0;
+ GPUPrimType prim_type = GPU_PRIM_NONE;
+
+ switch (highlighted) {
+ case ED_GIZMO_CAGE2D_PART_SCALE_MIN_X: {
+ rctf r = {
+ .xmin = -size[0],
+ .xmax = -size[0] + margin[0],
+ .ymin = -size[1] + margin[1],
+ .ymax = size[1] - margin[1],
+ };
+ ARRAY_SET_ITEMS(verts[0], r.xmin, r.ymin);
+ ARRAY_SET_ITEMS(verts[1], r.xmin, r.ymax);
+ verts_len = 2;
+ if (is_solid) {
+ ARRAY_SET_ITEMS(verts[2], r.xmax, r.ymax);
+ ARRAY_SET_ITEMS(verts[3], r.xmax, r.ymin);
+ verts_len += 2;
+ prim_type = GPU_PRIM_TRI_FAN;
+ }
+ else {
+ prim_type = GPU_PRIM_LINE_STRIP;
+ }
+ break;
+ }
+ case ED_GIZMO_CAGE2D_PART_SCALE_MAX_X: {
+ rctf r = {
+ .xmin = size[0] - margin[0],
+ .xmax = size[0],
+ .ymin = -size[1] + margin[1],
+ .ymax = size[1] - margin[1],
+ };
+ ARRAY_SET_ITEMS(verts[0], r.xmax, r.ymin);
+ ARRAY_SET_ITEMS(verts[1], r.xmax, r.ymax);
+ verts_len = 2;
+ if (is_solid) {
+ ARRAY_SET_ITEMS(verts[2], r.xmin, r.ymax);
+ ARRAY_SET_ITEMS(verts[3], r.xmin, r.ymin);
+ verts_len += 2;
+ prim_type = GPU_PRIM_TRI_FAN;
+ }
+ else {
+ prim_type = GPU_PRIM_LINE_STRIP;
+ }
+ break;
+ }
+ case ED_GIZMO_CAGE2D_PART_SCALE_MIN_Y: {
+ rctf r = {
+ .xmin = -size[0] + margin[0],
+ .xmax = size[0] - margin[0],
+ .ymin = -size[1],
+ .ymax = -size[1] + margin[1],
+ };
+ ARRAY_SET_ITEMS(verts[0], r.xmin, r.ymin);
+ ARRAY_SET_ITEMS(verts[1], r.xmax, r.ymin);
+ verts_len = 2;
+ if (is_solid) {
+ ARRAY_SET_ITEMS(verts[2], r.xmax, r.ymax);
+ ARRAY_SET_ITEMS(verts[3], r.xmin, r.ymax);
+ verts_len += 2;
+ prim_type = GPU_PRIM_TRI_FAN;
+ }
+ else {
+ prim_type = GPU_PRIM_LINE_STRIP;
+ }
+ break;
+ }
+ case ED_GIZMO_CAGE2D_PART_SCALE_MAX_Y: {
+ rctf r = {
+ .xmin = -size[0] + margin[0],
+ .xmax = size[0] - margin[0],
+ .ymin = size[1] - margin[1],
+ .ymax = size[1],
+ };
+ ARRAY_SET_ITEMS(verts[0], r.xmin, r.ymax);
+ ARRAY_SET_ITEMS(verts[1], r.xmax, r.ymax);
+ verts_len = 2;
+ if (is_solid) {
+ ARRAY_SET_ITEMS(verts[2], r.xmax, r.ymin);
+ ARRAY_SET_ITEMS(verts[3], r.xmin, r.ymin);
+ verts_len += 2;
+ prim_type = GPU_PRIM_TRI_FAN;
+ }
+ else {
+ prim_type = GPU_PRIM_LINE_STRIP;
+ }
+ break;
+ }
+ case ED_GIZMO_CAGE2D_PART_SCALE_MIN_X_MIN_Y: {
+ rctf r = {
+ .xmin = -size[0],
+ .xmax = -size[0] + margin[0],
+ .ymin = -size[1],
+ .ymax = -size[1] + margin[1],
+ };
+ ARRAY_SET_ITEMS(verts[0], r.xmax, r.ymin);
+ ARRAY_SET_ITEMS(verts[1], r.xmax, r.ymax);
+ ARRAY_SET_ITEMS(verts[2], r.xmin, r.ymax);
+ verts_len = 3;
+ if (is_solid) {
+ ARRAY_SET_ITEMS(verts[3], r.xmin, r.ymin);
+ verts_len += 1;
+ prim_type = GPU_PRIM_TRI_FAN;
+ }
+ else {
+ prim_type = GPU_PRIM_LINE_STRIP;
+ }
+ break;
+ }
+ case ED_GIZMO_CAGE2D_PART_SCALE_MIN_X_MAX_Y: {
+ rctf r = {
+ .xmin = -size[0],
+ .xmax = -size[0] + margin[0],
+ .ymin = size[1] - margin[1],
+ .ymax = size[1],
+ };
+ ARRAY_SET_ITEMS(verts[0], r.xmax, r.ymax);
+ ARRAY_SET_ITEMS(verts[1], r.xmax, r.ymin);
+ ARRAY_SET_ITEMS(verts[2], r.xmin, r.ymin);
+ verts_len = 3;
+ if (is_solid) {
+ ARRAY_SET_ITEMS(verts[3], r.xmin, r.ymax);
+ verts_len += 1;
+ prim_type = GPU_PRIM_TRI_FAN;
+ }
+ else {
+ prim_type = GPU_PRIM_LINE_STRIP;
+ }
+ break;
+ }
+ case ED_GIZMO_CAGE2D_PART_SCALE_MAX_X_MIN_Y: {
+ rctf r = {
+ .xmin = size[0] - margin[0],
+ .xmax = size[0],
+ .ymin = -size[1],
+ .ymax = -size[1] + margin[1],
+ };
+ ARRAY_SET_ITEMS(verts[0], r.xmin, r.ymin);
+ ARRAY_SET_ITEMS(verts[1], r.xmin, r.ymax);
+ ARRAY_SET_ITEMS(verts[2], r.xmax, r.ymax);
+ verts_len = 3;
+ if (is_solid) {
+ ARRAY_SET_ITEMS(verts[3], r.xmax, r.ymin);
+ verts_len += 1;
+ prim_type = GPU_PRIM_TRI_FAN;
+ }
+ else {
+ prim_type = GPU_PRIM_LINE_STRIP;
+ }
+ break;
+ }
+ case ED_GIZMO_CAGE2D_PART_SCALE_MAX_X_MAX_Y: {
+ rctf r = {
+ .xmin = size[0] - margin[0],
+ .xmax = size[0],
+ .ymin = size[1] - margin[1],
+ .ymax = size[1],
+ };
+ ARRAY_SET_ITEMS(verts[0], r.xmin, r.ymax);
+ ARRAY_SET_ITEMS(verts[1], r.xmin, r.ymin);
+ ARRAY_SET_ITEMS(verts[2], r.xmax, r.ymin);
+ verts_len = 3;
+ if (is_solid) {
+ ARRAY_SET_ITEMS(verts[3], r.xmax, r.ymax);
+ verts_len += 1;
+ prim_type = GPU_PRIM_TRI_FAN;
+ }
+ else {
+ prim_type = GPU_PRIM_LINE_STRIP;
+ }
+ break;
+ }
+ case ED_GIZMO_CAGE2D_PART_ROTATE: {
+ const float rotate_pt[2] = {0.0f, size[1] + margin[1]};
+ const rctf r_rotate = {
+ .xmin = rotate_pt[0] - margin[0] / 2.0f,
+ .xmax = rotate_pt[0] + margin[0] / 2.0f,
+ .ymin = rotate_pt[1] - margin[1] / 2.0f,
+ .ymax = rotate_pt[1] + margin[1] / 2.0f,
+ };
+
+ ARRAY_SET_ITEMS(verts[0], r_rotate.xmin, r_rotate.ymin);
+ ARRAY_SET_ITEMS(verts[1], r_rotate.xmin, r_rotate.ymax);
+ ARRAY_SET_ITEMS(verts[2], r_rotate.xmax, r_rotate.ymax);
+ ARRAY_SET_ITEMS(verts[3], r_rotate.xmax, r_rotate.ymin);
+ verts_len = 4;
+ if (is_solid) {
+ prim_type = GPU_PRIM_TRI_FAN;
+ }
+ else {
+ prim_type = GPU_PRIM_LINE_STRIP;
+ }
+ break;
+ }
+
+ case ED_GIZMO_CAGE2D_PART_TRANSLATE:
+ if (draw_options & ED_GIZMO_CAGE2D_DRAW_FLAG_XFORM_CENTER_HANDLE) {
+ ARRAY_SET_ITEMS(verts[0], -margin[0] / 2, -margin[1] / 2);
+ ARRAY_SET_ITEMS(verts[1], margin[0] / 2, margin[1] / 2);
+ ARRAY_SET_ITEMS(verts[2], -margin[0] / 2, margin[1] / 2);
+ ARRAY_SET_ITEMS(verts[3], margin[0] / 2, -margin[1] / 2);
+ verts_len = 4;
+ if (is_solid) {
+ prim_type = GPU_PRIM_TRI_FAN;
+ }
+ else {
+ prim_type = GPU_PRIM_LINES;
+ }
+ }
+ else {
+ /* Only used for 3D view selection, never displayed to the user. */
+ ARRAY_SET_ITEMS(verts[0], -size[0], -size[1]);
+ ARRAY_SET_ITEMS(verts[1], -size[0], size[1]);
+ ARRAY_SET_ITEMS(verts[2], size[0], size[1]);
+ ARRAY_SET_ITEMS(verts[3], size[0], -size[1]);
+ verts_len = 4;
+ if (is_solid) {
+ prim_type = GPU_PRIM_TRI_FAN;
+ }
+ else {
+ /* unreachable */
+ BLI_assert(0);
+ prim_type = GPU_PRIM_LINE_STRIP;
+ }
+ }
+ break;
+ default:
+ return;
+ }
+
+ BLI_assert(prim_type != GPU_PRIM_NONE);
+
+ GPUVertFormat *format = immVertexFormat();
+ struct {
+ uint pos, col;
+ } attr_id = {
+ .pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT),
+ .col = GPU_vertformat_attr_add(format, "color", GPU_COMP_F32, 3, GPU_FETCH_FLOAT),
+ };
+ immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR);
+
+ {
+ if (is_solid) {
+ BLI_assert(ELEM(prim_type, GPU_PRIM_TRI_FAN));
+ immBegin(prim_type, verts_len);
+ immAttr3f(attr_id.col, 0.0f, 0.0f, 0.0f);
+ for (uint i = 0; i < verts_len; i++) {
+ immVertex2fv(attr_id.pos, verts[i]);
+ }
+ immEnd();
+ }
+ else {
+ BLI_assert(ELEM(prim_type, GPU_PRIM_LINE_STRIP, GPU_PRIM_LINES));
+ GPU_line_width(line_width + 3.0f);
+
+ immBegin(prim_type, verts_len);
+ immAttr3f(attr_id.col, 0.0f, 0.0f, 0.0f);
+ for (uint i = 0; i < verts_len; i++) {
+ immVertex2fv(attr_id.pos, verts[i]);
+ }
+ immEnd();
+
+ GPU_line_width(line_width);
+
+ immBegin(prim_type, verts_len);
+ immAttr3fv(attr_id.col, color);
+ for (uint i = 0; i < verts_len; i++) {
+ immVertex2fv(attr_id.pos, verts[i]);
+ }
+ immEnd();
+ }
+ }
+
+ immUnbindProgram();
}
/** \} */
@@ -457,222 +496,238 @@ static void cage2d_draw_box_interaction(
* \{ */
static void imm_draw_point_aspect_2d(
- uint pos, float x, float y, float rad_x, float rad_y, bool solid)
+ uint pos, float x, float y, float rad_x, float rad_y, bool solid)
{
- immBegin(solid ? GPU_PRIM_TRI_FAN : GPU_PRIM_LINE_LOOP, 4);
- immVertex2f(pos, x - rad_x, y - rad_y);
- immVertex2f(pos, x - rad_x, y + rad_y);
- immVertex2f(pos, x + rad_x, y + rad_y);
- immVertex2f(pos, x + rad_x, y - rad_y);
- immEnd();
+ immBegin(solid ? GPU_PRIM_TRI_FAN : GPU_PRIM_LINE_LOOP, 4);
+ immVertex2f(pos, x - rad_x, y - rad_y);
+ immVertex2f(pos, x - rad_x, y + rad_y);
+ immVertex2f(pos, x + rad_x, y + rad_y);
+ immVertex2f(pos, x + rad_x, y - rad_y);
+ immEnd();
}
-static void cage2d_draw_circle_wire(
- const rctf *r, const float margin[2], const float color[3],
- const int transform_flag, const int draw_options)
+static void cage2d_draw_circle_wire(const rctf *r,
+ const float margin[2],
+ const float color[3],
+ const int transform_flag,
+ const int draw_options)
{
- uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
-
- immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
- immUniformColor3fv(color);
-
- immBegin(GPU_PRIM_LINE_LOOP, 4);
- immVertex2f(pos, r->xmin, r->ymin);
- immVertex2f(pos, r->xmax, r->ymin);
- immVertex2f(pos, r->xmax, r->ymax);
- immVertex2f(pos, r->xmin, r->ymax);
- immEnd();
-
- if (transform_flag & ED_GIZMO_CAGE2D_XFORM_FLAG_ROTATE) {
- immBegin(GPU_PRIM_LINE_LOOP, 2);
- immVertex2f(pos, BLI_rctf_cent_x(r), r->ymax);
- immVertex2f(pos, BLI_rctf_cent_x(r), r->ymax + margin[1]);
- immEnd();
- }
-
- if (transform_flag & ED_GIZMO_CAGE2D_XFORM_FLAG_TRANSLATE) {
- if (draw_options & ED_GIZMO_CAGE2D_DRAW_FLAG_XFORM_CENTER_HANDLE) {
- const float rad[2] = {margin[0] / 2, margin[1] / 2};
- const float center[2] = {BLI_rctf_cent_x(r), BLI_rctf_cent_y(r)};
-
- immBegin(GPU_PRIM_LINES, 4);
- immVertex2f(pos, center[0] - rad[0], center[1] - rad[1]);
- immVertex2f(pos, center[0] + rad[0], center[1] + rad[1]);
- immVertex2f(pos, center[0] + rad[0], center[1] - rad[1]);
- immVertex2f(pos, center[0] - rad[0], center[1] + rad[1]);
- immEnd();
- }
- }
-
- immUnbindProgram();
+ uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformColor3fv(color);
+
+ immBegin(GPU_PRIM_LINE_LOOP, 4);
+ immVertex2f(pos, r->xmin, r->ymin);
+ immVertex2f(pos, r->xmax, r->ymin);
+ immVertex2f(pos, r->xmax, r->ymax);
+ immVertex2f(pos, r->xmin, r->ymax);
+ immEnd();
+
+ if (transform_flag & ED_GIZMO_CAGE2D_XFORM_FLAG_ROTATE) {
+ immBegin(GPU_PRIM_LINE_LOOP, 2);
+ immVertex2f(pos, BLI_rctf_cent_x(r), r->ymax);
+ immVertex2f(pos, BLI_rctf_cent_x(r), r->ymax + margin[1]);
+ immEnd();
+ }
+
+ if (transform_flag & ED_GIZMO_CAGE2D_XFORM_FLAG_TRANSLATE) {
+ if (draw_options & ED_GIZMO_CAGE2D_DRAW_FLAG_XFORM_CENTER_HANDLE) {
+ const float rad[2] = {margin[0] / 2, margin[1] / 2};
+ const float center[2] = {BLI_rctf_cent_x(r), BLI_rctf_cent_y(r)};
+
+ immBegin(GPU_PRIM_LINES, 4);
+ immVertex2f(pos, center[0] - rad[0], center[1] - rad[1]);
+ immVertex2f(pos, center[0] + rad[0], center[1] + rad[1]);
+ immVertex2f(pos, center[0] + rad[0], center[1] - rad[1]);
+ immVertex2f(pos, center[0] - rad[0], center[1] + rad[1]);
+ immEnd();
+ }
+ }
+
+ immUnbindProgram();
}
-static void cage2d_draw_circle_handles(
- const rctf *r, const float margin[2], const float color[3],
- const int transform_flag,
- bool solid)
+static void cage2d_draw_circle_handles(const rctf *r,
+ const float margin[2],
+ const float color[3],
+ const int transform_flag,
+ bool solid)
{
- uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
- void (*circle_fn)(uint, float, float, float, float, int) =
- (solid) ? imm_draw_circle_fill_aspect_2d : imm_draw_circle_wire_aspect_2d;
- const int resolu = 12;
- const float rad[2] = {margin[0] / 3, margin[1] / 3};
-
- immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
- immUniformColor3fv(color);
-
- /* should really divide by two, but looks too bulky. */
- {
- imm_draw_point_aspect_2d(pos, r->xmin, r->ymin, rad[0], rad[1], solid);
- imm_draw_point_aspect_2d(pos, r->xmax, r->ymin, rad[0], rad[1], solid);
- imm_draw_point_aspect_2d(pos, r->xmax, r->ymax, rad[0], rad[1], solid);
- imm_draw_point_aspect_2d(pos, r->xmin, r->ymax, rad[0], rad[1], solid);
- }
-
- if (transform_flag & ED_GIZMO_CAGE2D_XFORM_FLAG_ROTATE) {
- const float handle[2] = {BLI_rctf_cent_x(r), r->ymax + (margin[1] * GIZMO_MARGIN_OFFSET_SCALE)};
- circle_fn(pos, handle[0], handle[1], rad[0], rad[1], resolu);
- }
-
- immUnbindProgram();
+ uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+ void (*circle_fn)(uint, float, float, float, float, int) = (solid) ?
+ imm_draw_circle_fill_aspect_2d :
+ imm_draw_circle_wire_aspect_2d;
+ const int resolu = 12;
+ const float rad[2] = {margin[0] / 3, margin[1] / 3};
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformColor3fv(color);
+
+ /* should really divide by two, but looks too bulky. */
+ {
+ imm_draw_point_aspect_2d(pos, r->xmin, r->ymin, rad[0], rad[1], solid);
+ imm_draw_point_aspect_2d(pos, r->xmax, r->ymin, rad[0], rad[1], solid);
+ imm_draw_point_aspect_2d(pos, r->xmax, r->ymax, rad[0], rad[1], solid);
+ imm_draw_point_aspect_2d(pos, r->xmin, r->ymax, rad[0], rad[1], solid);
+ }
+
+ if (transform_flag & ED_GIZMO_CAGE2D_XFORM_FLAG_ROTATE) {
+ const float handle[2] = {BLI_rctf_cent_x(r),
+ r->ymax + (margin[1] * GIZMO_MARGIN_OFFSET_SCALE)};
+ circle_fn(pos, handle[0], handle[1], rad[0], rad[1], resolu);
+ }
+
+ immUnbindProgram();
}
/** \} */
-static void gizmo_cage2d_draw_intern(
- wmGizmo *gz, const bool select, const bool highlight, const int select_id)
+static void gizmo_cage2d_draw_intern(wmGizmo *gz,
+ const bool select,
+ const bool highlight,
+ const int select_id)
{
- // const bool use_clamp = (gz->parent_gzgroup->type->flag & WM_GIZMOGROUPTYPE_3D) == 0;
- float dims[2];
- RNA_float_get_array(gz->ptr, "dimensions", dims);
- float matrix_final[4][4];
-
- const int transform_flag = RNA_enum_get(gz->ptr, "transform");
- const int draw_style = RNA_enum_get(gz->ptr, "draw_style");
- const int draw_options = RNA_enum_get(gz->ptr, "draw_options");
-
- const float size_real[2] = {dims[0] / 2.0f, dims[1] / 2.0f};
-
- WM_gizmo_calc_matrix_final(gz, matrix_final);
-
- GPU_matrix_push();
- GPU_matrix_mul(matrix_final);
-
- float margin[2];
- gizmo_calc_rect_view_margin(gz, dims, margin);
-
- /* Handy for quick testing draw (if it's outside bounds). */
- if (false) {
- GPU_blend(true);
- uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
- immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
- immUniformColor4fv((const float[4]){1, 1, 1, 0.5f});
- float s = 0.5f;
- immRectf(pos, -s, -s, s, s);
- immUnbindProgram();
- GPU_blend(false);
- }
-
- if (select) {
- /* expand for hotspot */
- const float size[2] = {size_real[0] + margin[0] / 2, size_real[1] + margin[1] / 2};
-
- if (transform_flag & ED_GIZMO_CAGE2D_XFORM_FLAG_SCALE) {
- int scale_parts[] = {
- ED_GIZMO_CAGE2D_PART_SCALE_MIN_X,
- ED_GIZMO_CAGE2D_PART_SCALE_MAX_X,
- ED_GIZMO_CAGE2D_PART_SCALE_MIN_Y,
- ED_GIZMO_CAGE2D_PART_SCALE_MAX_Y,
-
- ED_GIZMO_CAGE2D_PART_SCALE_MIN_X_MIN_Y,
- ED_GIZMO_CAGE2D_PART_SCALE_MIN_X_MAX_Y,
- ED_GIZMO_CAGE2D_PART_SCALE_MAX_X_MIN_Y,
- ED_GIZMO_CAGE2D_PART_SCALE_MAX_X_MAX_Y,
- };
- for (int i = 0; i < ARRAY_SIZE(scale_parts); i++) {
- GPU_select_load_id(select_id | scale_parts[i]);
- cage2d_draw_box_interaction(
- gz->color, scale_parts[i], size, margin, gz->line_width, true, draw_options);
- }
- }
- if (transform_flag & ED_GIZMO_CAGE2D_XFORM_FLAG_TRANSLATE) {
- const int transform_part = ED_GIZMO_CAGE2D_PART_TRANSLATE;
- GPU_select_load_id(select_id | transform_part);
- cage2d_draw_box_interaction(
- gz->color, transform_part, size, margin, gz->line_width, true, draw_options);
- }
- if (transform_flag & ED_GIZMO_CAGE2D_XFORM_FLAG_ROTATE) {
- cage2d_draw_box_interaction(
- gz->color, ED_GIZMO_CAGE2D_PART_ROTATE, size_real, margin, gz->line_width, true, draw_options);
- }
- }
- else {
- const rctf r = {
- .xmin = -size_real[0],
- .ymin = -size_real[1],
- .xmax = size_real[0],
- .ymax = size_real[1],
- };
- if (draw_style == ED_GIZMO_CAGE2D_STYLE_BOX) {
- /* corner gizmos */
- GPU_line_width(gz->line_width + 3.0f);
- cage2d_draw_box_corners(&r, margin, (const float[3]){0, 0, 0});
-
- /* corner gizmos */
- float color[4];
- gizmo_color_get(gz, highlight, color);
- GPU_line_width(gz->line_width);
- cage2d_draw_box_corners(&r, margin, color);
-
- bool show = false;
- if (gz->highlight_part == ED_GIZMO_CAGE2D_PART_TRANSLATE) {
- /* Only show if we're drawing the center handle
- * otherwise the entire rectangle is the hotspot. */
- if (draw_options & ED_GIZMO_CAGE2D_DRAW_FLAG_XFORM_CENTER_HANDLE) {
- show = true;
- }
- }
- else {
- show = true;
- }
-
- if (show) {
- cage2d_draw_box_interaction(
- gz->color, gz->highlight_part, size_real, margin, gz->line_width, false, draw_options);
- }
-
- if (transform_flag & ED_GIZMO_CAGE2D_XFORM_FLAG_ROTATE) {
- cage2d_draw_box_interaction(
- gz->color, ED_GIZMO_CAGE2D_PART_ROTATE, size_real, margin, gz->line_width, false, draw_options);
- }
- }
- else if (draw_style == ED_GIZMO_CAGE2D_STYLE_CIRCLE) {
- float color[4];
- gizmo_color_get(gz, highlight, color);
-
- GPU_line_smooth(true);
- GPU_blend(true);
-
- GPU_line_width(gz->line_width + 3.0f);
- cage2d_draw_circle_wire(&r, margin, (const float[3]){0, 0, 0}, transform_flag, draw_options);
- GPU_line_width(gz->line_width);
- cage2d_draw_circle_wire(&r, margin, color, transform_flag, draw_options);
-
-
- /* corner gizmos */
- cage2d_draw_circle_handles(&r, margin, color, transform_flag, true);
- cage2d_draw_circle_handles(&r, margin, (const float[3]){0, 0, 0}, transform_flag, false);
-
- GPU_blend(false);
- GPU_line_smooth(false);
- }
- else {
- BLI_assert(0);
- }
- }
-
- GPU_line_width(1.0);
- GPU_matrix_pop();
+ // const bool use_clamp = (gz->parent_gzgroup->type->flag & WM_GIZMOGROUPTYPE_3D) == 0;
+ float dims[2];
+ RNA_float_get_array(gz->ptr, "dimensions", dims);
+ float matrix_final[4][4];
+
+ const int transform_flag = RNA_enum_get(gz->ptr, "transform");
+ const int draw_style = RNA_enum_get(gz->ptr, "draw_style");
+ const int draw_options = RNA_enum_get(gz->ptr, "draw_options");
+
+ const float size_real[2] = {dims[0] / 2.0f, dims[1] / 2.0f};
+
+ WM_gizmo_calc_matrix_final(gz, matrix_final);
+
+ GPU_matrix_push();
+ GPU_matrix_mul(matrix_final);
+
+ float margin[2];
+ gizmo_calc_rect_view_margin(gz, dims, margin);
+
+ /* Handy for quick testing draw (if it's outside bounds). */
+ if (false) {
+ GPU_blend(true);
+ uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformColor4fv((const float[4]){1, 1, 1, 0.5f});
+ float s = 0.5f;
+ immRectf(pos, -s, -s, s, s);
+ immUnbindProgram();
+ GPU_blend(false);
+ }
+
+ if (select) {
+ /* expand for hotspot */
+ const float size[2] = {size_real[0] + margin[0] / 2, size_real[1] + margin[1] / 2};
+
+ if (transform_flag & ED_GIZMO_CAGE2D_XFORM_FLAG_SCALE) {
+ int scale_parts[] = {
+ ED_GIZMO_CAGE2D_PART_SCALE_MIN_X,
+ ED_GIZMO_CAGE2D_PART_SCALE_MAX_X,
+ ED_GIZMO_CAGE2D_PART_SCALE_MIN_Y,
+ ED_GIZMO_CAGE2D_PART_SCALE_MAX_Y,
+
+ ED_GIZMO_CAGE2D_PART_SCALE_MIN_X_MIN_Y,
+ ED_GIZMO_CAGE2D_PART_SCALE_MIN_X_MAX_Y,
+ ED_GIZMO_CAGE2D_PART_SCALE_MAX_X_MIN_Y,
+ ED_GIZMO_CAGE2D_PART_SCALE_MAX_X_MAX_Y,
+ };
+ for (int i = 0; i < ARRAY_SIZE(scale_parts); i++) {
+ GPU_select_load_id(select_id | scale_parts[i]);
+ cage2d_draw_box_interaction(
+ gz->color, scale_parts[i], size, margin, gz->line_width, true, draw_options);
+ }
+ }
+ if (transform_flag & ED_GIZMO_CAGE2D_XFORM_FLAG_TRANSLATE) {
+ const int transform_part = ED_GIZMO_CAGE2D_PART_TRANSLATE;
+ GPU_select_load_id(select_id | transform_part);
+ cage2d_draw_box_interaction(
+ gz->color, transform_part, size, margin, gz->line_width, true, draw_options);
+ }
+ if (transform_flag & ED_GIZMO_CAGE2D_XFORM_FLAG_ROTATE) {
+ cage2d_draw_box_interaction(gz->color,
+ ED_GIZMO_CAGE2D_PART_ROTATE,
+ size_real,
+ margin,
+ gz->line_width,
+ true,
+ draw_options);
+ }
+ }
+ else {
+ const rctf r = {
+ .xmin = -size_real[0],
+ .ymin = -size_real[1],
+ .xmax = size_real[0],
+ .ymax = size_real[1],
+ };
+ if (draw_style == ED_GIZMO_CAGE2D_STYLE_BOX) {
+ /* corner gizmos */
+ GPU_line_width(gz->line_width + 3.0f);
+ cage2d_draw_box_corners(&r, margin, (const float[3]){0, 0, 0});
+
+ /* corner gizmos */
+ float color[4];
+ gizmo_color_get(gz, highlight, color);
+ GPU_line_width(gz->line_width);
+ cage2d_draw_box_corners(&r, margin, color);
+
+ bool show = false;
+ if (gz->highlight_part == ED_GIZMO_CAGE2D_PART_TRANSLATE) {
+ /* Only show if we're drawing the center handle
+ * otherwise the entire rectangle is the hotspot. */
+ if (draw_options & ED_GIZMO_CAGE2D_DRAW_FLAG_XFORM_CENTER_HANDLE) {
+ show = true;
+ }
+ }
+ else {
+ show = true;
+ }
+
+ if (show) {
+ cage2d_draw_box_interaction(
+ gz->color, gz->highlight_part, size_real, margin, gz->line_width, false, draw_options);
+ }
+
+ if (transform_flag & ED_GIZMO_CAGE2D_XFORM_FLAG_ROTATE) {
+ cage2d_draw_box_interaction(gz->color,
+ ED_GIZMO_CAGE2D_PART_ROTATE,
+ size_real,
+ margin,
+ gz->line_width,
+ false,
+ draw_options);
+ }
+ }
+ else if (draw_style == ED_GIZMO_CAGE2D_STYLE_CIRCLE) {
+ float color[4];
+ gizmo_color_get(gz, highlight, color);
+
+ GPU_line_smooth(true);
+ GPU_blend(true);
+
+ GPU_line_width(gz->line_width + 3.0f);
+ cage2d_draw_circle_wire(&r, margin, (const float[3]){0, 0, 0}, transform_flag, draw_options);
+ GPU_line_width(gz->line_width);
+ cage2d_draw_circle_wire(&r, margin, color, transform_flag, draw_options);
+
+ /* corner gizmos */
+ cage2d_draw_circle_handles(&r, margin, color, transform_flag, true);
+ cage2d_draw_circle_handles(&r, margin, (const float[3]){0, 0, 0}, transform_flag, false);
+
+ GPU_blend(false);
+ GPU_line_smooth(false);
+ }
+ else {
+ BLI_assert(0);
+ }
+ }
+
+ GPU_line_width(1.0);
+ GPU_matrix_pop();
}
/**
@@ -680,377 +735,400 @@ static void gizmo_cage2d_draw_intern(
*/
static void gizmo_cage2d_draw_select(const bContext *UNUSED(C), wmGizmo *gz, int select_id)
{
- gizmo_cage2d_draw_intern(gz, true, false, select_id);
+ gizmo_cage2d_draw_intern(gz, true, false, select_id);
}
static void gizmo_cage2d_draw(const bContext *UNUSED(C), wmGizmo *gz)
{
- const bool is_highlight = (gz->state & WM_GIZMO_STATE_HIGHLIGHT) != 0;
- gizmo_cage2d_draw_intern(gz, false, is_highlight, -1);
+ const bool is_highlight = (gz->state & WM_GIZMO_STATE_HIGHLIGHT) != 0;
+ gizmo_cage2d_draw_intern(gz, false, is_highlight, -1);
}
static int gizmo_cage2d_get_cursor(wmGizmo *gz)
{
- int highlight_part = gz->highlight_part;
-
- if (gz->parent_gzgroup->type->flag & WM_GIZMOGROUPTYPE_3D) {
- return BC_NSEW_SCROLLCURSOR;
- }
-
- switch (highlight_part) {
- case ED_GIZMO_CAGE2D_PART_TRANSLATE:
- return BC_NSEW_SCROLLCURSOR;
- case ED_GIZMO_CAGE2D_PART_SCALE_MIN_X:
- case ED_GIZMO_CAGE2D_PART_SCALE_MAX_X:
- return CURSOR_X_MOVE;
- case ED_GIZMO_CAGE2D_PART_SCALE_MIN_Y:
- case ED_GIZMO_CAGE2D_PART_SCALE_MAX_Y:
- return CURSOR_Y_MOVE;
-
- /* TODO diagonal cursor */
- case ED_GIZMO_CAGE2D_PART_SCALE_MIN_X_MIN_Y:
- case ED_GIZMO_CAGE2D_PART_SCALE_MAX_X_MIN_Y:
- return BC_NSEW_SCROLLCURSOR;
- case ED_GIZMO_CAGE2D_PART_SCALE_MIN_X_MAX_Y:
- case ED_GIZMO_CAGE2D_PART_SCALE_MAX_X_MAX_Y:
- return BC_NSEW_SCROLLCURSOR;
- case ED_GIZMO_CAGE2D_PART_ROTATE:
- return BC_CROSSCURSOR;
- default:
- return CURSOR_STD;
- }
+ int highlight_part = gz->highlight_part;
+
+ if (gz->parent_gzgroup->type->flag & WM_GIZMOGROUPTYPE_3D) {
+ return BC_NSEW_SCROLLCURSOR;
+ }
+
+ switch (highlight_part) {
+ case ED_GIZMO_CAGE2D_PART_TRANSLATE:
+ return BC_NSEW_SCROLLCURSOR;
+ case ED_GIZMO_CAGE2D_PART_SCALE_MIN_X:
+ case ED_GIZMO_CAGE2D_PART_SCALE_MAX_X:
+ return CURSOR_X_MOVE;
+ case ED_GIZMO_CAGE2D_PART_SCALE_MIN_Y:
+ case ED_GIZMO_CAGE2D_PART_SCALE_MAX_Y:
+ return CURSOR_Y_MOVE;
+
+ /* TODO diagonal cursor */
+ case ED_GIZMO_CAGE2D_PART_SCALE_MIN_X_MIN_Y:
+ case ED_GIZMO_CAGE2D_PART_SCALE_MAX_X_MIN_Y:
+ return BC_NSEW_SCROLLCURSOR;
+ case ED_GIZMO_CAGE2D_PART_SCALE_MIN_X_MAX_Y:
+ case ED_GIZMO_CAGE2D_PART_SCALE_MAX_X_MAX_Y:
+ return BC_NSEW_SCROLLCURSOR;
+ case ED_GIZMO_CAGE2D_PART_ROTATE:
+ return BC_CROSSCURSOR;
+ default:
+ return CURSOR_STD;
+ }
}
-static int gizmo_cage2d_test_select(
- bContext *C, wmGizmo *gz, const int mval[2])
+static int gizmo_cage2d_test_select(bContext *C, wmGizmo *gz, const int mval[2])
{
- float point_local[2];
- float dims[2];
- RNA_float_get_array(gz->ptr, "dimensions", dims);
- const float size_real[2] = {dims[0] / 2.0f, dims[1] / 2.0f};
-
- if (gizmo_window_project_2d(
- C, gz, (const float[2]){UNPACK2(mval)}, 2, true, point_local) == false)
- {
- return -1;
- }
-
- float margin[2];
- if (!gizmo_calc_rect_view_margin(gz, dims, margin)) {
- return -1;
- }
-
- /* expand for hotspot */
- const float size[2] = {size_real[0] + margin[0] / 2, size_real[1] + margin[1] / 2};
-
- const int transform_flag = RNA_enum_get(gz->ptr, "transform");
- const int draw_options = RNA_enum_get(gz->ptr, "draw_options");
-
- if (transform_flag & ED_GIZMO_CAGE2D_XFORM_FLAG_TRANSLATE) {
- rctf r;
- if (draw_options & ED_GIZMO_CAGE2D_DRAW_FLAG_XFORM_CENTER_HANDLE) {
- r.xmin = -margin[0] / 2;
- r.ymin = -margin[1] / 2;
- r.xmax = margin[0] / 2;
- r.ymax = margin[1] / 2;
- }
- else {
- r.xmin = -size[0] + margin[0];
- r.ymin = -size[1] + margin[1];
- r.xmax = size[0] - margin[0];
- r.ymax = size[1] - margin[1];
- }
- bool isect = BLI_rctf_isect_pt_v(&r, point_local);
- if (isect) {
- return ED_GIZMO_CAGE2D_PART_TRANSLATE;
- }
- }
-
- /* if gizmo does not have a scale intersection, don't do it */
- if (transform_flag & (ED_GIZMO_CAGE2D_XFORM_FLAG_SCALE | ED_GIZMO_CAGE2D_XFORM_FLAG_SCALE_UNIFORM)) {
- const rctf r_xmin = { .xmin = -size[0], .ymin = -size[1], .xmax = -size[0] + margin[0], .ymax = size[1], };
- const rctf r_xmax = { .xmin = size[0] - margin[0], .ymin = -size[1], .xmax = size[0], .ymax = size[1], };
- const rctf r_ymin = { .xmin = -size[0], .ymin = -size[1], .xmax = size[0], .ymax = -size[1] + margin[1], };
- const rctf r_ymax = { .xmin = -size[0], .ymin = size[1] - margin[1], .xmax = size[0], .ymax = size[1], };
-
- if (BLI_rctf_isect_pt_v(&r_xmin, point_local)) {
- if (BLI_rctf_isect_pt_v(&r_ymin, point_local)) {
- return ED_GIZMO_CAGE2D_PART_SCALE_MIN_X_MIN_Y;
- }
- if (BLI_rctf_isect_pt_v(&r_ymax, point_local)) {
- return ED_GIZMO_CAGE2D_PART_SCALE_MIN_X_MAX_Y;
- }
- return ED_GIZMO_CAGE2D_PART_SCALE_MIN_X;
- }
- if (BLI_rctf_isect_pt_v(&r_xmax, point_local)) {
- if (BLI_rctf_isect_pt_v(&r_ymin, point_local)) {
- return ED_GIZMO_CAGE2D_PART_SCALE_MAX_X_MIN_Y;
- }
- if (BLI_rctf_isect_pt_v(&r_ymax, point_local)) {
- return ED_GIZMO_CAGE2D_PART_SCALE_MAX_X_MAX_Y;
- }
- return ED_GIZMO_CAGE2D_PART_SCALE_MAX_X;
- }
- if (BLI_rctf_isect_pt_v(&r_ymin, point_local)) {
- return ED_GIZMO_CAGE2D_PART_SCALE_MIN_Y;
- }
- if (BLI_rctf_isect_pt_v(&r_ymax, point_local)) {
- return ED_GIZMO_CAGE2D_PART_SCALE_MAX_Y;
- }
- }
-
- if (transform_flag & ED_GIZMO_CAGE2D_XFORM_FLAG_ROTATE) {
- /* Rotate:
- * (*) <-- hot spot is here!
- * +---+
- * | |
- * +---+ */
- const float r_rotate_pt[2] = {0.0f, size_real[1] + (margin[1] * GIZMO_MARGIN_OFFSET_SCALE)};
- const rctf r_rotate = {
- .xmin = r_rotate_pt[0] - margin[0] / 2.0f,
- .xmax = r_rotate_pt[0] + margin[0] / 2.0f,
- .ymin = r_rotate_pt[1] - margin[1] / 2.0f,
- .ymax = r_rotate_pt[1] + margin[1] / 2.0f,
- };
-
- if (BLI_rctf_isect_pt_v(&r_rotate, point_local)) {
- return ED_GIZMO_CAGE2D_PART_ROTATE;
- }
- }
-
- return -1;
+ float point_local[2];
+ float dims[2];
+ RNA_float_get_array(gz->ptr, "dimensions", dims);
+ const float size_real[2] = {dims[0] / 2.0f, dims[1] / 2.0f};
+
+ if (gizmo_window_project_2d(C, gz, (const float[2]){UNPACK2(mval)}, 2, true, point_local) ==
+ false) {
+ return -1;
+ }
+
+ float margin[2];
+ if (!gizmo_calc_rect_view_margin(gz, dims, margin)) {
+ return -1;
+ }
+
+ /* expand for hotspot */
+ const float size[2] = {size_real[0] + margin[0] / 2, size_real[1] + margin[1] / 2};
+
+ const int transform_flag = RNA_enum_get(gz->ptr, "transform");
+ const int draw_options = RNA_enum_get(gz->ptr, "draw_options");
+
+ if (transform_flag & ED_GIZMO_CAGE2D_XFORM_FLAG_TRANSLATE) {
+ rctf r;
+ if (draw_options & ED_GIZMO_CAGE2D_DRAW_FLAG_XFORM_CENTER_HANDLE) {
+ r.xmin = -margin[0] / 2;
+ r.ymin = -margin[1] / 2;
+ r.xmax = margin[0] / 2;
+ r.ymax = margin[1] / 2;
+ }
+ else {
+ r.xmin = -size[0] + margin[0];
+ r.ymin = -size[1] + margin[1];
+ r.xmax = size[0] - margin[0];
+ r.ymax = size[1] - margin[1];
+ }
+ bool isect = BLI_rctf_isect_pt_v(&r, point_local);
+ if (isect) {
+ return ED_GIZMO_CAGE2D_PART_TRANSLATE;
+ }
+ }
+
+ /* if gizmo does not have a scale intersection, don't do it */
+ if (transform_flag &
+ (ED_GIZMO_CAGE2D_XFORM_FLAG_SCALE | ED_GIZMO_CAGE2D_XFORM_FLAG_SCALE_UNIFORM)) {
+ const rctf r_xmin = {
+ .xmin = -size[0],
+ .ymin = -size[1],
+ .xmax = -size[0] + margin[0],
+ .ymax = size[1],
+ };
+ const rctf r_xmax = {
+ .xmin = size[0] - margin[0],
+ .ymin = -size[1],
+ .xmax = size[0],
+ .ymax = size[1],
+ };
+ const rctf r_ymin = {
+ .xmin = -size[0],
+ .ymin = -size[1],
+ .xmax = size[0],
+ .ymax = -size[1] + margin[1],
+ };
+ const rctf r_ymax = {
+ .xmin = -size[0],
+ .ymin = size[1] - margin[1],
+ .xmax = size[0],
+ .ymax = size[1],
+ };
+
+ if (BLI_rctf_isect_pt_v(&r_xmin, point_local)) {
+ if (BLI_rctf_isect_pt_v(&r_ymin, point_local)) {
+ return ED_GIZMO_CAGE2D_PART_SCALE_MIN_X_MIN_Y;
+ }
+ if (BLI_rctf_isect_pt_v(&r_ymax, point_local)) {
+ return ED_GIZMO_CAGE2D_PART_SCALE_MIN_X_MAX_Y;
+ }
+ return ED_GIZMO_CAGE2D_PART_SCALE_MIN_X;
+ }
+ if (BLI_rctf_isect_pt_v(&r_xmax, point_local)) {
+ if (BLI_rctf_isect_pt_v(&r_ymin, point_local)) {
+ return ED_GIZMO_CAGE2D_PART_SCALE_MAX_X_MIN_Y;
+ }
+ if (BLI_rctf_isect_pt_v(&r_ymax, point_local)) {
+ return ED_GIZMO_CAGE2D_PART_SCALE_MAX_X_MAX_Y;
+ }
+ return ED_GIZMO_CAGE2D_PART_SCALE_MAX_X;
+ }
+ if (BLI_rctf_isect_pt_v(&r_ymin, point_local)) {
+ return ED_GIZMO_CAGE2D_PART_SCALE_MIN_Y;
+ }
+ if (BLI_rctf_isect_pt_v(&r_ymax, point_local)) {
+ return ED_GIZMO_CAGE2D_PART_SCALE_MAX_Y;
+ }
+ }
+
+ if (transform_flag & ED_GIZMO_CAGE2D_XFORM_FLAG_ROTATE) {
+ /* Rotate:
+ * (*) <-- hot spot is here!
+ * +---+
+ * | |
+ * +---+ */
+ const float r_rotate_pt[2] = {0.0f, size_real[1] + (margin[1] * GIZMO_MARGIN_OFFSET_SCALE)};
+ const rctf r_rotate = {
+ .xmin = r_rotate_pt[0] - margin[0] / 2.0f,
+ .xmax = r_rotate_pt[0] + margin[0] / 2.0f,
+ .ymin = r_rotate_pt[1] - margin[1] / 2.0f,
+ .ymax = r_rotate_pt[1] + margin[1] / 2.0f,
+ };
+
+ if (BLI_rctf_isect_pt_v(&r_rotate, point_local)) {
+ return ED_GIZMO_CAGE2D_PART_ROTATE;
+ }
+ }
+
+ return -1;
}
typedef struct RectTransformInteraction {
- float orig_mouse[2];
- float orig_matrix_offset[4][4];
- float orig_matrix_final_no_offset[4][4];
- Dial *dial;
+ float orig_mouse[2];
+ float orig_matrix_offset[4][4];
+ float orig_matrix_final_no_offset[4][4];
+ Dial *dial;
} RectTransformInteraction;
static void gizmo_cage2d_setup(wmGizmo *gz)
{
- gz->flag |= WM_GIZMO_DRAW_MODAL | WM_GIZMO_DRAW_NO_SCALE;
+ gz->flag |= WM_GIZMO_DRAW_MODAL | WM_GIZMO_DRAW_NO_SCALE;
}
-static int gizmo_cage2d_invoke(
- bContext *C, wmGizmo *gz, const wmEvent *event)
+static int gizmo_cage2d_invoke(bContext *C, wmGizmo *gz, const wmEvent *event)
{
- RectTransformInteraction *data = MEM_callocN(sizeof(RectTransformInteraction), "cage_interaction");
+ RectTransformInteraction *data = MEM_callocN(sizeof(RectTransformInteraction),
+ "cage_interaction");
- copy_m4_m4(data->orig_matrix_offset, gz->matrix_offset);
- WM_gizmo_calc_matrix_final_no_offset(gz, data->orig_matrix_final_no_offset);
+ copy_m4_m4(data->orig_matrix_offset, gz->matrix_offset);
+ WM_gizmo_calc_matrix_final_no_offset(gz, data->orig_matrix_final_no_offset);
- if (gizmo_window_project_2d(
- C, gz, (const float[2]){UNPACK2(event->mval)}, 2, false, data->orig_mouse) == 0)
- {
- zero_v2(data->orig_mouse);
- }
+ if (gizmo_window_project_2d(
+ C, gz, (const float[2]){UNPACK2(event->mval)}, 2, false, data->orig_mouse) == 0) {
+ zero_v2(data->orig_mouse);
+ }
- gz->interaction_data = data;
+ gz->interaction_data = data;
- return OPERATOR_RUNNING_MODAL;
+ return OPERATOR_RUNNING_MODAL;
}
-static int gizmo_cage2d_modal(
- bContext *C, wmGizmo *gz, const wmEvent *event,
- eWM_GizmoFlagTweak UNUSED(tweak_flag))
+static int gizmo_cage2d_modal(bContext *C,
+ wmGizmo *gz,
+ const wmEvent *event,
+ eWM_GizmoFlagTweak UNUSED(tweak_flag))
{
- if (event->type != MOUSEMOVE) {
- return OPERATOR_RUNNING_MODAL;
- }
- /* For transform logic to be manageable we operate in -0.5..0.5 2D space,
- * no matter the size of the rectangle, mouse coords are scaled to unit space.
- * The mouse coords have been projected into the matrix so we don't need to worry about axis alignment.
- *
- * - The cursor offset are multiplied by 'dims'.
- * - Matrix translation is also multiplied by 'dims'.
- */
- RectTransformInteraction *data = gz->interaction_data;
- float point_local[2];
-
- float dims[2];
- RNA_float_get_array(gz->ptr, "dimensions", dims);
-
- {
- float matrix_back[4][4];
- copy_m4_m4(matrix_back, gz->matrix_offset);
- copy_m4_m4(gz->matrix_offset, data->orig_matrix_offset);
-
- bool ok = gizmo_window_project_2d(
- C, gz, (const float[2]){UNPACK2(event->mval)}, 2, false, point_local);
- copy_m4_m4(gz->matrix_offset, matrix_back);
- if (!ok) {
- return OPERATOR_RUNNING_MODAL;
- }
- }
-
- const int transform_flag = RNA_enum_get(gz->ptr, "transform");
- wmGizmoProperty *gz_prop;
-
- gz_prop = WM_gizmo_target_property_find(gz, "matrix");
- if (gz_prop->type != NULL) {
- WM_gizmo_target_property_float_get_array(gz, gz_prop, &gz->matrix_offset[0][0]);
- }
-
- if (gz->highlight_part == ED_GIZMO_CAGE2D_PART_TRANSLATE) {
- /* do this to prevent clamping from changing size */
- copy_m4_m4(gz->matrix_offset, data->orig_matrix_offset);
- gz->matrix_offset[3][0] = data->orig_matrix_offset[3][0] + (point_local[0] - data->orig_mouse[0]);
- gz->matrix_offset[3][1] = data->orig_matrix_offset[3][1] + (point_local[1] - data->orig_mouse[1]);
- }
- else if (gz->highlight_part == ED_GIZMO_CAGE2D_PART_ROTATE) {
+ if (event->type != MOUSEMOVE) {
+ return OPERATOR_RUNNING_MODAL;
+ }
+ /* For transform logic to be manageable we operate in -0.5..0.5 2D space,
+ * no matter the size of the rectangle, mouse coords are scaled to unit space.
+ * The mouse coords have been projected into the matrix so we don't need to worry about axis alignment.
+ *
+ * - The cursor offset are multiplied by 'dims'.
+ * - Matrix translation is also multiplied by 'dims'.
+ */
+ RectTransformInteraction *data = gz->interaction_data;
+ float point_local[2];
+
+ float dims[2];
+ RNA_float_get_array(gz->ptr, "dimensions", dims);
+
+ {
+ float matrix_back[4][4];
+ copy_m4_m4(matrix_back, gz->matrix_offset);
+ copy_m4_m4(gz->matrix_offset, data->orig_matrix_offset);
+
+ bool ok = gizmo_window_project_2d(
+ C, gz, (const float[2]){UNPACK2(event->mval)}, 2, false, point_local);
+ copy_m4_m4(gz->matrix_offset, matrix_back);
+ if (!ok) {
+ return OPERATOR_RUNNING_MODAL;
+ }
+ }
+
+ const int transform_flag = RNA_enum_get(gz->ptr, "transform");
+ wmGizmoProperty *gz_prop;
+
+ gz_prop = WM_gizmo_target_property_find(gz, "matrix");
+ if (gz_prop->type != NULL) {
+ WM_gizmo_target_property_float_get_array(gz, gz_prop, &gz->matrix_offset[0][0]);
+ }
+
+ if (gz->highlight_part == ED_GIZMO_CAGE2D_PART_TRANSLATE) {
+ /* do this to prevent clamping from changing size */
+ copy_m4_m4(gz->matrix_offset, data->orig_matrix_offset);
+ gz->matrix_offset[3][0] = data->orig_matrix_offset[3][0] +
+ (point_local[0] - data->orig_mouse[0]);
+ gz->matrix_offset[3][1] = data->orig_matrix_offset[3][1] +
+ (point_local[1] - data->orig_mouse[1]);
+ }
+ else if (gz->highlight_part == ED_GIZMO_CAGE2D_PART_ROTATE) {
#define MUL_V2_V3_M4_FINAL(test_co, mouse_co) \
- mul_v3_m4v3(test_co, data->orig_matrix_final_no_offset, ((const float[3]){UNPACK2(mouse_co), 0.0}))
+ mul_v3_m4v3( \
+ test_co, data->orig_matrix_final_no_offset, ((const float[3]){UNPACK2(mouse_co), 0.0}))
- float test_co[3];
+ float test_co[3];
- if (data->dial == NULL) {
- MUL_V2_V3_M4_FINAL(test_co, data->orig_matrix_offset[3]);
+ if (data->dial == NULL) {
+ MUL_V2_V3_M4_FINAL(test_co, data->orig_matrix_offset[3]);
- data->dial = BLI_dial_initialize(test_co, FLT_EPSILON);
+ data->dial = BLI_dial_initialize(test_co, FLT_EPSILON);
- MUL_V2_V3_M4_FINAL(test_co, data->orig_mouse);
- BLI_dial_angle(data->dial, test_co);
- }
+ MUL_V2_V3_M4_FINAL(test_co, data->orig_mouse);
+ BLI_dial_angle(data->dial, test_co);
+ }
- /* rotate */
- MUL_V2_V3_M4_FINAL(test_co, point_local);
- const float angle = BLI_dial_angle(data->dial, test_co);
+ /* rotate */
+ MUL_V2_V3_M4_FINAL(test_co, point_local);
+ const float angle = BLI_dial_angle(data->dial, test_co);
- float matrix_space_inv[4][4];
- float matrix_rotate[4][4];
- float pivot[3];
+ float matrix_space_inv[4][4];
+ float matrix_rotate[4][4];
+ float pivot[3];
- copy_v3_v3(pivot, data->orig_matrix_offset[3]);
+ copy_v3_v3(pivot, data->orig_matrix_offset[3]);
- invert_m4_m4(matrix_space_inv, gz->matrix_space);
+ invert_m4_m4(matrix_space_inv, gz->matrix_space);
- unit_m4(matrix_rotate);
- mul_m4_m4m4(matrix_rotate, matrix_rotate, matrix_space_inv);
- rotate_m4(matrix_rotate, 'Z', -angle);
- mul_m4_m4m4(matrix_rotate, matrix_rotate, gz->matrix_space);
+ unit_m4(matrix_rotate);
+ mul_m4_m4m4(matrix_rotate, matrix_rotate, matrix_space_inv);
+ rotate_m4(matrix_rotate, 'Z', -angle);
+ mul_m4_m4m4(matrix_rotate, matrix_rotate, gz->matrix_space);
- zero_v3(matrix_rotate[3]);
- transform_pivot_set_m4(matrix_rotate, pivot);
+ zero_v3(matrix_rotate[3]);
+ transform_pivot_set_m4(matrix_rotate, pivot);
- mul_m4_m4m4(gz->matrix_offset, matrix_rotate, data->orig_matrix_offset);
+ mul_m4_m4m4(gz->matrix_offset, matrix_rotate, data->orig_matrix_offset);
#undef MUL_V2_V3_M4_FINAL
- }
- else {
- /* scale */
- copy_m4_m4(gz->matrix_offset, data->orig_matrix_offset);
- float pivot[2];
- bool constrain_axis[2] = {false};
-
- if (transform_flag & ED_GIZMO_CAGE2D_XFORM_FLAG_TRANSLATE) {
- gizmo_rect_pivot_from_scale_part(gz->highlight_part, pivot, constrain_axis);
- }
- else {
- zero_v2(pivot);
- }
-
- /* Cursor deltas scaled to (-0.5..0.5). */
- float delta_orig[2], delta_curr[2];
- for (int i = 0; i < 2; i++) {
- delta_orig[i] = ((data->orig_mouse[i] - data->orig_matrix_offset[3][i]) / dims[i]) - pivot[i];
- delta_curr[i] = ((point_local[i] - data->orig_matrix_offset[3][i]) / dims[i]) - pivot[i];
- }
-
- float scale[2] = {1.0f, 1.0f};
- for (int i = 0; i < 2; i++) {
- if (constrain_axis[i] == false) {
- if (delta_orig[i] < 0.0f) {
- delta_orig[i] *= -1.0f;
- delta_curr[i] *= -1.0f;
- }
- const int sign = signum_i(scale[i]);
-
- scale[i] = 1.0f + ((delta_curr[i] - delta_orig[i]) / len_v3(data->orig_matrix_offset[i]));
-
- if ((transform_flag & ED_GIZMO_CAGE2D_XFORM_FLAG_SCALE_SIGNED) == 0) {
- if (sign != signum_i(scale[i])) {
- scale[i] = 0.0f;
- }
- }
- }
- }
-
- if (transform_flag & ED_GIZMO_CAGE2D_XFORM_FLAG_SCALE_UNIFORM) {
- if (constrain_axis[0] == false && constrain_axis[1] == false) {
- scale[1] = scale[0] = (scale[1] + scale[0]) / 2.0f;
- }
- else if (constrain_axis[0] == false) {
- scale[1] = scale[0];
- }
- else if (constrain_axis[1] == false) {
- scale[0] = scale[1];
- }
- else {
- BLI_assert(0);
- }
- }
-
- /* scale around pivot */
- float matrix_scale[4][4];
- unit_m4(matrix_scale);
-
- mul_v3_fl(matrix_scale[0], scale[0]);
- mul_v3_fl(matrix_scale[1], scale[1]);
-
- transform_pivot_set_m4(matrix_scale, (const float[3]){pivot[0] * dims[0], pivot[1] * dims[1], 0.0f});
- mul_m4_m4m4(gz->matrix_offset, data->orig_matrix_offset, matrix_scale);
- }
-
- if (gz_prop->type != NULL) {
- WM_gizmo_target_property_float_set_array(C, gz, gz_prop, &gz->matrix_offset[0][0]);
- }
-
- /* tag the region for redraw */
- ED_region_tag_redraw(CTX_wm_region(C));
- WM_event_add_mousemove(C);
-
- return OPERATOR_RUNNING_MODAL;
+ }
+ else {
+ /* scale */
+ copy_m4_m4(gz->matrix_offset, data->orig_matrix_offset);
+ float pivot[2];
+ bool constrain_axis[2] = {false};
+
+ if (transform_flag & ED_GIZMO_CAGE2D_XFORM_FLAG_TRANSLATE) {
+ gizmo_rect_pivot_from_scale_part(gz->highlight_part, pivot, constrain_axis);
+ }
+ else {
+ zero_v2(pivot);
+ }
+
+ /* Cursor deltas scaled to (-0.5..0.5). */
+ float delta_orig[2], delta_curr[2];
+ for (int i = 0; i < 2; i++) {
+ delta_orig[i] = ((data->orig_mouse[i] - data->orig_matrix_offset[3][i]) / dims[i]) -
+ pivot[i];
+ delta_curr[i] = ((point_local[i] - data->orig_matrix_offset[3][i]) / dims[i]) - pivot[i];
+ }
+
+ float scale[2] = {1.0f, 1.0f};
+ for (int i = 0; i < 2; i++) {
+ if (constrain_axis[i] == false) {
+ if (delta_orig[i] < 0.0f) {
+ delta_orig[i] *= -1.0f;
+ delta_curr[i] *= -1.0f;
+ }
+ const int sign = signum_i(scale[i]);
+
+ scale[i] = 1.0f + ((delta_curr[i] - delta_orig[i]) / len_v3(data->orig_matrix_offset[i]));
+
+ if ((transform_flag & ED_GIZMO_CAGE2D_XFORM_FLAG_SCALE_SIGNED) == 0) {
+ if (sign != signum_i(scale[i])) {
+ scale[i] = 0.0f;
+ }
+ }
+ }
+ }
+
+ if (transform_flag & ED_GIZMO_CAGE2D_XFORM_FLAG_SCALE_UNIFORM) {
+ if (constrain_axis[0] == false && constrain_axis[1] == false) {
+ scale[1] = scale[0] = (scale[1] + scale[0]) / 2.0f;
+ }
+ else if (constrain_axis[0] == false) {
+ scale[1] = scale[0];
+ }
+ else if (constrain_axis[1] == false) {
+ scale[0] = scale[1];
+ }
+ else {
+ BLI_assert(0);
+ }
+ }
+
+ /* scale around pivot */
+ float matrix_scale[4][4];
+ unit_m4(matrix_scale);
+
+ mul_v3_fl(matrix_scale[0], scale[0]);
+ mul_v3_fl(matrix_scale[1], scale[1]);
+
+ transform_pivot_set_m4(matrix_scale,
+ (const float[3]){pivot[0] * dims[0], pivot[1] * dims[1], 0.0f});
+ mul_m4_m4m4(gz->matrix_offset, data->orig_matrix_offset, matrix_scale);
+ }
+
+ if (gz_prop->type != NULL) {
+ WM_gizmo_target_property_float_set_array(C, gz, gz_prop, &gz->matrix_offset[0][0]);
+ }
+
+ /* tag the region for redraw */
+ ED_region_tag_redraw(CTX_wm_region(C));
+ WM_event_add_mousemove(C);
+
+ return OPERATOR_RUNNING_MODAL;
}
static void gizmo_cage2d_property_update(wmGizmo *gz, wmGizmoProperty *gz_prop)
{
- if (STREQ(gz_prop->type->idname, "matrix")) {
- if (WM_gizmo_target_property_array_length(gz, gz_prop) == 16) {
- WM_gizmo_target_property_float_get_array(gz, gz_prop, &gz->matrix_offset[0][0]);
- }
- else {
- BLI_assert(0);
- }
- }
- else {
- BLI_assert(0);
- }
+ if (STREQ(gz_prop->type->idname, "matrix")) {
+ if (WM_gizmo_target_property_array_length(gz, gz_prop) == 16) {
+ WM_gizmo_target_property_float_get_array(gz, gz_prop, &gz->matrix_offset[0][0]);
+ }
+ else {
+ BLI_assert(0);
+ }
+ }
+ else {
+ BLI_assert(0);
+ }
}
static void gizmo_cage2d_exit(bContext *C, wmGizmo *gz, const bool cancel)
{
- RectTransformInteraction *data = gz->interaction_data;
+ RectTransformInteraction *data = gz->interaction_data;
- MEM_SAFE_FREE(data->dial);
+ MEM_SAFE_FREE(data->dial);
- if (!cancel)
- return;
+ if (!cancel)
+ return;
- wmGizmoProperty *gz_prop;
+ wmGizmoProperty *gz_prop;
- /* reset properties */
- gz_prop = WM_gizmo_target_property_find(gz, "matrix");
- if (gz_prop->type != NULL) {
- WM_gizmo_target_property_float_set_array(C, gz, gz_prop, &data->orig_matrix_offset[0][0]);
- }
+ /* reset properties */
+ gz_prop = WM_gizmo_target_property_find(gz, "matrix");
+ if (gz_prop->type != NULL) {
+ WM_gizmo_target_property_float_set_array(C, gz, gz_prop, &data->orig_matrix_offset[0][0]);
+ }
- copy_m4_m4(gz->matrix_offset, data->orig_matrix_offset);
+ copy_m4_m4(gz->matrix_offset, data->orig_matrix_offset);
}
-
/* -------------------------------------------------------------------- */
/** \name Cage Gizmo API
*
@@ -1058,53 +1136,66 @@ static void gizmo_cage2d_exit(bContext *C, wmGizmo *gz, const bool cancel)
static void GIZMO_GT_cage_2d(wmGizmoType *gzt)
{
- /* identifiers */
- gzt->idname = "GIZMO_GT_cage_2d";
-
- /* api callbacks */
- gzt->draw = gizmo_cage2d_draw;
- gzt->draw_select = gizmo_cage2d_draw_select;
- gzt->test_select = gizmo_cage2d_test_select;
- gzt->setup = gizmo_cage2d_setup;
- gzt->invoke = gizmo_cage2d_invoke;
- gzt->property_update = gizmo_cage2d_property_update;
- gzt->modal = gizmo_cage2d_modal;
- gzt->exit = gizmo_cage2d_exit;
- gzt->cursor_get = gizmo_cage2d_get_cursor;
-
- gzt->struct_size = sizeof(wmGizmo);
-
- /* rna */
- static EnumPropertyItem rna_enum_draw_style[] = {
- {ED_GIZMO_CAGE2D_STYLE_BOX, "BOX", 0, "Box", ""},
- {ED_GIZMO_CAGE2D_STYLE_CIRCLE, "CIRCLE", 0, "Circle", ""},
- {0, NULL, 0, NULL, NULL},
- };
- static EnumPropertyItem rna_enum_transform[] = {
- {ED_GIZMO_CAGE2D_XFORM_FLAG_TRANSLATE, "TRANSLATE", 0, "Move", ""},
- {ED_GIZMO_CAGE2D_XFORM_FLAG_ROTATE, "ROTATE", 0, "Rotate", ""},
- {ED_GIZMO_CAGE2D_XFORM_FLAG_SCALE, "SCALE", 0, "Scale", ""},
- {ED_GIZMO_CAGE2D_XFORM_FLAG_SCALE_UNIFORM, "SCALE_UNIFORM", 0, "Scale Uniform", ""},
- {0, NULL, 0, NULL, NULL},
- };
- static EnumPropertyItem rna_enum_draw_options[] = {
- {ED_GIZMO_CAGE2D_DRAW_FLAG_XFORM_CENTER_HANDLE, "XFORM_CENTER_HANDLE", 0, "Center Handle", ""},
- {0, NULL, 0, NULL, NULL},
- };
- static float unit_v2[2] = {1.0f, 1.0f};
- RNA_def_float_vector(gzt->srna, "dimensions", 2, unit_v2, 0, FLT_MAX, "Dimensions", "", 0.0f, FLT_MAX);
- RNA_def_enum_flag(gzt->srna, "transform", rna_enum_transform, 0, "Transform Options", "");
- RNA_def_enum(gzt->srna, "draw_style", rna_enum_draw_style, ED_GIZMO_CAGE2D_STYLE_CIRCLE, "Draw Style", "");
- RNA_def_enum_flag(
- gzt->srna, "draw_options", rna_enum_draw_options,
- ED_GIZMO_CAGE2D_DRAW_FLAG_XFORM_CENTER_HANDLE, "Draw Options", "");
-
- WM_gizmotype_target_property_def(gzt, "matrix", PROP_FLOAT, 16);
+ /* identifiers */
+ gzt->idname = "GIZMO_GT_cage_2d";
+
+ /* api callbacks */
+ gzt->draw = gizmo_cage2d_draw;
+ gzt->draw_select = gizmo_cage2d_draw_select;
+ gzt->test_select = gizmo_cage2d_test_select;
+ gzt->setup = gizmo_cage2d_setup;
+ gzt->invoke = gizmo_cage2d_invoke;
+ gzt->property_update = gizmo_cage2d_property_update;
+ gzt->modal = gizmo_cage2d_modal;
+ gzt->exit = gizmo_cage2d_exit;
+ gzt->cursor_get = gizmo_cage2d_get_cursor;
+
+ gzt->struct_size = sizeof(wmGizmo);
+
+ /* rna */
+ static EnumPropertyItem rna_enum_draw_style[] = {
+ {ED_GIZMO_CAGE2D_STYLE_BOX, "BOX", 0, "Box", ""},
+ {ED_GIZMO_CAGE2D_STYLE_CIRCLE, "CIRCLE", 0, "Circle", ""},
+ {0, NULL, 0, NULL, NULL},
+ };
+ static EnumPropertyItem rna_enum_transform[] = {
+ {ED_GIZMO_CAGE2D_XFORM_FLAG_TRANSLATE, "TRANSLATE", 0, "Move", ""},
+ {ED_GIZMO_CAGE2D_XFORM_FLAG_ROTATE, "ROTATE", 0, "Rotate", ""},
+ {ED_GIZMO_CAGE2D_XFORM_FLAG_SCALE, "SCALE", 0, "Scale", ""},
+ {ED_GIZMO_CAGE2D_XFORM_FLAG_SCALE_UNIFORM, "SCALE_UNIFORM", 0, "Scale Uniform", ""},
+ {0, NULL, 0, NULL, NULL},
+ };
+ static EnumPropertyItem rna_enum_draw_options[] = {
+ {ED_GIZMO_CAGE2D_DRAW_FLAG_XFORM_CENTER_HANDLE,
+ "XFORM_CENTER_HANDLE",
+ 0,
+ "Center Handle",
+ ""},
+ {0, NULL, 0, NULL, NULL},
+ };
+ static float unit_v2[2] = {1.0f, 1.0f};
+ RNA_def_float_vector(
+ gzt->srna, "dimensions", 2, unit_v2, 0, FLT_MAX, "Dimensions", "", 0.0f, FLT_MAX);
+ RNA_def_enum_flag(gzt->srna, "transform", rna_enum_transform, 0, "Transform Options", "");
+ RNA_def_enum(gzt->srna,
+ "draw_style",
+ rna_enum_draw_style,
+ ED_GIZMO_CAGE2D_STYLE_CIRCLE,
+ "Draw Style",
+ "");
+ RNA_def_enum_flag(gzt->srna,
+ "draw_options",
+ rna_enum_draw_options,
+ ED_GIZMO_CAGE2D_DRAW_FLAG_XFORM_CENTER_HANDLE,
+ "Draw Options",
+ "");
+
+ WM_gizmotype_target_property_def(gzt, "matrix", PROP_FLOAT, 16);
}
void ED_gizmotypes_cage_2d(void)
{
- WM_gizmotype_append(GIZMO_GT_cage_2d);
+ WM_gizmotype_append(GIZMO_GT_cage_2d);
}
/** \} */
diff --git a/source/blender/editors/gizmo_library/gizmo_types/cage3d_gizmo.c b/source/blender/editors/gizmo_library/gizmo_types/cage3d_gizmo.c
index 9579f7db196..3273012930a 100644
--- a/source/blender/editors/gizmo_library/gizmo_types/cage3d_gizmo.c
+++ b/source/blender/editors/gizmo_library/gizmo_types/cage3d_gizmo.c
@@ -57,79 +57,77 @@
#define GIZMO_RESIZER_SIZE 10.0f
#define GIZMO_MARGIN_OFFSET_SCALE 1.5f
-static void gizmo_calc_matrix_final_no_offset(
- const wmGizmo *gz, float orig_matrix_final_no_offset[4][4], bool use_space)
+static void gizmo_calc_matrix_final_no_offset(const wmGizmo *gz,
+ float orig_matrix_final_no_offset[4][4],
+ bool use_space)
{
- float mat_identity[4][4];
- struct WM_GizmoMatrixParams params = {NULL};
- unit_m4(mat_identity);
- if (use_space == false) {
- params.matrix_basis = mat_identity;
- }
- params.matrix_offset = mat_identity;
- WM_gizmo_calc_matrix_final_params(gz, &params, orig_matrix_final_no_offset);
+ float mat_identity[4][4];
+ struct WM_GizmoMatrixParams params = {NULL};
+ unit_m4(mat_identity);
+ if (use_space == false) {
+ params.matrix_basis = mat_identity;
+ }
+ params.matrix_offset = mat_identity;
+ WM_gizmo_calc_matrix_final_params(gz, &params, orig_matrix_final_no_offset);
}
-static void gizmo_calc_rect_view_scale(
- const wmGizmo *gz, const float dims[3], float scale[3])
+static void gizmo_calc_rect_view_scale(const wmGizmo *gz, const float dims[3], float scale[3])
{
- UNUSED_VARS(dims);
+ UNUSED_VARS(dims);
- /* Unlike cage2d, no need to correct for aspect. */
- float matrix_final_no_offset[4][4];
+ /* Unlike cage2d, no need to correct for aspect. */
+ float matrix_final_no_offset[4][4];
- float x_axis[3], y_axis[3], z_axis[3];
- gizmo_calc_matrix_final_no_offset(gz, matrix_final_no_offset, false);
- mul_v3_mat3_m4v3(x_axis, matrix_final_no_offset, gz->matrix_offset[0]);
- mul_v3_mat3_m4v3(y_axis, matrix_final_no_offset, gz->matrix_offset[1]);
- mul_v3_mat3_m4v3(z_axis, matrix_final_no_offset, gz->matrix_offset[2]);
+ float x_axis[3], y_axis[3], z_axis[3];
+ gizmo_calc_matrix_final_no_offset(gz, matrix_final_no_offset, false);
+ mul_v3_mat3_m4v3(x_axis, matrix_final_no_offset, gz->matrix_offset[0]);
+ mul_v3_mat3_m4v3(y_axis, matrix_final_no_offset, gz->matrix_offset[1]);
+ mul_v3_mat3_m4v3(z_axis, matrix_final_no_offset, gz->matrix_offset[2]);
- scale[0] = 1.0f / len_v3(x_axis);
- scale[1] = 1.0f / len_v3(y_axis);
- scale[2] = 1.0f / len_v3(z_axis);
+ scale[0] = 1.0f / len_v3(x_axis);
+ scale[1] = 1.0f / len_v3(y_axis);
+ scale[2] = 1.0f / len_v3(z_axis);
}
-static void gizmo_calc_rect_view_margin(
- const wmGizmo *gz, const float dims[3], float margin[3])
+static void gizmo_calc_rect_view_margin(const wmGizmo *gz, const float dims[3], float margin[3])
{
- float handle_size;
- if (gz->parent_gzgroup->type->flag & WM_GIZMOGROUPTYPE_3D) {
- handle_size = 0.15f;
- }
- else {
- handle_size = GIZMO_RESIZER_SIZE;
- }
- // XXX, the scale isn't taking offset into account, we need to calculate scale per handle!
- // handle_size *= gz->scale_final;
-
- float scale_xyz[3];
- gizmo_calc_rect_view_scale(gz, dims, scale_xyz);
- margin[0] = ((handle_size * scale_xyz[0]));
- margin[1] = ((handle_size * scale_xyz[1]));
- margin[2] = ((handle_size * scale_xyz[2]));
+ float handle_size;
+ if (gz->parent_gzgroup->type->flag & WM_GIZMOGROUPTYPE_3D) {
+ handle_size = 0.15f;
+ }
+ else {
+ handle_size = GIZMO_RESIZER_SIZE;
+ }
+ // XXX, the scale isn't taking offset into account, we need to calculate scale per handle!
+ // handle_size *= gz->scale_final;
+
+ float scale_xyz[3];
+ gizmo_calc_rect_view_scale(gz, dims, scale_xyz);
+ margin[0] = ((handle_size * scale_xyz[0]));
+ margin[1] = ((handle_size * scale_xyz[1]));
+ margin[2] = ((handle_size * scale_xyz[2]));
}
/* -------------------------------------------------------------------- */
static void gizmo_rect_pivot_from_scale_part(int part, float r_pt[3], bool r_constrain_axis[3])
{
- if (part >= ED_GIZMO_CAGE3D_PART_SCALE_MIN_X_MIN_Y_MIN_Z &&
- part <= ED_GIZMO_CAGE3D_PART_SCALE_MAX_X_MAX_Y_MAX_Z)
- {
- int index = (part - ED_GIZMO_CAGE3D_PART_SCALE_MIN_X_MIN_Y_MIN_Z);
- int range[3];
- range[2] = index % 3;
- index = index / 3;
- range[1] = index % 3;
- index = index / 3;
- range[0] = index % 3;
-
- const float sign[3] = {0.5f, 0.0f, -0.5f};
- for (int i = 0; i < 3; i++) {
- r_pt[i] = sign[range[i]];
- r_constrain_axis[i] = (range[i] == 1);
- }
- }
+ if (part >= ED_GIZMO_CAGE3D_PART_SCALE_MIN_X_MIN_Y_MIN_Z &&
+ part <= ED_GIZMO_CAGE3D_PART_SCALE_MAX_X_MAX_Y_MAX_Z) {
+ int index = (part - ED_GIZMO_CAGE3D_PART_SCALE_MIN_X_MIN_Y_MIN_Z);
+ int range[3];
+ range[2] = index % 3;
+ index = index / 3;
+ range[1] = index % 3;
+ index = index / 3;
+ range[0] = index % 3;
+
+ const float sign[3] = {0.5f, 0.0f, -0.5f};
+ for (int i = 0; i < 3; i++) {
+ r_pt[i] = sign[range[i]];
+ r_constrain_axis[i] = (range[i] == 1);
+ }
+ }
}
/* -------------------------------------------------------------------- */
@@ -138,51 +136,51 @@ static void gizmo_rect_pivot_from_scale_part(int part, float r_pt[3], bool r_con
* Useful for 3D views, see: #ED_GIZMO_CAGE2D_STYLE_BOX
* \{ */
-static void cage3d_draw_box_corners(
- const float r[3], const float margin[3], const float color[3])
+static void cage3d_draw_box_corners(const float r[3], const float margin[3], const float color[3])
{
- uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
- UNUSED_VARS(margin);
+ uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
+ UNUSED_VARS(margin);
- immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
- immUniformColor3fv(color);
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+ immUniformColor3fv(color);
- imm_draw_cube_wire_3d(pos, (float[3]){0}, r);
+ imm_draw_cube_wire_3d(pos, (float[3]){0}, r);
- immUnbindProgram();
+ immUnbindProgram();
}
-static void cage3d_draw_box_interaction(
- const float color[4], const int highlighted,
- const float size[3], const float margin[3])
+static void cage3d_draw_box_interaction(const float color[4],
+ const int highlighted,
+ const float size[3],
+ const float margin[3])
{
- if (highlighted >= ED_GIZMO_CAGE3D_PART_SCALE_MIN_X_MIN_Y_MIN_Z &&
- highlighted <= ED_GIZMO_CAGE3D_PART_SCALE_MAX_X_MAX_Y_MAX_Z)
- {
- int index = (highlighted - ED_GIZMO_CAGE3D_PART_SCALE_MIN_X_MIN_Y_MIN_Z);
- int range[3];
- range[2] = index % 3;
- index = index / 3;
- range[1] = index % 3;
- index = index / 3;
- range[0] = index % 3;
-
- const float sign[3] = {-1.0f, 0.0f, 1.0f};
- float co[3];
-
- for (int i = 0; i < 3; i++) {
- co[i] = size[i] * sign[range[i]];
- }
- const float rad[3] = {margin[0] / 3, margin[1] / 3, margin[2] / 3};
-
- {
- uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
- immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
- immUniformColor3fv(color);
- imm_draw_cube_fill_3d(pos, co, rad);
- immUnbindProgram();
- }
- }
+ if (highlighted >= ED_GIZMO_CAGE3D_PART_SCALE_MIN_X_MIN_Y_MIN_Z &&
+ highlighted <= ED_GIZMO_CAGE3D_PART_SCALE_MAX_X_MAX_Y_MAX_Z) {
+ int index = (highlighted - ED_GIZMO_CAGE3D_PART_SCALE_MIN_X_MIN_Y_MIN_Z);
+ int range[3];
+ range[2] = index % 3;
+ index = index / 3;
+ range[1] = index % 3;
+ index = index / 3;
+ range[0] = index % 3;
+
+ const float sign[3] = {-1.0f, 0.0f, 1.0f};
+ float co[3];
+
+ for (int i = 0; i < 3; i++) {
+ co[i] = size[i] * sign[range[i]];
+ }
+ const float rad[3] = {margin[0] / 3, margin[1] / 3, margin[2] / 3};
+
+ {
+ uint pos = GPU_vertformat_attr_add(
+ immVertexFormat(), "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+ immUniformColor3fv(color);
+ imm_draw_cube_fill_3d(pos, co, rad);
+ immUnbindProgram();
+ }
+ }
}
/** \} */
@@ -193,217 +191,216 @@ static void cage3d_draw_box_interaction(
* Useful for 2D views, see: #ED_GIZMO_CAGE2D_STYLE_CIRCLE
* \{ */
-static void imm_draw_point_aspect_3d(
- uint pos, const float co[3], const float rad[3], bool solid)
+static void imm_draw_point_aspect_3d(uint pos, const float co[3], const float rad[3], bool solid)
{
- if (solid) {
- imm_draw_cube_fill_3d(pos, co, rad);
- }
- else {
- imm_draw_cube_wire_3d(pos, co, rad);
- }
+ if (solid) {
+ imm_draw_cube_fill_3d(pos, co, rad);
+ }
+ else {
+ imm_draw_cube_wire_3d(pos, co, rad);
+ }
}
-static void cage3d_draw_circle_wire(
- const float r[3], const float margin[3], const float color[3],
- const int transform_flag, const int draw_options)
+static void cage3d_draw_circle_wire(const float r[3],
+ const float margin[3],
+ const float color[3],
+ const int transform_flag,
+ const int draw_options)
{
- uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
+ uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
- immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
- immUniformColor3fv(color);
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+ immUniformColor3fv(color);
- imm_draw_cube_wire_3d(pos, (float[3]){0}, r);
+ imm_draw_cube_wire_3d(pos, (float[3]){0}, r);
#if 0
- if (transform_flag & ED_GIZMO_CAGE2D_XFORM_FLAG_TRANSLATE) {
- if (draw_options & ED_GIZMO_CAGE2D_DRAW_FLAG_XFORM_CENTER_HANDLE) {
- const float rad[2] = {margin[0] / 2, margin[1] / 2};
- const float center[2] = {0.0f, 0.0f};
-
- immBegin(GPU_PRIM_LINES, 4);
- immVertex2f(pos, center[0] - rad[0], center[1] - rad[1]);
- immVertex2f(pos, center[0] + rad[0], center[1] + rad[1]);
- immVertex2f(pos, center[0] + rad[0], center[1] - rad[1]);
- immVertex2f(pos, center[0] - rad[0], center[1] + rad[1]);
- immEnd();
- }
- }
+ if (transform_flag & ED_GIZMO_CAGE2D_XFORM_FLAG_TRANSLATE) {
+ if (draw_options & ED_GIZMO_CAGE2D_DRAW_FLAG_XFORM_CENTER_HANDLE) {
+ const float rad[2] = {margin[0] / 2, margin[1] / 2};
+ const float center[2] = {0.0f, 0.0f};
+
+ immBegin(GPU_PRIM_LINES, 4);
+ immVertex2f(pos, center[0] - rad[0], center[1] - rad[1]);
+ immVertex2f(pos, center[0] + rad[0], center[1] + rad[1]);
+ immVertex2f(pos, center[0] + rad[0], center[1] - rad[1]);
+ immVertex2f(pos, center[0] - rad[0], center[1] + rad[1]);
+ immEnd();
+ }
+ }
#else
- UNUSED_VARS(margin, transform_flag, draw_options);
+ UNUSED_VARS(margin, transform_flag, draw_options);
#endif
-
- immUnbindProgram();
+ immUnbindProgram();
}
-static void cage3d_draw_circle_handles(
- const RegionView3D *rv3d, const float matrix_final[4][4],
- const float r[3], const float margin[3], const float color[3],
- bool solid, float scale)
+static void cage3d_draw_circle_handles(const RegionView3D *rv3d,
+ const float matrix_final[4][4],
+ const float r[3],
+ const float margin[3],
+ const float color[3],
+ bool solid,
+ float scale)
{
- uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
- const float rad[3] = {margin[0] / 3, margin[1] / 3, margin[2] / 3};
-
- immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
- immUniformColor3fv(color);
-
- float sign[3] = {-1.0f, 0.0f, 1.0f};
- for (int x = 0; x < 3; x++) {
- for (int y = 0; y < 3; y++) {
- for (int z = 0; z < 3; z++) {
- if (x == 1 && y == 1 && z == 1) {
- continue;
- }
- const float co[3] = {r[0] * sign[x], r[1] * sign[y], r[2] * sign[z]};
- float co_test[3];
- mul_v3_m4v3(co_test, matrix_final, co);
- float rad_scale[3];
- mul_v3_v3fl(rad_scale, rad, ED_view3d_pixel_size(rv3d, co_test) * scale);
- imm_draw_point_aspect_3d(pos, co, rad_scale, solid);
- }
- }
- }
-
- immUnbindProgram();
+ uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
+ const float rad[3] = {margin[0] / 3, margin[1] / 3, margin[2] / 3};
+
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+ immUniformColor3fv(color);
+
+ float sign[3] = {-1.0f, 0.0f, 1.0f};
+ for (int x = 0; x < 3; x++) {
+ for (int y = 0; y < 3; y++) {
+ for (int z = 0; z < 3; z++) {
+ if (x == 1 && y == 1 && z == 1) {
+ continue;
+ }
+ const float co[3] = {r[0] * sign[x], r[1] * sign[y], r[2] * sign[z]};
+ float co_test[3];
+ mul_v3_m4v3(co_test, matrix_final, co);
+ float rad_scale[3];
+ mul_v3_v3fl(rad_scale, rad, ED_view3d_pixel_size(rv3d, co_test) * scale);
+ imm_draw_point_aspect_3d(pos, co, rad_scale, solid);
+ }
+ }
+ }
+
+ immUnbindProgram();
}
/** \} */
static void gizmo_cage3d_draw_intern(
- RegionView3D *rv3d,
- wmGizmo *gz, const bool select, const bool highlight, const int select_id)
+ RegionView3D *rv3d, wmGizmo *gz, const bool select, const bool highlight, const int select_id)
{
- // const bool use_clamp = (gz->parent_gzgroup->type->flag & WM_GIZMOGROUPTYPE_3D) == 0;
- float dims[3];
- RNA_float_get_array(gz->ptr, "dimensions", dims);
- float matrix_final[4][4];
-
- const int transform_flag = RNA_enum_get(gz->ptr, "transform");
- const int draw_style = RNA_enum_get(gz->ptr, "draw_style");
- const int draw_options = RNA_enum_get(gz->ptr, "draw_options");
-
- const float size_real[3] = {dims[0] / 2.0f, dims[1] / 2.0f, dims[2] / 2.0f};
-
- WM_gizmo_calc_matrix_final(gz, matrix_final);
-
- GPU_matrix_push();
- GPU_matrix_mul(matrix_final);
-
- float margin[3];
- gizmo_calc_rect_view_margin(gz, dims, margin);
-
- /* Handy for quick testing draw (if it's outside bounds). */
- if (false) {
- GPU_blend(true);
- uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
- immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
- immUniformColor4fv((const float[4]){1, 1, 1, 0.5f});
- float s = 0.5f;
- immRectf(pos, -s, -s, s, s);
- immUnbindProgram();
- GPU_blend(false);
- }
-
- if (select) {
- /* expand for hotspot */
+ // const bool use_clamp = (gz->parent_gzgroup->type->flag & WM_GIZMOGROUPTYPE_3D) == 0;
+ float dims[3];
+ RNA_float_get_array(gz->ptr, "dimensions", dims);
+ float matrix_final[4][4];
+
+ const int transform_flag = RNA_enum_get(gz->ptr, "transform");
+ const int draw_style = RNA_enum_get(gz->ptr, "draw_style");
+ const int draw_options = RNA_enum_get(gz->ptr, "draw_options");
+
+ const float size_real[3] = {dims[0] / 2.0f, dims[1] / 2.0f, dims[2] / 2.0f};
+
+ WM_gizmo_calc_matrix_final(gz, matrix_final);
+
+ GPU_matrix_push();
+ GPU_matrix_mul(matrix_final);
+
+ float margin[3];
+ gizmo_calc_rect_view_margin(gz, dims, margin);
+
+ /* Handy for quick testing draw (if it's outside bounds). */
+ if (false) {
+ GPU_blend(true);
+ uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+ immUniformColor4fv((const float[4]){1, 1, 1, 0.5f});
+ float s = 0.5f;
+ immRectf(pos, -s, -s, s, s);
+ immUnbindProgram();
+ GPU_blend(false);
+ }
+
+ if (select) {
+ /* expand for hotspot */
#if 0
- const float size[3] = {
- size_real[0] + margin[0] / 2,
- size_real[1] + margin[1] / 2,
- size_real[2] + margin[2] / 2,
- };
+ const float size[3] = {
+ size_real[0] + margin[0] / 2,
+ size_real[1] + margin[1] / 2,
+ size_real[2] + margin[2] / 2,
+ };
#else
- /* just use same value for now. */
- const float size[3] = {UNPACK3(size_real)};
+ /* just use same value for now. */
+ const float size[3] = {UNPACK3(size_real)};
#endif
-
- if (transform_flag & ED_GIZMO_CAGE2D_XFORM_FLAG_SCALE) {
- for (int i = ED_GIZMO_CAGE3D_PART_SCALE_MIN_X_MIN_Y_MIN_Z;
- i <= ED_GIZMO_CAGE3D_PART_SCALE_MAX_X_MAX_Y_MAX_Z;
- i++)
- {
- if (i == ED_GIZMO_CAGE3D_PART_SCALE_MID_X_MID_Y_MID_Z) {
- continue;
- }
- GPU_select_load_id(select_id | i);
- cage3d_draw_box_interaction(
- gz->color, i, size, margin);
- }
- }
- if (transform_flag & ED_GIZMO_CAGE2D_XFORM_FLAG_TRANSLATE) {
- const int transform_part = ED_GIZMO_CAGE3D_PART_TRANSLATE;
- GPU_select_load_id(select_id | transform_part);
- cage3d_draw_box_interaction(
- gz->color, transform_part, size, margin);
- }
- }
- else {
+ if (transform_flag & ED_GIZMO_CAGE2D_XFORM_FLAG_SCALE) {
+ for (int i = ED_GIZMO_CAGE3D_PART_SCALE_MIN_X_MIN_Y_MIN_Z;
+ i <= ED_GIZMO_CAGE3D_PART_SCALE_MAX_X_MAX_Y_MAX_Z;
+ i++) {
+ if (i == ED_GIZMO_CAGE3D_PART_SCALE_MID_X_MID_Y_MID_Z) {
+ continue;
+ }
+ GPU_select_load_id(select_id | i);
+ cage3d_draw_box_interaction(gz->color, i, size, margin);
+ }
+ }
+ if (transform_flag & ED_GIZMO_CAGE2D_XFORM_FLAG_TRANSLATE) {
+ const int transform_part = ED_GIZMO_CAGE3D_PART_TRANSLATE;
+ GPU_select_load_id(select_id | transform_part);
+ cage3d_draw_box_interaction(gz->color, transform_part, size, margin);
+ }
+ }
+ else {
#if 0
- const rctf _r = {
- .xmin = -size_real[0],
- .ymin = -size_real[1],
- .xmax = size_real[0],
- .ymax = size_real[1],
- };
+ const rctf _r = {
+ .xmin = -size_real[0],
+ .ymin = -size_real[1],
+ .xmax = size_real[0],
+ .ymax = size_real[1],
+ };
#endif
- if (draw_style == ED_GIZMO_CAGE2D_STYLE_BOX) {
- /* corner gizmos */
- GPU_line_width(gz->line_width + 3.0f);
- cage3d_draw_box_corners(size_real, margin, (const float[3]){0, 0, 0});
-
- /* corner gizmos */
- float color[4];
- gizmo_color_get(gz, highlight, color);
- GPU_line_width(gz->line_width);
- cage3d_draw_box_corners(size_real, margin, color);
-
- bool show = false;
- if (gz->highlight_part == ED_GIZMO_CAGE3D_PART_TRANSLATE) {
- /* Only show if we're drawing the center handle
- * otherwise the entire rectangle is the hotspot. */
- if (draw_options & ED_GIZMO_CAGE2D_DRAW_FLAG_XFORM_CENTER_HANDLE) {
- show = true;
- }
- }
- else {
- show = true;
- }
-
- if (show) {
- cage3d_draw_box_interaction(
- gz->color, gz->highlight_part, size_real, margin);
- }
- }
- else if (draw_style == ED_GIZMO_CAGE2D_STYLE_CIRCLE) {
- float color[4];
- gizmo_color_get(gz, highlight, color);
-
- GPU_line_smooth(true);
- GPU_polygon_smooth(true);
- GPU_blend(true);
-
- GPU_line_width(gz->line_width + 3.0f);
- cage3d_draw_circle_wire(size_real, margin, (const float[3]){0, 0, 0}, transform_flag, draw_options);
- GPU_line_width(gz->line_width);
- cage3d_draw_circle_wire(size_real, margin, color, transform_flag, draw_options);
-
- /* corner gizmos */
- cage3d_draw_circle_handles(rv3d, matrix_final, size_real, margin, (const float[3]){0, 0, 0}, true, 60);
- cage3d_draw_circle_handles(rv3d, matrix_final, size_real, margin, color, true, 40);
-
- GPU_blend(false);
- GPU_polygon_smooth(false);
- GPU_line_smooth(false);
- }
- else {
- BLI_assert(0);
- }
- }
-
- GPU_line_width(1.0);
- GPU_matrix_pop();
+ if (draw_style == ED_GIZMO_CAGE2D_STYLE_BOX) {
+ /* corner gizmos */
+ GPU_line_width(gz->line_width + 3.0f);
+ cage3d_draw_box_corners(size_real, margin, (const float[3]){0, 0, 0});
+
+ /* corner gizmos */
+ float color[4];
+ gizmo_color_get(gz, highlight, color);
+ GPU_line_width(gz->line_width);
+ cage3d_draw_box_corners(size_real, margin, color);
+
+ bool show = false;
+ if (gz->highlight_part == ED_GIZMO_CAGE3D_PART_TRANSLATE) {
+ /* Only show if we're drawing the center handle
+ * otherwise the entire rectangle is the hotspot. */
+ if (draw_options & ED_GIZMO_CAGE2D_DRAW_FLAG_XFORM_CENTER_HANDLE) {
+ show = true;
+ }
+ }
+ else {
+ show = true;
+ }
+
+ if (show) {
+ cage3d_draw_box_interaction(gz->color, gz->highlight_part, size_real, margin);
+ }
+ }
+ else if (draw_style == ED_GIZMO_CAGE2D_STYLE_CIRCLE) {
+ float color[4];
+ gizmo_color_get(gz, highlight, color);
+
+ GPU_line_smooth(true);
+ GPU_polygon_smooth(true);
+ GPU_blend(true);
+
+ GPU_line_width(gz->line_width + 3.0f);
+ cage3d_draw_circle_wire(
+ size_real, margin, (const float[3]){0, 0, 0}, transform_flag, draw_options);
+ GPU_line_width(gz->line_width);
+ cage3d_draw_circle_wire(size_real, margin, color, transform_flag, draw_options);
+
+ /* corner gizmos */
+ cage3d_draw_circle_handles(
+ rv3d, matrix_final, size_real, margin, (const float[3]){0, 0, 0}, true, 60);
+ cage3d_draw_circle_handles(rv3d, matrix_final, size_real, margin, color, true, 40);
+
+ GPU_blend(false);
+ GPU_polygon_smooth(false);
+ GPU_line_smooth(false);
+ }
+ else {
+ BLI_assert(0);
+ }
+ }
+
+ GPU_line_width(1.0);
+ GPU_matrix_pop();
}
/**
@@ -411,224 +408,227 @@ static void gizmo_cage3d_draw_intern(
*/
static void gizmo_cage3d_draw_select(const bContext *C, wmGizmo *gz, int select_id)
{
- ARegion *ar = CTX_wm_region(C);
- RegionView3D *rv3d = ar->regiondata;
- gizmo_cage3d_draw_intern(rv3d, gz, true, false, select_id);
+ ARegion *ar = CTX_wm_region(C);
+ RegionView3D *rv3d = ar->regiondata;
+ gizmo_cage3d_draw_intern(rv3d, gz, true, false, select_id);
}
static void gizmo_cage3d_draw(const bContext *C, wmGizmo *gz)
{
- ARegion *ar = CTX_wm_region(C);
- RegionView3D *rv3d = ar->regiondata;
- const bool is_highlight = (gz->state & WM_GIZMO_STATE_HIGHLIGHT) != 0;
- gizmo_cage3d_draw_intern(rv3d, gz, false, is_highlight, -1);
+ ARegion *ar = CTX_wm_region(C);
+ RegionView3D *rv3d = ar->regiondata;
+ const bool is_highlight = (gz->state & WM_GIZMO_STATE_HIGHLIGHT) != 0;
+ gizmo_cage3d_draw_intern(rv3d, gz, false, is_highlight, -1);
}
static int gizmo_cage3d_get_cursor(wmGizmo *gz)
{
- if (gz->parent_gzgroup->type->flag & WM_GIZMOGROUPTYPE_3D) {
- return BC_NSEW_SCROLLCURSOR;
- }
+ if (gz->parent_gzgroup->type->flag & WM_GIZMOGROUPTYPE_3D) {
+ return BC_NSEW_SCROLLCURSOR;
+ }
- return CURSOR_STD;
+ return CURSOR_STD;
}
typedef struct RectTransformInteraction {
- float orig_mouse[3];
- float orig_matrix_offset[4][4];
- float orig_matrix_final_no_offset[4][4];
+ float orig_mouse[3];
+ float orig_matrix_offset[4][4];
+ float orig_matrix_final_no_offset[4][4];
} RectTransformInteraction;
static void gizmo_cage3d_setup(wmGizmo *gz)
{
- gz->flag |= /* WM_GIZMO_DRAW_MODAL | */ /* TODO */
- WM_GIZMO_DRAW_NO_SCALE;
+ gz->flag |= /* WM_GIZMO_DRAW_MODAL | */ /* TODO */
+ WM_GIZMO_DRAW_NO_SCALE;
}
-static int gizmo_cage3d_invoke(
- bContext *C, wmGizmo *gz, const wmEvent *event)
+static int gizmo_cage3d_invoke(bContext *C, wmGizmo *gz, const wmEvent *event)
{
- RectTransformInteraction *data = MEM_callocN(sizeof(RectTransformInteraction), "cage_interaction");
+ RectTransformInteraction *data = MEM_callocN(sizeof(RectTransformInteraction),
+ "cage_interaction");
- copy_m4_m4(data->orig_matrix_offset, gz->matrix_offset);
- gizmo_calc_matrix_final_no_offset(gz, data->orig_matrix_final_no_offset, true);
+ copy_m4_m4(data->orig_matrix_offset, gz->matrix_offset);
+ gizmo_calc_matrix_final_no_offset(gz, data->orig_matrix_final_no_offset, true);
- if (gizmo_window_project_3d(
- C, gz, (const float[2]){UNPACK2(event->mval)}, false, data->orig_mouse) == 0)
- {
- zero_v3(data->orig_mouse);
- }
+ if (gizmo_window_project_3d(
+ C, gz, (const float[2]){UNPACK2(event->mval)}, false, data->orig_mouse) == 0) {
+ zero_v3(data->orig_mouse);
+ }
- gz->interaction_data = data;
+ gz->interaction_data = data;
- return OPERATOR_RUNNING_MODAL;
+ return OPERATOR_RUNNING_MODAL;
}
-static int gizmo_cage3d_modal(
- bContext *C, wmGizmo *gz, const wmEvent *event,
- eWM_GizmoFlagTweak UNUSED(tweak_flag))
+static int gizmo_cage3d_modal(bContext *C,
+ wmGizmo *gz,
+ const wmEvent *event,
+ eWM_GizmoFlagTweak UNUSED(tweak_flag))
{
- if (event->type != MOUSEMOVE) {
- return OPERATOR_RUNNING_MODAL;
- }
- /* For transform logic to be manageable we operate in -0.5..0.5 2D space,
- * no matter the size of the rectangle, mouse coords are scaled to unit space.
- * The mouse coords have been projected into the matrix so we don't need to worry about axis alignment.
- *
- * - The cursor offset are multiplied by 'dims'.
- * - Matrix translation is also multiplied by 'dims'.
- */
- RectTransformInteraction *data = gz->interaction_data;
- float point_local[3];
-
- float dims[3];
- RNA_float_get_array(gz->ptr, "dimensions", dims);
-
- {
- float matrix_back[4][4];
- copy_m4_m4(matrix_back, gz->matrix_offset);
- copy_m4_m4(gz->matrix_offset, data->orig_matrix_offset);
-
- bool ok = gizmo_window_project_3d(
- C, gz, (const float[2]){UNPACK2(event->mval)}, false, point_local);
- copy_m4_m4(gz->matrix_offset, matrix_back);
- if (!ok) {
- return OPERATOR_RUNNING_MODAL;
- }
- }
-
- const int transform_flag = RNA_enum_get(gz->ptr, "transform");
- wmGizmoProperty *gz_prop;
-
- gz_prop = WM_gizmo_target_property_find(gz, "matrix");
- if (gz_prop->type != NULL) {
- WM_gizmo_target_property_float_get_array(gz, gz_prop, &gz->matrix_offset[0][0]);
- }
-
- if (gz->highlight_part == ED_GIZMO_CAGE3D_PART_TRANSLATE) {
- /* do this to prevent clamping from changing size */
- copy_m4_m4(gz->matrix_offset, data->orig_matrix_offset);
- gz->matrix_offset[3][0] = data->orig_matrix_offset[3][0] + (point_local[0] - data->orig_mouse[0]);
- gz->matrix_offset[3][1] = data->orig_matrix_offset[3][1] + (point_local[1] - data->orig_mouse[1]);
- gz->matrix_offset[3][2] = data->orig_matrix_offset[3][2] + (point_local[2] - data->orig_mouse[2]);
- }
- else if (gz->highlight_part == ED_GIZMO_CAGE3D_PART_ROTATE) {
- /* TODO (if needed) */
- }
- else {
- /* scale */
- copy_m4_m4(gz->matrix_offset, data->orig_matrix_offset);
- float pivot[3];
- bool constrain_axis[3] = {false};
-
- if (transform_flag & ED_GIZMO_CAGE2D_XFORM_FLAG_TRANSLATE) {
- gizmo_rect_pivot_from_scale_part(gz->highlight_part, pivot, constrain_axis);
- }
- else {
- zero_v3(pivot);
- }
-
- /* Cursor deltas scaled to (-0.5..0.5). */
- float delta_orig[3], delta_curr[3];
-
- for (int i = 0; i < 3; i++) {
- delta_orig[i] = ((data->orig_mouse[i] - data->orig_matrix_offset[3][i]) / dims[i]) - pivot[i];
- delta_curr[i] = ((point_local[i] - data->orig_matrix_offset[3][i]) / dims[i]) - pivot[i];
- }
-
- float scale[3] = {1.0f, 1.0f, 1.0f};
- for (int i = 0; i < 3; i++) {
- if (constrain_axis[i] == false) {
- if (delta_orig[i] < 0.0f) {
- delta_orig[i] *= -1.0f;
- delta_curr[i] *= -1.0f;
- }
- const int sign = signum_i(scale[i]);
-
- scale[i] = 1.0f + ((delta_curr[i] - delta_orig[i]) / len_v3(data->orig_matrix_offset[i]));
-
- if ((transform_flag & ED_GIZMO_CAGE2D_XFORM_FLAG_SCALE_SIGNED) == 0) {
- if (sign != signum_i(scale[i])) {
- scale[i] = 0.0f;
- }
- }
- }
- }
-
- if (transform_flag & ED_GIZMO_CAGE2D_XFORM_FLAG_SCALE_UNIFORM) {
- if (constrain_axis[0] == false && constrain_axis[1] == false) {
- scale[1] = scale[0] = (scale[1] + scale[0]) / 2.0f;
- }
- else if (constrain_axis[0] == false) {
- scale[1] = scale[0];
- }
- else if (constrain_axis[1] == false) {
- scale[0] = scale[1];
- }
- else {
- BLI_assert(0);
- }
- }
-
- /* scale around pivot */
- float matrix_scale[4][4];
- unit_m4(matrix_scale);
-
- mul_v3_fl(matrix_scale[0], scale[0]);
- mul_v3_fl(matrix_scale[1], scale[1]);
- mul_v3_fl(matrix_scale[2], scale[2]);
-
- transform_pivot_set_m4(
- matrix_scale,
- (const float[3]){pivot[0] * dims[0], pivot[1] * dims[1], pivot[2] * dims[2]});
- mul_m4_m4m4(gz->matrix_offset, data->orig_matrix_offset, matrix_scale);
- }
-
- if (gz_prop->type != NULL) {
- WM_gizmo_target_property_float_set_array(C, gz, gz_prop, &gz->matrix_offset[0][0]);
- }
-
- /* tag the region for redraw */
- ED_region_tag_redraw(CTX_wm_region(C));
- WM_event_add_mousemove(C);
-
- return OPERATOR_RUNNING_MODAL;
+ if (event->type != MOUSEMOVE) {
+ return OPERATOR_RUNNING_MODAL;
+ }
+ /* For transform logic to be manageable we operate in -0.5..0.5 2D space,
+ * no matter the size of the rectangle, mouse coords are scaled to unit space.
+ * The mouse coords have been projected into the matrix so we don't need to worry about axis alignment.
+ *
+ * - The cursor offset are multiplied by 'dims'.
+ * - Matrix translation is also multiplied by 'dims'.
+ */
+ RectTransformInteraction *data = gz->interaction_data;
+ float point_local[3];
+
+ float dims[3];
+ RNA_float_get_array(gz->ptr, "dimensions", dims);
+
+ {
+ float matrix_back[4][4];
+ copy_m4_m4(matrix_back, gz->matrix_offset);
+ copy_m4_m4(gz->matrix_offset, data->orig_matrix_offset);
+
+ bool ok = gizmo_window_project_3d(
+ C, gz, (const float[2]){UNPACK2(event->mval)}, false, point_local);
+ copy_m4_m4(gz->matrix_offset, matrix_back);
+ if (!ok) {
+ return OPERATOR_RUNNING_MODAL;
+ }
+ }
+
+ const int transform_flag = RNA_enum_get(gz->ptr, "transform");
+ wmGizmoProperty *gz_prop;
+
+ gz_prop = WM_gizmo_target_property_find(gz, "matrix");
+ if (gz_prop->type != NULL) {
+ WM_gizmo_target_property_float_get_array(gz, gz_prop, &gz->matrix_offset[0][0]);
+ }
+
+ if (gz->highlight_part == ED_GIZMO_CAGE3D_PART_TRANSLATE) {
+ /* do this to prevent clamping from changing size */
+ copy_m4_m4(gz->matrix_offset, data->orig_matrix_offset);
+ gz->matrix_offset[3][0] = data->orig_matrix_offset[3][0] +
+ (point_local[0] - data->orig_mouse[0]);
+ gz->matrix_offset[3][1] = data->orig_matrix_offset[3][1] +
+ (point_local[1] - data->orig_mouse[1]);
+ gz->matrix_offset[3][2] = data->orig_matrix_offset[3][2] +
+ (point_local[2] - data->orig_mouse[2]);
+ }
+ else if (gz->highlight_part == ED_GIZMO_CAGE3D_PART_ROTATE) {
+ /* TODO (if needed) */
+ }
+ else {
+ /* scale */
+ copy_m4_m4(gz->matrix_offset, data->orig_matrix_offset);
+ float pivot[3];
+ bool constrain_axis[3] = {false};
+
+ if (transform_flag & ED_GIZMO_CAGE2D_XFORM_FLAG_TRANSLATE) {
+ gizmo_rect_pivot_from_scale_part(gz->highlight_part, pivot, constrain_axis);
+ }
+ else {
+ zero_v3(pivot);
+ }
+
+ /* Cursor deltas scaled to (-0.5..0.5). */
+ float delta_orig[3], delta_curr[3];
+
+ for (int i = 0; i < 3; i++) {
+ delta_orig[i] = ((data->orig_mouse[i] - data->orig_matrix_offset[3][i]) / dims[i]) -
+ pivot[i];
+ delta_curr[i] = ((point_local[i] - data->orig_matrix_offset[3][i]) / dims[i]) - pivot[i];
+ }
+
+ float scale[3] = {1.0f, 1.0f, 1.0f};
+ for (int i = 0; i < 3; i++) {
+ if (constrain_axis[i] == false) {
+ if (delta_orig[i] < 0.0f) {
+ delta_orig[i] *= -1.0f;
+ delta_curr[i] *= -1.0f;
+ }
+ const int sign = signum_i(scale[i]);
+
+ scale[i] = 1.0f + ((delta_curr[i] - delta_orig[i]) / len_v3(data->orig_matrix_offset[i]));
+
+ if ((transform_flag & ED_GIZMO_CAGE2D_XFORM_FLAG_SCALE_SIGNED) == 0) {
+ if (sign != signum_i(scale[i])) {
+ scale[i] = 0.0f;
+ }
+ }
+ }
+ }
+
+ if (transform_flag & ED_GIZMO_CAGE2D_XFORM_FLAG_SCALE_UNIFORM) {
+ if (constrain_axis[0] == false && constrain_axis[1] == false) {
+ scale[1] = scale[0] = (scale[1] + scale[0]) / 2.0f;
+ }
+ else if (constrain_axis[0] == false) {
+ scale[1] = scale[0];
+ }
+ else if (constrain_axis[1] == false) {
+ scale[0] = scale[1];
+ }
+ else {
+ BLI_assert(0);
+ }
+ }
+
+ /* scale around pivot */
+ float matrix_scale[4][4];
+ unit_m4(matrix_scale);
+
+ mul_v3_fl(matrix_scale[0], scale[0]);
+ mul_v3_fl(matrix_scale[1], scale[1]);
+ mul_v3_fl(matrix_scale[2], scale[2]);
+
+ transform_pivot_set_m4(
+ matrix_scale,
+ (const float[3]){pivot[0] * dims[0], pivot[1] * dims[1], pivot[2] * dims[2]});
+ mul_m4_m4m4(gz->matrix_offset, data->orig_matrix_offset, matrix_scale);
+ }
+
+ if (gz_prop->type != NULL) {
+ WM_gizmo_target_property_float_set_array(C, gz, gz_prop, &gz->matrix_offset[0][0]);
+ }
+
+ /* tag the region for redraw */
+ ED_region_tag_redraw(CTX_wm_region(C));
+ WM_event_add_mousemove(C);
+
+ return OPERATOR_RUNNING_MODAL;
}
static void gizmo_cage3d_property_update(wmGizmo *gz, wmGizmoProperty *gz_prop)
{
- if (STREQ(gz_prop->type->idname, "matrix")) {
- if (WM_gizmo_target_property_array_length(gz, gz_prop) == 16) {
- WM_gizmo_target_property_float_get_array(gz, gz_prop, &gz->matrix_offset[0][0]);
- }
- else {
- BLI_assert(0);
- }
- }
- else {
- BLI_assert(0);
- }
+ if (STREQ(gz_prop->type->idname, "matrix")) {
+ if (WM_gizmo_target_property_array_length(gz, gz_prop) == 16) {
+ WM_gizmo_target_property_float_get_array(gz, gz_prop, &gz->matrix_offset[0][0]);
+ }
+ else {
+ BLI_assert(0);
+ }
+ }
+ else {
+ BLI_assert(0);
+ }
}
static void gizmo_cage3d_exit(bContext *C, wmGizmo *gz, const bool cancel)
{
- RectTransformInteraction *data = gz->interaction_data;
+ RectTransformInteraction *data = gz->interaction_data;
- if (!cancel)
- return;
+ if (!cancel)
+ return;
- wmGizmoProperty *gz_prop;
+ wmGizmoProperty *gz_prop;
- /* reset properties */
- gz_prop = WM_gizmo_target_property_find(gz, "matrix");
- if (gz_prop->type != NULL) {
- WM_gizmo_target_property_float_set_array(C, gz, gz_prop, &data->orig_matrix_offset[0][0]);
- }
+ /* reset properties */
+ gz_prop = WM_gizmo_target_property_find(gz, "matrix");
+ if (gz_prop->type != NULL) {
+ WM_gizmo_target_property_float_set_array(C, gz, gz_prop, &data->orig_matrix_offset[0][0]);
+ }
- copy_m4_m4(gz->matrix_offset, data->orig_matrix_offset);
+ copy_m4_m4(gz->matrix_offset, data->orig_matrix_offset);
}
-
/* -------------------------------------------------------------------- */
/** \name Cage Gizmo API
*
@@ -636,51 +636,64 @@ static void gizmo_cage3d_exit(bContext *C, wmGizmo *gz, const bool cancel)
static void GIZMO_GT_cage_3d(wmGizmoType *gzt)
{
- /* identifiers */
- gzt->idname = "GIZMO_GT_cage_3d";
-
- /* api callbacks */
- gzt->draw = gizmo_cage3d_draw;
- gzt->draw_select = gizmo_cage3d_draw_select;
- gzt->setup = gizmo_cage3d_setup;
- gzt->invoke = gizmo_cage3d_invoke;
- gzt->property_update = gizmo_cage3d_property_update;
- gzt->modal = gizmo_cage3d_modal;
- gzt->exit = gizmo_cage3d_exit;
- gzt->cursor_get = gizmo_cage3d_get_cursor;
-
- gzt->struct_size = sizeof(wmGizmo);
-
- /* rna */
- static EnumPropertyItem rna_enum_draw_style[] = {
- {ED_GIZMO_CAGE2D_STYLE_BOX, "BOX", 0, "Box", ""},
- {ED_GIZMO_CAGE2D_STYLE_CIRCLE, "CIRCLE", 0, "Circle", ""},
- {0, NULL, 0, NULL, NULL},
- };
- static EnumPropertyItem rna_enum_transform[] = {
- {ED_GIZMO_CAGE2D_XFORM_FLAG_TRANSLATE, "TRANSLATE", 0, "Move", ""},
- {ED_GIZMO_CAGE2D_XFORM_FLAG_SCALE, "SCALE", 0, "Scale", ""},
- {ED_GIZMO_CAGE2D_XFORM_FLAG_SCALE_UNIFORM, "SCALE_UNIFORM", 0, "Scale Uniform", ""},
- {0, NULL, 0, NULL, NULL},
- };
- static EnumPropertyItem rna_enum_draw_options[] = {
- {ED_GIZMO_CAGE2D_DRAW_FLAG_XFORM_CENTER_HANDLE, "XFORM_CENTER_HANDLE", 0, "Center Handle", ""},
- {0, NULL, 0, NULL, NULL},
- };
- static float unit_v3[3] = {1.0f, 1.0f, 1.0f};
- RNA_def_float_vector(gzt->srna, "dimensions", 3, unit_v3, 0, FLT_MAX, "Dimensions", "", 0.0f, FLT_MAX);
- RNA_def_enum_flag(gzt->srna, "transform", rna_enum_transform, 0, "Transform Options", "");
- RNA_def_enum(gzt->srna, "draw_style", rna_enum_draw_style, ED_GIZMO_CAGE2D_STYLE_CIRCLE, "Draw Style", "");
- RNA_def_enum_flag(
- gzt->srna, "draw_options", rna_enum_draw_options,
- ED_GIZMO_CAGE2D_DRAW_FLAG_XFORM_CENTER_HANDLE, "Draw Options", "");
-
- WM_gizmotype_target_property_def(gzt, "matrix", PROP_FLOAT, 16);
+ /* identifiers */
+ gzt->idname = "GIZMO_GT_cage_3d";
+
+ /* api callbacks */
+ gzt->draw = gizmo_cage3d_draw;
+ gzt->draw_select = gizmo_cage3d_draw_select;
+ gzt->setup = gizmo_cage3d_setup;
+ gzt->invoke = gizmo_cage3d_invoke;
+ gzt->property_update = gizmo_cage3d_property_update;
+ gzt->modal = gizmo_cage3d_modal;
+ gzt->exit = gizmo_cage3d_exit;
+ gzt->cursor_get = gizmo_cage3d_get_cursor;
+
+ gzt->struct_size = sizeof(wmGizmo);
+
+ /* rna */
+ static EnumPropertyItem rna_enum_draw_style[] = {
+ {ED_GIZMO_CAGE2D_STYLE_BOX, "BOX", 0, "Box", ""},
+ {ED_GIZMO_CAGE2D_STYLE_CIRCLE, "CIRCLE", 0, "Circle", ""},
+ {0, NULL, 0, NULL, NULL},
+ };
+ static EnumPropertyItem rna_enum_transform[] = {
+ {ED_GIZMO_CAGE2D_XFORM_FLAG_TRANSLATE, "TRANSLATE", 0, "Move", ""},
+ {ED_GIZMO_CAGE2D_XFORM_FLAG_SCALE, "SCALE", 0, "Scale", ""},
+ {ED_GIZMO_CAGE2D_XFORM_FLAG_SCALE_UNIFORM, "SCALE_UNIFORM", 0, "Scale Uniform", ""},
+ {0, NULL, 0, NULL, NULL},
+ };
+ static EnumPropertyItem rna_enum_draw_options[] = {
+ {ED_GIZMO_CAGE2D_DRAW_FLAG_XFORM_CENTER_HANDLE,
+ "XFORM_CENTER_HANDLE",
+ 0,
+ "Center Handle",
+ ""},
+ {0, NULL, 0, NULL, NULL},
+ };
+ static float unit_v3[3] = {1.0f, 1.0f, 1.0f};
+ RNA_def_float_vector(
+ gzt->srna, "dimensions", 3, unit_v3, 0, FLT_MAX, "Dimensions", "", 0.0f, FLT_MAX);
+ RNA_def_enum_flag(gzt->srna, "transform", rna_enum_transform, 0, "Transform Options", "");
+ RNA_def_enum(gzt->srna,
+ "draw_style",
+ rna_enum_draw_style,
+ ED_GIZMO_CAGE2D_STYLE_CIRCLE,
+ "Draw Style",
+ "");
+ RNA_def_enum_flag(gzt->srna,
+ "draw_options",
+ rna_enum_draw_options,
+ ED_GIZMO_CAGE2D_DRAW_FLAG_XFORM_CENTER_HANDLE,
+ "Draw Options",
+ "");
+
+ WM_gizmotype_target_property_def(gzt, "matrix", PROP_FLOAT, 16);
}
void ED_gizmotypes_cage_3d(void)
{
- WM_gizmotype_append(GIZMO_GT_cage_3d);
+ WM_gizmotype_append(GIZMO_GT_cage_3d);
}
/** \} */
diff --git a/source/blender/editors/gizmo_library/gizmo_types/dial3d_gizmo.c b/source/blender/editors/gizmo_library/gizmo_types/dial3d_gizmo.c
index 9072ced0bd1..31e30a0dd1a 100644
--- a/source/blender/editors/gizmo_library/gizmo_types/dial3d_gizmo.c
+++ b/source/blender/editors/gizmo_library/gizmo_types/dial3d_gizmo.c
@@ -38,7 +38,6 @@
#include "BKE_context.h"
-
#include "GPU_immediate.h"
#include "GPU_immediate_util.h"
#include "GPU_matrix.h"
@@ -64,30 +63,30 @@
// #define USE_GIZMO_CUSTOM_DIAL
typedef struct DialInteraction {
- struct {
- float mval[2];
- /* Only for when using properties. */
- float prop_angle;
- } init;
- struct {
- /* Cache the last angle to detect rotations bigger than -/+ PI. */
- eWM_GizmoFlagTweak tweak_flag;
- float angle;
- } prev;
-
- /* Number of full rotations. */
- int rotations;
- bool has_drag;
- float angle_increment;
-
- /* Final output values, used for drawing. */
- struct {
- float angle_ofs;
- float angle_delta;
- } output;
+ struct {
+ float mval[2];
+ /* Only for when using properties. */
+ float prop_angle;
+ } init;
+ struct {
+ /* Cache the last angle to detect rotations bigger than -/+ PI. */
+ eWM_GizmoFlagTweak tweak_flag;
+ float angle;
+ } prev;
+
+ /* Number of full rotations. */
+ int rotations;
+ bool has_drag;
+ float angle_increment;
+
+ /* Final output values, used for drawing. */
+ struct {
+ float angle_ofs;
+ float angle_delta;
+ } output;
} DialInteraction;
-#define DIAL_WIDTH 1.0f
+#define DIAL_WIDTH 1.0f
#define DIAL_RESOLUTION 48
/* Could make option, negative to clip more (don't show when view aligned). */
@@ -95,439 +94,455 @@ typedef struct DialInteraction {
/* -------------------------------------------------------------------- */
-static void dial_geom_draw(
- const float color[4], const float line_width,
- const bool select,
- const float axis_modal_mat[4][4], const float clip_plane[4],
- const float arc_partial_angle, const float arc_inner_factor,
- const int draw_options)
+static void dial_geom_draw(const float color[4],
+ const float line_width,
+ const bool select,
+ const float axis_modal_mat[4][4],
+ const float clip_plane[4],
+ const float arc_partial_angle,
+ const float arc_inner_factor,
+ const int draw_options)
{
#ifdef USE_GIZMO_CUSTOM_DIAL
- UNUSED_VARS(gz, axis_modal_mat, clip_plane);
- wm_gizmo_geometryinfo_draw(&wm_gizmo_geom_data_dial, select, color);
+ UNUSED_VARS(gz, axis_modal_mat, clip_plane);
+ wm_gizmo_geometryinfo_draw(&wm_gizmo_geom_data_dial, select, color);
#else
- const bool filled = (
- (draw_options &
- (select ?
- (ED_GIZMO_DIAL_DRAW_FLAG_FILL | ED_GIZMO_DIAL_DRAW_FLAG_FILL_SELECT) :
- ED_GIZMO_DIAL_DRAW_FLAG_FILL)));
-
- GPU_line_width(line_width);
-
- GPUVertFormat *format = immVertexFormat();
- uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
-
- if (clip_plane) {
- immBindBuiltinProgram(GPU_SHADER_3D_CLIPPED_UNIFORM_COLOR);
- immUniform4fv("ClipPlane", clip_plane);
- immUniformMatrix4fv("ModelMatrix", axis_modal_mat);
- glEnable(GL_CLIP_DISTANCE0);
- }
- else {
- immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
- }
-
- immUniformColor4fv(color);
-
- if (filled) {
- imm_draw_circle_fill_2d(pos, 0, 0, 1.0, DIAL_RESOLUTION);
- }
- else {
- if (arc_partial_angle == 0.0f) {
- imm_draw_circle_wire_2d(pos, 0, 0, 1.0, DIAL_RESOLUTION);
- if (arc_inner_factor != 0.0f) {
- imm_draw_circle_wire_2d(pos, 0, 0, arc_inner_factor, DIAL_RESOLUTION);
- }
- }
- else {
- float arc_partial_deg = RAD2DEGF((M_PI * 2) - arc_partial_angle);
- imm_draw_circle_partial_wire_2d(
- pos, 0, 0, 1.0, DIAL_RESOLUTION,
- -arc_partial_deg / 2, arc_partial_deg);
-#if 0
- if (arc_inner_factor != 0.0f) {
- BLI_assert(0);
- }
-#endif
- }
- }
-
- immUnbindProgram();
-
- if (clip_plane) {
- glDisable(GL_CLIP_DISTANCE0);
- }
-
- UNUSED_VARS(select);
+ const bool filled = ((draw_options & (select ? (ED_GIZMO_DIAL_DRAW_FLAG_FILL |
+ ED_GIZMO_DIAL_DRAW_FLAG_FILL_SELECT) :
+ ED_GIZMO_DIAL_DRAW_FLAG_FILL)));
+
+ GPU_line_width(line_width);
+
+ GPUVertFormat *format = immVertexFormat();
+ uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+
+ if (clip_plane) {
+ immBindBuiltinProgram(GPU_SHADER_3D_CLIPPED_UNIFORM_COLOR);
+ immUniform4fv("ClipPlane", clip_plane);
+ immUniformMatrix4fv("ModelMatrix", axis_modal_mat);
+ glEnable(GL_CLIP_DISTANCE0);
+ }
+ else {
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+ }
+
+ immUniformColor4fv(color);
+
+ if (filled) {
+ imm_draw_circle_fill_2d(pos, 0, 0, 1.0, DIAL_RESOLUTION);
+ }
+ else {
+ if (arc_partial_angle == 0.0f) {
+ imm_draw_circle_wire_2d(pos, 0, 0, 1.0, DIAL_RESOLUTION);
+ if (arc_inner_factor != 0.0f) {
+ imm_draw_circle_wire_2d(pos, 0, 0, arc_inner_factor, DIAL_RESOLUTION);
+ }
+ }
+ else {
+ float arc_partial_deg = RAD2DEGF((M_PI * 2) - arc_partial_angle);
+ imm_draw_circle_partial_wire_2d(
+ pos, 0, 0, 1.0, DIAL_RESOLUTION, -arc_partial_deg / 2, arc_partial_deg);
+# if 0
+ if (arc_inner_factor != 0.0f) {
+ BLI_assert(0);
+ }
+# endif
+ }
+ }
+
+ immUnbindProgram();
+
+ if (clip_plane) {
+ glDisable(GL_CLIP_DISTANCE0);
+ }
+
+ UNUSED_VARS(select);
#endif
}
/**
* Draws a line from (0, 0, 0) to \a co_outer, at \a angle.
*/
-static void dial_ghostarc_draw_helpline(
- const float angle, const float co_outer[3], const float color[4])
+static void dial_ghostarc_draw_helpline(const float angle,
+ const float co_outer[3],
+ const float color[4])
{
- GPU_matrix_push();
- GPU_matrix_rotate_3f(RAD2DEGF(angle), 0.0f, 0.0f, -1.0f);
+ GPU_matrix_push();
+ GPU_matrix_rotate_3f(RAD2DEGF(angle), 0.0f, 0.0f, -1.0f);
- uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
+ uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
- immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
- immUniformColor4fv(color);
+ immUniformColor4fv(color);
- immBegin(GPU_PRIM_LINE_STRIP, 2);
- immVertex3f(pos, 0.0f, 0, 0.0f);
- immVertex3fv(pos, co_outer);
- immEnd();
+ immBegin(GPU_PRIM_LINE_STRIP, 2);
+ immVertex3f(pos, 0.0f, 0, 0.0f);
+ immVertex3fv(pos, co_outer);
+ immEnd();
- immUnbindProgram();
+ immUnbindProgram();
- GPU_matrix_pop();
+ GPU_matrix_pop();
}
/**
* Draws segments to indicate the position of each increment.
*/
-static void dial_ghostarc_draw_incremental_angle(
- const float incremental_angle, const float offset)
+static void dial_ghostarc_draw_incremental_angle(const float incremental_angle, const float offset)
{
- const int tot_incr = (2 * M_PI) / incremental_angle;
- GPU_line_width(1.0f);
+ const int tot_incr = (2 * M_PI) / incremental_angle;
+ GPU_line_width(1.0f);
- uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
- immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
- immUniformColor3f(1.0f, 1.0f, 1.0f);
- immBegin(GPU_PRIM_LINES, tot_incr * 2);
+ uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+ immUniformColor3f(1.0f, 1.0f, 1.0f);
+ immBegin(GPU_PRIM_LINES, tot_incr * 2);
- float v[3] = { 0 };
- for (int i = 0; i < tot_incr; i++) {
- v[0] = sinf(offset + incremental_angle * i);
- v[1] = cosf(offset + incremental_angle * i);
+ float v[3] = {0};
+ for (int i = 0; i < tot_incr; i++) {
+ v[0] = sinf(offset + incremental_angle * i);
+ v[1] = cosf(offset + incremental_angle * i);
- mul_v2_fl(v, DIAL_WIDTH * 1.1f);
- immVertex3fv(pos, v);
+ mul_v2_fl(v, DIAL_WIDTH * 1.1f);
+ immVertex3fv(pos, v);
- mul_v2_fl(v, 1.1f);
- immVertex3fv(pos, v);
- }
+ mul_v2_fl(v, 1.1f);
+ immVertex3fv(pos, v);
+ }
- immEnd();
- immUnbindProgram();
+ immEnd();
+ immUnbindProgram();
}
-static void dial_ghostarc_draw(
- const float angle_ofs, const float angle_delta,
- const float arc_inner_factor, const float color[4])
+static void dial_ghostarc_draw(const float angle_ofs,
+ const float angle_delta,
+ const float arc_inner_factor,
+ const float color[4])
{
- const float width_inner = DIAL_WIDTH;
- GPUVertFormat *format = immVertexFormat();
- uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
- immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
-
- if (arc_inner_factor != 0.0) {
- float color_dark[4] = {0};
- color_dark[3] = color[3] / 2;
- immUniformColor4fv(color_dark);
- imm_draw_disk_partial_fill_2d(
- pos, 0, 0, arc_inner_factor, width_inner, DIAL_RESOLUTION, RAD2DEGF(angle_ofs), RAD2DEGF(M_PI * 2));
- }
-
- immUniformColor4fv(color);
- imm_draw_disk_partial_fill_2d(
- pos, 0, 0, arc_inner_factor, width_inner, DIAL_RESOLUTION, RAD2DEGF(angle_ofs), RAD2DEGF(angle_delta));
- immUnbindProgram();
+ const float width_inner = DIAL_WIDTH;
+ GPUVertFormat *format = immVertexFormat();
+ uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+
+ if (arc_inner_factor != 0.0) {
+ float color_dark[4] = {0};
+ color_dark[3] = color[3] / 2;
+ immUniformColor4fv(color_dark);
+ imm_draw_disk_partial_fill_2d(pos,
+ 0,
+ 0,
+ arc_inner_factor,
+ width_inner,
+ DIAL_RESOLUTION,
+ RAD2DEGF(angle_ofs),
+ RAD2DEGF(M_PI * 2));
+ }
+
+ immUniformColor4fv(color);
+ imm_draw_disk_partial_fill_2d(pos,
+ 0,
+ 0,
+ arc_inner_factor,
+ width_inner,
+ DIAL_RESOLUTION,
+ RAD2DEGF(angle_ofs),
+ RAD2DEGF(angle_delta));
+ immUnbindProgram();
}
-static void dial_ghostarc_get_angles(
- const wmGizmo *gz,
- const wmEvent *event,
- const ARegion *ar,
- float mat[4][4], const float co_outer[3],
- float *r_start, float *r_delta)
+static void dial_ghostarc_get_angles(const wmGizmo *gz,
+ const wmEvent *event,
+ const ARegion *ar,
+ float mat[4][4],
+ const float co_outer[3],
+ float *r_start,
+ float *r_delta)
{
- DialInteraction *inter = gz->interaction_data;
- const RegionView3D *rv3d = ar->regiondata;
- const float mval[2] = {event->x - ar->winrct.xmin, event->y - ar->winrct.ymin};
-
- /* We might need to invert the direction of the angles. */
- float view_vec[3], axis_vec[3];
- ED_view3d_global_to_vector(rv3d, gz->matrix_basis[3], view_vec);
- normalize_v3_v3(axis_vec, gz->matrix_basis[2]);
-
- float proj_outer_rel[3];
- mul_v3_project_m4_v3(proj_outer_rel, mat, co_outer);
- sub_v3_v3(proj_outer_rel, gz->matrix_basis[3]);
-
- float proj_mval_new_rel[3];
- float proj_mval_init_rel[3];
- float dial_plane[4];
-
- plane_from_point_normal_v3(dial_plane, gz->matrix_basis[3], axis_vec);
-
- if (!ED_view3d_win_to_3d_on_plane(ar, dial_plane, inter->init.mval, false, proj_mval_init_rel)) {
- goto fail;
- }
- sub_v3_v3(proj_mval_init_rel, gz->matrix_basis[3]);
-
- if (!ED_view3d_win_to_3d_on_plane(ar, dial_plane, mval, false, proj_mval_new_rel)) {
- goto fail;
- }
- sub_v3_v3(proj_mval_new_rel, gz->matrix_basis[3]);
-
- const int draw_options = RNA_enum_get(gz->ptr, "draw_options");
-
- /* Start direction from mouse or set by user. */
- const float *proj_init_rel =
- (draw_options & ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_START_Y) ?
- gz->matrix_basis[1] : proj_mval_init_rel;
-
- /* Return angles. */
- const float start = angle_wrap_rad(angle_signed_on_axis_v3v3_v3(proj_outer_rel, proj_init_rel, axis_vec));
- const float delta = angle_wrap_rad(angle_signed_on_axis_v3v3_v3(proj_mval_init_rel, proj_mval_new_rel, axis_vec));
-
- /* Change of sign, we passed the 180 degree threshold. This means we need to add a turn
- * to distinguish between transition from 0 to -1 and -PI to +PI, use comparison with PI/2.
- * Logic taken from #BLI_dial_angle */
- if ((delta * inter->prev.angle < 0.0f) &&
- (fabsf(inter->prev.angle) > (float)M_PI_2))
- {
- if (inter->prev.angle < 0.0f) {
- inter->rotations--;
- }
- else {
- inter->rotations++;
- }
- }
- inter->prev.angle = delta;
-
- const bool wrap_angle = RNA_boolean_get(gz->ptr, "wrap_angle");
- const double delta_final = (double)delta + ((2 * M_PI) * (double)inter->rotations);
- *r_start = start;
- *r_delta = (float)(wrap_angle ? fmod(delta_final, 2 * M_PI) : delta_final);
- return;
-
- /* If we can't project (unlikely). */
+ DialInteraction *inter = gz->interaction_data;
+ const RegionView3D *rv3d = ar->regiondata;
+ const float mval[2] = {event->x - ar->winrct.xmin, event->y - ar->winrct.ymin};
+
+ /* We might need to invert the direction of the angles. */
+ float view_vec[3], axis_vec[3];
+ ED_view3d_global_to_vector(rv3d, gz->matrix_basis[3], view_vec);
+ normalize_v3_v3(axis_vec, gz->matrix_basis[2]);
+
+ float proj_outer_rel[3];
+ mul_v3_project_m4_v3(proj_outer_rel, mat, co_outer);
+ sub_v3_v3(proj_outer_rel, gz->matrix_basis[3]);
+
+ float proj_mval_new_rel[3];
+ float proj_mval_init_rel[3];
+ float dial_plane[4];
+
+ plane_from_point_normal_v3(dial_plane, gz->matrix_basis[3], axis_vec);
+
+ if (!ED_view3d_win_to_3d_on_plane(ar, dial_plane, inter->init.mval, false, proj_mval_init_rel)) {
+ goto fail;
+ }
+ sub_v3_v3(proj_mval_init_rel, gz->matrix_basis[3]);
+
+ if (!ED_view3d_win_to_3d_on_plane(ar, dial_plane, mval, false, proj_mval_new_rel)) {
+ goto fail;
+ }
+ sub_v3_v3(proj_mval_new_rel, gz->matrix_basis[3]);
+
+ const int draw_options = RNA_enum_get(gz->ptr, "draw_options");
+
+ /* Start direction from mouse or set by user. */
+ const float *proj_init_rel = (draw_options & ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_START_Y) ?
+ gz->matrix_basis[1] :
+ proj_mval_init_rel;
+
+ /* Return angles. */
+ const float start = angle_wrap_rad(
+ angle_signed_on_axis_v3v3_v3(proj_outer_rel, proj_init_rel, axis_vec));
+ const float delta = angle_wrap_rad(
+ angle_signed_on_axis_v3v3_v3(proj_mval_init_rel, proj_mval_new_rel, axis_vec));
+
+ /* Change of sign, we passed the 180 degree threshold. This means we need to add a turn
+ * to distinguish between transition from 0 to -1 and -PI to +PI, use comparison with PI/2.
+ * Logic taken from #BLI_dial_angle */
+ if ((delta * inter->prev.angle < 0.0f) && (fabsf(inter->prev.angle) > (float)M_PI_2)) {
+ if (inter->prev.angle < 0.0f) {
+ inter->rotations--;
+ }
+ else {
+ inter->rotations++;
+ }
+ }
+ inter->prev.angle = delta;
+
+ const bool wrap_angle = RNA_boolean_get(gz->ptr, "wrap_angle");
+ const double delta_final = (double)delta + ((2 * M_PI) * (double)inter->rotations);
+ *r_start = start;
+ *r_delta = (float)(wrap_angle ? fmod(delta_final, 2 * M_PI) : delta_final);
+ return;
+
+ /* If we can't project (unlikely). */
fail:
- *r_start = 0.0;
- *r_delta = 0.0;
+ *r_start = 0.0;
+ *r_delta = 0.0;
}
-static void dial_ghostarc_draw_with_helplines(
- const float angle_ofs, const float angle_delta,
- const float arc_inner_factor, const float color_helpline[4], const int draw_options)
+static void dial_ghostarc_draw_with_helplines(const float angle_ofs,
+ const float angle_delta,
+ const float arc_inner_factor,
+ const float color_helpline[4],
+ const int draw_options)
{
- /* Coordinate at which the arc drawing will be started. */
- const float co_outer[4] = {0.0f, DIAL_WIDTH, 0.0f};
- dial_ghostarc_draw(angle_ofs, angle_delta, arc_inner_factor, (const float[4]){0.8f, 0.8f, 0.8f, 0.4f});
- GPU_line_width(1.0f);
- dial_ghostarc_draw_helpline(angle_ofs, co_outer, color_helpline);
- if (draw_options & ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_VALUE) {
- GPU_line_width(3.0f);
- }
- dial_ghostarc_draw_helpline(angle_ofs + angle_delta, co_outer, color_helpline);
+ /* Coordinate at which the arc drawing will be started. */
+ const float co_outer[4] = {0.0f, DIAL_WIDTH, 0.0f};
+ dial_ghostarc_draw(
+ angle_ofs, angle_delta, arc_inner_factor, (const float[4]){0.8f, 0.8f, 0.8f, 0.4f});
+ GPU_line_width(1.0f);
+ dial_ghostarc_draw_helpline(angle_ofs, co_outer, color_helpline);
+ if (draw_options & ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_VALUE) {
+ GPU_line_width(3.0f);
+ }
+ dial_ghostarc_draw_helpline(angle_ofs + angle_delta, co_outer, color_helpline);
}
static void dial_draw_intern(
- const bContext *C, wmGizmo *gz,
- const bool select, const bool highlight, float clip_plane[4])
+ const bContext *C, wmGizmo *gz, const bool select, const bool highlight, float clip_plane[4])
{
- float matrix_final[4][4];
- float color[4];
-
- (void)C;
- BLI_assert(CTX_wm_area(C)->spacetype == SPACE_VIEW3D);
-
- gizmo_color_get(gz, highlight, color);
-
- WM_gizmo_calc_matrix_final(gz, matrix_final);
-
- const float arc_partial_angle = RNA_float_get(gz->ptr, "arc_partial_angle");
- const float arc_inner_factor = RNA_float_get(gz->ptr, "arc_inner_factor");
- int draw_options = RNA_enum_get(gz->ptr, "draw_options");
- float angle_ofs = 0.0f;
- float angle_delta = 0.0f;
- float angle_increment = 0.0f;
-
- if (select) {
- draw_options &= ~ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_VALUE;
- }
-
- if (draw_options & ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_VALUE &&
- (gz->flag & WM_GIZMO_DRAW_VALUE))
- {
- DialInteraction *inter = gz->interaction_data;
- if (inter) {
- angle_ofs = inter->output.angle_ofs;
- angle_delta = inter->output.angle_delta;
- angle_increment = inter->angle_increment;
- }
- else {
- wmGizmoProperty *gz_prop = WM_gizmo_target_property_find(gz, "offset");
- if (WM_gizmo_target_property_is_valid(gz_prop)) {
- angle_delta = WM_gizmo_target_property_float_get(gz, gz_prop);
- }
- }
- }
-
- ED_gizmotypes_dial_3d_draw_util(
- gz->matrix_basis, matrix_final, gz->line_width, color, select,
- &(struct Dial3dParams){
- .draw_options = draw_options,
- .angle_ofs = angle_ofs,
- .angle_delta = angle_delta,
- .angle_increment = angle_increment,
- .arc_partial_angle = arc_partial_angle,
- .arc_inner_factor = arc_inner_factor,
- .clip_plane = clip_plane,
- });
+ float matrix_final[4][4];
+ float color[4];
+
+ (void)C;
+ BLI_assert(CTX_wm_area(C)->spacetype == SPACE_VIEW3D);
+
+ gizmo_color_get(gz, highlight, color);
+
+ WM_gizmo_calc_matrix_final(gz, matrix_final);
+
+ const float arc_partial_angle = RNA_float_get(gz->ptr, "arc_partial_angle");
+ const float arc_inner_factor = RNA_float_get(gz->ptr, "arc_inner_factor");
+ int draw_options = RNA_enum_get(gz->ptr, "draw_options");
+ float angle_ofs = 0.0f;
+ float angle_delta = 0.0f;
+ float angle_increment = 0.0f;
+
+ if (select) {
+ draw_options &= ~ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_VALUE;
+ }
+
+ if (draw_options & ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_VALUE && (gz->flag & WM_GIZMO_DRAW_VALUE)) {
+ DialInteraction *inter = gz->interaction_data;
+ if (inter) {
+ angle_ofs = inter->output.angle_ofs;
+ angle_delta = inter->output.angle_delta;
+ angle_increment = inter->angle_increment;
+ }
+ else {
+ wmGizmoProperty *gz_prop = WM_gizmo_target_property_find(gz, "offset");
+ if (WM_gizmo_target_property_is_valid(gz_prop)) {
+ angle_delta = WM_gizmo_target_property_float_get(gz, gz_prop);
+ }
+ }
+ }
+
+ ED_gizmotypes_dial_3d_draw_util(gz->matrix_basis,
+ matrix_final,
+ gz->line_width,
+ color,
+ select,
+ &(struct Dial3dParams){
+ .draw_options = draw_options,
+ .angle_ofs = angle_ofs,
+ .angle_delta = angle_delta,
+ .angle_increment = angle_increment,
+ .arc_partial_angle = arc_partial_angle,
+ .arc_inner_factor = arc_inner_factor,
+ .clip_plane = clip_plane,
+ });
}
static void gizmo_dial_draw_select(const bContext *C, wmGizmo *gz, int select_id)
{
- float clip_plane_buf[4];
- const int draw_options = RNA_enum_get(gz->ptr, "draw_options");
- float *clip_plane = (draw_options & ED_GIZMO_DIAL_DRAW_FLAG_CLIP) ? clip_plane_buf : NULL;
+ float clip_plane_buf[4];
+ const int draw_options = RNA_enum_get(gz->ptr, "draw_options");
+ float *clip_plane = (draw_options & ED_GIZMO_DIAL_DRAW_FLAG_CLIP) ? clip_plane_buf : NULL;
- if (clip_plane) {
- ARegion *ar = CTX_wm_region(C);
- RegionView3D *rv3d = ar->regiondata;
+ if (clip_plane) {
+ ARegion *ar = CTX_wm_region(C);
+ RegionView3D *rv3d = ar->regiondata;
- copy_v3_v3(clip_plane, rv3d->viewinv[2]);
- clip_plane[3] = -dot_v3v3(rv3d->viewinv[2], gz->matrix_basis[3]);
- clip_plane[3] += DIAL_CLIP_BIAS;
- }
+ copy_v3_v3(clip_plane, rv3d->viewinv[2]);
+ clip_plane[3] = -dot_v3v3(rv3d->viewinv[2], gz->matrix_basis[3]);
+ clip_plane[3] += DIAL_CLIP_BIAS;
+ }
- GPU_select_load_id(select_id);
- dial_draw_intern(C, gz, true, false, clip_plane);
+ GPU_select_load_id(select_id);
+ dial_draw_intern(C, gz, true, false, clip_plane);
- if (clip_plane) {
- glDisable(GL_CLIP_DISTANCE0);
- }
+ if (clip_plane) {
+ glDisable(GL_CLIP_DISTANCE0);
+ }
}
static void gizmo_dial_draw(const bContext *C, wmGizmo *gz)
{
- const bool is_modal = gz->state & WM_GIZMO_STATE_MODAL;
- const bool is_highlight = (gz->state & WM_GIZMO_STATE_HIGHLIGHT) != 0;
- float clip_plane_buf[4];
- const int draw_options = RNA_enum_get(gz->ptr, "draw_options");
- float *clip_plane = (!is_modal && (draw_options & ED_GIZMO_DIAL_DRAW_FLAG_CLIP)) ? clip_plane_buf : NULL;
-
- if (clip_plane) {
- ARegion *ar = CTX_wm_region(C);
- RegionView3D *rv3d = ar->regiondata;
-
- copy_v3_v3(clip_plane, rv3d->viewinv[2]);
- clip_plane[3] = -dot_v3v3(rv3d->viewinv[2], gz->matrix_basis[3]);
- clip_plane[3] += DIAL_CLIP_BIAS;
- }
-
- GPU_blend(true);
- dial_draw_intern(C, gz, false, is_highlight, clip_plane);
- GPU_blend(false);
+ const bool is_modal = gz->state & WM_GIZMO_STATE_MODAL;
+ const bool is_highlight = (gz->state & WM_GIZMO_STATE_HIGHLIGHT) != 0;
+ float clip_plane_buf[4];
+ const int draw_options = RNA_enum_get(gz->ptr, "draw_options");
+ float *clip_plane = (!is_modal && (draw_options & ED_GIZMO_DIAL_DRAW_FLAG_CLIP)) ?
+ clip_plane_buf :
+ NULL;
+
+ if (clip_plane) {
+ ARegion *ar = CTX_wm_region(C);
+ RegionView3D *rv3d = ar->regiondata;
+
+ copy_v3_v3(clip_plane, rv3d->viewinv[2]);
+ clip_plane[3] = -dot_v3v3(rv3d->viewinv[2], gz->matrix_basis[3]);
+ clip_plane[3] += DIAL_CLIP_BIAS;
+ }
+
+ GPU_blend(true);
+ dial_draw_intern(C, gz, false, is_highlight, clip_plane);
+ GPU_blend(false);
}
-static int gizmo_dial_modal(
- bContext *C, wmGizmo *gz, const wmEvent *event,
- eWM_GizmoFlagTweak tweak_flag)
+static int gizmo_dial_modal(bContext *C,
+ wmGizmo *gz,
+ const wmEvent *event,
+ eWM_GizmoFlagTweak tweak_flag)
{
- DialInteraction *inter = gz->interaction_data;
- if ((event->type != MOUSEMOVE) && (inter->prev.tweak_flag == tweak_flag)) {
- return OPERATOR_RUNNING_MODAL;
- }
- /* Coordinate at which the arc drawing will be started. */
- const float co_outer[4] = {0.0f, DIAL_WIDTH, 0.0f};
- float angle_ofs, angle_delta, angle_increment = 0.0f;
-
- dial_ghostarc_get_angles(
- gz, event, CTX_wm_region(C), gz->matrix_basis, co_outer, &angle_ofs, &angle_delta);
-
- if (tweak_flag & WM_GIZMO_TWEAK_SNAP) {
- angle_increment = RNA_float_get(gz->ptr, "incremental_angle");
- angle_delta = (float)roundf((double)angle_delta / angle_increment) * angle_increment;
- }
- if (tweak_flag & WM_GIZMO_TWEAK_PRECISE) {
- angle_increment *= 0.2f;
- angle_delta *= 0.2f;
- }
- if (angle_delta != 0.0f) {
- inter->has_drag = true;
- }
-
- inter->angle_increment = angle_increment;
- inter->output.angle_delta = angle_delta;
- inter->output.angle_ofs = angle_ofs;
-
- /* Set the property for the operator and call its modal function. */
- wmGizmoProperty *gz_prop = WM_gizmo_target_property_find(gz, "offset");
- if (WM_gizmo_target_property_is_valid(gz_prop)) {
- WM_gizmo_target_property_float_set(C, gz, gz_prop, inter->init.prop_angle + angle_delta);
- }
-
- inter->prev.tweak_flag = tweak_flag;
-
- return OPERATOR_RUNNING_MODAL;
+ DialInteraction *inter = gz->interaction_data;
+ if ((event->type != MOUSEMOVE) && (inter->prev.tweak_flag == tweak_flag)) {
+ return OPERATOR_RUNNING_MODAL;
+ }
+ /* Coordinate at which the arc drawing will be started. */
+ const float co_outer[4] = {0.0f, DIAL_WIDTH, 0.0f};
+ float angle_ofs, angle_delta, angle_increment = 0.0f;
+
+ dial_ghostarc_get_angles(
+ gz, event, CTX_wm_region(C), gz->matrix_basis, co_outer, &angle_ofs, &angle_delta);
+
+ if (tweak_flag & WM_GIZMO_TWEAK_SNAP) {
+ angle_increment = RNA_float_get(gz->ptr, "incremental_angle");
+ angle_delta = (float)roundf((double)angle_delta / angle_increment) * angle_increment;
+ }
+ if (tweak_flag & WM_GIZMO_TWEAK_PRECISE) {
+ angle_increment *= 0.2f;
+ angle_delta *= 0.2f;
+ }
+ if (angle_delta != 0.0f) {
+ inter->has_drag = true;
+ }
+
+ inter->angle_increment = angle_increment;
+ inter->output.angle_delta = angle_delta;
+ inter->output.angle_ofs = angle_ofs;
+
+ /* Set the property for the operator and call its modal function. */
+ wmGizmoProperty *gz_prop = WM_gizmo_target_property_find(gz, "offset");
+ if (WM_gizmo_target_property_is_valid(gz_prop)) {
+ WM_gizmo_target_property_float_set(C, gz, gz_prop, inter->init.prop_angle + angle_delta);
+ }
+
+ inter->prev.tweak_flag = tweak_flag;
+
+ return OPERATOR_RUNNING_MODAL;
}
static void gizmo_dial_exit(bContext *C, wmGizmo *gz, const bool cancel)
{
- DialInteraction *inter = gz->interaction_data;
- bool use_reset_value = false;
- float reset_value = 0.0f;
- if (cancel) {
- /* Set the property for the operator and call its modal function. */
- wmGizmoProperty *gz_prop = WM_gizmo_target_property_find(gz, "offset");
- if (WM_gizmo_target_property_is_valid(gz_prop)) {
- use_reset_value = true;
- reset_value = inter->init.prop_angle;
- }
- }
- else {
- if (inter->has_drag == false) {
- PropertyRNA *prop = RNA_struct_find_property(gz->ptr, "click_value");
- if (RNA_property_is_set(gz->ptr, prop)) {
- use_reset_value = true;
- reset_value = RNA_property_float_get(gz->ptr, prop);
- }
- }
- }
-
- if (use_reset_value) {
- wmGizmoProperty *gz_prop = WM_gizmo_target_property_find(gz, "offset");
- if (WM_gizmo_target_property_is_valid(gz_prop)) {
- WM_gizmo_target_property_float_set(C, gz, gz_prop, reset_value);
- }
- }
-
+ DialInteraction *inter = gz->interaction_data;
+ bool use_reset_value = false;
+ float reset_value = 0.0f;
+ if (cancel) {
+ /* Set the property for the operator and call its modal function. */
+ wmGizmoProperty *gz_prop = WM_gizmo_target_property_find(gz, "offset");
+ if (WM_gizmo_target_property_is_valid(gz_prop)) {
+ use_reset_value = true;
+ reset_value = inter->init.prop_angle;
+ }
+ }
+ else {
+ if (inter->has_drag == false) {
+ PropertyRNA *prop = RNA_struct_find_property(gz->ptr, "click_value");
+ if (RNA_property_is_set(gz->ptr, prop)) {
+ use_reset_value = true;
+ reset_value = RNA_property_float_get(gz->ptr, prop);
+ }
+ }
+ }
+
+ if (use_reset_value) {
+ wmGizmoProperty *gz_prop = WM_gizmo_target_property_find(gz, "offset");
+ if (WM_gizmo_target_property_is_valid(gz_prop)) {
+ WM_gizmo_target_property_float_set(C, gz, gz_prop, reset_value);
+ }
+ }
}
-
static void gizmo_dial_setup(wmGizmo *gz)
{
- const float dir_default[3] = {0.0f, 0.0f, 1.0f};
+ const float dir_default[3] = {0.0f, 0.0f, 1.0f};
- /* defaults */
- copy_v3_v3(gz->matrix_basis[2], dir_default);
+ /* defaults */
+ copy_v3_v3(gz->matrix_basis[2], dir_default);
}
-static int gizmo_dial_invoke(
- bContext *UNUSED(C), wmGizmo *gz, const wmEvent *event)
+static int gizmo_dial_invoke(bContext *UNUSED(C), wmGizmo *gz, const wmEvent *event)
{
- DialInteraction *inter = MEM_callocN(sizeof(DialInteraction), __func__);
+ DialInteraction *inter = MEM_callocN(sizeof(DialInteraction), __func__);
- inter->init.mval[0] = event->mval[0];
- inter->init.mval[1] = event->mval[1];
+ inter->init.mval[0] = event->mval[0];
+ inter->init.mval[1] = event->mval[1];
- wmGizmoProperty *gz_prop = WM_gizmo_target_property_find(gz, "offset");
- if (WM_gizmo_target_property_is_valid(gz_prop)) {
- inter->init.prop_angle = WM_gizmo_target_property_float_get(gz, gz_prop);
- }
+ wmGizmoProperty *gz_prop = WM_gizmo_target_property_find(gz, "offset");
+ if (WM_gizmo_target_property_is_valid(gz_prop)) {
+ inter->init.prop_angle = WM_gizmo_target_property_float_get(gz, gz_prop);
+ }
- gz->interaction_data = inter;
+ gz->interaction_data = inter;
- return OPERATOR_RUNNING_MODAL;
+ return OPERATOR_RUNNING_MODAL;
}
/* -------------------------------------------------------------------- */
@@ -535,87 +550,115 @@ static int gizmo_dial_invoke(
*
* \{ */
-void ED_gizmotypes_dial_3d_draw_util(
- const float matrix_basis[4][4],
- const float matrix_final[4][4],
- const float line_width,
- const float color[4],
- const bool select,
- struct Dial3dParams *params)
+void ED_gizmotypes_dial_3d_draw_util(const float matrix_basis[4][4],
+ const float matrix_final[4][4],
+ const float line_width,
+ const float color[4],
+ const bool select,
+ struct Dial3dParams *params)
{
- GPU_matrix_push();
- GPU_matrix_mul(matrix_final);
-
- GPU_polygon_smooth(false);
-
- if ((params->draw_options & ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_VALUE) != 0) {
- /* Draw rotation indicator arc first. */
- dial_ghostarc_draw_with_helplines(
- params->angle_ofs, params->angle_delta,
- params->arc_inner_factor, color, params->draw_options);
-
- if ((params->draw_options & ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_MIRROR) != 0) {
- dial_ghostarc_draw_with_helplines(
- params->angle_ofs + M_PI, params->angle_delta,
- params->arc_inner_factor, color, params->draw_options);
- }
- }
-
- if (params->angle_increment) {
- dial_ghostarc_draw_incremental_angle(params->angle_increment, params->angle_ofs);
- }
-
- /* Draw actual dial gizmo. */
- dial_geom_draw(
- color, line_width, select, matrix_basis, params->clip_plane,
- params->arc_partial_angle, params->arc_inner_factor, params->draw_options);
-
- GPU_matrix_pop();
+ GPU_matrix_push();
+ GPU_matrix_mul(matrix_final);
+
+ GPU_polygon_smooth(false);
+
+ if ((params->draw_options & ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_VALUE) != 0) {
+ /* Draw rotation indicator arc first. */
+ dial_ghostarc_draw_with_helplines(params->angle_ofs,
+ params->angle_delta,
+ params->arc_inner_factor,
+ color,
+ params->draw_options);
+
+ if ((params->draw_options & ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_MIRROR) != 0) {
+ dial_ghostarc_draw_with_helplines(params->angle_ofs + M_PI,
+ params->angle_delta,
+ params->arc_inner_factor,
+ color,
+ params->draw_options);
+ }
+ }
+
+ if (params->angle_increment) {
+ dial_ghostarc_draw_incremental_angle(params->angle_increment, params->angle_ofs);
+ }
+
+ /* Draw actual dial gizmo. */
+ dial_geom_draw(color,
+ line_width,
+ select,
+ matrix_basis,
+ params->clip_plane,
+ params->arc_partial_angle,
+ params->arc_inner_factor,
+ params->draw_options);
+
+ GPU_matrix_pop();
}
static void GIZMO_GT_dial_3d(wmGizmoType *gzt)
{
- /* identifiers */
- gzt->idname = "GIZMO_GT_dial_3d";
-
- /* api callbacks */
- gzt->draw = gizmo_dial_draw;
- gzt->draw_select = gizmo_dial_draw_select;
- gzt->setup = gizmo_dial_setup;
- gzt->invoke = gizmo_dial_invoke;
- gzt->modal = gizmo_dial_modal;
- gzt->exit = gizmo_dial_exit;
-
- gzt->struct_size = sizeof(wmGizmo);
-
- /* rna */
- static EnumPropertyItem rna_enum_draw_options[] = {
- {ED_GIZMO_DIAL_DRAW_FLAG_CLIP, "CLIP", 0, "Clipped", ""},
- {ED_GIZMO_DIAL_DRAW_FLAG_FILL, "FILL", 0, "Filled", ""},
- {ED_GIZMO_DIAL_DRAW_FLAG_FILL_SELECT, "FILL_SELECT", 0, "Use fill for selection test", ""},
- {ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_MIRROR, "ANGLE_MIRROR", 0, "Angle Mirror", ""},
- {ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_START_Y, "ANGLE_START_Y", 0, "Angle Start Y", ""},
- {ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_VALUE, "ANGLE_VALUE", 0, "Show Angle Value", ""},
- {0, NULL, 0, NULL, NULL},
- };
- RNA_def_enum_flag(gzt->srna, "draw_options", rna_enum_draw_options, 0, "Draw Options", "");
- RNA_def_boolean(gzt->srna, "wrap_angle", true, "Wrap Angle", "");
- RNA_def_float_factor(gzt->srna, "arc_inner_factor", 0.0f, 0.0f, 1.0f, "Arc Inner Factor", "", 0.0f, 1.0f);
- RNA_def_float_factor(gzt->srna, "arc_partial_angle", 0.0f, 0.0f, M_PI * 2, "Show Partial Dial", "", 0.0f, M_PI * 2);
- RNA_def_float_factor(
- gzt->srna, "incremental_angle", SNAP_INCREMENTAL_ANGLE, 0.0f,
- M_PI * 2, "Incremental Angle", "Angle to snap in steps", 0.0f, M_PI * 2);
- RNA_def_float(
- gzt->srna, "click_value", 0.0f, -FLT_MAX, FLT_MAX,
- "Click Value", "Value to use for a single click action",
- -FLT_MAX, FLT_MAX);
-
- WM_gizmotype_target_property_def(gzt, "offset", PROP_FLOAT, 1);
+ /* identifiers */
+ gzt->idname = "GIZMO_GT_dial_3d";
+
+ /* api callbacks */
+ gzt->draw = gizmo_dial_draw;
+ gzt->draw_select = gizmo_dial_draw_select;
+ gzt->setup = gizmo_dial_setup;
+ gzt->invoke = gizmo_dial_invoke;
+ gzt->modal = gizmo_dial_modal;
+ gzt->exit = gizmo_dial_exit;
+
+ gzt->struct_size = sizeof(wmGizmo);
+
+ /* rna */
+ static EnumPropertyItem rna_enum_draw_options[] = {
+ {ED_GIZMO_DIAL_DRAW_FLAG_CLIP, "CLIP", 0, "Clipped", ""},
+ {ED_GIZMO_DIAL_DRAW_FLAG_FILL, "FILL", 0, "Filled", ""},
+ {ED_GIZMO_DIAL_DRAW_FLAG_FILL_SELECT, "FILL_SELECT", 0, "Use fill for selection test", ""},
+ {ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_MIRROR, "ANGLE_MIRROR", 0, "Angle Mirror", ""},
+ {ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_START_Y, "ANGLE_START_Y", 0, "Angle Start Y", ""},
+ {ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_VALUE, "ANGLE_VALUE", 0, "Show Angle Value", ""},
+ {0, NULL, 0, NULL, NULL},
+ };
+ RNA_def_enum_flag(gzt->srna, "draw_options", rna_enum_draw_options, 0, "Draw Options", "");
+ RNA_def_boolean(gzt->srna, "wrap_angle", true, "Wrap Angle", "");
+ RNA_def_float_factor(
+ gzt->srna, "arc_inner_factor", 0.0f, 0.0f, 1.0f, "Arc Inner Factor", "", 0.0f, 1.0f);
+ RNA_def_float_factor(gzt->srna,
+ "arc_partial_angle",
+ 0.0f,
+ 0.0f,
+ M_PI * 2,
+ "Show Partial Dial",
+ "",
+ 0.0f,
+ M_PI * 2);
+ RNA_def_float_factor(gzt->srna,
+ "incremental_angle",
+ SNAP_INCREMENTAL_ANGLE,
+ 0.0f,
+ M_PI * 2,
+ "Incremental Angle",
+ "Angle to snap in steps",
+ 0.0f,
+ M_PI * 2);
+ RNA_def_float(gzt->srna,
+ "click_value",
+ 0.0f,
+ -FLT_MAX,
+ FLT_MAX,
+ "Click Value",
+ "Value to use for a single click action",
+ -FLT_MAX,
+ FLT_MAX);
+
+ WM_gizmotype_target_property_def(gzt, "offset", PROP_FLOAT, 1);
}
void ED_gizmotypes_dial_3d(void)
{
- WM_gizmotype_append(GIZMO_GT_dial_3d);
+ WM_gizmotype_append(GIZMO_GT_dial_3d);
}
/** \} */
diff --git a/source/blender/editors/gizmo_library/gizmo_types/move3d_gizmo.c b/source/blender/editors/gizmo_library/gizmo_types/move3d_gizmo.c
index 3870ce984b5..f9ad836b054 100644
--- a/source/blender/editors/gizmo_library/gizmo_types/move3d_gizmo.c
+++ b/source/blender/editors/gizmo_library/gizmo_types/move3d_gizmo.c
@@ -34,7 +34,6 @@
#include "BKE_context.h"
-
#include "GPU_immediate.h"
#include "GPU_immediate_util.h"
#include "GPU_matrix.h"
@@ -59,36 +58,37 @@
#define MVAL_MAX_PX_DIST 12.0f
typedef struct MoveGizmo3D {
- wmGizmo gizmo;
- /* Added to 'matrix_basis' when calculating the matrix. */
- float prop_co[3];
+ wmGizmo gizmo;
+ /* Added to 'matrix_basis' when calculating the matrix. */
+ float prop_co[3];
} MoveGizmo3D;
static void gizmo_move_matrix_basis_get(const wmGizmo *gz, float r_matrix[4][4])
{
- MoveGizmo3D *move = (MoveGizmo3D *)gz;
+ MoveGizmo3D *move = (MoveGizmo3D *)gz;
- copy_m4_m4(r_matrix, move->gizmo.matrix_basis);
- add_v3_v3(r_matrix[3], move->prop_co);
+ copy_m4_m4(r_matrix, move->gizmo.matrix_basis);
+ add_v3_v3(r_matrix[3], move->prop_co);
}
-static int gizmo_move_modal(
- bContext *C, wmGizmo *gz, const wmEvent *event,
- eWM_GizmoFlagTweak tweak_flag);
+static int gizmo_move_modal(bContext *C,
+ wmGizmo *gz,
+ const wmEvent *event,
+ eWM_GizmoFlagTweak tweak_flag);
typedef struct MoveInteraction {
- struct {
- float mval[2];
- /* Only for when using properties. */
- float prop_co[3];
- float matrix_final[4][4];
- } init;
- struct {
- eWM_GizmoFlagTweak tweak_flag;
- } prev;
-
- /* We could have other snap contexts, for now only support 3D view. */
- struct SnapObjectContext *snap_context_v3d;
+ struct {
+ float mval[2];
+ /* Only for when using properties. */
+ float prop_co[3];
+ float matrix_final[4][4];
+ } init;
+ struct {
+ eWM_GizmoFlagTweak tweak_flag;
+ } prev;
+
+ /* We could have other snap contexts, for now only support 3D view. */
+ struct SnapObjectContext *snap_context_v3d;
} MoveInteraction;
@@ -96,321 +96,322 @@ typedef struct MoveInteraction {
/* -------------------------------------------------------------------- */
-static void move_geom_draw(
- const wmGizmo *gz, const float color[4], const bool select, const int draw_options)
+static void move_geom_draw(const wmGizmo *gz,
+ const float color[4],
+ const bool select,
+ const int draw_options)
{
#ifdef USE_GIZMO_CUSTOM_DIAL
- UNUSED_VARS(move3d, col, axis_modal_mat);
- wm_gizmo_geometryinfo_draw(&wm_gizmo_geom_data_move3d, select);
+ UNUSED_VARS(move3d, col, axis_modal_mat);
+ wm_gizmo_geometryinfo_draw(&wm_gizmo_geom_data_move3d, select);
#else
- const int draw_style = RNA_enum_get(gz->ptr, "draw_style");
- const bool filled = (
- (draw_options &
- (select ?
- (ED_GIZMO_MOVE_DRAW_FLAG_FILL | ED_GIZMO_MOVE_DRAW_FLAG_FILL_SELECT) :
- ED_GIZMO_MOVE_DRAW_FLAG_FILL)));
-
- GPU_line_width(gz->line_width);
-
- GPUVertFormat *format = immVertexFormat();
- uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
-
- immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
-
- immUniformColor4fv(color);
-
- if (draw_style == ED_GIZMO_MOVE_STYLE_RING_2D) {
- if (filled) {
- imm_draw_circle_fill_2d(pos, 0, 0, 1.0f, DIAL_RESOLUTION);
- }
- else {
- imm_draw_circle_wire_2d(pos, 0, 0, 1.0f, DIAL_RESOLUTION);
- }
- }
- else if (draw_style == ED_GIZMO_MOVE_STYLE_CROSS_2D) {
- immBegin(GPU_PRIM_LINES, 4);
- immVertex2f(pos, 1.0f, 1.0f);
- immVertex2f(pos, -1.0f, -1.0f);
-
- immVertex2f(pos, -1.0f, 1.0f);
- immVertex2f(pos, 1.0f, -1.0f);
- immEnd();
- }
- else {
- BLI_assert(0);
- }
-
- immUnbindProgram();
-
- UNUSED_VARS(select);
+ const int draw_style = RNA_enum_get(gz->ptr, "draw_style");
+ const bool filled = ((draw_options & (select ? (ED_GIZMO_MOVE_DRAW_FLAG_FILL |
+ ED_GIZMO_MOVE_DRAW_FLAG_FILL_SELECT) :
+ ED_GIZMO_MOVE_DRAW_FLAG_FILL)));
+
+ GPU_line_width(gz->line_width);
+
+ GPUVertFormat *format = immVertexFormat();
+ uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+
+ immUniformColor4fv(color);
+
+ if (draw_style == ED_GIZMO_MOVE_STYLE_RING_2D) {
+ if (filled) {
+ imm_draw_circle_fill_2d(pos, 0, 0, 1.0f, DIAL_RESOLUTION);
+ }
+ else {
+ imm_draw_circle_wire_2d(pos, 0, 0, 1.0f, DIAL_RESOLUTION);
+ }
+ }
+ else if (draw_style == ED_GIZMO_MOVE_STYLE_CROSS_2D) {
+ immBegin(GPU_PRIM_LINES, 4);
+ immVertex2f(pos, 1.0f, 1.0f);
+ immVertex2f(pos, -1.0f, -1.0f);
+
+ immVertex2f(pos, -1.0f, 1.0f);
+ immVertex2f(pos, 1.0f, -1.0f);
+ immEnd();
+ }
+ else {
+ BLI_assert(0);
+ }
+
+ immUnbindProgram();
+
+ UNUSED_VARS(select);
#endif
}
-static void move3d_get_translate(
- const wmGizmo *gz, const wmEvent *event, const ARegion *ar,
- float co_delta[3])
+static void move3d_get_translate(const wmGizmo *gz,
+ const wmEvent *event,
+ const ARegion *ar,
+ float co_delta[3])
{
- MoveInteraction *inter = gz->interaction_data;
- const float mval_delta[2] = {
- event->mval[0] - inter->init.mval[0],
- event->mval[1] - inter->init.mval[1],
- };
-
- RegionView3D *rv3d = ar->regiondata;
- float co_ref[3];
- mul_v3_mat3_m4v3(co_ref, gz->matrix_space, inter->init.prop_co);
- const float zfac = ED_view3d_calc_zfac(rv3d, co_ref, NULL);
-
- ED_view3d_win_to_delta(ar, mval_delta, co_delta, zfac);
-
- float matrix_space_inv[3][3];
- copy_m3_m4(matrix_space_inv, gz->matrix_space);
- invert_m3(matrix_space_inv);
- mul_m3_v3(matrix_space_inv, co_delta);
+ MoveInteraction *inter = gz->interaction_data;
+ const float mval_delta[2] = {
+ event->mval[0] - inter->init.mval[0],
+ event->mval[1] - inter->init.mval[1],
+ };
+
+ RegionView3D *rv3d = ar->regiondata;
+ float co_ref[3];
+ mul_v3_mat3_m4v3(co_ref, gz->matrix_space, inter->init.prop_co);
+ const float zfac = ED_view3d_calc_zfac(rv3d, co_ref, NULL);
+
+ ED_view3d_win_to_delta(ar, mval_delta, co_delta, zfac);
+
+ float matrix_space_inv[3][3];
+ copy_m3_m4(matrix_space_inv, gz->matrix_space);
+ invert_m3(matrix_space_inv);
+ mul_m3_v3(matrix_space_inv, co_delta);
}
-static void move3d_draw_intern(
- const bContext *C, wmGizmo *gz,
- const bool select, const bool highlight)
+static void move3d_draw_intern(const bContext *C,
+ wmGizmo *gz,
+ const bool select,
+ const bool highlight)
{
- MoveInteraction *inter = gz->interaction_data;
- const int draw_options = RNA_enum_get(gz->ptr, "draw_options");
- const bool align_view = (draw_options & ED_GIZMO_MOVE_DRAW_FLAG_ALIGN_VIEW) != 0;
- float color[4];
- float matrix_final[4][4];
- float matrix_align[4][4];
-
- gizmo_color_get(gz, highlight, color);
- WM_gizmo_calc_matrix_final(gz, matrix_final);
-
- GPU_matrix_push();
- GPU_matrix_mul(matrix_final);
-
- if (align_view) {
- float matrix_final_unit[4][4];
- RegionView3D *rv3d = CTX_wm_region_view3d(C);
- normalize_m4_m4(matrix_final_unit, matrix_final);
- mul_m4_m4m4(matrix_align, rv3d->viewmat, matrix_final_unit);
- zero_v3(matrix_align[3]);
- transpose_m4(matrix_align);
- GPU_matrix_mul(matrix_align);
- }
-
- GPU_blend(true);
- move_geom_draw(gz, color, select, draw_options);
- GPU_blend(false);
- GPU_matrix_pop();
-
- if (gz->interaction_data) {
- GPU_matrix_push();
- GPU_matrix_mul(inter->init.matrix_final);
-
- if (align_view) {
- GPU_matrix_mul(matrix_align);
- }
-
- GPU_blend(true);
- move_geom_draw(gz, (const float[4]){0.5f, 0.5f, 0.5f, 0.5f}, select, draw_options);
- GPU_blend(false);
- GPU_matrix_pop();
- }
+ MoveInteraction *inter = gz->interaction_data;
+ const int draw_options = RNA_enum_get(gz->ptr, "draw_options");
+ const bool align_view = (draw_options & ED_GIZMO_MOVE_DRAW_FLAG_ALIGN_VIEW) != 0;
+ float color[4];
+ float matrix_final[4][4];
+ float matrix_align[4][4];
+
+ gizmo_color_get(gz, highlight, color);
+ WM_gizmo_calc_matrix_final(gz, matrix_final);
+
+ GPU_matrix_push();
+ GPU_matrix_mul(matrix_final);
+
+ if (align_view) {
+ float matrix_final_unit[4][4];
+ RegionView3D *rv3d = CTX_wm_region_view3d(C);
+ normalize_m4_m4(matrix_final_unit, matrix_final);
+ mul_m4_m4m4(matrix_align, rv3d->viewmat, matrix_final_unit);
+ zero_v3(matrix_align[3]);
+ transpose_m4(matrix_align);
+ GPU_matrix_mul(matrix_align);
+ }
+
+ GPU_blend(true);
+ move_geom_draw(gz, color, select, draw_options);
+ GPU_blend(false);
+ GPU_matrix_pop();
+
+ if (gz->interaction_data) {
+ GPU_matrix_push();
+ GPU_matrix_mul(inter->init.matrix_final);
+
+ if (align_view) {
+ GPU_matrix_mul(matrix_align);
+ }
+
+ GPU_blend(true);
+ move_geom_draw(gz, (const float[4]){0.5f, 0.5f, 0.5f, 0.5f}, select, draw_options);
+ GPU_blend(false);
+ GPU_matrix_pop();
+ }
}
static void gizmo_move_draw_select(const bContext *C, wmGizmo *gz, int select_id)
{
- GPU_select_load_id(select_id);
- move3d_draw_intern(C, gz, true, false);
+ GPU_select_load_id(select_id);
+ move3d_draw_intern(C, gz, true, false);
}
static void gizmo_move_draw(const bContext *C, wmGizmo *gz)
{
- const bool is_modal = gz->state & WM_GIZMO_STATE_MODAL;
- const bool is_highlight = (gz->state & WM_GIZMO_STATE_HIGHLIGHT) != 0;
+ const bool is_modal = gz->state & WM_GIZMO_STATE_MODAL;
+ const bool is_highlight = (gz->state & WM_GIZMO_STATE_HIGHLIGHT) != 0;
- (void)is_modal;
+ (void)is_modal;
- GPU_blend(true);
- move3d_draw_intern(C, gz, false, is_highlight);
- GPU_blend(false);
+ GPU_blend(true);
+ move3d_draw_intern(C, gz, false, is_highlight);
+ GPU_blend(false);
}
-static int gizmo_move_modal(
- bContext *C, wmGizmo *gz, const wmEvent *event,
- eWM_GizmoFlagTweak tweak_flag)
+static int gizmo_move_modal(bContext *C,
+ wmGizmo *gz,
+ const wmEvent *event,
+ eWM_GizmoFlagTweak tweak_flag)
{
- MoveInteraction *inter = gz->interaction_data;
- if ((event->type != MOUSEMOVE) && (inter->prev.tweak_flag == tweak_flag)) {
- return OPERATOR_RUNNING_MODAL;
- }
- MoveGizmo3D *move = (MoveGizmo3D *)gz;
- ARegion *ar = CTX_wm_region(C);
-
- float prop_delta[3];
- if (CTX_wm_area(C)->spacetype == SPACE_VIEW3D) {
- move3d_get_translate(gz, event, ar, prop_delta);
- }
- else {
- float mval_proj_init[2], mval_proj_curr[2];
- if ((gizmo_window_project_2d(
- C, gz, inter->init.mval, 2, false, mval_proj_init) == false) ||
- (gizmo_window_project_2d(
- C, gz, (const float[2]){UNPACK2(event->mval)}, 2, false, mval_proj_curr) == false))
- {
- return OPERATOR_RUNNING_MODAL;
- }
- sub_v2_v2v2(prop_delta, mval_proj_curr, mval_proj_init);
- prop_delta[2] = 0.0f;
- }
-
- if (tweak_flag & WM_GIZMO_TWEAK_PRECISE) {
- mul_v3_fl(prop_delta, 0.1f);
- }
-
- add_v3_v3v3(move->prop_co, inter->init.prop_co, prop_delta);
-
- if (tweak_flag & WM_GIZMO_TWEAK_SNAP) {
- if (inter->snap_context_v3d) {
- float dist_px = MVAL_MAX_PX_DIST * U.pixelsize;
- const float mval_fl[2] = {UNPACK2(event->mval)};
- float co[3];
- if (ED_transform_snap_object_project_view3d(
- inter->snap_context_v3d,
- (SCE_SNAP_MODE_VERTEX | SCE_SNAP_MODE_EDGE | SCE_SNAP_MODE_FACE),
- &(const struct SnapObjectParams){
- .snap_select = SNAP_ALL,
- .use_object_edit_cage = true,
- .use_occlusion_test = true,
- },
- mval_fl, &dist_px,
- co, NULL))
- {
- float matrix_space_inv[4][4];
- invert_m4_m4(matrix_space_inv, gz->matrix_space);
- mul_v3_m4v3(move->prop_co, matrix_space_inv, co);
- }
- }
- }
-
- /* set the property for the operator and call its modal function */
- wmGizmoProperty *gz_prop = WM_gizmo_target_property_find(gz, "offset");
- if (WM_gizmo_target_property_is_valid(gz_prop)) {
- WM_gizmo_target_property_float_set_array(C, gz, gz_prop, move->prop_co);
- }
- else {
- zero_v3(move->prop_co);
- }
-
- ED_region_tag_redraw(ar);
-
- inter->prev.tweak_flag = tweak_flag;
-
- return OPERATOR_RUNNING_MODAL;
+ MoveInteraction *inter = gz->interaction_data;
+ if ((event->type != MOUSEMOVE) && (inter->prev.tweak_flag == tweak_flag)) {
+ return OPERATOR_RUNNING_MODAL;
+ }
+ MoveGizmo3D *move = (MoveGizmo3D *)gz;
+ ARegion *ar = CTX_wm_region(C);
+
+ float prop_delta[3];
+ if (CTX_wm_area(C)->spacetype == SPACE_VIEW3D) {
+ move3d_get_translate(gz, event, ar, prop_delta);
+ }
+ else {
+ float mval_proj_init[2], mval_proj_curr[2];
+ if ((gizmo_window_project_2d(C, gz, inter->init.mval, 2, false, mval_proj_init) == false) ||
+ (gizmo_window_project_2d(
+ C, gz, (const float[2]){UNPACK2(event->mval)}, 2, false, mval_proj_curr) == false)) {
+ return OPERATOR_RUNNING_MODAL;
+ }
+ sub_v2_v2v2(prop_delta, mval_proj_curr, mval_proj_init);
+ prop_delta[2] = 0.0f;
+ }
+
+ if (tweak_flag & WM_GIZMO_TWEAK_PRECISE) {
+ mul_v3_fl(prop_delta, 0.1f);
+ }
+
+ add_v3_v3v3(move->prop_co, inter->init.prop_co, prop_delta);
+
+ if (tweak_flag & WM_GIZMO_TWEAK_SNAP) {
+ if (inter->snap_context_v3d) {
+ float dist_px = MVAL_MAX_PX_DIST * U.pixelsize;
+ const float mval_fl[2] = {UNPACK2(event->mval)};
+ float co[3];
+ if (ED_transform_snap_object_project_view3d(
+ inter->snap_context_v3d,
+ (SCE_SNAP_MODE_VERTEX | SCE_SNAP_MODE_EDGE | SCE_SNAP_MODE_FACE),
+ &(const struct SnapObjectParams){
+ .snap_select = SNAP_ALL,
+ .use_object_edit_cage = true,
+ .use_occlusion_test = true,
+ },
+ mval_fl,
+ &dist_px,
+ co,
+ NULL)) {
+ float matrix_space_inv[4][4];
+ invert_m4_m4(matrix_space_inv, gz->matrix_space);
+ mul_v3_m4v3(move->prop_co, matrix_space_inv, co);
+ }
+ }
+ }
+
+ /* set the property for the operator and call its modal function */
+ wmGizmoProperty *gz_prop = WM_gizmo_target_property_find(gz, "offset");
+ if (WM_gizmo_target_property_is_valid(gz_prop)) {
+ WM_gizmo_target_property_float_set_array(C, gz, gz_prop, move->prop_co);
+ }
+ else {
+ zero_v3(move->prop_co);
+ }
+
+ ED_region_tag_redraw(ar);
+
+ inter->prev.tweak_flag = tweak_flag;
+
+ return OPERATOR_RUNNING_MODAL;
}
static void gizmo_move_exit(bContext *C, wmGizmo *gz, const bool cancel)
{
- MoveInteraction *inter = gz->interaction_data;
- bool use_reset_value = false;
- const float *reset_value = NULL;
- if (cancel) {
- /* Set the property for the operator and call its modal function. */
- wmGizmoProperty *gz_prop = WM_gizmo_target_property_find(gz, "offset");
- if (WM_gizmo_target_property_is_valid(gz_prop)) {
- use_reset_value = true;
- reset_value = inter->init.prop_co;
- }
- }
-
- if (use_reset_value) {
- wmGizmoProperty *gz_prop = WM_gizmo_target_property_find(gz, "offset");
- if (WM_gizmo_target_property_is_valid(gz_prop)) {
- WM_gizmo_target_property_float_set_array(C, gz, gz_prop, reset_value);
- }
- }
-
- if (inter->snap_context_v3d) {
- ED_transform_snap_object_context_destroy(inter->snap_context_v3d);
- inter->snap_context_v3d = NULL;
- }
+ MoveInteraction *inter = gz->interaction_data;
+ bool use_reset_value = false;
+ const float *reset_value = NULL;
+ if (cancel) {
+ /* Set the property for the operator and call its modal function. */
+ wmGizmoProperty *gz_prop = WM_gizmo_target_property_find(gz, "offset");
+ if (WM_gizmo_target_property_is_valid(gz_prop)) {
+ use_reset_value = true;
+ reset_value = inter->init.prop_co;
+ }
+ }
+
+ if (use_reset_value) {
+ wmGizmoProperty *gz_prop = WM_gizmo_target_property_find(gz, "offset");
+ if (WM_gizmo_target_property_is_valid(gz_prop)) {
+ WM_gizmo_target_property_float_set_array(C, gz, gz_prop, reset_value);
+ }
+ }
+
+ if (inter->snap_context_v3d) {
+ ED_transform_snap_object_context_destroy(inter->snap_context_v3d);
+ inter->snap_context_v3d = NULL;
+ }
}
-static int gizmo_move_invoke(
- bContext *C, wmGizmo *gz, const wmEvent *event)
+static int gizmo_move_invoke(bContext *C, wmGizmo *gz, const wmEvent *event)
{
- const bool use_snap = RNA_boolean_get(gz->ptr, "use_snap");
+ const bool use_snap = RNA_boolean_get(gz->ptr, "use_snap");
- MoveInteraction *inter = MEM_callocN(sizeof(MoveInteraction), __func__);
- inter->init.mval[0] = event->mval[0];
- inter->init.mval[1] = event->mval[1];
+ MoveInteraction *inter = MEM_callocN(sizeof(MoveInteraction), __func__);
+ inter->init.mval[0] = event->mval[0];
+ inter->init.mval[1] = event->mval[1];
#if 0
- copy_v3_v3(inter->init.prop_co, move->prop_co);
+ copy_v3_v3(inter->init.prop_co, move->prop_co);
#else
- wmGizmoProperty *gz_prop = WM_gizmo_target_property_find(gz, "offset");
- if (WM_gizmo_target_property_is_valid(gz_prop)) {
- WM_gizmo_target_property_float_get_array(gz, gz_prop, inter->init.prop_co);
- }
+ wmGizmoProperty *gz_prop = WM_gizmo_target_property_find(gz, "offset");
+ if (WM_gizmo_target_property_is_valid(gz_prop)) {
+ WM_gizmo_target_property_float_get_array(gz, gz_prop, inter->init.prop_co);
+ }
#endif
- WM_gizmo_calc_matrix_final(gz, inter->init.matrix_final);
-
- if (use_snap) {
- ScrArea *sa = CTX_wm_area(C);
- if (sa) {
- switch (sa->spacetype) {
- case SPACE_VIEW3D:
- {
- inter->snap_context_v3d = ED_transform_snap_object_context_create_view3d(
- CTX_data_main(C), CTX_data_scene(C), CTX_data_depsgraph(C), 0,
- CTX_wm_region(C), CTX_wm_view3d(C));
- break;
- }
- default:
- /* Not yet supported. */
- BLI_assert(0);
- }
- }
- }
-
- gz->interaction_data = inter;
-
- return OPERATOR_RUNNING_MODAL;
+ WM_gizmo_calc_matrix_final(gz, inter->init.matrix_final);
+
+ if (use_snap) {
+ ScrArea *sa = CTX_wm_area(C);
+ if (sa) {
+ switch (sa->spacetype) {
+ case SPACE_VIEW3D: {
+ inter->snap_context_v3d = ED_transform_snap_object_context_create_view3d(
+ CTX_data_main(C),
+ CTX_data_scene(C),
+ CTX_data_depsgraph(C),
+ 0,
+ CTX_wm_region(C),
+ CTX_wm_view3d(C));
+ break;
+ }
+ default:
+ /* Not yet supported. */
+ BLI_assert(0);
+ }
+ }
+ }
+
+ gz->interaction_data = inter;
+
+ return OPERATOR_RUNNING_MODAL;
}
-
-static int gizmo_move_test_select(
- bContext *C, wmGizmo *gz, const int mval[2])
+static int gizmo_move_test_select(bContext *C, wmGizmo *gz, const int mval[2])
{
- float point_local[2];
+ float point_local[2];
- if (gizmo_window_project_2d(
- C, gz, (const float[2]){UNPACK2(mval)}, 2, true, point_local) == false)
- {
- return -1;
- }
+ if (gizmo_window_project_2d(C, gz, (const float[2]){UNPACK2(mval)}, 2, true, point_local) ==
+ false) {
+ return -1;
+ }
- /* The 'gz->scale_final' is already applied when projecting. */
- if (len_squared_v2(point_local) < 1.0f) {
- return 0;
- }
+ /* The 'gz->scale_final' is already applied when projecting. */
+ if (len_squared_v2(point_local) < 1.0f) {
+ return 0;
+ }
- return -1;
+ return -1;
}
static void gizmo_move_property_update(wmGizmo *gz, wmGizmoProperty *gz_prop)
{
- MoveGizmo3D *move = (MoveGizmo3D *)gz;
- if (WM_gizmo_target_property_is_valid(gz_prop)) {
- WM_gizmo_target_property_float_get_array(gz, gz_prop, move->prop_co);
- }
- else {
- zero_v3(move->prop_co);
- }
+ MoveGizmo3D *move = (MoveGizmo3D *)gz;
+ if (WM_gizmo_target_property_is_valid(gz_prop)) {
+ WM_gizmo_target_property_float_get_array(gz, gz_prop, move->prop_co);
+ }
+ else {
+ zero_v3(move->prop_co);
+ }
}
static int gizmo_move_cursor_get(wmGizmo *UNUSED(gz))
{
- return BC_NSEW_SCROLLCURSOR;
+ return BC_NSEW_SCROLLCURSOR;
}
/* -------------------------------------------------------------------- */
@@ -420,45 +421,46 @@ static int gizmo_move_cursor_get(wmGizmo *UNUSED(gz))
static void GIZMO_GT_move_3d(wmGizmoType *gzt)
{
- /* identifiers */
- gzt->idname = "GIZMO_GT_move_3d";
-
- /* api callbacks */
- gzt->draw = gizmo_move_draw;
- gzt->draw_select = gizmo_move_draw_select;
- gzt->test_select = gizmo_move_test_select;
- gzt->matrix_basis_get = gizmo_move_matrix_basis_get;
- gzt->invoke = gizmo_move_invoke;
- gzt->property_update = gizmo_move_property_update;
- gzt->modal = gizmo_move_modal;
- gzt->exit = gizmo_move_exit;
- gzt->cursor_get = gizmo_move_cursor_get;
-
- gzt->struct_size = sizeof(MoveGizmo3D);
-
- /* rna */
- static EnumPropertyItem rna_enum_draw_style[] = {
- {ED_GIZMO_MOVE_STYLE_RING_2D, "RING_2D", 0, "Ring", ""},
- {ED_GIZMO_MOVE_STYLE_CROSS_2D, "CROSS_2D", 0, "Ring", ""},
- {0, NULL, 0, NULL, NULL},
- };
- static EnumPropertyItem rna_enum_draw_options[] = {
- {ED_GIZMO_MOVE_DRAW_FLAG_FILL, "FILL", 0, "Filled", ""},
- {ED_GIZMO_MOVE_DRAW_FLAG_FILL_SELECT, "FILL_SELECT", 0, "Use fill for selection test", ""},
- {ED_GIZMO_MOVE_DRAW_FLAG_ALIGN_VIEW, "ALIGN_VIEW", 0, "Align View", ""},
- {0, NULL, 0, NULL, NULL},
- };
-
- RNA_def_enum(gzt->srna, "draw_style", rna_enum_draw_style, ED_GIZMO_MOVE_STYLE_RING_2D, "Draw Style", "");
- RNA_def_enum_flag(gzt->srna, "draw_options", rna_enum_draw_options, 0, "Draw Options", "");
- RNA_def_boolean(gzt->srna, "use_snap", false, "Use Snap", "");
-
- WM_gizmotype_target_property_def(gzt, "offset", PROP_FLOAT, 3);
+ /* identifiers */
+ gzt->idname = "GIZMO_GT_move_3d";
+
+ /* api callbacks */
+ gzt->draw = gizmo_move_draw;
+ gzt->draw_select = gizmo_move_draw_select;
+ gzt->test_select = gizmo_move_test_select;
+ gzt->matrix_basis_get = gizmo_move_matrix_basis_get;
+ gzt->invoke = gizmo_move_invoke;
+ gzt->property_update = gizmo_move_property_update;
+ gzt->modal = gizmo_move_modal;
+ gzt->exit = gizmo_move_exit;
+ gzt->cursor_get = gizmo_move_cursor_get;
+
+ gzt->struct_size = sizeof(MoveGizmo3D);
+
+ /* rna */
+ static EnumPropertyItem rna_enum_draw_style[] = {
+ {ED_GIZMO_MOVE_STYLE_RING_2D, "RING_2D", 0, "Ring", ""},
+ {ED_GIZMO_MOVE_STYLE_CROSS_2D, "CROSS_2D", 0, "Ring", ""},
+ {0, NULL, 0, NULL, NULL},
+ };
+ static EnumPropertyItem rna_enum_draw_options[] = {
+ {ED_GIZMO_MOVE_DRAW_FLAG_FILL, "FILL", 0, "Filled", ""},
+ {ED_GIZMO_MOVE_DRAW_FLAG_FILL_SELECT, "FILL_SELECT", 0, "Use fill for selection test", ""},
+ {ED_GIZMO_MOVE_DRAW_FLAG_ALIGN_VIEW, "ALIGN_VIEW", 0, "Align View", ""},
+ {0, NULL, 0, NULL, NULL},
+ };
+
+ RNA_def_enum(
+ gzt->srna, "draw_style", rna_enum_draw_style, ED_GIZMO_MOVE_STYLE_RING_2D, "Draw Style", "");
+ RNA_def_enum_flag(gzt->srna, "draw_options", rna_enum_draw_options, 0, "Draw Options", "");
+ RNA_def_boolean(gzt->srna, "use_snap", false, "Use Snap", "");
+
+ WM_gizmotype_target_property_def(gzt, "offset", PROP_FLOAT, 3);
}
void ED_gizmotypes_move_3d(void)
{
- WM_gizmotype_append(GIZMO_GT_move_3d);
+ WM_gizmotype_append(GIZMO_GT_move_3d);
}
-/** \} */ // Move Gizmo API
+/** \} */ // Move Gizmo API
diff --git a/source/blender/editors/gizmo_library/gizmo_types/primitive3d_gizmo.c b/source/blender/editors/gizmo_library/gizmo_types/primitive3d_gizmo.c
index 2b13398dc4c..48b2e3348c9 100644
--- a/source/blender/editors/gizmo_library/gizmo_types/primitive3d_gizmo.c
+++ b/source/blender/editors/gizmo_library/gizmo_types/primitive3d_gizmo.c
@@ -33,7 +33,6 @@
#include "BKE_context.h"
-
#include "GPU_immediate.h"
#include "GPU_matrix.h"
#include "GPU_select.h"
@@ -51,106 +50,101 @@
#include "../gizmo_library_intern.h"
static float verts_plane[4][3] = {
- {-1, -1, 0},
- { 1, -1, 0},
- { 1, 1, 0},
- {-1, 1, 0},
+ {-1, -1, 0},
+ {1, -1, 0},
+ {1, 1, 0},
+ {-1, 1, 0},
};
-
/* -------------------------------------------------------------------- */
-static void gizmo_primitive_draw_geom(
- const float col_inner[4], const float col_outer[4], const int draw_style)
+static void gizmo_primitive_draw_geom(const float col_inner[4],
+ const float col_outer[4],
+ const int draw_style)
{
- float (*verts)[3];
- uint vert_count = 0;
-
- if (draw_style == ED_GIZMO_PRIMITIVE_STYLE_PLANE) {
- verts = verts_plane;
- vert_count = ARRAY_SIZE(verts_plane);
- }
-
- if (vert_count > 0) {
- uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
- immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
- wm_gizmo_vec_draw(col_inner, verts, vert_count, pos, GPU_PRIM_TRI_FAN);
- wm_gizmo_vec_draw(col_outer, verts, vert_count, pos, GPU_PRIM_LINE_LOOP);
- immUnbindProgram();
- }
+ float(*verts)[3];
+ uint vert_count = 0;
+
+ if (draw_style == ED_GIZMO_PRIMITIVE_STYLE_PLANE) {
+ verts = verts_plane;
+ vert_count = ARRAY_SIZE(verts_plane);
+ }
+
+ if (vert_count > 0) {
+ uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+ wm_gizmo_vec_draw(col_inner, verts, vert_count, pos, GPU_PRIM_TRI_FAN);
+ wm_gizmo_vec_draw(col_outer, verts, vert_count, pos, GPU_PRIM_LINE_LOOP);
+ immUnbindProgram();
+ }
}
-static void gizmo_primitive_draw_intern(
- wmGizmo *gz, const bool UNUSED(select),
- const bool highlight)
+static void gizmo_primitive_draw_intern(wmGizmo *gz,
+ const bool UNUSED(select),
+ const bool highlight)
{
- float color_inner[4], color_outer[4];
- float matrix_final[4][4];
- const int draw_style = RNA_enum_get(gz->ptr, "draw_style");
+ float color_inner[4], color_outer[4];
+ float matrix_final[4][4];
+ const int draw_style = RNA_enum_get(gz->ptr, "draw_style");
- gizmo_color_get(gz, highlight, color_outer);
- copy_v4_v4(color_inner, color_outer);
- color_inner[3] *= 0.5f;
+ gizmo_color_get(gz, highlight, color_outer);
+ copy_v4_v4(color_inner, color_outer);
+ color_inner[3] *= 0.5f;
- WM_gizmo_calc_matrix_final(gz, matrix_final);
+ WM_gizmo_calc_matrix_final(gz, matrix_final);
- GPU_matrix_push();
- GPU_matrix_mul(matrix_final);
+ GPU_matrix_push();
+ GPU_matrix_mul(matrix_final);
- GPU_blend(true);
- gizmo_primitive_draw_geom(color_inner, color_outer, draw_style);
- GPU_blend(false);
+ GPU_blend(true);
+ gizmo_primitive_draw_geom(color_inner, color_outer, draw_style);
+ GPU_blend(false);
- GPU_matrix_pop();
+ GPU_matrix_pop();
- if (gz->interaction_data) {
- GizmoInteraction *inter = gz->interaction_data;
+ if (gz->interaction_data) {
+ GizmoInteraction *inter = gz->interaction_data;
- copy_v4_fl(color_inner, 0.5f);
- copy_v3_fl(color_outer, 0.5f);
- color_outer[3] = 0.8f;
+ copy_v4_fl(color_inner, 0.5f);
+ copy_v3_fl(color_outer, 0.5f);
+ color_outer[3] = 0.8f;
- GPU_matrix_push();
- GPU_matrix_mul(inter->init_matrix_final);
+ GPU_matrix_push();
+ GPU_matrix_mul(inter->init_matrix_final);
- GPU_blend(true);
- gizmo_primitive_draw_geom(color_inner, color_outer, draw_style);
- GPU_blend(false);
+ GPU_blend(true);
+ gizmo_primitive_draw_geom(color_inner, color_outer, draw_style);
+ GPU_blend(false);
- GPU_matrix_pop();
- }
+ GPU_matrix_pop();
+ }
}
-static void gizmo_primitive_draw_select(
- const bContext *UNUSED(C), wmGizmo *gz,
- int select_id)
+static void gizmo_primitive_draw_select(const bContext *UNUSED(C), wmGizmo *gz, int select_id)
{
- GPU_select_load_id(select_id);
- gizmo_primitive_draw_intern(gz, true, false);
+ GPU_select_load_id(select_id);
+ gizmo_primitive_draw_intern(gz, true, false);
}
static void gizmo_primitive_draw(const bContext *UNUSED(C), wmGizmo *gz)
{
- gizmo_primitive_draw_intern(
- gz, false,
- (gz->state & WM_GIZMO_STATE_HIGHLIGHT));
+ gizmo_primitive_draw_intern(gz, false, (gz->state & WM_GIZMO_STATE_HIGHLIGHT));
}
static void gizmo_primitive_setup(wmGizmo *gz)
{
- gz->flag |= WM_GIZMO_DRAW_MODAL;
+ gz->flag |= WM_GIZMO_DRAW_MODAL;
}
-static int gizmo_primitive_invoke(
- bContext *UNUSED(C), wmGizmo *gz, const wmEvent *UNUSED(event))
+static int gizmo_primitive_invoke(bContext *UNUSED(C), wmGizmo *gz, const wmEvent *UNUSED(event))
{
- GizmoInteraction *inter = MEM_callocN(sizeof(GizmoInteraction), __func__);
+ GizmoInteraction *inter = MEM_callocN(sizeof(GizmoInteraction), __func__);
- WM_gizmo_calc_matrix_final(gz, inter->init_matrix_final);
+ WM_gizmo_calc_matrix_final(gz, inter->init_matrix_final);
- gz->interaction_data = inter;
+ gz->interaction_data = inter;
- return OPERATOR_RUNNING_MODAL;
+ return OPERATOR_RUNNING_MODAL;
}
/* -------------------------------------------------------------------- */
@@ -160,27 +154,32 @@ static int gizmo_primitive_invoke(
static void GIZMO_GT_primitive_3d(wmGizmoType *gzt)
{
- /* identifiers */
- gzt->idname = "GIZMO_GT_primitive_3d";
-
- /* api callbacks */
- gzt->draw = gizmo_primitive_draw;
- gzt->draw_select = gizmo_primitive_draw_select;
- gzt->setup = gizmo_primitive_setup;
- gzt->invoke = gizmo_primitive_invoke;
-
- gzt->struct_size = sizeof(wmGizmo);
-
- static EnumPropertyItem rna_enum_draw_style[] = {
- {ED_GIZMO_PRIMITIVE_STYLE_PLANE, "PLANE", 0, "Plane", ""},
- {0, NULL, 0, NULL, NULL},
- };
- RNA_def_enum(gzt->srna, "draw_style", rna_enum_draw_style, ED_GIZMO_PRIMITIVE_STYLE_PLANE, "Draw Style", "");
+ /* identifiers */
+ gzt->idname = "GIZMO_GT_primitive_3d";
+
+ /* api callbacks */
+ gzt->draw = gizmo_primitive_draw;
+ gzt->draw_select = gizmo_primitive_draw_select;
+ gzt->setup = gizmo_primitive_setup;
+ gzt->invoke = gizmo_primitive_invoke;
+
+ gzt->struct_size = sizeof(wmGizmo);
+
+ static EnumPropertyItem rna_enum_draw_style[] = {
+ {ED_GIZMO_PRIMITIVE_STYLE_PLANE, "PLANE", 0, "Plane", ""},
+ {0, NULL, 0, NULL, NULL},
+ };
+ RNA_def_enum(gzt->srna,
+ "draw_style",
+ rna_enum_draw_style,
+ ED_GIZMO_PRIMITIVE_STYLE_PLANE,
+ "Draw Style",
+ "");
}
void ED_gizmotypes_primitive_3d(void)
{
- WM_gizmotype_append(GIZMO_GT_primitive_3d);
+ WM_gizmotype_append(GIZMO_GT_primitive_3d);
}
/** \} */
diff --git a/source/blender/editors/gizmo_library/gizmo_types/value2d_gizmo.c b/source/blender/editors/gizmo_library/gizmo_types/value2d_gizmo.c
index 9854b62dade..059d3acbd9c 100644
--- a/source/blender/editors/gizmo_library/gizmo_types/value2d_gizmo.c
+++ b/source/blender/editors/gizmo_library/gizmo_types/value2d_gizmo.c
@@ -55,110 +55,108 @@
* \{ */
typedef struct ValueInteraction {
- struct {
- float mval[2];
- float prop_value;
- } init;
- struct {
- float prop_value;
- eWM_GizmoFlagTweak tweak_flag;
- } prev;
- float range[2];
+ struct {
+ float mval[2];
+ float prop_value;
+ } init;
+ struct {
+ float prop_value;
+ eWM_GizmoFlagTweak tweak_flag;
+ } prev;
+ float range[2];
} ValueInteraction;
static void gizmo_value_draw(const bContext *UNUSED(C), wmGizmo *UNUSED(gz))
{
- /* pass */
+ /* pass */
}
-static int gizmo_value_modal(
- bContext *C, wmGizmo *gz, const wmEvent *event,
- eWM_GizmoFlagTweak tweak_flag)
+static int gizmo_value_modal(bContext *C,
+ wmGizmo *gz,
+ const wmEvent *event,
+ eWM_GizmoFlagTweak tweak_flag)
{
- ValueInteraction *inter = gz->interaction_data;
- if ((event->type != MOUSEMOVE) && (inter->prev.tweak_flag == tweak_flag)) {
- return OPERATOR_RUNNING_MODAL;
- }
- ARegion *ar = CTX_wm_region(C);
- const float value_scale = 4.0f; /* Could be option. */
- const float value_range = inter->range[1] - inter->range[0];
- float value_delta = (
- inter->init.prop_value +
- (((event->mval[0] - inter->init.mval[0]) / ar->winx) * value_range)) * value_scale;
-
-
- if (tweak_flag & WM_GIZMO_TWEAK_SNAP) {
- const double snap = 0.1;
- value_delta = (float)roundf((double)value_delta / snap) * snap;
-
- }
- if (tweak_flag & WM_GIZMO_TWEAK_PRECISE) {
- value_delta *= 0.1f;
- }
- const float value_final = inter->init.prop_value + value_delta;
-
- if (value_final != inter->prev.prop_value) {
- /* set the property for the operator and call its modal function */
- wmGizmoProperty *gz_prop = WM_gizmo_target_property_find(gz, "offset");
- if (WM_gizmo_target_property_is_valid(gz_prop)) {
- WM_gizmo_target_property_float_set(C, gz, gz_prop, value_final);
- }
-
- {
- ScrArea *sa = CTX_wm_area(C);
- char str[64];
- SNPRINTF(str, "%.4f", value_final);
- ED_area_status_text(sa, str);
- }
- }
-
- inter->prev.prop_value = value_final;
- inter->prev.tweak_flag = tweak_flag;
-
- return OPERATOR_RUNNING_MODAL;
+ ValueInteraction *inter = gz->interaction_data;
+ if ((event->type != MOUSEMOVE) && (inter->prev.tweak_flag == tweak_flag)) {
+ return OPERATOR_RUNNING_MODAL;
+ }
+ ARegion *ar = CTX_wm_region(C);
+ const float value_scale = 4.0f; /* Could be option. */
+ const float value_range = inter->range[1] - inter->range[0];
+ float value_delta = (inter->init.prop_value +
+ (((event->mval[0] - inter->init.mval[0]) / ar->winx) * value_range)) *
+ value_scale;
+
+ if (tweak_flag & WM_GIZMO_TWEAK_SNAP) {
+ const double snap = 0.1;
+ value_delta = (float)roundf((double)value_delta / snap) * snap;
+ }
+ if (tweak_flag & WM_GIZMO_TWEAK_PRECISE) {
+ value_delta *= 0.1f;
+ }
+ const float value_final = inter->init.prop_value + value_delta;
+
+ if (value_final != inter->prev.prop_value) {
+ /* set the property for the operator and call its modal function */
+ wmGizmoProperty *gz_prop = WM_gizmo_target_property_find(gz, "offset");
+ if (WM_gizmo_target_property_is_valid(gz_prop)) {
+ WM_gizmo_target_property_float_set(C, gz, gz_prop, value_final);
+ }
+
+ {
+ ScrArea *sa = CTX_wm_area(C);
+ char str[64];
+ SNPRINTF(str, "%.4f", value_final);
+ ED_area_status_text(sa, str);
+ }
+ }
+
+ inter->prev.prop_value = value_final;
+ inter->prev.tweak_flag = tweak_flag;
+
+ return OPERATOR_RUNNING_MODAL;
}
-
-static int gizmo_value_invoke(
- bContext *UNUSED(C), wmGizmo *gz, const wmEvent *event)
+static int gizmo_value_invoke(bContext *UNUSED(C), wmGizmo *gz, const wmEvent *event)
{
- ValueInteraction *inter = MEM_callocN(sizeof(ValueInteraction), __func__);
+ ValueInteraction *inter = MEM_callocN(sizeof(ValueInteraction), __func__);
- inter->init.mval[0] = event->mval[0];
- inter->init.mval[1] = event->mval[1];
- inter->prev.prop_value = -FLT_MAX;
+ inter->init.mval[0] = event->mval[0];
+ inter->init.mval[1] = event->mval[1];
+ inter->prev.prop_value = -FLT_MAX;
- wmGizmoProperty *gz_prop = WM_gizmo_target_property_find(gz, "offset");
- if (WM_gizmo_target_property_is_valid(gz_prop)) {
- inter->init.prop_value = WM_gizmo_target_property_float_get(gz, gz_prop);
- if (!WM_gizmo_target_property_float_range_get(gz, gz_prop, inter->range)) {
- inter->range[0] = 0.0f;
- inter->range[1] = 1.0f;
- }
- }
+ wmGizmoProperty *gz_prop = WM_gizmo_target_property_find(gz, "offset");
+ if (WM_gizmo_target_property_is_valid(gz_prop)) {
+ inter->init.prop_value = WM_gizmo_target_property_float_get(gz, gz_prop);
+ if (!WM_gizmo_target_property_float_range_get(gz, gz_prop, inter->range)) {
+ inter->range[0] = 0.0f;
+ inter->range[1] = 1.0f;
+ }
+ }
- gz->interaction_data = inter;
+ gz->interaction_data = inter;
- return OPERATOR_RUNNING_MODAL;
+ return OPERATOR_RUNNING_MODAL;
}
static void gizmo_value_exit(bContext *C, wmGizmo *gz, const bool cancel)
{
- ScrArea *sa = CTX_wm_area(C);
- ED_area_status_text(sa, NULL);
- if (cancel) {
- ValueInteraction *inter = gz->interaction_data;
- wmGizmoProperty *gz_prop = WM_gizmo_target_property_find(gz, "offset");
- if (WM_gizmo_target_property_is_valid(gz_prop)) {
- WM_gizmo_target_property_float_set(C, gz, gz_prop, inter->init.prop_value);
- }
- }
+ ScrArea *sa = CTX_wm_area(C);
+ ED_area_status_text(sa, NULL);
+ if (cancel) {
+ ValueInteraction *inter = gz->interaction_data;
+ wmGizmoProperty *gz_prop = WM_gizmo_target_property_find(gz, "offset");
+ if (WM_gizmo_target_property_is_valid(gz_prop)) {
+ WM_gizmo_target_property_float_set(C, gz, gz_prop, inter->init.prop_value);
+ }
+ }
}
-static int gizmo_value_test_select(
- bContext *UNUSED(C), wmGizmo *UNUSED(gz), const int UNUSED(mval[2]))
+static int gizmo_value_test_select(bContext *UNUSED(C),
+ wmGizmo *UNUSED(gz),
+ const int UNUSED(mval[2]))
{
- return 0;
+ return 0;
}
/** \} */
@@ -170,25 +168,25 @@ static int gizmo_value_test_select(
static void GIZMO_GT_value_2d(wmGizmoType *gzt)
{
- /* identifiers */
- gzt->idname = "GIZMO_GT_value_2d";
+ /* identifiers */
+ gzt->idname = "GIZMO_GT_value_2d";
- /* api callbacks */
- gzt->draw = gizmo_value_draw;
- gzt->invoke = gizmo_value_invoke;
- gzt->exit = gizmo_value_exit;
- gzt->modal = gizmo_value_modal;
- gzt->test_select = gizmo_value_test_select;
+ /* api callbacks */
+ gzt->draw = gizmo_value_draw;
+ gzt->invoke = gizmo_value_invoke;
+ gzt->exit = gizmo_value_exit;
+ gzt->modal = gizmo_value_modal;
+ gzt->test_select = gizmo_value_test_select;
- gzt->struct_size = sizeof(wmGizmo);
+ gzt->struct_size = sizeof(wmGizmo);
- WM_gizmotype_target_property_def(gzt, "offset", PROP_FLOAT, 1);
- /* Options: relative / absolute */
+ WM_gizmotype_target_property_def(gzt, "offset", PROP_FLOAT, 1);
+ /* Options: relative / absolute */
}
void ED_gizmotypes_value_2d(void)
{
- WM_gizmotype_append(GIZMO_GT_value_2d);
+ WM_gizmotype_append(GIZMO_GT_value_2d);
}
/** \} */