Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TGLPShapeObjEditor.cxx
Go to the documentation of this file.
1 // @(#)root/gl:$Id$
2 // Author: Matevz Tadel 25/09/2006
3 
4 #include <cstring>
5 
6 #include "TGLPShapeObjEditor.h"
7 #include "TGLPShapeObj.h"
8 #include "TGedEditor.h"
9 
10 #include "TG3DLine.h"
11 #include "TGButton.h"
12 #include "TGButtonGroup.h"
13 #include "TString.h"
14 #include "TGLabel.h"
15 #include "TClass.h"
16 #include "TGCanvas.h"
17 #include "TGTab.h"
18 #include "TGSlider.h"
19 #include "TGNumberEntry.h"
20 #include "TGButtonGroup.h"
21 #include "TROOT.h"
22 #include "TVirtualMutex.h"
23 
24 #include "TVirtualGL.h"
25 #include "TVirtualX.h"
26 #include "TGLViewer.h"
27 #include "TGLUtil.h"
28 #include "TGLPhysicalShape.h"
29 #include "TGLWidget.h"
30 #include "TGLIncludes.h"
31 
32 #include "Buttons.h"
33 
34 /** \class TGLPShapeObjEditor
35 \ingroup opengl
36 GUI editor for TGLPShapeObj.
37 */
38 
39 ClassImp(TGLPShapeObjEditor);
40 
41 enum EGeometry {
42  kCenterX,
43  kCenterY,
44  kCenterZ,
45  kScaleX,
46  kScaleY,
47  kScaleZ,
48  kTot
49 };
50 
51 enum EApplyButtonIds {
52  kTBcp,
53  kTBcpm,
54  kTBda,
55  kTBa,
56  kTBaf,
57  kTBEndOfList
58 };
59 
60 enum EGLEditorIdent {
61  kCPa = kTBEndOfList + 1,
62  kCPd, kCPs, kCPe,
63  kHSr, kHSg, kHSb,
64  kHSa, kHSs, kHSe,
65  kNExc, kNEyc, kNEzc,
66  kNExs, kNEys, kNEzs,
67  kNExp, kNEyp, kNEzp,
68  kNEat
69 };
70 
71 ////////////////////////////////////////////////////////////////////////////////
72 /// Constructor of TGLPhysicalShape editor GUI.
73 
74 TGLPShapeObjEditor::TGLPShapeObjEditor(const TGWindow *p, Int_t width, Int_t height, UInt_t options, Pixel_t back)
75  : TGedFrame(p, width, height, options | kVerticalFrame, back),
76  fLb(kLHintsTop | kLHintsCenterX | kLHintsExpandX, 2, 2, 3, 3), //button
77  fLe(kLHintsTop | kLHintsCenterX | kLHintsExpandX, 0, 0, 3, 3), //entries
78  fLl(kLHintsLeft, 0, 8, 6, 0), // labels
79  fLs(kLHintsTop | kLHintsCenterX, 2, 2, 0, 0), ///sliders
80  fGeoFrame(0),fGeoApplyButton(0),
81  fColorFrame(0),
82  fRedSlider(0), fGreenSlider(0), fBlueSlider(0), fAlphaSlider(0), fShineSlider(0),
83  fColorApplyButton(0), fColorApplyFamily(0),
84  fRGBA(),
85  fPShapeObj(0)
86 {
87  fRGBA[12] = fRGBA[13] = fRGBA[14] = 0.0f;
88  fRGBA[15] = 1.0f;
89  fRGBA[16] = 60.0f;
90 
91  CreateColorControls();
92  CreateGeoControls();
93 }
94 
95 ////////////////////////////////////////////////////////////////////////////////
96 /// Destroy color editor GUI component.
97 /// Done automatically.
98 
99 TGLPShapeObjEditor::~TGLPShapeObjEditor()
100 {
101 }
102 
103 ////////////////////////////////////////////////////////////////////////////////
104 /// Shape has changed.
105 /// Check if set to zero and make sure we're no longer in editor.
106 
107 void TGLPShapeObjEditor::SetPShape(TGLPhysicalShape * shape)
108 {
109  TGLPShapeRef::SetPShape(shape);
110  if (shape == 0 && fGedEditor->GetModel() == fPShapeObj)
111  fGedEditor->SetModel(fGedEditor->GetPad(), fPShapeObj->fViewer, kButton1Down);
112 }
113 
114 ////////////////////////////////////////////////////////////////////////////////
115 /// Shape has been modified.
116 /// Update editor if we're still shown. Otherwise unref.
117 
118 void TGLPShapeObjEditor::PShapeModified()
119 {
120  if (fGedEditor->GetModel() == fPShapeObj)
121  fGedEditor->SetModel(fGedEditor->GetPad(), fPShapeObj, kButton1Down);
122  else
123  SetPShape(0);
124 }
125 
126 ////////////////////////////////////////////////////////////////////////////////
127 /// Sets model or disables/hides viewer.
128 
129 void TGLPShapeObjEditor::SetModel(TObject* obj)
130 {
131  fPShapeObj = 0;
132 
133  fPShapeObj = static_cast<TGLPShapeObj *>(obj);
134  SetPShape(fPShapeObj->fPShape);
135 
136  SetRGBA(fPShapeObj->fPShape->Color());
137  SetCenter(fPShapeObj->fPShape->GetTranslation().CArr());
138  SetScale(fPShapeObj->fPShape->GetScale().CArr());
139  fGeoApplyButton->SetState(kButtonDisabled);
140 }
141 
142 ////////////////////////////////////////////////////////////////////////////////
143 /// Set internal center data from 3 component 'c'.
144 
145 void TGLPShapeObjEditor::SetCenter(const Double_t *c)
146 {
147  fGeomData[kCenterX]->SetNumber(c[0]);
148  fGeomData[kCenterY]->SetNumber(c[1]);
149  fGeomData[kCenterZ]->SetNumber(c[2]);
150 }
151 
152 ////////////////////////////////////////////////////////////////////////////////
153 /// Set internal scale data from 3 component 'c'.
154 
155 void TGLPShapeObjEditor::SetScale(const Double_t *s)
156 {
157  fGeomData[kScaleX]->SetNumber(s[0]);
158  fGeomData[kScaleY]->SetNumber(s[1]);
159  fGeomData[kScaleZ]->SetNumber(s[2]);
160 }
161 
162 ////////////////////////////////////////////////////////////////////////////////
163 /// Process 'Apply' - update the viewer object from GUI.
164 
165 void TGLPShapeObjEditor::DoGeoButton()
166 {
167  TGLVertex3 trans;
168  TGLVector3 scale;
169  GetObjectData(trans.Arr(), scale.Arr());
170  if (fPShape) {
171  fPShape->SetTranslation(trans);
172  fPShape->Scale(scale);
173  }
174  fPShapeObj->fViewer->RequestDraw();
175  fGeoApplyButton->SetState(kButtonDisabled);
176 }
177 
178 ////////////////////////////////////////////////////////////////////////////////
179 /// Extract the GUI object data, return center in 3 component 'center'
180 /// scale in 3 component 'scale'.
181 
182 void TGLPShapeObjEditor::GetObjectData(Double_t *center, Double_t *scale)
183 {
184  center[0] = fGeomData[kCenterX]->GetNumber();
185  center[1] = fGeomData[kCenterY]->GetNumber();
186  center[2] = fGeomData[kCenterZ]->GetNumber();
187  scale[0] = fGeomData[kScaleX]->GetNumber();
188  scale[1] = fGeomData[kScaleY]->GetNumber();
189  scale[2] = fGeomData[kScaleZ]->GetNumber();
190 }
191 
192 ////////////////////////////////////////////////////////////////////////////////
193 /// Process setting of value in edit box - activate 'Apply' button.
194 
195 void TGLPShapeObjEditor::GeoValueSet(Long_t)
196 {
197  if (fGeoApplyButton->GetState() != kButtonUp)
198  fGeoApplyButton->SetState(kButtonUp);
199 }
200 
201 ////////////////////////////////////////////////////////////////////////////////
202 /// Create GUI for setting scale and position.
203 
204 void TGLPShapeObjEditor::CreateGeoControls()
205 {
206  fGeoFrame = CreateEditorTabSubFrame("Geometry");
207 
208  TGLabel *label=0;
209 
210  // Postion container
211  TGGroupFrame* container = new TGGroupFrame(fGeoFrame, "Object position:");
212  container->SetTitlePos(TGGroupFrame::kLeft);
213  fGeoFrame->AddFrame(container, new TGLayoutHints(kLHintsTop | kLHintsCenterX | kLHintsExpandX, 8, 8, 3, 3));//-
214  TGLayoutHints lh = TGLayoutHints(kLHintsTop | kLHintsCenterX | kLHintsExpandX, 0, 0, 0, 0);
215 
216  TGHorizontalFrame* hf;
217 
218  hf = new TGHorizontalFrame(container);
219  label = new TGLabel(hf, "X:");
220  hf->AddFrame(label, new TGLayoutHints(fLl));
221  fGeomData[kCenterX] = new TGNumberEntry(hf, 0.0, 8, kNExc);
222  hf->AddFrame(fGeomData[kCenterX], new TGLayoutHints(fLe));
223  fGeomData[kCenterX]->Connect("ValueSet(Long_t)", "TGLPShapeObjEditor",
224  this, "GeoValueSet(Long_t)");
225  container->AddFrame(hf, new TGLayoutHints(lh));
226 
227  hf = new TGHorizontalFrame(container);
228  label = new TGLabel(hf, "Y:");
229  hf->AddFrame(label, new TGLayoutHints(fLl));
230  fGeomData[kCenterY] = new TGNumberEntry(hf, 0.0, 8, kNEyc);
231  hf->AddFrame(fGeomData[kCenterY], new TGLayoutHints(fLe));
232  fGeomData[kCenterY]->Connect("ValueSet(Long_t)", "TGLPShapeObjEditor",
233  this, "GeoValueSet(Long_t)");
234  container->AddFrame(hf, new TGLayoutHints(lh));
235 
236  hf = new TGHorizontalFrame(container);
237  hf->AddFrame(new TGLabel(hf, "Z:"), new TGLayoutHints(fLl));
238  fGeomData[kCenterZ] = new TGNumberEntry(hf, 1.0, 8, kNEzc);
239  hf->AddFrame(fGeomData[kCenterZ], new TGLayoutHints(fLe));
240  fGeomData[kCenterZ]->Connect("ValueSet(Long_t)", "TGLPShapeObjEditor",
241  this, "GeoValueSet(Long_t)");
242  container->AddFrame(hf, new TGLayoutHints(lh));
243 
244  // Scale container
245  TGGroupFrame* osf = new TGGroupFrame(fGeoFrame, "Object scale:", kLHintsTop | kLHintsCenterX);
246  osf->SetTitlePos(TGGroupFrame::kLeft);
247  fGeoFrame->AddFrame(osf, new TGLayoutHints(kLHintsTop | kLHintsCenterX | kLHintsExpandX, 8, 8, 3, 3));
248 
249  hf = new TGHorizontalFrame(osf);
250  hf->AddFrame(new TGLabel(hf, "X:"),new TGLayoutHints(fLl));
251  fGeomData[kScaleX] = new TGNumberEntry(hf, 1.0, 5, kNExs);
252  hf->AddFrame(fGeomData[kScaleX], new TGLayoutHints(fLe));
253  fGeomData[kScaleX]->Connect("ValueSet(Long_t)", "TGLPShapeObjEditor",
254  this, "GeoValueSet(Long_t)");
255  osf->AddFrame(hf, new TGLayoutHints(lh));
256 
257  hf = new TGHorizontalFrame(osf);
258  hf->AddFrame(new TGLabel(hf, "Y:"),new TGLayoutHints(fLl));
259  fGeomData[kScaleY] = new TGNumberEntry(hf, 1.0, 5, kNEys);
260  hf->AddFrame(fGeomData[kScaleY], new TGLayoutHints(fLe));
261  fGeomData[kScaleY]->Connect("ValueSet(Long_t)", "TGLPShapeObjEditor",
262  this, "GeoValueSet(Long_t)");
263  osf->AddFrame(hf, new TGLayoutHints(lh));
264 
265  hf = new TGHorizontalFrame(osf);
266  hf->AddFrame(new TGLabel(hf, "Z:"),new TGLayoutHints(fLl));
267  fGeomData[kScaleZ] = new TGNumberEntry(hf, 1.0, 5, kNEzs);
268  hf->AddFrame(fGeomData[kScaleZ], new TGLayoutHints(fLe));
269  fGeomData[kScaleZ]->Connect("ValueSet(Long_t)", "TGLPShapeObjEditor",
270  this, "GeoValueSet(Long_t)");
271  osf->AddFrame(hf, new TGLayoutHints(lh));
272 
273  hf = new TGHorizontalFrame(osf);
274  fGeomData[kScaleX]->SetLimits(TGNumberFormat::kNELLimitMin, 0.1);
275  fGeomData[kScaleY]->SetLimits(TGNumberFormat::kNELLimitMin, 0.1);
276  fGeomData[kScaleZ]->SetLimits(TGNumberFormat::kNELLimitMin, 0.1);
277  osf->AddFrame(hf, new TGLayoutHints(lh));
278 
279  // Modify button
280  fGeoApplyButton = new TGTextButton(fGeoFrame, "Modify object");
281  fGeoFrame->AddFrame(fGeoApplyButton, new TGLayoutHints(fLb));
282  fGeoApplyButton->SetState(kButtonDisabled);
283  fGeoApplyButton->Connect("Pressed()", "TGLPShapeObjEditor", this, "DoGeoButton()");
284 }
285 
286 ////////////////////////////////////////////////////////////////////////////////
287 /// Set color sliders from 17 component 'rgba'.
288 
289 void TGLPShapeObjEditor::SetRGBA(const Float_t *rgba)
290 {
291  fColorApplyButton->SetState(kButtonDisabled);
292  fColorApplyFamily->SetState(kButtonDisabled);
293 
294  for (Int_t i = 0; i < 17; ++i) fRGBA[i] = rgba[i];
295 
296  fRedSlider->SetPosition(Int_t(fRGBA[fLMode * 4] * 100));
297  fGreenSlider->SetPosition(Int_t(fRGBA[fLMode * 4 + 1] * 100));
298  fBlueSlider->SetPosition(Int_t(fRGBA[fLMode * 4 + 2] * 100));
299  fShineSlider->SetPosition(Int_t(fRGBA[16]));
300 
301  DrawSphere();
302 }
303 
304 ////////////////////////////////////////////////////////////////////////////////
305 /// Process slider movement.
306 
307 void TGLPShapeObjEditor::DoColorSlider(Int_t val)
308 {
309  TGSlider *frm = (TGSlider *)gTQSender;
310 
311  if (frm) {
312  Int_t wid = frm->WidgetId();
313 
314  switch (wid) {
315  case kHSr:
316  fRGBA[fLMode * 4] = val / 100.f;
317  break;
318  case kHSg:
319  fRGBA[fLMode * 4 + 1] = val / 100.f;
320  break;
321  case kHSb:
322  fRGBA[fLMode * 4 + 2] = val / 100.f;
323  break;
324  case kHSa:
325  fRGBA[fLMode * 4 + 3] = val / 100.f;
326  break;
327  case kHSs:
328  fRGBA[16] = val;
329  break;
330  }
331 
332  fColorApplyButton->SetState(kButtonUp);
333  fColorApplyFamily->SetState(kButtonUp);
334  DrawSphere();
335  }
336 }
337 
338 ////////////////////////////////////////////////////////////////////////////////
339 /// Process button action.
340 
341 void TGLPShapeObjEditor::DoColorButton()
342 {
343  TGButton *btn = (TGButton *) gTQSender;
344  Int_t id = btn->WidgetId();
345 
346  switch (id) {
347  case kCPd:
348  fLightTypes[fLMode]->SetState(kButtonUp);
349  fLMode = kDiffuse;
350  SetColorSlidersPos();
351  break;
352  case kCPa:
353  fLightTypes[fLMode]->SetState(kButtonUp);
354  fLMode = kAmbient;
355  SetColorSlidersPos();
356  break;
357  case kCPs:
358  fLightTypes[fLMode]->SetState(kButtonUp);
359  fLMode = kSpecular;
360  SetColorSlidersPos();
361  break;
362  case kCPe:
363  fLightTypes[fLMode]->SetState(kButtonUp);
364  fLMode = kEmission;
365  SetColorSlidersPos();
366  break;
367  case kTBa:
368  fColorApplyButton->SetState(kButtonDisabled);
369  fColorApplyFamily->SetState(kButtonDisabled);
370  if (fPShape) {
371  fPShape->SetColor(GetRGBA());
372  }
373  fPShapeObj->fViewer->RequestDraw();
374  break;
375  case kTBaf:
376  fColorApplyButton->SetState(kButtonDisabled);
377  fColorApplyFamily->SetState(kButtonDisabled);
378  if (fPShape) {
379  fPShape->SetColorOnFamily(GetRGBA());
380  }
381  fPShapeObj->fViewer->RequestDraw();
382  break;
383  }
384 }
385 
386 ////////////////////////////////////////////////////////////////////////////////
387 /// Create Diffuse/Ambient/Specular/Emissive radio buttons and sub-frames.
388 
389 void TGLPShapeObjEditor::CreateColorRadioButtons()
390 {
391  TGGroupFrame *partFrame = new TGGroupFrame(fColorFrame, "Color components:", kLHintsTop | kLHintsCenterX);
392  fColorFrame->AddFrame(partFrame, new TGLayoutHints(kLHintsTop | kLHintsCenterX, 2, 0, 2, 2));
393 
394  partFrame->SetTitlePos(TGGroupFrame::kLeft);
395  TGMatrixLayout *ml = new TGMatrixLayout(partFrame, 0, 1, 10);
396  partFrame->SetLayoutManager(ml);
397 
398  // partFrame will delete the layout manager ml for us so don't add to fTrash
399  fLightTypes[kDiffuse] = new TGRadioButton(partFrame, "Diffuse", kCPd);
400  fLightTypes[kDiffuse]->Connect("Pressed()", "TGLPShapeObjEditor", this, "DoColorButton()");
401  fLightTypes[kDiffuse]->SetToolTipText("Diffuse component of color");
402  partFrame->AddFrame(fLightTypes[kDiffuse]);
403 
404  fLightTypes[kAmbient] = new TGRadioButton(partFrame, "Ambient", kCPa);
405  fLightTypes[kAmbient]->Connect("Pressed()", "TGLPShapeObjEditor", this, "DoColorButton()");
406  fLightTypes[kAmbient]->SetToolTipText("Ambient component of color");
407  partFrame->AddFrame(fLightTypes[kAmbient]);
408 
409  fLightTypes[kSpecular] = new TGRadioButton(partFrame, "Specular", kCPs);
410  fLightTypes[kSpecular]->Connect("Pressed()", "TGLPShapeObjEditor", this, "DoColorButton()");
411  fLightTypes[kSpecular]->SetToolTipText("Specular component of color");
412  partFrame->AddFrame(fLightTypes[kSpecular]);
413 
414  fLightTypes[kEmission] = new TGRadioButton(partFrame, "Emissive", kCPe);
415  fLightTypes[kEmission]->Connect("Pressed()", "TGLPShapeObjEditor", this, "DoColorButton()");
416  fLightTypes[kEmission]->SetToolTipText("Emissive component of color");
417  partFrame->AddFrame(fLightTypes[kEmission]);
418 
419  fLMode = kDiffuse;
420  fLightTypes[fLMode]->SetState(kButtonDown);
421 }
422 
423 ////////////////////////////////////////////////////////////////////////////////
424 /// Create GUI for setting light color.
425 
426 void TGLPShapeObjEditor::CreateColorSliders()
427 {
428  UInt_t sw = 120; //fColorFrame->GetDefalutWidth();,
429 
430  // Create Red/Green/BlueAlpha/Shine sliders
431  fColorFrame->AddFrame(new TGLabel(fColorFrame, "Red :"), new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 0, 0, 0));
432  fRedSlider = new TGHSlider(fColorFrame, sw, kSlider1 | kScaleBoth, kHSr);
433  fRedSlider->Connect("PositionChanged(Int_t)", "TGLPShapeObjEditor", this, "DoColorSlider(Int_t)");
434  fRedSlider->SetRange(0, 100);
435  fRedSlider->SetPosition(Int_t(fRGBA[0] * 100));
436  fColorFrame->AddFrame(fRedSlider, new TGLayoutHints(fLs));
437 
438 
439  fColorFrame->AddFrame(new TGLabel(fColorFrame, "Green :"), new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 0, 0, 0));
440  fGreenSlider = new TGHSlider(fColorFrame, sw, kSlider1 | kScaleBoth, kHSg);
441  fGreenSlider->Connect("PositionChanged(Int_t)", "TGLPShapeObjEditor", this, "DoColorSlider(Int_t)");
442  fGreenSlider->SetRange(0, 100);
443  fGreenSlider->SetPosition(Int_t(fRGBA[1] * 100));
444  fColorFrame->AddFrame(fGreenSlider, new TGLayoutHints(fLs));
445 
446 
447  fColorFrame->AddFrame(new TGLabel(fColorFrame, "Blue :"), new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 0, 0, 0));
448  fBlueSlider = new TGHSlider(fColorFrame, sw, kSlider1 | kScaleBoth, kHSb);
449  fBlueSlider->Connect("PositionChanged(Int_t)", "TGLPShapeObjEditor", this, "DoColorSlider(Int_t)");
450  fBlueSlider->SetRange(0, 100);
451  fBlueSlider->SetPosition(Int_t(fRGBA[2] * 100));
452  fColorFrame->AddFrame(fBlueSlider, new TGLayoutHints(fLs));
453 
454  fColorFrame->AddFrame(new TGLabel(fColorFrame, "Shine :"), new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 0, 0, 0));
455  fShineSlider = new TGHSlider(fColorFrame, sw, kSlider1 | kScaleBoth, kHSs);
456  fShineSlider->Connect("PositionChanged(Int_t)", "TGLPShapeObjEditor", this, "DoColorSlider(Int_t)");
457  fShineSlider->SetRange(0, 128);
458  fColorFrame->AddFrame(fShineSlider, new TGLayoutHints(fLs));
459 }
460 
461 ////////////////////////////////////////////////////////////////////////////////
462 /// Update GUI sliders from internal data.
463 
464 void TGLPShapeObjEditor::SetColorSlidersPos()
465 {
466  fRedSlider->SetPosition(Int_t(fRGBA[fLMode * 4] * 100));
467  fGreenSlider->SetPosition(Int_t(fRGBA[fLMode * 4 + 1] * 100));
468  fBlueSlider->SetPosition(Int_t(fRGBA[fLMode * 4 + 2] * 100));
469  // fAlphaSlider->SetPosition(Int_t(fRGBA[fLMode * 4 + 3] * 100));
470 
471  if (fRGBA[16] >= 0.f)
472  fShineSlider->SetPosition(Int_t(fRGBA[16]));
473 }
474 
475 ////////////////////////////////////////////////////////////////////////////////
476 /// Redraw widget. Render sphere and pass to base-class.
477 
478 void TGLPShapeObjEditor::DoRedraw()
479 {
480  DrawSphere();
481  TGedFrame::DoRedraw();
482 }
483 
484 ////////////////////////////////////////////////////////////////////////////////
485 
486 namespace {
487  GLUquadric *GetQuadric()
488  {
489  // GLU quadric.
490 
491  static struct Init {
492  Init()
493  {
494  fQuad = gluNewQuadric();
495  if (!fQuad) {
496  Error("GetQuadric::Init", "could not create quadric object");
497  } else {
498  gluQuadricOrientation(fQuad, (GLenum)GLU_OUTSIDE);
499  gluQuadricDrawStyle(fQuad, (GLenum)GLU_FILL);
500  gluQuadricNormals(fQuad, (GLenum)GLU_FLAT);
501  }
502  }
503  ~Init()
504  {
505  if(fQuad)
506  gluDeleteQuadric(fQuad);
507  }
508  GLUquadric *fQuad;
509  }singleton;
510 
511  return singleton.fQuad;
512  }
513 
514 }
515 
516 ////////////////////////////////////////////////////////////////////////////////
517 /// Draw local sphere reflecting current color options.
518 
519 void TGLPShapeObjEditor::DrawSphere()const
520 {
521  if (!gVirtualX->IsCmdThread()) {
522  gROOT->ProcessLineFast(Form("((TGLPShapeObjEditor *)0x%lx)->DrawSphere()", (ULong_t)this));
523  return;
524  }
525 
526  R__LOCKGUARD(gROOTMutex);
527 
528  fMatView->MakeCurrent();
529  glViewport(0, 0, fMatView->GetWidth(), fMatView->GetHeight());
530  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
531 
532  glEnable(GL_LIGHTING);
533  glEnable(GL_LIGHT0);
534  glEnable(GL_DEPTH_TEST);
535  glEnable(GL_CULL_FACE);
536  glCullFace(GL_BACK);
537  glMatrixMode(GL_PROJECTION);
538  glLoadIdentity();
539  glFrustum(-0.5, 0.5, -0.5, 0.5, 1., 10.);
540  glMatrixMode(GL_MODELVIEW);
541  glLoadIdentity();
542  Float_t ligPos[] = {0.f, 0.f, 0.f, 1.f};
543  glLightfv(GL_LIGHT0, GL_POSITION, ligPos);
544  glTranslated(0., 0., -3.);
545 
546  const Float_t whiteColor[] = {1.f, 1.f, 1.f, 1.f};
547  const Float_t nullColor[] = {0.f, 0.f, 0.f, 1.f};
548 
549  if (fRGBA[16] < 0.f) {
550  glLightfv(GL_LIGHT0, GL_DIFFUSE, fRGBA);
551  glLightfv(GL_LIGHT0, GL_AMBIENT, fRGBA + 4);
552  glLightfv(GL_LIGHT0, GL_SPECULAR, fRGBA + 8);
553  glMaterialfv(GL_FRONT, GL_DIFFUSE, whiteColor);
554  glMaterialfv(GL_FRONT, GL_AMBIENT, nullColor);
555  glMaterialfv(GL_FRONT, GL_SPECULAR, whiteColor);
556  glMaterialfv(GL_FRONT, GL_EMISSION, nullColor);
557  glMaterialf(GL_FRONT, GL_SHININESS, 60.f);
558  } else {
559  glLightfv(GL_LIGHT0, GL_DIFFUSE, whiteColor);
560  glLightfv(GL_LIGHT0, GL_AMBIENT, nullColor);
561  glLightfv(GL_LIGHT0, GL_SPECULAR, whiteColor);
562  glMaterialfv(GL_FRONT, GL_DIFFUSE, fRGBA);
563  glMaterialfv(GL_FRONT, GL_AMBIENT, fRGBA + 4);
564  glMaterialfv(GL_FRONT, GL_SPECULAR, fRGBA + 8);
565  glMaterialfv(GL_FRONT, GL_EMISSION, fRGBA + 12);
566  glMaterialf(GL_FRONT, GL_SHININESS, fRGBA[16]);
567  }
568 
569  glEnable(GL_BLEND);
570  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
571  GLUquadric * quad = GetQuadric();
572  if (quad) {
573  glRotated(-90., 1., 0., 0.);
574  gluSphere(quad, 1., 100, 100);
575  }
576  glDisable(GL_BLEND);
577 
578  fMatView->SwapBuffers();
579 }
580 
581 ////////////////////////////////////////////////////////////////////////////////
582 /// Create widgets to chose colors component and its RGBA values on fGedEditor
583 /// model or family it belongs to.
584 
585 void TGLPShapeObjEditor::CreateColorControls()
586 {
587  fColorFrame = this;
588 
589  fMatView = TGLWidget::Create(fColorFrame, kFALSE, kTRUE, 0, 120, 120);
590  fColorFrame->AddFrame(fMatView, new TGLayoutHints(kLHintsTop | kLHintsCenterX, 2, 0, 2, 2));
591 
592  CreateColorRadioButtons();
593 
594  CreateColorSliders();
595 
596  //apply button creation
597  fColorApplyButton = new TGTextButton(fColorFrame, "Apply", kTBa);
598  fColorFrame->AddFrame(fColorApplyButton, new TGLayoutHints(fLb));
599  fColorApplyButton->SetState(kButtonDisabled);
600  fColorApplyButton->Connect("Pressed()", "TGLPShapeObjEditor", this, "DoColorButton()");
601  //apply to family button creation
602  fColorApplyFamily = new TGTextButton(fColorFrame, "Apply to family", kTBaf);
603  fColorFrame->AddFrame(fColorApplyFamily, new TGLayoutHints(fLb));
604  fColorApplyFamily->SetState(kButtonDisabled);
605  fColorApplyFamily->Connect("Pressed()", "TGLPShapeObjEditor", this, "DoColorButton()");
606 }