changeset 16874:36a0efc02dea draft

(svn r21608) -Codechange: Move diagnonal rectangle dragging detection completely to tile highlighting.
author alberth <alberth@openttd.org>
date Thu, 23 Dec 2010 14:24:34 +0000
parents ef26237cdf6e
children c037855d747c
files src/terraform_gui.cpp src/terraform_gui.h src/tilehighlight_type.h src/viewport.cpp
diffstat 4 files changed, 20 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/src/terraform_gui.cpp
+++ b/src/terraform_gui.cpp
@@ -174,22 +174,22 @@
 
 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 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_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 @@
 	}
 }
 
-/**
- * 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()
 	{
--- 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();
 
--- a/src/tilehighlight_type.h
+++ b/src/tilehighlight_type.h
@@ -27,6 +27,7 @@
 	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 @@
 
 	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 */
--- a/src/viewport.cpp
+++ b/src/viewport.cpp
@@ -2026,6 +2026,15 @@
 }
 
 /**
+ * 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 @@
 			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 @@
 				/* 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,