Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
TAttMarkerEditor.cxx
Go to the documentation of this file.
1// @(#)root/ged:$Id$
2// Author: Ilka Antcheva 11/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 TAttMarkerEditor
13 \ingroup ged
14
15Implements GUI for editing marker attributes.
16 color, style and size
17
18*/
19
20
21#include "TAttMarkerEditor.h"
22#include "TAttMarker.h"
23#include "TGedMarkerSelect.h"
24#include "TGColorSelect.h"
25#include "TGNumberEntry.h"
26#include "TColor.h"
27#include "TGLabel.h"
28#include "TGSlider.h"
29#include "TCanvas.h"
30#include "TROOT.h"
31
32
40
41////////////////////////////////////////////////////////////////////////////////
42/// Constructor of marker attributes GUI.
43
45 Int_t height,UInt_t options, Pixel_t back)
46 : TGedFrame(p, width, height, options | kVerticalFrame, back)
47{
48 fAttMarker = 0;
50
51 MakeTitle("Marker");
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);
57
59 f2->AddFrame(fMarkerType, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
60 fMarkerType->Associate(this);
61
62 fMarkerSize = new TGNumberEntry(f2, 0., 4, kMARKER_SIZE,
66 fMarkerSize->GetNumberEntry()->SetToolTipText("Set marker size");
67 f2->AddFrame(fMarkerSize, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
68 fMarkerSize->Associate(this);
69 AddFrame(f2, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
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()) {
83 fAlpha->SetEnabled(kFALSE);
84 AlphaLabel->Disable(kTRUE);
85 fAlphaField->SetEnabled(kFALSE);
86 }
89}
90
91////////////////////////////////////////////////////////////////////////////////
92/// Destructor of marker editor.
93
97
98////////////////////////////////////////////////////////////////////////////////
99/// Connect signals to slots.
100
102{
103 fColorSelect->Connect("ColorSelected(Pixel_t)", "TAttMarkerEditor", this, "DoMarkerColor(Pixel_t)");
104 fColorSelect->Connect("AlphaColorSelected(ULong_t)", "TAttMarkerEditor", this, "DoMarkerAlphaColor(ULong_t)");
105 fMarkerType->Connect("MarkerSelected(Style_t)", "TAttMarkerEditor", this, "DoMarkerStyle(Style_t)");
106 fMarkerSize->Connect("ValueSet(Long_t)", "TAttMarkerEditor", this, "DoMarkerSize()");
107 (fMarkerSize->GetNumberEntry())->Connect("ReturnPressed()", "TAttMarkerEditor", this, "DoMarkerSize()");
108 fAlpha->Connect("Released()","TAttMarkerEditor", this, "DoAlpha()");
109 fAlpha->Connect("PositionChanged(Int_t)","TAttMarkerEditor", this, "DoLiveAlpha(Int_t)");
110 fAlphaField->Connect("ReturnPressed()","TAttMarkerEditor", this, "DoAlphaField()");
111 fAlpha->Connect("Pressed()","TAttMarkerEditor", this, "GetCurAlpha()");
112 fInit = kFALSE;
113}
114
115////////////////////////////////////////////////////////////////////////////////
116/// Pick up the values of used marker attributes.
117
119{
121
122 fAttMarker = dynamic_cast<TAttMarker *>(obj);
123 if (!fAttMarker) return;
124
125 TString str = GetDrawOption();
126 str.ToUpper();
127 if (obj->InheritsFrom("TH2") && str.Contains("TEXT")) {
129 } else {
131 }
132 Style_t marker = fAttMarker->GetMarkerStyle();
133 if ((marker==1 || marker==6 || marker==7) && !fSizeForText) {
134 fMarkerSize->SetNumber(1.);
135 fMarkerSize->SetState(kFALSE);
136 } else {
137 Float_t s = fAttMarker->GetMarkerSize();
138 fMarkerSize->SetState(kTRUE);
139 fMarkerSize->SetNumber(s);
140 }
141 fMarkerType->SetMarkerStyle(marker);
142
143 Color_t c = fAttMarker->GetMarkerColor();
145 fColorSelect->SetColor(p);
146
149
150 if (TColor *color = gROOT->GetColor(fAttMarker->GetMarkerColor())) {
151 fAlpha->SetPosition((Int_t)(color->GetAlpha()*1000));
152 fAlphaField->SetNumber(color->GetAlpha());
153 }
154}
155
156
157////////////////////////////////////////////////////////////////////////////////
158/// Slot connected to the marker color.
159
161{
162 if (fAvoidSignal) return;
163 fAttMarker->SetMarkerColor(TColor::GetColor(color));
164
165 if (TColor *tcolor = gROOT->GetColor(TColor::GetColor(color))) {
166 fAlpha->SetPosition((Int_t)(tcolor->GetAlpha()*1000));
167 fAlphaField->SetNumber(tcolor->GetAlpha());
168 }
169
170 Update();
171}
172
173////////////////////////////////////////////////////////////////////////////////
174/// Slot connected to the color with alpha.
175
177{
178 TColor *color = (TColor *)p;
179
180 if (fAvoidSignal) return;
181 fAttMarker->SetMarkerColor(color->GetNumber());
182 fAlpha->SetPosition((Int_t)(color->GetAlpha()*1000));
183 fAlphaField->SetNumber(color->GetAlpha());
184
185 Update();
186}
187
188////////////////////////////////////////////////////////////////////////////////
189/// Slot connected to the marker type.
190
192{
193 if (fAvoidSignal) return;
194 if ((marker==1 || marker==6 || marker==7) && !fSizeForText) {
195 fMarkerSize->SetNumber(1.);
196 fMarkerSize->SetState(kFALSE);
197 } else
198 fMarkerSize->SetState(kTRUE);
199
200 fAttMarker->SetMarkerStyle(marker);
201 Update();
202}
203
204////////////////////////////////////////////////////////////////////////////////
205/// Slot connected to the marker size.
206
208{
209 if (fAvoidSignal) return;
210 Style_t marker = fAttMarker->GetMarkerStyle();
211 if ((marker==1 || marker==6 || marker==7) && !fSizeForText) {
212 fMarkerSize->SetNumber(1.);
213 fMarkerSize->SetState(kFALSE);
214 } else
215 fMarkerSize->SetState(kTRUE);
216 Float_t size = fMarkerSize->GetNumber();
217 fAttMarker->SetMarkerSize(size);
218 Update();
219}
220
221////////////////////////////////////////////////////////////////////////////////
222/// Slot to set the alpha value from the entry field.
223
225{
226 if (fAvoidSignal) return;
227
228 if (TColor *color = gROOT->GetColor(fAttMarker->GetMarkerColor())) {
229 color->SetAlpha((Float_t)fAlphaField->GetNumber());
230 fAlpha->SetPosition((Int_t)fAlphaField->GetNumber()*1000);
231 }
232 Update();
233}
234
235////////////////////////////////////////////////////////////////////////////////
236/// Slot to set the alpha value
237
239{
240 if (fAvoidSignal) return;
241
242 if (TColor *color = gROOT->GetColor(fAttMarker->GetMarkerColor())) {
243 color->SetAlpha((Float_t)fAlpha->GetPosition()/1000);
244 fAlphaField->SetNumber((Float_t)fAlpha->GetPosition()/1000);
245 }
246 Update();
247}
248
249////////////////////////////////////////////////////////////////////////////////
250/// Slot to set alpha value online.
251
253{
254 if (fAvoidSignal) return;
255 fAlphaField->SetNumber((Float_t)a/1000);
256
257 if (TColor *color = gROOT->GetColor(fAttMarker->GetMarkerColor())) {
258 // In case the color is not transparent a new color is created.
259 if (color->GetAlpha() == 1.) {
260 fAttMarker->SetMarkerColor(TColor::GetColorTransparent(color->GetNumber(),0.99));
261 } else {
262 color->SetAlpha((Float_t)a/1000);
263 }
264 }
265 Update();
266}
267
268////////////////////////////////////////////////////////////////////////////////
269/// Slot to update alpha value on click on Slider
270
272{
273 if (fAvoidSignal) return;
274
275 if (TColor *color = gROOT->GetColor(fAttMarker->GetMarkerColor())) {
276 fAlpha->SetPosition((Int_t)(color->GetAlpha()*1000));
277 fAlphaField->SetNumber(color->GetAlpha());
278 }
279 Update();
280}
@ 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
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
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
@ kCOLOR
@ kALPHA
@ kMARKER_SIZE
@ kMARKER
@ 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 DoAlpha()
Slot to set the alpha value.
virtual void GetCurAlpha()
Slot to update alpha value on click on Slider.
void SetModel(TObject *obj) override
Pick up the values of used marker attributes.
Bool_t fSizeForText
true if "text" draw option uses marker size
TAttMarker * fAttMarker
marker attribute object
virtual void ConnectSignals2Slots()
Connect signals to slots.
~TAttMarkerEditor() override
Destructor of marker editor.
virtual void DoLiveAlpha(Int_t a)
Slot to set alpha value online.
TAttMarkerEditor(const TGWindow *p=nullptr, Int_t width=140, Int_t height=30, UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground())
Constructor of marker attributes GUI.
TGNumberEntryField * fAlphaField
virtual void DoMarkerStyle(Style_t style)
Slot connected to the marker type.
TGedMarkerSelect * fMarkerType
marker type
virtual void DoMarkerSize()
Slot connected to the marker size.
TGHSlider * fAlpha
fill opacity
virtual void DoMarkerColor(Pixel_t color)
Slot connected to the marker color.
TGColorSelect * fColorSelect
marker color
virtual void DoAlphaField()
Slot to set the alpha value from the entry field.
virtual void DoMarkerAlphaColor(ULongptr_t p)
Slot connected to the color with alpha.
TGNumberEntry * fMarkerSize
marker size combo box
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
TGNumberEntry is a number entry input widget with up/down buttons.
@ kNEANonNegative
Non-negative number.
@ kNESRealOne
Fixed fraction real, one digit.
@ kNESReal
Real number.
@ kNELLimitMinMax
Both lower and upper limits.
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
Option_t * GetDrawOption() const override
Get draw options of the selected object.
Definition TGedFrame.cxx:79
Bool_t fAvoidSignal
flag for executing slots
Definition TGedFrame.h:50
The TGedMarkerSelect widget is a button showing selected marker and a little down arrow.
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
Basic string class.
Definition TString.h:138