KWWidgets
debian/tmp/usr/include/KWWidgets/vtkKWColorPresetSelector.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3 Copyright (c) 1998-2003 Kitware Inc. 469 Clifton Corporate Parkway,
4 Clifton Park, NY, 12065, USA.
5 
6 All rights reserved. No part of this software may be reproduced, distributed,
7 or modified, in any form or by any means, without permission in writing from
8 Kitware Inc.
9 
10 IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR
11 DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
12 OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF,
13 EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14 
15 THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
16 BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
17 PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN
18 "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
19 MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
20 
21 =========================================================================*/
22 // .NAME vtkKWColorPresetSelector - a color preset selector.
23 // .SECTION Description
24 // This class is a widget that can be used to store color presets.
25 // For example, a list of favorite colors, or a list of "recently picked"
26 // colors.
27 // It is used internally by the vtkKWColorPickerWidget class.
28 // .SECTION Thanks
29 // This work is part of the National Alliance for Medical Image
30 // Computing (NAMIC), funded by the National Institutes of Health
31 // through the NIH Roadmap for Medical Research, Grant U54 EB005149.
32 // Information on the National Centers for Biomedical Computing
33 // can be obtained from http://nihroadmap.nih.gov/bioinformatics.
34 // .SECTION See Also
35 // vtkKWColorPickerWidget vtkKWColorSpectrumWidget vtkKWPresetSelector
36 
37 #ifndef __vtkKWColorPresetSelector_h
38 #define __vtkKWColorPresetSelector_h
39 
40 #include "vtkKWPresetSelector.h"
41 
43 {
44 public:
45  static vtkKWColorPresetSelector* New();
47  void PrintSelf(ostream& os, vtkIndent indent);
48 
49  // Description:
50  // Set/Get the color for a given preset.
51  // A method is available to retrieve the Id of the preset that has
52  // been assigned a specific color.
53  // Return 1 on success, 0 on error (id on success, -1 otherwise)
54  virtual void GetPresetColorAsRGB(int id, double &r, double &g, double &b);
55  virtual void GetPresetColorAsRGB(int id, double rgb[3]);
56  virtual int SetPresetColorAsRGB(int id, double r, double g, double b);
57  virtual int SetPresetColorAsRGB(int id, double rgb[3]);
58  virtual void GetPresetColorAsHSV(int id, double &h, double &s, double &v);
59  virtual void GetPresetColorAsHSV(int id, double hsv[3]);
60  virtual int SetPresetColorAsHSV(int id, double h, double s, double v);
61  virtual int SetPresetColorAsHSV(int id, double hsv[3]);
62  virtual int GetIdOfPresetWithColorAsRGB(double r, double g, double b);
63  virtual int GetIdOfPresetWithColorAsRGB(double rgb[3]);
64 
65  // Description:
66  // Set/Get the preset comment to the hexadecimal RGB representation
67  // Return 1 on success, 0 otherwise
68  virtual int SetPresetCommentAsHexadecimalRGB(int id);
69  virtual int GetPresetCommentAsHexadecimalRGB(int id, int &r, int &g, int &b);
70  virtual int HasPresetCommentAsHexadecimalRGB(int id);
71 
72  // Description:
73  // Add a few default color presets (black, white, primary colors).
74  virtual void AddDefaultColorPresets();
75 
76  // Description:
77  // Remove all duplicated colors from the list.
78  // Return the number of duplicates removed.
79  virtual int RemoveDuplicatedColors();
80 
81  // Description:
82  // Set/Get if the color cell (i.e. the cell representing the color
83  // for each preset entry) is drawn as a color button (i.e. a square frame
84  // with a background color set to the preset color, a black outline, and
85  // some margin so that it doesn't touch the row separators) or if the whole
86  // cell background color is used to represent the color. The former option
87  // looks nicer, but is a tad slower to display: while it takes about the
88  // same amount of time to insert a lot of entries (about 1200 entries per
89  // second), displaying them is a little slower when this option is On (about
90  // 285 vs. 400 entries per second).
91  // Note: set this option before inserting any entries; for performance
92  // reasons, switching from one to the other interactively is not supported.
93  virtual void SetDrawColorCellAsColorButton(int);
94  vtkGetMacro(DrawColorCellAsColorButton,int);
95  vtkBooleanMacro(DrawColorCellAsColorButton,int);
96 
97  // Description:
98  // Set/Get the registry key under which presets will be saved and/or
99  // restored automatically. Note that presets are saved automatically only
100  // when performing *user-interactions* (add/remove/update/edit).
101  // For performance reason, adding/removing/changing a preset
102  // programatically will not save the presets to the registry; it is up
103  // to the user to call SavePresetsToRegistry() manually.
104  // IMPORTANT: make sure this variable is set before calling Create().
105  // This goes as well for composite widgets that embed an instance of this
106  // class. The vtkKWColorPickerWidget class, for example, uses two
107  // color preset selectors: make sure to set their RegistryKey (if needed)
108  // *before* calling the Create() method on the vtkKWColorPickerWidget
109  // instance.
110  vtkSetStringMacro(RegistryKey);
111  vtkGetStringMacro(RegistryKey);
112 
113  // Description:
114  // Save/Restore colors to/from registry, using the RegistryKey ivar as key.
115  // Note that presets are saved automatically when performing
116  // *user-interactions* (see RegistryKey)
117  virtual void SavePresetsToRegistry();
118  virtual void RestorePresetsFromRegistry();
119 
120  // Description:
121  // Some constants
122  //BTX
123  static const char *ColorColumnName;
124  //ETX
125 
126 protected:
129 
130  // Description:
131  // Create the widget.
132  virtual void CreateWidget();
133 
134  // Description:
135  // Create the columns.
136  // Subclasses should override this method to add their own columns and
137  // display their own preset fields (do not forget to call the superclass
138  // first).
139  virtual void CreateColumns();
140 
141  // Description:
142  // Update the preset row, i.e. add a row for that preset if it is not
143  // displayed already, hide it if it does not match GroupFilter, and
144  // update the table columns with the corresponding preset fields.
145  // Subclass should override this method to display their own fields.
146  // Return 1 on success, 0 if the row was not (or can not be) updated.
147  // Subclasses should call the parent's UpdatePresetRow, and abort
148  // if the result is not 1.
149  virtual int UpdatePresetRow(int id);
150 
151  // Description:
152  // Convenience methods to get the index of a given column
153  virtual int GetColorColumnIndex();
154 
156  char *RegistryKey;
157 
158  virtual int InvokePresetAddCommand();
159  virtual void InvokePresetRemovedCommand();
160  virtual void InvokePresetUpdateCommand(int id);
161  virtual void InvokePresetHasChangedCommand(int id);
162 
163  static int CompareRGBColors(double rgb1[3], double rgb2[3]);
164  static int CompareRGBColors(double r1, double g1, double b1,
165  double r2, double g2, double b2);
166 
167 private:
168 
169  vtkKWColorPresetSelector(const vtkKWColorPresetSelector&); // Not implemented
170  void operator=(const vtkKWColorPresetSelector&); // Not implemented
171 };
172 
173 #endif