Eclipse SUMO - Simulation of Urban MObility
GUIPerspectiveChanger.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2022 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
20 // A class that allows to steer the visual output in dependence to user
21 /****************************************************************************/
22 #include <config.h>
23 
24 #include "GUISUMOAbstractView.h"
25 #include "GUIPerspectiveChanger.h"
26 
27 
28 // ===========================================================================
29 // method definitions
30 // ===========================================================================
32  myCallback(callBack),
33  myViewPort(viewPort) {
34 }
35 
36 
38 }
39 
40 
41 void
43 }
44 
45 
46 bool
48  return false;
49 }
50 
51 
52 void
54 }
55 
56 
57 bool
59  return false;
60 }
61 
62 void
64 }
65 
66 
67 void
69 }
70 
71 
72 void
74 }
75 
76 
77 long
79  return 0;
80 }
81 
82 
83 long
85  return 0;
86 }
87 
88 
89 FXint
91  return myMouseXPosition;
92 }
93 
94 
95 FXint
97  return myMouseYPosition;
98 }
99 
100 
101 Boundary
103  if (fixRatio) {
104  return patchedViewPort();
105  } else {
106  return myViewPort;
107  }
108 }
109 
110 
111 void
113  myViewPort = viewPort;
114 }
115 
116 
117 Boundary
119  // avoid division by zero
120  if (myCallback.getHeight() == 0 ||
121  myCallback.getWidth() == 0 ||
122  myViewPort.getHeight() == 0 ||
123  myViewPort.getWidth() == 0) {
124  return myViewPort;
125  }
126  Boundary result = myViewPort;
127  double canvasRatio = (double)myCallback.getWidth() / myCallback.getHeight();
128  double ratio = result.getWidth() / result.getHeight();
129  if (ratio < canvasRatio) {
130  result.growWidth(result.getWidth() * (canvasRatio / ratio - 1) / 2);
131  } else {
132  result.growHeight(result.getHeight() * (ratio / canvasRatio - 1) / 2);
133  }
134  return result;
135 }
136 
137 
138 /****************************************************************************/
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:39
void growHeight(double by)
Increases the height of the boundary (y-axis)
Definition: Boundary.cpp:324
double getHeight() const
Returns the height of the boundary (y-axis)
Definition: Boundary.cpp:159
double getWidth() const
Returns the width of the boudary (x-axis)
Definition: Boundary.cpp:153
void growWidth(double by)
Increases the width of the boundary (x-axis)
Definition: Boundary.cpp:317
GUISUMOAbstractView & myCallback
The parent window (canvas to scale)
virtual long onKeyPress(void *data)
called when user press a key
virtual void onRightBtnPress(void *data)
called when user press right button
virtual ~GUIPerspectiveChanger()
Destructor.
virtual bool onLeftBtnRelease(void *data)
called when user releases left button
Boundary myViewPort
the intended viewport
GUIPerspectiveChanger(GUISUMOAbstractView &callBack, const Boundary &viewPort)
Constructor.
virtual void onLeftBtnPress(void *data)
mouse functions
FXint getMouseXPosition() const
Returns the last mouse x-position an event occurred at.
virtual void onDoubleClicked(void *data)
called when user click two times
FXint getMouseYPosition() const
Returns the last mouse y-position an event occurred at.
virtual long onKeyRelease(void *data)
called when user releases a key
Boundary patchedViewPort()
patched viewPort with the same aspect ratio as the canvas
FXint myMouseXPosition
the current mouse position
virtual void onMouseMove(void *data)
called when user moves mouse
virtual void onMouseWheel(void *data)
called when user changes mouse wheel
virtual bool onRightBtnRelease(void *data)
called when user releases right button
Boundary getViewport(bool fixRatio=true)
get viewport
virtual void setViewport(double zoom, double xPos, double yPos)=0
Sets the viewport Used for: Adapting a new viewport.