181 pt = MapXYZToViewport(vp, x, y, GetSlopeZ(x, y)); |
182 pt = MapXYZToViewport(vp, x, y, GetSlopeZ(x, y)); |
182 } |
183 } |
183 |
184 |
184 WP(w, vp_d).scrollpos_x = pt.x; |
185 WP(w, vp_d).scrollpos_x = pt.x; |
185 WP(w, vp_d).scrollpos_y = pt.y; |
186 WP(w, vp_d).scrollpos_y = pt.y; |
|
187 WP(w, vp_d).dest_scrollpos_x = pt.x; |
|
188 WP(w, vp_d).dest_scrollpos_y = pt.y; |
|
189 |
186 w->viewport = vp; |
190 w->viewport = vp; |
187 vp->virtual_left = 0;//pt.x; |
191 vp->virtual_left = 0;//pt.x; |
188 vp->virtual_top = 0;//pt.y; |
192 vp->virtual_top = 0;//pt.y; |
189 } |
193 } |
190 |
194 |
1070 right > wp->sign.left && |
1065 right > wp->sign.left && |
1071 left < wp->sign.left + ScaleByZoom(wp->sign.width_2, dpi->zoom)) { |
1066 left < wp->sign.left + ScaleByZoom(wp->sign.width_2, dpi->zoom)) { |
1072 AddWaypoint(wp, STR_WAYPOINT_VIEWPORT_TINY, wp->sign.width_2 | 0x8000); |
1067 AddWaypoint(wp, STR_WAYPOINT_VIEWPORT_TINY, wp->sign.width_2 | 0x8000); |
1073 } |
1068 } |
1074 } |
1069 } |
1075 break; |
|
1076 |
|
1077 case ZOOM_LVL_OUT_16X: |
|
1078 break; |
1070 break; |
1079 |
1071 |
1080 default: NOT_REACHED(); |
1072 default: NOT_REACHED(); |
1081 } |
1073 } |
1082 } |
1074 } |
1384 int vy; |
1376 int vy; |
1385 |
1377 |
1386 /* Center of the viewport is hot spot */ |
1378 /* Center of the viewport is hot spot */ |
1387 x = WP(w,vp_d).scrollpos_x + vp->virtual_width / 2; |
1379 x = WP(w,vp_d).scrollpos_x + vp->virtual_width / 2; |
1388 y = WP(w,vp_d).scrollpos_y + vp->virtual_height / 2; |
1380 y = WP(w,vp_d).scrollpos_y + vp->virtual_height / 2; |
|
1381 |
|
1382 int dest_x = WP(w,vp_d).dest_scrollpos_x + vp->virtual_width / 2; |
|
1383 int dest_y = WP(w,vp_d).dest_scrollpos_y + vp->virtual_height / 2; |
|
1384 |
|
1385 int delta_x = dest_x - x; |
|
1386 int delta_y = dest_y - y; |
|
1387 |
|
1388 if (delta_x != 0 || delta_y != 0) { |
|
1389 if (_patches.smooth_scroll) { |
|
1390 int max_scroll = ScaleByMapSize1D(512); |
|
1391 /* Not at our desired positon yet... */ |
|
1392 x += clamp(delta_x / 8, -max_scroll, max_scroll); |
|
1393 y += clamp(delta_y / 8, -max_scroll, max_scroll); |
|
1394 } else { |
|
1395 x = dest_x; |
|
1396 y = dest_y; |
|
1397 } |
|
1398 } |
|
1399 |
1389 /* Convert viewport coordinates to map coordinates |
1400 /* Convert viewport coordinates to map coordinates |
1390 * Calculation is scaled by 4 to avoid rounding errors */ |
1401 * Calculation is scaled by 4 to avoid rounding errors */ |
1391 vx = -x + y * 2; |
1402 vx = -x + y * 2; |
1392 vy = x + y * 2; |
1403 vy = x + y * 2; |
1393 /* clamp to size of map */ |
1404 /* clamp to size of map */ |
1762 |
1761 |
1763 static void SafeShowTrainViewWindow(const Vehicle* v) |
1762 static void SafeShowTrainViewWindow(const Vehicle* v) |
1764 { |
1763 { |
1765 if (!IsFrontEngine(v)) v = GetFirstVehicleInChain(v); |
1764 if (!IsFrontEngine(v)) v = GetFirstVehicleInChain(v); |
1766 ShowTrainViewWindow(v); |
1765 ShowTrainViewWindow(v); |
|
1766 } |
|
1767 |
|
1768 static void SafeShowRoadVehViewWindow(const Vehicle *v) |
|
1769 { |
|
1770 if (!IsRoadVehFront(v)) v = GetFirstVehicleInChain(v); |
|
1771 ShowRoadVehViewWindow(v); |
1767 } |
1772 } |
1768 |
1773 |
1769 static void Nop(const Vehicle *v) {} |
1774 static void Nop(const Vehicle *v) {} |
1770 |
1775 |
1771 typedef void OnVehicleClickProc(const Vehicle *v); |
1776 typedef void OnVehicleClickProc(const Vehicle *v); |
1772 static OnVehicleClickProc* const _on_vehicle_click_proc[] = { |
1777 static OnVehicleClickProc* const _on_vehicle_click_proc[] = { |
1773 SafeShowTrainViewWindow, |
1778 SafeShowTrainViewWindow, |
1774 ShowRoadVehViewWindow, |
1779 SafeShowRoadVehViewWindow, |
1775 ShowShipViewWindow, |
1780 ShowShipViewWindow, |
1776 ShowAircraftViewWindow, |
1781 ShowAircraftViewWindow, |
1777 Nop, // Special vehicles |
1782 Nop, // Special vehicles |
1778 Nop // Disaster vehicles |
1783 Nop // Disaster vehicles |
1779 }; |
1784 }; |
1839 } |
1844 } |
1840 } |
1845 } |
1841 |
1846 |
1842 |
1847 |
1843 /* scrolls the viewport in a window to a given location */ |
1848 /* scrolls the viewport in a window to a given location */ |
1844 bool ScrollWindowTo(int x , int y, Window *w) |
1849 bool ScrollWindowTo(int x , int y, Window *w, bool instant) |
1845 { |
1850 { |
1846 Point pt; |
1851 Point pt; |
1847 |
1852 |
1848 pt = MapXYZToViewport(w->viewport, x, y, GetSlopeZ(x, y)); |
1853 pt = MapXYZToViewport(w->viewport, x, y, GetSlopeZ(x, y)); |
1849 WP(w, vp_d).follow_vehicle = INVALID_VEHICLE; |
1854 WP(w, vp_d).follow_vehicle = INVALID_VEHICLE; |
1850 |
1855 |
1851 if (WP(w, vp_d).scrollpos_x == pt.x && WP(w, vp_d).scrollpos_y == pt.y) |
1856 if (WP(w, vp_d).dest_scrollpos_x == pt.x && WP(w, vp_d).dest_scrollpos_y == pt.y) |
1852 return false; |
1857 return false; |
1853 |
1858 |
1854 WP(w, vp_d).scrollpos_x = pt.x; |
1859 if (instant) { |
1855 WP(w, vp_d).scrollpos_y = pt.y; |
1860 WP(w, vp_d).scrollpos_x = pt.x; |
|
1861 WP(w, vp_d).scrollpos_y = pt.y; |
|
1862 } |
|
1863 |
|
1864 WP(w, vp_d).dest_scrollpos_x = pt.x; |
|
1865 WP(w, vp_d).dest_scrollpos_y = pt.y; |
1856 return true; |
1866 return true; |
1857 } |
1867 } |
1858 |
1868 |
1859 |
1869 |
1860 bool ScrollMainWindowTo(int x, int y) |
1870 bool ScrollMainWindowTo(int x, int y, bool instant) |
1861 { |
1871 { |
1862 Window *w; |
1872 Window *w; |
1863 bool res = ScrollWindowTo(x, y, FindWindowById(WC_MAIN_WINDOW, 0)); |
1873 bool res = ScrollWindowTo(x, y, FindWindowById(WC_MAIN_WINDOW, 0), instant); |
1864 |
1874 |
1865 /* If a user scrolls to a tile (via what way what so ever) and already is on |
1875 /* If a user scrolls to a tile (via what way what so ever) and already is on |
1866 * that tile (e.g.: pressed twice), move the smallmap to that location, |
1876 * that tile (e.g.: pressed twice), move the smallmap to that location, |
1867 * so you directly see where you are on the smallmap. */ |
1877 * so you directly see where you are on the smallmap. */ |
1868 |
1878 |