SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GUIDanielPerspectiveChanger.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // A class that allows to steer the visual output in dependence to
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
12 // Copyright (C) 2001-2014 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 <utils/geom/Boundary.h>
34 #include <utils/geom/Position.h>
36 #include "GUIPerspectiveChanger.h"
38 
39 #ifdef CHECK_MEMORY_LEAKS
40 #include <foreign/nvwa/debug_new.h>
41 #endif // CHECK_MEMORY_LEAKS
42 
43 
44 // ===========================================================================
45 // method definitions
46 // ===========================================================================
48  GUISUMOAbstractView& callBack, const Boundary& viewPort) :
49  GUIPerspectiveChanger(callBack, viewPort),
50  myOrigWidth(viewPort.getWidth()),
51  myOrigHeight(viewPort.getHeight()),
52  myRotation(0),
53  myMouseButtonState(MOUSEBTN_NONE),
54  myMoveOnClick(false),
55  myDragDelay(0) {}
56 
57 
59 
60 
61 void
62 GUIDanielPerspectiveChanger::move(int xdiff, int ydiff) {
63  myViewPort.moveby(myCallback.p2m(xdiff), -myCallback.p2m(ydiff));
64  myCallback.update();
65 }
66 
67 
68 void
70  if (myCallback.getApp()->reg().readIntEntry("gui", "zoomAtCenter", 1)) {
72  }
73  if (factor > 0) {
75  myZoomBase.x() - (myZoomBase.x() - myViewPort.xmin()) / factor,
76  myZoomBase.y() - (myZoomBase.y() - myViewPort.ymin()) / factor,
77  myZoomBase.x() - (myZoomBase.x() - myViewPort.xmax()) / factor,
78  myZoomBase.y() - (myZoomBase.y() - myViewPort.ymax()) / factor);
79  myCallback.update();
80  }
81 }
82 
83 
84 void
86  /*
87  if (myCallback.allowRotation()) {
88  myRotation += (SUMOReal) diff / (SUMOReal) 10.0;
89  myCallback.update();
90  }
91  */
92 }
93 
94 
97  return myRotation;
98 }
99 
100 
101 SUMOReal
103  return myViewPort.getCenter().x();
104 }
105 
106 
107 SUMOReal
109  return myViewPort.getCenter().y();
110 }
111 
112 
113 SUMOReal
115  return myOrigWidth / myViewPort.getWidth() * 100;
116 }
117 
118 
119 void
121  bool applyZoom) {
122  if (applyZoom) {
123  myViewPort = Boundary();
124  myViewPort.add(pos);
125  myViewPort.grow(radius);
126  } else {
127  myViewPort.moveby(pos.x() - getXPos(), pos.y() - getYPos());
128  }
129 }
130 
131 
132 void
135  FXEvent* e = (FXEvent*) data;
136  myMouseXPosition = e->win_x;
137  myMouseYPosition = e->win_y;
138  myMoveOnClick = false;
139  myMouseDownTime = FXThread::time();
140 }
141 
142 
143 bool
146  FXEvent* e = (FXEvent*) data;
147  myMouseXPosition = e->win_x;
148  myMouseYPosition = e->win_y;
149  return myMoveOnClick;
150 }
151 
152 
153 void
156  FXEvent* e = (FXEvent*) data;
157  myMouseXPosition = e->win_x;
158  myMouseYPosition = e->win_y;
159  myMoveOnClick = false;
160  myMouseDownTime = FXThread::time();
162 }
163 
164 
165 bool
168  if (data != 0) {
169  FXEvent* e = (FXEvent*) data;
170  myMouseXPosition = e->win_x;
171  myMouseYPosition = e->win_y;
172  }
173  return myMoveOnClick;
174 }
175 
176 
177 void
179  FXEvent* e = (FXEvent*) data;
180  SUMOReal diff = 0.1;
181  if (e->state & CONTROLMASK) {
182  diff /= 2;
183  } else if (e->state & SHIFTMASK) {
184  diff *= 2;
185  }
186  if (e->code < 0) {
187  diff = -diff;
188  }
190  zoom(1.0 + diff);
192 }
193 
194 
195 void
197  FXEvent* e = (FXEvent*) data;
198  myCallback.setWindowCursorPosition(e->win_x, e->win_y);
199  const int xdiff = myMouseXPosition - e->win_x;
200  const int ydiff = myMouseYPosition - e->win_y;
201  const bool moved = xdiff != 0 || ydiff != 0;
202  const bool pastDelay = !gSchemeStorage.getDefault().gaming && FXThread::time() > (myMouseDownTime + myDragDelay);
203  switch (myMouseButtonState) {
204  case MOUSEBTN_LEFT:
205  if (pastDelay) {
206  move(xdiff, ydiff);
207  if (moved) {
208  myMoveOnClick = true;
209  }
210  }
211  break;
212  case MOUSEBTN_RIGHT:
213  if (pastDelay) {
214  zoom(1 + 10.0 * ydiff / myCallback.getWidth());
215  rotate(xdiff);
216  if (moved) {
217  myMoveOnClick = true;
218  }
219  }
220  break;
221  default:
222  if (moved) {
224  }
225  break;
226  }
227  myMouseXPosition = e->win_x;
228  myMouseYPosition = e->win_y;
229 }
230 
231 
232 void
234  SUMOReal xPos, SUMOReal yPos) {
235  const SUMOReal zoomFactor = zoom / 50; // /100 to normalize, *2 because growth is added on both sides
236  myViewPort = Boundary();
237  myViewPort.add(Position(xPos, yPos));
238  myViewPort.growHeight(myOrigHeight / zoomFactor);
239  myViewPort.growWidth(myOrigWidth / zoomFactor);
240  myCallback.update();
241 }
242 
243 
244 void
247  myViewPort.xmin() - myCallback.p2m(change),
248  myViewPort.ymin(),
249  myViewPort.xmax(),
250  myViewPort.ymax());
251 }
252 
253 /****************************************************************************/