Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
298 | serge | 1 | // Emacs style mode select -*- C++ -*- |
2 | //----------------------------------------------------------------------------- |
||
3 | // |
||
4 | // $Id:$ |
||
5 | // |
||
6 | // Copyright (C) 1993-1996 by id Software, Inc. |
||
7 | // |
||
8 | // This source is available for distribution and/or modification |
||
9 | // only under the terms of the DOOM Source Code License as |
||
10 | // published by id Software. All rights reserved. |
||
11 | // |
||
12 | // The source is distributed in the hope that it will be useful, |
||
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License |
||
15 | // for more details. |
||
16 | // |
||
17 | // $Log:$ |
||
18 | // |
||
19 | // DESCRIPTION: |
||
20 | // DOOM graphics stuff for SDL library |
||
21 | // |
||
22 | //----------------------------------------------------------------------------- |
||
23 | |||
24 | static const char |
||
25 | rcsid[] = "$Id: i_x.c,v 1.6 1997/02/03 22:45:10 b1 Exp $"; |
||
26 | |||
27 | #include |
||
28 | |||
29 | //#include "SDL.h" |
||
30 | |||
31 | //#include "m_swap.h" |
||
32 | #include "doomstat.h" |
||
33 | #include "i_system.h" |
||
34 | #include "v_video.h" |
||
35 | #include "m_argv.h" |
||
36 | #include "d_main.h" |
||
37 | |||
38 | #include "doomdef.h" |
||
39 | #define WIN32_LEAN_AND_MEAN |
||
40 | #include |
||
41 | |||
42 | typedef struct SURFACE |
||
43 | { |
||
44 | int w, h; |
||
45 | int pitch; |
||
46 | unsigned char *pixels; |
||
47 | int offset; |
||
48 | } SURFACE; |
||
49 | |||
50 | SURFACE screen; |
||
51 | |||
52 | // Fake mouse handling. |
||
53 | boolean grabMouse; |
||
54 | |||
55 | // Blocky mode, |
||
56 | // replace each 320x200 pixel with multiply*multiply pixels. |
||
57 | // According to Dave Taylor, it still is a bonehead thing |
||
58 | // to use .... |
||
59 | static int multiply=2; |
||
60 | |||
61 | void WinError(char *msg); |
||
62 | |||
63 | |||
64 | int BPP; |
||
65 | byte *hicolortable; |
||
66 | short hicolortransmask1,hicolortransmask2; |
||
67 | int X_width; |
||
68 | int X_height; |
||
69 | static int disableVerticalMouse = 0; |
||
70 | static int closed=0; |
||
71 | static int windowActive = 0; |
||
72 | |||
73 | HWND win; |
||
74 | static HINSTANCE inst; |
||
75 | static HDC dibDC; |
||
76 | static LOGPALETTE *palette; |
||
77 | static HPALETTE dibPal; |
||
78 | BITMAPINFO *bminfo; |
||
79 | static unsigned char *dibData; |
||
80 | static int bits8; |
||
81 | int palette_color[256]; |
||
82 | |||
83 | |||
84 | static int lastmousex = 0; |
||
85 | static int lastmousey = 0; |
||
86 | boolean mousemoved = false; |
||
87 | boolean shmFinished; |
||
88 | |||
89 | |||
90 | |||
91 | // |
||
92 | // Translates the key |
||
93 | // |
||
94 | |||
95 | /******* |
||
96 | int xlatekey(SDL_keysym *key) |
||
97 | { |
||
98 | |||
99 | int rc; |
||
100 | |||
101 | switch(key->sym) |
||
102 | { |
||
103 | case SDLK_LEFT: rc = KEY_LEFTARROW; break; |
||
104 | case SDLK_RIGHT: rc = KEY_RIGHTARROW; break; |
||
105 | case SDLK_DOWN: rc = KEY_DOWNARROW; break; |
||
106 | case SDLK_UP: rc = KEY_UPARROW; break; |
||
107 | case SDLK_ESCAPE: rc = KEY_ESCAPE; break; |
||
108 | case SDLK_RETURN: rc = KEY_ENTER; break; |
||
109 | case SDLK_TAB: rc = KEY_TAB; break; |
||
110 | case SDLK_F1: rc = KEY_F1; break; |
||
111 | case SDLK_F2: rc = KEY_F2; break; |
||
112 | case SDLK_F3: rc = KEY_F3; break; |
||
113 | case SDLK_F4: rc = KEY_F4; break; |
||
114 | case SDLK_F5: rc = KEY_F5; break; |
||
115 | case SDLK_F6: rc = KEY_F6; break; |
||
116 | case SDLK_F7: rc = KEY_F7; break; |
||
117 | case SDLK_F8: rc = KEY_F8; break; |
||
118 | case SDLK_F9: rc = KEY_F9; break; |
||
119 | case SDLK_F10: rc = KEY_F10; break; |
||
120 | case SDLK_F11: rc = KEY_F11; break; |
||
121 | case SDLK_F12: rc = KEY_F12; break; |
||
122 | |||
123 | case SDLK_BACKSPACE: |
||
124 | case SDLK_DELETE: rc = KEY_BACKSPACE; break; |
||
125 | |||
126 | case SDLK_PAUSE: rc = KEY_PAUSE; break; |
||
127 | |||
128 | case SDLK_EQUALS: rc = KEY_EQUALS; break; |
||
129 | |||
130 | case SDLK_KP_MINUS: |
||
131 | case SDLK_MINUS: rc = KEY_MINUS; break; |
||
132 | |||
133 | case SDLK_LSHIFT: |
||
134 | case SDLK_RSHIFT: |
||
135 | rc = KEY_RSHIFT; |
||
136 | break; |
||
137 | |||
138 | case 'z': |
||
139 | case SDLK_LCTRL: |
||
140 | case SDLK_RCTRL: |
||
141 | rc = KEY_RCTRL; |
||
142 | break; |
||
143 | |||
144 | case SDLK_LALT: |
||
145 | case SDLK_LMETA: |
||
146 | case SDLK_RALT: |
||
147 | case SDLK_RMETA: |
||
148 | rc = KEY_RALT; |
||
149 | break; |
||
150 | |||
151 | default: |
||
152 | rc = key->sym; |
||
153 | break; |
||
154 | } |
||
155 | |||
156 | return rc; |
||
157 | |||
158 | } |
||
159 | **********/ |
||
160 | |||
161 | void I_ShutdownGraphics(void) |
||
162 | { |
||
163 | // SDL_Quit(); |
||
164 | } |
||
165 | |||
166 | |||
167 | |||
168 | // |
||
169 | // I_StartFrame |
||
170 | // |
||
171 | void I_StartFrame (void) |
||
172 | { |
||
173 | // er? |
||
174 | |||
175 | } |
||
176 | |||
177 | /* This processes SDL events */ |
||
178 | /***** |
||
179 | void I_GetEvent(SDL_Event *Event) |
||
180 | { |
||
181 | Uint8 buttonstate; |
||
182 | event_t event; |
||
183 | |||
184 | switch (Event->type) |
||
185 | { |
||
186 | case SDL_KEYDOWN: |
||
187 | event.type = ev_keydown; |
||
188 | event.data1 = xlatekey(&Event->key.keysym); |
||
189 | D_PostEvent(&event); |
||
190 | break; |
||
191 | case SDL_KEYUP: |
||
192 | event.type = ev_keyup; |
||
193 | event.data1 = xlatekey(&Event->key.keysym); |
||
194 | D_PostEvent(&event); |
||
195 | break; |
||
196 | case SDL_QUIT: |
||
197 | I_Quit(); |
||
198 | break; |
||
199 | } |
||
200 | } |
||
201 | |||
202 | *******/ |
||
203 | |||
204 | |||
205 | |||
206 | |||
207 | void I_GetEvent(void) |
||
208 | { |
||
209 | MSG msg; |
||
210 | POINT point; |
||
211 | static LONG prevX, prevY; |
||
212 | static int hadMouse = 0; |
||
213 | event_t event; |
||
214 | RECT rect; |
||
215 | int lb, rb; |
||
216 | static int prevlb = 0, prevrb = 0; |
||
217 | |||
218 | /* Dispatch all messages: */ |
||
219 | while ( PeekMessage(&msg, NULL, 0, 0xFFFFFFFF, PM_REMOVE) ) |
||
220 | { |
||
221 | TranslateMessage (&msg) ; |
||
222 | DispatchMessage (&msg) ; |
||
223 | } |
||
224 | |||
225 | /* Check mouse and generate events if necessary: */ |
||
226 | if ( !GetCursorPos(&point) ) |
||
227 | WinError("GetCursorPos() failed"); |
||
228 | if ( hadMouse && windowActive) |
||
229 | { |
||
230 | lb = (GetAsyncKeyState(VK_LBUTTON) < 0); |
||
231 | rb = (GetAsyncKeyState(VK_RBUTTON) < 0); |
||
232 | |||
233 | if ( (prevX != point.x) || (prevY != point.y) || |
||
234 | (prevlb != lb) || (prevrb != rb) ) |
||
235 | { |
||
236 | event.type = ev_mouse; |
||
237 | event.data1 = lb | (rb << 1); |
||
238 | event.data2 = (point.x - prevX)*9; |
||
239 | if ( disableVerticalMouse ) |
||
240 | event.data3 = 0; |
||
241 | else |
||
242 | event.data3 = (prevY - point.y)*9; |
||
243 | prevX = point.x; |
||
244 | prevY = point.y; |
||
245 | prevlb = lb; |
||
246 | prevrb = rb; |
||
247 | D_PostEvent(&event); |
||
248 | } |
||
249 | |||
250 | if ( grabMouse ) |
||
251 | { |
||
252 | GetWindowRect(win, &rect); |
||
253 | if ( !SetCursorPos((rect.left + rect.right) / 2, |
||
254 | (rect.top + rect.bottom) / 2) ) |
||
255 | WinError("SetCursorPos() failed"); |
||
256 | prevX = (rect.left + rect.right) / 2; |
||
257 | prevY = (rect.top + rect.bottom) / 2; |
||
258 | } |
||
259 | } |
||
260 | else |
||
261 | { |
||
262 | prevX = point.x; |
||
263 | prevY = point.y; |
||
264 | hadMouse = 1; |
||
265 | } |
||
266 | } |
||
267 | |||
268 | |||
269 | |||
270 | // |
||
271 | // I_StartTic |
||
272 | // |
||
273 | void I_StartTic (void) |
||
274 | { |
||
275 | // SDL_Event Event; |
||
276 | |||
277 | // while ( SDL_PollEvent(&Event) ) |
||
278 | // I_GetEvent(&Event); |
||
279 | I_GetEvent(); |
||
280 | |||
281 | } |
||
282 | |||
283 | |||
284 | // |
||
285 | // I_UpdateNoBlit |
||
286 | // |
||
287 | void I_UpdateNoBlit (void) |
||
288 | { |
||
289 | // what is this? |
||
290 | } |
||
291 | |||
292 | // |
||
293 | // I_ReadScreen |
||
294 | // |
||
295 | void I_ReadScreen (byte* scr) |
||
296 | { |
||
297 | memcpy (scr, screens[0], SCREENWIDTH*SCREENHEIGHT); |
||
298 | } |
||
299 | |||
300 | |||
301 | // |
||
302 | // I_SetPalette |
||
303 | // |
||
304 | |||
305 | typedef struct SDL_Color |
||
306 | { |
||
307 | byte r; |
||
308 | byte g; |
||
309 | byte b; |
||
310 | byte unused; |
||
311 | } SDL_Color; |
||
312 | |||
313 | SDL_Color colors[256]; |
||
314 | |||
315 | void I_SetPalette (byte* palette) |
||
316 | { |
||
317 | int i; |
||
318 | RGBQUAD *rgb; |
||
319 | |||
320 | // |
||
321 | // for ( i=0; i<256; ++i ) { |
||
322 | // colors[i].r = gammatable[usegamma][*palette++]; |
||
323 | // colors[i].g = gammatable[usegamma][*palette++]; |
||
324 | // colors[i].b = gammatable[usegamma][*palette++]; |
||
325 | // colors[i].unused = 0; |
||
326 | // } |
||
327 | // SDL_SetColors(screen, colors, 0, 256); |
||
328 | |||
329 | rgb = bminfo->bmiColors; |
||
330 | for ( i = 0; i < 256; i++ ) |
||
331 | { |
||
332 | rgb->rgbRed = gammatable[usegamma][*palette++]; |
||
333 | rgb->rgbGreen = gammatable[usegamma][*palette++]; |
||
334 | rgb->rgbBlue = gammatable[usegamma][*palette++]; |
||
335 | rgb->rgbReserved = 0; |
||
336 | rgb++; |
||
337 | }; |
||
338 | |||
339 | |||
340 | } |
||
341 | |||
342 | |||
343 | |||
344 | int makecol(int r, int g, int b) |
||
345 | { |
||
346 | // assert(BPP==2); |
||
347 | return (b >> 3) | ((g >> 3) << 5) | ((r >> 3) << 10); |
||
348 | } |
||
349 | |||
350 | int TranslateKey(unsigned k) |
||
351 | { |
||
352 | /*wtf? if ( (k >= VK_0) && (k <= VK_9) )*/ |
||
353 | if ( (k >= 0x30) && (k <= 0x39) ) |
||
354 | return (k - 0x30 + '0'); |
||
355 | if ( (k >= 0x41) && (k <= 0x5a) ) |
||
356 | return (k - 0x41 + 'a'); |
||
357 | |||
358 | #define K(a,b) case a: return b; |
||
359 | switch ( k ) |
||
360 | { |
||
361 | K(VK_LEFT, KEY_LEFTARROW); |
||
362 | K(VK_RIGHT, KEY_RIGHTARROW); |
||
363 | K(VK_UP, KEY_UPARROW); |
||
364 | K(VK_DOWN, KEY_DOWNARROW); |
||
365 | K(VK_BACK, KEY_BACKSPACE); |
||
366 | K(VK_TAB, KEY_TAB); |
||
367 | K(VK_RETURN, KEY_ENTER); |
||
368 | K(VK_SHIFT, KEY_RSHIFT); |
||
369 | K(VK_CONTROL, KEY_RCTRL); |
||
370 | K(VK_MENU, KEY_RALT); |
||
371 | K(VK_PAUSE, KEY_PAUSE); |
||
372 | K(VK_ESCAPE, KEY_ESCAPE); |
||
373 | K(VK_SPACE, ' '); |
||
374 | K(VK_DELETE, KEY_BACKSPACE); |
||
375 | K(VK_ADD, '+'); |
||
376 | K(VK_SUBTRACT, KEY_MINUS); |
||
377 | K(0xBC, ','); |
||
378 | K(0xBE, '.'); |
||
379 | K(VK_F1, KEY_F1); |
||
380 | K(VK_F2, KEY_F2); |
||
381 | K(VK_F3, KEY_F3); |
||
382 | K(VK_F4, KEY_F4); |
||
383 | K(VK_F5, KEY_F5); |
||
384 | K(VK_F6, KEY_F6); |
||
385 | K(VK_F7, KEY_F7); |
||
386 | K(VK_F8, KEY_F8); |
||
387 | K(VK_F9, KEY_F9); |
||
388 | K(VK_F10, KEY_F10); |
||
389 | K(VK_F11, KEY_F11); |
||
390 | K(VK_F12, KEY_F12); |
||
391 | } |
||
392 | |||
393 | return 0; |
||
394 | } |
||
395 | |||
396 | void WinError(char *msg) |
||
397 | { |
||
398 | printf("Windows Error: %s, GetLastError(): %u\n", msg, GetLastError()); |
||
399 | exit(EXIT_FAILURE); |
||
400 | } |
||
401 | |||
402 | static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, |
||
403 | WPARAM wparam, LPARAM lparam); |
||
404 | |||
405 | void BlitDIB(void) |
||
406 | { |
||
407 | RECT rect; |
||
408 | |||
409 | GetClientRect(win, &rect); |
||
410 | if ( StretchDIBits(dibDC, rect.left, rect.top, rect.right-rect.left, |
||
411 | rect.bottom-rect.top, 0, 0, SCREENWIDTH*2, |
||
412 | SCREENHEIGHT*2, dibData, bminfo, DIB_RGB_COLORS, |
||
413 | SRCCOPY) |
||
414 | == GDI_ERROR ) |
||
415 | WinError("StrecthDIBits failed"); |
||
416 | |||
417 | GdiFlush(); |
||
418 | } |
||
419 | |||
420 | |||
421 | void I_InitGraphics(void) |
||
422 | { |
||
423 | static int firsttime=1; |
||
424 | |||
425 | WNDCLASS wc; |
||
426 | unsigned i, x, y, j; |
||
427 | WORD *d; |
||
428 | unsigned char *b; |
||
429 | int bits; |
||
430 | int frameX, frameY, capY; |
||
431 | RECT rect; |
||
432 | int width, height; |
||
433 | RGBQUAD *rgb; |
||
434 | int retval; |
||
435 | |||
436 | if (!firsttime) |
||
437 | return; |
||
438 | firsttime = 0; |
||
439 | |||
440 | if (M_CheckParm("-2")) |
||
441 | multiply = 2; |
||
442 | |||
443 | if (M_CheckParm("-3")) |
||
444 | multiply = 3; |
||
445 | |||
446 | if (M_CheckParm("-4")) |
||
447 | multiply = 4; |
||
448 | |||
449 | X_width = SCREENWIDTH * multiply; |
||
450 | X_height = SCREENHEIGHT * multiply; |
||
451 | |||
452 | // check if the user wants to grab the mouse (quite unnice) |
||
453 | grabMouse = !!M_CheckParm("-grabmouse"); |
||
454 | |||
455 | /* [Petteri] New: Option to disable mouse vertical movement - useful |
||
456 | for players used to Quake: */ |
||
457 | disableVerticalMouse = !!M_CheckParm("-novertmouse"); |
||
458 | |||
459 | /* Build and initialize the window: */ |
||
460 | |||
461 | inst = (HINSTANCE) GetModuleHandle(NULL); |
||
462 | |||
463 | frameX = GetSystemMetrics(SM_CXFRAME); |
||
464 | frameY = GetSystemMetrics(SM_CYFRAME); |
||
465 | capY = GetSystemMetrics(SM_CYCAPTION); |
||
466 | |||
467 | wc.style = CS_HREDRAW | CS_VREDRAW; |
||
468 | wc.lpfnWndProc = WndProc; |
||
469 | wc.cbClsExtra = 0; |
||
470 | wc.cbWndExtra = 0; |
||
471 | wc.hInstance = inst; |
||
472 | wc.hIcon = NULL; |
||
473 | if ( grabMouse ) |
||
474 | wc.hCursor = LoadCursor( 0, IDC_ARROW ); |
||
475 | else |
||
476 | wc.hCursor = LoadCursor( 0, IDC_ARROW ); |
||
477 | /*wc.hbrBackground = GetStockObject( WHITE_BRUSH );*/ |
||
478 | wc.hbrBackground = NULL; |
||
479 | wc.lpszMenuName = NULL; |
||
480 | wc.lpszClassName = "DoomWindowClass"; |
||
481 | |||
482 | retval= RegisterClass(&wc); |
||
483 | |||
484 | width = X_width + 2*frameX; |
||
485 | height = X_height + 2*frameY + capY; |
||
486 | |||
487 | win = CreateWindow("DoomWindowClass", "NTDOOM", |
||
488 | WS_OVERLAPPEDWINDOW | WS_VISIBLE, 200, 200, width, height, |
||
489 | NULL, NULL, inst, NULL); |
||
490 | |||
491 | /* Display the window: */ |
||
492 | ShowWindow(win, SW_SHOW); |
||
493 | UpdateWindow(win); |
||
494 | |||
495 | GetClientRect(win, &rect); |
||
496 | fprintf(stderr, "I_InitGraphics: Client area: %ux%u\n", |
||
497 | rect.right-rect.left, rect.bottom-rect.top); |
||
498 | |||
499 | if ( (rect.right-rect.left) != X_width ) |
||
500 | { |
||
501 | fprintf(stderr, "I_InitGraphics: Fixing width\n"); |
||
502 | width += X_width - (rect.right-rect.left); |
||
503 | MoveWindow(win, 0, 0, width, height, TRUE); |
||
504 | } |
||
505 | if ( (rect.bottom-rect.top) != X_height ) |
||
506 | { |
||
507 | fprintf(stderr, "I_InitGraphics: Fixing height\n"); |
||
508 | height += X_height - (rect.bottom-rect.top); |
||
509 | MoveWindow(win, 0, 0, width, height, TRUE); |
||
510 | } |
||
511 | |||
512 | GetClientRect(win, &rect); |
||
513 | fprintf(stderr, "I_InitGraphics: Client area: %ux%u\n", |
||
514 | rect.right-rect.left, rect.bottom-rect.top); |
||
515 | |||
516 | dibDC = GetDC(win); |
||
517 | BPP=1; |
||
518 | bits = 8; //GetDeviceCaps(dibDC, BITSPIXEL); |
||
519 | fprintf(stderr, "I_InitGraphics: %i bpp screen\n", bits); |
||
520 | |||
521 | if ( BPP == 1 ) |
||
522 | bminfo = malloc(sizeof(BITMAPINFOHEADER) + 4*256); |
||
523 | else |
||
524 | bminfo = malloc(sizeof(BITMAPINFOHEADER)); |
||
525 | |||
526 | |||
527 | if ( BPP == 1 ) |
||
528 | { |
||
529 | rgb = bminfo->bmiColors; |
||
530 | for ( i = 0; i < 256; i++ ) |
||
531 | { |
||
532 | rgb->rgbRed = i; |
||
533 | rgb->rgbGreen = i; |
||
534 | rgb->rgbBlue = i; |
||
535 | rgb->rgbReserved = 0; |
||
536 | rgb++; |
||
537 | } |
||
538 | } |
||
539 | |||
540 | bminfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); |
||
541 | bminfo->bmiHeader.biWidth = 640; X_width; |
||
542 | bminfo->bmiHeader.biHeight = -400 ;X_height; |
||
543 | bminfo->bmiHeader.biPlanes = 1; |
||
544 | if ( BPP == 1 ) |
||
545 | bminfo->bmiHeader.biBitCount = 8; |
||
546 | else |
||
547 | bminfo->bmiHeader.biBitCount = 16; |
||
548 | bminfo->bmiHeader.biCompression = BI_RGB; |
||
549 | bminfo->bmiHeader.biSizeImage = 0; |
||
550 | bminfo->bmiHeader.biXPelsPerMeter = 0; |
||
551 | bminfo->bmiHeader.biYPelsPerMeter = 0; |
||
552 | bminfo->bmiHeader.biClrUsed = 0; |
||
553 | bminfo->bmiHeader.biClrImportant = 0; |
||
554 | |||
555 | dibData = malloc(640*400*BPP); |
||
556 | |||
557 | // BlitDIB(); |
||
558 | |||
559 | screen.pixels=(unsigned char *) (dibData); |
||
560 | screen.h=400; |
||
561 | screen.w=640; |
||
562 | screen.pitch=640; |
||
563 | |||
564 | // screens[0] = malloc(320*200); |
||
565 | |||
566 | /* Build magic highcolor table: */ |
||
567 | if (BPP==2) |
||
568 | { |
||
569 | byte *tempptr, *tempptr2; |
||
570 | |||
571 | tempptr=hicolortable=(byte *)malloc(256*32*9); |
||
572 | |||
573 | for (i=0;i<32;i++) |
||
574 | { |
||
575 | for (j=0;j<256;j++) |
||
576 | { |
||
577 | *tempptr=j*gammatable[3][i*(256/32)]/256; |
||
578 | tempptr++; |
||
579 | } |
||
580 | } |
||
581 | for (i=1;i<=8;i++) |
||
582 | { |
||
583 | tempptr2=hicolortable; |
||
584 | for (j=0;j<(256*32);j++) |
||
585 | { |
||
586 | *tempptr=(byte)(((int)(*tempptr2))*(8-i)/8); |
||
587 | tempptr++; tempptr2++; |
||
588 | } |
||
589 | } |
||
590 | hicolortransmask1=makecol(127,127,127); |
||
591 | hicolortransmask2=makecol(63,63,63); |
||
592 | } |
||
593 | } |
||
594 | |||
595 | static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, |
||
596 | WPARAM wparam, LPARAM lparam) |
||
597 | { |
||
598 | event_t event; |
||
599 | RECT rect; |
||
600 | |||
601 | switch ( message ) |
||
602 | { |
||
603 | case WM_DESTROY: |
||
604 | if ( grabMouse ) |
||
605 | { |
||
606 | ClipCursor(NULL); |
||
607 | ShowCursor(TRUE); |
||
608 | } |
||
609 | fprintf(stderr, "WM_DESTROY\n"); |
||
610 | PostQuitMessage(0); |
||
611 | closed = 1; |
||
612 | break; |
||
613 | |||
614 | case WM_MOVE: |
||
615 | GetWindowRect(win, &rect); |
||
616 | fprintf(stderr, "%u,%u - %u, %u\n", |
||
617 | rect.left,rect.top,rect.right,rect.bottom); |
||
618 | ClipCursor(&rect); |
||
619 | break; |
||
620 | |||
621 | case WM_ACTIVATE: |
||
622 | fprintf(stderr, "WM_ACTIVATE %u\n", (unsigned) LOWORD(wparam)); |
||
623 | if ( LOWORD(wparam) ) |
||
624 | { |
||
625 | if ( !windowActive ) |
||
626 | { |
||
627 | if ( grabMouse ) |
||
628 | { |
||
629 | ClipCursor(NULL); /* helps with Win95? */ |
||
630 | GetWindowRect(win, &rect); |
||
631 | fprintf(stderr, "%u,%u - %u, %u\n", |
||
632 | rect.left,rect.top,rect.right,rect.bottom); |
||
633 | ClipCursor(&rect); |
||
634 | ShowCursor(FALSE); |
||
635 | } |
||
636 | } |
||
637 | windowActive = 1; |
||
638 | if ( bits8 ) |
||
639 | { |
||
640 | if ( SetPaletteEntries(dibPal, 0, 256, palette->palPalEntry) != 256 ) |
||
641 | WinError("SetPaletteEntries failed"); |
||
642 | if ( !UnrealizeObject(dibPal) ) |
||
643 | WinError("UnrealizeObject failed"); |
||
644 | if ( SelectPalette(dibDC, dibPal, FALSE) == NULL ) |
||
645 | WinError("SelectPalette failed"); |
||
646 | } |
||
647 | } |
||
648 | else |
||
649 | { |
||
650 | if ( grabMouse ) |
||
651 | { |
||
652 | ClipCursor(NULL); |
||
653 | ShowCursor(TRUE); |
||
654 | } |
||
655 | windowActive = 0; |
||
656 | } |
||
657 | return DefWindowProc(hwnd, message, wparam, lparam); |
||
658 | |||
659 | case WM_KEYDOWN: |
||
660 | event.type = ev_keydown; |
||
661 | event.data1 = TranslateKey(wparam); |
||
662 | if ( event.data1 != 0 ) |
||
663 | D_PostEvent(&event); |
||
664 | break; |
||
665 | |||
666 | case WM_KEYUP: |
||
667 | event.type = ev_keyup; |
||
668 | event.data1 = TranslateKey(wparam); |
||
669 | if ( event.data1 != 0 ) |
||
670 | D_PostEvent(&event); |
||
671 | break; |
||
672 | |||
673 | default: |
||
674 | return(DefWindowProc(hwnd, message, wparam, lparam)); |
||
675 | } |
||
676 | |||
677 | return 0; |
||
678 | } |
||
679 | |||
680 | // |
||
681 | // I_FinishUpdate |
||
682 | // |
||
683 | void I_FinishUpdate (void) |
||
684 | { |
||
685 | |||
686 | static int lasttic; |
||
687 | int tics; |
||
688 | int i; |
||
689 | |||
690 | // draws little dots on the bottom of the screen |
||
691 | if (devparm) |
||
692 | { i = I_GetTime(); |
||
693 | |||
694 | tics = i - lasttic; |
||
695 | lasttic = i; |
||
696 | if (tics > 20) |
||
697 | tics = 20; |
||
698 | |||
699 | for (i=0 ; i |
||
700 | screens[0][ (SCREENHEIGHT-1)*SCREENWIDTH + i] = 0xff; |
||
701 | for ( ; i<20*2 ; i+=2) |
||
702 | screens[0][ (SCREENHEIGHT-1)*SCREENWIDTH + i] = 0x0; |
||
703 | } |
||
704 | |||
705 | // scales the screen size before blitting it |
||
706 | if (multiply == 1) |
||
707 | { |
||
708 | unsigned char *olineptr; |
||
709 | unsigned char *ilineptr; |
||
710 | int y; |
||
711 | |||
712 | ilineptr = (unsigned char *) screens[0]; |
||
713 | olineptr = (unsigned char *) screen.pixels; |
||
714 | |||
715 | y = SCREENHEIGHT; |
||
716 | while (y--) |
||
717 | { |
||
718 | memcpy(olineptr, ilineptr, screen.w); |
||
719 | ilineptr += SCREENWIDTH; |
||
720 | olineptr += screen.pitch; |
||
721 | } |
||
722 | } |
||
723 | else if (multiply == 2) |
||
724 | { |
||
725 | unsigned int *olineptrs[2]; |
||
726 | unsigned int *ilineptr; |
||
727 | int x, y, i; |
||
728 | unsigned int twoopixels; |
||
729 | unsigned int twomoreopixels; |
||
730 | unsigned int fouripixels; |
||
731 | |||
732 | ilineptr = (unsigned int *) (screens[0]); |
||
733 | for (i=0 ; i<2 ; i++) { |
||
734 | olineptrs[i] = |
||
735 | (unsigned int *)&((byte *)screen.pixels)[i*screen.pitch]; |
||
736 | } |
||
737 | |||
738 | y = SCREENHEIGHT; |
||
739 | while (y--) |
||
740 | { |
||
741 | x = SCREENWIDTH; |
||
742 | do |
||
743 | { |
||
744 | fouripixels = *ilineptr++; |
||
745 | twoopixels = (fouripixels & 0xff000000) |
||
746 | | ((fouripixels>>8) & 0xffff00) |
||
747 | | ((fouripixels>>16) & 0xff); |
||
748 | twomoreopixels = ((fouripixels<<16) & 0xff000000) |
||
749 | | ((fouripixels<<8) & 0xffff00) |
||
750 | | (fouripixels & 0xff); |
||
751 | *olineptrs[0]++ = twomoreopixels; |
||
752 | *olineptrs[1]++ = twomoreopixels; |
||
753 | *olineptrs[0]++ = twoopixels; |
||
754 | *olineptrs[1]++ = twoopixels; |
||
755 | } while (x-=4); |
||
756 | olineptrs[0] += screen.pitch/4; |
||
757 | olineptrs[1] += screen.pitch/4; |
||
758 | } |
||
759 | |||
760 | } |
||
761 | else if (multiply == 3) |
||
762 | { |
||
763 | unsigned int *olineptrs[3]; |
||
764 | unsigned int *ilineptr; |
||
765 | int x, y, i; |
||
766 | unsigned int fouropixels[3]; |
||
767 | unsigned int fouripixels; |
||
768 | |||
769 | ilineptr = (unsigned int *) (screens[0]); |
||
770 | for (i=0 ; i<3 ; i++) { |
||
771 | olineptrs[i] = |
||
772 | (unsigned int *)&((byte *)screen.pixels)[i*screen.pitch]; |
||
773 | } |
||
774 | |||
775 | y = SCREENHEIGHT; |
||
776 | while (y--) |
||
777 | { |
||
778 | x = SCREENWIDTH; |
||
779 | do |
||
780 | { |
||
781 | fouripixels = *ilineptr++; |
||
782 | fouropixels[0] = (fouripixels & 0xff000000) |
||
783 | | ((fouripixels>>8) & 0xff0000) |
||
784 | | ((fouripixels>>16) & 0xffff); |
||
785 | fouropixels[1] = ((fouripixels<<8) & 0xff000000) |
||
786 | | (fouripixels & 0xffff00) |
||
787 | | ((fouripixels>>8) & 0xff); |
||
788 | fouropixels[2] = ((fouripixels<<16) & 0xffff0000) |
||
789 | | ((fouripixels<<8) & 0xff00) |
||
790 | | (fouripixels & 0xff); |
||
791 | *olineptrs[0]++ = fouropixels[2]; |
||
792 | *olineptrs[1]++ = fouropixels[2]; |
||
793 | *olineptrs[2]++ = fouropixels[2]; |
||
794 | *olineptrs[0]++ = fouropixels[1]; |
||
795 | *olineptrs[1]++ = fouropixels[1]; |
||
796 | *olineptrs[2]++ = fouropixels[1]; |
||
797 | *olineptrs[0]++ = fouropixels[0]; |
||
798 | *olineptrs[1]++ = fouropixels[0]; |
||
799 | *olineptrs[2]++ = fouropixels[0]; |
||
800 | } while (x-=4); |
||
801 | olineptrs[0] += 2*screen.pitch/4; |
||
802 | olineptrs[1] += 2*screen.pitch/4; |
||
803 | olineptrs[2] += 2*screen.pitch/4; |
||
804 | } |
||
805 | |||
806 | } |
||
807 | BlitDIB(); |
||
808 | } |
||
809 | |||
810 | |||
811 | |||
812 | |||
813 | /** |
||
814 | void I_InitGraphics(void) |
||
815 | { |
||
816 | |||
817 | static int firsttime=1; |
||
818 | int video_w, video_h, w, h; |
||
819 | byte video_bpp; |
||
820 | unsigned int video_flags; |
||
821 | |||
822 | if (!firsttime) |
||
823 | return; |
||
824 | firsttime = 0; |
||
825 | |||
826 | video_flags = (SDL_SWSURFACE|SDL_HWPALETTE); |
||
827 | if (!!M_CheckParm("-fullscreen")) |
||
828 | video_flags |= SDL_FULLSCREEN; |
||
829 | |||
830 | if (M_CheckParm("-2")) |
||
831 | multiply = 2; |
||
832 | |||
833 | if (M_CheckParm("-3")) |
||
834 | multiply = 3; |
||
835 | |||
836 | // check if the user wants to grab the mouse (quite unnice) |
||
837 | grabMouse = !!M_CheckParm("-grabmouse"); |
||
838 | |||
839 | video_w = w = SCREENWIDTH * multiply; |
||
840 | video_h = h = SCREENHEIGHT * multiply; |
||
841 | video_bpp = 8; |
||
842 | |||
843 | |||
844 | if ( multiply > 3 ) { |
||
845 | I_Error("Smallest available mode (%dx%d) is too large!", |
||
846 | video_w, video_h); |
||
847 | } |
||
848 | screen = SDL_SetVideoMode(video_w, video_h, 8, video_flags); |
||
849 | if ( screen == NULL ) { |
||
850 | I_Error("Could not set %dx%d video mode: %s", video_w, video_h, |
||
851 | SDL_GetError()); |
||
852 | } |
||
853 | SDL_ShowCursor(0); |
||
854 | SDL_WM_SetCaption("MenuetOS-DOOM", "doom"); |
||
855 | |||
856 | w = SCREENWIDTH * multiply; |
||
857 | h = SCREENHEIGHT * multiply; |
||
858 | if (multiply == 1 && !SDL_MUSTLOCK(screen) ) { |
||
859 | screens[0] = (unsigned char *) screen->pixels; |
||
860 | } else { |
||
861 | screens[0] = (unsigned char *) malloc (SCREENWIDTH * SCREENHEIGHT); |
||
862 | if ( screens[0] == NULL ) |
||
863 | I_Error("Couldn't allocate screen memory"); |
||
864 | } |
||
865 | } |
||
866 | *****/8)><8)>16)><16)>8)><8)>3>8)><8)>16)><16)>2>20*2>(256*32);j++) |