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
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;
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);
72
73 Float_t offset = (fPosY >= 0.0)? 0.0 : vp.Height()-fHeight;
74
81 glClearColor(0.0, 0.0, 0.0, 0.0);
82 glPushName(1);
83
84 // Button rendering
85 {
87 glPolygonOffset(0.5f, 0.5f);
90 // First the border, same color as text
94 glBegin(GL_LINE_LOOP);
95 glVertex2f(0.0, 0.0);
96 glVertex2f(0.0, 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...
105 glVertex2f(0.0, 0.0);
106 glVertex2f(0.0, fHeight);
108 glVertex2f(fWidth, 0.0);
109 glEnd();
110 glPopMatrix();
111 }
112
113 // Text rendering
114 {
115 rnrCtx.RegisterFontNoScale(TMath::Nint(fHeight*0.8), "arial", TGLFont::kPixmap, fFont);
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, nullptr);
128 glPopMatrix();
129 }
130 glPopName();
131
133 glPopMatrix();
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
188
189////////////////////////////////////////////////////////////////////////////////
190/// Mouse has left overlay area.
191
193{
194 fActiveID = -1;
195}
@ 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
Definition RtypesCore.h:75
float Float_t
Definition RtypesCore.h:57
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
#define ClassImp(name)
Definition Rtypes.h:374
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:2517
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 &)=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:1795
static Float_t LineWidth()
Get the line-width, taking the global scaling into account.
Definition TGLUtil.cxx:1943
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:376
Int_t Nint(T x)
Round to nearest integer. Rounds half integers to the nearest even integer.
Definition TMath.h:697
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