diff --git a/config.cpp b/config.cpp index e255ea74..7ab36ec0 100644 --- a/config.cpp +++ b/config.cpp @@ -2360,9 +2360,9 @@ EX void projectionDialog() { dialog::add_action([] () { *dialog::get_ne().editwhat = -1; vpconf.scale = 1; dialog::get_ne().s = "-1"; }); } dialog::addItem(sphere ? "orthographic" : "Gans model", 'O'); - dialog::add_action([] () { vpconf.alpha = vpconf.scale = 999; dialog::get_ne().s = dialog::disp(vpconf.alpha); }); + dialog::add_action([] () { vpconf.alpha = vpconf.scale = 999; dialog::get_ne().reset_str(); }); dialog::addItem(sphere ? "towards orthographic" : "towards Gans model", 'T'); - dialog::add_action([] () { double d = 1.1; vpconf.alpha *= d; vpconf.scale *= d; dialog::get_ne().s = dialog::disp(vpconf.alpha); }); + dialog::add_action([] () { double d = 1.1; vpconf.alpha *= d; vpconf.scale *= d; dialog::get_ne().reset_str(); }); }; } diff --git a/dialogs.cpp b/dialogs.cpp index ba3e11fc..8e0ea6b8 100644 --- a/dialogs.cpp +++ b/dialogs.cpp @@ -48,7 +48,7 @@ EX namespace dialog { const static scaler asinhic100 = {[] (ld x) { return asinh(x*100); }, [] (ld x) { return sinh(x)/100; }, false}; /** extendable dialog */ - struct extdialog { + struct extdialog : funbase { string title, help; int dialogflags; reaction_t reaction; @@ -73,17 +73,19 @@ EX namespace dialog { void draw() override; void apply_edit(); void apply_slider(); + string disp(ld x); + void reset_str() { s = disp(*editwhat); } }; #endif EX number_dialog& get_ne() { - auto ptr = screens.back().target(); + auto ptr = dynamic_cast (screens.back().target_base()); if(!ptr) throw hr_exception("get_ne() called without number dialog"); return *ptr; } EX extdialog& get_di() { - auto ptr = screens.back().target(); + auto ptr = dynamic_cast (screens.back().target_base()); if(!ptr) throw hr_exception("get_di() called without extdialog"); return *ptr; } @@ -1167,10 +1169,9 @@ EX namespace dialog { else return int(x-.5); } - EX string disp(ld x) { - auto& ne = get_ne(); - if(ne.dialogflags & sm::HEXEDIT) return "0x" + itsh((unsigned long long)(x)); - if(ne.intval) return its(ldtoint(x)); + string number_dialog::disp(ld x) { + if(dialogflags & sm::HEXEDIT) return "0x" + itsh((unsigned long long)(x)); + if(intval) return its(ldtoint(x)); return fts(x); } @@ -1179,7 +1180,7 @@ EX namespace dialog { if(ne.intval) *ne.intval = ldtoint(*ne.editwhat); if(ne.reaction) ne.reaction(); if(ne.intval) *ne.editwhat = *ne.intval; - ne.s = disp(*ne.editwhat); + reset_str(); #if CAP_ANIMATIONS anims::deanimate(anims::find_param(ne.editwhat)); #endif @@ -1188,7 +1189,7 @@ EX namespace dialog { EX void use_hexeditor() { auto& ne = get_ne(); ne.dialogflags |= sm::HEXEDIT; - ne.s = disp(*ne.editwhat); + ne.reset_str(); } void number_dialog::apply_edit() { @@ -1460,7 +1461,6 @@ EX namespace dialog { EX void editNumber(ld& x, ld vmin, ld vmax, ld step, ld dft, string title, string help) { number_dialog ne; ne.editwhat = &x; - ne.s = disp(x); ne.vmin = vmin; ne.vmax = vmax; ne.step = step; @@ -1473,6 +1473,7 @@ EX namespace dialog { #if CAP_ANIMATIONS anims::get_parameter_animation(anims::find_param(&x), ne.s); #endif + ne.reset_str(); pushScreen(ne); } diff --git a/hyper_function.h b/hyper_function.h index 9904010a..5e959238 100644 --- a/hyper_function.h +++ b/hyper_function.h @@ -8,11 +8,15 @@ namespace hr { template class function; +/* callable objects derived from funbase can be retrieved from hr::function using target_base */ +struct funbase { virtual ~funbase() {} }; + template struct function_state_base { virtual R call(Args...) const = 0; virtual function_state_base *clone() const = 0; virtual ~function_state_base() {} + virtual funbase* as_funbase() = 0; }; template @@ -25,6 +29,10 @@ struct function_state : function_state_base { function_state_base *clone() const override { return new function_state(*this); } + virtual funbase* as_funbase() { + if(std::is_base_of::value) return (funbase*) (&t_); + return nullptr; + } }; template @@ -65,6 +73,10 @@ public: if(!ptr) return nullptr; return &ptr->t_; } + + struct funbase* target_base() { + return ptr_->as_funbase(); + } }; } // namespace hr