virtual void OnClick(Point pt, int widget, int click_count) { switch (widget) { case WID_EV_ZOOM_IN: DoZoomInOutWindow(ZOOM_IN, this); break; case WID_EV_ZOOM_OUT: DoZoomInOutWindow(ZOOM_OUT, this); break; case WID_EV_MAIN_TO_VIEW: { // location button (move main view to same spot as this view) 'Paste Location' Window *w = FindWindowById(WC_MAIN_WINDOW, 0); int x = this->viewport->scrollpos_x; // Where is the main looking at int y = this->viewport->scrollpos_y; /* set this view to same location. Based on the center, adjusting for zoom */ w->viewport->dest_scrollpos_x = x - (w->viewport->virtual_width - this->viewport->virtual_width) / 2; w->viewport->dest_scrollpos_y = y - (w->viewport->virtual_height - this->viewport->virtual_height) / 2; w->viewport->follow_vehicle = INVALID_VEHICLE; break; } case WID_EV_VIEW_TO_MAIN: { // inverse location button (move this view to same spot as main view) 'Copy Location' const Window *w = FindWindowById(WC_MAIN_WINDOW, 0); int x = w->viewport->scrollpos_x; int y = w->viewport->scrollpos_y; this->viewport->dest_scrollpos_x = x + (w->viewport->virtual_width - this->viewport->virtual_width) / 2; this->viewport->dest_scrollpos_y = y + (w->viewport->virtual_height - this->viewport->virtual_height) / 2; break; } } }
void ResetViewportAfterLoadGame() { Window *w = FindWindowById(WC_MAIN_WINDOW, 0); w->viewport->scrollpos_x = _saved_scrollpos_x; w->viewport->scrollpos_y = _saved_scrollpos_y; w->viewport->dest_scrollpos_x = _saved_scrollpos_x; w->viewport->dest_scrollpos_y = _saved_scrollpos_y; ViewPort *vp = w->viewport; vp->zoom = (ZoomLevel)min(_saved_scrollpos_zoom, ZOOM_LVL_MAX); vp->virtual_width = ScaleByZoom(vp->width, vp->zoom); vp->virtual_height = ScaleByZoom(vp->height, vp->zoom); /* If zoom_max is ZOOM_LVL_MIN then the setting has not been loaded yet, therefore all levels are allowed. */ if (_settings_client.gui.zoom_max != ZOOM_LVL_MIN) { /* Ensure zoom level is allowed */ while (vp->zoom < _settings_client.gui.zoom_min) DoZoomInOutWindow(ZOOM_OUT, w); while (vp->zoom > _settings_client.gui.zoom_max) DoZoomInOutWindow(ZOOM_IN, w); } DoZoomInOutWindow(ZOOM_NONE, w); // update button status MarkWholeScreenDirty(); }
void ZoomInOrOutToCursorWindow(bool in, Window *w) { assert(w != NULL); if (_game_mode != GM_MENU) { ViewPort *vp = w->viewport; if ((in && vp->zoom <= _settings_client.gui.zoom_min) || (!in && vp->zoom >= _settings_client.gui.zoom_max)) return; Point pt = GetTileZoomCenterWindow(in, w); if (pt.x != -1) { ScrollWindowTo(pt.x, pt.y, -1, w, true); DoZoomInOutWindow(in ? ZOOM_IN : ZOOM_OUT, w); } } }
void ResetViewportAfterLoadGame() { Window *w = FindWindowById(WC_MAIN_WINDOW, 0); w->viewport->scrollpos_x = _saved_scrollpos_x; w->viewport->scrollpos_y = _saved_scrollpos_y; w->viewport->dest_scrollpos_x = _saved_scrollpos_x; w->viewport->dest_scrollpos_y = _saved_scrollpos_y; ViewPort *vp = w->viewport; vp->zoom = (ZoomLevel)min(_saved_scrollpos_zoom, ZOOM_LVL_MAX); vp->virtual_width = ScaleByZoom(vp->width, vp->zoom); vp->virtual_height = ScaleByZoom(vp->height, vp->zoom); DoZoomInOutWindow(ZOOM_NONE, w); // update button status MarkWholeScreenDirty(); }