diff options
| -rw-r--r-- | CHANGES | 2 | ||||
| -rw-r--r-- | FL/Fl_Spinner.H | 9 | ||||
| -rw-r--r-- | documentation/Fl_Spinner.html | 20 | ||||
| -rw-r--r-- | fluid/Fl_Widget_Type.cxx | 30 | ||||
| -rw-r--r-- | fluid/factory.cxx | 6 | ||||
| -rw-r--r-- | test/valuators.fl | 142 |
6 files changed, 134 insertions, 75 deletions
@@ -1,5 +1,7 @@ CHANGES IN FLTK 1.1.8 + - Added support for floating point Fl_Spinner in the + API, documentation, and Fluid (STR #1331) - Repeat button now cancels timeout if it should get deactivated during a callback (STR #1330) - Added support for assigning Fl_Menu_Items to array diff --git a/FL/Fl_Spinner.H b/FL/Fl_Spinner.H index 2a6c0bcdf..c475681de 100644 --- a/FL/Fl_Spinner.H +++ b/FL/Fl_Spinner.H @@ -163,6 +163,15 @@ class Fl_Spinner : public Fl_Group void textsize(uchar s) { input_.textsize(s); } + uchar type() const { return (input_.type()); } + void type(uchar v) { + if (v==FL_FLOAT_INPUT) { + format("%g"); + } else { + format("%.0f"); + } + input_.type(v); + } double value() const { return (value_); } void value(double v) { value_ = v; update(); } }; diff --git a/documentation/Fl_Spinner.html b/documentation/Fl_Spinner.html index ab6383c77..c294262ca 100644 --- a/documentation/Fl_Spinner.html +++ b/documentation/Fl_Spinner.html @@ -44,6 +44,7 @@ input area or use the buttons to change the value. <li><a href='#Fl_Spinner.textcolor'>textcolor</a></li> <li><a href='#Fl_Spinner.textfont'>textfont</a></li> <li><a href='#Fl_Spinner.textsize'>textsize</a></li> + <li><a href='#Fl_Spinner.type'>type</a></li> <li><a href='#Fl_Spinner.value'>value</a></li> </ul> @@ -81,7 +82,10 @@ double minimum() const</a></h4> double step() const</a></h4> <p>Sets or returns the amount to change the value when the user -clicks a button.</p> +clicks a button. +Before setting <tt>step</tt> to a non-integer value, the spinner +<a href='#Fl_Spinner.type'><tt>type()</tt></a> should be changed +to floating point.</p> <h4><a name='Fl_Spinner.textcolor'>void textcolor(Fl_Color c)<br /> Fl_Color textcolor() const</a></h4> @@ -98,10 +102,22 @@ uchar textsize() const</a></h4> <p>Sets or returns the size of the text in the input field.</p> +<h4><a name='Fl_Spinner.type'>void type(uchar s)<br /> +uchar type() const</a></h4> + +<p>Sets or returns the numeric representation in the input field. +Valid values are <tt>FL_INT_INPUT</tt> and <tt>FL_FLOAT_INPUT</tt>. +The first form also changes the <tt>format()</tt> template. +Please note that <tt>type</tt> is not a virtual function. +Setting a new spinner type via a superclass pointer will not work.</p> + <h4><a name="Fl_Spinner.value">void Fl_Spinner::value(double v)<br /> double Fl_Spinner::value() const</a></h4> -<p>Sets or returns the current value of the widget.</p> +<p>Sets or returns the current value of the widget. +Before setting <tt>value</tt> to a non-integer value, the spinner +<a href='#Fl_Spinner.type'><tt>type()</tt></a> should be changed +to floating point.</p> </body> </html> diff --git a/fluid/Fl_Widget_Type.cxx b/fluid/Fl_Widget_Type.cxx index 893b0f40b..f4f99d2cf 100644 --- a/fluid/Fl_Widget_Type.cxx +++ b/fluid/Fl_Widget_Type.cxx @@ -32,6 +32,7 @@ #include "alignment_panel.h" #include <FL/fl_message.H> #include <FL/Fl_Slider.H> +#include <FL/Fl_Spinner.H> #include <FL/Fl_Window.H> #include "../src/flstring.h" #include <stdio.h> @@ -1590,7 +1591,11 @@ void subtype_cb(Fl_Choice* i, void* v) { int j; for (j = 0;; j++) { if (!m[j].text) {j = 0; break;} - if (m[j].argument() == current_widget->o->type()) break; + if (current_widget->is_spinner()) { + if (m[j].argument() == ((Fl_Spinner*)current_widget->o)->type()) break; + } else { + if (m[j].argument() == current_widget->o->type()) break; + } } i->value(j); i->activate(); @@ -1603,9 +1608,12 @@ void subtype_cb(Fl_Choice* i, void* v) { if (o->selected && o->is_widget()) { Fl_Widget_Type* q = (Fl_Widget_Type*)o; if (q->subtypes()==m) { - q->o->type(n); - q->redraw(); - mod = 1; + if (q->is_spinner()) + ((Fl_Spinner*)q->o)->type(n); + else + q->o->type(n); + q->redraw(); + mod = 1; } } } @@ -2061,7 +2069,9 @@ void Fl_Widget_Type::write_widget_code() { write_c(");\n"); } - if (o->type() != tplate->type() && !is_window()) + if (is_spinner() && ((Fl_Spinner*)o)->type() != ((Fl_Spinner*)tplate)->type()) + write_c("%so->type(%d);\n", indent(), ((Fl_Spinner*)o)->type()); + else if (o->type() != tplate->type() && !is_window()) write_c("%so->type(%d);\n", indent(), o->type()); if (o->box() != tplate->box() || subclass()) write_c("%so->box(FL_%s);\n", indent(), boxname(o->box())); @@ -2203,7 +2213,10 @@ void Fl_Widget_Type::write_properties() { } write_string("xywh {%d %d %d %d}", o->x(), o->y(), o->w(), o->h()); Fl_Widget* tplate = ((Fl_Widget_Type*)factory)->o; - if (o->type() != tplate->type() || is_window()) { + if (is_spinner() && ((Fl_Spinner*)o)->type() != ((Fl_Spinner*)tplate)->type()) { + write_string("type"); + write_word(item_name(subtypes(), ((Fl_Spinner*)o)->type())); + } else if (o->type() != tplate->type() || is_window()) { write_string("type"); write_word(item_name(subtypes(), o->type())); } @@ -2304,7 +2317,10 @@ void Fl_Widget_Type::read_property(const char *c) { } else if (!strcmp(c,"deimage")) { inactive_name(read_word()); } else if (!strcmp(c,"type")) { - o->type(item_number(subtypes(), read_word())); + if (is_spinner()) + ((Fl_Spinner*)o)->type(item_number(subtypes(), read_word())); + else + o->type(item_number(subtypes(), read_word())); } else if (!strcmp(c,"box")) { const char* value = read_word(); if ((x = boxnumber(value))) { diff --git a/fluid/factory.cxx b/fluid/factory.cxx index 71391e7f1..8b255f6c6 100644 --- a/fluid/factory.cxx +++ b/fluid/factory.cxx @@ -378,8 +378,12 @@ int Fl_Counter_Type::textstuff(int w, Fl_Font& f, int& s, Fl_Color& c) { //////////////////////////////////////////////////////////////// #include <FL/Fl_Spinner.H> +static Fl_Menu_Item spinner_type_menu[] = { + {"Integer",0,0,(void*)FL_INT_INPUT}, + {"Float", 0,0,(void*)FL_FLOAT_INPUT}, + {0}}; class Fl_Spinner_Type : public Fl_Widget_Type { - Fl_Menu_Item *subtypes() {return 0;} + Fl_Menu_Item *subtypes() {return spinner_type_menu;} int textstuff(int w, Fl_Font& f, int& s, Fl_Color& c); int pixmapID() { return 47; } public: diff --git a/test/valuators.fl b/test/valuators.fl index c1f735c48..668a462f6 100644 --- a/test/valuators.fl +++ b/test/valuators.fl @@ -12,7 +12,7 @@ Function {} {open } { Fl_Window {} { label {Valuator classes, showing values for type()} open - xywh {204 225 565 505} type Double color 43 selection_color 43 + xywh {479 151 580 510} type Double color 43 selection_color 43 code0 {\#include <stdio.h>} visible } { Fl_Box {} { @@ -34,9 +34,24 @@ Function {} {open callback callback xywh {105 45 20 145} type {Vert Knob} box FLAT_BOX color 10 selection_color 1 labelsize 8 align 1 } + Fl_Slider {} { + label FL_HORIZONTAL + callback callback + xywh {140 80 130 20} type Horizontal selection_color 1 labelsize 8 + } + Fl_Slider {} { + label FL_HOR_FILL_SLIDER + callback callback + xywh {140 120 130 20} type {Horz Fill} selection_color 1 labelsize 8 + } + Fl_Slider {} { + label FL_HOR_NICE_SLIDER + callback callback + xywh {140 160 130 20} type {Horz Knob} box FLAT_BOX color 10 selection_color 1 labelsize 8 + } Fl_Box {} { label Fl_Value_Slider - xywh {10 230 280 205} box ENGRAVED_BOX labelfont 1 align 17 + xywh {10 230 280 210} box ENGRAVED_BOX labelfont 1 align 17 } Fl_Value_Slider {} { label 0 @@ -53,88 +68,117 @@ Function {} {open callback callback xywh {110 260 20 145} type {Vert Knob} box FLAT_BOX color 10 selection_color 1 labelsize 8 align 1 } - Fl_Slider {} { - label FL_HORIZONTAL + Fl_Value_Slider {} { + label FL_HOR_SLIDER callback callback - xywh {140 80 130 20} type Horizontal selection_color 1 labelsize 8 + xywh {140 290 130 20} type Horizontal selection_color 1 labelsize 8 } - Fl_Slider {} { + Fl_Value_Slider {} { label FL_HOR_FILL_SLIDER callback callback - xywh {140 120 130 20} type {Horz Fill} selection_color 1 labelsize 8 + xywh {140 330 130 20} type {Horz Fill} selection_color 1 labelsize 8 } - Fl_Slider {} { + Fl_Value_Slider {} { label FL_HOR_NICE_SLIDER callback callback - xywh {140 160 130 20} type {Horz Knob} box FLAT_BOX color 10 selection_color 1 labelsize 8 + xywh {140 370 130 20} type {Horz Knob} box FLAT_BOX color 10 selection_color 1 labelsize 8 } - Fl_Value_Slider {} { - label FL_HOR_SLIDER + Fl_Box {} { + label Fl_Value_Input + xywh {10 450 135 50} box ENGRAVED_BOX labelfont 1 align 17 + } + Fl_Value_Input {} { + label 0 callback callback - xywh {140 290 130 20} type Horizontal selection_color 1 labelsize 8 + tooltip {Value Input} xywh {30 470 105 25} labelsize 8 maximum 100 step 0.1 } - Fl_Value_Slider {} { - label FL_HOR_FILL_SLIDER + Fl_Box {} { + label Fl_Value_Output + xywh {155 450 135 50} box ENGRAVED_BOX labelfont 1 align 17 + } + Fl_Value_Output {} { + label 0 callback callback - xywh {140 330 130 20} type {Horz Fill} selection_color 1 labelsize 8 + tooltip {Value Output} xywh {170 470 105 25} labelsize 8 maximum 100 step 0.1 } Fl_Box {} { - label Fl_Adjuster - xywh {430 10 125 120} box ENGRAVED_BOX labelfont 1 align 17 + label { Fl_Scrollbar} + xywh {300 10 130 120} box ENGRAVED_BOX labelfont 1 align 21 } - Fl_Value_Slider {} { - label FL_HOR_NICE_SLIDER + Fl_Scrollbar {} { + label FL_HORIZONTAL callback callback - xywh {140 370 130 20} type {Horz Knob} box FLAT_BOX color 10 selection_color 1 labelsize 8 + tooltip {Horizontal Scrollbar} xywh {305 65 95 20} type Horizontal labelsize 8 maximum 100 value 20 + } + Fl_Scrollbar {} { + label 0 + callback callback + tooltip {Vertical Scrollbar} xywh {400 20 20 105} labelsize 8 align 1 maximum 100 + } + Fl_Box {} { + label Fl_Adjuster + xywh {440 10 130 120} box ENGRAVED_BOX labelfont 1 align 17 } Fl_Adjuster {} { label {w()>h()} callback callback - tooltip {Horizontal Adjuster} xywh {440 60 75 25} labelsize 8 + tooltip {Horizontal Adjuster} xywh {450 60 75 25} labelsize 8 } Fl_Adjuster {} { label {w()<h()} callback callback - tooltip {Vertical Adjuster} xywh {520 35 25 75} labelsize 8 + tooltip {Vertical Adjuster} xywh {530 35 25 75} labelsize 8 } Fl_Box {} { label Fl_Counter - xywh {345 135 210 115} box ENGRAVED_BOX labelfont 1 align 17 + xywh {300 140 130 120} box ENGRAVED_BOX labelfont 1 align 17 } Fl_Counter {} { label 0 callback callback - tooltip {Standard Counter} xywh {360 160 180 30} labelsize 8 + tooltip {Standard Counter} xywh {310 175 110 25} labelsize 8 } Fl_Counter {} { label FL_SIMPLE_COUNTER callback callback - tooltip {Simple Counter} xywh {360 205 180 30} type Simple labelsize 8 + tooltip {Simple Counter} xywh {310 215 110 25} type Simple labelsize 8 + } + Fl_Box {} { + label Fl_Spinner + xywh {440 140 130 120} box ENGRAVED_BOX labelfont 1 align 17 + } + Fl_Spinner {} { + label FL_INT_INPUT + xywh {465 176 80 24} labelsize 8 align 2 minimum -30 maximum 30 step 2 value 5 + } + Fl_Spinner {} { + label FL_FLOAT_INPUT + xywh {465 216 80 24} type Float labelsize 8 align 2 minimum 0 maximum 1 step 0.01 value 0.05 } Fl_Box {} { label Fl_Dial - xywh {300 260 255 105} box ENGRAVED_BOX labelfont 1 align 17 + xywh {300 270 270 105} box ENGRAVED_BOX labelfont 1 align 17 } Fl_Dial {} { label 0 callback callback - tooltip {Standard Dial} xywh {315 280 65 65} color 10 selection_color 1 labelsize 8 value 0.5 + tooltip {Standard Dial} xywh {320 295 65 65} color 10 selection_color 1 labelsize 8 value 0.5 code0 {o->angles(0,315);} } Fl_Dial {} { label FL_LINE_DIAL callback callback - tooltip {Line Dial} xywh {395 280 65 65} type Line color 10 selection_color 1 labelsize 8 value 0.5 + tooltip {Line Dial} xywh {400 295 65 65} type Line color 10 selection_color 1 labelsize 8 value 0.5 } Fl_Dial {} { label FL_FILL_DIAL callback callback - tooltip {Fill Dial} xywh {475 280 65 65} type Fill color 10 selection_color 1 labelsize 8 value 1 + tooltip {Fill Dial} xywh {480 295 65 65} type Fill color 10 selection_color 1 labelsize 8 value 1 code0 {o->angles(0,360);} } Fl_Box {} { label Fl_Roller - xywh {300 375 145 120} box ENGRAVED_BOX labelfont 1 align 17 + xywh {300 385 150 115} box ENGRAVED_BOX labelfont 1 align 17 } Fl_Roller {} { label 0 @@ -144,43 +188,11 @@ Function {} {open Fl_Roller {} { label FL_HORIZONTAL callback callback - tooltip {Horizontal Roller} xywh {340 430 90 20} type Horizontal labelsize 8 - } - Fl_Box {} { - label Fl_Value_Input - xywh {10 445 140 50} box ENGRAVED_BOX labelfont 1 align 17 + tooltip {Horizontal Roller} xywh {345 430 90 20} type Horizontal labelsize 8 } Fl_Box {} { - label {Some widgets have color(FL_GREEN) and color2(FL_RED) to show the areas these effect.} - xywh {455 375 100 120} box BORDER_FRAME color 0 selection_color 0 labelsize 10 align 128 - } - Fl_Box {} { - label Fl_Value_Output - xywh {155 445 135 50} box ENGRAVED_BOX labelfont 1 align 17 - } - Fl_Value_Input {} { - label 0 - callback callback - tooltip {Value Input} xywh {30 460 110 30} labelsize 8 maximum 100 step 0.1 - } - Fl_Value_Output {} { - label 0 - callback callback - tooltip {Value Output} xywh {170 460 110 30} labelsize 8 maximum 100 step 0.1 - } - Fl_Box {} { - label { Fl_Scrollbar} - xywh {295 10 130 120} box ENGRAVED_BOX labelfont 1 align 21 - } - Fl_Scrollbar {} { - label 0 - callback callback - tooltip {Vertical Scrollbar} xywh {395 20 20 105} labelsize 8 align 1 maximum 100 - } - Fl_Scrollbar {} { - label FL_HORIZONTAL - callback callback selected - tooltip {Horizontal Scrollbar} xywh {300 65 95 20} type Horizontal labelsize 8 maximum 100 value 20 + label {Some widgets have color(FL_GREEN) and color2(FL_RED) to show the areas these effect.} selected + xywh {460 385 110 115} box BORDER_FRAME color 0 selection_color 0 labelsize 11 align 128 } } } |
