diff --git a/Fltk/helpWindow.cpp b/Fltk/helpWindow.cpp index af46e3daa3d4ad2bd703c4190d790a054338f54e..245d7b2322aa4c1a816ee5c3f8606aee57d42c45 100644 --- a/Fltk/helpWindow.cpp +++ b/Fltk/helpWindow.cpp @@ -8,10 +8,10 @@ #include <FL/Fl_Help_View.H> #include <FL/Fl_Check_Button.H> #include <FL/Fl_Input.H> -#include <FL/Fl_Value_Input.H> #include <FL/Fl_Color_Chooser.H> #include "GmshConfig.h" #include "FlGui.h" +#include "inputValue.h" #include "helpWindow.h" #include "paletteWindow.h" #include "CommandLine.h" @@ -41,7 +41,7 @@ struct opt_data{ static void interactive_cb(Fl_Widget* w, void* data) { if(!data) return; - Fl_Value_Input *v = (Fl_Value_Input*)w; + inputValueFloat *v = (inputValueFloat*)w; opt_data *d = (opt_data*)data; double val = v->value(); NumberOption(GMSH_SET|GMSH_GUI, d->category.c_str(), d->index, @@ -69,10 +69,10 @@ double numberOrStringOptionChooser(const std::string &category, int index, Fl_Window *win = new paletteWindow(width, height, false, t.c_str()); win->set_modal(); win->hotspot(win); - Fl_Value_Input *number = 0; + inputValueFloat *number = 0; Fl_Input *string = 0; if(isNumber){ - number = new Fl_Value_Input(WB, WB, width - 2 * WB, BH); + number = new inputValueFloat(WB, WB, width - 2 * WB, BH); number->value(valn); if(isInteractive){ static opt_data d; diff --git a/Fltk/inputRange.h b/Fltk/inputRange.h index b878918d19167d9a8a892fdb3285fd81913420d6..7b799d958dbd8245ff09bbf001f15c5259497605 100644 --- a/Fltk/inputRange.h +++ b/Fltk/inputRange.h @@ -20,7 +20,7 @@ class inputRange : public Fl_Group { private: - inputValue *_input; + inputValueFloat *_input; Fl_Toggle_Button *_loop_butt; Fl_Button *_range_butt, *_graph_butt; Fl_Menu_Button *_graph_menu; @@ -248,7 +248,7 @@ class inputRange : public Fl_Group { int dot_w = FL_NORMAL_SIZE - 2, loop_w = FL_NORMAL_SIZE + 6, graph_w = loop_w; int input_w = w - dot_w - loop_w - graph_w; - _input = new inputValue(x, y, input_w, h); + _input = new inputValueFloat(x, y, input_w, h); _input->callback(_input_cb, this); _input->when(FL_WHEN_ENTER_KEY|FL_WHEN_RELEASE); diff --git a/Fltk/inputValue.cpp b/Fltk/inputValue.cpp index e7edb4896325049a96edc5e40593f38f7bbe7f68..dd0707c1430a7882e8db082a23ec488fde6b8af8 100644 --- a/Fltk/inputValue.cpp +++ b/Fltk/inputValue.cpp @@ -8,9 +8,9 @@ #include <stdlib.h> #include <FL/math.h> -void inputValue::new_input_cb(Fl_Widget*, void* v) +void inputValueFloat::new_input_cb(Fl_Widget*, void* v) { - inputValue& t = *(inputValue*)v; + inputValueFloat& t = *(inputValueFloat*)v; double nv = strtod(t.input.value(), 0); if (nv != t.value() || t.when() & FL_WHEN_NOT_CHANGED) { t.set_value(nv); @@ -19,14 +19,14 @@ void inputValue::new_input_cb(Fl_Widget*, void* v) } } -inputValue::inputValue(int x, int y, int w, int h, const char *l) : - Fl_Value_Input(x, y, w, h, l) +inputValueFloat::inputValueFloat(int x, int y, int w, int h, const char *l) : + inputValue(x, y, w, h, l) { input.type(FL_FLOAT_INPUT); input.callback(new_input_cb, this); } -int inputValue::handle(int event) +int inputValueFloat::handle(int event) { double v; int delta; diff --git a/Fltk/inputValue.h b/Fltk/inputValue.h index c5627c370dcd8ae0e6c8bf0f241d8cb5a0b112f8..0ec88b54a388c970a3a2aee047c83b098b5330bb 100644 --- a/Fltk/inputValue.h +++ b/Fltk/inputValue.h @@ -9,16 +9,26 @@ #include <FL/Fl.H> #include <FL/Fl_Value_Input.H> -// this is basically the same as Fl_Value_Input, except that we force the -// underlying input to always accept floats (whatever the step value) +// same as FL_Value_Input, but prints values in engineering notation class inputValue : public Fl_Value_Input +{ + public: + inputValue(int x, int y, int w, int h, const char *l=0) : + Fl_Value_Input(x, y, w, h, l) {} + virtual int format(char *buffer){ return sprintf(buffer, "%g", value()); } +}; + + +// same as inputValue, but forces the underlying FL_Value_Input to always accept +// floats (whatever the step value) + +class inputValueFloat : public inputValue { private: static void new_input_cb(Fl_Widget*,void*); public: - inputValue(int x, int y, int w, int h, const char *l=0); - virtual int format(char *buffer){ return sprintf(buffer, "%g", value()); } + inputValueFloat(int x, int y, int w, int h, const char *l=0); int handle(int event); }; diff --git a/Fltk/optionWindow.cpp b/Fltk/optionWindow.cpp index 00b49ae3da5b970c4d0fd2ac4e81e0944778a705..9afebed98c3db3380e3ff6585f512e96a13e5607 100644 --- a/Fltk/optionWindow.cpp +++ b/Fltk/optionWindow.cpp @@ -18,6 +18,7 @@ typedef unsigned long intptr_t; #include "GmshDefines.h" #include "GmshMessage.h" #include "FlGui.h" +#include "inputValue.h" #include "optionWindow.h" #include "gamepadWindow.h" #include "graphicWindow.h" @@ -47,14 +48,6 @@ extern StringXColor PostProcessingOptions_Color[] ; extern StringXColor ViewOptions_Color[] ; extern StringXColor PrintOptions_Color[] ; -class engineeringValueInput : public Fl_Value_Input -{ - public: - engineeringValueInput(int x, int y, int w, int h, const char *l=0) : - Fl_Value_Input(x, y, w, h, l) {} - virtual int format(char *buffer){ return sprintf(buffer, "%g", value()); } -}; - static Fl_Menu_Item menu_point_display[] = { {"Color dot", 0, 0, 0}, {"3D sphere", 0, 0, 0}, @@ -3214,7 +3207,7 @@ optionWindow::optionWindow(int deltaFontSize) (L + 2 * WB + ss , 2 * WB + 2 * BH, ss, BH); view.value[53] = new Fl_Value_Input (L + 2 * WB + 2*ss, 2 * WB + 2 * BH, ss, BH, " X"); - view.value[40] = new engineeringValueInput + view.value[40] = new inputValueFloat (L + 2 * WB + IW , 2 * WB + 2 * BH, 7*IW/10, BH); view.value[54] = new Fl_Value_Input @@ -3223,7 +3216,7 @@ optionWindow::optionWindow(int deltaFontSize) (L + 2 * WB + ss , 2 * WB + 3 * BH, ss, BH); view.value[56] = new Fl_Value_Input (L + 2 * WB + 2*ss, 2 * WB + 3 * BH, ss, BH, " Y +"); - view.value[41] = new engineeringValueInput + view.value[41] = new inputValueFloat (L + 2 * WB + IW , 2 * WB + 3 * BH, 7*IW/10, BH); view.value[57] = new Fl_Value_Input @@ -3232,21 +3225,21 @@ optionWindow::optionWindow(int deltaFontSize) (L + 2 * WB + ss , 2 * WB + 4 * BH, ss, BH); view.value[59] = new Fl_Value_Input (L + 2 * WB + 2*ss, 2 * WB + 4 * BH, ss, BH, " Z"); - view.value[42] = new engineeringValueInput + view.value[42] = new inputValueFloat (L + 2 * WB + IW , 2 * WB + 4 * BH, 7*IW/10, BH); Fl_Box *b2 = new Fl_Box (FL_NO_BOX, L + 2 * WB + 2 * IW-3*WB, 2 * WB + 1 * BH, 7*IW/10, BH, "Raise:"); b2->align(FL_ALIGN_INSIDE|FL_ALIGN_LEFT); - view.value[43] = new engineeringValueInput + view.value[43] = new inputValueFloat (L + 2 * WB + 2 * IW-3*WB, 2 * WB + 2 * BH, 7*IW/10, BH); - view.value[44] = new engineeringValueInput + view.value[44] = new inputValueFloat (L + 2 * WB + 2 * IW-3*WB, 2 * WB + 3 * BH, 7*IW/10, BH); - view.value[45] = new engineeringValueInput + view.value[45] = new inputValueFloat (L + 2 * WB + 2 * IW-3*WB, 2 * WB + 4 * BH, 7*IW/10, BH); - view.value[46] = new engineeringValueInput + view.value[46] = new inputValueFloat (L + 2 * WB, 2 * WB + 5 * BH, 3*ss, BH, "Normal raise"); for(int i = 40; i <= 46; i++){ @@ -3274,7 +3267,7 @@ optionWindow::optionWindow(int deltaFontSize) view.choice[11]->add("Self"); view.choice[11]->callback(view_options_ok_cb); - view.value[2] = new engineeringValueInput + view.value[2] = new inputValueFloat (L + 2 * WB, 2 * WB + 8 * BH, IW, BH, "Factor"); view.value[2]->align(FL_ALIGN_RIGHT); view.value[2]->when(FL_WHEN_RELEASE); @@ -3376,7 +3369,7 @@ optionWindow::optionWindow(int deltaFontSize) view.value[60]->align(FL_ALIGN_RIGHT); view.value[60]->callback(view_options_ok_cb); - view.value[63] = new engineeringValueInput + view.value[63] = new inputValueFloat (L + 2 * WB, 2 * WB + 8 * BH, IW, BH, "Displacement factor"); view.value[63]->minimum(0.); view.value[63]->maximum(1.);