KWWidgets
|
00001 /*========================================================================= 00002 00003 Module: $RCSfile: vtkKWHSVColorSelector.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 vtkKWHSVColorSelector - an HSV color selector 00015 // .SECTION Description 00016 // A widget that allows the user choose a HSV color interactively 00017 00018 #ifndef __vtkKWHSVColorSelector_h 00019 #define __vtkKWHSVColorSelector_h 00020 00021 #include "vtkKWCompositeWidget.h" 00022 00023 class vtkKWCanvas; 00024 class vtkKWLabel; 00025 00026 class KWWidgets_EXPORT vtkKWHSVColorSelector : public vtkKWCompositeWidget 00027 { 00028 public: 00029 static vtkKWHSVColorSelector* New(); 00030 vtkTypeRevisionMacro(vtkKWHSVColorSelector,vtkKWCompositeWidget); 00031 void PrintSelf(ostream& os, vtkIndent indent); 00032 00033 // Description: 00034 // Set/Get the hue/saturation wheel radius in pixels. 00035 virtual void SetHueSatWheelRadius(int); 00036 vtkGetMacro(HueSatWheelRadius, int); 00037 00038 // Description: 00039 // Set/Get the value box width in pixels. 00040 virtual void SetValueBoxWidth(int); 00041 vtkGetMacro(ValueBoxWidth, int); 00042 00043 // Description: 00044 // Set/Get the radius of the selection cursor in the hue/sat wheel in pixels. 00045 virtual void SetHueSatCursorRadius(int); 00046 vtkGetMacro(HueSatCursorRadius, int); 00047 00048 // Description: 00049 // Set/Get the horizontal outer margin of the selection cursor in the value 00050 // box in pixels. 00051 virtual void SetValueCursorMargin(int); 00052 vtkGetMacro(ValueCursorMargin, int); 00053 00054 // Description: 00055 // Select/Deselect a color (in HSV space) 00056 vtkGetVector3Macro(SelectedColor, double); 00057 virtual void SetSelectedColor(double h, double s, double v); 00058 virtual void SetSelectedColor(double hsv[3]) 00059 { this->SetSelectedColor(hsv[0], hsv[1], hsv[2]); }; 00060 virtual void ClearSelection(); 00061 virtual int HasSelection(); 00062 00063 // Description: 00064 // User can only modify the selection, it can not create a selection (i.e. 00065 // pick a color) when nothing has been selected yet. 00066 vtkSetMacro(ModificationOnly, int); 00067 vtkGetMacro(ModificationOnly, int); 00068 vtkBooleanMacro(ModificationOnly, int); 00069 00070 // Description: 00071 // Hide the Value UI. 00072 virtual void SetHideValue(int); 00073 vtkGetMacro(HideValue, int); 00074 vtkBooleanMacro(HideValue, int); 00075 00076 // Description: 00077 // Specifies commands to associate with the widget. 00078 // 'SelectionChangedCommand' is invoked when the selected color has 00079 // changed (i.e. at the end of the user interaction). 00080 // 'SelectionChangingCommand' is invoked when the selected color is 00081 // changing (i.e. during the user interaction). 00082 // The need for a '...ChangedCommand' and '...ChangingCommand' can be 00083 // explained as follows: the former can be used to be notified about any 00084 // changes made to this widget *after* the corresponding user interaction has 00085 // been performed (say, after releasing the mouse button that was dragging 00086 // a slider, or after clicking on a checkbutton). The later can be set 00087 // *additionally* to be notified about the intermediate changes that 00088 // occur *during* the corresponding user interaction (say, *while* dragging 00089 // a slider). While setting '...ChangedCommand' is enough to be notified 00090 // about any changes, setting '...ChangingCommand' is an application-specific 00091 // choice that is likely to depend on how fast you want (or can) answer to 00092 // rapid changes occuring during a user interaction, if any. 00093 // The 'object' argument is the object that will have the method called on 00094 // it. The 'method' argument is the name of the method to be called and any 00095 // arguments in string form. If the object is NULL, the method is still 00096 // evaluated as a simple command. 00097 // The following parameters are also passed to the command: 00098 // - selected HSV color: double, double, double 00099 // Note that if InvokeCommandsWithRGB is true, the selected color is passed 00100 // as RGB instead of HSV. 00101 virtual void SetSelectionChangedCommand( 00102 vtkObject *object, const char *method); 00103 virtual void SetSelectionChangingCommand( 00104 vtkObject *object, const char *method); 00105 00106 // Description: 00107 // Set/Get if the commands should be invoked with RGB parameters instead 00108 // of the current HSV value. 00109 vtkSetMacro(InvokeCommandsWithRGB, int); 00110 vtkGetMacro(InvokeCommandsWithRGB, int); 00111 vtkBooleanMacro(InvokeCommandsWithRGB, int); 00112 00113 // Description: 00114 // Set the string that enables balloon help for this widget. 00115 // Override to pass down to children. 00116 virtual void SetBalloonHelpString(const char *str); 00117 00118 // Description: 00119 // Access to the canvas and internal elements 00120 vtkGetObjectMacro(HueSatWheelCanvas, vtkKWCanvas); 00121 vtkGetObjectMacro(ValueBoxCanvas, vtkKWCanvas); 00122 00123 // Description: 00124 // Update the whole UI depending on the value of the Ivars 00125 virtual void Update(); 00126 00127 // Description: 00128 // Update the "enable" state of the object and its internal parts. 00129 // Depending on different Ivars (this->Enabled, the application's 00130 // Limited Edition Mode, etc.), the "enable" state of the object is updated 00131 // and propagated to its internal parts/subwidgets. This will, for example, 00132 // enable/disable parts of the widget UI, enable/disable the visibility 00133 // of 3D widgets, etc. 00134 virtual void UpdateEnableState(); 00135 00136 // Description: 00137 // Callbacks. Internal, do not use. 00138 virtual void HueSatPickCallback(int x, int y); 00139 virtual void HueSatMoveCallback(int x, int y); 00140 virtual void HueSatReleaseCallback(); 00141 virtual void ValuePickCallback(int x, int y); 00142 virtual void ValueMoveCallback(int x, int y); 00143 virtual void ValueReleaseCallback(); 00144 00145 protected: 00146 vtkKWHSVColorSelector(); 00147 ~vtkKWHSVColorSelector(); 00148 00149 // Description: 00150 // Create the widget. 00151 virtual void CreateWidget(); 00152 00153 int HueSatWheelRadius; 00154 int HueSatCursorRadius; 00155 int ValueBoxWidth; 00156 int ValueCursorMargin; 00157 int Selected; 00158 double SelectedColor[3]; 00159 int ModificationOnly; 00160 int HideValue; 00161 double PreviouslySelectedColor[3]; 00162 00163 // Commands 00164 00165 char *SelectionChangedCommand; 00166 char *SelectionChangingCommand; 00167 00168 int InvokeCommandsWithRGB; 00169 virtual void InvokeCommandWithColor( 00170 const char *command, double h, double s, double v); 00171 virtual void InvokeSelectionChangedCommand(double h, double s, double v); 00172 virtual void InvokeSelectionChangingCommand(double h, double s, double v); 00173 00174 // GUI 00175 00176 vtkKWCanvas *HueSatWheelCanvas; 00177 vtkKWCanvas *ValueBoxCanvas; 00178 vtkKWLabel *HueSatLabel; 00179 vtkKWLabel *ValueLabel; 00180 00181 // Description: 00182 // Bind/Unbind all components. 00183 virtual void Bind(); 00184 virtual void UnBind(); 00185 00186 // Description: 00187 // Pack the widget 00188 virtual void Pack(); 00189 00190 // Description: 00191 // Redraw or update canvas elements 00192 virtual void Redraw(); 00193 virtual void RedrawHueSatWheelCanvas(); 00194 virtual void UpdateHueSatWheelImage(); 00195 virtual void UpdateHueSatWheelSelection(); 00196 virtual void RedrawValueBoxCanvas(); 00197 virtual void UpdateValueBoxImage(); 00198 virtual void UpdateValueBoxSelection(); 00199 00200 // Description: 00201 // Get Hue/Sat given coordinates in Hue/Sat wheel image 00202 // Return 1 if OK, 0 if coords were out of the wheel (i.e. sat was > 1.0) 00203 virtual int GetHueSatFromCoordinates(int x, int y, double &hue, double &sat); 00204 00205 // Description: 00206 // Get Value given coordinates in Value image 00207 virtual void GetValueFromCoordinate(int y, double &value); 00208 00209 private: 00210 vtkKWHSVColorSelector(const vtkKWHSVColorSelector&); // Not implemented 00211 void operator=(const vtkKWHSVColorSelector&); // Not implemented 00212 }; 00213 00214 #endif 00215