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.dev/sumo
3 // Copyright (C) 2001-2024 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  // reimplement in child
44 }
45 
46 
47 bool
49  // reimplement in child
50  return false;
51 }
52 
53 
54 void
56  // reimplement in child
57 }
58 
59 
60 bool
62  // reimplement in child
63  return false;
64 }
65 
66 
67 void
69  // reimplement in child
70 }
71 
72 
73 bool
75  // reimplement in child
76  return false;
77 }
78 
79 void
81  // reimplement in child
82 }
83 
84 
85 void
87  // reimplement in child
88 }
89 
90 
91 void
93  // reimplement in child
94 }
95 
96 
97 long
99  // reimplement in child
100  return 0;
101 }
102 
103 
104 long
106  // reimplement in child
107  return 0;
108 }
109 
110 
111 FXint
113  return myMouseXPosition;
114 }
115 
116 
117 FXint
119  return myMouseYPosition;
120 }
121 
122 
123 Boundary
125  if (fixRatio) {
126  return patchedViewPort();
127  } else {
128  return myViewPort;
129  }
130 }
131 
132 
133 void
135  myViewPort = viewPort;
136 }
137 
138 
139 Boundary
141  // avoid division by zero
142  if (myCallback.getHeight() == 0 ||
143  myCallback.getWidth() == 0 ||
144  myViewPort.getHeight() == 0 ||
145  myViewPort.getWidth() == 0) {
146  return myViewPort;
147  }
148  Boundary result = myViewPort;
149  double canvasRatio = (double)myCallback.getWidth() / myCallback.getHeight();
150  double ratio = result.getWidth() / result.getHeight();
151  if (ratio < canvasRatio) {
152  result.growWidth(result.getWidth() * (canvasRatio / ratio - 1) / 2);
153  } else {
154  result.growHeight(result.getHeight() * (ratio / canvasRatio - 1) / 2);
155  }
156  return result;
157 }
158 
159 
160 /****************************************************************************/
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:345
double getHeight() const
Returns the height of the boundary (y-axis)
Definition: Boundary.cpp:160
double getWidth() const
Returns the width of the boudary (x-axis)
Definition: Boundary.cpp:154
void growWidth(double by)
Increases the width of the boundary (x-axis)
Definition: Boundary.cpp:338
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 bool onMiddleBtnRelease(void *data)
called when user releases middle button
virtual void onDoubleClicked(void *data)
called when user click two times
virtual void onMiddleBtnPress(void *data)
called when user press middle button
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.