Logo ROOT  
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
60 TGCompositeFrame *f2 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
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));
66
67 fStyleCombo = new TGLineStyleComboBox(this, kLINE_STYLE);
68 fStyleCombo->Resize(137, 20);
71
72 fWidthCombo = new TGLineWidthComboBox(f2, kLINE_WIDTH);
73 fWidthCombo->Resize(90, 20);
74 f2->AddFrame(fWidthCombo, new TGLayoutHints(kLHintsLeft, 3, 1, 1, 1));
76
77 TGLabel *AlphaLabel = new TGLabel(this,"Opacity");
78 AddFrame(AlphaLabel,
80 TGHorizontalFrame *f2a = new TGHorizontalFrame(this);
82 fAlpha->SetRange(0,1000);
87 fAlphaField->Resize(40,20);
88 if (!TCanvas::SupportAlpha()) {
90 AlphaLabel->Disable(kTRUE);
92 }
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;
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;
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 {
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;
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}
void Class()
Definition: Class.C:29
ULong_t Pixel_t
Definition: GuiTypes.h:39
#define c(i)
Definition: RSha256.hxx:101
int Int_t
Definition: RtypesCore.h:41
unsigned int UInt_t
Definition: RtypesCore.h:42
const Bool_t kFALSE
Definition: RtypesCore.h:88
unsigned long ULong_t
Definition: RtypesCore.h:51
short Color_t
Definition: RtypesCore.h:79
float Float_t
Definition: RtypesCore.h:53
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassImp(name)
Definition: Rtypes.h:365
@ kALPHAFIELD
@ kCOLOR
@ kALPHA
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:121
@ kVerticalFrame
Definition: TGFrame.h:59
@ kHorizontalFrame
Definition: TGFrame.h:60
@ kLHintsLeft
Definition: TGLayout.h:31
@ kLHintsCenterY
Definition: TGLayout.h:35
@ kLHintsTop
Definition: TGLayout.h:34
@ kScaleNo
Definition: TGSlider.h:60
@ kSlider2
Definition: TGSlider.h:57
ELineWid
Definition: TLineEditor.cxx:34
#define gROOT
Definition: TROOT.h:415
virtual ~TAttLineEditor()
Destructor of line editor.
TAttLineEditor(const TGWindow *p=0, Int_t width=140, Int_t height=30, UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground())
Constructor of line attributes GUI.
virtual void DoAlpha()
Slot to set the alpha value.
TGHSlider * fAlpha
virtual void DoLineColor(Pixel_t color)
Slot connected to the line color.
virtual void DoLineAlphaColor(ULong_t p)
Slot connected to the color with alpha.
TAttLine * fAttLine
virtual void DoLineWidth(Int_t width)
Slot connected to the line width.
virtual void GetCurAlpha()
Slot to update alpha value on click on Slider.
virtual void DoLineStyle(Int_t style)
Slot connected to the line style.
TGLineStyleComboBox * fStyleCombo
virtual void DoLiveAlpha(Int_t a)
Slot to set alpha value online.
TGColorSelect * fColorSelect
TGNumberEntryField * fAlphaField
virtual void SetModel(TObject *obj)
Pick up the used line attributes.
TGLineWidthComboBox * fWidthCombo
virtual void ConnectSignals2Slots()
Connect signals to slots.
virtual void DoAlphaField()
Slot to set the alpha value from the entry field.
Line Attributes class.
Definition: TAttLine.h:18
virtual Color_t GetLineColor() const
Return the line color.
Definition: TAttLine.h:33
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
Definition: TAttLine.h:42
virtual Width_t GetLineWidth() const
Return the line width.
Definition: TAttLine.h:35
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition: TAttLine.h:43
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
virtual Style_t GetLineStyle() const
Return the line style.
Definition: TAttLine.h:34
static Bool_t SupportAlpha()
Static function returning "true" if transparency is supported.
Definition: TCanvas.cxx:2326
The color creation and management class.
Definition: TColor.h:19
static ULong_t Number2Pixel(Int_t ci)
Static method that given a color index number, returns the corresponding pixel value.
Definition: TColor.cxx:2003
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:1764
Float_t GetAlpha() const
Definition: TColor.h:63
Int_t GetNumber() const
Definition: TColor.h:55
static Int_t GetColorTransparent(Int_t color, Float_t a)
Static function: Returns the transparent color number corresponding to n.
Definition: TColor.cxx:1966
void SetColor(Pixel_t color, Bool_t emit=kTRUE)
Set color.
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:450
TGCompositeFrame(const TGCompositeFrame &)
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 Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:587
virtual void Disable(Bool_t on=kTRUE)
Definition: TGLabel.h:97
virtual Double_t GetNumber() const
Get the numeric value (floating point representation).
virtual void SetNumber(Double_t val)
Set the numeric value (floating point representation).
virtual Int_t GetPosition() const
Definition: TGSlider.h:109
virtual void SetPosition(Int_t pos)
Definition: TGSlider.h:105
virtual void SetRange(Int_t min, Int_t max)
Definition: TGSlider.h:101
virtual void SetEnabled(Bool_t flag=kTRUE)
Definition: TGSlider.h:98
void SetEnabled(Bool_t flag=kTRUE)
Definition: TGTextEntry.h:164
virtual void Associate(const TGWindow *w)
Definition: TGWidget.h:84
Bool_t fInit
Definition: TGedFrame.h:53
virtual void MakeTitle(const char *title)
Create attribute frame title.
Definition: TGedFrame.cxx:96
virtual void Update()
Update the current pad when an attribute is changed via GUI.
Definition: TGedFrame.cxx:73
Int_t fPriority
Definition: TGedFrame.h:59
Bool_t fAvoidSignal
Definition: TGedFrame.h:56
A Graph is a graphics object made of two arrays X and Y with npoints each.
Definition: TGraph.h:41
Mother of all ROOT objects.
Definition: TObject.h:37
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:443
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:867
Short_t Abs(Short_t d)
Definition: TMathBase.h:120
TCanvas * style()
Definition: style.C:1
auto * a
Definition: textangle.C:12