src/video/win32_v.cpp
author rubidium
Sun, 25 May 2008 19:17:03 +0000
changeset 9354 845e07db4549
parent 9117 87f472043e9e
child 9470 08424e2e79e4
permissions -rw-r--r--
(svn r13251) -Codechange: rename _patches to _settings as that is more logic.
-Codechange: move all Settings into substructs of _settings in a way that they are logically grouped.
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2174
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2174
diff changeset
     2
9111
48ce04029fe4 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 9085
diff changeset
     3
/** @file win32_v.cpp Implementation of the Windows (GDI) video driver. */
48ce04029fe4 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 9085
diff changeset
     4
2189
5cdc11ffeaa4 (svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents: 2186
diff changeset
     5
#include "../stdafx.h"
5cdc11ffeaa4 (svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents: 2186
diff changeset
     6
#include "../openttd.h"
8123
ce31d2843a95 (svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents: 8121
diff changeset
     7
#include "../gfx_func.h"
2189
5cdc11ffeaa4 (svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents: 2186
diff changeset
     8
#include "../variables.h"
2207
be1ef1e1fc58 (svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents: 2189
diff changeset
     9
#include "../win32.h"
9085
8b3897a75aed (svn r12944) -Codechange: use rev.h instead of externs at many places
smatz
parents: 8985
diff changeset
    10
#include "../rev.h"
6939
2f865906b933 (svn r10192) -Fix r10190: forgot to change the includes of win32 and cocoa video-driver
truelight
parents: 6937
diff changeset
    11
#include "../blitter/factory.hpp"
8121
3bc6351e7369 (svn r11682) -Codechange: move some 'generic' geometry related types into a single file and do not include gfx.h everywhere to get a Point type.
rubidium
parents: 8115
diff changeset
    12
#include "../network/network.h"
8277
7a84582dd43b (svn r11841) -Fix: win32 compilation
glx
parents: 8171
diff changeset
    13
#include "../core/math_func.hpp"
8437
0da2a03711b9 (svn r12007) -Fix (r12003): win32 compilation was broken again ;)
glx
parents: 8277
diff changeset
    14
#include "../core/random_func.hpp"
9117
87f472043e9e (svn r12977) -Codechange: remove quite some redundant (duplicate) function declarations.
rubidium
parents: 9111
diff changeset
    15
#include "../functions.h"
87f472043e9e (svn r12977) -Codechange: remove quite some redundant (duplicate) function declarations.
rubidium
parents: 9111
diff changeset
    16
#include "../texteff.hpp"
2189
5cdc11ffeaa4 (svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents: 2186
diff changeset
    17
#include "win32_v.h"
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    18
#include <windows.h>
5168
e206899169c4 (svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents: 5112
diff changeset
    19
#include <tchar.h>
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    20
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    21
static struct {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    22
	HWND main_wnd;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    23
	HBITMAP dib_sect;
6878
5cefd3ac59c7 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 6615
diff changeset
    24
	void *buffer_bits;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    25
	HPALETTE gdi_palette;
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
    26
	int width;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
    27
	int height;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
    28
	int width_org;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
    29
	int height_org;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    30
	bool fullscreen;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    31
	bool has_focus;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    32
	bool running;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    33
} _wnd;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    34
3051
6a9ddcac6d56 (svn r3640) - Remove win32-only variables from variables.h and put them into win32_v.c. Also ifdef the win32 specific configuration file settings.
Darkvater
parents: 2952
diff changeset
    35
bool _force_full_redraw;
4258
087d44b3514f (svn r5874) -Feature [FS#234]: Remember the maximized state and restore on start. This also fixes a bug where a different resolution is chosen for a maximized window, but it retains the maximized flag. Only win32.
Darkvater
parents: 4077
diff changeset
    36
bool _window_maximize;
3051
6a9ddcac6d56 (svn r3640) - Remove win32-only variables from variables.h and put them into win32_v.c. Also ifdef the win32 specific configuration file settings.
Darkvater
parents: 2952
diff changeset
    37
uint _display_hz;
6a9ddcac6d56 (svn r3640) - Remove win32-only variables from variables.h and put them into win32_v.c. Also ifdef the win32 specific configuration file settings.
Darkvater
parents: 2952
diff changeset
    38
uint _fullscreen_bpp;
5020
e2564f4400b7 (svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents: 5019
diff changeset
    39
static uint16 _bck_resolution[2];
6251
2ad87f850eb9 (svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents: 6248
diff changeset
    40
#if !defined(UNICODE)
2ad87f850eb9 (svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents: 6248
diff changeset
    41
uint _codepage;
2ad87f850eb9 (svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents: 6248
diff changeset
    42
#endif
3051
6a9ddcac6d56 (svn r3640) - Remove win32-only variables from variables.h and put them into win32_v.c. Also ifdef the win32 specific configuration file settings.
Darkvater
parents: 2952
diff changeset
    43
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
    44
static void MakePalette()
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    45
{
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    46
	LOGPALETTE *pal;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    47
	uint i;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    48
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6277
diff changeset
    49
	pal = (LOGPALETTE*)alloca(sizeof(LOGPALETTE) + (256 - 1) * sizeof(PALETTEENTRY));
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    50
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    51
	pal->palVersion = 0x300;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    52
	pal->palNumEntries = 256;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    53
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    54
	for (i = 0; i != 256; i++) {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    55
		pal->palPalEntry[i].peRed   = _cur_palette[i].r;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    56
		pal->palPalEntry[i].peGreen = _cur_palette[i].g;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    57
		pal->palPalEntry[i].peBlue  = _cur_palette[i].b;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    58
		pal->palPalEntry[i].peFlags = 0;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    59
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    60
	}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    61
	_wnd.gdi_palette = CreatePalette(pal);
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
    62
	if (_wnd.gdi_palette == NULL) error("CreatePalette failed!\n");
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    63
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    64
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    65
static void UpdatePalette(HDC dc, uint start, uint count)
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    66
{
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    67
	RGBQUAD rgb[256];
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    68
	uint i;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    69
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    70
	for (i = 0; i != count; i++) {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    71
		rgb[i].rgbRed   = _cur_palette[start + i].r;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    72
		rgb[i].rgbGreen = _cur_palette[start + i].g;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    73
		rgb[i].rgbBlue  = _cur_palette[start + i].b;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    74
		rgb[i].rgbReserved = 0;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    75
	}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    76
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    77
	SetDIBColorTable(dc, start, count, rgb);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    78
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    79
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    80
struct VkMapping {
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    81
	byte vk_from;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    82
	byte vk_count;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    83
	byte map_to;
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    84
};
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    85
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    86
#define AS(x, z) {x, 0, z}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    87
#define AM(x, y, z, w) {x, y - x, z}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    88
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    89
static const VkMapping _vk_mapping[] = {
7311
fde7a4d92a39 (svn r10663) -Fix r10662: bad me, didn't comply with coding style, as penalty I updated the surrounding code to comply with coding style too; I will never do it again (I hope :p)
truelight
parents: 7310
diff changeset
    90
	/* Pageup stuff + up/down */
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    91
	AM(VK_PRIOR,VK_DOWN, WKC_PAGEUP, WKC_DOWN),
7311
fde7a4d92a39 (svn r10663) -Fix r10662: bad me, didn't comply with coding style, as penalty I updated the surrounding code to comply with coding style too; I will never do it again (I hope :p)
truelight
parents: 7310
diff changeset
    92
	/* Map letters & digits */
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    93
	AM('A','Z','A','Z'),
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    94
	AM('0','9','0','9'),
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    95
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
    96
	AS(VK_ESCAPE,   WKC_ESC),
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
    97
	AS(VK_PAUSE,    WKC_PAUSE),
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
    98
	AS(VK_BACK,     WKC_BACKSPACE),
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
    99
	AM(VK_INSERT,   VK_DELETE, WKC_INSERT, WKC_DELETE),
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   100
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
   101
	AS(VK_SPACE,    WKC_SPACE),
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
   102
	AS(VK_RETURN,   WKC_RETURN),
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
   103
	AS(VK_TAB,      WKC_TAB),
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   104
7311
fde7a4d92a39 (svn r10663) -Fix r10662: bad me, didn't comply with coding style, as penalty I updated the surrounding code to comply with coding style too; I will never do it again (I hope :p)
truelight
parents: 7310
diff changeset
   105
	/* Function keys */
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
   106
	AM(VK_F1, VK_F12, WKC_F1, WKC_F12),
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   107
7311
fde7a4d92a39 (svn r10663) -Fix r10662: bad me, didn't comply with coding style, as penalty I updated the surrounding code to comply with coding style too; I will never do it again (I hope :p)
truelight
parents: 7310
diff changeset
   108
	/* Numeric part */
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
   109
	AM(VK_NUMPAD0, VK_NUMPAD9, WKC_NUM_0, WKC_NUM_9),
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
   110
	AS(VK_DIVIDE,   WKC_NUM_DIV),
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
   111
	AS(VK_MULTIPLY, WKC_NUM_MUL),
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
   112
	AS(VK_SUBTRACT, WKC_NUM_MINUS),
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
   113
	AS(VK_ADD,      WKC_NUM_PLUS),
7310
eed5036fee1f (svn r10662) -Add: added 'V' as new shortcut for new viewport (bilbo)
truelight
parents: 7170
diff changeset
   114
	AS(VK_DECIMAL,  WKC_NUM_DECIMAL),
eed5036fee1f (svn r10662) -Add: added 'V' as new shortcut for new viewport (bilbo)
truelight
parents: 7170
diff changeset
   115
7311
fde7a4d92a39 (svn r10663) -Fix r10662: bad me, didn't comply with coding style, as penalty I updated the surrounding code to comply with coding style too; I will never do it again (I hope :p)
truelight
parents: 7310
diff changeset
   116
	/* Other non-letter keys */
7310
eed5036fee1f (svn r10662) -Add: added 'V' as new shortcut for new viewport (bilbo)
truelight
parents: 7170
diff changeset
   117
	AS(0xBF,  WKC_SLASH),
eed5036fee1f (svn r10662) -Add: added 'V' as new shortcut for new viewport (bilbo)
truelight
parents: 7170
diff changeset
   118
	AS(0xBA,  WKC_SEMICOLON),
eed5036fee1f (svn r10662) -Add: added 'V' as new shortcut for new viewport (bilbo)
truelight
parents: 7170
diff changeset
   119
	AS(0xBB,  WKC_EQUALS),
eed5036fee1f (svn r10662) -Add: added 'V' as new shortcut for new viewport (bilbo)
truelight
parents: 7170
diff changeset
   120
	AS(0xDB,  WKC_L_BRACKET),
eed5036fee1f (svn r10662) -Add: added 'V' as new shortcut for new viewport (bilbo)
truelight
parents: 7170
diff changeset
   121
	AS(0xDC,  WKC_BACKSLASH),
eed5036fee1f (svn r10662) -Add: added 'V' as new shortcut for new viewport (bilbo)
truelight
parents: 7170
diff changeset
   122
	AS(0xDD,  WKC_R_BRACKET),
eed5036fee1f (svn r10662) -Add: added 'V' as new shortcut for new viewport (bilbo)
truelight
parents: 7170
diff changeset
   123
eed5036fee1f (svn r10662) -Add: added 'V' as new shortcut for new viewport (bilbo)
truelight
parents: 7170
diff changeset
   124
	AS(0xDE,  WKC_SINGLEQUOTE),
eed5036fee1f (svn r10662) -Add: added 'V' as new shortcut for new viewport (bilbo)
truelight
parents: 7170
diff changeset
   125
	AS(0xBC,  WKC_COMMA),
eed5036fee1f (svn r10662) -Add: added 'V' as new shortcut for new viewport (bilbo)
truelight
parents: 7170
diff changeset
   126
	AS(0xBD,  WKC_MINUS),
eed5036fee1f (svn r10662) -Add: added 'V' as new shortcut for new viewport (bilbo)
truelight
parents: 7170
diff changeset
   127
	AS(0xBE,  WKC_PERIOD)
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   128
};
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   129
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   130
static uint MapWindowsKey(uint sym)
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   131
{
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   132
	const VkMapping *map;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   133
	uint key = 0;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   134
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   135
	for (map = _vk_mapping; map != endof(_vk_mapping); ++map) {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   136
		if ((uint)(sym - map->vk_from) <= map->vk_count) {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   137
			key = sym - map->vk_from + map->map_to;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   138
			break;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   139
		}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   140
	}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   141
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   142
	if (GetAsyncKeyState(VK_SHIFT)   < 0) key |= WKC_SHIFT;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   143
	if (GetAsyncKeyState(VK_CONTROL) < 0) key |= WKC_CTRL;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   144
	if (GetAsyncKeyState(VK_MENU)    < 0) key |= WKC_ALT;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   145
	return key;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   146
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   147
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   148
static bool AllocateDibSection(int w, int h);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   149
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   150
static void ClientSizeChanged(int w, int h)
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   151
{
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   152
	// allocate new dib section of the new size
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   153
	if (AllocateDibSection(w, h)) {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   154
		// mark all palette colors dirty
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   155
		_pal_first_dirty = 0;
7392
0964cfefbe64 (svn r10761) -Fix (FS#1101, r10216): _pal_last_dirty changed to _pal_count_dirty without updating, so it was of by one
glx
parents: 7311
diff changeset
   156
		_pal_count_dirty = 256;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   157
		GameSizeChanged();
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   158
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   159
		// redraw screen
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   160
		if (_wnd.running) {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   161
			_screen.dst_ptr = _wnd.buffer_bits;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   162
			UpdateWindows();
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   163
		}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   164
	}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   165
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   166
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   167
#ifdef _DEBUG
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   168
// Keep this function here..
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   169
// It allows you to redraw the screen from within the MSVC debugger
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
   170
int RedrawScreenDebug()
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   171
{
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   172
	HDC dc,dc2;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   173
	static int _fooctr;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   174
	HBITMAP old_bmp;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   175
	HPALETTE old_palette;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   176
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   177
	_screen.dst_ptr = _wnd.buffer_bits;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   178
	UpdateWindows();
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   179
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   180
	dc = GetDC(_wnd.main_wnd);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   181
	dc2 = CreateCompatibleDC(dc);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   182
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   183
	old_bmp = (HBITMAP)SelectObject(dc2, _wnd.dib_sect);
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   184
	old_palette = SelectPalette(dc, _wnd.gdi_palette, FALSE);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   185
	BitBlt(dc, 0, 0, _wnd.width, _wnd.height, dc2, 0, 0, SRCCOPY);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   186
	SelectPalette(dc, old_palette, TRUE);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   187
	SelectObject(dc2, old_bmp);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   188
	DeleteDC(dc2);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   189
	ReleaseDC(_wnd.main_wnd, dc);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   190
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   191
	return _fooctr++;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   192
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   193
#endif
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   194
5021
6fb82e055ceb (svn r7062) -[win32] Codechange: Remove unneeded WM_MOUSEENTER event, and change mouse behaviour
Darkvater
parents: 5020
diff changeset
   195
/* Windows 95 will not have a WM_MOUSELEAVE message, so define it if needed */
3312
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   196
#if !defined(WM_MOUSELEAVE)
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   197
#define WM_MOUSELEAVE 0x02A3
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   198
#endif
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   199
#define TID_POLLMOUSE 1
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   200
#define MOUSE_POLL_DELAY 75
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   201
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   202
static void CALLBACK TrackMouseTimerProc(HWND hwnd, UINT msg, UINT event, DWORD time)
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   203
{
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   204
	RECT rc;
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   205
	POINT pt;
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   206
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   207
	/* Get the rectangle of our window and translate it to screen coordinates.
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   208
	 * Compare this with the current screen coordinates of the mouse and if it
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   209
	 * falls outside of the area or our window we have left the window. */
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   210
	GetClientRect(hwnd, &rc);
3802
e3f0d57cc358 (svn r4810) - Fix: removed warning about strict-alias (release build)
glx
parents: 3325
diff changeset
   211
	MapWindowPoints(hwnd, HWND_DESKTOP, (LPPOINT)(LPRECT)&rc, 2);
3312
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   212
	GetCursorPos(&pt);
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   213
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   214
	if (!PtInRect(&rc, pt) || (WindowFromPoint(pt) != hwnd)) {
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   215
		KillTimer(hwnd, event);
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   216
		PostMessage(hwnd, WM_MOUSELEAVE, 0, 0L);
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   217
	}
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   218
}
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   219
8171
3fb9d1f8ac3b (svn r11734) -Change: Allow ToggleFullScreen to return the result of the operation' attempt. Previously, only visual clues were available.
belugas
parents: 8131
diff changeset
   220
static bool MakeWindow(bool full_screen)
6995
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   221
{
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   222
	_fullscreen = full_screen;
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   223
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   224
	// recreate window?
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   225
	if ((full_screen || _wnd.fullscreen) && _wnd.main_wnd) {
7429
9147a1f31a4e (svn r10834) -Revert (part of r10833): something too much was committed :(
rubidium
parents: 7428
diff changeset
   226
		DestroyWindow(_wnd.main_wnd);
6995
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   227
		_wnd.main_wnd = 0;
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   228
	}
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   229
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   230
#if defined(WINCE)
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   231
	/* WinCE is always fullscreen */
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   232
#else
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   233
	if (full_screen) {
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   234
		DEVMODE settings;
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   235
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   236
		/* Make sure we are always at least the screen-depth of the blitter */
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   237
		if (_fullscreen_bpp < BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth()) _fullscreen_bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth();
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   238
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   239
		memset(&settings, 0, sizeof(settings));
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   240
		settings.dmSize = sizeof(settings);
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   241
		settings.dmFields =
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   242
			(_fullscreen_bpp != 0 ? DM_BITSPERPEL : 0) |
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   243
			DM_PELSWIDTH |
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   244
			DM_PELSHEIGHT |
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   245
			(_display_hz != 0 ? DM_DISPLAYFREQUENCY : 0);
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   246
		settings.dmBitsPerPel = _fullscreen_bpp;
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   247
		settings.dmPelsWidth  = _wnd.width_org;
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   248
		settings.dmPelsHeight = _wnd.height_org;
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   249
		settings.dmDisplayFrequency = _display_hz;
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   250
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   251
		if (ChangeDisplaySettings(&settings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) {
8171
3fb9d1f8ac3b (svn r11734) -Change: Allow ToggleFullScreen to return the result of the operation' attempt. Previously, only visual clues were available.
belugas
parents: 8131
diff changeset
   252
			MakeWindow(false);  // don't care about the result
3fb9d1f8ac3b (svn r11734) -Change: Allow ToggleFullScreen to return the result of the operation' attempt. Previously, only visual clues were available.
belugas
parents: 8131
diff changeset
   253
			return false;  // the request failed
6995
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   254
		}
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   255
	} else if (_wnd.fullscreen) {
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   256
		// restore display?
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   257
		ChangeDisplaySettings(NULL, 0);
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   258
	}
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   259
#endif
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   260
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   261
	{
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   262
		RECT r;
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   263
		DWORD style, showstyle;
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   264
		int x, y, w, h;
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   265
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   266
		showstyle = SW_SHOWNORMAL;
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   267
		_wnd.fullscreen = full_screen;
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   268
		if (_wnd.fullscreen) {
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   269
			style = WS_POPUP;
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   270
			SetRect(&r, 0, 0, _wnd.width_org, _wnd.height_org);
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   271
		} else {
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   272
			style = WS_OVERLAPPEDWINDOW;
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   273
			/* On window creation, check if we were in maximize mode before */
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   274
			if (_window_maximize) showstyle = SW_SHOWMAXIMIZED;
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   275
			SetRect(&r, 0, 0, _wnd.width, _wnd.height);
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   276
		}
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   277
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   278
#if !defined(WINCE)
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   279
		AdjustWindowRect(&r, style, FALSE);
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   280
#endif
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   281
		w = r.right - r.left;
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   282
		h = r.bottom - r.top;
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   283
		x = (GetSystemMetrics(SM_CXSCREEN) - w) / 2;
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   284
		y = (GetSystemMetrics(SM_CYSCREEN) - h) / 2;
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   285
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   286
		if (_wnd.main_wnd) {
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   287
			ShowWindow(_wnd.main_wnd, SW_SHOWNORMAL); // remove maximize-flag
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   288
			SetWindowPos(_wnd.main_wnd, 0, x, y, w, h, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   289
		} else {
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   290
			TCHAR Windowtitle[50];
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   291
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   292
			_sntprintf(Windowtitle, sizeof(Windowtitle), _T("OpenTTD %s"), MB_TO_WIDE(_openttd_revision));
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   293
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   294
			_wnd.main_wnd = CreateWindow(_T("OTTD"), Windowtitle, style, x, y, w, h, 0, 0, GetModuleHandle(NULL), 0);
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   295
			if (_wnd.main_wnd == NULL) error("CreateWindow failed");
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   296
			ShowWindow(_wnd.main_wnd, showstyle);
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   297
		}
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   298
	}
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   299
	GameSizeChanged(); // invalidate all windows, force redraw
8171
3fb9d1f8ac3b (svn r11734) -Change: Allow ToggleFullScreen to return the result of the operation' attempt. Previously, only visual clues were available.
belugas
parents: 8131
diff changeset
   300
	return true; // the request succedded
6995
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   301
}
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   302
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   303
static LRESULT CALLBACK WndProcGdi(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   304
{
6277
58822e8a88b6 (svn r9086) -Feature/Fix: [win32] Rewrite keyboard input and handle all keypresses in a WM_CHAR event. This saves us from doing translation (ToUnicode[Ex], ToAscii[Ex]), and we get free IME-input support as a plus.
Darkvater
parents: 6276
diff changeset
   305
	static uint32 keycode = 0;
6539
71cb3360be11 (svn r9728) -Fix r9086: [win32] For some keyboard layout the 'console' key is a dead-key. It needs to be pressed twice to have an effect but the console is then opened and closed on the 'same' keypress (2 WM_CHAR events). So skip the first WM_CHAR generated to restore the 'console' key functionality.
glx
parents: 6491
diff changeset
   306
	static bool console = false;
6277
58822e8a88b6 (svn r9086) -Feature/Fix: [win32] Rewrite keyboard input and handle all keypresses in a WM_CHAR event. This saves us from doing translation (ToUnicode[Ex], ToAscii[Ex]), and we get free IME-input support as a plus.
Darkvater
parents: 6276
diff changeset
   307
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   308
	switch (msg) {
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   309
		case WM_CREATE:
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   310
			SetTimer(hwnd, TID_POLLMOUSE, MOUSE_POLL_DELAY, (TIMERPROC)TrackMouseTimerProc);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   311
			break;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   312
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   313
		case WM_PAINT: {
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   314
			PAINTSTRUCT ps;
8969
6d1c74e0e2cd (svn r12761) -Codechange: lots of minor whitespace coding style fixes around operators.
rubidium
parents: 8586
diff changeset
   315
			HDC dc, dc2;
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   316
			HBITMAP old_bmp;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   317
			HPALETTE old_palette;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   318
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   319
			BeginPaint(hwnd, &ps);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   320
			dc = ps.hdc;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   321
			dc2 = CreateCompatibleDC(dc);
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   322
			old_bmp = (HBITMAP)SelectObject(dc2, _wnd.dib_sect);
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   323
			old_palette = SelectPalette(dc, _wnd.gdi_palette, FALSE);
3312
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   324
6960
356d856462b6 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 6939
diff changeset
   325
			if (_pal_count_dirty != 0) {
6961
8e5217fd71f4 (svn r10217) -Fix r10216: forgot to declare 'blitter' in win32 and cocoa driver (tnx glx)
truelight
parents: 6960
diff changeset
   326
				Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
8e5217fd71f4 (svn r10217) -Fix r10216: forgot to declare 'blitter' in win32 and cocoa driver (tnx glx)
truelight
parents: 6960
diff changeset
   327
6960
356d856462b6 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 6939
diff changeset
   328
				switch (blitter->UsePaletteAnimation()) {
356d856462b6 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 6939
diff changeset
   329
					case Blitter::PALETTE_ANIMATION_VIDEO_BACKEND:
6962
3e925700b4c8 (svn r10218) -Fix r10216: more compile errors
glx
parents: 6961
diff changeset
   330
						UpdatePalette(dc2, _pal_first_dirty, _pal_count_dirty);
6960
356d856462b6 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 6939
diff changeset
   331
						break;
356d856462b6 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 6939
diff changeset
   332
356d856462b6 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 6939
diff changeset
   333
					case Blitter::PALETTE_ANIMATION_BLITTER:
356d856462b6 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 6939
diff changeset
   334
						blitter->PaletteAnimate(_pal_first_dirty, _pal_count_dirty);
356d856462b6 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 6939
diff changeset
   335
						break;
356d856462b6 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 6939
diff changeset
   336
356d856462b6 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 6939
diff changeset
   337
					case Blitter::PALETTE_ANIMATION_NONE:
356d856462b6 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 6939
diff changeset
   338
						break;
356d856462b6 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 6939
diff changeset
   339
356d856462b6 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 6939
diff changeset
   340
					default:
356d856462b6 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 6939
diff changeset
   341
						NOT_REACHED();
356d856462b6 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 6939
diff changeset
   342
				}
356d856462b6 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 6939
diff changeset
   343
				_pal_count_dirty = 0;
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   344
			}
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   345
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   346
			BitBlt(dc, 0, 0, _wnd.width, _wnd.height, dc2, 0, 0, SRCCOPY);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   347
			SelectPalette(dc, old_palette, TRUE);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   348
			SelectObject(dc2, old_bmp);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   349
			DeleteDC(dc2);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   350
			EndPaint(hwnd, &ps);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   351
			return 0;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   352
		}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   353
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   354
		case WM_PALETTECHANGED:
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   355
			if ((HWND)wParam == hwnd) return 0;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   356
			/* FALLTHROUGH */
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   357
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   358
		case WM_QUERYNEWPALETTE: {
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   359
			HDC hDC = GetWindowDC(hwnd);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   360
			HPALETTE hOldPalette = SelectPalette(hDC, _wnd.gdi_palette, FALSE);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   361
			UINT nChanged = RealizePalette(hDC);
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   362
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   363
			SelectPalette(hDC, hOldPalette, TRUE);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   364
			ReleaseDC(hwnd, hDC);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   365
			if (nChanged) InvalidateRect(hwnd, NULL, FALSE);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   366
			return 0;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   367
		}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   368
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   369
		case WM_CLOSE:
4548
6165e12570bf (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4536
diff changeset
   370
			HandleExitGameRequest();
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   371
			return 0;
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   372
5020
e2564f4400b7 (svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents: 5019
diff changeset
   373
		case WM_DESTROY:
e2564f4400b7 (svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents: 5019
diff changeset
   374
			if (_window_maximize) {
e2564f4400b7 (svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents: 5019
diff changeset
   375
				_cur_resolution[0] = _bck_resolution[0];
e2564f4400b7 (svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents: 5019
diff changeset
   376
				_cur_resolution[1] = _bck_resolution[1];
e2564f4400b7 (svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents: 5019
diff changeset
   377
			}
e2564f4400b7 (svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents: 5019
diff changeset
   378
			return 0;
e2564f4400b7 (svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents: 5019
diff changeset
   379
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   380
		case WM_LBUTTONDOWN:
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   381
			SetCapture(hwnd);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   382
			_left_button_down = true;
5090
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
   383
			HandleMouseEvents();
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   384
			return 0;
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   385
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   386
		case WM_LBUTTONUP:
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   387
			ReleaseCapture();
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   388
			_left_button_down = false;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   389
			_left_button_clicked = false;
5090
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
   390
			HandleMouseEvents();
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   391
			return 0;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   392
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   393
		case WM_RBUTTONDOWN:
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   394
			SetCapture(hwnd);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   395
			_right_button_down = true;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   396
			_right_button_clicked = true;
5090
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
   397
			HandleMouseEvents();
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   398
			return 0;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   399
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   400
		case WM_RBUTTONUP:
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   401
			ReleaseCapture();
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   402
			_right_button_down = false;
5090
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
   403
			HandleMouseEvents();
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   404
			return 0;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   405
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   406
		case WM_MOUSELEAVE:
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   407
			UndrawMouseCursor();
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   408
			_cursor.in_window = false;
5021
6fb82e055ceb (svn r7062) -[win32] Codechange: Remove unneeded WM_MOUSEENTER event, and change mouse behaviour
Darkvater
parents: 5020
diff changeset
   409
6fb82e055ceb (svn r7062) -[win32] Codechange: Remove unneeded WM_MOUSEENTER event, and change mouse behaviour
Darkvater
parents: 5020
diff changeset
   410
			if (!_left_button_down && !_right_button_down) MyShowCursor(true);
5090
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
   411
			HandleMouseEvents();
5021
6fb82e055ceb (svn r7062) -[win32] Codechange: Remove unneeded WM_MOUSEENTER event, and change mouse behaviour
Darkvater
parents: 5020
diff changeset
   412
			return 0;
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   413
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   414
		case WM_MOUSEMOVE: {
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   415
			int x = (int16)LOWORD(lParam);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   416
			int y = (int16)HIWORD(lParam);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   417
			POINT pt;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   418
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   419
			/* If the mouse was not in the window and it has moved it means it has
5021
6fb82e055ceb (svn r7062) -[win32] Codechange: Remove unneeded WM_MOUSEENTER event, and change mouse behaviour
Darkvater
parents: 5020
diff changeset
   420
			 * come into the window, so start drawing the mouse. Also start
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   421
			 * tracking the mouse for exiting the window */
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   422
			if (!_cursor.in_window) {
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   423
				_cursor.in_window = true;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   424
				SetTimer(hwnd, TID_POLLMOUSE, MOUSE_POLL_DELAY, (TIMERPROC)TrackMouseTimerProc);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   425
5021
6fb82e055ceb (svn r7062) -[win32] Codechange: Remove unneeded WM_MOUSEENTER event, and change mouse behaviour
Darkvater
parents: 5020
diff changeset
   426
				DrawMouseCursor();
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   427
			}
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   428
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   429
			if (_cursor.fix_at) {
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   430
				int dx = x - _cursor.pos.x;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   431
				int dy = y - _cursor.pos.y;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   432
				if (dx != 0 || dy != 0) {
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   433
					_cursor.delta.x += dx;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   434
					_cursor.delta.y += dy;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   435
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   436
					pt.x = _cursor.pos.x;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   437
					pt.y = _cursor.pos.y;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   438
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   439
					ClientToScreen(hwnd, &pt);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   440
					SetCursorPos(pt.x, pt.y);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   441
				}
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   442
			} else {
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   443
				_cursor.delta.x += x - _cursor.pos.x;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   444
				_cursor.delta.y += y - _cursor.pos.y;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   445
				_cursor.pos.x = x;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   446
				_cursor.pos.y = y;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   447
				_cursor.dirty = true;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   448
			}
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   449
			MyShowCursor(false);
5090
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
   450
			HandleMouseEvents();
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   451
			return 0;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   452
		}
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   453
6251
2ad87f850eb9 (svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents: 6248
diff changeset
   454
#if !defined(UNICODE)
2ad87f850eb9 (svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents: 6248
diff changeset
   455
		case WM_INPUTLANGCHANGE: {
2ad87f850eb9 (svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents: 6248
diff changeset
   456
			TCHAR locale[6];
2ad87f850eb9 (svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents: 6248
diff changeset
   457
			LCID lcid = GB(lParam, 0, 16);
2ad87f850eb9 (svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents: 6248
diff changeset
   458
2ad87f850eb9 (svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents: 6248
diff changeset
   459
			int len = GetLocaleInfo(lcid, LOCALE_IDEFAULTANSICODEPAGE, locale, lengthof(locale));
2ad87f850eb9 (svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents: 6248
diff changeset
   460
			if (len != 0) _codepage = _ttoi(locale);
2ad87f850eb9 (svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents: 6248
diff changeset
   461
			return 1;
2ad87f850eb9 (svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents: 6248
diff changeset
   462
		}
2ad87f850eb9 (svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents: 6248
diff changeset
   463
#endif /* UNICODE */
2ad87f850eb9 (svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents: 6248
diff changeset
   464
6539
71cb3360be11 (svn r9728) -Fix r9086: [win32] For some keyboard layout the 'console' key is a dead-key. It needs to be pressed twice to have an effect but the console is then opened and closed on the 'same' keypress (2 WM_CHAR events). So skip the first WM_CHAR generated to restore the 'console' key functionality.
glx
parents: 6491
diff changeset
   465
		case WM_DEADCHAR:
71cb3360be11 (svn r9728) -Fix r9086: [win32] For some keyboard layout the 'console' key is a dead-key. It needs to be pressed twice to have an effect but the console is then opened and closed on the 'same' keypress (2 WM_CHAR events). So skip the first WM_CHAR generated to restore the 'console' key functionality.
glx
parents: 6491
diff changeset
   466
			console = GB(lParam, 16, 8) == 41;
71cb3360be11 (svn r9728) -Fix r9086: [win32] For some keyboard layout the 'console' key is a dead-key. It needs to be pressed twice to have an effect but the console is then opened and closed on the 'same' keypress (2 WM_CHAR events). So skip the first WM_CHAR generated to restore the 'console' key functionality.
glx
parents: 6491
diff changeset
   467
			return 0;
71cb3360be11 (svn r9728) -Fix r9086: [win32] For some keyboard layout the 'console' key is a dead-key. It needs to be pressed twice to have an effect but the console is then opened and closed on the 'same' keypress (2 WM_CHAR events). So skip the first WM_CHAR generated to restore the 'console' key functionality.
glx
parents: 6491
diff changeset
   468
6277
58822e8a88b6 (svn r9086) -Feature/Fix: [win32] Rewrite keyboard input and handle all keypresses in a WM_CHAR event. This saves us from doing translation (ToUnicode[Ex], ToAscii[Ex]), and we get free IME-input support as a plus.
Darkvater
parents: 6276
diff changeset
   469
		case WM_CHAR: {
58822e8a88b6 (svn r9086) -Feature/Fix: [win32] Rewrite keyboard input and handle all keypresses in a WM_CHAR event. This saves us from doing translation (ToUnicode[Ex], ToAscii[Ex]), and we get free IME-input support as a plus.
Darkvater
parents: 6276
diff changeset
   470
			/* Silently drop all non-text messages as those were handled by WM_KEYDOWN */
58822e8a88b6 (svn r9086) -Feature/Fix: [win32] Rewrite keyboard input and handle all keypresses in a WM_CHAR event. This saves us from doing translation (ToUnicode[Ex], ToAscii[Ex]), and we get free IME-input support as a plus.
Darkvater
parents: 6276
diff changeset
   471
			if (wParam < VK_SPACE) return 0;
58822e8a88b6 (svn r9086) -Feature/Fix: [win32] Rewrite keyboard input and handle all keypresses in a WM_CHAR event. This saves us from doing translation (ToUnicode[Ex], ToAscii[Ex]), and we get free IME-input support as a plus.
Darkvater
parents: 6276
diff changeset
   472
			uint scancode = GB(lParam, 16, 8);
58822e8a88b6 (svn r9086) -Feature/Fix: [win32] Rewrite keyboard input and handle all keypresses in a WM_CHAR event. This saves us from doing translation (ToUnicode[Ex], ToAscii[Ex]), and we get free IME-input support as a plus.
Darkvater
parents: 6276
diff changeset
   473
			uint charcode = wParam;
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   474
6539
71cb3360be11 (svn r9728) -Fix r9086: [win32] For some keyboard layout the 'console' key is a dead-key. It needs to be pressed twice to have an effect but the console is then opened and closed on the 'same' keypress (2 WM_CHAR events). So skip the first WM_CHAR generated to restore the 'console' key functionality.
glx
parents: 6491
diff changeset
   475
			/* If the console key is a dead-key, we need to press it twice to get a WM_CHAR message.
71cb3360be11 (svn r9728) -Fix r9086: [win32] For some keyboard layout the 'console' key is a dead-key. It needs to be pressed twice to have an effect but the console is then opened and closed on the 'same' keypress (2 WM_CHAR events). So skip the first WM_CHAR generated to restore the 'console' key functionality.
glx
parents: 6491
diff changeset
   476
			 * But we then get two WM_CHAR messages, so ignore the first one */
71cb3360be11 (svn r9728) -Fix r9086: [win32] For some keyboard layout the 'console' key is a dead-key. It needs to be pressed twice to have an effect but the console is then opened and closed on the 'same' keypress (2 WM_CHAR events). So skip the first WM_CHAR generated to restore the 'console' key functionality.
glx
parents: 6491
diff changeset
   477
			if (console && scancode == 41) {
71cb3360be11 (svn r9728) -Fix r9086: [win32] For some keyboard layout the 'console' key is a dead-key. It needs to be pressed twice to have an effect but the console is then opened and closed on the 'same' keypress (2 WM_CHAR events). So skip the first WM_CHAR generated to restore the 'console' key functionality.
glx
parents: 6491
diff changeset
   478
				console = false;
71cb3360be11 (svn r9728) -Fix r9086: [win32] For some keyboard layout the 'console' key is a dead-key. It needs to be pressed twice to have an effect but the console is then opened and closed on the 'same' keypress (2 WM_CHAR events). So skip the first WM_CHAR generated to restore the 'console' key functionality.
glx
parents: 6491
diff changeset
   479
				return 0;
71cb3360be11 (svn r9728) -Fix r9086: [win32] For some keyboard layout the 'console' key is a dead-key. It needs to be pressed twice to have an effect but the console is then opened and closed on the 'same' keypress (2 WM_CHAR events). So skip the first WM_CHAR generated to restore the 'console' key functionality.
glx
parents: 6491
diff changeset
   480
			}
71cb3360be11 (svn r9728) -Fix r9086: [win32] For some keyboard layout the 'console' key is a dead-key. It needs to be pressed twice to have an effect but the console is then opened and closed on the 'same' keypress (2 WM_CHAR events). So skip the first WM_CHAR generated to restore the 'console' key functionality.
glx
parents: 6491
diff changeset
   481
6277
58822e8a88b6 (svn r9086) -Feature/Fix: [win32] Rewrite keyboard input and handle all keypresses in a WM_CHAR event. This saves us from doing translation (ToUnicode[Ex], ToAscii[Ex]), and we get free IME-input support as a plus.
Darkvater
parents: 6276
diff changeset
   482
#if !defined(UNICODE)
58822e8a88b6 (svn r9086) -Feature/Fix: [win32] Rewrite keyboard input and handle all keypresses in a WM_CHAR event. This saves us from doing translation (ToUnicode[Ex], ToAscii[Ex]), and we get free IME-input support as a plus.
Darkvater
parents: 6276
diff changeset
   483
			wchar_t w;
58822e8a88b6 (svn r9086) -Feature/Fix: [win32] Rewrite keyboard input and handle all keypresses in a WM_CHAR event. This saves us from doing translation (ToUnicode[Ex], ToAscii[Ex]), and we get free IME-input support as a plus.
Darkvater
parents: 6276
diff changeset
   484
			int len = MultiByteToWideChar(_codepage, 0, (char*)&charcode, 1, &w, 1);
58822e8a88b6 (svn r9086) -Feature/Fix: [win32] Rewrite keyboard input and handle all keypresses in a WM_CHAR event. This saves us from doing translation (ToUnicode[Ex], ToAscii[Ex]), and we get free IME-input support as a plus.
Darkvater
parents: 6276
diff changeset
   485
			charcode = len == 1 ? w : 0;
58822e8a88b6 (svn r9086) -Feature/Fix: [win32] Rewrite keyboard input and handle all keypresses in a WM_CHAR event. This saves us from doing translation (ToUnicode[Ex], ToAscii[Ex]), and we get free IME-input support as a plus.
Darkvater
parents: 6276
diff changeset
   486
#endif /* UNICODE */
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   487
6277
58822e8a88b6 (svn r9086) -Feature/Fix: [win32] Rewrite keyboard input and handle all keypresses in a WM_CHAR event. This saves us from doing translation (ToUnicode[Ex], ToAscii[Ex]), and we get free IME-input support as a plus.
Darkvater
parents: 6276
diff changeset
   488
			/* No matter the keyboard layout, we will map the '~' to the console */
58822e8a88b6 (svn r9086) -Feature/Fix: [win32] Rewrite keyboard input and handle all keypresses in a WM_CHAR event. This saves us from doing translation (ToUnicode[Ex], ToAscii[Ex]), and we get free IME-input support as a plus.
Darkvater
parents: 6276
diff changeset
   489
			scancode = scancode == 41 ? (int)WKC_BACKQUOTE : keycode;
58822e8a88b6 (svn r9086) -Feature/Fix: [win32] Rewrite keyboard input and handle all keypresses in a WM_CHAR event. This saves us from doing translation (ToUnicode[Ex], ToAscii[Ex]), and we get free IME-input support as a plus.
Darkvater
parents: 6276
diff changeset
   490
			HandleKeypress(GB(charcode, 0, 16) | (scancode << 16));
58822e8a88b6 (svn r9086) -Feature/Fix: [win32] Rewrite keyboard input and handle all keypresses in a WM_CHAR event. This saves us from doing translation (ToUnicode[Ex], ToAscii[Ex]), and we get free IME-input support as a plus.
Darkvater
parents: 6276
diff changeset
   491
			return 0;
58822e8a88b6 (svn r9086) -Feature/Fix: [win32] Rewrite keyboard input and handle all keypresses in a WM_CHAR event. This saves us from doing translation (ToUnicode[Ex], ToAscii[Ex]), and we get free IME-input support as a plus.
Darkvater
parents: 6276
diff changeset
   492
		}
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   493
6277
58822e8a88b6 (svn r9086) -Feature/Fix: [win32] Rewrite keyboard input and handle all keypresses in a WM_CHAR event. This saves us from doing translation (ToUnicode[Ex], ToAscii[Ex]), and we get free IME-input support as a plus.
Darkvater
parents: 6276
diff changeset
   494
		case WM_KEYDOWN: {
58822e8a88b6 (svn r9086) -Feature/Fix: [win32] Rewrite keyboard input and handle all keypresses in a WM_CHAR event. This saves us from doing translation (ToUnicode[Ex], ToAscii[Ex]), and we get free IME-input support as a plus.
Darkvater
parents: 6276
diff changeset
   495
			keycode = MapWindowsKey(wParam);
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   496
6277
58822e8a88b6 (svn r9086) -Feature/Fix: [win32] Rewrite keyboard input and handle all keypresses in a WM_CHAR event. This saves us from doing translation (ToUnicode[Ex], ToAscii[Ex]), and we get free IME-input support as a plus.
Darkvater
parents: 6276
diff changeset
   497
			/* Silently drop all text messages as those will be handled by WM_CHAR
58822e8a88b6 (svn r9086) -Feature/Fix: [win32] Rewrite keyboard input and handle all keypresses in a WM_CHAR event. This saves us from doing translation (ToUnicode[Ex], ToAscii[Ex]), and we get free IME-input support as a plus.
Darkvater
parents: 6276
diff changeset
   498
			 * WM_KEYDOWN only handles CTRL+ commands and special keys like VK_LEFT, etc. */
58822e8a88b6 (svn r9086) -Feature/Fix: [win32] Rewrite keyboard input and handle all keypresses in a WM_CHAR event. This saves us from doing translation (ToUnicode[Ex], ToAscii[Ex]), and we get free IME-input support as a plus.
Darkvater
parents: 6276
diff changeset
   499
			if (keycode == 0 || (keycode > WKC_PAUSE && GB(keycode, 13, 4) == 0)) return 0;
58822e8a88b6 (svn r9086) -Feature/Fix: [win32] Rewrite keyboard input and handle all keypresses in a WM_CHAR event. This saves us from doing translation (ToUnicode[Ex], ToAscii[Ex]), and we get free IME-input support as a plus.
Darkvater
parents: 6276
diff changeset
   500
7541
8086db74ec5b (svn r11061) -Fix [FS#1086]: [win32] some keys were handled twice
glx
parents: 7454
diff changeset
   501
			/* Keys handled in WM_CHAR */
8086db74ec5b (svn r11061) -Fix [FS#1086]: [win32] some keys were handled twice
glx
parents: 7454
diff changeset
   502
			if ((uint)(GB(keycode, 0, 12) - WKC_NUM_DIV) <= WKC_MINUS - WKC_NUM_DIV) return 0;
8086db74ec5b (svn r11061) -Fix [FS#1086]: [win32] some keys were handled twice
glx
parents: 7454
diff changeset
   503
6277
58822e8a88b6 (svn r9086) -Feature/Fix: [win32] Rewrite keyboard input and handle all keypresses in a WM_CHAR event. This saves us from doing translation (ToUnicode[Ex], ToAscii[Ex]), and we get free IME-input support as a plus.
Darkvater
parents: 6276
diff changeset
   504
			HandleKeypress(0 | (keycode << 16));
58822e8a88b6 (svn r9086) -Feature/Fix: [win32] Rewrite keyboard input and handle all keypresses in a WM_CHAR event. This saves us from doing translation (ToUnicode[Ex], ToAscii[Ex]), and we get free IME-input support as a plus.
Darkvater
parents: 6276
diff changeset
   505
			return 0;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   506
		}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   507
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   508
		case WM_SYSKEYDOWN: /* user presses F10 or Alt, both activating the title-menu */
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   509
			switch (wParam) {
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   510
				case VK_RETURN:
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   511
				case 'F': /* Full Screen on ALT + ENTER/F */
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   512
					ToggleFullScreen(!_wnd.fullscreen);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   513
					return 0;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   514
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   515
				case VK_MENU: /* Just ALT */
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   516
					return 0; // do nothing
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   517
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   518
				case VK_F10: /* F10, ignore activation of menu */
5086
386ba9fe0621 (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5076
diff changeset
   519
					HandleKeypress(MapWindowsKey(wParam) << 16);
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   520
					return 0;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   521
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   522
				default: /* ALT in combination with something else */
5086
386ba9fe0621 (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5076
diff changeset
   523
					HandleKeypress(MapWindowsKey(wParam) << 16);
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   524
					break;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   525
			}
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   526
			break;
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   527
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   528
		case WM_SIZE:
7126
6c1f274be84e (svn r10399) -Fix (FS#962): [Windows] _wnd.has_focus was not properly set after using ALT-TAB
glx
parents: 7019
diff changeset
   529
			if (wParam != SIZE_MINIMIZED) {
5019
9046723a0878 (svn r7060) -Fix (r5874): Restore of window maximized state not always working (Mart3p) . Remember
Darkvater
parents: 4840
diff changeset
   530
				/* Set maximized flag when we maximize (obviously), but also when we
9046723a0878 (svn r7060) -Fix (r5874): Restore of window maximized state not always working (Mart3p) . Remember
Darkvater
parents: 4840
diff changeset
   531
				 * switched to fullscreen from a maximized state */
9046723a0878 (svn r7060) -Fix (r5874): Restore of window maximized state not always working (Mart3p) . Remember
Darkvater
parents: 4840
diff changeset
   532
				_window_maximize = (wParam == SIZE_MAXIMIZED || (_window_maximize && _fullscreen));
5020
e2564f4400b7 (svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents: 5019
diff changeset
   533
				if (_window_maximize) {
e2564f4400b7 (svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents: 5019
diff changeset
   534
					_bck_resolution[0] = _cur_resolution[0];
e2564f4400b7 (svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents: 5019
diff changeset
   535
					_bck_resolution[1] = _cur_resolution[1];
e2564f4400b7 (svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents: 5019
diff changeset
   536
				}
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   537
				ClientSizeChanged(LOWORD(lParam), HIWORD(lParam));
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   538
			}
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   539
			return 0;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   540
5758
4b10d28b54c7 (svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents: 5587
diff changeset
   541
#if !defined(WINCE)
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   542
		case WM_SIZING: {
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   543
			RECT* r = (RECT*)lParam;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   544
			RECT r2;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   545
			int w, h;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   546
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   547
			SetRect(&r2, 0, 0, 0, 0);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   548
			AdjustWindowRect(&r2, GetWindowLong(hwnd, GWL_STYLE), FALSE);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   549
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   550
			w = r->right - r->left - (r2.right - r2.left);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   551
			h = r->bottom - r->top - (r2.bottom - r2.top);
8985
6461e5c6d6e4 (svn r12779) -Codechange: remove a few constants from openttd.h.
rubidium
parents: 8969
diff changeset
   552
			w = max(w, 64);
6461e5c6d6e4 (svn r12779) -Codechange: remove a few constants from openttd.h.
rubidium
parents: 8969
diff changeset
   553
			h = max(h, 64);
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   554
			SetRect(&r2, 0, 0, w, h);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   555
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   556
			AdjustWindowRect(&r2, GetWindowLong(hwnd, GWL_STYLE), FALSE);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   557
			w = r2.right - r2.left;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   558
			h = r2.bottom - r2.top;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   559
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   560
			switch (wParam) {
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   561
				case WMSZ_BOTTOM:
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   562
					r->bottom = r->top + h;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   563
					break;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   564
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   565
				case WMSZ_BOTTOMLEFT:
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   566
					r->bottom = r->top + h;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   567
					r->left = r->right - w;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   568
					break;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   569
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   570
				case WMSZ_BOTTOMRIGHT:
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   571
					r->bottom = r->top + h;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   572
					r->right = r->left + w;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   573
					break;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   574
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   575
				case WMSZ_LEFT:
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   576
					r->left = r->right - w;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   577
					break;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   578
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   579
				case WMSZ_RIGHT:
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   580
					r->right = r->left + w;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   581
					break;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   582
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   583
				case WMSZ_TOP:
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   584
					r->top = r->bottom - h;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   585
					break;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   586
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   587
				case WMSZ_TOPLEFT:
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   588
					r->top = r->bottom - h;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   589
					r->left = r->right - w;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   590
					break;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   591
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   592
				case WMSZ_TOPRIGHT:
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   593
					r->top = r->bottom - h;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   594
					r->right = r->left + w;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   595
					break;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   596
			}
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   597
			return TRUE;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   598
		}
5759
213aacbe7b07 (svn r8310) -Fix r8309: it is wise to put #endifs in the right place ;)
truelight
parents: 5758
diff changeset
   599
#endif
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   600
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   601
// needed for wheel
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   602
#if !defined(WM_MOUSEWHEEL)
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   603
# define WM_MOUSEWHEEL 0x020A
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   604
#endif  //WM_MOUSEWHEEL
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   605
#if !defined(GET_WHEEL_DELTA_WPARAM)
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   606
# define GET_WHEEL_DELTA_WPARAM(wparam) ((short)HIWORD(wparam))
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   607
#endif  //GET_WHEEL_DELTA_WPARAM
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   608
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   609
		case WM_MOUSEWHEEL: {
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   610
			int delta = GET_WHEEL_DELTA_WPARAM(wParam);
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   611
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   612
			if (delta < 0) {
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   613
				_cursor.wheel++;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   614
			} else if (delta > 0) {
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   615
				_cursor.wheel--;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   616
			}
5090
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
   617
			HandleMouseEvents();
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   618
			return 0;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   619
		}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   620
7126
6c1f274be84e (svn r10399) -Fix (FS#962): [Windows] _wnd.has_focus was not properly set after using ALT-TAB
glx
parents: 7019
diff changeset
   621
		case WM_SETFOCUS:
6c1f274be84e (svn r10399) -Fix (FS#962): [Windows] _wnd.has_focus was not properly set after using ALT-TAB
glx
parents: 7019
diff changeset
   622
			_wnd.has_focus = true;
6c1f274be84e (svn r10399) -Fix (FS#962): [Windows] _wnd.has_focus was not properly set after using ALT-TAB
glx
parents: 7019
diff changeset
   623
			break;
6c1f274be84e (svn r10399) -Fix (FS#962): [Windows] _wnd.has_focus was not properly set after using ALT-TAB
glx
parents: 7019
diff changeset
   624
6c1f274be84e (svn r10399) -Fix (FS#962): [Windows] _wnd.has_focus was not properly set after using ALT-TAB
glx
parents: 7019
diff changeset
   625
		case WM_KILLFOCUS:
6c1f274be84e (svn r10399) -Fix (FS#962): [Windows] _wnd.has_focus was not properly set after using ALT-TAB
glx
parents: 7019
diff changeset
   626
			_wnd.has_focus = false;
6c1f274be84e (svn r10399) -Fix (FS#962): [Windows] _wnd.has_focus was not properly set after using ALT-TAB
glx
parents: 7019
diff changeset
   627
			break;
6c1f274be84e (svn r10399) -Fix (FS#962): [Windows] _wnd.has_focus was not properly set after using ALT-TAB
glx
parents: 7019
diff changeset
   628
6933
252b74991781 (svn r10186) -Fix (FS#876): don't mess desktop when using alt-tab (win32)
glx
parents: 6878
diff changeset
   629
#if !defined(WINCE)
7126
6c1f274be84e (svn r10399) -Fix (FS#962): [Windows] _wnd.has_focus was not properly set after using ALT-TAB
glx
parents: 7019
diff changeset
   630
		case WM_ACTIVATE: {
7430
73c42fa0119f (svn r10835) -Fix [FS#998] (r10399): don't try to minimise or restore the window when closing openttd
glx
parents: 7429
diff changeset
   631
			/* Don't do anything if we are closing openttd */
73c42fa0119f (svn r10835) -Fix [FS#998] (r10399): don't try to minimise or restore the window when closing openttd
glx
parents: 7429
diff changeset
   632
			if (_exit_game) break;
73c42fa0119f (svn r10835) -Fix [FS#998] (r10399): don't try to minimise or restore the window when closing openttd
glx
parents: 7429
diff changeset
   633
7126
6c1f274be84e (svn r10399) -Fix (FS#962): [Windows] _wnd.has_focus was not properly set after using ALT-TAB
glx
parents: 7019
diff changeset
   634
			bool active = (LOWORD(wParam) != WA_INACTIVE);
6c1f274be84e (svn r10399) -Fix (FS#962): [Windows] _wnd.has_focus was not properly set after using ALT-TAB
glx
parents: 7019
diff changeset
   635
			bool minimized = (HIWORD(wParam) != 0);
6933
252b74991781 (svn r10186) -Fix (FS#876): don't mess desktop when using alt-tab (win32)
glx
parents: 6878
diff changeset
   636
			if (_wnd.fullscreen) {
7126
6c1f274be84e (svn r10399) -Fix (FS#962): [Windows] _wnd.has_focus was not properly set after using ALT-TAB
glx
parents: 7019
diff changeset
   637
				if (active && minimized) {
6933
252b74991781 (svn r10186) -Fix (FS#876): don't mess desktop when using alt-tab (win32)
glx
parents: 6878
diff changeset
   638
					/* Restore the game window */
252b74991781 (svn r10186) -Fix (FS#876): don't mess desktop when using alt-tab (win32)
glx
parents: 6878
diff changeset
   639
					ShowWindow(hwnd, SW_RESTORE);
6995
dbcd37808b05 (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 6987
diff changeset
   640
					MakeWindow(true);
7126
6c1f274be84e (svn r10399) -Fix (FS#962): [Windows] _wnd.has_focus was not properly set after using ALT-TAB
glx
parents: 7019
diff changeset
   641
				} else if (!active && !minimized) {
6933
252b74991781 (svn r10186) -Fix (FS#876): don't mess desktop when using alt-tab (win32)
glx
parents: 6878
diff changeset
   642
					/* Minimise the window and restore desktop */
252b74991781 (svn r10186) -Fix (FS#876): don't mess desktop when using alt-tab (win32)
glx
parents: 6878
diff changeset
   643
					ShowWindow(hwnd, SW_MINIMIZE);
252b74991781 (svn r10186) -Fix (FS#876): don't mess desktop when using alt-tab (win32)
glx
parents: 6878
diff changeset
   644
					ChangeDisplaySettings(NULL, 0);
252b74991781 (svn r10186) -Fix (FS#876): don't mess desktop when using alt-tab (win32)
glx
parents: 6878
diff changeset
   645
				}
252b74991781 (svn r10186) -Fix (FS#876): don't mess desktop when using alt-tab (win32)
glx
parents: 6878
diff changeset
   646
			}
7409
44932e96a196 (svn r10782) -Fix: wrongly places #endif a long time ago broke WinCE compiling for sure
truelight
parents: 7408
diff changeset
   647
		} break;
44932e96a196 (svn r10782) -Fix: wrongly places #endif a long time ago broke WinCE compiling for sure
truelight
parents: 7408
diff changeset
   648
#endif
7126
6c1f274be84e (svn r10399) -Fix (FS#962): [Windows] _wnd.has_focus was not properly set after using ALT-TAB
glx
parents: 7019
diff changeset
   649
	}
6c1f274be84e (svn r10399) -Fix (FS#962): [Windows] _wnd.has_focus was not properly set after using ALT-TAB
glx
parents: 7019
diff changeset
   650
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   651
	return DefWindowProc(hwnd, msg, wParam, lParam);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   652
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   653
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
   654
static void RegisterWndClass()
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   655
{
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   656
	static bool registered = false;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   657
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   658
	if (!registered) {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   659
		HINSTANCE hinst = GetModuleHandle(NULL);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   660
		WNDCLASS wnd = {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   661
			0,
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   662
			WndProcGdi,
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   663
			0,
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   664
			0,
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   665
			hinst,
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   666
			LoadIcon(hinst, MAKEINTRESOURCE(100)),
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   667
			LoadCursor(NULL, IDC_ARROW),
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   668
			0,
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   669
			0,
5168
e206899169c4 (svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents: 5112
diff changeset
   670
			_T("OTTD")
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   671
		};
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   672
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   673
		registered = true;
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   674
		if (!RegisterClass(&wnd)) error("RegisterClass failed");
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   675
	}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   676
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   677
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   678
static bool AllocateDibSection(int w, int h)
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   679
{
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   680
	BITMAPINFO *bi;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   681
	HDC dc;
6878
5cefd3ac59c7 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 6615
diff changeset
   682
	int bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth();
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   683
8985
6461e5c6d6e4 (svn r12779) -Codechange: remove a few constants from openttd.h.
rubidium
parents: 8969
diff changeset
   684
	w = max(w, 64);
6461e5c6d6e4 (svn r12779) -Codechange: remove a few constants from openttd.h.
rubidium
parents: 8969
diff changeset
   685
	h = max(h, 64);
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   686
6878
5cefd3ac59c7 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 6615
diff changeset
   687
	if (bpp == 0) error("Can't use a blitter that blits 0 bpp for normal visuals");
5cefd3ac59c7 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 6615
diff changeset
   688
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   689
	if (w == _screen.width && h == _screen.height)
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   690
		return false;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   691
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   692
	_screen.width = w;
7927
3a3289a049f9 (svn r11480) -Codechange: Rename the function ALIGN fitting to the naming style
skidd13
parents: 7922
diff changeset
   693
	_screen.pitch = (bpp == 8) ? Align(w, 4) : w;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   694
	_screen.height = h;
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6277
diff changeset
   695
	bi = (BITMAPINFO*)alloca(sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256);
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6277
diff changeset
   696
	memset(bi, 0, sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256);
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   697
	bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   698
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   699
	bi->bmiHeader.biWidth = _wnd.width = w;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   700
	bi->bmiHeader.biHeight = -(_wnd.height = h);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   701
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   702
	bi->bmiHeader.biPlanes = 1;
6878
5cefd3ac59c7 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 6615
diff changeset
   703
	bi->bmiHeader.biBitCount = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth();
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   704
	bi->bmiHeader.biCompression = BI_RGB;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   705
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   706
	if (_wnd.dib_sect) DeleteObject(_wnd.dib_sect);
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   707
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   708
	dc = GetDC(0);
6878
5cefd3ac59c7 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 6615
diff changeset
   709
	_wnd.dib_sect = CreateDIBSection(dc, bi, DIB_RGB_COLORS, (VOID**)&_wnd.buffer_bits, NULL, 0);
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   710
	if (_wnd.dib_sect == NULL) error("CreateDIBSection failed");
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   711
	ReleaseDC(0, dc);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   712
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   713
	return true;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   714
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   715
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   716
static const uint16 default_resolutions[][2] = {
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   717
	{  640,  480 },
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   718
	{  800,  600 },
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   719
	{ 1024,  768 },
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   720
	{ 1152,  864 },
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   721
	{ 1280,  800 },
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   722
	{ 1280,  960 },
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   723
	{ 1280, 1024 },
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   724
	{ 1400, 1050 },
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   725
	{ 1600, 1200 },
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   726
	{ 1680, 1050 },
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   727
	{ 1920, 1200 }
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   728
};
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   729
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
   730
static void FindResolutions()
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   731
{
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3802
diff changeset
   732
	uint n = 0;
5758
4b10d28b54c7 (svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents: 5587
diff changeset
   733
#if defined(WINCE)
4b10d28b54c7 (svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents: 5587
diff changeset
   734
	/* EnumDisplaySettingsW is only supported in CE 4.2+ */
4b10d28b54c7 (svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents: 5587
diff changeset
   735
	/* XXX -- One might argue that we assume 4.2+ on every system. Then we can use this function safely */
4b10d28b54c7 (svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents: 5587
diff changeset
   736
#else
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3802
diff changeset
   737
	uint i;
5169
cd4113ed34f7 (svn r7279) -Codechange: [win32] Add Windows95/98 support by using MSLU. Only workaround is that the
Darkvater
parents: 5168
diff changeset
   738
	DEVMODEA dm;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   739
5169
cd4113ed34f7 (svn r7279) -Codechange: [win32] Add Windows95/98 support by using MSLU. Only workaround is that the
Darkvater
parents: 5168
diff changeset
   740
	/* XXX - EnumDisplaySettingsW crashes with unicows.dll on Windows95
cd4113ed34f7 (svn r7279) -Codechange: [win32] Add Windows95/98 support by using MSLU. Only workaround is that the
Darkvater
parents: 5168
diff changeset
   741
	 * Doesn't really matter since we don't pass a string anyways, but still
cd4113ed34f7 (svn r7279) -Codechange: [win32] Add Windows95/98 support by using MSLU. Only workaround is that the
Darkvater
parents: 5168
diff changeset
   742
	 * a letdown */
cd4113ed34f7 (svn r7279) -Codechange: [win32] Add Windows95/98 support by using MSLU. Only workaround is that the
Darkvater
parents: 5168
diff changeset
   743
	for (i = 0; EnumDisplaySettingsA(NULL, i, &dm) != 0; i++) {
8985
6461e5c6d6e4 (svn r12779) -Codechange: remove a few constants from openttd.h.
rubidium
parents: 8969
diff changeset
   744
		if (dm.dmBitsPerPel == BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() &&
6461e5c6d6e4 (svn r12779) -Codechange: remove a few constants from openttd.h.
rubidium
parents: 8969
diff changeset
   745
				dm.dmPelsWidth >= 640 && dm.dmPelsHeight >= 480) {
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3802
diff changeset
   746
			uint j;
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3802
diff changeset
   747
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   748
			for (j = 0; j < n; j++) {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   749
				if (_resolutions[j][0] == dm.dmPelsWidth && _resolutions[j][1] == dm.dmPelsHeight) break;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   750
			}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   751
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   752
			/* In the previous loop we have checked already existing/added resolutions if
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   753
			 * they are the same as the new ones. If this is not the case (j == n); we have
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   754
			 * looped all and found none, add the new one to the list. If we have reached the
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   755
			 * maximum amount of resolutions, then quit querying the display */
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   756
			if (j == n) {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   757
				_resolutions[j][0] = dm.dmPelsWidth;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   758
				_resolutions[j][1] = dm.dmPelsHeight;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   759
				if (++n == lengthof(_resolutions)) break;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   760
			}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   761
		}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   762
	}
5758
4b10d28b54c7 (svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents: 5587
diff changeset
   763
#endif
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   764
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   765
	/* We have found no resolutions, show the default list */
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   766
	if (n == 0) {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   767
		memcpy(_resolutions, default_resolutions, sizeof(default_resolutions));
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   768
		n = lengthof(default_resolutions);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   769
	}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   770
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   771
	_num_resolutions = n;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   772
	SortResolutions(_num_resolutions);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   773
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   774
7170
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7126
diff changeset
   775
static FVideoDriver_Win32 iFVideoDriver_Win32;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   776
7170
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7126
diff changeset
   777
const char *VideoDriver_Win32::Start(const char * const *parm)
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   778
{
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   779
	memset(&_wnd, 0, sizeof(_wnd));
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   780
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   781
	RegisterWndClass();
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   782
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   783
	MakePalette();
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   784
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   785
	FindResolutions();
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   786
7408
605b333582d5 (svn r10781) -Fix: ported more pieces to WinCE, so it compiles a bit more
truelight
parents: 7392
diff changeset
   787
	DEBUG(driver, 2, "Resolution for display: %dx%d", _cur_resolution[0], _cur_resolution[1]);
605b333582d5 (svn r10781) -Fix: ported more pieces to WinCE, so it compiles a bit more
truelight
parents: 7392
diff changeset
   788
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   789
	// fullscreen uses those
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   790
	_wnd.width_org = _cur_resolution[0];
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   791
	_wnd.height_org = _cur_resolution[1];
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   792
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   793
	AllocateDibSection(_cur_resolution[0], _cur_resolution[1]);
8985
6461e5c6d6e4 (svn r12779) -Codechange: remove a few constants from openttd.h.
rubidium
parents: 8969
diff changeset
   794
	MakeWindow(_fullscreen);
6461e5c6d6e4 (svn r12779) -Codechange: remove a few constants from openttd.h.
rubidium
parents: 8969
diff changeset
   795
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   796
	MarkWholeScreenDirty();
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   797
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   798
	return NULL;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   799
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   800
7170
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7126
diff changeset
   801
void VideoDriver_Win32::Stop()
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   802
{
3285
50f77357b94a (svn r3999) - Fix: [win32] Change the order of DestroyWindow and ChangeDisplay. On some machines a sizechange messagequeue is handled before sending WM_DISPLAYCHANGE resulting in an improper resolution written to the configuration file when exiting from fullscreen. (Frostregen)
Darkvater
parents: 3051
diff changeset
   803
	DeleteObject(_wnd.gdi_palette);
50f77357b94a (svn r3999) - Fix: [win32] Change the order of DestroyWindow and ChangeDisplay. On some machines a sizechange messagequeue is handled before sending WM_DISPLAYCHANGE resulting in an improper resolution written to the configuration file when exiting from fullscreen. (Frostregen)
Darkvater
parents: 3051
diff changeset
   804
	DeleteObject(_wnd.dib_sect);
7429
9147a1f31a4e (svn r10834) -Revert (part of r10833): something too much was committed :(
rubidium
parents: 7428
diff changeset
   805
	DestroyWindow(_wnd.main_wnd);
3285
50f77357b94a (svn r3999) - Fix: [win32] Change the order of DestroyWindow and ChangeDisplay. On some machines a sizechange messagequeue is handled before sending WM_DISPLAYCHANGE resulting in an improper resolution written to the configuration file when exiting from fullscreen. (Frostregen)
Darkvater
parents: 3051
diff changeset
   806
5758
4b10d28b54c7 (svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents: 5587
diff changeset
   807
#if !defined(WINCE)
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   808
	if (_wnd.fullscreen) ChangeDisplaySettings(NULL, 0);
5758
4b10d28b54c7 (svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents: 5587
diff changeset
   809
#endif
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   810
	MyShowCursor(true);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   811
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   812
7170
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7126
diff changeset
   813
void VideoDriver_Win32::MakeDirty(int left, int top, int width, int height)
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   814
{
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   815
	RECT r = { left, top, left + width, top + height };
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   816
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   817
	InvalidateRect(_wnd.main_wnd, &r, FALSE);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   818
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   819
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
   820
static void CheckPaletteAnim()
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   821
{
6962
3e925700b4c8 (svn r10218) -Fix r10216: more compile errors
glx
parents: 6961
diff changeset
   822
	if (_pal_count_dirty == 0)
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   823
		return;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   824
	InvalidateRect(_wnd.main_wnd, NULL, FALSE);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   825
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   826
7170
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7126
diff changeset
   827
void VideoDriver_Win32::MainLoop()
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   828
{
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   829
	MSG mesg;
5581
cf2b8ba6556b (svn r8028) -Fix: overflow of ticks was not handled properly, possibly resulting a non-reacting gameserver/gameclient.
rubidium
parents: 5475
diff changeset
   830
	uint32 cur_ticks = GetTickCount();
7018
71e174292e42 (svn r10276) -Codechange: made a counter based on milliseconds and independent of the game-state to base double-click and TGP Generation Process on
truelight
parents: 6999
diff changeset
   831
	uint32 last_cur_ticks = cur_ticks;
5581
cf2b8ba6556b (svn r8028) -Fix: overflow of ticks was not handled properly, possibly resulting a non-reacting gameserver/gameclient.
rubidium
parents: 5475
diff changeset
   832
	uint32 next_tick = cur_ticks + 30;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   833
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   834
	_wnd.running = true;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   835
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2773
diff changeset
   836
	for (;;) {
5581
cf2b8ba6556b (svn r8028) -Fix: overflow of ticks was not handled properly, possibly resulting a non-reacting gameserver/gameclient.
rubidium
parents: 5475
diff changeset
   837
		uint32 prev_cur_ticks = cur_ticks; // to check for wrapping
cf2b8ba6556b (svn r8028) -Fix: overflow of ticks was not handled properly, possibly resulting a non-reacting gameserver/gameclient.
rubidium
parents: 5475
diff changeset
   838
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   839
		while (PeekMessage(&mesg, NULL, 0, 0, PM_REMOVE)) {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   840
			InteractiveRandom(); // randomness
6277
58822e8a88b6 (svn r9086) -Feature/Fix: [win32] Rewrite keyboard input and handle all keypresses in a WM_CHAR event. This saves us from doing translation (ToUnicode[Ex], ToAscii[Ex]), and we get free IME-input support as a plus.
Darkvater
parents: 6276
diff changeset
   841
			TranslateMessage(&mesg);
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   842
			DispatchMessage(&mesg);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   843
		}
2228
93cdde0f85ba (svn r2748) Remove unused cruft from the main loop
tron
parents: 2208
diff changeset
   844
		if (_exit_game) return;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   845
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   846
#if defined(_DEBUG)
5089
67c761427921 (svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents: 5086
diff changeset
   847
		if (_wnd.has_focus && GetAsyncKeyState(VK_SHIFT) < 0 &&
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   848
#else
5089
67c761427921 (svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents: 5086
diff changeset
   849
		/* Speed up using TAB, but disable for ALT+TAB of course */
67c761427921 (svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents: 5086
diff changeset
   850
		if (_wnd.has_focus && GetAsyncKeyState(VK_TAB) < 0 && GetAsyncKeyState(VK_MENU) >= 0 &&
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   851
#endif
5089
67c761427921 (svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents: 5086
diff changeset
   852
			  !_networking && _game_mode != GM_MENU) {
67c761427921 (svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents: 5086
diff changeset
   853
			_fast_forward |= 2;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
   854
		} else if (_fast_forward & 2) {
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   855
			_fast_forward = 0;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
   856
		}
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   857
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   858
		cur_ticks = GetTickCount();
6231
ff7454d35935 (svn r9034) -Codechange: renamed _pause to _pause_game, as some targets already have
truelight
parents: 6205
diff changeset
   859
		if (cur_ticks >= next_tick || (_fast_forward && !_pause_game) || cur_ticks < prev_cur_ticks) {
7019
09e090048a59 (svn r10278) -Fix r10276: make the _realtime_tick less demanding on the CPU
truelight
parents: 7018
diff changeset
   860
			_realtime_tick += cur_ticks - last_cur_ticks;
09e090048a59 (svn r10278) -Fix r10276: make the _realtime_tick less demanding on the CPU
truelight
parents: 7018
diff changeset
   861
			last_cur_ticks = cur_ticks;
5581
cf2b8ba6556b (svn r8028) -Fix: overflow of ticks was not handled properly, possibly resulting a non-reacting gameserver/gameclient.
rubidium
parents: 5475
diff changeset
   862
			next_tick = cur_ticks + 30;
8586
cb0e7e00f1d2 (svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents: 8437
diff changeset
   863
cb0e7e00f1d2 (svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents: 8437
diff changeset
   864
			bool old_ctrl_pressed = _ctrl_pressed;
cb0e7e00f1d2 (svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents: 8437
diff changeset
   865
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   866
			_ctrl_pressed = _wnd.has_focus && GetAsyncKeyState(VK_CONTROL)<0;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   867
			_shift_pressed = _wnd.has_focus && GetAsyncKeyState(VK_SHIFT)<0;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   868
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   869
			// determine which directional keys are down
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   870
			if (_wnd.has_focus) {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   871
				_dirkeys =
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   872
					(GetAsyncKeyState(VK_LEFT) < 0 ? 1 : 0) +
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   873
					(GetAsyncKeyState(VK_UP) < 0 ? 2 : 0) +
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   874
					(GetAsyncKeyState(VK_RIGHT) < 0 ? 4 : 0) +
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   875
					(GetAsyncKeyState(VK_DOWN) < 0 ? 8 : 0);
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
   876
			} else {
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   877
				_dirkeys = 0;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
   878
			}
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   879
8586
cb0e7e00f1d2 (svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents: 8437
diff changeset
   880
			if (old_ctrl_pressed != _ctrl_pressed) HandleCtrlChanged();
cb0e7e00f1d2 (svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents: 8437
diff changeset
   881
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   882
			GameLoop();
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   883
			_cursor.delta.x = _cursor.delta.y = 0;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   884
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
   885
			if (_force_full_redraw) MarkWholeScreenDirty();
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   886
5758
4b10d28b54c7 (svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents: 5587
diff changeset
   887
#if !defined(WINCE)
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   888
			GdiFlush();
5758
4b10d28b54c7 (svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents: 5587
diff changeset
   889
#endif
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   890
			_screen.dst_ptr = _wnd.buffer_bits;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   891
			UpdateWindows();
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   892
			CheckPaletteAnim();
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   893
		} else {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   894
			Sleep(1);
5758
4b10d28b54c7 (svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents: 5587
diff changeset
   895
#if !defined(WINCE)
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   896
			GdiFlush();
5758
4b10d28b54c7 (svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents: 5587
diff changeset
   897
#endif
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   898
			_screen.dst_ptr = _wnd.buffer_bits;
7454
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7430
diff changeset
   899
			DrawChatMessage();
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   900
			DrawMouseCursor();
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   901
		}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   902
	}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   903
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   904
7170
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7126
diff changeset
   905
bool VideoDriver_Win32::ChangeResolution(int w, int h)
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   906
{
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   907
	_wnd.width = _wnd.width_org = w;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   908
	_wnd.height = _wnd.height_org = h;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   909
8171
3fb9d1f8ac3b (svn r11734) -Change: Allow ToggleFullScreen to return the result of the operation' attempt. Previously, only visual clues were available.
belugas
parents: 8131
diff changeset
   910
	return MakeWindow(_fullscreen); // _wnd.fullscreen screws up ingame resolution switching
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   911
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   912
8171
3fb9d1f8ac3b (svn r11734) -Change: Allow ToggleFullScreen to return the result of the operation' attempt. Previously, only visual clues were available.
belugas
parents: 8131
diff changeset
   913
bool VideoDriver_Win32::ToggleFullscreen(bool full_screen)
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   914
{
8171
3fb9d1f8ac3b (svn r11734) -Change: Allow ToggleFullScreen to return the result of the operation' attempt. Previously, only visual clues were available.
belugas
parents: 8131
diff changeset
   915
	return MakeWindow(full_screen);
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   916
}