summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2010-12-23 14:24:34 +0000
committeralberth <alberth@openttd.org>2010-12-23 14:24:34 +0000
commit90780fd25bab45fb97304337f10b78c9210a7190 (patch)
treee89a067d86fa4e9b8034660396cbb0fc2e0eb27a
parent1ba348914dc78ae72026aff568a2e09442be4bcb (diff)
downloadopenttd-90780fd25bab45fb97304337f10b78c9210a7190.tar.xz
(svn r21608) -Codechange: Move diagnonal rectangle dragging detection completely to tile highlighting.
-rw-r--r--src/terraform_gui.cpp23
-rw-r--r--src/terraform_gui.h2
-rw-r--r--src/tilehighlight_type.h3
-rw-r--r--src/viewport.cpp13
4 files changed, 20 insertions, 21 deletions
diff --git a/src/terraform_gui.cpp b/src/terraform_gui.cpp
index 1901203d5..ad403143b 100644
--- a/src/terraform_gui.cpp
+++ b/src/terraform_gui.cpp
@@ -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()
{
diff --git a/src/terraform_gui.h b/src/terraform_gui.h
index 2e9c3e240..26a1c5e9a 100644
--- a/src/terraform_gui.h
+++ b/src/terraform_gui.h
@@ -14,8 +14,6 @@
#include "window_type.h"
-bool IsDraggingDiagonal();
-
Window *ShowTerraformToolbar(Window *link = NULL);
Window *ShowEditorTerraformToolbar();
diff --git a/src/tilehighlight_type.h b/src/tilehighlight_type.h
index b61dda3c5..26278968e 100644
--- a/src/tilehighlight_type.h
+++ b/src/tilehighlight_type.h
@@ -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 */
diff --git a/src/viewport.cpp b/src/viewport.cpp
index b0116e39e..cf58fccf5 100644
--- a/src/viewport.cpp
+++ b/src/viewport.cpp
@@ -2026,6 +2026,15 @@ static HighLightStyle GetAutorailHT(int x, int y)
}
/**
+ * 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
* Also drawstyle is determined. Uses _thd.new.* as a buffer and calls SetSelectionTilesDirty() twice,
@@ -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,