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.sourceforge.net/
12 // Copyright (C) 2001-2012 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  if (false) {//myCallback.allowRotation()) {
87  myRotation += (SUMOReal) diff / (SUMOReal) 10.0;
88  myCallback.update();
89  }
90 }
91 
92 
95  return myRotation;
96 }
97 
98 
101  return myViewPort.getCenter().x();
102 }
103 
104 
105 SUMOReal
107  return myViewPort.getCenter().y();
108 }
109 
110 
111 SUMOReal
113  return myOrigWidth / myViewPort.getWidth() * 100;
114 }
115 
116 
117 void
119  bool applyZoom) {
120  if (applyZoom) {
121  myViewPort = Boundary();
122  myViewPort.add(pos);
123  myViewPort.grow(radius);
124  } else {
125  myViewPort.moveby(pos.x() - getXPos(), pos.y() - getYPos());
126  }
127 }
128 
129 
130 void
133  FXEvent* e = (FXEvent*) data;
134  myMouseXPosition = e->win_x;
135  myMouseYPosition = e->win_y;
136  myMoveOnClick = false;
137  myMouseDownTime = FXThread::time();
138 }
139 
140 
141 bool
144  FXEvent* e = (FXEvent*) data;
145  myMouseXPosition = e->win_x;
146  myMouseYPosition = e->win_y;
147  return myMoveOnClick;
148 }
149 
150 
151 void
154  FXEvent* e = (FXEvent*) data;
155  myMouseXPosition = e->win_x;
156  myMouseYPosition = e->win_y;
157  myMoveOnClick = false;
158  myMouseDownTime = FXThread::time();
160 }
161 
162 
163 bool
166  if (data != 0) {
167  FXEvent* e = (FXEvent*) data;
168  myMouseXPosition = e->win_x;
169  myMouseYPosition = e->win_y;
170  }
171  return myMoveOnClick;
172 }
173 
174 
175 void
177  FXEvent* e = (FXEvent*) data;
178  SUMOReal diff = 0.1;
179  if (e->state & CONTROLMASK) {
180  diff /= 2;
181  } else if (e->state & SHIFTMASK) {
182  diff *= 2;
183  }
184  if (e->code < 0) {
185  diff = -diff;
186  }
188  zoom(1.0 + diff);
190 }
191 
192 
193 void
195  FXEvent* e = (FXEvent*) data;
196  myCallback.setWindowCursorPosition(e->win_x, e->win_y);
197  const int xdiff = myMouseXPosition - e->win_x;
198  const int ydiff = myMouseYPosition - e->win_y;
199  const bool moved = xdiff != 0 || ydiff != 0;
200  const bool pastDelay = FXThread::time() > (myMouseDownTime + myDragDelay);
201  switch (myMouseButtonState) {
202  case MOUSEBTN_LEFT:
203  if (pastDelay) {
204  move(xdiff, ydiff);
205  if (moved) {
206  myMoveOnClick = true;
207  }
208  }
209  break;
210  case MOUSEBTN_RIGHT:
211  if (pastDelay) {
212  zoom(1 + 10.0 * ydiff / myCallback.getWidth());
213  rotate(xdiff);
214  if (moved) {
215  myMoveOnClick = true;
216  }
217  }
218  break;
219  default:
220  if (moved) {
222  }
223  break;
224  }
225  myMouseXPosition = e->win_x;
226  myMouseYPosition = e->win_y;
227 }
228 
229 
230 void
232  SUMOReal xPos, SUMOReal yPos) {
233  const SUMOReal zoomFactor = zoom / 50; // /100 to normalize, *2 because growth is added on both sides
234  myViewPort = Boundary();
235  myViewPort.add(Position(xPos, yPos));
236  myViewPort.growHeight(myOrigHeight / zoomFactor);
237  myViewPort.growWidth(myOrigWidth / zoomFactor);
238  myCallback.update();
239 }
240 
241 
242 void
245  myViewPort.xmin() - myCallback.p2m(change),
246  myViewPort.ymin(),
247  myViewPort.xmax(),
248  myViewPort.ymax());
249 }
250 
251 /****************************************************************************/