Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
36 ClassImp(TAttFillEditor);
37 
38 enum EFillWid {
39  kCOLOR,
40  kPATTERN,
41  kALPHA,
42  kALPHAFIELD
43 };
44 
45 
46 ////////////////////////////////////////////////////////////////////////////////
47 /// Constructor of fill attributes GUI.
48 
49 TAttFillEditor::TAttFillEditor(const TGWindow *p, Int_t width,
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));
62  fColorSelect->Associate(this);
63  fPatternSelect = new TGedPatternSelect(f2, 1, kPATTERN);
64  f2->AddFrame(fPatternSelect, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
65  fPatternSelect->Associate(this);
66  AddFrame(f2, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
67 
68  TGLabel *AlphaLabel = new TGLabel(this,"Opacity");
69  AddFrame(AlphaLabel,
70  new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
71  TGHorizontalFrame *f2a = new TGHorizontalFrame(this);
72  fAlpha = new TGHSlider(f2a,100,kSlider2|kScaleNo,kALPHA);
73  fAlpha->SetRange(0,1000);
74  f2a->AddFrame(fAlpha,new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
75  fAlphaField = new TGNumberEntryField(f2a, kALPHAFIELD, 0,
76  TGNumberFormat::kNESReal,
77  TGNumberFormat::kNEANonNegative);
78  fAlphaField->Resize(40,20);
79  if (!TCanvas::SupportAlpha()) {
80  fAlpha->SetEnabled(kFALSE);
81  AlphaLabel->Disable(kTRUE);
82  fAlphaField->SetEnabled(kFALSE);
83  }
84  f2a->AddFrame(fAlphaField,new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
85  AddFrame(f2a, new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
86 }
87 
88 ////////////////////////////////////////////////////////////////////////////////
89 /// Destructor of fill editor.
90 
91 TAttFillEditor::~TAttFillEditor()
92 {
93 }
94 
95 ////////////////////////////////////////////////////////////////////////////////
96 /// Connect signals to slots.
97 
98 void TAttFillEditor::ConnectSignals2Slots()
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 
113 void TAttFillEditor::SetModel(TObject* obj)
114 {
115  TAttFill *attfill = dynamic_cast<TAttFill *>(obj);
116  if (!attfill) return;
117 
118  fAttFill = attfill;
119  fAvoidSignal = kTRUE;
120 
121  Color_t c = fAttFill->GetFillColor();
122  Pixel_t p = TColor::Number2Pixel(c);
123  fColorSelect->SetColor(p, kFALSE);
124 
125  Style_t s = fAttFill->GetFillStyle();
126  fPatternSelect->SetPattern(s, kFALSE);
127 
128  if (fInit) ConnectSignals2Slots();
129  fAvoidSignal = kFALSE;
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 
140 void TAttFillEditor::DoFillAlphaColor(ULong_t p)
141 {
142  TColor *color = (TColor *)p;
143 
144  if (fAvoidSignal) return;
145  fAttFill->SetFillColor(color->GetNumber());
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 
155 void TAttFillEditor::DoFillColor(Pixel_t color)
156 {
157  if (fAvoidSignal) return;
158  fAttFill->SetFillColor(TColor::GetColor(color));
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 
171 void TAttFillEditor::DoFillPattern(Style_t pattern)
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 
181 void TAttFillEditor::DoAlphaField()
182 {
183  if (fAvoidSignal) return;
184 
185  if (TColor *color = gROOT->GetColor(fAttFill->GetFillColor())) {
186  color->SetAlpha((Float_t)fAlphaField->GetNumber());
187  fAlpha->SetPosition((Int_t)fAlphaField->GetNumber()*1000);
188  }
189  Update();
190 }
191 
192 ////////////////////////////////////////////////////////////////////////////////
193 /// Slot to set the alpha value
194 
195 void TAttFillEditor::DoAlpha()
196 {
197  if (fAvoidSignal) return;
198 
199  if (TColor *color = gROOT->GetColor(fAttFill->GetFillColor())) {
200  color->SetAlpha((Float_t)fAlpha->GetPosition()/1000);
201  fAlphaField->SetNumber((Float_t)fAlpha->GetPosition()/1000);
202  }
203  Update();
204 }
205 
206 ////////////////////////////////////////////////////////////////////////////////
207 /// Slot to set alpha value online.
208 
209 void TAttFillEditor::DoLiveAlpha(Int_t a)
210 {
211  if (fAvoidSignal) return;
212  fAlphaField->SetNumber((Float_t)a/1000);
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 
228 void TAttFillEditor::GetCurAlpha()
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 }