summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2008-05-05 11:36:43 +0000
committerpeter1138 <peter1138@openttd.org>2008-05-05 11:36:43 +0000
commit78c0929b18e508f3f18728dc55e760470308d796 (patch)
tree2b03bcb1a0888d81488cf0ab912ed5a356863cee /src
parent7e70d9f09f8f8c29357372883a6788e7668e92c7 (diff)
downloadopenttd-78c0929b18e508f3f18728dc55e760470308d796.tar.xz
(svn r12953) -Feature: Open a new viewport when ctrl-clicking on a 'Location' button, a town/station/industry list, or some news items.
Diffstat (limited to 'src')
-rw-r--r--src/depot_gui.cpp8
-rw-r--r--src/gui.h2
-rw-r--r--src/industry_gui.cpp12
-rw-r--r--src/news_gui.cpp11
-rw-r--r--src/player_gui.cpp6
-rw-r--r--src/smallmap_gui.cpp29
-rw-r--r--src/station_gui.cpp13
-rw-r--r--src/subsidy_gui.cpp12
-rw-r--r--src/town_gui.cpp12
9 files changed, 80 insertions, 25 deletions
diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp
index 7a859b1bc..fcd4adebc 100644
--- a/src/depot_gui.cpp
+++ b/src/depot_gui.cpp
@@ -819,7 +819,13 @@ static void DepotWndProc(Window *w, WindowEvent *e)
}
break;
- case DEPOT_WIDGET_LOCATION: ScrollMainWindowToTile(w->window_number); break;
+ case DEPOT_WIDGET_LOCATION:
+ if (_ctrl_pressed) {
+ ShowExtraViewPortWindow(w->window_number);
+ } else {
+ ScrollMainWindowToTile(w->window_number);
+ }
+ break;
case DEPOT_WIDGET_STOP_ALL:
case DEPOT_WIDGET_START_ALL:
diff --git a/src/gui.h b/src/gui.h
index 591819c8c..afee0f3ac 100644
--- a/src/gui.h
+++ b/src/gui.h
@@ -92,7 +92,7 @@ void ShowEstimatedCostOrIncome(Money cost, int x, int y);
void ShowErrorMessage(StringID msg_1, StringID msg_2, int x, int y);
void ShowSmallMap();
-void ShowExtraViewPortWindow();
+void ShowExtraViewPortWindow(TileIndex tile = INVALID_TILE);
void SetVScrollCount(Window *w, int num);
void SetVScroll2Count(Window *w, int num);
void SetHScrollCount(Window *w, int num);
diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp
index 9df7ac4b5..29714963a 100644
--- a/src/industry_gui.cpp
+++ b/src/industry_gui.cpp
@@ -568,7 +568,11 @@ static void IndustryViewWndProc(Window *w, WindowEvent *e)
} break;
case IVW_GOTO:
i = GetIndustry(w->window_number);
- ScrollMainWindowToTile(i->xy + TileDiffXY(1, 1));
+ if (_ctrl_pressed) {
+ ShowExtraViewPortWindow(i->xy + TileDiffXY(1, 1));
+ } else {
+ ScrollMainWindowToTile(i->xy + TileDiffXY(1, 1));
+ }
} break;
}
@@ -853,7 +857,11 @@ static void IndustryDirectoryWndProc(Window *w, WindowEvent *e)
if (!IsInsideMM(y, 0, w->vscroll.cap)) return;
p = y + w->vscroll.pos;
if (p < _num_industry_sort) {
- ScrollMainWindowToTile(_industry_sort[p]->xy);
+ if (_ctrl_pressed) {
+ ShowExtraViewPortWindow(_industry_sort[p]->xy);
+ } else {
+ ScrollMainWindowToTile(_industry_sort[p]->xy);
+ }
}
} break;
}
diff --git a/src/news_gui.cpp b/src/news_gui.cpp
index f92c9ffc9..92f0ecf12 100644
--- a/src/news_gui.cpp
+++ b/src/news_gui.cpp
@@ -206,8 +206,15 @@ static void NewsWindowProc(Window *w, WindowEvent *e)
Vehicle *v = GetVehicle(ni->data_a);
ScrollMainWindowTo(v->x_pos, v->y_pos);
} else if (ni->flags & NF_TILE) {
- if (!ScrollMainWindowToTile(ni->data_a) && ni->data_b != 0) {
- ScrollMainWindowToTile(ni->data_b);
+ if (_ctrl_pressed) {
+ ShowExtraViewPortWindow(ni->data_a);
+ if (ni->data_b != 0) {
+ ShowExtraViewPortWindow(ni->data_b);
+ }
+ } else {
+ if (!ScrollMainWindowToTile(ni->data_a) && ni->data_b != 0) {
+ ScrollMainWindowToTile(ni->data_b);
+ }
}
}
break;
diff --git a/src/player_gui.cpp b/src/player_gui.cpp
index 53d2a2c5a..b6aed6bab 100644
--- a/src/player_gui.cpp
+++ b/src/player_gui.cpp
@@ -1270,7 +1270,11 @@ static void PlayerCompanyWndProc(Window *w, WindowEvent *e)
w->LowerWidget(PCW_WIDGET_BUILD_VIEW_HQ);
w->InvalidateWidget(PCW_WIDGET_BUILD_VIEW_HQ);
} else {
- ScrollMainWindowToTile(tile);
+ if (_ctrl_pressed) {
+ ShowExtraViewPortWindow(tile);
+ } else {
+ ScrollMainWindowToTile(tile);
+ }
}
break;
}
diff --git a/src/smallmap_gui.cpp b/src/smallmap_gui.cpp
index 1cba5798b..b4e70ac4c 100644
--- a/src/smallmap_gui.cpp
+++ b/src/smallmap_gui.cpp
@@ -1191,25 +1191,30 @@ static const WindowDesc _extra_view_port_desc = {
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);
-
- /* 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;
+ Point pt;
+
+ 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;
}
diff --git a/src/station_gui.cpp b/src/station_gui.cpp
index 64e993e30..c1345e5c1 100644
--- a/src/station_gui.cpp
+++ b/src/station_gui.cpp
@@ -422,7 +422,12 @@ static void PlayerStationsWndProc(Window *w, WindowEvent *e)
const Station *st = sl->sort_list[id_v];
/* do not check HasStationInUse - it is slow and may be invalid */
assert(st->owner == owner || (st->owner == OWNER_NONE && !st->IsBuoy()));
- ScrollMainWindowToTile(st->xy);
+
+ if (_ctrl_pressed) {
+ ShowExtraViewPortWindow(st->xy);
+ } else {
+ ScrollMainWindowToTile(st->xy);
+ }
break;
}
@@ -936,7 +941,11 @@ static void StationViewWndProc(Window *w, WindowEvent *e)
break;
case SVW_LOCATION:
- ScrollMainWindowToTile(GetStation(w->window_number)->xy);
+ if (_ctrl_pressed) {
+ ShowExtraViewPortWindow(GetStation(w->window_number)->xy);
+ } else {
+ ScrollMainWindowToTile(GetStation(w->window_number)->xy);
+ }
break;
case SVW_RATINGS:
diff --git a/src/subsidy_gui.cpp b/src/subsidy_gui.cpp
index 93b19530b..9d54fc563 100644
--- a/src/subsidy_gui.cpp
+++ b/src/subsidy_gui.cpp
@@ -15,6 +15,7 @@
#include "date_func.h"
#include "viewport_func.h"
#include "gfx_func.h"
+#include "gui.h"
#include "table/strings.h"
@@ -66,7 +67,9 @@ handle_click:
xy = GetIndustry(offs)->xy;
}
- if (!ScrollMainWindowToTile(xy)) {
+ if (_ctrl_pressed || !ScrollMainWindowToTile(xy)) {
+ if (_ctrl_pressed) ShowExtraViewPortWindow(xy);
+
/* otherwise determine to coordinate for subsidy and scroll to it */
offs = s->to;
if (s->age >= 12) {
@@ -76,7 +79,12 @@ handle_click:
} else {
xy = GetIndustry(offs)->xy;
}
- ScrollMainWindowToTile(xy);
+
+ if (_ctrl_pressed) {
+ ShowExtraViewPortWindow(xy);
+ } else {
+ ScrollMainWindowToTile(xy);
+ }
}
}
diff --git a/src/town_gui.cpp b/src/town_gui.cpp
index 64767290e..3937e9917 100644
--- a/src/town_gui.cpp
+++ b/src/town_gui.cpp
@@ -333,7 +333,11 @@ static void TownViewWndProc(Window *w, WindowEvent *e)
case WE_CLICK:
switch (e->we.click.widget) {
case TVW_CENTERVIEW: /* scroll to location */
- ScrollMainWindowToTile(t->xy);
+ if (_ctrl_pressed) {
+ ShowExtraViewPortWindow(t->xy);
+ } else {
+ ScrollMainWindowToTile(t->xy);
+ }
break;
case TVW_SHOWAUTORITY: /* town authority */
@@ -541,7 +545,11 @@ static void TownDirectoryWndProc(Window *w, WindowEvent *e)
t = _town_sort[id_v];
assert(t->xy);
- ScrollMainWindowToTile(t->xy);
+ if (_ctrl_pressed) {
+ ShowExtraViewPortWindow(t->xy);
+ } else {
+ ScrollMainWindowToTile(t->xy);
+ }
} break;
}
break;