~ubuntu-branches/debian/squeeze/openttd/squeeze

« back to all changes in this revision

Viewing changes to src/video/win32_v.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jordi Mallach, Matthijs Kooijman, Jordi Mallach
  • Date: 2009-04-15 18:22:10 UTC
  • mfrom: (1.1.6 upstream) (2.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090415182210-22ktb8kdbp2tf3bm
[ Matthijs Kooijman ]
* New upstream release.
* Remove Debian specific desktop file, upstream provides one now. 
* Add debian/watch file.

[ Jordi Mallach ]
* Bump Standards-Version to 3.8.1, with no changes required.
* Move to debhelper compat 7. Bump Build-Depends accordingly.
* Use dh_prep.
* Add "set -e" to config script.
* Remove a few extra doc files that get installed by upstream Makefile.
* Add more complete copyright information.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: win32_v.cpp 14426 2008-10-01 11:48:57Z rubidium $ */
 
1
/* $Id: win32_v.cpp 15718 2009-03-15 00:32:18Z rubidium $ */
 
2
 
 
3
/** @file win32_v.cpp Implementation of the Windows (GDI) video driver. */
2
4
 
3
5
#include "../stdafx.h"
4
6
#include "../openttd.h"
5
7
#include "../gfx_func.h"
6
8
#include "../variables.h"
7
9
#include "../win32.h"
 
10
#include "../rev.h"
8
11
#include "../blitter/factory.hpp"
9
12
#include "../network/network.h"
10
13
#include "../core/math_func.hpp"
11
14
#include "../core/random_func.hpp"
 
15
#include "../functions.h"
 
16
#include "../texteff.hpp"
12
17
#include "win32_v.h"
13
18
#include <windows.h>
14
 
#include <tchar.h>
15
19
 
16
20
static struct {
17
21
        HWND main_wnd;
31
35
bool _window_maximize;
32
36
uint _display_hz;
33
37
uint _fullscreen_bpp;
34
 
static uint16 _bck_resolution[2];
 
38
static Dimension _bck_resolution;
35
39
#if !defined(UNICODE)
36
40
uint _codepage;
37
41
#endif
54
58
 
55
59
        }
56
60
        _wnd.gdi_palette = CreatePalette(pal);
57
 
        if (_wnd.gdi_palette == NULL) error("CreatePalette failed!\n");
 
61
        if (_wnd.gdi_palette == NULL) usererror("CreatePalette failed!\n");
58
62
}
59
63
 
60
64
static void UpdatePalette(HDC dc, uint start, uint count)
83
87
 
