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,
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));
59
61 fStyleCombo->Resize(137, 20);
64
66 fWidthCombo->Resize(90, 20);
67 f2->AddFrame(fWidthCombo, new TGLayoutHints(kLHintsLeft, 3, 1, 1, 1));
69
70 TGLabel *AlphaLabel = new TGLabel(this,"Opacity");
75 fAlpha->SetRange(0,1000);
80 fAlphaField->Resize(40,20);
81 if (!TCanvas::SupportAlpha()) {
83 AlphaLabel->Disable(kTRUE);
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
124
126
127 if (obj->InheritsFrom(TGraph::Class())) {
128 fWidthCombo->Select(std::abs(fAttLine->GetLineWidth()%100));
129 } else {
131 }
132
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;
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;
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
188
189
190////////////////////////////////////////////////////////////////////////////////
191/// Slot connected to the line width.
192
194{
195 if (fAvoidSignal) return;
196 if (dynamic_cast<TGraph*>(fAttLine)) {
198 if (graphLineWidth >= 0) {
200 } else {
202 }
203 } else if (fAttLine) {
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());
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);
233 }
234 Update();
235}
236
237////////////////////////////////////////////////////////////////////////////////
238/// Slot to set alpha value online.
239
241{
242 if (fAvoidSignal) return;
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: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
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
short Color_t
Color number (short)
Definition RtypesCore.h:99
unsigned long ULongptr_t
Unsigned integer large enough to hold a pointer (platform-dependent)
Definition RtypesCore.h:90
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
@ kALPHAFIELD
@ kCOLOR
@ kALPHA
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
@ 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:411
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.
Line Attributes class.
Definition TAttLine.h:20
virtual Color_t GetLineColor() const
Return the line color.
Definition TAttLine.h:35
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
Definition TAttLine.h:44
virtual Width_t GetLineWidth() const
Return the line width.
Definition TAttLine.h:37
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition TAttLine.h:45
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:42
virtual Style_t GetLineStyle() const
Return the line style.
Definition TAttLine.h:36
static Bool_t SupportAlpha()
Static function returning "true" if transparency is supported.
Definition TCanvas.cxx:2473
The color creation and management class.
Definition TColor.h:22
static ULong_t Number2Pixel(Int_t ci)
Static method that given a color index number, returns the corresponding pixel value.
Definition TColor.cxx:2445
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:1926
Float_t GetAlpha() const
Definition TColor.h:67
Int_t GetNumber() const
Definition TColor.h:59
static Int_t GetColorTransparent(Int_t color, Float_t a)
Static function: Returns the transparent color number corresponding to n.
Definition TColor.cxx:2182
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:289
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
void Resize(UInt_t w=0, UInt_t h=0) override
Resize the frame.
Definition TGFrame.cxx:597
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
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:107
virtual void SetRange(Int_t min, Int_t max)
Set slider range.
Definition TGSlider.cxx:96
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: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
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:543
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:865