Logo ROOT   6.16/01
Reference Guide
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// //
14// TAttFillEditor //
15// //
16// Implements GUI for editing fill attributes. // //
17// color and fill style //
18// //
19//////////////////////////////////////////////////////////////////////////
20//Begin_Html
21/*
22<img src="gif/TAttFillEditor.gif">
23*/
24//End_Html
25
26#include "TAttFillEditor.h"
27#include "TGedPatternSelect.h"
28#include "TGColorSelect.h"
29#include "TColor.h"
30#include "TGLabel.h"
31#include "TGNumberEntry.h"
32#include "TPad.h"
33#include "TCanvas.h"
34#include "TROOT.h"
35
37
43};
44
45
46////////////////////////////////////////////////////////////////////////////////
47/// Constructor of fill attributes GUI.
48
50 Int_t height, UInt_t options, Pixel_t back)
51 : TGedFrame(p, width, height, options | kVerticalFrame, back)
52{
53 fPriority = 2;
54
55 fAttFill = 0;
56
57 MakeTitle("Fill");
58
59 TGCompositeFrame *f2 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
60 fColorSelect = new TGColorSelect(f2, 0, kCOLOR);
61 f2->AddFrame(fColorSelect, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
64 f2->AddFrame(fPatternSelect, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
66 AddFrame(f2, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
67
68 TGLabel *AlphaLabel = new TGLabel(this,"Opacity");
69 AddFrame(AlphaLabel,
71 TGHorizontalFrame *f2a = new TGHorizontalFrame(this);
73 fAlpha->SetRange(0,1000);
78 fAlphaField->Resize(40,20);
79 if (!TCanvas::SupportAlpha()) {
81 AlphaLabel->Disable(kTRUE);
83 }
86}
87
88////////////////////////////////////////////////////////////////////////////////
89/// Destructor of fill editor.
90
92{
93}
94
95////////////////////////////////////////////////////////////////////////////////
96/// Connect signals to slots.
97
99{
100 fColorSelect->Connect("ColorSelected(Pixel_t)", "TAttFillEditor", this, "DoFillColor(Pixel_t)");
101 fColorSelect->Connect("AlphaColorSelected(ULong_t)", "TAttFillEditor", this, "DoFillAlphaColor(ULong_t)");
102 fPatternSelect->Connect("PatternSelected(Style_t)", "TAttFillEditor", this, "DoFillPattern(Style_t)");
103 fAlpha->Connect("Released()","TAttFillEditor", this, "DoAlpha()");
104 fAlpha->Connect("PositionChanged(Int_t)","TAttFillEditor", this, "DoLiveAlpha(Int_t)");
105 fAlphaField->Connect("ReturnPressed()","TAttFillEditor", this, "DoAlphaField()");
106 fAlpha->Connect("Pressed()","TAttFillEditor", this, "GetCurAlpha()");
107 fInit = kFALSE;
108}
109
110////////////////////////////////////////////////////////////////////////////////
111/// Pick up the used fill attributes.
112
114{
115 TAttFill *attfill = dynamic_cast<TAttFill *>(obj);
116 if (!attfill) return;
117
118 fAttFill = attfill;
120
124
127
130
131 if (TColor *color = gROOT->GetColor(fAttFill->GetFillColor())) {
132 fAlpha->SetPosition((Int_t)(color->GetAlpha()*1000));
133 fAlphaField->SetNumber(color->GetAlpha());
134 }
135}
136
137////////////////////////////////////////////////////////////////////////////////
138/// Slot connected to the fill area color with alpha.
139
141{
142 TColor *color = (TColor *)p;
143
144 if (fAvoidSignal) return;
146 fAlpha->SetPosition((Int_t)(color->GetAlpha()*1000));
147 fAlphaField->SetNumber(color->GetAlpha());
148
149 Update();
150}
151
152////////////////////////////////////////////////////////////////////////////////
153/// Slot connected to the fill area color.
154
156{
157 if (fAvoidSignal) return;
159
160 if (TColor *tcolor = gROOT->GetColor(TColor::GetColor(color))) {
161 fAlpha->SetPosition((Int_t)(tcolor->GetAlpha()*1000));
162 fAlphaField->SetNumber(tcolor->GetAlpha());
163 }
164
165 Update();
166}
167
168////////////////////////////////////////////////////////////////////////////////
169/// Slot connected to the fill area pattern.
170
172{
173 if (fAvoidSignal) return;
174 fAttFill->SetFillStyle(pattern);
175 Update();
176}
177
178////////////////////////////////////////////////////////////////////////////////
179/// Slot to set the alpha value from the entry field.
180
182{
183 if (fAvoidSignal) return;
184
185 if (TColor *color = gROOT->GetColor(fAttFill->GetFillColor())) {
186 color->SetAlpha((Float_t)fAlphaField->GetNumber());
188 }
189 Update();
190}
191
192////////////////////////////////////////////////////////////////////////////////
193/// Slot to set the alpha value
194
196{
197 if (fAvoidSignal) return;
198
199 if (TColor *color = gROOT->GetColor(fAttFill->GetFillColor())) {
200 color->SetAlpha((Float_t)fAlpha->GetPosition()/1000);
202 }
203 Update();
204}
205
206////////////////////////////////////////////////////////////////////////////////
207/// Slot to set alpha value online.
208
210{
211 if (fAvoidSignal) return;
213
214 if (TColor *color = gROOT->GetColor(fAttFill->GetFillColor())) {
215 // In case the color is not transparent a new color is created.
216 if (color->GetAlpha() == 1.) {
217 fAttFill->SetFillColor(TColor::GetColorTransparent(color->GetNumber(),0.99));
218 } else {
219 color->SetAlpha((Float_t)a/1000);
220 }
221 }
222 Update();
223}
224
225////////////////////////////////////////////////////////////////////////////////
226/// Slot to update alpha value on click on Slider
227
229{
230 if (fAvoidSignal) return;
231
232 if (TColor *color = gROOT->GetColor(fAttFill->GetFillColor())) {
233 fAlpha->SetPosition((Int_t)(color->GetAlpha()*1000));
234 fAlphaField->SetNumber(color->GetAlpha());
235 }
236 Update();
237}
ULong_t Pixel_t
Definition: GuiTypes.h:39
#define c(i)
Definition: RSha256.hxx:101
int Int_t
Definition: RtypesCore.h:41
unsigned int UInt_t
Definition: RtypesCore.h:42
const Bool_t kFALSE
Definition: RtypesCore.h:88
unsigned long ULong_t
Definition: RtypesCore.h:51
short Color_t
Definition: RtypesCore.h:79
short Style_t
Definition: RtypesCore.h:76
float Float_t
Definition: RtypesCore.h:53
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassImp(name)
Definition: Rtypes.h:363
EFillWid
@ kALPHAFIELD
@ kPATTERN
@ kCOLOR
@ kALPHA
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:121
@ kVerticalFrame
Definition: TGFrame.h:59
@ kHorizontalFrame
Definition: TGFrame.h:60
@ 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
#define gROOT
Definition: TROOT.h:410
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.
virtual void DoFillPattern(Style_t color)
Slot connected to the fill area pattern.
TAttFillEditor(const TGWindow *p=0, Int_t width=140, Int_t height=30, UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground())
Constructor of fill attributes GUI.
TGColorSelect * fColorSelect
virtual void DoFillAlphaColor(ULong_t p)
Slot connected to the fill area color with alpha.
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.
TAttFill * fAttFill
TGHSlider * fAlpha
virtual void DoAlpha()
Slot to set the alpha value.
virtual void SetModel(TObject *obj)
Pick up the used fill attributes.
TGedPatternSelect * fPatternSelect
virtual ~TAttFillEditor()
Destructor of fill editor.
Fill Area Attributes class.
Definition: TAttFill.h:19
virtual Color_t GetFillColor() const
Return the fill area color.
Definition: TAttFill.h:30
virtual Style_t GetFillStyle() const
Return the fill area style.
Definition: TAttFill.h:31
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:37
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
Definition: TAttFill.h:39
static Bool_t SupportAlpha()
Static function returning "true" if transparency is supported.
Definition: TCanvas.cxx:2273
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:1997
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:1758
Float_t GetAlpha() const
Definition: TColor.h:62
Int_t GetNumber() const
Definition: TColor.h:54
static Int_t GetColorTransparent(Int_t color, Float_t a)
Static function: Returns the transparent color number corresponding to n.
Definition: TColor.cxx:1960
void SetColor(Pixel_t color, Bool_t emit=kTRUE)
Set color.
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:1099
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:587
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
void SetPattern(Style_t pattern, Bool_t emit=kTRUE)
Set pattern.
Mother of all ROOT objects.
Definition: TObject.h:37
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:867
static constexpr double s
auto * a
Definition: textangle.C:12