(svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
authordarkvater
Fri, 03 Sep 2004 19:59:05 +0000
changeset 152 c3964b43943e
parent 151 e90bf7f77216
child 153 3dbe2cfd7b3c
(svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
functions.h
gui.h
lang/english.txt
main_gui.c
smallmap_gui.c
ttd.c
ttd.h
viewport.c
viewport.h
window.c
--- a/functions.h	Fri Sep 03 18:23:03 2004 +0000
+++ b/functions.h	Fri Sep 03 19:59:05 2004 +0000
@@ -185,6 +185,10 @@
 void SetObjectToPlace(int icon, byte mode, byte window_class, uint16 window_num);
 
 void ResetObjectToPlace();
+
+bool ScrollWindowToTile(TileIndex tile, Window * w);
+bool ScrollWindowTo(int x, int y, Window * w);
+
 bool ScrollMainWindowToTile(TileIndex tile);
 bool ScrollMainWindowTo(int x, int y);
 void DrawSprite(uint32 img, int x, int y);
@@ -246,7 +250,6 @@
 
 // callback from drivers that is called if the game size changes dynamically
 void GameSizeChanged();
-void ZoomInOrOutToCursor(bool in);
 bool MakeScreenshot();
 bool MakeWorldScreenshot(int left, int top, int width, int height, int zoom);
 bool FileExists(const char *filename);
--- a/gui.h	Fri Sep 03 18:23:03 2004 +0000
+++ b/gui.h	Fri Sep 03 19:59:05 2004 +0000
@@ -79,6 +79,7 @@
 void CheckRedrawStationCoverage(Window *w);
 
 void ShowSmallMap();
+void ShowExtraViewPortWindow();
 void SetVScrollCount(Window *w, int num);
 void SetHScrollCount(Window *w, int num);
 
@@ -102,7 +103,7 @@
 	ZOOM_NONE = 2, // hack, used to update the button status
 };
 
-bool DoZoomInOut(int how);
+bool DoZoomInOutWindow(int how, Window * w);
 void ShowBuildIndustryWindow();
 void ShowQueryString(StringID str, StringID caption, int maxlen, int maxwidth, byte window_class, uint16 window_number);
 void ShowMusicWindow();
--- a/lang/english.txt	Fri Sep 03 18:23:03 2004 +0000
+++ b/lang/english.txt	Fri Sep 03 19:59:05 2004 +0000
@@ -749,6 +749,13 @@
 STR_02DC_DISPLAY_SUBSIDIES				:{BLACK}Display subsidies
 STR_02DD_SUBSIDIES						:Subsidies
 STR_02DE_MAP_OF_WORLD					:Map of world
+STR_EXTRA_VIEW_PORT						:Extra viewport
+STR_EXTRA_VIEW_PORT_TITLE				:{WHITE}Viewport {COMMA16}
+STR_EXTRA_VIEW_MOVE_VIEW_TO_MAIN		:{BLACK}Copy to viewport
+STR_EXTRA_VIEW_MOVE_VIEW_TO_MAIN_TT		:{BLACK}Copy the location of the global view to this viewport
+STR_EXTRA_VIEW_MOVE_MAIN_TO_VIEW		:{BLACK}Paste from viewport
+STR_EXTRA_VIEW_MOVE_MAIN_TO_VIEW_TT		:{BLACK}Paste the location of this viewport to the global view
+
 STR_02DF_TOWN_DIRECTORY					:Town directory
 STR_02E0_CURRENCY_UNITS					:{BLACK}Currency units
 STR_02E1								:{BLACK}{SKIP}{STRING}
--- a/main_gui.c	Fri Sep 03 18:23:03 2004 +0000
+++ b/main_gui.c	Fri Sep 03 19:59:05 2004 +0000
@@ -152,6 +152,7 @@
 {
 	switch(index) {
 	case 0: ShowSmallMap(); break;
+	case 1: ShowExtraViewPortWindow(); break;
 	}
 }
 
@@ -617,7 +618,7 @@
 
 static void ToolbarMapClick(Window *w)
 {
-	PopupMainToolbMenu(w, 96, 4, STR_02DE_MAP_OF_WORLD, 1);
+	PopupMainToolbMenu(w, 96, 4, STR_02DE_MAP_OF_WORLD, 2);
 }
 
 static void ToolbarTownClick(Window *w)
@@ -696,10 +697,11 @@
 	PopupMainPlayerToolbMenu(w, 376, 16, dis);
 }
 
