Logo ROOT  
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 #include "TGFrame.h"
39 #include "TGWidget.h"
40 #include "TColor.h"
41 
42 
43 class TGTextEntry;
44 class TGTextBuffer;
45 class TGTab;
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);
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 
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; }
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
TGColorPalette::LostFocus
virtual void LostFocus()
Remove keyboard input.
Definition: TGColorDialog.cxx:360
c
#define c(i)
Definition: RSha256.hxx:119
TGColorPick::CreateDitheredImage
void CreateDitheredImage(Pixmap_t image, Int_t which)
Create a dithered version of the color map and lightness images for display modes with reduced number...
Definition: TGColorDialog.cxx:629
TGColorPick::SetColor
void SetColor(Pixel_t color)
Position the slider cursor on right color position.
Definition: TGColorDialog.cxx:854
m
auto * m
Definition: textangle.C:8
TGColorPick::GetCurrentColor
Pixel_t GetCurrentColor() const
Definition: TGColorDialog.h:147
TGColorDialog::fRetc
Int_t * fRetc
Definition: TGColorDialog.h:167
TGColorDialog::fColorInfo
TGLabel * fColorInfo
Definition: TGColorDialog.h:183
TGColorDialog::fEcanvas
TRootEmbeddedCanvas * fEcanvas
Definition: TGColorDialog.h:181
TGTransientFrame
Definition: TGFrame.h:553
TGColorDialog::fAle
TGTextEntry * fAle
Definition: TGColorDialog.h:176
TGWindow
Definition: TGWindow.h:31
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
Pixmap_t
Handle_t Pixmap_t
Definition: GuiTypes.h:29
TGColorPalette::SetColors
void SetColors(Pixel_t colors[])
Set color entries in color samples.
Definition: TGColorDialog.cxx:281
TGColorDialog::GetCustomPalette
TGColorPalette * GetCustomPalette() const
Definition: TGColorDialog.h:198
TGColorPick::HandleMotion
virtual Bool_t HandleMotion(Event_t *event)
Handle mouse motion events in color pick widget.
Definition: TGColorDialog.cxx:481
TGColorPalette::fRows
Int_t fRows
Definition: TGColorDialog.h:65
TGDimension
Definition: TGDimension.h:27
TGColorPalette::DoRedraw
virtual void DoRedraw()
Redraw color palette.
Definition: TGColorDialog.cxx:329
TGColorPick::fCursorGC
TGGC fCursorGC
Definition: TGColorDialog.h:121
Rectangle_t
Definition: GuiTypes.h:360
TGColorDialog::DoPreview
void DoPreview()
Slot method called when Preview button is clicked.
Definition: TGColorDialog.cxx:1617
TGColorDialog::CloseWindow
virtual void CloseWindow()
Called when window is closed via window manager.
Definition: TGColorDialog.cxx:1360
Pixel_t
ULong_t Pixel_t
Definition: GuiTypes.h:39
TGColorPick::fPixel
Pixel_t fPixel[64]
Definition: TGColorDialog.h:108
TGColorDialog::fTab
TGTab * fTab
Definition: TGColorDialog.h:180
TGColorPalette::fPixels
Pixel_t * fPixels
Definition: TGColorDialog.h:67
TGColorDialog::fColors
TGColorPick * fColors
Definition: TGColorDialog.h:173
TGColorDialog::fHte
TGTextEntry * fHte
Definition: TGColorDialog.h:176
colors
Color * colors
Definition: X3DBuffer.c:21
TGColorPalette::SetColor
void SetColor(Int_t ix, Pixel_t color)
Set color at index ix of color entries.
Definition: TGColorDialog.cxx:291
TGLabel
Definition: TGLabel.h:32
TGColorPalette::SetCurrentCellColor
void SetCurrentCellColor(Pixel_t color)
Set current cell color.
Definition: TGColorDialog.cxx:300
TGColorPick::UpdateCurrentColor
void UpdateCurrentColor()
Assign the current cursor position as currently selected color.
Definition: TGColorDialog.cxx:879
TGColorPalette::SetCellSize
void SetCellSize(Int_t w=20, Int_t h=17)
Set color cell size.
Definition: TGColorDialog.cxx:308
TGColorPick::fCz
Int_t fCz
Definition: TGColorDialog.h:117
TGTextButton
Definition: TGButton.h:142
TGColorPick::fSliderRect
Rectangle_t fSliderRect
Definition: TGColorDialog.h:120
TGColorDialog::fPalette
TGColorPalette * fPalette
Definition: TGColorDialog.h:171
Int_t
int Int_t
Definition: RtypesCore.h:45
TGWidget
Definition: TGWidget.h:55
TGColorPick::fCx
Int_t fCx
Definition: TGColorDialog.h:115
TGColorDialog::fSample
TGFrame * fSample
Definition: TGColorDialog.h:174
TGColorDialog::fPreview
TGTextButton * fPreview
Definition: TGColorDialog.h:184
x
Double_t x[n]
Definition: legend1.C:17
TGColorPick::SetLcursor
void SetLcursor(Int_t z)
Set lightness slider cursor position.
Definition: TGColorDialog.cxx:954
TGColorDialog::fRetTColor
TColor * fRetTColor
Definition: TGColorDialog.h:169
TColor.h
TGColorDialog::fGte
TGTextEntry * fGte
Definition: TGColorDialog.h:176
TGColorDialog::AlphaColorSelected
virtual void AlphaColorSelected(ULong_t)
Emit signal about selected alpha and color.
Definition: TGColorDialog.cxx:1352
TGColorDialog::fSampleOld
TGFrame * fSampleOld
Definition: TGColorDialog.h:175
TGColorPalette::fCh
UInt_t fCh
Definition: TGColorDialog.h:64
TGColorDialog::fLte
TGTextEntry * fLte
Definition: TGColorDialog.h:176
TGFrame
Definition: TGFrame.h:105
TGColorDialog::operator=
TGColorDialog & operator=(const TGColorDialog &)
TGColorDialog::UpdateRGBentries
void UpdateRGBentries(Pixel_t *c)
Update RGB text entries with RGB values of color c.
Definition: TGColorDialog.cxx:1406
bool
TGColorPick::AllocColors
void AllocColors()
Try to allocate first a palette of 64 colors.
Definition: TGColorDialog.cxx:528
TGTextBuffer
Definition: TGTextBuffer.h:30
TGColorDialog::GetPalette
TGColorPalette * GetPalette() const
Definition: TGColorDialog.h:197
TGColorPick::fColormap
Int_t fColormap[64][3]
Definition: TGColorDialog.h:107
TGColorPick::InitImages
void InitImages()
Initialize color palette and slider images.
Definition: TGColorDialog.cxx:778
TGColorPalette::fCols
Int_t fCols
Definition: TGColorDialog.h:66
TGColorPalette::operator=
TGColorPalette & operator=(const TGColorPalette &)
TGColorPick::SetHScursor
void SetHScursor(Int_t x, Int_t y)
Set hue / saturation cursor position.
Definition: TGColorDialog.cxx:927
TColorWheel
Definition: TColorWheel.h:24
TGColorPick::ColorSelected
virtual void ColorSelected(Pixel_t col=0)
Definition: TGColorDialog.h:149
TGColorDialog
Definition: TGColorDialog.h:157
TGColorDialog::UpdateAlpha
void UpdateAlpha(Pixel_t *c)
Upadate Opacity text entry with alpha value of color c.
Definition: TGColorDialog.cxx:1388
TGColorPalette::ColorSelected
virtual void ColorSelected(Pixel_t col=0)
Definition: TGColorDialog.h:96
TGColorDialog::SetCurrentColor
virtual void SetCurrentColor(Pixel_t col)
Change current color.
Definition: TGColorDialog.cxx:1328
TGColorDialog::fCurrentColor
Pixel_t fCurrentColor
Definition: TGColorDialog.h:165
TColor
Definition: TColor.h:19
h
#define h(i)
Definition: RSha256.hxx:124
TGColorDialog::fInitColor
Pixel_t fInitColor
Definition: TGColorDialog.h:166
TGGC
Definition: TGGC.h:31
TGColorDialog::fColorWheel
TColorWheel * fColorWheel
Definition: TGColorDialog.h:182
TGTextEntry
Definition: TGTextEntry.h:39
TGColorDialog::fRtb
TGTextBuffer * fRtb
Definition: TGColorDialog.h:177
TGColorPick::fClick
Int_t fClick
Definition: TGColorDialog.h:114
TGColorPalette::TGColorPalette
TGColorPalette(const TGColorPalette &)
TGFrame.h
Long_t
long Long_t
Definition: RtypesCore.h:54
TGColorPick::fCurrentColor
Pixel_t fCurrentColor
Definition: TGColorDialog.h:118
TGColorDialog::SetColorInfo
void SetColorInfo(Int_t event, Int_t px, Int_t py, TObject *selected)
Set the color info in RGB and HLS parts.
Definition: TGColorDialog.cxx:1591
TGColorPalette::HandleKey
virtual Bool_t HandleKey(Event_t *event)
Handle keyboard events in color palette.
Definition: TGColorDialog.cxx:219
TGColorPalette::GotFocus
virtual void GotFocus()
Add keyboard input.
Definition: TGColorDialog.cxx:352
TGColorPick
Definition: TGColorDialog.h:104
TGTab
Definition: TGTab.h:62
TGColorDialog::fCpalette
TGColorPalette * fCpalette
Definition: TGColorDialog.h:172
TGColorPalette::fDrawGC
TGGC fDrawGC
Definition: TGColorDialog.h:68
y
Double_t y[n]
Definition: legend1.C:17
ULong_t
unsigned long ULong_t
Definition: RtypesCore.h:55
TGColorPalette::fCx
Int_t fCx
Definition: TGColorDialog.h:61
TGColorPalette::fCw
UInt_t fCw
Definition: TGColorDialog.h:63
TGColorDialog::ProcessMessage
virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
Process messages for the color selection dialog.
Definition: TGColorDialog.cxx:1461
TGColorPalette
Definition: TGColorDialog.h:53
TGWidget.h
TGColorDialog::ColorSelected
virtual void ColorSelected(Pixel_t)
Emit signal about selected color.
Definition: TGColorDialog.cxx:1344
TGColorDialog::~TGColorDialog
virtual ~TGColorDialog()
TGColorDialog destructor.
Definition: TGColorDialog.cxx:1318
unsigned int
TGColorDialog::fRte
TGTextEntry * fRte
Definition: TGColorDialog.h:176
TGColorDialog::fGtb
TGTextBuffer * fGtb
Definition: TGColorDialog.h:177
TGColorPick::FreeColors
void FreeColors()
Free allocated colors.
Definition: TGColorDialog.cxx:616
TGColorPick::DoRedraw
virtual void DoRedraw()
Redraw the color pick widget.
Definition: TGColorDialog.cxx:900
TGColorDialog::fRetColor
Pixel_t * fRetColor
Definition: TGColorDialog.h:168
TGColorDialog::fSte
TGTextEntry * fSte
Definition: TGColorDialog.h:176
TGColorPick::fColormapRect
Rectangle_t fColormapRect
Definition: TGColorDialog.h:119
TGColorDialog::fBte
TGTextEntry * fBte
Definition: TGColorDialog.h:176
TGColorPick::fCy
Int_t fCy
Definition: TGColorDialog.h:116
TGColorPick::CreateImages
void CreateImages()
Create colormap and color slider images.
Definition: TGColorDialog.cxx:512
TGColorPalette::fCy
Int_t fCy
Definition: TGColorDialog.h:62
TGColorPalette::GetDefaultSize
virtual TGDimension GetDefaultSize() const
std::cout << fWidth << "x" << fHeight << std::endl;
Definition: TGColorDialog.h:84
TGColorPalette::HandleMotion
virtual Bool_t HandleMotion(Event_t *event)
Handle mouse motion events in color palette.
Definition: TGColorDialog.cxx:192
TGColorDialog::fAlb
TGTextBuffer * fAlb
Definition: TGColorDialog.h:177
TGColorDialog::fHtb
TGTextBuffer * fHtb
Definition: TGColorDialog.h:177
TObject
Definition: TObject.h:37
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TGColorPalette::GetCurrentColor
Pixel_t GetCurrentColor() const
Return currently selected color value.
Definition: TGColorDialog.cxx:318
Event_t
Definition: GuiTypes.h:173
TGColorPick::fHSimage
Pixmap_t fHSimage
Definition: TGColorDialog.h:111
TGColorDialog::UpdateHLSentries
void UpdateHLSentries(Pixel_t *c)
Update HLS text entries with HLS values of color c.
Definition: TGColorDialog.cxx:1432
TGColorPick::DrawLcursor
void DrawLcursor(Int_t onoff)
Draw lightness slider cursor.
Definition: TGColorDialog.cxx:1020
TGColorDialog::fStb
TGTextBuffer * fStb
Definition: TGColorDialog.h:177
TGColorPick::DrawHScursor
void DrawHScursor(Int_t onoff)
Draw hue / saturation cursor.
Definition: TGColorDialog.cxx:975
TGColorPick::TGColorPick
TGColorPick(const TGWindow *p=0, Int_t w=1, Int_t h=1, Int_t id=-1)
TGColorPick constructor.
Definition: TGColorDialog.cxx:386
TGColorPick::HandleButton
virtual Bool_t HandleButton(Event_t *event)
Handle mouse button events in color pick widget.
Definition: TGColorDialog.cxx:446
TGColorPalette::DrawFocusHilite
void DrawFocusHilite(Int_t onoff)
Draw a highlight rectangle around cell obtaining focus.
Definition: TGColorDialog.cxx:369
TGColorPick::fNColors
Int_t fNColors
Definition: TGColorDialog.h:113
TGColorPalette::GetColorByIndex
Pixel_t GetColorByIndex(Int_t ix) const
Definition: TGColorDialog.h:93
TGColorPalette::HandleButton
virtual Bool_t HandleButton(Event_t *event)
Handle button events in color palette.
Definition: TGColorDialog.cxx:162
TGColorDialog::TGColorDialog
TGColorDialog(const TGColorDialog &)
TQObject::Emit
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Definition: TQObject.h:164
TRootEmbeddedCanvas
Definition: TRootEmbeddedCanvas.h:32
TGColorPick::fLimage
Pixmap_t fLimage
Definition: TGColorDialog.h:112
TGColorDialog::fLtb
TGTextBuffer * fLtb
Definition: TGColorDialog.h:177
int
TGColorPalette::~TGColorPalette
virtual ~TGColorPalette()
Destructor.
Definition: TGColorDialog.cxx:154
TGColorDialog::fBtb
TGTextBuffer * fBtb
Definition: TGColorDialog.h:177
TGColorPick::SetSliderColor
void SetSliderColor()
Set slider colors.
Definition: TGColorDialog.cxx:817
TGColorPick::~TGColorPick
virtual ~TGColorPick()
TGColorPick destructor.
Definition: TGColorDialog.cxx:435
TGColorDialog::fWaitFor
Bool_t fWaitFor
Definition: TGColorDialog.h:178