ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 //////////////////////////////////////////////////////////////////////////
13 // //
14 // TAttMarkerEditor //
15 // //
16 // Implements GUI for editing marker attributes. //
17 // color, style and size //
18 // //
19 //////////////////////////////////////////////////////////////////////////
20 //Begin_Html
21 /*
22 <img src="gif/TAttMarkerEditor.gif">
23 */
24 //End_Html
25 
26 
27 #include "TAttMarkerEditor.h"
28 #include "TGedMarkerSelect.h"
29 #include "TGColorSelect.h"
30 #include "TGNumberEntry.h"
31 #include "TColor.h"
32 #include "TGLabel.h"
33 #include "TGNumberEntry.h"
34 #include "TPad.h"
35 #include "TCanvas.h"
36 #include "TROOT.h"
37 
39 
40 enum EMarkerWid {
41  kCOLOR,
42  kMARKER,
43  kMARKER_SIZE,
44  kALPHA,
45  kALPHAFIELD
46 };
47 
48 ////////////////////////////////////////////////////////////////////////////////
49 /// Constructor of marker attributes GUI.
50 
52  Int_t height,UInt_t options, Pixel_t back)
53  : TGedFrame(p, width, height, options | kVerticalFrame, back)
54 {
55  fAttMarker = 0;
57 
58  MakeTitle("Marker");
59 
61  fColorSelect = new TGColorSelect(f2, 0, kCOLOR);
62  f2->AddFrame(fColorSelect, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
63  fColorSelect->Associate(this);
64 
65  fMarkerType = new TGedMarkerSelect(f2, 1, kMARKER);
66  f2->AddFrame(fMarkerType, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
67  fMarkerType->Associate(this);
68 
69  fMarkerSize = new TGNumberEntry(f2, 0., 4, kMARKER_SIZE,
73  fMarkerSize->GetNumberEntry()->SetToolTipText("Set marker size");
74  f2->AddFrame(fMarkerSize, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
75  fMarkerSize->Associate(this);
76  AddFrame(f2, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
77 
78  TGLabel *AlphaLabel = new TGLabel(this,"Opacity");
79  AddFrame(AlphaLabel,
81  TGHorizontalFrame *f2a = new TGHorizontalFrame(this);
82  fAlpha = new TGHSlider(f2a,100,kSlider2|kScaleNo,kALPHA);
83  fAlpha->SetRange(0,1000);
85  fAlphaField = new TGNumberEntryField(f2a, kALPHAFIELD, 0,
88  fAlphaField->Resize(40,20);
89  if (!TCanvas::SupportAlpha()) {
91  AlphaLabel->Disable(kTRUE);
93  }
96 }
97 
98 ////////////////////////////////////////////////////////////////////////////////
99 /// Destructor of marker editor.
100 
102 {
103 }
104 
105 ////////////////////////////////////////////////////////////////////////////////
106 /// Connect signals to slots.
107 
109 {
110  fColorSelect->Connect("ColorSelected(Pixel_t)", "TAttMarkerEditor", this, "DoMarkerColor(Pixel_t)");
111  fColorSelect->Connect("AlphaColorSelected(ULong_t)", "TAttMarkerEditor", this, "DoMarkerAlphaColor(ULong_t)");
112  fMarkerType->Connect("MarkerSelected(Style_t)", "TAttMarkerEditor", this, "DoMarkerStyle(Style_t)");
113  fMarkerSize->Connect("ValueSet(Long_t)", "TAttMarkerEditor", this, "DoMarkerSize()");
114  (fMarkerSize->GetNumberEntry())->Connect("ReturnPressed()", "TAttMarkerEditor", this, "DoMarkerSize()");
115  fAlpha->Connect("Released()","TAttMarkerEditor", this, "DoAlpha()");
116  fAlpha->Connect("PositionChanged(Int_t)","TAttMarkerEditor", this, "DoLiveAlpha(Int_t)");
117  fAlphaField->Connect("ReturnPressed()","TAttMarkerEditor", this, "DoAlphaField()");
118  fAlpha->Connect("Pressed()","TAttMarkerEditor", this, "GetCurAlpha()");
119  fInit = kFALSE;
120 }
121 
122 ////////////////////////////////////////////////////////////////////////////////
123 /// Pick up the values of used marker attributes.
124 
126 {
128 
129  fAttMarker = dynamic_cast<TAttMarker *>(obj);
130  if (!fAttMarker) return;
131 
132  TString str = GetDrawOption();
133  str.ToUpper();
134  if (obj->InheritsFrom("TH2") && str.Contains("TEXT")) {
136  } else {
138  }
139  Style_t marker = fAttMarker->GetMarkerStyle();
140  if ((marker==1 || marker==6 || marker==7) && !fSizeForText) {
141  fMarkerSize->SetNumber(1.);
143  } else {
147  }
148  fMarkerType->SetMarkerStyle(marker);
149 
153 
156 
157  if (TColor *color = gROOT->GetColor(fAttMarker->GetMarkerColor())) {
158  fAlpha->SetPosition((Int_t)(color->GetAlpha()*1000));
159  fAlphaField->SetNumber(color->GetAlpha());
160  }
161 }
162 
163 
164 ////////////////////////////////////////////////////////////////////////////////
165 /// Slot connected to the marker color.
166 
168 {
169  if (fAvoidSignal) return;
171 
172  if (TColor *tcolor = gROOT->GetColor(TColor::GetColor(color))) {
173  fAlpha->SetPosition((Int_t)(tcolor->GetAlpha()*1000));
174  fAlphaField->SetNumber(tcolor->GetAlpha());
175  }
176 
177  Update();
178 }
179 
180 ////////////////////////////////////////////////////////////////////////////////
181 /// Slot connected to the color with alpha.
182 
184 {
185  TColor *color = (TColor *)p;
186 
187  if (fAvoidSignal) return;
189  fAlpha->SetPosition((Int_t)(color->GetAlpha()*1000));
190  fAlphaField->SetNumber(color->GetAlpha());
191 
192  Update();
193 }
194 
195 ////////////////////////////////////////////////////////////////////////////////
196 /// Slot connected to the marker type.
197 
199 {
200  if (fAvoidSignal) return;
201  if ((marker==1 || marker==6 || marker==7) && !fSizeForText) {
202  fMarkerSize->SetNumber(1.);
204  } else
206 
207  fAttMarker->SetMarkerStyle(marker);
208  Update();
209 }
210 
211 ////////////////////////////////////////////////////////////////////////////////
212 /// Slot connected to the marker size.
213 
215 {
216  if (fAvoidSignal) return;
217  Style_t marker = fAttMarker->GetMarkerStyle();
218  if ((marker==1 || marker==6 || marker==7) && !fSizeForText) {
219  fMarkerSize->SetNumber(1.);
221  } else
223  Float_t size = fMarkerSize->GetNumber();
224  fAttMarker->SetMarkerSize(size);
225  Update();
226 }
227 
228 ////////////////////////////////////////////////////////////////////////////////
229 /// Slot to set the alpha value from the entry field.
230 
232 {
233  if (fAvoidSignal) return;
234 
235  if (TColor *color = gROOT->GetColor(fAttMarker->GetMarkerColor())) {
236  color->SetAlpha((Float_t)fAlphaField->GetNumber());
238  }
239  Update();
240 }
241 
242 ////////////////////////////////////////////////////////////////////////////////
243 /// Slot to set the alpha value
244 
246 {
247  if (fAvoidSignal) return;
248 
249  if (TColor *color = gROOT->GetColor(fAttMarker->GetMarkerColor())) {
250  color->SetAlpha((Float_t)fAlpha->GetPosition()/1000);
252  }
253  Update();
254 }
255 
256 ////////////////////////////////////////////////////////////////////////////////
257 /// Slot to set alpha value online.
258 
260 {
261  if (fAvoidSignal) return;
262  fAlphaField->SetNumber((Float_t)a/1000);
263 
264  if (TColor *color = gROOT->GetColor(fAttMarker->GetMarkerColor())) {
265  // In case the color is not transparent a new color is created.
266  if (color->GetAlpha() == 1.) {
267  fAttMarker->SetMarkerColor(TColor::GetColorTransparent(color->GetNumber(),0.99));
268  } else {
269  color->SetAlpha((Float_t)a/1000);
270  }
271  }
272  Update();
273 }
274 
275 ////////////////////////////////////////////////////////////////////////////////
276 /// Slot to update alpha value on click on Slider
277 
279 {
280  if (fAvoidSignal) return;
281 
282  if (TColor *color = gROOT->GetColor(fAttMarker->GetMarkerColor())) {
283  fAlpha->SetPosition((Int_t)(color->GetAlpha()*1000));
284  fAlphaField->SetNumber(color->GetAlpha());
285  }
286  Update();
287 }
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:587
short Style_t
Definition: RtypesCore.h:76
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:487
float Float_t
Definition: RtypesCore.h:53
virtual void SetRange(Int_t min, Int_t max)
Definition: TGSlider.h:105
return c
TAttMarker * fAttMarker
virtual void SetToolTipText(const char *text, Long_t delayms=500)
Set tool tip text associated with this text entry.
tuple f2
Definition: surfaces.py:24
void SetColor(Pixel_t color, Bool_t emit=kTRUE)
Set color.
virtual ~TAttMarkerEditor()
Destructor of marker editor.
virtual void SetNumber(Double_t val)
void ToUpper()
Change string to upper case.
Definition: TString.cxx:1088
void SetMarkerStyle(Style_t pattern)
Set marker.
virtual void DoMarkerAlphaColor(ULong_t p)
Slot connected to the color with alpha.
#define gROOT
Definition: TROOT.h:344
ClassImp(TAttMarkerEditor) enum EMarkerWid
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
TArc * a
Definition: textangle.C:12
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual void SetState(Bool_t enable=kTRUE)
Set the active state.
Marker Attributes class.
Definition: TAttMarker.h:32
TGHSlider * fAlpha
Bool_t fAvoidSignal
Definition: TGedFrame.h:58
TGNumberEntryField * GetNumberEntry() const
ULong_t Pixel_t
Definition: GuiTypes.h:41
TGedMarkerSelect * fMarkerType
virtual void Update()
Update the current pad when an attribute is changed via GUI.
Definition: TGedFrame.cxx:73
TGCompositeFrame(const TGCompositeFrame &)
virtual void SetMarkerColor(Color_t mcolor=1)
Definition: TAttMarker.h:51
virtual void DoMarkerColor(Pixel_t color)
Slot connected to the marker color.
short Color_t
Definition: RtypesCore.h:79
static Bool_t SupportAlpha()
Static function returning "true" if transparency is supported.
Definition: TCanvas.cxx:2169
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:1135
virtual void Associate(const TGWindow *w)
Make w the window that will receive the generated messages.
virtual void DoAlpha()
Slot to set the alpha value.
virtual Size_t GetMarkerSize() const
Definition: TAttMarker.h:46
virtual Int_t GetPosition() const
Definition: TGSlider.h:107
virtual void Disable(Bool_t on=kTRUE)
Definition: TGLabel.h:103
virtual void Associate(const TGWindow *w)
Definition: TGWidget.h:90
TGNumberEntryField * fAlphaField
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual void SetPosition(Int_t pos)
Definition: TGSlider.h:106
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:1023
virtual Double_t GetNumber() const
Get the numeric value (floating point representation).
virtual void SetMarkerStyle(Style_t mstyle=1)
Definition: TAttMarker.h:53
virtual void GetCurAlpha()
Slot to update alpha value on click on Slider.
virtual void SetMarkerSize(Size_t msize=1)
Definition: TAttMarker.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:1196
TGNumberEntry * fMarkerSize
static ULong_t Number2Pixel(Int_t ci)
Static method that given a color index number, returns the corresponding pixel value.
Definition: TColor.cxx:1219
void SetEnabled(Bool_t flag=kTRUE)
Definition: TGTextEntry.h:170
virtual void SetModel(TObject *obj)
Pick up the values of used marker attributes.
unsigned long ULong_t
Definition: RtypesCore.h:51
virtual void SetEnabled(Bool_t flag=kTRUE)
Definition: TGSlider.h:102
The color creation and management class.
Definition: TColor.h:47
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 DoMarkerSize()
Slot connected to the marker size.
virtual void ConnectSignals2Slots()
Connect signals to slots.
Mother of all ROOT objects.
Definition: TObject.h:58
virtual void DoLiveAlpha(Int_t a)
Slot to set alpha value online.
Bool_t fInit
Definition: TGedFrame.h:55
virtual Color_t GetMarkerColor() const
Definition: TAttMarker.h:44
virtual void SetNumber(Double_t val)
Set the numeric value (floating point representation).
virtual Option_t * GetDrawOption() const
Get draw options of the selected object.
Definition: TGedFrame.cxx:81
virtual void DoAlphaField()
Slot to set the alpha value from the entry field.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:567
TGColorSelect * fColorSelect
Float_t GetAlpha() const
Definition: TColor.h:91
virtual Double_t GetNumber() const
virtual void DoMarkerStyle(Style_t style)
Slot connected to the marker type.
TAttMarkerEditor(const TGWindow *p=0, Int_t width=140, Int_t height=30, UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground())
Constructor of marker attributes GUI.
virtual Style_t GetMarkerStyle() const
Definition: TAttMarker.h:45
const Bool_t kTRUE
Definition: Rtypes.h:91
TObject * obj
virtual void MakeTitle(const char *title)
Create attribute frame title.
Definition: TGedFrame.cxx:96
Int_t GetNumber() const
Definition: TColor.h:83