--- a/src/smallmap_gui.cpp Mon May 05 12:35:38 2008 +0000
+++ b/src/smallmap_gui.cpp Wed May 07 21:09:51 2008 +0000
@@ -1,6 +1,6 @@
/* $Id$ */
-/** @file smallmap_gui.cpp */
+/** @file smallmap_gui.cpp GUI that shows a small map of the world with metadata like owner or height. */
#include "stdafx.h"
#include "openttd.h"
@@ -27,6 +27,7 @@
#include "vehicle_base.h"
#include "sound_func.h"
#include "settings_type.h"
+#include "window_func.h"
#include "table/strings.h"
#include "table/sprites.h"
@@ -785,7 +786,7 @@
y = ((vp->virtual_height - (w->widget[SM_WIDGET_MAP].bottom - w->widget[SM_WIDGET_MAP].top ) * TILE_SIZE) / 2 + vp->virtual_top ) / 2 - TILE_SIZE * 2;
WP(w, smallmap_d).scroll_x = (y - x) & ~0xF;
WP(w, smallmap_d).scroll_y = (x + y) & ~0xF;
- SetWindowDirty(w);
+ w->SetDirty();
}
enum {
@@ -879,7 +880,7 @@
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);
- SetWindowDirty(w);
+ w->SetDirty();
} break;
case SM_WIDGET_CONTOUR: // Show land contours
@@ -892,14 +893,14 @@
_smallmap_type = e->we.click.widget - SM_WIDGET_CONTOUR;
w->LowerWidget(_smallmap_type + SM_WIDGET_CONTOUR);
- SetWindowDirty(w);
+ w->SetDirty();
SndPlayFx(SND_15_BEEP);
break;
case SM_WIDGET_CENTERMAP: // Center the smallmap again
SmallMapCenterOnCurrentPos(w);
- SetWindowDirty(w);
+ w->SetDirty();
SndPlayFx(SND_15_BEEP);
break;
@@ -907,7 +908,7 @@
w->ToggleWidgetLoweredState(SM_WIDGET_TOGGLETOWNNAME);
_smallmap_show_towns = w->IsWidgetLowered(SM_WIDGET_TOGGLETOWNNAME);
- SetWindowDirty(w);
+ w->SetDirty();
SndPlayFx(SND_15_BEEP);
break;
@@ -939,7 +940,7 @@
/* Raise the two buttons "all", as we have done a specific choice */
w->RaiseWidget(SM_WIDGET_ENABLEINDUSTRIES);
w->RaiseWidget(SM_WIDGET_DISABLEINDUSTRIES);
- SetWindowDirty(w);
+ w->SetDirty();
}
break;
@@ -950,7 +951,7 @@
/* toggle appeareance indicating the choice */
w->LowerWidget(SM_WIDGET_ENABLEINDUSTRIES);
w->RaiseWidget(SM_WIDGET_DISABLEINDUSTRIES);
- SetWindowDirty(w);
+ w->SetDirty();
break;
case SM_WIDGET_DISABLEINDUSTRIES: // disable all industries
@@ -960,7 +961,7 @@
/* toggle appeareance indicating the choice */
w->RaiseWidget(SM_WIDGET_ENABLEINDUSTRIES);
w->LowerWidget(SM_WIDGET_DISABLEINDUSTRIES);
- SetWindowDirty(w);
+ w->SetDirty();
break;
}
break;
@@ -976,7 +977,7 @@
case WE_MOUSELOOP:
/* update the window every now and then */
- if ((++w->vscroll.pos & 0x1F) == 0) SetWindowDirty(w);
+ if ((++w->vscroll.pos & 0x1F) == 0) w->SetDirty();
break;
case WE_SCROLL: {
@@ -1037,7 +1038,7 @@
WP(w, smallmap_d).scroll_y = y;
WP(w, smallmap_d).subscroll = sub;
- SetWindowDirty(w);
+ w->SetDirty();
} break;
}
}
@@ -1191,25 +1192,30 @@
ExtraViewPortWndProc
};
-void ShowExtraViewPortWindow()
+void ShowExtraViewPortWindow(TileIndex tile)
{
- Window *w, *v;
int i = 0;
/* find next free window number for extra viewport */
while (FindWindowById(WC_EXTRA_VIEW_PORT, i) != NULL) i++;
- w = AllocateWindowDescFront(&_extra_view_port_desc, i);
+ Window *w = AllocateWindowDescFront(&_extra_view_port_desc, i);
if (w != NULL) {
- int x, y;
- /* the main window with the main view */
- v = FindWindowById(WC_MAIN_WINDOW, 0);
+ Point pt;
- /* center on same place as main window (zoom is maximum, no adjustment needed) */
- x = WP(v, vp_d).scrollpos_x;
- y = WP(v, vp_d).scrollpos_y;
- WP(w, vp_d).scrollpos_x = x + (v->viewport->virtual_width - (w->widget[4].right - w->widget[4].left) - 1) / 2;
- WP(w, vp_d).scrollpos_y = y + (v->viewport->virtual_height - (w->widget[4].bottom - w->widget[4].top) - 1) / 2;
+ if (tile == INVALID_TILE) {
+ /* the main window with the main view */
+ 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;
+ } 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;
}