Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
25GL-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
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...
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
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);
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*)", (Longptr_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}
#define GL_QUADS
Definition GL_glu.h:290
#define GL_LINE_LOOP
Definition GL_glu.h:285
@ kButtonRelease
Definition GuiTypes.h:60
@ kButtonPress
Definition GuiTypes.h:60
@ kButton1
Definition GuiTypes.h:214
ROOT::R::TRInterface & r
Definition Object.C:4
#define b(i)
Definition RSha256.hxx:100
#define g(i)
Definition RSha256.hxx:105
long Longptr_t
Definition RtypesCore.h:82
const Bool_t kFALSE
Definition RtypesCore.h:101
float Float_t
Definition RtypesCore.h:57
const Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:364
include TDocParser_001 C image html pict1_TDocParser_001 png width
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:2145
void WindowToViewport(Int_t &, Int_t &y) const
Definition TGLCamera.h:198
TGLRect & RefViewport()
Definition TGLCamera.h:128
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
virtual void PostRender() const
Reset GL state after FTFont rendering.
virtual void PreRender(Bool_t autoLight=kTRUE, Bool_t lightOn=kFALSE) const
Set-up GL state before FTFont rendering.
GL-overlay button.
TGLOverlayButton(const TGLOverlayButton &)
virtual Bool_t Handle(TGLRnrCtx &rnrCtx, TGLOvlSelectRecord &selRec, Event_t *event)
Handle overlay event.
virtual void MouseLeave()
Mouse has left overlay area.
virtual void Render(TGLRnrCtx &rnrCtx)
Render the overlay elements.
virtual void Clicked(TGLViewerBase *viewer)
Emits "Clicked(TGLViewerBase*)" signal.
virtual Bool_t MouseEnter(TGLOvlSelectRecord &selRec)
Mouse has entered overlay area.
An overlay element.
Definition TGLOverlay.h:23
Selection record for overlay objects.
Viewport (pixel base) 2D rectangle class.
Definition TGLUtil.h:422
Int_t Y() const
Definition TGLUtil.h:448
const Int_t * CArr() const
Definition TGLUtil.h:443
Int_t Height() const
Definition TGLUtil.h:452
Int_t Width() const
Definition TGLUtil.h:450
Int_t X() const
Definition TGLUtil.h:446
The TGLRnrCtx class aggregates data for a given redering context as needed by various parts of the RO...
Definition TGLRnrCtx.h:41
TGLViewerBase * GetViewer()
Definition TGLRnrCtx.h:154
TGLRect * GetPickRectangle()
Return current pick rectangle.
void RegisterFontNoScale(Int_t size, Int_t file, Int_t mode, TGLFont &out)
Get font in the GL rendering context.
TGLCamera & RefCamera()
Definition TGLRnrCtx.h:157
TGLCamera * GetCamera()
Definition TGLRnrCtx.h:156
Bool_t Selection() const
Definition TGLRnrCtx.h:222
UInt_t GetItem(Int_t i) const
static void Color4f(Float_t r, Float_t g, Float_t b, Float_t a)
Wrapper for glColor4f.
Definition TGLUtil.cxx:1789
static Float_t LineWidth()
Get the line-width, taking the global scaling into account.
Definition TGLUtil.cxx:1937
Base class for GL viewers.
virtual void AddOverlayElement(TGLOverlayElement *el)
Add overlay element.
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Definition TQObject.h:164
const char * Data() const
Definition TString.h:369
TText * text
Int_t Nint(T x)
Round to nearest integer. Rounds half integers to the nearest even integer.
Definition TMath.h:663
Event structure.
Definition GuiTypes.h:174