Changeset - r7912:aac2d19fbcb0
[Not reviewed]
master
0 1 0
smatz - 17 years ago 2007-11-18 20:05:44
smatz@openttd.org
(svn r11465) -Fix: more user-friedly placement in X and Y directions (most noticeable with autoroad)
1 file changed with 14 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/viewport.cpp
Show inline comments
 
@@ -2232,26 +2232,26 @@ static byte GetAutorailHT(int x, int y)
 
 */
 
void UpdateTileSelection()
 
{
 
	int x1;
 
	int y1;
 

	
 
	_thd.new_drawstyle = 0;
 

	
 
	if (_thd.place_mode == VHM_SPECIAL) {
 
		x1 = _thd.selend.x;
 
		y1 = _thd.selend.y;
 
		if (x1 != -1) {
 
			int x2 = _thd.selstart.x;
 
			int y2 = _thd.selstart.y;
 
			int x2 = _thd.selstart.x & ~0xF;
 
			int y2 = _thd.selstart.y & ~0xF;
 
			x1 &= ~0xF;
 
			y1 &= ~0xF;
 

	
 
			if (x1 >= x2) Swap(x1, x2);
 
			if (y1 >= y2) Swap(y1, y2);
 
			_thd.new_pos.x = x1;
 
			_thd.new_pos.y = y1;
 
			_thd.new_size.x = x2 - x1 + TILE_SIZE;
 
			_thd.new_size.y = y2 - y1 + TILE_SIZE;
 
			_thd.new_drawstyle = _thd.next_drawstyle;
 
		}
 
	} else if (_thd.place_mode != VHM_NONE) {
 
@@ -2296,24 +2296,35 @@ void UpdateTileSelection()
 
	}
 
}
 

	
 
/** highlighting tiles while only going over them with the mouse */
 
void VpStartPlaceSizing(TileIndex tile, ViewportPlaceMethod method, byte process)
 
{
 
	_thd.select_method = method;
 
	_thd.select_proc   = process;
 
	_thd.selend.x = TileX(tile) * TILE_SIZE;
 
	_thd.selstart.x = TileX(tile) * TILE_SIZE;
 
	_thd.selend.y = TileY(tile) * TILE_SIZE;
 
	_thd.selstart.y = TileY(tile) * TILE_SIZE;
 

	
 
	/* Needed so several things (road, autoroad, bridges, ...) are placed correctly.
 
	 * In effect, placement starts from the centre of a tile
 
	 */
 
	if (method == VPM_X_OR_Y || method == VPM_FIX_X || method == VPM_FIX_Y) {
 
		_thd.selend.x += TILE_SIZE / 2;
 
		_thd.selend.y += TILE_SIZE / 2;
 
		_thd.selstart.x += TILE_SIZE / 2;
 
		_thd.selstart.y += TILE_SIZE / 2;
 
	}
 

	
 
	if (_thd.place_mode == VHM_RECT) {
 
		_thd.place_mode = VHM_SPECIAL;
 
		_thd.next_drawstyle = HT_RECT;
 
	} else if (_thd.place_mode == VHM_RAIL) { // autorail one piece
 
		_thd.place_mode = VHM_SPECIAL;
 
		_thd.next_drawstyle = _thd.drawstyle;
 
	} else {
 
		_thd.place_mode = VHM_SPECIAL;
 
		_thd.next_drawstyle = HT_POINT;
 
	}
 
	_special_mouse_mode = WSM_SIZING;
 
}
 
@@ -2643,24 +2654,25 @@ void VpSelectTilesWithMethod(int x, int 
 
		_thd.selend.x = -1;
 
		return;
 
	}
 

	
 
	/* Special handling of drag in any (8-way) direction */
 
	if (method == VPM_RAILDIRS || method == VPM_SIGNALDIRS) {
 
		_thd.selend.x = x;
 
		_thd.selend.y = y;
 
		CalcRaildirsDrawstyle(&_thd, x, y, method);
 
		return;
 
	}
 

	
 
	/* Needed so level-land is placed correctly */
 
	if (_thd.next_drawstyle == HT_POINT) {
 
		x += TILE_SIZE / 2;
 
		y += TILE_SIZE / 2;
 
	}
 

	
 
	sx = _thd.selstart.x;
 
	sy = _thd.selstart.y;
 

	
 
	switch (method) {
 
		case VPM_X_OR_Y: /* drag in X or Y direction */
 
			if (myabs(sy - y) < myabs(sx - x)) {
 
				y = sy;
0 comments (0 inline, 0 general)