KWWidgets
debian/tmp/usr/include/KWWidgets/vtkKWScale.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Module: $RCSfile: vtkKWScale.h,v $
4 
5  Copyright (c) Kitware, Inc.
6  All rights reserved.
7  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
8 
9  This software is distributed WITHOUT ANY WARRANTY; without even
10  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11  PURPOSE. See the above copyright notice for more information.
12 
13 =========================================================================*/
14 // .NAME vtkKWScale - a scale (slider) widget
15 // .SECTION Description
16 // A widget that repsentes a scale (or slider).
17 // .SECTION See Also
18 // vtkKWScaleWithEntry
19 
20 #ifndef __vtkKWScale_h
21 #define __vtkKWScale_h
22 
23 #include "vtkKWCoreWidget.h"
24 
25 class vtkKWEntry;
26 class vtkKWLabel;
27 class vtkKWPushButton;
28 class vtkKWTopLevel;
29 
31 {
32 public:
33  static vtkKWScale* New();
34  vtkTypeRevisionMacro(vtkKWScale,vtkKWCoreWidget);
35  void PrintSelf(ostream& os, vtkIndent indent);
36 
37  // Description:
38  // Set the range for this scale.
39  virtual void SetRange(double min, double max);
40  virtual void SetRange(const double *range)
41  { this->SetRange(range[0], range[1]); };
42  vtkGetVector2Macro(Range, double);
43  virtual double GetRangeMin() { return this->GetRange()[0]; };
44  virtual double GetRangeMax() { return this->GetRange()[1]; };
45 
46  // Description:
47  // Set/Get the value of the scale.
48  virtual void SetValue(double v);
49  vtkGetMacro(Value, double);
50 
51  // Description:
52  // Set/Get the resolution of the slider.
53  // The range or the value of the scale are not snapped to this resolution.
54  // The range and the value can be any floating point number.
55  // Think of the slider and the resolution as a way to set the value
56  // interactively using nice clean steps (power of 10 for example).
57  // The entry associated to the scale can be used to set the value to
58  // anything within the range, despite the resolution, allowing the user
59  // to enter a precise value that could not be reached given the resolution.
60  virtual void SetResolution(double r);
61  vtkGetMacro(Resolution, double);
62 
63  // Description:
64  // Set/Get the background color of the widget.
65  virtual void GetBackgroundColor(double *r, double *g, double *b);
66  virtual double* GetBackgroundColor();
67  virtual void SetBackgroundColor(double r, double g, double b);
68  virtual void SetBackgroundColor(double rgb[3])
69  { this->SetBackgroundColor(rgb[0], rgb[1], rgb[2]); };
70 
71  // Description:
72  // Set/Get the foreground color of the widget.
73  virtual void GetForegroundColor(double *r, double *g, double *b);
74  virtual double* GetForegroundColor();
75  virtual void SetForegroundColor(double r, double g, double b);
76  virtual void SetForegroundColor(double rgb[3])
77  { this->SetForegroundColor(rgb[0], rgb[1], rgb[2]); };
78 
79  // Description:
80  // Set/Get the highlight thickness, a non-negative value indicating the
81  // width of the highlight rectangle to draw around the outside of the
82  // widget when it has the input focus.
83  virtual void SetHighlightThickness(int);
84  virtual int GetHighlightThickness();
85 
86  // Description:
87  // Set/Get the active background color of the widget. An element
88  // (a widget or portion of a widget) is active if the mouse cursor is
89  // positioned over the element and pressing a mouse button will cause some
90  // action to occur.
91  virtual void GetActiveBackgroundColor(double *r, double *g, double *b);
92  virtual double* GetActiveBackgroundColor();
93  virtual void SetActiveBackgroundColor(double r, double g, double b);
94  virtual void SetActiveBackgroundColor(double rgb[3])
95  { this->SetActiveBackgroundColor(rgb[0], rgb[1], rgb[2]); };
96 
97  // Description:
98  // Set/Get the border width, a non-negative value indicating the width of
99  // the 3-D border to draw around the outside of the widget (if such a border
100  // is being drawn; the Relief option typically determines this).
101  virtual void SetBorderWidth(int);
102  virtual int GetBorderWidth();
103 
104  // Description:
105  // Set/Get the 3-D effect desired for the widget.
106  // The value indicates how the interior of the widget should appear
107  // relative to its exterior.
108  // Valid constants can be found in vtkKWOptions::ReliefType.
109  virtual void SetRelief(int);
110  virtual int GetRelief();
111  virtual void SetReliefToRaised();
112  virtual void SetReliefToSunken();
113  virtual void SetReliefToFlat();
114  virtual void SetReliefToRidge();
115  virtual void SetReliefToSolid();
116  virtual void SetReliefToGroove();
117 
118  // Description:
119  // Specifies the font to use when drawing text inside the widget.
120  // You can use predefined font names (e.g. 'system'), or you can specify
121  // a set of font attributes with a platform-independent name, for example,
122  // 'times 12 bold'. In this example, the font is specified with a three
123  // element list: the first element is the font family, the second is the
124  // size, the third is a list of style parameters (normal, bold, roman,
125  // italic, underline, overstrike). Example: 'times 12 {bold italic}'.
126  // The Times, Courier and Helvetica font families are guaranteed to exist
127  // and will be matched to the corresponding (closest) font on your system.
128  // If you are familiar with the X font names specification, you can also
129  // describe the font that way (say, '*times-medium-r-*-*-12*').
130  virtual void SetFont(const char *font);
131  virtual const char* GetFont();
132 
133  // Description:
134  // Set/Get the orientation type.
135  // For widgets that can lay themselves out with either a horizontal or
136  // vertical orientation, such as scales, this option specifies which
137  // orientation should be used.
138  // Valid constants can be found in vtkKWOptions::OrientationType.
139  virtual void SetOrientation(int);
140  vtkGetMacro(Orientation, int);
141  virtual void SetOrientationToHorizontal();
142  virtual void SetOrientationToVertical();
143 
144  // Description:
145  // Set/Get the trough color, i.e. the color to use for the rectangular
146  // trough areas in widgets such as scrollbars and scales.
147  virtual void GetTroughColor(double *r, double *g, double *b);
148  virtual double* GetTroughColor();
149  virtual void SetTroughColor(double r, double g, double b);
150  virtual void SetTroughColor(double rgb[3])
151  { this->SetTroughColor(rgb[0], rgb[1], rgb[2]); };
152 
153  // Description
154  // Set/Get the narrow dimension of scale. For vertical
155  // scales this is the trough's width; for horizontal scales this is the
156  // trough's height. In pixel.
157  virtual void SetWidth(int width);
158  virtual int GetWidth();
159 
160  // Description
161  // Set/Get the desired long dimension of the scale.
162  // For vertical scales this is the scale's height, for horizontal scales
163  // it is the scale's width. In pixel.
164  virtual void SetLength(int length);
165  virtual int GetLength();
166 
167  // Description
168  // Set/Get the size of the slider, measured in screen units along
169  // the slider's long dimension.
170  virtual void SetSliderLength(int length);
171  virtual int GetSliderLength();
172 
173  // Description:
174  // Set/Get the visibility of the value on top of the slider.
175  virtual void SetValueVisibility(int);
176  virtual int GetValueVisibility();
177  vtkBooleanMacro(ValueVisibility, int);
178 
179  // Description:
180  // Set/Get the tick interval.
181  // Determines the spacing between numerical tick marks displayed below or to
182  // the left of the slider. If 0, no tick marks will be displayed.
183  virtual void SetTickInterval(double val);
184  virtual double GetTickInterval();
185 
186  // Description
187  // Set/Get the string to display as a label for the scale.
188  // For vertical scales the label is displayed just to the right of the top
189  // end of the scale. For horizontal scales the label is displayed just above
190  // the left end of the scale. If the option is specified as an empty string,
191  // no label is displayed. The position of the label can not be changed. For
192  // more elaborated options, check vtkKWScaleWithEntry
193  virtual void SetLabelText(const char *);
194  virtual const char* GetLabelText();
195 
196  // Description:
197  // Specifies commands to associate with the widget.
198  // 'Command' is invoked when the widget value is changing (i.e. during
199  // user interaction).
200  // 'StartCommand' is invoked at the beginning of a user interaction with
201  // the widget (when a mouse button is pressed over the widget for example).
202  // 'EndCommand' is invoked at the end of the user interaction with the
203  // widget (when the mouse button is released for example).
204  // The need for a 'Command', 'StartCommand' and 'EndCommand' can be
205  // explained as follows: 'EndCommand' can be used to be notified about any
206  // changes made to this widget *after* the corresponding user interaction has
207  // been performed (say, after releasing the mouse button that was dragging
208  // a slider, or after clicking on a checkbutton). 'Command' can be set
209  // *additionally* to be notified about the intermediate changes that
210  // occur *during* the corresponding user interaction (say, *while* dragging
211  // a slider). While setting 'EndCommand' is enough to be notified about
212  // any changes, setting 'Command' is an application-specific choice that
213  // is likely to depend on how fast you want (or can) answer to rapid changes
214  // occuring during a user interaction, if any. 'StartCommand' is rarely
215  // used but provides an opportunity for the application to modify its
216  // state and prepare itself for user-interaction; in that case, the
217  // 'EndCommand' is usually set in a symmetric fashion to set the application
218  // back to its previous state.
219  // The 'object' argument is the object that will have the method called on
220  // it. The 'method' argument is the name of the method to be called and any
221  // arguments in string form. If the object is NULL, the method is still
222  // evaluated as a simple command.
223  // The following parameters are also passed to the command:
224  // - the current value: int (if Resolution is integer); double otherwise
225  // Note: the 'int' signature is for convenience, so that the command can
226  // be set to a callback accepting 'int'. In doubt, implement the callback
227  // using a 'double' signature that will accept both 'int' and 'double'.
228  virtual void SetCommand(vtkObject *object, const char *method);
229  virtual void SetStartCommand(vtkObject *object, const char *method);
230  virtual void SetEndCommand(vtkObject *object, const char *method);
231 
232  // Description:
233  // Events. The ScaleValueChangingEvent is triggered when the widget value
234  // is changed (i.e., during user interaction on the widget's slider),
235  // the ScaleValueStartChangingEvent is invoked at the beginning of an
236  // interaction with the widget, the ScaleValueChangedEvent is invoked at the
237  // end of an interaction with the widget. They are similar in concept as
238  // the 'Command', 'StartCommand', and 'EndCommand' callbacks but can be
239  // used by multiple listeners/observers at a time.
240  // The following parameters are also passed as client data:
241  // - the current value: double
242  //BTX
243  enum
244  {
245  ScaleValueChangingEvent = 10000,
247  ScaleValueStartChangingEvent
248  };
249  //ETX
250 
251  // Description:
252  // Set/Get whether the above commands should be called or not.
253  // This make it easier to disable the commands while setting the scale
254  // value for example.
255  vtkSetMacro(DisableCommands, int);
256  vtkGetMacro(DisableCommands, int);
257  vtkBooleanMacro(DisableCommands, int);
258 
259  // Description:
260  // Update the "enable" state of the object and its internal parts.
261  // Depending on different Ivars (this->Enabled, the application's
262  // Limited Edition Mode, etc.), the "enable" state of the object is updated
263  // and propagated to its internal parts/subwidgets. This will, for example,
264  // enable/disable parts of the widget UI, enable/disable the visibility
265  // of 3D widgets, etc.
266  virtual void UpdateEnableState();
267 
268  // Description:
269  // Turn on/off the automatic clamping of the end values when the
270  // user types a value beyond the range. Default is on.
271  vtkSetMacro(ClampValue, int);
272  vtkGetMacro(ClampValue, int);
273  vtkBooleanMacro(ClampValue, int);
274 
275  // Description:
276  // Callbacks. Internal, do not use.
277  vtkGetMacro(DisableScaleValueCallback, int);
278  vtkSetMacro(DisableScaleValueCallback, int);
279  vtkBooleanMacro(DisableScaleValueCallback, int);
280  virtual void ScaleValueCallback(double num);
281  virtual void ButtonPressCallback();
282  virtual void ButtonReleaseCallback();
283 
284 protected:
285  vtkKWScale();
286  ~vtkKWScale();
287 
288  // Description:
289  // Create the widget.
290  virtual void CreateWidget();
291 
292  // Description:
293  // Bind/Unbind all components so that values can be changed, but
294  // no command will be called.
295  void Bind();
296  void UnBind();
297 
300 
301  double Value;
302  double Resolution;
303  double Range[2];
304 
306 
307  // Description:
308  // Update internal widgets value
309  virtual void UpdateRange();
310  virtual void UpdateResolution();
311  virtual void UpdateValue();
312  virtual void UpdateOrientation();
313 
314  //BTX
315  friend class vtkKWScaleWithEntry;
316  //ETX
317 
319  char *Command;
321  char *EndCommand;
322 
323  virtual void InvokeScaleCommand(const char *command, double value);
324  virtual void InvokeCommand(double value);
325  virtual void InvokeStartCommand(double value);
326  virtual void InvokeEndCommand(double value);
327 
328 private:
329  vtkKWScale(const vtkKWScale&); // Not implemented
330  void operator=(const vtkKWScale&); // Not implemented
331 };
332 
333 
334 #endif