ROOT logo
// @(#)root/gui:$Id$
// Author: Bertrand Bellenot + Fons Rademakers   22/08/02
// Author: Ilka Antcheva (color wheel support)   16/03/07

/*************************************************************************
 * Copyright (C) 1995-2002, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TGColorDialog
#define ROOT_TGColorDialog

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TGColorPalette, TGColorPick and TGColorDialog.                       //
//                                                                      //
// The TGColorPalette is a widget showing an matrix of color cells. The //
// colors can be set and selected.                                      //
//                                                                      //
// The TGColorPick is a widget which allows a color to be picked from   //
// HLS space. It consists of two elements: a color map window from      //
// where the user can select the hue and saturation level of a color,   //
// and a slider to select color's lightness.                            //
//                                                                      //
// Selecting a color in these two widgets will generate the event:      //
// kC_COLORSEL, kCOL_CLICK, widget id, 0.                               //
// and the signal:                                                      //
// ColorSelected(Pixel_t color)                                         //
//                                                                      //
// The TGColorDialog presents a full featured color selection dialog.   //
// It uses 2 TGColorPalette's and the TGColorPick widgets.              //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TGFrame
#include "TGFrame.h"
#endif
#ifndef ROOT_TGWidget
#include "TGWidget.h"
#endif
#include "TColor.h"


class TGTextEntry;
class TGTextBuffer;
class TGTab;
class TRootEmbeddedCanvas;
class TColorWheel;
class TGLabel;
class TGTextButton;

//----------------------------------------------------------------------

class TGColorPalette : public TGFrame, public TGWidget {

private:
   
   TGColorPalette(const TGColorPalette&); // Not implemented
   TGColorPalette& operator=(const TGColorPalette&); // Not implemented

protected:
   Int_t    fCx;           // x coordinate of currently selected color cell
   Int_t    fCy;           // y coordinate of currently selected color cell
   UInt_t   fCw;           // color cell width
   UInt_t   fCh;           // color cell height
   Int_t    fRows;         // number of color cell rows
   Int_t    fCols;         // number of color cell columns
   Pixel_t *fPixels;       // pixel value of colors
   TGGC     fDrawGC;       // graphics context used for drawing

   virtual void DoRedraw();
   virtual void GotFocus();
   virtual void LostFocus();

   void DrawFocusHilite(Int_t onoff);

public:
   TGColorPalette(const TGWindow *p = 0, Int_t cols = 8, Int_t rows = 8, Int_t id = -1);
   virtual ~TGColorPalette();

   virtual Bool_t HandleButton(Event_t *event);
   virtual Bool_t HandleMotion(Event_t *event);
   virtual Bool_t HandleKey(Event_t *event);

   virtual TGDimension GetDefaultSize() const
            { return TGDimension((fCw + 5) * fCols, (fCh + 5) * fRows); }

   void    SetColors(Pixel_t colors[]);
   void    SetColor(Int_t ix, Pixel_t color);
   void    SetCurrentCellColor(Pixel_t color);

   void    SetCellSize(Int_t w = 20, Int_t h = 17);

   Pixel_t GetColorByIndex(Int_t ix) const { return fPixels[ix]; }
   Pixel_t GetCurrentColor() const;

   virtual void ColorSelected(Pixel_t col = 0)
            { Emit("ColorSelected(Pixel_t)", col ? col : GetCurrentColor()); }  //*SIGNAL*

   ClassDef(TGColorPalette,0)  // Color palette widget
};

//----------------------------------------------------------------------

class TGColorPick : public TGFrame, public TGWidget {

private:
   Int_t    fColormap[64][3];    // colormap
   Pixel_t  fPixel[64];          // pixel values

protected:
   Pixmap_t     fHSimage;        // hue / saturation colormap pixmap
   Pixmap_t     fLimage;         // color lightness slider pixmap
   Int_t        fNColors;        // number of color samples
   Int_t        fClick;          // mouse click location (kCLICK_NONE, kCLICK_HS, kCLICK_L)
   Int_t        fCx;             // x position in hs colormap
   Int_t        fCy;             // y position in hs colormap
   Int_t        fCz;             // position in lightness slider 
   Pixel_t      fCurrentColor;   // currently selected color value
   Rectangle_t  fColormapRect;   // hue / saturation colormap rectangle
   Rectangle_t  fSliderRect;     // color lightness slider rectangle
   TGGC         fCursorGC;       // color lightness slider cursor GC

   virtual void DoRedraw();

   void    DrawHScursor(Int_t onoff);
   void    DrawLcursor(Int_t onoff);
   void    SetHScursor(Int_t x, Int_t y);
   void    SetLcursor(Int_t z);

   void    CreateImages();
   void    InitImages();
   void    SetSliderColor();
   void    UpdateCurrentColor();

   void    AllocColors();
   void    FreeColors();
   void    CreateDitheredImage(Pixmap_t image, Int_t which);

public:
   TGColorPick(const TGWindow *p = 0, Int_t w = 1, Int_t h = 1, Int_t id = -1);
   virtual ~TGColorPick();

   virtual Bool_t HandleButton(Event_t *event);
   virtual Bool_t HandleMotion(Event_t *event);

   void     SetColor(Pixel_t color);
   Pixel_t  GetCurrentColor() const { return fCurrentColor; }

   virtual  void ColorSelected(Pixel_t col = 0)
            { Emit("ColorSelected(Pixel_t)", col ? col : GetCurrentColor()); }  //*SIGNAL*

   ClassDef(TGColorPick,0)  // Color picker widget
};

//----------------------------------------------------------------------

class TGColorDialog : public TGTransientFrame {

private:

   TGColorDialog(const TGColorDialog&); // Not implemented
   TGColorDialog& operator=(const TGColorDialog&); // Not implemented

protected:
   Pixel_t         fCurrentColor;   // currently selected color
   Pixel_t         fInitColor;      // initially set color
   Int_t          *fRetc;           // return code (kMBOk, kMBCancel)
   Pixel_t        *fRetColor;       // return color
   TColor         *fRetTColor;      // return TColor, needed for changed alpha

   TGColorPalette *fPalette;        // color palette
   TGColorPalette *fCpalette;       // color palette
   TGColorPick    *fColors;         // color pick widget
   TGFrame        *fSample;         // color sample frame
   TGFrame        *fSampleOld;      // color sample frame
   TGTextEntry    *fRte, *fGte, *fBte, *fHte, *fLte, *fSte, *fAle; // RGB/HLS text entries
   TGTextBuffer   *fRtb, *fGtb, *fBtb, *fHtb, *fLtb, *fStb, *fAlb; // RGB/HLS associated buffers
   Bool_t          fWaitFor;         // call WaitFor method in constructor
   
   TGTab               *fTab;        //tab widget holding the color selectors
   TRootEmbeddedCanvas *fEcanvas;    //embedded canvas holding the color wheel
   TColorWheel         *fColorWheel; //color wheel
   TGLabel             *fColorInfo;  //color info
   TGTextButton        *fPreview;    //preview button;
   
   void           UpdateRGBentries(Pixel_t *c);
   void           UpdateHLSentries(Pixel_t *c);
   void           UpdateAlpha(Pixel_t *c);
   virtual void   CloseWindow();
   virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2);

public:
   TGColorDialog(const TGWindow *p = 0, const TGWindow *m = 0, Int_t *retc = 0,
                 Pixel_t *color = 0, Bool_t wait = kTRUE);
   virtual ~TGColorDialog();

   TGColorPalette *GetPalette() const { return fPalette; }
   TGColorPalette *GetCustomPalette() const { return fCpalette; }

   virtual void ColorSelected(Pixel_t); //*SIGNAL*
   virtual void AlphaColorSelected(ULong_t); //*SIGNAL*
           void DoPreview();
   virtual void SetCurrentColor(Pixel_t col);
           void SetColorInfo(Int_t event, Int_t px, Int_t py, TObject *selected);

   ClassDef(TGColorDialog,0)  // Color selection dialog
};

#endif
 TGColorDialog.h:1
 TGColorDialog.h:2
 TGColorDialog.h:3
 TGColorDialog.h:4
 TGColorDialog.h:5
 TGColorDialog.h:6
 TGColorDialog.h:7
 TGColorDialog.h:8
 TGColorDialog.h:9
 TGColorDialog.h:10
 TGColorDialog.h:11
 TGColorDialog.h:12
 TGColorDialog.h:13
 TGColorDialog.h:14
 TGColorDialog.h:15
 TGColorDialog.h:16
 TGColorDialog.h:17
 TGColorDialog.h:18
 TGColorDialog.h:19
 TGColorDialog.h:20
 TGColorDialog.h:21
 TGColorDialog.h:22
 TGColorDialog.h:23
 TGColorDialog.h:24
 TGColorDialog.h:25
 TGColorDialog.h:26
 TGColorDialog.h:27
 TGColorDialog.h:28
 TGColorDialog.h:29
 TGColorDialog.h:30
 TGColorDialog.h:31
 TGColorDialog.h:32
 TGColorDialog.h:33
 TGColorDialog.h:34
 TGColorDialog.h:35
 TGColorDialog.h:36
 TGColorDialog.h:37
 TGColorDialog.h:38
 TGColorDialog.h:39
 TGColorDialog.h:40
 TGColorDialog.h:41
 TGColorDialog.h:42
 TGColorDialog.h:43
 TGColorDialog.h:44
 TGColorDialog.h:45
 TGColorDialog.h:46
 TGColorDialog.h:47
 TGColorDialog.h:48
 TGColorDialog.h:49
 TGColorDialog.h:50
 TGColorDialog.h:51
 TGColorDialog.h:52
 TGColorDialog.h:53
 TGColorDialog.h:54
 TGColorDialog.h:55
 TGColorDialog.h:56
 TGColorDialog.h:57
 TGColorDialog.h:58
 TGColorDialog.h:59
 TGColorDialog.h:60
 TGColorDialog.h:61
 TGColorDialog.h:62
 TGColorDialog.h:63
 TGColorDialog.h:64
 TGColorDialog.h:65
 TGColorDialog.h:66
 TGColorDialog.h:67
 TGColorDialog.h:68
 TGColorDialog.h:69
 TGColorDialog.h:70
 TGColorDialog.h:71
 TGColorDialog.h:72
 TGColorDialog.h:73
 TGColorDialog.h:74
 TGColorDialog.h:75
 TGColorDialog.h:76
 TGColorDialog.h:77
 TGColorDialog.h:78
 TGColorDialog.h:79
 TGColorDialog.h:80
 TGColorDialog.h:81
 TGColorDialog.h:82
 TGColorDialog.h:83
 TGColorDialog.h:84
 TGColorDialog.h:85
 TGColorDialog.h:86
 TGColorDialog.h:87
 TGColorDialog.h:88
 TGColorDialog.h:89
 TGColorDialog.h:90
 TGColorDialog.h:91
 TGColorDialog.h:92
 TGColorDialog.h:93
 TGColorDialog.h:94
 TGColorDialog.h:95
 TGColorDialog.h:96
 TGColorDialog.h:97
 TGColorDialog.h:98
 TGColorDialog.h:99
 TGColorDialog.h:100
 TGColorDialog.h:101
 TGColorDialog.h:102
 TGColorDialog.h:103
 TGColorDialog.h:104
 TGColorDialog.h:105
 TGColorDialog.h:106
 TGColorDialog.h:107
 TGColorDialog.h:108
 TGColorDialog.h:109
 TGColorDialog.h:110
 TGColorDialog.h:111
 TGColorDialog.h:112
 TGColorDialog.h:113
 TGColorDialog.h:114
 TGColorDialog.h:115
 TGColorDialog.h:116
 TGColorDialog.h:117
 TGColorDialog.h:118
 TGColorDialog.h:119
 TGColorDialog.h:120
 TGColorDialog.h:121
 TGColorDialog.h:122
 TGColorDialog.h:123
 TGColorDialog.h:124
 TGColorDialog.h:125
 TGColorDialog.h:126
 TGColorDialog.h:127
 TGColorDialog.h:128
 TGColorDialog.h:129
 TGColorDialog.h:130
 TGColorDialog.h:131
 TGColorDialog.h:132
 TGColorDialog.h:133
 TGColorDialog.h:134
 TGColorDialog.h:135
 TGColorDialog.h:136
 TGColorDialog.h:137
 TGColorDialog.h:138
 TGColorDialog.h:139
 TGColorDialog.h:140
 TGColorDialog.h:141
 TGColorDialog.h:142
 TGColorDialog.h:143
 TGColorDialog.h:144
 TGColorDialog.h:145
 TGColorDialog.h:146
 TGColorDialog.h:147
 TGColorDialog.h:148
 TGColorDialog.h:149
 TGColorDialog.h:150
 TGColorDialog.h:151
 TGColorDialog.h:152
 TGColorDialog.h:153
 TGColorDialog.h:154
 TGColorDialog.h:155
 TGColorDialog.h:156
 TGColorDialog.h:157
 TGColorDialog.h:158
 TGColorDialog.h:159
 TGColorDialog.h:160
 TGColorDialog.h:161
 TGColorDialog.h:162
 TGColorDialog.h:163
 TGColorDialog.h:164
 TGColorDialog.h:165
 TGColorDialog.h:166
 TGColorDialog.h:167
 TGColorDialog.h:168
 TGColorDialog.h:169
 TGColorDialog.h:170
 TGColorDialog.h:171
 TGColorDialog.h:172
 TGColorDialog.h:173
 TGColorDialog.h:174
 TGColorDialog.h:175
 TGColorDialog.h:176
 TGColorDialog.h:177
 TGColorDialog.h:178
 TGColorDialog.h:179
 TGColorDialog.h:180
 TGColorDialog.h:181
 TGColorDialog.h:182
 TGColorDialog.h:183
 TGColorDialog.h:184
 TGColorDialog.h:185
 TGColorDialog.h:186
 TGColorDialog.h:187
 TGColorDialog.h:188
 TGColorDialog.h:189
 TGColorDialog.h:190
 TGColorDialog.h:191
 TGColorDialog.h:192
 TGColorDialog.h:193
 TGColorDialog.h:194
 TGColorDialog.h:195
 TGColorDialog.h:196
 TGColorDialog.h:197
 TGColorDialog.h:198
 TGColorDialog.h:199
 TGColorDialog.h:200
 TGColorDialog.h:201
 TGColorDialog.h:202
 TGColorDialog.h:203
 TGColorDialog.h:204
 TGColorDialog.h:205
 TGColorDialog.h:206
 TGColorDialog.h:207
 TGColorDialog.h:208
 TGColorDialog.h:209
 TGColorDialog.h:210
 TGColorDialog.h:211
 TGColorDialog.h:212
 TGColorDialog.h:213