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
28
29////////////////////////////////////////////////////////////////////////////////
30/// Constructor.
31
33 Float_t posx, Float_t posy, Float_t width, Float_t height) :
35 fText(text),
36 fActiveID(-1),
37 fBackColor(0x8080ff),
38 fTextColor(0xffffff),
39 fNormAlpha(0.2),
40 fHighAlpha(1.0),
41 fPosX(posx),
42 fPosY(posy),
43 fWidth(width),
44 fHeight(height)
45{
46 if (parent)
47 parent->AddOverlayElement(this);
48}
49
50////////////////////////////////////////////////////////////////////////////////
51/// Render the overlay elements.
52
54{
55 Float_t r, g, b;
56 glMatrixMode(GL_PROJECTION);
57 glPushMatrix();
58 glLoadIdentity();
59 if (rnrCtx.Selection())
60 {
61 TGLRect rect(*rnrCtx.GetPickRectangle());
62 rnrCtx.GetCamera()->WindowToViewport(rect);
63 gluPickMatrix(rect.X(), rect.Y(), rect.Width(), rect.Height(),
64 (Int_t*) rnrCtx.GetCamera()->RefViewport().CArr());
65 }
66 const TGLRect& vp = rnrCtx.RefCamera().RefViewport();
67 glOrtho(vp.X(), vp.Width(), vp.Y(), vp.Height(), 0, 1);
68 glMatrixMode(GL_MODELVIEW);
69 glPushMatrix();
70 glLoadIdentity();
71
72 Float_t offset = (fPosY >= 0.0)? 0.0 : vp.Height()-fHeight;
73
74 TGLCapabilitySwitch lights_off(GL_LIGHTING, kFALSE);
75 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
76 glDisable(GL_CULL_FACE);
77 glEnable(GL_BLEND);
78 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
79 glShadeModel(GL_FLAT);
80 glClearColor(0.0, 0.0, 0.0, 0.0);
81 glPushName(1);
82
83 // Button rendering
84 {
85 TGLCapabilitySwitch move_to_back(GL_POLYGON_OFFSET_FILL, kTRUE);
86 glPolygonOffset(0.5f, 0.5f);
87 glPushMatrix();
88 glTranslatef(fPosX, offset+fPosY, 0);
89 // First the border, same color as text
93 glBegin(GL_LINE_LOOP);
94 glVertex2f(0.0, 0.0);
95 glVertex2f(0.0, fHeight);
96 glVertex2f(fWidth, fHeight);
97 glVertex2f(fWidth, 0.0);
98 glEnd();
99 // then the button itself, with its own color
100 // decrease a bit the highlight, to avoid bad effects...
103 glBegin(GL_QUADS);
104 glVertex2f(0.0, 0.0);
105 glVertex2f(0.0, fHeight);
106 glVertex2f(fWidth, fHeight);
107 glVertex2f(fWidth, 0.0);
108 glEnd();
109 glPopMatrix();
110 }
111
112 // Text rendering
113 {
115 fFont.PreRender(kFALSE);
116
119 glPushMatrix();
120 glTranslatef(fPosX+(fWidth/2.0), offset+fPosY+(fHeight/2.0), 0);
121 Float_t llx, lly, llz, urx, ury, urz;
122 fFont.BBox(fText.Data(), llx, lly, llz, urx, ury, urz);
123 glRasterPos2i(0, 0);
124 glBitmap(0, 0, 0, 0, -urx*0.5f, -ury*0.5f, nullptr);
125 fFont.Render(fText.Data());
126 fFont.PostRender();
127 glPopMatrix();
128 }
129 glPopName();
130
131 glMatrixMode(GL_PROJECTION);
132 glPopMatrix();
133 glMatrixMode(GL_MODELVIEW);
134 glPopMatrix();
135}
136
137////////////////////////////////////////////////////////////////////////////////
138/// Emits "Clicked(TGLViewerBase*)" signal.
139/// Called when user click on the GL button.
140
142{
143 Emit("Clicked(TGLViewerBase*)", (Longptr_t)viewer);
144}
145
146/******************************************************************************/
147// Virtual event handlers from TGLOverlayElement
148/******************************************************************************/
149
150////////////////////////////////////////////////////////////////////////////////
151/// Handle overlay event.
152/// Return TRUE if event was handled.
153
155 TGLOvlSelectRecord & rec,
156 Event_t * event)
157{
158 if (event->fCode != kButton1) {
159 return kFALSE;
160 }
161 switch (event->fType) {
162 case kButtonPress:
163 if (rec.GetItem(1) == 1) {
164 return kTRUE;
165 }
166 break;
167 case kButtonRelease:
168 if (rec.GetItem(1) == 1) {
169 Clicked(rnrCtx.GetViewer());
170 return kTRUE;
171 }
172 break;
173 default:
174 break;
175 }
176 return kFALSE;
177}
178
179////////////////////////////////////////////////////////////////////////////////
180/// Mouse has entered overlay area.
181
187
188////////////////////////////////////////////////////////////////////////////////
189/// Mouse has left overlay area.
190
192{
193 fActiveID = -1;
194}
@ kButtonRelease
Definition GuiTypes.h:61
@ kButtonPress
Definition GuiTypes.h:61
@ kButton1
Definition GuiTypes.h:215
ROOT::R::TRInterface & r
Definition Object.C:4
#define b(i)
Definition RSha256.hxx:100
#define g(i)
Definition RSha256.hxx:105
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
long Longptr_t
Integer large enough to hold a pointer (platform-dependent).
Definition RtypesCore.h:89
bool Bool_t
Boolean (0=false, 1=true) (bool).
Definition RtypesCore.h:77
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
float Float_t
Float 4 bytes (float).
Definition RtypesCore.h:71
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
static void Pixel2RGB(ULong_t pixel, Int_t &r, Int_t &g, Int_t &b)
void WindowToViewport(Int_t &, Int_t &y) const
Definition TGLCamera.h:198
TGLRect & RefViewport()
Definition TGLCamera.h:128
TGLOverlayButton(const TGLOverlayButton &)=delete
void Render(TGLRnrCtx &rnrCtx) override
Render the overlay elements.
void MouseLeave() override
Mouse has left overlay area.
Bool_t Handle(TGLRnrCtx &rnrCtx, TGLOvlSelectRecord &selRec, Event_t *event) override
Handle overlay event.
virtual void Clicked(TGLViewerBase *viewer)
Emits "Clicked(TGLViewerBase*)" signal.
Bool_t MouseEnter(TGLOvlSelectRecord &selRec) override
Mouse has entered overlay area.
TGLOverlayElement(const TGLOverlayElement &)=delete
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:1786
static Float_t LineWidth()
Get the line-width, taking the global scaling into account.
Definition TGLUtil.cxx:1934
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
TText * text
Int_t Nint(T x)
Round to nearest integer. Rounds half integers to the nearest even integer.
Definition TMath.h:704
Event structure.
Definition GuiTypes.h:175
EGEventType fType
of event (see EGEventType)
Definition GuiTypes.h:176
UInt_t fCode
key or button code
Definition GuiTypes.h:181