SUMO - Simulation of Urban MObility
GUIPerspectiveChanger.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // A class that allows to steer the visual output in dependence to user
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include "GUISUMOAbstractView.h"
34 #include "GUIPerspectiveChanger.h"
35 
36 #ifdef CHECK_MEMORY_LEAKS
37 #include <foreign/nvwa/debug_new.h>
38 #endif // CHECK_MEMORY_LEAKS
39 
40 
41 // ===========================================================================
42 // method definitions
43 // ===========================================================================
45  myCallback(callBack),
46  myViewPort(viewPort) {
47 }
48 
49 
51 }
52 
53 
54 void
56 }
57 
58 
59 bool
61  return false;
62 }
63 
64 
65 void
67 }
68 
69 
70 bool
72  return false;
73 }
74 
75 void
77 }
78 
79 
80 void
82 }
83 
84 
85 void
87 }
88 
89 
90 long
92  return 0;
93 }
94 
95 
96 long
98  return 0;
99 }
100 
101 
102 FXint
104  return myMouseXPosition;
105 }
106 
107 
108 FXint
110  return myMouseYPosition;
111 }
112 
113 
114 Boundary
116  if (fixRatio) {
117  return patchedViewPort();
118  } else {
119  return myViewPort;
120  }
121 }
122 
123 
124 void
126  myViewPort = viewPort;
127 }
128 
129 
130 Boundary
132  // avoid division by zero
133  if (myCallback.getHeight() == 0 ||
134  myCallback.getWidth() == 0 ||
135  myViewPort.getHeight() == 0 ||
136  myViewPort.getWidth() == 0) {
137  return myViewPort;
138  }
139  Boundary result = myViewPort;
140  SUMOReal canvasRatio = (SUMOReal)myCallback.getWidth() / myCallback.getHeight();
141  SUMOReal ratio = result.getWidth() / result.getHeight();
142  if (ratio < canvasRatio) {
143  result.growWidth(result.getWidth() * (canvasRatio / ratio - 1) / 2);
144  } else {
145  result.growHeight(result.getHeight() * (ratio / canvasRatio - 1) / 2);
146  }
147  return result;
148 }
149 
150 /****************************************************************************/
151 
SUMOReal getHeight() const
Returns the height of the boundary.
Definition: Boundary.cpp:142
void growWidth(SUMOReal by)
Definition: Boundary.cpp:210
virtual void setViewport(SUMOReal zoom, SUMOReal xPos, SUMOReal yPos)=0
Sets the viewport Used for: Adapting a new viewport.
SUMOReal getWidth() const
Returns the width of the boudary.
Definition: Boundary.cpp:136
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
Boundary patchedViewPort()
patched viewPort with the same aspect ratio as the canvas
virtual bool onLeftBtnRelease(void *data)
called when user releases left button
virtual bool onRightBtnRelease(void *data)
called when user releases right button
GUISUMOAbstractView & myCallback
The parent window (canvas to scale)
virtual void onLeftBtnPress(void *data)
mouse functions
Boundary getViewport(bool fixRatio=true)
get viewport
FXint getMouseXPosition() const
Returns the last mouse x-position an event occured at.
Boundary myViewPort
the intended viewport
virtual void onMouseWheel(void *data)
called when user changes mouse wheel
virtual long onKeyPress(void *data)
called when user press a key
FXint getMouseYPosition() const
Returns the last mouse y-position an event occured at.
GUIPerspectiveChanger(GUISUMOAbstractView &callBack, const Boundary &viewPort)
Constructor.
virtual void onDoubleClicked(void *data)
called when user click two times
#define SUMOReal
Definition: config.h:213
virtual void onMouseMove(void *data)
called when user moves mouse
virtual void onRightBtnPress(void *data)
called when user press right button
void growHeight(SUMOReal by)
Definition: Boundary.cpp:217
FXint myMouseXPosition
the current mouse position
virtual long onKeyRelease(void *data)
called when user releases a key
virtual ~GUIPerspectiveChanger()
Destructor.