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
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;
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);
71
72 Float_t offset = (fPosY >= 0.0)? 0.0 : vp.Height()-fHeight;
73
80 glClearColor(0.0, 0.0, 0.0, 0.0);
81 glPushName(1);
82
83 // Button rendering
84 {
86 glPolygonOffset(0.5f, 0.5f);
89 // First the border, same color as text
93 glBegin(GL_LINE_LOOP);
94 glVertex2f(0.0, 0.0);
95 glVertex2f(0.0, 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...
104 glVertex2f(0.0, 0.0);
105 glVertex2f(0.0, fHeight);
107 glVertex2f(fWidth, 0.0);
108 glEnd();
109 glPopMatrix();
110 }
111
112 // Text rendering
113 {
114 rnrCtx.RegisterFontNoScale(TMath::Nint(fHeight*0.8), "arial", TGLFont::kPixmap, fFont);
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);
127 glPopMatrix();
128 }
129 glPopName();
130
132 glPopMatrix();
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:60
@ kButtonPress
Definition GuiTypes.h:60
@ kButton1
Definition GuiTypes.h:214
#define b(i)
Definition RSha256.hxx:100
#define g(i)
Definition RSha256.hxx:105
long Longptr_t
Integer large enough to hold a pointer (platform-dependent)
Definition RtypesCore.h:89
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t rect
Option_t Option_t width
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t height
Option_t Option_t TPoint TPoint const char text
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:2521
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.
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.
An overlay element.
Definition TGLOverlay.h:23
Selection record for overlay objects.
Viewport (pixel base) 2D rectangle class.
Definition TGLUtil.h:422
The TGLRnrCtx class aggregates data for a given redering context as needed by various parts of the RO...
Definition TGLRnrCtx.h:41
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
const char * Data() const
Definition TString.h:384
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:174
EGEventType fType
of event (see EGEventType)
Definition GuiTypes.h:175
UInt_t fCode
key or button code
Definition GuiTypes.h:180