116 static ViewportDrawer *_cur_vd; |
116 static ViewportDrawer *_cur_vd; |
117 |
117 |
118 TileHighlightData _thd; |
118 TileHighlightData _thd; |
119 static TileInfo *_cur_ti; |
119 static TileInfo *_cur_ti; |
120 |
120 |
121 extern void SmallMapCenterOnCurrentPos(Window *w); |
121 extern void SmallMapCenterOnCurrentPos(BaseWindow *w); |
122 |
122 |
123 static Point MapXYZToViewport(const ViewPort *vp, uint x, uint y, uint z) |
123 static Point MapXYZToViewport(const ViewPort *vp, uint x, uint y, uint z) |
124 { |
124 { |
125 Point p = RemapCoords(x, y, z); |
125 Point p = RemapCoords(x, y, z); |
126 p.x -= vp->virtual_width / 2; |
126 p.x -= vp->virtual_width / 2; |
131 void InitViewports(void) { |
131 void InitViewports(void) { |
132 memset(_viewports, 0, sizeof(_viewports)); |
132 memset(_viewports, 0, sizeof(_viewports)); |
133 _active_viewports = 0; |
133 _active_viewports = 0; |
134 } |
134 } |
135 |
135 |
136 void DeleteWindowViewport(Window *w) |
136 void DeleteWindowViewport(BaseWindow *w) |
137 { |
137 { |
138 CLRBIT(_active_viewports, w->viewport - _viewports); |
138 CLRBIT(_active_viewports, w->viewport - _viewports); |
139 w->viewport->width = 0; |
139 w->viewport->width = 0; |
140 w->viewport = NULL; |
140 w->viewport = NULL; |
141 } |
141 } |
142 |
142 |
143 void AssignWindowViewport(Window *w, int x, int y, |
143 void AssignWindowViewport(BaseWindow *w, int x, int y, |
144 int width, int height, uint32 follow_flags, byte zoom) |
144 int width, int height, uint32 follow_flags, byte zoom) |
145 { |
145 { |
146 ViewPort *vp; |
146 ViewPort *vp; |
147 Point pt; |
147 Point pt; |
148 uint32 bit; |
148 uint32 bit; |
186 |
186 |
187 static Point _vp_move_offs; |
187 static Point _vp_move_offs; |
188 |
188 |
189 static void DoSetViewportPosition(WindowList::Iterator vit, int left, int top, int width, int height) |
189 static void DoSetViewportPosition(WindowList::Iterator vit, int left, int top, int width, int height) |
190 { |
190 { |
191 //Window *w = (*wit).w; |
191 //BaseWindow *w = (*wit).w; |
192 |
192 |
193 for (WindowList::Iterator wit = vit; wit != Window::s_list.m_list.end(); wit++) { |
193 for (WindowList::Iterator wit = vit; wit != BaseWindow::s_list.m_list.end(); wit++) { |
194 const Window *w = (*wit).w; |
194 const BaseWindow *w = (*wit).w; |
195 |
195 |
196 if (left + width > w->left && |
196 if (left + width > w->left && |
197 w->left + w->width > left && |
197 w->left + w->width > left && |
198 top + height > w->top && |
198 top + height > w->top && |
199 w->top + w->height > top) { |
199 w->top + w->height > top) { |
253 RedrawScreenRect(left, top + height + yo, width+left, top + height); |
253 RedrawScreenRect(left, top + height + yo, width+left, top + height); |
254 } |
254 } |
255 } |
255 } |
256 } |
256 } |
257 |
257 |
258 static void SetViewportPosition(Window *w, int x, int y) |
258 static void SetViewportPosition(BaseWindow *w, int x, int y) |
259 { |
259 { |
260 ViewPort *vp = w->viewport; |
260 ViewPort *vp = w->viewport; |
261 int old_left = vp->virtual_left; |
261 int old_left = vp->virtual_left; |
262 int old_top = vp->virtual_top; |
262 int old_top = vp->virtual_top; |
263 int i; |
263 int i; |
299 } |
299 } |
300 |
300 |
301 i = top + height - _screen.height; |
301 i = top + height - _screen.height; |
302 if (i >= 0) height -= i; |
302 if (i >= 0) height -= i; |
303 |
303 |
304 WindowList::Iterator it = Window::s_list.Find(w); |
304 WindowList::Iterator it = BaseWindow::s_list.Find(w); |
305 if (height > 0) DoSetViewportPosition(++it, left, top, width, height); |
305 if (height > 0) DoSetViewportPosition(++it, left, top, width, height); |
306 } |
306 } |
307 } |
307 } |
308 |
308 |
309 |
309 |
310 ViewPort *IsPtInWindowViewport(const Window *w, int x, int y) |
310 ViewPort *IsPtInWindowViewport(const BaseWindow *w, int x, int y) |
311 { |
311 { |
312 ViewPort *vp = w->viewport; |
312 ViewPort *vp = w->viewport; |
313 |
313 |
314 if (vp != NULL && |
314 if (vp != NULL && |
315 IS_INT_INSIDE(x, vp->left, vp->left + vp->width) && |
315 IS_INT_INSIDE(x, vp->left, vp->left + vp->width) && |
358 /* When used for zooming, check area below current coordinates (x,y) |
358 /* When used for zooming, check area below current coordinates (x,y) |
359 * and return the tile of the zoomed out/in position (zoom_x, zoom_y) |
359 * and return the tile of the zoomed out/in position (zoom_x, zoom_y) |
360 * when you just want the tile, make x = zoom_x and y = zoom_y */ |
360 * when you just want the tile, make x = zoom_x and y = zoom_y */ |
361 static Point GetTileFromScreenXY(int x, int y, int zoom_x, int zoom_y) |
361 static Point GetTileFromScreenXY(int x, int y, int zoom_x, int zoom_y) |
362 { |
362 { |
363 Window *w; |
363 BaseWindow *w; |
364 ViewPort *vp; |
364 ViewPort *vp; |
365 Point pt; |
365 Point pt; |
366 |
366 |
367 if ( (w = FindWindowFromPt(x, y)) != NULL && |
367 if ( (w = BaseWindow::FindFromPt(x, y)) != NULL && |
368 (vp = IsPtInWindowViewport(w, x, y)) != NULL) |
368 (vp = IsPtInWindowViewport(w, x, y)) != NULL) |
369 return TranslateXYToTileCoord(vp, zoom_x, zoom_y); |
369 return TranslateXYToTileCoord(vp, zoom_x, zoom_y); |
370 |
370 |
371 pt.y = pt.x = -1; |
371 pt.y = pt.x = -1; |
372 return pt; |
372 return pt; |
400 * of the viewport. This will update their status and invalidate accordingly |
400 * of the viewport. This will update their status and invalidate accordingly |
401 * @param window pointer to the window that has the zoom buttons |
401 * @param window pointer to the window that has the zoom buttons |
402 * @param vp pointer to the viewport whose zoom-level the buttons represent |
402 * @param vp pointer to the viewport whose zoom-level the buttons represent |
403 * @param widget_zoom_in widget index for window with zoom-in button |
403 * @param widget_zoom_in widget index for window with zoom-in button |
404 * @param widget_zoom_out widget index for window with zoom-out button */ |
404 * @param widget_zoom_out widget index for window with zoom-out button */ |
405 void HandleZoomMessage(Window *w, const ViewPort *vp, byte widget_zoom_in, byte widget_zoom_out) |
405 void HandleZoomMessage(BaseWindow *w, const ViewPort *vp, byte widget_zoom_in, byte widget_zoom_out) |
406 { |
406 { |
407 w->SetWidgetDisabledState(widget_zoom_in, vp->zoom == 0); |
407 w->SetWidgetDisabledState(widget_zoom_in, vp->zoom == 0); |
408 w->InvalidateWidget(widget_zoom_in); |
408 w->InvalidateWidget(widget_zoom_in); |
409 |
409 |
410 w->SetWidgetDisabledState(widget_zoom_out, vp->zoom == 2); |
410 w->SetWidgetDisabledState(widget_zoom_out, vp->zoom == 2); |
1330 if (bottom > vp->top + vp->height) bottom = vp->top + vp->height; |
1330 if (bottom > vp->top + vp->height) bottom = vp->top + vp->height; |
1331 |
1331 |
1332 ViewportDrawChk(vp, left, top, right, bottom); |
1332 ViewportDrawChk(vp, left, top, right, bottom); |
1333 } |
1333 } |
1334 |
1334 |
1335 void Window::DrawViewport() const |
1335 void BaseWindow::DrawViewport() const |
1336 { |
1336 { |
1337 DrawPixelInfo *dpi = _cur_dpi; |
1337 DrawPixelInfo *dpi = _cur_dpi; |
1338 |
1338 |
1339 dpi->left += left; |
1339 dpi->left += left; |
1340 dpi->top += top; |
1340 dpi->top += top; |
1343 |
1343 |
1344 dpi->left -= left; |
1344 dpi->left -= left; |
1345 dpi->top -= top; |
1345 dpi->top -= top; |
1346 } |
1346 } |
1347 |
1347 |
1348 void UpdateViewportPosition(Window *w) |
1348 void UpdateViewportPosition(BaseWindow *w) |
1349 { |
1349 { |
1350 const ViewPort *vp = w->viewport; |
1350 const ViewPort *vp = w->viewport; |
1351 |
1351 |
1352 if (WP(w, vp_d).follow_vehicle != INVALID_VEHICLE) { |
1352 if (WP(w, vp_d).follow_vehicle != INVALID_VEHICLE) { |
1353 const Vehicle* veh = GetVehicle(WP(w,vp_d).follow_vehicle); |
1353 const Vehicle* veh = GetVehicle(WP(w,vp_d).follow_vehicle); |
1744 } |
1744 } |
1745 } |
1745 } |
1746 |
1746 |
1747 Vehicle *CheckMouseOverVehicle(void) |
1747 Vehicle *CheckMouseOverVehicle(void) |
1748 { |
1748 { |
1749 const Window *w; |
1749 const BaseWindow *w; |
1750 const ViewPort *vp; |
1750 const ViewPort *vp; |
1751 |
1751 |
1752 int x = _cursor.pos.x; |
1752 int x = _cursor.pos.x; |
1753 int y = _cursor.pos.y; |
1753 int y = _cursor.pos.y; |
1754 |
1754 |
1755 w = FindWindowFromPt(x, y); |
1755 w = BaseWindow::FindFromPt(x, y); |
1756 if (w == NULL) return NULL; |
1756 if (w == NULL) return NULL; |
1757 |
1757 |
1758 vp = IsPtInWindowViewport(w, x, y); |
1758 vp = IsPtInWindowViewport(w, x, y); |
1759 return (vp != NULL) ? CheckClickOnVehicle(vp, x, y) : NULL; |
1759 return (vp != NULL) ? CheckClickOnVehicle(vp, x, y) : NULL; |
1760 } |
1760 } |
1788 } |
1788 } |
1789 } |
1789 } |
1790 |
1790 |
1791 |
1791 |
1792 /* scrolls the viewport in a window to a given location */ |
1792 /* scrolls the viewport in a window to a given location */ |
1793 bool ScrollWindowTo(int x , int y, Window *w) |
1793 bool ScrollWindowTo(int x , int y, BaseWindow *w) |
1794 { |
1794 { |
1795 Point pt; |
1795 Point pt; |
1796 |
1796 |
1797 pt = MapXYZToViewport(w->viewport, x, y, GetSlopeZ(x, y)); |
1797 pt = MapXYZToViewport(w->viewport, x, y, GetSlopeZ(x, y)); |
1798 WP(w, vp_d).follow_vehicle = INVALID_VEHICLE; |
1798 WP(w, vp_d).follow_vehicle = INVALID_VEHICLE; |
1806 } |
1806 } |
1807 |
1807 |
1808 |
1808 |
1809 bool ScrollMainWindowTo(int x, int y) |
1809 bool ScrollMainWindowTo(int x, int y) |
1810 { |
1810 { |
1811 Window *w; |
1811 BaseWindow *w; |
1812 bool res = ScrollWindowTo(x, y, Window::FindById(WC_MAIN_WINDOW, 0)); |
1812 bool res = ScrollWindowTo(x, y, BaseWindow::FindById(WC_MAIN_WINDOW, 0)); |
1813 |
1813 |
1814 /* If a user scrolls to a tile (via what way what so ever) and already is on |
1814 /* If a user scrolls to a tile (via what way what so ever) and already is on |
1815 * that tile (e.g.: pressed twice), move the smallmap to that location, |
1815 * that tile (e.g.: pressed twice), move the smallmap to that location, |
1816 * so you directly see where you are on the smallmap. */ |
1816 * so you directly see where you are on the smallmap. */ |
1817 |
1817 |
1818 if (res) return res; |
1818 if (res) return res; |
1819 |
1819 |
1820 w = Window::FindById(WC_SMALLMAP, 0); |
1820 w = BaseWindow::FindById(WC_SMALLMAP, 0); |
1821 if (w == NULL) return res; |
1821 if (w == NULL) return res; |
1822 |
1822 |
1823 SmallMapCenterOnCurrentPos(w); |
1823 SmallMapCenterOnCurrentPos(w); |
1824 |
1824 |
1825 return res; |
1825 return res; |
2386 } |
2386 } |
2387 |
2387 |
2388 // while dragging |
2388 // while dragging |
2389 bool VpHandlePlaceSizingDrag(void) |
2389 bool VpHandlePlaceSizingDrag(void) |
2390 { |
2390 { |
2391 Window *w; |
2391 BaseWindow *w; |
2392 WindowEvent e; |
2392 WindowEvent e; |
2393 |
2393 |
2394 if (_special_mouse_mode != WSM_SIZING) return true; |
2394 if (_special_mouse_mode != WSM_SIZING) return true; |
2395 |
2395 |
2396 e.we.place.userdata = _thd.userdata; |
2396 e.we.place.userdata = _thd.userdata; |
2397 |
2397 |
2398 // stop drag mode if the window has been closed |
2398 // stop drag mode if the window has been closed |
2399 w = Window::FindById(_thd.window_class,_thd.window_number); |
2399 w = BaseWindow::FindById(_thd.window_class,_thd.window_number); |
2400 if (w == NULL) { |
2400 if (w == NULL) { |
2401 ResetObjectToPlace(); |
2401 ResetObjectToPlace(); |
2402 return false; |
2402 return false; |
2403 } |
2403 } |
2404 |
2404 |
2434 w->wndproc(w, &e); |
2434 w->wndproc(w, &e); |
2435 |
2435 |
2436 return false; |
2436 return false; |
2437 } |
2437 } |
2438 |
2438 |
2439 void SetObjectToPlaceWnd(CursorID icon, SpriteID pal, byte mode, Window *w) |
2439 void SetObjectToPlaceWnd(CursorID icon, SpriteID pal, byte mode, BaseWindow *w) |
2440 { |
2440 { |
2441 SetObjectToPlace(icon, pal, mode, w->window_class, w->window_number); |
2441 SetObjectToPlace(icon, pal, mode, w->window_class, w->window_number); |
2442 } |
2442 } |
2443 |
2443 |
2444 #include "table/animcursors.h" |
2444 #include "table/animcursors.h" |
2445 |
2445 |
2446 void SetObjectToPlace(CursorID icon, SpriteID pal, byte mode, WindowClass window_class, WindowNumber window_num) |
2446 void SetObjectToPlace(CursorID icon, SpriteID pal, byte mode, WindowClass window_class, WindowNumber window_num) |
2447 { |
2447 { |
2448 Window *w; |
2448 BaseWindow *w; |
2449 |
2449 |
2450 // undo clicking on button |
2450 // undo clicking on button |
2451 if (_thd.place_mode != 0) { |
2451 if (_thd.place_mode != 0) { |
2452 _thd.place_mode = 0; |
2452 _thd.place_mode = 0; |
2453 w = Window::FindById(_thd.window_class, _thd.window_number); |
2453 w = BaseWindow::FindById(_thd.window_class, _thd.window_number); |
2454 if (w != NULL) w->CallEventNP(WE_ABORT_PLACE_OBJ); |
2454 if (w != NULL) w->CallEventNP(WE_ABORT_PLACE_OBJ); |
2455 } |
2455 } |
2456 |
2456 |
2457 SetTileSelectSize(1, 1); |
2457 SetTileSelectSize(1, 1); |
2458 |
2458 |