// @(#)root/eve:$Id$
// Authors: Alja & Matevz Tadel 2008

/*************************************************************************
 * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#include "TEveTextEditor.h"
#include "TEveText.h"
#include "TEveGValuators.h"

#include "TGLFontManager.h"

#include "TColor.h"
#include "TGLabel.h"
#include "TGColorSelect.h"
#include "TGComboBox.h"
#include "TGTextBuffer.h"
#include "TGTextEntry.h"
#include "TObjArray.h"
#include "TObjString.h"
#include "TG3DLine.h"


//______________________________________________________________________________
// GUI editor for TEveText.
//

ClassImp(TEveTextEditor);

//______________________________________________________________________________
TEveTextEditor::TEveTextEditor(const TGWindow *p, Int_t width, Int_t height,
                               UInt_t options, Pixel_t back) :
   TGedFrame(p, width, height, options | kVerticalFrame, back),
   fM(0),

   fSize(0),
   fFile(0),
   fMode(0),
   fExtrude(0),

   fLighting(0),
   fAutoLighting(0)
{
   // Constructor.

   MakeTitle("TEveText");

   // Text entry
   fText = new TGTextEntry(this);
   fText->Resize(135, fText->GetDefaultHeight());
   AddFrame(fText, new TGLayoutHints(kLHintsLeft, 3, 1, 2, 5));
   fText->Connect("TextChanged(const char *)", "TEveTextEditor", this, "DoText(const char *)");

   // Face Size combo
   fSize = MakeLabeledCombo("Size:");
   Int_t* fsp = &TGLFontManager::GetFontSizeArray()->front();
   Int_t  nums = TGLFontManager::GetFontSizeArray()->size();
   for(Int_t i= 0; i< nums; i++)
   {
      fSize->AddEntry(Form("%-2d", fsp[i]), fsp[i]);
   }
   fSize->Connect("Selected(Int_t)", "TEveTextEditor", this, "DoFontSize()");

   // Font File combo
   fFile = MakeLabeledCombo("File:");
   TObjArray* farr = TGLFontManager::GetFontFileArray();
   TIter next(farr);
   TObjString* os;
   Int_t cnt = 0;
   while ((os = (TObjString*) next()) != 0)
   {
      fFile->AddEntry(Form("%s", os->GetString().Data()), cnt);
      cnt++;
   }
   fFile->Connect("Selected(Int_t)", "TEveTextEditor", this, "DoFontFile()");

   // Mode combo
   fMode = MakeLabeledCombo("Mode:");
   fMode->AddEntry("Bitmap",  TGLFont::kBitmap);
   fMode->AddEntry("Pixmap",  TGLFont::kPixmap);
   fMode->AddEntry("Texture", TGLFont::kTexture);
   fMode->AddEntry("Outline", TGLFont::kOutline);
   fMode->AddEntry("Polygon", TGLFont::kPolygon);
   fMode->AddEntry("Extrude", TGLFont::kExtrude);
   fMode->Connect("Selected(Int_t)", "TEveTextEditor", this, "DoFontMode()");

   fExtrude = new TEveGValuator(this, "Depth:", 90, 0);
   fExtrude->SetLabelWidth(45);
   fExtrude->SetNELength(5);
   // fExtrude->SetShowSlider(kFALSE);
   fExtrude->Build();
   fExtrude->SetLimits(0.01, 10, 100, TGNumberFormat::kNESRealTwo);
   fExtrude->SetToolTip("Extrusion depth.");
   fExtrude->Connect("ValueSet(Double_t)", "TEveTextEditor", this, "DoExtrude()");
   AddFrame(fExtrude, new TGLayoutHints(kLHintsTop, 4, 1, 1, 1));

   // GLConfig
   TGCompositeFrame *f1 = new TGCompositeFrame(this, 145, 10, kHorizontalFrame | kFitWidth | kFixedWidth );
   f1->AddFrame(new TGLabel(f1, "GLConfig"), new TGLayoutHints(kLHintsLeft, 1, 1, 0, 0));
   f1->AddFrame(new TGHorizontal3DLine(f1), new TGLayoutHints(kLHintsExpandX, 5, 5, 7, 7));
   AddFrame(f1, new TGLayoutHints(kLHintsTop, 0, 0, 8, 0));

   TGCompositeFrame *alf = new TGCompositeFrame(this, 145, 10, kHorizontalFrame );
   fAutoLighting  = new TGCheckButton(alf, "AutoLighting");
   alf->AddFrame(fAutoLighting, new TGLayoutHints(kLHintsLeft, 1,2,0,0));
   fAutoLighting->Connect("Toggled(Bool_t)", "TEveTextEditor", this, "DoAutoLighting()");
   fLighting  = new TGCheckButton(alf, "Lighting");
   alf->AddFrame(fLighting, new TGLayoutHints(kLHintsLeft, 1,2,0,0));
   fLighting->Connect("Toggled(Bool_t)", "TEveTextEditor", this, "DoLighting()");
   AddFrame(alf, new TGLayoutHints(kLHintsTop, 0, 0, 0, 0));
}

//______________________________________________________________________________
TGComboBox* TEveTextEditor::MakeLabeledCombo(const char* name)
{
   // Helper function. Creates TGComboBox with fixed size TGLabel.

   UInt_t labelW = 45;
   UInt_t labelH = 20;
   TGHorizontalFrame* hf = new TGHorizontalFrame(this);
   // label
   TGCompositeFrame *labfr = new TGHorizontalFrame(hf, labelW, labelH, kFixedSize);
   TGLabel* label = new TGLabel(labfr, name);
   labfr->AddFrame(label, new TGLayoutHints(kLHintsLeft  | kLHintsBottom));
   hf->AddFrame(labfr, new TGLayoutHints(kLHintsLeft));
   // combo
   TGLayoutHints*  clh =  new TGLayoutHints(kLHintsLeft, 0,0,0,0);
   TGComboBox* combo = new TGComboBox(hf);
   combo->Resize(90, 20);
   hf->AddFrame(combo, clh);

   AddFrame(hf, new TGLayoutHints(kLHintsTop, 4, 1, 1, 1));
   return combo;
}

//______________________________________________________________________________
void TEveTextEditor::SetModel(TObject* obj)
{
   // Set model object.

   fM = dynamic_cast<TEveText*>(obj);
   if (strcmp(fM->GetText(), fText->GetText()))
      fText->SetText(fM->GetText());

   fSize->Select(fM->GetFontSize(), kFALSE);
   fFile->Select(fM->GetFontFile(), kFALSE);

   // mode
   fMode->Select(fM->GetFontMode(), kFALSE);

   // lightning
   fAutoLighting->SetState(fM->GetAutoLighting() ? kButtonDown : kButtonUp);
   if (fM->GetAutoLighting()) {
      fLighting->SetDisabledAndSelected(fM->GetLighting() ? kButtonDown : kButtonUp);
   } else {
      fLighting->SetEnabled();
      fLighting->SetState(fM->GetLighting() ? kButtonDown : kButtonUp);
   }

   // extrude
   if (fM->GetFontMode() == TGLFont::kExtrude)
   {
      ShowFrame(fExtrude);
      fExtrude->SetValue(fM->GetExtrude());
   }
   else
   {
      HideFrame(fExtrude);
   }
}

//______________________________________________________________________________
void TEveTextEditor::DoText(const char* /*txt*/)
{
   // Slot for setting text.

   fM->SetText(fText->GetText());
   Update();
}

