src/video/win32_v.cpp
author truelight
Thu, 21 Jun 2007 16:53:57 +0000
changeset 7495 3bed6c98b8f3
parent 7491 8eda96f8600a
child 7514 98a024616010
permissions -rw-r--r--
(svn r10255) -Codechange: remove some old debug code nobody was using anymore
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2174
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2174
diff changeset
     2
2189
d240b9097139 (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
     3
#include "../stdafx.h"
d240b9097139 (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
     4
#include "../openttd.h"
d240b9097139 (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 "../functions.h"
d240b9097139 (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 "../gfx.h"
d240b9097139 (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
     7
#include "../macros.h"
5720
cc0ceeafaa55 (svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents: 5565
diff changeset
     8
#include "../network/network.h"
2189
d240b9097139 (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
     9
#include "../variables.h"
2207
40c928fbde8a (svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents: 2189
diff changeset
    10
#include "../win32.h"
2189
d240b9097139 (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
    11
#include "../window.h"
7435
8105b989409a (svn r10192) -Fix r10190: forgot to change the includes of win32 and cocoa video-driver
truelight
parents: 7433
diff changeset
    12
#include "../blitter/factory.hpp"
2189
d240b9097139 (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
    13
#include "win32_v.h"
2171
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents: 2163
diff changeset
    14
#include <windows.h>
5168
10a8dc9788d7 (svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents: 5112
diff changeset
    15
#include <tchar.h>
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    17
static struct {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    18
	HWND main_wnd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    19
	HBITMAP dib_sect;
7374
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7111
diff changeset
    20
	void *buffer_bits;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
	HPALETTE gdi_palette;
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
    22
	int width;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
    23
	int height;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
    24
	int width_org;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
    25
	int height_org;
7429
e112860fbc16 (svn r10186) -Fix (FS#876): don't mess desktop when using alt-tab (win32)
glx
parents: 7374
diff changeset
    26
	bool minimized;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
	bool fullscreen;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    28
	bool has_focus;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    29
	bool running;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    30
} _wnd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    31
3051
16f6e40c67eb (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
    32
bool _force_full_redraw;
4258
3ac20963213d (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
    33
bool _window_maximize;
3051
16f6e40c67eb (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
    34
uint _display_hz;
16f6e40c67eb (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
uint _fullscreen_bpp;
5020
a679bc02c88d (svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents: 5019
diff changeset
    36
static uint16 _bck_resolution[2];
6577
ee768d653dd0 (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: 6574
diff changeset
    37
#if !defined(UNICODE)
ee768d653dd0 (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: 6574
diff changeset
    38
uint _codepage;
ee768d653dd0 (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: 6574
diff changeset
    39
#endif
3051
16f6e40c67eb (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
    40
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
    41
static void MakePalette()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    42
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    43
	LOGPALETTE *pal;
1468
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
    44
	uint i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    45
6987
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6603
diff changeset
    46
	pal = (LOGPALETTE*)alloca(sizeof(LOGPALETTE) + (256 - 1) * sizeof(PALETTEENTRY));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    47
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    48
	pal->palVersion = 0x300;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    49
	pal->palNumEntries = 256;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
    50
1991
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1957
diff changeset
    51
	for (i = 0; i != 256; i++) {
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1957
diff changeset
    52
		pal->palPalEntry[i].peRed   = _cur_palette[i].r;
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1957
diff changeset
    53
		pal->palPalEntry[i].peGreen = _cur_palette[i].g;
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1957
diff changeset
    54
		pal->palPalEntry[i].peBlue  = _cur_palette[i].b;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    55
		pal->palPalEntry[i].peFlags = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    56
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    57
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    58
	_wnd.gdi_palette = CreatePalette(pal);
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
    59
	if (_wnd.gdi_palette == NULL) error("CreatePalette failed!\n");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    60
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    61
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    62
static void UpdatePalette(HDC dc, uint start, uint count)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    63
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    64
	RGBQUAD rgb[256];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    65
	uint i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    66
1995
6dacb8a758a3 (svn r2501) Forgot to change part of the win32 code in r2497
tron
parents: 1991
diff changeset
    67
	for (i = 0; i != count; i++) {
6dacb8a758a3 (svn r2501) Forgot to change part of the win32 code in r2497
tron
parents: 1991
diff changeset
    68
		rgb[i].rgbRed   = _cur_palette[start + i].r;
6dacb8a758a3 (svn r2501) Forgot to change part of the win32 code in r2497
tron
parents: 1991
diff changeset
    69
		rgb[i].rgbGreen = _cur_palette[start + i].g;
6dacb8a758a3 (svn r2501) Forgot to change part of the win32 code in r2497
tron
parents: 1991
diff changeset
    70
		rgb[i].rgbBlue  = _cur_palette[start + i].b;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    71
		rgb[i].rgbReserved = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    72
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    73
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    74
	SetDIBColorTable(dc, start, count, rgb);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    75
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    76
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    77
struct VkMapping {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    78
	byte vk_from;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    79
	byte vk_count;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    80
	byte map_to;
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    81
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    82
1468
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
    83
#define AS(x, z) {x, 0, z}
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
    84
#define AM(x, y, z, w) {x, y - x, z}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    85
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    86
static const VkMapping _vk_mapping[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    87
	// Pageup stuff + up/down
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    88
	AM(VK_PRIOR,VK_DOWN, WKC_PAGEUP, WKC_DOWN),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    89
	// Map letters & digits
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    90
	AM('A','Z','A','Z'),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    91
	AM('0','9','0','9'),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    92
4434
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
    93
	AS(VK_ESCAPE,   WKC_ESC),
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
    94
	AS(VK_PAUSE,    WKC_PAUSE),
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
    95
	AS(VK_BACK,     WKC_BACKSPACE),
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
    96
	AM(VK_INSERT,   VK_DELETE, WKC_INSERT, WKC_DELETE),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    97
4434
4175805666a5 (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_SPACE,    WKC_SPACE),
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
    99
	AS(VK_RETURN,   WKC_RETURN),
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
   100
	AS(VK_TAB,      WKC_TAB),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   101
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   102
	// Function keys
4434
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
   103
	AM(VK_F1, VK_F12, WKC_F1, WKC_F12),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   104
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   105
	// Numeric part.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   106
	// What is the virtual keycode for numeric enter??
4434
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
   107
	AM(VK_NUMPAD0, VK_NUMPAD9, WKC_NUM_0, WKC_NUM_9),
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
   108
	AS(VK_DIVIDE,   WKC_NUM_DIV),
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
   109
	AS(VK_MULTIPLY, WKC_NUM_MUL),
4175805666a5 (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_SUBTRACT, WKC_NUM_MINUS),
4175805666a5 (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_ADD,      WKC_NUM_PLUS),
4175805666a5 (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_DECIMAL,  WKC_NUM_DECIMAL)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   113
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   114
1466
fd5c1d8c992a (svn r1970) Fix some warnings which Cygwin showed
tron
parents: 1403
diff changeset
   115
static uint MapWindowsKey(uint sym)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   116
{
1466
fd5c1d8c992a (svn r1970) Fix some warnings which Cygwin showed
tron
parents: 1403
diff changeset
   117
	const VkMapping *map;
fd5c1d8c992a (svn r1970) Fix some warnings which Cygwin showed
tron
parents: 1403
diff changeset
   118
	uint key = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   119
1466
fd5c1d8c992a (svn r1970) Fix some warnings which Cygwin showed
tron
parents: 1403
diff changeset
   120
	for (map = _vk_mapping; map != endof(_vk_mapping); ++map) {
fd5c1d8c992a (svn r1970) Fix some warnings which Cygwin showed
tron
parents: 1403
diff changeset
   121
		if ((uint)(sym - map->vk_from) <= map->vk_count) {
fd5c1d8c992a (svn r1970) Fix some warnings which Cygwin showed
tron
parents: 1403
diff changeset
   122
			key = sym - map->vk_from + map->map_to;
fd5c1d8c992a (svn r1970) Fix some warnings which Cygwin showed
tron
parents: 1403
diff changeset
   123
			break;
fd5c1d8c992a (svn r1970) Fix some warnings which Cygwin showed
tron
parents: 1403
diff changeset
   124
		}
fd5c1d8c992a (svn r1970) Fix some warnings which Cygwin showed
tron
parents: 1403
diff changeset
   125
	}
135
638fb31434eb (svn r136) -Feature/Fix: Console Rev #2 and WKC_BACKQUOTE this patch adds new features to the ingame console and inserts a new keymanagement for windows pcs... (sign_de)
darkvater
parents: 49
diff changeset
   126
2026
02dfa0aa2c2f (svn r2535) Tabs
tron
parents: 1995
diff changeset
   127
	if (GetAsyncKeyState(VK_SHIFT)   < 0) key |= WKC_SHIFT;
02dfa0aa2c2f (svn r2535) Tabs
tron
parents: 1995
diff changeset
   128
	if (GetAsyncKeyState(VK_CONTROL) < 0) key |= WKC_CTRL;
02dfa0aa2c2f (svn r2535) Tabs
tron
parents: 1995
diff changeset
   129
	if (GetAsyncKeyState(VK_MENU)    < 0) key |= WKC_ALT;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   130
	return key;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   131
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   132
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   133
static bool AllocateDibSection(int w, int h);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   134
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   135
static void ClientSizeChanged(int w, int h)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   136
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   137
	// allocate new dib section of the new size
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   138
	if (AllocateDibSection(w, h)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   139
		// mark all palette colors dirty
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   140
		_pal_first_dirty = 0;
7456
0c0636370335 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 7435
diff changeset
   141
		_pal_count_dirty = 255;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   142
		GameSizeChanged();
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   143
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   144
		// redraw screen
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   145
		if (_wnd.running) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   146
			_screen.dst_ptr = _wnd.buffer_bits;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   147
			UpdateWindows();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   148
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   149
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   150
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   151
2125
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2099
diff changeset
   152
#ifdef _DEBUG
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2099
diff changeset
   153
// Keep this function here..
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2099
diff changeset
   154
// It allows you to redraw the screen from within the MSVC debugger
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
   155
int RedrawScreenDebug()
2125
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2099
diff changeset
   156
{
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2099
diff changeset
   157
	HDC dc,dc2;
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2099
diff changeset
   158
	static int _fooctr;
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2099
diff changeset
   159
	HBITMAP old_bmp;
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2099
diff changeset
   160
	HPALETTE old_palette;
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2099
diff changeset
   161
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2099
diff changeset
   162
	_screen.dst_ptr = _wnd.buffer_bits;
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2099
diff changeset
   163
	UpdateWindows();
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2099
diff changeset
   164
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2099
diff changeset
   165
	dc = GetDC(_wnd.main_wnd);
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2099
diff changeset
   166
	dc2 = CreateCompatibleDC(dc);
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2099
diff changeset
   167
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   168
	old_bmp = (HBITMAP)SelectObject(dc2, _wnd.dib_sect);
2125
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2099
diff changeset
   169
	old_palette = SelectPalette(dc, _wnd.gdi_palette, FALSE);
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2099
diff changeset
   170
	BitBlt(dc, 0, 0, _wnd.width, _wnd.height, dc2, 0, 0, SRCCOPY);
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2099
diff changeset
   171
	SelectPalette(dc, old_palette, TRUE);
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2099
diff changeset
   172
	SelectObject(dc2, old_bmp);
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2099
diff changeset
   173
	DeleteDC(dc2);
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2099
diff changeset
   174
	ReleaseDC(_wnd.main_wnd, dc);
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2099
diff changeset
   175
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2099
diff changeset
   176
	return _fooctr++;
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2099
diff changeset
   177
}
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2099
diff changeset
   178
#endif
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2099
diff changeset
   179
5021
711e711f6b9a (svn r7062) -[win32] Codechange: Remove unneeded WM_MOUSEENTER event, and change mouse behaviour
Darkvater
parents: 5020
diff changeset
   180
/* Windows 95 will not have a WM_MOUSELEAVE message, so define it if needed */
3312
593789444b01 (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
   181
#if !defined(WM_MOUSELEAVE)
593789444b01 (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
   182
#define WM_MOUSELEAVE 0x02A3
593789444b01 (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
   183
#endif
593789444b01 (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
   184
#define TID_POLLMOUSE 1
593789444b01 (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
   185
#define MOUSE_POLL_DELAY 75
593789444b01 (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
   186
593789444b01 (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
   187
static void CALLBACK TrackMouseTimerProc(HWND hwnd, UINT msg, UINT event, DWORD time)
593789444b01 (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
   188
{
593789444b01 (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
   189
	RECT rc;
593789444b01 (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
   190
	POINT pt;
593789444b01 (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
   191
593789444b01 (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
   192
	/* Get the rectangle of our window and translate it to screen coordinates.
593789444b01 (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
   193
	 * Compare this with the current screen coordinates of the mouse and if it
593789444b01 (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
   194
	 * falls outside of the area or our window we have left the window. */
593789444b01 (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
   195
	GetClientRect(hwnd, &rc);
3802
72aed211db94 (svn r4810) - Fix: removed warning about strict-alias (release build)
glx
parents: 3325
diff changeset
   196
	MapWindowPoints(hwnd, HWND_DESKTOP, (LPPOINT)(LPRECT)&rc, 2);
3312
593789444b01 (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
	GetCursorPos(&pt);
593789444b01 (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
593789444b01 (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
	if (!PtInRect(&rc, pt) || (WindowFromPoint(pt) != hwnd)) {
593789444b01 (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
		KillTimer(hwnd, event);
593789444b01 (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
		PostMessage(hwnd, WM_MOUSELEAVE, 0, 0L);
593789444b01 (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
	}
593789444b01 (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
}
593789444b01 (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
7491
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   205
static void MakeWindow(bool full_screen)
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   206
{
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   207
	_fullscreen = full_screen;
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   208
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   209
	// recreate window?
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   210
	if ((full_screen || _wnd.fullscreen) && _wnd.main_wnd) {
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   211
		DestroyWindow(_wnd.main_wnd);
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   212
		_wnd.main_wnd = 0;
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   213
	}
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   214
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   215
#if defined(WINCE)
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   216
	/* WinCE is always fullscreen */
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   217
#else
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   218
	if (full_screen) {
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   219
		DEVMODE settings;
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   220
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   221
		/* Make sure we are always at least the screen-depth of the blitter */
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   222
		if (_fullscreen_bpp < BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth()) _fullscreen_bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth();
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   223
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   224
		memset(&settings, 0, sizeof(settings));
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   225
		settings.dmSize = sizeof(settings);
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   226
		settings.dmFields =
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   227
			(_fullscreen_bpp != 0 ? DM_BITSPERPEL : 0) |
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   228
			DM_PELSWIDTH |
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   229
			DM_PELSHEIGHT |
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   230
			(_display_hz != 0 ? DM_DISPLAYFREQUENCY : 0);
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   231
		settings.dmBitsPerPel = _fullscreen_bpp;
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   232
		settings.dmPelsWidth  = _wnd.width_org;
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   233
		settings.dmPelsHeight = _wnd.height_org;
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   234
		settings.dmDisplayFrequency = _display_hz;
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   235
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   236
		if (ChangeDisplaySettings(&settings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) {
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   237
			MakeWindow(false);
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   238
			return;
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   239
		}
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   240
	} else if (_wnd.fullscreen) {
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   241
		// restore display?
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   242
		ChangeDisplaySettings(NULL, 0);
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   243
	}
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   244
#endif
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   245
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   246
	{
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   247
		RECT r;
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   248
		DWORD style, showstyle;
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   249
		int x, y, w, h;
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   250
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   251
		showstyle = SW_SHOWNORMAL;
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   252
		_wnd.fullscreen = full_screen;
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   253
		if (_wnd.fullscreen) {
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   254
			style = WS_POPUP;
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   255
			SetRect(&r, 0, 0, _wnd.width_org, _wnd.height_org);
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   256
		} else {
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   257
			style = WS_OVERLAPPEDWINDOW;
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   258
			/* On window creation, check if we were in maximize mode before */
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   259
			if (_window_maximize) showstyle = SW_SHOWMAXIMIZED;
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   260
			SetRect(&r, 0, 0, _wnd.width, _wnd.height);
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   261
		}
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   262
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   263
#if !defined(WINCE)
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   264
		AdjustWindowRect(&r, style, FALSE);
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   265
#endif
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   266
		w = r.right - r.left;
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   267
		h = r.bottom - r.top;
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   268
		x = (GetSystemMetrics(SM_CXSCREEN) - w) / 2;
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   269
		y = (GetSystemMetrics(SM_CYSCREEN) - h) / 2;
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   270
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   271
		if (_wnd.main_wnd) {
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   272
			ShowWindow(_wnd.main_wnd, SW_SHOWNORMAL); // remove maximize-flag
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   273
			SetWindowPos(_wnd.main_wnd, 0, x, y, w, h, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   274
		} else {
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   275
			extern const char _openttd_revision[];
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   276
			TCHAR Windowtitle[50];
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   277
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   278
			_sntprintf(Windowtitle, sizeof(Windowtitle), _T("OpenTTD %s"), MB_TO_WIDE(_openttd_revision));
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   279
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   280
			_wnd.main_wnd = CreateWindow(_T("OTTD"), Windowtitle, style, x, y, w, h, 0, 0, GetModuleHandle(NULL), 0);
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   281
			if (_wnd.main_wnd == NULL) error("CreateWindow failed");
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   282
			ShowWindow(_wnd.main_wnd, showstyle);
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   283
		}
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   284
	}
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   285
	GameSizeChanged(); // invalidate all windows, force redraw
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   286
}
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   287
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
static LRESULT CALLBACK WndProcGdi(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
{
6603
a83fd7ad59d0 (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: 6602
diff changeset
   290
	static uint32 keycode = 0;
7035
b49ecaba95f5 (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: 6987
diff changeset
   291
	static bool console = false;
6603
a83fd7ad59d0 (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: 6602
diff changeset
   292
1468
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   293
	switch (msg) {
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   294
		case WM_CREATE:
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   295
			SetTimer(hwnd, TID_POLLMOUSE, MOUSE_POLL_DELAY, (TIMERPROC)TrackMouseTimerProc);
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   296
			break;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   297
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   298
		case WM_PAINT: {
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   299
			PAINTSTRUCT ps;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   300
			HDC dc,dc2;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   301
			HBITMAP old_bmp;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   302
			HPALETTE old_palette;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   303
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   304
			BeginPaint(hwnd, &ps);
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   305
			dc = ps.hdc;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   306
			dc2 = CreateCompatibleDC(dc);
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   307
			old_bmp = (HBITMAP)SelectObject(dc2, _wnd.dib_sect);
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   308
			old_palette = SelectPalette(dc, _wnd.gdi_palette, FALSE);
3312
593789444b01 (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
   309
7456
0c0636370335 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 7435
diff changeset
   310
			if (_pal_count_dirty != 0) {
7457
b380079242fa (svn r10217) -Fix r10216: forgot to declare 'blitter' in win32 and cocoa driver (tnx glx)
truelight
parents: 7456
diff changeset
   311
				Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
b380079242fa (svn r10217) -Fix r10216: forgot to declare 'blitter' in win32 and cocoa driver (tnx glx)
truelight
parents: 7456
diff changeset
   312
7456
0c0636370335 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 7435
diff changeset
   313
				switch (blitter->UsePaletteAnimation()) {
0c0636370335 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 7435
diff changeset
   314
					case Blitter::PALETTE_ANIMATION_VIDEO_BACKEND:
7458
c0d603d1f7c1 (svn r10218) -Fix r10216: more compile errors
glx
parents: 7457
diff changeset
   315
						UpdatePalette(dc2, _pal_first_dirty, _pal_count_dirty);
7456
0c0636370335 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 7435
diff changeset
   316
						break;
0c0636370335 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 7435
diff changeset
   317
0c0636370335 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 7435
diff changeset
   318
					case Blitter::PALETTE_ANIMATION_BLITTER:
0c0636370335 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 7435
diff changeset
   319
						blitter->PaletteAnimate(_pal_first_dirty, _pal_count_dirty);
0c0636370335 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 7435
diff changeset
   320
						break;
0c0636370335 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 7435
diff changeset
   321
0c0636370335 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 7435
diff changeset
   322
					case Blitter::PALETTE_ANIMATION_NONE:
0c0636370335 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 7435
diff changeset
   323
						break;
0c0636370335 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 7435
diff changeset
   324
0c0636370335 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 7435
diff changeset
   325
					default:
0c0636370335 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 7435
diff changeset
   326
						NOT_REACHED();
0c0636370335 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 7435
diff changeset
   327
				}
0c0636370335 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 7435
diff changeset
   328
				_pal_count_dirty = 0;
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   329
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   330
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   331
			BitBlt(dc, 0, 0, _wnd.width, _wnd.height, dc2, 0, 0, SRCCOPY);
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   332
			SelectPalette(dc, old_palette, TRUE);
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   333
			SelectObject(dc2, old_bmp);
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   334
			DeleteDC(dc2);
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   335
			EndPaint(hwnd, &ps);
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   336
			return 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   337
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   338
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   339
		case WM_PALETTECHANGED:
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   340
			if ((HWND)wParam == hwnd) return 0;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   341
			/* FALLTHROUGH */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   342
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   343
		case WM_QUERYNEWPALETTE: {
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   344
			HDC hDC = GetWindowDC(hwnd);
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   345
			HPALETTE hOldPalette = SelectPalette(hDC, _wnd.gdi_palette, FALSE);
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   346
			UINT nChanged = RealizePalette(hDC);
719
14d8c2d40bb8 (svn r1171) Fix: Console hotkey works again on keyboards where this key is a deadkey.
dominik
parents: 704
diff changeset
   347
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   348
			SelectPalette(hDC, hOldPalette, TRUE);
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   349
			ReleaseDC(hwnd, hDC);
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   350
			if (nChanged) InvalidateRect(hwnd, NULL, FALSE);
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   351
			return 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   352
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   353
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   354
		case WM_CLOSE:
4548
23b56455df33 (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4536
diff changeset
   355
			HandleExitGameRequest();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   356
			return 0;
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   357
5020
a679bc02c88d (svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents: 5019
diff changeset
   358
		case WM_DESTROY:
a679bc02c88d (svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents: 5019
diff changeset
   359
			if (_window_maximize) {
a679bc02c88d (svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents: 5019
diff changeset
   360
				_cur_resolution[0] = _bck_resolution[0];
a679bc02c88d (svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents: 5019
diff changeset
   361
				_cur_resolution[1] = _bck_resolution[1];
a679bc02c88d (svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents: 5019
diff changeset
   362
			}
a679bc02c88d (svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents: 5019
diff changeset
   363
			return 0;
a679bc02c88d (svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents: 5019
diff changeset
   364
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   365
		case WM_LBUTTONDOWN:
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   366
			SetCapture(hwnd);
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   367
			_left_button_down = true;
5090
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
   368
			HandleMouseEvents();
1548
a69e1b3b7774 (svn r2052) - Fix Regression: ALT+F4 once again shuts down openttd in windows and F10, etc. is fixed.
darkvater
parents: 1508
diff changeset
   369
			return 0;
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   370
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   371
		case WM_LBUTTONUP:
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   372
			ReleaseCapture();
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   373
			_left_button_down = false;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   374
			_left_button_clicked = false;
5090
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
   375
			HandleMouseEvents();
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   376
			return 0;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   377
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   378
		case WM_RBUTTONDOWN:
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   379
			SetCapture(hwnd);
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   380
			_right_button_down = true;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   381
			_right_button_clicked = true;
5090
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
   382
			HandleMouseEvents();
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   383
			return 0;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   384
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   385
		case WM_RBUTTONUP:
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   386
			ReleaseCapture();
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   387
			_right_button_down = false;
5090
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
   388
			HandleMouseEvents();
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   389
			return 0;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   390
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   391
		case WM_MOUSELEAVE:
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   392
			UndrawMouseCursor();
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   393
			_cursor.in_window = false;
5021
711e711f6b9a (svn r7062) -[win32] Codechange: Remove unneeded WM_MOUSEENTER event, and change mouse behaviour
Darkvater
parents: 5020
diff changeset
   394
711e711f6b9a (svn r7062) -[win32] Codechange: Remove unneeded WM_MOUSEENTER event, and change mouse behaviour
Darkvater
parents: 5020
diff changeset
   395
			if (!_left_button_down && !_right_button_down) MyShowCursor(true);
5090
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
   396
			HandleMouseEvents();
5021
711e711f6b9a (svn r7062) -[win32] Codechange: Remove unneeded WM_MOUSEENTER event, and change mouse behaviour
Darkvater
parents: 5020
diff changeset
   397
			return 0;
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   398
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   399
		case WM_MOUSEMOVE: {
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   400
			int x = (int16)LOWORD(lParam);
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   401
			int y = (int16)HIWORD(lParam);
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   402
			POINT pt;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   403
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   404
			/* If the mouse was not in the window and it has moved it means it has
5021
711e711f6b9a (svn r7062) -[win32] Codechange: Remove unneeded WM_MOUSEENTER event, and change mouse behaviour
Darkvater
parents: 5020
diff changeset
   405
			 * come into the window, so start drawing the mouse. Also start
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   406
			 * tracking the mouse for exiting the window */
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   407
			if (!_cursor.in_window) {
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   408
				_cursor.in_window = true;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   409
				SetTimer(hwnd, TID_POLLMOUSE, MOUSE_POLL_DELAY, (TIMERPROC)TrackMouseTimerProc);
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   410
5021
711e711f6b9a (svn r7062) -[win32] Codechange: Remove unneeded WM_MOUSEENTER event, and change mouse behaviour
Darkvater
parents: 5020
diff changeset
   411
				DrawMouseCursor();
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   412
			}
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   413
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   414
			if (_cursor.fix_at) {
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   415
				int dx = x - _cursor.pos.x;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   416
				int dy = y - _cursor.pos.y;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   417
				if (dx != 0 || dy != 0) {
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   418
					_cursor.delta.x += dx;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   419
					_cursor.delta.y += dy;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   420
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   421
					pt.x = _cursor.pos.x;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   422
					pt.y = _cursor.pos.y;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   423
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   424
					ClientToScreen(hwnd, &pt);
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   425
					SetCursorPos(pt.x, pt.y);
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   426
				}
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   427
			} else {
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   428
				_cursor.delta.x += x - _cursor.pos.x;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   429
				_cursor.delta.y += y - _cursor.pos.y;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   430
				_cursor.pos.x = x;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   431
				_cursor.pos.y = y;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   432
				_cursor.dirty = true;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   433
			}
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   434
			MyShowCursor(false);
5090
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
   435
			HandleMouseEvents();
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   436
			return 0;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   437
		}
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   438
6577
ee768d653dd0 (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: 6574
diff changeset
   439
#if !defined(UNICODE)
ee768d653dd0 (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: 6574
diff changeset
   440
		case WM_INPUTLANGCHANGE: {
ee768d653dd0 (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: 6574
diff changeset
   441
			TCHAR locale[6];
ee768d653dd0 (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: 6574
diff changeset
   442
			LCID lcid = GB(lParam, 0, 16);
ee768d653dd0 (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: 6574
diff changeset
   443
ee768d653dd0 (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: 6574
diff changeset
   444
			int len = GetLocaleInfo(lcid, LOCALE_IDEFAULTANSICODEPAGE, locale, lengthof(locale));
ee768d653dd0 (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: 6574
diff changeset
   445
			if (len != 0) _codepage = _ttoi(locale);
ee768d653dd0 (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: 6574
diff changeset
   446
			return 1;
ee768d653dd0 (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: 6574
diff changeset
   447
		}
ee768d653dd0 (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: 6574
diff changeset
   448
#endif /* UNICODE */
ee768d653dd0 (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: 6574
diff changeset
   449
7035
b49ecaba95f5 (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: 6987
diff changeset
   450
		case WM_DEADCHAR:
b49ecaba95f5 (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: 6987
diff changeset
   451
			console = GB(lParam, 16, 8) == 41;
b49ecaba95f5 (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: 6987
diff changeset
   452
			return 0;
b49ecaba95f5 (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: 6987
diff changeset
   453
6603
a83fd7ad59d0 (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: 6602
diff changeset
   454
		case WM_CHAR: {
a83fd7ad59d0 (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: 6602
diff changeset
   455
			/* Silently drop all non-text messages as those were handled by WM_KEYDOWN */
a83fd7ad59d0 (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: 6602
diff changeset
   456
			if (wParam < VK_SPACE) return 0;
a83fd7ad59d0 (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: 6602
diff changeset
   457
			uint scancode = GB(lParam, 16, 8);
a83fd7ad59d0 (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: 6602
diff changeset
   458
			uint charcode = wParam;
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   459
7035
b49ecaba95f5 (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: 6987
diff changeset
   460
			/* If the console key is a dead-key, we need to press it twice to get a WM_CHAR message.
b49ecaba95f5 (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: 6987
diff changeset
   461
			 * But we then get two WM_CHAR messages, so ignore the first one */
b49ecaba95f5 (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: 6987
diff changeset
   462
			if (console && scancode == 41) {
b49ecaba95f5 (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: 6987
diff changeset
   463
				console = false;
b49ecaba95f5 (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: 6987
diff changeset
   464
				return 0;
b49ecaba95f5 (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: 6987
diff changeset
   465
			}
b49ecaba95f5 (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: 6987
diff changeset
   466
6603
a83fd7ad59d0 (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: 6602
diff changeset
   467
#if !defined(UNICODE)
a83fd7ad59d0 (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: 6602
diff changeset
   468
			wchar_t w;
a83fd7ad59d0 (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: 6602
diff changeset
   469
			int len = MultiByteToWideChar(_codepage, 0, (char*)&charcode, 1, &w, 1);
a83fd7ad59d0 (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: 6602
diff changeset
   470
			charcode = len == 1 ? w : 0;
a83fd7ad59d0 (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: 6602
diff changeset
   471
#endif /* UNICODE */
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   472
6603
a83fd7ad59d0 (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: 6602
diff changeset
   473
			/* No matter the keyboard layout, we will map the '~' to the console */
a83fd7ad59d0 (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: 6602
diff changeset
   474
			scancode = scancode == 41 ? (int)WKC_BACKQUOTE : keycode;
a83fd7ad59d0 (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: 6602
diff changeset
   475
			HandleKeypress(GB(charcode, 0, 16) | (scancode << 16));
a83fd7ad59d0 (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: 6602
diff changeset
   476
			return 0;
a83fd7ad59d0 (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: 6602
diff changeset
   477
		}
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   478
6603
a83fd7ad59d0 (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: 6602
diff changeset
   479
		case WM_KEYDOWN: {
a83fd7ad59d0 (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: 6602
diff changeset
   480
			keycode = MapWindowsKey(wParam);
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   481
6603
a83fd7ad59d0 (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: 6602
diff changeset
   482
			/* Silently drop all text messages as those will be handled by WM_CHAR
a83fd7ad59d0 (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: 6602
diff changeset
   483
			 * WM_KEYDOWN only handles CTRL+ commands and special keys like VK_LEFT, etc. */
a83fd7ad59d0 (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: 6602
diff changeset
   484
			if (keycode == 0 || (keycode > WKC_PAUSE && GB(keycode, 13, 4) == 0)) return 0;
a83fd7ad59d0 (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: 6602
diff changeset
   485
a83fd7ad59d0 (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: 6602
diff changeset
   486
			HandleKeypress(0 | (keycode << 16));
a83fd7ad59d0 (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: 6602
diff changeset
   487
			return 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   488
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   489
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   490
		case WM_SYSKEYDOWN: /* user presses F10 or Alt, both activating the title-menu */
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   491
			switch (wParam) {
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   492
				case VK_RETURN:
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   493
				case 'F': /* Full Screen on ALT + ENTER/F */
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   494
					ToggleFullScreen(!_wnd.fullscreen);
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   495
					return 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   496
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   497
				case VK_MENU: /* Just ALT */
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   498
					return 0; // do nothing
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   499
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   500
				case VK_F10: /* F10, ignore activation of menu */
5086
99e0b202b9fb (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5076
diff changeset
   501
					HandleKeypress(MapWindowsKey(wParam) << 16);
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   502
					return 0;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   503
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   504
				default: /* ALT in combination with something else */
5086
99e0b202b9fb (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5076
diff changeset
   505
					HandleKeypress(MapWindowsKey(wParam) << 16);
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   506
					break;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   507
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   508
			break;
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   509
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   510
		case WM_SIZE:
7429
e112860fbc16 (svn r10186) -Fix (FS#876): don't mess desktop when using alt-tab (win32)
glx
parents: 7374
diff changeset
   511
			_wnd.minimized = (wParam == SIZE_MINIMIZED);
e112860fbc16 (svn r10186) -Fix (FS#876): don't mess desktop when using alt-tab (win32)
glx
parents: 7374
diff changeset
   512
			if (!_wnd.minimized) {
5019
1e16d845265a (svn r7060) -Fix (r5874): Restore of window maximized state not always working (Mart3p) . Remember
Darkvater
parents: 4840
diff changeset
   513
				/* Set maximized flag when we maximize (obviously), but also when we
1e16d845265a (svn r7060) -Fix (r5874): Restore of window maximized state not always working (Mart3p) . Remember
Darkvater
parents: 4840
diff changeset
   514
				 * switched to fullscreen from a maximized state */
1e16d845265a (svn r7060) -Fix (r5874): Restore of window maximized state not always working (Mart3p) . Remember
Darkvater
parents: 4840
diff changeset
   515
				_window_maximize = (wParam == SIZE_MAXIMIZED || (_window_maximize && _fullscreen));
5020
a679bc02c88d (svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents: 5019
diff changeset
   516
				if (_window_maximize) {
a679bc02c88d (svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents: 5019
diff changeset
   517
					_bck_resolution[0] = _cur_resolution[0];
a679bc02c88d (svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents: 5019
diff changeset
   518
					_bck_resolution[1] = _cur_resolution[1];
a679bc02c88d (svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents: 5019
diff changeset
   519
				}
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   520
				ClientSizeChanged(LOWORD(lParam), HIWORD(lParam));
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   521
			}
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   522
			return 0;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   523
6009
cf31b0e5c696 (svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents: 5838
diff changeset
   524
#if !defined(WINCE)
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   525
		case WM_SIZING: {
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   526
			RECT* r = (RECT*)lParam;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   527
			RECT r2;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   528
			int w, h;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   529
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   530
			SetRect(&r2, 0, 0, 0, 0);
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   531
			AdjustWindowRect(&r2, GetWindowLong(hwnd, GWL_STYLE), FALSE);
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   532
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   533
			w = r->right - r->left - (r2.right - r2.left);
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   534
			h = r->bottom - r->top - (r2.bottom - r2.top);
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   535
			w = clamp(w, 64, MAX_SCREEN_WIDTH);
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   536
			h = clamp(h, 64, MAX_SCREEN_HEIGHT);
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   537
			SetRect(&r2, 0, 0, w, h);
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   538
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   539
			AdjustWindowRect(&r2, GetWindowLong(hwnd, GWL_STYLE), FALSE);
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   540
			w = r2.right - r2.left;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   541
			h = r2.bottom - r2.top;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   542
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   543
			switch (wParam) {
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   544
				case WMSZ_BOTTOM:
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   545
					r->bottom = r->top + h;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   546
					break;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   547
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   548
				case WMSZ_BOTTOMLEFT:
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   549
					r->bottom = r->top + h;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   550
					r->left = r->right - w;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   551
					break;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   552
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   553
				case WMSZ_BOTTOMRIGHT:
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   554
					r->bottom = r->top + h;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   555
					r->right = r->left + w;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   556
					break;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   557
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   558
				case WMSZ_LEFT:
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   559
					r->left = r->right - w;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   560
					break;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   561
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   562
				case WMSZ_RIGHT:
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   563
					r->right = r->left + w;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   564
					break;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   565
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   566
				case WMSZ_TOP:
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   567
					r->top = r->bottom - h;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   568
					break;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   569
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   570
				case WMSZ_TOPLEFT:
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   571
					r->top = r->bottom - h;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   572
					r->left = r->right - w;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   573
					break;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   574
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   575
				case WMSZ_TOPRIGHT:
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   576
					r->top = r->bottom - h;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   577
					r->right = r->left + w;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   578
					break;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   579
			}
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   580
			return TRUE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   581
		}
6010
31378995786b (svn r8310) -Fix r8309: it is wise to put #endifs in the right place ;)
truelight
parents: 6009
diff changeset
   582
#endif
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   583
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   584
// needed for wheel
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   585
#if !defined(WM_MOUSEWHEEL)
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   586
# define WM_MOUSEWHEEL 0x020A
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   587
#endif  //WM_MOUSEWHEEL
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   588
#if !defined(GET_WHEEL_DELTA_WPARAM)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   589
# define GET_WHEEL_DELTA_WPARAM(wparam) ((short)HIWORD(wparam))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   590
#endif  //GET_WHEEL_DELTA_WPARAM
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   591
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   592
		case WM_MOUSEWHEEL: {
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   593
			int delta = GET_WHEEL_DELTA_WPARAM(wParam);
1468
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   594
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   595
			if (delta < 0) {
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   596
				_cursor.wheel++;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   597
			} else if (delta > 0) {
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   598
				_cursor.wheel--;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   599
			}
5090
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
   600
			HandleMouseEvents();
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   601
			return 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   602
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   603
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   604
		case WM_ACTIVATEAPP:
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   605
			_wnd.has_focus = (wParam != 0);
7429
e112860fbc16 (svn r10186) -Fix (FS#876): don't mess desktop when using alt-tab (win32)
glx
parents: 7374
diff changeset
   606
#if !defined(WINCE)
e112860fbc16 (svn r10186) -Fix (FS#876): don't mess desktop when using alt-tab (win32)
glx
parents: 7374
diff changeset
   607
			if (_wnd.fullscreen) {
e112860fbc16 (svn r10186) -Fix (FS#876): don't mess desktop when using alt-tab (win32)
glx
parents: 7374
diff changeset
   608
				if (_wnd.has_focus && _wnd.minimized) {
e112860fbc16 (svn r10186) -Fix (FS#876): don't mess desktop when using alt-tab (win32)
glx
parents: 7374
diff changeset
   609
					/* Restore the game window */
e112860fbc16 (svn r10186) -Fix (FS#876): don't mess desktop when using alt-tab (win32)
glx
parents: 7374
diff changeset
   610
					ShowWindow(hwnd, SW_RESTORE);
7491
8eda96f8600a (svn r10251) -Fix (r10186, FS#907): alt-tab back into openttd could leave the taskbar visible
glx
parents: 7483
diff changeset
   611
					MakeWindow(true);
7429
e112860fbc16 (svn r10186) -Fix (FS#876): don't mess desktop when using alt-tab (win32)
glx
parents: 7374
diff changeset
   612
				} else if (!_wnd.has_focus && !_wnd.minimized) {
e112860fbc16 (svn r10186) -Fix (FS#876): don't mess desktop when using alt-tab (win32)
glx
parents: 7374
diff changeset
   613
					/* Minimise the window and restore desktop */
e112860fbc16 (svn r10186) -Fix (FS#876): don't mess desktop when using alt-tab (win32)
glx
parents: 7374
diff changeset
   614
					ShowWindow(hwnd, SW_MINIMIZE);
e112860fbc16 (svn r10186) -Fix (FS#876): don't mess desktop when using alt-tab (win32)
glx
parents: 7374
diff changeset
   615
					ChangeDisplaySettings(NULL, 0);
e112860fbc16 (svn r10186) -Fix (FS#876): don't mess desktop when using alt-tab (win32)
glx
parents: 7374
diff changeset
   616
				}
e112860fbc16 (svn r10186) -Fix (FS#876): don't mess desktop when using alt-tab (win32)
glx
parents: 7374
diff changeset
   617
			}
e112860fbc16 (svn r10186) -Fix (FS#876): don't mess desktop when using alt-tab (win32)
glx
parents: 7374
diff changeset
   618
#endif
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   619
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   620
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   621
	return DefWindowProc(hwnd, msg, wParam, lParam);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   622
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   623
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
   624
static void RegisterWndClass()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   625
{
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   626
	static bool registered = false;
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   627
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   628
	if (!registered) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   629
		HINSTANCE hinst = GetModuleHandle(NULL);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   630
		WNDCLASS wnd = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   631
			0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   632
			WndProcGdi,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   633
			0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   634
			0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   635
			hinst,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   636
			LoadIcon(hinst, MAKEINTRESOURCE(100)),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   637
			LoadCursor(NULL, IDC_ARROW),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   638
			0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   639
			0,
5168
10a8dc9788d7 (svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents: 5112
diff changeset
   640
			_T("OTTD")
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   641
		};
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   642
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   643
		registered = true;
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   644
		if (!RegisterClass(&wnd)) error("RegisterClass failed");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   645
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   646
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   647
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   648
static bool AllocateDibSection(int w, int h)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   649
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   650
	BITMAPINFO *bi;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   651
	HDC dc;
7374
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7111
diff changeset
   652
	int bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   653
306
c44133836566 (svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents: 298
diff changeset
   654
	w = clamp(w, 64, MAX_SCREEN_WIDTH);
c44133836566 (svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents: 298
diff changeset
   655
	h = clamp(h, 64, MAX_SCREEN_HEIGHT);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   656
7374
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7111
diff changeset
   657
	if (bpp == 0) error("Can't use a blitter that blits 0 bpp for normal visuals");
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7111
diff changeset
   658
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   659
	if (w == _screen.width && h == _screen.height)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   660
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   661
306
c44133836566 (svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents: 298
diff changeset
   662
	_screen.width = w;
7483
44be8159472b (svn r10243) -Fix: crash when resizing with 32bpp and 'broken' display with 'non-standard' resolutions
glx
parents: 7460
diff changeset
   663
	_screen.pitch = (bpp == 8) ? ALIGN(w, 4) : w;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   664
	_screen.height = h;
6987
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6603
diff changeset
   665
	bi = (BITMAPINFO*)alloca(sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256);
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6603
diff changeset
   666
	memset(bi, 0, sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   667
	bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   668
306
c44133836566 (svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents: 298
diff changeset
   669
	bi->bmiHeader.biWidth = _wnd.width = w;
c44133836566 (svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents: 298
diff changeset
   670
	bi->bmiHeader.biHeight = -(_wnd.height = h);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   671
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   672
	bi->bmiHeader.biPlanes = 1;
7374
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7111
diff changeset
   673
	bi->bmiHeader.biBitCount = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   674
	bi->bmiHeader.biCompression = BI_RGB;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   675
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   676
	if (_wnd.dib_sect) DeleteObject(_wnd.dib_sect);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   677
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   678
	dc = GetDC(0);
7374
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7111
diff changeset
   679
	_wnd.dib_sect = CreateDIBSection(dc, bi, DIB_RGB_COLORS, (VOID**)&_wnd.buffer_bits, NULL, 0);
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   680
	if (_wnd.dib_sect == NULL) error("CreateDIBSection failed");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   681
	ReleaseDC(0, dc);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   682
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   683
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   684
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   685
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   686
static const uint16 default_resolutions[][2] = {
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   687
	{  640,  480 },
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   688
	{  800,  600 },
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   689
	{ 1024,  768 },
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   690
	{ 1152,  864 },
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   691
	{ 1280,  800 },
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   692
	{ 1280,  960 },
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   693
	{ 1280, 1024 },
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   694
	{ 1400, 1050 },
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   695
	{ 1600, 1200 },
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   696
	{ 1680, 1050 },
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   697
	{ 1920, 1200 }
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   698
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   699
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
   700
static void FindResolutions()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   701
{
4000
bab1ebc37da0 (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
   702
	uint n = 0;
6009
cf31b0e5c696 (svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents: 5838
diff changeset
   703
#if defined(WINCE)
cf31b0e5c696 (svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents: 5838
diff changeset
   704
	/* EnumDisplaySettingsW is only supported in CE 4.2+ */
cf31b0e5c696 (svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents: 5838
diff changeset
   705
	/* XXX -- One might argue that we assume 4.2+ on every system. Then we can use this function safely */
cf31b0e5c696 (svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents: 5838
diff changeset
   706
#else
4000
bab1ebc37da0 (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
   707
	uint i;
5169
56b54b6e54ec (svn r7279) -Codechange: [win32] Add Windows95/98 support by using MSLU. Only workaround is that the
Darkvater
parents: 5168
diff changeset
   708
	DEVMODEA dm;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   709
5169
56b54b6e54ec (svn r7279) -Codechange: [win32] Add Windows95/98 support by using MSLU. Only workaround is that the
Darkvater
parents: 5168
diff changeset
   710
	/* XXX - EnumDisplaySettingsW crashes with unicows.dll on Windows95
56b54b6e54ec (svn r7279) -Codechange: [win32] Add Windows95/98 support by using MSLU. Only workaround is that the
Darkvater
parents: 5168
diff changeset
   711
	 * Doesn't really matter since we don't pass a string anyways, but still
56b54b6e54ec (svn r7279) -Codechange: [win32] Add Windows95/98 support by using MSLU. Only workaround is that the
Darkvater
parents: 5168
diff changeset
   712
	 * a letdown */
56b54b6e54ec (svn r7279) -Codechange: [win32] Add Windows95/98 support by using MSLU. Only workaround is that the
Darkvater
parents: 5168
diff changeset
   713
	for (i = 0; EnumDisplaySettingsA(NULL, i, &dm) != 0; i++) {
7374
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7111
diff changeset
   714
		if (dm.dmBitsPerPel == BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() && IS_INT_INSIDE(dm.dmPelsWidth, 640, MAX_SCREEN_WIDTH + 1) &&
4000
bab1ebc37da0 (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
   715
				IS_INT_INSIDE(dm.dmPelsHeight, 480, MAX_SCREEN_HEIGHT + 1)) {
bab1ebc37da0 (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
   716
			uint j;
bab1ebc37da0 (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
   717
1806
75dc9c737892 (svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents: 1686
diff changeset
   718
			for (j = 0; j < n; j++) {
75dc9c737892 (svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents: 1686
diff changeset
   719
				if (_resolutions[j][0] == dm.dmPelsWidth && _resolutions[j][1] == dm.dmPelsHeight) break;
75dc9c737892 (svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents: 1686
diff changeset
   720
			}
75dc9c737892 (svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents: 1686
diff changeset
   721
75dc9c737892 (svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents: 1686
diff changeset
   722
			/* In the previous loop we have checked already existing/added resolutions if
75dc9c737892 (svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents: 1686
diff changeset
   723
			 * they are the same as the new ones. If this is not the case (j == n); we have
75dc9c737892 (svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents: 1686
diff changeset
   724
			 * looped all and found none, add the new one to the list. If we have reached the
75dc9c737892 (svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents: 1686
diff changeset
   725
			 * maximum amount of resolutions, then quit querying the display */
75dc9c737892 (svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents: 1686
diff changeset
   726
			if (j == n) {
75dc9c737892 (svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents: 1686
diff changeset
   727
				_resolutions[j][0] = dm.dmPelsWidth;
75dc9c737892 (svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents: 1686
diff changeset
   728
				_resolutions[j][1] = dm.dmPelsHeight;
75dc9c737892 (svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents: 1686
diff changeset
   729
				if (++n == lengthof(_resolutions)) break;
75dc9c737892 (svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents: 1686
diff changeset
   730
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   731
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   732
	}
6009
cf31b0e5c696 (svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents: 5838
diff changeset
   733
#endif
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   734
1806
75dc9c737892 (svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents: 1686
diff changeset
   735
	/* We have found no resolutions, show the default list */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   736
	if (n == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   737
		memcpy(_resolutions, default_resolutions, sizeof(default_resolutions));
1468
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   738
		n = lengthof(default_resolutions);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   739
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   740
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   741
	_num_resolutions = n;
1806
75dc9c737892 (svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents: 1686
diff changeset
   742
	SortResolutions(_num_resolutions);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   743
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   744
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   745
1301
313804601383 (svn r1805) Teach the driver layer a few things about const correctness
tron
parents: 1230
diff changeset
   746
static const char *Win32GdiStart(const char * const *parm)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   747
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   748
	memset(&_wnd, 0, sizeof(_wnd));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   749
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   750
	RegisterWndClass();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   751
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   752
	MakePalette();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   753
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   754
	FindResolutions();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   755
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   756
	// fullscreen uses those
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   757
	_wnd.width_org = _cur_resolution[0];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   758
	_wnd.height_org = _cur_resolution[1];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   759
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   760
	AllocateDibSection(_cur_resolution[0], _cur_resolution[1]);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   761
	MarkWholeScreenDirty();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   762
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   763
	MakeWindow(_fullscreen);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   764
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   765
	return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   766
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   767
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
   768
static void Win32GdiStop()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   769
{
3285
c162cb0b57c1 (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
   770
	DeleteObject(_wnd.gdi_palette);
c162cb0b57c1 (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
   771
	DeleteObject(_wnd.dib_sect);
c162cb0b57c1 (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
   772
	DestroyWindow(_wnd.main_wnd);
c162cb0b57c1 (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
   773
6009
cf31b0e5c696 (svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents: 5838
diff changeset
   774
#if !defined(WINCE)
1468
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   775
	if (_wnd.fullscreen) ChangeDisplaySettings(NULL, 0);
6009
cf31b0e5c696 (svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents: 5838
diff changeset
   776
#endif
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   777
	MyShowCursor(true);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   778
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   779
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   780
static void Win32GdiMakeDirty(int left, int top, int width, int height)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   781
{
1468
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   782
	RECT r = { left, top, left + width, top + height };
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   783
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   784
	InvalidateRect(_wnd.main_wnd, &r, FALSE);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   785
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   786
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
   787
static void CheckPaletteAnim()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   788
{
7458
c0d603d1f7c1 (svn r10218) -Fix r10216: more compile errors
glx
parents: 7457
diff changeset
   789
	if (_pal_count_dirty == 0)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   790
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   791
	InvalidateRect(_wnd.main_wnd, NULL, FALSE);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   792
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   793
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
   794
static void Win32GdiMainLoop()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   795
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   796
	MSG mesg;
5832
28aa8ad3bb04 (svn r8028) -Fix: overflow of ticks was not handled properly, possibly resulting a non-reacting gameserver/gameclient.
rubidium
parents: 5726
diff changeset
   797
	uint32 cur_ticks = GetTickCount();
28aa8ad3bb04 (svn r8028) -Fix: overflow of ticks was not handled properly, possibly resulting a non-reacting gameserver/gameclient.
rubidium
parents: 5726
diff changeset
   798
	uint32 next_tick = cur_ticks + 30;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   799
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   800
	_wnd.running = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   801
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2773
diff changeset
   802
	for (;;) {
5832
28aa8ad3bb04 (svn r8028) -Fix: overflow of ticks was not handled properly, possibly resulting a non-reacting gameserver/gameclient.
rubidium
parents: 5726
diff changeset
   803
		uint32 prev_cur_ticks = cur_ticks; // to check for wrapping
28aa8ad3bb04 (svn r8028) -Fix: overflow of ticks was not handled properly, possibly resulting a non-reacting gameserver/gameclient.
rubidium
parents: 5726
diff changeset
   804
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   805
		while (PeekMessage(&mesg, NULL, 0, 0, PM_REMOVE)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   806
			InteractiveRandom(); // randomness
6603
a83fd7ad59d0 (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: 6602
diff changeset
   807
			TranslateMessage(&mesg);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   808
			DispatchMessage(&mesg);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   809
		}
2228
7014d372374f (svn r2748) Remove unused cruft from the main loop
tron
parents: 2208
diff changeset
   810
		if (_exit_game) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   811
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   812
#if defined(_DEBUG)
5089
9d290a04d79c (svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents: 5086
diff changeset
   813
		if (_wnd.has_focus && GetAsyncKeyState(VK_SHIFT) < 0 &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   814
#else
5089
9d290a04d79c (svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents: 5086
diff changeset
   815
		/* Speed up using TAB, but disable for ALT+TAB of course */
9d290a04d79c (svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents: 5086
diff changeset
   816
		if (_wnd.has_focus && GetAsyncKeyState(VK_TAB) < 0 && GetAsyncKeyState(VK_MENU) >= 0 &&
1548
a69e1b3b7774 (svn r2052) - Fix Regression: ALT+F4 once again shuts down openttd in windows and F10, etc. is fixed.
darkvater
parents: 1508
diff changeset
   817
#endif
5089
9d290a04d79c (svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents: 5086
diff changeset
   818
			  !_networking && _game_mode != GM_MENU) {
9d290a04d79c (svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents: 5086
diff changeset
   819
			_fast_forward |= 2;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
   820
		} else if (_fast_forward & 2) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   821
			_fast_forward = 0;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
   822
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   823
1403
6d9ed6c85a22 (svn r1907) - Fix: [ 1114261 ] Speeding up when pressing ALT+TAB (Windows)
darkvater
parents: 1390
diff changeset
   824
		cur_ticks = GetTickCount();
6557
8381016f71f3 (svn r9034) -Codechange: renamed _pause to _pause_game, as some targets already have
truelight
parents: 6531
diff changeset
   825
		if (cur_ticks >= next_tick || (_fast_forward && !_pause_game) || cur_ticks < prev_cur_ticks) {
5832
28aa8ad3bb04 (svn r8028) -Fix: overflow of ticks was not handled properly, possibly resulting a non-reacting gameserver/gameclient.
rubidium
parents: 5726
diff changeset
   826
			next_tick = cur_ticks + 30;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   827
			_ctrl_pressed = _wnd.has_focus && GetAsyncKeyState(VK_CONTROL)<0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   828
			_shift_pressed = _wnd.has_focus && GetAsyncKeyState(VK_SHIFT)<0;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   829
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   830
			// determine which directional keys are down
1230
701163ef52b8 (svn r1734) - Fix: [ 1112253 ] hijacking of arrow keys, game also scrolled when it was out of focus (dominik)
darkvater
parents: 1102
diff changeset
   831
			if (_wnd.has_focus) {
701163ef52b8 (svn r1734) - Fix: [ 1112253 ] hijacking of arrow keys, game also scrolled when it was out of focus (dominik)
darkvater
parents: 1102
diff changeset
   832
				_dirkeys =
701163ef52b8 (svn r1734) - Fix: [ 1112253 ] hijacking of arrow keys, game also scrolled when it was out of focus (dominik)
darkvater
parents: 1102
diff changeset
   833
					(GetAsyncKeyState(VK_LEFT) < 0 ? 1 : 0) +
701163ef52b8 (svn r1734) - Fix: [ 1112253 ] hijacking of arrow keys, game also scrolled when it was out of focus (dominik)
darkvater
parents: 1102
diff changeset
   834
					(GetAsyncKeyState(VK_UP) < 0 ? 2 : 0) +
701163ef52b8 (svn r1734) - Fix: [ 1112253 ] hijacking of arrow keys, game also scrolled when it was out of focus (dominik)
darkvater
parents: 1102
diff changeset
   835
					(GetAsyncKeyState(VK_RIGHT) < 0 ? 4 : 0) +
701163ef52b8 (svn r1734) - Fix: [ 1112253 ] hijacking of arrow keys, game also scrolled when it was out of focus (dominik)
darkvater
parents: 1102
diff changeset
   836
					(GetAsyncKeyState(VK_DOWN) < 0 ? 8 : 0);
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
   837
			} else {
1230
701163ef52b8 (svn r1734) - Fix: [ 1112253 ] hijacking of arrow keys, game also scrolled when it was out of focus (dominik)
darkvater
parents: 1102
diff changeset
   838
				_dirkeys = 0;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
   839
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   840
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   841
			GameLoop();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   842
			_cursor.delta.x = _cursor.delta.y = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   843
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
   844
			if (_force_full_redraw) MarkWholeScreenDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   845
6009
cf31b0e5c696 (svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents: 5838
diff changeset
   846
#if !defined(WINCE)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   847
			GdiFlush();
6009
cf31b0e5c696 (svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents: 5838
diff changeset
   848
#endif
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   849
			_screen.dst_ptr = _wnd.buffer_bits;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   850
			UpdateWindows();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   851
			CheckPaletteAnim();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   852
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   853
			Sleep(1);
6009
cf31b0e5c696 (svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents: 5838
diff changeset
   854
#if !defined(WINCE)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   855
			GdiFlush();
6009
cf31b0e5c696 (svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents: 5838
diff changeset
   856
#endif
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   857
			_screen.dst_ptr = _wnd.buffer_bits;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   858
			DrawTextMessage();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   859
			DrawMouseCursor();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   860
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   861
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   862
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   863
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   864
static bool Win32GdiChangeRes(int w, int h)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   865
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   866
	_wnd.width = _wnd.width_org = w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   867
	_wnd.height = _wnd.height_org = h;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   868
298
b3e83b94be19 (svn r304) -Fix: [967096] fullscreen. New button 'Fullscreen' in 'Game Options' menu which lets you set fullscreen ingame.
darkvater
parents: 287
diff changeset
   869
	MakeWindow(_fullscreen); // _wnd.fullscreen screws up ingame resolution switching
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   870
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   871
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   872
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   873
4489
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   874
static void Win32GdiFullScreen(bool full_screen)
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   875
{
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   876
	MakeWindow(full_screen);
9399fe83fd41 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   877
}
1806
75dc9c737892 (svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents: 1686
diff changeset
   878
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   879
const HalVideoDriver _win32_video_driver = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   880
	Win32GdiStart,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   881
	Win32GdiStop,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   882
	Win32GdiMakeDirty,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   883
	Win32GdiMainLoop,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   884
	Win32GdiChangeRes,
1829
0b6de3b4458a (svn r2334) - Fix (regression): moved togglefullscreen into the video-driver, now windows works, dedicated works and sdl works. Also reverted the change to the makefile.
Darkvater
parents: 1806
diff changeset
   885
	Win32GdiFullScreen,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   886
};