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 "TCanvas.h"
35#include "TROOT.h"
36
38
39////////////////////////////////////////////////////////////////////////////////
40/// Constructor of line attributes GUI.
41
43 Int_t height, UInt_t options, Pixel_t back)
44 : TGedFrame(p, width, height, options | kVerticalFrame, back)
45{
46 enum ELineWid {
47 kCOLOR,
48 kLINE_WIDTH,
49 kLINE_STYLE,
50 kALPHA,
52 };
53
54 fPriority = 1;
55 fAttLine = 0;
56
57 MakeTitle("Line");
58
59 TGCompositeFrame *f2 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
60 AddFrame(f2, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
61
62 fColorSelect = new TGColorSelect(f2, 0, kCOLOR);
63 f2->AddFrame(fColorSelect, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
65
66 fStyleCombo = new TGLineStyleComboBox(this, kLINE_STYLE);
67 fStyleCombo->Resize(137, 20);
70
71 fWidthCombo = new TGLineWidthComboBox(f2, kLINE_WIDTH);
72 fWidthCombo->Resize(90, 20);
73 f2->AddFrame(fWidthCombo, new TGLayoutHints(kLHintsLeft, 3, 1, 1, 1));
75
76 TGLabel *AlphaLabel = new TGLabel(this,"Opacity");
77 AddFrame(AlphaLabel,
79 TGHorizontalFrame *f2a = new TGHorizontalFrame(this);
81 fAlpha->SetRange(0,1000);
86 fAlphaField->Resize(40,20);
87 if (!TCanvas::SupportAlpha()) {
89 AlphaLabel->Disable(kTRUE);
91 }
94}
95
96////////////////////////////////////////////////////////////////////////////////
97/// Destructor of line editor.
98
100{
101}
102
103////////////////////////////////////////////////////////////////////////////////
104/// Connect signals to slots.
105
107{
108 fColorSelect->Connect("ColorSelected(Pixel_t)", "TAttLineEditor", this, "DoLineColor(Pixel_t)");
109 fColorSelect->Connect("AlphaColorSelected(ULong_t)", "TAttLineEditor", this, "DoLineAlphaColor(ULong_t)");
110 fStyleCombo->Connect("Selected(Int_t)", "TAttLineEditor", this, "DoLineStyle(Int_t)");
111 fWidthCombo->Connect("Selected(Int_t)", "TAttLineEditor", this, "DoLineWidth(Int_t)");
112 fAlpha->Connect("Released()","TAttLineEditor", this, "DoAlpha()");
113 fAlpha->Connect("PositionChanged(Int_t)","TAttLineEditor", this, "DoLiveAlpha(Int_t)");
114 fAlphaField->Connect("ReturnPressed()","TAttLineEditor", this, "DoAlphaField()");
115 fAlpha->Connect("Pressed()","TAttLineEditor", this, "GetCurAlpha()");
116
117 fInit = kFALSE;
118}
119
120////////////////////////////////////////////////////////////////////////////////
121/// Pick up the used line attributes.
122
124{
125 TAttLine *attline = dynamic_cast<TAttLine*>(obj);
126 if (!attline) return;
127
128 fAttLine = attline;
130
132
133 if (obj->InheritsFrom(TGraph::Class())) {
135 } else {
137 }
138
142
144
146
147 if (TColor *color = gROOT->GetColor(fAttLine->GetLineColor())) {
148 fAlpha->SetPosition((Int_t)(color->GetAlpha()*1000));
149 fAlphaField->SetNumber(color->GetAlpha());
150 }
151}
152
153////////////////////////////////////////////////////////////////////////////////
154/// Slot connected to the line color.
155
157{
158 if (fAvoidSignal) return;
160
161 if (TColor *tcolor = gROOT->GetColor(TColor::GetColor(color))) {
162 fAlpha->SetPosition((Int_t)(tcolor->GetAlpha()*1000));
163 fAlphaField->SetNumber(tcolor->GetAlpha());
164 }
165
166 Update();
167}
168
169
170////////////////////////////////////////////////////////////////////////////////
171/// Slot connected to the color with alpha.
172
174{
175 TColor *color = (TColor *)p;
176
177 if (fAvoidSignal) return;
179 fAlpha->SetPosition((Int_t)(color->GetAlpha()*1000));
180 fAlphaField->SetNumber(color->GetAlpha());
181
182 Update();
183}
184
185////////////////////////////////////////////////////////////////////////////////
186/// Slot connected to the line style.
187
189{
190 if (fAvoidSignal) return;
192 Update();
193}
194
195
196////////////////////////////////////////////////////////////////////////////////
197/// Slot connected to the line width.
198
200{
201 if (fAvoidSignal) return;
202 if (dynamic_cast<TGraph*>(fAttLine)) {
203 Int_t graphLineWidth = 100*Int_t(fAttLine->GetLineWidth()/100);
204 if (graphLineWidth >= 0) {
205 fAttLine->SetLineWidth(graphLineWidth+width);
206 } else {
207 fAttLine->SetLineWidth(-(TMath::Abs(graphLineWidth)+width));
208 }
209 } else {
211 }
212 Update();
213}
214
215////////////////////////////////////////////////////////////////////////////////
216/// Slot to set the alpha value from the entry field.
217
219{
220 if (fAvoidSignal) return;
221
222 if (TColor *color = gROOT->GetColor(fAttLine->GetLineColor())) {
223 color->SetAlpha((Float_t)fAlphaField->GetNumber());
225 }
226 Update();
227}
228
229////////////////////////////////////////////////////////////////////////////////
230/// Slot to set the alpha value
231
233{
234 if (fAvoidSignal) return;
235
236 if (TColor *color = gROOT->GetColor(fAttLine->GetLineColor())) {
237 color->SetAlpha((Float_t)fAlpha->GetPosition()/1000);
239 }
240 Update();
241}
242
243////////////////////////////////////////////////////////////////////////////////
244/// Slot to set alpha value online.
245
247{
248 if (fAvoidSignal) return;
250
251 if (TColor *color = gROOT->GetColor(fAttLine->GetLineColor())) {
252 // In case the color is not transparent a new color is created.
253 if (color->GetAlpha() == 1.) {
254 fAttLine->SetLineColor(TColor::GetColorTransparent(color->GetNumber(),0.99));
255 } else {
256 color->SetAlpha((Float_t)a/1000);
257 }
258 }
259 Update();
260}
261
262////////////////////////////////////////////////////////////////////////////////
263/// Slot to update alpha value on click on Slider
264
266{
267 if (fAvoidSignal) return;
268
269 if (TColor *color = gROOT->GetColor(fAttLine->GetLineColor())) {
270 fAlpha->SetPosition((Int_t)(color->GetAlpha()*1000));
271 fAlphaField->SetNumber(color->GetAlpha());
272 }
273 Update();
274}
void Class()
Definition: Class.C:29
@ kVerticalFrame
Definition: GuiTypes.h:381
@ kHorizontalFrame
Definition: GuiTypes.h:382
ULong_t Pixel_t
Definition: GuiTypes.h:39
#define c(i)
Definition: RSha256.hxx:101
int Int_t
Definition: RtypesCore.h:43
const Bool_t kFALSE
Definition: RtypesCore.h:90
unsigned long ULong_t
Definition: RtypesCore.h:53
short Color_t
Definition: RtypesCore.h:81
float Float_t
Definition: RtypesCore.h:55
const Bool_t kTRUE
Definition: RtypesCore.h:89
#define ClassImp(name)
Definition: Rtypes.h:361
@ kALPHAFIELD
@ kCOLOR
@ kALPHA
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:121
@ 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:406
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:2420
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:2016
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:1769
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:1979
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:451
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:1101
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:589
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 TGraph is an 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:866
Short_t Abs(Short_t d)
Definition: TMathBase.h:120
TCanvas * style()
Definition: style.C:1
auto * a
Definition: textangle.C:12