Visualization Library 2.0.0

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
FlatManipulator.hpp
Go to the documentation of this file.
1 /**************************************************************************************/
2 /* */
3 /* Visualization Library */
4 /* http://visualizationlibrary.org */
5 /* */
6 /* Copyright (c) 2005-2020, Michele Bosi */
7 /* All rights reserved. */
8 /* */
9 /* Redistribution and use in source and binary forms, with or without modification, */
10 /* are permitted provided that the following conditions are met: */
11 /* */
12 /* - Redistributions of source code must retain the above copyright notice, this */
13 /* list of conditions and the following disclaimer. */
14 /* */
15 /* - Redistributions in binary form must reproduce the above copyright notice, this */
16 /* list of conditions and the following disclaimer in the documentation and/or */
17 /* other materials provided with the distribution. */
18 /* */
19 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */
20 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */
21 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
22 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */
23 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
24 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
25 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
26 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
27 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
28 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
29 /* */
30 /**************************************************************************************/
31 
32 #ifndef FlatManipulator_INCLUDE_ONCE
33 #define FlatManipulator_INCLUDE_ONCE
34 
35 #include <vlCore/Vector3.hpp>
36 #include <vlCore/Vector4.hpp>
38 #include <vlGraphics/Camera.hpp>
39 #include <vlGraphics/Geometry.hpp>
40 
41 // mic fixme: clean up this mess
42 
43 namespace vl
44 {
45 
46  //------------------------------------------------------------------------------
47  // FlatManipulator
48  //------------------------------------------------------------------------------
58 {
60 
61  public:
63 
66 
67  // --- UIEventListener ---
68 
69  virtual void mouseDownEvent(EMouseButton, int x, int y);
70 
71  virtual void mouseUpEvent(EMouseButton, int x, int y);
72 
73  virtual void mouseMoveEvent(int x, int y);
74 
75  virtual void enableEvent(bool enabled);
76 
77  virtual void initEvent() {}
78 
79  virtual void destroyEvent() {}
80 
81  virtual void updateEvent() {}
82 
84 
86 
87  virtual void mouseWheelEvent(int) {}
88 
89  virtual void keyPressEvent(unsigned short, EKey) {}
90 
91  virtual void keyReleaseEvent(unsigned short, EKey) {}
92 
93  virtual void resizeEvent(int, int) {}
94 
95  virtual void fileDroppedEvent(const std::vector<String>&) {}
96 
97  virtual void visibilityEvent(bool) {}
98 
99  // --- user methods ---
100 
102  void setCamera(Camera* camera);
103 
105  Camera* camera() { return mCamera.get(); }
106 
108  int zoomButton() const { return mZoomButton; }
109 
111  void setZoomButton(int mouse_button) { mZoomButton = mouse_button; }
112 
114  int translationButton() const { return mTranslationButton; }
115 
117  void setTranslationButton(int mouse_button) { mTranslationButton = mouse_button; }
118 
120  float zoomSpeed() const { return mZoomSpeed; }
121 
123  void setZoomSpeed(float speed) { mZoomSpeed = speed; }
124 
126  EManipMode mode() const { return mMode; }
127 
128  protected:
129 
130  bool mouseInViewport(int mx, int my, int& vx, int& vy);
131 
132  protected:
136  EManipMode mMode;
139  float mZoomSpeed;
140  };
141 
143 
155 vl::ref<vl::Geometry> makeScales(bool X = true,
156  bool Y = true,
157  bool Z = true,
158  int numArmTicks = 50,
159  float mmStep = 10,
160  float mmTickSize = 4,
161  vl::fvec4 color = vl::fvec4(1,1,1,1));
162 }
163 
164 #endif
virtual void removedListenerEvent(OpenGLContext *)
Event generated whenever a listener is unbound from an OpenGLContext context.
void setZoomButton(int mouse_button)
Mouse button used to zoom.
bool mouseInViewport(int mx, int my, int &vx, int &vy)
virtual void destroyEvent()
Event generated right before the bound OpenGLContext is destroyed.
float zoomSpeed() const
Zoom speed multiplicative factor (default = 1).
The UIEventListener class listens to the events emitted by an OpenGLContext.
virtual void keyReleaseEvent(unsigned short, EKey)
Event generated when a key is released.
virtual void mouseMoveEvent(int x, int y)
Event generated when the mouse moves.
virtual void resizeEvent(int, int)
Event generated when the bound OpenGLContext is resized.
virtual void visibilityEvent(bool)
Event generated when the bound OpenGLContext is shown or hidden.
void setZoomSpeed(float speed)
Zoom speed multiplicative factor (default = 1).
Represents an OpenGL context, possibly a widget or a pbuffer, which can also respond to keyboard...
virtual void addedListenerEvent(OpenGLContext *)
Event generated whenever a listener is bound to an OpenGLContext context.
virtual void enableEvent(bool enabled)
Event generated whenever setEnabled() is called.
Camera * camera()
The camera through which the manipulator is used.
#define VL_INSTRUMENT_CLASS(ClassName, BaseClass)
Definition: TypeInfo.hpp:122
virtual void mouseUpEvent(EMouseButton, int x, int y)
Event generated when one of the mouse buttons is released.
This class lets you pan (translate) and zoom a 2D scene using the mouse.
void setCamera(Camera *camera)
The camera through which the manipulator is used.
Visualization Library main namespace.
virtual void mouseWheelEvent(int)
Event generated when the mouse wheel rotated.
virtual void fileDroppedEvent(const std::vector< String > &)
Event generated when one or more files are dropped on the bound OpenGLContext&#39;s area.
virtual void updateEvent()
Event generated when the bound OpenGLContext does not have any other message to process and OpenGLCon...
FlatManipulator()
Constructor.
EMouseButton
virtual void keyPressEvent(unsigned short, EKey)
Event generated when a key is pressed.
virtual void initEvent()
Event generated when the bound OpenGLContext bocomes initialized or when the event listener is bound ...
virtual void mouseDownEvent(EMouseButton, int x, int y)
Event generated when one of the mouse buttons is pressed.
void setTranslationButton(int mouse_button)
Mouse button used to translate the view.
int zoomButton() const
Mouse button used to zoom.
vl::ref< vl::Geometry > makeScales(bool X=true, bool Y=true, bool Z=true, int numArmTicks=50, float mmStep=10, float mmTickSize=4, vl::fvec4 color=vl::fvec4(1, 1, 1, 1))
Makes an orthogonal cross-hair scales (reticle).
The ref<> class is used to reference-count an Object.
Definition: Object.hpp:55
EManipMode mode() const
Returns the current manipulator state.
Represents a virtual camera defining, among other things, the point of view from which scenes can be ...
Definition: Camera.hpp:50
int translationButton() const
Mouse button used to translate the view.