Author: matt
Date: 2012-05-01 14:45:44 -0700 (Tue, 01 May 2012)
New Revision: 9426
Log:
Just a bit of reformatting.
Modified:
branches/branch-3.0/include/fltk3/Valuator.h
branches/branch-3.0/src/fltk3/Valuator.cxx
Modified: branches/branch-3.0/include/fltk3/Valuator.h
===================================================================
--- branches/branch-3.0/include/fltk3/Valuator.h 2012-05-01 21:30:42 UTC
(rev 9425)
+++ branches/branch-3.0/include/fltk3/Valuator.h 2012-05-01 21:45:44 UTC
(rev 9426)
@@ -37,21 +37,28 @@
namespace fltk3 {
// shared type() values for classes that work in both directions:
- const uchar VERTICAL = 0; ///< The valuator can work vertically
- const uchar HORIZONTAL = 1; ///< The valuator can work
horizontally
+ const uchar VERTICAL = 0; ///< The valuator can work vertically
+ const uchar HORIZONTAL = 1; ///< The valuator can work horizontally
/**
+ \brief The Valuator is the base class for all numerical slider-type widgets.
+
The fltk3::Valuator class controls a single floating-point value
and provides a consistent interface to set the value, range, and step,
and insures that callbacks are done the same for every object.
- <P>There are probably more of these classes in FLTK than any others:
- <P ALIGN=CENTER>\image html valuators.png</P>
- \image latex valuators.png "Valuators derived from fltk3::Valuators"
width=10cm
- <P>In the above diagram each box surrounds an actual subclass. These
- are further differentiated by setting the type() of the widget t
- o the symbolic value labeling the widget.
- The ones labelled "0" are the default versions with a type(0).
- For consistency the symbol fltk3::VERTICAL is defined as zero.
+
+ There are probably more of these classes in FLTK than any others:
+ <P ALIGN=CENTER>
+ \image html valuators.png
+ \image latex valuators.png
+ </P>
+ "Valuators derived from fltk3::Valuators" width=10cm
+
+ In the above diagram each box surrounds an actual subclass. These are
+ further differentiated by setting the type() of the widget to the symbolic
+ value labeling the widget. The ones labelled "0" are the default versions
+ with a type(0). For consistency the symbol fltk3::VERTICAL is defined
+ as zero.
*/
class FLTK3_EXPORT Valuator : public fltk3::Widget {
@@ -63,8 +70,7 @@
protected:
/** Tells if the valuator is an fltk3::HORIZONTAL one */
int horizontal() const {return type()& fltk3::HORIZONTAL;}
- Valuator(int X, int Y, int W, int H, const char* L);
-
+ Valuator(int X, int Y, int W, int H, const char* L);
/** Gets the previous floating point value before an event changed it */
double previous_value() const {return previous_value_;}
/** Stores the current value in the previous value */
@@ -78,53 +84,58 @@
public:
- /** Sets the minimum (a) and maximum (b) values for the valuator
widget. */
+ /** Sets the minimum (a) and maximum (b) values for the valuator widget. */
void bounds(double a, double b) {min=a; max=b;}
- /** Gets the minimum value for the valuator. */
+ /** Gets the minimum value for the valuator. */
double minimum() const {return min;}
- /** Sets the minimum value for the valuator. */
+ /** Sets the minimum value for the valuator. */
void minimum(double a) {min = a;}
- /** Gets the maximum value for the valuator. */
+ /** Gets the maximum value for the valuator. */
double maximum() const {return max;}
- /** Sets the maximum value for the valuator. */
+ /** Sets the maximum value for the valuator. */
void maximum(double a) {max = a;}
/**
- Sets the minimum and maximum values for the valuator. When
- the user manipulates the widget, the value is limited to this
+ \brief Sets the minimum and maximum values for the valuator.
+
+ Whenthe user manipulates the widget, the value is limited to this
range. This clamping is done <I>after</I> rounding to the step
value (this makes a difference if the range is not a multiple of
the step).
- <P>The minimum may be greater than the maximum. This has the
+ The minimum may be greater than the maximum. This has the
effect of "reversing" the object so the larger values
are in the opposite direction. This also switches which end of
- the filled sliders is filled.</P>
+ the filled sliders is filled.
- <P>Some widgets consider this a "soft" range. This
+ Some widgets consider this a "soft" range. This
means they will stop at the range, but if the user releases and
grabs the control again and tries to move it further, it is
- allowed.</P>
+ allowed.
- <P>The range may affect the display. You must redraw()
+ The range may affect the display. You must redraw()
the widget after changing the range.
*/
void range(double a, double b) {min = a; max = b;}
- /** See double fltk3::Valuator::step() const */
+ /** See double fltk3::Valuator::step() const */
void step(int a) {A = a; B = 1;}
- /** See double fltk3::Valuator::step() const */
- void step(double a, int b) {A = a; B = b;}
- void step(double s);
/**
- Gets or sets the step value. As the user moves the mouse the
+ \brief Sets the step value.
+
+ As the user moves the mouse the
value is rounded to the nearest multiple of the step value. This
is done <I>before</I> clamping it to the range. For most widgets
the default step is zero.
- <P>For precision the step is stored as the ratio of two
+ For precision the step is stored as the ratio of two
integers, A/B. You can set these integers directly. Currently
setting a floating point value sets the nearest A/1 or 1/B value
possible.
*/
+ void step(double a, int b) {A = a; B = b;}
+ void step(double s);
+ /**
+ \brief Gets the step value.
+ */
double step() const {return A/B;}
void precision(int);
Modified: branches/branch-3.0/src/fltk3/Valuator.cxx
===================================================================
--- branches/branch-3.0/src/fltk3/Valuator.cxx 2012-05-01 21:30:42 UTC (rev
9425)
+++ branches/branch-3.0/src/fltk3/Valuator.cxx 2012-05-01 21:45:44 UTC (rev
9426)
@@ -34,12 +34,17 @@
#include <stdio.h>
#include "flstring.h"
+
+const double epsilon = 4.66e-10;
+
+
+/**
+ Creates a new fltk3::Valuator widget using the given position,
+ size, and label string. The default boxtype is fltk3::NO_BOX.
+ */
fltk3::Valuator::Valuator(int X, int Y, int W, int H, const char* L)
-/**
- Creates a new fltk3::Valuator widget using the given position,
- size, and label string. The default boxtype is fltk3::NO_BOX.
-*/
-: fltk3::Widget(X,Y,W,H,L) {
+: fltk3::Widget(X,Y,W,H,L)
+{
align(fltk3::ALIGN_BOTTOM);
when(fltk3::WHEN_CHANGED);
value_ = 0;
@@ -50,43 +55,57 @@
B = 1;
}
-const double epsilon = 4.66e-10;
/** See double fltk3::Valuator::step() const */
-void fltk3::Valuator::step(double s) {
+void fltk3::Valuator::step(double s)
+{
if (s < 0) s = -s;
A = rint(s);
B = 1;
while (fabs(s-A/B) > epsilon && B<=(0x7fffffff/10)) {B *= 10; A = rint(s*B);}
}
+
/** Sets the step value to 1/10<SUP>digits</SUP>.*/
-void fltk3::Valuator::precision(int p) {
+void fltk3::Valuator::precision(int p)
+{
A = 1.0;
for (B = 1; p--;) B *= 10;
}
+
+
/** Asks for partial redraw */
-void fltk3::Valuator::value_damage() {damage(fltk3::DAMAGE_EXPOSE);} // by
default do partial-redraw
+void fltk3::Valuator::value_damage()
+{
+ damage(fltk3::DAMAGE_EXPOSE); // by default do partial-redraw
+}
+
/**
- Sets the current value. The new value is <I>not</I>
- clamped or otherwise changed before storing it. Use
- clamp() or round() to modify the value before
- calling value(). The widget is redrawn if the new value
- is different than the current one. The initial value is zero.
- <P>changed() will return true if the user has moved the slider,
- but it will be turned off by value(x) and just before doing a callback
- (the callback can turn it back on if desired).
-*/
-int fltk3::Valuator::value(double v) {
+ Sets the current value. The new value is <I>not</I>
+ clamped or otherwise changed before storing it. Use
+ clamp() or round() to modify the value before
+ calling value(). The widget is redrawn if the new value
+ is different than the current one. The initial value is zero.
+ <P>changed() will return true if the user has moved the slider,
+ but it will be turned off by value(x) and just before doing a callback
+ (the callback can turn it back on if desired).
+ */
+int fltk3::Valuator::value(double v)
+{
clear_changed();
if (v == value_) return 0;
value_ = v;
value_damage();
return 1;
}
-/** Clamps the value, but accepts v if the previous value is not already out
of range */
-double fltk3::Valuator::softclamp(double v) {
+
+
+/** Clamps the value, but accepts v if the previous value is not already out
+ of range
+ */
+double fltk3::Valuator::softclamp(double v)
+{
int which = (min<=max);
double p = previous_value_;
if ((v<min)==which && p!=min && (p<min)!=which) return min;
@@ -94,9 +113,12 @@
else return v;
}
-// inline void fltk3::Valuator::handle_push() {previous_value_ = value_;}
-/** Called during a drag operation, after an fltk3::WHEN_CHANGED event is
received and before the callback. */
-void fltk3::Valuator::handle_drag(double v) {
+
+/** Called during a drag operation, after an fltk3::WHEN_CHANGED event is
+ received and before the callback.
+ */
+void fltk3::Valuator::handle_drag(double v)
+{
if (v != value_) {
value_ = v;
value_damage();
@@ -104,8 +126,13 @@
if (when() & fltk3::WHEN_CHANGED) do_callback();
}
}
-/** Called after an fltk3::WHEN_RELEASE event is received and before the
callback. */
-void fltk3::Valuator::handle_release() {
+
+
+/** Called after an fltk3::WHEN_RELEASE event is received and before the
+ callback.
+ */
+void fltk3::Valuator::handle_release()
+{
if (when()&fltk3::WHEN_RELEASE) {
// insure changed() is off even if no callback is done. It may have
// been turned on by the drag, and then the slider returned to it's
@@ -118,58 +145,63 @@
}
}
+
/**
- Round the passed value to the nearest step increment. Does
- nothing if step is zero.
-*/
-double fltk3::Valuator::round(double v) {
+ Round the passed value to the nearest step increment. Does
+ nothing if step is zero.
+ */
+double fltk3::Valuator::round(double v)
+{
if (A) return rint(v*B/A)*A/B;
else return v;
}
-/** Clamps the passed value to the valuator range.*/
+
+/** Clamps the passed value to the valuator range. */
double fltk3::Valuator::clamp(double v) {
if ((v<min)==(min<=max)) return min;
else if ((v>max)==(min<=max)) return max;
else return v;
}
+
/**
- Adds n times the step value to the passed value. If
- step was set to zero it uses fabs(maximum() - minimum()) /
- 100.
-*/
+ Adds n times the step value to the passed value. If
+ step was set to zero it uses fabs(maximum() - minimum()) /
+ 100.
+ */
double fltk3::Valuator::increment(double v, int n) {
if (!A) return v+n*(max-min)/100;
if (min > max) n = -n;
return (rint(v*B/A)+n)*A/B;
}
+
/**
- Uses internal rules to format the fields numerical value into
- the character array pointed to by the passed parameter.</P>
-
- <P>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.</P>
-
- <P>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 <i>buffer</i>.
- <i>buffer</i> should have space for at least 128 bytes.</P>
-
- <P>You may override this function to create your own text formatting.
-*/
+ Uses internal rules to format the fields numerical value into
+ the character array pointed to by the passed parameter.</P>
+
+ <P>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.</P>
+
+ <P>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 <i>buffer</i>.
+ <i>buffer</i> should have space for at least 128 bytes.</P>
+
+ <P>You may override this function to create your own text formatting.
+ */
int fltk3::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;
@@ -186,11 +218,12 @@
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$".
//
_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit