Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
TAttFillEditor.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/** \class TAttFillEditor
14 \ingroup ged
15
16Implements GUI for editing fill attributes.
17 color and fill style
18
19*/
20
21#include "TAttFillEditor.h"
22#include "TGedPatternSelect.h"
23#include "TGColorSelect.h"
24#include "TColor.h"
25#include "TGLabel.h"
26#include "TGSlider.h"
27#include "TGNumberEntry.h"
28#include "TCanvas.h"
29#include "TROOT.h"
30
31
38
39
40////////////////////////////////////////////////////////////////////////////////
41/// Constructor of fill attributes GUI.
42
44 Int_t height, UInt_t options, Pixel_t back)
45 : TGedFrame(p, width, height, options | kVerticalFrame, back)
46{
47 fPriority = 2;
48
49 fAttFill = 0;
50
51 MakeTitle("Fill");
52
53 TGCompositeFrame *f2 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
54 fColorSelect = new TGColorSelect(f2, 0, kCOLOR);
55 f2->AddFrame(fColorSelect, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
56 fColorSelect->Associate(this);
58 f2->AddFrame(fPatternSelect, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
59 fPatternSelect->Associate(this);
60 AddFrame(f2, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
61
62 TGLabel *AlphaLabel = new TGLabel(this,"Opacity");
63 AddFrame(AlphaLabel,
65 TGHorizontalFrame *f2a = new TGHorizontalFrame(this);
67 fAlpha->SetRange(0,1000);
72 fAlphaField->Resize(40,20);
73 if (!TCanvas::SupportAlpha()) {
74 fAlpha->SetEnabled(kFALSE);
75 AlphaLabel->Disable(kTRUE);
76 fAlphaField->SetEnabled(kFALSE);
77 }
80}
81
82////////////////////////////////////////////////////////////////////////////////
83/// Destructor of fill editor.
84
88
89////////////////////////////////////////////////////////////////////////////////
90/// Connect signals to slots.
91
93{
94 fColorSelect->Connect("ColorSelected(Pixel_t)", "TAttFillEditor", this, "DoFillColor(Pixel_t)");
95 fColorSelect->Connect("AlphaColorSelected(ULong_t)", "TAttFillEditor", this, "DoFillAlphaColor(ULong_t)");
96 fPatternSelect->Connect("PatternSelected(Style_t)", "TAttFillEditor", this, "DoFillPattern(Style_t)");
97 fAlpha->Connect("Released()","TAttFillEditor", this, "DoAlpha()");
98 fAlpha->Connect("PositionChanged(Int_t)","TAttFillEditor", this, "DoLiveAlpha(Int_t)");
99 fAlphaField->Connect("ReturnPressed()","TAttFillEditor", this, "DoAlphaField()");
100 fAlpha->Connect("Pressed()","TAttFillEditor", this, "GetCurAlpha()");
101 fInit = kFALSE;
102}
103
104////////////////////////////////////////////////////////////////////////////////
105/// Pick up the used fill attributes.
106
108{
109 TAttFill *attfill = dynamic_cast<TAttFill *>(obj);
110 if (!attfill) return;
111
112 fAttFill = attfill;
114
115 Color_t c = fAttFill->GetFillColor();
117 fColorSelect->SetColor(p, kFALSE);
118
119 Style_t s = fAttFill->GetFillStyle();
120 fPatternSelect->SetPattern(s, kFALSE);
121
124
125 if (TColor *color = gROOT->GetColor(fAttFill->GetFillColor())) {
126 fAlpha->SetPosition((Int_t)(color->GetAlpha()*1000));
127 fAlphaField->SetNumber(color->GetAlpha());
128 }
129}
130
131////////////////////////////////////////////////////////////////////////////////
132/// Slot connected to the fill area color with alpha.
133
135{
136 TColor *color = (TColor *)p;
137
138 if (fAvoidSignal) return;
139 fAttFill->SetFillColor(color->GetNumber());
140 fAlpha->SetPosition((Int_t)(color->GetAlpha()*1000));
141 fAlphaField->SetNumber(color->GetAlpha());
142
143 Update();
144}
145
146////////////////////////////////////////////////////////////////////////////////
147/// Slot connected to the fill area color.
148
150{
151 if (fAvoidSignal) return;
152 fAttFill->SetFillColor(TColor::GetColor(color));
153
154 if (TColor *tcolor = gROOT->GetColor(TColor::GetColor(color))) {
155 fAlpha->SetPosition((Int_t)(tcolor->GetAlpha()*1000));
156 fAlphaField->SetNumber(tcolor->GetAlpha());
157 }
158
159 Update();
160}
161
162////////////////////////////////////////////////////////////////////////////////
163/// Slot connected to the fill area pattern.
164
166{
167 if (fAvoidSignal) return;
168 fAttFill->SetFillStyle(pattern);
169 Update();
170}
171
172////////////////////////////////////////////////////////////////////////////////
173/// Slot to set the alpha value from the entry field.
174
176{
177 if (fAvoidSignal) return;
178
179 if (TColor *color = gROOT->GetColor(fAttFill->GetFillColor())) {
180 color->SetAlpha((Float_t)fAlphaField->GetNumber());
181 fAlpha->SetPosition((Int_t)fAlphaField->GetNumber()*1000);
182 }
183 Update();
184}
185
186////////////////////////////////////////////////////////////////////////////////
187/// Slot to set the alpha value
188
190{
191 if (fAvoidSignal) return;
192
193 if (TColor *color = gROOT->GetColor(fAttFill->GetFillColor())) {
194 color->SetAlpha((Float_t)fAlpha->GetPosition()/1000);
195 fAlphaField->SetNumber((Float_t)fAlpha->GetPosition()/1000);
196 }
197 Update();
198}
199
200////////////////////////////////////////////////////////////////////////////////
201/// Slot to set alpha value online.
202
204{
205 if (fAvoidSignal) return;
206 fAlphaField->SetNumber((Float_t)a/1000);
207
208 if (TColor *color = gROOT->GetColor(fAttFill->GetFillColor())) {
209 // In case the color is not transparent a new color is created.
210 if (color->GetAlpha() == 1.) {
211 fAttFill->SetFillColor(TColor::GetColorTransparent(color->GetNumber(),0.99));
212 } else {
213 color->SetAlpha((Float_t)a/1000);
214 }
215 }
216 Update();
217}
218
219////////////////////////////////////////////////////////////////////////////////
220/// Slot to update alpha value on click on Slider
221
223{
224 if (fAvoidSignal) return;
225
226 if (TColor *color = gROOT->GetColor(fAttFill->GetFillColor())) {
227 fAlpha->SetPosition((Int_t)(color->GetAlpha()*1000));
228 fAlphaField->SetNumber(color->GetAlpha());
229 }
230 Update();
231}
@ 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
short Style_t
Style number (short).
Definition RtypesCore.h:96
float Float_t
Float 4 bytes (float).
Definition RtypesCore.h:71
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
@ kALPHAFIELD
@ kPATTERN
@ 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
#define gROOT
Definition TROOT.h:417
virtual void ConnectSignals2Slots()
Connect signals to slots.
virtual void GetCurAlpha()
Slot to update alpha value on click on Slider.
TGNumberEntryField * fAlphaField
virtual void DoFillColor(Pixel_t color)
Slot connected to the fill area color.
TAttFillEditor(const TGWindow *p=nullptr, Int_t width=140, Int_t height=30, UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground())
Constructor of fill attributes GUI.
void SetModel(TObject *obj) override
Pick up the used fill attributes.
virtual void DoFillPattern(Style_t color)
Slot connected to the fill area pattern.
TGColorSelect * fColorSelect
fill color widget
virtual void DoLiveAlpha(Int_t a)
Slot to set alpha value online.
virtual void DoAlphaField()
Slot to set the alpha value from the entry field.
~TAttFillEditor() override
Destructor of fill editor.
TAttFill * fAttFill
fill attribute object
TGHSlider * fAlpha
fill opacity
virtual void DoAlpha()
Slot to set the alpha value.
TGedPatternSelect * fPatternSelect
fill pattern widget
virtual void DoFillAlphaColor(ULongptr_t p)
Slot connected to the fill area color with alpha.
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
@ 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
is a button with pattern area with a little down arrow.
Mother of all ROOT objects.
Definition TObject.h:42