Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/TGColorDialog.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // @(#)root/gui:$Id$
0002 // Author: Bertrand Bellenot + Fons Rademakers   22/08/02
0003 // Author: Ilka Antcheva (color wheel support)   16/03/07
0004 
0005 /*************************************************************************
0006  * Copyright (C) 1995-2021, Rene Brun and Fons Rademakers.               *
0007  * All rights reserved.                                                  *
0008  *                                                                       *
0009  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0010  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0011  *************************************************************************/
0012 
0013 #ifndef ROOT_TGColorDialog
0014 #define ROOT_TGColorDialog
0015 
0016 
0017 #include "TGFrame.h"
0018 #include "TGWidget.h"
0019 #include "TColor.h"
0020 
0021 
0022 class TGTextEntry;
0023 class TGTextBuffer;
0024 class TGTab;
0025 class TRootEmbeddedCanvas;
0026 class TColorWheel;
0027 class TGLabel;
0028 class TGTextButton;
0029 
0030 //----------------------------------------------------------------------
0031 
0032 class TGColorPalette : public TGFrame, public TGWidget {
0033 
0034 private:
0035 
0036    TGColorPalette(const TGColorPalette&) = delete;
0037    TGColorPalette& operator=(const TGColorPalette&) = delete;
0038 
0039 protected:
0040    Int_t    fCx;           ///< x coordinate of currently selected color cell
0041    Int_t    fCy;           ///< y coordinate of currently selected color cell
0042    UInt_t   fCw;           ///< color cell width
0043    UInt_t   fCh;           ///< color cell height
0044    Int_t    fRows;         ///< number of color cell rows
0045    Int_t    fCols;         ///< number of color cell columns
0046    Pixel_t *fPixels;       ///< pixel value of colors
0047    TGGC     fDrawGC;       ///< graphics context used for drawing
0048 
0049    void DoRedraw() override;
0050    virtual void GotFocus();
0051    virtual void LostFocus();
0052 
0053    void DrawFocusHilite(Int_t onoff);
0054 
0055 public:
0056    TGColorPalette(const TGWindow *p = nullptr, Int_t cols = 8, Int_t rows = 8, Int_t id = -1);
0057    ~TGColorPalette() override;
0058 
0059    Bool_t HandleButton(Event_t *event) override;
0060    Bool_t HandleMotion(Event_t *event) override;
0061    Bool_t HandleKey(Event_t *event) override;
0062 
0063    TGDimension GetDefaultSize() const override
0064       { return TGDimension((fCw + 5) * fCols, (fCh + 5) * fRows); }
0065 
0066    void    SetColors(Pixel_t colors[]);
0067    void    SetColor(Int_t ix, Pixel_t color);
0068    void    SetCurrentCellColor(Pixel_t color);
0069 
0070    void    SetCellSize(Int_t w = 20, Int_t h = 17);
0071 
0072    Pixel_t GetColorByIndex(Int_t ix) const { return fPixels[ix]; }
0073    Pixel_t GetCurrentColor() const;
0074 
0075    virtual void ColorSelected(Pixel_t col = 0)
0076             { Emit("ColorSelected(Pixel_t)", col ? col : GetCurrentColor()); }  //*SIGNAL*
0077 
0078    ClassDefOverride(TGColorPalette,0)  // Color palette widget
0079 };
0080 
0081 //----------------------------------------------------------------------
0082 
0083 class TGColorPick : public TGFrame, public TGWidget {
0084 
0085 private:
0086    Int_t    fColormap[64][3];    // colormap
0087    Pixel_t  fPixel[64];          // pixel values
0088 
0089 protected:
0090    Pixmap_t     fHSimage;        ///< hue / saturation colormap pixmap
0091    Pixmap_t     fLimage;         ///< color lightness slider pixmap
0092    Int_t        fNColors;        ///< number of color samples
0093    Int_t        fClick;          ///< mouse click location (kCLICK_NONE, kCLICK_HS, kCLICK_L)
0094    Int_t        fCx;             ///< x position in hs colormap
0095    Int_t        fCy;             ///< y position in hs colormap
0096    Int_t        fCz;             ///< position in lightness slider
0097    Pixel_t      fCurrentColor;   ///< currently selected color value
0098    Rectangle_t  fColormapRect;   ///< hue / saturation colormap rectangle
0099    Rectangle_t  fSliderRect;     ///< color lightness slider rectangle
0100    TGGC         fCursorGC;       ///< color lightness slider cursor GC
0101 
0102    void    DoRedraw() override;
0103 
0104    void    DrawHScursor(Int_t onoff);
0105    void    DrawLcursor(Int_t onoff);
0106    void    SetHScursor(Int_t x, Int_t y);
0107    void    SetLcursor(Int_t z);
0108 
0109    void    CreateImages();
0110    void    InitImages();
0111    void    SetSliderColor();
0112    void    UpdateCurrentColor();
0113 
0114    void    AllocColors();
0115    void    FreeColors();
0116    void    CreateDitheredImage(Pixmap_t image, Int_t which);
0117 
0118 public:
0119    TGColorPick(const TGWindow *p = nullptr, Int_t w = 1, Int_t h = 1, Int_t id = -1);
0120    ~TGColorPick() override;
0121 
0122    Bool_t HandleButton(Event_t *event) override;
0123    Bool_t HandleMotion(Event_t *event) override;
0124 
0125    void     SetColor(Pixel_t color);
0126    Pixel_t  GetCurrentColor() const { return fCurrentColor; }
0127 
0128    virtual  void ColorSelected(Pixel_t col = 0)
0129             { Emit("ColorSelected(Pixel_t)", col ? col : GetCurrentColor()); }  //*SIGNAL*
0130 
0131    ClassDefOverride(TGColorPick,0)  // Color picker widget
0132 };
0133 
0134 //----------------------------------------------------------------------
0135 
0136 class TGColorDialog : public TGTransientFrame {
0137 
0138 private:
0139 
0140    TGColorDialog(const TGColorDialog&) = delete;
0141    TGColorDialog& operator=(const TGColorDialog&) = delete;
0142 
0143 protected:
0144    Pixel_t         fCurrentColor;   ///< currently selected color
0145    Pixel_t         fInitColor;      ///< initially set color
0146    Int_t          *fRetc;           ///< return code (kMBOk, kMBCancel)
0147    Pixel_t        *fRetColor;       ///< return color
0148    TColor         *fRetTColor;      ///< return TColor, needed for changed alpha
0149 
0150    TGColorPalette *fPalette;        ///< color palette
0151    TGColorPalette *fCpalette;       ///< color palette
0152    TGColorPick    *fColors;         ///< color pick widget
0153    TGFrame        *fSample;         ///< color sample frame
0154    TGFrame        *fSampleOld;      ///< color sample frame
0155    TGTextEntry    *fRte, *fGte, *fBte, *fHte, *fLte, *fSte, *fAle; ///< RGB/HLS text entries
0156    TGTextBuffer   *fRtb, *fGtb, *fBtb, *fHtb, *fLtb, *fStb, *fAlb; ///< RGB/HLS associated buffers
0157    Bool_t          fWaitFor;         ///< call WaitFor method in constructor
0158 
0159    TGTab               *fTab;        ///< tab widget holding the color selectors
0160    TRootEmbeddedCanvas *fEcanvas;    ///< embedded canvas holding the color wheel
0161    TColorWheel         *fColorWheel; ///< color wheel
0162    TGLabel             *fColorInfo;  ///< color info
0163    TGTextButton        *fPreview;    ///< preview button;
0164 
0165    void   UpdateRGBentries(Pixel_t *c);
0166    void   UpdateHLSentries(Pixel_t *c);
0167    void   UpdateAlpha(Pixel_t *c);
0168    void   CloseWindow() override;
0169    Bool_t ProcessMessage(Longptr_t msg, Longptr_t parm1, Longptr_t parm2) override;
0170 
0171 public:
0172    TGColorDialog(const TGWindow *p = nullptr, const TGWindow *m = nullptr, Int_t *retc = nullptr,
0173                  Pixel_t *color = nullptr, Bool_t wait = kTRUE);
0174    ~TGColorDialog() override;
0175 
0176    TGColorPalette *GetPalette() const { return fPalette; }
0177    TGColorPalette *GetCustomPalette() const { return fCpalette; }
0178 
0179    virtual void ColorSelected(Pixel_t); //*SIGNAL*
0180    virtual void AlphaColorSelected(ULongptr_t); //*SIGNAL*
0181            void DoPreview();
0182    virtual void SetCurrentColor(Pixel_t col);
0183            void SetColorInfo(Int_t event, Int_t px, Int_t py, TObject *selected);
0184 
0185    ClassDefOverride(TGColorDialog,0)  // Color selection dialog
0186 };
0187 
0188 #endif