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
33
34////////////////////////////////////////////////////////////////////////////////
35/// Constructor of line attributes GUI.
36
38 Int_t height, UInt_t options, Pixel_t back)
39 : TGedFrame(p, width, height, options | kVerticalFrame, back)
40{
41 enum ELineWid {
42 kCOLOR,
44 kLINE_STYLE,
45 kALPHA,
47 };
48
49 fPriority = 1;
50 fAttLine = 0;
51
52 MakeTitle("Line");
53
54 TGCompositeFrame *f2 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
55 AddFrame(f2, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
56
57 fColorSelect = new TGColorSelect(f2, 0, kCOLOR);
58 f2->AddFrame(fColorSelect, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
60
61 fStyleCombo = new TGLineStyleComboBox(this, kLINE_STYLE);
62 fStyleCombo->Resize(137, 20);
65
67 fWidthCombo->Resize(90, 20);
68 f2->AddFrame(fWidthCombo, new TGLayoutHints(kLHintsLeft, 3, 1, 1, 1));
70
71 TGLabel *AlphaLabel = new TGLabel(this,"Opacity");
72 AddFrame(AlphaLabel,
74 TGHorizontalFrame *f2a = new TGHorizontalFrame(this);
76 fAlpha->SetRange(0,1000);
81 fAlphaField->Resize(40,20);
82 if (!TCanvas::SupportAlpha()) {
84 AlphaLabel->Disable(kTRUE);
86 }
89}
90
91////////////////////////////////////////////////////////////////////////////////
92/// Destructor of line editor.
93
95{
96}
97
98////////////////////////////////////////////////////////////////////////////////
99/// Connect signals to slots.
100
102{
103 fColorSelect->Connect("ColorSelected(Pixel_t)", "TAttLineEditor", this, "DoLineColor(Pixel_t)");
104 fColorSelect->Connect("AlphaColorSelected(ULong_t)", "TAttLineEditor", this, "DoLineAlphaColor(ULong_t)");
105 fStyleCombo->Connect("Selected(Int_t)", "TAttLineEditor", this, "DoLineStyle(Int_t)");
106 fWidthCombo->Connect("Selected(Int_t)", "TAttLineEditor", this, "DoLineWidth(Int_t)");
107 fAlpha->Connect("Released()","TAttLineEditor", this, "DoAlpha()");
108 fAlpha->Connect("PositionChanged(Int_t)","TAttLineEditor", this, "DoLiveAlpha(Int_t)");
109 fAlphaField->Connect("ReturnPressed()","TAttLineEditor", this, "DoAlphaField()");
110 fAlpha->Connect("Pressed()","TAttLineEditor", this, "GetCurAlpha()");
111
112 fInit = kFALSE;
113}
114
115////////////////////////////////////////////////////////////////////////////////
116/// Pick up the used line attributes.
117
119{
120 TAttLine *attline = dynamic_cast<TAttLine*>(obj);
121 if (!attline) return;
122
123 fAttLine = attline;
125
127
128 if (obj->InheritsFrom(TGraph::Class())) {
130 } else {
132 }
133
137
139
141
142 if (TColor *color = gROOT->GetColor(fAttLine->GetLineColor())) {
143 fAlpha->SetPosition((Int_t)(color->GetAlpha()*1000));
144 fAlphaField->SetNumber(color->GetAlpha());
145 }
146}
147
148////////////////////////////////////////////////////////////////////////////////
149/// Slot connected to the line color.
150
152{
153 if (fAvoidSignal) return;
155
156 if (TColor *tcolor = gROOT->GetColor(TColor::GetColor(color))) {
157 fAlpha->SetPosition((Int_t)(tcolor->GetAlpha()*1000));
158 fAlphaField->SetNumber(tcolor->GetAlpha());
159 }
160
161 Update();
162}
163
164
165////////////////////////////////////////////////////////////////////////////////
166/// Slot connected to the color with alpha.
167
169{
170 TColor *color = (TColor *)p;
171
172 if (fAvoidSignal) return;
174 fAlpha->SetPosition((Int_t)(color->GetAlpha()*1000));
175 fAlphaField->SetNumber(color->GetAlpha());
176
177 Update();
178}
179
180////////////////////////////////////////////////////////////////////////////////
181/// Slot connected to the line style.
182
184{
185 if (fAvoidSignal) return;
187 Update();
188}
189
190
191////////////////////////////////////////////////////////////////////////////////
192/// Slot connected to the line width.
193
195{
196 if (fAvoidSignal) return;
197 if (dynamic_cast<TGraph*>(fAttLine)) {
198 Int_t graphLineWidth = 100*Int_t(fAttLine->GetLineWidth()/100);
199 if (graphLineWidth >= 0) {
200 fAttLine->SetLineWidth(graphLineWidth+width);
201 } else {
202 fAttLine->SetLineWidth(-(TMath::Abs(graphLineWidth)+width));
203 }
204 } else if (fAttLine) {
206 }
207 Update();
208}
209
210////////////////////////////////////////////////////////////////////////////////
211/// Slot to set the alpha value from the entry field.
212
214{
215 if (fAvoidSignal) return;
216
217 if (TColor *color = gROOT->GetColor(fAttLine->GetLineColor())) {
218 color->SetAlpha((Float_t)fAlphaField->GetNumber());
220 }
221 Update();
222}
223
224////////////////////////////////////////////////////////////////////////////////
225/// Slot to set the alpha value
226
228{
229 if (fAvoidSignal) return;
230
231 if (TColor *color = gROOT->GetColor(fAttLine->GetLineColor())) {
232 color->SetAlpha((Float_t)fAlpha->GetPosition()/1000);
234 }
235 Update();
236}
237
238////////////////////////////////////////////////////////////////////////////////
239/// Slot to set alpha value online.
240
242{
243 if (fAvoidSignal) return;
245
246 if (TColor *color = gROOT->GetColor(fAttLine->GetLineColor())) {
247 // In case the color is not transparent a new color is created.
248 if (color->GetAlpha() == 1.) {
249 fAttLine->SetLineColor(TColor::GetColorTransparent(color->GetNumber(),0.99));
250 } else {
251 color->SetAlpha((Float_t)a/1000);
252 }
253 }
254 Update();
255}
256
257////////////////////////////////////////////////////////////////////////////////
258/// Slot to update alpha value on click on Slider
259
261{
262 if (fAvoidSignal) return;
263
264 if (TColor *color = gROOT->GetColor(fAttLine->GetLineColor())) {
265 fAlpha->SetPosition((Int_t)(color->GetAlpha()*1000));
266 fAlphaField->SetNumber(color->GetAlpha());
267 }
268 Update();
269}
@ kLINE_WIDTH
@ kVerticalFrame
Definition GuiTypes.h:381
@ kHorizontalFrame
Definition GuiTypes.h:382
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:40
#define c(i)
Definition RSha256.hxx:101
#define a(i)
Definition RSha256.hxx:99
int Int_t
Definition RtypesCore.h:45
short Color_t
Definition RtypesCore.h:92
unsigned long ULongptr_t
Definition RtypesCore.h:83
float Float_t
Definition RtypesCore.h:57
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:377
@ 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
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t width
Option_t Option_t style
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t height
ELineWid
#define gROOT
Definition TROOT.h:405
Implements GUI for editing line attributes.
virtual ~TAttLineEditor()
Destructor of line editor.
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.
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
virtual void SetModel(TObject *obj)
Pick up the used line attributes.
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.
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:2455
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:2082
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:1823
Float_t GetAlpha() const
Definition TColor.h:64
Int_t GetNumber() const
Definition TColor.h:56
static Int_t GetColorTransparent(Int_t color, Float_t a)
Static function: Returns the transparent color number corresponding to n.
Definition TColor.cxx:2034
Like a checkbutton but instead of the check mark there is color area with a little down arrow.
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...
The base class for composite widgets (menu bars, list boxes, etc.).
Definition TGFrame.h:287
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1117
void Resize(UInt_t w=0, UInt_t h=0) override
Resize the frame.
Definition TGFrame.cxx:605
Concrete class for horizontal slider.
Definition TGSlider.h:119
A composite frame that layout their children in horizontal way.
Definition TGFrame.h:385
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
virtual void SetNumber(Double_t val, Bool_t emit=kTRUE)
Set the numeric value (floating point representation).
virtual Double_t GetNumber() const
Get the numeric value (floating point representation).
@ kNEANonNegative
Non-negative number.
@ kNESReal
Real number.
virtual Int_t GetPosition() const
Definition TGSlider.h:77
virtual void SetPosition(Int_t pos)
Set slider position.
Definition TGSlider.cxx:110
virtual void SetRange(Int_t min, Int_t max)
Set slider range.
Definition TGSlider.cxx:99
virtual void SetEnabled(Bool_t flag=kTRUE)
Definition TGSlider.h:72
void SetEnabled(Bool_t flag=kTRUE)
virtual void Associate(const TGWindow *w)
Definition TGWidget.h:72
ROOT GUI Window base class.
Definition TGWindow.h:23
Base frame for implementing GUI - a service class.
Definition TGedFrame.h:27
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:95
virtual void Update()
Update the current pad when an attribute is changed via GUI.
Definition TGedFrame.cxx:72
Int_t fPriority
location in GedEditor
Definition TGedFrame.h:53
Bool_t fAvoidSignal
flag for executing slots
Definition TGedFrame.h:50
A TGraph is an object made of two arrays X and Y with npoints each.
Definition TGraph.h:41
static TClass * Class()
Mother of all ROOT objects.
Definition TObject.h:41
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:525
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:869
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:123