ROOT  6.06/09
Reference Guide
TAttFillEditor.cxx
Go to the documentation of this file.
1 // @(#)root/ged:$Id$
2 // Author: Ilka Antcheva 10/05/04
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2002, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 //////////////////////////////////////////////////////////////////////////
13 // //
14 // TAttFillEditor //
15 // //
16 // Implements GUI for editing fill attributes. // //
17 // color and fill style //
18 // //
19 //////////////////////////////////////////////////////////////////////////
20 //Begin_Html
21 /*
22 <img src="gif/TAttFillEditor.gif">
23 */
24 //End_Html
25 
26 #include "TAttFillEditor.h"
27 #include "TGedPatternSelect.h"
28 #include "TGColorSelect.h"
29 #include "TColor.h"
30 #include "TGLabel.h"
31 #include "TGNumberEntry.h"
32 #include "TPad.h"
33 #include "TCanvas.h"
34 #include "TROOT.h"
35 
37 
38 enum EFillWid {
39  kCOLOR,
40  kPATTERN,
41  kALPHA,
42  kALPHAFIELD
43 };
44 
45 
46 ////////////////////////////////////////////////////////////////////////////////
47 /// Constructor of fill attributes GUI.
48 
50  Int_t height, UInt_t options, Pixel_t back)
51  : TGedFrame(p, width, height, options | kVerticalFrame, back)
52 {
53  fPriority = 2;
54 
55  fAttFill = 0;
56 
57  MakeTitle("Fill");
58 
60  fColorSelect = new TGColorSelect(f2, 0, kCOLOR);
61  f2->AddFrame(fColorSelect, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
62  fColorSelect->Associate(this);
63  fPatternSelect = new TGedPatternSelect(f2, 1, kPATTERN);
64  f2->AddFrame(fPatternSelect, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
66  AddFrame(f2, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
67 
68  TGLabel *AlphaLabel = new TGLabel(this,"Opacity");
69  AddFrame(AlphaLabel,
71  TGHorizontalFrame *f2a = new TGHorizontalFrame(this);
72  fAlpha = new TGHSlider(f2a,100,kSlider2|kScaleNo,kALPHA);
73  fAlpha->SetRange(0,1000);
75  fAlphaField = new TGNumberEntryField(f2a, kALPHAFIELD, 0,
78  fAlphaField->Resize(40,20);
79  if (!TCanvas::SupportAlpha()) {
81  AlphaLabel->Disable(kTRUE);
83  }
86 }
87 
88 ////////////////////////////////////////////////////////////////////////////////
89 /// Destructor of fill editor.
90 
92 {
93 }
94 
95 ////////////////////////////////////////////////////////////////////////////////
96 /// Connect signals to slots.
97 
99 {
100  fColorSelect->Connect("ColorSelected(Pixel_t)", "TAttFillEditor", this, "DoFillColor(Pixel_t)");
101  fColorSelect->Connect("AlphaColorSelected(ULong_t)", "TAttFillEditor", this, "DoFillAlphaColor(ULong_t)");
102  fPatternSelect->Connect("PatternSelected(Style_t)", "TAttFillEditor", this, "DoFillPattern(Style_t)");
103  fAlpha->Connect("Released()","TAttFillEditor", this, "DoAlpha()");
104  fAlpha->Connect("PositionChanged(Int_t)","TAttFillEditor", this, "DoLiveAlpha(Int_t)");
105  fAlphaField->Connect("ReturnPressed()","TAttFillEditor", this, "DoAlphaField()");
106  fAlpha->Connect("Pressed()","TAttFillEditor", this, "GetCurAlpha()");
107  fInit = kFALSE;
108 }
109 
110 ////////////////////////////////////////////////////////////////////////////////
111 /// Pick up the used fill attributes.
112 
114 {
115  TAttFill *attfill = dynamic_cast<TAttFill *>(obj);
116  if (!attfill) return;
117 
118  fAttFill = attfill;
120 
124 
127 
130 
131  if (TColor *color = gROOT->GetColor(fAttFill->GetFillColor())) {
132  fAlpha->SetPosition((Int_t)(color->GetAlpha()*1000));
133  fAlphaField->SetNumber(color->GetAlpha());
134  }
135 }
136 
137 ////////////////////////////////////////////////////////////////////////////////
138 /// Slot connected to the fill area color with alpha.
139 
141 {
142  TColor *color = (TColor *)p;
143 
144  if (fAvoidSignal) return;
145  fAttFill->SetFillColor(color->GetNumber());
146  fAlpha->SetPosition((Int_t)(color->GetAlpha()*1000));
147  fAlphaField->SetNumber(color->GetAlpha());
148 
149  Update();
150 }
151 
152 ////////////////////////////////////////////////////////////////////////////////
153 /// Slot connected to the fill area color.
154 
156 {
157  if (fAvoidSignal) return;
159 
160  if (TColor *tcolor = gROOT->GetColor(TColor::GetColor(color))) {
161  fAlpha->SetPosition((Int_t)(tcolor->GetAlpha()*1000));
162  fAlphaField->SetNumber(tcolor->GetAlpha());
163  }
164 
165  Update();
166 }
167 
168 ////////////////////////////////////////////////////////////////////////////////
169 /// Slot connected to the fill area pattern.
170 
172 {
173  if (fAvoidSignal) return;
174  fAttFill->SetFillStyle(pattern);
175  Update();
176 }
177 
178 ////////////////////////////////////////////////////////////////////////////////
179 /// Slot to set the alpha value from the entry field.
180 
182 {
183  if (fAvoidSignal) return;
184 
185  if (TColor *color = gROOT->GetColor(fAttFill->GetFillColor())) {
186  color->SetAlpha((Float_t)fAlphaField->GetNumber());
188  }
189  Update();
190 }
191 
192 ////////////////////////////////////////////////////////////////////////////////
193 /// Slot to set the alpha value
194 
196 {
197  if (fAvoidSignal) return;
198 
199  if (TColor *color = gROOT->GetColor(fAttFill->GetFillColor())) {
200  color->SetAlpha((Float_t)fAlpha->GetPosition()/1000);
202  }
203  Update();
204 }
205 
206 ////////////////////////////////////////////////////////////////////////////////
207 /// Slot to set alpha value online.
208 
210 {
211  if (fAvoidSignal) return;
212  fAlphaField->SetNumber((Float_t)a/1000);
213 
214  if (TColor *color = gROOT->GetColor(fAttFill->GetFillColor())) {
215  // In case the color is not transparent a new color is created.
216  if (color->GetAlpha() == 1.) {
217  fAttFill->SetFillColor(TColor::GetColorTransparent(color->GetNumber(),0.99));
218  } else {
219  color->SetAlpha((Float_t)a/1000);
220  }
221  }
222  Update();
223 }
224 
225 ////////////////////////////////////////////////////////////////////////////////
226 /// Slot to update alpha value on click on Slider
227 
229 {
230  if (fAvoidSignal) return;
231 
232  if (TColor *color = gROOT->GetColor(fAttFill->GetFillColor())) {
233  fAlpha->SetPosition((Int_t)(color->GetAlpha()*1000));
234  fAlphaField->SetNumber(color->GetAlpha());
235  }
236  Update();
237 }
virtual Style_t GetFillStyle() const
Definition: TAttFill.h:44
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:587
short Style_t
Definition: RtypesCore.h:76
float Float_t
Definition: RtypesCore.h:53
virtual void SetRange(Int_t min, Int_t max)
Definition: TGSlider.h:105
void SetColor(Pixel_t color, Bool_t emit=kTRUE)
Set color.
#define gROOT
Definition: TROOT.h:340
TGHSlider * fAlpha
int Int_t
Definition: RtypesCore.h:41
TArc * a
Definition: textangle.C:12
virtual void SetModel(TObject *obj)
Pick up the used fill attributes.
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual void SetFillStyle(Style_t fstyle)
Definition: TAttFill.h:52
virtual void DoLiveAlpha(Int_t a)
Slot to set alpha value online.
Fill Area Attributes class.
Definition: TAttFill.h:32
Bool_t fAvoidSignal
Definition: TGedFrame.h:58
ULong_t Pixel_t
Definition: GuiTypes.h:41
virtual ~TAttFillEditor()
Destructor of fill editor.
virtual void DoFillPattern(Style_t color)
Slot connected to the fill area pattern.
virtual void Update()
Update the current pad when an attribute is changed via GUI.
Definition: TGedFrame.cxx:73
TGCompositeFrame(const TGCompositeFrame &)
virtual void DoFillColor(Pixel_t color)
Slot connected to the fill area color.
static const std::string pattern("pattern")
TAttFill * fAttFill
short Color_t
Definition: RtypesCore.h:79
static Bool_t SupportAlpha()
Static function returning "true" if transparency is supported.
Definition: TCanvas.cxx:2169
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot...
Definition: TQObject.cxx:1135
virtual Int_t GetPosition() const
Definition: TGSlider.h:107
virtual void SetFillColor(Color_t fcolor)
Definition: TAttFill.h:50
virtual void Disable(Bool_t on=kTRUE)
Definition: TGLabel.h:103
virtual void DoAlpha()
Slot to set the alpha value.
virtual void Associate(const TGWindow *w)
Definition: TGWidget.h:90
virtual Color_t GetFillColor() const
Definition: TAttFill.h:43
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual void SetPosition(Int_t pos)
Definition: TGSlider.h:106
static Int_t GetColor(const char *hexcolor)
Static method returning color number for color specified by hex color string of form: "#rrggbb"...
Definition: TColor.cxx:1666
virtual Double_t GetNumber() const
Get the numeric value (floating point representation).
void SetPattern(Style_t pattern, Bool_t emit=kTRUE)
Set pattern.
ClassImp(TAttFillEditor) enum EFillWid
virtual void DoAlphaField()
Slot to set the alpha value from the entry field.
static Int_t GetColorTransparent(Int_t color, Float_t a)
Static function: Returns the transparent color number corresponding to n.
Definition: TColor.cxx:1839
static ULong_t Number2Pixel(Int_t ci)
Static method that given a color index number, returns the corresponding pixel value.
Definition: TColor.cxx:1862
virtual void GetCurAlpha()
Slot to update alpha value on click on Slider.
void SetEnabled(Bool_t flag=kTRUE)
Definition: TGTextEntry.h:170
unsigned long ULong_t
Definition: RtypesCore.h:51
virtual void SetEnabled(Bool_t flag=kTRUE)
Definition: TGSlider.h:102
The color creation and management class.
Definition: TColor.h:23
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1099
TAttFillEditor(const TGWindow *p=0, Int_t width=140, Int_t height=30, UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground())
Constructor of fill attributes GUI.
Mother of all ROOT objects.
Definition: TObject.h:58
Bool_t fInit
Definition: TGedFrame.h:55
virtual void SetNumber(Double_t val)
Set the numeric value (floating point representation).
virtual void DoFillAlphaColor(ULong_t p)
Slot connected to the fill area color with alpha.
double f2(const double *x)
Float_t GetAlpha() const
Definition: TColor.h:66
TGedPatternSelect * fPatternSelect
TGColorSelect * fColorSelect
virtual void ConnectSignals2Slots()
Connect signals to slots.
const Bool_t kTRUE
Definition: Rtypes.h:91
TObject * obj
virtual void MakeTitle(const char *title)
Create attribute frame title.
Definition: TGedFrame.cxx:96
Int_t GetNumber() const
Definition: TColor.h:58
TGNumberEntryField * fAlphaField
Int_t fPriority
Definition: TGedFrame.h:61