File: vtkKWHSVColorSelector.h

package info (click to toggle)
kwwidgets 1.0.0~cvs20090825-4
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 14,108 kB
  • ctags: 15,770
  • sloc: cpp: 128,146; ansic: 44,137; tcl: 30,595; python: 2,283; sh: 338; makefile: 69; xml: 10
file content (215 lines) | stat: -rw-r--r-- 7,675 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*=========================================================================

  Module:    $RCSfile: vtkKWHSVColorSelector.h,v $

  Copyright (c) Kitware, Inc.
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
// .NAME vtkKWHSVColorSelector - an HSV color selector
// .SECTION Description
// A widget that allows the user choose a HSV color interactively

#ifndef __vtkKWHSVColorSelector_h
#define __vtkKWHSVColorSelector_h

#include "vtkKWCompositeWidget.h"

class vtkKWCanvas;
class vtkKWLabel;

class KWWidgets_EXPORT vtkKWHSVColorSelector : public vtkKWCompositeWidget
{
public:
  static vtkKWHSVColorSelector* New();
  vtkTypeRevisionMacro(vtkKWHSVColorSelector,vtkKWCompositeWidget);
  void PrintSelf(ostream& os, vtkIndent indent);

  // Description:
  // Set/Get the hue/saturation wheel radius in pixels.
  virtual void SetHueSatWheelRadius(int);
  vtkGetMacro(HueSatWheelRadius, int);
  
  // Description:
  // Set/Get the value box width in pixels.
  virtual void SetValueBoxWidth(int);
  vtkGetMacro(ValueBoxWidth, int);
  
  // Description:
  // Set/Get the radius of the selection cursor in the hue/sat wheel in pixels.
  virtual void SetHueSatCursorRadius(int);
  vtkGetMacro(HueSatCursorRadius, int);

  // Description:
  // Set/Get the horizontal outer margin of the selection cursor in the value
  // box in pixels.
  virtual void SetValueCursorMargin(int);
  vtkGetMacro(ValueCursorMargin, int);

  // Description:
  // Select/Deselect a color (in HSV space)
  vtkGetVector3Macro(SelectedColor, double);
  virtual void SetSelectedColor(double h, double s, double v);
  virtual void SetSelectedColor(double hsv[3])
    { this->SetSelectedColor(hsv[0], hsv[1], hsv[2]); };
  virtual void ClearSelection();
  virtual int  HasSelection();

  // Description:
  // User can only modify the selection, it can not create a selection (i.e.
  // pick a color) when nothing has been selected yet.
  vtkSetMacro(ModificationOnly, int);
  vtkGetMacro(ModificationOnly, int);
  vtkBooleanMacro(ModificationOnly, int);

  // Description:
  // Hide the Value UI.
  virtual void SetHideValue(int);
  vtkGetMacro(HideValue, int);
  vtkBooleanMacro(HideValue, int);

  // Description:
  // Specifies commands to associate with the widget. 
  // 'SelectionChangedCommand' is invoked when the selected color has
  // changed (i.e. at the end of the user interaction).
  // 'SelectionChangingCommand' is invoked when the selected color is
  // changing (i.e. during the user interaction).
  // The need for a '...ChangedCommand' and '...ChangingCommand' can be
  // explained as follows: the former can be used to be notified about any
  // changes made to this widget *after* the corresponding user interaction has
  // been performed (say, after releasing the mouse button that was dragging
  // a slider, or after clicking on a checkbutton). The later can be set
  // *additionally* to be notified about the intermediate changes that
  // occur *during* the corresponding user interaction (say, *while* dragging
  // a slider). While setting '...ChangedCommand' is enough to be notified
  // about any changes, setting '...ChangingCommand' is an application-specific
  // choice that is likely to depend on how fast you want (or can) answer to
  // rapid changes occuring during a user interaction, if any.
  // The 'object' argument is the object that will have the method called on
  // it. The 'method' argument is the name of the method to be called and any
  // arguments in string form. If the object is NULL, the method is still
  // evaluated as a simple command. 
  // The following parameters are also passed to the command:
  // - selected HSV color: double, double, double
  // Note that if InvokeCommandsWithRGB is true, the selected color is passed
  // as RGB instead of HSV.
  virtual void SetSelectionChangedCommand(
    vtkObject *object, const char *method);
  virtual void SetSelectionChangingCommand(
    vtkObject *object, const char *method);

