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-2021, 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 #include "TGFrame.h"
18 #include "TGWidget.h"
19 #include "TColor.h"
20 
21 
22 class TGTextEntry;
23 class TGTextBuffer;
24 class TGTab;
26 class TColorWheel;
27 class TGLabel;
28 class TGTextButton;
29 
30 //----------------------------------------------------------------------
31 
32 class TGColorPalette : public TGFrame, public TGWidget {
33 
34 private:
35 
36  TGColorPalette(const TGColorPalette&) = delete;
38 
39 protected:
40  Int_t fCx; ///< x coordinate of currently selected color cell
41  Int_t fCy; ///< y coordinate of currently selected color cell
42  UInt_t fCw; ///< color cell width
43  UInt_t fCh; ///< color cell height
44  Int_t fRows; ///< number of color cell rows
45  Int_t fCols; ///< number of color cell columns
46  Pixel_t *fPixels; ///< pixel value of colors
47  TGGC fDrawGC; ///< graphics context used for drawing
48 
49  virtual void DoRedraw();
50  virtual void GotFocus();
51  virtual void LostFocus();
52 
53  void DrawFocusHilite(Int_t onoff);
54 
55 public:
56  TGColorPalette(const TGWindow *p = 0, Int_t cols = 8, Int_t rows = 8, Int_t id = -1);
57  virtual ~TGColorPalette();
58 
59  virtual Bool_t HandleButton(Event_t *event);
60  virtual Bool_t HandleMotion(Event_t *event);
61  virtual Bool_t HandleKey(Event_t *event);
62 
63  virtual TGDimension GetDefaultSize() const
64  { return TGDimension((fCw + 5) * fCols, (fCh + 5) * fRows); }
65 
66  void SetColors(Pixel_t colors[]);
67  void SetColor(Int_t ix, Pixel_t color);
68  void SetCurrentCellColor(Pixel_t color);
69 
70  void SetCellSize(Int_t w = 20, Int_t h = 17);
71 
72  Pixel_t GetColorByIndex(Int_t ix) const { return fPixels[ix]; }
73  Pixel_t GetCurrentColor() const;
74 
75  virtual void ColorSelected(Pixel_t col = 0)
76  { Emit("ColorSelected(Pixel_t)", col ? col : GetCurrentColor()); } //*SIGNAL*
77 
78  ClassDef(TGColorPalette,0) // Color palette widget
79 };
80 
81 //----------------------------------------------------------------------
82 
83 class TGColorPick : public TGFrame, public TGWidget {
84 
85 private:
86  Int_t fColormap[64][3]; // colormap
87  Pixel_t fPixel[64]; // pixel values
88 
89 protected:
90  Pixmap_t fHSimage; ///< hue / saturation colormap pixmap
91  Pixmap_t fLimage; ///< color lightness slider pixmap
92  Int_t fNColors; ///< number of color samples
93  Int_t fClick; ///< mouse click location (kCLICK_NONE, kCLICK_HS, kCLICK_L)
94  Int_t fCx; ///< x position in hs colormap
95  Int_t fCy; ///< y position in hs colormap
96  Int_t fCz; ///< position in lightness slider
97  Pixel_t fCurrentColor; ///< currently selected color value
98  Rectangle_t fColormapRect; ///< hue / saturation colormap rectangle
99  Rectangle_t fSliderRect; ///< color lightness slider rectangle
100  TGGC fCursorGC; ///< color lightness slider cursor GC
101 
102  virtual void DoRedraw();
103 
104  void DrawHScursor(Int_t onoff);
105  void DrawLcursor(Int_t onoff);
106  void SetHScursor(Int_t x, Int_t y);
107  void SetLcursor(Int_t z);
108 
109  void CreateImages();
110  void InitImages();
111  void SetSliderColor();
112  void UpdateCurrentColor();
113 
114  void AllocColors();
115  void FreeColors();
116  void CreateDitheredImage(Pixmap_t image, Int_t which);
117 
118 public:
119  TGColorPick(const TGWindow *p = 0, Int_t w = 1, Int_t h = 1, Int_t id = -1);
120  virtual ~TGColorPick();
121 
122  virtual Bool_t HandleButton(Event_t *event);
123  virtual Bool_t HandleMotion(Event_t *event);
124 
125  void SetColor(Pixel_t color);
127 
128  virtual void ColorSelected(Pixel_t col = 0)
129  { Emit("ColorSelected(Pixel_t)", col ? col : GetCurrentColor()); } //*SIGNAL*
130 
131  ClassDef(TGColorPick,0) // Color picker widget
132 };
133 
134 //----------------------------------------------------------------------
135 
137 
138 private:
139 
140  TGColorDialog(const TGColorDialog&) = delete;
142 
143 protected:
144  Pixel_t fCurrentColor; ///< currently selected color
145  Pixel_t fInitColor; ///< initially set color
146  Int_t *fRetc; ///< return code (kMBOk, kMBCancel)
147  Pixel_t *fRetColor; ///< return color
148  TColor *fRetTColor; ///< return TColor, needed for changed alpha
149 
150  TGColorPalette *fPalette; ///< color palette
151  TGColorPalette *fCpalette; ///< color palette
152  TGColorPick *fColors; ///< color pick widget
153  TGFrame *fSample; ///< color sample frame
154  TGFrame *fSampleOld; ///< color sample frame
155  TGTextEntry *fRte, *fGte, *fBte, *fHte, *fLte, *fSte, *fAle; ///< RGB/HLS text entries
156  TGTextBuffer *fRtb, *fGtb, *fBtb, *fHtb, *fLtb, *fStb, *fAlb; ///< RGB/HLS associated buffers
157  Bool_t fWaitFor; ///< call WaitFor method in constructor
158 
159  TGTab *fTab; ///< tab widget holding the color selectors
160  TRootEmbeddedCanvas *fEcanvas; ///< embedded canvas holding the color wheel
161  TColorWheel *fColorWheel; ///< color wheel
162  TGLabel *fColorInfo; ///< color info
163  TGTextButton *fPreview; ///< preview button;
164 
165  void UpdateRGBentries(Pixel_t *c);
166  void UpdateHLSentries(Pixel_t *c);
167  void UpdateAlpha(Pixel_t *c);
168  virtual void CloseWindow();
169  virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2);
170 
171 public:
172  TGColorDialog(const TGWindow *p = nullptr, const TGWindow *m = nullptr, Int_t *retc = nullptr,
173  Pixel_t *color = nullptr, Bool_t wait = kTRUE);
174  virtual ~TGColorDialog();
175 
176  TGColorPalette *GetPalette() const { return fPalette; }
178 
179  virtual void ColorSelected(Pixel_t); //*SIGNAL*
180  virtual void AlphaColorSelected(ULong_t); //*SIGNAL*
181  void DoPreview();
182  virtual void SetCurrentColor(Pixel_t col);
183  void SetColorInfo(Int_t event, Int_t px, Int_t py, TObject *selected);
184 
185  ClassDef(TGColorDialog,0) // Color selection dialog
186 };
187 
188 #endif
TGColorPalette::LostFocus
virtual void LostFocus()
Remove keyboard input.
Definition: TGColorDialog.cxx:373
c
#define c(i)
Definition: RSha256.hxx:101
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:642
TGColorPick::SetColor
void SetColor(Pixel_t color)
Position the slider cursor on right color position.
Definition: TGColorDialog.cxx:867
m
auto * m
Definition: textangle.C:8
TGColorPick::GetCurrentColor
Pixel_t GetCurrentColor() const
Definition: TGColorDialog.h:126
TGColorDialog::fRetc
Int_t * fRetc
return code (kMBOk, kMBCancel)
Definition: TGColorDialog.h:146
TGColorDialog::fColorInfo
TGLabel * fColorInfo
color info
Definition: TGColorDialog.h:162
TGColorDialog::fEcanvas
TRootEmbeddedCanvas * fEcanvas
embedded canvas holding the color wheel
Definition: TGColorDialog.h:160
TGTransientFrame
Defines transient windows that typically are used for dialogs windows.
Definition: TGFrame.h:498
TGColorDialog::fAle
TGTextEntry * fAle
RGB/HLS text entries.
Definition: TGColorDialog.h:155
TGWindow
ROOT GUI Window base class.
Definition: TGWindow.h:23
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:100
Pixmap_t
Handle_t Pixmap_t
Pixmap handle.
Definition: GuiTypes.h:30
TGColorPalette::SetColors
void SetColors(Pixel_t colors[])
Set color entries in color samples.
Definition: TGColorDialog.cxx:294
TGColorDialog::GetCustomPalette
TGColorPalette * GetCustomPalette() const
Definition: TGColorDialog.h:177
TGColorPick::HandleMotion
virtual Bool_t HandleMotion(Event_t *event)
Handle mouse motion events in color pick widget.
Definition: TGColorDialog.cxx:494
TGColorPalette::fRows
Int_t fRows
number of color cell rows
Definition: TGColorDialog.h:44
TGDimension
Definition: TGDimension.h:18
TGColorPalette::DoRedraw
virtual void DoRedraw()
Redraw color palette.
Definition: TGColorDialog.cxx:342
TGColorPick::fCursorGC
TGGC fCursorGC
color lightness slider cursor GC
Definition: TGColorDialog.h:100
Rectangle_t
Rectangle structure (maps to the X11 XRectangle structure)
Definition: GuiTypes.h:361
TGColorDialog::DoPreview
void DoPreview()
Slot method called when Preview button is clicked.
Definition: TGColorDialog.cxx:1630
TGColorDialog::CloseWindow
virtual void CloseWindow()
Called when window is closed via window manager.
Definition: TGColorDialog.cxx:1373
Pixel_t
ULong_t Pixel_t
Pixel value.
Definition: GuiTypes.h:40
TGColorPick::fPixel
Pixel_t fPixel[64]
Definition: TGColorDialog.h:87
TGColorDialog::fTab
TGTab * fTab
tab widget holding the color selectors
Definition: TGColorDialog.h:159
TGColorPalette::fPixels
Pixel_t * fPixels
pixel value of colors
Definition: TGColorDialog.h:46
TGColorDialog::fColors
TGColorPick * fColors
color pick widget
Definition: TGColorDialog.h:152
TGColorDialog::fHte
TGTextEntry * fHte
Definition: TGColorDialog.h:155
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:304
TGLabel
This class handles GUI labels.
Definition: TGLabel.h:24
TGColorPalette::SetCurrentCellColor
void SetCurrentCellColor(Pixel_t color)
Set current cell color.
Definition: TGColorDialog.cxx:313
TGColorPick::UpdateCurrentColor
void UpdateCurrentColor()
Assign the current cursor position as currently selected color.
Definition: TGColorDialog.cxx:892
TGColorPalette::SetCellSize
void SetCellSize(Int_t w=20, Int_t h=17)
Set color cell size.
Definition: TGColorDialog.cxx:321
TGColorPick::fCz
Int_t fCz
position in lightness slider
Definition: TGColorDialog.h:96
TGTextButton
Yield an action as soon as it is clicked.
Definition: TGButton.h:142
TGColorPick::fSliderRect
Rectangle_t fSliderRect
color lightness slider rectangle
Definition: TGColorDialog.h:99
TGColorDialog::fPalette
TGColorPalette * fPalette
color palette
Definition: TGColorDialog.h:150
Int_t
int Int_t
Definition: RtypesCore.h:45
TGWidget
The widget base class.
Definition: TGWidget.h:43
TGColorPick::fCx
Int_t fCx
x position in hs colormap
Definition: TGColorDialog.h:94
TGColorDialog::fSample
TGFrame * fSample
color sample frame
Definition: TGColorDialog.h:153
TGColorDialog::fPreview
TGTextButton * fPreview
preview button;
Definition: TGColorDialog.h:163
event
Definition: triangle.c:553
x
Double_t x[n]
Definition: legend1.C:17
TGColorPick::SetLcursor
void SetLcursor(Int_t z)
Set lightness slider cursor position.
Definition: TGColorDialog.cxx:967
TGColorDialog::fRetTColor
TColor * fRetTColor
return TColor, needed for changed alpha
Definition: TGColorDialog.h:148
TColor.h
TGColorDialog::fGte
TGTextEntry * fGte
Definition: TGColorDialog.h:155
TGColorDialog::AlphaColorSelected
virtual void AlphaColorSelected(ULong_t)
Emit signal about selected alpha and color.
Definition: TGColorDialog.cxx:1365
TGColorDialog::fSampleOld
TGFrame * fSampleOld
color sample frame
Definition: TGColorDialog.h:154
TGColorPalette::fCh
UInt_t fCh
color cell height
Definition: TGColorDialog.h:43
TGColorDialog::operator=
TGColorDialog & operator=(const TGColorDialog &)=delete
TGColorDialog::TGColorDialog
TGColorDialog(const TGColorDialog &)=delete
TGColorDialog::fLte
TGTextEntry * fLte
Definition: TGColorDialog.h:155
TGFrame
A subclasses of TGWindow, and is used as base class for some simple widgets (buttons,...
Definition: TGFrame.h:80
TGColorDialog::UpdateRGBentries
void UpdateRGBentries(Pixel_t *c)
Update RGB text entries with RGB values of color c.
Definition: TGColorDialog.cxx:1419
bool
TGColorPick::AllocColors
void AllocColors()
Try to allocate first a palette of 64 colors.
Definition: TGColorDialog.cxx:541
TGTextBuffer
A text buffer is used in several widgets, like TGTextEntry, TGFileDialog, etc.
Definition: TGTextBuffer.h:19
TGColorDialog::GetPalette
TGColorPalette * GetPalette() const
Definition: TGColorDialog.h:176
TGColorPick::fColormap
Int_t fColormap[64][3]
Definition: TGColorDialog.h:86
TGColorPick::InitImages
void InitImages()
Initialize color palette and slider images.
Definition: TGColorDialog.cxx:791
TGColorPalette::fCols
Int_t fCols
number of color cell columns
Definition: TGColorDialog.h:45
TGColorPick::SetHScursor
void SetHScursor(Int_t x, Int_t y)
Set hue / saturation cursor position.
Definition: TGColorDialog.cxx:940
TColorWheel
Draw the ROOT Color Wheel.
Definition: TColorWheel.h:23
TGColorPick::ColorSelected
virtual void ColorSelected(Pixel_t col=0)
Definition: TGColorDialog.h:128
TGColorDialog
A full featured color selection dialog.
Definition: TGColorDialog.h:136
TGColorDialog::UpdateAlpha
void UpdateAlpha(Pixel_t *c)
Update Opacity text entry with alpha value of color c.
Definition: TGColorDialog.cxx:1401
TGColorPalette::ColorSelected
virtual void ColorSelected(Pixel_t col=0)
Definition: TGColorDialog.h:75
TGColorDialog::SetCurrentColor
virtual void SetCurrentColor(Pixel_t col)
Change current color.
Definition: TGColorDialog.cxx:1341
TGColorDialog::fCurrentColor
Pixel_t fCurrentColor
currently selected color
Definition: TGColorDialog.h:144
TColor
The color creation and management class.
Definition: TColor.h:19
h
#define h(i)
Definition: RSha256.hxx:106
TGColorDialog::fInitColor
Pixel_t fInitColor
initially set color
Definition: TGColorDialog.h:145
TGGC
Encapsulate a graphics context used in the low level graphics.
Definition: TGGC.h:22
TGColorDialog::fColorWheel
TColorWheel * fColorWheel
color wheel
Definition: TGColorDialog.h:161
TGTextEntry
A TGTextEntry is a one line text input widget.
Definition: TGTextEntry.h:24
TGColorDialog::fRtb
TGTextBuffer * fRtb
Definition: TGColorDialog.h:156
TGColorPick::fClick
Int_t fClick
mouse click location (kCLICK_NONE, kCLICK_HS, kCLICK_L)
Definition: TGColorDialog.h:93
TGFrame.h
Long_t
long Long_t
Definition: RtypesCore.h:54
TGColorPick::fCurrentColor
Pixel_t fCurrentColor
currently selected color value
Definition: TGColorDialog.h:97
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:1604
TGColorPalette::HandleKey
virtual Bool_t HandleKey(Event_t *event)
Handle keyboard events in color palette.
Definition: TGColorDialog.cxx:232
TGColorPalette::GotFocus
virtual void GotFocus()
Add keyboard input.
Definition: TGColorDialog.cxx:365
TGColorPick
A widget which allows a color to be picked from HLS color space.
Definition: TGColorDialog.h:83
TGTab
A tab widget contains a set of composite frames each with a little tab with a name (like a set of fol...
Definition: TGTab.h:46
TGColorDialog::fCpalette
TGColorPalette * fCpalette
color palette
Definition: TGColorDialog.h:151
TGColorPalette::fDrawGC
TGGC fDrawGC
graphics context used for drawing
Definition: TGColorDialog.h:47
y
Double_t y[n]
Definition: legend1.C:17
ULong_t
unsigned long ULong_t
Definition: RtypesCore.h:55
TGColorPalette::fCx
Int_t fCx
x coordinate of currently selected color cell
Definition: TGColorDialog.h:40
TGColorPalette::fCw
UInt_t fCw
color cell width
Definition: TGColorDialog.h:42
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:1474
TGColorPalette
A widget showing an matrix of color cells.
Definition: TGColorDialog.h:32
TGWidget.h
TGColorDialog::ColorSelected
virtual void ColorSelected(Pixel_t)
Emit signal about selected color.
Definition: TGColorDialog.cxx:1357
TGColorDialog::~TGColorDialog
virtual ~TGColorDialog()
TGColorDialog destructor.
Definition: TGColorDialog.cxx:1331
unsigned int
TGColorDialog::fRte
TGTextEntry * fRte
Definition: TGColorDialog.h:155
TGColorDialog::fGtb
TGTextBuffer * fGtb
Definition: TGColorDialog.h:156
TGColorPick::FreeColors
void FreeColors()
Free allocated colors.
Definition: TGColorDialog.cxx:629
TGColorPick::DoRedraw
virtual void DoRedraw()
Redraw the color pick widget.
Definition: TGColorDialog.cxx:913
TGColorDialog::fRetColor
Pixel_t * fRetColor
return color
Definition: TGColorDialog.h:147
TGColorDialog::fSte
TGTextEntry * fSte
Definition: TGColorDialog.h:155
TGColorPick::fColormapRect
Rectangle_t fColormapRect
hue / saturation colormap rectangle
Definition: TGColorDialog.h:98
TGColorDialog::fBte
TGTextEntry * fBte
Definition: TGColorDialog.h:155
TGColorPick::fCy
Int_t fCy
y position in hs colormap
Definition: TGColorDialog.h:95
TGColorPalette::operator=
TGColorPalette & operator=(const TGColorPalette &)=delete
TGColorPick::CreateImages
void CreateImages()
Create colormap and color slider images.
Definition: TGColorDialog.cxx:525
TGColorPalette::fCy
Int_t fCy
y coordinate of currently selected color cell
Definition: TGColorDialog.h:41
TGColorPalette::GetDefaultSize
virtual TGDimension GetDefaultSize() const
std::cout << fWidth << "x" << fHeight << std::endl;
Definition: TGColorDialog.h:63
TGColorPalette::HandleMotion
virtual Bool_t HandleMotion(Event_t *event)
Handle mouse motion events in color palette.
Definition: TGColorDialog.cxx:205
TGColorDialog::fAlb
TGTextBuffer * fAlb
RGB/HLS associated buffers.
Definition: TGColorDialog.h:156
TGColorDialog::fHtb
TGTextBuffer * fHtb
Definition: TGColorDialog.h:156
TObject
Mother of all ROOT objects.
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:331
Event_t
Event structure.
Definition: GuiTypes.h:174
TGColorPick::fHSimage
Pixmap_t fHSimage
hue / saturation colormap pixmap
Definition: TGColorDialog.h:90
TGColorDialog::UpdateHLSentries
void UpdateHLSentries(Pixel_t *c)
Update HLS text entries with HLS values of color c.
Definition: TGColorDialog.cxx:1445
TGColorPick::DrawLcursor
void DrawLcursor(Int_t onoff)
Draw lightness slider cursor.
Definition: TGColorDialog.cxx:1033
TGColorDialog::fStb
TGTextBuffer * fStb
Definition: TGColorDialog.h:156
TGColorPick::DrawHScursor
void DrawHScursor(Int_t onoff)
Draw hue / saturation cursor.
Definition: TGColorDialog.cxx:988
TGColorPick::TGColorPick
TGColorPick(const TGWindow *p=0, Int_t w=1, Int_t h=1, Int_t id=-1)
TGColorPick constructor.
Definition: TGColorDialog.cxx:399
TGColorPick::HandleButton
virtual Bool_t HandleButton(Event_t *event)
Handle mouse button events in color pick widget.
Definition: TGColorDialog.cxx:459
TGColorPalette::DrawFocusHilite
void DrawFocusHilite(Int_t onoff)
Draw a highlight rectangle around cell obtaining focus.
Definition: TGColorDialog.cxx:382
TGColorPick::fNColors
Int_t fNColors
number of color samples
Definition: TGColorDialog.h:92
TGColorPalette::GetColorByIndex
Pixel_t GetColorByIndex(Int_t ix) const
Definition: TGColorDialog.h:72
TGColorPalette::HandleButton
virtual Bool_t HandleButton(Event_t *event)
Handle button events in color palette.
Definition: TGColorDialog.cxx:175
TGColorPalette::TGColorPalette
TGColorPalette(const TGColorPalette &)=delete
TQObject::Emit
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Definition: TQObject.h:164
TRootEmbeddedCanvas
This class creates a TGCanvas in which a TCanvas is created.
Definition: TRootEmbeddedCanvas.h:24
TGColorPick::fLimage
Pixmap_t fLimage
color lightness slider pixmap
Definition: TGColorDialog.h:91
TGColorDialog::fLtb
TGTextBuffer * fLtb
Definition: TGColorDialog.h:156
int
TGColorPalette::~TGColorPalette
virtual ~TGColorPalette()
Destructor.
Definition: TGColorDialog.cxx:167
TGColorDialog::fBtb
TGTextBuffer * fBtb
Definition: TGColorDialog.h:156
TGColorPick::SetSliderColor
void SetSliderColor()
Set slider colors.
Definition: TGColorDialog.cxx:830
TGColorPick::~TGColorPick
virtual ~TGColorPick()
TGColorPick destructor.
Definition: TGColorDialog.cxx:448
TGColorDialog::fWaitFor
Bool_t fWaitFor
call WaitFor method in constructor
Definition: TGColorDialog.h:157