Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:36

0001 #ifndef Fireworks_Core_FWColorSelect_h
0002 #define Fireworks_Core_FWColorSelect_h
0003 
0004 #include "TGLabel.h"
0005 #include "TGButton.h"
0006 #include "TGColorSelect.h"
0007 
0008 #include <vector>
0009 
0010 class FWColorManager;
0011 class TGColorPopup;
0012 
0013 //------------------------------FWColorFrame------------------------------//
0014 
0015 class FWColorFrame : public TGFrame {
0016 protected:
0017   Color_t fColor;
0018 
0019 public:
0020   FWColorFrame(const TGWindow *p = nullptr, Color_t ci = 0);
0021   ~FWColorFrame() override {}
0022 
0023   Bool_t HandleButton(Event_t *event) override;
0024   void DrawBorder() override {}
0025 
0026   void SetColor(Color_t);
0027   Color_t GetColor() const { return fColor; }
0028 
0029   void ColorSelected(Color_t);  // *SIGNAL*
0030 
0031   ClassDefOverride(FWColorFrame, 0);
0032 };
0033 
0034 //------------------------------FWColorRow------------------------------//
0035 
0036 class FWColorRow : public TGHorizontalFrame {
0037   void DrawHighlight();
0038 
0039 protected:
0040   Bool_t fBackgroundIsBlack;
0041   Int_t fSelectedIndex;
0042   std::vector<FWColorFrame *> fCc;
0043 
0044   void DoRedraw() override;
0045 
0046 public:
0047   FWColorRow(const TGWindow *p = nullptr);
0048   ~FWColorRow() override;
0049 
0050   virtual void AddColor(Color_t color);
0051 
0052   void ResetColor(Int_t, Color_t);
0053   void SetBackgroundToBlack(Bool_t);
0054 
0055   //if it can't find the color it returns -1
0056   Int_t FindColorIndex(Color_t) const;
0057 
0058   Int_t GetSelectedIndex() const { return fSelectedIndex; }
0059   void SetSelectedIndex(Int_t i) { fSelectedIndex = i; }
0060 
0061   void ColorChanged(Color_t);  // *SIGNAL*
0062 
0063   ClassDefOverride(FWColorRow, 0);
0064 };
0065 
0066 //------------------------------FWColorPopup------------------------------//
0067 
0068 class FWColorPopup : public TGVerticalFrame {
0069 private:
0070   void SetColors(const std::vector<Pixel_t> &colors, bool backgroundIsBlack);
0071 
0072 protected:
0073   Color_t fSelectedColor;
0074   FWColorRow *fFirstRow, *fSecondRow;
0075   TGLabel *fLabel;
0076   Int_t fNumColors;
0077   Bool_t fShowWheel;
0078 
0079   static Bool_t fgFreePalette;
0080 
0081 public:
0082   FWColorPopup(const TGWindow *p = nullptr, Color_t color = 0);
0083   ~FWColorPopup() override;
0084 
0085   Bool_t HandleButton(Event_t *event) override;
0086 
0087   void InitContent(const char *name, const std::vector<Color_t> &colors, bool backgroundIsBlack = true);
0088   void SetName(const char *iName) override;
0089   void SetColors(const std::vector<Color_t> &colors, bool backgroundIsBlack = true);
0090   void ResetColors(const std::vector<Color_t> &colors, bool backgroundIsBlack = true);
0091   void SetSelection(Color_t);
0092   void PlacePopup(Int_t x, Int_t y, UInt_t w, UInt_t h);
0093 
0094   void ColorSelected(Color_t);  // *SIGNAL*
0095 
0096   void PopupColorWheel();
0097   void ColorWheelSelected(Pixel_t);
0098 
0099   static Bool_t HasFreePalette();
0100   static void EnableFreePalette();
0101 
0102   ClassDefOverride(FWColorPopup, 0);
0103 };
0104 
0105 //------------------------------FWColorSelect------------------------------//
0106 
0107 class FWColorSelect : public TGColorSelect {
0108 private:
0109   std::string fLabel;
0110   Color_t fSelectedColor;
0111   FWColorPopup *fFireworksPopup;
0112   const FWColorManager *fColorManager;
0113 
0114 public:
0115   FWColorSelect(const TGWindow *p, const char *label, Color_t colorIndex, const FWColorManager *, Int_t id);
0116   ~FWColorSelect() override;
0117 
0118   Bool_t HandleButton(Event_t *event) override;
0119 
0120   void SetColorByIndex(Color_t iColor);
0121   void SetColorByIndex(Color_t iColor, Bool_t iSendSignal);
0122   void UpdateColors();
0123   const std::string &label() const { return fLabel; }
0124   void ColorChosen(Color_t);  // *SIGNAL*
0125 
0126   ClassDefOverride(FWColorSelect, 0);
0127 };
0128 #endif