  // Description:
  // Set/Get if the commands should be invoked with RGB parameters instead
  // of the current HSV value.
  vtkSetMacro(InvokeCommandsWithRGB, int);
  vtkGetMacro(InvokeCommandsWithRGB, int);
  vtkBooleanMacro(InvokeCommandsWithRGB, int);

  // Description:
  // Set the string that enables balloon help for this widget.
  // Override to pass down to children.
  virtual void SetBalloonHelpString(const char *str);

  // Description:
  // Access to the canvas and internal elements
  vtkGetObjectMacro(HueSatWheelCanvas, vtkKWCanvas);
  vtkGetObjectMacro(ValueBoxCanvas, vtkKWCanvas);

  // Description:
  // Update the whole UI depending on the value of the Ivars
  virtual void Update();

  // Description:
  // Update the "enable" state of the object and its internal parts.
  // Depending on different Ivars (this->Enabled, the application's 
  // Limited Edition Mode, etc.), the "enable" state of the object is updated
  // and propagated to its internal parts/subwidgets. This will, for example,
  // enable/disable parts of the widget UI, enable/disable the visibility
  // of 3D widgets, etc.
  virtual void UpdateEnableState();

  // Description:
  // Callbacks. Internal, do not use.
  virtual void HueSatPickCallback(int x, int y);
  virtual void HueSatMoveCallback(int x, int y);
  virtual void HueSatReleaseCallback();
  virtual void ValuePickCallback(int x, int y);
  virtual void ValueMoveCallback(int x, int y);
  virtual void ValueReleaseCallback();

protected:
  vtkKWHSVColorSelector();
  ~vtkKWHSVColorSelector();

  // Description:
  // Create the widget.
  virtual void CreateWidget();

  int    HueSatWheelRadius;
  int    HueSatCursorRadius;
  int    ValueBoxWidth;
  int    ValueCursorMargin;
  int    Selected;
  double SelectedColor[3];
  int    ModificationOnly;
  int    HideValue;
  double PreviouslySelectedColor[3];

  // Commands

  char *SelectionChangedCommand;
  char *SelectionChangingCommand;

  int InvokeCommandsWithRGB;
  virtual void InvokeCommandWithColor(
    const char *command, double h, double s, double v);
  virtual void InvokeSelectionChangedCommand(double h, double s, double v);
  virtual void InvokeSelectionChangingCommand(double h, double s, double v);

  // GUI

  vtkKWCanvas *HueSatWheelCanvas;
  vtkKWCanvas *ValueBoxCanvas;
  vtkKWLabel  *HueSatLabel;
  vtkKWLabel  *ValueLabel;

  // Description:
  // Bind/Unbind all components.
  virtual void Bind();
  virtual void UnBind();

  // Description:
  // Pack the widget
  virtual void Pack();

  // Description:
  // Redraw or update canvas elements
  virtual void Redraw();
  virtual void RedrawHueSatWheelCanvas();
  virtual void UpdateHueSatWheelImage();
  virtual void UpdateHueSatWheelSelection();
  virtual void RedrawValueBoxCanvas();
  virtual void UpdateValueBoxImage();
  virtual void UpdateValueBoxSelection();

  // Description:
  // Get Hue/Sat given coordinates in Hue/Sat wheel image
  // Return 1 if OK, 0 if coords were out of the wheel (i.e. sat was > 1.0)
  virtual int GetHueSatFromCoordinates(int x, int y, double &hue, double &sat);

  // Description:
  // Get Value given coordinates in Value image
  virtual void GetValueFromCoordinate(int y, double &value);

private:
  vtkKWHSVColorSelector(const vtkKWHSVColorSelector&); // Not implemented
  void operator=(const vtkKWHSVColorSelector&); // Not implemented
};

#endif