1
0
Fork 0

Add: Add new viewport place methods for rectangles with one side with a fixed length.

pull/9577/head
J0anJosep 2021-03-31 23:20:44 +02:00
parent d63b540d63
commit ebcca95b15
4 changed files with 30 additions and 8 deletions

View File

@ -26,6 +26,8 @@ void VpStartDragging(ViewportDragDropSelectionProcess process);
void VpStartPlaceSizing(TileIndex tile, ViewportPlaceMethod method, ViewportDragDropSelectionProcess process); void VpStartPlaceSizing(TileIndex tile, ViewportPlaceMethod method, ViewportDragDropSelectionProcess process);
void VpSetPresizeRange(TileIndex from, TileIndex to); void VpSetPresizeRange(TileIndex from, TileIndex to);
void VpSetPlaceSizingLimit(int limit); void VpSetPlaceSizingLimit(int limit);
void VpSetPlaceFixedSize(uint8_t fixed_size);
void VpResetFixedSize();
void UpdateTileSelection(); void UpdateTileSelection();

View File

@ -60,6 +60,7 @@ struct TileHighlightData {
Point selstart; ///< The location where the dragging started. Point selstart; ///< The location where the dragging started.
Point selend; ///< The location where the drag currently ends. Point selend; ///< The location where the drag currently ends.
uint8_t sizelimit; ///< Whether the selection is limited in length, and what the maximum length is. uint8_t sizelimit; ///< Whether the selection is limited in length, and what the maximum length is.
uint8_t fixed_size; ///< The fixed length for one of the sides.
HighLightStyle drawstyle; ///< Lower bits 0-3 are reserved for detailed highlight information. HighLightStyle drawstyle; ///< Lower bits 0-3 are reserved for detailed highlight information.
HighLightStyle next_drawstyle; ///< Queued, but not yet drawn style. HighLightStyle next_drawstyle; ///< Queued, but not yet drawn style.

View File

@ -2680,6 +2680,8 @@ void UpdateTileSelection()
} }
_thd.new_pos.x = x1 & ~TILE_UNIT_MASK; _thd.new_pos.x = x1 & ~TILE_UNIT_MASK;
_thd.new_pos.y = y1 & ~TILE_UNIT_MASK; _thd.new_pos.y = y1 & ~TILE_UNIT_MASK;
if (_thd.select_method == VPM_LIMITED_X_FIXED_Y) _thd.new_size.y = (TILE_SIZE * _thd.fixed_size) & ~TILE_UNIT_MASK;
if (_thd.select_method == VPM_LIMITED_Y_FIXED_X) _thd.new_size.x = (TILE_SIZE * _thd.fixed_size) & ~TILE_UNIT_MASK;
} }
} }
@ -2772,6 +2774,15 @@ void VpSetPlaceSizingLimit(int limit)
_thd.sizelimit = limit; _thd.sizelimit = limit;
} }
void VpSetPlaceFixedSize(uint8_t fixed)
{
_thd.fixed_size = fixed;
}
void VpResetFixedSize() {
VpSetPlaceFixedSize(1);
}
/** /**
* Highlights all tiles between a set of two tiles. Used in dock and tunnel placement * Highlights all tiles between a set of two tiles. Used in dock and tunnel placement
* @param from TileIndex of the first tile to highlight * @param from TileIndex of the first tile to highlight
@ -3243,7 +3254,7 @@ void VpSelectTilesWithMethod(int x, int y, ViewportPlaceMethod method)
sx = _thd.selstart.x; sx = _thd.selstart.x;
sy = _thd.selstart.y; sy = _thd.selstart.y;
int limit = 0; int limit = -1;
switch (method) { switch (method) {
case VPM_X_OR_Y: // drag in X or Y direction case VPM_X_OR_Y: // drag in X or Y direction
@ -3256,28 +3267,33 @@ void VpSelectTilesWithMethod(int x, int y, ViewportPlaceMethod method)
} }
goto calc_heightdiff_single_direction; goto calc_heightdiff_single_direction;
case VPM_LIMITED_Y_FIXED_X:
case VPM_X_LIMITED: // Drag in X direction (limited size). case VPM_X_LIMITED: // Drag in X direction (limited size).
limit = (_thd.sizelimit - 1) * TILE_SIZE; limit = (_thd.sizelimit - 1) * TILE_SIZE;
[[fallthrough]]; [[fallthrough]];
case VPM_FIX_X: // drag in Y direction case VPM_FIX_X: // drag in Y direction
x = sx; x = sx + (method == VPM_LIMITED_Y_FIXED_X ? (TILE_SIZE * (_thd.fixed_size - 1)) : 0) ;
style = HT_DIR_Y; style = HT_DIR_Y;
goto calc_heightdiff_single_direction; goto calc_heightdiff_single_direction;
case VPM_LIMITED_X_FIXED_Y:
case VPM_Y_LIMITED: // Drag in Y direction (limited size). case VPM_Y_LIMITED: // Drag in Y direction (limited size).
limit = (_thd.sizelimit - 1) * TILE_SIZE; limit = (_thd.sizelimit - 1) * TILE_SIZE;
[[fallthrough]]; [[fallthrough]];
case VPM_FIX_Y: // drag in X direction case VPM_FIX_Y: // drag in X direction
y = sy; y = sy + (method == VPM_LIMITED_X_FIXED_Y ? (TILE_SIZE * (_thd.fixed_size - 1)) : 0) ;
style = HT_DIR_X; style = HT_DIR_X;
calc_heightdiff_single_direction:; calc_heightdiff_single_direction:;
if (limit > 0) { if (limit >= 0) {
x = sx + Clamp(x - sx, -limit, limit); if (method != VPM_LIMITED_X_FIXED_Y) y = sy + Clamp(y - sy, -limit, limit);
y = sy + Clamp(y - sy, -limit, limit); if (method != VPM_LIMITED_Y_FIXED_X) x = sx + Clamp(x - sx, -limit, limit);
} }
if (method == VPM_LIMITED_Y_FIXED_X || method == VPM_LIMITED_X_FIXED_Y) goto measure_area;
if (_settings_client.gui.measure_tooltip) { if (_settings_client.gui.measure_tooltip) {
TileIndex t0 = TileVirtXY(sx, sy); TileIndex t0 = TileVirtXY(sx, sy);
TileIndex t1 = TileVirtXY(x, y); TileIndex t1 = TileVirtXY(x, y);
@ -3307,6 +3323,7 @@ calc_heightdiff_single_direction:;
[[fallthrough]]; [[fallthrough]];
case VPM_X_AND_Y: // drag an X by Y area case VPM_X_AND_Y: // drag an X by Y area
measure_area:
if (_settings_client.gui.measure_tooltip) { if (_settings_client.gui.measure_tooltip) {
static const StringID measure_strings_area[] = { static const StringID measure_strings_area[] = {
STR_NULL, STR_NULL, STR_MEASURE_AREA, STR_MEASURE_AREA_HEIGHTDIFF STR_NULL, STR_NULL, STR_MEASURE_AREA, STR_MEASURE_AREA_HEIGHTDIFF

View File

@ -99,6 +99,8 @@ enum ViewportPlaceMethod {
VPM_FIX_VERTICAL = 6, ///< drag only in vertical direction VPM_FIX_VERTICAL = 6, ///< drag only in vertical direction
VPM_X_LIMITED = 7, ///< Drag only in X axis with limited size 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_Y_LIMITED = 8, ///< Drag only in Y axis with limited size
VPM_LIMITED_Y_FIXED_X = 9, ///< Drag only in Y axis with limited size and a fixed value for X axis
VPM_LIMITED_X_FIXED_Y = 10, ///< Drag only in X axis with limited size and a fixed value for Y axis
VPM_RAILDIRS = 0x40, ///< all rail directions VPM_RAILDIRS = 0x40, ///< all rail directions
VPM_SIGNALDIRS = 0x80, ///< similar to VMP_RAILDIRS, but with different cursor VPM_SIGNALDIRS = 0x80, ///< similar to VMP_RAILDIRS, but with different cursor
}; };