author | Darkvater |
Tue, 26 Dec 2006 13:30:48 +0000 | |
changeset 5565 | 4eae079a5609 |
parent 5169 | 56b54b6e54ec |
child 5410 | 68d63813dd0e |
child 5642 | bfa6074e2833 |
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" |
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 "../network.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
|
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" |
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
|
12 |
#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
|
13 |
#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
|
14 |
#include <tchar.h> |
0 | 15 |
|
16 |
static struct { |
|
17 |
HWND main_wnd; |
|
18 |
HBITMAP dib_sect; |
|
2062 | 19 |
Pixel *bitmap_bits; |
20 |
Pixel *buffer_bits; |
|
21 |
Pixel *alloced_bits; |
|
0 | 22 |
HPALETTE gdi_palette; |
4489 | 23 |
int width; |
24 |
int height; |
|
25 |
int width_org; |
|
26 |
int height_org; |
|
0 | 27 |
bool fullscreen; |
28 |
bool double_size; |
|
29 |
bool has_focus; |
|
30 |
bool running; |
|
31 |
} _wnd; |
|
32 |
||
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 |
bool _force_full_redraw; |
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 |
bool _double_size; |
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
|
35 |
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
|
36 |
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
|
37 |
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
|
38 |
static uint16 _bck_resolution[2]; |
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 |
|
1102
316643e34104
(svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents:
1040
diff
changeset
|
40 |
static void MakePalette(void) |
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 |
|
45 |
pal = alloca(sizeof(LOGPALETTE) + (256-1) * sizeof(PALETTEENTRY)); |
|
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 |
||
76 |
typedef struct { |
|
77 |
byte vk_from; |
|
78 |
byte vk_count; |
|
79 |
byte map_to; |
|
80 |
} VkMapping; |
|
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 |
{ |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
136 |
if (_wnd.double_size) { |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
137 |
w /= 2; |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
138 |
h /= 2; |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
139 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
140 |
|
0 | 141 |
// allocate new dib section of the new size |
142 |
if (AllocateDibSection(w, h)) { |
|
143 |
// mark all palette colors dirty |
|
144 |
_pal_first_dirty = 0; |
|
145 |
_pal_last_dirty = 255; |
|
146 |
GameSizeChanged(); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
147 |
|
0 | 148 |
// redraw screen |
149 |
if (_wnd.running) { |
|
150 |
_screen.dst_ptr = _wnd.buffer_bits; |
|
151 |
UpdateWindows(); |
|
152 |
} |
|
153 |
} |
|
154 |
} |
|
155 |
||
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
156 |
#ifdef _DEBUG |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
157 |
// 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
|
158 |
// It allows you to redraw the screen from within the MSVC debugger |
2171
008122046f7f
(svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
2163
diff
changeset
|
159 |
int RedrawScreenDebug(void) |
2125
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 |
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
|
162 |
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
|
163 |
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
|
164 |
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
|
165 |
|
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
166 |
_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
|
167 |
UpdateWindows(); |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
168 |
|
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
169 |
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
|
170 |
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
|
171 |
|
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
172 |
old_bmp = SelectObject(dc2, _wnd.dib_sect); |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
173 |
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
|
174 |
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
|
175 |
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
|
176 |
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
|
177 |
DeleteDC(dc2); |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
178 |
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
|
179 |
|
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
180 |
return _fooctr++; |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
181 |
} |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
182 |
#endif |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
183 |
|
5021
711e711f6b9a
(svn r7062) -[win32] Codechange: Remove unneeded WM_MOUSEENTER event, and change mouse behaviour
Darkvater
parents:
5020
diff
changeset
|
184 |
/* Windows 95 will not have a WM_MOUSELEAVE message, so define it if needed */ |
3312
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 |
#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
|
186 |
#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
|
187 |
#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
|
188 |
#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
|
189 |
#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
|
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 |
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
|
192 |
{ |
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 |
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
|
194 |
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
|
195 |
|
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 |
/* 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
|
197 |
* 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
|
198 |
* 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
|
199 |
GetClientRect(hwnd, &rc); |
3802
72aed211db94
(svn r4810) - Fix: removed warning about strict-alias (release build)
glx
parents:
3325
diff
changeset
|
200 |
MapWindowPoints(hwnd, HWND_DESKTOP, (LPPOINT)(LPRECT)&rc, 2); |
3312
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 |
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
|
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 |
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
|
204 |
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
|
205 |
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
|
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 |
} |
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 |
|
0 | 209 |
static LRESULT CALLBACK WndProcGdi(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) |
210 |
{ |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
211 |
switch (msg) { |
4489 | 212 |
case WM_CREATE: |
213 |
SetTimer(hwnd, TID_POLLMOUSE, MOUSE_POLL_DELAY, (TIMERPROC)TrackMouseTimerProc); |
|
214 |
break; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
215 |
|
4489 | 216 |
case WM_PAINT: { |
217 |
PAINTSTRUCT ps; |
|
218 |
HDC dc,dc2; |
|
219 |
HBITMAP old_bmp; |
|
220 |
HPALETTE old_palette; |
|
0 | 221 |
|
4489 | 222 |
BeginPaint(hwnd, &ps); |
223 |
dc = ps.hdc; |
|
224 |
dc2 = CreateCompatibleDC(dc); |
|
225 |
old_bmp = SelectObject(dc2, _wnd.dib_sect); |
|
226 |
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
|
227 |
|
4489 | 228 |
if (_pal_last_dirty != -1) { |
229 |
UpdatePalette(dc2, _pal_first_dirty, _pal_last_dirty - _pal_first_dirty + 1); |
|
230 |
_pal_last_dirty = -1; |
|
231 |
} |
|
0 | 232 |
|
4489 | 233 |
BitBlt(dc, 0, 0, _wnd.width, _wnd.height, dc2, 0, 0, SRCCOPY); |
234 |
SelectPalette(dc, old_palette, TRUE); |
|
235 |
SelectObject(dc2, old_bmp); |
|
236 |
DeleteDC(dc2); |
|
237 |
EndPaint(hwnd, &ps); |
|
238 |
return 0; |
|
0 | 239 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
240 |
|
4489 | 241 |
case WM_PALETTECHANGED: |
242 |
if ((HWND)wParam == hwnd) return 0; |
|
243 |
/* FALLTHROUGH */ |
|
0 | 244 |
|
4489 | 245 |
case WM_QUERYNEWPALETTE: { |
246 |
HDC hDC = GetWindowDC(hwnd); |
|
247 |
HPALETTE hOldPalette = SelectPalette(hDC, _wnd.gdi_palette, FALSE); |
|
248 |
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
|
249 |
|
4489 | 250 |
SelectPalette(hDC, hOldPalette, TRUE); |
251 |
ReleaseDC(hwnd, hDC); |
|
252 |
if (nChanged) InvalidateRect(hwnd, NULL, FALSE); |
|
253 |
return 0; |
|
0 | 254 |
} |
255 |
||
4489 | 256 |
case WM_CLOSE: |
4548
23b56455df33
(svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents:
4536
diff
changeset
|
257 |
HandleExitGameRequest(); |
0 | 258 |
return 0; |
4489 | 259 |
|
5020
a679bc02c88d
(svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents:
5019
diff
changeset
|
260 |
case WM_DESTROY: |
a679bc02c88d
(svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents:
5019
diff
changeset
|
261 |
if (_window_maximize) { |
a679bc02c88d
(svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents:
5019
diff
changeset
|
262 |
_cur_resolution[0] = _bck_resolution[0]; |
a679bc02c88d
(svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents:
5019
diff
changeset
|
263 |
_cur_resolution[1] = _bck_resolution[1]; |
a679bc02c88d
(svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents:
5019
diff
changeset
|
264 |
} |
a679bc02c88d
(svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents:
5019
diff
changeset
|
265 |
return 0; |
a679bc02c88d
(svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents:
5019
diff
changeset
|
266 |
|
4489 | 267 |
case WM_LBUTTONDOWN: |
268 |
SetCapture(hwnd); |
|
269 |
_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
|
270 |
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
|
271 |
return 0; |
4489 | 272 |
|
273 |
case WM_LBUTTONUP: |
|
274 |
ReleaseCapture(); |
|
275 |
_left_button_down = false; |
|
276 |
_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
|
277 |
HandleMouseEvents(); |
4489 | 278 |
return 0; |
279 |
||
280 |
case WM_RBUTTONDOWN: |
|
281 |
SetCapture(hwnd); |
|
282 |
_right_button_down = true; |
|
283 |
_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
|
284 |
HandleMouseEvents(); |
4489 | 285 |
return 0; |
286 |
||
287 |
case WM_RBUTTONUP: |
|
288 |
ReleaseCapture(); |
|
289 |
_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
|
290 |
HandleMouseEvents(); |
4489 | 291 |
return 0; |
292 |
||
293 |
case WM_MOUSELEAVE: |
|
294 |
UndrawMouseCursor(); |
|
295 |
_cursor.in_window = false; |
|
5021
711e711f6b9a
(svn r7062) -[win32] Codechange: Remove unneeded WM_MOUSEENTER event, and change mouse behaviour
Darkvater
parents:
5020
diff
changeset
|
296 |
|
711e711f6b9a
(svn r7062) -[win32] Codechange: Remove unneeded WM_MOUSEENTER event, and change mouse behaviour
Darkvater
parents:
5020
diff
changeset
|
297 |
if (!_left_button_down && !_right_button_down) MyShowCursor(true); |
5090
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
298 |
HandleMouseEvents(); |
5021
711e711f6b9a
(svn r7062) -[win32] Codechange: Remove unneeded WM_MOUSEENTER event, and change mouse behaviour
Darkvater
parents:
5020
diff
changeset
|
299 |
return 0; |
4489 | 300 |
|
301 |
case WM_MOUSEMOVE: { |
|
302 |
int x = (int16)LOWORD(lParam); |
|
303 |
int y = (int16)HIWORD(lParam); |
|
304 |
POINT pt; |
|
305 |
||
306 |
/* 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
|
307 |
* come into the window, so start drawing the mouse. Also start |
4489 | 308 |
* tracking the mouse for exiting the window */ |
309 |
if (!_cursor.in_window) { |
|
310 |
_cursor.in_window = true; |
|
311 |
SetTimer(hwnd, TID_POLLMOUSE, MOUSE_POLL_DELAY, (TIMERPROC)TrackMouseTimerProc); |
|
312 |
||
5021
711e711f6b9a
(svn r7062) -[win32] Codechange: Remove unneeded WM_MOUSEENTER event, and change mouse behaviour
Darkvater
parents:
5020
diff
changeset
|
313 |
DrawMouseCursor(); |
4489 | 314 |
} |
315 |
||
316 |
if (_wnd.double_size) { |
|
317 |
x /= 2; |
|
318 |
y /= 2; |
|
319 |
} |
|
320 |
||
321 |
if (_cursor.fix_at) { |
|
322 |
int dx = x - _cursor.pos.x; |
|
323 |
int dy = y - _cursor.pos.y; |
|
324 |
if (dx != 0 || dy != 0) { |
|
325 |
_cursor.delta.x += dx; |
|
326 |
_cursor.delta.y += dy; |
|
327 |
||
328 |
pt.x = _cursor.pos.x; |
|
329 |
pt.y = _cursor.pos.y; |
|
330 |
||
331 |
if (_wnd.double_size) { |
|
332 |
pt.x *= 2; |
|
333 |
pt.y *= 2; |
|
334 |
} |
|
335 |
ClientToScreen(hwnd, &pt); |
|
336 |
SetCursorPos(pt.x, pt.y); |
|
337 |
} |
|
338 |
} else { |
|
339 |
_cursor.delta.x += x - _cursor.pos.x; |
|
340 |
_cursor.delta.y += y - _cursor.pos.y; |
|
341 |
_cursor.pos.x = x; |
|
342 |
_cursor.pos.y = y; |
|
343 |
_cursor.dirty = true; |
|
344 |
} |
|
345 |
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
|
346 |
HandleMouseEvents(); |
4489 | 347 |
return 0; |
348 |
} |
|
349 |
||
350 |
case WM_KEYDOWN: { |
|
351 |
// this is the rewritten ascii input function |
|
352 |
// it disables windows deadkey handling --> more linux like :D |
|
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5090
diff
changeset
|
353 |
wchar_t w = 0; |
4489 | 354 |
byte ks[256]; |
355 |
uint scancode; |
|
5086
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5076
diff
changeset
|
356 |
uint32 pressed_key; |
4489 | 357 |
|
358 |
GetKeyboardState(ks); |
|
5112
9bb62a7fc166
(svn r7187) -CodeChange: [win32] Limit success of ToUnicode/ToAscii to only one translated character as we only support one and remove TranslateMessage() call since we do not use it anyways (glx)
Darkvater
parents:
5108
diff
changeset
|
359 |
if (ToUnicode(wParam, 0, ks, &w, 1, 0) != 1) { |
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5090
diff
changeset
|
360 |
/* On win9x ToUnicode always fails, so fall back to ToAscii */ |
5112
9bb62a7fc166
(svn r7187) -CodeChange: [win32] Limit success of ToUnicode/ToAscii to only one translated character as we only support one and remove TranslateMessage() call since we do not use it anyways (glx)
Darkvater
parents:
5108
diff
changeset
|
361 |
if (ToAscii(wParam, 0, ks, &w, 0) != 1) w = 0; // no translation was possible |
4489 | 362 |
} |
363 |
||
5086
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5076
diff
changeset
|
364 |
pressed_key = w | MapWindowsKey(wParam) << 16; |
4489 | 365 |
|
366 |
scancode = GB(lParam, 16, 8); |
|
5086
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5076
diff
changeset
|
367 |
if (scancode == 41) pressed_key = w | WKC_BACKQUOTE << 16; |
4489 | 368 |
|
5089
9d290a04d79c
(svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents:
5086
diff
changeset
|
369 |
if (GB(pressed_key, 16, 16) == ('D' | WKC_CTRL) && !_wnd.fullscreen) { |
4489 | 370 |
_double_size ^= 1; |
371 |
_wnd.double_size = _double_size; |
|
372 |
ClientSizeChanged(_wnd.width, _wnd.height); |
|
373 |
MarkWholeScreenDirty(); |
|
374 |
} |
|
5086
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5076
diff
changeset
|
375 |
HandleKeypress(pressed_key); |
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
|
376 |
break; |
0 | 377 |
} |
378 |
||
4489 | 379 |
case WM_SYSKEYDOWN: /* user presses F10 or Alt, both activating the title-menu */ |
380 |
switch (wParam) { |
|
381 |
case VK_RETURN: |
|
382 |
case 'F': /* Full Screen on ALT + ENTER/F */ |
|
383 |
ToggleFullScreen(!_wnd.fullscreen); |
|
384 |
return 0; |
|
0 | 385 |
|
4489 | 386 |
case VK_MENU: /* Just ALT */ |
387 |
return 0; // do nothing |
|
388 |
||
389 |
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
|
390 |
HandleKeypress(MapWindowsKey(wParam) << 16); |
4489 | 391 |
return 0; |
392 |
||
393 |
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
|
394 |
HandleKeypress(MapWindowsKey(wParam) << 16); |
4489 | 395 |
break; |
396 |
} |
|
0 | 397 |
break; |
4489 | 398 |
|
399 |
case WM_SIZE: |
|
400 |
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
|
401 |
/* 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
|
402 |
* 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
|
403 |
_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
|
404 |
if (_window_maximize) { |
a679bc02c88d
(svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents:
5019
diff
changeset
|
405 |
_bck_resolution[0] = _cur_resolution[0]; |
a679bc02c88d
(svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents:
5019
diff
changeset
|
406 |
_bck_resolution[1] = _cur_resolution[1]; |
a679bc02c88d
(svn r7061) -[win32] Feature: Remember the window size between restarts when quit in fullscreen mode.
Darkvater
parents:
5019
diff
changeset
|
407 |
} |
4489 | 408 |
ClientSizeChanged(LOWORD(lParam), HIWORD(lParam)); |
409 |
} |
|
410 |
return 0; |
|
411 |
||
412 |
case WM_SIZING: { |
|
413 |
RECT* r = (RECT*)lParam; |
|
414 |
RECT r2; |
|
415 |
int w, h; |
|
416 |
||
417 |
SetRect(&r2, 0, 0, 0, 0); |
|
418 |
AdjustWindowRect(&r2, GetWindowLong(hwnd, GWL_STYLE), FALSE); |
|
419 |
||
420 |
w = r->right - r->left - (r2.right - r2.left); |
|
421 |
h = r->bottom - r->top - (r2.bottom - r2.top); |
|
422 |
if (_wnd.double_size) { |
|
423 |
w /= 2; |
|
424 |
h /= 2; |
|
425 |
} |
|
426 |
w = clamp(w, 64, MAX_SCREEN_WIDTH); |
|
427 |
h = clamp(h, 64, MAX_SCREEN_HEIGHT); |
|
428 |
if (_wnd.double_size) { |
|
429 |
w *= 2; |
|
430 |
h *= 2; |
|
431 |
} |
|
432 |
SetRect(&r2, 0, 0, w, h); |
|
433 |
||
434 |
AdjustWindowRect(&r2, GetWindowLong(hwnd, GWL_STYLE), FALSE); |
|
435 |
w = r2.right - r2.left; |
|
436 |
h = r2.bottom - r2.top; |
|
437 |
||
438 |
switch (wParam) { |
|
439 |
case WMSZ_BOTTOM: |
|
440 |
r->bottom = r->top + h; |
|
441 |
break; |
|
442 |
||
443 |
case WMSZ_BOTTOMLEFT: |
|
444 |
r->bottom = r->top + h; |
|
445 |
r->left = r->right - w; |
|
446 |
break; |
|
447 |
||
448 |
case WMSZ_BOTTOMRIGHT: |
|
449 |
r->bottom = r->top + h; |
|
450 |
r->right = r->left + w; |
|
451 |
break; |
|
452 |
||
453 |
case WMSZ_LEFT: |
|
454 |
r->left = r->right - w; |
|
455 |
break; |
|
456 |
||
457 |
case WMSZ_RIGHT: |
|
458 |
r->right = r->left + w; |
|
459 |
break; |
|
460 |
||
461 |
case WMSZ_TOP: |
|
462 |
r->top = r->bottom - h; |
|
463 |
break; |
|
464 |
||
465 |
case WMSZ_TOPLEFT: |
|
466 |
r->top = r->bottom - h; |
|
467 |
r->left = r->right - w; |
|
468 |
break; |
|
469 |
||
470 |
case WMSZ_TOPRIGHT: |
|
471 |
r->top = r->bottom - h; |
|
472 |
r->right = r->left + w; |
|
473 |
break; |
|
474 |
} |
|
475 |
return TRUE; |
|
0 | 476 |
} |
477 |
||
478 |
// needed for wheel |
|
479 |
#if !defined(WM_MOUSEWHEEL) |
|
4489 | 480 |
# define WM_MOUSEWHEEL 0x020A |
0 | 481 |
#endif //WM_MOUSEWHEEL |
482 |
#if !defined(GET_WHEEL_DELTA_WPARAM) |
|
483 |
# define GET_WHEEL_DELTA_WPARAM(wparam) ((short)HIWORD(wparam)) |
|
484 |
#endif //GET_WHEEL_DELTA_WPARAM |
|
485 |
||
4489 | 486 |
case WM_MOUSEWHEEL: { |
487 |
int delta = GET_WHEEL_DELTA_WPARAM(wParam); |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
488 |
|
4489 | 489 |
if (delta < 0) { |
490 |
_cursor.wheel++; |
|
491 |
} else if (delta > 0) { |
|
492 |
_cursor.wheel--; |
|
493 |
} |
|
5090
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
494 |
HandleMouseEvents(); |
4489 | 495 |
return 0; |
0 | 496 |
} |
497 |
||
4489 | 498 |
case WM_ACTIVATEAPP: |
499 |
_wnd.has_focus = (bool)wParam; |
|
500 |
break; |
|
0 | 501 |
} |
502 |
return DefWindowProc(hwnd, msg, wParam, lParam); |
|
503 |
} |
|
504 |
||
1102
316643e34104
(svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents:
1040
diff
changeset
|
505 |
static void RegisterWndClass(void) |
0 | 506 |
{ |
4489 | 507 |
static bool registered = false; |
508 |
||
0 | 509 |
if (!registered) { |
510 |
HINSTANCE hinst = GetModuleHandle(NULL); |
|
511 |
WNDCLASS wnd = { |
|
512 |
0, |
|
513 |
WndProcGdi, |
|
514 |
0, |
|
515 |
0, |
|
516 |
hinst, |
|
517 |
LoadIcon(hinst, MAKEINTRESOURCE(100)), |
|
518 |
LoadCursor(NULL, IDC_ARROW), |
|
519 |
0, |
|
520 |
0, |
|
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5112
diff
changeset
|
521 |
_T("OTTD") |
0 | 522 |
}; |
4489 | 523 |
|
0 | 524 |
registered = true; |
4489 | 525 |
if (!RegisterClass(&wnd)) error("RegisterClass failed"); |
0 | 526 |
} |
527 |
} |
|
528 |
||
529 |
static void MakeWindow(bool full_screen) |
|
530 |
{ |
|
531 |
_fullscreen = full_screen; |
|
532 |
||
533 |
_wnd.double_size = _double_size && !full_screen; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
534 |
|
0 | 535 |
// recreate window? |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
536 |
if ((full_screen || _wnd.fullscreen) && _wnd.main_wnd) { |
0 | 537 |
DestroyWindow(_wnd.main_wnd); |
538 |
_wnd.main_wnd = 0; |
|
539 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
540 |
|
0 | 541 |
if (full_screen) { |
542 |
DEVMODE settings; |
|
543 |
||
4489 | 544 |
memset(&settings, 0, sizeof(settings)); |
545 |
settings.dmSize = sizeof(settings); |
|
546 |
settings.dmFields = |
|
547 |
(_fullscreen_bpp != 0 ? DM_BITSPERPEL : 0) | |
|
548 |
DM_PELSWIDTH | |
|
549 |
DM_PELSHEIGHT | |
|
550 |
(_display_hz != 0 ? DM_DISPLAYFREQUENCY : 0); |
|
551 |
settings.dmBitsPerPel = _fullscreen_bpp; |
|
552 |
settings.dmPelsWidth = _wnd.width_org; |
|
0 | 553 |
settings.dmPelsHeight = _wnd.height_org; |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
554 |
settings.dmDisplayFrequency = _display_hz; |
4489 | 555 |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
556 |
if (ChangeDisplaySettings(&settings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) { |
0 | 557 |
MakeWindow(false); |
558 |
return; |
|
559 |
} |
|
560 |
} else if (_wnd.fullscreen) { |
|
561 |
// restore display? |
|
562 |
ChangeDisplaySettings(NULL, 0); |
|
563 |
} |
|
564 |
||
565 |
{ |
|
566 |
RECT r; |
|
5565
4eae079a5609
(svn r7562) -Fix (r7060, 5874): It seems windows doesn't have the same functionality for CreateWindow when starting a program from the console or from the GUI. Because of this starting OpenTTD from the desktop wouldn't maximize the window, even if the config file said so. So work around this...
Darkvater
parents:
5169
diff
changeset
|
567 |
DWORD style, showstyle; |
0 | 568 |
int x, y, w, h; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
569 |
|
5565
4eae079a5609
(svn r7562) -Fix (r7060, 5874): It seems windows doesn't have the same functionality for CreateWindow when starting a program from the console or from the GUI. Because of this starting OpenTTD from the desktop wouldn't maximize the window, even if the config file said so. So work around this...
Darkvater
parents:
5169
diff
changeset
|
570 |
showstyle = SW_SHOWNORMAL; |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
571 |
_wnd.fullscreen = full_screen; |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
572 |
if (_wnd.fullscreen) { |
5565
4eae079a5609
(svn r7562) -Fix (r7060, 5874): It seems windows doesn't have the same functionality for CreateWindow when starting a program from the console or from the GUI. Because of this starting OpenTTD from the desktop wouldn't maximize the window, even if the config file said so. So work around this...
Darkvater
parents:
5169
diff
changeset
|
573 |
style = WS_POPUP; |
0 | 574 |
SetRect(&r, 0, 0, _wnd.width_org, _wnd.height_org); |
575 |
} else { |
|
5565
4eae079a5609
(svn r7562) -Fix (r7060, 5874): It seems windows doesn't have the same functionality for CreateWindow when starting a program from the console or from the GUI. Because of this starting OpenTTD from the desktop wouldn't maximize the window, even if the config file said so. So work around this...
Darkvater
parents:
5169
diff
changeset
|
576 |
style = WS_OVERLAPPEDWINDOW; |
5019
1e16d845265a
(svn r7060) -Fix (r5874): Restore of window maximized state not always working (Mart3p) . Remember
Darkvater
parents:
4840
diff
changeset
|
577 |
/* On window creation, check if we were in maximize mode before */ |
5565
4eae079a5609
(svn r7562) -Fix (r7060, 5874): It seems windows doesn't have the same functionality for CreateWindow when starting a program from the console or from the GUI. Because of this starting OpenTTD from the desktop wouldn't maximize the window, even if the config file said so. So work around this...
Darkvater
parents:
5169
diff
changeset
|
578 |
if (_window_maximize) showstyle = SW_SHOWMAXIMIZED; |
0 | 579 |
SetRect(&r, 0, 0, _wnd.width, _wnd.height); |
580 |
} |
|
581 |
||
582 |
AdjustWindowRect(&r, style, FALSE); |
|
583 |
w = r.right - r.left; |
|
584 |
h = r.bottom - r.top; |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
585 |
x = (GetSystemMetrics(SM_CXSCREEN) - w) / 2; |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
586 |
y = (GetSystemMetrics(SM_CYSCREEN) - h) / 2; |
0 | 587 |
|
588 |
if (_wnd.main_wnd) { |
|
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
|
589 |
ShowWindow(_wnd.main_wnd, SW_SHOWNORMAL); // remove maximize-flag |
0 | 590 |
SetWindowPos(_wnd.main_wnd, 0, x, y, w, h, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER); |
591 |
} else { |
|
4840
176bc2a66322
(svn r6766) -Codechange: Move _openttd_revision[] into the functions that use it instead of global
Darkvater
parents:
4548
diff
changeset
|
592 |
extern const char _openttd_revision[]; |
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5112
diff
changeset
|
593 |
TCHAR Windowtitle[50]; |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
594 |
|
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5112
diff
changeset
|
595 |
_sntprintf(Windowtitle, sizeof(Windowtitle), _T("OpenTTD %s"), MB_TO_WIDE(_openttd_revision)); |
659
a98c731921b4
(svn r1093) -Fix: Hopefully fixed windows revision issues once and for all. Removed globalness of _openttd_revision and put all such ifdefs into one place. If server has a revision only the same revisions can join; if the server has no revision everyone can join. I reckon this should be a server-side option to allow people to join or not to join.
darkvater
parents:
656
diff
changeset
|
596 |
|
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5112
diff
changeset
|
597 |
_wnd.main_wnd = CreateWindow(_T("OTTD"), Windowtitle, style, x, y, w, h, 0, 0, GetModuleHandle(NULL), 0); |
4258
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
|
598 |
if (_wnd.main_wnd == NULL) error("CreateWindow failed"); |
5565
4eae079a5609
(svn r7562) -Fix (r7060, 5874): It seems windows doesn't have the same functionality for CreateWindow when starting a program from the console or from the GUI. Because of this starting OpenTTD from the desktop wouldn't maximize the window, even if the config file said so. So work around this...
Darkvater
parents:
5169
diff
changeset
|
599 |
ShowWindow(_wnd.main_wnd, showstyle); |
0 | 600 |
} |
601 |
} |
|
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
|
602 |
GameSizeChanged(); // invalidate all windows, force redraw |
0 | 603 |
} |
604 |
||
605 |
static bool AllocateDibSection(int w, int h) |
|
606 |
{ |
|
607 |
BITMAPINFO *bi; |
|
608 |
HDC dc; |
|
609 |
||
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
|
610 |
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
|
611 |
h = clamp(h, 64, MAX_SCREEN_HEIGHT); |
0 | 612 |
|
613 |
if (w == _screen.width && h == _screen.height) |
|
614 |
return false; |
|
615 |
||
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
|
616 |
_screen.width = w; |
2398
70de6626d65f
(svn r2924) Introduce the ALIGN() macro which aligns values to multiples of a power of 2, for exact semantics see the commment in macros.h
tron
parents:
2228
diff
changeset
|
617 |
_screen.pitch = ALIGN(w, 4); |
0 | 618 |
_screen.height = h; |
619 |
||
620 |
if (_wnd.alloced_bits) { |
|
621 |
free(_wnd.alloced_bits); |
|
622 |
_wnd.alloced_bits = NULL; |
|
623 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
624 |
|
0 | 625 |
bi = alloca(sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD)*256); |
626 |
memset(bi, 0, sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD)*256); |
|
627 |
bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
628 |
|
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
|
629 |
if (_wnd.double_size) { |
2398
70de6626d65f
(svn r2924) Introduce the ALIGN() macro which aligns values to multiples of a power of 2, for exact semantics see the commment in macros.h
tron
parents:
2228
diff
changeset
|
630 |
w = ALIGN(w, 4); |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
631 |
_wnd.alloced_bits = _wnd.buffer_bits = malloc(w * h); |
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
|
632 |
w *= 2; |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
298
diff
changeset
|
633 |
h *= 2; |
c44133836566
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
298
diff
changeset
|
634 |
} |
0 | 635 |
|
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
|
636 |
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
|
637 |
bi->bmiHeader.biHeight = -(_wnd.height = h); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
638 |
|
0 | 639 |
bi->bmiHeader.biPlanes = 1; |
640 |
bi->bmiHeader.biBitCount = 8; |
|
641 |
bi->bmiHeader.biCompression = BI_RGB; |
|
642 |
||
4489 | 643 |
if (_wnd.dib_sect) DeleteObject(_wnd.dib_sect); |
0 | 644 |
|
645 |
dc = GetDC(0); |
|
4489 | 646 |
_wnd.dib_sect = CreateDIBSection(dc, bi, DIB_RGB_COLORS, (VOID**)&_wnd.bitmap_bits, NULL, 0); |
647 |
if (_wnd.dib_sect == NULL) error("CreateDIBSection failed"); |
|
0 | 648 |
ReleaseDC(0, dc); |
649 |
||
4489 | 650 |
if (!_wnd.double_size) _wnd.buffer_bits = _wnd.bitmap_bits; |
0 | 651 |
|
652 |
return true; |
|
653 |
} |
|
654 |
||
655 |
static const uint16 default_resolutions[][2] = { |
|
4489 | 656 |
{ 640, 480 }, |
657 |
{ 800, 600 }, |
|
658 |
{ 1024, 768 }, |
|
659 |
{ 1152, 864 }, |
|
660 |
{ 1280, 800 }, |
|
661 |
{ 1280, 960 }, |
|
662 |
{ 1280, 1024 }, |
|
663 |
{ 1400, 1050 }, |
|
664 |
{ 1600, 1200 }, |
|
665 |
{ 1680, 1050 }, |
|
666 |
{ 1920, 1200 } |
|
0 | 667 |
}; |
668 |
||
1102
316643e34104
(svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents:
1040
diff
changeset
|
669 |
static void FindResolutions(void) |
0 | 670 |
{ |
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
|
671 |
uint n = 0; |
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
|
672 |
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
|
673 |
DEVMODEA dm; |
0 | 674 |
|
5169
56b54b6e54ec
(svn r7279) -Codechange: [win32] Add Windows95/98 support by using MSLU. Only workaround is that the
Darkvater
parents:
5168
diff
changeset
|
675 |
/* XXX - EnumDisplaySettingsW crashes with unicows.dll on Windows95 |
56b54b6e54ec
(svn r7279) -Codechange: [win32] Add Windows95/98 support by using MSLU. Only workaround is that the
Darkvater
parents:
5168
diff
changeset
|
676 |
* Doesn't really matter since we don't pass a string anyways, but still |
56b54b6e54ec
(svn r7279) -Codechange: [win32] Add Windows95/98 support by using MSLU. Only workaround is that the
Darkvater
parents:
5168
diff
changeset
|
677 |
* a letdown */ |
56b54b6e54ec
(svn r7279) -Codechange: [win32] Add Windows95/98 support by using MSLU. Only workaround is that the
Darkvater
parents:
5168
diff
changeset
|
678 |
for (i = 0; EnumDisplaySettingsA(NULL, i, &dm) != 0; i++) { |
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
|
679 |
if (dm.dmBitsPerPel == 8 && 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
|
680 |
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
|
681 |
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
|
682 |
|
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
|
683 |
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
|
684 |
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
|
685 |
} |
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
|
686 |
|
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
|
687 |
/* 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
|
688 |
* 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
|
689 |
* 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
|
690 |
* 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
|
691 |
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
|
692 |
_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
|
693 |
_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
|
694 |
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
|
695 |
} |
0 | 696 |
} |
697 |
} |
|
698 |
||
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
|
699 |
/* We have found no resolutions, show the default list */ |
0 | 700 |
if (n == 0) { |
701 |
memcpy(_resolutions, default_resolutions, sizeof(default_resolutions)); |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
702 |
n = lengthof(default_resolutions); |
0 | 703 |
} |
704 |
||
705 |
_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
|
706 |
SortResolutions(_num_resolutions); |
0 | 707 |
} |
708 |
||
709 |
||
1301
313804601383
(svn r1805) Teach the driver layer a few things about const correctness
tron
parents:
1230
diff
changeset
|
710 |
static const char *Win32GdiStart(const char * const *parm) |
0 | 711 |
{ |
712 |
memset(&_wnd, 0, sizeof(_wnd)); |
|
713 |
||
714 |
RegisterWndClass(); |
|
715 |
||
716 |
MakePalette(); |
|
717 |
||
718 |
FindResolutions(); |
|
719 |
||
720 |
// fullscreen uses those |
|
721 |
_wnd.width_org = _cur_resolution[0]; |
|
722 |
_wnd.height_org = _cur_resolution[1]; |
|
723 |
||
724 |
AllocateDibSection(_cur_resolution[0], _cur_resolution[1]); |
|
725 |
MarkWholeScreenDirty(); |
|
726 |
||
727 |
MakeWindow(_fullscreen); |
|
728 |
||
729 |
return NULL; |
|
730 |
} |
|
731 |
||
1102
316643e34104
(svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents:
1040
diff
changeset
|
732 |
static void Win32GdiStop(void) |
0 | 733 |
{ |
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
|
734 |
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
|
735 |
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
|
736 |
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
|
737 |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
738 |
if (_wnd.fullscreen) ChangeDisplaySettings(NULL, 0); |
2773
d51afa1ff173
(svn r3320) - Fix: FS#22 - Exiting with double size enabled saves wrong window size. Reset the window size to its true size upon exiting when double-size is active. Is set in ClientSizeChanged.
Darkvater
parents:
2665
diff
changeset
|
739 |
if (_double_size) { |
d51afa1ff173
(svn r3320) - Fix: FS#22 - Exiting with double size enabled saves wrong window size. Reset the window size to its true size upon exiting when double-size is active. Is set in ClientSizeChanged.
Darkvater
parents:
2665
diff
changeset
|
740 |
_cur_resolution[0] *= 2; |
d51afa1ff173
(svn r3320) - Fix: FS#22 - Exiting with double size enabled saves wrong window size. Reset the window size to its true size upon exiting when double-size is active. Is set in ClientSizeChanged.
Darkvater
parents:
2665
diff
changeset
|
741 |
_cur_resolution[1] *= 2; |
d51afa1ff173
(svn r3320) - Fix: FS#22 - Exiting with double size enabled saves wrong window size. Reset the window size to its true size upon exiting when double-size is active. Is set in ClientSizeChanged.
Darkvater
parents:
2665
diff
changeset
|
742 |
} |
d51afa1ff173
(svn r3320) - Fix: FS#22 - Exiting with double size enabled saves wrong window size. Reset the window size to its true size upon exiting when double-size is active. Is set in ClientSizeChanged.
Darkvater
parents:
2665
diff
changeset
|
743 |
|
0 | 744 |
MyShowCursor(true); |
745 |
} |
|
746 |
||
747 |
// simple upscaler by 2 |
|
748 |
static void filter(int left, int top, int width, int height) |
|
749 |
{ |
|
750 |
uint p = _screen.pitch; |
|
2062 | 751 |
const Pixel *s = _wnd.buffer_bits + top * p + left; |
752 |
Pixel *d = _wnd.bitmap_bits + top * p * 4 + left * 2; |
|
0 | 753 |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
754 |
for (; height > 0; height--) { |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
755 |
int i; |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
756 |
|
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
757 |
for (i = 0; i != width; i++) { |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
758 |
d[i * 2] = d[i * 2 + 1] = d[i * 2 + p * 2] = d[i * 2 + 1 + p * 2] = s[i]; |
0 | 759 |
} |
760 |
s += p; |
|
761 |
d += p * 4; |
|
762 |
} |
|
763 |
} |
|
764 |
||
765 |
static void Win32GdiMakeDirty(int left, int top, int width, int height) |
|
766 |
{ |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
767 |
RECT r = { left, top, left + width, top + height }; |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
768 |
|
0 | 769 |
if (_wnd.double_size) { |
770 |
filter(left, top, width, height); |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
771 |
r.left *= 2; |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
772 |
r.top *= 2; |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
773 |
r.right *= 2; |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
774 |
r.bottom *= 2; |
0 | 775 |
} |
776 |
InvalidateRect(_wnd.main_wnd, &r, FALSE); |
|
777 |
} |
|
778 |
||
1102
316643e34104
(svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents:
1040
diff
changeset
|
779 |
static void CheckPaletteAnim(void) |
0 | 780 |
{ |
781 |
if (_pal_last_dirty == -1) |
|
782 |
return; |
|
783 |
InvalidateRect(_wnd.main_wnd, NULL, FALSE); |
|
784 |
} |
|
785 |
||
2228 | 786 |
static void Win32GdiMainLoop(void) |
0 | 787 |
{ |
788 |
MSG mesg; |
|
789 |
uint32 next_tick = GetTickCount() + 30, cur_ticks; |
|
790 |
||
791 |
_wnd.running = true; |
|
792 |
||
2952 | 793 |
for (;;) { |
0 | 794 |
while (PeekMessage(&mesg, NULL, 0, 0, PM_REMOVE)) { |
795 |
InteractiveRandom(); // randomness |
|
796 |
DispatchMessage(&mesg); |
|
797 |
} |
|
2228 | 798 |
if (_exit_game) return; |
0 | 799 |
|
800 |
#if defined(_DEBUG) |
|
5089
9d290a04d79c
(svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents:
5086
diff
changeset
|
801 |
if (_wnd.has_focus && GetAsyncKeyState(VK_SHIFT) < 0 && |
0 | 802 |
#else |
5089
9d290a04d79c
(svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents:
5086
diff
changeset
|
803 |
/* 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
|
804 |
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
|
805 |
#endif |
5089
9d290a04d79c
(svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents:
5086
diff
changeset
|
806 |
!_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
|
807 |
_fast_forward |= 2; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
808 |
} else if (_fast_forward & 2) { |
0 | 809 |
_fast_forward = 0; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
810 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
811 |
|
1403
6d9ed6c85a22
(svn r1907) - Fix: [ 1114261 ] Speeding up when pressing ALT+TAB (Windows)
darkvater
parents:
1390
diff
changeset
|
812 |
cur_ticks = GetTickCount(); |
0 | 813 |
if ((_fast_forward && !_pause) || cur_ticks > next_tick) |
814 |
next_tick = cur_ticks; |
|
815 |
||
816 |
if (cur_ticks == next_tick) { |
|
817 |
next_tick += 30; |
|
818 |
_ctrl_pressed = _wnd.has_focus && GetAsyncKeyState(VK_CONTROL)<0; |
|
819 |
_shift_pressed = _wnd.has_focus && GetAsyncKeyState(VK_SHIFT)<0; |
|
2664
fcefd29dd9d2
(svn r3206) Wrap all instances of _dbg_screen_rect in #ifdef _DEBUG
tron
parents:
2398
diff
changeset
|
820 |
#ifdef _DEBUG |
0 | 821 |
_dbg_screen_rect = _wnd.has_focus && GetAsyncKeyState(VK_CAPITAL)<0; |
2665 | 822 |
#endif |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
823 |
|
0 | 824 |
// 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
|
825 |
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
|
826 |
_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
|
827 |
(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
|
828 |
(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
|
829 |
(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
|
830 |
(GetAsyncKeyState(VK_DOWN) < 0 ? 8 : 0); |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
831 |
} 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
|
832 |
_dirkeys = 0; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
833 |
} |
0 | 834 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
835 |
GameLoop(); |
0 | 836 |
_cursor.delta.x = _cursor.delta.y = 0; |
837 |
||
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
838 |
if (_force_full_redraw) MarkWholeScreenDirty(); |
0 | 839 |
|
840 |
GdiFlush(); |
|
841 |
_screen.dst_ptr = _wnd.buffer_bits; |
|
842 |
UpdateWindows(); |
|
843 |
CheckPaletteAnim(); |
|
844 |
} else { |
|
845 |
Sleep(1); |
|
846 |
GdiFlush(); |
|
847 |
_screen.dst_ptr = _wnd.buffer_bits; |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
848 |
DrawTextMessage(); |
0 | 849 |
DrawMouseCursor(); |
850 |
} |
|
851 |
} |
|
852 |
} |
|
853 |
||
854 |
static bool Win32GdiChangeRes(int w, int h) |
|
855 |
{ |
|
856 |
_wnd.width = _wnd.width_org = w; |
|
857 |
_wnd.height = _wnd.height_org = h; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
858 |
|
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
|
859 |
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
|
860 |
|
0 | 861 |
return true; |
862 |
} |
|
863 |
||
4489 | 864 |
static void Win32GdiFullScreen(bool full_screen) |
865 |
{ |
|
866 |
MakeWindow(full_screen); |
|
867 |
} |
|
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
|
868 |
|
0 | 869 |
const HalVideoDriver _win32_video_driver = { |
870 |
Win32GdiStart, |
|
871 |
Win32GdiStop, |
|
872 |
Win32GdiMakeDirty, |
|
873 |
Win32GdiMainLoop, |
|
874 |
Win32GdiChangeRes, |
|
1829
0b6de3b4458a
(svn r2334) - Fix (regression): moved togglefullscreen into the video-driver, now windows works, dedicated works and sdl works. Also reverted the change to the makefile.
Darkvater
parents:
1806
diff
changeset
|
875 |
Win32GdiFullScreen, |
0 | 876 |
}; |