From e12c08e8d170b7ca40f204a5b0423c23a9fbc2c1 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 17 Apr 2019 06:17:24 +0200 Subject: ClangFormat: apply to source, most of intern Apply clang format as proposed in T53211. For details on usage and instructions for migrating branches without conflicts, see: https://wiki.blender.org/wiki/Tools/ClangFormat --- .../blender/editors/gizmo_library/CMakeLists.txt | 66 +- .../gizmo_library/geometry/geom_arrow_gizmo.c | 138 +- .../gizmo_library/geometry/geom_cube_gizmo.c | 56 +- .../gizmo_library/geometry/geom_dial_gizmo.c | 1031 +++-------- .../editors/gizmo_library/gizmo_draw_utils.c | 78 +- .../blender/editors/gizmo_library/gizmo_geometry.h | 13 +- .../gizmo_group_types/value2d_gizmo_group.c | 153 +- .../editors/gizmo_library/gizmo_library_intern.h | 97 +- .../editors/gizmo_library/gizmo_library_presets.c | 120 +- .../editors/gizmo_library/gizmo_library_utils.c | 329 ++-- .../gizmo_library/gizmo_types/arrow2d_gizmo.c | 229 +-- .../gizmo_library/gizmo_types/arrow3d_gizmo.c | 641 ++++--- .../gizmo_library/gizmo_types/blank3d_gizmo.c | 34 +- .../gizmo_library/gizmo_types/button2d_gizmo.c | 401 ++-- .../gizmo_library/gizmo_types/cage2d_gizmo.c | 1925 ++++++++++---------- .../gizmo_library/gizmo_types/cage3d_gizmo.c | 1011 +++++----- .../gizmo_library/gizmo_types/dial3d_gizmo.c | 955 +++++----- .../gizmo_library/gizmo_types/move3d_gizmo.c | 648 +++---- .../gizmo_library/gizmo_types/primitive3d_gizmo.c | 165 +- .../gizmo_library/gizmo_types/value2d_gizmo.c | 188 +- 20 files changed, 3925 insertions(+), 4353 deletions(-) (limited to 'source/blender/editors/gizmo_library') diff --git a/source/blender/editors/gizmo_library/CMakeLists.txt b/source/blender/editors/gizmo_library/CMakeLists.txt index 0d2d9446889..8b035d3207d 100644 --- a/source/blender/editors/gizmo_library/CMakeLists.txt +++ b/source/blender/editors/gizmo_library/CMakeLists.txt @@ -17,45 +17,45 @@ # ***** END GPL LICENSE BLOCK ***** set(INC - ../include - ../../blenkernel - ../../blenlib - ../../blentranslation - ../../bmesh - ../../depsgraph - ../../gpu - ../../makesdna - ../../makesrna - ../../windowmanager - ../../../../intern/guardedalloc - ../../../../intern/eigen - ../../../../intern/glew-mx + ../include + ../../blenkernel + ../../blenlib + ../../blentranslation + ../../bmesh + ../../depsgraph + ../../gpu + ../../makesdna + ../../makesrna + ../../windowmanager + ../../../../intern/guardedalloc + ../../../../intern/eigen + ../../../../intern/glew-mx ) set(INC_SYS - ${GLEW_INCLUDE_PATH} + ${GLEW_INCLUDE_PATH} ) set(SRC - gizmo_draw_utils.c - gizmo_geometry.h - gizmo_library_intern.h - gizmo_library_presets.c - gizmo_library_utils.c - geometry/geom_arrow_gizmo.c - geometry/geom_cube_gizmo.c - geometry/geom_dial_gizmo.c - gizmo_group_types/value2d_gizmo_group.c - gizmo_types/arrow2d_gizmo.c - gizmo_types/arrow3d_gizmo.c - gizmo_types/blank3d_gizmo.c - gizmo_types/button2d_gizmo.c - gizmo_types/cage2d_gizmo.c - gizmo_types/cage3d_gizmo.c - gizmo_types/dial3d_gizmo.c - gizmo_types/move3d_gizmo.c - gizmo_types/primitive3d_gizmo.c - gizmo_types/value2d_gizmo.c + gizmo_draw_utils.c + gizmo_geometry.h + gizmo_library_intern.h + gizmo_library_presets.c + gizmo_library_utils.c + geometry/geom_arrow_gizmo.c + geometry/geom_cube_gizmo.c + geometry/geom_dial_gizmo.c + gizmo_group_types/value2d_gizmo_group.c + gizmo_types/arrow2d_gizmo.c + gizmo_types/arrow3d_gizmo.c + gizmo_types/blank3d_gizmo.c + gizmo_types/button2d_gizmo.c + gizmo_types/cage2d_gizmo.c + gizmo_types/cage3d_gizmo.c + gizmo_types/dial3d_gizmo.c + gizmo_types/move3d_gizmo.c + gizmo_types/primitive3d_gizmo.c + gizmo_types/value2d_gizmo.c ) set(LIB diff --git a/source/blender/editors/gizmo_library/geometry/geom_arrow_gizmo.c b/source/blender/editors/gizmo_library/geometry/geom_arrow_gizmo.c index d62d397c783..90196988d94 100644 --- a/source/blender/editors/gizmo_library/geometry/geom_arrow_gizmo.c +++ b/source/blender/editors/gizmo_library/geometry/geom_arrow_gizmo.c @@ -24,114 +24,50 @@ #include "../gizmo_geometry.h" static float verts[][3] = { - {-0.000000, 0.012320, 0.000000}, - {-0.000000, 0.012320, 0.974306}, - {0.008711, 0.008711, 0.000000}, - {0.008711, 0.008711, 0.974306}, - {0.012320, -0.000000, 0.000000}, - {0.012320, -0.000000, 0.974306}, - {0.008711, -0.008711, 0.000000}, - {0.008711, -0.008711, 0.974306}, - {-0.000000, -0.012320, 0.000000}, - {-0.000000, -0.012320, 0.974306}, - {-0.008711, -0.008711, 0.000000}, - {-0.008711, -0.008711, 0.974306}, - {-0.012320, 0.000000, 0.000000}, - {-0.012320, 0.000000, 0.974306}, - {-0.008711, 0.008711, 0.000000}, - {-0.008711, 0.008711, 0.974306}, - {0.000000, 0.072555, 0.974306}, - {0.051304, 0.051304, 0.974306}, - {0.072555, -0.000000, 0.974306}, - {0.051304, -0.051304, 0.974306}, - {-0.000000, -0.072555, 0.974306}, - {-0.051304, -0.051304, 0.974306}, - {-0.072555, 0.000000, 0.974306}, - {-0.051304, 0.051304, 0.974306}, - {0.000000, -0.000000, 1.268098}, + {-0.000000, 0.012320, 0.000000}, {-0.000000, 0.012320, 0.974306}, + {0.008711, 0.008711, 0.000000}, {0.008711, 0.008711, 0.974306}, + {0.012320, -0.000000, 0.000000}, {0.012320, -0.000000, 0.974306}, + {0.008711, -0.008711, 0.000000}, {0.008711, -0.008711, 0.974306}, + {-0.000000, -0.012320, 0.000000}, {-0.000000, -0.012320, 0.974306}, + {-0.008711, -0.008711, 0.000000}, {-0.008711, -0.008711, 0.974306}, + {-0.012320, 0.000000, 0.000000}, {-0.012320, 0.000000, 0.974306}, + {-0.008711, 0.008711, 0.000000}, {-0.008711, 0.008711, 0.974306}, + {0.000000, 0.072555, 0.974306}, {0.051304, 0.051304, 0.974306}, + {0.072555, -0.000000, 0.974306}, {0.051304, -0.051304, 0.974306}, + {-0.000000, -0.072555, 0.974306}, {-0.051304, -0.051304, 0.974306}, + {-0.072555, 0.000000, 0.974306}, {-0.051304, 0.051304, 0.974306}, + {0.000000, -0.000000, 1.268098}, }; static float normals[][3] = { - {0.000000, 0.776360, -0.630238}, - {0.000000, 0.594348, -0.804163}, - {0.548967, 0.548967, -0.630238}, - {0.420270, 0.420270, -0.804163}, - {0.776360, 0.000000, -0.630238}, - {0.594378, 0.000000, -0.804163}, - {0.548967, -0.548967, -0.630238}, - {0.420270, -0.420270, -0.804163}, - {0.000000, -0.776360, -0.630238}, - {0.000000, -0.594378, -0.804163}, - {-0.548967, -0.548967, -0.630238}, - {-0.420270, -0.420270, -0.804163}, - {-0.776360, 0.000000, -0.630238}, - {-0.594378, 0.000000, -0.804163}, - {-0.548967, 0.548967, -0.630238}, - {-0.420270, 0.420270, -0.804163}, - {0.000000, 0.843226, -0.537492}, - {0.596271, 0.596271, -0.537492}, - {0.843226, 0.000000, -0.537492}, - {0.596271, -0.596271, -0.537492}, - {0.000000, -0.843226, -0.537492}, - {-0.596271, -0.596271, -0.537492}, - {-0.843226, 0.000000, -0.537492}, - {-0.596271, 0.596271, -0.537492}, - {0.000000, 0.000000, 1.000000}, + {0.000000, 0.776360, -0.630238}, {0.000000, 0.594348, -0.804163}, + {0.548967, 0.548967, -0.630238}, {0.420270, 0.420270, -0.804163}, + {0.776360, 0.000000, -0.630238}, {0.594378, 0.000000, -0.804163}, + {0.548967, -0.548967, -0.630238}, {0.420270, -0.420270, -0.804163}, + {0.000000, -0.776360, -0.630238}, {0.000000, -0.594378, -0.804163}, + {-0.548967, -0.548967, -0.630238}, {-0.420270, -0.420270, -0.804163}, + {-0.776360, 0.000000, -0.630238}, {-0.594378, 0.000000, -0.804163}, + {-0.548967, 0.548967, -0.630238}, {-0.420270, 0.420270, -0.804163}, + {0.000000, 0.843226, -0.537492}, {0.596271, 0.596271, -0.537492}, + {0.843226, 0.000000, -0.537492}, {0.596271, -0.596271, -0.537492}, + {0.000000, -0.843226, -0.537492}, {-0.596271, -0.596271, -0.537492}, + {-0.843226, 0.000000, -0.537492}, {-0.596271, 0.596271, -0.537492}, + {0.000000, 0.000000, 1.000000}, }; static unsigned short indices[] = { - 1, 3, 2, - 3, 5, 4, - 5, 7, 6, - 7, 9, 8, - 9, 11, 10, - 11, 13, 12, - 5, 18, 19, - 15, 1, 0, - 13, 15, 14, - 6, 10, 14, - 11, 21, 22, - 7, 19, 20, - 13, 22, 23, - 3, 17, 18, - 9, 20, 21, - 15, 23, 16, - 1, 16, 17, - 23, 22, 24, - 21, 20, 24, - 19, 18, 24, - 17, 16, 24, - 16, 23, 24, - 22, 21, 24, - 20, 19, 24, - 18, 17, 24, - 0, 1, 2, - 2, 3, 4, - 4, 5, 6, - 6, 7, 8, - 8, 9, 10, - 10, 11, 12, - 7, 5, 19, - 14, 15, 0, - 12, 13, 14, - 14, 0, 2, - 2, 4, 6, - 6, 8, 10, - 10, 12, 14, - 14, 2, 6, - 13, 11, 22, - 9, 7, 20, - 15, 13, 23, - 5, 3, 18, - 11, 9, 21, - 1, 15, 16, - 3, 1, 17, + 1, 3, 2, 3, 5, 4, 5, 7, 6, 7, 9, 8, 9, 11, 10, 11, 13, 12, 5, 18, 19, 15, 1, + 0, 13, 15, 14, 6, 10, 14, 11, 21, 22, 7, 19, 20, 13, 22, 23, 3, 17, 18, 9, 20, 21, 15, + 23, 16, 1, 16, 17, 23, 22, 24, 21, 20, 24, 19, 18, 24, 17, 16, 24, 16, 23, 24, 22, 21, 24, + 20, 19, 24, 18, 17, 24, 0, 1, 2, 2, 3, 4, 4, 5, 6, 6, 7, 8, 8, 9, 10, 10, 11, + 12, 7, 5, 19, 14, 15, 0, 12, 13, 14, 14, 0, 2, 2, 4, 6, 6, 8, 10, 10, 12, 14, 14, + 2, 6, 13, 11, 22, 9, 7, 20, 15, 13, 23, 5, 3, 18, 11, 9, 21, 1, 15, 16, 3, 1, 17, }; GizmoGeomInfo wm_gizmo_geom_data_arrow = { - .nverts = 25, - .ntris = 46, - .verts = verts, - .normals = normals, - .indices = indices, + .nverts = 25, + .ntris = 46, + .verts = verts, + .normals = normals, + .indices = indices, }; diff --git a/source/blender/editors/gizmo_library/geometry/geom_cube_gizmo.c b/source/blender/editors/gizmo_library/geometry/geom_cube_gizmo.c index e89d20a41bd..ea1a3147148 100644 --- a/source/blender/editors/gizmo_library/geometry/geom_cube_gizmo.c +++ b/source/blender/editors/gizmo_library/geometry/geom_cube_gizmo.c @@ -24,46 +24,36 @@ #include "../gizmo_geometry.h" static const float verts[][3] = { - {1.000000, 1.000000, -1.000000}, - {1.000000, -1.000000, -1.000000}, - {-1.000000, -1.000000, -1.000000}, - {-1.000000, 1.000000, -1.000000}, - {1.000000, 1.000000, 1.000000}, - {0.999999, -1.000001, 1.000000}, - {-1.000000, -1.000000, 1.000000}, - {-1.000000, 1.000000, 1.000000}, + {1.000000, 1.000000, -1.000000}, + {1.000000, -1.000000, -1.000000}, + {-1.000000, -1.000000, -1.000000}, + {-1.000000, 1.000000, -1.000000}, + {1.000000, 1.000000, 1.000000}, + {0.999999, -1.000001, 1.000000}, + {-1.000000, -1.000000, 1.000000}, + {-1.000000, 1.000000, 1.000000}, }; static const float normals[][3] = { - {0.577349, 0.577349, -0.577349}, - {0.577349, -0.577349, -0.577349}, - {-0.577349, -0.577349, -0.577349}, - {-0.577349, 0.577349, -0.577349}, - {0.577349, 0.577349, 0.577349}, - {0.577349, -0.577349, 0.577349}, - {-0.577349, -0.577349, 0.577349}, - {-0.577349, 0.577349, 0.577349}, + {0.577349, 0.577349, -0.577349}, + {0.577349, -0.577349, -0.577349}, + {-0.577349, -0.577349, -0.577349}, + {-0.577349, 0.577349, -0.577349}, + {0.577349, 0.577349, 0.577349}, + {0.577349, -0.577349, 0.577349}, + {-0.577349, -0.577349, 0.577349}, + {-0.577349, 0.577349, 0.577349}, }; static const unsigned short indices[] = { - 1, 2, 3, - 7, 6, 5, - 4, 5, 1, - 5, 6, 2, - 2, 6, 7, - 0, 3, 7, - 0, 1, 3, - 4, 7, 5, - 0, 4, 1, - 1, 5, 2, - 3, 2, 7, - 4, 0, 7, + 1, 2, 3, 7, 6, 5, 4, 5, 1, 5, 6, 2, 2, 6, 7, 0, 3, 7, + 0, 1, 3, 4, 7, 5, 0, 4, 1, 1, 5, 2, 3, 2, 7, 4, 0, 7, }; GizmoGeomInfo wm_gizmo_geom_data_cube = { - .nverts = 8, - .ntris = 12, - .verts = verts, - .normals = normals, - .indices = indices, + .nverts = 8, + .ntris = 12, + .verts = verts, + .normals = normals, + .indices = indices, }; diff --git a/source/blender/editors/gizmo_library/geometry/geom_dial_gizmo.c b/source/blender/editors/gizmo_library/geometry/geom_dial_gizmo.c index 5ead50f67d1..273f957e9b6 100644 --- a/source/blender/editors/gizmo_library/geometry/geom_dial_gizmo.c +++ b/source/blender/editors/gizmo_library/geometry/geom_dial_gizmo.c @@ -24,786 +24,271 @@ #include "../gizmo_geometry.h" static const float verts[][3] = { - {1.034000, 0.000000, 0.000000}, - {1.017000, 0.000000, 0.029445}, - {0.983000, 0.000000, 0.029445}, - {0.966000, 0.000000, 0.000000}, - {0.983000, 0.000000, -0.029445}, - {1.017000, 0.000000, -0.029445}, - {1.014132, 0.201723, 0.000000}, - {0.997459, 0.198407, 0.029445}, - {0.964112, 0.191774, 0.029445}, - {0.947439, 0.188457, 0.000000}, - {0.964112, 0.191774, -0.029445}, - {0.997459, 0.198407, -0.029445}, - {0.955292, 0.395695, 0.000000}, - {0.939586, 0.389189, 0.029445}, - {0.908174, 0.376178, 0.029445}, - {0.892468, 0.369672, 0.000000}, - {0.908174, 0.376178, -0.029445}, - {0.939586, 0.389189, -0.029445}, - {0.859740, 0.574460, 0.000000}, - {0.845605, 0.565015, 0.029445}, - {0.817335, 0.546126, 0.029445}, - {0.803200, 0.536681, 0.000000}, - {0.817335, 0.546126, -0.029445}, - {0.845605, 0.565015, -0.029445}, - {0.731148, 0.731148, 0.000000}, - {0.719128, 0.719128, 0.029445}, - {0.695086, 0.695086, 0.029445}, - {0.683065, 0.683065, 0.000000}, - {0.695086, 0.695086, -0.029445}, - {0.719128, 0.719128, -0.029445}, - {0.574460, 0.859740, 0.000000}, - {0.565015, 0.845605, 0.029445}, - {0.546125, 0.817335, 0.029445}, - {0.536681, 0.803200, 0.000000}, - {0.546125, 0.817335, -0.029445}, - {0.565015, 0.845605, -0.029445}, - {0.395695, 0.955291, 0.000000}, - {0.389189, 0.939585, 0.029445}, - {0.376178, 0.908173, 0.029445}, - {0.369672, 0.892467, 0.000000}, - {0.376178, 0.908173, -0.029445}, - {0.389189, 0.939585, -0.029445}, - {0.201724, 1.014132, 0.000000}, - {0.198407, 0.997459, 0.029445}, - {0.191774, 0.964112, 0.029445}, - {0.188457, 0.947439, 0.000000}, - {0.191774, 0.964112, -0.029445}, - {0.198407, 0.997459, -0.029445}, - {0.000000, 1.034000, 0.000000}, - {0.000000, 1.017000, 0.029445}, - {0.000000, 0.983000, 0.029445}, - {0.000000, 0.966000, 0.000000}, - {0.000000, 0.983000, -0.029445}, - {0.000000, 1.017000, -0.029445}, - {-0.201723, 1.014132, 0.000000}, - {-0.198407, 0.997459, 0.029445}, - {-0.191774, 0.964112, 0.029445}, - {-0.188457, 0.947439, 0.000000}, - {-0.191774, 0.964112, -0.029445}, - {-0.198407, 0.997459, -0.029445}, - {-0.395695, 0.955291, 0.000000}, - {-0.389189, 0.939585, 0.029445}, - {-0.376178, 0.908174, 0.029445}, - {-0.369672, 0.892468, 0.000000}, - {-0.376178, 0.908174, -0.029445}, - {-0.389189, 0.939585, -0.029445}, - {-0.574459, 0.859740, 0.000000}, - {-0.565015, 0.845605, 0.029445}, - {-0.546125, 0.817335, 0.029445}, - {-0.536681, 0.803200, 0.000000}, - {-0.546125, 0.817335, -0.029445}, - {-0.565015, 0.845605, -0.029445}, - {-0.731149, 0.731148, 0.000000}, - {-0.719128, 0.719127, 0.029445}, - {-0.695086, 0.695086, 0.029445}, - {-0.683065, 0.683065, 0.000000}, - {-0.695086, 0.695086, -0.029445}, - {-0.719128, 0.719127, -0.029445}, - {-0.859740, 0.574460, 0.000000}, - {-0.845604, 0.565015, 0.029445}, - {-0.817335, 0.546126, 0.029445}, - {-0.803200, 0.536681, 0.000000}, - {-0.817335, 0.546126, -0.029445}, - {-0.845604, 0.565015, -0.029445}, - {-0.955291, 0.395695, 0.000000}, - {-0.939585, 0.389189, 0.029445}, - {-0.908173, 0.376178, 0.029445}, - {-0.892468, 0.369672, 0.000000}, - {-0.908173, 0.376178, -0.029445}, - {-0.939585, 0.389189, -0.029445}, - {-1.014132, 0.201723, 0.000000}, - {-0.997459, 0.198407, 0.029445}, - {-0.964112, 0.191774, 0.029445}, - {-0.947439, 0.188457, 0.000000}, - {-0.964112, 0.191774, -0.029445}, - {-0.997459, 0.198407, -0.029445}, - {-1.034000, 0.000000, 0.000000}, - {-1.017000, 0.000000, 0.029445}, - {-0.983000, 0.000000, 0.029445}, - {-0.966000, 0.000000, 0.000000}, - {-0.983000, 0.000000, -0.029445}, - {-1.017000, 0.000000, -0.029445}, - {-1.014132, -0.201723, 0.000000}, - {-0.997459, -0.198407, 0.029445}, - {-0.964112, -0.191774, 0.029445}, - {-0.947439, -0.188457, 0.000000}, - {-0.964112, -0.191774, -0.029445}, - {-0.997459, -0.198407, -0.029445}, - {-0.955292, -0.395694, 0.000000}, - {-0.939586, -0.389189, 0.029445}, - {-0.908174, -0.376177, 0.029445}, - {-0.892468, -0.369672, 0.000000}, - {-0.908174, -0.376177, -0.029445}, - {-0.939586, -0.389189, -0.029445}, - {-0.859740, -0.574460, 0.000000}, - {-0.845604, -0.565015, 0.029445}, - {-0.817335, -0.546126, 0.029445}, - {-0.803200, -0.536681, 0.000000}, - {-0.817335, -0.546126, -0.029445}, - {-0.845604, -0.565015, -0.029445}, - {-0.731149, -0.731148, 0.000000}, - {-0.719128, -0.719127, 0.029445}, - {-0.695086, -0.695086, 0.029445}, - {-0.683065, -0.683065, 0.000000}, - {-0.695086, -0.695086, -0.029445}, - {-0.719128, -0.719127, -0.029445}, - {-0.574460, -0.859739, 0.000000}, - {-0.565015, -0.845604, 0.029445}, - {-0.546126, -0.817334, 0.029445}, - {-0.536681, -0.803199, 0.000000}, - {-0.546126, -0.817334, -0.029445}, - {-0.565015, -0.845604, -0.029445}, - {-0.395695, -0.955291, 0.000000}, - {-0.389189, -0.939585, 0.029445}, - {-0.376178, -0.908174, 0.029445}, - {-0.369672, -0.892468, 0.000000}, - {-0.376178, -0.908174, -0.029445}, - {-0.389189, -0.939585, -0.029445}, - {-0.201724, -1.014132, 0.000000}, - {-0.198407, -0.997459, 0.029445}, - {-0.191774, -0.964112, 0.029445}, - {-0.188458, -0.947438, 0.000000}, - {-0.191774, -0.964112, -0.029445}, - {-0.198407, -0.997459, -0.029445}, - {0.000000, -1.034000, 0.000000}, - {0.000000, -1.017000, 0.029445}, - {0.000000, -0.983000, 0.029445}, - {0.000000, -0.966000, 0.000000}, - {0.000000, -0.983000, -0.029445}, - {0.000000, -1.017000, -0.029445}, - {0.201723, -1.014132, 0.000000}, - {0.198407, -0.997459, 0.029445}, - {0.191773, -0.964112, 0.029445}, - {0.188457, -0.947439, 0.000000}, - {0.191773, -0.964112, -0.029445}, - {0.198407, -0.997459, -0.029445}, - {0.395695, -0.955291, 0.000000}, - {0.389189, -0.939585, 0.029445}, - {0.376178, -0.908173, 0.029445}, - {0.369672, -0.892467, 0.000000}, - {0.376178, -0.908173, -0.029445}, - {0.389189, -0.939585, -0.029445}, - {0.574460, -0.859740, 0.000000}, - {0.565015, -0.845605, 0.029445}, - {0.546125, -0.817335, 0.029445}, - {0.536681, -0.803200, 0.000000}, - {0.546125, -0.817335, -0.029445}, - {0.565015, -0.845605, -0.029445}, - {0.731148, -0.731149, 0.000000}, - {0.719127, -0.719128, 0.029445}, - {0.695086, -0.695086, 0.029445}, - {0.683065, -0.683066, 0.000000}, - {0.695086, -0.695086, -0.029445}, - {0.719127, -0.719128, -0.029445}, - {0.859740, -0.574460, 0.000000}, - {0.845605, -0.565015, 0.029445}, - {0.817335, -0.546126, 0.029445}, - {0.803200, -0.536681, 0.000000}, - {0.817335, -0.546126, -0.029445}, - {0.845605, -0.565015, -0.029445}, - {0.955291, -0.395695, 0.000000}, - {0.939585, -0.389189, 0.029445}, - {0.908173, -0.376178, 0.029445}, - {0.892467, -0.369673, 0.000000}, - {0.908173, -0.376178, -0.029445}, - {0.939585, -0.389189, -0.029445}, - {1.014132, -0.201723, 0.000000}, - {0.997459, -0.198407, 0.029445}, - {0.964112, -0.191774, 0.029445}, - {0.947439, -0.188457, 0.000000}, - {0.964112, -0.191774, -0.029445}, - {0.997459, -0.198407, -0.029445}, + {1.034000, 0.000000, 0.000000}, {1.017000, 0.000000, 0.029445}, + {0.983000, 0.000000, 0.029445}, {0.966000, 0.000000, 0.000000}, + {0.983000, 0.000000, -0.029445}, {1.017000, 0.000000, -0.029445}, + {1.014132, 0.201723, 0.000000}, {0.997459, 0.198407, 0.029445}, + {0.964112, 0.191774, 0.029445}, {0.947439, 0.188457, 0.000000}, + {0.964112, 0.191774, -0.029445}, {0.997459, 0.198407, -0.029445}, + {0.955292, 0.395695, 0.000000}, {0.939586, 0.389189, 0.029445}, + {0.908174, 0.376178, 0.029445}, {0.892468, 0.369672, 0.000000}, + {0.908174, 0.376178, -0.029445}, {0.939586, 0.389189, -0.029445}, + {0.859740, 0.574460, 0.000000}, {0.845605, 0.565015, 0.029445}, + {0.817335, 0.546126, 0.029445}, {0.803200, 0.536681, 0.000000}, + {0.817335, 0.546126, -0.029445}, {0.845605, 0.565015, -0.029445}, + {0.731148, 0.731148, 0.000000}, {0.719128, 0.719128, 0.029445}, + {0.695086, 0.695086, 0.029445}, {0.683065, 0.683065, 0.000000}, + {0.695086, 0.695086, -0.029445}, {0.719128, 0.719128, -0.029445}, + {0.574460, 0.859740, 0.000000}, {0.565015, 0.845605, 0.029445}, + {0.546125, 0.817335, 0.029445}, {0.536681, 0.803200, 0.000000}, + {0.546125, 0.817335, -0.029445}, {0.565015, 0.845605, -0.029445}, + {0.395695, 0.955291, 0.000000}, {0.389189, 0.939585, 0.029445}, + {0.376178, 0.908173, 0.029445}, {0.369672, 0.892467, 0.000000}, + {0.376178, 0.908173, -0.029445}, {0.389189, 0.939585, -0.029445}, + {0.201724, 1.014132, 0.000000}, {0.198407, 0.997459, 0.029445}, + {0.191774, 0.964112, 0.029445}, {0.188457, 0.947439, 0.000000}, + {0.191774, 0.964112, -0.029445}, {0.198407, 0.997459, -0.029445}, + {0.000000, 1.034000, 0.000000}, {0.000000, 1.017000, 0.029445}, + {0.000000, 0.983000, 0.029445}, {0.000000, 0.966000, 0.000000}, + {0.000000, 0.983000, -0.029445}, {0.000000, 1.017000, -0.029445}, + {-0.201723, 1.014132, 0.000000}, {-0.198407, 0.997459, 0.029445}, + {-0.191774, 0.964112, 0.029445}, {-0.188457, 0.947439, 0.000000}, + {-0.191774, 0.964112, -0.029445}, {-0.198407, 0.997459, -0.029445}, + {-0.395695, 0.955291, 0.000000}, {-0.389189, 0.939585, 0.029445}, + {-0.376178, 0.908174, 0.029445}, {-0.369672, 0.892468, 0.000000}, + {-0.376178, 0.908174, -0.029445}, {-0.389189, 0.939585, -0.029445}, + {-0.574459, 0.859740, 0.000000}, {-0.565015, 0.845605, 0.029445}, + {-0.546125, 0.817335, 0.029445}, {-0.536681, 0.803200, 0.000000}, + {-0.546125, 0.817335, -0.029445}, {-0.565015, 0.845605, -0.029445}, + {-0.731149, 0.731148, 0.000000}, {-0.719128, 0.719127, 0.029445}, + {-0.695086, 0.695086, 0.029445}, {-0.683065, 0.683065, 0.000000}, + {-0.695086, 0.695086, -0.029445}, {-0.719128, 0.719127, -0.029445}, + {-0.859740, 0.574460, 0.000000}, {-0.845604, 0.565015, 0.029445}, + {-0.817335, 0.546126, 0.029445}, {-0.803200, 0.536681, 0.000000}, + {-0.817335, 0.546126, -0.029445}, {-0.845604, 0.565015, -0.029445}, + {-0.955291, 0.395695, 0.000000}, {-0.939585, 0.389189, 0.029445}, + {-0.908173, 0.376178, 0.029445}, {-0.892468, 0.369672, 0.000000}, + {-0.908173, 0.376178, -0.029445}, {-0.939585, 0.389189, -0.029445}, + {-1.014132, 0.201723, 0.000000}, {-0.997459, 0.198407, 0.029445}, + {-0.964112, 0.191774, 0.029445}, {-0.947439, 0.188457, 0.000000}, + {-0.964112, 0.191774, -0.029445}, {-0.997459, 0.198407, -0.029445}, + {-1.034000, 0.000000, 0.000000}, {-1.017000, 0.000000, 0.029445}, + {-0.983000, 0.000000, 0.029445}, {-0.966000, 0.000000, 0.000000}, + {-0.983000, 0.000000, -0.029445}, {-1.017000, 0.000000, -0.029445}, + {-1.014132, -0.201723, 0.000000}, {-0.997459, -0.198407, 0.029445}, + {-0.964112, -0.191774, 0.029445}, {-0.947439, -0.188457, 0.000000}, + {-0.964112, -0.191774, -0.029445}, {-0.997459, -0.198407, -0.029445}, + {-0.955292, -0.395694, 0.000000}, {-0.939586, -0.389189, 0.029445}, + {-0.908174, -0.376177, 0.029445}, {-0.892468, -0.369672, 0.000000}, + {-0.908174, -0.376177, -0.029445}, {-0.939586, -0.389189, -0.029445}, + {-0.859740, -0.574460, 0.000000}, {-0.845604, -0.565015, 0.029445}, + {-0.817335, -0.546126, 0.029445}, {-0.803200, -0.536681, 0.000000}, + {-0.817335, -0.546126, -0.029445}, {-0.845604, -0.565015, -0.029445}, + {-0.731149, -0.731148, 0.000000}, {-0.719128, -0.719127, 0.029445}, + {-0.695086, -0.695086, 0.029445}, {-0.683065, -0.683065, 0.000000}, + {-0.695086, -0.695086, -0.029445}, {-0.719128, -0.719127, -0.029445}, + {-0.574460, -0.859739, 0.000000}, {-0.565015, -0.845604, 0.029445}, + {-0.546126, -0.817334, 0.029445}, {-0.536681, -0.803199, 0.000000}, + {-0.546126, -0.817334, -0.029445}, {-0.565015, -0.845604, -0.029445}, + {-0.395695, -0.955291, 0.000000}, {-0.389189, -0.939585, 0.029445}, + {-0.376178, -0.908174, 0.029445}, {-0.369672, -0.892468, 0.000000}, + {-0.376178, -0.908174, -0.029445}, {-0.389189, -0.939585, -0.029445}, + {-0.201724, -1.014132, 0.000000}, {-0.198407, -0.997459, 0.029445}, + {-0.191774, -0.964112, 0.029445}, {-0.188458, -0.947438, 0.000000}, + {-0.191774, -0.964112, -0.029445}, {-0.198407, -0.997459, -0.029445}, + {0.000000, -1.034000, 0.000000}, {0.000000, -1.017000, 0.029445}, + {0.000000, -0.983000, 0.029445}, {0.000000, -0.966000, 0.000000}, + {0.000000, -0.983000, -0.029445}, {0.000000, -1.017000, -0.029445}, + {0.201723, -1.014132, 0.000000}, {0.198407, -0.997459, 0.029445}, + {0.191773, -0.964112, 0.029445}, {0.188457, -0.947439, 0.000000}, + {0.191773, -0.964112, -0.029445}, {0.198407, -0.997459, -0.029445}, + {0.395695, -0.955291, 0.000000}, {0.389189, -0.939585, 0.029445}, + {0.376178, -0.908173, 0.029445}, {0.369672, -0.892467, 0.000000}, + {0.376178, -0.908173, -0.029445}, {0.389189, -0.939585, -0.029445}, + {0.574460, -0.859740, 0.000000}, {0.565015, -0.845605, 0.029445}, + {0.546125, -0.817335, 0.029445}, {0.536681, -0.803200, 0.000000}, + {0.546125, -0.817335, -0.029445}, {0.565015, -0.845605, -0.029445}, + {0.731148, -0.731149, 0.000000}, {0.719127, -0.719128, 0.029445}, + {0.695086, -0.695086, 0.029445}, {0.683065, -0.683066, 0.000000}, + {0.695086, -0.695086, -0.029445}, {0.719127, -0.719128, -0.029445}, + {0.859740, -0.574460, 0.000000}, {0.845605, -0.565015, 0.029445}, + {0.817335, -0.546126, 0.029445}, {0.803200, -0.536681, 0.000000}, + {0.817335, -0.546126, -0.029445}, {0.845605, -0.565015, -0.029445}, + {0.955291, -0.395695, 0.000000}, {0.939585, -0.389189, 0.029445}, + {0.908173, -0.376178, 0.029445}, {0.892467, -0.369673, 0.000000}, + {0.908173, -0.376178, -0.029445}, {0.939585, -0.389189, -0.029445}, + {1.014132, -0.201723, 0.000000}, {0.997459, -0.198407, 0.029445}, + {0.964112, -0.191774, 0.029445}, {0.947439, -0.188457, 0.000000}, + {0.964112, -0.191774, -0.029445}, {0.997459, -0.198407, -0.029445}, }; static const float normals[][3] = { - {1.000000, 0.000000, 0.000000}, - {0.522691, 0.000000, 0.852504}, - {-0.475845, 0.000000, 0.879513}, - {-1.000000, 0.000000, 0.000000}, - {-0.475845, 0.000000, -0.879513}, - {0.522691, 0.000000, -0.852504}, - {0.980773, 0.195074, 0.000000}, - {0.512650, 0.101962, 0.852504}, - {-0.466689, -0.092807, 0.879513}, - {-0.980773, -0.195074, 0.000000}, - {-0.466689, -0.092807, -0.879513}, - {0.512650, 0.101962, -0.852504}, - {0.923856, 0.382672, 0.000000}, - {0.482894, 0.200018, 0.852504}, - {-0.439619, -0.182073, 0.879513}, - {-0.923856, -0.382672, 0.000000}, - {-0.439619, -0.182073, -0.879513}, - {0.482894, 0.200018, -0.852504}, - {0.831446, 0.555559, 0.000000}, - {0.434614, 0.290384, 0.852504}, - {-0.395642, -0.264351, 0.879513}, - {-0.831446, -0.555559, 0.000000}, - {-0.395642, -0.264351, -0.879513}, - {0.434614, 0.290384, -0.852504}, - {0.707083, 0.707083, 0.000000}, - {0.369610, 0.369610, 0.852504}, - {-0.336467, -0.336467, 0.879513}, - {-0.707083, -0.707083, 0.000000}, - {-0.336467, -0.336467, -0.879513}, - {0.369610, 0.369610, -0.852504}, - {0.555559, 0.831446, 0.000000}, - {0.290384, 0.434614, 0.852504}, - {-0.264351, -0.395642, 0.879513}, - {-0.555559, -0.831446, 0.000000}, - {-0.264351, -0.395642, -0.879513}, - {0.290384, 0.434614, -0.852504}, - {0.382672, 0.923856, 0.000000}, - {0.200018, 0.482894, 0.852504}, - {-0.182073, -0.439619, 0.879513}, - {-0.382672, -0.923856, 0.000000}, - {-0.182073, -0.439619, -0.879513}, - {0.200018, 0.482894, -0.852504}, - {0.195074, 0.980773, 0.000000}, - {0.101962, 0.512650, 0.852504}, - {-0.092807, -0.466689, 0.879513}, - {-0.195074, -0.980773, 0.000000}, - {-0.092807, -0.466689, -0.879513}, - {0.101962, 0.512650, -0.852504}, - {0.000000, 1.000000, 0.000000}, - {0.000000, 0.522691, 0.852504}, - {0.000000, -0.475845, 0.879513}, - {0.000000, -1.000000, 0.000000}, - {0.000000, -0.475845, -0.879513}, - {0.000000, 0.522691, -0.852504}, - {-0.195074, 0.980773, 0.000000}, - {-0.101962, 0.512650, 0.852504}, - {0.092807, -0.466689, 0.879513}, - {0.195074, -0.980773, 0.000000}, - {0.092807, -0.466689, -0.879513}, - {-0.101962, 0.512650, -0.852504}, - {-0.382672, 0.923856, 0.000000}, - {-0.200018, 0.482894, 0.852504}, - {0.182073, -0.439619, 0.879513}, - {0.382672, -0.923856, 0.000000}, - {0.182073, -0.439619, -0.879513}, - {-0.200018, 0.482894, -0.852504}, - {-0.555559, 0.831446, 0.000000}, - {-0.290384, 0.434614, 0.852504}, - {0.264351, -0.395642, 0.879513}, - {0.555559, -0.831446, 0.000000}, - {0.264351, -0.395642, -0.879513}, - {-0.290384, 0.434614, -0.852504}, - {-0.707083, 0.707083, 0.000000}, - {-0.369610, 0.369610, 0.852504}, - {0.336467, -0.336467, 0.879513}, - {0.707083, -0.707083, 0.000000}, - {0.336467, -0.336467, -0.879513}, - {-0.369610, 0.369610, -0.852504}, - {-0.831446, 0.555559, 0.000000}, - {-0.434614, 0.290384, 0.852504}, - {0.395642, -0.264351, 0.879513}, - {0.831446, -0.555559, 0.000000}, - {0.395642, -0.264351, -0.879513}, - {-0.434614, 0.290384, -0.852504}, - {-0.923856, 0.382672, 0.000000}, - {-0.482894, 0.200018, 0.852504}, - {0.439619, -0.182073, 0.879513}, - {0.923856, -0.382672, 0.000000}, - {0.439619, -0.182073, -0.879513}, - {-0.482894, 0.200018, -0.852504}, - {-0.980773, 0.195074, 0.000000}, - {-0.512650, 0.101962, 0.852504}, - {0.466689, -0.092807, 0.879513}, - {0.980773, -0.195074, 0.000000}, - {0.466689, -0.092807, -0.879513}, - {-0.512650, 0.101962, -0.852504}, - {-1.000000, 0.000000, 0.000000}, - {-0.522691, 0.000000, 0.852504}, - {0.475845, 0.000000, 0.879513}, - {1.000000, 0.000000, 0.000000}, - {0.475845, 0.000000, -0.879513}, - {-0.522691, 0.000000, -0.852504}, - {-0.980773, -0.195074, 0.000000}, - {-0.512650, -0.101962, 0.852504}, - {0.466689, 0.092807, 0.879513}, - {0.980773, 0.195074, 0.000000}, - {0.466689, 0.092807, -0.879513}, - {-0.512650, -0.101962, -0.852504}, - {-0.923856, -0.382672, 0.000000}, - {-0.482894, -0.200018, 0.852504}, - {0.439619, 0.182073, 0.879513}, - {0.923856, 0.382672, 0.000000}, - {0.439619, 0.182073, -0.879513}, - {-0.482894, -0.200018, -0.852504}, - {-0.831446, -0.555559, 0.000000}, - {-0.434614, -0.290384, 0.852504}, - {0.395642, 0.264351, 0.879513}, - {0.831446, 0.555559, 0.000000}, - {0.395642, 0.264351, -0.879513}, - {-0.434614, -0.290384, -0.852504}, - {-0.707083, -0.707083, 0.000000}, - {-0.369610, -0.369610, 0.852504}, - {0.336467, 0.336467, 0.879513}, - {0.707083, 0.707083, 0.000000}, - {0.336467, 0.336467, -0.879513}, - {-0.369610, -0.369610, -0.852504}, - {-0.555559, -0.831446, 0.000000}, - {-0.290384, -0.434614, 0.852504}, - {0.264351, 0.395642, 0.879513}, - {0.555559, 0.831446, 0.000000}, - {0.264351, 0.395642, -0.879513}, - {-0.290384, -0.434614, -0.852504}, - {-0.382672, -0.923856, 0.000000}, - {-0.200018, -0.482894, 0.852504}, - {0.182073, 0.439619, 0.879513}, - {0.382672, 0.923856, 0.000000}, - {0.182073, 0.439619, -0.879513}, - {-0.200018, -0.482894, -0.852504}, - {-0.195074, -0.980773, 0.000000}, - {-0.101962, -0.512650, 0.852504}, - {0.092807, 0.466689, 0.879513}, - {0.195074, 0.980773, 0.000000}, - {0.092807, 0.466689, -0.879513}, - {-0.101962, -0.512650, -0.852504}, - {0.000000, -1.000000, 0.000000}, - {0.000000, -0.522691, 0.852504}, - {0.000000, 0.475845, 0.879513}, - {0.000000, 1.000000, 0.000000}, - {0.000000, 0.475845, -0.879513}, - {0.000000, -0.522691, -0.852504}, - {0.195074, -0.980773, 0.000000}, - {0.101962, -0.512650, 0.852504}, - {-0.092807, 0.466689, 0.879513}, - {-0.195074, 0.980773, 0.000000}, - {-0.092807, 0.466689, -0.879513}, - {0.101962, -0.512650, -0.852504}, - {0.382672, -0.923856, 0.000000}, - {0.200018, -0.482894, 0.852504}, - {-0.182073, 0.439619, 0.879513}, - {-0.382672, 0.923856, 0.000000}, - {-0.182073, 0.439619, -0.879513}, - {0.200018, -0.482894, -0.852504}, - {0.555559, -0.831446, 0.000000}, - {0.290384, -0.434614, 0.852504}, - {-0.264351, 0.395642, 0.879513}, - {-0.555559, 0.831446, 0.000000}, - {-0.264351, 0.395642, -0.879513}, - {0.290384, -0.434614, -0.852504}, - {0.707083, -0.707083, 0.000000}, - {0.369610, -0.369610, 0.852504}, - {-0.336467, 0.336467, 0.879513}, - {-0.707083, 0.707083, 0.000000}, - {-0.336467, 0.336467, -0.879513}, - {0.369610, -0.369610, -0.852504}, - {0.831446, -0.555559, 0.000000}, - {0.434614, -0.290384, 0.852504}, - {-0.395642, 0.264351, 0.879513}, - {-0.831446, 0.555559, 0.000000}, - {-0.395642, 0.264351, -0.879513}, - {0.434614, -0.290384, -0.852504}, - {0.923856, -0.382672, 0.000000}, - {0.482894, -0.200018, 0.852504}, - {-0.439619, 0.182073, 0.879513}, - {-0.923856, 0.382672, 0.000000}, - {-0.439619, 0.182073, -0.879513}, - {0.482894, -0.200018, -0.852504}, - {0.980773, -0.195074, 0.000000}, - {0.512650, -0.101962, 0.852504}, - {-0.466689, 0.092807, 0.879513}, - {-0.980773, 0.195074, 0.000000}, - {-0.466689, 0.092807, -0.879513}, - {0.512650, -0.101962, -0.852504}, + {1.000000, 0.000000, 0.000000}, {0.522691, 0.000000, 0.852504}, + {-0.475845, 0.000000, 0.879513}, {-1.000000, 0.000000, 0.000000}, + {-0.475845, 0.000000, -0.879513}, {0.522691, 0.000000, -0.852504}, + {0.980773, 0.195074, 0.000000}, {0.512650, 0.101962, 0.852504}, + {-0.466689, -0.092807, 0.879513}, {-0.980773, -0.195074, 0.000000}, + {-0.466689, -0.092807, -0.879513}, {0.512650, 0.101962, -0.852504}, + {0.923856, 0.382672, 0.000000}, {0.482894, 0.200018, 0.852504}, + {-0.439619, -0.182073, 0.879513}, {-0.923856, -0.382672, 0.000000}, + {-0.439619, -0.182073, -0.879513}, {0.482894, 0.200018, -0.852504}, + {0.831446, 0.555559, 0.000000}, {0.434614, 0.290384, 0.852504}, + {-0.395642, -0.264351, 0.879513}, {-0.831446, -0.555559, 0.000000}, + {-0.395642, -0.264351, -0.879513}, {0.434614, 0.290384, -0.852504}, + {0.707083, 0.707083, 0.000000}, {0.369610, 0.369610, 0.852504}, + {-0.336467, -0.336467, 0.879513}, {-0.707083, -0.707083, 0.000000}, + {-0.336467, -0.336467, -0.879513}, {0.369610, 0.369610, -0.852504}, + {0.555559, 0.831446, 0.000000}, {0.290384, 0.434614, 0.852504}, + {-0.264351, -0.395642, 0.879513}, {-0.555559, -0.831446, 0.000000}, + {-0.264351, -0.395642, -0.879513}, {0.290384, 0.434614, -0.852504}, + {0.382672, 0.923856, 0.000000}, {0.200018, 0.482894, 0.852504}, + {-0.182073, -0.439619, 0.879513}, {-0.382672, -0.923856, 0.000000}, + {-0.182073, -0.439619, -0.879513}, {0.200018, 0.482894, -0.852504}, + {0.195074, 0.980773, 0.000000}, {0.101962, 0.512650, 0.852504}, + {-0.092807, -0.466689, 0.879513}, {-0.195074, -0.980773, 0.000000}, + {-0.092807, -0.466689, -0.879513}, {0.101962, 0.512650, -0.852504}, + {0.000000, 1.000000, 0.000000}, {0.000000, 0.522691, 0.852504}, + {0.000000, -0.475845, 0.879513}, {0.000000, -1.000000, 0.000000}, + {0.000000, -0.475845, -0.879513}, {0.000000, 0.522691, -0.852504}, + {-0.195074, 0.980773, 0.000000}, {-0.101962, 0.512650, 0.852504}, + {0.092807, -0.466689, 0.879513}, {0.195074, -0.980773, 0.000000}, + {0.092807, -0.466689, -0.879513}, {-0.101962, 0.512650, -0.852504}, + {-0.382672, 0.923856, 0.000000}, {-0.200018, 0.482894, 0.852504}, + {0.182073, -0.439619, 0.879513}, {0.382672, -0.923856, 0.000000}, + {0.182073, -0.439619, -0.879513}, {-0.200018, 0.482894, -0.852504}, + {-0.555559, 0.831446, 0.000000}, {-0.290384, 0.434614, 0.852504}, + {0.264351, -0.395642, 0.879513}, {0.555559, -0.831446, 0.000000}, + {0.264351, -0.395642, -0.879513}, {-0.290384, 0.434614, -0.852504}, + {-0.707083, 0.707083, 0.000000}, {-0.369610, 0.369610, 0.852504}, + {0.336467, -0.336467, 0.879513}, {0.707083, -0.707083, 0.000000}, + {0.336467, -0.336467, -0.879513}, {-0.369610, 0.369610, -0.852504}, + {-0.831446, 0.555559, 0.000000}, {-0.434614, 0.290384, 0.852504}, + {0.395642, -0.264351, 0.879513}, {0.831446, -0.555559, 0.000000}, + {0.395642, -0.264351, -0.879513}, {-0.434614, 0.290384, -0.852504}, + {-0.923856, 0.382672, 0.000000}, {-0.482894, 0.200018, 0.852504}, + {0.439619, -0.182073, 0.879513}, {0.923856, -0.382672, 0.000000}, + {0.439619, -0.182073, -0.879513}, {-0.482894, 0.200018, -0.852504}, + {-0.980773, 0.195074, 0.000000}, {-0.512650, 0.101962, 0.852504}, + {0.466689, -0.092807, 0.879513}, {0.980773, -0.195074, 0.000000}, + {0.466689, -0.092807, -0.879513}, {-0.512650, 0.101962, -0.852504}, + {-1.000000, 0.000000, 0.000000}, {-0.522691, 0.000000, 0.852504}, + {0.475845, 0.000000, 0.879513}, {1.000000, 0.000000, 0.000000}, + {0.475845, 0.000000, -0.879513}, {-0.522691, 0.000000, -0.852504}, + {-0.980773, -0.195074, 0.000000}, {-0.512650, -0.101962, 0.852504}, + {0.466689, 0.092807, 0.879513}, {0.980773, 0.195074, 0.000000}, + {0.466689, 0.092807, -0.879513}, {-0.512650, -0.101962, -0.852504}, + {-0.923856, -0.382672, 0.000000}, {-0.482894, -0.200018, 0.852504}, + {0.439619, 0.182073, 0.879513}, {0.923856, 0.382672, 0.000000}, + {0.439619, 0.182073, -0.879513}, {-0.482894, -0.200018, -0.852504}, + {-0.831446, -0.555559, 0.000000}, {-0.434614, -0.290384, 0.852504}, + {0.395642, 0.264351, 0.879513}, {0.831446, 0.555559, 0.000000}, + {0.395642, 0.264351, -0.879513}, {-0.434614, -0.290384, -0.852504}, + {-0.707083, -0.707083, 0.000000}, {-0.369610, -0.369610, 0.852504}, + {0.336467, 0.336467, 0.879513}, {0.707083, 0.707083, 0.000000}, + {0.336467, 0.336467, -0.879513}, {-0.369610, -0.369610, -0.852504}, + {-0.555559, -0.831446, 0.000000}, {-0.290384, -0.434614, 0.852504}, + {0.264351, 0.395642, 0.879513}, {0.555559, 0.831446, 0.000000}, + {0.264351, 0.395642, -0.879513}, {-0.290384, -0.434614, -0.852504}, + {-0.382672, -0.923856, 0.000000}, {-0.200018, -0.482894, 0.852504}, + {0.182073, 0.439619, 0.879513}, {0.382672, 0.923856, 0.000000}, + {0.182073, 0.439619, -0.879513}, {-0.200018, -0.482894, -0.852504}, + {-0.195074, -0.980773, 0.000000}, {-0.101962, -0.512650, 0.852504}, + {0.092807, 0.466689, 0.879513}, {0.195074, 0.980773, 0.000000}, + {0.092807, 0.466689, -0.879513}, {-0.101962, -0.512650, -0.852504}, + {0.000000, -1.000000, 0.000000}, {0.000000, -0.522691, 0.852504}, + {0.000000, 0.475845, 0.879513}, {0.000000, 1.000000, 0.000000}, + {0.000000, 0.475845, -0.879513}, {0.000000, -0.522691, -0.852504}, + {0.195074, -0.980773, 0.000000}, {0.101962, -0.512650, 0.852504}, + {-0.092807, 0.466689, 0.879513}, {-0.195074, 0.980773, 0.000000}, + {-0.092807, 0.466689, -0.879513}, {0.101962, -0.512650, -0.852504}, + {0.382672, -0.923856, 0.000000}, {0.200018, -0.482894, 0.852504}, + {-0.182073, 0.439619, 0.879513}, {-0.382672, 0.923856, 0.000000}, + {-0.182073, 0.439619, -0.879513}, {0.200018, -0.482894, -0.852504}, + {0.555559, -0.831446, 0.000000}, {0.290384, -0.434614, 0.852504}, + {-0.264351, 0.395642, 0.879513}, {-0.555559, 0.831446, 0.000000}, + {-0.264351, 0.395642, -0.879513}, {0.290384, -0.434614, -0.852504}, + {0.707083, -0.707083, 0.000000}, {0.369610, -0.369610, 0.852504}, + {-0.336467, 0.336467, 0.879513}, {-0.707083, 0.707083, 0.000000}, + {-0.336467, 0.336467, -0.879513}, {0.369610, -0.369610, -0.852504}, + {0.831446, -0.555559, 0.000000}, {0.434614, -0.290384, 0.852504}, + {-0.395642, 0.264351, 0.879513}, {-0.831446, 0.555559, 0.000000}, + {-0.395642, 0.264351, -0.879513}, {0.434614, -0.290384, -0.852504}, + {0.923856, -0.382672, 0.000000}, {0.482894, -0.200018, 0.852504}, + {-0.439619, 0.182073, 0.879513}, {-0.923856, 0.382672, 0.000000}, + {-0.439619, 0.182073, -0.879513}, {0.482894, -0.200018, -0.852504}, + {0.980773, -0.195074, 0.000000}, {0.512650, -0.101962, 0.852504}, + {-0.466689, 0.092807, 0.879513}, {-0.980773, 0.195074, 0.000000}, + {-0.466689, 0.092807, -0.879513}, {0.512650, -0.101962, -0.852504}, }; static const unsigned short indices[] = { - 6, 7, 1, - 7, 8, 2, - 8, 9, 3, - 9, 10, 4, - 10, 11, 5, - 5, 11, 6, - 12, 13, 7, - 13, 14, 8, - 14, 15, 9, - 15, 16, 10, - 16, 17, 11, - 11, 17, 12, - 18, 19, 13, - 13, 19, 20, - 20, 21, 15, - 15, 21, 22, - 22, 23, 17, - 17, 23, 18, - 24, 25, 19, - 19, 25, 26, - 26, 27, 21, - 21, 27, 28, - 28, 29, 23, - 23, 29, 24, - 30, 31, 25, - 25, 31, 32, - 26, 32, 33, - 27, 33, 34, - 34, 35, 29, - 29, 35, 30, - 36, 37, 31, - 31, 37, 38, - 38, 39, 33, - 39, 40, 34, - 40, 41, 35, - 35, 41, 36, - 36, 42, 43, - 43, 44, 38, - 44, 45, 39, - 45, 46, 40, - 46, 47, 41, - 47, 42, 36, - 48, 49, 43, - 49, 50, 44, - 50, 51, 45, - 51, 52, 46, - 52, 53, 47, - 47, 53, 48, - 54, 55, 49, - 49, 55, 56, - 50, 56, 57, - 57, 58, 52, - 58, 59, 53, - 53, 59, 54, - 60, 61, 55, - 55, 61, 62, - 56, 62, 63, - 63, 64, 58, - 64, 65, 59, - 59, 65, 60, - 66, 67, 61, - 61, 67, 68, - 68, 69, 63, - 69, 70, 64, - 70, 71, 65, - 71, 66, 60, - 72, 73, 67, - 73, 74, 68, - 68, 74, 75, - 75, 76, 70, - 76, 77, 71, - 71, 77, 72, - 78, 79, 73, - 79, 80, 74, - 74, 80, 81, - 81, 82, 76, - 82, 83, 77, - 83, 78, 72, - 78, 84, 85, - 85, 86, 80, - 80, 86, 87, - 87, 88, 82, - 82, 88, 89, - 89, 84, 78, - 90, 91, 85, - 91, 92, 86, - 86, 92, 93, - 93, 94, 88, - 88, 94, 95, - 95, 90, 84, - 96, 97, 91, - 97, 98, 92, - 98, 99, 93, - 99, 100, 94, - 100, 101, 95, - 101, 96, 90, - 102, 103, 97, - 103, 104, 98, - 104, 105, 99, - 99, 105, 106, - 106, 107, 101, - 101, 107, 102, - 108, 109, 103, - 103, 109, 110, - 110, 111, 105, - 105, 111, 112, - 112, 113, 107, - 107, 113, 108, - 114, 115, 109, - 115, 116, 110, - 116, 117, 111, - 111, 117, 118, - 112, 118, 119, - 113, 119, 114, - 114, 120, 121, - 121, 122, 116, - 122, 123, 117, - 117, 123, 124, - 124, 125, 119, - 125, 120, 114, - 126, 127, 121, - 121, 127, 128, - 128, 129, 123, - 123, 129, 130, - 130, 131, 125, - 125, 131, 126, - 132, 133, 127, - 133, 134, 128, - 128, 134, 135, - 135, 136, 130, - 136, 137, 131, - 131, 137, 132, - 132, 138, 139, - 133, 139, 140, - 134, 140, 141, - 141, 142, 136, - 142, 143, 137, - 143, 138, 132, - 138, 144, 145, - 139, 145, 146, - 146, 147, 141, - 141, 147, 148, - 148, 149, 143, - 149, 144, 138, - 144, 150, 151, - 151, 152, 146, - 146, 152, 153, - 153, 154, 148, - 154, 155, 149, - 155, 150, 144, - 156, 157, 151, - 151, 157, 158, - 158, 159, 153, - 159, 160, 154, - 160, 161, 155, - 155, 161, 156, - 156, 162, 163, - 163, 164, 158, - 158, 164, 165, - 165, 166, 160, - 160, 166, 167, - 167, 162, 156, - 162, 168, 169, - 169, 170, 164, - 164, 170, 171, - 165, 171, 172, - 166, 172, 173, - 173, 168, 162, - 174, 175, 169, - 175, 176, 170, - 170, 176, 177, - 177, 178, 172, - 172, 178, 179, - 173, 179, 174, - 174, 180, 181, - 181, 182, 176, - 176, 182, 183, - 183, 184, 178, - 178, 184, 185, - 179, 185, 180, - 186, 187, 181, - 187, 188, 182, - 188, 189, 183, - 183, 189, 190, - 190, 191, 185, - 191, 186, 180, - 0, 1, 187, - 1, 2, 188, - 2, 3, 189, - 3, 4, 190, - 190, 4, 5, - 191, 5, 0, - 0, 6, 1, - 1, 7, 2, - 2, 8, 3, - 3, 9, 4, - 4, 10, 5, - 0, 5, 6, - 6, 12, 7, - 7, 13, 8, - 8, 14, 9, - 9, 15, 10, - 10, 16, 11, - 6, 11, 12, - 12, 18, 13, - 14, 13, 20, - 14, 20, 15, - 16, 15, 22, - 16, 22, 17, - 12, 17, 18, - 18, 24, 19, - 20, 19, 26, - 20, 26, 21, - 22, 21, 28, - 22, 28, 23, - 18, 23, 24, - 24, 30, 25, - 26, 25, 32, - 27, 26, 33, - 28, 27, 34, - 28, 34, 29, - 24, 29, 30, - 30, 36, 31, - 32, 31, 38, - 32, 38, 33, - 33, 39, 34, - 34, 40, 35, - 30, 35, 36, - 37, 36, 43, - 37, 43, 38, - 38, 44, 39, - 39, 45, 40, - 40, 46, 41, - 41, 47, 36, - 42, 48, 43, - 43, 49, 44, - 44, 50, 45, - 45, 51, 46, - 46, 52, 47, - 42, 47, 48, - 48, 54, 49, - 50, 49, 56, - 51, 50, 57, - 51, 57, 52, - 52, 58, 53, - 48, 53, 54, - 54, 60, 55, - 56, 55, 62, - 57, 56, 63, - 57, 63, 58, - 58, 64, 59, - 54, 59, 60, - 60, 66, 61, - 62, 61, 68, - 62, 68, 63, - 63, 69, 64, - 64, 70, 65, - 65, 71, 60, - 66, 72, 67, - 67, 73, 68, - 69, 68, 75, - 69, 75, 70, - 70, 76, 71, - 66, 71, 72, - 72, 78, 73, - 73, 79, 74, - 75, 74, 81, - 75, 81, 76, - 76, 82, 77, - 77, 83, 72, - 79, 78, 85, - 79, 85, 80, - 81, 80, 87, - 81, 87, 82, - 83, 82, 89, - 83, 89, 78, - 84, 90, 85, - 85, 91, 86, - 87, 86, 93, - 87, 93, 88, - 89, 88, 95, - 89, 95, 84, - 90, 96, 91, - 91, 97, 92, - 92, 98, 93, - 93, 99, 94, - 94, 100, 95, - 95, 101, 90, - 96, 102, 97, - 97, 103, 98, - 98, 104, 99, - 100, 99, 106, - 100, 106, 101, - 96, 101, 102, - 102, 108, 103, - 104, 103, 110, - 104, 110, 105, - 106, 105, 112, - 106, 112, 107, - 102, 107, 108, - 108, 114, 109, - 109, 115, 110, - 110, 116, 111, - 112, 111, 118, - 113, 112, 119, - 108, 113, 114, - 115, 114, 121, - 115, 121, 116, - 116, 122, 117, - 118, 117, 124, - 118, 124, 119, - 119, 125, 114, - 120, 126, 121, - 122, 121, 128, - 122, 128, 123, - 124, 123, 130, - 124, 130, 125, - 120, 125, 126, - 126, 132, 127, - 127, 133, 128, - 129, 128, 135, - 129, 135, 130, - 130, 136, 131, - 126, 131, 132, - 133, 132, 139, - 134, 133, 140, - 135, 134, 141, - 135, 141, 136, - 136, 142, 137, - 137, 143, 132, - 139, 138, 145, - 140, 139, 146, - 140, 146, 141, - 142, 141, 148, - 142, 148, 143, - 143, 149, 138, - 145, 144, 151, - 145, 151, 146, - 147, 146, 153, - 147, 153, 148, - 148, 154, 149, - 149, 155, 144, - 150, 156, 151, - 152, 151, 158, - 152, 158, 153, - 153, 159, 154, - 154, 160, 155, - 150, 155, 156, - 157, 156, 163, - 157, 163, 158, - 159, 158, 165, - 159, 165, 160, - 161, 160, 167, - 161, 167, 156, - 163, 162, 169, - 163, 169, 164, - 165, 164, 171, - 166, 165, 172, - 167, 166, 173, - 167, 173, 162, - 168, 174, 169, - 169, 175, 170, - 171, 170, 177, - 171, 177, 172, - 173, 172, 179, - 168, 173, 174, - 175, 174, 181, - 175, 181, 176, - 177, 176, 183, - 177, 183, 178, - 179, 178, 185, - 174, 179, 180, - 180, 186, 181, - 181, 187, 182, - 182, 188, 183, - 184, 183, 190, - 184, 190, 185, - 185, 191, 180, - 186, 0, 187, - 187, 1, 188, - 188, 2, 189, - 189, 3, 190, - 191, 190, 5, - 186, 191, 0, + 6, 7, 1, 7, 8, 2, 8, 9, 3, 9, 10, 4, 10, 11, 5, 5, 11, 6, 12, + 13, 7, 13, 14, 8, 14, 15, 9, 15, 16, 10, 16, 17, 11, 11, 17, 12, 18, 19, + 13, 13, 19, 20, 20, 21, 15, 15, 21, 22, 22, 23, 17, 17, 23, 18, 24, 25, 19, + 19, 25, 26, 26, 27, 21, 21, 27, 28, 28, 29, 23, 23, 29, 24, 30, 31, 25, 25, + 31, 32, 26, 32, 33, 27, 33, 34, 34, 35, 29, 29, 35, 30, 36, 37, 31, 31, 37, + 38, 38, 39, 33, 39, 40, 34, 40, 41, 35, 35, 41, 36, 36, 42, 43, 43, 44, 38, + 44, 45, 39, 45, 46, 40, 46, 47, 41, 47, 42, 36, 48, 49, 43, 49, 50, 44, 50, + 51, 45, 51, 52, 46, 52, 53, 47, 47, 53, 48, 54, 55, 49, 49, 55, 56, 50, 56, + 57, 57, 58, 52, 58, 59, 53, 53, 59, 54, 60, 61, 55, 55, 61, 62, 56, 62, 63, + 63, 64, 58, 64, 65, 59, 59, 65, 60, 66, 67, 61, 61, 67, 68, 68, 69, 63, 69, + 70, 64, 70, 71, 65, 71, 66, 60, 72, 73, 67, 73, 74, 68, 68, 74, 75, 75, 76, + 70, 76, 77, 71, 71, 77, 72, 78, 79, 73, 79, 80, 74, 74, 80, 81, 81, 82, 76, + 82, 83, 77, 83, 78, 72, 78, 84, 85, 85, 86, 80, 80, 86, 87, 87, 88, 82, 82, + 88, 89, 89, 84, 78, 90, 91, 85, 91, 92, 86, 86, 92, 93, 93, 94, 88, 88, 94, + 95, 95, 90, 84, 96, 97, 91, 97, 98, 92, 98, 99, 93, 99, 100, 94, 100, 101, 95, + 101, 96, 90, 102, 103, 97, 103, 104, 98, 104, 105, 99, 99, 105, 106, 106, 107, 101, 101, + 107, 102, 108, 109, 103, 103, 109, 110, 110, 111, 105, 105, 111, 112, 112, 113, 107, 107, 113, + 108, 114, 115, 109, 115, 116, 110, 116, 117, 111, 111, 117, 118, 112, 118, 119, 113, 119, 114, + 114, 120, 121, 121, 122, 116, 122, 123, 117, 117, 123, 124, 124, 125, 119, 125, 120, 114, 126, + 127, 121, 121, 127, 128, 128, 129, 123, 123, 129, 130, 130, 131, 125, 125, 131, 126, 132, 133, + 127, 133, 134, 128, 128, 134, 135, 135, 136, 130, 136, 137, 131, 131, 137, 132, 132, 138, 139, + 133, 139, 140, 134, 140, 141, 141, 142, 136, 142, 143, 137, 143, 138, 132, 138, 144, 145, 139, + 145, 146, 146, 147, 141, 141, 147, 148, 148, 149, 143, 149, 144, 138, 144, 150, 151, 151, 152, + 146, 146, 152, 153, 153, 154, 148, 154, 155, 149, 155, 150, 144, 156, 157, 151, 151, 157, 158, + 158, 159, 153, 159, 160, 154, 160, 161, 155, 155, 161, 156, 156, 162, 163, 163, 164, 158, 158, + 164, 165, 165, 166, 160, 160, 166, 167, 167, 162, 156, 162, 168, 169, 169, 170, 164, 164, 170, + 171, 165, 171, 172, 166, 172, 173, 173, 168, 162, 174, 175, 169, 175, 176, 170, 170, 176, 177, + 177, 178, 172, 172, 178, 179, 173, 179, 174, 174, 180, 181, 181, 182, 176, 176, 182, 183, 183, + 184, 178, 178, 184, 185, 179, 185, 180, 186, 187, 181, 187, 188, 182, 188, 189, 183, 183, 189, + 190, 190, 191, 185, 191, 186, 180, 0, 1, 187, 1, 2, 188, 2, 3, 189, 3, 4, 190, + 190, 4, 5, 191, 5, 0, 0, 6, 1, 1, 7, 2, 2, 8, 3, 3, 9, 4, 4, + 10, 5, 0, 5, 6, 6, 12, 7, 7, 13, 8, 8, 14, 9, 9, 15, 10, 10, 16, + 11, 6, 11, 12, 12, 18, 13, 14, 13, 20, 14, 20, 15, 16, 15, 22, 16, 22, 17, + 12, 17, 18, 18, 24, 19, 20, 19, 26, 20, 26, 21, 22, 21, 28, 22, 28, 23, 18, + 23, 24, 24, 30, 25, 26, 25, 32, 27, 26, 33, 28, 27, 34, 28, 34, 29, 24, 29, + 30, 30, 36, 31, 32, 31, 38, 32, 38, 33, 33, 39, 34, 34, 40, 35, 30, 35, 36, + 37, 36, 43, 37, 43, 38, 38, 44, 39, 39, 45, 40, 40, 46, 41, 41, 47, 36, 42, + 48, 43, 43, 49, 44, 44, 50, 45, 45, 51, 46, 46, 52, 47, 42, 47, 48, 48, 54, + 49, 50, 49, 56, 51, 50, 57, 51, 57, 52, 52, 58, 53, 48, 53, 54, 54, 60, 55, + 56, 55, 62, 57, 56, 63, 57, 63, 58, 58, 64, 59, 54, 59, 60, 60, 66, 61, 62, + 61, 68, 62, 68, 63, 63, 69, 64, 64, 70, 65, 65, 71, 60, 66, 72, 67, 67, 73, + 68, 69, 68, 75, 69, 75, 70, 70, 76, 71, 66, 71, 72, 72, 78, 73, 73, 79, 74, + 75, 74, 81, 75, 81, 76, 76, 82, 77, 77, 83, 72, 79, 78, 85, 79, 85, 80, 81, + 80, 87, 81, 87, 82, 83, 82, 89, 83, 89, 78, 84, 90, 85, 85, 91, 86, 87, 86, + 93, 87, 93, 88, 89, 88, 95, 89, 95, 84, 90, 96, 91, 91, 97, 92, 92, 98, 93, + 93, 99, 94, 94, 100, 95, 95, 101, 90, 96, 102, 97, 97, 103, 98, 98, 104, 99, 100, + 99, 106, 100, 106, 101, 96, 101, 102, 102, 108, 103, 104, 103, 110, 104, 110, 105, 106, 105, + 112, 106, 112, 107, 102, 107, 108, 108, 114, 109, 109, 115, 110, 110, 116, 111, 112, 111, 118, + 113, 112, 119, 108, 113, 114, 115, 114, 121, 115, 121, 116, 116, 122, 117, 118, 117, 124, 118, + 124, 119, 119, 125, 114, 120, 126, 121, 122, 121, 128, 122, 128, 123, 124, 123, 130, 124, 130, + 125, 120, 125, 126, 126, 132, 127, 127, 133, 128, 129, 128, 135, 129, 135, 130, 130, 136, 131, + 126, 131, 132, 133, 132, 139, 134, 133, 140, 135, 134, 141, 135, 141, 136, 136, 142, 137, 137, + 143, 132, 139, 138, 145, 140, 139, 146, 140, 146, 141, 142, 141, 148, 142, 148, 143, 143, 149, + 138, 145, 144, 151, 145, 151, 146, 147, 146, 153, 147, 153, 148, 148, 154, 149, 149, 155, 144, + 150, 156, 151, 152, 151, 158, 152, 158, 153, 153, 159, 154, 154, 160, 155, 150, 155, 156, 157, + 156, 163, 157, 163, 158, 159, 158, 165, 159, 165, 160, 161, 160, 167, 161, 167, 156, 163, 162, + 169, 163, 169, 164, 165, 164, 171, 166, 165, 172, 167, 166, 173, 167, 173, 162, 168, 174, 169, + 169, 175, 170, 171, 170, 177, 171, 177, 172, 173, 172, 179, 168, 173, 174, 175, 174, 181, 175, + 181, 176, 177, 176, 183, 177, 183, 178, 179, 178, 185, 174, 179, 180, 180, 186, 181, 181, 187, + 182, 182, 188, 183, 184, 183, 190, 184, 190, 185, 185, 191, 180, 186, 0, 187, 187, 1, 188, + 188, 2, 189, 189, 3, 190, 191, 190, 5, 186, 191, 0, }; GizmoGeomInfo wm_gizmo_geom_data_dial = { - .nverts = 192, - .ntris = 384, - .verts = verts, - .normals = normals, - .indices = indices, + .nverts = 192, + .ntris = 384, + .verts = verts, + .normals = normals, + .indices = indices, }; diff --git a/source/blender/editors/gizmo_library/gizmo_draw_utils.c b/source/blender/editors/gizmo_library/gizmo_draw_utils.c index 999e211a492..f1d8c1ac6b0 100644 --- a/source/blender/editors/gizmo_library/gizmo_draw_utils.c +++ b/source/blender/editors/gizmo_library/gizmo_draw_utils.c @@ -49,63 +49,63 @@ /** * Main draw call for GizmoGeomInfo data */ -void wm_gizmo_geometryinfo_draw(const GizmoGeomInfo *info, const bool UNUSED(select), const float color[4]) +void wm_gizmo_geometryinfo_draw(const GizmoGeomInfo *info, + const bool UNUSED(select), + const float color[4]) { - /* TODO store the Batches inside the GizmoGeomInfo and updated it when geom changes - * So we don't need to re-created and discard it every time */ + /* TODO store the Batches inside the GizmoGeomInfo and updated it when geom changes + * So we don't need to re-created and discard it every time */ - GPUVertBuf *vbo; - GPUIndexBuf *el; - GPUBatch *batch; - GPUIndexBufBuilder elb = {0}; + GPUVertBuf *vbo; + GPUIndexBuf *el; + GPUBatch *batch; + GPUIndexBufBuilder elb = {0}; - GPUVertFormat format = {0}; - uint pos_id = GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); + GPUVertFormat format = {0}; + uint pos_id = GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); - /* Elements */ - GPU_indexbuf_init(&elb, GPU_PRIM_TRIS, info->ntris, info->nverts); - for (int i = 0; i < info->ntris; ++i) { - const unsigned short *idx = &info->indices[i * 3]; - GPU_indexbuf_add_tri_verts(&elb, idx[0], idx[1], idx[2]); - } - el = GPU_indexbuf_build(&elb); + /* Elements */ + GPU_indexbuf_init(&elb, GPU_PRIM_TRIS, info->ntris, info->nverts); + for (int i = 0; i < info->ntris; ++i) { + const unsigned short *idx = &info->indices[i * 3]; + GPU_indexbuf_add_tri_verts(&elb, idx[0], idx[1], idx[2]); + } + el = GPU_indexbuf_build(&elb); - vbo = GPU_vertbuf_create_with_format(&format); - GPU_vertbuf_data_alloc(vbo, info->nverts); + vbo = GPU_vertbuf_create_with_format(&format); + GPU_vertbuf_data_alloc(vbo, info->nverts); - GPU_vertbuf_attr_fill(vbo, pos_id, info->verts); + GPU_vertbuf_attr_fill(vbo, pos_id, info->verts); - batch = GPU_batch_create_ex(GPU_PRIM_TRIS, vbo, el, GPU_BATCH_OWNS_VBO | GPU_BATCH_OWNS_INDEX); - GPU_batch_program_set_builtin(batch, GPU_SHADER_3D_UNIFORM_COLOR); + batch = GPU_batch_create_ex(GPU_PRIM_TRIS, vbo, el, GPU_BATCH_OWNS_VBO | GPU_BATCH_OWNS_INDEX); + GPU_batch_program_set_builtin(batch, GPU_SHADER_3D_UNIFORM_COLOR); - GPU_batch_uniform_4fv(batch, "color", color); + GPU_batch_uniform_4fv(batch, "color", color); - /* We may want to re-visit this, for now disable - * since it causes issues leaving the GL state modified. */ + /* We may want to re-visit this, for now disable + * since it causes issues leaving the GL state modified. */ #if 0 - glEnable(GL_CULL_FACE); - GPU_depth_test(true); + glEnable(GL_CULL_FACE); + GPU_depth_test(true); #endif - GPU_batch_draw(batch); + GPU_batch_draw(batch); #if 0 - GPU_depth_test(false); - glDisable(GL_CULL_FACE); + GPU_depth_test(false); + glDisable(GL_CULL_FACE); #endif - - GPU_batch_discard(batch); + GPU_batch_discard(batch); } void wm_gizmo_vec_draw( - const float color[4], const float (*verts)[3], uint vert_count, - uint pos, uint primitive_type) + const float color[4], const float (*verts)[3], uint vert_count, uint pos, uint primitive_type) { - immUniformColor4fv(color); - immBegin(primitive_type, vert_count); - for (int i = 0; i < vert_count; i++) { - immVertex3fv(pos, verts[i]); - } - immEnd(); + immUniformColor4fv(color); + immBegin(primitive_type, vert_count); + for (int i = 0; i < vert_count; i++) { + immVertex3fv(pos, verts[i]); + } + immEnd(); } diff --git a/source/blender/editors/gizmo_library/gizmo_geometry.h b/source/blender/editors/gizmo_library/gizmo_geometry.h index 71d8919c91d..42cb0c0bc1b 100644 --- a/source/blender/editors/gizmo_library/gizmo_geometry.h +++ b/source/blender/editors/gizmo_library/gizmo_geometry.h @@ -26,16 +26,15 @@ * called geom_xxx_gizmo.c */ - #ifndef __GIZMO_GEOMETRY_H__ #define __GIZMO_GEOMETRY_H__ typedef struct GizmoGeomInfo { - int nverts; - int ntris; - const float (*verts)[3]; - const float (*normals)[3]; - const unsigned short *indices; + int nverts; + int ntris; + const float (*verts)[3]; + const float (*normals)[3]; + const unsigned short *indices; } GizmoGeomInfo; /* arrow gizmo */ @@ -47,4 +46,4 @@ extern GizmoGeomInfo wm_gizmo_geom_data_cube; /* dial gizmo */ extern GizmoGeomInfo wm_gizmo_geom_data_dial; -#endif /* __GIZMO_GEOMETRY_H__ */ +#endif /* __GIZMO_GEOMETRY_H__ */ diff --git a/source/blender/editors/gizmo_library/gizmo_group_types/value2d_gizmo_group.c b/source/blender/editors/gizmo_library/gizmo_group_types/value2d_gizmo_group.c index 28a5200a041..3b61aed5e27 100644 --- a/source/blender/editors/gizmo_library/gizmo_group_types/value2d_gizmo_group.c +++ b/source/blender/editors/gizmo_library/gizmo_group_types/value2d_gizmo_group.c @@ -44,118 +44,115 @@ * \{ */ struct ValueOpRedoGroup { - wmGizmo *gizmo; - struct { - const bContext *context; /* needed for redo. */ - wmOperator *op; - } state; + wmGizmo *gizmo; + struct { + const bContext *context; /* needed for redo. */ + wmOperator *op; + } state; }; static void gizmo_op_redo_exec(struct ValueOpRedoGroup *igzgroup) { - wmOperator *op = igzgroup->state.op; - if (op == WM_operator_last_redo((bContext *)igzgroup->state.context)) { - ED_undo_operator_repeat((bContext *)igzgroup->state.context, op); - } + wmOperator *op = igzgroup->state.op; + if (op == WM_operator_last_redo((bContext *)igzgroup->state.context)) { + ED_undo_operator_repeat((bContext *)igzgroup->state.context, op); + } } /* translate callbacks */ -static void gizmo_value_operator_redo_value_get( - const wmGizmo *gz, wmGizmoProperty *gz_prop, - void *value_p) +static void gizmo_value_operator_redo_value_get(const wmGizmo *gz, + wmGizmoProperty *gz_prop, + void *value_p) { - float *value = value_p; - BLI_assert(gz_prop->type->array_length == 1); - UNUSED_VARS_NDEBUG(gz_prop); + float *value = value_p; + BLI_assert(gz_prop->type->array_length == 1); + UNUSED_VARS_NDEBUG(gz_prop); - struct ValueOpRedoGroup *igzgroup = gz->parent_gzgroup->customdata; - wmOperator *op = igzgroup->state.op; - *value = RNA_property_float_get(op->ptr, op->type->prop); + struct ValueOpRedoGroup *igzgroup = gz->parent_gzgroup->customdata; + wmOperator *op = igzgroup->state.op; + *value = RNA_property_float_get(op->ptr, op->type->prop); } -static void gizmo_value_operator_redo_value_set( - const wmGizmo *gz, wmGizmoProperty *gz_prop, - const void *value_p) +static void gizmo_value_operator_redo_value_set(const wmGizmo *gz, + wmGizmoProperty *gz_prop, + const void *value_p) { - const float *value = value_p; - BLI_assert(gz_prop->type->array_length == 1); - UNUSED_VARS_NDEBUG(gz_prop); - - struct ValueOpRedoGroup *igzgroup = gz->parent_gzgroup->customdata; - wmOperator *op = igzgroup->state.op; - RNA_property_float_set(op->ptr, op->type->prop, *value); - gizmo_op_redo_exec(igzgroup); + const float *value = value_p; + BLI_assert(gz_prop->type->array_length == 1); + UNUSED_VARS_NDEBUG(gz_prop); + + struct ValueOpRedoGroup *igzgroup = gz->parent_gzgroup->customdata; + wmOperator *op = igzgroup->state.op; + RNA_property_float_set(op->ptr, op->type->prop, *value); + gizmo_op_redo_exec(igzgroup); } -static void WIDGETGROUP_value_operator_redo_modal_from_setup( - const bContext *C, wmGizmoGroup *gzgroup) +static void WIDGETGROUP_value_operator_redo_modal_from_setup(const bContext *C, + wmGizmoGroup *gzgroup) { - /* Start off dragging. */ - wmWindow *win = CTX_wm_window(C); - wmGizmo *gz = gzgroup->gizmos.first; - wmGizmoMap *gzmap = gzgroup->parent_gzmap; - WM_gizmo_modal_set_from_setup( - gzmap, (bContext *)C, gz, 0, win->eventstate); + /* Start off dragging. */ + wmWindow *win = CTX_wm_window(C); + wmGizmo *gz = gzgroup->gizmos.first; + wmGizmoMap *gzmap = gzgroup->parent_gzmap; + WM_gizmo_modal_set_from_setup(gzmap, (bContext *)C, gz, 0, win->eventstate); } static void WIDGETGROUP_value_operator_redo_setup(const bContext *C, wmGizmoGroup *gzgroup) { - struct ValueOpRedoGroup *igzgroup = MEM_mallocN(sizeof(struct ValueOpRedoGroup), __func__); + struct ValueOpRedoGroup *igzgroup = MEM_mallocN(sizeof(struct ValueOpRedoGroup), __func__); - igzgroup->gizmo = WM_gizmo_new("GIZMO_GT_value_2d", gzgroup, NULL); - wmGizmo *gz = igzgroup->gizmo; + igzgroup->gizmo = WM_gizmo_new("GIZMO_GT_value_2d", gzgroup, NULL); + wmGizmo *gz = igzgroup->gizmo; - igzgroup->state.context = C; - igzgroup->state.op = WM_operator_last_redo(C); + igzgroup->state.context = C; + igzgroup->state.op = WM_operator_last_redo(C); - gzgroup->customdata = igzgroup; + gzgroup->customdata = igzgroup; - UI_GetThemeColor3fv(TH_GIZMO_PRIMARY, gz->color); - UI_GetThemeColor3fv(TH_GIZMO_HI, gz->color_hi); + UI_GetThemeColor3fv(TH_GIZMO_PRIMARY, gz->color); + UI_GetThemeColor3fv(TH_GIZMO_HI, gz->color_hi); - WM_gizmo_target_property_def_func( - gz, "offset", - &(const struct wmGizmoPropertyFnParams) { - .value_get_fn = gizmo_value_operator_redo_value_get, - .value_set_fn = gizmo_value_operator_redo_value_set, - .range_get_fn = NULL, - .user_data = igzgroup, - }); + WM_gizmo_target_property_def_func(gz, + "offset", + &(const struct wmGizmoPropertyFnParams){ + .value_get_fn = gizmo_value_operator_redo_value_get, + .value_set_fn = gizmo_value_operator_redo_value_set, + .range_get_fn = NULL, + .user_data = igzgroup, + }); - /* Become modal as soon as it's started. */ - WIDGETGROUP_value_operator_redo_modal_from_setup(C, gzgroup); + /* Become modal as soon as it's started. */ + WIDGETGROUP_value_operator_redo_modal_from_setup(C, gzgroup); } -static void WIDGETGROUP_value_operator_redo_refresh(const bContext *UNUSED(C), wmGizmoGroup *gzgroup) +static void WIDGETGROUP_value_operator_redo_refresh(const bContext *UNUSED(C), + wmGizmoGroup *gzgroup) { - struct ValueOpRedoGroup *igzgroup = gzgroup->customdata; - wmGizmo *gz = igzgroup->gizmo; - wmOperator *op = WM_operator_last_redo((bContext *)igzgroup->state.context); - wmGizmoMap *gzmap = gzgroup->parent_gzmap; - - /* FIXME */ - extern struct wmGizmo *wm_gizmomap_modal_get(struct wmGizmoMap *gzmap); - if ((op != igzgroup->state.op) || - (wm_gizmomap_modal_get(gzmap) != gz)) - { - WM_gizmo_group_type_unlink_delayed_ptr(gzgroup->type); - } + struct ValueOpRedoGroup *igzgroup = gzgroup->customdata; + wmGizmo *gz = igzgroup->gizmo; + wmOperator *op = WM_operator_last_redo((bContext *)igzgroup->state.context); + wmGizmoMap *gzmap = gzgroup->parent_gzmap; + + /* FIXME */ + extern struct wmGizmo *wm_gizmomap_modal_get(struct wmGizmoMap * gzmap); + if ((op != igzgroup->state.op) || (wm_gizmomap_modal_get(gzmap) != gz)) { + WM_gizmo_group_type_unlink_delayed_ptr(gzgroup->type); + } } static void WM_GGT_value_operator_redo(wmGizmoGroupType *gzgt) { - gzgt->name = "Value Operator Redo"; - gzgt->idname = "WM_GGT_value_operator_redo"; + gzgt->name = "Value Operator Redo"; + gzgt->idname = "WM_GGT_value_operator_redo"; - /* FIXME, allow multiple. */ - gzgt->flag = WM_GIZMOGROUPTYPE_3D | WM_GIZMOGROUPTYPE_TOOL_INIT; + /* FIXME, allow multiple. */ + gzgt->flag = WM_GIZMOGROUPTYPE_3D | WM_GIZMOGROUPTYPE_TOOL_INIT; - gzgt->gzmap_params.spaceid = SPACE_VIEW3D; - gzgt->gzmap_params.regionid = RGN_TYPE_WINDOW; + gzgt->gzmap_params.spaceid = SPACE_VIEW3D; + gzgt->gzmap_params.regionid = RGN_TYPE_WINDOW; - - gzgt->setup = WIDGETGROUP_value_operator_redo_setup; - gzgt->refresh = WIDGETGROUP_value_operator_redo_refresh; + gzgt->setup = WIDGETGROUP_value_operator_redo_setup; + gzgt->refresh = WIDGETGROUP_value_operator_redo_refresh; } /** \} */ @@ -166,7 +163,7 @@ static void WM_GGT_value_operator_redo(wmGizmoGroupType *gzgt) void ED_gizmogrouptypes_value_2d(void) { - WM_gizmogrouptype_append(WM_GGT_value_operator_redo); + WM_gizmogrouptype_append(WM_GGT_value_operator_redo); } /** \} */ diff --git a/source/blender/editors/gizmo_library/gizmo_library_intern.h b/source/blender/editors/gizmo_library/gizmo_library_intern.h index 7712767c5ad..35782ea8b95 100644 --- a/source/blender/editors/gizmo_library/gizmo_library_intern.h +++ b/source/blender/editors/gizmo_library/gizmo_library_intern.h @@ -31,69 +31,76 @@ * Data for common interactions. Used in gizmo_library_utils.c functions. */ typedef struct GizmoCommonData { - float range_fac; /* factor for arrow min/max distance */ - float offset; + float range_fac; /* factor for arrow min/max distance */ + float offset; - /* property range for constrained gizmos */ - float range; - /* min/max value for constrained gizmos */ - float min, max; + /* property range for constrained gizmos */ + float range; + /* min/max value for constrained gizmos */ + float min, max; - uint is_custom_range_set : 1; + uint is_custom_range_set : 1; } GizmoCommonData; typedef struct GizmoInteraction { - float init_value; /* initial property value */ - float init_mval[2]; - float init_offset; - float init_matrix_final[4][4]; - float init_matrix_basis[4][4]; - - /* offset of last handling step */ - float prev_offset; - /* Total offset added by precision tweaking. - * Needed to allow toggling precision on/off without causing jumps */ - float precision_offset; + float init_value; /* initial property value */ + float init_mval[2]; + float init_offset; + float init_matrix_final[4][4]; + float init_matrix_basis[4][4]; + + /* offset of last handling step */ + float prev_offset; + /* Total offset added by precision tweaking. + * Needed to allow toggling precision on/off without causing jumps */ + float precision_offset; } GizmoInteraction; -float gizmo_offset_from_value( - GizmoCommonData *data, const float value, - const bool constrained, const bool inverted); -float gizmo_value_from_offset( - GizmoCommonData *data, GizmoInteraction *inter, const float offset, - const bool constrained, const bool inverted, const bool use_precision); - -void gizmo_property_data_update( - struct wmGizmo *gz, GizmoCommonData *data, wmGizmoProperty *gz_prop, - const bool constrained, const bool inverted); - -void gizmo_property_value_reset( - bContext *C, const struct wmGizmo *gz, GizmoInteraction *inter, wmGizmoProperty *gz_prop); - +float gizmo_offset_from_value(GizmoCommonData *data, + const float value, + const bool constrained, + const bool inverted); +float gizmo_value_from_offset(GizmoCommonData *data, + GizmoInteraction *inter, + const float offset, + const bool constrained, + const bool inverted, + const bool use_precision); + +void gizmo_property_data_update(struct wmGizmo *gz, + GizmoCommonData *data, + wmGizmoProperty *gz_prop, + const bool constrained, + const bool inverted); + +void gizmo_property_value_reset(bContext *C, + const struct wmGizmo *gz, + GizmoInteraction *inter, + wmGizmoProperty *gz_prop); /* -------------------------------------------------------------------- */ -void gizmo_color_get( - const struct wmGizmo *gz, const bool highlight, - float r_color[4]); +void gizmo_color_get(const struct wmGizmo *gz, const bool highlight, float r_color[4]); -bool gizmo_window_project_2d( - bContext *C, const struct wmGizmo *gz, const float mval[2], int axis, bool use_offset, - float r_co[2]); +bool gizmo_window_project_2d(bContext *C, + const struct wmGizmo *gz, + const float mval[2], + int axis, + bool use_offset, + float r_co[2]); bool gizmo_window_project_3d( - bContext *C, const struct wmGizmo *gz, const float mval[2], bool use_offset, - float r_co[3]); + bContext *C, const struct wmGizmo *gz, const float mval[2], bool use_offset, float r_co[3]); /* -------------------------------------------------------------------- */ /* Gizmo drawing */ #include "gizmo_geometry.h" -void wm_gizmo_geometryinfo_draw(const struct GizmoGeomInfo *info, const bool select, const float color[4]); +void wm_gizmo_geometryinfo_draw(const struct GizmoGeomInfo *info, + const bool select, + const float color[4]); void wm_gizmo_vec_draw( - const float color[4], const float (*verts)[3], uint vert_count, - uint pos, uint primitive_type); - + const float color[4], const float (*verts)[3], uint vert_count, uint pos, uint primitive_type); -#endif /* __GIZMO_LIBRARY_INTERN_H__ */ +#endif /* __GIZMO_LIBRARY_INTERN_H__ */ diff --git a/source/blender/editors/gizmo_library/gizmo_library_presets.c b/source/blender/editors/gizmo_library/gizmo_library_presets.c index 9dba0c0d515..ce62171ccb0 100644 --- a/source/blender/editors/gizmo_library/gizmo_library_presets.c +++ b/source/blender/editors/gizmo_library/gizmo_library_presets.c @@ -48,97 +48,99 @@ #include "ED_screen.h" /* own includes */ -#include "ED_gizmo_library.h" /* own include */ -#include "gizmo_library_intern.h" /* own include */ +#include "ED_gizmo_library.h" /* own include */ +#include "gizmo_library_intern.h" /* own include */ /* TODO, this is to be used by RNA. might move to ED_gizmo_library */ /** * Given a single axis, orient the matrix to a different direction. */ -static void single_axis_convert( - int src_axis, float src_mat[4][4], - int dst_axis, float dst_mat[4][4]) +static void single_axis_convert(int src_axis, + float src_mat[4][4], + int dst_axis, + float dst_mat[4][4]) { - copy_m4_m4(dst_mat, src_mat); - if (src_axis == dst_axis) { - return; - } - - float rotmat[3][3]; - mat3_from_axis_conversion_single(src_axis, dst_axis, rotmat); - transpose_m3(rotmat); - mul_m4_m4m3(dst_mat, src_mat, rotmat); + copy_m4_m4(dst_mat, src_mat); + if (src_axis == dst_axis) { + return; + } + + float rotmat[3][3]; + mat3_from_axis_conversion_single(src_axis, dst_axis, rotmat); + transpose_m3(rotmat); + mul_m4_m4m3(dst_mat, src_mat, rotmat); } /** * Use for all geometry. */ -static void ed_gizmo_draw_preset_geometry( - const struct wmGizmo *gz, float mat[4][4], int select_id, - const GizmoGeomInfo *info) +static void ed_gizmo_draw_preset_geometry(const struct wmGizmo *gz, + float mat[4][4], + int select_id, + const GizmoGeomInfo *info) { - const bool is_select = (select_id != -1); - const bool is_highlight = is_select && (gz->state & WM_GIZMO_STATE_HIGHLIGHT) != 0; + const bool is_select = (select_id != -1); + const bool is_highlight = is_select && (gz->state & WM_GIZMO_STATE_HIGHLIGHT) != 0; - float color[4]; - gizmo_color_get(gz, is_highlight, color); + float color[4]; + gizmo_color_get(gz, is_highlight, color); - if (is_select) { - GPU_select_load_id(select_id); - } + if (is_select) { + GPU_select_load_id(select_id); + } - GPU_matrix_push(); - GPU_matrix_mul(mat); - wm_gizmo_geometryinfo_draw(info, is_select, color); - GPU_matrix_pop(); + GPU_matrix_push(); + GPU_matrix_mul(mat); + wm_gizmo_geometryinfo_draw(info, is_select, color); + GPU_matrix_pop(); - if (is_select) { - GPU_select_load_id(-1); - } + if (is_select) { + GPU_select_load_id(-1); + } } -void ED_gizmo_draw_preset_box( - const struct wmGizmo *gz, float mat[4][4], int select_id) +void ED_gizmo_draw_preset_box(const struct wmGizmo *gz, float mat[4][4], int select_id) { - ed_gizmo_draw_preset_geometry(gz, mat, select_id, &wm_gizmo_geom_data_cube); + ed_gizmo_draw_preset_geometry(gz, mat, select_id, &wm_gizmo_geom_data_cube); } -void ED_gizmo_draw_preset_arrow( - const struct wmGizmo *gz, float mat[4][4], int axis, int select_id) +void ED_gizmo_draw_preset_arrow(const struct wmGizmo *gz, float mat[4][4], int axis, int select_id) { - float mat_rotate[4][4]; - single_axis_convert(OB_POSZ, mat, axis, mat_rotate); - ed_gizmo_draw_preset_geometry(gz, mat_rotate, select_id, &wm_gizmo_geom_data_arrow); + float mat_rotate[4][4]; + single_axis_convert(OB_POSZ, mat, axis, mat_rotate); + ed_gizmo_draw_preset_geometry(gz, mat_rotate, select_id, &wm_gizmo_geom_data_arrow); } -void ED_gizmo_draw_preset_circle( - const struct wmGizmo *gz, float mat[4][4], int axis, int select_id) +void ED_gizmo_draw_preset_circle(const struct wmGizmo *gz, + float mat[4][4], + int axis, + int select_id) { - float mat_rotate[4][4]; - single_axis_convert(OB_POSZ, mat, axis, mat_rotate); - ed_gizmo_draw_preset_geometry(gz, mat_rotate, select_id, &wm_gizmo_geom_data_dial); + float mat_rotate[4][4]; + single_axis_convert(OB_POSZ, mat, axis, mat_rotate); + ed_gizmo_draw_preset_geometry(gz, mat_rotate, select_id, &wm_gizmo_geom_data_dial); } void ED_gizmo_draw_preset_facemap( - const bContext *C, const struct wmGizmo *gz, Object *ob, const int facemap, int select_id) + const bContext *C, const struct wmGizmo *gz, Object *ob, const int facemap, int select_id) { - const bool is_select = (select_id != -1); - const bool is_highlight = is_select && (gz->state & WM_GIZMO_STATE_HIGHLIGHT) != 0; + const bool is_select = (select_id != -1); + const bool is_highlight = is_select && (gz->state & WM_GIZMO_STATE_HIGHLIGHT) != 0; - float color[4]; - gizmo_color_get(gz, is_highlight, color); + float color[4]; + gizmo_color_get(gz, is_highlight, color); - if (is_select) { - GPU_select_load_id(select_id); - } + if (is_select) { + GPU_select_load_id(select_id); + } - GPU_matrix_push(); - GPU_matrix_mul(ob->obmat); - ED_draw_object_facemap(CTX_data_depsgraph(C), ob, color, facemap); - GPU_matrix_pop(); + GPU_matrix_push(); + GPU_matrix_mul(ob->obmat); + ED_draw_object_facemap(CTX_data_depsgraph(C), ob, color, facemap); + GPU_matrix_pop(); - if (is_select) { - GPU_select_load_id(-1); - } + if (is_select) { + GPU_select_load_id(-1); + } } diff --git a/source/blender/editors/gizmo_library/gizmo_library_utils.c b/source/blender/editors/gizmo_library/gizmo_library_utils.c index 0ae312d552e..2e5c3b37542 100644 --- a/source/blender/editors/gizmo_library/gizmo_library_utils.c +++ b/source/blender/editors/gizmo_library/gizmo_library_utils.c @@ -45,114 +45,127 @@ /* factor for precision tweaking */ #define GIZMO_PRECISION_FAC 0.05f - -BLI_INLINE float gizmo_offset_from_value_constr( - const float range_fac, const float min, const float range, const float value, - const bool inverted) +BLI_INLINE float gizmo_offset_from_value_constr(const float range_fac, + const float min, + const float range, + const float value, + const bool inverted) { - return inverted ? (range_fac * (min + range - value) / range) : (range_fac * (value / range)); + return inverted ? (range_fac * (min + range - value) / range) : (range_fac * (value / range)); } -BLI_INLINE float gizmo_value_from_offset_constr( - const float range_fac, const float min, const float range, const float value, - const bool inverted) +BLI_INLINE float gizmo_value_from_offset_constr(const float range_fac, + const float min, + const float range, + const float value, + const bool inverted) { - return inverted ? (min + range - (value * range / range_fac)) : (value * range / range_fac); + return inverted ? (min + range - (value * range / range_fac)) : (value * range / range_fac); } -float gizmo_offset_from_value( - GizmoCommonData *data, const float value, const bool constrained, const bool inverted) +float gizmo_offset_from_value(GizmoCommonData *data, + const float value, + const bool constrained, + const bool inverted) { - if (constrained) - return gizmo_offset_from_value_constr(data->range_fac, data->min, data->range, value, inverted); + if (constrained) + return gizmo_offset_from_value_constr( + data->range_fac, data->min, data->range, value, inverted); - return value; + return value; } -float gizmo_value_from_offset( - GizmoCommonData *data, GizmoInteraction *inter, const float offset, - const bool constrained, const bool inverted, const bool use_precision) +float gizmo_value_from_offset(GizmoCommonData *data, + GizmoInteraction *inter, + const float offset, + const bool constrained, + const bool inverted, + const bool use_precision) { - const float max = data->min + data->range; - - if (use_precision) { - /* add delta offset of this step to total precision_offset */ - inter->precision_offset += offset - inter->prev_offset; - } - inter->prev_offset = offset; - - float ofs_new = inter->init_offset + offset - inter->precision_offset * (1.0f - GIZMO_PRECISION_FAC); - float value; - - if (constrained) { - value = gizmo_value_from_offset_constr(data->range_fac, data->min, data->range, ofs_new, inverted); - } - else { - value = ofs_new; - } - - /* clamp to custom range */ - if (data->is_custom_range_set) { - CLAMP(value, data->min, max); - } - - return value; + const float max = data->min + data->range; + + if (use_precision) { + /* add delta offset of this step to total precision_offset */ + inter->precision_offset += offset - inter->prev_offset; + } + inter->prev_offset = offset; + + float ofs_new = inter->init_offset + offset - + inter->precision_offset * (1.0f - GIZMO_PRECISION_FAC); + float value; + + if (constrained) { + value = gizmo_value_from_offset_constr( + data->range_fac, data->min, data->range, ofs_new, inverted); + } + else { + value = ofs_new; + } + + /* clamp to custom range */ + if (data->is_custom_range_set) { + CLAMP(value, data->min, max); + } + + return value; } -void gizmo_property_data_update( - wmGizmo *gz, GizmoCommonData *data, wmGizmoProperty *gz_prop, - const bool constrained, const bool inverted) +void gizmo_property_data_update(wmGizmo *gz, + GizmoCommonData *data, + wmGizmoProperty *gz_prop, + const bool constrained, + const bool inverted) { - if (gz_prop->custom_func.value_get_fn != NULL) { - /* pass */ - } - else if (gz_prop->prop != NULL) { - /* pass */ - } - else { - data->offset = 0.0f; - return; - } - - float value = WM_gizmo_target_property_float_get(gz, gz_prop); - - if (constrained) { - if (data->is_custom_range_set == false) { - float range[2]; - if (WM_gizmo_target_property_float_range_get(gz, gz_prop, range)) { - data->range = range[1] - range[0]; - data->min = range[0]; - } - else { - BLI_assert(0); - } - } - data->offset = gizmo_offset_from_value_constr(data->range_fac, data->min, data->range, value, inverted); - } - else { - data->offset = value; - } + if (gz_prop->custom_func.value_get_fn != NULL) { + /* pass */ + } + else if (gz_prop->prop != NULL) { + /* pass */ + } + else { + data->offset = 0.0f; + return; + } + + float value = WM_gizmo_target_property_float_get(gz, gz_prop); + + if (constrained) { + if (data->is_custom_range_set == false) { + float range[2]; + if (WM_gizmo_target_property_float_range_get(gz, gz_prop, range)) { + data->range = range[1] - range[0]; + data->min = range[0]; + } + else { + BLI_assert(0); + } + } + data->offset = gizmo_offset_from_value_constr( + data->range_fac, data->min, data->range, value, inverted); + } + else { + data->offset = value; + } } -void gizmo_property_value_reset( - bContext *C, const wmGizmo *gz, GizmoInteraction *inter, - wmGizmoProperty *gz_prop) +void gizmo_property_value_reset(bContext *C, + const wmGizmo *gz, + GizmoInteraction *inter, + wmGizmoProperty *gz_prop) { - WM_gizmo_target_property_float_set(C, gz, gz_prop, inter->init_value); + WM_gizmo_target_property_float_set(C, gz, gz_prop, inter->init_value); } /* -------------------------------------------------------------------- */ -void gizmo_color_get( - const wmGizmo *gz, const bool highlight, - float r_col[4]) +void gizmo_color_get(const wmGizmo *gz, const bool highlight, float r_col[4]) { - if (highlight && !(gz->flag & WM_GIZMO_DRAW_HOVER)) { - copy_v4_v4(r_col, gz->color_hi); - } - else { - copy_v4_v4(r_col, gz->color); - } + if (highlight && !(gz->flag & WM_GIZMO_DRAW_HOVER)) { + copy_v4_v4(r_col, gz->color_hi); + } + else { + copy_v4_v4(r_col, gz->color); + } } /* -------------------------------------------------------------------- */ @@ -161,80 +174,82 @@ void gizmo_color_get( * Takes mouse coordinates and returns them in relation to the gizmo. * Both 2D & 3D supported, use so we can use 2D gizmos in the 3D view. */ -bool gizmo_window_project_2d( - bContext *C, const struct wmGizmo *gz, const float mval[2], int axis, bool use_offset, - float r_co[2]) +bool gizmo_window_project_2d(bContext *C, + const struct wmGizmo *gz, + const float mval[2], + int axis, + bool use_offset, + float r_co[2]) { - float mat[4][4]; - { - float mat_identity[4][4]; - struct WM_GizmoMatrixParams params = {NULL}; - if (use_offset == false) { - unit_m4(mat_identity); - params.matrix_offset = mat_identity; - } - WM_gizmo_calc_matrix_final_params(gz, ¶ms, mat); - } - - /* rotate mouse in relation to the center and relocate it */ - if (gz->parent_gzgroup->type->flag & WM_GIZMOGROUPTYPE_3D) { - /* For 3d views, transform 2D mouse pos onto plane. */ - ARegion *ar = CTX_wm_region(C); - - float plane[4], co[3]; - plane_from_point_normal_v3(plane, mat[3], mat[2]); - bool clip_ray = ((RegionView3D *)ar->regiondata)->is_persp; - if (ED_view3d_win_to_3d_on_plane(ar, plane, mval, clip_ray, co)) { - float imat[4][4]; - invert_m4_m4(imat, mat); - mul_m4_v3(imat, co); - r_co[0] = co[(axis + 1) % 3]; - r_co[1] = co[(axis + 2) % 3]; - return true; - } - return false; - } - else { - float co[3] = {mval[0], mval[1], 0.0f}; - float imat[4][4]; - invert_m4_m4(imat, mat); - mul_m4_v3(imat, co); - copy_v2_v2(r_co, co); - return true; - } + float mat[4][4]; + { + float mat_identity[4][4]; + struct WM_GizmoMatrixParams params = {NULL}; + if (use_offset == false) { + unit_m4(mat_identity); + params.matrix_offset = mat_identity; + } + WM_gizmo_calc_matrix_final_params(gz, ¶ms, mat); + } + + /* rotate mouse in relation to the center and relocate it */ + if (gz->parent_gzgroup->type->flag & WM_GIZMOGROUPTYPE_3D) { + /* For 3d views, transform 2D mouse pos onto plane. */ + ARegion *ar = CTX_wm_region(C); + + float plane[4], co[3]; + plane_from_point_normal_v3(plane, mat[3], mat[2]); + bool clip_ray = ((RegionView3D *)ar->regiondata)->is_persp; + if (ED_view3d_win_to_3d_on_plane(ar, plane, mval, clip_ray, co)) { + float imat[4][4]; + invert_m4_m4(imat, mat); + mul_m4_v3(imat, co); + r_co[0] = co[(axis + 1) % 3]; + r_co[1] = co[(axis + 2) % 3]; + return true; + } + return false; + } + else { + float co[3] = {mval[0], mval[1], 0.0f}; + float imat[4][4]; + invert_m4_m4(imat, mat); + mul_m4_v3(imat, co); + copy_v2_v2(r_co, co); + return true; + } } bool gizmo_window_project_3d( - bContext *C, const struct wmGizmo *gz, const float mval[2], bool use_offset, - float r_co[3]) + bContext *C, const struct wmGizmo *gz, const float mval[2], bool use_offset, float r_co[3]) { - float mat[4][4]; - { - float mat_identity[4][4]; - struct WM_GizmoMatrixParams params = {NULL}; - if (use_offset == false) { - unit_m4(mat_identity); - params.matrix_offset = mat_identity; - } - WM_gizmo_calc_matrix_final_params(gz, ¶ms, mat); - } - - if (gz->parent_gzgroup->type->flag & WM_GIZMOGROUPTYPE_3D) { - View3D *v3d = CTX_wm_view3d(C); - ARegion *ar = CTX_wm_region(C); - /* Note: we might want a custom reference point passed in, - * instead of the gizmo center. */ - ED_view3d_win_to_3d(v3d, ar, mat[3], mval, r_co); - invert_m4(mat); - mul_m4_v3(mat, r_co); - return true; - } - else { - float co[3] = {mval[0], mval[1], 0.0f}; - float imat[4][4]; - invert_m4_m4(imat, mat); - mul_m4_v3(imat, co); - copy_v2_v2(r_co, co); - return true; - } + float mat[4][4]; + { + float mat_identity[4][4]; + struct WM_GizmoMatrixParams params = {NULL}; + if (use_offset == false) { + unit_m4(mat_identity); + params.matrix_offset = mat_identity; + } + WM_gizmo_calc_matrix_final_params(gz, ¶ms, mat); + } + + if (gz->parent_gzgroup->type->flag & WM_GIZMOGROUPTYPE_3D) { + View3D *v3d = CTX_wm_view3d(C); + ARegion *ar = CTX_wm_region(C); + /* Note: we might want a custom reference point passed in, + * instead of the gizmo center. */ + ED_view3d_win_to_3d(v3d, ar, mat[3], mval, r_co); + invert_m4(mat); + mul_m4_v3(mat, r_co); + return true; + } + else { + float co[3] = {mval[0], mval[1], 0.0f}; + float imat[4][4]; + invert_m4_m4(imat, mat); + mul_m4_v3(imat, co); + copy_v2_v2(r_co, co); + return true; + } } 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, ¶ms, 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, ¶ms, 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); } /** \} */ -- cgit v1.2.3