84
88
static const VkMapping _vk_mapping[] = {
85
89
        /* Pageup stuff + up/down */
86
 
        AM(VK_PRIOR,VK_DOWN, WKC_PAGEUP, WKC_DOWN),
 
90
        AM(VK_PRIOR, VK_DOWN, WKC_PAGEUP, WKC_DOWN),
87
91
        /* Map letters & digits */
88
 
        AM('A','Z','A','Z'),
89
 
        AM('0','9','0','9'),
 
92
        AM('A', 'Z', 'A', 'Z'),
 
93
        AM('0', '9', '0', '9'),
90
94
 
91
95
        AS(VK_ESCAPE,   WKC_ESC),
92
96
        AS(VK_PAUSE,    WKC_PAUSE),
144
148
 
145
149
static void ClientSizeChanged(int w, int h)
146
150
{
147
 
        // allocate new dib section of the new size
 
151
        /* allocate new dib section of the new size */
148
152
        if (AllocateDibSection(w, h)) {
149
 
                // mark all palette colors dirty
 
153
                /* mark all palette colors dirty */
150
154
                _pal_first_dirty = 0;
151
155
                _pal_count_dirty = 256;
152
156
                GameSizeChanged();
153
157
 
154
 
                // redraw screen
 
158
                /* redraw screen */
155
159
                if (_wnd.running) {
156
160
                        _screen.dst_ptr = _wnd.buffer_bits;
157
161
                        UpdateWindows();
160
164
}
161
165
 
162
166
#ifdef _DEBUG
163
 
// Keep this function here..
164
 
// It allows you to redraw the screen from within the MSVC debugger
 
167
/* Keep this function here..
 
168
 * It allows you to redraw the screen from within the MSVC debugger */
165
169
int RedrawScreenDebug()
166
170
{
167
 
        HDC dc,dc2;
 
171
        HDC dc, dc2;
168
172
        static int _fooctr;
169
173
        HBITMAP old_bmp;
170
174
        HPALETTE old_palette;
216
220
{
217
221
        _fullscreen = full_screen;
218
222
 
219
 
        // recreate window?
 
223
        /* recreate window? */
220
224
        if ((full_screen || _wnd.fullscreen) && _wnd.main_wnd) {
221
225
                DestroyWindow(_wnd.main_wnd);
222
226
                _wnd.main_wnd = 0;
248
252
                        return false;  // the request failed
249
253
                }
250
254
        } else if (_wnd.fullscreen) {
251
 
                // restore display?
 
255
                /* restore display? */
252
256
                ChangeDisplaySettings(NULL, 0);
253
257
        }
254
258
#endif
282
286
                        ShowWindow(_wnd.main_wnd, SW_SHOWNORMAL); // remove maximize-flag
283
287
                        SetWindowPos(_wnd.main_wnd, 0, x, y, w, h, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
284
288
                } else {
285
 
                        extern const char _openttd_revision[];
286
289
                        TCHAR Windowtitle[50];
287
290
 
288
291
                        _sntprintf(Windowtitle, lengthof(Windowtitle), _T("OpenTTD %s"), MB_TO_WIDE(_openttd_revision));
289
292
 
290
293
                        _wnd.main_wnd = CreateWindow(_T("OTTD"), Windowtitle, style, x, y, w, h, 0, 0, GetModuleHandle(NULL), 0);
291
 
                        if (_wnd.main_wnd == NULL) error("CreateWindow failed");
 
294
                        if (_wnd.main_wnd == NULL) usererror("CreateWindow failed");
292
295
                        ShowWindow(_wnd.main_wnd, showstyle);
293
296
                }
294
297
        }
308
311
 
309
312
                case WM_PAINT: {
310
313
                        PAINTSTRUCT ps;
311
 
                        HDC dc,dc2;
 
314
                        HDC dc, dc2;
312
315
                        HBITMAP old_bmp;
313
316
                        HPALETTE old_palette;
314
317
 
367
370
                        return 0;
368
371
 
369
372
                case WM_DESTROY:
370
 
                        if (_window_maximize) {
371
 
                                _cur_resolution[0] = _bck_resolution[0];
372
 
                                _cur_resolution[1] = _bck_resolution[1];
373
 
                        }
 
373
                        if (_window_maximize) _cur_resolution = _bck_resolution;
374
374
                        return 0;
375
375
 
376
376
                case WM_LBUTTONDOWN:
500
500
                        return 0;
501
501
                }
502
502
 
503
 
                case WM_SYSKEYDOWN: /* user presses F10 or Alt, both activating the title-menu */
 
503
                case WM_SYSKEYDOWN: // user presses F10 or Alt, both activating the title-menu
504
504
                        switch (wParam) {
505
505
                                case VK_RETURN:
506
 
                                case 'F': /* Full Screen on ALT + ENTER/F */
 
506
                                case 'F': // Full Screen on ALT + ENTER/F
507
507
                                        ToggleFullScreen(!_wnd.fullscreen);
508
508
                                        return 0;
509
509
 
510
 
                                case VK_MENU: /* Just ALT */
 
510
                                case VK_MENU: // Just ALT
511
511
                                        return 0; // do nothing
512
512
 
513
 
                                case VK_F10: /* F10, ignore activation of menu */
 
513
                                case VK_F10: // F10, ignore activation of menu
514
514
                                        HandleKeypress(MapWindowsKey(wParam) << 16);
515
515
                                        return 0;
516
516
 
517
 
                                default: /* ALT in combination with something else */
 
517
                                default: // ALT in combination with something else
518
518
                                        HandleKeypress(MapWindowsKey(wParam) << 16);
519
519
                                        break;
520
520
                        }
525
525
                                /* Set maximized flag when we maximize (obviously), but also when we
526
526
                                 * switched to fullscreen from a maximized state */
527
527
                                _window_maximize = (wParam == SIZE_MAXIMIZED || (_window_maximize && _fullscreen));
528
 
                                if (_window_maximize) {
529
 
                                        _bck_resolution[0] = _cur_resolution[0];
530
 
                                        _bck_resolution[1] = _cur_resolution[1];
531
 
                                }
 
528
                                if (_window_maximize) _bck_resolution = _cur_resolution;
532
529
                                ClientSizeChanged(LOWORD(lParam), HIWORD(lParam));
533
530
                        }
534
531
                        return 0;
535
532
 
536
533
#if !defined(WINCE)
537
534
                case WM_SIZING: {
538
 
                        RECT* r = (RECT*)lParam;
 
535
                        RECT *r = (RECT*)lParam;
539
536
                        RECT r2;
540
537
                        int w, h;
541
538
 
544
541
 
545
542
                        w = r->right - r->left - (r2.right - r2.left);
546
543
                        h = r->bottom - r->top - (r2.bottom - r2.top);
547
 
                        w = Clamp(w, 64, MAX_SCREEN_WIDTH);
548
 
                        h = Clamp(h, 64, MAX_SCREEN_HEIGHT);
 
544
                        w = max(w, 64);
 
545
                        h = max(h, 64);
549
546
                        SetRect(&r2, 0, 0, w, h);
550
547
 
551
548
                        AdjustWindowRect(&r2, GetWindowLong(hwnd, GWL_STYLE), FALSE);
593
590
                }
594
591
#endif
595
592
 
596
 
// needed for wheel
 
593
/* needed for wheel */
597
594
#if !defined(WM_MOUSEWHEEL)
598
595
# define WM_MOUSEWHEEL 0x020A
599
 
#endif  //WM_MOUSEWHEEL
 
596
#endif  /* WM_MOUSEWHEEL */
600
597
#if !defined(GET_WHEEL_DELTA_WPARAM)
601
598
# define GET_WHEEL_DELTA_WPARAM(wparam) ((short)HIWORD(wparam))
602
 
#endif  //GET_WHEEL_DELTA_WPARAM
 
599
#endif  /* GET_WHEEL_DELTA_WPARAM */
603
600
 
604
601
                case WM_MOUSEWHEEL: {
605
602
                        int delta = GET_WHEEL_DELTA_WPARAM(wParam);
666
663
                };
667
664
 
668
665
                registered = true;
669
 
                if (!RegisterClass(&wnd)) error("RegisterClass failed");
 
666
                if (!RegisterClass(&wnd)) usererror("RegisterClass failed");
670
667
        }
671
668
}
672
669
 
