viewport.c
changeset 4799 20311e38bedf
parent 4634 07699ac2bf37
child 4834 3c6e8a547174
equal deleted inserted replaced
4798:f43a4a725947 4799:20311e38bedf
  1988 
  1988 
  1989 
  1989 
  1990 // while dragging
  1990 // while dragging
  1991 static void CalcRaildirsDrawstyle(TileHighlightData *thd, int x, int y, int method)
  1991 static void CalcRaildirsDrawstyle(TileHighlightData *thd, int x, int y, int method)
  1992 {
  1992 {
  1993 	int d;
  1993 	HighLightStyle b;
  1994 	byte b=6;
  1994 	uint w, h;
  1995 	uint w,h;
  1995 
  1996 
  1996 	int dx = thd->selstart.x - (thd->selend.x & ~0xF);
  1997 	int dx = thd->selstart.x - (thd->selend.x&~0xF);
  1997 	int dy = thd->selstart.y - (thd->selend.y & ~0xF);
  1998 	int dy = thd->selstart.y - (thd->selend.y&~0xF);
       
  1999 	w = myabs(dx) + 16;
  1998 	w = myabs(dx) + 16;
  2000 	h = myabs(dy) + 16;
  1999 	h = myabs(dy) + 16;
  2001 
  2000 
  2002 	if (TileVirtXY(thd->selstart.x, thd->selstart.y) == TileVirtXY(x, y)) { // check if we're only within one tile
  2001 	if (TileVirtXY(thd->selstart.x, thd->selstart.y) == TileVirtXY(x, y)) { // check if we're only within one tile
  2003 		if (method == VPM_RAILDIRS) {
  2002 		if (method == VPM_RAILDIRS) {
  2028 		y = thd->selstart.y;
  2027 		y = thd->selstart.y;
  2029 	} else if (h > w * 2) { // still count as y dir?
  2028 	} else if (h > w * 2) { // still count as y dir?
  2030 		b = HT_LINE | HT_DIR_Y;
  2029 		b = HT_LINE | HT_DIR_Y;
  2031 		x = thd->selstart.x;
  2030 		x = thd->selstart.x;
  2032 	} else { // complicated direction
  2031 	} else { // complicated direction
  2033 		d = w - h;
  2032 		int d = w - h;
  2034 		thd->selend.x = thd->selend.x & ~0xF;
  2033 		thd->selend.x = thd->selend.x & ~0xF;
  2035 		thd->selend.y = thd->selend.y & ~0xF;
  2034 		thd->selend.y = thd->selend.y & ~0xF;
  2036 
  2035 
  2037 		// four cases.
  2036 		// four cases.
  2038 		if (x > thd->selstart.x) {
  2037 		if (x > thd->selstart.x) {
  2091 	thd->selend.x = x;
  2090 	thd->selend.x = x;
  2092 	thd->selend.y = y;
  2091 	thd->selend.y = y;
  2093 	thd->next_drawstyle = b;
  2092 	thd->next_drawstyle = b;
  2094 }
  2093 }
  2095 
  2094 
  2096 // while dragging
  2095 /**
       
  2096  * Selects tiles while dragging
       
  2097  * @param x X coordinate of end of selection
       
  2098  * @param y Y coordinate of end of selection
       
  2099  * @param method modifies the way tiles are selected. Possible
       
  2100  * methods are VPM_* in viewport.h */
  2097 void VpSelectTilesWithMethod(int x, int y, int method)
  2101 void VpSelectTilesWithMethod(int x, int y, int method)
  2098 {
  2102 {
  2099 	int sx;
  2103 	int sx, sy;
  2100 	int sy;
       
  2101 
  2104 
  2102 	if (x == -1) {
  2105 	if (x == -1) {
  2103 		_thd.selend.x = -1;
  2106 		_thd.selend.x = -1;
  2104 		return;
  2107 		return;
  2105 	}
  2108 	}
  2106 
  2109 
  2107 	// allow drag in any rail direction
  2110 	/* Special handling of drag in any (8-way) direction */
  2108 	if (method == VPM_RAILDIRS || method == VPM_SIGNALDIRS) {
  2111 	if (method == VPM_RAILDIRS || method == VPM_SIGNALDIRS) {
  2109 		_thd.selend.x = x;
  2112 		_thd.selend.x = x;
  2110 		_thd.selend.y = y;
  2113 		_thd.selend.y = y;
  2111 		CalcRaildirsDrawstyle(&_thd, x, y, method);
  2114 		CalcRaildirsDrawstyle(&_thd, x, y, method);
  2112 		return;
  2115 		return;
  2113 	}
  2116 	}
  2114 
  2117 
  2115 	if (_thd.next_drawstyle == HT_POINT) {
  2118 	if (_thd.next_drawstyle == HT_POINT) {
  2116 		x += 8;
  2119 		x += TILE_SIZE / 2;
  2117 		y += 8;
  2120 		y += TILE_SIZE / 2;
  2118 	}
  2121 	}
  2119 
  2122 
  2120 	sx = _thd.selstart.x;
  2123 	sx = _thd.selstart.x;
  2121 	sy = _thd.selstart.y;
  2124 	sy = _thd.selstart.y;
  2122 
  2125