ROOT logo
// @(#)root/gl:$Id$
// Author:  Matevz Tadel, Feb 2007

/*************************************************************************
 * Copyright (C) 1995-2004, 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 "TGLLightSetEditor.h"
#include <TGLLightSet.h>

#include <TVirtualPad.h>
#include <TColor.h>

#include <TGLabel.h>
#include <TGButton.h>
#include <TGNumberEntry.h>
#include <TGColorSelect.h>
#include <TGDoubleSlider.h>

//______________________________________________________________________
// TGLLightSetSubEditor
//
// Sub-editor for TGLLightSet.

ClassImp(TGLLightSetSubEditor)

//______________________________________________________________________________
TGLLightSetSubEditor::TGLLightSetSubEditor(const TGWindow *p) :
   TGVerticalFrame(p),
   fM             (0),

   fLightFrame    (0),
   fTopLight      (0),
   fRightLight    (0),
   fBottomLight   (0),
   fLeftLight     (0),
   fFrontLight    (0),
   fSpecularLight (0)
{
   // Constructor.

   fLightFrame = new TGGroupFrame(this, "Light sources:", kVerticalFrame);//, kLHintsTop | kLHintsCenterX);
   fLightFrame->SetTitlePos(TGGroupFrame::kLeft);
   AddFrame(fLightFrame, new TGLayoutHints(kLHintsTop| kLHintsExpandX, 1, 1, 1, 1));//-
   TGCompositeFrame* hf =0;

   hf = new TGHorizontalFrame(fLightFrame);
   fTopLight      = MakeLampButton("Top",      TGLLightSet::kLightTop, hf);
   fBottomLight   = MakeLampButton("Bottom",   TGLLightSet::kLightBottom, hf);
   fLightFrame->AddFrame(hf, new TGLayoutHints(kLHintsTop|kLHintsExpandX, 0, 0, 2, 2));

   hf = new TGHorizontalFrame(fLightFrame);
   fLeftLight     = MakeLampButton("Left",     TGLLightSet::kLightLeft, hf);
   fRightLight    = MakeLampButton("Right",    TGLLightSet::kLightRight, hf);
   fLightFrame->AddFrame(hf, new TGLayoutHints(kLHintsTop|kLHintsExpandX , 0, 0, 0, 2));

   hf = new TGHorizontalFrame(fLightFrame);
   fFrontLight    = MakeLampButton("Front",    TGLLightSet::kLightFront, hf);
   fSpecularLight = MakeLampButton("Specular", TGLLightSet::kLightSpecular, hf);

   fLightFrame->AddFrame(hf, new TGLayoutHints(kLHintsTop|kLHintsExpandX, 0, 0, 0, 2));
}

//______________________________________________________________________________
TGButton* TGLLightSetSubEditor::MakeLampButton(const char* name, Int_t wid,
                                               TGCompositeFrame* parent)
{
   // Create a button for given lamp and set it up.

   TGButton* b = new TGCheckButton(parent, name, wid);
   parent->AddFrame(b, new TGLayoutHints(kLHintsNormal|kLHintsExpandX, -2, 0, 0, 2));
   b->Connect("Clicked()", "TGLLightSetSubEditor", this, "DoButton()");
   return b;
}

//______________________________________________________________________________
void TGLLightSetSubEditor::SetModel(TGLLightSet* m)
{
   // New model was set, refresh data.

   fM = m;
   UInt_t als = fM->GetLightState();

   fTopLight   ->SetState((als & TGLLightSet::kLightTop)    ? kButtonDown : kButtonUp);
   fRightLight ->SetState((als & TGLLightSet::kLightRight)  ? kButtonDown : kButtonUp);
   fBottomLight->SetState((als & TGLLightSet::kLightBottom) ? kButtonDown : kButtonUp);
   fLeftLight  ->SetState((als & TGLLightSet::kLightLeft)   ? kButtonDown : kButtonUp);
   fFrontLight ->SetState((als & TGLLightSet::kLightFront)  ? kButtonDown : kButtonUp);

   fSpecularLight->SetState(fM->GetUseSpecular() ? kButtonDown : kButtonUp);
}

//______________________________________________________________________________
void TGLLightSetSubEditor::Changed()
{
   // Data in sub-editor has been changed, emit "Changed()" signal.

   Emit("Changed()");
}

//______________________________________________________________________________
void TGLLightSetSubEditor::DoButton()
{
   // Lights radio button was clicked.

   TGButton* b = (TGButton*) gTQSender;
   fM->SetLight(TGLLightSet::ELight(b->WidgetId()), b->IsOn());
   Changed();
}


//______________________________________________________________________________
// TGLLightSetEditor
//
// Editor for TGLLightSet.

ClassImp(TGLLightSetEditor)

//______________________________________________________________________________
TGLLightSetEditor::TGLLightSetEditor(const TGWindow *p,
                                     Int_t width, Int_t height,
                                     UInt_t options, Pixel_t back) :
   TGedFrame(p, width, height, options | kVerticalFrame, back),
   fM  (0),
   fSE (0)
{
   // Constructor.

   MakeTitle("TGLLightSet");

   fSE = new TGLLightSetSubEditor(this);
   AddFrame(fSE, new TGLayoutHints(kLHintsTop, 2, 0, 2, 2));
   fSE->Connect("Changed()", "TGLLightSetEditor", this, "Update()");
}

//______________________________________________________________________________
TGLLightSetEditor::~TGLLightSetEditor()
{
   // Destructor.
}

//______________________________________________________________________________
void TGLLightSetEditor::SetModel(TObject* obj)
{
   // SetModel ... forward to sub-editor.

   fM = dynamic_cast<TGLLightSet*>(obj);
   fSE->SetModel(fM);
}
 TGLLightSetEditor.cxx:1
 TGLLightSetEditor.cxx:2
 TGLLightSetEditor.cxx:3
 TGLLightSetEditor.cxx:4
 TGLLightSetEditor.cxx:5
 TGLLightSetEditor.cxx:6
 TGLLightSetEditor.cxx:7
 TGLLightSetEditor.cxx:8
 TGLLightSetEditor.cxx:9
 TGLLightSetEditor.cxx:10
 TGLLightSetEditor.cxx:11
 TGLLightSetEditor.cxx:12
 TGLLightSetEditor.cxx:13
 TGLLightSetEditor.cxx:14
 TGLLightSetEditor.cxx:15
 TGLLightSetEditor.cxx:16
 TGLLightSetEditor.cxx:17
 TGLLightSetEditor.cxx:18
 TGLLightSetEditor.cxx:19
 TGLLightSetEditor.cxx:20
 TGLLightSetEditor.cxx:21
 TGLLightSetEditor.cxx:22
 TGLLightSetEditor.cxx:23
 TGLLightSetEditor.cxx:24
 TGLLightSetEditor.cxx:25
 TGLLightSetEditor.cxx:26
 TGLLightSetEditor.cxx:27
 TGLLightSetEditor.cxx:28
 TGLLightSetEditor.cxx:29
 TGLLightSetEditor.cxx:30
 TGLLightSetEditor.cxx:31
 TGLLightSetEditor.cxx:32
 TGLLightSetEditor.cxx:33
 TGLLightSetEditor.cxx:34
 TGLLightSetEditor.cxx:35
 TGLLightSetEditor.cxx:36
 TGLLightSetEditor.cxx:37
 TGLLightSetEditor.cxx:38
 TGLLightSetEditor.cxx:39
 TGLLightSetEditor.cxx:40
 TGLLightSetEditor.cxx:41
 TGLLightSetEditor.cxx:42
 TGLLightSetEditor.cxx:43
 TGLLightSetEditor.cxx:44
 TGLLightSetEditor.cxx:45
 TGLLightSetEditor.cxx:46
 TGLLightSetEditor.cxx:47
 TGLLightSetEditor.cxx:48
 TGLLightSetEditor.cxx:49
 TGLLightSetEditor.cxx:50
 TGLLightSetEditor.cxx:51
 TGLLightSetEditor.cxx:52
 TGLLightSetEditor.cxx:53
 TGLLightSetEditor.cxx:54
 TGLLightSetEditor.cxx:55
 TGLLightSetEditor.cxx:56
 TGLLightSetEditor.cxx:57
 TGLLightSetEditor.cxx:58
 TGLLightSetEditor.cxx:59
 TGLLightSetEditor.cxx:60
 TGLLightSetEditor.cxx:61
 TGLLightSetEditor.cxx:62
 TGLLightSetEditor.cxx:63
 TGLLightSetEditor.cxx:64
 TGLLightSetEditor.cxx:65
 TGLLightSetEditor.cxx:66
 TGLLightSetEditor.cxx:67
 TGLLightSetEditor.cxx:68
 TGLLightSetEditor.cxx:69
 TGLLightSetEditor.cxx:70
 TGLLightSetEditor.cxx:71
 TGLLightSetEditor.cxx:72
 TGLLightSetEditor.cxx:73
 TGLLightSetEditor.cxx:74
 TGLLightSetEditor.cxx:75
 TGLLightSetEditor.cxx:76
 TGLLightSetEditor.cxx:77
 TGLLightSetEditor.cxx:78
 TGLLightSetEditor.cxx:79
 TGLLightSetEditor.cxx:80
 TGLLightSetEditor.cxx:81
 TGLLightSetEditor.cxx:82
 TGLLightSetEditor.cxx:83
 TGLLightSetEditor.cxx:84
 TGLLightSetEditor.cxx:85
 TGLLightSetEditor.cxx:86
 TGLLightSetEditor.cxx:87
 TGLLightSetEditor.cxx:88
 TGLLightSetEditor.cxx:89
 TGLLightSetEditor.cxx:90
 TGLLightSetEditor.cxx:91
 TGLLightSetEditor.cxx:92
 TGLLightSetEditor.cxx:93
 TGLLightSetEditor.cxx:94
 TGLLightSetEditor.cxx:95
 TGLLightSetEditor.cxx:96
 TGLLightSetEditor.cxx:97
 TGLLightSetEditor.cxx:98
 TGLLightSetEditor.cxx:99
 TGLLightSetEditor.cxx:100
 TGLLightSetEditor.cxx:101
 TGLLightSetEditor.cxx:102
 TGLLightSetEditor.cxx:103
 TGLLightSetEditor.cxx:104
 TGLLightSetEditor.cxx:105
 TGLLightSetEditor.cxx:106
 TGLLightSetEditor.cxx:107
 TGLLightSetEditor.cxx:108
 TGLLightSetEditor.cxx:109
 TGLLightSetEditor.cxx:110
 TGLLightSetEditor.cxx:111
 TGLLightSetEditor.cxx:112
 TGLLightSetEditor.cxx:113
 TGLLightSetEditor.cxx:114
 TGLLightSetEditor.cxx:115
 TGLLightSetEditor.cxx:116
 TGLLightSetEditor.cxx:117
 TGLLightSetEditor.cxx:118
 TGLLightSetEditor.cxx:119
 TGLLightSetEditor.cxx:120
 TGLLightSetEditor.cxx:121
 TGLLightSetEditor.cxx:122
 TGLLightSetEditor.cxx:123
 TGLLightSetEditor.cxx:124
 TGLLightSetEditor.cxx:125
 TGLLightSetEditor.cxx:126
 TGLLightSetEditor.cxx:127
 TGLLightSetEditor.cxx:128
 TGLLightSetEditor.cxx:129
 TGLLightSetEditor.cxx:130
 TGLLightSetEditor.cxx:131
 TGLLightSetEditor.cxx:132
 TGLLightSetEditor.cxx:133
 TGLLightSetEditor.cxx:134
 TGLLightSetEditor.cxx:135
 TGLLightSetEditor.cxx:136
 TGLLightSetEditor.cxx:137
 TGLLightSetEditor.cxx:138
 TGLLightSetEditor.cxx:139
 TGLLightSetEditor.cxx:140
 TGLLightSetEditor.cxx:141
 TGLLightSetEditor.cxx:142
 TGLLightSetEditor.cxx:143
 TGLLightSetEditor.cxx:144
 TGLLightSetEditor.cxx:145
 TGLLightSetEditor.cxx:146
 TGLLightSetEditor.cxx:147
 TGLLightSetEditor.cxx:148
 TGLLightSetEditor.cxx:149
 TGLLightSetEditor.cxx:150
 TGLLightSetEditor.cxx:151
 TGLLightSetEditor.cxx:152
 TGLLightSetEditor.cxx:153