src/video/win32_v.cpp
author KUDr
Fri, 12 Jan 2007 15:43:00 +0000
changeset 5620 eab6f02899a0
parent 5587 167d9a91ef02
child 5758 4b10d28b54c7
permissions -rw-r--r--
(svn r8079) -Fix [YAPF]: float division by zero when calculating stats (YAPF cache hit ratio). Caused BSOD on Win9x. (thanks 3iff for report, Darkvater for help)
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2174
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2174
diff changeset
     2
2189
5cdc11ffeaa4 (svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents: 2186
diff changeset
     3
#include "../stdafx.h"
5cdc11ffeaa4 (svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents: 2186
diff changeset
     4
#include "../openttd.h"
5cdc11ffeaa4 (svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents: 2186
diff changeset
     5
#include "../functions.h"
5cdc11ffeaa4 (svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents: 2186
diff changeset
     6
#include "../gfx.h"
5cdc11ffeaa4 (svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents: 2186
diff changeset
     7
#include "../macros.h"
5469
7edfc643abbc (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: 5377
diff changeset
     8
#include "../network/network.h"
2189
5cdc11ffeaa4 (svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents: 2186
diff changeset
     9
#include "../variables.h"
2207
be1ef1e1fc58 (svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents: 2189
diff changeset
    10
#include "../win32.h"
2189
5cdc11ffeaa4 (svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents: 2186
diff changeset
    11
#include "../window.h"
5cdc11ffeaa4 (svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents: 2186
diff changeset
    12
#include "win32_v.h"
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    13
#include <windows.h>
5168
e206899169c4 (svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents: 5112
diff changeset
    14
#include <tchar.h>
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    15
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    16
static struct {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    17
	HWND main_wnd;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    18
	HBITMAP dib_sect;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    19
	Pixel *bitmap_bits;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    20
	Pixel *buffer_bits;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    21
	Pixel *alloced_bits;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    22
	HPALETTE gdi_palette;
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
    23
	int width;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
    24
	int height;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
    25
	int width_org;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
    26
	int height_org;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    27
	bool fullscreen;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    28
	bool double_size;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    29
	bool has_focus;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    30
	bool running;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    31
} _wnd;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    32
3051
6a9ddcac6d56 (svn r3640) - Remove win32-only variables from variables.h and put them into win32_v.c. Also ifdef the win32 specific configuration file settings.
Darkvater
parents: 2952
diff changeset
    33
bool _force_full_redraw;
6a9ddcac6d56 (svn r3640) - Remove win32-only variables from variables.h and put them into win32_v.c. Also ifdef the win32 specific configuration file settings.
Darkvater
parents: 2952
diff changeset
    34
bool _double_size;
4258
087d44b3514f (svn r5874) -Feature [FS#234]: Remember the maximized state and restore on start. This also fixes a bug where a different resolution is chosen for a maximized window, but it retains the maximized flag. Only win32.
Darkvater
parents: 4077
diff changeset
    35
bool _window_maximize;
3051
6a9ddcac6d56 (svn r3640) - Remove win32-only variables from variables.h and put them into win32_v.c. Also ifdef the win32 specific configuration file settings.
Darkvater
parents: 2952
diff changeset
    36
uint _display_hz;
6a9ddcac6d56 (svn r3640) - Remove win32-only variables from variables.h and put them into win32_v.c. Also ifdef the win32 specific configuration file settings.
Darkvater
parents: 2952
diff changeset
    37
uint _fullscreen_bpp;
5020
e2564f4400b7 (svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents: 5019
diff changeset
    38
static uint16 _bck_resolution[2];
3051
6a9ddcac6d56 (svn r3640) - Remove win32-only variables from variables.h and put them into win32_v.c. Also ifdef the win32 specific configuration file settings.
Darkvater
parents: 2952
diff changeset
    39
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    40
static void MakePalette(void)
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    41
{
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    42
	LOGPALETTE *pal;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    43
	uint i;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    44
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
    45
	pal = (LOGPALETTE*)alloca(sizeof(LOGPALETTE) + (256-1) * sizeof(PALETTEENTRY));
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    46
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    47
	pal->palVersion = 0x300;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    48
	pal->palNumEntries = 256;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    49
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    50
	for (i = 0; i != 256; i++) {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    51
		pal->palPalEntry[i].peRed   = _cur_palette[i].r;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    52
		pal->palPalEntry[i].peGreen = _cur_palette[i].g;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    53
		pal->palPalEntry[i].peBlue  = _cur_palette[i].b;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    54
		pal->palPalEntry[i].peFlags = 0;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    55
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    56
	}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    57
	_wnd.gdi_palette = CreatePalette(pal);
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
    58
	if (_wnd.gdi_palette == NULL) error("CreatePalette failed!\n");
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    59
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    60
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    61
static void UpdatePalette(HDC dc, uint start, uint count)
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    62
{
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    63
	RGBQUAD rgb[256];
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    64
	uint i;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    65
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    66
	for (i = 0; i != count; i++) {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    67
		rgb[i].rgbRed   = _cur_palette[start + i].r;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    68
		rgb[i].rgbGreen = _cur_palette[start + i].g;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    69
		rgb[i].rgbBlue  = _cur_palette[start + i].b;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    70
		rgb[i].rgbReserved = 0;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    71
	}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    72
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    73
	SetDIBColorTable(dc, start, count, rgb);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    74
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    75
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    76
typedef struct {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    77
	byte vk_from;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    78
	byte vk_count;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    79
	byte map_to;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    80
} VkMapping;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    81
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    82
#define AS(x, z) {x, 0, z}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    83
#define AM(x, y, z, w) {x, y - x, z}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    84
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    85
static const VkMapping _vk_mapping[] = {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    86
	// Pageup stuff + up/down
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    87
	AM(VK_PRIOR,VK_DOWN, WKC_PAGEUP, WKC_DOWN),
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    88
	// Map letters & digits
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    89
	AM('A','Z','A','Z'),
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    90
	AM('0','9','0','9'),
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    91
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
    92
	AS(VK_ESCAPE,   WKC_ESC),
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
    93
	AS(VK_PAUSE,    WKC_PAUSE),
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
    94
	AS(VK_BACK,     WKC_BACKSPACE),
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
    95
	AM(VK_INSERT,   VK_DELETE, WKC_INSERT, WKC_DELETE),
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    96
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
    97
	AS(VK_SPACE,    WKC_SPACE),
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
    98
	AS(VK_RETURN,   WKC_RETURN),
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
    99
	AS(VK_TAB,      WKC_TAB),
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   100
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   101
	// Function keys
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
   102
	AM(VK_F1, VK_F12, WKC_F1, WKC_F12),
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   103
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   104
	// Numeric part.
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   105
	// What is the virtual keycode for numeric enter??
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
   106
	AM(VK_NUMPAD0, VK_NUMPAD9, WKC_NUM_0, WKC_NUM_9),
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
   107
	AS(VK_DIVIDE,   WKC_NUM_DIV),
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
   108
	AS(VK_MULTIPLY, WKC_NUM_MUL),
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
   109
	AS(VK_SUBTRACT, WKC_NUM_MINUS),
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
   110
	AS(VK_ADD,      WKC_NUM_PLUS),
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
   111
	AS(VK_DECIMAL,  WKC_NUM_DECIMAL)
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   112
};
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   113
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   114
static uint MapWindowsKey(uint sym)
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   115
{
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   116
	const VkMapping *map;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   117
	uint key = 0;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   118
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   119
	for (map = _vk_mapping; map != endof(_vk_mapping); ++map) {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   120
		if ((uint)(sym - map->vk_from) <= map->vk_count) {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   121
			key = sym - map->vk_from + map->map_to;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   122
			break;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   123
		}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   124
	}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   125
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   126
	if (GetAsyncKeyState(VK_SHIFT)   < 0) key |= WKC_SHIFT;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   127
	if (GetAsyncKeyState(VK_CONTROL) < 0) key |= WKC_CTRL;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   128
	if (GetAsyncKeyState(VK_MENU)    < 0) key |= WKC_ALT;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   129
	return key;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   130
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   131
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   132
static bool AllocateDibSection(int w, int h);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   133
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   134
static void ClientSizeChanged(int w, int h)
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   135
{
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   136
	if (_wnd.double_size) {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   137
		w /= 2;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   138
		h /= 2;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   139
	}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   140
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   141
	// allocate new dib section of the new size
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   142
	if (AllocateDibSection(w, h)) {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   143
		// mark all palette colors dirty
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   144
		_pal_first_dirty = 0;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   145
		_pal_last_dirty = 255;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   146
		GameSizeChanged();
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   147
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   148
		// redraw screen
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   149
		if (_wnd.running) {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   150
			_screen.dst_ptr = _wnd.buffer_bits;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   151
			UpdateWindows();
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   152
		}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   153
	}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   154
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   155
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   156
#ifdef _DEBUG
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   157
// Keep this function here..
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   158
// It allows you to redraw the screen from within the MSVC debugger
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   159
int RedrawScreenDebug(void)
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   160
{
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   161
	HDC dc,dc2;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   162
	static int _fooctr;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   163
	HBITMAP old_bmp;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   164
	HPALETTE old_palette;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   165
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   166
	_screen.dst_ptr = _wnd.buffer_bits;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   167
	UpdateWindows();
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   168
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   169
	dc = GetDC(_wnd.main_wnd);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   170
	dc2 = CreateCompatibleDC(dc);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   171
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   172
	old_bmp = (HBITMAP)SelectObject(dc2, _wnd.dib_sect);
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   173
	old_palette = SelectPalette(dc, _wnd.gdi_palette, FALSE);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   174
	BitBlt(dc, 0, 0, _wnd.width, _wnd.height, dc2, 0, 0, SRCCOPY);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   175
	SelectPalette(dc, old_palette, TRUE);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   176
	SelectObject(dc2, old_bmp);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   177
	DeleteDC(dc2);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   178
	ReleaseDC(_wnd.main_wnd, dc);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   179
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   180
	return _fooctr++;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   181
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   182
#endif
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   183
5021
6fb82e055ceb (svn r7062) -[win32] Codechange: Remove unneeded WM_MOUSEENTER event, and change mouse behaviour
Darkvater
parents: 5020
diff changeset
   184
/* Windows 95 will not have a WM_MOUSELEAVE message, so define it if needed */
3312
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   185
#if !defined(WM_MOUSELEAVE)
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   186
#define WM_MOUSELEAVE 0x02A3
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   187
#endif
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   188
#define TID_POLLMOUSE 1
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   189
#define MOUSE_POLL_DELAY 75
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   190
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   191
static void CALLBACK TrackMouseTimerProc(HWND hwnd, UINT msg, UINT event, DWORD time)
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   192
{
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   193
	RECT rc;
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   194
	POINT pt;
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   195
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   196
	/* Get the rectangle of our window and translate it to screen coordinates.
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   197
	 * Compare this with the current screen coordinates of the mouse and if it
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   198
	 * falls outside of the area or our window we have left the window. */
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   199
	GetClientRect(hwnd, &rc);
3802
e3f0d57cc358 (svn r4810) - Fix: removed warning about strict-alias (release build)
glx
parents: 3325
diff changeset
   200
	MapWindowPoints(hwnd, HWND_DESKTOP, (LPPOINT)(LPRECT)&rc, 2);
3312
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   201
	GetCursorPos(&pt);
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   202
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   203
	if (!PtInRect(&rc, pt) || (WindowFromPoint(pt) != hwnd)) {
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   204
		KillTimer(hwnd, event);
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   205
		PostMessage(hwnd, WM_MOUSELEAVE, 0, 0L);
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   206
	}
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   207
}
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   208
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   209
static LRESULT CALLBACK WndProcGdi(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   210
{
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   211
	switch (msg) {
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   212
		case WM_CREATE:
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   213
			SetTimer(hwnd, TID_POLLMOUSE, MOUSE_POLL_DELAY, (TIMERPROC)TrackMouseTimerProc);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   214
			break;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   215
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   216
		case WM_PAINT: {
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   217
			PAINTSTRUCT ps;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   218
			HDC dc,dc2;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   219
			HBITMAP old_bmp;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   220
			HPALETTE old_palette;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   221
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   222
			BeginPaint(hwnd, &ps);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   223
			dc = ps.hdc;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   224
			dc2 = CreateCompatibleDC(dc);
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   225
			old_bmp = (HBITMAP)SelectObject(dc2, _wnd.dib_sect);
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   226
			old_palette = SelectPalette(dc, _wnd.gdi_palette, FALSE);
3312
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3285
diff changeset
   227
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   228
			if (_pal_last_dirty != -1) {
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   229
				UpdatePalette(dc2, _pal_first_dirty, _pal_last_dirty - _pal_first_dirty + 1);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   230
				_pal_last_dirty = -1;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   231
			}
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   232
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   233
			BitBlt(dc, 0, 0, _wnd.width, _wnd.height, dc2, 0, 0, SRCCOPY);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   234
			SelectPalette(dc, old_palette, TRUE);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   235
			SelectObject(dc2, old_bmp);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   236
			DeleteDC(dc2);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   237
			EndPaint(hwnd, &ps);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   238
			return 0;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   239
		}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   240
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   241
		case WM_PALETTECHANGED:
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   242
			if ((HWND)wParam == hwnd) return 0;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   243
			/* FALLTHROUGH */
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   244
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   245
		case WM_QUERYNEWPALETTE: {
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   246
			HDC hDC = GetWindowDC(hwnd);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   247
			HPALETTE hOldPalette = SelectPalette(hDC, _wnd.gdi_palette, FALSE);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   248
			UINT nChanged = RealizePalette(hDC);
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   249
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   250
			SelectPalette(hDC, hOldPalette, TRUE);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   251
			ReleaseDC(hwnd, hDC);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   252
			if (nChanged) InvalidateRect(hwnd, NULL, FALSE);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   253
			return 0;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   254
		}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   255
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   256
		case WM_CLOSE:
4548
6165e12570bf (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4536
diff changeset
   257
			HandleExitGameRequest();
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   258
			return 0;
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   259
5020
e2564f4400b7 (svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents: 5019
diff changeset
   260
		case WM_DESTROY:
e2564f4400b7 (svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents: 5019
diff changeset
   261
			if (_window_maximize) {
e2564f4400b7 (svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents: 5019
diff changeset
   262
				_cur_resolution[0] = _bck_resolution[0];
e2564f4400b7 (svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents: 5019
diff changeset
   263
				_cur_resolution[1] = _bck_resolution[1];
e2564f4400b7 (svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents: 5019
diff changeset
   264
			}
e2564f4400b7 (svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents: 5019
diff changeset
   265
			return 0;
e2564f4400b7 (svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents: 5019
diff changeset
   266
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   267
		case WM_LBUTTONDOWN:
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   268
			SetCapture(hwnd);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   269
			_left_button_down = true;
5090
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
   270
			HandleMouseEvents();
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   271
			return 0;
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   272
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   273
		case WM_LBUTTONUP:
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   274
			ReleaseCapture();
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   275
			_left_button_down = false;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   276
			_left_button_clicked = false;
5090
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
   277
			HandleMouseEvents();
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   278
			return 0;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   279
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   280
		case WM_RBUTTONDOWN:
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   281
			SetCapture(hwnd);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   282
			_right_button_down = true;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   283
			_right_button_clicked = true;
5090
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
   284
			HandleMouseEvents();
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   285
			return 0;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   286
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   287
		case WM_RBUTTONUP:
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   288
			ReleaseCapture();
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   289
			_right_button_down = false;
5090
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
   290
			HandleMouseEvents();
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   291
			return 0;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   292
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   293
		case WM_MOUSELEAVE:
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   294
			UndrawMouseCursor();
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   295
			_cursor.in_window = false;
5021
6fb82e055ceb (svn r7062) -[win32] Codechange: Remove unneeded WM_MOUSEENTER event, and change mouse behaviour
Darkvater
parents: 5020
diff changeset
   296
6fb82e055ceb (svn r7062) -[win32] Codechange: Remove unneeded WM_MOUSEENTER event, and change mouse behaviour
Darkvater
parents: 5020
diff changeset
   297
			if (!_left_button_down && !_right_button_down) MyShowCursor(true);
5090
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
   298
			HandleMouseEvents();
5021
6fb82e055ceb (svn r7062) -[win32] Codechange: Remove unneeded WM_MOUSEENTER event, and change mouse behaviour
Darkvater
parents: 5020
diff changeset
   299
			return 0;
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   300
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   301
		case WM_MOUSEMOVE: {
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   302
			int x = (int16)LOWORD(lParam);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   303
			int y = (int16)HIWORD(lParam);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   304
			POINT pt;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   305
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   306
			/* If the mouse was not in the window and it has moved it means it has
5021
6fb82e055ceb (svn r7062) -[win32] Codechange: Remove unneeded WM_MOUSEENTER event, and change mouse behaviour
Darkvater
parents: 5020
diff changeset
   307
			 * come into the window, so start drawing the mouse. Also start
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   308
			 * tracking the mouse for exiting the window */
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   309
			if (!_cursor.in_window) {
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   310
				_cursor.in_window = true;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   311
				SetTimer(hwnd, TID_POLLMOUSE, MOUSE_POLL_DELAY, (TIMERPROC)TrackMouseTimerProc);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   312
5021
6fb82e055ceb (svn r7062) -[win32] Codechange: Remove unneeded WM_MOUSEENTER event, and change mouse behaviour
Darkvater
parents: 5020
diff changeset
   313
				DrawMouseCursor();
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   314
			}
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   315
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   316
			if (_wnd.double_size) {
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   317
				x /= 2;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   318
				y /= 2;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   319
			}
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   320
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   321
			if (_cursor.fix_at) {
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   322
				int dx = x - _cursor.pos.x;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   323
				int dy = y - _cursor.pos.y;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   324
				if (dx != 0 || dy != 0) {
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   325
					_cursor.delta.x += dx;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   326
					_cursor.delta.y += dy;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   327
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   328
					pt.x = _cursor.pos.x;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   329
					pt.y = _cursor.pos.y;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   330
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   331
					if (_wnd.double_size) {
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   332
						pt.x *= 2;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   333
						pt.y *= 2;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   334
					}
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   335
					ClientToScreen(hwnd, &pt);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   336
					SetCursorPos(pt.x, pt.y);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   337
				}
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   338
			} else {
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   339
				_cursor.delta.x += x - _cursor.pos.x;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   340
				_cursor.delta.y += y - _cursor.pos.y;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   341
				_cursor.pos.x = x;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   342
				_cursor.pos.y = y;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   343
				_cursor.dirty = true;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   344
			}
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   345
			MyShowCursor(false);
5090
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
   346
			HandleMouseEvents();
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   347
			return 0;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   348
		}
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   349
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   350
		case WM_KEYDOWN: {
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   351
			// this is the rewritten ascii input function
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   352
			// it disables windows deadkey handling --> more linux like :D
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5090
diff changeset
   353
			wchar_t w = 0;
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   354
			byte ks[256];
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   355
			uint scancode;
5086
386ba9fe0621 (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5076
diff changeset
   356
			uint32 pressed_key;
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   357
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   358
			GetKeyboardState(ks);
5112
e76a1f05ed8b (svn r7187) -CodeChange: [win32] Limit success of ToUnicode/ToAscii to only one translated character as we only support one and remove TranslateMessage() call since we do not use it anyways (glx)
Darkvater
parents: 5108
diff changeset
   359
			if (ToUnicode(wParam, 0, ks, &w, 1, 0) != 1) {
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5090
diff changeset
   360
				/* On win9x ToUnicode always fails, so fall back to ToAscii */
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   361
				if (ToAscii(wParam, 0, ks, (LPWORD)&w, 0) != 1) w = 0; // no translation was possible
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   362
			}
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   363
5086
386ba9fe0621 (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5076
diff changeset
   364
			pressed_key = w | MapWindowsKey(wParam) << 16;
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   365
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   366
			scancode = GB(lParam, 16, 8);
5086
386ba9fe0621 (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5076
diff changeset
   367
			if (scancode == 41) pressed_key = w | WKC_BACKQUOTE << 16;
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   368
5089
67c761427921 (svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents: 5086
diff changeset
   369
			if (GB(pressed_key, 16, 16) == ('D' | WKC_CTRL) && !_wnd.fullscreen) {
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   370
				_double_size ^= 1;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   371
				_wnd.double_size = _double_size;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   372
				ClientSizeChanged(_wnd.width, _wnd.height);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   373
				MarkWholeScreenDirty();
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   374
			}
5086
386ba9fe0621 (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5076
diff changeset
   375
			HandleKeypress(pressed_key);
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   376
			break;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   377
		}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   378
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   379
		case WM_SYSKEYDOWN: /* user presses F10 or Alt, both activating the title-menu */
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   380
			switch (wParam) {
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   381
				case VK_RETURN:
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   382
				case 'F': /* Full Screen on ALT + ENTER/F */
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   383
					ToggleFullScreen(!_wnd.fullscreen);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   384
					return 0;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   385
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   386
				case VK_MENU: /* Just ALT */
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   387
					return 0; // do nothing
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   388
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   389
				case VK_F10: /* F10, ignore activation of menu */
5086
386ba9fe0621 (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5076
diff changeset
   390
					HandleKeypress(MapWindowsKey(wParam) << 16);
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   391
					return 0;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   392
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   393
				default: /* ALT in combination with something else */
5086
386ba9fe0621 (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5076
diff changeset
   394
					HandleKeypress(MapWindowsKey(wParam) << 16);
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   395
					break;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   396
			}
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   397
			break;
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   398
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   399
		case WM_SIZE:
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   400
			if (wParam != SIZE_MINIMIZED) {
5019
9046723a0878 (svn r7060) -Fix (r5874): Restore of window maximized state not always working (Mart3p) . Remember
Darkvater
parents: 4840
diff changeset
   401
				/* Set maximized flag when we maximize (obviously), but also when we
9046723a0878 (svn r7060) -Fix (r5874): Restore of window maximized state not always working (Mart3p) . Remember
Darkvater
parents: 4840
diff changeset
   402
				 * switched to fullscreen from a maximized state */
9046723a0878 (svn r7060) -Fix (r5874): Restore of window maximized state not always working (Mart3p) . Remember
Darkvater
parents: 4840
diff changeset
   403
				_window_maximize = (wParam == SIZE_MAXIMIZED || (_window_maximize && _fullscreen));
5020
e2564f4400b7 (svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents: 5019
diff changeset
   404
				if (_window_maximize) {
e2564f4400b7 (svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents: 5019
diff changeset
   405
					_bck_resolution[0] = _cur_resolution[0];
e2564f4400b7 (svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents: 5019
diff changeset
   406
					_bck_resolution[1] = _cur_resolution[1];
e2564f4400b7 (svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents: 5019
diff changeset
   407
				}
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   408
				ClientSizeChanged(LOWORD(lParam), HIWORD(lParam));
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   409
			}
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   410
			return 0;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   411
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   412
		case WM_SIZING: {
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   413
			RECT* r = (RECT*)lParam;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   414
			RECT r2;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   415
			int w, h;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   416
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   417
			SetRect(&r2, 0, 0, 0, 0);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   418
			AdjustWindowRect(&r2, GetWindowLong(hwnd, GWL_STYLE), FALSE);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   419
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   420
			w = r->right - r->left - (r2.right - r2.left);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   421
			h = r->bottom - r->top - (r2.bottom - r2.top);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   422
			if (_wnd.double_size) {
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   423
				w /= 2;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   424
				h /= 2;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   425
			}
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   426
			w = clamp(w, 64, MAX_SCREEN_WIDTH);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   427
			h = clamp(h, 64, MAX_SCREEN_HEIGHT);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   428
			if (_wnd.double_size) {
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   429
				w *= 2;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   430
				h *= 2;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   431
			}
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   432
			SetRect(&r2, 0, 0, w, h);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   433
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   434
			AdjustWindowRect(&r2, GetWindowLong(hwnd, GWL_STYLE), FALSE);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   435
			w = r2.right - r2.left;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   436
			h = r2.bottom - r2.top;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   437
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   438
			switch (wParam) {
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   439
				case WMSZ_BOTTOM:
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   440
					r->bottom = r->top + h;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   441
					break;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   442
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   443
				case WMSZ_BOTTOMLEFT:
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   444
					r->bottom = r->top + h;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   445
					r->left = r->right - w;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   446
					break;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   447
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   448
				case WMSZ_BOTTOMRIGHT:
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   449
					r->bottom = r->top + h;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   450
					r->right = r->left + w;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   451
					break;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   452
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   453
				case WMSZ_LEFT:
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   454
					r->left = r->right - w;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   455
					break;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   456
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   457
				case WMSZ_RIGHT:
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   458
					r->right = r->left + w;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   459
					break;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   460
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   461
				case WMSZ_TOP:
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   462
					r->top = r->bottom - h;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   463
					break;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   464
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   465
				case WMSZ_TOPLEFT:
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   466
					r->top = r->bottom - h;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   467
					r->left = r->right - w;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   468
					break;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   469
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   470
				case WMSZ_TOPRIGHT:
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   471
					r->top = r->bottom - h;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   472
					r->right = r->left + w;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   473
					break;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   474
			}
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   475
			return TRUE;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   476
		}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   477
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   478
// needed for wheel
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   479
#if !defined(WM_MOUSEWHEEL)
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   480
# define WM_MOUSEWHEEL 0x020A
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   481
#endif  //WM_MOUSEWHEEL
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   482
#if !defined(GET_WHEEL_DELTA_WPARAM)
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   483
# define GET_WHEEL_DELTA_WPARAM(wparam) ((short)HIWORD(wparam))
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   484
#endif  //GET_WHEEL_DELTA_WPARAM
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   485
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   486
		case WM_MOUSEWHEEL: {
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   487
			int delta = GET_WHEEL_DELTA_WPARAM(wParam);
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   488
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   489
			if (delta < 0) {
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   490
				_cursor.wheel++;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   491
			} else if (delta > 0) {
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   492
				_cursor.wheel--;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   493
			}
5090
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
   494
			HandleMouseEvents();
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   495
			return 0;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   496
		}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   497
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   498
		case WM_ACTIVATEAPP:
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   499
			_wnd.has_focus = (wParam != 0);
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   500
			break;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   501
	}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   502
	return DefWindowProc(hwnd, msg, wParam, lParam);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   503
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   504
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   505
static void RegisterWndClass(void)
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   506
{
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   507
	static bool registered = false;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   508
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   509
	if (!registered) {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   510
		HINSTANCE hinst = GetModuleHandle(NULL);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   511
		WNDCLASS wnd = {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   512
			0,
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   513
			WndProcGdi,
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   514
			0,
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   515
			0,
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   516
			hinst,
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   517
			LoadIcon(hinst, MAKEINTRESOURCE(100)),
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   518
			LoadCursor(NULL, IDC_ARROW),
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   519
			0,
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   520
			0,
5168
e206899169c4 (svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents: 5112
diff changeset
   521
			_T("OTTD")
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   522
		};
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   523
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   524
		registered = true;
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   525
		if (!RegisterClass(&wnd)) error("RegisterClass failed");
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   526
	}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   527
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   528
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   529
static void MakeWindow(bool full_screen)
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   530
{
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   531
	_fullscreen = full_screen;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   532
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   533
	_wnd.double_size = _double_size && !full_screen;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   534
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   535
	// recreate window?
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   536
	if ((full_screen || _wnd.fullscreen) && _wnd.main_wnd) {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   537
		DestroyWindow(_wnd.main_wnd);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   538
		_wnd.main_wnd = 0;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   539
	}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   540
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   541
	if (full_screen) {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   542
		DEVMODE settings;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   543
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   544
		memset(&settings, 0, sizeof(settings));
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   545
		settings.dmSize = sizeof(settings);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   546
		settings.dmFields =
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   547
			(_fullscreen_bpp != 0 ? DM_BITSPERPEL : 0) |
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   548
			DM_PELSWIDTH |
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   549
			DM_PELSHEIGHT |
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   550
			(_display_hz != 0 ? DM_DISPLAYFREQUENCY : 0);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   551
		settings.dmBitsPerPel = _fullscreen_bpp;
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   552
		settings.dmPelsWidth  = _wnd.width_org;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   553
		settings.dmPelsHeight = _wnd.height_org;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   554
		settings.dmDisplayFrequency = _display_hz;
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   555
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   556
		if (ChangeDisplaySettings(&settings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   557
			MakeWindow(false);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   558
			return;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   559
		}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   560
	} else if (_wnd.fullscreen) {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   561
		// restore display?
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   562
		ChangeDisplaySettings(NULL, 0);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   563
	}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   564
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   565
	{
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   566
		RECT r;
5377
aaf47045a721 (svn r7562) -Fix (r7060, 5874): It seems windows doesn't have the same functionality for CreateWindow when starting a program from the console or from the GUI. Because of this starting OpenTTD from the desktop wouldn't maximize the window, even if the config file said so. So work around this...
Darkvater
parents: 5169
diff changeset
   567
		DWORD style, showstyle;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   568
		int x, y, w, h;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   569
5377
aaf47045a721 (svn r7562) -Fix (r7060, 5874): It seems windows doesn't have the same functionality for CreateWindow when starting a program from the console or from the GUI. Because of this starting OpenTTD from the desktop wouldn't maximize the window, even if the config file said so. So work around this...
Darkvater
parents: 5169
diff changeset
   570
		showstyle = SW_SHOWNORMAL;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   571
		_wnd.fullscreen = full_screen;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   572
		if (_wnd.fullscreen) {
5377
aaf47045a721 (svn r7562) -Fix (r7060, 5874): It seems windows doesn't have the same functionality for CreateWindow when starting a program from the console or from the GUI. Because of this starting OpenTTD from the desktop wouldn't maximize the window, even if the config file said so. So work around this...
Darkvater
parents: 5169
diff changeset
   573
			style = WS_POPUP;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   574
			SetRect(&r, 0, 0, _wnd.width_org, _wnd.height_org);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   575
		} else {
5377
aaf47045a721 (svn r7562) -Fix (r7060, 5874): It seems windows doesn't have the same functionality for CreateWindow when starting a program from the console or from the GUI. Because of this starting OpenTTD from the desktop wouldn't maximize the window, even if the config file said so. So work around this...
Darkvater
parents: 5169
diff changeset
   576
			style = WS_OVERLAPPEDWINDOW;
5019
9046723a0878 (svn r7060) -Fix (r5874): Restore of window maximized state not always working (Mart3p) . Remember
Darkvater
parents: 4840
diff changeset
   577
			/* On window creation, check if we were in maximize mode before */
5377
aaf47045a721 (svn r7562) -Fix (r7060, 5874): It seems windows doesn't have the same functionality for CreateWindow when starting a program from the console or from the GUI. Because of this starting OpenTTD from the desktop wouldn't maximize the window, even if the config file said so. So work around this...
Darkvater
parents: 5169
diff changeset
   578
			if (_window_maximize) showstyle = SW_SHOWMAXIMIZED;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   579
			SetRect(&r, 0, 0, _wnd.width, _wnd.height);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   580
		}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   581
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   582
		AdjustWindowRect(&r, style, FALSE);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   583
		w = r.right - r.left;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   584
		h = r.bottom - r.top;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   585
		x = (GetSystemMetrics(SM_CXSCREEN) - w) / 2;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   586
		y = (GetSystemMetrics(SM_CYSCREEN) - h) / 2;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   587
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   588
		if (_wnd.main_wnd) {
4258
087d44b3514f (svn r5874) -Feature [FS#234]: Remember the maximized state and restore on start. This also fixes a bug where a different resolution is chosen for a maximized window, but it retains the maximized flag. Only win32.
Darkvater
parents: 4077
diff changeset
   589
			ShowWindow(_wnd.main_wnd, SW_SHOWNORMAL); // remove maximize-flag
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   590
			SetWindowPos(_wnd.main_wnd, 0, x, y, w, h, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   591
		} else {
4840
a76d40e0aea4 (svn r6766) -Codechange: Move _openttd_revision[] into the functions that use it instead of global
Darkvater
parents: 4548
diff changeset
   592
			extern const char _openttd_revision[];
5168
e206899169c4 (svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents: 5112
diff changeset
   593
			TCHAR Windowtitle[50];
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   594
5168
e206899169c4 (svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents: 5112
diff changeset
   595
			_sntprintf(Windowtitle, sizeof(Windowtitle), _T("OpenTTD %s"), MB_TO_WIDE(_openttd_revision));
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   596
5168
e206899169c4 (svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents: 5112
diff changeset
   597
			_wnd.main_wnd = CreateWindow(_T("OTTD"), Windowtitle, style, x, y, w, h, 0, 0, GetModuleHandle(NULL), 0);
4258
087d44b3514f (svn r5874) -Feature [FS#234]: Remember the maximized state and restore on start. This also fixes a bug where a different resolution is chosen for a maximized window, but it retains the maximized flag. Only win32.
Darkvater
parents: 4077
diff changeset
   598
			if (_wnd.main_wnd == NULL) error("CreateWindow failed");
5377
aaf47045a721 (svn r7562) -Fix (r7060, 5874): It seems windows doesn't have the same functionality for CreateWindow when starting a program from the console or from the GUI. Because of this starting OpenTTD from the desktop wouldn't maximize the window, even if the config file said so. So work around this...
Darkvater
parents: 5169
diff changeset
   599
			ShowWindow(_wnd.main_wnd, showstyle);
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   600
		}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   601
	}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   602
	GameSizeChanged(); // invalidate all windows, force redraw
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   603
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   604
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   605
static bool AllocateDibSection(int w, int h)
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   606
{
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   607
	BITMAPINFO *bi;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   608
	HDC dc;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   609
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   610
	w = clamp(w, 64, MAX_SCREEN_WIDTH);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   611
	h = clamp(h, 64, MAX_SCREEN_HEIGHT);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   612
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   613
	if (w == _screen.width && h == _screen.height)
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   614
		return false;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   615
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   616
	_screen.width = w;
2398
912f16512ce2 (svn r2924) Introduce the ALIGN() macro which aligns values to multiples of a power of 2, for exact semantics see the commment in macros.h
tron
parents: 2228
diff changeset
   617
	_screen.pitch = ALIGN(w, 4);
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   618
	_screen.height = h;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   619
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   620
	if (_wnd.alloced_bits) {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   621
		free(_wnd.alloced_bits);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   622
		_wnd.alloced_bits = NULL;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   623
	}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   624
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   625
	bi = (BITMAPINFO*)alloca(sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD)*256);
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   626
	memset(bi, 0, sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD)*256);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   627
	bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   628
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   629
	if (_wnd.double_size) {
2398
912f16512ce2 (svn r2924) Introduce the ALIGN() macro which aligns values to multiples of a power of 2, for exact semantics see the commment in macros.h
tron
parents: 2228
diff changeset
   630
		w = ALIGN(w, 4);
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   631
		_wnd.alloced_bits = _wnd.buffer_bits = (Pixel*)malloc(w * h);
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   632
		w *= 2;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   633
		h *= 2;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   634
	}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   635
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   636
	bi->bmiHeader.biWidth = _wnd.width = w;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   637
	bi->bmiHeader.biHeight = -(_wnd.height = h);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   638
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   639
	bi->bmiHeader.biPlanes = 1;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   640
	bi->bmiHeader.biBitCount = 8;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   641
	bi->bmiHeader.biCompression = BI_RGB;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   642
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   643
	if (_wnd.dib_sect) DeleteObject(_wnd.dib_sect);
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   644
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   645
	dc = GetDC(0);
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   646
	_wnd.dib_sect = CreateDIBSection(dc, bi, DIB_RGB_COLORS, (VOID**)&_wnd.bitmap_bits, NULL, 0);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   647
	if (_wnd.dib_sect == NULL) error("CreateDIBSection failed");
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   648
	ReleaseDC(0, dc);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   649
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   650
	if (!_wnd.double_size) _wnd.buffer_bits = _wnd.bitmap_bits;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   651
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   652
	return true;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   653
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   654
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   655
static const uint16 default_resolutions[][2] = {
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   656
	{  640,  480 },
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   657
	{  800,  600 },
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   658
	{ 1024,  768 },
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   659
	{ 1152,  864 },
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   660
	{ 1280,  800 },
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   661
	{ 1280,  960 },
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   662
	{ 1280, 1024 },
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   663
	{ 1400, 1050 },
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   664
	{ 1600, 1200 },
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   665
	{ 1680, 1050 },
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   666
	{ 1920, 1200 }
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   667
};
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   668
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   669
static void FindResolutions(void)
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   670
{
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3802
diff changeset
   671
	uint n = 0;
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3802
diff changeset
   672
	uint i;
5169
cd4113ed34f7 (svn r7279) -Codechange: [win32] Add Windows95/98 support by using MSLU. Only workaround is that the
Darkvater
parents: 5168
diff changeset
   673
	DEVMODEA dm;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   674
5169
cd4113ed34f7 (svn r7279) -Codechange: [win32] Add Windows95/98 support by using MSLU. Only workaround is that the
Darkvater
parents: 5168
diff changeset
   675
	/* XXX - EnumDisplaySettingsW crashes with unicows.dll on Windows95
cd4113ed34f7 (svn r7279) -Codechange: [win32] Add Windows95/98 support by using MSLU. Only workaround is that the
Darkvater
parents: 5168
diff changeset
   676
	 * Doesn't really matter since we don't pass a string anyways, but still
cd4113ed34f7 (svn r7279) -Codechange: [win32] Add Windows95/98 support by using MSLU. Only workaround is that the
Darkvater
parents: 5168
diff changeset
   677
	 * a letdown */
cd4113ed34f7 (svn r7279) -Codechange: [win32] Add Windows95/98 support by using MSLU. Only workaround is that the
Darkvater
parents: 5168
diff changeset
   678
	for (i = 0; EnumDisplaySettingsA(NULL, i, &dm) != 0; i++) {
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   679
		if (dm.dmBitsPerPel == 8 && IS_INT_INSIDE(dm.dmPelsWidth, 640, MAX_SCREEN_WIDTH + 1) &&
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3802
diff changeset
   680
				IS_INT_INSIDE(dm.dmPelsHeight, 480, MAX_SCREEN_HEIGHT + 1)) {
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3802
diff changeset
   681
			uint j;
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3802
diff changeset
   682
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   683
			for (j = 0; j < n; j++) {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   684
				if (_resolutions[j][0] == dm.dmPelsWidth && _resolutions[j][1] == dm.dmPelsHeight) break;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   685
			}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   686
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   687
			/* In the previous loop we have checked already existing/added resolutions if
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   688
			 * they are the same as the new ones. If this is not the case (j == n); we have
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   689
			 * looped all and found none, add the new one to the list. If we have reached the
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   690
			 * maximum amount of resolutions, then quit querying the display */
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   691
			if (j == n) {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   692
				_resolutions[j][0] = dm.dmPelsWidth;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   693
				_resolutions[j][1] = dm.dmPelsHeight;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   694
				if (++n == lengthof(_resolutions)) break;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   695
			}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   696
		}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   697
	}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   698
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   699
	/* We have found no resolutions, show the default list */
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   700
	if (n == 0) {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   701
		memcpy(_resolutions, default_resolutions, sizeof(default_resolutions));
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   702
		n = lengthof(default_resolutions);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   703
	}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   704
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   705
	_num_resolutions = n;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   706
	SortResolutions(_num_resolutions);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   707
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   708
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   709
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   710
static const char *Win32GdiStart(const char * const *parm)
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   711
{
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   712
	memset(&_wnd, 0, sizeof(_wnd));
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   713
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   714
	RegisterWndClass();
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   715
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   716
	MakePalette();
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   717
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   718
	FindResolutions();
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   719
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   720
	// fullscreen uses those
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   721
	_wnd.width_org = _cur_resolution[0];
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   722
	_wnd.height_org = _cur_resolution[1];
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   723
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   724
	AllocateDibSection(_cur_resolution[0], _cur_resolution[1]);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   725
	MarkWholeScreenDirty();
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   726
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   727
	MakeWindow(_fullscreen);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   728
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   729
	return NULL;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   730
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   731
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   732
static void Win32GdiStop(void)
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   733
{
3285
50f77357b94a (svn r3999) - Fix: [win32] Change the order of DestroyWindow and ChangeDisplay. On some machines a sizechange messagequeue is handled before sending WM_DISPLAYCHANGE resulting in an improper resolution written to the configuration file when exiting from fullscreen. (Frostregen)
Darkvater
parents: 3051
diff changeset
   734
	DeleteObject(_wnd.gdi_palette);
50f77357b94a (svn r3999) - Fix: [win32] Change the order of DestroyWindow and ChangeDisplay. On some machines a sizechange messagequeue is handled before sending WM_DISPLAYCHANGE resulting in an improper resolution written to the configuration file when exiting from fullscreen. (Frostregen)
Darkvater
parents: 3051
diff changeset
   735
	DeleteObject(_wnd.dib_sect);
50f77357b94a (svn r3999) - Fix: [win32] Change the order of DestroyWindow and ChangeDisplay. On some machines a sizechange messagequeue is handled before sending WM_DISPLAYCHANGE resulting in an improper resolution written to the configuration file when exiting from fullscreen. (Frostregen)
Darkvater
parents: 3051
diff changeset
   736
	DestroyWindow(_wnd.main_wnd);
50f77357b94a (svn r3999) - Fix: [win32] Change the order of DestroyWindow and ChangeDisplay. On some machines a sizechange messagequeue is handled before sending WM_DISPLAYCHANGE resulting in an improper resolution written to the configuration file when exiting from fullscreen. (Frostregen)
Darkvater
parents: 3051
diff changeset
   737
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   738
	if (_wnd.fullscreen) ChangeDisplaySettings(NULL, 0);
2773
121bea441d07 (svn r3320) - Fix: FS#22 - Exiting with double size enabled saves wrong window size. Reset the window size to its true size upon exiting when double-size is active. Is set in ClientSizeChanged.
Darkvater
parents: 2665
diff changeset
   739
	if (_double_size) {
121bea441d07 (svn r3320) - Fix: FS#22 - Exiting with double size enabled saves wrong window size. Reset the window size to its true size upon exiting when double-size is active. Is set in ClientSizeChanged.
Darkvater
parents: 2665
diff changeset
   740
		_cur_resolution[0] *= 2;
121bea441d07 (svn r3320) - Fix: FS#22 - Exiting with double size enabled saves wrong window size. Reset the window size to its true size upon exiting when double-size is active. Is set in ClientSizeChanged.
Darkvater
parents: 2665
diff changeset
   741
		_cur_resolution[1] *= 2;
121bea441d07 (svn r3320) - Fix: FS#22 - Exiting with double size enabled saves wrong window size. Reset the window size to its true size upon exiting when double-size is active. Is set in ClientSizeChanged.
Darkvater
parents: 2665
diff changeset
   742
	}
121bea441d07 (svn r3320) - Fix: FS#22 - Exiting with double size enabled saves wrong window size. Reset the window size to its true size upon exiting when double-size is active. Is set in ClientSizeChanged.
Darkvater
parents: 2665
diff changeset
   743
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   744
	MyShowCursor(true);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   745
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   746
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   747
// simple upscaler by 2
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   748
static void filter(int left, int top, int width, int height)
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   749
{
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   750
	uint p = _screen.pitch;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   751
	const Pixel *s = _wnd.buffer_bits + top * p + left;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   752
	Pixel *d = _wnd.bitmap_bits + top * p * 4 + left * 2;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   753
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   754
	for (; height > 0; height--) {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   755
		int i;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   756
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   757
		for (i = 0; i != width; i++) {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   758
			d[i * 2] = d[i * 2 + 1] = d[i * 2 + p * 2] = d[i * 2 + 1 + p * 2] = s[i];
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   759
		}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   760
		s += p;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   761
		d += p * 4;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   762
	}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   763
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   764
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   765
static void Win32GdiMakeDirty(int left, int top, int width, int height)
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   766
{
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   767
	RECT r = { left, top, left + width, top + height };
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   768
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   769
	if (_wnd.double_size) {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   770
		filter(left, top, width, height);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   771
		r.left *= 2;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   772
		r.top *= 2;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   773
		r.right *= 2;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   774
		r.bottom *= 2;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   775
	}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   776
	InvalidateRect(_wnd.main_wnd, &r, FALSE);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   777
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   778
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   779
static void CheckPaletteAnim(void)
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   780
{
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   781
	if (_pal_last_dirty == -1)
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   782
		return;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   783
	InvalidateRect(_wnd.main_wnd, NULL, FALSE);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   784
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   785
2228
93cdde0f85ba (svn r2748) Remove unused cruft from the main loop
tron
parents: 2208
diff changeset
   786
static void Win32GdiMainLoop(void)
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   787
{
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   788
	MSG mesg;
5581
cf2b8ba6556b (svn r8028) -Fix: overflow of ticks was not handled properly, possibly resulting a non-reacting gameserver/gameclient.
rubidium
parents: 5475
diff changeset
   789
	uint32 cur_ticks = GetTickCount();
cf2b8ba6556b (svn r8028) -Fix: overflow of ticks was not handled properly, possibly resulting a non-reacting gameserver/gameclient.
rubidium
parents: 5475
diff changeset
   790
	uint32 next_tick = cur_ticks + 30;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   791
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   792
	_wnd.running = true;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   793
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2773
diff changeset
   794
	for (;;) {
5581
cf2b8ba6556b (svn r8028) -Fix: overflow of ticks was not handled properly, possibly resulting a non-reacting gameserver/gameclient.
rubidium
parents: 5475
diff changeset
   795
		uint32 prev_cur_ticks = cur_ticks; // to check for wrapping
cf2b8ba6556b (svn r8028) -Fix: overflow of ticks was not handled properly, possibly resulting a non-reacting gameserver/gameclient.
rubidium
parents: 5475
diff changeset
   796
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   797
		while (PeekMessage(&mesg, NULL, 0, 0, PM_REMOVE)) {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   798
			InteractiveRandom(); // randomness
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   799
			DispatchMessage(&mesg);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   800
		}
2228
93cdde0f85ba (svn r2748) Remove unused cruft from the main loop
tron
parents: 2208
diff changeset
   801
		if (_exit_game) return;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   802
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   803
#if defined(_DEBUG)
5089
67c761427921 (svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents: 5086
diff changeset
   804
		if (_wnd.has_focus && GetAsyncKeyState(VK_SHIFT) < 0 &&
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   805
#else
5089
67c761427921 (svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents: 5086
diff changeset
   806
		/* Speed up using TAB, but disable for ALT+TAB of course */
67c761427921 (svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents: 5086
diff changeset
   807
		if (_wnd.has_focus && GetAsyncKeyState(VK_TAB) < 0 && GetAsyncKeyState(VK_MENU) >= 0 &&
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   808
#endif
5089
67c761427921 (svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents: 5086
diff changeset
   809
			  !_networking && _game_mode != GM_MENU) {
67c761427921 (svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents: 5086
diff changeset
   810
			_fast_forward |= 2;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
   811
		} else if (_fast_forward & 2) {
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   812
			_fast_forward = 0;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
   813
		}
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   814
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   815
		cur_ticks = GetTickCount();
5581
cf2b8ba6556b (svn r8028) -Fix: overflow of ticks was not handled properly, possibly resulting a non-reacting gameserver/gameclient.
rubidium
parents: 5475
diff changeset
   816
		if (cur_ticks >= next_tick || (_fast_forward && !_pause) || cur_ticks < prev_cur_ticks) {
cf2b8ba6556b (svn r8028) -Fix: overflow of ticks was not handled properly, possibly resulting a non-reacting gameserver/gameclient.
rubidium
parents: 5475
diff changeset
   817
			next_tick = cur_ticks + 30;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   818
			_ctrl_pressed = _wnd.has_focus && GetAsyncKeyState(VK_CONTROL)<0;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   819
			_shift_pressed = _wnd.has_focus && GetAsyncKeyState(VK_SHIFT)<0;
2664
875d6800baaf (svn r3206) Wrap all instances of _dbg_screen_rect in #ifdef _DEBUG
tron
parents: 2398
diff changeset
   820
#ifdef _DEBUG
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   821
			_dbg_screen_rect = _wnd.has_focus && GetAsyncKeyState(VK_CAPITAL)<0;
2665
6be437294af0 (svn r3207) Typo in last revision
tron
parents: 2664
diff changeset
   822
#endif
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   823
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   824
			// determine which directional keys are down
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   825
			if (_wnd.has_focus) {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   826
				_dirkeys =
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   827
					(GetAsyncKeyState(VK_LEFT) < 0 ? 1 : 0) +
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   828
					(GetAsyncKeyState(VK_UP) < 0 ? 2 : 0) +
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   829
					(GetAsyncKeyState(VK_RIGHT) < 0 ? 4 : 0) +
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   830
					(GetAsyncKeyState(VK_DOWN) < 0 ? 8 : 0);
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
   831
			} else {
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   832
				_dirkeys = 0;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
   833
			}
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   834
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   835
			GameLoop();
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   836
			_cursor.delta.x = _cursor.delta.y = 0;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   837
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
   838
			if (_force_full_redraw) MarkWholeScreenDirty();
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   839
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   840
			GdiFlush();
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   841
			_screen.dst_ptr = _wnd.buffer_bits;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   842
			UpdateWindows();
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   843
			CheckPaletteAnim();
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   844
		} else {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   845
			Sleep(1);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   846
			GdiFlush();
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   847
			_screen.dst_ptr = _wnd.buffer_bits;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   848
			DrawTextMessage();
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   849
			DrawMouseCursor();
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   850
		}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   851
	}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   852
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   853
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   854
static bool Win32GdiChangeRes(int w, int h)
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   855
{
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   856
	_wnd.width = _wnd.width_org = w;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   857
	_wnd.height = _wnd.height_org = h;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   858
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   859
	MakeWindow(_fullscreen); // _wnd.fullscreen screws up ingame resolution switching
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   860
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   861
	return true;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   862
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   863
4489
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   864
static void Win32GdiFullScreen(bool full_screen)
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   865
{
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   866
	MakeWindow(full_screen);
e84a0355e096 (svn r6274) Clean up a bit
tron
parents: 4477
diff changeset
   867
}
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   868
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   869
const HalVideoDriver _win32_video_driver = {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   870
	Win32GdiStart,
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   871
	Win32GdiStop,
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   872
	Win32GdiMakeDirty,
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   873
	Win32GdiMainLoop,
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   874
	Win32GdiChangeRes,
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   875
	Win32GdiFullScreen,
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   876
};