Line data Source code
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 : /****************************************************************************/ 14 : /// @file GUIPerspectiveChanger.cpp 15 : /// @author Daniel Krajzewicz 16 : /// @author Jakob Erdmann 17 : /// @author Michael Behrisch 18 : /// @date Sept 2002 19 : /// 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 : // =========================================================================== 31 7236 : GUIPerspectiveChanger::GUIPerspectiveChanger(GUISUMOAbstractView& callBack, const Boundary& viewPort) : 32 7236 : myCallback(callBack), 33 7236 : myViewPort(viewPort) { 34 7236 : } 35 : 36 : 37 7220 : GUIPerspectiveChanger::~GUIPerspectiveChanger() { 38 7220 : } 39 : 40 : 41 : void 42 0 : GUIPerspectiveChanger::onLeftBtnPress(void*) { 43 : // reimplement in child 44 0 : } 45 : 46 : 47 : bool 48 0 : GUIPerspectiveChanger::onLeftBtnRelease(void*) { 49 : // reimplement in child 50 0 : return false; 51 : } 52 : 53 : 54 : void 55 0 : GUIPerspectiveChanger::onMiddleBtnPress(void*) { 56 : // reimplement in child 57 0 : } 58 : 59 : 60 : bool 61 0 : GUIPerspectiveChanger::onMiddleBtnRelease(void*) { 62 : // reimplement in child 63 0 : return false; 64 : } 65 : 66 : 67 : void 68 0 : GUIPerspectiveChanger::onRightBtnPress(void*) { 69 : // reimplement in child 70 0 : } 71 : 72 : 73 : bool 74 0 : GUIPerspectiveChanger::onRightBtnRelease(void*) { 75 : // reimplement in child 76 0 : return false; 77 : } 78 : 79 : void 80 0 : GUIPerspectiveChanger::onDoubleClicked(void*) { 81 : // reimplement in child 82 0 : } 83 : 84 : 85 : void 86 0 : GUIPerspectiveChanger::onMouseWheel(void*) { 87 : // reimplement in child 88 0 : } 89 : 90 : 91 : void 92 0 : GUIPerspectiveChanger::onMouseMove(void*) { 93 : // reimplement in child 94 0 : } 95 : 96 : 97 : long 98 0 : GUIPerspectiveChanger::onKeyPress(void*) { 99 : // reimplement in child 100 0 : return 0; 101 : } 102 : 103 : 104 : long 105 0 : GUIPerspectiveChanger::onKeyRelease(void*) { 106 : // reimplement in child 107 0 : return 0; 108 : } 109 : 110 : 111 : FXint 112 0 : GUIPerspectiveChanger::getMouseXPosition() const { 113 0 : return myMouseXPosition; 114 : } 115 : 116 : 117 : FXint 118 0 : GUIPerspectiveChanger::getMouseYPosition() const { 119 0 : return myMouseYPosition; 120 : } 121 : 122 : 123 : Boundary 124 2553536 : GUIPerspectiveChanger::getViewport(bool fixRatio) { 125 2553536 : if (fixRatio) { 126 2553536 : return patchedViewPort(); 127 : } else { 128 : return myViewPort; 129 : } 130 : } 131 : 132 : 133 : void 134 6840 : GUIPerspectiveChanger::setViewport(const Boundary& viewPort) { 135 : myViewPort = viewPort; 136 6840 : } 137 : 138 : 139 : Boundary 140 2553536 : GUIPerspectiveChanger::patchedViewPort() { 141 : // avoid division by zero 142 2553536 : if (myCallback.getHeight() == 0 || 143 2553536 : myCallback.getWidth() == 0 || 144 7660608 : myViewPort.getHeight() == 0 || 145 2553536 : myViewPort.getWidth() == 0) { 146 : return myViewPort; 147 : } 148 : Boundary result = myViewPort; 149 2553536 : double canvasRatio = (double)myCallback.getWidth() / myCallback.getHeight(); 150 2553536 : double ratio = result.getWidth() / result.getHeight(); 151 2553536 : if (ratio < canvasRatio) { 152 1609007 : result.growWidth(result.getWidth() * (canvasRatio / ratio - 1) / 2); 153 : } else { 154 944529 : result.growHeight(result.getHeight() * (ratio / canvasRatio - 1) / 2); 155 : } 156 : return result; 157 2553536 : } 158 : 159 : 160 : /****************************************************************************/