annotate src/viewport_gui.cpp @ 20342:63dba929ba42 draft

(svn r25294) -Feature: Add another button to window title bars to resize the window to its default size.
author frosch <frosch@openttd.org>
date Sun, 26 May 2013 19:30:07 +0000
parents 491ddf49f744
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13313
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
1 /* $Id$ */
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
2
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
3 /*
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
4 * This file is part of OpenTTD.
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
8 */
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
9
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
10 /** @file viewport_gui.cpp Extra viewport window. */
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
11
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
12 #include "stdafx.h"
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
13 #include "landscape.h"
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
14 #include "window_gui.h"
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
15 #include "viewport_func.h"
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
16 #include "strings_func.h"
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
17 #include "zoom_func.h"
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
18 #include "window_func.h"
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
19
18680
e87c7c30e606 (svn r23528) -Codechange: move widget enums to widgets/NNN_type.h
truebrain <truebrain@openttd.org>
parents: 18477
diff changeset
20 #include "widgets/viewport_widget.h"
e87c7c30e606 (svn r23528) -Codechange: move widget enums to widgets/NNN_type.h
truebrain <truebrain@openttd.org>
parents: 18477
diff changeset
21
13313
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
22 #include "table/strings.h"
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
23 #include "table/sprites.h"
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
24
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
25 /* Extra ViewPort Window Stuff */
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
26 static const NWidgetPart _nested_extra_view_port_widgets[] = {
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
27 NWidget(NWID_HORIZONTAL),
13752
517d77f53919 (svn r18277) -Codechange: remove unneeded widget indices for close, resize and sticky boxes and for window captions
rubidium <rubidium@openttd.org>
parents: 13749
diff changeset
28 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
18684
55b1341827bd (svn r23532) -Codechange: unify widget naming of (extra) viewport
rubidium <rubidium@openttd.org>
parents: 18680
diff changeset
29 NWidget(WWT_CAPTION, COLOUR_GREY, WID_EV_CAPTION), SetDataTip(STR_EXTRA_VIEW_PORT_TITLE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
14045
68fabdc82f5b (svn r18588) -Feature [FS#2943]: Add shading and unshading of windows.
alberth <alberth@openttd.org>
parents: 13796
diff changeset
30 NWidget(WWT_SHADEBOX, COLOUR_GREY),
20342
63dba929ba42 (svn r25294) -Feature: Add another button to window title bars to resize the window to its default size.
frosch <frosch@openttd.org>
parents: 20338
diff changeset
31 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
13752
517d77f53919 (svn r18277) -Codechange: remove unneeded widget indices for close, resize and sticky boxes and for window captions
rubidium <rubidium@openttd.org>
parents: 13749
diff changeset
32 NWidget(WWT_STICKYBOX, COLOUR_GREY),
13313
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
33 EndContainer(),
13755
bf8a4ced15fe (svn r18280) -Codechange: remove widget indices that are not needed for custom drawing/handling input
rubidium <rubidium@openttd.org>
parents: 13752
diff changeset
34 NWidget(WWT_PANEL, COLOUR_GREY),
18684
55b1341827bd (svn r23532) -Codechange: unify widget naming of (extra) viewport
rubidium <rubidium@openttd.org>
parents: 18680
diff changeset
35 NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_EV_VIEWPORT), SetPadding(2, 2, 2, 2), SetResize(1, 1), SetFill(1, 1),
13313
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
36 EndContainer(),
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
37 NWidget(NWID_HORIZONTAL),
18684
55b1341827bd (svn r23532) -Codechange: unify widget naming of (extra) viewport
rubidium <rubidium@openttd.org>
parents: 18680
diff changeset
38 NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_EV_ZOOM_IN), SetDataTip(SPR_IMG_ZOOMIN, STR_TOOLBAR_TOOLTIP_ZOOM_THE_VIEW_IN),
55b1341827bd (svn r23532) -Codechange: unify widget naming of (extra) viewport
rubidium <rubidium@openttd.org>
parents: 18680
diff changeset
39 NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_EV_ZOOM_OUT), SetDataTip(SPR_IMG_ZOOMOUT, STR_TOOLBAR_TOOLTIP_ZOOM_THE_VIEW_OUT),
13313
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
40 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
18684
55b1341827bd (svn r23532) -Codechange: unify widget naming of (extra) viewport
rubidium <rubidium@openttd.org>
parents: 18680
diff changeset
41 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_EV_MAIN_TO_VIEW), SetFill(1, 1), SetResize(1, 0),
13313
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
42 SetDataTip(STR_EXTRA_VIEW_MOVE_MAIN_TO_VIEW, STR_EXTRA_VIEW_MOVE_MAIN_TO_VIEW_TT),
18684
55b1341827bd (svn r23532) -Codechange: unify widget naming of (extra) viewport
rubidium <rubidium@openttd.org>
parents: 18680
diff changeset
43 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_EV_VIEW_TO_MAIN), SetFill(1, 1), SetResize(1, 0),
13313
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
44 SetDataTip(STR_EXTRA_VIEW_MOVE_VIEW_TO_MAIN, STR_EXTRA_VIEW_MOVE_VIEW_TO_MAIN_TT),
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
45 EndContainer(),
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
46 EndContainer(),
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
47 NWidget(NWID_HORIZONTAL),
13755
bf8a4ced15fe (svn r18280) -Codechange: remove widget indices that are not needed for custom drawing/handling input
rubidium <rubidium@openttd.org>
parents: 13752
diff changeset
48 NWidget(WWT_PANEL, COLOUR_GREY), SetFill(1, 1), SetResize(1, 0), EndContainer(),
13752
517d77f53919 (svn r18277) -Codechange: remove unneeded widget indices for close, resize and sticky boxes and for window captions
rubidium <rubidium@openttd.org>
parents: 13749
diff changeset
49 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
13313
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
50 EndContainer(),
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
51 };
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
52
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
53 class ExtraViewportWindow : public Window {
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
54 public:
20335
cadf6aaa0573 (svn r25287) -Codechange: Keep a reference to the WindowDesc in the Window after construction.
frosch <frosch@openttd.org>
parents: 19767
diff changeset
55 ExtraViewportWindow(WindowDesc *desc, int window_number, TileIndex tile) : Window(desc)
13313
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
56 {
20335
cadf6aaa0573 (svn r25287) -Codechange: Keep a reference to the WindowDesc in the Window after construction.
frosch <frosch@openttd.org>
parents: 19767
diff changeset
57 this->InitNested(window_number);
13313
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
58
18684
55b1341827bd (svn r23532) -Codechange: unify widget naming of (extra) viewport
rubidium <rubidium@openttd.org>
parents: 18680
diff changeset
59 NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_EV_VIEWPORT);
18477
45def1e34fa6 (svn r23321) -Fix (r23316): Extra viewports and waypoint detail opened up at wrong zoom level.
peter1138 <peter1138@openttd.org>
parents: 17486
diff changeset
60 nvp->InitializeViewport(this, 0, ZOOM_LVL_VIEWPORT);
18684
55b1341827bd (svn r23532) -Codechange: unify widget naming of (extra) viewport
rubidium <rubidium@openttd.org>
parents: 18680
diff changeset
61 if (_settings_client.gui.zoom_min == ZOOM_LVL_VIEWPORT) this->DisableWidget(WID_EV_ZOOM_IN);
13313
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
62
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
63 Point pt;
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
64 if (tile == INVALID_TILE) {
16261
8dcd31422ab1 (svn r20962) -Fix [FS#4166](r20956): Determine tile under cursor before opening the new viewport. It might appear just below the cursor.
frosch <frosch@openttd.org>
parents: 16255
diff changeset
65 /* No tile? Use center of main viewport. */
13313
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
66 const Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
67
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
68 /* center on same place as main window (zoom is maximum, no adjustment needed) */
14182
a8403f2aa0d1 (svn r18730) -Fix [FS#3414]: new viewports didn't center on the correct position
yexo <yexo@openttd.org>
parents: 14045
diff changeset
69 pt.x = w->viewport->scrollpos_x + w->viewport->virtual_width / 2;
13313
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
70 pt.y = w->viewport->scrollpos_y + w->viewport->virtual_height / 2;
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
71 } else {
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
72 pt = RemapCoords(TileX(tile) * TILE_SIZE + TILE_SIZE / 2, TileY(tile) * TILE_SIZE + TILE_SIZE / 2, TileHeight(tile));
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
73 }
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
74
14182
a8403f2aa0d1 (svn r18730) -Fix [FS#3414]: new viewports didn't center on the correct position
yexo <yexo@openttd.org>
parents: 14045
diff changeset
75 this->viewport->scrollpos_x = pt.x - this->viewport->virtual_width / 2;
a8403f2aa0d1 (svn r18730) -Fix [FS#3414]: new viewports didn't center on the correct position
yexo <yexo@openttd.org>
parents: 14045
diff changeset
76 this->viewport->scrollpos_y = pt.y - this->viewport->virtual_height / 2;
13313
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
77 this->viewport->dest_scrollpos_x = this->viewport->scrollpos_x;
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
78 this->viewport->dest_scrollpos_y = this->viewport->scrollpos_y;
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
79 }
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
80
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
81 virtual void SetStringParameters(int widget) const
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
82 {
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
83 switch (widget) {
18684
55b1341827bd (svn r23532) -Codechange: unify widget naming of (extra) viewport
rubidium <rubidium@openttd.org>
parents: 18680
diff changeset
84 case WID_EV_CAPTION:
13313
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
85 /* set the number in the title bar */
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
86 SetDParam(0, this->window_number + 1);
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
87 break;
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
88 }
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
89 }
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
90
14409
1eaefde497fd (svn r18966) -Codechange: Remove Window::OnDoubleClick() in favour of a parameter for OnClick().
frosch <frosch@openttd.org>
parents: 14182
diff changeset
91 virtual void OnClick(Point pt, int widget, int click_count)
13313
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
92 {
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
93 switch (widget) {
18684
55b1341827bd (svn r23532) -Codechange: unify widget naming of (extra) viewport
rubidium <rubidium@openttd.org>
parents: 18680
diff changeset
94 case WID_EV_ZOOM_IN: DoZoomInOutWindow(ZOOM_IN, this); break;
55b1341827bd (svn r23532) -Codechange: unify widget naming of (extra) viewport
rubidium <rubidium@openttd.org>
parents: 18680
diff changeset
95 case WID_EV_ZOOM_OUT: DoZoomInOutWindow(ZOOM_OUT, this); break;
13313
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
96
18684
55b1341827bd (svn r23532) -Codechange: unify widget naming of (extra) viewport
rubidium <rubidium@openttd.org>
parents: 18680
diff changeset
97 case WID_EV_MAIN_TO_VIEW: { // location button (move main view to same spot as this view) 'Paste Location'
13313
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
98 Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
99 int x = this->viewport->scrollpos_x; // Where is the main looking at
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
100 int y = this->viewport->scrollpos_y;
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
101
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
102 /* set this view to same location. Based on the center, adjusting for zoom */
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
103 w->viewport->dest_scrollpos_x = x - (w->viewport->virtual_width - this->viewport->virtual_width) / 2;
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
104 w->viewport->dest_scrollpos_y = y - (w->viewport->virtual_height - this->viewport->virtual_height) / 2;
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
105 w->viewport->follow_vehicle = INVALID_VEHICLE;
15618
e4640748f223 (svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents: 14409
diff changeset
106 break;
e4640748f223 (svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents: 14409
diff changeset
107 }
13313
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
108
18684
55b1341827bd (svn r23532) -Codechange: unify widget naming of (extra) viewport
rubidium <rubidium@openttd.org>
parents: 18680
diff changeset
109 case WID_EV_VIEW_TO_MAIN: { // inverse location button (move this view to same spot as main view) 'Copy Location'
13313
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
110 const Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
111 int x = w->viewport->scrollpos_x;
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
112 int y = w->viewport->scrollpos_y;
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
113
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
114 this->viewport->dest_scrollpos_x = x + (w->viewport->virtual_width - this->viewport->virtual_width) / 2;
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
115 this->viewport->dest_scrollpos_y = y + (w->viewport->virtual_height - this->viewport->virtual_height) / 2;
15618
e4640748f223 (svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents: 14409
diff changeset
116 break;
e4640748f223 (svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents: 14409
diff changeset
117 }
13313
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
118 }
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
119 }
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
120
13344
04b02b2cfa2b (svn r17853) -Codechange: remove the 'delta' parameter from OnResize; it was used in ways that aren't always wanted, causing bugs and the like. Also with nested widgets most reasons for handling OnResize have gone.
rubidium <rubidium@openttd.org>
parents: 13313
diff changeset
121 virtual void OnResize()
13313
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
122 {
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
123 if (this->viewport != NULL) {
18684
55b1341827bd (svn r23532) -Codechange: unify widget naming of (extra) viewport
rubidium <rubidium@openttd.org>
parents: 18680
diff changeset
124 NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_EV_VIEWPORT);
13313
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
125 nvp->UpdateViewportCoordinates(this);
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
126 }
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
127 }
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
128
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
129 virtual void OnScroll(Point delta)
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
130 {
17101
0c415ae476a0 (svn r21838) -Change: allow LMB scrolling with the mouse outside of the extra viewport instead of canceling scrolling when going slightly over the edge
rubidium <rubidium@openttd.org>
parents: 16601
diff changeset
131 this->viewport->scrollpos_x += ScaleByZoom(delta.x, this->viewport->zoom);
0c415ae476a0 (svn r21838) -Change: allow LMB scrolling with the mouse outside of the extra viewport instead of canceling scrolling when going slightly over the edge
rubidium <rubidium@openttd.org>
parents: 16601
diff changeset
132 this->viewport->scrollpos_y += ScaleByZoom(delta.y, this->viewport->zoom);
13313
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
133 this->viewport->dest_scrollpos_x = this->viewport->scrollpos_x;
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
134 this->viewport->dest_scrollpos_y = this->viewport->scrollpos_y;
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
135 }
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
136
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
137 virtual void OnMouseWheel(int wheel)
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
138 {
17237
d8b501ee60b3 (svn r21977) -Codechange: Always cal Window::OnMouseWheel(), independent of viewport scroll/zoom settings.
frosch <frosch@openttd.org>
parents: 17152
diff changeset
139 if (_settings_client.gui.scrollwheel_scrolling == 0) {
d8b501ee60b3 (svn r21977) -Codechange: Always cal Window::OnMouseWheel(), independent of viewport scroll/zoom settings.
frosch <frosch@openttd.org>
parents: 17152
diff changeset
140 ZoomInOrOutToCursorWindow(wheel < 0, this);
d8b501ee60b3 (svn r21977) -Codechange: Always cal Window::OnMouseWheel(), independent of viewport scroll/zoom settings.
frosch <frosch@openttd.org>
parents: 17152
diff changeset
141 }
13313
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
142 }
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
143
17486
e7672bafbe1c (svn r22241) -Codechange: Add additional to-be-used parameter to OnInvalidateData().
frosch <frosch@openttd.org>
parents: 17237
diff changeset
144 /**
e7672bafbe1c (svn r22241) -Codechange: Add additional to-be-used parameter to OnInvalidateData().
frosch <frosch@openttd.org>
parents: 17237
diff changeset
145 * Some data on this window has become invalid.
e7672bafbe1c (svn r22241) -Codechange: Add additional to-be-used parameter to OnInvalidateData().
frosch <frosch@openttd.org>
parents: 17237
diff changeset
146 * @param data Information about the changed data.
e7672bafbe1c (svn r22241) -Codechange: Add additional to-be-used parameter to OnInvalidateData().
frosch <frosch@openttd.org>
parents: 17237
diff changeset
147 * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
e7672bafbe1c (svn r22241) -Codechange: Add additional to-be-used parameter to OnInvalidateData().
frosch <frosch@openttd.org>
parents: 17237
diff changeset
148 */
e7672bafbe1c (svn r22241) -Codechange: Add additional to-be-used parameter to OnInvalidateData().
frosch <frosch@openttd.org>
parents: 17237
diff changeset
149 virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
13313
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
150 {
17486
e7672bafbe1c (svn r22241) -Codechange: Add additional to-be-used parameter to OnInvalidateData().
frosch <frosch@openttd.org>
parents: 17237
diff changeset
151 if (!gui_scope) return;
13313
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
152 /* Only handle zoom message if intended for us (msg ZOOM_IN/ZOOM_OUT) */
18684
55b1341827bd (svn r23532) -Codechange: unify widget naming of (extra) viewport
rubidium <rubidium@openttd.org>
parents: 18680
diff changeset
153 HandleZoomMessage(this, this->viewport, WID_EV_ZOOM_IN, WID_EV_ZOOM_OUT);
13313
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
154 }
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
155 };
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
156
20335
cadf6aaa0573 (svn r25287) -Codechange: Keep a reference to the WindowDesc in the Window after construction.
frosch <frosch@openttd.org>
parents: 19767
diff changeset
157 static WindowDesc _extra_view_port_desc(
20338
491ddf49f744 (svn r25290) -Add: Assign string names to notable windows.
frosch <frosch@openttd.org>
parents: 20335
diff changeset
158 WDP_AUTO, "extra_viewport", 300, 268,
13313
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
159 WC_EXTRA_VIEW_PORT, WC_NONE,
19767
2a11204038e3 (svn r24700) -Cleanup: Remove WDF_UNCLICK_BUTTONS and make it the default.
frosch <frosch@openttd.org>
parents: 18684
diff changeset
160 0,
13564
bae287664b02 (svn r18086) -Codechange: remove 'widget' from WindowDesc
rubidium <rubidium@openttd.org>
parents: 13344
diff changeset
161 _nested_extra_view_port_widgets, lengthof(_nested_extra_view_port_widgets)
13313
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
162 );
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
163
16261
8dcd31422ab1 (svn r20962) -Fix [FS#4166](r20956): Determine tile under cursor before opening the new viewport. It might appear just below the cursor.
frosch <frosch@openttd.org>
parents: 16255
diff changeset
164 /**
8dcd31422ab1 (svn r20962) -Fix [FS#4166](r20956): Determine tile under cursor before opening the new viewport. It might appear just below the cursor.
frosch <frosch@openttd.org>
parents: 16255
diff changeset
165 * Show a new Extra Viewport window.
8dcd31422ab1 (svn r20962) -Fix [FS#4166](r20956): Determine tile under cursor before opening the new viewport. It might appear just below the cursor.
frosch <frosch@openttd.org>
parents: 16255
diff changeset
166 * @param tile Tile to center the view on. INVALID_TILE means to use the center of main viewport.
8dcd31422ab1 (svn r20962) -Fix [FS#4166](r20956): Determine tile under cursor before opening the new viewport. It might appear just below the cursor.
frosch <frosch@openttd.org>
parents: 16255
diff changeset
167 */
13313
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
168 void ShowExtraViewPortWindow(TileIndex tile)
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
169 {
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
170 int i = 0;
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
171
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
172 /* find next free window number for extra viewport */
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
173 while (FindWindowById(WC_EXTRA_VIEW_PORT, i) != NULL) i++;
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
174
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
175 new ExtraViewportWindow(&_extra_view_port_desc, i, tile);
c41b3f705c2e (svn r17822) -Codechange: move 'extra viewport' code from smallmap_gui.cpp to viewport_gui.cpp
smatz <smatz@openttd.org>
parents:
diff changeset
176 }
16261
8dcd31422ab1 (svn r20962) -Fix [FS#4166](r20956): Determine tile under cursor before opening the new viewport. It might appear just below the cursor.
frosch <frosch@openttd.org>
parents: 16255
diff changeset
177
8dcd31422ab1 (svn r20962) -Fix [FS#4166](r20956): Determine tile under cursor before opening the new viewport. It might appear just below the cursor.
frosch <frosch@openttd.org>
parents: 16255
diff changeset
178 /**
8dcd31422ab1 (svn r20962) -Fix [FS#4166](r20956): Determine tile under cursor before opening the new viewport. It might appear just below the cursor.
frosch <frosch@openttd.org>
parents: 16255
diff changeset
179 * Show a new Extra Viewport window.
8dcd31422ab1 (svn r20962) -Fix [FS#4166](r20956): Determine tile under cursor before opening the new viewport. It might appear just below the cursor.
frosch <frosch@openttd.org>
parents: 16255
diff changeset
180 * Center it on the tile under the cursor, if the cursor is inside a viewport.
8dcd31422ab1 (svn r20962) -Fix [FS#4166](r20956): Determine tile under cursor before opening the new viewport. It might appear just below the cursor.
frosch <frosch@openttd.org>
parents: 16255
diff changeset
181 * If that fails, center it on main viewport center.
8dcd31422ab1 (svn r20962) -Fix [FS#4166](r20956): Determine tile under cursor before opening the new viewport. It might appear just below the cursor.
frosch <frosch@openttd.org>
parents: 16255
diff changeset
182 */
8dcd31422ab1 (svn r20962) -Fix [FS#4166](r20956): Determine tile under cursor before opening the new viewport. It might appear just below the cursor.
frosch <frosch@openttd.org>
parents: 16255
diff changeset
183 void ShowExtraViewPortWindowForTileUnderCursor()
8dcd31422ab1 (svn r20962) -Fix [FS#4166](r20956): Determine tile under cursor before opening the new viewport. It might appear just below the cursor.
frosch <frosch@openttd.org>
parents: 16255
diff changeset
184 {
8dcd31422ab1 (svn r20962) -Fix [FS#4166](r20956): Determine tile under cursor before opening the new viewport. It might appear just below the cursor.
frosch <frosch@openttd.org>
parents: 16255
diff changeset
185 /* Use tile under mouse as center for new viewport.
8dcd31422ab1 (svn r20962) -Fix [FS#4166](r20956): Determine tile under cursor before opening the new viewport. It might appear just below the cursor.
frosch <frosch@openttd.org>
parents: 16255
diff changeset
186 * Do this before creating the window, it might appear just below the mouse. */
8dcd31422ab1 (svn r20962) -Fix [FS#4166](r20956): Determine tile under cursor before opening the new viewport. It might appear just below the cursor.
frosch <frosch@openttd.org>
parents: 16255
diff changeset
187 Point pt = GetTileBelowCursor();
8dcd31422ab1 (svn r20962) -Fix [FS#4166](r20956): Determine tile under cursor before opening the new viewport. It might appear just below the cursor.
frosch <frosch@openttd.org>
parents: 16255
diff changeset
188 ShowExtraViewPortWindow(pt.x != -1 ? TileVirtXY(pt.x, pt.y) : INVALID_TILE);
8dcd31422ab1 (svn r20962) -Fix [FS#4166](r20956): Determine tile under cursor before opening the new viewport. It might appear just below the cursor.
frosch <frosch@openttd.org>
parents: 16255
diff changeset
189 }