From 05bd3ade18e53762079994c41cbb953994d994c9 Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Thu, 22 Jun 2006 07:35:39 +0000 Subject: Added support for floating point Fl_Spinner git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@5221 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- CHANGES | 2 + FL/Fl_Spinner.H | 9 +++ documentation/Fl_Spinner.html | 20 +++++- fluid/Fl_Widget_Type.cxx | 30 ++++++--- fluid/factory.cxx | 6 +- test/valuators.fl | 142 +++++++++++++++++++++++------------------- 6 files changed, 134 insertions(+), 75 deletions(-) diff --git a/CHANGES b/CHANGES index 01e7a2643..9a5f81a36 100644 --- a/CHANGES +++ b/CHANGES @@ -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.
  • textcolor
  • textfont
  • textsize
  • +
  • type
  • value
  • @@ -81,7 +82,10 @@ double minimum() const double step() const

    Sets or returns the amount to change the value when the user -clicks a button.

    +clicks a button. +Before setting step to a non-integer value, the spinner +type() should be changed +to floating point.

    void textcolor(Fl_Color c)
    Fl_Color textcolor() const

    @@ -98,10 +102,22 @@ uchar textsize() const

    Sets or returns the size of the text in the input field.

    +

    void type(uchar s)
    +uchar type() const

    + +

    Sets or returns the numeric representation in the input field. +Valid values are FL_INT_INPUT and FL_FLOAT_INPUT. +The first form also changes the format() template. +Please note that type is not a virtual function. +Setting a new spinner type via a superclass pointer will not work.

    +

    void Fl_Spinner::value(double v)
    double Fl_Spinner::value() const

    -

    Sets or returns the current value of the widget.

    +

    Sets or returns the current value of the widget. +Before setting value to a non-integer value, the spinner +type() should be changed +to floating point.

    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 #include +#include #include #include "../src/flstring.h" #include @@ -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 +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 } 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()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 } } } -- cgit v1.2.3