GUIDanielPerspectiveChanger.cpp
Go to the documentation of this file.00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifdef _MSC_VER
00025 #include <windows_config.h>
00026 #else
00027 #include <config.h>
00028 #endif
00029
00030 #include <utils/geom/Boundary.h>
00031 #include <utils/geom/Position2D.h>
00032 #include "GUIPerspectiveChanger.h"
00033 #include "GUIDanielPerspectiveChanger.h"
00034
00035 #ifdef CHECK_MEMORY_LEAKS
00036 #include <foreign/nvwa/debug_new.h>
00037 #endif // CHECK_MEMORY_LEAKS
00038
00039
00040
00041
00042
00043 GUIDanielPerspectiveChanger::GUIDanielPerspectiveChanger(
00044 GUISUMOAbstractView &callBack)
00045 : GUIPerspectiveChanger(callBack),
00046 myViewCenter(0, 0), myRotation(0), myZoom(100),
00047 myMouseButtonState(MOUSEBTN_NONE), myMoveOnClick(false) {}
00048
00049
00050 GUIDanielPerspectiveChanger::~GUIDanielPerspectiveChanger() {}
00051
00052
00053 void
00054 GUIDanielPerspectiveChanger::move(int xdiff, int ydiff) {
00055 myViewCenter.add((SUMOReal) -myCallback.p2m((SUMOReal) xdiff), (SUMOReal) myCallback.p2m((SUMOReal) ydiff));
00056 myCallback.update();
00057 }
00058
00059
00060 void
00061 GUIDanielPerspectiveChanger::zoom(int diff) {
00062 SUMOReal zoom = (SUMOReal) myZoom
00063 + (SUMOReal) diff /(SUMOReal) 100.0 * (SUMOReal) myZoom;
00064 if (zoom>0.01&&zoom<10000000.0) {
00065 myZoom = zoom;
00066 myCallback.update();
00067 }
00068 }
00069
00070
00071 void
00072 GUIDanielPerspectiveChanger::rotate(int diff) {
00073 if (false) {
00074 myRotation += (SUMOReal) diff / (SUMOReal) 10.0;
00075 myCallback.update();
00076 }
00077 }
00078
00079
00080 SUMOReal
00081 GUIDanielPerspectiveChanger::getRotation() const {
00082 return myRotation;
00083 }
00084
00085
00086 SUMOReal
00087 GUIDanielPerspectiveChanger::getXPos() const {
00088 return myViewCenter.x();
00089 }
00090
00091
00092 SUMOReal
00093 GUIDanielPerspectiveChanger::getYPos() const {
00094 return myViewCenter.y();
00095 }
00096
00097
00098 SUMOReal
00099 GUIDanielPerspectiveChanger::getZoom() const {
00100 return myZoom;
00101 }
00102
00103
00104 void
00105 GUIDanielPerspectiveChanger::recenterView() {
00106 myRotation = 0;
00107 myViewCenter.set(0, 0);
00108 myZoom = 100;
00109 }
00110
00111
00112
00113 void
00114 GUIDanielPerspectiveChanger::centerTo(const Boundary &netBoundary,
00115 const Position2D &pos, SUMOReal radius,
00116 bool applyZoom) {
00117 myViewCenter.set(pos);
00118 myViewCenter.sub(netBoundary.getCenter());
00119 myViewCenter.mul(-1.0);
00120 if (applyZoom) {
00121 myZoom =
00122 netBoundary.getWidth() < netBoundary.getHeight() ?
00123 (SUMOReal) 25.0 * (SUMOReal) netBoundary.getWidth() / radius :
00124 (SUMOReal) 25.0 * (SUMOReal) netBoundary.getHeight() / radius;
00125 }
00126 }
00127
00128
00129 void
00130 GUIDanielPerspectiveChanger::centerTo(const Boundary &netBoundary,
00131 Boundary bound,
00132 bool applyZoom) {
00133 myViewCenter.set(bound.getCenter());
00134 myViewCenter.sub(netBoundary.getCenter());
00135 myViewCenter.mul(-1.0);
00136 if (applyZoom) {
00137 myZoom =
00138 bound.getWidth() > bound.getHeight() ?
00139 (SUMOReal) 100.0 * (SUMOReal) netBoundary.getWidth() / (SUMOReal) bound.getWidth() :
00140 (SUMOReal) 100.0 * (SUMOReal) netBoundary.getHeight() / (SUMOReal) bound.getHeight();
00141 }
00142 }
00143
00144
00145
00146 void
00147 GUIDanielPerspectiveChanger::onLeftBtnPress(void*data) {
00148 myMouseButtonState |= MOUSEBTN_LEFT;
00149 FXEvent* e = (FXEvent*) data;
00150 myMouseXPosition = e->win_x;
00151 myMouseYPosition = e->win_y;
00152 myMoveOnClick = false;
00153 }
00154
00155
00156 bool
00157 GUIDanielPerspectiveChanger::onLeftBtnRelease(void*data) {
00158 myMouseButtonState &= !MOUSEBTN_LEFT;
00159 FXEvent* e = (FXEvent*) data;
00160 myMouseXPosition = e->win_x;
00161 myMouseYPosition = e->win_y;
00162 return myMoveOnClick;
00163 }
00164
00165
00166 void
00167 GUIDanielPerspectiveChanger::onRightBtnPress(void*data) {
00168 myMouseButtonState |= MOUSEBTN_RIGHT;
00169 FXEvent* e = (FXEvent*) data;
00170 myMouseXPosition = e->win_x;
00171 myMouseYPosition = e->win_y;
00172 myMoveOnClick = false;
00173 }
00174
00175
00176 bool
00177 GUIDanielPerspectiveChanger::onRightBtnRelease(void*data) {
00178 myMouseButtonState &= !MOUSEBTN_RIGHT;
00179 if (data != 0) {
00180 FXEvent* e = (FXEvent*) data;
00181 myMouseXPosition = e->win_x;
00182 myMouseYPosition = e->win_y;
00183 }
00184 return myMoveOnClick;
00185 }
00186
00187
00188 void
00189 GUIDanielPerspectiveChanger::onMouseWheel(void*data) {
00190 FXEvent* e = (FXEvent*) data;
00191 int diff = 10;
00192 if (e->state&CONTROLMASK) {
00193 diff = 5;
00194 } else if (e->state&SHIFTMASK) {
00195 diff = 20;
00196 }
00197 if (e->code < 0) {
00198 diff = -diff;
00199 }
00200 zoom(diff);
00201 myCallback.updateToolTip();
00202 }
00203
00204
00205 void
00206 GUIDanielPerspectiveChanger::onMouseMove(void*data) {
00207 FXEvent* e = (FXEvent*) data;
00208 myCallback.setWindowCursorPosition(e->win_x, e->win_y);
00209 int xdiff = myMouseXPosition - e->win_x;
00210 int ydiff = myMouseYPosition - e->win_y;
00211 switch (myMouseButtonState) {
00212 case MOUSEBTN_LEFT:
00213 move(xdiff, ydiff);
00214 if (xdiff!=0||ydiff!=0) {
00215 myMoveOnClick = true;
00216 }
00217 break;
00218 case MOUSEBTN_RIGHT:
00219 zoom(ydiff);
00220 rotate(xdiff);
00221 if (xdiff!=0||ydiff!=0) {
00222 myMoveOnClick = true;
00223 }
00224 break;
00225 default:
00226 if (xdiff!=0||ydiff!=0) {
00227 myCallback.updateToolTip();
00228 }
00229 break;
00230 }
00231 myMouseXPosition = e->win_x;
00232 myMouseYPosition = e->win_y;
00233 }
00234
00235
00236 void
00237 GUIDanielPerspectiveChanger::setViewport(SUMOReal zoom,
00238 SUMOReal xPos, SUMOReal yPos) {
00239 myZoom = zoom;
00240 myViewCenter.set(xPos, yPos);
00241 }
00242
00243
00244
00245