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 --- .../editors/gizmo_library/gizmo_library_utils.c | 329 +++++++++++---------- 1 file changed, 172 insertions(+), 157 deletions(-) (limited to 'source/blender/editors/gizmo_library/gizmo_library_utils.c') 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; + } } -- cgit v1.2.3