ROOT logo
// @(#)root/eve:$Id: test_windows.C 29032 2009-06-16 17:16:42Z matevz $
// Author: Matevz Tadel

// Demonstrates usage of EVE window-manager.

#include "TEveWindow.h"
#include "TEveViewer.h"
#include "TEveManager.h"
#include "TEveBrowser.h"
#include "TEveGedEditor.h"
#include "TGLEmbeddedViewer.h"
#include "TCanvas.h"
#include "TGTab.h"

void test_windows()
{
   TEveManager::Create();

   TEveUtil::Macro("pointset_test.C");

   PackTest();
   DetailTest();
   TabsTest();

   gEve->GetBrowser()->GetTabRight()->SetTab(1);
   gDebug = 1;
}

void PackTest()
{
   TEveWindowSlot  *slot  = 0;
   TEveWindowFrame *frame = 0;
   TEveViewer *v = 0;

   slot = TEveWindow::CreateWindowInTab(gEve->GetBrowser()->GetTabRight());
   TEveWindowPack* pack1 = slot->MakePack();
   pack1->SetShowTitleBar(kFALSE);
   pack1->SetHorizontal();

   // Embedded viewer.
   slot = pack1->NewSlot();
   v = new TEveViewer("BarViewer");
   v->SpawnGLEmbeddedViewer();
   slot->ReplaceWindow(v);
   v->SetElementName("Bar Embedded Viewer");

   gEve->GetViewers()->AddElement(v);
   v->AddScene(gEve->GetEventScene());

   slot = pack1->NewSlot();   
   TEveWindowPack* pack2 = slot->MakePack();
   pack2->SetShowTitleBar(kFALSE);

   slot = pack2->NewSlot();
   slot->StartEmbedding();
   TCanvas* can = new TCanvas("Root Canvas");
   can->ToggleEditor();
   slot->StopEmbedding();

   // SA viewer.
   slot = pack2->NewSlot();
   v = new TEveViewer("FooViewer");
   v->SpawnGLViewer(gEve->GetEditor());
   slot->ReplaceWindow(v);
   gEve->GetViewers()->AddElement(v);
   v->AddScene(gEve->GetEventScene());   
}


void DetailTest()
{
   TEveWindowSlot  *slot  = 0;
   TEveWindowFrame *frame = 0;
   TEveViewer *v = 0;

   slot = TEveWindow::CreateWindowInTab(gEve->GetBrowser()->GetTabRight());
   TEveWindowPack* pack1 = slot->MakePack();
   pack1->SetShowTitleBar(kFALSE);
   pack1->SetElementName("Detail");
   pack1->SetHorizontal();

   //
   slot = pack1->NewSlot();
   frame = slot->MakeFrame();
   frame->SetElementName("Latex Frame");
   frame->SetShowTitleBar(kFALSE);
   TGCompositeFrame* cf = frame->GetGUICompositeFrame();

   TGHorizontalFrame* hf = new TGHorizontalFrame(cf);
   cf->AddFrame(hf, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));

   {
      TRootEmbeddedCanvas* ec = new TRootEmbeddedCanvas("Embeddedcanvas", hf, 220);
      hf->AddFrame(ec, new TGLayoutHints(kLHintsExpandY));
      double fontsize = 0.07;
      double x = 0.02;
      double y = 1 -1*fontsize;
      TLatex* latex = new TLatex(x, y, "Legend:");
      latex->SetTextSize(fontsize);
      latex->Draw();
      y -= 2*fontsize;
      // legend
      latex->DrawLatex(x, y, "greek letter #Delta#eta_{out}");
      y -= fontsize;
      latex->DrawLatex(x, y, "#color[5]{+} marker");
      y -= fontsize;
      latex->DrawLatex(x, y, "#color[5]{+} marker");
      y -= fontsize;
      latex->DrawLatex(x, y, "#color[4]{+} marker");
      y -= fontsize;
      latex->DrawLatex(x, y, "#color[5]{#bullet} marker");
      y -= fontsize;
      latex->DrawLatex(x, y, "#color[4]{#bullet} marker some text");
      y -= fontsize;
      latex->DrawLatex(x, y, "#color[2]{#Box} square");
      y -= fontsize;
      latex->DrawLatex(x, y, "#color[5]{#Box} color");
   }

   // viwer
   TGLEmbeddedViewer* ev = new TGLEmbeddedViewer(hf, 0, 0);
   TEveViewer *v = new TEveViewer();
   v->SetGLViewer(ev,ev->GetFrame());
   gEve->GetViewers()->AddElement(v);
   v->AddScene(gEve->GetEventScene());
   hf->AddFrame(ev->GetFrame(), new TGLayoutHints(kLHintsExpandX | kLHintsExpandY|kLHintsTop));

   if (0) {
      TGTextButton *b = new TGTextButton(hf, "BigButton");
      hf->AddFrame(b, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
   }

   cf->MapSubwindows();
   cf->Layout();
   cf->MapWindow();
}

