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
30
31////////////////////////////////////////////////////////////////////////////////
32/// Construct a manipulator object, bound to supplied viewer, and no
33/// physical shape.
34
36 fShape(nullptr),
37 fSelectedWidget(0), fActive(kFALSE),
38 fFirstMouse(0, 0),
39 fLastMouse(0, 0)
40{
41}
42
43////////////////////////////////////////////////////////////////////////////////
44/// Construct a manipulator object, bound to supplied physical shape.
45
47 fShape(shape),
48 fSelectedWidget(0), fActive(kFALSE),
49 fFirstMouse(0, 0),
50 fLastMouse(0, 0)
51{
52}
53
54////////////////////////////////////////////////////////////////////////////////
55/// Copy constructor.
56
60 fSelectedWidget(gm.fSelectedWidget),
61 fActive(gm.fActive),
62 fFirstMouse(gm.fFirstMouse),
63 fLastMouse(gm.fLastMouse)
64{
65}
66
67////////////////////////////////////////////////////////////////////////////////
68/// Assignment operator.
69
71{
72 if(this!=&gm) {
73 TVirtualGLManip::operator=(gm);
74 fShape=gm.fShape;
75 fSelectedWidget=gm.fSelectedWidget;
76 fActive=gm.fActive;
77 fFirstMouse=gm.fFirstMouse;
78 fLastMouse=gm.fLastMouse;
79 }
80 return *this;
81}
82
83////////////////////////////////////////////////////////////////////////////////
84/// Destroy manipulator object.
85
89
90////////////////////////////////////////////////////////////////////////////////
91/// Returns color to be used for given widget.
92
94{
96 {
97 return TGLUtil::fgYellow;
98 }
99 else
100 {
101 switch (widget)
102 {
103 case 1: return TGLUtil::fgRed;
104 case 2: return TGLUtil::fgGreen;
105 case 3: return TGLUtil::fgBlue;
106 default: return TGLUtil::fgGrey;
107 }
108 }
109}
110
111////////////////////////////////////////////////////////////////////////////////
112/// Handle a mouse button event - return kTRUE if processed, kFALSE otherwise
113
114Bool_t TGLManip::HandleButton(const Event_t& event, const TGLCamera& /*camera*/)
115{
116 // Only interested in Left mouse button actions
117 if (event.fCode != kButton1) {
118 return kFALSE;
119 }
120
121 // Mouse down on selected widget?
122 if (event.fType == kButtonPress && fSelectedWidget != 0) {
123 fFirstMouse.SetX(event.fX);
124 fFirstMouse.SetY(event.fY);
125 fLastMouse.SetX(event.fX);
126 fLastMouse.SetY(event.fY);
127 fActive = kTRUE;
128 return kTRUE;
129 } else if (event.fType == kButtonRelease && fActive) {
130 fActive = kFALSE;
131 return kTRUE;
132 } else {
133 return kFALSE;
134 }
135}
136
137////////////////////////////////////////////////////////////////////////////////
138/// Handle a mouse button event - return kTRUE if widget selection change
139/// kFALSE otherwise
140
142 const TGLCamera& /*camera*/)
143{
144 return kFALSE;
145}
146
147////////////////////////////////////////////////////////////////////////////////
148/// Calculates base and axis scale factor (in world units) for
149/// drawing manipulators with reasonable size range in current
150/// camera.
151
153 const TGLCamera& camera,
154 Double_t& base,
155 TGLVector3 axis[3]) const
156{
157 // Calculate a base scale
158 base = box.Extents().Mag() / 100.0;
159
160 // Clamp this base scale to a viewport pixel range
161 // Allow some variation so zooming is noticeable
162 TGLVector3 pixelInWorld = camera.ViewportDeltaToWorld(box.Center(), 1, 1);
164 if (base < pixelScale * 3.0) {
165 base = pixelScale * 3.0;
166 } else if (base > pixelScale * 6.0) {
167 base = pixelScale * 6.0;
168 }
169
170 // Calculate some axis scales
171 for (UInt_t i = 0; i<3; i++) {
172 if (box.IsEmpty()) {
173 axis[i] = box.Axis(i, kTRUE)*base*-10.0;
174 } else {
175 axis[i] = box.Axis(i, kFALSE)*-0.51;
176 if (axis[i].Mag() < base*10.0) {
177 axis[i] = box.Axis(i, kTRUE)*base*-10.0;
178 }
179 }
180 }
181}
dims_t fShape
@ kButtonRelease
Definition GuiTypes.h:60
@ kButtonPress
Definition GuiTypes.h:60
@ kButton1
Definition GuiTypes.h:214
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
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
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:35
TGLManip & operator=(const TGLManip &)
Assignment operator.
Definition TGLManip.cxx:70
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:93
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:114
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:152
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:141
~TGLManip() override
Destroy manipulator object.
Definition TGLManip.cxx:86
Concrete physical shape - a GL drawable.
static const UChar_t fgRed[4]
Definition TGLUtil.h:1421
static const UChar_t fgBlue[4]
Definition TGLUtil.h:1423
static const UChar_t fgGrey[4]
Definition TGLUtil.h:1426
static const UChar_t fgGreen[4]
Definition TGLUtil.h:1422
static const UChar_t fgYellow[4]
Definition TGLUtil.h:1424
3 component (x/y/z) vector class.
Definition TGLUtil.h:248
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