-bool DoZoomInOut(int how)
+/* Zooms a viewport in a window in or out */
+/* No button handling or what so ever */
+bool DoZoomInOutWindow(int how, Window *w)
 {
 	ViewPort *vp;
-	Window *w, *wt;
 	int button;
 	
 	switch(_game_mode) {
@@ -708,13 +710,9 @@
 	default: return false;
 	}
 
-	w = FindWindowById(WC_MAIN_WINDOW, 0);
 	assert(w);
 	vp = w->viewport;
 
-	wt = FindWindowById(WC_MAIN_TOOLBAR, 0);
-	assert(wt);
-
 	if (how == ZOOM_IN) {
 		if (vp->zoom == 0) return false;
 		vp->zoom--;
@@ -738,24 +736,40 @@
 		SetWindowDirty(w);
 	}
 
-	// update the toolbar button too
-	CLRBIT(wt->disabled_state, button);
-	CLRBIT(wt->disabled_state, button + 1);
-	if (vp->zoom == 0) SETBIT(wt->disabled_state, button);
-	else if (vp->zoom == 2) SETBIT(wt->disabled_state, button + 1);
-	SetWindowDirty(wt);
+	// routine to disable/enable the zoom buttons. Didn't know where to place these otherwise
+	{
+		Window * wt;
+		switch (w->window_class) {
+		case WC_MAIN_WINDOW:
+			wt = FindWindowById(WC_MAIN_TOOLBAR, 0);
+			break;
+		case WC_EXTRA_VIEW_PORT:
+			wt = FindWindowById(WC_EXTRA_VIEW_PORT, w->window_number);
+			button = 4;
+			break;
+		}
 
+		assert(wt);
+
+		// update the toolbar button too
+		CLRBIT(wt->disabled_state, button);
+		CLRBIT(wt->disabled_state, button + 1);
+		if (vp->zoom == 0) SETBIT(wt->disabled_state, button);
+		else if (vp->zoom == 2) SETBIT(wt->disabled_state, button + 1);
+		SetWindowDirty(wt);
+	}
+	
 	return true;
 }
 
 static void MaxZoomIn()
 {
-	while (DoZoomInOut(ZOOM_IN)) {}
+	while (DoZoomInOutWindow(ZOOM_IN, FindWindowById(WC_MAIN_WINDOW, 0) ) ) {}
 }
 
 static void ToolbarZoomInClick(Window *w)
 {
-	if (DoZoomInOut(ZOOM_IN)) {
+	if (DoZoomInOutWindow(ZOOM_IN, FindWindowById(WC_MAIN_WINDOW, 0))) {
 		HandleButtonClick(w, 17);
 		SndPlayFx(0x13);
 	}
@@ -763,7 +777,7 @@
 
 static void ToolbarZoomOutClick(Window *w)
 {
-	if (DoZoomInOut(ZOOM_OUT)) {
+	if (DoZoomInOutWindow(ZOOM_OUT,FindWindowById(WC_MAIN_WINDOW, 0))) {
 		HandleButtonClick(w, 18);
 		SndPlayFx(0x13);
 	}
@@ -870,7 +884,7 @@
 
 static void ToolbarScenZoomIn(Window *w)
 {
-	if (DoZoomInOut(ZOOM_IN)) {
+	if (DoZoomInOutWindow(ZOOM_IN, FindWindowById(WC_MAIN_WINDOW, 0))) {
 		HandleButtonClick(w, 9);
 		SndPlayFx(0x13);
 	}
@@ -878,19 +892,17 @@
 
 static void ToolbarScenZoomOut(Window *w)
 {
-	if (DoZoomInOut(ZOOM_OUT)) {
+	if (DoZoomInOutWindow(ZOOM_OUT, FindWindowById(WC_MAIN_WINDOW, 0))) {
 		HandleButtonClick(w, 10);
 		SndPlayFx(0x13);
 	}
 }
 
-void ZoomInOrOutToCursor(bool in)
+void ZoomInOrOutToCursorWindow(bool in, Window *w) 
 {
+	ViewPort * vp;
 	Point pt;
-	Window* w;
-	ViewPort* vp;
 
-	w = FindWindowById(WC_MAIN_WINDOW, 0);
 	assert(w != 0);
 
 	vp = w->viewport;
@@ -899,11 +911,11 @@
 		if ((in && vp->zoom == 0) || (!in && vp->zoom == 2))
 			return;
 
-		pt = GetTileZoomCenter(in);
+		pt = GetTileZoomCenterWindow(in,w);
 		if (pt.x != -1) {
-			ScrollMainWindowTo(pt.x, pt.y);
+			ScrollWindowTo(pt.x, pt.y, w);
 
-			DoZoomInOut(in ? ZOOM_IN : ZOOM_OUT);
+			DoZoomInOutWindow(in ? ZOOM_IN : ZOOM_OUT, w);
 		}
 	}
 }
--- a/smallmap_gui.c	Fri Sep 03 18:23:03 2004 +0000
+++ b/smallmap_gui.c	Fri Sep 03 19:59:05 2004 +0000
@@ -1,6 +1,6 @@
 #include "stdafx.h"
 #include "ttd.h"
-
+#include "gui.h"
 #include "window.h"
 #include "gfx.h"
 #include "viewport.h"
@@ -996,3 +996,97 @@
 {
 	DoShowSmallMap(_smallmap_size);
 }
+
+/* Extra ViewPort Window Stuff */
+static Widget _extra_view_port_widgets[] = {
+{   WWT_CLOSEBOX,    14,     0,    10,     0,    13, STR_00C5, STR_018B_CLOSE_WINDOW},
+{    WWT_CAPTION,    14,    11,   299,     0,    13, STR_EXTRA_VIEW_PORT_TITLE, STR_018C_WINDOW_TITLE_DRAG_THIS},
+{      WWT_PANEL,    14,     0,   299,    14,   233, 0x0, 0},
+{          WWT_6,    14,     2,   297,    16,   231, 0, 0},
+{      WWT_PANEL,    14,     0,    21,   234,   255, 0x2DF, STR_017F_ZOOM_THE_VIEW_IN},
+{      WWT_PANEL,    14,    22,    43,   234,   255, 0x2E0, STR_0180_ZOOM_THE_VIEW_OUT},
+{ WWT_PUSHTXTBTN,    14,    44,   171,   234,   255, STR_EXTRA_VIEW_MOVE_MAIN_TO_VIEW, STR_EXTRA_VIEW_MOVE_MAIN_TO_VIEW_TT},
+{ WWT_PUSHTXTBTN,    14,   172,   299,   234,   255, STR_EXTRA_VIEW_MOVE_VIEW_TO_MAIN, STR_EXTRA_VIEW_MOVE_VIEW_TO_MAIN_TT},
+{      WWT_LAST},
+};
+
+static void ExtraViewPortWndProc(Window *w, WindowEvent *e)
+{
+	ViewPort *vp = w->viewport;
+	int button = 4;
+
+	switch(e->event) {
+	case WE_PAINT: {
+		// set the number in the title bar
+		SET_DPARAM16(0, (w->window_number+1));
+
+		DrawWindowWidgets(w);
+		DrawWindowViewport(w);
+	}	break;
+	case WE_CLICK: {
+		switch(e->click.widget) {
+		case 4: { /* zoom in */
+			DoZoomInOutWindow(ZOOM_IN,w);
+		} break;
+
+		case 5: { /* zoom out */
+			DoZoomInOutWindow(ZOOM_OUT,w);
+		} break;
+
+		case 6: { /* location button (move main view to same spot as this view) */
+			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;
+
+			// set this view to same location. Based on the center, adjusting for zoom
+			WP(w2,vp_d).scrollpos_x =  x - (w2->viewport->virtual_width - (294 <<vp->zoom) )/2;
+			WP(w2,vp_d).scrollpos_y =  y - (w2->viewport->virtual_height - (214 << vp->zoom) )/2;			
+		} break;
+		case 7: { /* inverse location button (move this view to same spot as main view) */
+			Window * w2 = FindWindowById(WC_MAIN_WINDOW, 0);
+			int x = WP(w2,vp_d).scrollpos_x;
+			int y = WP(w2,vp_d).scrollpos_y;
+
+			WP(w,vp_d).scrollpos_x =  x + (w2->viewport->virtual_width - (294 <<vp->zoom) )/2;
+			WP(w,vp_d).scrollpos_y =  y + (w2->viewport->virtual_height - (214 << vp->zoom) )/2;			
+		} break;
+		}	
+	} break;
+	}
+}
+
+static const WindowDesc _extra_view_port_desc = {
+	-1,-1, 300, 256,
+	WC_EXTRA_VIEW_PORT,0,
+	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
+	_extra_view_port_widgets,
+	ExtraViewPortWndProc
+};
+
+void ShowExtraViewPortWindow()
+{
+	Window *w, *v;
+	int i = 0;
+	
+	// find next free window number for extra viewport
+	while (FindWindowById(WC_EXTRA_VIEW_PORT,i) ) {
+		i++;
+	}
+
+	w = AllocateWindowDescFront(&_extra_view_port_desc,i);
+	if (w) {
+		int x,y;
+		// disable zoom in button
+		w->disabled_state = 1 << 4;
+		// the main window with the main view
+		v = FindWindowById(WC_MAIN_WINDOW, 0); 
+		// New viewport start ats (zero,zero) 
+		AssignWindowViewport(w, 3, 17, 294, 214, 0 , 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 - (294) )/2;
+		WP(w,vp_d).scrollpos_y =  y + (v->viewport->virtual_height - (214)  )/2;
+	}
+}
--- a/ttd.c	Fri Sep 03 18:23:03 2004 +0000
+++ b/ttd.c	Fri Sep 03 19:59:05 2004 +0000
@@ -1141,7 +1141,7 @@
 	if (!_players[0].is_active)
 		DoStartupNewPlayer(false);
 
-	DoZoomInOut(ZOOM_NONE); // update button status
+	DoZoomInOutWindow(ZOOM_NONE, w); // update button status
 	MarkWholeScreenDirty();
 
 	return true;
--- a/ttd.h	Fri Sep 03 18:23:03 2004 +0000
+++ b/ttd.h	Fri Sep 03 19:59:05 2004 +0000
@@ -393,8 +393,9 @@
 	WC_INDUSTRY_DIRECTORY = 0x43,
 	WC_MESSAGE_HISTORY = 0x44,
 	WC_CHEATS = 0x45,
-	WC_PERFORMANCE_DETAIL = 0x46,
+	WC_PERFORMANCE_DETAIL = 0x46,
 	WC_CONSOLE = 0x47,
+	WC_EXTRA_VIEW_PORT = 0x48,
 };
 
 
--- a/viewport.c	Fri Sep 03 18:23:03 2004 +0000
+++ b/viewport.c	Fri Sep 03 19:59:05 2004 +0000
@@ -312,19 +312,23 @@
 	return GetTileFromScreenXY(_cursor.pos.x, _cursor.pos.y);
 }
 
-Point GetTileZoomCenter(bool in)
+
+Point GetTileZoomCenterWindow(bool in, Window * w)
 {
 	int x, y;
-	
+	ViewPort * vp;
+
+	vp = w->viewport;
+
 	if (in)	{
-		x = (_cursor.pos.x >> 1) + (_screen.width >> 2);
-		y = (_cursor.pos.y >> 1) + (_screen.height >> 2);
+		x = ( (_cursor.pos.x - vp->left ) >> 1) + (vp->width >> 2);
+		y = ( (_cursor.pos.y - vp->top ) >> 1) + (vp->height >> 2);
 	}
 	else {
-		x = _screen.width - _cursor.pos.x;
-		y = _screen.height - _cursor.pos.y;
+		x = vp->width - (_cursor.pos.x - vp->left);
+		y = vp->height - (_cursor.pos.y - vp->top);
 	}
-	return GetTileFromScreenXY(x, y);
+	return GetTileFromScreenXY(x+vp->left, y+vp->top);
 }
 
 void DrawGroundSpriteAt(uint32 image, int16 x, int16 y, byte z)
@@ -1708,6 +1712,32 @@
 	}
 }
 
+
+/* scrolls the viewport in a window to a given location */
+bool ScrollWindowTo(int x , int y, Window * w)
+{
+	Point pt;
+
+	pt = MapXYZToViewport(w->viewport, x, y, GetSlopeZ(x, y));
+	WP(w,vp_d).follow_vehicle = -1;
+
+	if (WP(w,vp_d).scrollpos_x == pt.x &&
+			WP(w,vp_d).scrollpos_y == pt.y)
+				return false;
+
+	WP(w,vp_d).scrollpos_x = pt.x;
+	WP(w,vp_d).scrollpos_y = pt.y;
+	return true;
+}
+
+/* scrolls the viewport in a window to a given tile */
+bool ScrollWindowToTile(TileIndex tile, Window * w)
+{
+	return ScrollWindowTo(GET_TILE_X(tile)*16+8, GET_TILE_Y(tile)*16+8, w);
+}
+
+
+
 bool ScrollMainWindowTo(int x, int y)
 {
 	Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
--- a/viewport.h	Fri Sep 03 18:23:03 2004 +0000
+++ b/viewport.h	Fri Sep 03 19:59:05 2004 +0000
@@ -18,7 +18,8 @@
 void SetViewportPosition(Window *w, int x, int y);
 ViewPort *IsPtInWindowViewport(Window *w, int x, int y);
 Point GetTileBelowCursor();
-Point GetTileZoomCenter(bool in);
+void ZoomInOrOutToCursorWindow(bool in, Window * w);
+Point GetTileZoomCenterWindow(bool in, Window * w);
 void UpdateViewportPosition(Window *w);
 
 void OffsetGroundSprite(int x, int y);
--- a/window.c	Fri Sep 03 18:23:03 2004 +0000
+++ b/window.c	Fri Sep 03 19:59:05 2004 +0000
@@ -2,7 +2,7 @@
 #include "ttd.h"
 #include "window.h"
 #include "gfx.h"
-#include "viewport.h"
+#include "viewport.h"
 #include "console.h"
 
 void HandleButtonClick(Window *w, byte widget)
@@ -574,7 +574,7 @@
 
 
 void InitWindowSystem()
-{
+{
 	IConsoleClose();
 	memset(&_windows, 0, sizeof(_windows));
 	_last_window = _windows;
@@ -1021,7 +1021,7 @@
 			return;
 
 		if (mousewheel && !(w->flags4 & WF_DISABLE_VP_SCROLL)) {
-			ZoomInOrOutToCursor(mousewheel < 0);
+			ZoomInOrOutToCursorWindow(mousewheel < 0,w);
 		}
 
 		if (click == 1) {
@@ -1206,8 +1206,8 @@
 			vp->virtual_width = neww << vp->zoom;
 			vp->virtual_height = newh << vp->zoom;
 			continue; // don't modify top,left
-		}
-
+		}
+
 		IConsoleResize();
 
 		if (w->window_class == WC_MAIN_TOOLBAR) {