//
// "$Id$"
//
// Valuator widget for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2005 by Bill Spitzak and others.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA.
//
// Please report all bugs and problems on the following page:
//
// http://www.fltk.org/str.php
//
/** \fn int Fl_Valuator::changed() const
This value is true if the user has moved the slider. It is
turned off by value(x) and just before doing a callback
(the callback can turn it back on if desired).
*/
// Base class for sliders and all other one-value "knobs"
#include
The actual format used depends on the current step value. If the step value has been set to zero then a %g format is used. If the step value is non-zero, then a %.*f format is used, where the precision is calculated to show sufficient digits for the current step value. An integer step value, such as 1 or 1.0, gives a precision of 0, so the formatted value will appear as an integer.
This method is used by the Fl_Value_... group of widgets to format the current value into a text string. The return value is the length of the formatted text. The formatted value is written into in buffer. buffer should have space for at least 128 bytes.
You may override this function to create your own text formatting. */ int Fl_Valuator::format(char* buffer) { double v = value(); // MRS: THIS IS A HACK - RECOMMEND ADDING BUFFER SIZE ARGUMENT if (!A || !B) return snprintf(buffer, 128, "%g", v); // Figure out how many digits are required to correctly format the // value. int i, c = 0; char temp[32]; // output a number with many digits after the decimal point. This // seems to be needed to get high precission snprintf(temp, sizeof(temp), "%.12f", A/B); // strip all trailing 0's for (i=strlen(temp)-1; i>0; i--) { if (temp[i]!='0') break; } // count digits until we find the decimal point (or comma or whatever // letter is set in the current locale) for (; i>0; i--, c++) { if (!isdigit(temp[i])) break; } // MRS: THIS IS A HACK - RECOMMEND ADDING BUFFER SIZE ARGUMENT return snprintf(buffer, 128, "%.*f", c, v); } // // End of "$Id$". //