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
22class TGTextEntry;
23class TGTextBuffer;
24class TGTab;
26class TColorWheel;
27class TGLabel;
28class TGTextButton;
29
30//----------------------------------------------------------------------
31
32class TGColorPalette : public TGFrame, public TGWidget {
33
34private:
35
38
39protected:
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 void DoRedraw() override;
50 virtual void GotFocus();
51 virtual void LostFocus();
52
53 void DrawFocusHilite(Int_t onoff);
54
55public:
56 TGColorPalette(const TGWindow *p = nullptr, Int_t cols = 8, Int_t rows = 8, Int_t id = -1);
57 virtual ~TGColorPalette();
58
61 Bool_t HandleKey(Event_t *event) override;
62
63 TGDimension GetDefaultSize() const override
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]; }
74
75 virtual void ColorSelected(Pixel_t col = 0)
76 { Emit("ColorSelected(Pixel_t)", col ? col : GetCurrentColor()); } //*SIGNAL*
77
78 ClassDefOverride(TGColorPalette,0) // Color palette widget
79};
80
81//----------------------------------------------------------------------
82
83class TGColorPick : public TGFrame, public TGWidget {
84
85private:
86 Int_t fColormap[64][3]; // colormap
87 Pixel_t fPixel[64]; // pixel values
88
89protected:
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 void DoRedraw() override;
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
118public:
119 TGColorPick(const TGWindow *p = nullptr, Int_t w = 1, Int_t h = 1, Int_t id = -1);
120 virtual ~TGColorPick();
121
122 Bool_t HandleButton(Event_t *event) override;
123 Bool_t HandleMotion(Event_t *event) override;
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 ClassDefOverride(TGColorPick,0) // Color picker widget
132};
133
134//----------------------------------------------------------------------
135
137
138private:
139
140 TGColorDialog(const TGColorDialog&) = delete;
142
143protected:
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
167 void UpdateAlpha(Pixel_t *c);
168 void CloseWindow() override;
169 Bool_t ProcessMessage(Longptr_t msg, Longptr_t parm1, Longptr_t parm2) override;
170
171public:
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(ULongptr_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 ClassDefOverride(TGColorDialog,0) // Color selection dialog
186};
187
188#endif
Handle_t Pixmap_t
Pixmap handle.
Definition: GuiTypes.h:30
ULong_t Pixel_t
Pixel value.
Definition: GuiTypes.h:40
#define c(i)
Definition: RSha256.hxx:101
#define h(i)
Definition: RSha256.hxx:106
int Int_t
Definition: RtypesCore.h:45
long Longptr_t
Definition: RtypesCore.h:82
unsigned long ULongptr_t
Definition: RtypesCore.h:83
const Bool_t kTRUE
Definition: RtypesCore.h:100
#define ClassDefOverride(name, id)
Definition: Rtypes.h:339
winID h TVirtualViewer3D TVirtualGLPainter p
Color * colors
Definition: X3DBuffer.c:21
Draw the ROOT Color Wheel.
Definition: TColorWheel.h:23
The color creation and management class.
Definition: TColor.h:19
A full featured color selection dialog.
TGTextEntry * fLte
TGTextEntry * fBte
Bool_t ProcessMessage(Longptr_t msg, Longptr_t parm1, Longptr_t parm2) override
Process messages for the color selection dialog.
TGColorDialog & operator=(const TGColorDialog &)=delete
TGColorPalette * fPalette
color palette
TGTab * fTab
tab widget holding the color selectors
TGLabel * fColorInfo
color info
virtual void SetCurrentColor(Pixel_t col)
Change current color.
void DoPreview()
Slot method called when Preview button is clicked.
TGTextEntry * fRte
Int_t * fRetc
return code (kMBOk, kMBCancel)
TColorWheel * fColorWheel
color wheel
TGTextBuffer * fStb
TGTextBuffer * fAlb
RGB/HLS associated buffers.
TGTextButton * fPreview
preview button;
Pixel_t fCurrentColor
currently selected color
Pixel_t * fRetColor
return color
TGColorPick * fColors
color pick widget
TGColorDialog(const TGColorDialog &)=delete
TColor * fRetTColor
return TColor, needed for changed alpha
TGTextEntry * fHte
TGColorPalette * GetPalette() const
void SetColorInfo(Int_t event, Int_t px, Int_t py, TObject *selected)
Set the color info in RGB and HLS parts.
TRootEmbeddedCanvas * fEcanvas
embedded canvas holding the color wheel
TGColorPalette * fCpalette
color palette
TGTextBuffer * fLtb
virtual void ColorSelected(Pixel_t)
Emit signal about selected color.
void CloseWindow() override
Called when window is closed via window manager.
TGTextEntry * fAle
RGB/HLS text entries.
TGFrame * fSample
color sample frame
TGTextBuffer * fBtb
TGTextBuffer * fHtb
virtual void AlphaColorSelected(ULongptr_t)
Emit signal about selected alpha and color.
TGTextBuffer * fRtb
Bool_t fWaitFor
call WaitFor method in constructor
Pixel_t fInitColor
initially set color
TGColorPalette * GetCustomPalette() const
void UpdateRGBentries(Pixel_t *c)
Update RGB text entries with RGB values of color c.
void UpdateHLSentries(Pixel_t *c)
Update HLS text entries with HLS values of color c.
TGFrame * fSampleOld
color sample frame
virtual ~TGColorDialog()
TGColorDialog destructor.
TGTextEntry * fGte
void UpdateAlpha(Pixel_t *c)
Update Opacity text entry with alpha value of color c.
TGTextEntry * fSte
TGTextBuffer * fGtb
A widget showing an matrix of color cells.
Definition: TGColorDialog.h:32
void SetCellSize(Int_t w=20, Int_t h=17)
Set color cell size.
TGDimension GetDefaultSize() const override
std::cout << fWidth << "x" << fHeight << std::endl;
Definition: TGColorDialog.h:63
Bool_t HandleButton(Event_t *event) override
Handle button events in color palette.
Bool_t HandleMotion(Event_t *event) override
Handle mouse motion events in color palette.
virtual ~TGColorPalette()
Destructor.
void SetColors(Pixel_t colors[])
Set color entries in color samples.
void DoRedraw() override
Redraw color palette.
Int_t fRows
number of color cell rows
Definition: TGColorDialog.h:44
Pixel_t GetColorByIndex(Int_t ix) const
Definition: TGColorDialog.h:72
virtual void LostFocus()
Remove keyboard input.
Pixel_t GetCurrentColor() const
Return currently selected color value.
UInt_t fCh
color cell height
Definition: TGColorDialog.h:43
void SetCurrentCellColor(Pixel_t color)
Set current cell color.
Int_t fCols
number of color cell columns
Definition: TGColorDialog.h:45
UInt_t fCw
color cell width
Definition: TGColorDialog.h:42
void DrawFocusHilite(Int_t onoff)
Draw a highlight rectangle around cell obtaining focus.
Pixel_t * fPixels
pixel value of colors
Definition: TGColorDialog.h:46
TGGC fDrawGC
graphics context used for drawing
Definition: TGColorDialog.h:47
virtual void GotFocus()
Add keyboard input.
void SetColor(Int_t ix, Pixel_t color)
Set color at index ix of color entries.
Int_t fCy
y coordinate of currently selected color cell
Definition: TGColorDialog.h:41
TGColorPalette(const TGColorPalette &)=delete
virtual void ColorSelected(Pixel_t col=0)
Definition: TGColorDialog.h:75
Bool_t HandleKey(Event_t *event) override
Handle keyboard events in color palette.
Int_t fCx
x coordinate of currently selected color cell
Definition: TGColorDialog.h:40
TGColorPalette & operator=(const TGColorPalette &)=delete
A widget which allows a color to be picked from HLS color space.
Definition: TGColorDialog.h:83
Bool_t HandleButton(Event_t *event) override
Handle mouse button events in color pick widget.
void SetLcursor(Int_t z)
Set lightness slider cursor position.
void DoRedraw() override
Redraw the color pick widget.
Int_t fCx
x position in hs colormap
Definition: TGColorDialog.h:94
Pixmap_t fLimage
color lightness slider pixmap
Definition: TGColorDialog.h:91
Int_t fNColors
number of color samples
Definition: TGColorDialog.h:92
Pixmap_t fHSimage
hue / saturation colormap pixmap
Definition: TGColorDialog.h:90
void UpdateCurrentColor()
Assign the current cursor position as currently selected color.
virtual ~TGColorPick()
TGColorPick destructor.
Int_t fClick
mouse click location (kCLICK_NONE, kCLICK_HS, kCLICK_L)
Definition: TGColorDialog.h:93
void CreateImages()
Create colormap and color slider images.
void SetColor(Pixel_t color)
Position the slider cursor on right color position.
virtual void ColorSelected(Pixel_t col=0)
Pixel_t fCurrentColor
currently selected color value
Definition: TGColorDialog.h:97
Int_t fCz
position in lightness slider
Definition: TGColorDialog.h:96
void SetSliderColor()
Set slider colors.
TGColorPick(const TGWindow *p=nullptr, Int_t w=1, Int_t h=1, Int_t id=-1)
TGColorPick constructor.
void AllocColors()
Try to allocate first a palette of 64 colors.
Rectangle_t fColormapRect
hue / saturation colormap rectangle
Definition: TGColorDialog.h:98
void FreeColors()
Free allocated colors.
Pixel_t GetCurrentColor() const
Int_t fColormap[64][3]
Definition: TGColorDialog.h:86
void DrawHScursor(Int_t onoff)
Draw hue / saturation cursor.
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...
void DrawLcursor(Int_t onoff)
Draw lightness slider cursor.
void InitImages()
Initialize color palette and slider images.
Rectangle_t fSliderRect
color lightness slider rectangle
Definition: TGColorDialog.h:99
void SetHScursor(Int_t x, Int_t y)
Set hue / saturation cursor position.
Bool_t HandleMotion(Event_t *event) override
Handle mouse motion events in color pick widget.
Pixel_t fPixel[64]
Definition: TGColorDialog.h:87
Int_t fCy
y position in hs colormap
Definition: TGColorDialog.h:95
TGGC fCursorGC
color lightness slider cursor GC
A subclasses of TGWindow, and is used as base class for some simple widgets (buttons,...
Definition: TGFrame.h:80
Encapsulate a graphics context used in the low level graphics.
Definition: TGGC.h:22
This class handles GUI labels.
Definition: TGLabel.h:24
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
A text buffer is used in several widgets, like TGTextEntry, TGFileDialog, etc.
Definition: TGTextBuffer.h:17
Yield an action as soon as it is clicked.
Definition: TGButton.h:142
A TGTextEntry is a one line text input widget.
Definition: TGTextEntry.h:24
Defines transient windows that typically are used for dialogs windows.
Definition: TGFrame.h:498
The widget base class.
Definition: TGWidget.h:43
ROOT GUI Window base class.
Definition: TGWindow.h:23
Mother of all ROOT objects.
Definition: TObject.h:37
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Definition: TQObject.h:164
This class creates a TGCanvas in which a TCanvas is created.
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
Event structure.
Definition: GuiTypes.h:174
Rectangle structure (maps to the X11 XRectangle structure)
Definition: GuiTypes.h:361
auto * m
Definition: textangle.C:8