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
 
@@ -171,28 +171,28 @@ enum TerraformToolbarWidgets {
 
	TTW_PLACE_SIGN,                       ///< Place sign button
 
	TTW_PLACE_OBJECT,                     ///< Place object button
 
};
 

	
 
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)
 
{
 
	HandlePlacePushButton(w, TTW_BUY_LAND, SPR_CURSOR_BUY_LAND, HT_RECT, PlaceProc_BuyLand);
 
}
 
@@ -543,13 +543,13 @@ static const NWidgetPart _nested_scen_ed
 
/**
 
 * @todo Merge with terraform_gui.cpp (move there) after I have cooled down at its braindeadness
 
 * and changed OnButtonClick to include the widget as well in the function declaration. Post 0.4.0 - Darkvater
 
 */
 
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)
 
{
 
	HandlePlacePushButton(w, ETTW_LOWER_LAND, ANIMCURSOR_LOWERLAND, HT_POINT, PlaceProc_LowerBigLand);
 
}
 
@@ -558,13 +558,13 @@ static void EditorTerraformClick_RaiseBi
 
{
 
	HandlePlacePushButton(w, ETTW_RAISE_LAND, ANIMCURSOR_RAISELAND, HT_POINT, PlaceProc_RaiseBigLand);
 
}
 

	
 
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)
 
{
 
	HandlePlacePushButton(w, ETTW_PLACE_ROCKS, SPR_CURSOR_ROCKY_AREA, HT_RECT, PlaceProc_RockyArea);
 
}
 
@@ -620,23 +620,12 @@ static void ResetLandscapeConfirmationCa
 
		}
 

	
 
		MarkWholeScreenDirty();
 
	}
 
}
 

	
 
/**
 
 * 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()
 
	{
 
		this->CreateNestedTree(desc);
 
		NWidgetStacked *show_desert = this->GetWidget<NWidgetStacked>(ETTW_SHOW_PLACE_DESERT);
 
		show_desert->SetDisplayedPlane(_settings_game.game_creation.landscape == LT_TROPIC ? 0 : SZSP_NONE);
src/terraform_gui.h
Show inline comments
 
@@ -11,12 +11,10 @@
 

	
 
#ifndef TERRAFORM_GUI_H
 
#define TERRAFORM_GUI_H
 

	
 
#include "window_type.h"
 

	
 
bool IsDraggingDiagonal();
 

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

	
 
#endif /* TERRAFORM_GUI_H */
src/tilehighlight_type.h
Show inline comments
 
@@ -24,12 +24,13 @@ enum HighLightStyle {
 
	HT_POINT     = 0x020, ///< point (lower land, raise land, level land, ...)
 
	HT_SPECIAL   = 0x030, ///< special mode used for highlighting while dragging (and for tunnels/docks)
 
	HT_DRAG      = 0x040, ///< dragging items in the depot windows
 
	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):
 
	 * (see ASCII art in autorail.h for a visual interpretation) */
 
	HT_DIR_X  = 0,    ///< X direction
 
	HT_DIR_Y  = 1,    ///< Y direction
 
@@ -69,9 +70,11 @@ struct TileHighlightData {
 

	
 
	bool make_square_red;          ///< Whether to give a tile a red selection.
 
	TileIndex redsq;               ///< The tile that has to get a red selection.
 

	
 
	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
 
@@ -2023,12 +2023,21 @@ void SetTileSelectBigSize(int ox, int oy
 
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
 
 * Also drawstyle is determined. Uses _thd.new.* as a buffer and calls SetSelectionTilesDirty() twice,
 
 * Once for the old and once for the new selection.
 
 * _thd is TileHighlightData, found in viewport.h
 
 */
 
@@ -2046,13 +2055,13 @@ void UpdateTileSelection()
 
		if (x1 != -1) {
 
			int x2 = _thd.selstart.x & ~TILE_UNIT_MASK;
 
			int y2 = _thd.selstart.y & ~TILE_UNIT_MASK;
 
			x1 &= ~TILE_UNIT_MASK;
 
			y1 &= ~TILE_UNIT_MASK;
 

	
 
			if (IsDraggingDiagonal()) {
 
			if (_thd.IsDraggingDiagonal()) {
 
				new_diagonal = true;
 
			} else {
 
				if (x1 >= x2) Swap(x1, x2);
 
				if (y1 >= y2) Swap(y1, y2);
 
			}
 
			_thd.new_pos.x = x1;
 
@@ -2721,13 +2730,13 @@ calc_heightdiff_single_direction:;
 
				byte index = 0;
 
				uint64 params[3];
 

	
 
				/* 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,
 
					 * multiplying these two numbers does not give the exact
 
					 * number of tiles; basically we are counting the black
 
					 * squares on a chess board and ignore the white ones to
0 comments (0 inline, 0 general)