ROOT  6.06/09
Reference Guide
TGLEmbeddedViewer.cxx
Go to the documentation of this file.
1 // @(#)root/gl:$Id$
2 // Author: Bertrand Bellenot 23/01/2008
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2008, 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 "TGFrame.h"
13 #include "TGLayout.h"
14 #include "TGLWidget.h"
15 #include "TGLSAFrame.h"
16 #include "TString.h"
17 #include "TGLPShapeObj.h"
18 #include "TGLPhysicalShape.h"
19 #include "TGLLogicalShape.h"
20 #include "TGLEmbeddedViewer.h"
21 #include "TGLEventHandler.h"
22 
23 /** \class TGLEmbeddedViewer
24 \ingroup opengl
25 Minimal GL-viewer that can be embedded in a standard ROOT frames.
26 */
27 
29 
30 ////////////////////////////////////////////////////////////////////////////////
31 /// Constructor.
32 /// Argument 'border' specifies how many pixels to pad on each side of the
33 /// viewer. This area can be used for highlightning of the active viewer.
34 
36  Int_t border) :
37  TGLViewer(pad, 0, 0, 400, 300),
38  fFrame(0),
39  fBorder(border)
40 {
41  Init(parent);
42 }
43 
44 ////////////////////////////////////////////////////////////////////////////////
45 /// Constructor allowing to also specify an GED editor to use.
46 /// Argument 'border' specifies how many pixels to pad on each side of the
47 /// viewer. This area can be used for highlightning of the active viewer.
48 
50  TGedEditor *ged, Int_t border) :
51  TGLViewer(pad, 0, 0, 400, 300),
52  fFrame(0),
53  fBorder(border)
54 {
55  fGedEditor = ged;
56  Init(parent);
57 }
58 
59 ////////////////////////////////////////////////////////////////////////////////
60 /// Destroy standalone viewer object.
61 
63 {
64  delete fFrame;
65  fGLWidget = 0;
66 }
67 
68 ////////////////////////////////////////////////////////////////////////////////
69 /// Common initialization from all constructors.
70 
71 void TGLEmbeddedViewer::Init(const TGWindow *parent)
72 {
73  fFrame = new TGCompositeFrame(parent);
74 
75  CreateFrames();
76 
79  fFrame->Resize(400, 300);
80 }
81 
82 ////////////////////////////////////////////////////////////////////////////////
83 /// Internal frames creation.
84 
86 {
88 
89  // Direct events from the TGWindow directly to the base viewer
90  fEventHandler = new TGLEventHandler(0, this);
92 
95 }
96 
97 ////////////////////////////////////////////////////////////////////////////////
98 /// Create a GLwidget, it is an error if it is already created.
99 /// This is needed for frame-swapping on mac.
100 
102 {
103  if (fGLWidget) {
104  Error("CreateGLWidget", "Widget already exists.");
105  return;
106  }
107 
108  fGLWidget = TGLWidget::Create(fFrame, kTRUE, kTRUE, 0, 10, 10);
110 
113  fFrame->Layout();
114 
115  fGLWidget->MapWindow();
116 }
117 
118 ////////////////////////////////////////////////////////////////////////////////
119 /// Destroy the GLwidget, it is an error if it does not exist.
120 /// This is needed for frame-swapping on mac.
121 
123 {
124  if (fGLWidget == 0) {
125  Error("DestroyGLWidget", "Widget does not exist.");
126  return;
127  }
128 
131 
134  fGLWidget = 0;
135 }
TGEventHandler * fEventHandler
select record from last overlay select
Definition: TGLViewer.h:119
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:587
int Int_t
Definition: RtypesCore.h:41
virtual void Layout()
Layout the elements of the composite frame.
Definition: TGFrame.cxx:1239
virtual void RemoveFrame(TGFrame *f)
Remove frame from composite frame.
Definition: TGFrame.cxx:1131
Minimal GL-viewer that can be embedded in a standard ROOT frames.
static TGLWidget * Create(const TGWindow *parent, Bool_t selectInput, Bool_t shareDefault, const TGLPaintDevice *shareDevice, UInt_t width, UInt_t height)
Static constructor for creating widget with default pixel format.
Definition: TGLWidget.cxx:83
void SetEventHandler(TGEventHandler *eh)
Set event-handler. All events are passed to this object.
Definition: TGLWidget.cxx:558
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:918
ClassImp(TGLEmbeddedViewer)
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition: TVirtualPad.h:59
TGLWidget * fGLWidget
Definition: TGLViewer.h:185
virtual void DestroyGLWidget()
Destroy the GLwidget, it is an error if it does not exist.
virtual void CreateGLWidget()
Create a GLwidget, it is an error if it is already created.
~TGLEmbeddedViewer()
Destroy standalone viewer object.
Base GL viewer object - used by both standalone and embedded (in pad) GL.
Definition: TGLViewer.h:53
void Init(const TGWindow *parent)
Common initialization from all constructors.
friend class TGLEventHandler
Definition: TGLViewer.h:59
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1099
virtual void MapSubwindows()
Map all sub windows that are part of the composite frame.
Definition: TGFrame.cxx:1146
virtual void UnmapWindow()
Definition: TGFrame.h:269
virtual void MapWindow()
Definition: TGFrame.h:267
TGLEmbeddedViewer(const TGLEmbeddedViewer &)
virtual TGDimension GetDefaultSize() const
std::cout << fWidth << "x" << fHeight << std::endl;
Definition: TGFrame.h:391
TGCompositeFrame * fFrame
virtual void DeleteWindow()
Delete window.
Definition: TGFrame.cxx:258
const Bool_t kTRUE
Definition: Rtypes.h:91
TGedEditor * fGedEditor
event handler
Definition: TGLViewer.h:120
void CreateFrames()
Internal frames creation.