mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r21608) -Codechange: Move diagnonal rectangle dragging detection completely to tile highlighting.
This commit is contained in:
parent
1ba348914d
commit
90780fd25b
|
@ -174,22 +174,22 @@ enum TerraformToolbarWidgets {
|
|||
|
||||
static void TerraformClick_Lower(Window *w)
|
||||
{
|
||||
HandlePlacePushButton(w, TTW_LOWER_LAND, ANIMCURSOR_LOWERLAND, HT_POINT, PlaceProc_LowerLand);
|
||||
HandlePlacePushButton(w, TTW_LOWER_LAND, ANIMCURSOR_LOWERLAND, HT_POINT | HT_DIAGONAL, PlaceProc_LowerLand);
|
||||
}
|
||||
|
||||
static void TerraformClick_Raise(Window *w)
|
||||
{
|
||||
HandlePlacePushButton(w, TTW_RAISE_LAND, ANIMCURSOR_RAISELAND, HT_POINT, PlaceProc_RaiseLand);
|
||||
HandlePlacePushButton(w, TTW_RAISE_LAND, ANIMCURSOR_RAISELAND, HT_POINT | HT_DIAGONAL, PlaceProc_RaiseLand);
|
||||
}
|
||||
|
||||
static void TerraformClick_Level(Window *w)
|
||||
{
|
||||
HandlePlacePushButton(w, TTW_LEVEL_LAND, SPR_CURSOR_LEVEL_LAND, HT_POINT, PlaceProc_LevelLand);
|
||||
HandlePlacePushButton(w, TTW_LEVEL_LAND, SPR_CURSOR_LEVEL_LAND, HT_POINT | HT_DIAGONAL, PlaceProc_LevelLand);
|
||||
}
|
||||
|
||||
static void TerraformClick_Dynamite(Window *w)
|
||||
{
|
||||
HandlePlacePushButton(w, TTW_DEMOLISH, ANIMCURSOR_DEMOLISH, HT_RECT, PlaceProc_DemolishArea);
|
||||
HandlePlacePushButton(w, TTW_DEMOLISH, ANIMCURSOR_DEMOLISH, HT_RECT | HT_DIAGONAL, PlaceProc_DemolishArea);
|
||||
}
|
||||
|
||||
static void TerraformClick_BuyLand(Window *w)
|
||||
|
@ -546,7 +546,7 @@ static const NWidgetPart _nested_scen_edit_land_gen_widgets[] = {
|
|||
*/
|
||||
static void EditorTerraformClick_Dynamite(Window *w)
|
||||
{
|
||||
HandlePlacePushButton(w, ETTW_DEMOLISH, ANIMCURSOR_DEMOLISH, HT_RECT, PlaceProc_DemolishArea);
|
||||
HandlePlacePushButton(w, ETTW_DEMOLISH, ANIMCURSOR_DEMOLISH, HT_RECT | HT_DIAGONAL, PlaceProc_DemolishArea);
|
||||
}
|
||||
|
||||
static void EditorTerraformClick_LowerBigLand(Window *w)
|
||||
|
@ -561,7 +561,7 @@ static void EditorTerraformClick_RaiseBigLand(Window *w)
|
|||
|
||||
static void EditorTerraformClick_LevelLand(Window *w)
|
||||
{
|
||||
HandlePlacePushButton(w, ETTW_LEVEL_LAND, SPR_CURSOR_LEVEL_LAND, HT_POINT, PlaceProc_LevelLand);
|
||||
HandlePlacePushButton(w, ETTW_LEVEL_LAND, SPR_CURSOR_LEVEL_LAND, HT_POINT | HT_DIAGONAL, PlaceProc_LevelLand);
|
||||
}
|
||||
|
||||
static void EditorTerraformClick_RockyArea(Window *w)
|
||||
|
@ -623,17 +623,6 @@ static void ResetLandscapeConfirmationCallback(Window *w, bool confirmed)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether we are currently dragging diagonally.
|
||||
* @returns True iff we are selecting a diagonal rectangle for an action that supports it, otherwise false.
|
||||
*/
|
||||
bool IsDraggingDiagonal()
|
||||
{
|
||||
return _ctrl_pressed && _left_button_down && (
|
||||
_place_proc == PlaceProc_DemolishArea || _place_proc == PlaceProc_LevelLand ||
|
||||
_place_proc == PlaceProc_RaiseLand || _place_proc == PlaceProc_LowerLand);
|
||||
}
|
||||
|
||||
struct ScenarioEditorLandscapeGenerationWindow : Window {
|
||||
ScenarioEditorLandscapeGenerationWindow(const WindowDesc *desc, WindowNumber window_number) : Window()
|
||||
{
|
||||
|
|
|
@ -14,8 +14,6 @@
|
|||
|
||||
#include "window_type.h"
|
||||
|
||||
bool IsDraggingDiagonal();
|
||||
|
||||
Window *ShowTerraformToolbar(Window *link = NULL);
|
||||
Window *ShowEditorTerraformToolbar();
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ enum HighLightStyle {
|
|||
HT_LINE = 0x008, ///< used for autorail highlighting (longer streches), lower bits: direction
|
||||
HT_RAIL = 0x080, ///< autorail (one piece), lower bits: direction
|
||||
HT_VEHICLE = 0x100, ///< vehicle is accepted as target as well (bitmask)
|
||||
HT_DIAGONAL = 0x200, ///< Also allow 'diagonal rectangles'.
|
||||
HT_DRAG_MASK = 0x0F8, ///< masks the drag-type
|
||||
|
||||
/* lower bits (used with HT_LINE and HT_RAIL):
|
||||
|
@ -72,6 +73,8 @@ struct TileHighlightData {
|
|||
|
||||
ViewportPlaceMethod select_method; ///< The method which governs how tiles are selected.
|
||||
ViewportDragDropSelectionProcess select_proc; ///< The procedure that has to be called when the selection is done.
|
||||
|
||||
bool IsDraggingDiagonal();
|
||||
};
|
||||
|
||||
#endif /* TILEHIGHLIGHT_TYPE_H */
|
||||
|
|
|
@ -2025,6 +2025,15 @@ static HighLightStyle GetAutorailHT(int x, int y)
|
|||
return HT_RAIL | _autorail_piece[x & TILE_UNIT_MASK][y & TILE_UNIT_MASK];
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the user dragging a 'diagonal rectangle'?
|
||||
* @return User is dragging a rotated rectangle.
|
||||
*/
|
||||
bool TileHighlightData::IsDraggingDiagonal()
|
||||
{
|
||||
return (this->place_mode & HT_DIAGONAL) != 0 && _ctrl_pressed && _left_button_down;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates tile highlighting for all cases.
|
||||
* Uses _thd.selstart and _thd.selend and _thd.place_mode (set elsewhere) to determine _thd.pos and _thd.size
|
||||
|
@ -2049,7 +2058,7 @@ void UpdateTileSelection()
|
|||
x1 &= ~TILE_UNIT_MASK;
|
||||
y1 &= ~TILE_UNIT_MASK;
|
||||
|
||||
if (IsDraggingDiagonal()) {
|
||||
if (_thd.IsDraggingDiagonal()) {
|
||||
new_diagonal = true;
|
||||
} else {
|
||||
if (x1 >= x2) Swap(x1, x2);
|
||||
|
@ -2724,7 +2733,7 @@ calc_heightdiff_single_direction:;
|
|||
/* If dragging an area (eg dynamite tool) and it is actually a single
|
||||
* row/column, change the type to 'line' to get proper calculation for height */
|
||||
style = (HighLightStyle)_thd.next_drawstyle;
|
||||
if (IsDraggingDiagonal()) {
|
||||
if (_thd.IsDraggingDiagonal()) {
|
||||
/* Determine the "area" of the diagonal dragged selection.
|
||||
* We assume the area is the number of tiles along the X
|
||||
* edge and the number of tiles along the Y edge. However,
|
||||
|
|
Loading…
Reference in New Issue