Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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// //
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
43class TGTextEntry;
44class TGTextBuffer;
45class TGTab;
47class TColorWheel;
48class TGLabel;
49class TGTextButton;
50
51//----------------------------------------------------------------------
52
53class TGColorPalette : public TGFrame, public TGWidget {
54
55private:
56
59
60protected:
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
76public:
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
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]; }
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
104class TGColorPick : public TGFrame, public TGWidget {
105
106private:
107 Int_t fColormap[64][3]; // colormap
108 Pixel_t fPixel[64]; // pixel values
109
110protected:
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
139public:
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
159private:
160
161 TGColorDialog(const TGColorDialog&) = delete;
163
164protected:
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
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
192public:
193 TGColorDialog(const TGWindow *p = nullptr, const TGWindow *m = nullptr, Int_t *retc = nullptr,
194 Pixel_t *color = nullptr, 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
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
unsigned long ULong_t
Definition RtypesCore.h:55
long Long_t
Definition RtypesCore.h:54
const Bool_t kTRUE
Definition RtypesCore.h:91
#define ClassDef(name, id)
Definition Rtypes.h:325
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
TGTextEntry * fLte
TGTextEntry * fBte
TGColorDialog & operator=(const TGColorDialog &)=delete
TGColorPalette * fPalette
TGLabel * fColorInfo
virtual void SetCurrentColor(Pixel_t col)
Change current color.
void DoPreview()
Slot method called when Preview button is clicked.
virtual void CloseWindow()
Called when window is closed via window manager.
TGTextEntry * fRte
TColorWheel * fColorWheel
TGTextBuffer * fStb
TGTextBuffer * fAlb
TGTextButton * fPreview
Pixel_t fCurrentColor
Pixel_t * fRetColor
TGColorPick * fColors
TGColorDialog(const TGColorDialog &)=delete
TColor * fRetTColor
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
TGColorPalette * fCpalette
TGTextBuffer * fLtb
virtual void ColorSelected(Pixel_t)
Emit signal about selected color.
TGTextEntry * fAle
TGFrame * fSample
TGTextBuffer * fBtb
TGTextBuffer * fHtb
virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
Process messages for the color selection dialog.
TGTextBuffer * fRtb
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
virtual ~TGColorDialog()
TGColorDialog destructor.
TGTextEntry * fGte
void UpdateAlpha(Pixel_t *c)
Upadate Opacity text entry with alpha value of color c.
virtual void AlphaColorSelected(ULong_t)
Emit signal about selected alpha and color.
TGTextEntry * fSte
TGTextBuffer * fGtb
virtual Bool_t HandleKey(Event_t *event)
Handle keyboard events in color palette.
void SetCellSize(Int_t w=20, Int_t h=17)
Set color cell size.
virtual ~TGColorPalette()
Destructor.
virtual Bool_t HandleButton(Event_t *event)
Handle button events in color palette.
void SetColors(Pixel_t colors[])
Set color entries in color samples.
virtual void DoRedraw()
Redraw color palette.
Pixel_t GetColorByIndex(Int_t ix) const
virtual void LostFocus()
Remove keyboard input.
Pixel_t GetCurrentColor() const
Return currently selected color value.
void SetCurrentCellColor(Pixel_t color)
Set current cell color.
void DrawFocusHilite(Int_t onoff)
Draw a highlight rectangle around cell obtaining focus.
virtual TGDimension GetDefaultSize() const
std::cout << fWidth << "x" << fHeight << std::endl;
Pixel_t * fPixels
virtual void GotFocus()
Add keyboard input.
void SetColor(Int_t ix, Pixel_t color)
Set color at index ix of color entries.
virtual Bool_t HandleMotion(Event_t *event)
Handle mouse motion events in color palette.
TGColorPalette(const TGColorPalette &)=delete
virtual void ColorSelected(Pixel_t col=0)
TGColorPalette & operator=(const TGColorPalette &)=delete
void SetLcursor(Int_t z)
Set lightness slider cursor position.
Pixmap_t fLimage
Pixmap_t fHSimage
void UpdateCurrentColor()
Assign the current cursor position as currently selected color.
virtual Bool_t HandleMotion(Event_t *event)
Handle mouse motion events in color pick widget.
virtual ~TGColorPick()
TGColorPick destructor.
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
void SetSliderColor()
Set slider colors.
void AllocColors()
Try to allocate first a palette of 64 colors.
Rectangle_t fColormapRect
void FreeColors()
Free allocated colors.
Pixel_t GetCurrentColor() const
Int_t fColormap[64][3]
void DrawHScursor(Int_t onoff)
Draw hue / saturation cursor.
virtual Bool_t HandleButton(Event_t *event)
Handle mouse button events in color pick widget.
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.
virtual void DoRedraw()
Redraw the color pick widget.
void InitImages()
Initialize color palette and slider images.
Rectangle_t fSliderRect
void SetHScursor(Int_t x, Int_t y)
Set hue / saturation cursor position.
Pixel_t fPixel[64]
Definition TGGC.h:31
Definition TGTab.h:62
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
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