Changeset - r16864:c352f2985632
[Not reviewed]
master
0 4 0
alberth - 14 years ago 2010-12-23 14:24:34
alberth@openttd.org
(svn r21608) -Codechange: Move diagnonal rectangle dragging detection completely to tile highlighting.
4 files changed with 20 insertions and 21 deletions:
0 comments (0 inline, 0 general)
src/terraform_gui.cpp
Show inline comments
 
@@ -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_ed
 
 */
 
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_RaiseBi
 

	
 
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 ResetLandscapeConfirmationCa
 
	}
 
}
 

	
 
/**
 
 * 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()
 
	{
src/terraform_gui.h
Show inline comments
 
@@ -14,8 +14,6 @@
 

	
 
#include "window_type.h"
 

	
 
bool IsDraggingDiagonal();
 

	
 
Window *ShowTerraformToolbar(Window *link = NULL);
 
Window *ShowEditorTerraformToolbar();
 

	
src/tilehighlight_type.h
Show inline comments
 
@@ -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 */
src/viewport.cpp
Show inline comments
 
@@ -2026,6 +2026,15 @@ static HighLightStyle GetAutorailHT(int 
 
}
 

	
 
/**
 
 * 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,
0 comments (0 inline, 0 general)