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