Logo ROOT   6.10/00
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
TColorWheel * fColorWheel
TGTextBuffer * fRtb
TGColorPalette * GetCustomPalette() const
void SetSliderColor()
Set slider colors.
Pixel_t GetCurrentColor() const
Return currently selected color value.
TGTextBuffer * fLtb
void SetColor(Pixel_t color)
Position the slider cursor on right color position.
TGTextEntry * fHte
virtual void ColorSelected(Pixel_t col=0)
Definition: TGColorDialog.h:96
Definition: TGTab.h:62
virtual Bool_t HandleButton(Event_t *event)
Handle button events in color palette.
TGColorPalette * fCpalette
void SetLcursor(Int_t z)
Set lightness slider cursor position.
TRootEmbeddedCanvas * fEcanvas
TH1 * h
Definition: legend2.C:5
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 UpdateHLSentries(Pixel_t *c)
Update HLS text entries with HLS values of color c.
TColor * fRetTColor
TGTextBuffer * fGtb
Rectangle_t fSliderRect
virtual ~TGColorDialog()
TGColorDialog destructor.
Pixel_t * fRetColor
Pixel_t fCurrentColor
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TGTextEntry * fBte
virtual ~TGColorPalette()
Destructor.
TGColorPalette * GetPalette() const
void UpdateCurrentColor()
Assign the current cursor position as currently selected color.
TGColorDialog(const TGColorDialog &)
TGTextBuffer * fHtb
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:297
ULong_t Pixel_t
Definition: GuiTypes.h:39
TGColorPalette * fPalette
TGTextButton * fPreview
virtual void SetCurrentColor(Pixel_t col)
Change current color.
TGTextBuffer * fStb
void AllocColors()
Try to allocate first a palette of 64 colors.
TGFrame * fSampleOld
void UpdateRGBentries(Pixel_t *c)
Update RGB text entries with RGB values of color c.
Int_t fColormap[64][3]
void DrawFocusHilite(Int_t onoff)
Draw a highlight rectangle around cell obtaining focus.
TGColorPick * fColors
void InitImages()
Initialize color palette and slider images.
unsigned int UInt_t
Definition: RtypesCore.h:42
TMarker * m
Definition: textangle.C:8
TGTextEntry * fSte
void SetHScursor(Int_t x, Int_t y)
Set hue / saturation cursor position.
Pixel_t fCurrentColor
virtual void CloseWindow()
Called when window is closed via window manager.
void SetColor(Int_t ix, Pixel_t color)
Set color at index ix of color entries.
void FreeColors()
Free allocated colors.
TGColorPalette(const TGColorPalette &)
Pixmap_t fHSimage
TGTextBuffer * fAlb
long Long_t
Definition: RtypesCore.h:50
Color * colors
Definition: X3DBuffer.c:19
TGTextBuffer * fBtb
void DrawLcursor(Int_t onoff)
Draw lightness slider cursor.
void CreateImages()
Create colormap and color slider images.
void DrawHScursor(Int_t onoff)
Draw hue / saturation cursor.
virtual Bool_t HandleKey(Event_t *event)
Handle keyboard events in color palette.
TGFrame * fSample
unsigned long ULong_t
Definition: RtypesCore.h:51
virtual Bool_t HandleButton(Event_t *event)
Handle mouse button events in color pick widget.
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:67
The color creation and management class.
Definition: TColor.h:19
virtual void DoRedraw()
Redraw color palette.
Rectangle_t fColormapRect
Pixel_t GetCurrentColor() const
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
virtual void AlphaColorSelected(ULong_t)
Emit signal about selected alpha and color.
TGTextEntry * fLte
Pixmap_t fLimage
void DoPreview()
Slot method called when Preview button is clicked.
TGColorPick(const TGWindow *p=0, Int_t w=1, Int_t h=1, Int_t id=-1)
TGColorPick constructor.
Pixel_t GetColorByIndex(Int_t ix) const
Definition: TGColorDialog.h:93
void SetCurrentCellColor(Pixel_t color)
Set current cell color.
TGColorDialog & operator=(const TGColorDialog &)
Handle_t Pixmap_t
Definition: GuiTypes.h:29
virtual TGDimension GetDefaultSize() const
std::cout << fWidth << "x" << fHeight << std::endl;
Definition: TGColorDialog.h:84
void SetCellSize(Int_t w=20, Int_t h=17)
Set color cell size.
virtual void DoRedraw()
Redraw the color pick widget.
void SetColorInfo(Int_t event, Int_t px, Int_t py, TObject *selected)
Set the color info in RGB and HLS parts.
TGColorPalette & operator=(const TGColorPalette &)
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Definition: TQObject.h:164
TGLabel * fColorInfo
virtual Bool_t HandleMotion(Event_t *event)
Handle mouse motion events in color pick widget.
TGTextEntry * fAle
const Bool_t kTRUE
Definition: RtypesCore.h:91
virtual Bool_t HandleMotion(Event_t *event)
Handle mouse motion events in color palette.
virtual ~TGColorPick()
TGColorPick destructor.
Definition: TGGC.h:31
Draw the ROOT Color Wheel.
Definition: TColorWheel.h:24
virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
Process messages for the color selection dialog.
virtual void ColorSelected(Pixel_t)
Emit signal about selected color.
void UpdateAlpha(Pixel_t *c)
Upadate Opacity text entry with alpha value of color c.
TGTextEntry * fGte
TGTextEntry * fRte
Pixel_t fPixel[64]