Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TGColorDialog.h
Go to the documentation of this file.
1 // @(#)root/gui:$Id$
2 // Author: Bertrand Bellenot + Fons Rademakers 22/08/02
3 // Author: Ilka Antcheva (color wheel support) 16/03/07
4 
5 /*************************************************************************
6  * Copyright (C) 1995-2002, Rene Brun and Fons Rademakers. *
7  * All rights reserved. *
8  * *
9  * For the licensing terms see $ROOTSYS/LICENSE. *
10  * For the list of contributors see $ROOTSYS/README/CREDITS. *
11  *************************************************************************/
12 
13 #ifndef ROOT_TGColorDialog
14 #define ROOT_TGColorDialog
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TGColorPalette, TGColorPick and TGColorDialog. //
19 // //
20 // The TGColorPalette is a widget showing an matrix of color cells. The //
21 // colors can be set and selected. //
22 // //
23 // The TGColorPick is a widget which allows a color to be picked from //
24 // HLS space. It consists of two elements: a color map window from //
25 // where the user can select the hue and saturation level of a color, //
26 // and a slider to select color's lightness. //
27 // //
28 // Selecting a color in these two widgets will generate the event: //
29 // kC_COLORSEL, kCOL_CLICK, widget id, 0. //
30 // and the signal: //
31 // ColorSelected(Pixel_t color) //
32 // //
33 // The TGColorDialog presents a full featured color selection dialog. //
34 // It uses 2 TGColorPalette's and the TGColorPick widgets. //
35 // //
36 //////////////////////////////////////////////////////////////////////////
37 
38 #include "TGFrame.h"
39 #include "TGWidget.h"
40 #include "TColor.h"
41 
42 
43 class TGTextEntry;
44 class TGTextBuffer;
45 class TGTab;
46 class TRootEmbeddedCanvas;
47 class TColorWheel;
48 class TGLabel;
49 class TGTextButton;
50 
51 //----------------------------------------------------------------------
52 
53 class TGColorPalette : public TGFrame, public TGWidget {
54 
55 private:
56 
57  TGColorPalette(const TGColorPalette&); // Not implemented
58  TGColorPalette& operator=(const TGColorPalette&); // Not implemented
59 
60 protected:
61  Int_t fCx; // x coordinate of currently selected color cell
62  Int_t fCy; // y coordinate of currently selected color cell
63  UInt_t fCw; // color cell width
64  UInt_t fCh; // color cell height
65  Int_t fRows; // number of color cell rows
66  Int_t fCols; // number of color cell columns
67  Pixel_t *fPixels; // pixel value of colors
68  TGGC fDrawGC; // graphics context used for drawing
69 
70  virtual void DoRedraw();
71  virtual void GotFocus();
72  virtual void LostFocus();
73 
74  void DrawFocusHilite(Int_t onoff);
75 
76 public:
77  TGColorPalette(const TGWindow *p = 0, Int_t cols = 8, Int_t rows = 8, Int_t id = -1);
78  virtual ~TGColorPalette();
79 
80  virtual Bool_t HandleButton(Event_t *event);
81  virtual Bool_t HandleMotion(Event_t *event);
82  virtual Bool_t HandleKey(Event_t *event);
83 
84  virtual TGDimension GetDefaultSize() const
85  { return TGDimension((fCw + 5) * fCols, (fCh + 5) * fRows); }
86 
87  void SetColors(Pixel_t colors[]);
88  void SetColor(Int_t ix, Pixel_t color);
89  void SetCurrentCellColor(Pixel_t color);
90 
91  void SetCellSize(Int_t w = 20, Int_t h = 17);
92 
93  Pixel_t GetColorByIndex(Int_t ix) const { return fPixels[ix]; }
94  Pixel_t GetCurrentColor() const;
95 
96  virtual void ColorSelected(Pixel_t col = 0)
97  { Emit("ColorSelected(Pixel_t)", col ? col : GetCurrentColor()); } //*SIGNAL*
98 
99  ClassDef(TGColorPalette,0) // Color palette widget
100 };
101 
102 //----------------------------------------------------------------------
103 
104 class TGColorPick : public TGFrame, public TGWidget {
105 
106 private:
107  Int_t fColormap[64][3]; // colormap
108  Pixel_t fPixel[64]; // pixel values
109 
110 protected:
111  Pixmap_t fHSimage; // hue / saturation colormap pixmap
112  Pixmap_t fLimage; // color lightness slider pixmap
113  Int_t fNColors; // number of color samples
114  Int_t fClick; // mouse click location (kCLICK_NONE, kCLICK_HS, kCLICK_L)
115  Int_t fCx; // x position in hs colormap
116  Int_t fCy; // y position in hs colormap
117  Int_t fCz; // position in lightness slider
118  Pixel_t fCurrentColor; // currently selected color value
119  Rectangle_t fColormapRect; // hue / saturation colormap rectangle
120  Rectangle_t fSliderRect; // color lightness slider rectangle
121  TGGC fCursorGC; // color lightness slider cursor GC
122 
123  virtual void DoRedraw();
124 
125  void DrawHScursor(Int_t onoff);
126  void DrawLcursor(Int_t onoff);
127  void SetHScursor(Int_t x, Int_t y);
128  void SetLcursor(Int_t z);
129 
130  void CreateImages();
131  void InitImages();
132  void SetSliderColor();
133  void UpdateCurrentColor();
134 
135  void AllocColors();
136  void FreeColors();
137  void CreateDitheredImage(Pixmap_t image, Int_t which);
138 
139 public:
140  TGColorPick(const TGWindow *p = 0, Int_t w = 1, Int_t h = 1, Int_t id = -1);
141  virtual ~TGColorPick();
142 
143  virtual Bool_t HandleButton(Event_t *event);
144  virtual Bool_t HandleMotion(Event_t *event);
145 
146  void SetColor(Pixel_t color);
147  Pixel_t GetCurrentColor() const { return fCurrentColor; }
148 
149  virtual void ColorSelected(Pixel_t col = 0)
150  { Emit("ColorSelected(Pixel_t)", col ? col : GetCurrentColor()); } //*SIGNAL*
151 
152  ClassDef(TGColorPick,0) // Color picker widget
153 };
154 
155 //----------------------------------------------------------------------
156 
157 class TGColorDialog : public TGTransientFrame {
158 
159 private:
160 
161  TGColorDialog(const TGColorDialog&); // Not implemented
162  TGColorDialog& operator=(const TGColorDialog&); // Not implemented
163 
164 protected:
165  Pixel_t fCurrentColor; // currently selected color
166  Pixel_t fInitColor; // initially set color
167  Int_t *fRetc; // return code (kMBOk, kMBCancel)
168  Pixel_t *fRetColor; // return color
169  TColor *fRetTColor; // return TColor, needed for changed alpha
170 
171  TGColorPalette *fPalette; // color palette
172  TGColorPalette *fCpalette; // color palette
173  TGColorPick *fColors; // color pick widget
174  TGFrame *fSample; // color sample frame
175  TGFrame *fSampleOld; // color sample frame
176  TGTextEntry *fRte, *fGte, *fBte, *fHte, *fLte, *fSte, *fAle; // RGB/HLS text entries
177  TGTextBuffer *fRtb, *fGtb, *fBtb, *fHtb, *fLtb, *fStb, *fAlb; // RGB/HLS associated buffers
178  Bool_t fWaitFor; // call WaitFor method in constructor
179 
180  TGTab *fTab; //tab widget holding the color selectors
181  TRootEmbeddedCanvas *fEcanvas; //embedded canvas holding the color wheel
182  TColorWheel *fColorWheel; //color wheel
183  TGLabel *fColorInfo; //color info
184  TGTextButton *fPreview; //preview button;
185 
186  void UpdateRGBentries(Pixel_t *c);
187  void UpdateHLSentries(Pixel_t *c);
188  void UpdateAlpha(Pixel_t *c);
189  virtual void CloseWindow();
190  virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2);
191 
192 public:
193  TGColorDialog(const TGWindow *p = 0, const TGWindow *m = 0, Int_t *retc = 0,
194  Pixel_t *color = 0, Bool_t wait = kTRUE);
195  virtual ~TGColorDialog();
196 
197  TGColorPalette *GetPalette() const { return fPalette; }
198  TGColorPalette *GetCustomPalette() const { return fCpalette; }
199 
200  virtual void ColorSelected(Pixel_t); //*SIGNAL*
201  virtual void AlphaColorSelected(ULong_t); //*SIGNAL*
202  void DoPreview();
203  virtual void SetCurrentColor(Pixel_t col);
204  void SetColorInfo(Int_t event, Int_t px, Int_t py, TObject *selected);
205 
206  ClassDef(TGColorDialog,0) // Color selection dialog
207 };
208 
209 #endif