Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TGLLightSetEditor.cxx
Go to the documentation of this file.
1 // @(#)root/gl:$Id$
2 // Author: Matevz Tadel, Feb 2007
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2004, 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 "TGLLightSetEditor.h"
13 #include <TGLLightSet.h>
14 
15 #include <TVirtualPad.h>
16 #include <TColor.h>
17 
18 #include <TGLabel.h>
19 #include <TGButton.h>
20 #include <TGNumberEntry.h>
21 #include <TGColorSelect.h>
22 #include <TGDoubleSlider.h>
23 
24 /** \class TGLLightSetSubEditor
25 \ingroup opengl
26 Sub-editor for TGLLightSet.
27 */
28 
29 ClassImp(TGLLightSetSubEditor);
30 
31 ////////////////////////////////////////////////////////////////////////////////
32 
33 TGLLightSetSubEditor::TGLLightSetSubEditor(const TGWindow *p) :
34  TGVerticalFrame(p),
35  fM (0),
36 
37  fLightFrame (0),
38  fTopLight (0),
39  fRightLight (0),
40  fBottomLight (0),
41  fLeftLight (0),
42  fFrontLight (0),
43  fSpecularLight (0)
44 {
45  // Constructor.
46 
47  fLightFrame = new TGGroupFrame(this, "Light sources:", kVerticalFrame);//, kLHintsTop | kLHintsCenterX);
48  fLightFrame->SetTitlePos(TGGroupFrame::kLeft);
49  AddFrame(fLightFrame, new TGLayoutHints(kLHintsTop| kLHintsExpandX, 1, 1, 1, 1));//-
50  TGCompositeFrame* hf =0;
51 
52  hf = new TGHorizontalFrame(fLightFrame);
53  fTopLight = MakeLampButton("Top", TGLLightSet::kLightTop, hf);
54  fBottomLight = MakeLampButton("Bottom", TGLLightSet::kLightBottom, hf);
55  fLightFrame->AddFrame(hf, new TGLayoutHints(kLHintsTop|kLHintsExpandX, 0, 0, 2, 2));
56 
57  hf = new TGHorizontalFrame(fLightFrame);
58  fLeftLight = MakeLampButton("Left", TGLLightSet::kLightLeft, hf);
59  fRightLight = MakeLampButton("Right", TGLLightSet::kLightRight, hf);
60  fLightFrame->AddFrame(hf, new TGLayoutHints(kLHintsTop|kLHintsExpandX , 0, 0, 0, 2));
61 
62  hf = new TGHorizontalFrame(fLightFrame);
63  fFrontLight = MakeLampButton("Front", TGLLightSet::kLightFront, hf);
64  fSpecularLight = MakeLampButton("Specular", TGLLightSet::kLightSpecular, hf);
65 
66  fLightFrame->AddFrame(hf, new TGLayoutHints(kLHintsTop|kLHintsExpandX, 0, 0, 0, 2));
67 }
68 
69 ////////////////////////////////////////////////////////////////////////////////
70 /// Create a button for given lamp and set it up.
71 
72 TGButton* TGLLightSetSubEditor::MakeLampButton(const char* name, Int_t wid,
73  TGCompositeFrame* parent)
74 {
75  TGButton* b = new TGCheckButton(parent, name, wid);
76  parent->AddFrame(b, new TGLayoutHints(kLHintsNormal|kLHintsExpandX, -2, 0, 0, 2));
77  b->Connect("Clicked()", "TGLLightSetSubEditor", this, "DoButton()");
78  return b;
79 }
80 
81 ////////////////////////////////////////////////////////////////////////////////
82 /// New model was set, refresh data.
83 
84 void TGLLightSetSubEditor::SetModel(TGLLightSet* m)
85 {
86  fM = m;
87  UInt_t als = fM->GetLightState();
88 
89  fTopLight ->SetState((als & TGLLightSet::kLightTop) ? kButtonDown : kButtonUp);
90  fRightLight ->SetState((als & TGLLightSet::kLightRight) ? kButtonDown : kButtonUp);
91  fBottomLight->SetState((als & TGLLightSet::kLightBottom) ? kButtonDown : kButtonUp);
92  fLeftLight ->SetState((als & TGLLightSet::kLightLeft) ? kButtonDown : kButtonUp);
93  fFrontLight ->SetState((als & TGLLightSet::kLightFront) ? kButtonDown : kButtonUp);
94 
95  fSpecularLight->SetState(fM->GetUseSpecular() ? kButtonDown : kButtonUp);
96 }
97 
98 ////////////////////////////////////////////////////////////////////////////////
99 /// Data in sub-editor has been changed, emit "Changed()" signal.
100 
101 void TGLLightSetSubEditor::Changed()
102 {
103  Emit("Changed()");
104 }
105 
106 ////////////////////////////////////////////////////////////////////////////////
107 /// Lights radio button was clicked.
108 
109 void TGLLightSetSubEditor::DoButton()
110 {
111  TGButton* b = (TGButton*) gTQSender;
112  fM->SetLight(TGLLightSet::ELight(b->WidgetId()), b->IsOn());
113  Changed();
114 }
115 
116 
117 //______________________________________________________________________________
118 // TGLLightSetEditor
119 //
120 // Editor for TGLLightSet.
121 
122 ClassImp(TGLLightSetEditor);
123 
124 ////////////////////////////////////////////////////////////////////////////////
125 /// Constructor.
126 
127 TGLLightSetEditor::TGLLightSetEditor(const TGWindow *p,
128  Int_t width, Int_t height,
129  UInt_t options, Pixel_t back) :
130  TGedFrame(p, width, height, options | kVerticalFrame, back),
131  fM (0),
132  fSE (0)
133 {
134  MakeTitle("TGLLightSet");
135 
136  fSE = new TGLLightSetSubEditor(this);
137  AddFrame(fSE, new TGLayoutHints(kLHintsTop, 2, 0, 2, 2));
138  fSE->Connect("Changed()", "TGLLightSetEditor", this, "Update()");
139 }
140 
141 ////////////////////////////////////////////////////////////////////////////////
142 /// Destructor.
143 
144 TGLLightSetEditor::~TGLLightSetEditor()
145 {
146 }
147 
148 ////////////////////////////////////////////////////////////////////////////////
149 /// SetModel ... forward to sub-editor.
150 
151 void TGLLightSetEditor::SetModel(TObject* obj)
152 {
153  fM = dynamic_cast<TGLLightSet*>(obj);
154  fSE->SetModel(fM);
155 }