From d12ceec40146f98b6d584a6ea276ab77834d816e Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Thu, 24 Apr 2014 17:17:55 +0200 Subject: Fix T39861: UI destroys float precision. Note this is only a workaround in fact, adding some precision in radians case. Validating the field will still generate a precision loss (doing otherwise is doable-ish, but likely to backfire and/or add too much complexity in an already complex area). --- source/blender/editors/interface/interface.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'source') diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 2cf2a46529e..6e1398549a6 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -98,6 +98,19 @@ bool ui_block_is_menu(const uiBlock *block) ((block->flag & UI_BLOCK_KEEP_OPEN) == 0)); } +static bool ui_is_but_unit_radians_ex(UnitSettings *unit, const int unit_type) +{ + return (unit->system_rotation == USER_UNIT_ROT_RADIANS && unit_type == PROP_UNIT_ROTATION); +} + +static bool ui_is_but_unit_radians(const uiBut *but) +{ + UnitSettings *unit = but->block->unit; + const int unit_type = uiButGetUnitType(but); + + return ui_is_but_unit_radians_ex(unit, unit_type); +} + /* ************* window matrix ************** */ void ui_block_to_window_fl(const ARegion *ar, uiBlock *block, float *x, float *y) @@ -429,10 +442,15 @@ void uiExplicitBoundsBlock(uiBlock *block, int minx, int miny, int maxx, int max static int ui_but_float_precision(uiBut *but, double value) { - int prec; + int prec = (int)but->a2; - /* first check if prec is 0 and fallback to a simple default */ - if ((prec = (int)but->a2) == -1) { + /* first check for various special cases: + * * If button is radians, we want additional precision (see T39861). + * * If prec is not set, we fallback to a simple default */ + if (ui_is_but_unit_radians(but) && prec < 5) { + prec = 5; + } + else if (prec == -1) { prec = (but->hardmax < 10.001f) ? 3 : 2; } @@ -1611,7 +1629,7 @@ bool ui_is_but_unit(const uiBut *but) return false; #if 1 /* removed so angle buttons get correct snapping */ - if (unit->system_rotation == USER_UNIT_ROT_RADIANS && unit_type == PROP_UNIT_ROTATION) + if (ui_is_but_unit_radians_ex(unit, unit_type)) return false; #endif -- cgit v1.2.3