KWWidgets
|
00001 /*========================================================================= 00002 00003 Copyright (c) 1998-2003 Kitware Inc. 469 Clifton Corporate Parkway, 00004 Clifton Park, NY, 12065, USA. 00005 00006 All rights reserved. No part of this software may be reproduced, distributed, 00007 or modified, in any form or by any means, without permission in writing from 00008 Kitware Inc. 00009 00010 IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR 00011 DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT 00012 OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF, 00013 EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00014 00015 THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING, 00016 BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 00017 PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN 00018 "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE 00019 MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 00020 00021 =========================================================================*/ 00022 // .NAME vtkKWColorPresetSelector - a color preset selector. 00023 // .SECTION Description 00024 // This class is a widget that can be used to store color presets. 00025 // For example, a list of favorite colors, or a list of "recently picked" 00026 // colors. 00027 // It is used internally by the vtkKWColorPickerWidget class. 00028 // .SECTION Thanks 00029 // This work is part of the National Alliance for Medical Image 00030 // Computing (NAMIC), funded by the National Institutes of Health 00031 // through the NIH Roadmap for Medical Research, Grant U54 EB005149. 00032 // Information on the National Centers for Biomedical Computing 00033 // can be obtained from http://nihroadmap.nih.gov/bioinformatics. 00034 // .SECTION See Also 00035 // vtkKWColorPickerWidget vtkKWColorSpectrumWidget vtkKWPresetSelector 00036 00037 #ifndef __vtkKWColorPresetSelector_h 00038 #define __vtkKWColorPresetSelector_h 00039 00040 #include "vtkKWPresetSelector.h" 00041 00042 class KWWidgets_EXPORT vtkKWColorPresetSelector : public vtkKWPresetSelector 00043 { 00044 public: 00045 static vtkKWColorPresetSelector* New(); 00046 vtkTypeRevisionMacro(vtkKWColorPresetSelector, vtkKWPresetSelector); 00047 void PrintSelf(ostream& os, vtkIndent indent); 00048 00049 // Description: 00050 // Set/Get the color for a given preset. 00051 // A method is available to retrieve the Id of the preset that has 00052 // been assigned a specific color. 00053 // Return 1 on success, 0 on error (id on success, -1 otherwise) 00054 virtual void GetPresetColorAsRGB(int id, double &r, double &g, double &b); 00055 virtual void GetPresetColorAsRGB(int id, double rgb[3]); 00056 virtual int SetPresetColorAsRGB(int id, double r, double g, double b); 00057 virtual int SetPresetColorAsRGB(int id, double rgb[3]); 00058 virtual void GetPresetColorAsHSV(int id, double &h, double &s, double &v); 00059 virtual void GetPresetColorAsHSV(int id, double hsv[3]); 00060 virtual int SetPresetColorAsHSV(int id, double h, double s, double v); 00061 virtual int SetPresetColorAsHSV(int id, double hsv[3]); 00062 virtual int GetIdOfPresetWithColorAsRGB(double r, double g, double b); 00063 virtual int GetIdOfPresetWithColorAsRGB(double rgb[3]); 00064 00065 // Description: 00066 // Set/Get the preset comment to the hexadecimal RGB representation 00067 // Return 1 on success, 0 otherwise 00068 virtual int SetPresetCommentAsHexadecimalRGB(int id); 00069 virtual int GetPresetCommentAsHexadecimalRGB(int id, int &r, int &g, int &b); 00070 virtual int HasPresetCommentAsHexadecimalRGB(int id); 00071 00072 // Description: 00073 // Add a few default color presets (black, white, primary colors). 00074 virtual void AddDefaultColorPresets(); 00075 00076 // Description: 00077 // Remove all duplicated colors from the list. 00078 // Return the number of duplicates removed. 00079 virtual int RemoveDuplicatedColors(); 00080 00081 // Description: 00082 // Set/Get if the color cell (i.e. the cell representing the color 00083 // for each preset entry) is drawn as a color button (i.e. a square frame 00084 // with a background color set to the preset color, a black outline, and 00085 // some margin so that it doesn't touch the row separators) or if the whole 00086 // cell background color is used to represent the color. The former option 00087 // looks nicer, but is a tad slower to display: while it takes about the 00088 // same amount of time to insert a lot of entries (about 1200 entries per 00089 // second), displaying them is a little slower when this option is On (about 00090 // 285 vs. 400 entries per second). 00091 // Note: set this option before inserting any entries; for performance 00092 // reasons, switching from one to the other interactively is not supported. 00093 virtual void SetDrawColorCellAsColorButton(int); 00094 vtkGetMacro(DrawColorCellAsColorButton,int); 00095 vtkBooleanMacro(DrawColorCellAsColorButton,int); 00096 00097 // Description: 00098 // Set/Get the registry key under which presets will be saved and/or 00099 // restored automatically. Note that presets are saved automatically only 00100 // when performing *user-interactions* (add/remove/update/edit). 00101 // For performance reason, adding/removing/changing a preset 00102 // programatically will not save the presets to the registry; it is up 00103 // to the user to call SavePresetsToRegistry() manually. 00104 // IMPORTANT: make sure this variable is set before calling Create(). 00105 // This goes as well for composite widgets that embed an instance of this 00106 // class. The vtkKWColorPickerWidget class, for example, uses two 00107 // color preset selectors: make sure to set their RegistryKey (if needed) 00108 // *before* calling the Create() method on the vtkKWColorPickerWidget 00109 // instance. 00110 vtkSetStringMacro(RegistryKey); 00111 vtkGetStringMacro(RegistryKey); 00112 00113 // Description: 00114 // Save/Restore colors to/from registry, using the RegistryKey ivar as key. 00115 // Note that presets are saved automatically when performing 00116 // *user-interactions* (see RegistryKey) 00117 virtual void SavePresetsToRegistry(); 00118 virtual void RestorePresetsFromRegistry(); 00119 00120 // Description: 00121 // Some constants 00122 //BTX 00123 static const char *ColorColumnName; 00124 //ETX 00125 00126 protected: 00127 vtkKWColorPresetSelector(); 00128 ~vtkKWColorPresetSelector(); 00129 00130 // Description: 00131 // Create the widget. 00132 virtual void CreateWidget(); 00133 00134 // Description: 00135 // Create the columns. 00136 // Subclasses should override this method to add their own columns and 00137 // display their own preset fields (do not forget to call the superclass 00138 // first). 00139 virtual void CreateColumns(); 00140 00141 // Description: 00142 // Update the preset row, i.e. add a row for that preset if it is not 00143 // displayed already, hide it if it does not match GroupFilter, and 00144 // update the table columns with the corresponding preset fields. 00145 // Subclass should override this method to display their own fields. 00146 // Return 1 on success, 0 if the row was not (or can not be) updated. 00147 // Subclasses should call the parent's UpdatePresetRow, and abort 00148 // if the result is not 1. 00149 virtual int UpdatePresetRow(int id); 00150 00151 // Description: 00152 // Convenience methods to get the index of a given column 00153 virtual int GetColorColumnIndex(); 00154 00155 int DrawColorCellAsColorButton; 00156 char *RegistryKey; 00157 00158 virtual int InvokePresetAddCommand(); 00159 virtual void InvokePresetRemovedCommand(); 00160 virtual void InvokePresetUpdateCommand(int id); 00161 virtual void InvokePresetHasChangedCommand(int id); 00162 00163 static int CompareRGBColors(double rgb1[3], double rgb2[3]); 00164 static int CompareRGBColors(double r1, double g1, double b1, 00165 double r2, double g2, double b2); 00166 00167 private: 00168 00169 vtkKWColorPresetSelector(const vtkKWColorPresetSelector&); // Not implemented 00170 void operator=(const vtkKWColorPresetSelector&); // Not implemented 00171 }; 00172 00173 #endif