KWWidgets
vtkKWIcon.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Module: $RCSfile: vtkKWIcon.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 vtkKWIcon - simple wrapper for icons
15 // .SECTION Description
16 // A simple icon wrapper. It can either be used with file KWIcons.h to
17 // provide a unified interface for internal icons or a wrapper for
18 // custom icons. The icons are defined with width, height, pixel_size,
19 // and array of unsigned char values.
20 
21 #ifndef __vtkKWIcon_h
22 #define __vtkKWIcon_h
23 
24 #include "vtkObject.h"
25 #include "vtkKWWidgets.h" // Needed for export symbols directives
26 
27 class vtkColorTransferFunction;
28 class vtkImageData;
29 
30 class KWWidgets_EXPORT vtkKWIcon : public vtkObject
31 {
32 public:
33  static vtkKWIcon* New();
34  vtkTypeRevisionMacro(vtkKWIcon,vtkObject);
35  void PrintSelf(ostream& os, vtkIndent indent);
36  void DeepCopy(vtkKWIcon *p);
37 
38  //BTX
39  // Description:
40  // Predefined icons.
41  enum {
42  IconAngleTool = 14,
43  IconBiDimensionalTool = 34,
44  IconBoundingBox = 13,
45  IconBrowserBack = 71,
46  IconBrowserForward = 72,
47  IconBrowserUp = 70,
48  IconBugMini = 200,
49  IconCalculator = 79,
50  IconCamera = 19,
51  IconCameraMini = 175,
52  IconCdRom = 75,
53  IconColorAlphaSquares = 216,
54  IconColorBarAnnotation = 12,
55  IconColorSquares = 18,
56  IconColumns = 220,
57  IconCompress = 211,
58  IconConnection = 1,
59  IconContourSegment = 33,
60  IconContourTool = 16,
61  IconContrast = 212,
62  IconCornerAnnotation = 11,
63  IconCropTool = 22,
64  IconDistanceTool = 15,
65  IconDocument = 9,
66  IconDocumentRGBColor = 209,
67  IconDocumentVolumeProperty = 177,
68  IconDocumentWindowLevel = 176,
69  IconEditContrast = 225,
70  IconEditVolumeProperties = 226,
71  IconEmpty16x16 = 6,
72  IconEmpty1x1 = 10,
73  IconError = 2,
74  IconErrorMini = 3,
75  IconErrorRedMini = 4,
76  IconExpand = 5,
77  IconExpandLeftMini = 180,
78  IconExpandMini = 23,
79  IconExpandRightMini = 178,
80  IconExpandUpMini = 179,
81  IconEye = 17,
82  IconFavorites = 67,
83  IconFileDelete = 73,
84  IconFileOpen = 8,
85  IconFloppy = 7,
86  IconFloppyDrive = 77,
87  IconFolder = 20,
88  IconFolder32 = 65,
89  IconFolderNew = 74,
90  IconFolderOpen = 21,
91  IconFolderXP = 66,
92  IconGrayscaleSquares = 218,
93  IconGridLinear = 40,
94  IconGridLog = 41,
95  IconHSVDiagram = 207,
96  IconHardDrive = 76,
97  IconHeaderAnnotation = 50,
98  IconHelpBubble = 60,
99  IconInfoMini = 61,
100  IconInterpolationBilinear = 215,
101  IconInterpolationNearest = 217,
102  IconLock = 62,
103  IconMagGlass = 63,
104  IconMinus = 64,
105  IconMove = 80,
106  IconMoveH = 81,
107  IconMoveV = 82,
108  IconNetDrive = 78,
109  IconNoIcon = 0,
110  IconObliqueProbe = 133,
111  IconOrientationCubeAnnotation = 83,
112  IconPanHand = 84,
113  IconParallelProjection = 213,
114  IconPerspectiveProjection = 214,
115  IconPlus = 100,
116  IconPointFinger = 90,
117  IconPresetAdd = 94,
118  IconPresetApply = 95,
119  IconPresetDelete = 96,
120  IconPresetEmail = 97,
121  IconPresetFilter = 237,
122  IconPresetLoad = 210,
123  IconPresetLocate = 98,
124  IconPresetNext = 173,
125  IconPresetPrevious = 174,
126  IconPresetRewind = 238,
127  IconPresetUpdate = 99,
128  IconQuestion = 101,
129  IconReload = 102,
130  IconResetCamera = 222,
131  IconResetContrast = 223,
132  IconRotate = 105,
133  IconRows = 219,
134  IconScaleBarAnnotation = 106,
135  IconSeedTool = 107,
136  IconShrink = 103,
137  IconSideAnnotation = 110,
138  IconSmallCounterBlue1 = 227,
139  IconSmallCounterBlue2 = 228,
140  IconSmallCounterBlue3 = 229,
141  IconSmallCounterBlue4 = 230,
142  IconSmallCounterBlue5 = 231,
143  IconSmallCounterBlue6 = 232,
144  IconSmallCounterBlue7 = 233,
145  IconSmallCounterBlue8 = 234,
146  IconSmallCounterBlue9 = 235,
147  IconSmallCounterBlue9Plus = 236,
148  IconSpinDown = 111,
149  IconSpinLeft = 112,
150  IconSpinRight = 113,
151  IconSpinUp = 114,
152  IconStandardView = 224,
153  IconStopwatch = 104,
154  IconTestTube = 190,
155  IconTime = 208,
156  IconTransportBeginning = 120,
157  IconTransportEnd = 121,
158  IconTransportFastForward = 122,
159  IconTransportFastForwardToKey = 123,
160  IconTransportLoop = 124,
161  IconTransportPause = 125,
162  IconTransportPlay = 126,
163  IconTransportPlayBackward = 201,
164  IconTransportPlayToKey = 127,
165  IconTransportRewind = 128,
166  IconTransportRewindToKey = 129,
167  IconTransportStop = 130,
168  IconTrashcan = 131,
169  IconTreeClose = 150,
170  IconTreeOpen = 151,
171  IconWarning = 170,
172  IconWarningMini = 171,
173  IconWindowLevel = 172,
174 
175  IconNuvola16x16ActionsColorPicker = 1022,
176  IconNuvola16x16ActionsConfigure = 1000,
177  IconNuvola16x16ActionsDecrypted = 1001,
178  IconNuvola16x16ActionsEditCopy = 1023,
179  IconNuvola16x16ActionsEditCut = 1024,
180  IconNuvola16x16ActionsEditPaste = 1025,
181  IconNuvola16x16ActionsEncrypted = 1019,
182  IconNuvola16x16ActionsExit = 1002,
183  IconNuvola16x16ActionsFileClose = 1003,
184  IconNuvola16x16ActionsFileOpen = 1004,
185  IconNuvola16x16ActionsFilePrint = 1005,
186  IconNuvola16x16ActionsFileSave = 1006,
187  IconNuvola16x16ActionsHelp = 1007,
188  IconNuvola16x16ActionsHistory = 1026,
189  IconNuvola16x16ActionsKAlarm = 1027,
190  IconNuvola16x16ActionsLedBlue = 1031,
191  IconNuvola16x16ActionsLedGreen = 1032,
192  IconNuvola16x16ActionsLedLightBlue = 1033,
193  IconNuvola16x16ActionsLedLightGreen = 1034,
194  IconNuvola16x16ActionsLedOrange = 1035,
195  IconNuvola16x16ActionsLedPurple = 1036,
196  IconNuvola16x16ActionsLedRed = 1037,
197  IconNuvola16x16ActionsLedYellow = 1038,
198  IconNuvola16x16ActionsMailGeneric = 1008,
199  IconNuvola16x16ActionsMessage = 1009,
200  IconNuvola16x16ActionsMessageBoxCritical = 1010,
201  IconNuvola16x16ActionsMessageBoxInfo = 1011,
202  IconNuvola16x16ActionsMessageBoxWarning = 1012,
203  IconNuvola16x16ActionsNo = 1013,
204  IconNuvola16x16ActionsRotate = 1014,
205  IconNuvola16x16ActionsStop = 1015,
206  IconNuvola16x16ActionsThumbnail = 1016,
207  IconNuvola16x16ActionsViewBottom = 1018,
208  IconNuvola16x16ActionsViewFullScreen = 1020,
209  IconNuvola16x16ActionsViewLeftRight = 1028,
210  IconNuvola16x16ActionsViewMag = 1017,
211  IconNuvola16x16ActionsViewRight = 1021,
212  IconNuvola16x16ActionsViewTopBottom = 1029,
213  IconNuvola16x16ActionsWindowNew = 1030,
214  IconNuvola16x16AppsArk = 1300,
215  IconNuvola16x16AppsBug = 1301,
216  IconNuvola16x16AppsEmail = 1302,
217  IconNuvola16x16AppsError = 1303,
218  IconNuvola16x16AppsKeyboard = 1304,
219  IconNuvola16x16AppsKTimer = 1305,
220  IconNuvola16x16DevicesCamera = 1600,
221  IconNuvola16x16FilesystemsFolderInbox = 1903,
222  IconNuvola16x16FilesystemsFolderOutbox = 1904,
223  IconNuvola16x16FilesystemsTrashcanEmpty = 1901,
224  IconNuvola16x16FilesystemsTrashcanFull = 1902,
225 
226  IconNuvola22x22ActionsHelp = 3000,
227  IconNuvola22x22ActionsMessageBoxInfo = 3001,
228  IconNuvola22x22ActionsMisc = 3002,
229  IconNuvola22x22ActionsWizard = 3003,
230  IconNuvola22x22AppsDesigner = 3300,
231  IconNuvola22x22DevicesCamera = 3600,
232  IconNuvola22x22FilesystemsFolderBlue = 3900,
233 
234  IconNuvola48x48ActionsMessageBoxCritical = 5001,
235  IconNuvola48x48ActionsMessageBoxInfo = 5002,
236  IconNuvola48x48ActionsMessageBoxWarning = 5003,
237  IconNuvola48x48ActionsHelp = 5004,
238  IconNuvola48x48ActionsHistory = 5000,
239  IconNuvola48x48AppsDownloadManager = 5300,
240  IconNuvola48x48DevicesMouse = 5600,
241  IconNuvola48x48FilesystemsFolderBlue = 5900,
242 
243  IconCrystalProject16x16Actions14LayerDeletelayer = 10000,
244  IconCrystalProject16x16Actions14LayerNovisible = 10001,
245  IconCrystalProject16x16Actions14LayerVisible = 10002,
246  IconCrystalProject16x16ActionsJabberOnline = 10003,
247  IconCrystalProject16x16ActionsRotate = 10004,
248  IconCrystalProject16x16AppsCookie = 10300,
249  IconCrystalProject16x16AppsTutorials = 10301,
250 
251  IconSilkAccept = 20044,
252  IconSilkAdd = 20045,
253  IconSilkApplicationXpTerminal = 20000,
254  IconSilkArrowRefresh = 20001,
255  IconSilkAttach = 20002,
256  IconSilkBinClosed = 20003,
257  IconSilkBug = 20004,
258  IconSilkBulletToggleMinus = 20056,
259  IconSilkBulletTogglePlus = 20057, //
260  IconSilkCamera = 20005,
261  IconSilkCancel = 20046,
262  IconSilkChartCurve = 20006,
263  IconSilkChartLine = 20007,
264  IconSilkChartOrganisation = 20008,
265  IconSilkChartPie = 20009,
266  IconSilkClock = 20010,
267  IconSilkCog = 20011,
268  IconSilkColorSwatch = 20012,
269  IconSilkColorWheel = 20013,
270  IconSilkCompress = 20014,
271  IconSilkCross = 20047,
272  IconSilkCut = 20048,
273  IconSilkDate = 20015,
274  IconSilkDelete = 20049,
275  IconSilkDisk = 20016,
276  IconSilkDoorIn = 20017,
277  IconSilkDoorOut = 20018,
278  IconSilkEmail = 20019,
279  IconSilkExclamation = 20020,
280  IconSilkEye = 20021,
281  IconSilkFilm = 20022,
282  IconSilkHelp = 20023,
283  IconSilkHourglass = 20024,
284  IconSilkInformation = 20025,
285  IconSilkKey = 20026,
286  IconSilkLink = 20027,
287  IconSilkLock = 20028,
288  IconSilkMagnifier = 20029,
289  IconSilkPaintCan = 20031,
290  IconSilkPaintbrush = 20030,
291  IconSilkPastePlain = 20050,
292  IconSilkPill = 20032,
293  IconSilkPlugin = 20033,
294  IconSilkStar = 20034,
295  IconSilkStop = 20035,
296  IconSilkTelephone = 20051,
297  IconSilkTextAllCaps = 20052,
298  IconSilkTextBold = 20053,
299  IconSilkTextItalic = 20054,
300  IconSilkTextUnderline = 20055,
301  IconSilkThumbDown = 20036,
302  IconSilkThumbUp = 20037,
303  IconSilkTick = 20038,
304  IconSilkTime = 20039,
305  IconSilkWrench = 20040,
306  IconSilkZoom = 20041,
307  IconSilkZoomIn = 20042,
308  IconSilkZoomOut = 20043,
309 
310  LastIcon
311  };
312  //ETX
313 
314  // Description:
315  // Set the icon image based on a predefined icon.
316  virtual void SetImage(int predefined_icon_index);
317 
318  // Description:
319  // Set the icon image based on an existing vtkKWIcon.
320  virtual void SetImage(vtkKWIcon*);
321 
322  // Description:
323  // Set the icon image based on an existing vtkImageData.
324  // A XZ, YZ slice will be permuted into a XY slice automatically.
325  virtual void SetImage(vtkImageData*);
326 
327  // Description:
328  // Set the icon image from pixel data, eventually zlib and base64.
329  // If 'buffer_length' is 0, compute it automatically by multiplying
330  // 'pixel_size', 'width' and 'height' together.
331  // If ImageOptionFlipVertical is set in 'option', flip the image vertically
332  //BTX
333  enum
334  {
335  ImageOptionFlipVertical = 1
336  };
337  //ETX
338  void SetImage(const unsigned char* data,
339  int width, int height,
340  int pixel_size,
341  unsigned long buffer_length = 0,
342  int options = 0);
343 
344  // Description:
345  // Set the icon image to a color transfer function gradient, or a 2-colors
346  // gradients, or a single color. Borders can be added automatically.
347  // Return 1 on success, 0 otherwise
348  //BTX
349  enum
350  {
351  ImageOptionDrawBorder = 1,
352  ImageOptionDrawDoubleBorder = 2,
353  ImageOptionDrawVertically = 4
354  };
355  //ETX
356  virtual int SetImageToGradient(vtkColorTransferFunction *ctf,
357  int width, int height,
358  int options = 0);
359  virtual int SetImageToRGBGradient(double r1, double g1, double b1,
360  double r2, double g2, double b2,
361  int width, int height,
362  int options = 0);
363  virtual int SetImageToSolidRGBColor(double r, double g, double b,
364  int width, int height,
365  int options = 0);
366 
367  // Description:
368  // Get the raw image data.
369  virtual const unsigned char* GetData();
370 
371  // Description:
372  // Get the width of the image.
373  vtkGetMacro(Width, int);
374 
375  // Description:
376  // Get the height of the image.
377  vtkGetMacro(Height, int);
378 
379  // Description:
380  // Get the pixel size of the image.
381  vtkGetMacro(PixelSize, int);
382 
383  // Description:
384  // Fade the icon by a factor.
385  // If the icon has an alpha channel, this multiplies each element in
386  // the alpha channel by 'factor'.
387  virtual void Fade(double factor);
388 
389  // Description:
390  // Change the hue to a new hue.
391  virtual void SetHue(double hue);
392 
393  // Description:
394  // Flatten the image against a color.
395  // If the icon has an alpha channel, this blends the image against
396  // a 'r', 'g', 'b' background and discards the alpha channel.
397  virtual void Flatten(double r, double g, double b);
398  virtual void Flatten(double rgb[3])
399  { this->Flatten(rgb[0], rgb[1], rgb[2]); };
400 
401  // Description:
402  // Compose an icon on top of this instance.
403  // Supports only same size RGBA against same size RGBA at the moment.
404  // Return 1 on success, 0 otherwise
405  virtual int Compose(vtkKWIcon *icon);
406  virtual int Compose(int icon_index);
407 
408  // Description:
409  // Trip the top or right portion of an icon (i.e. look for any fully
410  // transparent area and shift the icon to the top or right).
411  // Supports only RGBA at the moment.
412  // Return 1 on success, 0 otherwise
413  virtual int TrimTop();
414  virtual int TrimRight();
415 
416  // Description:
417  // Resize the canvas. The new canvas can be made larger, or smaller
418  // (thus cropping the current image). The position indicates where the
419  // original image should be placed in the new canvas.
420  // Supports pixel size 3 or 4, will create an output with pixel size = 4.
421  // Return 1 on success, 0 otherwise
422  //BTX
423  enum
424  {
425  PositionInCanvasCenter = 0,
426  PositionInCanvasNorthWest = 9,
427  PositionInCanvasNorth = 1,
428  PositionInCanvasNorthEast = 3,
429  PositionInCanvasEast = 2,
430  PositionInCanvasSouthEast = 6,
431  PositionInCanvasSouth = 4,
432  PositionInCanvasSouthWest = 12,
433  PositionInCanvasWest = 8
434  };
435  //ETX
436  virtual int ResizeCanvas(
437  int resized_width, int resized_height, int position);
438 
439  // Description:
440  // Resample the icon to a new size.
441  // If the new 'width' is 0, it will be computed from the new 'height' by
442  // keeping the aspect ratio of the icon (and vice-versa if height is 0).
443  // Return 1 on success, 0 otherwise
444  virtual int ResampleCanvas(int resampled_width, int resampled_height);
445 
446  // Description:
447  // Fit (and resample) the icon to a new size. The aspect ratio of the
448  // icon is kept so that the new icon is not larger in any dimension than
449  // the new size.
450  // Return 1 on success, 0 otherwise
451  virtual int FitCanvas(int fit_width, int fit_height);
452 
453 protected:
454  vtkKWIcon();
455  ~vtkKWIcon();
456 
457  // Description:
458  // Set icon to the custom data.
459  void SetData(const unsigned char* data,
460  int width, int height,
461  int pixel_size,
462  int options = 0);
463 
464  unsigned char* Data;
465  int Width;
466  int Height;
467  int PixelSize;
468 
469 private:
470  vtkKWIcon(const vtkKWIcon&); // Not implemented
471  void operator=(const vtkKWIcon&); // Not implemented
472 };
473 
474 #endif
475 
476 
477