CMS 3D CMS Logo

Public Member Functions | Static Public Member Functions | Protected Attributes | Static Protected Attributes | Private Member Functions

FWColorPopup Class Reference

#include <FWColorSelect.h>

List of all members.

Public Member Functions

 ClassDef (FWColorPopup, 0)
void ColorSelected (Color_t)
void ColorWheelSelected (Pixel_t)
 FWColorPopup (const TGWindow *p=0, Color_t color=0)
virtual Bool_t HandleButton (Event_t *event)
void InitContent (const char *name, const std::vector< Color_t > &colors, bool backgroundIsBlack=true)
void PlacePopup (Int_t x, Int_t y, UInt_t w, UInt_t h)
void PopupColorWheel ()
void ResetColors (const std::vector< Color_t > &colors, bool backgroundIsBlack=true)
void SetColors (const std::vector< Color_t > &colors, bool backgroundIsBlack=true)
void SetName (const char *iName)
void SetSelection (Color_t)
virtual ~FWColorPopup ()

Static Public Member Functions

static void EnableFreePalette ()
static Bool_t HasFreePalette ()

Protected Attributes

FWColorRowfFirstRow
TGLabel * fLabel
Int_t fNumColors
FWColorRowfSecondRow
Color_t fSelectedColor
Bool_t fShowWheel

Static Protected Attributes

static Bool_t fgFreePalette = kFALSE

Private Member Functions

void SetColors (const std::vector< Pixel_t > &colors, bool backgroundIsBlack)

Detailed Description

Definition at line 75 of file FWColorSelect.h.


Constructor & Destructor Documentation

FWColorPopup::FWColorPopup ( const TGWindow *  p = 0,
Color_t  color = 0 
)

Definition at line 153 of file FWColorSelect.cc.

References fFirstRow, fLabel, fNumColors, fSecondRow, and fSelectedColor.

                                                           :
   TGVerticalFrame(p, 10, 10, kDoubleBorder | kRaisedFrame | kOwnBackground, kColorPopupGray),
   fShowWheel(kFALSE)
{
   SetWindowAttributes_t wattr;
   wattr.fMask = kWAOverrideRedirect;
   wattr.fOverrideRedirect = kTRUE;
   gVirtualX->ChangeWindowAttributes(fId, &wattr);
   AddInput(kStructureNotifyMask); // to notify the client for structure (i.e. unmap) changes

   fSelectedColor = color;
   fLabel = 0;
   fNumColors = 0;

   fFirstRow  = new FWColorRow(this);
   fSecondRow = new FWColorRow(this);
   fFirstRow ->Connect("ColorChanged(Color_t)", "FWColorPopup", this, "ColorSelected(Color_t)");
   fSecondRow->Connect("ColorChanged(Color_t)", "FWColorPopup", this, "ColorSelected(Color_t)");
}
FWColorPopup::~FWColorPopup ( ) [virtual]

Definition at line 173 of file FWColorSelect.cc.

{
   Cleanup();
}

Member Function Documentation

FWColorPopup::ClassDef ( FWColorPopup  ,
 
)
void FWColorPopup::ColorSelected ( Color_t  ci)

Definition at line 322 of file FWColorSelect.cc.

References fSelectedColor.

Referenced by ColorWheelSelected().

{
   UnmapWindow();
   fSelectedColor = ci;
   Emit("ColorSelected(Color_t)", ci);
}
void FWColorPopup::ColorWheelSelected ( Pixel_t  pix)

Definition at line 230 of file FWColorSelect.cc.

References ColorSelected().

{
   ColorSelected(TColor::GetColor(pix));
}
void FWColorPopup::EnableFreePalette ( ) [static]

Definition at line 151 of file FWColorSelect.cc.

References fgFreePalette.

Referenced by CmsShowMain::CmsShowMain().

{ fgFreePalette = kTRUE; }
Bool_t FWColorPopup::HandleButton ( Event_t *  event) [virtual]

Definition at line 178 of file FWColorSelect.cc.

References f.

{
   if (event->fX < 0 || event->fX >= (Int_t) fWidth ||
       event->fY < 0 || event->fY >= (Int_t) fHeight)
   {
      if (event->fType == kButtonRelease)
         UnmapWindow();
   }
   else
   {
      TGFrame *f = GetFrameFromPoint(event->fX, event->fY);
      if (f && f != this)
      {
         TranslateCoordinates(f, event->fX, event->fY, event->fX, event->fY);
         f->HandleButton(event);
      }
   }
   return kTRUE;
}
Bool_t FWColorPopup::HasFreePalette ( ) [static]

Definition at line 150 of file FWColorSelect.cc.

References fgFreePalette.

{ return fgFreePalette;  }
void FWColorPopup::InitContent ( const char *  name,
const std::vector< Color_t > &  colors,
bool  backgroundIsBlack = true 
)

Definition at line 198 of file FWColorSelect.cc.

References b, fFirstRow, fgFreePalette, fLabel, fSecondRow, kCROffsetX, kCROffsetY, kCRPadAbove, kCRPadBelow, and SetColors().

Referenced by FWGeometryTableView::cellClicked(), FWModelContextMenuHandler::createColorPopup(), FWCollectionSummaryWidget::createColorPopup(), and FWColorSelect::FWColorSelect().

