diff options
| author | Juan Linietsky | 2017-01-02 19:12:25 -0300 |
|---|---|---|
| committer | Juan Linietsky | 2017-01-02 19:12:25 -0300 |
| commit | ce26eb74bca48f16e9a34b4eb1c34e50dfc5daae (patch) | |
| tree | 5f9c387037d0142d40f7275575436483dc0a7237 /scene/gui/range.cpp | |
| parent | ab4126f51061277e87b41c48b40e7b54942d4eca (diff) | |
| parent | 45c5c89de961357a7042d9e1f063e288d7a510cf (diff) | |
| download | godot-ce26eb74bca48f16e9a34b4eb1c34e50dfc5daae.tar.gz godot-ce26eb74bca48f16e9a34b4eb1c34e50dfc5daae.tar.zst godot-ce26eb74bca48f16e9a34b4eb1c34e50dfc5daae.zip | |
Diffstat (limited to 'scene/gui/range.cpp')
| -rw-r--r-- | scene/gui/range.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/scene/gui/range.cpp b/scene/gui/range.cpp index e056c55f7..ef0e735af 100644 --- a/scene/gui/range.cpp +++ b/scene/gui/range.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -136,16 +136,25 @@ double Range::get_page() const { } void Range::set_unit_value(double p_value) { + + double v; + if (shared->exp_unit_value && get_min()>0) { double exp_min = Math::log(get_min())/Math::log(2); double exp_max = Math::log(get_max())/Math::log(2); - double v = Math::pow(2,exp_min+(exp_max-exp_min)*p_value); - - set_val( v ); + v = Math::pow(2,exp_min+(exp_max-exp_min)*p_value); } else { - set_val( (get_max() - get_min()) * p_value + get_min() ); + + double percent = (get_max() - get_min()) * p_value; + if (get_step() > 0) { + double steps = round(percent / get_step()); + v = steps * get_step() + get_min(); + } else { + v = percent + get_min(); + } } + set_val( v ); } double Range::get_unit_value() const { |
