viewport.c
changeset 1542 2ca6d1624e6d
parent 1390 53a5713cf3f9
child 1863 610acc8bc189
equal deleted inserted replaced
1541:5c98ae4cf541 1542:2ca6d1624e6d
    11 #include "vehicle.h"
    11 #include "vehicle.h"
    12 #include "station.h"
    12 #include "station.h"
    13 #include "gfx.h"
    13 #include "gfx.h"
    14 #include "town.h"
    14 #include "town.h"
    15 #include "signs.h"
    15 #include "signs.h"
       
    16 #include "waypoint.h"
    16 
    17 
    17 #define VIEWPORT_DRAW_MEM (65536 * 2)
    18 #define VIEWPORT_DRAW_MEM (65536 * 2)
    18 
    19 
    19 static bool _added_tile_sprite;
    20 static bool _added_tile_sprite;
    20 static bool _offset_ground_sprites;
    21 static bool _offset_ground_sprites;
   976 	}
   977 	}
   977 }
   978 }
   978 
   979 
   979 static void ViewportAddWaypoints(DrawPixelInfo *dpi)
   980 static void ViewportAddWaypoints(DrawPixelInfo *dpi)
   980 {
   981 {
   981 	Waypoint *cp;
   982 	Waypoint *wp;
   982 
   983 
   983 	int left, top, right, bottom;
   984 	int left, top, right, bottom;
   984 	StringSpriteToDraw *sstd;
   985 	StringSpriteToDraw *sstd;
   985 
   986 
   986 	if (!(_display_opt & DO_WAYPOINTS))
   987 	if (!(_display_opt & DO_WAYPOINTS))
   990 	top = dpi->top;
   991 	top = dpi->top;
   991 	right = left + dpi->width;
   992 	right = left + dpi->width;
   992 	bottom = top + dpi->height;
   993 	bottom = top + dpi->height;
   993 
   994 
   994 	if (dpi->zoom < 1) {
   995 	if (dpi->zoom < 1) {
   995 		for(cp=_waypoints; cp != endof(_waypoints); cp++) {
   996 		FOR_ALL_WAYPOINTS(wp) {
   996 			if (cp->xy &&
   997 			if (wp->xy &&
   997 					bottom > cp->sign.top &&
   998 					bottom > wp->sign.top &&
   998 					top < cp->sign.top + 12 &&
   999 					top < wp->sign.top + 12 &&
   999 					right > cp->sign.left &&
  1000 					right > wp->sign.left &&
  1000 					left < cp->sign.left + cp->sign.width_1) {
  1001 					left < wp->sign.left + wp->sign.width_1) {
  1001 
  1002 
  1002 				sstd=AddStringToDraw(cp->sign.left + 1, cp->sign.top + 1, STR_WAYPOINT_VIEWPORT, cp - _waypoints, 0, 0);
  1003 				sstd = AddStringToDraw(wp->sign.left + 1, wp->sign.top + 1, STR_WAYPOINT_VIEWPORT, wp->index, 0, 0);
  1003 				if (sstd != NULL) {
  1004 				if (sstd != NULL) {
  1004 					sstd->width = cp->sign.width_1;
  1005 					sstd->width = wp->sign.width_1;
  1005 					sstd->color = (cp->deleted ? 0xE : 11);
  1006 					sstd->color = (wp->deleted ? 0xE : 11);
  1006 				}
  1007 				}
  1007 			}
  1008 			}
  1008 		}
  1009 		}
  1009 	} else if (dpi->zoom == 1) {
  1010 	} else if (dpi->zoom == 1) {
  1010 		right += 2;
  1011 		right += 2;
  1011 		bottom += 2;
  1012 		bottom += 2;
  1012 		for(cp=_waypoints; cp != endof(_waypoints); cp++) {
  1013 		FOR_ALL_WAYPOINTS(wp) {
  1013 			if (cp->xy &&
  1014 			if (wp->xy &&
  1014 					bottom > cp->sign.top &&
  1015 					bottom > wp->sign.top &&
  1015 					top < cp->sign.top + 24 &&
  1016 					top < wp->sign.top + 24 &&
  1016 					right > cp->sign.left &&
  1017 					right > wp->sign.left &&
  1017 					left < cp->sign.left + cp->sign.width_1*2) {
  1018 					left < wp->sign.left + wp->sign.width_1*2) {
  1018 
  1019 
  1019 				sstd=AddStringToDraw(cp->sign.left + 1, cp->sign.top + 1, STR_WAYPOINT_VIEWPORT, cp - _waypoints, 0, 0);
  1020 				sstd = AddStringToDraw(wp->sign.left + 1, wp->sign.top + 1, STR_WAYPOINT_VIEWPORT, wp->index, 0, 0);
  1020 				if (sstd != NULL) {
  1021 				if (sstd != NULL) {
  1021 					sstd->width = cp->sign.width_1;
  1022 					sstd->width = wp->sign.width_1;
  1022 					sstd->color = (cp->deleted ? 0xE : 11);
  1023 					sstd->color = (wp->deleted ? 0xE : 11);
  1023 				}
  1024 				}
  1024 			}
  1025 			}
  1025 		}
  1026 		}
  1026 	} else {
  1027 	} else {
  1027 		right += 4;
  1028 		right += 4;
  1028 		bottom += 5;
  1029 		bottom += 5;
  1029 
  1030 
  1030 		for(cp=_waypoints; cp != endof(_waypoints); cp++) {
  1031 		FOR_ALL_WAYPOINTS(wp) {
  1031 			if (cp->xy &&
  1032 			if (wp->xy &&
  1032 					bottom > cp->sign.top &&
  1033 					bottom > wp->sign.top &&
  1033 					top < cp->sign.top + 24 &&
  1034 					top < wp->sign.top + 24 &&
  1034 					right > cp->sign.left &&
  1035 					right > wp->sign.left &&
  1035 					left < cp->sign.left + cp->sign.width_2*4) {
  1036 					left < wp->sign.left + wp->sign.width_2*4) {
  1036 
  1037 
  1037 				sstd=AddStringToDraw(cp->sign.left + 1, cp->sign.top + 1, STR_WAYPOINT_VIEWPORT_TINY, cp - _waypoints, 0, 0);
  1038 				sstd = AddStringToDraw(wp->sign.left + 1, wp->sign.top + 1, STR_WAYPOINT_VIEWPORT_TINY, wp->index, 0, 0);
  1038 				if (sstd != NULL) {
  1039 				if (sstd != NULL) {
  1039 					sstd->width = cp->sign.width_2 | 0x8000;
  1040 					sstd->width = wp->sign.width_2 | 0x8000;
  1040 					sstd->color = (cp->deleted ? 0xE : 11);
  1041 					sstd->color = (wp->deleted ? 0xE : 11);
  1041 				}
  1042 				}
  1042 			}
  1043 			}
  1043 		}
  1044 		}
  1044 	}
  1045 	}
  1045 }
  1046 }
  1622 	return false;
  1623 	return false;
  1623 }
  1624 }
  1624 
  1625 
  1625 static bool CheckClickOnWaypoint(ViewPort *vp, int x, int y)
  1626 static bool CheckClickOnWaypoint(ViewPort *vp, int x, int y)
  1626 {
  1627 {
  1627 	Waypoint *cp;
  1628 	Waypoint *wp;
  1628 
  1629 
  1629 	if (!(_display_opt & DO_WAYPOINTS))
  1630 	if (!(_display_opt & DO_WAYPOINTS))
  1630 		return false;
  1631 		return false;
  1631 
  1632 
  1632 	if (vp->zoom < 1) {
  1633 	if (vp->zoom < 1) {
  1633 		x = x - vp->left + vp->virtual_left;
  1634 		x = x - vp->left + vp->virtual_left;
  1634 		y = y - vp->top + vp->virtual_top;
  1635 		y = y - vp->top + vp->virtual_top;
  1635 
  1636 
  1636 		for(cp = _waypoints; cp != endof(_waypoints); cp++) {
  1637 		FOR_ALL_WAYPOINTS(wp) {
  1637 			if (cp->xy &&
  1638 			if (wp->xy &&
  1638 			    y >= cp->sign.top &&
  1639 			    y >= wp->sign.top &&
  1639 					y < cp->sign.top + 12 &&
  1640 					y < wp->sign.top + 12 &&
  1640 					x >= cp->sign.left &&
  1641 					x >= wp->sign.left &&
  1641 					x < cp->sign.left + cp->sign.width_1) {
  1642 					x < wp->sign.left + wp->sign.width_1) {
  1642 				ShowRenameWaypointWindow(cp);
  1643 				ShowRenameWaypointWindow(wp);
  1643 				return true;
  1644 				return true;
  1644 			}
  1645 			}
  1645 		}
  1646 		}
  1646 	} else if (vp->zoom == 1) {
  1647 	} else if (vp->zoom == 1) {
  1647 		x = (x - vp->left + 1) * 2 + vp->virtual_left;
  1648 		x = (x - vp->left + 1) * 2 + vp->virtual_left;
  1648 		y = (y - vp->top + 1) * 2 + vp->virtual_top;
  1649 		y = (y - vp->top + 1) * 2 + vp->virtual_top;
  1649 		for(cp = _waypoints; cp != endof(_waypoints); cp++) {
  1650 		FOR_ALL_WAYPOINTS(wp) {
  1650 			if (cp->xy &&
  1651 			if (wp->xy &&
  1651 			    y >= cp->sign.top &&
  1652 			    y >= wp->sign.top &&
  1652 					y < cp->sign.top + 24 &&
  1653 					y < wp->sign.top + 24 &&
  1653 					x >= cp->sign.left &&
  1654 					x >= wp->sign.left &&
  1654 					x < cp->sign.left + cp->sign.width_1 * 2) {
  1655 					x < wp->sign.left + wp->sign.width_1 * 2) {
  1655 				ShowRenameWaypointWindow(cp);
  1656 				ShowRenameWaypointWindow(wp);
  1656 				return true;
  1657 				return true;
  1657 			}
  1658 			}
  1658 		}
  1659 		}
  1659 	} else {
  1660 	} else {
  1660 		x = (x - vp->left + 3) * 4 + vp->virtual_left;
  1661 		x = (x - vp->left + 3) * 4 + vp->virtual_left;
  1661 		y = (y - vp->top + 3) * 4 + vp->virtual_top;
  1662 		y = (y - vp->top + 3) * 4 + vp->virtual_top;
  1662 		for(cp = _waypoints; cp != endof(_waypoints); cp++) {
  1663 		FOR_ALL_WAYPOINTS(wp) {
  1663 			if (cp->xy &&
  1664 			if (wp->xy &&
  1664 			    y >= cp->sign.top &&
  1665 			    y >= wp->sign.top &&
  1665 					y < cp->sign.top + 24 &&
  1666 					y < wp->sign.top + 24 &&
  1666 					x >= cp->sign.left &&
  1667 					x >= wp->sign.left &&
  1667 					x < cp->sign.left + cp->sign.width_2 * 4) {
  1668 					x < wp->sign.left + wp->sign.width_2 * 4) {
  1668 				ShowRenameWaypointWindow(cp);
  1669 				ShowRenameWaypointWindow(wp);
  1669 				return true;
  1670 				return true;
  1670 			}
  1671 			}
  1671 		}
  1672 		}
  1672 	}
  1673 	}
  1673 
  1674