//______________________________________________________________________________
void TEveTextEditor::DoFontSize()
{
   // Slot for setting FTGL attributes.

   fM->SetFontSize(fSize->GetSelected(), kFALSE);
   Update();
}

//______________________________________________________________________________
void TEveTextEditor::DoFontFile()
{
   // Slot for setting FTGL attributes.

   fM->SetFontFile(fFile->GetSelected());
   Update();
}
//______________________________________________________________________________
void TEveTextEditor::DoFontMode()
{
   // Slot for setting FTGL attributes.

   fM->SetFontMode(fMode->GetSelected());
   Update();
}

//______________________________________________________________________________
void TEveTextEditor::DoExtrude()
{
   // Slot for setting an extrude depth.

   fM->SetExtrude(fExtrude->GetValue());
   Update();
}

//______________________________________________________________________________
void TEveTextEditor::DoAutoLighting()
{
   // Slot for enabling/disabling defaults.

   fM->SetAutoLighting(fAutoLighting->IsOn());
   Update();
}

//______________________________________________________________________________
void TEveTextEditor::DoLighting()
{
    // Slot for enabling/disabling GL lighting.

   fM->SetLighting(fLighting->IsOn());
   Update();
}
 TEveTextEditor.cxx:1
 TEveTextEditor.cxx:2
 TEveTextEditor.cxx:3
 TEveTextEditor.cxx:4
 TEveTextEditor.cxx:5
 TEveTextEditor.cxx:6
 TEveTextEditor.cxx:7
 TEveTextEditor.cxx:8
 TEveTextEditor.cxx:9
 TEveTextEditor.cxx:10
 TEveTextEditor.cxx:11
 TEveTextEditor.cxx:12
 TEveTextEditor.cxx:13
 TEveTextEditor.cxx:14
 TEveTextEditor.cxx:15
 TEveTextEditor.cxx:16
 TEveTextEditor.cxx:17
 TEveTextEditor.cxx:18
 TEveTextEditor.cxx:19
 TEveTextEditor.cxx:20
 TEveTextEditor.cxx:21
 TEveTextEditor.cxx:22
 TEveTextEditor.cxx:23
 TEveTextEditor.cxx:24
 TEveTextEditor.cxx:25
 TEveTextEditor.cxx:26
 TEveTextEditor.cxx:27
 TEveTextEditor.cxx:28
 TEveTextEditor.cxx:29
 TEveTextEditor.cxx:30
 TEveTextEditor.cxx:31
 TEveTextEditor.cxx:32
 TEveTextEditor.cxx:33
 TEveTextEditor.cxx:34
 TEveTextEditor.cxx:35
 TEveTextEditor.cxx:36
 TEveTextEditor.cxx:37
 TEveTextEditor.cxx:38
 TEveTextEditor.cxx:39
 TEveTextEditor.cxx:40
 TEveTextEditor.cxx:41
 TEveTextEditor.cxx:42
 TEveTextEditor.cxx:43
 TEveTextEditor.cxx:44
 TEveTextEditor.cxx:45
 TEveTextEditor.cxx:46
 TEveTextEditor.cxx:47
 TEveTextEditor.cxx:48
 TEveTextEditor.cxx:49
 TEveTextEditor.cxx:50
 TEveTextEditor.cxx:51
 TEveTextEditor.cxx:52
 TEveTextEditor.cxx:53
 TEveTextEditor.cxx:54
 TEveTextEditor.cxx:55
 TEveTextEditor.cxx:56
 TEveTextEditor.cxx:57
 TEveTextEditor.cxx:58
 TEveTextEditor.cxx:59
 TEveTextEditor.cxx:60
 TEveTextEditor.cxx:61
 TEveTextEditor.cxx:62
 TEveTextEditor.cxx:63
 TEveTextEditor.cxx:64
 TEveTextEditor.cxx:65
 TEveTextEditor.cxx:66
 TEveTextEditor.cxx:67
 TEveTextEditor.cxx:68
 TEveTextEditor.cxx:69
 TEveTextEditor.cxx:70
 TEveTextEditor.cxx:71
 TEveTextEditor.cxx:72
 TEveTextEditor.cxx:73
 TEveTextEditor.cxx:74
 TEveTextEditor.cxx:75
 TEveTextEditor.cxx:76
 TEveTextEditor.cxx:77
 TEveTextEditor.cxx:78
 TEveTextEditor.cxx:79
 TEveTextEditor.cxx:80
 TEveTextEditor.cxx:81
 TEveTextEditor.cxx:82
 TEveTextEditor.cxx:83
 TEveTextEditor.cxx:84
 TEveTextEditor.cxx:85
 TEveTextEditor.cxx:86
 TEveTextEditor.cxx:87
 TEveTextEditor.cxx:88
 TEveTextEditor.cxx:89
 TEveTextEditor.cxx:90
 TEveTextEditor.cxx:91
 TEveTextEditor.cxx:92
 TEveTextEditor.cxx:93
 TEveTextEditor.cxx:94
 TEveTextEditor.cxx:95
 TEveTextEditor.cxx:96
 TEveTextEditor.cxx:97
 TEveTextEditor.cxx:98
 TEveTextEditor.cxx:99
 TEveTextEditor.cxx:100
 TEveTextEditor.cxx:101
 TEveTextEditor.cxx:102
 TEveTextEditor.cxx:103
 TEveTextEditor.cxx:104
 TEveTextEditor.cxx:105
 TEveTextEditor.cxx:106
 TEveTextEditor.cxx:107
 TEveTextEditor.cxx:108
 TEveTextEditor.cxx:109
 TEveTextEditor.cxx:110
 TEveTextEditor.cxx:111
 TEveTextEditor.cxx:112
 TEveTextEditor.cxx:113
 TEveTextEditor.cxx:114
 TEveTextEditor.cxx:115
 TEveTextEditor.cxx:116
 TEveTextEditor.cxx:117
 TEveTextEditor.cxx:118
 TEveTextEditor.cxx:119
 TEveTextEditor.cxx:120
 TEveTextEditor.cxx:121
 TEveTextEditor.cxx:122
 TEveTextEditor.cxx:123
 TEveTextEditor.cxx:124
 TEveTextEditor.cxx:125
 TEveTextEditor.cxx:126
 TEveTextEditor.cxx:127
 TEveTextEditor.cxx:128
 TEveTextEditor.cxx:129
 TEveTextEditor.cxx:130
 TEveTextEditor.cxx:131
 TEveTextEditor.cxx:132
 TEveTextEditor.cxx:133
 TEveTextEditor.cxx:134
 TEveTextEditor.cxx:135
 TEveTextEditor.cxx:136
 TEveTextEditor.cxx:137
 TEveTextEditor.cxx:138
 TEveTextEditor.cxx:139
 TEveTextEditor.cxx:140
 TEveTextEditor.cxx:141
 TEveTextEditor.cxx:142
 TEveTextEditor.cxx:143
 TEveTextEditor.cxx:144
 TEveTextEditor.cxx:145
 TEveTextEditor.cxx:146
 TEveTextEditor.cxx:147
 TEveTextEditor.cxx:148
 TEveTextEditor.cxx:149
 TEveTextEditor.cxx:150
 TEveTextEditor.cxx:151
 TEveTextEditor.cxx:152
 TEveTextEditor.cxx:153
 TEveTextEditor.cxx:154
 TEveTextEditor.cxx:155
 TEveTextEditor.cxx:156
 TEveTextEditor.cxx:157
 TEveTextEditor.cxx:158
 TEveTextEditor.cxx:159
 TEveTextEditor.cxx:160
 TEveTextEditor.cxx:161
 TEveTextEditor.cxx:162
 TEveTextEditor.cxx:163
 TEveTextEditor.cxx:164
 TEveTextEditor.cxx:165
 TEveTextEditor.cxx:166
 TEveTextEditor.cxx:167
 TEveTextEditor.cxx:168
 TEveTextEditor.cxx:169
 TEveTextEditor.cxx:170
 TEveTextEditor.cxx:171
 TEveTextEditor.cxx:172
 TEveTextEditor.cxx:173
 TEveTextEditor.cxx:174
 TEveTextEditor.cxx:175
 TEveTextEditor.cxx:176
 TEveTextEditor.cxx:177
 TEveTextEditor.cxx:178
 TEveTextEditor.cxx:179
 TEveTextEditor.cxx:180
 TEveTextEditor.cxx:181
 TEveTextEditor.cxx:182
 TEveTextEditor.cxx:183
 TEveTextEditor.cxx:184
 TEveTextEditor.cxx:185
 TEveTextEditor.cxx:186
 TEveTextEditor.cxx:187
 TEveTextEditor.cxx:188
 TEveTextEditor.cxx:189
 TEveTextEditor.cxx:190
 TEveTextEditor.cxx:191
 TEveTextEditor.cxx:192
 TEveTextEditor.cxx:193
 TEveTextEditor.cxx:194
 TEveTextEditor.cxx:195
 TEveTextEditor.cxx:196
 TEveTextEditor.cxx:197
 TEveTextEditor.cxx:198
 TEveTextEditor.cxx:199
 TEveTextEditor.cxx:200
 TEveTextEditor.cxx:201
 TEveTextEditor.cxx:202
 TEveTextEditor.cxx:203
 TEveTextEditor.cxx:204
 TEveTextEditor.cxx:205
 TEveTextEditor.cxx:206
 TEveTextEditor.cxx:207
 TEveTextEditor.cxx:208
 TEveTextEditor.cxx:209
 TEveTextEditor.cxx:210
 TEveTextEditor.cxx:211
 TEveTextEditor.cxx:212
 TEveTextEditor.cxx:213
 TEveTextEditor.cxx:214
 TEveTextEditor.cxx:215
 TEveTextEditor.cxx:216
 TEveTextEditor.cxx:217
 TEveTextEditor.cxx:218
 TEveTextEditor.cxx:219
 TEveTextEditor.cxx:220
 TEveTextEditor.cxx:221
 TEveTextEditor.cxx:222
 TEveTextEditor.cxx:223
 TEveTextEditor.cxx:224
 TEveTextEditor.cxx:225
 TEveTextEditor.cxx:226
 TEveTextEditor.cxx:227
 TEveTextEditor.cxx:228
 TEveTextEditor.cxx:229
 TEveTextEditor.cxx:230
 TEveTextEditor.cxx:231
 TEveTextEditor.cxx:232
 TEveTextEditor.cxx:233
 TEveTextEditor.cxx:234
 TEveTextEditor.cxx:235
 TEveTextEditor.cxx:236
 TEveTextEditor.cxx:237