diff options
author | Jeroen Bakker <j.bakker@atmind.nl> | 2019-03-15 14:10:09 +0300 |
---|---|---|
committer | Jeroen Bakker <j.bakker@atmind.nl> | 2019-03-20 16:00:18 +0300 |
commit | daa4d4dd25877c3352d26c6ac89a4cc2e05c10fa (patch) | |
tree | bad5cc77cc7a4308e7607c5c09e95f48a211aa0b /source/blender/editors/gizmo_library | |
parent | d3ee995eafa9640bad51f6bb0c3f69b6d6aca4e6 (diff) |
Fix T62248: Infinite Hotspot Size Crop Node
When the area of the crop node is zero the hotspot margin becomes infinite.
This makes the gizmo by default think the translate mode hotspot is everywhere.
This fix will return a state if the INFINITY is detected so we can
return the hotspot drawing.
The cage2d gizmo is still not usable for sizes of 0 by 0 as now it won't
draw anything. the issues of the gizmo should be re-designed so we can
mitigate these limitations. But that is out of scope for this fix.
Reviewed By: campbellbarton
Maniphest Tasks: T62248
Differential Revision: https://developer.blender.org/D4516
Diffstat (limited to 'source/blender/editors/gizmo_library')
-rw-r--r-- | source/blender/editors/gizmo_library/gizmo_types/cage2d_gizmo.c | 26 |
1 files changed, 20 insertions, 6 deletions
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 d25f982fc23..2d8f48f8187 100644 --- a/source/blender/editors/gizmo_library/gizmo_types/cage2d_gizmo.c +++ b/source/blender/editors/gizmo_library/gizmo_types/cage2d_gizmo.c @@ -60,7 +60,7 @@ #define GIZMO_RESIZER_SIZE 10.0f #define GIZMO_MARGIN_OFFSET_SCALE 1.5f -static void gizmo_calc_rect_view_scale( +static bool gizmo_calc_rect_view_scale( const wmGizmo *gz, const float dims[2], float scale[2]) { float matrix_final_no_offset[4][4]; @@ -79,11 +79,19 @@ static void gizmo_calc_rect_view_scale( mul_v2_v2(x_axis, asp); mul_v2_v2(y_axis, asp); - scale[0] = 1.0f / len_v3(x_axis); - scale[1] = 1.0f / len_v3(y_axis); + 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 void gizmo_calc_rect_view_margin( +static bool gizmo_calc_rect_view_margin( const wmGizmo *gz, const float dims[2], float margin[2]) { float handle_size; @@ -95,9 +103,12 @@ static void gizmo_calc_rect_view_margin( } handle_size *= gz->scale_final; float scale_xy[2]; - gizmo_calc_rect_view_scale(gz, dims, scale_xy); + 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; } /* -------------------------------------------------------------------- */ @@ -725,7 +736,10 @@ static int gizmo_cage2d_test_select( } float margin[2]; - gizmo_calc_rect_view_margin(gz, dims, margin); + 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}; |