Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGLManip.cxx
Go to the documentation of this file.
1// @(#)root/gl:$Id$
2// Author: Richard Maunder 16/09/2005
3
4/*************************************************************************
5 * Copyright (C) 1995-2005, 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 "TGLManip.h"
13#include "TGLUtil.h"
14#include "TGLCamera.h"
15#include "TGLPhysicalShape.h"
16#include "TGLIncludes.h"
17
18/** \class TGLManip
19\ingroup opengl
20Abstract base class for viewer manipulators, which allow direct in
21viewer manipulation of a (TGlPhysicalShape) object - currently
22translation, scaling and rotation along/round objects local axes.
23See derived classes for these implementations.
24
25This class provides binding to the zero or one manipulated physical,
26hit testing (selection) for manipulator sub component (widget), and
27some common mouse action handling/tracking.
28*/
29
31
32////////////////////////////////////////////////////////////////////////////////
33/// Construct a manipulator object, bound to supplied viewer, and no
34/// physical shape.
35
37 fShape(nullptr),
38 fSelectedWidget(0), fActive(kFALSE),
39 fFirstMouse(0, 0),
40 fLastMouse(0, 0)
41{
42}
43
44////////////////////////////////////////////////////////////////////////////////
45/// Construct a manipulator object, bound to supplied physical shape.
46
48 fShape(shape),
49 fSelectedWidget(0), fActive(kFALSE),
50 fFirstMouse(0, 0),
51 fLastMouse(0, 0)
52{
53}
54
55////////////////////////////////////////////////////////////////////////////////
56/// Copy constructor.
57
60 fShape(gm.fShape),
61 fSelectedWidget(gm.fSelectedWidget),
62 fActive(gm.fActive),
63 fFirstMouse(gm.fFirstMouse),
64 fLastMouse(gm.fLastMouse)
65{
66}
67
68////////////////////////////////////////////////////////////////////////////////
69/// Assignment operator.
70
72{
73 if(this!=&gm) {
74 TVirtualGLManip::operator=(gm);
75 fShape=gm.fShape;
80 }
81 return *this;
82}
83
84////////////////////////////////////////////////////////////////////////////////
85/// Destroy manipulator object.
86
88{
89}
90
91////////////////////////////////////////////////////////////////////////////////
92/// Returns color to be used for given widget.
93
94const UChar_t* TGLManip::ColorFor(UInt_t widget) const
95{
96 if (widget == fSelectedWidget)
97 {
98 return TGLUtil::fgYellow;
99 }
100 else
101 {
102 switch (widget)
103 {
104 case 1: return TGLUtil::fgRed;
105 case 2: return TGLUtil::fgGreen;
106 case 3: return TGLUtil::fgBlue;
107 default: return TGLUtil::fgGrey;
108 }
109 }
110}
111
112////////////////////////////////////////////////////////////////////////////////
113/// Handle a mouse button event - return kTRUE if processed, kFALSE otherwise
114
115Bool_t TGLManip::HandleButton(const Event_t& event, const TGLCamera& /*camera*/)
116{
117 // Only interested in Left mouse button actions
118 if (event.fCode != kButton1) {
119 return kFALSE;
120 }
121
122 // Mouse down on selected widget?
123 if (event.fType == kButtonPress && fSelectedWidget != 0) {
124 fFirstMouse.SetX(event.fX);
125 fFirstMouse.SetY(event.fY);
126 fLastMouse.SetX(event.fX);
127 fLastMouse.SetY(event.fY);
128 fActive = kTRUE;
129 return kTRUE;
130 } else if (event.fType == kButtonRelease && fActive) {
131 fActive = kFALSE;
132 return kTRUE;
133 } else {
134 return kFALSE;
135 }
136}
137
138////////////////////////////////////////////////////////////////////////////////
139/// Handle a mouse button event - return kTRUE if widget selection change
140/// kFALSE otherwise
141
143 const TGLCamera& /*camera*/)
144{
145 return kFALSE;
146}
147
148////////////////////////////////////////////////////////////////////////////////
149/// Calculates base and axis scale factor (in world units) for
150/// drawing manipulators with reasonable size range in current
151/// camera.
152
154 const TGLCamera& camera,
155 Double_t& base,
156 TGLVector3 axis[3]) const
157{
158 // Calculate a base scale
159 base = box.Extents().Mag() / 100.0;
160
161 // Clamp this base scale to a viewport pixel range
162 // Allow some variation so zooming is noticeable
163 TGLVector3 pixelInWorld = camera.ViewportDeltaToWorld(box.Center(), 1, 1);
164 Double_t pixelScale = pixelInWorld.Mag();
165 if (base < pixelScale * 3.0) {
166 base = pixelScale * 3.0;
167 } else if (base > pixelScale * 6.0) {
168 base = pixelScale * 6.0;
169 }
170
171 // Calculate some axis scales
172 for (UInt_t i = 0; i<3; i++) {
173 if (box.IsEmpty()) {
174 axis[i] = box.Axis(i, kTRUE)*base*-10.0;
175 } else {
176 axis[i] = box.Axis(i, kFALSE)*-0.51;
177 if (axis[i].Mag() < base*10.0) {
178 axis[i] = box.Axis(i, kTRUE)*base*-10.0;
179 }
180 }
181 }
182}
dims_t fShape
@ kButtonRelease
Definition GuiTypes.h:60
@ kButtonPress
Definition GuiTypes.h:60
@ kButton1
Definition GuiTypes.h:214
unsigned char UChar_t
Definition RtypesCore.h:38
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
#define ClassImp(name)
Definition Rtypes.h:382
Concrete class describing an orientated (free) or axis aligned box of 8 vertices.
Abstract base camera class - concrete classes for orthographic and perspective cameras derive from it...
Definition TGLCamera.h:44
TGLVector3 ViewportDeltaToWorld(const TGLVertex3 &worldRef, Double_t viewportXDelta, Double_t viewportYDelta, TGLMatrix *modviewMat=nullptr) const
Apply a 2D viewport delta (shift) to the projection of worldRef onto viewport, returning the resultan...
Abstract base class for viewer manipulators, which allow direct in viewer manipulation of a (TGlPhysi...
Definition TGLManip.h:29
TGLManip()
Construct a manipulator object, bound to supplied viewer, and no physical shape.
Definition TGLManip.cxx:36
TGLManip & operator=(const TGLManip &)
Assignment operator.
Definition TGLManip.cxx:71
TPoint fLastMouse
first (start) mouse position (in WINDOW coords)
Definition TGLManip.h:37
const UChar_t * ColorFor(UInt_t widget) const
Returns color to be used for given widget.
Definition TGLManip.cxx:94
TPoint fFirstMouse
manipulator is active?
Definition TGLManip.h:36
virtual Bool_t HandleButton(const Event_t &event, const TGLCamera &camera)
Handle a mouse button event - return kTRUE if processed, kFALSE otherwise.
Definition TGLManip.cxx:115
Bool_t fActive
active width (axis) component
Definition TGLManip.h:33
void CalcDrawScale(const TGLBoundingBox &box, const TGLCamera &camera, Double_t &base, TGLVector3 axis[3]) const
Calculates base and axis scale factor (in world units) for drawing manipulators with reasonable size ...
Definition TGLManip.cxx:153
UInt_t fSelectedWidget
manipulated shape
Definition TGLManip.h:32
TGLPhysicalShape * fShape
Definition TGLManip.h:31
virtual Bool_t HandleMotion(const Event_t &event, const TGLCamera &camera)
Handle a mouse button event - return kTRUE if widget selection change kFALSE otherwise.
Definition TGLManip.cxx:142
~TGLManip() override
Destroy manipulator object.
Definition TGLManip.cxx:87
Concrete physical shape - a GL drawable.
static const UChar_t fgRed[4]
Definition TGLUtil.h:1056
static const UChar_t fgBlue[4]
Definition TGLUtil.h:1058
static const UChar_t fgGrey[4]
Definition TGLUtil.h:1061
static const UChar_t fgGreen[4]
Definition TGLUtil.h:1057
static const UChar_t fgYellow[4]
Definition TGLUtil.h:1059
3 component (x/y/z) vector class.
Definition TGLUtil.h:248
Double_t Mag() const
Definition TGLUtil.h:298
void SetX(SCoord_t x)
Definition TPoint.h:48
void SetY(SCoord_t y)
Definition TPoint.h:49
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition fillpatterns.C:1
Event structure.
Definition GuiTypes.h:174
EGEventType fType
of event (see EGEventType)
Definition GuiTypes.h:175
Int_t fY
pointer x, y coordinates in event window
Definition GuiTypes.h:178
Int_t fX
Definition GuiTypes.h:178
UInt_t fCode
key or button code
Definition GuiTypes.h:180