Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/gui/windows/GUIPerspectiveChanger.cpp
169684 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2025 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
GUIPerspectiveChanger::GUIPerspectiveChanger(GUISUMOAbstractView& callBack, const Boundary& viewPort) :
32
myCallback(callBack),
33
myViewPort(viewPort) {
34
}
35
36
37
GUIPerspectiveChanger::~GUIPerspectiveChanger() {
38
}
39
40
41
void
42
GUIPerspectiveChanger::onLeftBtnPress(void*) {
43
// reimplement in child
44
}
45
46
47
bool
48
GUIPerspectiveChanger::onLeftBtnRelease(void*) {
49
// reimplement in child
50
return false;
51
}
52
53
54
void
55
GUIPerspectiveChanger::onMiddleBtnPress(void*) {
56
// reimplement in child
57
}
58
59
60
bool
61
GUIPerspectiveChanger::onMiddleBtnRelease(void*) {
62
// reimplement in child
63
return false;
64
}
65
66
67
void
68
GUIPerspectiveChanger::onRightBtnPress(void*) {
69
// reimplement in child
70
}
71
72
73
bool
74
GUIPerspectiveChanger::onRightBtnRelease(void*) {
75
// reimplement in child
76
return false;
77
}
78
79
void
80
GUIPerspectiveChanger::onDoubleClicked(void*) {
81
// reimplement in child
82
}
83
84
85
void
86
GUIPerspectiveChanger::onMouseWheel(void*) {
87
// reimplement in child
88
}
89
90
91
void
92
GUIPerspectiveChanger::onMouseMove(void*) {
93
// reimplement in child
94
}
95
96
97
long
98
GUIPerspectiveChanger::onKeyPress(void*) {
99
// reimplement in child
100
return 0;
101
}
102
103
104
long
105
GUIPerspectiveChanger::onKeyRelease(void*) {
106
// reimplement in child
107
return 0;
108
}
109
110
111
FXint
112
GUIPerspectiveChanger::getMouseXPosition() const {
113
return myMouseXPosition;
114
}
115
116
117
FXint
118
GUIPerspectiveChanger::getMouseYPosition() const {
119
return myMouseYPosition;
120
}
121
122
123
Boundary
124
GUIPerspectiveChanger::getViewport(bool fixRatio) {
125
if (fixRatio) {
126
return patchedViewPort();
127
} else {
128
return myViewPort;
129
}
130
}
131
132
133
void
134
GUIPerspectiveChanger::setViewport(const Boundary& viewPort) {
135
myViewPort = viewPort;
136
}
137
138
139
Boundary
140
GUIPerspectiveChanger::patchedViewPort() {
141
// avoid division by zero
142
if (myCallback.getHeight() == 0 ||
143
myCallback.getWidth() == 0 ||
144
myViewPort.getHeight() == 0 ||
145
myViewPort.getWidth() == 0) {
146
return myViewPort;
147
}
148
Boundary result = myViewPort;
149
double canvasRatio = (double)myCallback.getWidth() / myCallback.getHeight();
150
double ratio = result.getWidth() / result.getHeight();
151
if (ratio < canvasRatio) {
152
result.growWidth(result.getWidth() * (canvasRatio / ratio - 1) / 2);
153
} else {
154
result.growHeight(result.getHeight() * (ratio / canvasRatio - 1) / 2);
155
}
156
return result;
157
}
158
159
160
/****************************************************************************/
161
162