diff options
Diffstat (limited to 'scene/gui/range.cpp')
-rw-r--r-- | scene/gui/range.cpp | 162 |
1 files changed, 75 insertions, 87 deletions
diff --git a/scene/gui/range.cpp b/scene/gui/range.cpp index f434aff08d..f15f3a6078 100644 --- a/scene/gui/range.cpp +++ b/scene/gui/range.cpp @@ -28,20 +28,18 @@ /*************************************************************************/ #include "range.h" - - void Range::_value_changed_notify() { _value_changed(shared->val); - emit_signal("value_changed",shared->val); + emit_signal("value_changed", shared->val); update(); _change_notify("range/value"); } void Range::Shared::emit_value_changed() { - for (Set<Range*>::Element *E=owners.front();E;E=E->next()) { - Range *r=E->get(); + for (Set<Range *>::Element *E = owners.front(); E; E = E->next()) { + Range *r = E->get(); if (!r->is_inside_tree()) continue; r->_value_changed_notify(); @@ -50,65 +48,62 @@ void Range::Shared::emit_value_changed() { void Range::_changed_notify(const char *p_what) { - emit_signal("changed",shared->val); + emit_signal("changed", shared->val); update(); _change_notify(p_what); } void Range::Shared::emit_changed(const char *p_what) { - for (Set<Range*>::Element *E=owners.front();E;E=E->next()) { - Range *r=E->get(); + for (Set<Range *>::Element *E = owners.front(); E; E = E->next()) { + Range *r = E->get(); if (!r->is_inside_tree()) continue; r->_changed_notify(p_what); } } - void Range::set_value(double p_val) { - if(_rounded_values){ + if (_rounded_values) { p_val = Math::round(p_val); } - if (p_val>shared->max-shared->page) - p_val=shared->max-shared->page; + if (p_val > shared->max - shared->page) + p_val = shared->max - shared->page; - if (p_val<shared->min) - p_val=shared->min; + if (p_val < shared->min) + p_val = shared->min; - if (shared->val==p_val) + if (shared->val == p_val) return; - shared->val=p_val; + shared->val = p_val; shared->emit_value_changed(); } void Range::set_min(double p_min) { - shared->min=p_min; + shared->min = p_min; set_value(shared->val); shared->emit_changed("range/min"); } void Range::set_max(double p_max) { - shared->max=p_max; + shared->max = p_max; set_value(shared->val); shared->emit_changed("range/max"); - } void Range::set_step(double p_step) { - shared->step=p_step; + shared->step = p_step; shared->emit_changed("range/step"); - } void Range::set_page(double p_page) { - shared->page=p_page; + shared->page = p_page; set_value(shared->val); shared->emit_changed("range/page"); @@ -139,11 +134,11 @@ void Range::set_as_ratio(double p_value) { double v; - if (shared->exp_ratio && get_min()>0) { + if (shared->exp_ratio && get_min() > 0) { - double exp_min = Math::log(get_min())/Math::log((double)2); - double exp_max = Math::log(get_max())/Math::log((double)2); - v = Math::pow(2,exp_min+(exp_max-exp_min)*p_value); + double exp_min = Math::log(get_min()) / Math::log((double)2); + double exp_max = Math::log(get_max()) / Math::log((double)2); + v = Math::pow(2, exp_min + (exp_max - exp_min) * p_value); } else { double percent = (get_max() - get_min()) * p_value; @@ -154,15 +149,15 @@ void Range::set_as_ratio(double p_value) { v = percent + get_min(); } } - set_value( v ); + set_value(v); } double Range::get_as_ratio() const { - if (shared->exp_ratio && get_min()>0) { + if (shared->exp_ratio && get_min() > 0) { - double exp_min = Math::log(get_min())/Math::log((double)2); - double exp_max = Math::log(get_max())/Math::log((double)2); - double v = Math::log(get_value())/Math::log((double)2); + double exp_min = Math::log(get_min()) / Math::log((double)2); + double exp_max = Math::log(get_max()) / Math::log((double)2); + double v = Math::log(get_value()) / Math::log((double)2); return (v - exp_min) / (exp_max - exp_min); @@ -174,7 +169,7 @@ double Range::get_as_ratio() const { void Range::_share(Node *p_range) { - Range * r = p_range->cast_to<Range>(); + Range *r = p_range->cast_to<Range>(); ERR_FAIL_COND(!r); share(r); } @@ -190,69 +185,67 @@ void Range::share(Range *p_range) { void Range::unshare() { - Shared * nshared = memnew(Shared); - nshared->min=shared->min; - nshared->max=shared->max; - nshared->val=shared->val; - nshared->step=shared->step; - nshared->page=shared->page; + Shared *nshared = memnew(Shared); + nshared->min = shared->min; + nshared->max = shared->max; + nshared->val = shared->val; + nshared->step = shared->step; + nshared->page = shared->page; _unref_shared(); _ref_shared(nshared); } void Range::_ref_shared(Shared *p_shared) { - if (shared && p_shared==shared) + if (shared && p_shared == shared) return; _unref_shared(); - shared=p_shared; + shared = p_shared; shared->owners.insert(this); } - void Range::_unref_shared() { shared->owners.erase(this); - if (shared->owners.size()==0) { + if (shared->owners.size() == 0) { memdelete(shared); - shared=NULL; + shared = NULL; } } void Range::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_value"),&Range::get_value); - ClassDB::bind_method(D_METHOD("get_min"),&Range::get_min); - ClassDB::bind_method(D_METHOD("get_max"),&Range::get_max); - ClassDB::bind_method(D_METHOD("get_step"),&Range::get_step); - ClassDB::bind_method(D_METHOD("get_page"),&Range::get_page); - ClassDB::bind_method(D_METHOD("get_as_ratio"),&Range::get_as_ratio); - ClassDB::bind_method(D_METHOD("set_value","value"),&Range::set_value); - ClassDB::bind_method(D_METHOD("set_min","minimum"),&Range::set_min); - ClassDB::bind_method(D_METHOD("set_max","maximum"),&Range::set_max); - ClassDB::bind_method(D_METHOD("set_step","step"),&Range::set_step); - ClassDB::bind_method(D_METHOD("set_page","pagesize"),&Range::set_page); - ClassDB::bind_method(D_METHOD("set_as_ratio","value"),&Range::set_as_ratio); - ClassDB::bind_method(D_METHOD("set_use_rounded_values","enabled"),&Range::set_use_rounded_values); - ClassDB::bind_method(D_METHOD("is_using_rounded_values"),&Range::is_using_rounded_values); - ClassDB::bind_method(D_METHOD("set_exp_ratio","enabled"),&Range::set_exp_ratio); - ClassDB::bind_method(D_METHOD("is_ratio_exp"),&Range::is_ratio_exp); - - ClassDB::bind_method(D_METHOD("share","with"),&Range::_share); - ClassDB::bind_method(D_METHOD("unshare"),&Range::unshare); - - ADD_SIGNAL( MethodInfo("value_changed", PropertyInfo(Variant::REAL,"value"))); - ADD_SIGNAL( MethodInfo("changed")); - - ADD_PROPERTY( PropertyInfo( Variant::REAL, "min_value" ), "set_min", "get_min") ; - ADD_PROPERTY( PropertyInfo( Variant::REAL, "max_value" ), "set_max", "get_max") ; - ADD_PROPERTY( PropertyInfo( Variant::REAL, "step" ), "set_step", "get_step") ; - ADD_PROPERTY( PropertyInfo( Variant::REAL, "page" ), "set_page", "get_page") ; - ADD_PROPERTY( PropertyInfo( Variant::REAL, "value" ), "set_value", "get_value") ; - ADD_PROPERTY( PropertyInfo( Variant::BOOL, "exp_edit" ), "set_exp_ratio", "is_ratio_exp") ; - ADD_PROPERTY( PropertyInfo( Variant::BOOL, "rounded" ), "set_use_rounded_values", "is_using_rounded_values") ; - + ClassDB::bind_method(D_METHOD("get_value"), &Range::get_value); + ClassDB::bind_method(D_METHOD("get_min"), &Range::get_min); + ClassDB::bind_method(D_METHOD("get_max"), &Range::get_max); + ClassDB::bind_method(D_METHOD("get_step"), &Range::get_step); + ClassDB::bind_method(D_METHOD("get_page"), &Range::get_page); + ClassDB::bind_method(D_METHOD("get_as_ratio"), &Range::get_as_ratio); + ClassDB::bind_method(D_METHOD("set_value", "value"), &Range::set_value); + ClassDB::bind_method(D_METHOD("set_min", "minimum"), &Range::set_min); + ClassDB::bind_method(D_METHOD("set_max", "maximum"), &Range::set_max); + ClassDB::bind_method(D_METHOD("set_step", "step"), &Range::set_step); + ClassDB::bind_method(D_METHOD("set_page", "pagesize"), &Range::set_page); + ClassDB::bind_method(D_METHOD("set_as_ratio", "value"), &Range::set_as_ratio); + ClassDB::bind_method(D_METHOD("set_use_rounded_values", "enabled"), &Range::set_use_rounded_values); + ClassDB::bind_method(D_METHOD("is_using_rounded_values"), &Range::is_using_rounded_values); + ClassDB::bind_method(D_METHOD("set_exp_ratio", "enabled"), &Range::set_exp_ratio); + ClassDB::bind_method(D_METHOD("is_ratio_exp"), &Range::is_ratio_exp); + + ClassDB::bind_method(D_METHOD("share", "with"), &Range::_share); + ClassDB::bind_method(D_METHOD("unshare"), &Range::unshare); + + ADD_SIGNAL(MethodInfo("value_changed", PropertyInfo(Variant::REAL, "value"))); + ADD_SIGNAL(MethodInfo("changed")); + + ADD_PROPERTY(PropertyInfo(Variant::REAL, "min_value"), "set_min", "get_min"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "max_value"), "set_max", "get_max"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "step"), "set_step", "get_step"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "page"), "set_page", "get_page"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "value"), "set_value", "get_value"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "exp_edit"), "set_exp_ratio", "is_ratio_exp"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "rounded"), "set_use_rounded_values", "is_using_rounded_values"); } void Range::set_use_rounded_values(bool p_enable) { @@ -267,7 +260,7 @@ bool Range::is_using_rounded_values() const { void Range::set_exp_ratio(bool p_enable) { - shared->exp_ratio=p_enable; + shared->exp_ratio = p_enable; } bool Range::is_ratio_exp() const { @@ -275,25 +268,20 @@ bool Range::is_ratio_exp() const { return shared->exp_ratio; } - -Range::Range() -{ +Range::Range() { shared = memnew(Shared); - shared->min=0; - shared->max=100; - shared->val= - shared->step=1; - shared->page=0; + shared->min = 0; + shared->max = 100; + shared->val = + shared->step = 1; + shared->page = 0; shared->owners.insert(this); - shared->exp_ratio=false; + shared->exp_ratio = false; _rounded_values = false; } - Range::~Range() { _unref_shared(); } - - |