author | rubidium |
Sat, 07 Jul 2007 09:20:52 +0000 | |
branch | noai |
changeset 9631 | 8a2d1c2ceb88 |
parent 9629 | 66dde6412125 |
child 9694 | e72987579514 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
2189
d240b9097139
(svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents:
2186
diff
changeset
|
3 |
#include "../stdafx.h" |
d240b9097139
(svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents:
2186
diff
changeset
|
4 |
#include "../openttd.h" |
d240b9097139
(svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents:
2186
diff
changeset
|
5 |
#include "../functions.h" |
d240b9097139
(svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents:
2186
diff
changeset
|
6 |
#include "../gfx.h" |
d240b9097139
(svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents:
2186
diff
changeset
|
7 |
#include "../macros.h" |
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
5565
diff
changeset
|
8 |
#include "../network/network.h" |
2189
d240b9097139
(svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents:
2186
diff
changeset
|
9 |
#include "../variables.h" |
2207
40c928fbde8a
(svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents:
2189
diff
changeset
|
10 |
#include "../win32.h" |
2189
d240b9097139
(svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents:
2186
diff
changeset
|
11 |
#include "../window.h" |
9628
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9624
diff
changeset
|
12 |
#include "../blitter/factory.hpp" |
2189
d240b9097139
(svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents:
2186
diff
changeset
|
13 |
#include "win32_v.h" |
2171
008122046f7f
(svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
2163
diff
changeset
|
14 |
#include <windows.h> |
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5112
diff
changeset
|
15 |
#include <tchar.h> |
0 | 16 |
|
17 |
static struct { |
|
18 |
HWND main_wnd; |
|
19 |
HBITMAP dib_sect; |
|
9628
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9624
diff
changeset
|
20 |
void *buffer_bits; |
0 | 21 |
HPALETTE gdi_palette; |
4489 | 22 |
int width; |
23 |
int height; |
|
24 |
int width_org; |
|
25 |
int height_org; |
|
0 | 26 |
bool fullscreen; |
27 |
bool has_focus; |
|
28 |
bool running; |
|
29 |
} _wnd; |
|
30 |
||
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
|
31 |
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
|
32 |
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
|
33 |
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
|
34 |
uint _fullscreen_bpp; |
5020
a679bc02c88d
(svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents:
5019
diff
changeset
|
35 |
static uint16 _bck_resolution[2]; |
6577
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
36 |
#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
|
37 |
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
|
38 |
#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
|
39 |
|
6573 | 40 |
static void MakePalette() |
0 | 41 |
{ |
42 |
LOGPALETTE *pal; |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
43 |
uint i; |
0 | 44 |
|
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
6603
diff
changeset
|
45 |
pal = (LOGPALETTE*)alloca(sizeof(LOGPALETTE) + (256 - 1) * sizeof(PALETTEENTRY)); |
0 | 46 |
|
47 |
pal->palVersion = 0x300; |
|
48 |
pal->palNumEntries = 256; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
49 |
|
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1957
diff
changeset
|
50 |
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
|
51 |
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
|
52 |
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
|
53 |
pal->palPalEntry[i].peBlue = _cur_palette[i].b; |
0 | 54 |
pal->palPalEntry[i].peFlags = 0; |
55 |
||
56 |
} |
|
57 |
_wnd.gdi_palette = CreatePalette(pal); |
|
4489 | 58 |
if (_wnd.gdi_palette == NULL) error("CreatePalette failed!\n"); |
0 | 59 |
} |
60 |
||
61 |
static void UpdatePalette(HDC dc, uint start, uint count) |
|
62 |
{ |
|
63 |
RGBQUAD rgb[256]; |
|
64 |
uint i; |
|
65 |
||
1995
6dacb8a758a3
(svn r2501) Forgot to change part of the win32 code in r2497
tron
parents:
1991
diff
changeset
|
66 |
for (i = 0; i != count; i++) { |
6dacb8a758a3
(svn r2501) Forgot to change part of the win32 code in r2497
tron
parents:
1991
diff
changeset
|
67 |
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
|
68 |
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
|
69 |
rgb[i].rgbBlue = _cur_palette[start + i].b; |
0 | 70 |
rgb[i].rgbReserved = 0; |
71 |
} |
|
72 |
||
73 |
SetDIBColorTable(dc, start, count, rgb); |
|
74 |
} |
|
75 |
||
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
76 |
struct VkMapping { |
0 | 77 |
byte vk_from; |
78 |
byte vk_count; |
|
79 |
byte map_to; |
|
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
80 |
}; |
0 | 81 |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
82 |
#define AS(x, z) {x, 0, z} |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
83 |
#define AM(x, y, z, w) {x, y - x, z} |
0 | 84 |
|
85 |
static const VkMapping _vk_mapping[] = { |
|
86 |
// Pageup stuff + up/down |
|
87 |
AM(VK_PRIOR,VK_DOWN, WKC_PAGEUP, WKC_DOWN), |
|
88 |
// Map letters & digits |
|
89 |
AM('A','Z','A','Z'), |
|
90 |
AM('0','9','0','9'), |
|
91 |
||
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
|
92 |
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
|
93 |
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
|
94 |
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
|
95 |
AM(VK_INSERT, VK_DELETE, WKC_INSERT, WKC_DELETE), |
0 | 96 |
|
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
|
97 |
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
|
98 |
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
|
99 |
AS(VK_TAB, WKC_TAB), |
0 | 100 |
|
101 |
// 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
|
102 |
AM(VK_F1, VK_F12, WKC_F1, WKC_F12), |
0 | 103 |
|
104 |
// Numeric part. |
|
105 |
// What is the virtual keycode for numeric enter?? |
|
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4300
diff
changeset
|
106 |
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
|
107 |
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
|
108 |
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
|
109 |
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
|
110 |
AS(VK_ADD, WKC_NUM_PLUS), |
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4300
diff
changeset
|
111 |
AS(VK_DECIMAL, WKC_NUM_DECIMAL) |
0 | 112 |
}; |
113 |
||
1466 | 114 |
static uint MapWindowsKey(uint sym) |
0 | 115 |
{ |
1466 | 116 |
const VkMapping *map; |
117 |
uint key = 0; |
|
0 | 118 |
|
1466 | 119 |
for (map = _vk_mapping; map != endof(_vk_mapping); ++map) { |
120 |
if ((uint)(sym - map->vk_from) <= map->vk_count) { |
|
121 |
key = sym - map->vk_from + map->map_to; |
|
122 |
break; |
|
123 |
} |
|
124 |
} |
|
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
|
125 |
|
2026 | 126 |
if (GetAsyncKeyState(VK_SHIFT) < 0) key |= WKC_SHIFT; |
127 |
if (GetAsyncKeyState(VK_CONTROL) < 0) key |= WKC_CTRL; |
|
128 |
if (GetAsyncKeyState(VK_MENU) < 0) key |= WKC_ALT; |
|
0 | 129 |
return key; |
130 |
} |
|
131 |
||
132 |
static bool AllocateDibSection(int w, int h); |
|
133 |
||
134 |
static void ClientSizeChanged(int w, int h) |
|
135 |
{ |
|
136 |
// allocate new dib section of the new size |
|
137 |
if (AllocateDibSection(w, h)) { |
|
138 |
// mark all palette colors dirty |
|
139 |
_pal_first_dirty = 0; |
|
9629 | 140 |
_pal_count_dirty = 255; |
0 | 141 |
GameSizeChanged(); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
142 |
|
0 | 143 |
// redraw screen |
144 |
if (_wnd.running) { |
|
145 |
_screen.dst_ptr = _wnd.buffer_bits; |
|
146 |
UpdateWindows(); |
|
147 |
} |
|
148 |
} |
|
149 |
} |
|
150 |
||
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
151 |
#ifdef _DEBUG |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
152 |
// 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
|
153 |
// It allows you to redraw the screen from within the MSVC debugger |
6573 | 154 |
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
|
155 |
{ |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
156 |
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
|
157 |
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
|
158 |
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
|
159 |
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
|
160 |
|
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
161 |
_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
|
162 |
UpdateWindows(); |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
163 |
|
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
164 |
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
|
165 |
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
|
166 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
167 |
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
|
168 |
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
|
169 |
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
|
170 |
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
|
171 |
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
|
172 |
DeleteDC(dc2); |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
173 |
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
|
174 |
|
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
175 |
return _fooctr++; |
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 |
#endif |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
178 |
|
5021
711e711f6b9a
(svn r7062) -[win32] Codechange: Remove unneeded WM_MOUSEENTER event, and change mouse behaviour
Darkvater
parents:
5020
diff
changeset
|
179 |
/* 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
|
180 |
#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
|
181 |
#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
|
182 |
#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
|
183 |
#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
|
184 |
#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
|
185 |
|
593789444b01
(svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents:
3285
diff
changeset
|
186 |
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
|
187 |
{ |
593789444b01
(svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents:
3285
diff
changeset
|
188 |
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
|
189 |
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
|
190 |
|
593789444b01
(svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents:
3285
diff
changeset
|
191 |
/* 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
|
192 |
* 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
|
193 |
* 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
|
194 |
GetClientRect(hwnd, &rc); |
3802
72aed211db94
(svn r4810) - Fix: removed warning about strict-alias (release build)
glx
parents:
3325
diff
changeset
|
195 |
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
|
196 |
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
|
197 |
|
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 |
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
|
199 |
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
|
200 |
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
|
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 |
} |
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 |
|
9629 | 204 |
static void MakeWindow(bool full_screen) |
205 |
{ |
|
206 |
_fullscreen = full_screen; |
|
207 |
||
208 |
// recreate window? |
|
209 |
if ((full_screen || _wnd.fullscreen) && _wnd.main_wnd) { |
|
210 |
DestroyWindow(_wnd.main_wnd); |
|
211 |
_wnd.main_wnd = 0; |
|
212 |
} |
|
213 |
||
214 |
#if defined(WINCE) |
|
215 |
/* WinCE is always fullscreen */ |
|
216 |
#else |
|
217 |
if (full_screen) { |
|
218 |
DEVMODE settings; |
|
219 |
||
220 |
/* Make sure we are always at least the screen-depth of the blitter */ |
|
221 |
if (_fullscreen_bpp < BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth()) _fullscreen_bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(); |
|
222 |
||
223 |
memset(&settings, 0, sizeof(settings)); |
|
224 |
settings.dmSize = sizeof(settings); |
|
225 |
settings.dmFields = |
|
226 |
(_fullscreen_bpp != 0 ? DM_BITSPERPEL : 0) | |
|
227 |
DM_PELSWIDTH | |
|
228 |
DM_PELSHEIGHT | |
|
229 |
(_display_hz != 0 ? DM_DISPLAYFREQUENCY : 0); |
|
230 |
settings.dmBitsPerPel = _fullscreen_bpp; |
|
231 |
settings.dmPelsWidth = _wnd.width_org; |
|
232 |
settings.dmPelsHeight = _wnd.height_org; |
|
233 |
settings.dmDisplayFrequency = _display_hz; |
|
234 |
||
235 |
if (ChangeDisplaySettings(&settings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) { |
|
236 |
MakeWindow(false); |
|
237 |
return; |
|
238 |
} |
|
239 |
} else if (_wnd.fullscreen) { |
|
240 |
// restore display? |
|
241 |
ChangeDisplaySettings(NULL, 0); |
|
242 |
} |
|
243 |
#endif |
|
244 |
||
245 |
{ |
|
246 |
RECT r; |
|
247 |
DWORD style, showstyle; |
|
248 |
int x, y, w, h; |
|
249 |
||
250 |
showstyle = SW_SHOWNORMAL; |
|
251 |
_wnd.fullscreen = full_screen; |
|
252 |
if (_wnd.fullscreen) { |
|
253 |
style = WS_POPUP; |
|
254 |
SetRect(&r, 0, 0, _wnd.width_org, _wnd.height_org); |
|
255 |
} else { |
|
256 |
style = WS_OVERLAPPEDWINDOW; |
|
257 |
/* On window creation, check if we were in maximize mode before */ |
|
258 |
if (_window_maximize) showstyle = SW_SHOWMAXIMIZED; |
|
259 |
SetRect(&r, 0, 0, _wnd.width, _wnd.height); |
|
260 |
} |
|
261 |
||
262 |
#if !defined(WINCE) |
|
263 |
AdjustWindowRect(&r, style, FALSE); |
|
264 |
#endif |
|
265 |
w = r.right - r.left; |
|
266 |
h = r.bottom - r.top; |
|
267 |
x = (GetSystemMetrics(SM_CXSCREEN) - w) / 2; |
|
268 |
y = (GetSystemMetrics(SM_CYSCREEN) - h) / 2; |
|
269 |
||
270 |
if (_wnd.main_wnd) { |
|
271 |
ShowWindow(_wnd.main_wnd, SW_SHOWNORMAL); // remove maximize-flag |
|
272 |
SetWindowPos(_wnd.main_wnd, 0, x, y, w, h, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER); |
|
273 |
} else { |
|
274 |
extern const char _openttd_revision[]; |
|
275 |
TCHAR Windowtitle[50]; |
|
276 |
||
277 |
_sntprintf(Windowtitle, sizeof(Windowtitle), _T("OpenTTD %s"), MB_TO_WIDE(_openttd_revision)); |
|
278 |
||
279 |
_wnd.main_wnd = CreateWindow(_T("OTTD"), Windowtitle, style, x, y, w, h, 0, 0, GetModuleHandle(NULL), 0); |
|
280 |
if (_wnd.main_wnd == NULL) error("CreateWindow failed"); |
|
281 |
ShowWindow(_wnd.main_wnd, showstyle); |
|
282 |
} |
|
283 |
} |
|
284 |
GameSizeChanged(); // invalidate all windows, force redraw |
|
285 |
} |
|
286 |
||
0 | 287 |
static LRESULT CALLBACK WndProcGdi(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) |
288 |
{ |
|
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
|
289 |
static uint32 keycode = 0; |
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
290 |
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
|
291 |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
292 |
switch (msg) { |
4489 | 293 |
case WM_CREATE: |
294 |
SetTimer(hwnd, TID_POLLMOUSE, MOUSE_POLL_DELAY, (TIMERPROC)TrackMouseTimerProc); |
|
295 |
break; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
296 |
|
4489 | 297 |
case WM_PAINT: { |
298 |
PAINTSTRUCT ps; |
|
299 |
HDC dc,dc2; |
|
300 |
HBITMAP old_bmp; |
|
301 |
HPALETTE old_palette; |
|
0 | 302 |
|
4489 | 303 |
BeginPaint(hwnd, &ps); |
304 |
dc = ps.hdc; |
|
305 |
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
|
306 |
old_bmp = (HBITMAP)SelectObject(dc2, _wnd.dib_sect); |
4489 | 307 |
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
|
308 |
|
9629 | 309 |
if (_pal_count_dirty != 0) { |
310 |
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); |
|
311 |
||
312 |
switch (blitter->UsePaletteAnimation()) { |
|
313 |
case Blitter::PALETTE_ANIMATION_VIDEO_BACKEND: |
|
314 |
UpdatePalette(dc2, _pal_first_dirty, _pal_count_dirty); |
|
315 |
break; |
|
316 |
||
317 |
case Blitter::PALETTE_ANIMATION_BLITTER: |
|
318 |
blitter->PaletteAnimate(_pal_first_dirty, _pal_count_dirty); |
|
319 |
break; |
|
320 |
||
321 |
case Blitter::PALETTE_ANIMATION_NONE: |
|
322 |
break; |
|
323 |
||
324 |
default: |
|
325 |
NOT_REACHED(); |
|
326 |
} |
|
327 |
_pal_count_dirty = 0; |
|
4489 | 328 |
} |
0 | 329 |
|
4489 | 330 |
BitBlt(dc, 0, 0, _wnd.width, _wnd.height, dc2, 0, 0, SRCCOPY); |
331 |
SelectPalette(dc, old_palette, TRUE); |
|
332 |
SelectObject(dc2, old_bmp); |
|
333 |
DeleteDC(dc2); |
|
334 |
EndPaint(hwnd, &ps); |
|
335 |
return 0; |
|
0 | 336 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
337 |
|
4489 | 338 |
case WM_PALETTECHANGED: |
339 |
if ((HWND)wParam == hwnd) return 0; |
|
340 |
/* FALLTHROUGH */ |
|
0 | 341 |
|
4489 | 342 |
case WM_QUERYNEWPALETTE: { |
343 |
HDC hDC = GetWindowDC(hwnd); |
|
344 |
HPALETTE hOldPalette = SelectPalette(hDC, _wnd.gdi_palette, FALSE); |
|
345 |
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
|
346 |
|
4489 | 347 |
SelectPalette(hDC, hOldPalette, TRUE); |
348 |
ReleaseDC(hwnd, hDC); |
|
349 |
if (nChanged) InvalidateRect(hwnd, NULL, FALSE); |
|
350 |
return 0; |
|
0 | 351 |
} |
352 |
||
4489 | 353 |
case WM_CLOSE: |
4548
23b56455df33
(svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents:
4536
diff
changeset
|
354 |
HandleExitGameRequest(); |
0 | 355 |
return 0; |
4489 | 356 |
|
5020
a679bc02c88d
(svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents:
5019
diff
changeset
|
357 |
case WM_DESTROY: |
a679bc02c88d
(svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents:
5019
diff
changeset
|
358 |
if (_window_maximize) { |
a679bc02c88d
(svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents:
5019
diff
changeset
|
359 |
_cur_resolution[0] = _bck_resolution[0]; |
a679bc02c88d
(svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents:
5019
diff
changeset
|
360 |
_cur_resolution[1] = _bck_resolution[1]; |
a679bc02c88d
(svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents:
5019
diff
changeset
|
361 |
} |
a679bc02c88d
(svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents:
5019
diff
changeset
|
362 |
return 0; |
a679bc02c88d
(svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents:
5019
diff
changeset
|
363 |
|
4489 | 364 |
case WM_LBUTTONDOWN: |
365 |
SetCapture(hwnd); |
|
366 |
_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
|
367 |
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
|
368 |
return 0; |
4489 | 369 |
|
370 |
case WM_LBUTTONUP: |
|
371 |
ReleaseCapture(); |
|
372 |
_left_button_down = false; |
|
373 |
_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
|
374 |
HandleMouseEvents(); |
4489 | 375 |
return 0; |
376 |
||
377 |
case WM_RBUTTONDOWN: |
|
378 |
SetCapture(hwnd); |
|
379 |
_right_button_down = true; |
|
380 |
_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
|
381 |
HandleMouseEvents(); |
4489 | 382 |
return 0; |
383 |
||
384 |
case WM_RBUTTONUP: |
|
385 |
ReleaseCapture(); |
|
386 |
_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
|
387 |
HandleMouseEvents(); |
4489 | 388 |
return 0; |
389 |
||
390 |
case WM_MOUSELEAVE: |
|
391 |
UndrawMouseCursor(); |
|
392 |
_cursor.in_window = false; |
|
5021
711e711f6b9a
(svn r7062) -[win32] Codechange: Remove unneeded WM_MOUSEENTER event, and change mouse behaviour
Darkvater
parents:
5020
diff
changeset
|
393 |
|
711e711f6b9a
(svn r7062) -[win32] Codechange: Remove unneeded WM_MOUSEENTER event, and change mouse behaviour
Darkvater
parents:
5020
diff
changeset
|
394 |
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
|
395 |
HandleMouseEvents(); |
5021
711e711f6b9a
(svn r7062) -[win32] Codechange: Remove unneeded WM_MOUSEENTER event, and change mouse behaviour
Darkvater
parents:
5020
diff
changeset
|
396 |
return 0; |
4489 | 397 |
|
398 |
case WM_MOUSEMOVE: { |
|
399 |
int x = (int16)LOWORD(lParam); |
|
400 |
int y = (int16)HIWORD(lParam); |
|
401 |
POINT pt; |
|
402 |
||
403 |
/* 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
|
404 |
* come into the window, so start drawing the mouse. Also start |
4489 | 405 |
* tracking the mouse for exiting the window */ |
406 |
if (!_cursor.in_window) { |
|
407 |
_cursor.in_window = true; |
|
408 |
SetTimer(hwnd, TID_POLLMOUSE, MOUSE_POLL_DELAY, (TIMERPROC)TrackMouseTimerProc); |
|
409 |
||
5021
711e711f6b9a
(svn r7062) -[win32] Codechange: Remove unneeded WM_MOUSEENTER event, and change mouse behaviour
Darkvater
parents:
5020
diff
changeset
|
410 |
DrawMouseCursor(); |
4489 | 411 |
} |
412 |
||
413 |
if (_cursor.fix_at) { |
|
414 |
int dx = x - _cursor.pos.x; |
|
415 |
int dy = y - _cursor.pos.y; |
|
416 |
if (dx != 0 || dy != 0) { |
|
417 |
_cursor.delta.x += dx; |
|
418 |
_cursor.delta.y += dy; |
|
419 |
||
420 |
pt.x = _cursor.pos.x; |
|
421 |
pt.y = _cursor.pos.y; |
|
422 |
||
423 |
ClientToScreen(hwnd, &pt); |
|
424 |
SetCursorPos(pt.x, pt.y); |
|
425 |
} |
|
426 |
} else { |
|
427 |
_cursor.delta.x += x - _cursor.pos.x; |
|
428 |
_cursor.delta.y += y - _cursor.pos.y; |
|
429 |
_cursor.pos.x = x; |
|
430 |
_cursor.pos.y = y; |
|
431 |
_cursor.dirty = true; |
|
432 |
} |
|
433 |
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
|
434 |
HandleMouseEvents(); |
4489 | 435 |
return 0; |
436 |
} |
|
437 |
||
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
|
438 |
#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
|
439 |
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
|
440 |
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
|
441 |
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
|
442 |
|
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
443 |
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
|
444 |
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
|
445 |
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
|
446 |
} |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
447 |
#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
|
448 |
|
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
449 |
case WM_DEADCHAR: |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
450 |
console = GB(lParam, 16, 8) == 41; |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
451 |
return 0; |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
452 |
|
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
|
453 |
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
|
454 |
/* 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
|
455 |
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
|
456 |
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
|
457 |
uint charcode = wParam; |
4489 | 458 |
|
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
459 |
/* If the console key is a dead-key, we need to press it twice to get a WM_CHAR message. |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
460 |
* But we then get two WM_CHAR messages, so ignore the first one */ |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
461 |
if (console && scancode == 41) { |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
462 |
console = false; |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
463 |
return 0; |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
464 |
} |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
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 |
#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
|
467 |
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
|
468 |
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
|
469 |
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
|
470 |
#endif /* UNICODE */ |
4489 | 471 |
|
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
|
472 |
/* 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
|
473 |
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
|
474 |
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
|
475 |
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
|
476 |
} |
4489 | 477 |
|
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
|
478 |
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
|
479 |
keycode = MapWindowsKey(wParam); |
4489 | 480 |
|
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
|
481 |
/* 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
|
482 |
* 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
|
483 |
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
|
484 |
|
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 |
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
|
486 |
return 0; |
0 | 487 |
} |
488 |
||
4489 | 489 |
case WM_SYSKEYDOWN: /* user presses F10 or Alt, both activating the title-menu */ |
490 |
switch (wParam) { |
|
491 |
case VK_RETURN: |
|
492 |
case 'F': /* Full Screen on ALT + ENTER/F */ |
|
493 |
ToggleFullScreen(!_wnd.fullscreen); |
|
494 |
return 0; |
|
0 | 495 |
|
4489 | 496 |
case VK_MENU: /* Just ALT */ |
497 |
return 0; // do nothing |
|
498 |
||
499 |
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
|
500 |
HandleKeypress(MapWindowsKey(wParam) << 16); |
4489 | 501 |
return 0; |
502 |
||
503 |
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
|
504 |
HandleKeypress(MapWindowsKey(wParam) << 16); |
4489 | 505 |
break; |
506 |
} |
|
0 | 507 |
break; |
4489 | 508 |
|
509 |
case WM_SIZE: |
|
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
510 |
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
|
511 |
/* 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
|
512 |
* 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
|
513 |
_window_maximize = (wParam == SIZE_MAXIMIZED || (_window_maximize && _fullscreen)); |
5020
a679bc02c88d
(svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents:
5019
diff
changeset
|
514 |
if (_window_maximize) { |
a679bc02c88d
(svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents:
5019
diff
changeset
|
515 |
_bck_resolution[0] = _cur_resolution[0]; |
a679bc02c88d
(svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents:
5019
diff
changeset
|
516 |
_bck_resolution[1] = _cur_resolution[1]; |
a679bc02c88d
(svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents:
5019
diff
changeset
|
517 |
} |
4489 | 518 |
ClientSizeChanged(LOWORD(lParam), HIWORD(lParam)); |
519 |
} |
|
520 |
return 0; |
|
521 |
||
6009
cf31b0e5c696
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5838
diff
changeset
|
522 |
#if !defined(WINCE) |
4489 | 523 |
case WM_SIZING: { |
524 |
RECT* r = (RECT*)lParam; |
|
525 |
RECT r2; |
|
526 |
int w, h; |
|
527 |
||
528 |
SetRect(&r2, 0, 0, 0, 0); |
|
529 |
AdjustWindowRect(&r2, GetWindowLong(hwnd, GWL_STYLE), FALSE); |
|
530 |
||
531 |
w = r->right - r->left - (r2.right - r2.left); |
|
532 |
h = r->bottom - r->top - (r2.bottom - r2.top); |
|
533 |
w = clamp(w, 64, MAX_SCREEN_WIDTH); |
|
534 |
h = clamp(h, 64, MAX_SCREEN_HEIGHT); |
|
535 |
SetRect(&r2, 0, 0, w, h); |
|
536 |
||
537 |
AdjustWindowRect(&r2, GetWindowLong(hwnd, GWL_STYLE), FALSE); |
|
538 |
w = r2.right - r2.left; |
|
539 |
h = r2.bottom - r2.top; |
|
540 |
||
541 |
switch (wParam) { |
|
542 |
case WMSZ_BOTTOM: |
|
543 |
r->bottom = r->top + h; |
|
544 |
break; |
|
545 |
||
546 |
case WMSZ_BOTTOMLEFT: |
|
547 |
r->bottom = r->top + h; |
|
548 |
r->left = r->right - w; |
|
549 |
break; |
|
550 |
||
551 |
case WMSZ_BOTTOMRIGHT: |
|
552 |
r->bottom = r->top + h; |
|
553 |
r->right = r->left + w; |
|
554 |
break; |
|
555 |
||
556 |
case WMSZ_LEFT: |
|
557 |
r->left = r->right - w; |
|
558 |
break; |
|
559 |
||
560 |
case WMSZ_RIGHT: |
|
561 |
r->right = r->left + w; |
|
562 |
break; |
|
563 |
||
564 |
case WMSZ_TOP: |
|
565 |
r->top = r->bottom - h; |
|
566 |
break; |
|
567 |
||
568 |
case WMSZ_TOPLEFT: |
|
569 |
r->top = r->bottom - h; |
|
570 |
r->left = r->right - w; |
|
571 |
break; |
|
572 |
||
573 |
case WMSZ_TOPRIGHT: |
|
574 |
r->top = r->bottom - h; |
|
575 |
r->right = r->left + w; |
|
576 |
break; |
|
577 |
} |
|
578 |
return TRUE; |
|
0 | 579 |
} |
6010
31378995786b
(svn r8310) -Fix r8309: it is wise to put #endifs in the right place ;)
truelight
parents:
6009
diff
changeset
|
580 |
#endif |
0 | 581 |
|
582 |
// needed for wheel |
|
583 |
#if !defined(WM_MOUSEWHEEL) |
|
4489 | 584 |
# define WM_MOUSEWHEEL 0x020A |
0 | 585 |
#endif //WM_MOUSEWHEEL |
586 |
#if !defined(GET_WHEEL_DELTA_WPARAM) |
|
587 |
# define GET_WHEEL_DELTA_WPARAM(wparam) ((short)HIWORD(wparam)) |
|
588 |
#endif //GET_WHEEL_DELTA_WPARAM |
|
589 |
||
4489 | 590 |
case WM_MOUSEWHEEL: { |
591 |
int delta = GET_WHEEL_DELTA_WPARAM(wParam); |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
592 |
|
4489 | 593 |
if (delta < 0) { |
594 |
_cursor.wheel++; |
|
595 |
} else if (delta > 0) { |
|
596 |
_cursor.wheel--; |
|
597 |
} |
|
5090
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
598 |
HandleMouseEvents(); |
4489 | 599 |
return 0; |
0 | 600 |
} |
601 |
||
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
602 |
case WM_SETFOCUS: |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
603 |
_wnd.has_focus = true; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
604 |
break; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
605 |
|
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
606 |
case WM_KILLFOCUS: |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
607 |
_wnd.has_focus = false; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
608 |
break; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
609 |
|
9628
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9624
diff
changeset
|
610 |
#if !defined(WINCE) |
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
611 |
case WM_ACTIVATE: { |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
612 |
bool active = (LOWORD(wParam) != WA_INACTIVE); |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
613 |
bool minimized = (HIWORD(wParam) != 0); |
9628
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9624
diff
changeset
|
614 |
if (_wnd.fullscreen) { |
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
615 |
if (active && minimized) { |
9628
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9624
diff
changeset
|
616 |
/* Restore the game window */ |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9624
diff
changeset
|
617 |
ShowWindow(hwnd, SW_RESTORE); |
9629 | 618 |
MakeWindow(true); |
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
619 |
} else if (!active && !minimized) { |
9628
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9624
diff
changeset
|
620 |
/* Minimise the window and restore desktop */ |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9624
diff
changeset
|
621 |
ShowWindow(hwnd, SW_MINIMIZE); |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9624
diff
changeset
|
622 |
ChangeDisplaySettings(NULL, 0); |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9624
diff
changeset
|
623 |
} |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9624
diff
changeset
|
624 |
} |
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
625 |
break; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
626 |
} |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
627 |
} |
9628
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9624
diff
changeset
|
628 |
#endif |
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
629 |
|
0 | 630 |
return DefWindowProc(hwnd, msg, wParam, lParam); |
631 |
} |
|
632 |
||
6573 | 633 |
static void RegisterWndClass() |
0 | 634 |
{ |
4489 | 635 |
static bool registered = false; |
636 |
||
0 | 637 |
if (!registered) { |
638 |
HINSTANCE hinst = GetModuleHandle(NULL); |
|
639 |
WNDCLASS wnd = { |
|
640 |
0, |
|
641 |
WndProcGdi, |
|
642 |
0, |
|
643 |
0, |
|
644 |
hinst, |
|
645 |
LoadIcon(hinst, MAKEINTRESOURCE(100)), |
|
646 |
LoadCursor(NULL, IDC_ARROW), |
|
647 |
0, |
|
648 |
0, |
|
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5112
diff
changeset
|
649 |
_T("OTTD") |
0 | 650 |
}; |
4489 | 651 |
|
0 | 652 |
registered = true; |
4489 | 653 |
if (!RegisterClass(&wnd)) error("RegisterClass failed"); |
0 | 654 |
} |
655 |
} |
|
656 |
||
657 |
static bool AllocateDibSection(int w, int h) |
|
658 |
{ |
|
659 |
BITMAPINFO *bi; |
|
660 |
HDC dc; |
|
9628
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9624
diff
changeset
|
661 |
int bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(); |
0 | 662 |
|
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
|
663 |
w = clamp(w, 64, MAX_SCREEN_WIDTH); |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
298
diff
changeset
|
664 |
h = clamp(h, 64, MAX_SCREEN_HEIGHT); |
0 | 665 |
|
9628
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9624
diff
changeset
|
666 |
if (bpp == 0) error("Can't use a blitter that blits 0 bpp for normal visuals"); |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9624
diff
changeset
|
667 |
|
0 | 668 |
if (w == _screen.width && h == _screen.height) |
669 |
return false; |
|
670 |
||
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
|
671 |
_screen.width = w; |
9629 | 672 |
_screen.pitch = (bpp == 8) ? ALIGN(w, 4) : w; |
0 | 673 |
_screen.height = h; |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
6603
diff
changeset
|
674 |
bi = (BITMAPINFO*)alloca(sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256); |
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
6603
diff
changeset
|
675 |
memset(bi, 0, sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256); |
0 | 676 |
bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
677 |
|
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
|
678 |
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
|
679 |
bi->bmiHeader.biHeight = -(_wnd.height = h); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
680 |
|
0 | 681 |
bi->bmiHeader.biPlanes = 1; |
9628
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9624
diff
changeset
|
682 |
bi->bmiHeader.biBitCount = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(); |
0 | 683 |
bi->bmiHeader.biCompression = BI_RGB; |
684 |
||
4489 | 685 |
if (_wnd.dib_sect) DeleteObject(_wnd.dib_sect); |
0 | 686 |
|
687 |
dc = GetDC(0); |
|
9628
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9624
diff
changeset
|
688 |
_wnd.dib_sect = CreateDIBSection(dc, bi, DIB_RGB_COLORS, (VOID**)&_wnd.buffer_bits, NULL, 0); |
4489 | 689 |
if (_wnd.dib_sect == NULL) error("CreateDIBSection failed"); |
0 | 690 |
ReleaseDC(0, dc); |
691 |
||
692 |
return true; |
|
693 |
} |
|
694 |
||
695 |
static const uint16 default_resolutions[][2] = { |
|
4489 | 696 |
{ 640, 480 }, |
697 |
{ 800, 600 }, |
|
698 |
{ 1024, 768 }, |
|
699 |
{ 1152, 864 }, |
|
700 |
{ 1280, 800 }, |
|
701 |
{ 1280, 960 }, |
|
702 |
{ 1280, 1024 }, |
|
703 |
{ 1400, 1050 }, |
|
704 |
{ 1600, 1200 }, |
|
705 |
{ 1680, 1050 }, |
|
706 |
{ 1920, 1200 } |
|
0 | 707 |
}; |
708 |
||
6573 | 709 |
static void FindResolutions() |
0 | 710 |
{ |
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
|
711 |
uint n = 0; |
6009
cf31b0e5c696
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5838
diff
changeset
|
712 |
#if defined(WINCE) |
cf31b0e5c696
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5838
diff
changeset
|
713 |
/* EnumDisplaySettingsW is only supported in CE 4.2+ */ |
cf31b0e5c696
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5838
diff
changeset
|
714 |
/* 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
|
715 |
#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
|
716 |
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
|
717 |
DEVMODEA dm; |
0 | 718 |
|
5169
56b54b6e54ec
(svn r7279) -Codechange: [win32] Add Windows95/98 support by using MSLU. Only workaround is that the
Darkvater
parents:
5168
diff
changeset
|
719 |
/* 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
|
720 |
* 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
|
721 |
* a letdown */ |
56b54b6e54ec
(svn r7279) -Codechange: [win32] Add Windows95/98 support by using MSLU. Only workaround is that the
Darkvater
parents:
5168
diff
changeset
|
722 |
for (i = 0; EnumDisplaySettingsA(NULL, i, &dm) != 0; i++) { |
9628
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9624
diff
changeset
|
723 |
if (dm.dmBitsPerPel == BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() && IS_INT_INSIDE(dm.dmPelsWidth, 640, MAX_SCREEN_WIDTH + 1) && |
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3802
diff
changeset
|
724 |
IS_INT_INSIDE(dm.dmPelsHeight, 480, MAX_SCREEN_HEIGHT + 1)) { |
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3802
diff
changeset
|
725 |
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
|
726 |
|
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
|
727 |
for (j = 0; j < n; j++) { |
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1686
diff
changeset
|
728 |
if (_resolutions[j][0] == dm.dmPelsWidth && _resolutions[j][1] == dm.dmPelsHeight) break; |
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1686
diff
changeset
|
729 |
} |
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1686
diff
changeset
|
730 |
|
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
|
731 |
/* 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
|
732 |
* 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
|
733 |
* 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
|
734 |
* 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
|
735 |
if (j == n) { |
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1686
diff
changeset
|
736 |
_resolutions[j][0] = dm.dmPelsWidth; |
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1686
diff
changeset
|
737 |
_resolutions[j][1] = dm.dmPelsHeight; |
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1686
diff
changeset
|
738 |
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
|
739 |
} |
0 | 740 |
} |
741 |
} |
|
6009
cf31b0e5c696
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5838
diff
changeset
|
742 |
#endif |
0 | 743 |
|
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 |
/* We have found no resolutions, show the default list */ |
0 | 745 |
if (n == 0) { |
746 |
memcpy(_resolutions, default_resolutions, sizeof(default_resolutions)); |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
747 |
n = lengthof(default_resolutions); |
0 | 748 |
} |
749 |
||
750 |
_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
|
751 |
SortResolutions(_num_resolutions); |
0 | 752 |
} |
753 |
||
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
754 |
static FVideoDriver_Win32 iFVideoDriver_Win32; |
0 | 755 |
|
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
756 |
const char *VideoDriver_Win32::Start(const char * const *parm) |
0 | 757 |
{ |
758 |
memset(&_wnd, 0, sizeof(_wnd)); |
|
759 |
||
760 |
RegisterWndClass(); |
|
761 |
||
762 |
MakePalette(); |
|
763 |
||
764 |
FindResolutions(); |
|
765 |
||
766 |
// fullscreen uses those |
|
767 |
_wnd.width_org = _cur_resolution[0]; |
|
768 |
_wnd.height_org = _cur_resolution[1]; |
|
769 |
||
770 |
AllocateDibSection(_cur_resolution[0], _cur_resolution[1]); |
|
771 |
MarkWholeScreenDirty(); |
|
772 |
||
773 |
MakeWindow(_fullscreen); |
|
774 |
||
775 |
return NULL; |
|
776 |
} |
|
777 |
||
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
778 |
void VideoDriver_Win32::Stop() |
0 | 779 |
{ |
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
|
780 |
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
|
781 |
DeleteObject(_wnd.dib_sect); |
c162cb0b57c1
(svn r3999) - Fix: [win32] Change the order of DestroyWindow and ChangeDisplay. On some machines a sizechange messagequeue is handled before sending WM_DISPLAYCHANGE resulting in an improper resolution written to the configuration file when exiting from fullscreen. (Frostregen)
Darkvater
parents:
3051
diff
changeset
|
782 |
DestroyWindow(_wnd.main_wnd); |
c162cb0b57c1
(svn r3999) - Fix: [win32] Change the order of DestroyWindow and ChangeDisplay. On some machines a sizechange messagequeue is handled before sending WM_DISPLAYCHANGE resulting in an improper resolution written to the configuration file when exiting from fullscreen. (Frostregen)
Darkvater
parents:
3051
diff
changeset
|
783 |
|
6009
cf31b0e5c696
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5838
diff
changeset
|
784 |
#if !defined(WINCE) |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
785 |
if (_wnd.fullscreen) ChangeDisplaySettings(NULL, 0); |
6009
cf31b0e5c696
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5838
diff
changeset
|
786 |
#endif |
0 | 787 |
MyShowCursor(true); |
788 |
} |
|
789 |
||
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
790 |
void VideoDriver_Win32::MakeDirty(int left, int top, int width, int height) |
0 | 791 |
{ |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
792 |
RECT r = { left, top, left + width, top + height }; |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
793 |
|
0 | 794 |
InvalidateRect(_wnd.main_wnd, &r, FALSE); |
795 |
} |
|
796 |
||
6573 | 797 |
static void CheckPaletteAnim() |
0 | 798 |
{ |
9629 | 799 |
if (_pal_count_dirty == 0) |
0 | 800 |
return; |
801 |
InvalidateRect(_wnd.main_wnd, NULL, FALSE); |
|
802 |
} |
|
803 |
||
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
804 |
void VideoDriver_Win32::MainLoop() |
0 | 805 |
{ |
806 |
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
|
807 |
uint32 cur_ticks = GetTickCount(); |
9629 | 808 |
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
|
809 |
uint32 next_tick = cur_ticks + 30; |
0 | 810 |
|
811 |
_wnd.running = true; |
|
812 |
||
2952 | 813 |
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
|
814 |
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
|
815 |
|
0 | 816 |
while (PeekMessage(&mesg, NULL, 0, 0, PM_REMOVE)) { |
817 |
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
|
818 |
TranslateMessage(&mesg); |
0 | 819 |
DispatchMessage(&mesg); |
820 |
} |
|
2228 | 821 |
if (_exit_game) return; |
0 | 822 |
|
823 |
#if defined(_DEBUG) |
|
5089
9d290a04d79c
(svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents:
5086
diff
changeset
|
824 |
if (_wnd.has_focus && GetAsyncKeyState(VK_SHIFT) < 0 && |
0 | 825 |
#else |
5089
9d290a04d79c
(svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents:
5086
diff
changeset
|
826 |
/* 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
|
827 |
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
|
828 |
#endif |
5089
9d290a04d79c
(svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents:
5086
diff
changeset
|
829 |
!_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
|
830 |
_fast_forward |= 2; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
831 |
} else if (_fast_forward & 2) { |
0 | 832 |
_fast_forward = 0; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
833 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
834 |
|
1403
6d9ed6c85a22
(svn r1907) - Fix: [ 1114261 ] Speeding up when pressing ALT+TAB (Windows)
darkvater
parents:
1390
diff
changeset
|
835 |
cur_ticks = GetTickCount(); |
6557
8381016f71f3
(svn r9034) -Codechange: renamed _pause to _pause_game, as some targets already have
truelight
parents:
6531
diff
changeset
|
836 |
if (cur_ticks >= next_tick || (_fast_forward && !_pause_game) || cur_ticks < prev_cur_ticks) { |
9629 | 837 |
_realtime_tick += cur_ticks - last_cur_ticks; |
838 |
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
|
839 |
next_tick = cur_ticks + 30; |
0 | 840 |
_ctrl_pressed = _wnd.has_focus && GetAsyncKeyState(VK_CONTROL)<0; |
841 |
_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
|
842 |
|
0 | 843 |
// 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
|
844 |
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
|
845 |
_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
|
846 |
(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
|
847 |
(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
|
848 |
(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
|
849 |
(GetAsyncKeyState(VK_DOWN) < 0 ? 8 : 0); |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
850 |
} 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
|
851 |
_dirkeys = 0; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
852 |
} |
0 | 853 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
854 |
GameLoop(); |
0 | 855 |
_cursor.delta.x = _cursor.delta.y = 0; |
856 |
||
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
857 |
if (_force_full_redraw) MarkWholeScreenDirty(); |
0 | 858 |
|
6009
cf31b0e5c696
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5838
diff
changeset
|
859 |
#if !defined(WINCE) |
0 | 860 |
GdiFlush(); |
6009
cf31b0e5c696
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5838
diff
changeset
|
861 |
#endif |
0 | 862 |
_screen.dst_ptr = _wnd.buffer_bits; |
863 |
UpdateWindows(); |
|
864 |
CheckPaletteAnim(); |
|
865 |
} else { |
|
866 |
Sleep(1); |
|
6009
cf31b0e5c696
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5838
diff
changeset
|
867 |
#if !defined(WINCE) |
0 | 868 |
GdiFlush(); |
6009
cf31b0e5c696
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5838
diff
changeset
|
869 |
#endif |
0 | 870 |
_screen.dst_ptr = _wnd.buffer_bits; |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
871 |
DrawTextMessage(); |
0 | 872 |
DrawMouseCursor(); |
873 |
} |
|
874 |
} |
|
875 |
} |
|
876 |
||
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
877 |
bool VideoDriver_Win32::ChangeResolution(int w, int h) |
0 | 878 |
{ |
879 |
_wnd.width = _wnd.width_org = w; |
|
880 |
_wnd.height = _wnd.height_org = h; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
881 |
|
298
b3e83b94be19
(svn r304) -Fix: [967096] fullscreen. New button 'Fullscreen' in 'Game Options' menu which lets you set fullscreen ingame.
darkvater
parents:
287
diff
changeset
|
882 |
MakeWindow(_fullscreen); // _wnd.fullscreen screws up ingame resolution switching |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
883 |
|
0 | 884 |
return true; |
885 |
} |
|
886 |
||
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
887 |
void VideoDriver_Win32::ToggleFullscreen(bool full_screen) |
4489 | 888 |
{ |
889 |
MakeWindow(full_screen); |
|
890 |
} |