Mercurial > hg > openttd
changeset 9184:a7020e34c67b draft
(svn r13047) -Codechange: remove vp_d
author | glx <glx@openttd.org> |
---|---|
date | Sun, 11 May 2008 15:08:44 +0000 |
parents | 5b8c9fe2e0f4 |
children | 227f376591eb |
files | src/industry_gui.cpp src/main_gui.cpp src/news_gui.cpp src/openttd.cpp src/smallmap_gui.cpp src/vehicle.cpp src/vehicle_gui.cpp src/viewport.cpp src/window.cpp src/window_gui.h |
diffstat | 10 files changed, 98 insertions(+), 99 deletions(-) [+] |
line wrap: on
line diff
--- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -433,7 +433,7 @@ }; /** Information to store about the industry window */ -struct indview_d : public vp_d { +struct indview_d { byte editbox_line; ///< The line clicked to open the edit box byte clicked_line; ///< The line of the button that has been clicked byte clicked_button; ///< The button that has been clicked (to raise) @@ -601,8 +601,8 @@ w->viewport->height += e->we.sizing.diff.y; w->viewport->virtual_width += e->we.sizing.diff.x; w->viewport->virtual_height += e->we.sizing.diff.y; - WP(w, vp_d).dest_scrollpos_x -= e->we.sizing.diff.x; - WP(w, vp_d).dest_scrollpos_y -= e->we.sizing.diff.y; + w->viewport->dest_scrollpos_x -= e->we.sizing.diff.x; + w->viewport->dest_scrollpos_y -= e->we.sizing.diff.y; UpdateViewportPosition(w); break;
--- a/src/main_gui.cpp +++ b/src/main_gui.cpp @@ -166,27 +166,27 @@ vp->virtual_width >>= 1; vp->virtual_height >>= 1; - WP(w, vp_d).scrollpos_x += vp->virtual_width >> 1; - WP(w, vp_d).scrollpos_y += vp->virtual_height >> 1; - WP(w, vp_d).dest_scrollpos_x = WP(w,vp_d).scrollpos_x; - WP(w, vp_d).dest_scrollpos_y = WP(w,vp_d).scrollpos_y; + w->viewport->scrollpos_x += vp->virtual_width >> 1; + w->viewport->scrollpos_y += vp->virtual_height >> 1; + w->viewport->dest_scrollpos_x = w->viewport->scrollpos_x; + w->viewport->dest_scrollpos_y = w->viewport->scrollpos_y; break; case ZOOM_OUT: if (vp->zoom == ZOOM_LVL_MAX) return false; vp->zoom = (ZoomLevel)((int)vp->zoom + 1); - WP(w, vp_d).scrollpos_x -= vp->virtual_width >> 1; - WP(w, vp_d).scrollpos_y -= vp->virtual_height >> 1; - WP(w, vp_d).dest_scrollpos_x = WP(w,vp_d).scrollpos_x; - WP(w, vp_d).dest_scrollpos_y = WP(w,vp_d).scrollpos_y; + w->viewport->scrollpos_x -= vp->virtual_width >> 1; + w->viewport->scrollpos_y -= vp->virtual_height >> 1; + w->viewport->dest_scrollpos_x = w->viewport->scrollpos_x; + w->viewport->dest_scrollpos_y = w->viewport->scrollpos_y; vp->virtual_width <<= 1; vp->virtual_height <<= 1; break; } if (vp != NULL) { // the vp can be null when how == ZOOM_NONE - vp->virtual_left = WP(w, vp_d).scrollpos_x; - vp->virtual_top = WP(w, vp_d).scrollpos_y; + vp->virtual_left = w->viewport->scrollpos_x; + vp->virtual_top = w->viewport->scrollpos_y; } w->SetDirty(); /* Update the windows that have zoom-buttons to perhaps disable their buttons */ @@ -380,10 +380,10 @@ _scrolling_viewport = false; } - WP(w, vp_d).scrollpos_x += ScaleByZoom(e->we.scroll.delta.x, vp->zoom); - WP(w, vp_d).scrollpos_y += ScaleByZoom(e->we.scroll.delta.y, vp->zoom); - WP(w, vp_d).dest_scrollpos_x = WP(w, vp_d).scrollpos_x; - WP(w, vp_d).dest_scrollpos_y = WP(w, vp_d).scrollpos_y; + w->viewport->scrollpos_x += ScaleByZoom(e->we.scroll.delta.x, vp->zoom); + w->viewport->scrollpos_y += ScaleByZoom(e->we.scroll.delta.y, vp->zoom); + w->viewport->dest_scrollpos_x = w->viewport->scrollpos_x; + w->viewport->dest_scrollpos_y = w->viewport->scrollpos_y; } break; case WE_MOUSEWHEEL:
--- a/src/news_gui.cpp +++ b/src/news_gui.cpp @@ -60,7 +60,7 @@ static NewsID _oldest_news = 0; ///< points to first item in fifo queue static NewsID _latest_news = INVALID_NEWS; ///< points to last item in fifo queue -struct news_d : vp_d { +struct news_d { uint16 chat_height; NewsItem *ni; };
--- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -1092,8 +1092,8 @@ Window *w = FindWindowById(WC_MAIN_WINDOW, 0); assert(w); - WP(w, vp_d).dest_scrollpos_x += ScaleByZoom(x, w->viewport->zoom); - WP(w, vp_d).dest_scrollpos_y += ScaleByZoom(y, w->viewport->zoom); + w->viewport->dest_scrollpos_x += ScaleByZoom(x, w->viewport->zoom); + w->viewport->dest_scrollpos_y += ScaleByZoom(y, w->viewport->zoom); } } @@ -1203,8 +1203,8 @@ const Window *w = FindWindowById(WC_MAIN_WINDOW, 0); if (w != NULL) { - _saved_scrollpos_x = WP(w, const vp_d).scrollpos_x; - _saved_scrollpos_y = WP(w, const vp_d).scrollpos_y; + _saved_scrollpos_x = w->viewport->scrollpos_x; + _saved_scrollpos_y = w->viewport->scrollpos_y; _saved_scrollpos_zoom = w->viewport->zoom; } } @@ -1316,10 +1316,10 @@ Window *w = FindWindowById(WC_MAIN_WINDOW, 0); - WP(w, vp_d).scrollpos_x = _saved_scrollpos_x; - WP(w, vp_d).scrollpos_y = _saved_scrollpos_y; - WP(w, vp_d).dest_scrollpos_x = _saved_scrollpos_x; - WP(w, vp_d).dest_scrollpos_y = _saved_scrollpos_y; + 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 = min(_saved_scrollpos_zoom, ZOOM_LVL_MAX);
--- a/src/smallmap_gui.cpp +++ b/src/smallmap_gui.cpp @@ -884,8 +884,8 @@ _left_button_clicked = false; pt = RemapCoords(WP(w, smallmap_d).scroll_x, WP(w,smallmap_d).scroll_y, 0); - WP(w2, vp_d).dest_scrollpos_x = pt.x + ((_cursor.pos.x - w->left + 2) << 4) - (w2->viewport->virtual_width >> 1); - WP(w2, vp_d).dest_scrollpos_y = pt.y + ((_cursor.pos.y - w->top - 16) << 4) - (w2->viewport->virtual_height >> 1); + w2->viewport->dest_scrollpos_x = pt.x + ((_cursor.pos.x - w->left + 2) << 4) - (w2->viewport->virtual_width >> 1); + w2->viewport->dest_scrollpos_y = pt.y + ((_cursor.pos.y - w->top - 16) << 4) - (w2->viewport->virtual_height >> 1); w->SetDirty(); } break; @@ -1138,21 +1138,21 @@ case 7: { // location button (move main view to same spot as this view) 'Paste Location' Window *w2 = FindWindowById(WC_MAIN_WINDOW, 0); - int x = WP(w, vp_d).scrollpos_x; // Where is the main looking at - int y = WP(w, vp_d).scrollpos_y; + int x = w->viewport->scrollpos_x; // Where is the main looking at + int y = w->viewport->scrollpos_y; /* set this view to same location. Based on the center, adjusting for zoom */ - WP(w2, vp_d).dest_scrollpos_x = x - (w2->viewport->virtual_width - w->viewport->virtual_width) / 2; - WP(w2, vp_d).dest_scrollpos_y = y - (w2->viewport->virtual_height - w->viewport->virtual_height) / 2; + w2->viewport->dest_scrollpos_x = x - (w2->viewport->virtual_width - w->viewport->virtual_width) / 2; + w2->viewport->dest_scrollpos_y = y - (w2->viewport->virtual_height - w->viewport->virtual_height) / 2; } break; case 8: { // inverse location button (move this view to same spot as main view) 'Copy Location' const Window *w2 = FindWindowById(WC_MAIN_WINDOW, 0); - int x = WP(w2, const vp_d).scrollpos_x; - int y = WP(w2, const vp_d).scrollpos_y; + int x = w2->viewport->scrollpos_x; + int y = w2->viewport->scrollpos_y; - WP(w, vp_d).dest_scrollpos_x = x + (w2->viewport->virtual_width - w->viewport->virtual_width) / 2; - WP(w, vp_d).dest_scrollpos_y = y + (w2->viewport->virtual_height - w->viewport->virtual_height) / 2; + w->viewport->dest_scrollpos_x = x + (w2->viewport->virtual_width - w->viewport->virtual_width) / 2; + w->viewport->dest_scrollpos_y = y + (w2->viewport->virtual_height - w->viewport->virtual_height) / 2; } break; } break; @@ -1172,10 +1172,10 @@ _scrolling_viewport = false; } - WP(w, vp_d).scrollpos_x += ScaleByZoom(e->we.scroll.delta.x, vp->zoom); - WP(w, vp_d).scrollpos_y += ScaleByZoom(e->we.scroll.delta.y, vp->zoom); - WP(w, vp_d).dest_scrollpos_x = WP(w, vp_d).scrollpos_x; - WP(w, vp_d).dest_scrollpos_y = WP(w, vp_d).scrollpos_y; + w->viewport->scrollpos_x += ScaleByZoom(e->we.scroll.delta.x, vp->zoom); + w->viewport->scrollpos_y += ScaleByZoom(e->we.scroll.delta.y, vp->zoom); + w->viewport->dest_scrollpos_x = w->viewport->scrollpos_x; + w->viewport->dest_scrollpos_y = w->viewport->scrollpos_y; } break; case WE_MOUSEWHEEL: @@ -1213,15 +1213,15 @@ const Window *v = FindWindowById(WC_MAIN_WINDOW, 0); /* center on same place as main window (zoom is maximum, no adjustment needed) */ - pt.x = WP(v, vp_d).scrollpos_x + v->viewport->virtual_height / 2; - pt.y = WP(v, vp_d).scrollpos_y + v->viewport->virtual_height / 2; + pt.x = v->viewport->scrollpos_x + v->viewport->virtual_height / 2; + pt.y = v->viewport->scrollpos_y + v->viewport->virtual_height / 2; } else { pt = RemapCoords(TileX(tile) * TILE_SIZE + TILE_SIZE / 2, TileY(tile) * TILE_SIZE + TILE_SIZE / 2, TileHeight(tile)); } - WP(w, vp_d).scrollpos_x = pt.x - ((w->widget[4].right - w->widget[4].left) - 1) / 2; - WP(w, vp_d).scrollpos_y = pt.y - ((w->widget[4].bottom - w->widget[4].top) - 1) / 2; - WP(w, vp_d).dest_scrollpos_x = WP(w, vp_d).scrollpos_x; - WP(w, vp_d).dest_scrollpos_y = WP(w, vp_d).scrollpos_y; + w->viewport->scrollpos_x = pt.x - ((w->widget[4].right - w->widget[4].left) - 1) / 2; + w->viewport->scrollpos_y = pt.y - ((w->widget[4].bottom - w->widget[4].top) - 1) / 2; + w->viewport->dest_scrollpos_x = w->viewport->scrollpos_x; + w->viewport->dest_scrollpos_y = w->viewport->scrollpos_y; } }
--- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -591,9 +591,9 @@ } Window *w = FindWindowById(WC_MAIN_WINDOW, 0); - if (w != NULL && WP(w, vp_d).follow_vehicle == this->index) { + if (w != NULL && w->viewport->follow_vehicle == this->index) { ScrollMainWindowTo(this->x_pos, this->y_pos, true); // lock the main view on the vehicle's last position - WP(w, vp_d).follow_vehicle = INVALID_VEHICLE; + w->viewport->follow_vehicle = INVALID_VEHICLE; } }
--- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -738,7 +738,7 @@ if (w != NULL) { w->window_number = to_index; - WP(w, vp_d).follow_vehicle = to_index; + w->viewport->follow_vehicle = to_index; w->SetDirty(); w = FindWindowById(WC_VEHICLE_ORDERS, from_index); @@ -2091,7 +2091,7 @@ const Window *mainwindow = FindWindowById(WC_MAIN_WINDOW, 0); /* code to allow the main window to 'follow' the vehicle if the ctrl key is pressed */ if (_ctrl_pressed && mainwindow->viewport->zoom == ZOOM_LVL_NORMAL) { - WP(mainwindow, vp_d).follow_vehicle = v->index; + mainwindow->viewport->follow_vehicle = v->index; } else { ScrollMainWindowTo(v->x_pos, v->y_pos); }
--- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -156,7 +156,7 @@ void DeleteWindowViewport(Window *w) { - w->viewport->width = 0; + free(w->viewport); w->viewport = NULL; } @@ -177,7 +177,7 @@ { assert(w->viewport == NULL); - ViewPort *vp = &(WP(w, vp_d).vp_data); + ViewportData *vp = CallocT<ViewportData>(1); vp->left = x + w->left; vp->top = y + w->top; @@ -194,21 +194,21 @@ if (follow_flags & 0x80000000) { const Vehicle *veh; - WP(w, vp_d).follow_vehicle = (VehicleID)(follow_flags & 0xFFFF); - veh = GetVehicle(WP(w, vp_d).follow_vehicle); + vp->follow_vehicle = (VehicleID)(follow_flags & 0xFFFF); + veh = GetVehicle(vp->follow_vehicle); pt = MapXYZToViewport(vp, veh->x_pos, veh->y_pos, veh->z_pos); } else { uint x = TileX(follow_flags) * TILE_SIZE; uint y = TileY(follow_flags) * TILE_SIZE; - WP(w, vp_d).follow_vehicle = INVALID_VEHICLE; + vp->follow_vehicle = INVALID_VEHICLE; pt = MapXYZToViewport(vp, x, y, GetSlopeZ(x, y)); } - WP(w, vp_d).scrollpos_x = pt.x; - WP(w, vp_d).scrollpos_y = pt.y; - WP(w, vp_d).dest_scrollpos_x = pt.x; - WP(w, vp_d).dest_scrollpos_y = pt.y; + vp->scrollpos_x = pt.x; + vp->scrollpos_y = pt.y; + vp->dest_scrollpos_x = pt.x; + vp->dest_scrollpos_y = pt.y; w->viewport = vp; vp->virtual_left = 0;//pt.x; @@ -426,9 +426,7 @@ Point GetTileZoomCenterWindow(bool in, Window * w) { int x, y; - ViewPort * vp; - - vp = w->viewport; + ViewPort *vp = w->viewport; if (in) { x = ((_cursor.pos.x - vp->left) >> 1) + (vp->width >> 2); @@ -1581,33 +1579,33 @@ { const ViewPort *vp = w->viewport; - if (WP(w, vp_d).follow_vehicle != INVALID_VEHICLE) { - const Vehicle* veh = GetVehicle(WP(w, vp_d).follow_vehicle); + if (w->viewport->follow_vehicle != INVALID_VEHICLE) { + const Vehicle* veh = GetVehicle(w->viewport->follow_vehicle); Point pt = MapXYZToViewport(vp, veh->x_pos, veh->y_pos, veh->z_pos); SetViewportPosition(w, pt.x, pt.y); } else { /* Ensure the destination location is within the map */ - ClampViewportToMap(vp, WP(w, vp_d).dest_scrollpos_x, WP(w, vp_d).dest_scrollpos_y); - - int delta_x = WP(w, vp_d).dest_scrollpos_x - WP(w, vp_d).scrollpos_x; - int delta_y = WP(w, vp_d).dest_scrollpos_y - WP(w, vp_d).scrollpos_y; + ClampViewportToMap(vp, w->viewport->dest_scrollpos_x, w->viewport->dest_scrollpos_y); + + int delta_x = w->viewport->dest_scrollpos_x - w->viewport->scrollpos_x; + int delta_y = w->viewport->dest_scrollpos_y - w->viewport->scrollpos_y; if (delta_x != 0 || delta_y != 0) { if (_patches.smooth_scroll) { int max_scroll = ScaleByMapSize1D(512); /* Not at our desired positon yet... */ - WP(w, vp_d).scrollpos_x += Clamp(delta_x / 4, -max_scroll, max_scroll); - WP(w, vp_d).scrollpos_y += Clamp(delta_y / 4, -max_scroll, max_scroll); + w->viewport->scrollpos_x += Clamp(delta_x / 4, -max_scroll, max_scroll); + w->viewport->scrollpos_y += Clamp(delta_y / 4, -max_scroll, max_scroll); } else { - WP(w, vp_d).scrollpos_x = WP(w, vp_d).dest_scrollpos_x; - WP(w, vp_d).scrollpos_y = WP(w, vp_d).dest_scrollpos_y; + w->viewport->scrollpos_x = w->viewport->dest_scrollpos_x; + w->viewport->scrollpos_y = w->viewport->dest_scrollpos_y; } } - ClampViewportToMap(vp, WP(w, vp_d).scrollpos_x, WP(w, vp_d).scrollpos_y); - - SetViewportPosition(w, WP(w, vp_d).scrollpos_x, WP(w, vp_d).scrollpos_y); + ClampViewportToMap(vp, w->viewport->scrollpos_x, w->viewport->scrollpos_y); + + SetViewportPosition(w, w->viewport->scrollpos_x, w->viewport->scrollpos_y); } } @@ -2066,18 +2064,18 @@ { /* The slope cannot be acquired outside of the map, so make sure we are always within the map. */ Point pt = MapXYZToViewport(w->viewport, x, y, GetSlopeZ(Clamp(x, 0, MapSizeX()), Clamp(y, 0, MapSizeY()))); - WP(w, vp_d).follow_vehicle = INVALID_VEHICLE; - - if (WP(w, vp_d).dest_scrollpos_x == pt.x && WP(w, vp_d).dest_scrollpos_y == pt.y) + w->viewport->follow_vehicle = INVALID_VEHICLE; + + if (w->viewport->dest_scrollpos_x == pt.x && w->viewport->dest_scrollpos_y == pt.y) return false; if (instant) { - WP(w, vp_d).scrollpos_x = pt.x; - WP(w, vp_d).scrollpos_y = pt.y; + w->viewport->scrollpos_x = pt.x; + w->viewport->scrollpos_y = pt.y; } - WP(w, vp_d).dest_scrollpos_x = pt.x; - WP(w, vp_d).dest_scrollpos_y = pt.y; + w->viewport->dest_scrollpos_x = pt.x; + w->viewport->dest_scrollpos_y = pt.y; return true; }
--- a/src/window.cpp +++ b/src/window.cpp @@ -1713,9 +1713,9 @@ return true; } - if (WP(w, vp_d).follow_vehicle != INVALID_VEHICLE && w == FindWindowById(WC_MAIN_WINDOW, 0)) { + if (w == FindWindowById(WC_MAIN_WINDOW, 0) && w->viewport->follow_vehicle != INVALID_VEHICLE) { /* If the main window is following a vehicle, then first let go of it! */ - const Vehicle *veh = GetVehicle(WP(w, vp_d).follow_vehicle); + const Vehicle *veh = GetVehicle(w->viewport->follow_vehicle); ScrollMainWindowTo(veh->x_pos, veh->y_pos, true); /* This also resets follow_vehicle */ return true; } @@ -1915,14 +1915,14 @@ /* here allows scrolling in both x and y axis */ #define scrollspeed 3 if (x - 15 < 0) { - WP(w, vp_d).dest_scrollpos_x += ScaleByZoom((x - 15) * scrollspeed, vp->zoom); + w->viewport->dest_scrollpos_x += ScaleByZoom((x - 15) * scrollspeed, vp->zoom); } else if (15 - (vp->width - x) > 0) { - WP(w, vp_d).dest_scrollpos_x += ScaleByZoom((15 - (vp->width - x)) * scrollspeed, vp->zoom); + w->viewport->dest_scrollpos_x += ScaleByZoom((15 - (vp->width - x)) * scrollspeed, vp->zoom); } if (y - 15 < 0) { - WP(w, vp_d).dest_scrollpos_y += ScaleByZoom((y - 15) * scrollspeed, vp->zoom); + w->viewport->dest_scrollpos_y += ScaleByZoom((y - 15) * scrollspeed, vp->zoom); } else if (15 - (vp->height - y) > 0) { - WP(w, vp_d).dest_scrollpos_y += ScaleByZoom((15 - (vp->height - y)) * scrollspeed, vp->zoom); + w->viewport->dest_scrollpos_y += ScaleByZoom((15 - (vp->height - y)) * scrollspeed, vp->zoom); } #undef scrollspeed }
--- a/src/window_gui.h +++ b/src/window_gui.h @@ -271,6 +271,17 @@ }; /** + * Data structure for a window viewport + */ +struct ViewportData : ViewPort { + VehicleID follow_vehicle; + int32 scrollpos_x; + int32 scrollpos_y; + int32 dest_scrollpos_x; + int32 dest_scrollpos_y; +}; + + /** * Data structure for an opened window */ struct Window : ZeroedMemoryAllocator { @@ -306,7 +317,7 @@ byte caption_color; ///< Background color of the window caption, contains PlayerID - ViewPort *viewport; ///< Pointer to viewport, if present + ViewportData *viewport; ///< Pointer to viewport data, if present const Widget *original_widget; ///< Original widget layout, copied from WindowDesc Widget *widget; ///< Widgets of the window uint widget_count; ///< Number of widgets of the window @@ -540,16 +551,6 @@ }; assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(depot_d)); -struct vp_d { - VehicleID follow_vehicle; - int32 scrollpos_x; - int32 scrollpos_y; - int32 dest_scrollpos_x; - int32 dest_scrollpos_y; - ViewPort vp_data; ///< Screen position and zoom of the viewport -}; -assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(vp_d)); - enum SortListFlags { VL_NONE = 0, ///< no sort VL_DESC = 1 << 0, ///< sort descending or ascending