Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
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/** \class TAttLineEditor
13 \ingroup ged
14
15Implements GUI for editing line attributes.
16 color, line width, line style
17
18*/
19
20
21#include "TAttLineEditor.h"
22#include "TGColorSelect.h"
23#include "TGComboBox.h"
24#include "TColor.h"
25#include "TGraph.h"
26#include "TGLabel.h"
27#include "TGSlider.h"
28#include "TGNumberEntry.h"
29#include "TCanvas.h"
30#include "TROOT.h"
31
32
33////////////////////////////////////////////////////////////////////////////////
34/// Constructor of line attributes GUI.
35
37 Int_t height, UInt_t options, Pixel_t back)
38 : TGedFrame(p, width, height, options | kVerticalFrame, back)
39{
40 enum ELineWid {
41 kCOLOR,
43 kLINE_STYLE,
44 kALPHA,
46 };
47
48 fPriority = 1;
49 fAttLine = 0;
50
51 MakeTitle("Line");
52
53 TGCompositeFrame *f2 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
54 AddFrame(f2, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
55
56 fColorSelect = new TGColorSelect(f2, 0, kCOLOR);
57 f2->AddFrame(fColorSelect, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
58 fColorSelect->Associate(this);
59
60 fStyleCombo = new TGLineStyleComboBox(this, kLINE_STYLE);
61 fStyleCombo->Resize(137, 20);
63 fStyleCombo->Associate(this);
64
66 fWidthCombo->Resize(90, 20);
67 f2->AddFrame(fWidthCombo, new TGLayoutHints(kLHintsLeft, 3, 1, 1, 1));
68 fWidthCombo->Associate(this);
69
70 TGLabel *AlphaLabel = new TGLabel(this,"Opacity");
71 AddFrame(AlphaLabel,
73 TGHorizontalFrame *f2a = new TGHorizontalFrame(this);
75 fAlpha->SetRange(0,1000);
80 fAlphaField->Resize(40,20);
81 if (!TCanvas::SupportAlpha()) {
82 fAlpha->SetEnabled(kFALSE);
83 AlphaLabel->Disable(kTRUE);
84 fAlphaField->SetEnabled(kFALSE);
85 }
88}
89
90////////////////////////////////////////////////////////////////////////////////
91/// Destructor of line editor.
92
96
97////////////////////////////////////////////////////////////////////////////////
98/// Connect signals to slots.
99
101{
102 fColorSelect->Connect("ColorSelected(Pixel_t)", "TAttLineEditor", this, "DoLineColor(Pixel_t)");
103 fColorSelect->Connect("AlphaColorSelected(ULong_t)", "TAttLineEditor", this, "DoLineAlphaColor(ULong_t)");
104 fStyleCombo->Connect("Selected(Int_t)", "TAttLineEditor", this, "DoLineStyle(Int_t)");
105 fWidthCombo->Connect("Selected(Int_t)", "TAttLineEditor", this, "DoLineWidth(Int_t)");
106 fAlpha->Connect("Released()","TAttLineEditor", this, "DoAlpha()");
107 fAlpha->Connect("PositionChanged(Int_t)","TAttLineEditor", this, "DoLiveAlpha(Int_t)");
108 fAlphaField->Connect("ReturnPressed()","TAttLineEditor", this, "DoAlphaField()");
109 fAlpha->Connect("Pressed()","TAttLineEditor", this, "GetCurAlpha()");
110
111 fInit = kFALSE;
112}
113
114////////////////////////////////////////////////////////////////////////////////
115/// Pick up the used line attributes.
116
118{
119 TAttLine *attline = dynamic_cast<TAttLine*>(obj);
120 if (!attline) return;
121
122 fAttLine = attline;
124
125 fStyleCombo->Select(fAttLine->GetLineStyle());
126
127 if (obj->InheritsFrom(TGraph::Class())) {
128 fWidthCombo->Select(std::abs(fAttLine->GetLineWidth()%100));
129 } else {
130 fWidthCombo->Select(fAttLine->GetLineWidth());
131 }
132
133 Color_t c = fAttLine->GetLineColor();
135 fColorSelect->SetColor(p);
136
138
140
141 if (TColor *color = gROOT->GetColor(fAttLine->GetLineColor())) {
142 fAlpha->SetPosition((Int_t)(color->GetAlpha()*1000));
143 fAlphaField->SetNumber(color->GetAlpha());
144 }
145}
146
147////////////////////////////////////////////////////////////////////////////////
148/// Slot connected to the line color.
149
151{
152 if (fAvoidSignal) return;
153 fAttLine->SetLineColor(TColor::GetColor(color));
154
155 if (TColor *tcolor = gROOT->GetColor(TColor::GetColor(color))) {
156 fAlpha->SetPosition((Int_t)(tcolor->GetAlpha()*1000));
157 fAlphaField->SetNumber(tcolor->GetAlpha());
158 }
159
160 Update();
161}
162
163
164////////////////////////////////////////////////////////////////////////////////
165/// Slot connected to the color with alpha.
166
168{
169 TColor *color = (TColor *)p;
170
171 if (fAvoidSignal) return;
172 fAttLine->SetLineColor(color->GetNumber());
173 fAlpha->SetPosition((Int_t)(color->GetAlpha()*1000));
174 fAlphaField->SetNumber(color->GetAlpha());
175
176 Update();
177}
178
179////////////////////////////////////////////////////////////////////////////////
180/// Slot connected to the line style.
181
183{
184 if (fAvoidSignal) return;
185 fAttLine->SetLineStyle(style);
186 Update();
187}
188
189
190////////////////////////////////////////////////////////////////////////////////
191/// Slot connected to the line width.
192
194{
195 if (fAvoidSignal) return;
196 if (dynamic_cast<TGraph*>(fAttLine)) {
197 Int_t graphLineWidth = 100*Int_t(fAttLine->GetLineWidth()/100);
198 if (graphLineWidth >= 0) {
199 fAttLine->SetLineWidth(graphLineWidth+width);
200 } else {
201 fAttLine->SetLineWidth(-(std::abs(graphLineWidth)+width));
202 }
203 } else if (fAttLine) {
204 fAttLine->SetLineWidth(width);
205 }
206 Update();
207}
208
209////////////////////////////////////////////////////////////////////////////////
210/// Slot to set the alpha value from the entry field.
211
213{
214 if (fAvoidSignal) return;
215
216 if (TColor *color = gROOT->GetColor(fAttLine->GetLineColor())) {
217 color->SetAlpha((Float_t)fAlphaField->GetNumber());
218 fAlpha->SetPosition((Int_t)fAlphaField->GetNumber()*1000);
219 }
220 Update();
221}
222
223////////////////////////////////////////////////////////////////////////////////
224/// Slot to set the alpha value
225
227{
228 if (fAvoidSignal) return;
229
230 if (TColor *color = gROOT->GetColor(fAttLine->GetLineColor())) {
231 color->SetAlpha((Float_t)fAlpha->GetPosition()/1000);
232 fAlphaField->SetNumber((Float_t)fAlpha->GetPosition()/1000);
233 }
234 Update();
235}
236
237////////////////////////////////////////////////////////////////////////////////
238/// Slot to set alpha value online.
239
241{
242 if (fAvoidSignal) return;
243 fAlphaField->SetNumber((Float_t)a/1000);
244
245 if (TColor *color = gROOT->GetColor(fAttLine->GetLineColor())) {
246 // In case the color is not transparent a new color is created.
247 if (color->GetAlpha() == 1.) {
248 fAttLine->SetLineColor(TColor::GetColorTransparent(color->GetNumber(),0.99));
249 } else {
250 color->SetAlpha((Float_t)a/1000);
251 }
252 }
253 Update();
254}
255
256////////////////////////////////////////////////////////////////////////////////
257/// Slot to update alpha value on click on Slider
258
260{
261 if (fAvoidSignal) return;
262
263 if (TColor *color = gROOT->GetColor(fAttLine->GetLineColor())) {
264 fAlpha->SetPosition((Int_t)(color->GetAlpha()*1000));
265 fAlphaField->SetNumber(color->GetAlpha());
266 }
267 Update();
268}
@ kLINE_WIDTH
@ kVerticalFrame
Definition GuiTypes.h:382
@ kHorizontalFrame
Definition GuiTypes.h:383
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:41
#define c(i)
Definition RSha256.hxx:101
#define a(i)
Definition RSha256.hxx:99
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
unsigned long ULongptr_t
Unsigned integer large enough to hold a pointer (platform-dependent).
Definition RtypesCore.h:90
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
Definition RtypesCore.h:60
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
short Color_t
Color number (short).
Definition RtypesCore.h:99
float Float_t
Float 4 bytes (float).
Definition RtypesCore.h:71
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
@ kALPHAFIELD
@ kCOLOR
@ kALPHA
@ kLHintsLeft
Definition TGLayout.h:24
@ kLHintsCenterY
Definition TGLayout.h:28
@ kLHintsTop
Definition TGLayout.h:27
@ kScaleNo
Definition TGSlider.h:34
@ kSlider2
Definition TGSlider.h:31
ELineWid
#define gROOT
Definition TROOT.h:417
void SetModel(TObject *obj) override
Pick up the used line attributes.
virtual void DoAlpha()
Slot to set the alpha value.
TGHSlider * fAlpha
fill opacity
virtual void DoLineColor(Pixel_t color)
Slot connected to the line color.
~TAttLineEditor() override
Destructor of line editor.
TAttLine * fAttLine
line attribute object
TAttLineEditor(const TGWindow *p=nullptr, Int_t width=140, Int_t height=30, UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground())
Constructor of line attributes GUI.
virtual void DoLineWidth(Int_t width)
Slot connected to the line width.
virtual void DoLineAlphaColor(ULongptr_t p)
Slot connected to the color with alpha.
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
line style combo box
virtual void DoLiveAlpha(Int_t a)
Slot to set alpha value online.
TGColorSelect * fColorSelect
line color widget
TGNumberEntryField * fAlphaField
TGLineWidthComboBox * fWidthCombo
line width combo box
virtual void ConnectSignals2Slots()
Connect signals to slots.
virtual void DoAlphaField()
Slot to set the alpha value from the entry field.
static Bool_t SupportAlpha()
Static function returning "true" if transparency is supported.
Definition TCanvas.cxx:2471
static Int_t GetColorTransparent(Int_t color, Float_t a)
static Int_t GetColor(const char *hexcolor)
static ULong_t Number2Pixel(Int_t ci)
Like a checkbutton but instead of the check mark there is color area with a little down arrow.
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1109
TGCompositeFrame(const TGCompositeFrame &)=delete
Concrete class for horizontal slider.
Definition TGSlider.h:119
A composite frame that layout their children in horizontal way.
Definition TGFrame.h:387
This class handles GUI labels.
Definition TGLabel.h:24
virtual void Disable(Bool_t on=kTRUE)
Definition TGLabel.h:89
This class describes layout hints used by the layout classes.
Definition TGLayout.h:50
The TGLineStyleComboBox user callable and it creates a combobox for selecting the line style.
Definition TGComboBox.h:140
The TGLineWidthComboBox user callable and it creates a combobox for selecting the line width.
Definition TGComboBox.h:158
@ kNEANonNegative
Non-negative number.
@ kNESReal
Real number.
ROOT GUI Window base class.
Definition TGWindow.h:23
TGedFrame(const TGedFrame &)=delete
Bool_t fInit
init flag for setting signals/slots
Definition TGedFrame.h:47
virtual void MakeTitle(const char *title)
Create attribute frame title.
Definition TGedFrame.cxx:94
virtual void Update()
Update the current pad when an attribute is changed via GUI.
Definition TGedFrame.cxx:71
Int_t fPriority
location in GedEditor
Definition TGedFrame.h:53
Bool_t fAvoidSignal
flag for executing slots
Definition TGedFrame.h:50
static TClass * Class()
Mother of all ROOT objects.
Definition TObject.h:42
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:549
TCanvas * style()
Definition style.C:1