{
   fLabel = new TGLabel(this, name);
   fLabel->SetBackgroundColor(GetBackground());
   SetColors(colors, backgroundIsBlack);

   AddFrame(fLabel, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, kCROffsetX, kCROffsetY, kCRPadAbove + 1, kCRPadBelow - 1));
   AddFrame(fFirstRow, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, kCROffsetX, kCROffsetY, kCRPadAbove, kCRPadBelow));
   AddFrame(fSecondRow, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, kCROffsetX, kCROffsetY, kCRPadAbove, kCRPadBelow));

   fFirstRow->MapSubwindows();
   fFirstRow->Resize(fFirstRow->GetDefaultSize());

   fSecondRow->MapSubwindows();
   fSecondRow->Resize(fSecondRow->GetDefaultSize());

   if (fgFreePalette)
   {
      TGTextButton *b = new TGTextButton(this, "Color wheel");
      AddFrame(b, new TGLayoutHints(kLHintsTop | kLHintsCenterX | kLHintsExpandX, kCROffsetX, kCROffsetY, kCRPadAbove, 2 * kCRPadBelow));
      b->Connect("Clicked()", "FWColorPopup", this, "PopupColorWheel()");
   }
}
void FWColorPopup::PlacePopup ( Int_t  x,
Int_t  y,
UInt_t  w,
UInt_t  h 
)

Definition at line 268 of file FWColorSelect.cc.

References fSelectedColor, fShowWheel, and WDecay::kNone.

Referenced by FWGeometryTableView::cellClicked(), FWModelContextMenuHandler::chosenItem(), FWCollectionSummaryWidget::colorClicked(), FWColorSelect::HandleButton(), and FWCollectionSummaryWidget::itemColorClicked().

{
   // Popup TGColorPopup at x,y position

   Int_t  rx, ry;
   UInt_t rw, rh;

   // Parent is root window for the popup:
   gVirtualX->GetWindowSize(fParent->GetId(), rx, ry, rw, rh);

   if (x < 0) x = 0;
   if (x + fWidth > rw) x = rw - fWidth;
   if (y < 0) y = 0;
   if (y + fHeight > rh) y = rh - fHeight;

   MoveResize(x, y, w, h);
   MapSubwindows();
   Layout();
   MapRaised();

   // find out if this is necessary
   gVirtualX->GrabPointer(fId, kButtonPressMask | kButtonReleaseMask | kPointerMotionMask, kNone, kNone);

   gClient->WaitForUnmap(this);
   gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);

   if (fShowWheel)
   {
      Int_t   retc;
      Pixel_t pixel = TColor::Number2Pixel(fSelectedColor);

      TGColorDialog *cd = new TGColorDialog(gClient->GetDefaultRoot(), this, &retc, &pixel, kFALSE);

      cd->Connect("ColorSelected(Pixel_t)", "FWColorPopup", this, "ColorWheelSelected(Pixel_t");

      cd->MapWindow();
      fClient->WaitForUnmap(cd);
      cd->DeleteWindow();

      fShowWheel = kFALSE;
   }
}
void FWColorPopup::PopupColorWheel ( )

Definition at line 224 of file FWColorSelect.cc.

References fShowWheel.

{
   fShowWheel = kTRUE;
   UnmapWindow();
}
void FWColorPopup::ResetColors ( const std::vector< Color_t > &  colors,
bool  backgroundIsBlack = true 
)
void FWColorPopup::SetColors ( const std::vector< Pixel_t > &  colors,
bool  backgroundIsBlack 
) [private]

Referenced by InitContent().

void FWColorPopup::SetColors ( const std::vector< Color_t > &  colors,
bool  backgroundIsBlack = true 
)

Definition at line 237 of file FWColorSelect.cc.

References FWColorRow::AddColor(), fFirstRow, fNumColors, fSecondRow, i, and FWColorRow::SetBackgroundToBlack().

{
   fNumColors = colors.size();
   for (UInt_t i = 0; i < colors.size() / 2; i++)
   {
      fFirstRow->AddColor(colors.at(i));
   }
   for (UInt_t i = colors.size() / 2; i < colors.size(); i++)
   {
      fSecondRow->AddColor(colors.at(i));
   }
   fFirstRow->SetBackgroundToBlack(backgroundIsBlack);
   fSecondRow->SetBackgroundToBlack(backgroundIsBlack);
}
void FWColorPopup::SetName ( const char *  iName)
void FWColorPopup::SetSelection ( Color_t  iColor)

Member Data Documentation

Definition at line 82 of file FWColorSelect.h.

Referenced by FWColorPopup(), InitContent(), ResetColors(), SetColors(), and SetSelection().

Bool_t FWColorPopup::fgFreePalette = kFALSE [static, protected]

Definition at line 87 of file FWColorSelect.h.

Referenced by EnableFreePalette(), HasFreePalette(), and InitContent().

TGLabel* FWColorPopup::fLabel [protected]

Definition at line 83 of file FWColorSelect.h.

Referenced by FWColorPopup(), InitContent(), and SetName().

Int_t FWColorPopup::fNumColors [protected]

Definition at line 84 of file FWColorSelect.h.

Referenced by FWColorPopup(), ResetColors(), and SetColors().

Definition at line 82 of file FWColorSelect.h.

Referenced by FWColorPopup(), InitContent(), ResetColors(), SetColors(), and SetSelection().

Color_t FWColorPopup::fSelectedColor [protected]

Definition at line 81 of file FWColorSelect.h.

Referenced by ColorSelected(), FWColorPopup(), and PlacePopup().

Bool_t FWColorPopup::fShowWheel [protected]

Definition at line 85 of file FWColorSelect.h.

Referenced by PlacePopup(), and PopupColorWheel().