--- a/src/viewport.cpp Mon Dec 03 23:39:38 2007 +0000
+++ b/src/viewport.cpp Tue Jan 22 21:00:30 2008 +0000
@@ -5,19 +5,12 @@
#include "stdafx.h"
#include "openttd.h"
#include "debug.h"
-#include "functions.h"
+#include "tile_cmd.h"
#include "gui.h"
#include "spritecache.h"
-#include "strings.h"
-#include "table/sprites.h"
-#include "table/strings.h"
#include "landscape.h"
-#include "map.h"
-#include "viewport.h"
-#include "window.h"
-#include "vehicle.h"
+#include "viewport_func.h"
#include "station.h"
-#include "gfx.h"
#include "town.h"
#include "signs.h"
#include "waypoint.h"
@@ -28,13 +21,37 @@
#include "blitter/factory.hpp"
#include "newgrf_fsmports.h"
#include "transparency.h"
+#include "strings_func.h"
+#include "zoom_func.h"
+#include "vehicle_func.h"
+#include "player_func.h"
+#include "settings_type.h"
+
+#include "table/sprites.h"
+#include "table/strings.h"
#define VIEWPORT_DRAW_MEM (65536 * 2)
+PlaceProc *_place_proc;
+Point _tile_fract_coords;
ZoomLevel _saved_scrollpos_zoom;
-/* XXX - maximum viewports is maximum windows - 2 (main toolbar + status bar) */
-static ViewPort _viewports[25 - 2];
+/**
+ * The maximum number of viewports depends on the maximum number
+ * of windows. Technically is could be the maximum number of
+ * windows, but there is always at least one window that does
+ * not need a viewport. Not having 'support' for that viewport
+ * saves some time and memory.
+ * For the introduction GUI and create game GUIs there is no
+ * need for more than one viewport, however in the normal game
+ * and scenario editor one can make a lot of viewports. For the
+ * normal game one always has a main toolbar and a status bar,
+ * however the statusbar does not exist on the scenario editor.
+ *
+ * This means that we can only safely assume that there is one
+ * window without viewport.
+ */
+static ViewPort _viewports[MAX_NUMBER_OF_WINDOWS - 1];
static uint32 _active_viewports; ///< bitmasked variable where each bit signifies if a viewport is in use or not
assert_compile(lengthof(_viewports) < sizeof(_active_viewports) * 8);
@@ -444,10 +461,10 @@
void HandleZoomMessage(Window *w, const ViewPort *vp, byte widget_zoom_in, byte widget_zoom_out)
{
w->SetWidgetDisabledState(widget_zoom_in, vp->zoom == ZOOM_LVL_MIN);
- InvalidateWidget(w, widget_zoom_in);
+ w->InvalidateWidget(widget_zoom_in);
w->SetWidgetDisabledState(widget_zoom_out, vp->zoom == ZOOM_LVL_MAX);
- InvalidateWidget(w, widget_zoom_out);
+ w->InvalidateWidget(widget_zoom_out);
}
/**
@@ -854,23 +871,22 @@
px -= _thd.selstart.x;
py -= _thd.selstart.y;
- switch (_thd.drawstyle) {
- case HT_LINE | HT_DIR_X: return py == 0; // x direction
- case HT_LINE | HT_DIR_Y: return px == 0; // y direction
- case HT_LINE | HT_DIR_HU: return px == -py || px == -py - 16; // horizontal upper
- case HT_LINE | HT_DIR_HL: return px == -py || px == -py + 16; // horizontal lower
- case HT_LINE | HT_DIR_VL: return px == py || px == py + 16; // vertival left
- case HT_LINE | HT_DIR_VR: return px == py || px == py - 16; // vertical right
- default:
- NOT_REACHED();
+ if ((_thd.drawstyle & ~HT_DIR_MASK) != HT_LINE) return false;
+
+ switch (_thd.drawstyle & HT_DIR_MASK) {
+ case HT_DIR_X: return py == 0; // x direction
+ case HT_DIR_Y: return px == 0; // y direction
+ case HT_DIR_HU: return px == -py || px == -py - 16; // horizontal upper
+ case HT_DIR_HL: return px == -py || px == -py + 16; // horizontal lower
+ case HT_DIR_VL: return px == py || px == py + 16; // vertival left
+ case HT_DIR_VR: return px == py || px == py - 16; // vertical right
+ default:
+ NOT_REACHED();
}
-
- /* useless, but avoids compiler warning this way */
- return 0;
}
// [direction][side]
-static const int _AutorailType[6][2] = {
+static const HighLightStyle _autorail_type[6][2] = {
{ HT_DIR_X, HT_DIR_X },
{ HT_DIR_Y, HT_DIR_Y },
{ HT_DIR_HU, HT_DIR_HL },
@@ -982,7 +998,7 @@
/* autorail highlight piece under cursor */
uint type = _thd.drawstyle & 0xF;
assert(type <= 5);
- DrawAutorailSelection(ti, _AutorailType[type][0]);
+ DrawAutorailSelection(ti, _autorail_type[type][0]);
} else if (IsPartOfAutoLine(ti->x, ti->y)) {
/* autorail highlighting long line */
int dir = _thd.drawstyle & ~0xF0;
@@ -995,7 +1011,7 @@
side = Delta(Delta(TileX(start), TileX(ti->tile)), Delta(TileY(start), TileY(ti->tile)));
}
- DrawAutorailSelection(ti, _AutorailType[dir][side]);
+ DrawAutorailSelection(ti, _autorail_type[dir][side]);
}
return;
}
@@ -1691,7 +1707,7 @@
const ViewPort *vp = w->viewport;
if (WP(w, vp_d).follow_vehicle != INVALID_VEHICLE) {
- const Vehicle* veh = GetVehicle(WP(w,vp_d).follow_vehicle);
+ const Vehicle* veh = GetVehicle(WP(w, vp_d).follow_vehicle);
Point pt = MapXYZToViewport(vp, veh->x_pos, veh->y_pos, veh->z_pos);
SetViewportPosition(w, pt.x, pt.y);
@@ -2242,9 +2258,9 @@
}
/** returns the best autorail highlight type from map coordinates */
-static byte GetAutorailHT(int x, int y)
+static HighLightStyle GetAutorailHT(int x, int y)
{
- return HT_RAIL | _AutorailPiece[x & 0xF][y & 0xF];
+ return HT_RAIL | _autorail_piece[x & 0xF][y & 0xF];
}
/**
@@ -2389,7 +2405,7 @@
/** returns information about the 2x1 piece to be build.
* The lower bits (0-3) are the track type. */
-static byte Check2x1AutoRail(int mode)
+static HighLightStyle Check2x1AutoRail(int mode)
{
int fxpy = _tile_fract_coords.x + _tile_fract_coords.y;
int sxpy = (_thd.selend.x & 0xF) + (_thd.selend.y & 0xF);
@@ -2397,28 +2413,27 @@
int sxmy = (_thd.selend.x & 0xF) - (_thd.selend.y & 0xF);
switch (mode) {
- case 0: // end piece is lower right
- if (fxpy >= 20 && sxpy <= 12) { /*SwapSelection(); DoRailroadTrack(0); */return 3; }
- if (fxmy < -3 && sxmy > 3) {/* DoRailroadTrack(0); */return 5; }
- return 1;
-
- case 1:
- if (fxmy > 3 && sxmy < -3) { /*SwapSelection(); DoRailroadTrack(0); */return 4; }
- if (fxpy <= 12 && sxpy >= 20) { /*DoRailroadTrack(0); */return 2; }
- return 1;
-
- case 2:
- if (fxmy > 3 && sxmy < -3) { /*DoRailroadTrack(3);*/ return 4; }
- if (fxpy >= 20 && sxpy <= 12) { /*SwapSelection(); DoRailroadTrack(0); */return 3; }
- return 0;
-
- case 3:
- if (fxmy < -3 && sxmy > 3) { /*SwapSelection(); DoRailroadTrack(3);*/ return 5; }
- if (fxpy <= 12 && sxpy >= 20) { /*DoRailroadTrack(0); */return 2; }
- return 0;
+ default: NOT_REACHED();
+ case 0: // end piece is lower right
+ if (fxpy >= 20 && sxpy <= 12) { /*SwapSelection(); DoRailroadTrack(0); */return HT_DIR_HL; }
+ if (fxmy < -3 && sxmy > 3) {/* DoRailroadTrack(0); */return HT_DIR_VR; }
+ return HT_DIR_Y;
+
+ case 1:
+ if (fxmy > 3 && sxmy < -3) { /*SwapSelection(); DoRailroadTrack(0); */return HT_DIR_VL; }
+ if (fxpy <= 12 && sxpy >= 20) { /*DoRailroadTrack(0); */return HT_DIR_HU; }
+ return HT_DIR_Y;
+
+ case 2:
+ if (fxmy > 3 && sxmy < -3) { /*DoRailroadTrack(3);*/ return HT_DIR_VL; }
+ if (fxpy >= 20 && sxpy <= 12) { /*SwapSelection(); DoRailroadTrack(0); */return HT_DIR_HL; }
+ return HT_DIR_X;
+
+ case 3:
+ if (fxmy < -3 && sxmy > 3) { /*SwapSelection(); DoRailroadTrack(3);*/ return HT_DIR_VR; }
+ if (fxpy <= 12 && sxpy >= 20) { /*DoRailroadTrack(0); */return HT_DIR_HU; }
+ return HT_DIR_X;
}
-
- return 0; // avoids compiler warnings
}
/** Check if the direction of start and end tile should be swapped based on
@@ -2762,7 +2777,7 @@
/* If dragging an area (eg dynamite tool) and it is actually a single
* row/column, change the type to 'line' to get proper calculation for height */
- style = _thd.next_drawstyle;
+ style = (HighLightStyle)_thd.next_drawstyle;
if (style & HT_RECT) {
if (dx == 1) {
style = HT_LINE | HT_DIR_Y;