src/smallmap_gui.cpp
changeset 6916 e87d54a598ea
parent 6683 7ec558346172
child 6937 965cbdb905ec
child 9599 949374e83b78
equal deleted inserted replaced
6915:99e67df845fd 6916:e87d54a598ea
     1 /* $Id$ */
     1 /* $Id$ */
       
     2 
       
     3 /** @file smallmap_gui.cpp */
     2 
     4 
     3 #include "stdafx.h"
     5 #include "stdafx.h"
     4 #include "openttd.h"
     6 #include "openttd.h"
     5 #include "functions.h"
     7 #include "functions.h"
     6 #include "bridge_map.h"
     8 #include "bridge_map.h"
   330 static void DrawSmallMapStuff(Pixel *dst, uint xc, uint yc, int pitch, int reps, uint32 mask, GetSmallMapPixels *proc)
   332 static void DrawSmallMapStuff(Pixel *dst, uint xc, uint yc, int pitch, int reps, uint32 mask, GetSmallMapPixels *proc)
   331 {
   333 {
   332 	Pixel *dst_ptr_end = _screen.dst_ptr + _screen.width * _screen.height - _screen.width;
   334 	Pixel *dst_ptr_end = _screen.dst_ptr + _screen.width * _screen.height - _screen.width;
   333 
   335 
   334 	do {
   336 	do {
   335 		// check if the tile (xc,yc) is within the map range
   337 		/* check if the tile (xc,yc) is within the map range */
   336 		if (xc < MapMaxX() && yc < MapMaxY()) {
   338 		if (xc < MapMaxX() && yc < MapMaxY()) {
   337 			// check if the dst pointer points to a pixel inside the screen buffer
   339 			/* check if the dst pointer points to a pixel inside the screen buffer */
   338 			if (dst > _screen.dst_ptr && dst < dst_ptr_end)
   340 			if (dst > _screen.dst_ptr && dst < dst_ptr_end)
   339 				WRITE_PIXELS_OR(dst, proc(TileXY(xc, yc)) & mask);
   341 				WRITE_PIXELS_OR(dst, proc(TileXY(xc, yc)) & mask);
   340 		}
   342 		}
   341 	// switch to next tile in the column
   343 	/* switch to next tile in the column */
   342 	} while (xc++, yc++, dst += pitch, --reps != 0);
   344 	} while (xc++, yc++, dst += pitch, --reps != 0);
   343 }
   345 }
   344 
   346 
   345 
   347 
   346 static inline TileType GetEffectiveTileType(TileIndex tile)
   348 static inline TileType GetEffectiveTileType(TileIndex tile)
   452 			case STATION_BUS:     bits = MKCOLOR(0xBFBFBFBF); break;
   454 			case STATION_BUS:     bits = MKCOLOR(0xBFBFBFBF); break;
   453 			case STATION_DOCK:    bits = MKCOLOR(0x98989898); break;
   455 			case STATION_DOCK:    bits = MKCOLOR(0x98989898); break;
   454 			default:              bits = MKCOLOR(0xFFFFFFFF); break;
   456 			default:              bits = MKCOLOR(0xFFFFFFFF); break;
   455 		}
   457 		}
   456 	} else {
   458 	} else {
   457 		// ground color
   459 		/* ground color */
   458 		bits = ApplyMask(MKCOLOR(0x54545454), &_smallmap_contours_andor[t]);
   460 		bits = ApplyMask(MKCOLOR(0x54545454), &_smallmap_contours_andor[t]);
   459 	}
   461 	}
   460 	return bits;
   462 	return bits;
   461 }
   463 }
   462 
   464 
   691 		byte color;
   693 		byte color;
   692 
   694 
   693 		FOR_ALL_VEHICLES(v) {
   695 		FOR_ALL_VEHICLES(v) {
   694 			if (v->type != VEH_SPECIAL &&
   696 			if (v->type != VEH_SPECIAL &&
   695 					(v->vehstatus & (VS_HIDDEN | VS_UNCLICKABLE)) == 0) {
   697 					(v->vehstatus & (VS_HIDDEN | VS_UNCLICKABLE)) == 0) {
   696 				// Remap into flat coordinates.
   698 				/* Remap into flat coordinates. */
   697 				Point pt = RemapCoords(
   699 				Point pt = RemapCoords(
   698 					v->x_pos / TILE_SIZE - WP(w,smallmap_d).scroll_x / TILE_SIZE, // divide each one separately because (a-b)/c != a/c-b/c in integer world
   700 					v->x_pos / TILE_SIZE - WP(w,smallmap_d).scroll_x / TILE_SIZE, // divide each one separately because (a-b)/c != a/c-b/c in integer world
   699 					v->y_pos / TILE_SIZE - WP(w,smallmap_d).scroll_y / TILE_SIZE, //    dtto
   701 					v->y_pos / TILE_SIZE - WP(w,smallmap_d).scroll_y / TILE_SIZE, //    dtto
   700 					0);
   702 					0);
   701 				x = pt.x;
   703 				x = pt.x;
   702 				y = pt.y;
   704 				y = pt.y;
   703 
   705 
   704 				// Check if y is out of bounds?
   706 				/* Check if y is out of bounds? */
   705 				y -= dpi->top;
   707 				y -= dpi->top;
   706 				if (!IS_INT_INSIDE(y, 0, dpi->height)) continue;
   708 				if (!IS_INT_INSIDE(y, 0, dpi->height)) continue;
   707 
   709 
   708 				// Default is to draw both pixels.
   710 				/* Default is to draw both pixels. */
   709 				skip = false;
   711 				skip = false;
   710 
   712 
   711 				// Offset X coordinate
   713 				/* Offset X coordinate */
   712 				x -= WP(w,smallmap_d).subscroll + 3 + dpi->left;
   714 				x -= WP(w,smallmap_d).subscroll + 3 + dpi->left;
   713 
   715 
   714 				if (x < 0) {
   716 				if (x < 0) {
   715 					// if x+1 is 0, that means we're on the very left edge,
   717 					/* if x+1 is 0, that means we're on the very left edge,
   716 					//  and should thus only draw a single pixel
   718 					 *  and should thus only draw a single pixel */
   717 					if (++x != 0) continue;
   719 					if (++x != 0) continue;
   718 					skip = true;
   720 					skip = true;
   719 				} else if (x >= dpi->width - 1) {
   721 				} else if (x >= dpi->width - 1) {
   720 					// Check if we're at the very right edge, and if so draw only a single pixel
   722 					/* Check if we're at the very right edge, and if so draw only a single pixel */
   721 					if (x != dpi->width - 1) continue;
   723 					if (x != dpi->width - 1) continue;
   722 					skip = true;
   724 					skip = true;
   723 				}
   725 				}
   724 
   726 
   725 				// Calculate pointer to pixel and the color
   727 				/* Calculate pointer to pixel and the color */
   726 				ptr = dpi->dst_ptr + y * dpi->pitch + x;
   728 				ptr = dpi->dst_ptr + y * dpi->pitch + x;
   727 				color = (type == 1) ? _vehicle_type_colors[v->type] : 0xF;
   729 				color = (type == 1) ? _vehicle_type_colors[v->type] : 0xF;
   728 
   730 
   729 				// And draw either one or two pixels depending on clipping
   731 				/* And draw either one or two pixels depending on clipping */
   730 				ptr[0] = color;
   732 				ptr[0] = color;
   731 				if (!skip) ptr[1] = color;
   733 				if (!skip) ptr[1] = color;
   732 			}
   734 			}
   733 		}
   735 		}
   734 	}
   736 	}
   735 
   737 
   736 	if (show_towns) {
   738 	if (show_towns) {
   737 		const Town *t;
   739 		const Town *t;
   738 
   740 
   739 		FOR_ALL_TOWNS(t) {
   741 		FOR_ALL_TOWNS(t) {
   740 			// Remap the town coordinate
   742 			/* Remap the town coordinate */
   741 			Point pt = RemapCoords(
   743 			Point pt = RemapCoords(
   742 				(int)(TileX(t->xy) * TILE_SIZE - WP(w, smallmap_d).scroll_x) / TILE_SIZE,
   744 				(int)(TileX(t->xy) * TILE_SIZE - WP(w, smallmap_d).scroll_x) / TILE_SIZE,
   743 				(int)(TileY(t->xy) * TILE_SIZE - WP(w, smallmap_d).scroll_y) / TILE_SIZE,
   745 				(int)(TileY(t->xy) * TILE_SIZE - WP(w, smallmap_d).scroll_y) / TILE_SIZE,
   744 				0);
   746 				0);
   745 			x = pt.x - WP(w,smallmap_d).subscroll + 3 - (t->sign.width_2 >> 1);
   747 			x = pt.x - WP(w,smallmap_d).subscroll + 3 - (t->sign.width_2 >> 1);
   746 			y = pt.y;
   748 			y = pt.y;
   747 
   749 
   748 			// Check if the town sign is within bounds
   750 			/* Check if the town sign is within bounds */
   749 			if (x + t->sign.width_2 > dpi->left &&
   751 			if (x + t->sign.width_2 > dpi->left &&
   750 					x < dpi->left + dpi->width &&
   752 					x < dpi->left + dpi->width &&
   751 					y + 6 > dpi->top &&
   753 					y + 6 > dpi->top &&
   752 					y < dpi->top + dpi->height) {
   754 					y < dpi->top + dpi->height) {
   753 				// And draw it.
   755 				/* And draw it. */
   754 				SetDParam(0, t->index);
   756 				SetDParam(0, t->index);
   755 				DrawString(x, y, STR_2056, 12);
   757 				DrawString(x, y, STR_2056, 12);
   756 			}
   758 			}
   757 		}
   759 		}
   758 	}
   760 	}
   759 
   761 
   760 	// Draw map indicators
   762 	/* Draw map indicators */
   761 	{
   763 	{
   762 		Point pt;
   764 		Point pt;
   763 
   765 
   764 		// Find main viewport.
   766 		/* Find main viewport. */
   765 		vp = FindWindowById(WC_MAIN_WINDOW,0)->viewport;
   767 		vp = FindWindowById(WC_MAIN_WINDOW,0)->viewport;
   766 
   768 
   767 		pt = RemapCoords(WP(w, smallmap_d).scroll_x, WP(w, smallmap_d).scroll_y, 0);
   769 		pt = RemapCoords(WP(w, smallmap_d).scroll_x, WP(w, smallmap_d).scroll_y, 0);
   768 
   770 
   769 		x = vp->virtual_left - pt.x;
   771 		x = vp->virtual_left - pt.x;
  1031 		case 7: { /* location button (move main view to same spot as this view) 'Paste Location' */
  1033 		case 7: { /* location button (move main view to same spot as this view) 'Paste Location' */
  1032 			Window *w2 = FindWindowById(WC_MAIN_WINDOW, 0);
  1034 			Window *w2 = FindWindowById(WC_MAIN_WINDOW, 0);
  1033 			int x = WP(w, vp_d).scrollpos_x; // Where is the main looking at
  1035 			int x = WP(w, vp_d).scrollpos_x; // Where is the main looking at
  1034 			int y = WP(w, vp_d).scrollpos_y;
  1036 			int y = WP(w, vp_d).scrollpos_y;
  1035 
  1037 
  1036 			// set this view to same location. Based on the center, adjusting for zoom
  1038 			/* set this view to same location. Based on the center, adjusting for zoom */
  1037 			WP(w2, vp_d).scrollpos_x =  x - (w2->viewport->virtual_width -  w->viewport->virtual_width) / 2;
  1039 			WP(w2, vp_d).scrollpos_x =  x - (w2->viewport->virtual_width -  w->viewport->virtual_width) / 2;
  1038 			WP(w2, vp_d).scrollpos_y =  y - (w2->viewport->virtual_height - w->viewport->virtual_height) / 2;
  1040 			WP(w2, vp_d).scrollpos_y =  y - (w2->viewport->virtual_height - w->viewport->virtual_height) / 2;
  1039 		} break;
  1041 		} break;
  1040 
  1042 
  1041 		case 8: { /* inverse location button (move this view to same spot as main view) 'Copy Location' */
  1043 		case 8: { /* inverse location button (move this view to same spot as main view) 'Copy Location' */
  1092 void ShowExtraViewPortWindow()
  1094 void ShowExtraViewPortWindow()
  1093 {
  1095 {
  1094 	Window *w, *v;
  1096 	Window *w, *v;
  1095 	int i = 0;
  1097 	int i = 0;
  1096 
  1098 
  1097 	// find next free window number for extra viewport
  1099 	/* find next free window number for extra viewport */
  1098 	while (FindWindowById(WC_EXTRA_VIEW_PORT, i) != NULL) i++;
  1100 	while (FindWindowById(WC_EXTRA_VIEW_PORT, i) != NULL) i++;
  1099 
  1101 
  1100 	w = AllocateWindowDescFront(&_extra_view_port_desc, i);
  1102 	w = AllocateWindowDescFront(&_extra_view_port_desc, i);
  1101 	if (w != NULL) {
  1103 	if (w != NULL) {
  1102 		int x, y;
  1104 		int x, y;
  1103 		// the main window with the main view
  1105 		/* the main window with the main view */
  1104 		v = FindWindowById(WC_MAIN_WINDOW, 0);
  1106 		v = FindWindowById(WC_MAIN_WINDOW, 0);
  1105 		// New viewport start ats (zero,zero)
  1107 		/* New viewport start ats (zero,zero) */
  1106 		AssignWindowViewport(w, 3, 17, 294, 214, 0 , 0);
  1108 		AssignWindowViewport(w, 3, 17, 294, 214, 0 , 0);
  1107 
  1109 
  1108 		// center on same place as main window (zoom is maximum, no adjustment needed)
  1110 		/* center on same place as main window (zoom is maximum, no adjustment needed) */
  1109 		x = WP(v, vp_d).scrollpos_x;
  1111 		x = WP(v, vp_d).scrollpos_x;
  1110 		y = WP(v, vp_d).scrollpos_y;
  1112 		y = WP(v, vp_d).scrollpos_y;
  1111 		WP(w, vp_d).scrollpos_x = x + (v->viewport->virtual_width  - (294)) / 2;
  1113 		WP(w, vp_d).scrollpos_x = x + (v->viewport->virtual_width  - (294)) / 2;
  1112 		WP(w, vp_d).scrollpos_y = y + (v->viewport->virtual_height - (214)) / 2;
  1114 		WP(w, vp_d).scrollpos_y = y + (v->viewport->virtual_height - (214)) / 2;
  1113 	}
  1115 	}