Path: blob/main/src/utils/gui/windows/GUIPerspectiveChanger.cpp
169684 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file GUIPerspectiveChanger.cpp14/// @author Daniel Krajzewicz15/// @author Jakob Erdmann16/// @author Michael Behrisch17/// @date Sept 200218///19// A class that allows to steer the visual output in dependence to user20/****************************************************************************/21#include <config.h>2223#include "GUISUMOAbstractView.h"24#include "GUIPerspectiveChanger.h"252627// ===========================================================================28// method definitions29// ===========================================================================30GUIPerspectiveChanger::GUIPerspectiveChanger(GUISUMOAbstractView& callBack, const Boundary& viewPort) :31myCallback(callBack),32myViewPort(viewPort) {33}343536GUIPerspectiveChanger::~GUIPerspectiveChanger() {37}383940void41GUIPerspectiveChanger::onLeftBtnPress(void*) {42// reimplement in child43}444546bool47GUIPerspectiveChanger::onLeftBtnRelease(void*) {48// reimplement in child49return false;50}515253void54GUIPerspectiveChanger::onMiddleBtnPress(void*) {55// reimplement in child56}575859bool60GUIPerspectiveChanger::onMiddleBtnRelease(void*) {61// reimplement in child62return false;63}646566void67GUIPerspectiveChanger::onRightBtnPress(void*) {68// reimplement in child69}707172bool73GUIPerspectiveChanger::onRightBtnRelease(void*) {74// reimplement in child75return false;76}7778void79GUIPerspectiveChanger::onDoubleClicked(void*) {80// reimplement in child81}828384void85GUIPerspectiveChanger::onMouseWheel(void*) {86// reimplement in child87}888990void91GUIPerspectiveChanger::onMouseMove(void*) {92// reimplement in child93}949596long97GUIPerspectiveChanger::onKeyPress(void*) {98// reimplement in child99return 0;100}101102103long104GUIPerspectiveChanger::onKeyRelease(void*) {105// reimplement in child106return 0;107}108109110FXint111GUIPerspectiveChanger::getMouseXPosition() const {112return myMouseXPosition;113}114115116FXint117GUIPerspectiveChanger::getMouseYPosition() const {118return myMouseYPosition;119}120121122Boundary123GUIPerspectiveChanger::getViewport(bool fixRatio) {124if (fixRatio) {125return patchedViewPort();126} else {127return myViewPort;128}129}130131132void133GUIPerspectiveChanger::setViewport(const Boundary& viewPort) {134myViewPort = viewPort;135}136137138Boundary139GUIPerspectiveChanger::patchedViewPort() {140// avoid division by zero141if (myCallback.getHeight() == 0 ||142myCallback.getWidth() == 0 ||143myViewPort.getHeight() == 0 ||144myViewPort.getWidth() == 0) {145return myViewPort;146}147Boundary result = myViewPort;148double canvasRatio = (double)myCallback.getWidth() / myCallback.getHeight();149double ratio = result.getWidth() / result.getHeight();150if (ratio < canvasRatio) {151result.growWidth(result.getWidth() * (canvasRatio / ratio - 1) / 2);152} else {153result.growHeight(result.getHeight() * (ratio / canvasRatio - 1) / 2);154}155return result;156}157158159/****************************************************************************/160161162