676
673
        HDC dc;
677
674
        int bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth();
678
675
 
679
 
        w = Clamp(w, 64, MAX_SCREEN_WIDTH);
680
 
        h = Clamp(h, 64, MAX_SCREEN_HEIGHT);
 
676
        w = max(w, 64);
 
677
        h = max(h, 64);
681
678
 
682
 
        if (bpp == 0) error("Can't use a blitter that blits 0 bpp for normal visuals");
 
679
        if (bpp == 0) usererror("Can't use a blitter that blits 0 bpp for normal visuals");
683
680
 
684
681
        if (w == _screen.width && h == _screen.height)
685
682
                return false;
702
699
 
703
700
        dc = GetDC(0);
704
701
        _wnd.dib_sect = CreateDIBSection(dc, bi, DIB_RGB_COLORS, (VOID**)&_wnd.buffer_bits, NULL, 0);
705
 
        if (_wnd.dib_sect == NULL) error("CreateDIBSection failed");
 
702
        if (_wnd.dib_sect == NULL) usererror("CreateDIBSection failed");
706
703
        ReleaseDC(0, dc);
707
704
 
708
705
        return true;
709
706
}
710
707
 
711
 
static const uint16 default_resolutions[][2] = {
 
708
static const Dimension default_resolutions[] = {
712
709
        {  640,  480 },
713
710
        {  800,  600 },
714
711
        { 1024,  768 },
726
723
{
727
724
        uint n = 0;
728
725
#if defined(WINCE)
729
 
        /* EnumDisplaySettingsW is only supported in CE 4.2+ */
730
 
        /* XXX -- One might argue that we assume 4.2+ on every system. Then we can use this function safely */
 
726
        /* EnumDisplaySettingsW is only supported in CE 4.2+
 
727
         * XXX -- One might argue that we assume 4.2+ on every system. Then we can use this function safely */
731
728
#else
732
729
        uint i;
733
730
        DEVMODEA dm;
736
733
         * Doesn't really matter since we don't pass a string anyways, but still
737
734
         * a letdown */
738
735
        for (i = 0; EnumDisplaySettingsA(NULL, i, &dm) != 0; i++) {
739
 
                if (dm.dmBitsPerPel == BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() && IsInsideMM(dm.dmPelsWidth, 640, MAX_SCREEN_WIDTH + 1) &&
740
 
                                IsInsideMM(dm.dmPelsHeight, 480, MAX_SCREEN_HEIGHT + 1)) {
 
736
                if (dm.dmBitsPerPel == BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() &&
 
737
                                dm.dmPelsWidth >= 640 && dm.dmPelsHeight >= 480) {
741
738
                        uint j;
742
739
 
743
740
                        for (j = 0; j < n; j++) {
744
 
                                if (_resolutions[j][0] == dm.dmPelsWidth && _resolutions[j][1] == dm.dmPelsHeight) break;
 
741
                                if (_resolutions[j].width == (int)dm.dmPelsWidth && _resolutions[j].height == (int)dm.dmPelsHeight) break;
745
742
                        }
746
743
 
747
744
                        /* In the previous loop we have checked already existing/added resolutions if
749
746
                         * looped all and found none, add the new one to the list. If we have reached the
750
747
                         * maximum amount of resolutions, then quit querying the display */
751
748
                        if (j == n) {
752
 
                                _resolutions[j][0] = dm.dmPelsWidth;
753
 
                                _resolutions[j][1] = dm.dmPelsHeight;
 
749
                                _resolutions[j].width  = dm.dmPelsWidth;
 
750
                                _resolutions[j].height = dm.dmPelsHeight;
754
751
                                if (++n == lengthof(_resolutions)) break;
755
752
                        }
756
753
                }
779
776
 
780
777
        FindResolutions();
781
778
 
782
 
        DEBUG(driver, 2, "Resolution for display: %dx%d", _cur_resolution[0], _cur_resolution[1]);
783
 
 
784
 
        // fullscreen uses those
785
 
        _wnd.width_org = _cur_resolution[0];
786
 
        _wnd.height_org = _cur_resolution[1];
787
 
 
788
 
        AllocateDibSection(_cur_resolution[0], _cur_resolution[1]);
 
779
        DEBUG(driver, 2, "Resolution for display: %dx%d", _cur_resolution.width, _cur_resolution.height);
 
780
 
 
781
        /* fullscreen uses those */
 
782
        _wnd.width_org  = _cur_resolution.width;
 
783
        _wnd.height_org = _cur_resolution.height;
 
784
 
 
785
        AllocateDibSection(_cur_resolution.width, _cur_resolution.height);
 
786
        MakeWindow(_fullscreen);
 
787
 
789
788
        MarkWholeScreenDirty();
790
789
 
791
 
        MakeWindow(_fullscreen);
792
 
 
793
790
        return NULL;
794
791
}
795
792
 
861
858
                        _ctrl_pressed = _wnd.has_focus && GetAsyncKeyState(VK_CONTROL)<0;
862
859
                        _shift_pressed = _wnd.has_focus && GetAsyncKeyState(VK_SHIFT)<0;
863
860
 
864
 
                        // determine which directional keys are down
 
861
                        /* determine which directional keys are down */
865
862
                        if (_wnd.has_focus) {
866
863
                                _dirkeys =
867
864
                                        (GetAsyncKeyState(VK_LEFT) < 0 ? 1 : 0) +
891
888
                        GdiFlush();
892
889
#endif
893
890
                        _screen.dst_ptr = _wnd.buffer_bits;
894
 
                        DrawChatMessage();
 
891
                        NetworkDrawChatMessage();
895
892
                        DrawMouseCursor();
896
893
                }
897
894
        }