src/video/sdl_v.cpp
author rubidium
Sat, 29 Nov 2008 01:28:13 +0000
changeset 10390 0c2cc4c7b91f
parent 10084 a544278a1b43
permissions -rw-r--r--
(svn r14641) -Change [Allegro]: when making a debug build revert Allegro's hooks on SIGSEGV/SIGABRT so one can actually use gdb.
-Change: make it more clear that Allegro's failing to find a driver.
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2174
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2174
diff changeset
     2
9111
48ce04029fe4 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 9085
diff changeset
     3
/** @file sdl_v.cpp Implementation of the SDL video driver. */
2189
5cdc11ffeaa4 (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
5cdc11ffeaa4 (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
#ifdef WITH_SDL
5cdc11ffeaa4 (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
9111
48ce04029fe4 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 9085
diff changeset
     7
#include "../stdafx.h"
2189
5cdc11ffeaa4 (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 "../openttd.h"
5cdc11ffeaa4 (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 "../debug.h"
8123
ce31d2843a95 (svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents: 8121
diff changeset
    10
#include "../gfx_func.h"
2189
5cdc11ffeaa4 (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 "../sdl.h"
5cdc11ffeaa4 (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 "../variables.h"
9085
8b3897a75aed (svn r12944) -Codechange: use rev.h instead of externs at many places
smatz
parents: 8985
diff changeset
    13
#include "../rev.h"
6937
40c760fcf1f6 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents: 6878
diff changeset
    14
#include "../blitter/factory.hpp"
8121
3bc6351e7369 (svn r11682) -Codechange: move some 'generic' geometry related types into a single file and do not include gfx.h everywhere to get a Point type.
rubidium
parents: 8113
diff changeset
    15
#include "../network/network.h"
8247
16e1c8db6f55 (svn r11811) -Fix: make compilation without networking work again (and thus move the debugdumpcommand stuff out of the network 'area').
rubidium
parents: 8171
diff changeset
    16
#include "../core/math_func.hpp"
8433
33899f3d6b5c (svn r12003) -Codechange: don't declare InteractiveRandom[Range] in multiple places.
rubidium
parents: 8247
diff changeset
    17
#include "../core/random_func.hpp"
9117
87f472043e9e (svn r12977) -Codechange: remove quite some redundant (duplicate) function declarations.
rubidium
parents: 9111
diff changeset
    18
#include "../functions.h"
87f472043e9e (svn r12977) -Codechange: remove quite some redundant (duplicate) function declarations.
rubidium
parents: 9111
diff changeset
    19
#include "../texteff.hpp"
2189
5cdc11ffeaa4 (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
    20
#include "sdl_v.h"
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    21
#include <SDL.h>
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    22
7170
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7019
diff changeset
    23
static FVideoDriver_SDL iFVideoDriver_SDL;
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7019
diff changeset
    24
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    25
static SDL_Surface *_sdl_screen;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    26
static bool _all_modes;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    27
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    28
#define MAX_DIRTY_RECTS 100
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    29
static SDL_Rect _dirty_rects[MAX_DIRTY_RECTS];
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    30
static int _num_dirty_rects;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    31
7170
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7019
diff changeset
    32
void VideoDriver_SDL::MakeDirty(int left, int top, int width, int height)
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    33
{
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    34
	if (_num_dirty_rects < MAX_DIRTY_RECTS) {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    35
		_dirty_rects[_num_dirty_rects].x = left;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    36
		_dirty_rects[_num_dirty_rects].y = top;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    37
		_dirty_rects[_num_dirty_rects].w = width;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    38
		_dirty_rects[_num_dirty_rects].h = height;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    39
	}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    40
	_num_dirty_rects++;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    41
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    42
2226
66e24b126ce0 (svn r2746) -Fix: SDL_SetColors() has the number of palette entries to change as parameter, not one beyond the last entry to change
tron
parents: 2210
diff changeset
    43
static void UpdatePalette(uint start, uint count)
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    44
{
2226
66e24b126ce0 (svn r2746) -Fix: SDL_SetColors() has the number of palette entries to change as parameter, not one beyond the last entry to change
tron
parents: 2210
diff changeset
    45
	SDL_Color pal[256];
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    46
	uint i;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    47
2226
66e24b126ce0 (svn r2746) -Fix: SDL_SetColors() has the number of palette entries to change as parameter, not one beyond the last entry to change
tron
parents: 2210
diff changeset
    48
	for (i = 0; i != count; i++) {
66e24b126ce0 (svn r2746) -Fix: SDL_SetColors() has the number of palette entries to change as parameter, not one beyond the last entry to change
tron
parents: 2210
diff changeset
    49
		pal[i].r = _cur_palette[start + i].r;
66e24b126ce0 (svn r2746) -Fix: SDL_SetColors() has the number of palette entries to change as parameter, not one beyond the last entry to change
tron
parents: 2210
diff changeset
    50
		pal[i].g = _cur_palette[start + i].g;
66e24b126ce0 (svn r2746) -Fix: SDL_SetColors() has the number of palette entries to change as parameter, not one beyond the last entry to change
tron
parents: 2210
diff changeset
    51
		pal[i].b = _cur_palette[start + i].b;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    52
		pal[i].unused = 0;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    53
	}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    54
2226
66e24b126ce0 (svn r2746) -Fix: SDL_SetColors() has the number of palette entries to change as parameter, not one beyond the last entry to change
tron
parents: 2210
diff changeset
    55
	SDL_CALL SDL_SetColors(_sdl_screen, pal, start, count);
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    56
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    57
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
    58
static void InitPalette()
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    59
{
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    60
	UpdatePalette(0, 256);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    61
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    62
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
    63
static void CheckPaletteAnim()
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    64
{
6961
8e5217fd71f4 (svn r10217) -Fix r10216: forgot to declare 'blitter' in win32 and cocoa driver (tnx glx)
truelight
parents: 6960
diff changeset
    65
	if (_pal_count_dirty != 0) {
8e5217fd71f4 (svn r10217) -Fix r10216: forgot to declare 'blitter' in win32 and cocoa driver (tnx glx)
truelight
parents: 6960
diff changeset
    66
		Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
6960
356d856462b6 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 6937
diff changeset
    67
356d856462b6 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 6937
diff changeset
    68
		switch (blitter->UsePaletteAnimation()) {
356d856462b6 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 6937
diff changeset
    69
			case Blitter::PALETTE_ANIMATION_VIDEO_BACKEND:
356d856462b6 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 6937
diff changeset
    70
				UpdatePalette(_pal_first_dirty, _pal_count_dirty);
356d856462b6 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 6937
diff changeset
    71
				break;
356d856462b6 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 6937
diff changeset
    72
356d856462b6 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 6937
diff changeset
    73
			case Blitter::PALETTE_ANIMATION_BLITTER:
356d856462b6 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 6937
diff changeset
    74
				blitter->PaletteAnimate(_pal_first_dirty, _pal_count_dirty);
356d856462b6 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 6937
diff changeset
    75
				break;
356d856462b6 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 6937
diff changeset
    76
356d856462b6 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 6937
diff changeset
    77
			case Blitter::PALETTE_ANIMATION_NONE:
356d856462b6 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 6937
diff changeset
    78
				break;
356d856462b6 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 6937
diff changeset
    79
356d856462b6 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 6937
diff changeset
    80
			default:
356d856462b6 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 6937
diff changeset
    81
				NOT_REACHED();
356d856462b6 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 6937
diff changeset
    82
		}
356d856462b6 (svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents: 6937
diff changeset
    83
		_pal_count_dirty = 0;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    84
	}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    85
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    86
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
    87
static void DrawSurfaceToScreen()
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    88
{
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    89
	int n = _num_dirty_rects;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    90
	if (n != 0) {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    91
		_num_dirty_rects = 0;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    92
		if (n > MAX_DIRTY_RECTS)
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    93
			SDL_CALL SDL_UpdateRect(_sdl_screen, 0, 0, 0, 0);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    94
		else
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    95
			SDL_CALL SDL_UpdateRects(_sdl_screen, n, _dirty_rects);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    96
	}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    97
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    98
9533
e8b86b70c5f6 (svn r13537) -Fix [FS#2090](r13523): QSortT won't work this way, use Dimension instead of uint16[2] for resolutions
smatz
parents: 9470
diff changeset
    99
static const Dimension default_resolutions[] = {
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   100
	{ 640,  480},
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   101
	{ 800,  600},
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   102
	{1024,  768},
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   103
	{1152,  864},
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   104
	{1280,  800},
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   105
	{1280,  960},
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   106
	{1280, 1024},
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   107
	{1400, 1050},
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   108
	{1600, 1200},
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   109
	{1680, 1050},
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   110
	{1920, 1200}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   111
};
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   112
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
   113
static void GetVideoModes()
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   114
{
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   115
	int i;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   116
	SDL_Rect **modes;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   117
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   118
	modes = SDL_CALL SDL_ListModes(NULL, SDL_SWSURFACE + (_fullscreen ? SDL_FULLSCREEN : 0));
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   119
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   120
	if (modes == NULL)
9470
08424e2e79e4 (svn r13390) -Codechange: introduce usererror() for fatal but not openttd related errors. Now all error() will 'crash' openttd after showing the message in win32 releases (MSVC), creating a crash.log and crash.dmp (like the '!' hack used before). On the other hand, usererror() will just close the game. So use error() only when it can be helpful to debugging, else use usererror().
glx
parents: 9117
diff changeset
   121
		usererror("sdl: no modes available");
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   122
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   123
	_all_modes = (modes == (void*)-1);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   124
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   125
	if (_all_modes) {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   126
		// all modes available, put some default ones here
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   127
		memcpy(_resolutions, default_resolutions, sizeof(default_resolutions));
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   128
		_num_resolutions = lengthof(default_resolutions);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   129
	} else {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   130
		int n = 0;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   131
		for (i = 0; modes[i]; i++) {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   132
			int w = modes[i]->w;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   133
			int h = modes[i]->h;
8985
6461e5c6d6e4 (svn r12779) -Codechange: remove a few constants from openttd.h.
rubidium
parents: 8586
diff changeset
   134
			if (w >= 640 && h >= 480) {
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   135
				int j;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   136
				for (j = 0; j < n; j++) {
9533
e8b86b70c5f6 (svn r13537) -Fix [FS#2090](r13523): QSortT won't work this way, use Dimension instead of uint16[2] for resolutions
smatz
parents: 9470
diff changeset
   137
					if (_resolutions[j].width == w && _resolutions[j].height == h) break;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   138
				}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   139
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   140
				if (j == n) {
9533
e8b86b70c5f6 (svn r13537) -Fix [FS#2090](r13523): QSortT won't work this way, use Dimension instead of uint16[2] for resolutions
smatz
parents: 9470
diff changeset
   141
					_resolutions[j].width  = w;
e8b86b70c5f6 (svn r13537) -Fix [FS#2090](r13523): QSortT won't work this way, use Dimension instead of uint16[2] for resolutions
smatz
parents: 9470
diff changeset
   142
					_resolutions[j].height = h;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   143
					if (++n == lengthof(_resolutions)) break;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   144
				}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   145
			}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   146
		}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   147
		_num_resolutions = n;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   148
		SortResolutions(_num_resolutions);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   149
	}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   150
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   151
4501
f544a0172d5c (svn r6286) Nobody cares for the return value of GetAvailableVideoMode(), therefore remove it
tron
parents: 4434
diff changeset
   152
static void GetAvailableVideoMode(int *w, int *h)
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   153
{
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   154
	int i;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   155
	int best;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   156
	uint delta;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   157
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   158
	// all modes available?
10390
0c2cc4c7b91f (svn r14641) -Change [Allegro]: when making a debug build revert Allegro's hooks on SIGSEGV/SIGABRT so one can actually use gdb.
rubidium
parents: 10084
diff changeset
   159
	if (_all_modes || _num_resolutions == 0) return;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   160
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   161
	// is the wanted mode among the available modes?
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   162
	for (i = 0; i != _num_resolutions; i++) {
9533
e8b86b70c5f6 (svn r13537) -Fix [FS#2090](r13523): QSortT won't work this way, use Dimension instead of uint16[2] for resolutions
smatz
parents: 9470
diff changeset
   163
		if (*w == _resolutions[i].width && *h == _resolutions[i].height) return;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   164
	}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   165
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   166
	// use the closest possible resolution
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   167
	best = 0;
9533
e8b86b70c5f6 (svn r13537) -Fix [FS#2090](r13523): QSortT won't work this way, use Dimension instead of uint16[2] for resolutions
smatz
parents: 9470
diff changeset
   168
	delta = abs((_resolutions[0].width - *w) * (_resolutions[0].height - *h));
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   169
	for (i = 1; i != _num_resolutions; ++i) {
9533
e8b86b70c5f6 (svn r13537) -Fix [FS#2090](r13523): QSortT won't work this way, use Dimension instead of uint16[2] for resolutions
smatz
parents: 9470
diff changeset
   170
		uint newdelta = abs((_resolutions[i].width - *w) * (_resolutions[i].height - *h));
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   171
		if (newdelta < delta) {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   172
			best = i;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   173
			delta = newdelta;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   174
		}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   175
	}
9533
e8b86b70c5f6 (svn r13537) -Fix [FS#2090](r13523): QSortT won't work this way, use Dimension instead of uint16[2] for resolutions
smatz
parents: 9470
diff changeset
   176
	*w = _resolutions[best].width;
e8b86b70c5f6 (svn r13537) -Fix [FS#2090](r13523): QSortT won't work this way, use Dimension instead of uint16[2] for resolutions
smatz
parents: 9470
diff changeset
   177
	*h = _resolutions[best].height;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   178
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   179
4256
5e29191a88a1 (svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents: 4077
diff changeset
   180
#ifndef ICON_DIR
5e29191a88a1 (svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents: 4077
diff changeset
   181
#define ICON_DIR "media"
5e29191a88a1 (svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents: 4077
diff changeset
   182
#endif
5e29191a88a1 (svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents: 4077
diff changeset
   183
5e29191a88a1 (svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents: 4077
diff changeset
   184
#ifdef WIN32
5e29191a88a1 (svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents: 4077
diff changeset
   185
/* Let's redefine the LoadBMP macro with because we are dynamically
5e29191a88a1 (svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents: 4077
diff changeset
   186
 * loading SDL and need to 'SDL_CALL' all functions */
5e29191a88a1 (svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents: 4077
diff changeset
   187
#undef SDL_LoadBMP
5e29191a88a1 (svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents: 4077
diff changeset
   188
#define SDL_LoadBMP(file)	SDL_LoadBMP_RW(SDL_CALL SDL_RWFromFile(file, "rb"), 1)
5e29191a88a1 (svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents: 4077
diff changeset
   189
#endif
5e29191a88a1 (svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents: 4077
diff changeset
   190
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   191
static bool CreateMainSurface(int w, int h)
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   192
{
4256
5e29191a88a1 (svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents: 4077
diff changeset
   193
	SDL_Surface *newscreen, *icon;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   194
	char caption[50];
6878
5cefd3ac59c7 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 6615
diff changeset
   195
	int bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth();
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   196
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   197
	GetAvailableVideoMode(&w, &h);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   198
6878
5cefd3ac59c7 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 6615
diff changeset
   199
	DEBUG(driver, 1, "SDL: using mode %dx%dx%d", w, h, bpp);
5cefd3ac59c7 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 6615
diff changeset
   200
9470
08424e2e79e4 (svn r13390) -Codechange: introduce usererror() for fatal but not openttd related errors. Now all error() will 'crash' openttd after showing the message in win32 releases (MSVC), creating a crash.log and crash.dmp (like the '!' hack used before). On the other hand, usererror() will just close the game. So use error() only when it can be helpful to debugging, else use usererror().
glx
parents: 9117
diff changeset
   201
	if (bpp == 0) usererror("Can't use a blitter that blits 0 bpp for normal visuals");
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   202
4256
5e29191a88a1 (svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents: 4077
diff changeset
   203
	/* Give the application an icon */
5e29191a88a1 (svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents: 4077
diff changeset
   204
	icon = SDL_CALL SDL_LoadBMP(ICON_DIR PATHSEP "openttd.32.bmp");
5e29191a88a1 (svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents: 4077
diff changeset
   205
	if (icon != NULL) {
5e29191a88a1 (svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents: 4077
diff changeset
   206
		/* Get the colourkey, which will be magenta */
5e29191a88a1 (svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents: 4077
diff changeset
   207
		uint32 rgbmap = SDL_CALL SDL_MapRGB(icon->format, 255, 0, 255);
4507
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   208
4256
5e29191a88a1 (svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents: 4077
diff changeset
   209
		SDL_CALL SDL_SetColorKey(icon, SDL_SRCCOLORKEY, rgbmap);
5e29191a88a1 (svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents: 4077
diff changeset
   210
		SDL_CALL SDL_WM_SetIcon(icon, NULL);
5e29191a88a1 (svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents: 4077
diff changeset
   211
		SDL_CALL SDL_FreeSurface(icon);
5e29191a88a1 (svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents: 4077
diff changeset
   212
	}
5e29191a88a1 (svn r5872) - Feature: Add an icon to the SDL openttd executable.
Darkvater
parents: 4077
diff changeset
   213
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   214
	// DO NOT CHANGE TO HWSURFACE, IT DOES NOT WORK
6878
5cefd3ac59c7 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 6615
diff changeset
   215
	newscreen = SDL_CALL SDL_SetVideoMode(w, h, bpp, SDL_SWSURFACE | SDL_HWPALETTE | (_fullscreen ? SDL_FULLSCREEN : SDL_RESIZABLE));
10390
0c2cc4c7b91f (svn r14641) -Change [Allegro]: when making a debug build revert Allegro's hooks on SIGSEGV/SIGABRT so one can actually use gdb.
rubidium
parents: 10084
diff changeset
   216
	if (newscreen == NULL) {
0c2cc4c7b91f (svn r14641) -Change [Allegro]: when making a debug build revert Allegro's hooks on SIGSEGV/SIGABRT so one can actually use gdb.
rubidium
parents: 10084
diff changeset
   217
		DEBUG(driver, 0, "SDL: Couldn't allocate a window to draw on");
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   218
		return false;
10390
0c2cc4c7b91f (svn r14641) -Change [Allegro]: when making a debug build revert Allegro's hooks on SIGSEGV/SIGABRT so one can actually use gdb.
rubidium
parents: 10084
diff changeset
   219
	}
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   220
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   221
	_screen.width = newscreen->w;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   222
	_screen.height = newscreen->h;
6878
5cefd3ac59c7 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 6615
diff changeset
   223
	_screen.pitch = newscreen->pitch / (bpp / 8);
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   224
	_sdl_screen = newscreen;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   225
	InitPalette();
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   226
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   227
	snprintf(caption, sizeof(caption), "OpenTTD %s", _openttd_revision);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   228
	SDL_CALL SDL_WM_SetCaption(caption, caption);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   229
	SDL_CALL SDL_ShowCursor(0);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   230
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   231
	GameSizeChanged();
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   232
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   233
	return true;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   234
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   235
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
   236
struct VkMapping {
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   237
	uint16 vk_from;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   238
	byte vk_count;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   239
	byte map_to;
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
   240
};
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   241
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   242
#define AS(x, z) {x, 0, z}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   243
#define AM(x, y, z, w) {x, y - x, z}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   244
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   245
static const VkMapping _vk_mapping[] = {
7311
fde7a4d92a39 (svn r10663) -Fix r10662: bad me, didn't comply with coding style, as penalty I updated the surrounding code to comply with coding style too; I will never do it again (I hope :p)
truelight
parents: 7310
diff changeset
   246
	/* Pageup stuff + up/down */
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   247
	AM(SDLK_PAGEUP, SDLK_PAGEDOWN, WKC_PAGEUP, WKC_PAGEDOWN),
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
   248
	AS(SDLK_UP,     WKC_UP),
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
   249
	AS(SDLK_DOWN,   WKC_DOWN),
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
   250
	AS(SDLK_LEFT,   WKC_LEFT),
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
   251
	AS(SDLK_RIGHT,  WKC_RIGHT),
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   252
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
   253
	AS(SDLK_HOME,   WKC_HOME),
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
   254
	AS(SDLK_END,    WKC_END),
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   255
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
   256
	AS(SDLK_INSERT, WKC_INSERT),
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
   257
	AS(SDLK_DELETE, WKC_DELETE),
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   258
7311
fde7a4d92a39 (svn r10663) -Fix r10662: bad me, didn't comply with coding style, as penalty I updated the surrounding code to comply with coding style too; I will never do it again (I hope :p)
truelight
parents: 7310
diff changeset
   259
	/* Map letters & digits */
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   260
	AM(SDLK_a, SDLK_z, 'A', 'Z'),
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   261
	AM(SDLK_0, SDLK_9, '0', '9'),
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   262
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
   263
	AS(SDLK_ESCAPE,    WKC_ESC),
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
   264
	AS(SDLK_PAUSE,     WKC_PAUSE),
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
   265
	AS(SDLK_BACKSPACE, WKC_BACKSPACE),
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   266
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
   267
	AS(SDLK_SPACE,     WKC_SPACE),
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
   268
	AS(SDLK_RETURN,    WKC_RETURN),
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
   269
	AS(SDLK_TAB,       WKC_TAB),
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   270
7311
fde7a4d92a39 (svn r10663) -Fix r10662: bad me, didn't comply with coding style, as penalty I updated the surrounding code to comply with coding style too; I will never do it again (I hope :p)
truelight
parents: 7310
diff changeset
   271
	/* Function keys */
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   272
	AM(SDLK_F1, SDLK_F12, WKC_F1, WKC_F12),
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   273
7311
fde7a4d92a39 (svn r10663) -Fix r10662: bad me, didn't comply with coding style, as penalty I updated the surrounding code to comply with coding style too; I will never do it again (I hope :p)
truelight
parents: 7310
diff changeset
   274
	/* Numeric part. */
10084
a544278a1b43 (svn r14260) -Fix [FS#2277]: merge keycode for "normal" 0-9 keys and keypad 0-9 keys so people don't get confused that the keypad doesn't work as expected.
rubidium
parents: 9898
diff changeset
   275
	AM(SDLK_KP0, SDLK_KP9, '0', '9'),
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
   276
	AS(SDLK_KP_DIVIDE,   WKC_NUM_DIV),
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
   277
	AS(SDLK_KP_MULTIPLY, WKC_NUM_MUL),
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
   278
	AS(SDLK_KP_MINUS,    WKC_NUM_MINUS),
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
   279
	AS(SDLK_KP_PLUS,     WKC_NUM_PLUS),
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
   280
	AS(SDLK_KP_ENTER,    WKC_NUM_ENTER),
7310
eed5036fee1f (svn r10662) -Add: added 'V' as new shortcut for new viewport (bilbo)
truelight
parents: 7170
diff changeset
   281
	AS(SDLK_KP_PERIOD,   WKC_NUM_DECIMAL),
eed5036fee1f (svn r10662) -Add: added 'V' as new shortcut for new viewport (bilbo)
truelight
parents: 7170
diff changeset
   282
7311
fde7a4d92a39 (svn r10663) -Fix r10662: bad me, didn't comply with coding style, as penalty I updated the surrounding code to comply with coding style too; I will never do it again (I hope :p)
truelight
parents: 7310
diff changeset
   283
	/* Other non-letter keys */
7310
eed5036fee1f (svn r10662) -Add: added 'V' as new shortcut for new viewport (bilbo)
truelight
parents: 7170
diff changeset
   284
	AS(SDLK_SLASH,        WKC_SLASH),
eed5036fee1f (svn r10662) -Add: added 'V' as new shortcut for new viewport (bilbo)
truelight
parents: 7170
diff changeset
   285
	AS(SDLK_SEMICOLON,    WKC_SEMICOLON),
eed5036fee1f (svn r10662) -Add: added 'V' as new shortcut for new viewport (bilbo)
truelight
parents: 7170
diff changeset
   286
	AS(SDLK_EQUALS,       WKC_EQUALS),
eed5036fee1f (svn r10662) -Add: added 'V' as new shortcut for new viewport (bilbo)
truelight
parents: 7170
diff changeset
   287
	AS(SDLK_LEFTBRACKET,  WKC_L_BRACKET),
eed5036fee1f (svn r10662) -Add: added 'V' as new shortcut for new viewport (bilbo)
truelight
parents: 7170
diff changeset
   288
	AS(SDLK_BACKSLASH,    WKC_BACKSLASH),
eed5036fee1f (svn r10662) -Add: added 'V' as new shortcut for new viewport (bilbo)
truelight
parents: 7170
diff changeset
   289
	AS(SDLK_RIGHTBRACKET, WKC_R_BRACKET),
eed5036fee1f (svn r10662) -Add: added 'V' as new shortcut for new viewport (bilbo)
truelight
parents: 7170
diff changeset
   290
eed5036fee1f (svn r10662) -Add: added 'V' as new shortcut for new viewport (bilbo)
truelight
parents: 7170
diff changeset
   291
	AS(SDLK_QUOTE,   WKC_SINGLEQUOTE),
eed5036fee1f (svn r10662) -Add: added 'V' as new shortcut for new viewport (bilbo)
truelight
parents: 7170
diff changeset
   292
	AS(SDLK_COMMA,   WKC_COMMA),
eed5036fee1f (svn r10662) -Add: added 'V' as new shortcut for new viewport (bilbo)
truelight
parents: 7170
diff changeset
   293
	AS(SDLK_MINUS,   WKC_MINUS),
eed5036fee1f (svn r10662) -Add: added 'V' as new shortcut for new viewport (bilbo)
truelight
parents: 7170
diff changeset
   294
	AS(SDLK_PERIOD,  WKC_PERIOD)
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   295
};
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   296
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   297
static uint32 ConvertSdlKeyIntoMy(SDL_keysym *sym)
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   298
{
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   299
	const VkMapping *map;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   300
	uint key = 0;
4507
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   301
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   302
	for (map = _vk_mapping; map != endof(_vk_mapping); ++map) {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   303
		if ((uint)(sym->sym - map->vk_from) <= map->vk_count) {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   304
			key = sym->sym - map->vk_from + map->map_to;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   305
			break;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   306
		}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   307
	}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   308
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   309
	// check scancode for BACKQUOTE key, because we want the key left of "1", not anything else (on non-US keyboards)
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   310
#if defined(WIN32) || defined(__OS2__)
5099
d62e259c4afe (svn r7170) -Fix: [sdl] Non-working console toggle for some keyboard layouts. Do not OR the backquote
Darkvater
parents: 5090
diff changeset
   311
	if (sym->scancode == 41) key = WKC_BACKQUOTE;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   312
#elif defined(__APPLE__)
5099
d62e259c4afe (svn r7170) -Fix: [sdl] Non-working console toggle for some keyboard layouts. Do not OR the backquote
Darkvater
parents: 5090
diff changeset
   313
	if (sym->scancode == 10) key = WKC_BACKQUOTE;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   314
#elif defined(__MORPHOS__)
5099
d62e259c4afe (svn r7170) -Fix: [sdl] Non-working console toggle for some keyboard layouts. Do not OR the backquote
Darkvater
parents: 5090
diff changeset
   315
	if (sym->scancode == 0)  key = WKC_BACKQUOTE;  // yes, that key is code '0' under MorphOS :)
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   316
#elif defined(__BEOS__)
5099
d62e259c4afe (svn r7170) -Fix: [sdl] Non-working console toggle for some keyboard layouts. Do not OR the backquote
Darkvater
parents: 5090
diff changeset
   317
	if (sym->scancode == 17) key = WKC_BACKQUOTE;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   318
#elif defined(__SVR4) && defined(__sun)
5099
d62e259c4afe (svn r7170) -Fix: [sdl] Non-working console toggle for some keyboard layouts. Do not OR the backquote
Darkvater
parents: 5090
diff changeset
   319
	if (sym->scancode == 60) key = WKC_BACKQUOTE;
d62e259c4afe (svn r7170) -Fix: [sdl] Non-working console toggle for some keyboard layouts. Do not OR the backquote
Darkvater
parents: 5090
diff changeset
   320
	if (sym->scancode == 49) key = WKC_BACKSPACE;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   321
#elif defined(__sgi__)
5099
d62e259c4afe (svn r7170) -Fix: [sdl] Non-working console toggle for some keyboard layouts. Do not OR the backquote
Darkvater
parents: 5090
diff changeset
   322
	if (sym->scancode == 22) key = WKC_BACKQUOTE;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   323
#else
5099
d62e259c4afe (svn r7170) -Fix: [sdl] Non-working console toggle for some keyboard layouts. Do not OR the backquote
Darkvater
parents: 5090
diff changeset
   324
	if (sym->scancode == 49) key = WKC_BACKQUOTE;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   325
#endif
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   326
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   327
	// META are the command keys on mac
4507
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   328
	if (sym->mod & KMOD_META)  key |= WKC_META;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   329
	if (sym->mod & KMOD_SHIFT) key |= WKC_SHIFT;
4507
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   330
	if (sym->mod & KMOD_CTRL)  key |= WKC_CTRL;
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   331
	if (sym->mod & KMOD_ALT)   key |= WKC_ALT;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   332
	// these two lines really help porting hotkey combos. Uncomment to use -- Bjarni
4507
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   333
#if 0
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5217
diff changeset
   334
	DEBUG(driver, 0, "Scancode character pressed %u", sym->scancode);
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5217
diff changeset
   335
	DEBUG(driver, 0, "Unicode character pressed %u", sym->unicode);
4507
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   336
#endif
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   337
	return (key << 16) + sym->unicode;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   338
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   339
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
   340
static int PollEvent()
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   341
{
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   342
	SDL_Event ev;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   343
4507
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   344
	if (!SDL_CALL SDL_PollEvent(&ev)) return -2;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   345
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   346
	switch (ev.type) {
4507
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   347
		case SDL_MOUSEMOTION:
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   348
			if (_cursor.fix_at) {
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   349
				int dx = ev.motion.x - _cursor.pos.x;
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   350
				int dy = ev.motion.y - _cursor.pos.y;
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   351
				if (dx != 0 || dy != 0) {
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   352
					_cursor.delta.x += dx;
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   353
					_cursor.delta.y += dy;
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   354
					SDL_CALL SDL_WarpMouse(_cursor.pos.x, _cursor.pos.y);
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   355
				}
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   356
			} else {
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   357
				_cursor.delta.x = ev.motion.x - _cursor.pos.x;
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   358
				_cursor.delta.y = ev.motion.y - _cursor.pos.y;
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   359
				_cursor.pos.x = ev.motion.x;
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   360
				_cursor.pos.y = ev.motion.y;
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   361
				_cursor.dirty = true;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   362
			}
5090
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
   363
			HandleMouseEvents();
4507
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   364
			break;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   365
4507
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   366
		case SDL_MOUSEBUTTONDOWN:
4508
0e626ba2a59a (svn r6293) -Codechange: Simply use KMOD_CTRL instead of KMOD_LCTRL | KMOD_RCTRL, same for KMOD_SHIFT
tron
parents: 4507
diff changeset
   367
			if (_rightclick_emulate && SDL_CALL SDL_GetModState() & KMOD_CTRL) {
4507
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   368
				ev.button.button = SDL_BUTTON_RIGHT;
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   369
			}
3312
d28f88dc5587 (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: 2952
diff changeset
   370
4507
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   371
			switch (ev.button.button) {
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   372
				case SDL_BUTTON_LEFT:
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   373
					_left_button_down = true;
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   374
					break;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   375
4507
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   376
				case SDL_BUTTON_RIGHT:
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   377
					_right_button_down = true;
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   378
					_right_button_clicked = true;
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   379
					break;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   380
4507
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   381
				case SDL_BUTTON_WHEELUP:   _cursor.wheel--; break;
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   382
				case SDL_BUTTON_WHEELDOWN: _cursor.wheel++; break;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   383
4507
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   384
				default: break;
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   385
			}
5090
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
   386
			HandleMouseEvents();
4507
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   387
			break;
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   388
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   389
		case SDL_MOUSEBUTTONUP:
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   390
			if (_rightclick_emulate) {
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   391
				_right_button_down = false;
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   392
				_left_button_down = false;
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   393
				_left_button_clicked = false;
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   394
			} else if (ev.button.button == SDL_BUTTON_LEFT) {
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   395
				_left_button_down = false;
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   396
				_left_button_clicked = false;
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   397
			} else if (ev.button.button == SDL_BUTTON_RIGHT) {
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   398
				_right_button_down = false;
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   399
			}
5090
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
   400
			HandleMouseEvents();
4507
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   401
			break;
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   402
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   403
		case SDL_ACTIVEEVENT:
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   404
			if (!(ev.active.state & SDL_APPMOUSEFOCUS)) break;
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   405
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   406
			if (ev.active.gain) { // mouse entered the window, enable cursor
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   407
				_cursor.in_window = true;
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   408
			} else {
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   409
				UndrawMouseCursor(); // mouse left the window, undraw cursor
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   410
				_cursor.in_window = false;
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   411
			}
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   412
			break;
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   413
4548
6165e12570bf (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4536
diff changeset
   414
		case SDL_QUIT: HandleExitGameRequest(); break;
4507
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   415
4548
6165e12570bf (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4536
diff changeset
   416
		case SDL_KEYDOWN: /* Toggle full-screen on ALT + ENTER/F */
4507
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   417
			if ((ev.key.keysym.mod & (KMOD_ALT | KMOD_META)) &&
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   418
					(ev.key.keysym.sym == SDLK_RETURN || ev.key.keysym.sym == SDLK_f)) {
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   419
				ToggleFullScreen(!_fullscreen);
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   420
			} else {
5086
386ba9fe0621 (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5015
diff changeset
   421
				HandleKeypress(ConvertSdlKeyIntoMy(&ev.key.keysym));
4507
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   422
			}
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   423
			break;
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   424
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   425
		case SDL_VIDEORESIZE: {
8985
6461e5c6d6e4 (svn r12779) -Codechange: remove a few constants from openttd.h.
rubidium
parents: 8586
diff changeset
   426
			int w = max(ev.resize.w, 64);
6461e5c6d6e4 (svn r12779) -Codechange: remove a few constants from openttd.h.
rubidium
parents: 8586
diff changeset
   427
			int h = max(ev.resize.h, 64);
4507
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   428
			ChangeResInGame(w, h);
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   429
			break;
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   430
		}
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   431
	}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   432
	return -1;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   433
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   434
7170
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7019
diff changeset
   435
const char *VideoDriver_SDL::Start(const char * const *parm)
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   436
{
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   437
	char buf[30];
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   438
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   439
	const char *s = SdlOpen(SDL_INIT_VIDEO);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   440
	if (s != NULL) return s;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   441
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   442
	SDL_CALL SDL_VideoDriverName(buf, 30);
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5217
diff changeset
   443
	DEBUG(driver, 1, "SDL: using driver '%s'", buf);
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   444
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   445
	GetVideoModes();
9533
e8b86b70c5f6 (svn r13537) -Fix [FS#2090](r13523): QSortT won't work this way, use Dimension instead of uint16[2] for resolutions
smatz
parents: 9470
diff changeset
   446
	CreateMainSurface(_cur_resolution.width, _cur_resolution.height);
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   447
	MarkWholeScreenDirty();
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   448
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   449
	SDL_CALL SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   450
	SDL_CALL SDL_EnableUNICODE(1);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   451
	return NULL;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   452
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   453
7170
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7019
diff changeset
   454
void VideoDriver_SDL::Stop()
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   455
{
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   456
	SdlClose(SDL_INIT_VIDEO);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   457
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   458
7170
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7019
diff changeset
   459
void VideoDriver_SDL::MainLoop()
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   460
{
5581
cf2b8ba6556b (svn r8028) -Fix: overflow of ticks was not handled properly, possibly resulting a non-reacting gameserver/gameclient.
rubidium
parents: 5475
diff changeset
   461
	uint32 cur_ticks = SDL_CALL SDL_GetTicks();
7018
71e174292e42 (svn r10276) -Codechange: made a counter based on milliseconds and independent of the game-state to base double-click and TGP Generation Process on
truelight
parents: 6999
diff changeset
   462
	uint32 last_cur_ticks = cur_ticks;
5581
cf2b8ba6556b (svn r8028) -Fix: overflow of ticks was not handled properly, possibly resulting a non-reacting gameserver/gameclient.
rubidium
parents: 5475
diff changeset
   463
	uint32 next_tick = cur_ticks + 30;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   464
	uint32 pal_tick = 0;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   465
	uint32 mod;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   466
	int numkeys;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   467
	Uint8 *keys;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   468
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   469
	for (;;) {
5581
cf2b8ba6556b (svn r8028) -Fix: overflow of ticks was not handled properly, possibly resulting a non-reacting gameserver/gameclient.
rubidium
parents: 5475
diff changeset
   470
		uint32 prev_cur_ticks = cur_ticks; // to check for wrapping
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   471
		InteractiveRandom(); // randomness
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   472
5089
67c761427921 (svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents: 5086
diff changeset
   473
		while (PollEvent() == -1) {}
2228
93cdde0f85ba (svn r2748) Remove unused cruft from the main loop
tron
parents: 2226
diff changeset
   474
		if (_exit_game) return;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   475
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   476
		mod = SDL_CALL SDL_GetModState();
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   477
		keys = SDL_CALL SDL_GetKeyState(&numkeys);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   478
#if defined(_DEBUG)
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   479
		if (_shift_pressed)
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   480
#else
5461
f056fa8bf44c (svn r7727) -Fix (FS#498): sometimes ALT-TAB could trigger the fast forward.
rubidium
parents: 5380
diff changeset
   481
		/* Speedup when pressing tab, except when using ALT+TAB
f056fa8bf44c (svn r7727) -Fix (FS#498): sometimes ALT-TAB could trigger the fast forward.
rubidium
parents: 5380
diff changeset
   482
		 * to switch to another application */
f056fa8bf44c (svn r7727) -Fix (FS#498): sometimes ALT-TAB could trigger the fast forward.
rubidium
parents: 5380
diff changeset
   483
		if (keys[SDLK_TAB] && (mod & KMOD_ALT) == 0)
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   484
#endif
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   485
		{
4536
d532b2611952 (svn r6365) -Cleanup: remove IsGeneratingWorld calls that are either not called or have no effect.
rubidium
parents: 4508
diff changeset
   486
			if (!_networking && _game_mode != GM_MENU) _fast_forward |= 2;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   487
		} else if (_fast_forward & 2) {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   488
			_fast_forward = 0;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   489
		}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   490
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   491
		cur_ticks = SDL_CALL SDL_GetTicks();
6231
ff7454d35935 (svn r9034) -Codechange: renamed _pause to _pause_game, as some targets already have
truelight
parents: 5988
diff changeset
   492
		if (cur_ticks >= next_tick || (_fast_forward && !_pause_game) || cur_ticks < prev_cur_ticks) {
7019
09e090048a59 (svn r10278) -Fix r10276: make the _realtime_tick less demanding on the CPU
truelight
parents: 7018
diff changeset
   493
			_realtime_tick += cur_ticks - last_cur_ticks;
09e090048a59 (svn r10278) -Fix r10276: make the _realtime_tick less demanding on the CPU
truelight
parents: 7018
diff changeset
   494
			last_cur_ticks = cur_ticks;
5581
cf2b8ba6556b (svn r8028) -Fix: overflow of ticks was not handled properly, possibly resulting a non-reacting gameserver/gameclient.
rubidium
parents: 5475
diff changeset
   495
			next_tick = cur_ticks + 30;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   496
8586
cb0e7e00f1d2 (svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents: 8433
diff changeset
   497
			bool old_ctrl_pressed = _ctrl_pressed;
cb0e7e00f1d2 (svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents: 8433
diff changeset
   498
4508
0e626ba2a59a (svn r6293) -Codechange: Simply use KMOD_CTRL instead of KMOD_LCTRL | KMOD_RCTRL, same for KMOD_SHIFT
tron
parents: 4507
diff changeset
   499
			_ctrl_pressed  = !!(mod & KMOD_CTRL);
0e626ba2a59a (svn r6293) -Codechange: Simply use KMOD_CTRL instead of KMOD_LCTRL | KMOD_RCTRL, same for KMOD_SHIFT
tron
parents: 4507
diff changeset
   500
			_shift_pressed = !!(mod & KMOD_SHIFT);
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   501
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   502
			// determine which directional keys are down
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   503
			_dirkeys =
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   504
				(keys[SDLK_LEFT]  ? 1 : 0) |
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   505
				(keys[SDLK_UP]    ? 2 : 0) |
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   506
				(keys[SDLK_RIGHT] ? 4 : 0) |
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   507
				(keys[SDLK_DOWN]  ? 8 : 0);
8586
cb0e7e00f1d2 (svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents: 8433
diff changeset
   508
cb0e7e00f1d2 (svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents: 8433
diff changeset
   509
			if (old_ctrl_pressed != _ctrl_pressed) HandleCtrlChanged();
cb0e7e00f1d2 (svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents: 8433
diff changeset
   510
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   511
			GameLoop();
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   512
6878
5cefd3ac59c7 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 6615
diff changeset
   513
			_screen.dst_ptr = _sdl_screen->pixels;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   514
			UpdateWindows();
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   515
			if (++pal_tick > 4) {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   516
				CheckPaletteAnim();
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   517
				pal_tick = 1;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   518
			}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   519
			DrawSurfaceToScreen();
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   520
		} else {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   521
			SDL_CALL SDL_Delay(1);
6878
5cefd3ac59c7 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 6615
diff changeset
   522
			_screen.dst_ptr = _sdl_screen->pixels;
9898
75347c78b276 (svn r14047) -Codechange: move chatmessage handling to the network directory as that's the only case chat messages are used. Furthermore remove any trace of chatmessages when compiling without network support.
rubidium
parents: 9533
diff changeset
   523
			NetworkDrawChatMessage();
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   524
			DrawMouseCursor();
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   525
			DrawSurfaceToScreen();
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   526
		}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   527
	}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   528
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   529
7170
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7019
diff changeset
   530
bool VideoDriver_SDL::ChangeResolution(int w, int h)
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   531
{
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   532
	return CreateMainSurface(w, h);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   533
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   534
8171
3fb9d1f8ac3b (svn r11734) -Change: Allow ToggleFullScreen to return the result of the operation' attempt. Previously, only visual clues were available.
belugas
parents: 8131
diff changeset
   535
bool VideoDriver_SDL::ToggleFullscreen(bool fullscreen)
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   536
{
7170
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7019
diff changeset
   537
	_fullscreen = fullscreen;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   538
	GetVideoModes(); // get the list of available video modes
9533
e8b86b70c5f6 (svn r13537) -Fix [FS#2090](r13523): QSortT won't work this way, use Dimension instead of uint16[2] for resolutions
smatz
parents: 9470
diff changeset
   539
	if (_num_resolutions == 0 || !this->ChangeResolution(_cur_resolution.width, _cur_resolution.height)) {
4507
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   540
		// switching resolution failed, put back full_screen to original status
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   541
		_fullscreen ^= true;
8171
3fb9d1f8ac3b (svn r11734) -Change: Allow ToggleFullScreen to return the result of the operation' attempt. Previously, only visual clues were available.
belugas
parents: 8131
diff changeset
   542
		return false;
4507
8db2d47a6527 (svn r6292) -Cleanup: Indentation, bracing, etc.
tron
parents: 4501
diff changeset
   543
	}
8171
3fb9d1f8ac3b (svn r11734) -Change: Allow ToggleFullScreen to return the result of the operation' attempt. Previously, only visual clues were available.
belugas
parents: 8131
diff changeset
   544
	return true;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   545
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   546
5988
1aabf94612c6 (svn r8691) -Cleanup: Some proper #endif comments for sound/music/video files, and a little elimination of magic numbers in Win32SoundStart
Darkvater
parents: 5587
diff changeset
   547
#endif /* WITH_SDL */