summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorterkhen <terkhen@openttd.org>2010-02-01 23:13:15 +0000
committerterkhen <terkhen@openttd.org>2010-02-01 23:13:15 +0000
commit8849943da5258af161e2d45c73dce3c7f68e6dc8 (patch)
treed56558309b556e62b19613359601af7b7b6e3add /src
parent615324130b16e9ba831be54d54e2b111d12fb2cb (diff)
downloadopenttd-8849943da5258af161e2d45c73dce3c7f68e6dc8.tar.xz
(svn r18984) -Add: Viewport place methods for dragging a line with limited size.
Diffstat (limited to 'src')
-rw-r--r--src/viewport.cpp23
-rw-r--r--src/viewport_type.h2
2 files changed, 22 insertions, 3 deletions
diff --git a/src/viewport.cpp b/src/viewport.cpp
index 4239a299e..4fe1553bb 100644
--- a/src/viewport.cpp
+++ b/src/viewport.cpp
@@ -2526,6 +2526,8 @@ void VpSelectTilesWithMethod(int x, int y, ViewportPlaceMethod method)
sx = _thd.selstart.x;
sy = _thd.selstart.y;
+ int limit = 0;
+
switch (method) {
case VPM_X_OR_Y: // drag in X or Y direction
if (abs(sy - y) < abs(sx - x)) {
@@ -2536,15 +2538,29 @@ void VpSelectTilesWithMethod(int x, int y, ViewportPlaceMethod method)
style = HT_DIR_Y;
}
goto calc_heightdiff_single_direction;
+
+ case VPM_X_LIMITED: // Drag in X direction (limited size).
+ limit = (_thd.sizelimit - 1) * TILE_SIZE;
+ /* Fallthrough. */
+
case VPM_FIX_X: // drag in Y direction
x = sx;
style = HT_DIR_Y;
goto calc_heightdiff_single_direction;
+
+ case VPM_Y_LIMITED: // Drag in Y direction (limited size).
+ limit = (_thd.sizelimit - 1) * TILE_SIZE;
+ /* Fallthrough. */
+
case VPM_FIX_Y: // drag in X direction
y = sy;
style = HT_DIR_X;
calc_heightdiff_single_direction:;
+ if (limit > 0) {
+ x = sx + Clamp(x - sx, -limit, limit);
+ y = sy + Clamp(y - sy, -limit, limit);
+ }
if (_settings_client.gui.measure_tooltip) {
TileIndex t0 = TileVirtXY(sx, sy);
TileIndex t1 = TileVirtXY(x, y);
@@ -2567,11 +2583,12 @@ calc_heightdiff_single_direction:;
ShowMeasurementTooltips(measure_strings_length[index], index, params);
} break;
- case VPM_X_AND_Y_LIMITED: { // drag an X by Y constrained rect area
- int limit = (_thd.sizelimit - 1) * TILE_SIZE;
+ case VPM_X_AND_Y_LIMITED: // Drag an X by Y constrained rect area.
+ limit = (_thd.sizelimit - 1) * TILE_SIZE;
x = sx + Clamp(x - sx, -limit, limit);
y = sy + Clamp(y - sy, -limit, limit);
- } // Fallthrough
+ /* Fallthrough. */
+
case VPM_X_AND_Y: { // drag an X by Y area
if (_settings_client.gui.measure_tooltip) {
static const StringID measure_strings_area[] = {
diff --git a/src/viewport_type.h b/src/viewport_type.h
index 5f8002bc6..72f1835e2 100644
--- a/src/viewport_type.h
+++ b/src/viewport_type.h
@@ -77,6 +77,8 @@ enum ViewportPlaceMethod {
VPM_X_AND_Y_LIMITED = 4, ///< area of land of limited size
VPM_FIX_HORIZONTAL = 5, ///< drag only in horizontal direction
VPM_FIX_VERTICAL = 6, ///< drag only in vertical direction
+ VPM_X_LIMITED = 7, ///< Drag only in X axis with limited size
+ VPM_Y_LIMITED = 8, ///< Drag only in Y axis with limited size
VPM_RAILDIRS = 0x40, ///< all rail directions
VPM_SIGNALDIRS = 0x80, ///< similiar to VMP_RAILDIRS, but with different cursor
};