diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-09-15 21:37:00 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-09-15 21:37:00 +0400 |
commit | 7d8f0fce7a551ff39a86cb5a113df8ae9b0b57cf (patch) | |
tree | a802ed68893c3010d4927612d8c202c720996185 /source/blender/editors/interface/interface.c | |
parent | fb454bfe08e72ec5c546d91627a90a8989432e76 (diff) |
patch [#23758] Better handling of UTF chars in UNITS fields (lengths, angles, etc.)
from Lorenzo Tozzi (oni_niubbo) with minor edits.
--- from the tracker
The present situation is this: due to bug#22274, during editing, UTF chars are stripped from buttons with a unit associated
(length, angles, etc.).
Example: if the button displays '90°' and you click on it with LMB, the editing string will become '90'.
The problem arises if you use microns: '34µm' becomes '34' that blender interprets as 34 meters. So clicking on a button
and hitting enter won't confirm the previous value, but will change it (very badly also).
Of course nobody is using microns in blender, but the problem will arise when we will implement areas and option 'Separate
Units' will be enabled. The value '2m² 3cm²' will become '2m' during editing.
This patch solves the problem rewriting the string in a smarter way than just stripping the UTF chars: the unit is translated
from unit->name_short ('µm') to unit->name_alt ('um'). So clicking on '34µm' the editing string will become
'34um'.
--- end
note: rather then allowing empty strings in name_alt field I made it so if the unit system was the default one a NULL name_alt will just strip the string, since its the default its not needed.
Diffstat (limited to 'source/blender/editors/interface/interface.c')
-rw-r--r-- | source/blender/editors/interface/interface.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 021dcc940e6..59e0af634b8 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -1443,6 +1443,23 @@ static double ui_get_but_scale_unit(uiBut *but, double value) } } +/* str will be overwritten */ +void ui_convert_to_unit_alt_name(uiBut *but, char *str, int maxlen) +{ + if(ui_is_but_unit(but)) { + int unit_type= RNA_SUBTYPE_UNIT_VALUE(RNA_property_subtype(but->rnaprop)); + char *orig_str; + Scene *scene= CTX_data_scene((bContext *)but->block->evil_C); + + orig_str= MEM_callocN(sizeof(char)*maxlen + 1, "textedit sub str"); + memcpy(orig_str, str, maxlen); + + bUnit_ToUnitAltName(str, maxlen, orig_str, scene->unit.system, unit_type); + + MEM_freeN(orig_str); + } +} + static void ui_get_but_string_unit(uiBut *but, char *str, int len_max, double value, int pad) { Scene *scene= CTX_data_scene((bContext *)but->block->evil_C); |