File diff r1198:e4060ade398c → r1199:9e086dfa1c99
main_gui.c
Show inline comments
 
@@ -2192,25 +2192,25 @@ static void StatusBarWndProc(Window *w, 
 
		break;
 

	
 
	case WE_TICK: {
 
		if (_pause || WP(w,def_d).data_1 <= -1280)
 
			return;
 
		WP(w,def_d).data_1 -= 2;
 
		InvalidateWidget(w, 1);
 
		break;
 
	}
 
	}
 
}
 

	
 
static void ScrollMainViewport(int x, int y)
 
void ScrollMainViewport(int x, int y)
 
{
 
	if (_game_mode != GM_MENU) {
 
		Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
 
		assert(w);
 

	
 
		WP(w,vp_d).scrollpos_x += x << w->viewport->zoom;
 
		WP(w,vp_d).scrollpos_y += y << w->viewport->zoom;
 
	}
 
}
 

	
 

	
 
static const Widget _main_status_widgets[] = {
 
@@ -2219,24 +2219,51 @@ static const Widget _main_status_widgets
 
{ WWT_PUSHIMGBTN,   RESIZE_NONE,    14,   500,   639,     0,    11, 0x0, STR_NULL},
 
{   WIDGETS_END},
 
};
 

	
 
static WindowDesc _main_status_desc = {
 
	WDP_CENTER, 0, 640, 12,
 
	WC_STATUS_BAR,0,
 
	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
 
	_main_status_widgets,
 
	StatusBarWndProc
 
};
 

	
 
static const int8 scrollamt[16][2] = {
 
	{ 0, 0},
 
	{-2, 0}, // 1:left
 
	{ 0,-2}, // 2:up
 
	{-2,-1}, // 3:left + up
 
	{ 2, 0}, // 4:right
 
	{ 0, 0}, // 5:left + right
 
	{ 2,-1}, // 6:right + up
 
	{ 0,-2}, // 7:left + right + up = up
 
	{ 0 ,2}, // 8:down
 
	{-2 ,1}, // 9:down+left
 
	{ 0, 0}, // 10:impossible
 
	{-2, 0}, // 11:left + up + down = left
 
	{ 2, 1}, // 12:down+right
 
	{ 0, 2}, // 13:left + right + down = down
 
	{ 0,-2}, // 14:left + right + up = up
 
	{ 0, 0}, // 15:impossible
 
};
 

	
 
void HandleKeyScrolling(void)
 
{
 
	if (_dirkeys) {
 
		int factor = _shift_pressed ? 50 : 10;
 
		ScrollMainViewport(scrollamt[_dirkeys][0] * factor, scrollamt[_dirkeys][1] * factor);
 
	}
 
}
 

	
 
extern void DebugProc(int i);
 

	
 
static void MainWindowWndProc(Window *w, WindowEvent *e) {
 
	int off_x;
 

	
 
	switch(e->event) {
 
	case WE_PAINT:
 
		DrawWindowViewport(w);
 
		if (_game_mode == GM_MENU) {
 
			off_x = _screen.width / 2;
 

	
 
			DrawSprite(SPR_OTTD_O, off_x - 120, 50);
 
@@ -2263,52 +2290,24 @@ static void MainWindowWndProc(Window *w,
 
			DrawSprite(SPR_OTTD_C, off_x + 447, 50);
 
			DrawSprite(SPR_OTTD_O, off_x + 478, 50);
 
			DrawSprite(SPR_OTTD_O, off_x + 509, 50);
 
			DrawSprite(SPR_OTTD_N, off_x + 541, 50);
 
			*/
 
		}
 
		break;
 

	
 
	case WE_KEYPRESS:
 
		if (_game_mode == GM_MENU)
 
			break;
 

	
 
		// this is a hack, but this needs to be called at a constant interval and i found
 
		// no other window event that was suited for that purpose.
 
		{
 
			static const int8 scrollamt[16][2] = {
 
				{0,0},
 
				{-1,0},   // 1:left
 
				{0,-1},   // 2:up
 
				{-1,-1}, // 3:left + up
 
				{1,0},    // 4:right
 
				{0,0},     // 5:left + right
 
				{1,-1},  // 6:right + up
 
				{0,0},     // 7:impossible
 
				{0,1},    // 8:down
 
				{-1,1},  // 9:down+left
 
				{0,0},     // 10:impossible
 
				{0,0},     // 11:impossible
 
				{1,1},   // 12:down+right
 
				{0,0},     // 13:impossible
 
				{0,0},     // 14:impossible
 
				{0,0},     // 15:impossible
 
			};
 

	
 
			if (_dirkeys) {
 
				int factor = _shift_pressed ? 50 : 10;
 
				ScrollMainViewport(scrollamt[_dirkeys][0] * factor, scrollamt[_dirkeys][1] * factor);
 
			}
 
		}
 

	
 
		switch(e->keypress.keycode) {
 
		case 'C':
 
		case 'Z': {
 
			Point pt;
 
			pt = GetTileBelowCursor();
 
			if (pt.x != -1) {
 
				ScrollMainWindowTo(pt.x, pt.y);
 
				if (e->keypress.keycode == 'Z')
 
					MaxZoomIn();
 
			}
 
			break;
 
		}