dialog:: more fixes

This commit is contained in:
Zeno Rogue 2023-08-09 14:22:32 +02:00
parent b6f13b953b
commit 4668321e4e
3 changed files with 25 additions and 12 deletions

View File

@ -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(); });
};
}

View File

@ -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<number_dialog>();
auto ptr = dynamic_cast<number_dialog*> (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<extdialog>();
auto ptr = dynamic_cast<extdialog*> (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);
}

View File

@ -8,11 +8,15 @@ namespace hr {
template<class Sig>
class function;
/* callable objects derived from funbase can be retrieved from hr::function using target_base */
struct funbase { virtual ~funbase() {} };
template<class R, class... Args>
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<class T, class R, class... Args>
@ -25,6 +29,10 @@ struct function_state : function_state_base<R, Args...> {
function_state_base<R, Args...> *clone() const override {
return new function_state(*this);
}
virtual funbase* as_funbase() {
if(std::is_base_of<funbase, T>::value) return (funbase*) (&t_);
return nullptr;
}
};
template<class R, class... Args>
@ -65,6 +73,10 @@ public:
if(!ptr) return nullptr;
return &ptr->t_;
}
struct funbase* target_base() {
return ptr_->as_funbase();
}
};
} // namespace hr