Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TEveTextEditor.cxx
Go to the documentation of this file.
1 // @(#)root/eve:$Id$
2 // Authors: Alja & Matevz Tadel 2008
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 "TEveTextEditor.h"
13 #include "TEveText.h"
14 #include "TEveGValuators.h"
15 
16 #include "TGLFontManager.h"
17 
18 #include "TColor.h"
19 #include "TGLabel.h"
20 #include "TGColorSelect.h"
21 #include "TGComboBox.h"
22 #include "TGTextBuffer.h"
23 #include "TGTextEntry.h"
24 #include "TObjArray.h"
25 #include "TObjString.h"
26 #include "TG3DLine.h"
27 
28 
29 /** \class TEveTextEditor
30 \ingroup TEve
31 GUI editor for TEveText.
32 */
33 
34 ClassImp(TEveTextEditor);
35 
36 ////////////////////////////////////////////////////////////////////////////////
37 /// Constructor.
38 
39 TEveTextEditor::TEveTextEditor(const TGWindow *p, Int_t width, Int_t height,
40  UInt_t options, Pixel_t back) :
41  TGedFrame(p, width, height, options | kVerticalFrame, back),
42  fM(0),
43 
44  fSize(0),
45  fFile(0),
46  fMode(0),
47  fExtrude(0),
48 
49  fLighting(0),
50  fAutoLighting(0)
51 {
52  MakeTitle("TEveText");
53 
54  // Text entry
55  fText = new TGTextEntry(this);
56  fText->Resize(135, fText->GetDefaultHeight());
57  AddFrame(fText, new TGLayoutHints(kLHintsLeft, 3, 1, 2, 5));
58  fText->Connect("TextChanged(const char *)", "TEveTextEditor", this, "DoText(const char *)");
59 
60  // Face Size combo
61  fSize = MakeLabeledCombo("Size:");
62  Int_t* fsp = &TGLFontManager::GetFontSizeArray()->front();
63  Int_t nums = TGLFontManager::GetFontSizeArray()->size();
64  for(Int_t i= 0; i< nums; i++)
65  {
66  fSize->AddEntry(Form("%-2d", fsp[i]), fsp[i]);
67  }
68  fSize->Connect("Selected(Int_t)", "TEveTextEditor", this, "DoFontSize()");
69 
70  // Font File combo
71  fFile = MakeLabeledCombo("File:");
72  TObjArray* farr = TGLFontManager::GetFontFileArray();
73  TIter next(farr);
74  TObjString* os;
75  Int_t cnt = 0;
76  while ((os = (TObjString*) next()) != 0)
77  {
78  fFile->AddEntry(Form("%s", os->GetString().Data()), cnt);
79  cnt++;
80  }
81  fFile->Connect("Selected(Int_t)", "TEveTextEditor", this, "DoFontFile()");
82 
83  // Mode combo
84  fMode = MakeLabeledCombo("Mode:");
85  fMode->AddEntry("Bitmap", TGLFont::kBitmap);
86  fMode->AddEntry("Pixmap", TGLFont::kPixmap);
87  fMode->AddEntry("Texture", TGLFont::kTexture);
88  fMode->AddEntry("Outline", TGLFont::kOutline);
89  fMode->AddEntry("Polygon", TGLFont::kPolygon);
90  fMode->AddEntry("Extrude", TGLFont::kExtrude);
91  fMode->Connect("Selected(Int_t)", "TEveTextEditor", this, "DoFontMode()");
92 
93  fExtrude = new TEveGValuator(this, "Depth:", 90, 0);
94  fExtrude->SetLabelWidth(45);
95  fExtrude->SetNELength(5);
96  // fExtrude->SetShowSlider(kFALSE);
97  fExtrude->Build();
98  fExtrude->SetLimits(0.01, 10, 100, TGNumberFormat::kNESRealTwo);
99  fExtrude->SetToolTip("Extrusion depth.");
100  fExtrude->Connect("ValueSet(Double_t)", "TEveTextEditor", this, "DoExtrude()");
101  AddFrame(fExtrude, new TGLayoutHints(kLHintsTop, 4, 1, 1, 1));
102 
103  // GLConfig
104  TGCompositeFrame *f1 = new TGCompositeFrame(this, 145, 10, kHorizontalFrame | kFitWidth | kFixedWidth );
105  f1->AddFrame(new TGLabel(f1, "GLConfig"), new TGLayoutHints(kLHintsLeft, 1, 1, 0, 0));
106  f1->AddFrame(new TGHorizontal3DLine(f1), new TGLayoutHints(kLHintsExpandX, 5, 5, 7, 7));
107  AddFrame(f1, new TGLayoutHints(kLHintsTop, 0, 0, 8, 0));
108 
109  TGCompositeFrame *alf = new TGCompositeFrame(this, 145, 10, kHorizontalFrame );
110  fAutoLighting = new TGCheckButton(alf, "AutoLighting");
111  alf->AddFrame(fAutoLighting, new TGLayoutHints(kLHintsLeft, 1,2,0,0));
112  fAutoLighting->Connect("Toggled(Bool_t)", "TEveTextEditor", this, "DoAutoLighting()");
113  fLighting = new TGCheckButton(alf, "Lighting");
114  alf->AddFrame(fLighting, new TGLayoutHints(kLHintsLeft, 1,2,0,0));
115  fLighting->Connect("Toggled(Bool_t)", "TEveTextEditor", this, "DoLighting()");
116  AddFrame(alf, new TGLayoutHints(kLHintsTop, 0, 0, 0, 0));
117 }
118 
119 ////////////////////////////////////////////////////////////////////////////////
120 /// Helper function. Creates TGComboBox with fixed size TGLabel.
121 
122 TGComboBox* TEveTextEditor::MakeLabeledCombo(const char* name)
123 {
124  UInt_t labelW = 45;
125  UInt_t labelH = 20;
126  TGHorizontalFrame* hf = new TGHorizontalFrame(this);
127  // label
128  TGCompositeFrame *labfr = new TGHorizontalFrame(hf, labelW, labelH, kFixedSize);
129  TGLabel* label = new TGLabel(labfr, name);
130  labfr->AddFrame(label, new TGLayoutHints(kLHintsLeft | kLHintsBottom));
131  hf->AddFrame(labfr, new TGLayoutHints(kLHintsLeft));
132  // combo
133  TGLayoutHints* clh = new TGLayoutHints(kLHintsLeft, 0,0,0,0);
134  TGComboBox* combo = new TGComboBox(hf);
135  combo->Resize(90, 20);
136  hf->AddFrame(combo, clh);
137 
138  AddFrame(hf, new TGLayoutHints(kLHintsTop, 4, 1, 1, 1));
139  return combo;
140 }
141 
142 ////////////////////////////////////////////////////////////////////////////////
143 /// Set model object.
144 
145 void TEveTextEditor::SetModel(TObject* obj)
146 {
147  fM = dynamic_cast<TEveText*>(obj);
148  if (strcmp(fM->GetText(), fText->GetText()))
149  fText->SetText(fM->GetText());
150 
151  fSize->Select(fM->GetFontSize(), kFALSE);
152  fFile->Select(fM->GetFontFile(), kFALSE);
153 
154  // mode
155  fMode->Select(fM->GetFontMode(), kFALSE);
156 
157  // lightning
158  fAutoLighting->SetState(fM->GetAutoLighting() ? kButtonDown : kButtonUp);
159  if (fM->GetAutoLighting()) {
160  fLighting->SetDisabledAndSelected(fM->GetLighting() ? kButtonDown : kButtonUp);
161  } else {
162  fLighting->SetEnabled();
163  fLighting->SetState(fM->GetLighting() ? kButtonDown : kButtonUp);
164  }
165 
166  // extrude
167  if (fM->GetFontMode() == TGLFont::kExtrude)
168  {
169  ShowFrame(fExtrude);
170  fExtrude->SetValue(fM->GetExtrude());
171  }
172  else
173  {
174  HideFrame(fExtrude);
175  }
176 }
177 
178 ////////////////////////////////////////////////////////////////////////////////
179 /// Slot for setting text.
180 
181 void TEveTextEditor::DoText(const char* /*txt*/)
182 {
183  fM->SetText(fText->GetText());
184  Update();
185 }
186 
187 ////////////////////////////////////////////////////////////////////////////////
188 /// Slot for setting FTGL attributes.
189 
190 void TEveTextEditor::DoFontSize()
191 {
192  fM->SetFontSize(fSize->GetSelected(), kFALSE);
193  Update();
194 }
195 
196 ////////////////////////////////////////////////////////////////////////////////
197 /// Slot for setting FTGL attributes.
198 
199 void TEveTextEditor::DoFontFile()
200 {
201  fM->SetFontFile(fFile->GetSelected());
202  Update();
203 }
204 ////////////////////////////////////////////////////////////////////////////////
205 /// Slot for setting FTGL attributes.
206 
207 void TEveTextEditor::DoFontMode()
208 {
209  fM->SetFontMode(fMode->GetSelected());
210  Update();
211 }
212 
213 ////////////////////////////////////////////////////////////////////////////////
214 /// Slot for setting an extrude depth.
215 
216 void TEveTextEditor::DoExtrude()
217 {
218  fM->SetExtrude(fExtrude->GetValue());
219  Update();
220 }
221 
222 ////////////////////////////////////////////////////////////////////////////////
223 /// Slot for enabling/disabling defaults.
224 
225 void TEveTextEditor::DoAutoLighting()
226 {
227  fM->SetAutoLighting(fAutoLighting->IsOn());
228  Update();
229 }
230 
231 ////////////////////////////////////////////////////////////////////////////////
232 /// Slot for enabling/disabling GL lighting.
233 
234 void TEveTextEditor::DoLighting()
235 {
236  fM->SetLighting(fLighting->IsOn());
237  Update();
238 }