Logo ROOT   6.08/07
Reference Guide
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 #ifndef ROOT_TGFrame
39 #include "TGFrame.h"
40 #endif
41 #ifndef ROOT_TGWidget
42 #include "TGWidget.h"
43 #endif
44 #include "TColor.h"
45 
46 
47 class TGTextEntry;
48 class TGTextBuffer;
49 class TGTab;
51 class TColorWheel;
52 class TGLabel;
53 class TGTextButton;
54 
55 //----------------------------------------------------------------------
56 
57 class TGColorPalette : public TGFrame, public TGWidget {
58 
59 private:
60 
61  TGColorPalette(const TGColorPalette&); // Not implemented
62  TGColorPalette& operator=(const TGColorPalette&); // Not implemented
63 
64 protected:
65  Int_t fCx; // x coordinate of currently selected color cell
66  Int_t fCy; // y coordinate of currently selected color cell
67  UInt_t fCw; // color cell width
68  UInt_t fCh; // color cell height
69  Int_t fRows; // number of color cell rows
70  Int_t fCols; // number of color cell columns
71  Pixel_t *fPixels; // pixel value of colors
72  TGGC fDrawGC; // graphics context used for drawing
73 
74  virtual void DoRedraw();
75  virtual void GotFocus();
76  virtual void LostFocus();
77 
78  void DrawFocusHilite(Int_t onoff);
79 
80 public:
81  TGColorPalette(const TGWindow *p = 0, Int_t cols = 8, Int_t rows = 8, Int_t id = -1);
82  virtual ~TGColorPalette();
83 
84  virtual Bool_t HandleButton(Event_t *event);
85  virtual Bool_t HandleMotion(Event_t *event);
86  virtual Bool_t HandleKey(Event_t *event);
87 
88  virtual TGDimension GetDefaultSize() const
89  { return TGDimension((fCw + 5) * fCols, (fCh + 5) * fRows); }
90 
91  void SetColors(Pixel_t colors[]);
92  void SetColor(Int_t ix, Pixel_t color);
93  void SetCurrentCellColor(Pixel_t color);
94 
95  void SetCellSize(Int_t w = 20, Int_t h = 17);
96 
97  Pixel_t GetColorByIndex(Int_t ix) const { return fPixels[ix]; }
98  Pixel_t GetCurrentColor() const;
99 
100  virtual void ColorSelected(Pixel_t col = 0)
101  { Emit("ColorSelected(Pixel_t)", col ? col : GetCurrentColor()); } //*SIGNAL*
102 
103  ClassDef(TGColorPalette,0) // Color palette widget
104 };
105 
106 //----------------------------------------------------------------------
107 
108 class TGColorPick : public TGFrame, public TGWidget {
109 
110 private:
111  Int_t fColormap[64][3]; // colormap
112  Pixel_t fPixel[64]; // pixel values
113 
114 protected:
115  Pixmap_t fHSimage; // hue / saturation colormap pixmap
116  Pixmap_t fLimage; // color lightness slider pixmap
117  Int_t fNColors; // number of color samples
118  Int_t fClick; // mouse click location (kCLICK_NONE, kCLICK_HS, kCLICK_L)
119  Int_t fCx; // x position in hs colormap
120  Int_t fCy; // y position in hs colormap
121  Int_t fCz; // position in lightness slider
122  Pixel_t fCurrentColor; // currently selected color value
123  Rectangle_t fColormapRect; // hue / saturation colormap rectangle
124  Rectangle_t fSliderRect; // color lightness slider rectangle
125  TGGC fCursorGC; // color lightness slider cursor GC
126 
127  virtual void DoRedraw();
128 
129  void DrawHScursor(Int_t onoff);
130  void DrawLcursor(Int_t onoff);
131  void SetHScursor(Int_t x, Int_t y);
132  void SetLcursor(Int_t z);
133 
134  void CreateImages();
135  void InitImages();
136  void SetSliderColor();
137  void UpdateCurrentColor();
138 
139  void AllocColors();
140  void FreeColors();
141  void CreateDitheredImage(Pixmap_t image, Int_t which);
142 
143 public:
144  TGColorPick(const TGWindow *p = 0, Int_t w = 1, Int_t h = 1, Int_t id = -1);
145  virtual ~TGColorPick();
146 
147  virtual Bool_t HandleButton(Event_t *event);
148  virtual Bool_t HandleMotion(Event_t *event);
149 
150  void SetColor(Pixel_t color);
151  Pixel_t GetCurrentColor() const { return fCurrentColor; }
152 
153  virtual void ColorSelected(Pixel_t col = 0)
154  { Emit("ColorSelected(Pixel_t)", col ? col : GetCurrentColor()); } //*SIGNAL*
155 
156  ClassDef(TGColorPick,0) // Color picker widget
157 };
158 
159 //----------------------------------------------------------------------
160 
162 
163 private:
164 
165  TGColorDialog(const TGColorDialog&); // Not implemented
166  TGColorDialog& operator=(const TGColorDialog&); // Not implemented
167 
168 protected:
169  Pixel_t fCurrentColor; // currently selected color
170  Pixel_t fInitColor; // initially set color
171  Int_t *fRetc; // return code (kMBOk, kMBCancel)
172  Pixel_t *fRetColor; // return color
173  TColor *fRetTColor; // return TColor, needed for changed alpha
174 
175  TGColorPalette *fPalette; // color palette
176  TGColorPalette *fCpalette; // color palette
177  TGColorPick *fColors; // color pick widget
178  TGFrame *fSample; // color sample frame
179  TGFrame *fSampleOld; // color sample frame
180  TGTextEntry *fRte, *fGte, *fBte, *fHte, *fLte, *fSte, *fAle; // RGB/HLS text entries
181  TGTextBuffer *fRtb, *fGtb, *fBtb, *fHtb, *fLtb, *fStb, *fAlb; // RGB/HLS associated buffers
182  Bool_t fWaitFor; // call WaitFor method in constructor
183 
184  TGTab *fTab; //tab widget holding the color selectors
185  TRootEmbeddedCanvas *fEcanvas; //embedded canvas holding the color wheel
186  TColorWheel *fColorWheel; //color wheel
187  TGLabel *fColorInfo; //color info
188  TGTextButton *fPreview; //preview button;
189 
190  void UpdateRGBentries(Pixel_t *c);
191  void UpdateHLSentries(Pixel_t *c);
192  void UpdateAlpha(Pixel_t *c);
193  virtual void CloseWindow();
194  virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2);
195 
196 public:
197  TGColorDialog(const TGWindow *p = 0, const TGWindow *m = 0, Int_t *retc = 0,
198  Pixel_t *color = 0, Bool_t wait = kTRUE);
199  virtual ~TGColorDialog();
200 
201  TGColorPalette *GetPalette() const { return fPalette; }
202  TGColorPalette *GetCustomPalette() const { return fCpalette; }
203 
204  virtual void ColorSelected(Pixel_t); //*SIGNAL*
205  virtual void AlphaColorSelected(ULong_t); //*SIGNAL*
206  void DoPreview();
207  virtual void SetCurrentColor(Pixel_t col);
208  void SetColorInfo(Int_t event, Int_t px, Int_t py, TObject *selected);
209 
210  ClassDef(TGColorDialog,0) // Color selection dialog
211 };
212 
213 #endif
TColorWheel * fColorWheel
virtual Bool_t ProcessMessage(Long_t, Long_t, Long_t)
Definition: TGFrame.h:246
virtual void ColorSelected(Pixel_t col=0)
Definition: TGTab.h:66
return c
virtual Bool_t HandleButton(Event_t *event)
Handle button events in color palette.
TGColorPalette * fCpalette
TRootEmbeddedCanvas * fEcanvas
TH1 * h
Definition: legend2.C:5
TColor * fRetTColor
Rectangle_t fSliderRect
Pixel_t * fRetColor
Pixel_t fCurrentColor
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual ~TGColorPalette()
Destructor.
virtual void ColorSelected(Pixel_t col=0)
virtual void LostFocus()
Remove keyboard input.
Double_t x[n]
Definition: legend1.C:17
#define ClassDef(name, id)
Definition: Rtypes.h:254
ULong_t Pixel_t
Definition: GuiTypes.h:41
TGColorPalette * fPalette
TGTextButton * fPreview
TGTextBuffer * fStb
TGFrame * fSampleOld
void DrawFocusHilite(Int_t onoff)
Draw a highlight rectangle around cell obtaining focus.
void Emit(const char *signal)
Acitvate signal without args.
Definition: TQObject.cxx:561
TGColorPick * fColors
unsigned int UInt_t
Definition: RtypesCore.h:42
TMarker * m
Definition: textangle.C:8
TGTextEntry * fSte
Pixel_t fCurrentColor
void SetColor(Int_t ix, Pixel_t color)
Set color at index ix of color entries.
TGColorPalette(const TGColorPalette &)
Pixmap_t fHSimage
long Long_t
Definition: RtypesCore.h:50
Color * colors
Definition: X3DBuffer.c:19
Pixel_t GetCurrentColor() const
Return currently selected color value.
TGColorPalette * GetPalette() const
virtual Bool_t HandleKey(Event_t *event)
Handle keyboard events in color palette.
TGFrame * fSample
unsigned long ULong_t
Definition: RtypesCore.h:51
virtual void GotFocus()
Add keyboard input.
Double_t y[n]
Definition: legend1.C:17
void SetColors(Pixel_t colors[])
Set color entries in color samples.
Pixel_t * fPixels
Definition: TGColorDialog.h:71
TGColorPalette * GetCustomPalette() const
The color creation and management class.
Definition: TColor.h:23
virtual TGDimension GetDefaultSize() const
std::cout << fWidth << "x" << fHeight << std::endl;
Definition: TGColorDialog.h:88
virtual void DoRedraw()
Redraw color palette.
Rectangle_t fColormapRect
Mother of all ROOT objects.
Definition: TObject.h:37
you should not use this method at all Int_t Int_t z
Definition: TRolke.cxx:630
Pixel_t fInitColor
Pixmap_t fLimage
void SetCurrentCellColor(Pixel_t color)
Set current cell color.
Handle_t Pixmap_t
Definition: GuiTypes.h:31
void SetCellSize(Int_t w=20, Int_t h=17)
Set color cell size.
Pixel_t GetCurrentColor() const
TGColorPalette & operator=(const TGColorPalette &)
TGLabel * fColorInfo
const Bool_t kTRUE
Definition: Rtypes.h:91
virtual Bool_t HandleMotion(Event_t *event)
Handle mouse motion events in color palette.
Definition: TGGC.h:35
Draw the ROOT Color Wheel.
Definition: TColorWheel.h:26
Pixel_t GetColorByIndex(Int_t ix) const
Definition: TGColorDialog.h:97