KWWidgets
vtkKWHSVColorSelector.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Module: $RCSfile: vtkKWHSVColorSelector.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 vtkKWHSVColorSelector - an HSV color selector
15 // .SECTION Description
16 // A widget that allows the user choose a HSV color interactively
17 
18 #ifndef __vtkKWHSVColorSelector_h
19 #define __vtkKWHSVColorSelector_h
20 
21 #include "vtkKWCompositeWidget.h"
22 
23 class vtkKWCanvas;
24 class vtkKWLabel;
25 
27 {
28 public:
29  static vtkKWHSVColorSelector* New();
31  void PrintSelf(ostream& os, vtkIndent indent);
32 
33  // Description:
34  // Set/Get the hue/saturation wheel radius in pixels.
35  virtual void SetHueSatWheelRadius(int);
36  vtkGetMacro(HueSatWheelRadius, int);
37 
38  // Description:
39  // Set/Get the value box width in pixels.
40  virtual void SetValueBoxWidth(int);
41  vtkGetMacro(ValueBoxWidth, int);
42 
43  // Description:
44  // Set/Get the radius of the selection cursor in the hue/sat wheel in pixels.
45  virtual void SetHueSatCursorRadius(int);
46  vtkGetMacro(HueSatCursorRadius, int);
47 
48  // Description:
49  // Set/Get the horizontal outer margin of the selection cursor in the value
50  // box in pixels.
51  virtual void SetValueCursorMargin(int);
52  vtkGetMacro(ValueCursorMargin, int);
53 
54  // Description:
55  // Select/Deselect a color (in HSV space)
56  vtkGetVector3Macro(SelectedColor, double);
57  virtual void SetSelectedColor(double h, double s, double v);
58  virtual void SetSelectedColor(double hsv[3])
59  { this->SetSelectedColor(hsv[0], hsv[1], hsv[2]); };
60  virtual void ClearSelection();
61  virtual int HasSelection();
62 
63  // Description:
64  // User can only modify the selection, it can not create a selection (i.e.
65  // pick a color) when nothing has been selected yet.
66  vtkSetMacro(ModificationOnly, int);
67  vtkGetMacro(ModificationOnly, int);
68  vtkBooleanMacro(ModificationOnly, int);
69 
70  // Description:
71  // Hide the Value UI.
72  virtual void SetHideValue(int);
73  vtkGetMacro(HideValue, int);
74  vtkBooleanMacro(HideValue, int);
75 
76  // Description:
77  // Specifies commands to associate with the widget.
78  // 'SelectionChangedCommand' is invoked when the selected color has
79  // changed (i.e. at the end of the user interaction).
80  // 'SelectionChangingCommand' is invoked when the selected color is
81  // changing (i.e. during the user interaction).
82  // The need for a '...ChangedCommand' and '...ChangingCommand' can be
83  // explained as follows: the former can be used to be notified about any
84  // changes made to this widget *after* the corresponding user interaction has
85  // been performed (say, after releasing the mouse button that was dragging
86  // a slider, or after clicking on a checkbutton). The later can be set
87  // *additionally* to be notified about the intermediate changes that
88  // occur *during* the corresponding user interaction (say, *while* dragging
89  // a slider). While setting '...ChangedCommand' is enough to be notified
90  // about any changes, setting '...ChangingCommand' is an application-specific
91  // choice that is likely to depend on how fast you want (or can) answer to
92  // rapid changes occuring during a user interaction, if any.
93  // The 'object' argument is the object that will have the method called on
94  // it. The 'method' argument is the name of the method to be called and any
95  // arguments in string form. If the object is NULL, the method is still
96  // evaluated as a simple command.
97  // The following parameters are also passed to the command:
98  // - selected HSV color: double, double, double
99  // Note that if InvokeCommandsWithRGB is true, the selected color is passed
100  // as RGB instead of HSV.
101  virtual void SetSelectionChangedCommand(
102  vtkObject *object, const char *method);
103  virtual void SetSelectionChangingCommand(
104  vtkObject *object, const char *method);
105 
106  // Description:
107  // Set/Get if the commands should be invoked with RGB parameters instead
108  // of the current HSV value.
109  vtkSetMacro(InvokeCommandsWithRGB, int);
110  vtkGetMacro(InvokeCommandsWithRGB, int);
111  vtkBooleanMacro(InvokeCommandsWithRGB, int);
112 
113  // Description:
114  // Set the string that enables balloon help for this widget.
115  // Override to pass down to children.
116  virtual void SetBalloonHelpString(const char *str);
117 
118  // Description:
119  // Access to the canvas and internal elements
120  vtkGetObjectMacro(HueSatWheelCanvas, vtkKWCanvas);
121  vtkGetObjectMacro(ValueBoxCanvas, vtkKWCanvas);
122 
123  // Description:
124  // Update the whole UI depending on the value of the Ivars
125  virtual void Update();
126 
127  // Description:
128  // Update the "enable" state of the object and its internal parts.
129  // Depending on different Ivars (this->Enabled, the application's
130  // Limited Edition Mode, etc.), the "enable" state of the object is updated
131  // and propagated to its internal parts/subwidgets. This will, for example,
132  // enable/disable parts of the widget UI, enable/disable the visibility
133  // of 3D widgets, etc.
134  virtual void UpdateEnableState();
135 
136  // Description:
137  // Callbacks. Internal, do not use.
138  virtual void HueSatPickCallback(int x, int y);
139  virtual void HueSatMoveCallback(int x, int y);
140  virtual void HueSatReleaseCallback();
141  virtual void ValuePickCallback(int x, int y);
142  virtual void ValueMoveCallback(int x, int y);
143  virtual void ValueReleaseCallback();
144 
145 protected:
148 
149  // Description:
150  // Create the widget.
151  virtual void CreateWidget();
152 
153  int HueSatWheelRadius;
154  int HueSatCursorRadius;
155  int ValueBoxWidth;
156  int ValueCursorMargin;
157  int Selected;
158  double SelectedColor[3];
159  int ModificationOnly;
160  int HideValue;
161  double PreviouslySelectedColor[3];
162 
163  // Commands
164 
165  char *SelectionChangedCommand;
166  char *SelectionChangingCommand;
167 
168  int InvokeCommandsWithRGB;
169  virtual void InvokeCommandWithColor(
170  const char *command, double h, double s, double v);
171  virtual void InvokeSelectionChangedCommand(double h, double s, double v);
172  virtual void InvokeSelectionChangingCommand(double h, double s, double v);
173 
174  // GUI
175 
176  vtkKWCanvas *HueSatWheelCanvas;
177  vtkKWCanvas *ValueBoxCanvas;
178  vtkKWLabel *HueSatLabel;
179  vtkKWLabel *ValueLabel;
180 
181  // Description:
182  // Bind/Unbind all components.
183  virtual void Bind();
184  virtual void UnBind();
185 
186  // Description:
187  // Pack the widget
188  virtual void Pack();
189 
190  // Description:
191  // Redraw or update canvas elements
192  virtual void Redraw();
193  virtual void RedrawHueSatWheelCanvas();
194  virtual void UpdateHueSatWheelImage();
195  virtual void UpdateHueSatWheelSelection();
196  virtual void RedrawValueBoxCanvas();
197  virtual void UpdateValueBoxImage();
198  virtual void UpdateValueBoxSelection();
199 
200  // Description:
201  // Get Hue/Sat given coordinates in Hue/Sat wheel image
202  // Return 1 if OK, 0 if coords were out of the wheel (i.e. sat was > 1.0)
203  virtual int GetHueSatFromCoordinates(int x, int y, double &hue, double &sat);
204 
205  // Description:
206  // Get Value given coordinates in Value image
207  virtual void GetValueFromCoordinate(int y, double &value);
208 
209 private:
210  vtkKWHSVColorSelector(const vtkKWHSVColorSelector&); // Not implemented
211  void operator=(const vtkKWHSVColorSelector&); // Not implemented
212 };
213 
214 #endif
215