KWWidgets
debian/tmp/usr/include/KWWidgets/vtkKWScale.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Module:    $RCSfile: vtkKWScale.h,v $
00004 
00005   Copyright (c) Kitware, Inc.
00006   All rights reserved.
00007   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00008 
00009      This software is distributed WITHOUT ANY WARRANTY; without even
00010      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00011      PURPOSE.  See the above copyright notice for more information.
00012 
00013 =========================================================================*/
00014 // .NAME vtkKWScale - a scale (slider) widget
00015 // .SECTION Description
00016 // A widget that repsentes a scale (or slider).
00017 // .SECTION See Also
00018 // vtkKWScaleWithEntry
00019 
00020 #ifndef __vtkKWScale_h
00021 #define __vtkKWScale_h
00022 
00023 #include "vtkKWCoreWidget.h"
00024 
00025 class vtkKWEntry;
00026 class vtkKWLabel;
00027 class vtkKWPushButton;
00028 class vtkKWTopLevel;
00029 
00030 class KWWidgets_EXPORT vtkKWScale : public vtkKWCoreWidget
00031 {
00032 public:
00033   static vtkKWScale* New();
00034   vtkTypeRevisionMacro(vtkKWScale,vtkKWCoreWidget);
00035   void PrintSelf(ostream& os, vtkIndent indent);
00036 
00037   // Description:
00038   // Set the range for this scale.
00039   virtual void SetRange(double min, double max);
00040   virtual void SetRange(const double *range) 
00041     { this->SetRange(range[0], range[1]); };
00042   vtkGetVector2Macro(Range, double);
00043   virtual double GetRangeMin() { return this->GetRange()[0]; };
00044   virtual double GetRangeMax() { return this->GetRange()[1]; };
00045 
00046   // Description:
00047   // Set/Get the value of the scale.
00048   virtual void SetValue(double v);
00049   vtkGetMacro(Value, double);
00050 
00051   // Description:
00052   // Set/Get the resolution of the slider.
00053   // The range or the value of the scale are not snapped to this resolution.
00054   // The range and the value can be any floating point number. 
00055   // Think of the slider and the resolution as a way to set the value
00056   // interactively using nice clean steps (power of 10 for example).
00057   // The entry associated to the scale can be used to set the value to 
00058   // anything within the range, despite the resolution, allowing the user
00059   // to enter a precise value that could not be reached given the resolution.
00060   virtual void SetResolution(double r);
00061   vtkGetMacro(Resolution, double);
00062   
00063   // Description:
00064   // Set/Get the background color of the widget.
00065   virtual void GetBackgroundColor(double *r, double *g, double *b);
00066   virtual double* GetBackgroundColor();
00067   virtual void SetBackgroundColor(double r, double g, double b);
00068   virtual void SetBackgroundColor(double rgb[3])
00069     { this->SetBackgroundColor(rgb[0], rgb[1], rgb[2]); };
00070   
00071   // Description:
00072   // Set/Get the foreground color of the widget.
00073   virtual void GetForegroundColor(double *r, double *g, double *b);
00074   virtual double* GetForegroundColor();
00075   virtual void SetForegroundColor(double r, double g, double b);
00076   virtual void SetForegroundColor(double rgb[3])
00077     { this->SetForegroundColor(rgb[0], rgb[1], rgb[2]); };
00078 
00079   // Description:
00080   // Set/Get the highlight thickness, a non-negative value indicating the
00081   // width of the highlight rectangle to draw around the outside of the
00082   // widget when it has the input focus.
00083   virtual void SetHighlightThickness(int);
00084   virtual int GetHighlightThickness();
00085   
00086   // Description:
00087   // Set/Get the active background color of the widget. An element
00088   // (a widget or portion of a widget) is active if the mouse cursor is
00089   // positioned over the element and pressing a mouse button will cause some
00090   // action to occur.
00091   virtual void GetActiveBackgroundColor(double *r, double *g, double *b);
00092   virtual double* GetActiveBackgroundColor();
00093   virtual void SetActiveBackgroundColor(double r, double g, double b);
00094   virtual void SetActiveBackgroundColor(double rgb[3])
00095     { this->SetActiveBackgroundColor(rgb[0], rgb[1], rgb[2]); };
00096   
00097   // Description:
00098   // Set/Get the border width, a non-negative value indicating the width of
00099   // the 3-D border to draw around the outside of the widget (if such a border
00100   // is being drawn; the Relief option typically determines this).
00101   virtual void SetBorderWidth(int);
00102   virtual int GetBorderWidth();
00103   
00104   // Description:
00105   // Set/Get the 3-D effect desired for the widget. 
00106   // The value indicates how the interior of the widget should appear
00107   // relative to its exterior. 
00108   // Valid constants can be found in vtkKWOptions::ReliefType.
00109   virtual void SetRelief(int);
00110   virtual int GetRelief();
00111   virtual void SetReliefToRaised();
00112   virtual void SetReliefToSunken();
00113   virtual void SetReliefToFlat();
00114   virtual void SetReliefToRidge();
00115   virtual void SetReliefToSolid();
00116   virtual void SetReliefToGroove();
00117 
00118   // Description:
00119   // Specifies the font to use when drawing text inside the widget. 
00120   // You can use predefined font names (e.g. 'system'), or you can specify
00121   // a set of font attributes with a platform-independent name, for example,
00122   // 'times 12 bold'. In this example, the font is specified with a three
00123   // element list: the first element is the font family, the second is the
00124   // size, the third is a list of style parameters (normal, bold, roman, 
00125   // italic, underline, overstrike). Example: 'times 12 {bold italic}'.
00126   // The Times, Courier and Helvetica font families are guaranteed to exist
00127   // and will be matched to the corresponding (closest) font on your system.
00128   // If you are familiar with the X font names specification, you can also
00129   // describe the font that way (say, '*times-medium-r-*-*-12*').
00130   virtual void SetFont(const char *font);
00131   virtual const char* GetFont();
00132 
00133   // Description:
00134   // Set/Get the orientation type.
00135   // For widgets that can lay themselves out with either a horizontal or
00136   // vertical orientation, such as scales, this option specifies which 
00137   // orientation should be used. 
00138   // Valid constants can be found in vtkKWOptions::OrientationType.
00139   virtual void SetOrientation(int);
00140   vtkGetMacro(Orientation, int);
00141   virtual void SetOrientationToHorizontal();
00142   virtual void SetOrientationToVertical();
00143 
00144   // Description:
00145   // Set/Get the trough color, i.e. the color to use for the rectangular
00146   // trough areas in widgets such as scrollbars and scales.
00147   virtual void GetTroughColor(double *r, double *g, double *b);
00148   virtual double* GetTroughColor();
00149   virtual void SetTroughColor(double r, double g, double b);
00150   virtual void SetTroughColor(double rgb[3])
00151     { this->SetTroughColor(rgb[0], rgb[1], rgb[2]); };
00152 
00153   // Description
00154   // Set/Get the narrow dimension of scale. For vertical 
00155   // scales this is the trough's width; for horizontal scales this is the 
00156   // trough's height. In pixel.
00157   virtual void SetWidth(int width);
00158   virtual int GetWidth();
00159 
00160   // Description
00161   // Set/Get the desired long dimension of the scale. 
00162   // For vertical scales this is the scale's height, for horizontal scales
00163   // it is the scale's width. In pixel.
00164   virtual void SetLength(int length);
00165   virtual int GetLength();
00166 
00167   // Description
00168   // Set/Get the size of the slider, measured in screen units along 
00169   // the slider's long dimension.
00170   virtual void SetSliderLength(int length);
00171   virtual int GetSliderLength();
00172 
00173   // Description:
00174   // Set/Get the visibility of the value on top of the slider.
00175   virtual void SetValueVisibility(int);
00176   virtual int GetValueVisibility();
00177   vtkBooleanMacro(ValueVisibility, int);
00178 
00179   // Description:
00180   // Set/Get the tick interval.
00181   // Determines the spacing between numerical tick marks displayed below or to
00182   // the left of the slider. If 0, no tick marks will be displayed. 
00183   virtual void SetTickInterval(double val);
00184   virtual double GetTickInterval();
00185   
00186   // Description
00187   // Set/Get the string to display as a label for the scale. 
00188   // For vertical scales the label is displayed just to the right of the top
00189   // end of the scale. For horizontal scales the label is displayed just above
00190   // the left end of the scale. If the option is specified as an empty string, 
00191   // no label is displayed. The position of the label can not be changed. For
00192   // more elaborated options, check vtkKWScaleWithEntry
00193   virtual void SetLabelText(const char *);
00194   virtual const char* GetLabelText();
00195 
00196   // Description:
00197   // Specifies commands to associate with the widget. 
00198   // 'Command' is invoked when the widget value is changing (i.e. during
00199   // user interaction).
00200   // 'StartCommand' is invoked at the beginning of a user interaction with
00201   // the widget (when a mouse button is pressed over the widget for example).
00202   // 'EndCommand' is invoked at the end of the user interaction with the 
00203   // widget (when the mouse button is released for example).
00204   // The need for a 'Command', 'StartCommand' and 'EndCommand' can be
00205   // explained as follows: 'EndCommand' can be used to be notified about any
00206   // changes made to this widget *after* the corresponding user interaction has
00207   // been performed (say, after releasing the mouse button that was dragging
00208   // a slider, or after clicking on a checkbutton). 'Command' can be set
00209   // *additionally* to be notified about the intermediate changes that
00210   // occur *during* the corresponding user interaction (say, *while* dragging
00211   // a slider). While setting 'EndCommand' is enough to be notified about
00212   // any changes, setting 'Command' is an application-specific choice that
00213   // is likely to depend on how fast you want (or can) answer to rapid changes
00214   // occuring during a user interaction, if any. 'StartCommand' is rarely
00215   // used but provides an opportunity for the application to modify its
00216   // state and prepare itself for user-interaction; in that case, the
00217   // 'EndCommand' is usually set in a symmetric fashion to set the application
00218   // back to its previous state.
00219   // The 'object' argument is the object that will have the method called on
00220   // it. The 'method' argument is the name of the method to be called and any
00221   // arguments in string form. If the object is NULL, the method is still
00222   // evaluated as a simple command. 
00223   // The following parameters are also passed to the command:
00224   // - the current value: int (if Resolution is integer); double otherwise
00225   //   Note: the 'int' signature is for convenience, so that the command can
00226   //   be set to a callback accepting 'int'. In doubt, implement the callback
00227   //   using a 'double' signature that will accept both 'int' and 'double'.
00228   virtual void SetCommand(vtkObject *object, const char *method);
00229   virtual void SetStartCommand(vtkObject *object, const char *method);
00230   virtual void SetEndCommand(vtkObject *object, const char *method);
00231 
00232   // Description:
00233   // Events. The ScaleValueChangingEvent is triggered when the widget value
00234   // is changed (i.e., during user interaction on the widget's slider),
00235   // the ScaleValueStartChangingEvent is invoked at the beginning of an 
00236   // interaction with the widget, the ScaleValueChangedEvent is invoked at the
00237   // end of an interaction with the widget. They are similar in concept as
00238   // the 'Command', 'StartCommand', and 'EndCommand' callbacks but can be
00239   // used by multiple listeners/observers at a time.
00240   // The following parameters are also passed as client data:
00241   // - the current value: double
00242   //BTX
00243   enum
00244   {
00245     ScaleValueChangingEvent = 10000,
00246     ScaleValueChangedEvent,
00247     ScaleValueStartChangingEvent
00248   };
00249   //ETX
00250 
00251   // Description:
00252   // Set/Get whether the above commands should be called or not.
00253   // This make it easier to disable the commands while setting the scale
00254   // value for example.
00255   vtkSetMacro(DisableCommands, int);
00256   vtkGetMacro(DisableCommands, int);
00257   vtkBooleanMacro(DisableCommands, int);
00258 
00259   // Description:
00260   // Update the "enable" state of the object and its internal parts.
00261   // Depending on different Ivars (this->Enabled, the application's 
00262   // Limited Edition Mode, etc.), the "enable" state of the object is updated
00263   // and propagated to its internal parts/subwidgets. This will, for example,
00264   // enable/disable parts of the widget UI, enable/disable the visibility
00265   // of 3D widgets, etc.
00266   virtual void UpdateEnableState();
00267 
00268   // Description:
00269   // Turn on/off the automatic clamping of the end values when the 
00270   // user types a value beyond the range. Default is on.
00271   vtkSetMacro(ClampValue, int);
00272   vtkGetMacro(ClampValue, int);
00273   vtkBooleanMacro(ClampValue, int);
00274 
00275   // Description:
00276   // Callbacks. Internal, do not use.
00277   vtkGetMacro(DisableScaleValueCallback, int);
00278   vtkSetMacro(DisableScaleValueCallback, int);
00279   vtkBooleanMacro(DisableScaleValueCallback, int);
00280   virtual void ScaleValueCallback(double num);
00281   virtual void ButtonPressCallback();
00282   virtual void ButtonReleaseCallback();
00283 
00284 protected:
00285   vtkKWScale();
00286   ~vtkKWScale();
00287 
00288   // Description:
00289   // Create the widget.
00290   virtual void CreateWidget();
00291 
00292   // Description:
00293   // Bind/Unbind all components so that values can be changed, but
00294   // no command will be called.
00295   void Bind();
00296   void UnBind();
00297 
00298   int DisableScaleValueCallback;
00299   int ClampValue;
00300 
00301   double       Value;
00302   double       Resolution;
00303   double       Range[2];
00304 
00305   int Orientation;
00306 
00307   // Description:
00308   // Update internal widgets value
00309   virtual void UpdateRange();
00310   virtual void UpdateResolution();
00311   virtual void UpdateValue();
00312   virtual void UpdateOrientation();
00313 
00314   //BTX
00315   friend class vtkKWScaleWithEntry;
00316   //ETX
00317 
00318   int DisableCommands;
00319   char *Command;
00320   char *StartCommand;
00321   char *EndCommand;
00322 
00323   virtual void InvokeScaleCommand(const char *command, double value);
00324   virtual void InvokeCommand(double value);
00325   virtual void InvokeStartCommand(double value);
00326   virtual void InvokeEndCommand(double value);
00327 
00328 private:
00329   vtkKWScale(const vtkKWScale&); // Not implemented
00330   void operator=(const vtkKWScale&); // Not implemented
00331 };
00332 
00333 
00334 #endif