ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TGLOverlayButton.cxx
Go to the documentation of this file.
1 // @(#)root/gl:$Id$
2 // Author: Bertrand Bellenot 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 "TGLOverlayButton.h"
13 #include "TColor.h"
14 #include "TMath.h"
15 
16 #include <TGLRnrCtx.h>
17 #include <TGLIncludes.h>
18 #include <TGLSelectRecord.h>
19 #include <TGLUtil.h>
20 #include <TGLCamera.h>
21 #include <TGLViewerBase.h>
22 
23 /** \class TGLOverlayButton
24 \ingroup opengl
25 GL-overlay button.
26 */
27 
29 
30 ////////////////////////////////////////////////////////////////////////////////
31 /// Constructor.
32 
34  Float_t posx, Float_t posy, Float_t width, Float_t height) :
36  fText(text),
37  fActiveID(-1),
38  fBackColor(0x8080ff),
39  fTextColor(0xffffff),
40  fNormAlpha(0.2),
41  fHighAlpha(1.0),
42  fPosX(posx),
43  fPosY(posy),
44  fWidth(width),
45  fHeight(height)
46 {
47  if (parent)
48  parent->AddOverlayElement(this);
49 }
50 
51 ////////////////////////////////////////////////////////////////////////////////
52 /// Render the overlay elements.
53 
55 {
56  Float_t r, g, b;
57  glMatrixMode(GL_PROJECTION);
58  glPushMatrix();
59  glLoadIdentity();
60  if (rnrCtx.Selection())
61  {
62  TGLRect rect(*rnrCtx.GetPickRectangle());
63  rnrCtx.GetCamera()->WindowToViewport(rect);
64  gluPickMatrix(rect.X(), rect.Y(), rect.Width(), rect.Height(),
65  (Int_t*) rnrCtx.GetCamera()->RefViewport().CArr());
66  }
67  const TGLRect& vp = rnrCtx.RefCamera().RefViewport();
68  glOrtho(vp.X(), vp.Width(), vp.Y(), vp.Height(), 0, 1);
69  glMatrixMode(GL_MODELVIEW);
70  glPushMatrix();
71  glLoadIdentity();
72 
73  Float_t offset = (fPosY >= 0.0)? 0.0 : vp.Height()-fHeight;
74 
75  TGLCapabilitySwitch lights_off(GL_LIGHTING, kFALSE);
76  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
77  glDisable(GL_CULL_FACE);
78  glEnable(GL_BLEND);
79  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
80  glShadeModel(GL_FLAT);
81  glClearColor(0.0, 0.0, 0.0, 0.0);
82  glPushName(1);
83 
84  // Button rendering
85  {
86  TGLCapabilitySwitch move_to_back(GL_POLYGON_OFFSET_FILL, kTRUE);
87  glPolygonOffset(0.5f, 0.5f);
88  glPushMatrix();
89  glTranslatef(fPosX, offset+fPosY, 0);
90  // First the border, same color as text
91  TColor::Pixel2RGB(fTextColor, r, g, b);
94  glBegin(GL_LINE_LOOP);
95  glVertex2f(0.0, 0.0);
96  glVertex2f(0.0, fHeight);
97  glVertex2f(fWidth, fHeight);
98  glVertex2f(fWidth, 0.0);
99  glEnd();
100  // then the button itself, with its own color
101  // decrease a bit the highlight, to avoid bad effects...
102  TColor::Pixel2RGB(fBackColor, r, g, b);
103  (fActiveID == 1) ? TGLUtil::Color4f(r, g, b, fHighAlpha * 0.8):TGLUtil::Color4f(r, g, b, fNormAlpha);
104  glBegin(GL_QUADS);
105  glVertex2f(0.0, 0.0);
106  glVertex2f(0.0, fHeight);
107  glVertex2f(fWidth, fHeight);
108  glVertex2f(fWidth, 0.0);
109  glEnd();
110  glPopMatrix();
111  }
112 
113  // Text rendering
114  {
117 
118  TColor::Pixel2RGB(fTextColor, r, g, b);
119  (fActiveID == 1) ? TGLUtil::Color4f(r, g, b, fHighAlpha):TGLUtil::Color4f(r, g, b, fNormAlpha);
120  glPushMatrix();
121  glTranslatef(fPosX+(fWidth/2.0), offset+fPosY+(fHeight/2.0), 0);
122  Float_t llx, lly, llz, urx, ury, urz;
123  fFont.BBox(fText.Data(), llx, lly, llz, urx, ury, urz);
124  glRasterPos2i(0, 0);
125  glBitmap(0, 0, 0, 0, -urx*0.5f, -ury*0.5f, 0);
126  fFont.Render(fText.Data());
127  fFont.PostRender();
128  glPopMatrix();
129  }
130  glPopName();
131 
132  glMatrixMode(GL_PROJECTION);
133  glPopMatrix();
134  glMatrixMode(GL_MODELVIEW);
135  glPopMatrix();
136 }
137 
138 ////////////////////////////////////////////////////////////////////////////////
139 /// Emits "Clicked(TGLViewerBase*)" signal.
140 /// Called when user click on the GL button.
141 
143 {
144  Emit("Clicked(TGLViewerBase*)", (Long_t)viewer);
145 }
146 
147 /******************************************************************************/
148 // Virtual event handlers from TGLOverlayElement
149 /******************************************************************************/
150 
151 ////////////////////////////////////////////////////////////////////////////////
152 /// Handle overlay event.
153 /// Return TRUE if event was handled.
154 
156  TGLOvlSelectRecord & rec,
157  Event_t * event)
158 {
159  if (event->fCode != kButton1) {
160  return kFALSE;
161  }
162  switch (event->fType) {
163  case kButtonPress:
164  if (rec.GetItem(1) == 1) {
165  return kTRUE;
166  }
167  break;
168  case kButtonRelease:
169  if (rec.GetItem(1) == 1) {
170  Clicked(rnrCtx.GetViewer());
171  return kTRUE;
172  }
173  break;
174  default:
175  break;
176  }
177  return kFALSE;
178 }
179 
180 ////////////////////////////////////////////////////////////////////////////////
181 /// Mouse has entered overlay area.
182 
184 {
185  fActiveID = 1;
186  return kTRUE;
187 }
188 
189 ////////////////////////////////////////////////////////////////////////////////
190 /// Mouse has left overlay area.
191 
193 {
194  fActiveID = -1;
195 }
The TGLRnrCtx class aggregates data for a given redering context as needed by various parts of the RO...
Definition: TGLRnrCtx.h:40
Int_t Width() const
Definition: TGLUtil.h:455
float Float_t
Definition: RtypesCore.h:53
tuple offset
Definition: tree.py:93
TGLOverlayButton(const TGLOverlayButton &)
virtual void Render(TGLRnrCtx &rnrCtx)
Render the overlay elements.
TGLCamera & RefCamera()
Definition: TGLRnrCtx.h:157
virtual Bool_t MouseEnter(TGLOvlSelectRecord &selRec)
Mouse has entered overlay area.
Bool_t Selection() const
Definition: TGLRnrCtx.h:222
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
void RegisterFontNoScale(Int_t size, Int_t file, Int_t mode, TGLFont &out)
Get font in the GL rendering context.
Definition: TGLRnrCtx.cxx:367
TGLRect & RefViewport()
Definition: TGLCamera.h:128
TGLRect * GetPickRectangle()
Return current pick rectangle.
Definition: TGLRnrCtx.cxx:249
TFile * f
An overlay element.
Definition: TGLOverlay.h:22
Base class for GL viewers.
Definition: TGLViewerBase.h:36
virtual void Clicked(TGLViewerBase *viewer)
Emits "Clicked(TGLViewerBase*)" signal.
virtual Bool_t Handle(TGLRnrCtx &rnrCtx, TGLOvlSelectRecord &selRec, Event_t *event)
Handle overlay event.
const char * Data() const
Definition: TString.h:349
void BBox(const char *txt, Float_t &llx, Float_t &lly, Float_t &llz, Float_t &urx, Float_t &ury, Float_t &urz) const
Get bounding box.
void Render(const char *txt, Double_t x, Double_t y, Double_t angle, Double_t mgn) const
TGLCamera * GetCamera()
Definition: TGLRnrCtx.h:156
Viewport (pixel base) 2D rectangle class.
Definition: TGLUtil.h:426
void Emit(const char *signal)
Acitvate signal without args.
Definition: TQObject.cxx:559
void WindowToViewport(Int_t &, Int_t &y) const
Definition: TGLCamera.h:198
ROOT::R::TRInterface & r
Definition: Object.C:4
EGEventType fType
Definition: GuiTypes.h:176
GL-overlay button.
static void Color4f(Float_t r, Float_t g, Float_t b, Float_t a)
Wrapper for glColor4f.
Definition: TGLUtil.cxx:1756
virtual void PostRender() const
Reset GL state after FTFont rendering.
Int_t X() const
Definition: TGLUtil.h:451
long Long_t
Definition: RtypesCore.h:50
virtual void AddOverlayElement(TGLOverlayElement *el)
Add overlay element.
const Int_t * CArr() const
Definition: TGLUtil.h:448
TText * text
UInt_t fCode
Definition: GuiTypes.h:181
UInt_t GetItem(Int_t i) const
ClassImp(TGLOverlayButton)
virtual void MouseLeave()
Mouse has left overlay area.
Int_t Height() const
Definition: TGLUtil.h:457
virtual void PreRender(Bool_t autoLight=kTRUE, Bool_t lightOn=kFALSE) const
Set-up GL state before FTFont rendering.
static Float_t LineWidth()
Get the line-width, taking the global scaling into account.
Definition: TGLUtil.cxx:1904
TGLViewerBase * GetViewer()
Definition: TGLRnrCtx.h:154
Selection record for overlay objects.
const Bool_t kTRUE
Definition: Rtypes.h:91
Int_t Nint(T x)
Definition: TMath.h:480
Int_t Y() const
Definition: TGLUtil.h:453
static void Pixel2RGB(ULong_t pixel, Int_t &r, Int_t &g, Int_t &b)
Convert machine dependent pixel value (obtained via RGB2Pixel or via Number2Pixel() or via TColor::Ge...
Definition: TColor.cxx:1295