void TabsTest()
{
   TRandom r(0);
   TEveWindowSlot  *slot  = 0;
   TEveWindowFrame *frame = 0;
   TEveViewer *v = 0;

   slot = TEveWindow::CreateWindowInTab(gEve->GetBrowser()->GetTabRight());
   TEveWindowTab* tab1 = slot->MakeTab();
   tab1->SetElementName("Tabs");
   tab1->SetShowTitleBar(kFALSE);

   // horizontal text views
   slot = tab1->NewSlot();
   TEveWindowPack* pack1 = slot->MakePack();
   for(int i = 0; i<4;++i)
   {
      Int_t weight = r.Uniform(3, 7);
      slot = pack1->NewSlotWithWeight(weight);
      frame = slot->MakeFrame();
      frame->SetElementName(Form("FrameInPack %d", i));
      TGCompositeFrame* cf = frame->GetGUICompositeFrame();
      TGTextView* text_view =  new TGTextView(cf, 200, 400);
      cf->AddFrame(text_view,  new TGLayoutHints(kLHintsLeft|kLHintsExpandX|kLHintsExpandY));

      for(Int_t l =0; l<weight; l++)
      {
         text_view->AddLine(Form("slot[%d] add line %d here ", i, l));
      }
      text_view->Update();
      text_view->SetWidth(text_view->ReturnLongestLineWidth()+20);
      text_view->Layout();
     
      cf->MapSubwindows();
      cf->Layout();
      cf->MapWindow();
   }

   // canvas tab
   slot = tab1->NewSlot();
   frame = slot->MakeFrame(new TRootEmbeddedCanvas());
   frame->SetElementName("Embedded Canvas");

   // neseted 2nd leveltabs
   slot = tab1->NewSlot();
   slot->SetShowTitleBar(kFALSE);
   TEveWindowTab* tab2 = slot->MakeTab();
   tab2->SetElementName("Nested");
   tab2->SetShowTitleBar(kFALSE);
   slot =  tab2->NewSlot();
   slot->SetShowTitleBar(kFALSE);
   slot =    tab2->NewSlot();
   slot->SetShowTitleBar(kFALSE);
}
 test_windows.C:1
 test_windows.C:2
 test_windows.C:3
 test_windows.C:4
 test_windows.C:5
 test_windows.C:6
 test_windows.C:7
 test_windows.C:8
 test_windows.C:9
 test_windows.C:10
 test_windows.C:11
 test_windows.C:12
 test_windows.C:13
 test_windows.C:14
 test_windows.C:15
 test_windows.C:16
 test_windows.C:17
 test_windows.C:18
 test_windows.C:19
 test_windows.C:20
 test_windows.C:21
 test_windows.C:22
 test_windows.C:23
 test_windows.C:24
 test_windows.C:25
 test_windows.C:26
 test_windows.C:27
 test_windows.C:28
 test_windows.C:29
 test_windows.C:30
 test_windows.C:31
 test_windows.C:32
 test_windows.C:33
 test_windows.C:34
 test_windows.C:35
 test_windows.C:36
 test_windows.C:37
 test_windows.C:38
 test_windows.C:39
 test_windows.C:40
 test_windows.C:41
 test_windows.C:42
 test_windows.C:43
 test_windows.C:44
 test_windows.C:45
 test_windows.C:46
 test_windows.C:47
 test_windows.C:48
 test_windows.C:49
 test_windows.C:50
 test_windows.C:51
 test_windows.C:52
 test_windows.C:53
 test_windows.C:54
 test_windows.C:55
 test_windows.C:56
 test_windows.C:57
 test_windows.C:58
 test_windows.C:59
 test_windows.C:60
 test_windows.C:61
 test_windows.C:62
 test_windows.C:63
 test_windows.C:64
 test_windows.C:65
 test_windows.C:66
 test_windows.C:67
 test_windows.C:68
 test_windows.C:69
 test_windows.C:70
 test_windows.C:71
 test_windows.C:72
 test_windows.C:73
 test_windows.C:74
 test_windows.C:75
 test_windows.C:76
 test_windows.C:77
 test_windows.C:78
 test_windows.C:79
 test_windows.C:80
 test_windows.C:81
 test_windows.C:82
 test_windows.C:83
 test_windows.C:84
 test_windows.C:85
 test_windows.C:86
 test_windows.C:87
 test_windows.C:88
 test_windows.C:89
 test_windows.C:90
 test_windows.C:91
 test_windows.C:92
 test_windows.C:93
 test_windows.C:94
 test_windows.C:95
 test_windows.C:96
 test_windows.C:97
 test_windows.C:98
 test_windows.C:99
 test_windows.C:100
 test_windows.C:101
 test_windows.C:102
 test_windows.C:103
 test_windows.C:104
 test_windows.C:105
 test_windows.C:106
 test_windows.C:107
 test_windows.C:108
 test_windows.C:109
 test_windows.C:110
 test_windows.C:111
 test_windows.C:112
 test_windows.C:113
 test_windows.C:114
 test_windows.C:115
 test_windows.C:116
 test_windows.C:117
 test_windows.C:118
 test_windows.C:119
 test_windows.C:120
 test_windows.C:121
 test_windows.C:122
 test_windows.C:123
 test_windows.C:124
 test_windows.C:125
 test_windows.C:126
 test_windows.C:127
 test_windows.C:128
 test_windows.C:129
 test_windows.C:130
 test_windows.C:131
 test_windows.C:132
 test_windows.C:133
 test_windows.C:134
 test_windows.C:135
 test_windows.C:136
 test_windows.C:137
 test_windows.C:138
 test_windows.C:139
 test_windows.C:140
 test_windows.C:141
 test_windows.C:142
 test_windows.C:143
 test_windows.C:144
 test_windows.C:145
 test_windows.C:146
 test_windows.C:147
 test_windows.C:148
 test_windows.C:149
 test_windows.C:150
 test_windows.C:151
 test_windows.C:152
 test_windows.C:153
 test_windows.C:154
 test_windows.C:155
 test_windows.C:156
 test_windows.C:157
 test_windows.C:158
 test_windows.C:159
 test_windows.C:160
 test_windows.C:161
 test_windows.C:162
 test_windows.C:163
 test_windows.C:164
 test_windows.C:165
 test_windows.C:166
 test_windows.C:167
 test_windows.C:168
 test_windows.C:169
 test_windows.C:170
 test_windows.C:171
 test_windows.C:172
 test_windows.C:173
 test_windows.C:174
 test_windows.C:175
 test_windows.C:176
 test_windows.C:177
 test_windows.C:178
 test_windows.C:179
 test_windows.C:180
 test_windows.C:181
 test_windows.C:182
 test_windows.C:183
 test_windows.C:184
 test_windows.C:185
 test_windows.C:186
 test_windows.C:187
 test_windows.C:188
 test_windows.C:189
 test_windows.C:190
 test_windows.C:191
 test_windows.C:192
thumb