1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
10 /// @file    GUIDanielPerspectiveChanger.h
11 /// @author  Daniel Krajzewicz
12 /// @author  Jakob Erdmann
13 /// @author  Michael Behrisch
14 /// @date    Sept 2002
15 /// @version $Id$
16 ///
17 // A class that allows to steer the visual output in dependence to
18 /****************************************************************************/
19 #ifndef GUIDanielPerspectiveChanger_h
20 #define GUIDanielPerspectiveChanger_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <utils/geom/Position.h>
29 #include "GUIPerspectiveChanger.h"
30 
31 
32 // ===========================================================================
33 // class declarations
34 // ===========================================================================
35 class Boundary;
36 
37 
38 // ===========================================================================
39 // class definitions
40 // ===========================================================================
41 /**
42  * @class GUIDanielPerspectiveChanger
43  * This changer has the following behaviour:
44  * - zooming by pressing the right mouse button and moving the
45  *  mouse vertically
46  * - rotation by pressing the right mouse button and moving the
47  *  mouse horizontally
48  * - network movement by pressing the left mouse button and
49  *  moving the mouse
50  */
51 class GUIDanielPerspectiveChanger : public GUIPerspectiveChanger {
52 public:
53     /* Constructor
54      * @param[in] callBack The view to be udpated upon changes
55      */
56     GUIDanielPerspectiveChanger(GUISUMOAbstractView& callBack, const Boundary& viewPort);
57 
58     /// Destructor
59     ~GUIDanielPerspectiveChanger();
60 
61     void onLeftBtnPress(void* data);
62     bool onLeftBtnRelease(void* data);
63     void onRightBtnPress(void* data);
64     bool onRightBtnRelease(void* data);
65     void onMouseWheel(void* data);
66     void onMouseMove(void* data);
67     long onKeyPress(void* data);
68 
69     /// Returns the rotation of the canvas stored in this changer
70     virtual double getRotation() const;
71 
72     /// Returns the x-offset of the field to show stored in this changer
73     virtual double getXPos() const;
74 
75     /// Returns the y-offset of the field to show stored in this changer
76     virtual double getYPos() const;
77 
78     /// Returns the zoom factor computed stored in this changer
79     virtual double getZoom() const;
80 
81     /// @brief Returns the camera height corresponding to the current zoom factor
82     virtual double getZPos() const;
83 
84     /// @brief Returns the camera height at which the given zoom level is reached
85     virtual double zoom2ZPos(double zoom) const;
86 
87     /// @brief Returns the zoom level that is achieved at a given camera height
88     virtual double zPos2Zoom(double zPos) const;
89 
90     /// Centers the view to the given position, setting it to a size that covers the radius
91     void centerTo(const Position& pos, double radius, bool applyZoom = true);
92 
93     /** @brief Sets the viewport */
94     void setViewport(double zoom, double xPos, double yPos);
95 
96     /// @brief Alternative method for setting the viewport
97     void setViewportFrom(double xPos, double yPos, double zPos);
98 
99     /// @brief Sets the rotation
100     void setRotation(double rotation);
101 
102     /* @brief Adapts the viewport so that a change in canvass size keeps most of the
103      * view intact (by showing more / less instead of zooming)
104      * The canvass is clipped/enlarged on the left side of the screen
105      *
106      * @param[in] change The horizontal change in canvas size in pixels
107      */
108     void changeCanvasSizeLeft(int change);
109 
110     /* @brief avoid unwanted flicker
111      * @param[in] delay The minimum time delay in nanoseconds after
112      *   mouseDown after which mouse-movements should be interpreted as zoom/drag
113      */
setDragDelay(FXTime delay)114     void setDragDelay(FXTime delay) {
115         myDragDelay = delay;
116     }
117 
118 private:
119     /* Performs the view movement
120      * @param[in] xdiff the change to myViewCenter in pixel
121      * @param[in] ydiff the change to myViewCenter in pixel
122      */
123     void move(int xdiff, int ydiff);
124 
125     /// Performs the zooming of the view
126     void zoom(double factor);
127 
128     /// Performs the rotation of the view
129     void rotate(int diff);
130 
131 private:
132     /// the original viewport dimensions in m which serve as the reference point for 100% zoom
133     double myOrigWidth, myOrigHeight;
134 
135     /// the current rotation
136     double myRotation;
137 
138     /// the current mouse state
139     int myMouseButtonState;
140 
141     /// Information whether the user has moved the cursor while pressing a mouse button
142     bool myMoveOnClick;
143 
144     /// the network location on which to zoom using right click+drag
145     Position myZoomBase;
146 
147     /// avoid flicker
148     FXTime myDragDelay;
149     FXlong myMouseDownTime;
150 
151 
152 private:
153     /// @brief Invalidated copy constructor.
154     GUIDanielPerspectiveChanger(const GUIDanielPerspectiveChanger&);
155 
156     /// @brief Invalidated assignment operator.
157     GUIDanielPerspectiveChanger& operator=(const GUIDanielPerspectiveChanger&);
158 
159 };
160 
161 
162 #endif
163 
164 /****************************************************************************/
165 
166