Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files 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 
38 ClassImp(TAttMarkerEditor);
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 
51 TAttMarkerEditor::TAttMarkerEditor(const TGWindow *p, Int_t width,
52  Int_t height,UInt_t options, Pixel_t back)
53  : TGedFrame(p, width, height, options | kVerticalFrame, back)
54 {
55  fAttMarker = 0;
56  fSizeForText = kFALSE;
57 
58  MakeTitle("Marker");
59 
60  TGCompositeFrame *f2 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
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,
70  TGNumberFormat::kNESRealOne,
71  TGNumberFormat::kNEANonNegative,
72  TGNumberFormat::kNELLimitMinMax, 0.2, 5.0);
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,
80  new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
81  TGHorizontalFrame *f2a = new TGHorizontalFrame(this);
82  fAlpha = new TGHSlider(f2a,100,kSlider2|kScaleNo,kALPHA);
83  fAlpha->SetRange(0,1000);
84  f2a->AddFrame(fAlpha,new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
85  fAlphaField = new TGNumberEntryField(f2a, kALPHAFIELD, 0,
86  TGNumberFormat::kNESReal,
87  TGNumberFormat::kNEANonNegative);
88  fAlphaField->Resize(40,20);
89  if (!TCanvas::SupportAlpha()) {
90  fAlpha->SetEnabled(kFALSE);
91  AlphaLabel->Disable(kTRUE);
92  fAlphaField->SetEnabled(kFALSE);
93  }
94  f2a->AddFrame(fAlphaField,new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
95  AddFrame(f2a, new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
96 }
97 
98 ////////////////////////////////////////////////////////////////////////////////
99 /// Destructor of marker editor.
100 
101 TAttMarkerEditor::~TAttMarkerEditor()
102 {
103 }
104 
105 ////////////////////////////////////////////////////////////////////////////////
106 /// Connect signals to slots.
107 
108 void TAttMarkerEditor::ConnectSignals2Slots()
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 
125 void TAttMarkerEditor::SetModel(TObject* obj)
126 {
127  fAvoidSignal = kTRUE;
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")) {
135  fSizeForText = kTRUE;
136  } else {
137  fSizeForText = kFALSE;
138  }
139  Style_t marker = fAttMarker->GetMarkerStyle();
140  if ((marker==1 || marker==6 || marker==7) && !fSizeForText) {
141  fMarkerSize->SetNumber(1.);
142  fMarkerSize->SetState(kFALSE);
143  } else {
144  Float_t s = fAttMarker->GetMarkerSize();
145  fMarkerSize->SetState(kTRUE);
146  fMarkerSize->SetNumber(s);
147  }
148  fMarkerType->SetMarkerStyle(marker);
149 
150  Color_t c = fAttMarker->GetMarkerColor();
151  Pixel_t p = TColor::Number2Pixel(c);
152  fColorSelect->SetColor(p);
153 
154  if (fInit) ConnectSignals2Slots();
155  fAvoidSignal = kFALSE;
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 
167 void TAttMarkerEditor::DoMarkerColor(Pixel_t color)
168 {
169  if (fAvoidSignal) return;
170  fAttMarker->SetMarkerColor(TColor::GetColor(color));
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 
183 void TAttMarkerEditor::DoMarkerAlphaColor(ULong_t p)
184 {
185  TColor *color = (TColor *)p;
186 
187  if (fAvoidSignal) return;
188  fAttMarker->SetMarkerColor(color->GetNumber());
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 
198 void TAttMarkerEditor::DoMarkerStyle(Style_t marker)
199 {
200  if (fAvoidSignal) return;
201  if ((marker==1 || marker==6 || marker==7) && !fSizeForText) {
202  fMarkerSize->SetNumber(1.);
203  fMarkerSize->SetState(kFALSE);
204  } else
205  fMarkerSize->SetState(kTRUE);
206 
207  fAttMarker->SetMarkerStyle(marker);
208  Update();
209 }
210 
211 ////////////////////////////////////////////////////////////////////////////////
212 /// Slot connected to the marker size.
213 
214 void TAttMarkerEditor::DoMarkerSize()
215 {
216  if (fAvoidSignal) return;
217  Style_t marker = fAttMarker->GetMarkerStyle();
218  if ((marker==1 || marker==6 || marker==7) && !fSizeForText) {
219  fMarkerSize->SetNumber(1.);
220  fMarkerSize->SetState(kFALSE);
221  } else
222  fMarkerSize->SetState(kTRUE);
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 
231 void TAttMarkerEditor::DoAlphaField()
232 {
233  if (fAvoidSignal) return;
234 
235  if (TColor *color = gROOT->GetColor(fAttMarker->GetMarkerColor())) {
236  color->SetAlpha((Float_t)fAlphaField->GetNumber());
237  fAlpha->SetPosition((Int_t)fAlphaField->GetNumber()*1000);
238  }
239  Update();
240 }
241 
242 ////////////////////////////////////////////////////////////////////////////////
243 /// Slot to set the alpha value
244 
245 void TAttMarkerEditor::DoAlpha()
246 {
247  if (fAvoidSignal) return;
248 
249  if (TColor *color = gROOT->GetColor(fAttMarker->GetMarkerColor())) {
250  color->SetAlpha((Float_t)fAlpha->GetPosition()/1000);
251  fAlphaField->SetNumber((Float_t)fAlpha->GetPosition()/1000);
252  }
253  Update();
254 }
255 
256 ////////////////////////////////////////////////////////////////////////////////
257 /// Slot to set alpha value online.
258 
259 void TAttMarkerEditor::DoLiveAlpha(Int_t a)
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 
278 void TAttMarkerEditor::GetCurAlpha()
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 }