FDOSTUI
FreeDOS Text User Interface
valuator.hpp
Go to the documentation of this file.
1 /*
2  VALUATOR.HPP
3 
4  Derived from FLTK Valuator class
5 
6  Copyright 1998-2006 by Bill Spitzak and others.
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Library General Public
10  License as published by the Free Software Foundation; either
11  version 2 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Library General Public License for more details.
17 
18  You should have received a copy of the GNU Library General Public
19  License along with this library; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21  USA.
22 
23 */
24 #ifndef __valuator_hpp__
25 
26 #include "widget.hpp"
27 
28 class valuator
29 {
30 
31 public:
32 
33  typedef void (*signal_value_t)(
34  widget const* i_widget,
35  void* io_user_data);
36 
37  valuator();
38 
39  virtual
40  ~valuator();
41 
42  virtual double
43  get_value() const;
44 
45  double
46  get_minimum() const;
47 
48  double
49  get_maximum() const;
50 
51  double
52  get_step() const;
53 
54  void
55  set_range(
56  double const i_minimum,
57  double const i_maximum);
58 
59  void
60  set_step(
61  double const i_step);
62 
63  void
64  set_step(
65  double const i_step,
66  int const i_precision);
67 
68  virtual bool
69  set_value(
70  double const i_value);
71 
72  void
74  int const i_digits);
75 
76  virtual int
77  format(
78  char* o_buffer,
79  unsigned int const i_size);
80 
81  void
83  signal_value_t i_signal);
84 
85  double
86  round(
87  double const i_value) const;
88 
89  double
90  clamp(
91  double const i_value) const;
92 
93  double
94  clamp_soft(
95  double const i_value) const;
96 
97  double
98  increment(
99  double const i_value,
100  int const i_amount) const;
101 
102  void
103  set_debounce(
104  bool const i_debounce);
105 
106 protected:
107 
109  double m_value;
111  double m_minimum;
112  double m_maximum;
113  double m_step;
114  double m_precision;
116 
117  void
118  handle_push();
119 
120  void
121  handle_drag(
122  widget *const io_widget,
123  double const i_value);
124 
125  void
127  widget *const io_widget);
128 
129 private:
130 
131  valuator(
132  const valuator&);
133 
134  valuator&
135  operator=(valuator const&);
136 
137 };
138 
139 inline void
141  signal_value_t i_signal)
142 {
143 
144  m_signal_value= i_signal;
145 
146  return;
147 }
148 
149 inline double
151 {
152  return m_value;
153 }
154 
155 inline double
157 {
158  return m_minimum;
159 }
160 
161 inline double
163 {
164  return m_maximum;
165 }
166 
167 inline double
169 {
170  double l_step;
171 
172  l_step= (m_step / m_precision);
173 
174  return l_step;
175 }
176 
177 inline void
179  double const i_minimum,
180  double const i_maximum)
181 {
182  m_minimum= i_minimum;
183  m_maximum= i_maximum;
184  // _mjo fixme if value out of new range
185  return;
186 }
187 
188 inline void
190  double const i_step)
191 {
192  m_step= i_step;
193  return;
194 }
195 
196 inline void
198  double const i_step,
199  int const i_precision)
200 {
201  m_step= i_step;
202  m_precision= i_precision;
203  return;
204 }
205 
206 inline void
208 {
210  return;
211 }
212 
213 inline void
215  bool const i_debounce)
216 {
217  m_debounce= i_debounce;
218 }
219 
220 #define __valuator_hpp__
221 #endif
void handle_release(widget *const io_widget)
emit a signal if the previous value is not equal to the current value
Definition: valuator.cpp:254
virtual double get_value() const
gets the current value
Definition: valuator.hpp:150
contains widget class
void set_signal_value(signal_value_t i_signal)
set callback
Definition: valuator.hpp:140
double m_previous_value
Definition: valuator.hpp:110
double increment(double const i_value, int const i_amount) const
increment the value
Definition: valuator.cpp:188
double m_step
Definition: valuator.hpp:113
void set_step(double const i_step)
set the amount that the value is incremented or decremented in response to mouse or keyboard movement...
Definition: valuator.hpp:189
double clamp(double const i_value) const
checks the bounds of i_value
Definition: valuator.cpp:120
base class for all derived widgets
Definition: widget.hpp:19
void set_debounce(bool const i_debounce)
turns drawing of the widget on or off
Definition: valuator.hpp:214
double round(double const i_value) const
rounds the value to the nearest step increment
Definition: valuator.cpp:99
void(* signal_value_t)(widget const *i_widget, void *io_user_data)
function prototype to recieve signal
Definition: valuator.hpp:33
double m_value
Definition: valuator.hpp:109
double get_minimum() const
gets the minimum value
Definition: valuator.hpp:156
void handle_push()
sets previous value to current value
Definition: valuator.hpp:207
double get_maximum() const
gets the maximum value
Definition: valuator.hpp:162
virtual int format(char *o_buffer, unsigned int const i_size)
format a value into string
Definition: valuator.cpp:268
signal_value_t m_signal_value
Definition: valuator.hpp:115
double get_step() const
the amount that the value is incremented or decremented in response to mouse or keyboard movement ...
Definition: valuator.hpp:168
void handle_drag(widget *const io_widget, double const i_value)
sets the value and if changed redraws the widget
Definition: valuator.cpp:236
double m_minimum
Definition: valuator.hpp:111
virtual ~valuator()
destructor
Definition: valuator.cpp:55
void set_range(double const i_minimum, double const i_maximum)
sets the minimum and maximum bounds the value can have
Definition: valuator.hpp:178
interface to control a floating point value
Definition: valuator.hpp:28
bool m_debounce
Definition: valuator.hpp:108
double clamp_soft(double const i_value) const
checks the bounds of i_value
Definition: valuator.cpp:148
valuator()
constructor
Definition: valuator.cpp:42
virtual bool set_value(double const i_value)
sets the value
Definition: valuator.cpp:219
void set_precision(int const i_digits)
sets the precision
Definition: valuator.cpp:61
double m_precision
Definition: valuator.hpp:114
double m_maximum
Definition: valuator.hpp:112