Logo ROOT   6.08/07
Reference Guide
TAttLineEditor.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 // TAttLineEditor //
15 // //
16 // Implements GUI for editing line attributes. // //
17 // color, line width, line style //
18 // //
19 //////////////////////////////////////////////////////////////////////////
20 //Begin_Html
21 /*
22 <img src="gif/TAttLineEditor.gif">
23 */
24 //End_Html
25 
26 
27 #include "TAttLineEditor.h"
28 #include "TGColorSelect.h"
29 #include "TGComboBox.h"
30 #include "TColor.h"
31 #include "TGraph.h"
32 #include "TGLabel.h"
33 #include "TGNumberEntry.h"
34 #include "TPad.h"
35 #include "TCanvas.h"
36 #include "TROOT.h"
37 
39 
40 ////////////////////////////////////////////////////////////////////////////////
41 /// Constructor of line attributes GUI.
42 
44  Int_t height, UInt_t options, Pixel_t back)
45  : TGedFrame(p, width, height, options | kVerticalFrame, back)
46 {
47  enum ELineWid {
48  kCOLOR,
49  kLINE_WIDTH,
50  kLINE_STYLE,
51  kALPHA,
53  };
54 
55  fPriority = 1;
56  fAttLine = 0;
57 
58  MakeTitle("Line");
59 
61  AddFrame(f2, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
62 
63  fColorSelect = new TGColorSelect(f2, 0, kCOLOR);
64  f2->AddFrame(fColorSelect, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
65  fColorSelect->Associate(this);
66 
67  fStyleCombo = new TGLineStyleComboBox(this, kLINE_STYLE);
68  fStyleCombo->Resize(137, 20);
69  AddFrame(fStyleCombo, new TGLayoutHints(kLHintsLeft, 3, 1, 1, 1));
70  fStyleCombo->Associate(this);
71 
72  fWidthCombo = new TGLineWidthComboBox(f2, kLINE_WIDTH);
73  fWidthCombo->Resize(90, 20);
74  f2->AddFrame(fWidthCombo, new TGLayoutHints(kLHintsLeft, 3, 1, 1, 1));
75  fWidthCombo->Associate(this);
76 
77  TGLabel *AlphaLabel = new TGLabel(this,"Opacity");
78  AddFrame(AlphaLabel,
80  TGHorizontalFrame *f2a = new TGHorizontalFrame(this);
81  fAlpha = new TGHSlider(f2a,100,kSlider2|kScaleNo,kALPHA);
82  fAlpha->SetRange(0,1000);
84  fAlphaField = new TGNumberEntryField(f2a, kALPHAFIELD, 0,
87  fAlphaField->Resize(40,20);
88  if (!TCanvas::SupportAlpha()) {
89  fAlpha->SetEnabled(kFALSE);
90  AlphaLabel->Disable(kTRUE);
91  fAlphaField->SetEnabled(kFALSE);
92  }
93  f2a->AddFrame(fAlphaField,new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
94  AddFrame(f2a, new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
95 }
96 
97 ////////////////////////////////////////////////////////////////////////////////
98 /// Destructor of line editor.
99 
101 {
102 }
103 
104 ////////////////////////////////////////////////////////////////////////////////
105 /// Connect signals to slots.
106 
108 {
109  fColorSelect->Connect("ColorSelected(Pixel_t)", "TAttLineEditor", this, "DoLineColor(Pixel_t)");
110  fColorSelect->Connect("AlphaColorSelected(ULong_t)", "TAttLineEditor", this, "DoLineAlphaColor(ULong_t)");
111  fStyleCombo->Connect("Selected(Int_t)", "TAttLineEditor", this, "DoLineStyle(Int_t)");
112  fWidthCombo->Connect("Selected(Int_t)", "TAttLineEditor", this, "DoLineWidth(Int_t)");
113  fAlpha->Connect("Released()","TAttLineEditor", this, "DoAlpha()");
114  fAlpha->Connect("PositionChanged(Int_t)","TAttLineEditor", this, "DoLiveAlpha(Int_t)");
115  fAlphaField->Connect("ReturnPressed()","TAttLineEditor", this, "DoAlphaField()");
116  fAlpha->Connect("Pressed()","TAttLineEditor", this, "GetCurAlpha()");
117 
118  fInit = kFALSE;
119 }
120 
121 ////////////////////////////////////////////////////////////////////////////////
122 /// Pick up the used line attributes.
123 
125 {
126  TAttLine *attline = dynamic_cast<TAttLine*>(obj);
127  if (!attline) return;
128 
129  fAttLine = attline;
131 
133 
134  if (obj->InheritsFrom(TGraph::Class())) {
136  } else {
138  }
139 
143 
145 
147 
148  if (TColor *color = gROOT->GetColor(fAttLine->GetLineColor())) {
149  fAlpha->SetPosition((Int_t)(color->GetAlpha()*1000));
150  fAlphaField->SetNumber(color->GetAlpha());
151  }
152 }
153 
154 ////////////////////////////////////////////////////////////////////////////////
155 /// Slot connected to the line color.
156 
158 {
159  if (fAvoidSignal) return;
161 
162  if (TColor *tcolor = gROOT->GetColor(TColor::GetColor(color))) {
163  fAlpha->SetPosition((Int_t)(tcolor->GetAlpha()*1000));
164  fAlphaField->SetNumber(tcolor->GetAlpha());
165  }
166 
167  Update();
168 }
169 
170 
171 ////////////////////////////////////////////////////////////////////////////////
172 /// Slot connected to the color with alpha.
173 
175 {
176  TColor *color = (TColor *)p;
177 
178  if (fAvoidSignal) return;
179  fAttLine->SetLineColor(color->GetNumber());
180  fAlpha->SetPosition((Int_t)(color->GetAlpha()*1000));
181  fAlphaField->SetNumber(color->GetAlpha());
182 
183  Update();
184 }
185 
186 ////////////////////////////////////////////////////////////////////////////////
187 /// Slot connected to the line style.
188 
190 {
191  if (fAvoidSignal) return;
192  fAttLine->SetLineStyle(style);
193  Update();
194 }
195 
196 
197 ////////////////////////////////////////////////////////////////////////////////
198 /// Slot connected to the line width.
199 
201 {
202  if (fAvoidSignal) return;
203  if (dynamic_cast<TGraph*>(fAttLine)) {
204  Int_t graphLineWidth = 100*Int_t(fAttLine->GetLineWidth()/100);
205  if (graphLineWidth >= 0) {
206  fAttLine->SetLineWidth(graphLineWidth+width);
207  } else {
208  fAttLine->SetLineWidth(-(TMath::Abs(graphLineWidth)+width));
209  }
210  } else {
211  fAttLine->SetLineWidth(width);
212  }
213  Update();
214 }
215 
216 ////////////////////////////////////////////////////////////////////////////////
217 /// Slot to set the alpha value from the entry field.
218 
220 {
221  if (fAvoidSignal) return;
222 
223  if (TColor *color = gROOT->GetColor(fAttLine->GetLineColor())) {
224  color->SetAlpha((Float_t)fAlphaField->GetNumber());
226  }
227  Update();
228 }
229 
230 ////////////////////////////////////////////////////////////////////////////////
231 /// Slot to set the alpha value
232 
234 {
235  if (fAvoidSignal) return;
236 
237  if (TColor *color = gROOT->GetColor(fAttLine->GetLineColor())) {
238  color->SetAlpha((Float_t)fAlpha->GetPosition()/1000);
240  }
241  Update();
242 }
243 
244 ////////////////////////////////////////////////////////////////////////////////
245 /// Slot to set alpha value online.
246 
248 {
249  if (fAvoidSignal) return;
250  fAlphaField->SetNumber((Float_t)a/1000);
251 
252  if (TColor *color = gROOT->GetColor(fAttLine->GetLineColor())) {
253  // In case the color is not transparent a new color is created.
254  if (color->GetAlpha() == 1.) {
255  fAttLine->SetLineColor(TColor::GetColorTransparent(color->GetNumber(),0.99));
256  } else {
257  color->SetAlpha((Float_t)a/1000);
258  }
259  }
260  Update();
261 }
262 
263 ////////////////////////////////////////////////////////////////////////////////
264 /// Slot to update alpha value on click on Slider
265 
267 {
268  if (fAvoidSignal) return;
269 
270  if (TColor *color = gROOT->GetColor(fAttLine->GetLineColor())) {
271  fAlpha->SetPosition((Int_t)(color->GetAlpha()*1000));
272  fAlphaField->SetNumber(color->GetAlpha());
273  }
274  Update();
275 }
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition: TAttLine.h:49
virtual Int_t GetPosition() const
Definition: TGSlider.h:107
float Float_t
Definition: RtypesCore.h:53
return c
TGLineStyleComboBox * fStyleCombo
Float_t GetAlpha() const
Definition: TColor.h:66
void SetColor(Pixel_t color, Bool_t emit=kTRUE)
Set color.
#define gROOT
Definition: TROOT.h:364
virtual void DoAlphaField()
Slot to set the alpha value from the entry field.
int Int_t
Definition: RtypesCore.h:41
TArc * a
Definition: textangle.C:12
const Bool_t kFALSE
Definition: Rtypes.h:92
const char * Class
Definition: TXMLSetup.cxx:64
Short_t Abs(Short_t d)
Definition: TMathBase.h:110
virtual Width_t GetLineWidth() const
Return the line width.
Definition: TAttLine.h:41
virtual ~TAttLineEditor()
Destructor of line editor.
virtual void DoLineWidth(Int_t width)
Slot connected to the line width.
virtual Style_t GetLineStyle() const
Return the line style.
Definition: TAttLine.h:40
Bool_t fAvoidSignal
Definition: TGedFrame.h:58
ULong_t Pixel_t
Definition: GuiTypes.h:41
virtual void Update()
Update the current pad when an attribute is changed via GUI.
Definition: TGedFrame.cxx:73
virtual void Select(Int_t id, Bool_t emit=kTRUE)
Make the selected item visible in the combo box window and emit signals according to the second param...
Definition: TGComboBox.cxx:443
virtual Double_t GetNumber() const
Get the numeric value (floating point representation).
TGColorSelect * fColorSelect
short Color_t
Definition: RtypesCore.h:79
virtual void SetModel(TObject *obj)
Pick up the used line attributes.
static Bool_t SupportAlpha()
Static function returning "true" if transparency is supported.
Definition: TCanvas.cxx:2170
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:46
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:1137
virtual void Disable(Bool_t on=kTRUE)
Definition: TGLabel.h:103
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:488
virtual void DoLineColor(Pixel_t color)
Slot connected to the line color.
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:1706
static Int_t GetColorTransparent(Int_t color, Float_t a)
Static function: Returns the transparent color number corresponding to n.
Definition: TColor.cxx:1879
TGLineWidthComboBox * fWidthCombo
virtual Color_t GetLineColor() const
Return the line color.
Definition: TAttLine.h:39
static ULong_t Number2Pixel(Int_t ci)
Static method that given a color index number, returns the corresponding pixel value.
Definition: TColor.cxx:1916
virtual void DoLineAlphaColor(ULong_t p)
Slot connected to the color with alpha.
#define ClassImp(name)
Definition: Rtypes.h:279
unsigned long ULong_t
Definition: RtypesCore.h:51
TCanvas * style()
Definition: style.C:1
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
virtual void DoAlpha()
Slot to set the alpha value.
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
Definition: TAttLine.h:48
std::string MakeTitle(std::string_view version, std::string_view histname, std::string_view title, std::string_view axis)
Definition: speedtest.cxx:115
TGNumberEntryField * fAlphaField
Mother of all ROOT objects.
Definition: TObject.h:37
Bool_t fInit
Definition: TGedFrame.h:55
virtual void SetNumber(Double_t val)
Set the numeric value (floating point representation).
double f2(const double *x)
TAttLine * fAttLine
virtual void GetCurAlpha()
Slot to update alpha value on click on Slider.
Int_t GetNumber() const
Definition: TColor.h:58
virtual void DoLineStyle(Int_t style)
Slot connected to the line style.
TGHSlider * fAlpha
ELineWid
Definition: TLineEditor.cxx:34
const Bool_t kTRUE
Definition: Rtypes.h:91
virtual void ConnectSignals2Slots()
Connect signals to slots.
Line Attributes class.
Definition: TAttLine.h:24
virtual void DoLiveAlpha(Int_t a)
Slot to set alpha value online.