Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TEveRGBAPaletteEditor.cxx
Go to the documentation of this file.
1 // @(#)root/eve:$Id$
2 // Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2007, 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 #include "TEveRGBAPaletteEditor.h"
13 #include "TEveRGBAPalette.h"
14 #include "TEveGValuators.h"
15 
16 #include "TVirtualPad.h"
17 #include "TColor.h"
18 
19 #include "TGLabel.h"
20 #include "TGButton.h"
21 #include "TGComboBox.h"
22 #include "TGColorSelect.h"
23 #include "TGSlider.h"
24 #include "TGDoubleSlider.h"
25 
26 /** \class TEveRGBAPaletteSubEditor
27 \ingroup TEve
28 Sub-editor for TEveRGBAPalette class.
29 */
30 
31 ClassImp(TEveRGBAPaletteSubEditor);
32 
33 ////////////////////////////////////////////////////////////////////////////////
34 /// Constructor.
35 
36 TEveRGBAPaletteSubEditor::TEveRGBAPaletteSubEditor(const TGWindow* p) :
37  TGVerticalFrame(p),
38 
39  fM(0),
40 
41  fUnderflowAction (0),
42  fUnderColor (0),
43  fOverflowAction (0),
44  fOverColor (0),
45 
46  fMinMax(0), fOldMin(0), fOldMax(0),
47 
48  fInterpolate(0),
49  fShowDefValue(0),
50  fDefaultColor(0),
51  fFixColorRange(0)
52 {
53  {
54  TGHorizontalFrame* f = new TGHorizontalFrame(this);
55 
56  fInterpolate = new TGCheckButton(f, "Interpolate");
57  f->AddFrame(fInterpolate, new TGLayoutHints(kLHintsLeft, 3, 1, 1, 0));
58  fInterpolate->Connect("Toggled(Bool_t)",
59  "TEveRGBAPaletteSubEditor", this, "DoInterpolate()");
60 
61  AddFrame(f, new TGLayoutHints(kLHintsTop, 1, 1, 1, 0));
62  }
63 
64  {
65  TGHorizontalFrame* f = new TGHorizontalFrame(this);
66 
67  fShowDefValue = new TGCheckButton(f, "Show default value");
68  f->AddFrame(fShowDefValue, new TGLayoutHints(kLHintsLeft, 3, 1, 1, 0));
69  fShowDefValue->Connect("Toggled(Bool_t)",
70  "TEveRGBAPaletteSubEditor", this, "DoShowDefValue()");
71 
72  fDefaultColor = new TGColorSelect(f, 0, -1);
73  f->AddFrame(fDefaultColor, new TGLayoutHints(kLHintsLeft|kLHintsTop, 0, 0, 0, 0));
74  fDefaultColor->Connect("ColorSelected(Pixel_t)",
75  "TEveRGBAPaletteSubEditor", this, "DoDefaultColor(Pixel_t)");
76 
77  AddFrame(f, new TGLayoutHints(kLHintsTop, 1, 1, 2, 0));
78  }
79 
80  {
81  TGHorizontalFrame* f = new TGHorizontalFrame(this);
82 
83  fFixColorRange = new TGCheckButton(f, "Fix color range");
84  f->AddFrame(fFixColorRange, new TGLayoutHints(kLHintsLeft, 3, 1, 0, 0));
85  fFixColorRange->Connect("Toggled(Bool_t)",
86  "TEveRGBAPaletteSubEditor", this, "DoFixColorRange()");
87 
88  AddFrame(f, new TGLayoutHints(kLHintsTop, 1, 1, 0, 2));
89  }
90 
91  { // Underflow
92  TGHorizontalFrame* f = new TGHorizontalFrame(this);
93  TGLabel* lab = new TGLabel(f, "Underflow:");
94  f->AddFrame(lab, new TGLayoutHints(kLHintsLeft|kLHintsBottom, 1, 15, 1, 2));
95  fUnderflowAction = new TGComboBox(f);
96  fUnderflowAction->AddEntry("Cut", 0);
97  fUnderflowAction->AddEntry("Mark", 1);
98  fUnderflowAction->AddEntry("Clip", 2);
99  fUnderflowAction->AddEntry("Wrap", 3);
100  TGListBox* lb = fUnderflowAction->GetListBox();
101  lb->Resize(lb->GetWidth(), 4*16);
102  fUnderflowAction->Resize(59, 20);
103  fUnderflowAction->Connect("Selected(Int_t)", "TEveRGBAPaletteSubEditor", this,
104  "DoUnderflowAction(Int_t)");
105  f->AddFrame(fUnderflowAction, new TGLayoutHints(kLHintsLeft, 1, 2, 1, 1));
106 
107  fUnderColor = new TGColorSelect(f, 0, -1);
108  f->AddFrame(fUnderColor, new TGLayoutHints(kLHintsLeft|kLHintsTop, 1, 1, 0, 2));
109  fUnderColor->Connect("ColorSelected(Pixel_t)",
110  "TEveRGBAPaletteSubEditor", this, "DoUnderColor(Pixel_t)");
111 
112  AddFrame(f);
113  }
114 
115  { // Overflow
116  TGHorizontalFrame* f = new TGHorizontalFrame(this);
117  TGLabel* lab = new TGLabel(f, "Overflow:");
118  f->AddFrame(lab, new TGLayoutHints(kLHintsLeft|kLHintsBottom, 1, 20, 1, 2));
119  fOverflowAction = new TGComboBox(f);
120  fOverflowAction->AddEntry("Cut", 0);
121  fOverflowAction->AddEntry("Mark", 1);
122  fOverflowAction->AddEntry("Clip", 2);
123  fOverflowAction->AddEntry("Wrap", 3);
124  TGListBox* lb = fOverflowAction->GetListBox();
125  lb->Resize(lb->GetWidth(), 4*16);
126  fOverflowAction->Resize(59, 20);
127  fOverflowAction->Connect("Selected(Int_t)", "TEveRGBAPaletteSubEditor", this,
128  "DoOverflowAction(Int_t)");
129  f->AddFrame(fOverflowAction, new TGLayoutHints(kLHintsLeft, 1, 2, 1, 1));
130 
131  fOverColor = new TGColorSelect(f, 0, -1);
132  f->AddFrame(fOverColor, new TGLayoutHints(kLHintsLeft|kLHintsTop, 1, 1, 0, 2));
133  fOverColor->Connect("ColorSelected(Pixel_t)",
134  "TEveRGBAPaletteSubEditor", this, "DoOverColor(Pixel_t)");
135 
136  AddFrame(f);
137  }
138 
139  fMinMax = new TEveGDoubleValuator(this,"Main range:", 130, 0);
140  fMinMax->SetNELength(5);
141  fMinMax->SetLabelWidth(74);
142  fMinMax->Build();
143  fMinMax->GetSlider()->SetWidth(190);
144  fMinMax->SetLimits(0, 1023, TGNumberFormat::kNESInteger);
145  fMinMax->Connect("ValueSet()",
146  "TEveRGBAPaletteSubEditor", this, "DoMinMax()");
147  AddFrame(fMinMax, new TGLayoutHints(kLHintsTop, 1, 1, 1, 1));
148 }
149 
150 ////////////////////////////////////////////////////////////////////////////////
151 /// Set model object.
152 
153 void TEveRGBAPaletteSubEditor::SetModel(TEveRGBAPalette* p)
154 {
155  fM = p;
156 
157  if (fM->fUIDoubleRep)
158  {
159  fMinMax->SetValues(fM->IntToDouble(fM->fMinVal), fM->IntToDouble(fM->fMaxVal));
160  Double_t ll = fM->IntToDouble(fM->fLowLimit);
161  Double_t hl = fM->IntToDouble(fM->fHighLimit);
162  Int_t mgk = TMath::Min(3, TMath::Max(0, 3 - TMath::Nint(TMath::Log10(hl-ll))));
163  fMinMax->SetLimits(ll, hl, (TGNumberFormat::EStyle)(TGNumberFormat::kNESInteger + mgk));
164  fOldMin = fMinMax->GetMin();
165  fOldMax = fMinMax->GetMax();
166  }
167  else
168  {
169  fMinMax->SetValues(fM->fMinVal, fM->fMaxVal);
170  fMinMax->SetLimits(fM->fLowLimit, fM->fHighLimit, TGNumberFormat::kNESInteger);
171  }
172 
173  fInterpolate ->SetState(fM->fInterpolate ? kButtonDown : kButtonUp);
174  fShowDefValue ->SetState(fM->fShowDefValue ? kButtonDown : kButtonUp);
175  fDefaultColor ->SetColor(TColor::Number2Pixel(fM->GetDefaultColor()), kFALSE);
176  fFixColorRange->SetState(fM->fFixColorRange ? kButtonDown : kButtonUp);
177 
178  fUnderColor->SetColor(TColor::Number2Pixel(fM->GetUnderColor()), kFALSE);
179  fOverColor ->SetColor(TColor::Number2Pixel(fM->GetOverColor()), kFALSE);
180 
181  fUnderflowAction->Select(fM->fUnderflowAction, kFALSE);
182  fOverflowAction ->Select(fM->fOverflowAction, kFALSE);
183 }
184 
185 ////////////////////////////////////////////////////////////////////////////////
186 /// Emit "Changed()" signal.
187 
188 void TEveRGBAPaletteSubEditor::Changed()
189 {
190  Emit("Changed()");
191 }
192 
193 ////////////////////////////////////////////////////////////////////////////////
194 /// Slot for MinMax.
195 
196 void TEveRGBAPaletteSubEditor::DoMinMax()
197 {
198  if (fM->fUIDoubleRep)
199  {
200  Double_t min = fMinMax->GetMin();
201  if (min != fOldMin && fM->DoubleToInt(min) == fM->fMinVal)
202  {
203  if (min < fOldMin)
204  min = fM->IntToDouble(fM->fMinVal - 1);
205  else
206  min = fM->IntToDouble(fM->fMinVal + 1);
207  }
208  Double_t max = fMinMax->GetMax();
209  if (max != fOldMax && fM->DoubleToInt(max) == fM->fMaxVal)
210  {
211  if (max < fOldMax)
212  max = fM->IntToDouble(fM->fMaxVal - 1);
213  else
214  max = fM->IntToDouble(fM->fMaxVal + 1);
215  }
216  fM->SetMinMax(fM->DoubleToInt(min), fM->DoubleToInt(max));
217  }
218  else
219  {
220  fM->SetMinMax((Int_t) fMinMax->GetMin(), (Int_t) fMinMax->GetMax());
221  }
222 
223  Changed();
224  fM->MinMaxValChanged();
225 }
226 
227 ////////////////////////////////////////////////////////////////////////////////
228 /// Slot for Interpolate.
229 
230 void TEveRGBAPaletteSubEditor::DoInterpolate()
231 {
232  fM->SetInterpolate(fInterpolate->IsOn());
233  Changed();
234 }
235 
236 ////////////////////////////////////////////////////////////////////////////////
237 /// Slot for ShowDefValue.
238 
239 void TEveRGBAPaletteSubEditor::DoShowDefValue()
240 {
241  fM->SetShowDefValue(fShowDefValue->IsOn());
242  Changed();
243 }
244 
245 ////////////////////////////////////////////////////////////////////////////////
246 /// Slot for DefaultColor.
247 
248 void TEveRGBAPaletteSubEditor::DoDefaultColor(Pixel_t color)
249 {
250  fM->SetDefaultColorPixel(color);
251  Changed();
252 }
253 
254 ////////////////////////////////////////////////////////////////////////////////
255 /// Slot for FixColorRange.
256 
257 void TEveRGBAPaletteSubEditor::DoFixColorRange()
258 {
259  fM->SetFixColorRange(fFixColorRange->IsOn());
260  Changed();
261 }
262 
263 ////////////////////////////////////////////////////////////////////////////////
264 /// Slot for UnderColor.
265 
266 void TEveRGBAPaletteSubEditor::DoUnderColor(Pixel_t color)
267 {
268  fM->SetUnderColorPixel(color);
269  Changed();
270 }
271 
272 ////////////////////////////////////////////////////////////////////////////////
273 /// Slot for OverColor.
274 
275 void TEveRGBAPaletteSubEditor::DoOverColor(Pixel_t color)
276 {
277  fM->SetOverColorPixel(color);
278  Changed();
279 }
280 
281 ////////////////////////////////////////////////////////////////////////////////
282 /// Slot for UnderflowAction.
283 
284 void TEveRGBAPaletteSubEditor::DoUnderflowAction(Int_t mode)
285 {
286  fM->SetUnderflowAction(mode);
287  Changed();
288 }
289 
290 ////////////////////////////////////////////////////////////////////////////////
291 /// Slot for OverflowAction.
292 
293 void TEveRGBAPaletteSubEditor::DoOverflowAction(Int_t mode)
294 {
295  fM->SetOverflowAction(mode);
296  Changed();
297 }
298 
299 
300 /** \class TEveRGBAPaletteEditor
301 \ingroup TEve
302 Editor for TEveRGBAPalette class.
303 */
304 
305 ClassImp(TEveRGBAPaletteEditor);
306 
307 ////////////////////////////////////////////////////////////////////////////////
308 /// Constructor.
309 
310 TEveRGBAPaletteEditor::TEveRGBAPaletteEditor(const TGWindow *p, Int_t width, Int_t height,
311  UInt_t options, Pixel_t back) :
312  TGedFrame(p, width, height, options | kVerticalFrame, back),
313  fM (0),
314  fSE(0)
315 {
316  MakeTitle("TEveRGBAPalette");
317 
318  fSE = new TEveRGBAPaletteSubEditor(this);
319  AddFrame(fSE, new TGLayoutHints(kLHintsTop, 2, 0, 2, 2));
320  fSE->Connect("Changed()", "TEveRGBAPaletteEditor", this, "Update()");
321 }
322 
323 ////////////////////////////////////////////////////////////////////////////////
324 /// Set model object.
325 
326 void TEveRGBAPaletteEditor::SetModel(TObject* obj)
327 {
328  fM = dynamic_cast<TEveRGBAPalette*>(obj);
329  fSE->SetModel(fM);
330 }