From 0447aedb960a1dc514fee8cd99d0eee43fae86ad Mon Sep 17 00:00:00 2001 From: Henrik Dick Date: Mon, 17 May 2021 17:28:12 +1000 Subject: UI: add non-linear slider support This patch introduces non linear sliders. That means, that the movement of the mouse doesn't map linearly to the value of the slider. The following changes have been made. - Free logarithmic sliders with maximum range of (`0 <= x < inf`) - Logarithmic sliders with correct value indication bar. - Free cubic sliders with maximum range of (`-inf < x < inf`) - Cubic sliders with correct value indication bar. Cubic mapping has been added as well, because it's used for brush sizes in other applications (Krita for e.g.). To make a slider have a different scale type use following line in RNA: `RNA_def_property_ui_scale_type(prop, PROP_SCALE_LOGARITHMIC);` or: `RNA_def_property_ui_scale_type(prop, PROP_SCALE_CUBIC);` Test the precision, step size and soft-min if you change the scale type of a property as it will feel very different and may need tweaking. Ref D9074 --- source/blender/makesrna/intern/rna_define.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'source/blender/makesrna/intern/rna_define.c') diff --git a/source/blender/makesrna/intern/rna_define.c b/source/blender/makesrna/intern/rna_define.c index 2fdf7e5eaa7..9b9d561603b 100644 --- a/source/blender/makesrna/intern/rna_define.c +++ b/source/blender/makesrna/intern/rna_define.c @@ -1754,6 +1754,28 @@ void RNA_def_property_ui_range( } } +void RNA_def_property_ui_scale_type(PropertyRNA *prop, PropertyScaleType ui_scale_type) +{ + StructRNA *srna = DefRNA.laststruct; + + switch (prop->type) { + case PROP_INT: { + IntPropertyRNA *iprop = (IntPropertyRNA *)prop; + iprop->ui_scale_type = ui_scale_type; + break; + } + case PROP_FLOAT: { + FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop; + fprop->ui_scale_type = ui_scale_type; + break; + } + default: + CLOG_ERROR(&LOG, "\"%s.%s\", invalid type for scale.", srna->identifier, prop->identifier); + DefRNA.error = true; + break; + } +} + void RNA_def_property_range(PropertyRNA *prop, double min, double max) { StructRNA *srna = DefRNA.laststruct; -- cgit v1.2.3