#include "quakedef.h"
#include "image.h"
#include "dpsoftrast.h"
+#include "utf8lib.h"
#ifndef __IPHONEOS__
#ifdef MACOSX
static int window_flags;
#endif
static SDL_Surface *vid_softsurface;
+static vid_mode_t desktop_mode;
/////////////////////////
// Input handling
#ifndef SDLK_PERCENT
#define SDLK_PERCENT '%'
+#if SDL_MAJOR_VERSION == 1
#define SDLK_PRINTSCREEN SDLK_PRINT
#define SDLK_SCROLLLOCK SDLK_SCROLLOCK
#define SDLK_NUMLOCKCLEAR SDLK_NUMLOCK
#define SDLK_KP_9 SDLK_KP9
#define SDLK_KP_0 SDLK_KP0
#endif
+#endif
static int MapKey( unsigned int sdlkey )
{
case SDLK_F10: return K_F10;
case SDLK_F11: return K_F11;
case SDLK_F12: return K_F12;
-#if SDL_MAJOR_VERSION == 1
case SDLK_PRINTSCREEN: return K_PRINTSCREEN;
case SDLK_SCROLLLOCK: return K_SCROLLOCK;
-#endif
case SDLK_PAUSE: return K_PAUSE;
case SDLK_INSERT: return K_INS;
case SDLK_HOME: return K_HOME;
case SDLK_LEFT: return K_LEFTARROW;
case SDLK_DOWN: return K_DOWNARROW;
case SDLK_UP: return K_UPARROW;
-#if SDL_MAJOR_VERSION == 1
case SDLK_NUMLOCKCLEAR: return K_NUMLOCK;
-#endif
case SDLK_KP_DIVIDE: return K_KP_DIVIDE;
case SDLK_KP_MULTIPLY: return K_KP_MULTIPLY;
case SDLK_KP_MINUS: return K_KP_MINUS;
case SDLK_KP_PLUS: return K_KP_PLUS;
case SDLK_KP_ENTER: return K_KP_ENTER;
-#if SDL_MAJOR_VERSION == 1
- case SDLK_KP_1: return K_KP_1;
- case SDLK_KP_2: return K_KP_2;
- case SDLK_KP_3: return K_KP_3;
- case SDLK_KP_4: return K_KP_4;
+ case SDLK_KP_1: return ((SDL_GetModState() & KMOD_NUM) ? K_KP_1 : K_END);
+ case SDLK_KP_2: return ((SDL_GetModState() & KMOD_NUM) ? K_KP_2 : K_DOWNARROW);
+ case SDLK_KP_3: return ((SDL_GetModState() & KMOD_NUM) ? K_KP_3 : K_PGDN);
+ case SDLK_KP_4: return ((SDL_GetModState() & KMOD_NUM) ? K_KP_4 : K_LEFTARROW);
case SDLK_KP_5: return K_KP_5;
- case SDLK_KP_6: return K_KP_6;
- case SDLK_KP_7: return K_KP_7;
- case SDLK_KP_8: return K_KP_8;
- case SDLK_KP_9: return K_KP_9;
- case SDLK_KP_0: return K_KP_0;
-#endif
- case SDLK_KP_PERIOD: return K_KP_PERIOD;
+ case SDLK_KP_6: return ((SDL_GetModState() & KMOD_NUM) ? K_KP_6 : K_RIGHTARROW);
+ case SDLK_KP_7: return ((SDL_GetModState() & KMOD_NUM) ? K_KP_7 : K_HOME);
+ case SDLK_KP_8: return ((SDL_GetModState() & KMOD_NUM) ? K_KP_8 : K_UPARROW);
+ case SDLK_KP_9: return ((SDL_GetModState() & KMOD_NUM) ? K_KP_9 : K_PGUP);
+ case SDLK_KP_0: return ((SDL_GetModState() & KMOD_NUM) ? K_KP_0 : K_INS);
+ case SDLK_KP_PERIOD: return ((SDL_GetModState() & KMOD_NUM) ? K_KP_PERIOD : K_DEL);
// case SDLK_APPLICATION: return K_APPLICATION;
// case SDLK_POWER: return K_POWER;
case SDLK_KP_EQUALS: return K_KP_EQUALS;
if (skip != 11) \
VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, NULL, &buttons[11], (keynum_t)'b', NULL, 0, 0, 0, false); \
if (skip != 12) \
- VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, NULL, &buttons[12], 'q', NULL, 0, 0, 0, false); \
+ VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, NULL, &buttons[12], (keynum_t)'q', NULL, 0, 0, 0, false); \
if (skip != 13) \
VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, NULL, &buttons[13], (keynum_t)'`', NULL, 0, 0, 0, false); \
if (skip != 14) \
{
VID_TouchscreenCursor(0, 0, 0, 0, &buttons[0], K_MOUSE1);
- VID_TouchscreenArea( 2,16*xscale,-240*yscale, 224*xscale, 224*yscale, "gfx/gui/touch_l_thumb_dpad.tga", 0.0f, NULL, move, &buttons[1], 0, NULL, 0.15, 112*xscale, 112*yscale, false);
+ VID_TouchscreenArea( 2,16*xscale,-240*yscale, 224*xscale, 224*yscale, "gfx/gui/touch_l_thumb_dpad.tga", 0.0f, NULL, move, &buttons[1], (keynum_t)0, NULL, 0.15, 112*xscale, 112*yscale, false);
- VID_TouchscreenArea( 3,-240*xscale,-160*yscale, 224*xscale, 128*yscale, "gfx/gui/touch_r_thumb_turn_n_shoot.tga" , 0.0f, NULL, NULL, 0, 0, NULL, 0, 56*xscale, 0, false);
- VID_TouchscreenArea( 3,-240*xscale,-256*yscale, 224*xscale, 224*yscale, NULL , 0.0f, NULL, aim, &buttons[2], 0, NULL, 0.2, 56*xscale, 0, false);
+ VID_TouchscreenArea( 3,-240*xscale,-160*yscale, 224*xscale, 128*yscale, "gfx/gui/touch_r_thumb_turn_n_shoot.tga" , 0.0f, NULL, NULL, 0, (keynum_t)0, NULL, 0, 56*xscale, 0, false);
+ VID_TouchscreenArea( 3,-240*xscale,-256*yscale, 224*xscale, 224*yscale, NULL , 0.0f, NULL, aim, &buttons[2], (keynum_t)0, NULL, 0.2, 56*xscale, 0, false);
VID_TouchscreenArea( 2, (vid_conwidth.value / 2) - 128,-80, 256, 80, NULL, 0.0f, NULL, NULL, &buttons[3], K_SHIFT, NULL, 0, 0, 0, true);
VID_TouchscreenArea( 1,-100, 0, 100, 100, NULL , 0.0f, NULL, NULL, &buttons[10], (keynum_t)'m', NULL, 0, 0, 0, true);
VID_TouchscreenArea( 1,-100, 120, 100, 100, NULL , 0.0f, NULL, NULL, &buttons[11], (keynum_t)'b', NULL, 0, 0, 0, true);
- VID_TouchscreenArea( 0, 0, 0, 64, 64, NULL , 0.0f, NULL, NULL, &buttons[12], 'q', NULL, 0, 0, 0, true);
+ VID_TouchscreenArea( 0, 0, 0, 64, 64, NULL , 0.0f, NULL, NULL, &buttons[12], (keynum_t)'q', NULL, 0, 0, 0, true);
if (developer.integer)
VID_TouchscreenArea( 0, 0, 96, 64, 64, NULL , 0.0f, NULL, NULL, &buttons[13], (keynum_t)'`', NULL, 0, 0, 0, true);
else
}
#endif
-static keynum_t buttonremap[18] =
+static keynum_t buttonremap[] =
{
K_MOUSE1,
K_MOUSE3,
K_MOUSE2,
+#if SDL_MAJOR_VERSION == 1
+ // TODO Find out how SDL maps these buttons. It looks like we should
+ // still include these for sdl2? At least the button indexes don't
+ // differ between SDL1 and SDL2 for me, thus this array should stay the
+ // same (in X11 button order).
K_MWHEELUP,
K_MWHEELDOWN,
+#endif
K_MOUSE4,
K_MOUSE5,
K_MOUSE6,
case SDL_KEYUP:
keycode = MapKey(event.key.keysym.sym);
if (!VID_JoyBlockEmulatedKeys(keycode))
+ {
+ if(keycode == K_NUMLOCK || keycode == K_CAPSLOCK)
+ {
+ // simulate down followed by up
+ Key_Event(keycode, event.key.keysym.unicode, true);
+ Key_Event(keycode, event.key.keysym.unicode, false);
+ break;
+ }
Key_Event(keycode, event.key.keysym.unicode, (event.key.state == SDL_PRESSED));
+ }
break;
case SDL_ACTIVEEVENT:
if( event.active.state & SDL_APPACTIVE )
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
if (!vid_touchscreen.integer)
- if (event.button.button <= 18)
+ if (event.button.button > 0 && event.button.button <= ARRAY_SIZE(buttonremap))
Key_Event( buttonremap[event.button.button - 1], 0, event.button.state == SDL_PRESSED );
break;
case SDL_JOYBUTTONDOWN:
case SDL_VIDEOEXPOSE:
break;
case SDL_VIDEORESIZE:
- if(vid_resizable.integer < 2)
+ if(vid_resizable.integer < 2 || vid_isfullscreen)
{
vid.width = event.resize.w;
vid.height = event.resize.h;
- screen = SDL_SetVideoMode(vid.width, vid.height, video_bpp, video_flags);
+ if (!vid_isfullscreen)
+ screen = SDL_SetVideoMode(vid.width, vid.height, video_bpp, video_flags);
if (vid_softsurface)
{
SDL_FreeSurface(vid_softsurface);
vid_softsurface = SDL_CreateRGBSurface(SDL_SWSURFACE, vid.width, vid.height, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
- vid.softpixels = (unsigned int *)vid_softsurface->pixels;
SDL_SetAlpha(vid_softsurface, 0, 255);
+ vid.softpixels = (unsigned int *)vid_softsurface->pixels;
if (vid.softdepthpixels)
free(vid.softdepthpixels);
vid.softdepthpixels = (unsigned int*)calloc(1, vid.width * vid.height * 4);
static qboolean sound_active = true;
int keycode;
int i;
- int j;
- int unicode;
+ Uchar unicode;
SDL_Event event;
VID_EnableJoystick(true);
case SDL_KEYUP:
#ifdef DEBUGSDLEVENTS
if (event.type == SDL_KEYDOWN)
- Con_DPrintf("SDL_Event: SDL_KEYDOWN %i unicode %i\n", event.key.keysym.sym, event.key.keysym.unicode);
+ Con_DPrintf("SDL_Event: SDL_KEYDOWN %i\n", event.key.keysym.sym);
else
- Con_DPrintf("SDL_Event: SDL_KEYUP %i unicode %i\n", event.key.keysym.sym, event.key.keysym.unicode);
+ Con_DPrintf("SDL_Event: SDL_KEYUP %i\n", event.key.keysym.sym);
#endif
keycode = MapKey(event.key.keysym.sym);
if (!VID_JoyBlockEmulatedKeys(keycode))
Con_DPrintf("SDL_Event: SDL_MOUSEBUTTONUP\n");
#endif
if (!vid_touchscreen.integer)
- if (event.button.button <= 18)
+ if (event.button.button > 0 && event.button.button <= ARRAY_SIZE(buttonremap))
Key_Event( buttonremap[event.button.button - 1], 0, event.button.state == SDL_PRESSED );
break;
+ case SDL_MOUSEWHEEL:
+ // TODO support wheel x direction.
+ i = event.wheel.y;
+ while (i > 0) {
+ --i;
+ Key_Event( K_MWHEELUP, 0, true );
+ Key_Event( K_MWHEELUP, 0, false );
+ }
+ while (i < 0) {
+ ++i;
+ Key_Event( K_MWHEELDOWN, 0, true );
+ Key_Event( K_MWHEELDOWN, 0, false );
+ }
+ break;
case SDL_JOYBUTTONDOWN:
case SDL_JOYBUTTONUP:
case SDL_JOYAXISMOTION:
{
SDL_FreeSurface(vid_softsurface);
vid_softsurface = SDL_CreateRGBSurface(SDL_SWSURFACE, vid.width, vid.height, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
+ SDL_SetSurfaceBlendMode(vid_softsurface, SDL_BLENDMODE_NONE);
vid.softpixels = (unsigned int *)vid_softsurface->pixels;
if (vid.softdepthpixels)
free(vid.softdepthpixels);
#ifdef DEBUGSDLEVENTS
Con_DPrintf("SDL_Event: SDL_TEXTINPUT - text: %s\n", event.text.text);
#endif
- // we have some characters to parse
- {
- unicode = 0;
- for (i = 0;event.text.text[i];)
- {
- unicode = event.text.text[i++];
- if (unicode & 0x80)
- {
- // UTF-8 character
- // strip high bits (we could count these to validate character length but we don't)
- for (j = 0x80;unicode & j;j >>= 1)
- unicode ^= j;
- for (;(event.text.text[i] & 0xC0) == 0x80;i++)
- unicode = (unicode << 6) | (event.text.text[i] & 0x3F);
- // low characters are invalid and could be bad, so replace them
- if (unicode < 0x80)
- unicode = '?'; // we could use 0xFFFD instead, the unicode substitute character
- }
- //Con_DPrintf("SDL_TEXTINPUT: K_TEXT %i \n", unicode);
-
- Key_Event(K_TEXT, unicode, true);
- Key_Event(K_TEXT, unicode, false);
- }
- }
+ // convert utf8 string to char
+ // NOTE: this code is supposed to run even if utf8enable is 0
+ unicode = u8_getchar_utf8_enabled(event.text.text + (int)u8_bytelen(event.text.text, 0), NULL);
+ Key_Event(K_TEXT, unicode, true);
+ Key_Event(K_TEXT, unicode, false);
break;
case SDL_MOUSEMOTION:
break;
vid.support.arb_draw_buffers = false;
vid.support.arb_multitexture = false;
vid.support.arb_occlusion_query = false;
+ vid.support.arb_query_buffer_object = false;
vid.support.arb_shadow = false;
vid.support.arb_texture_compression = false; // different (vendor-specific) formats than on desktop OpenGL...
vid.support.arb_texture_cube_map = SDL_GL_ExtensionSupported("GL_OES_texture_cube_map") != 0;
// Knghtbrd: should do platform-specific extension string function here
vid_isfullscreen = false;
- if (mode->fullscreen) {
#if SDL_MAJOR_VERSION == 1
- flags |= SDL_FULLSCREEN;
+ {
+ const SDL_VideoInfo *vi = SDL_GetVideoInfo();
+ desktop_mode.width = vi->current_w;
+ desktop_mode.height = vi->current_h;
+ desktop_mode.bpp = vi->vfmt->BitsPerPixel;
+ desktop_mode.pixelheight_num = 1;
+ desktop_mode.pixelheight_denom = 1; // SDL does not provide this
+ if (mode->fullscreen) {
+ if (vid_desktopfullscreen.integer)
+ {
+ mode->width = vi->current_w;
+ mode->height = vi->current_h;
+ mode->bitsperpixel = vi->vfmt->BitsPerPixel;
+ }
+ flags |= SDL_FULLSCREEN;
+ vid_isfullscreen = true;
+ }
+ }
#else
- windowflags |= SDL_WINDOW_FULLSCREEN;
-#endif
- vid_isfullscreen = true;
+ {
+ if (mode->fullscreen) {
+ if (vid_desktopfullscreen.integer)
+ {
+ vid_mode_t *m = VID_GetDesktopMode();
+ mode->width = m->width;
+ mode->height = m->height;
+ windowflags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
+ }
+ else
+ windowflags |= SDL_WINDOW_FULLSCREEN;
+ vid_isfullscreen = true;
+ }
}
+#endif
//flags |= SDL_HWSURFACE;
SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
vid_isfullscreen = false;
if (mode->fullscreen) {
#if SDL_MAJOR_VERSION == 1
+ const SDL_VideoInfo *vi = SDL_GetVideoInfo();
+ mode->width = vi->current_w;
+ mode->height = vi->current_h;
+ mode->bitsperpixel = vi->vfmt->BitsPerPixel;
flags |= SDL_FULLSCREEN;
#else
- windowflags |= SDL_WINDOW_FULLSCREEN;
+ if (vid_desktopfullscreen.integer)
+ windowflags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
+ else
+ windowflags |= SDL_WINDOW_FULLSCREEN;
#endif
vid_isfullscreen = true;
}
}
#if SDL_MAJOR_VERSION == 1
SDL_SetAlpha(vid_softsurface, 0, 255);
+#else
+ SDL_SetSurfaceBlendMode(vid_softsurface, SDL_BLENDMODE_NONE);
#endif
vid.softpixels = (unsigned int *)vid_softsurface->pixels;
vid_usevsync = (vid_vsync.integer && !cls.timedemo);
if (vid_usingvsync != vid_usevsync)
{
+ vid_usingvsync = vid_usevsync;
if (SDL_GL_SetSwapInterval(vid_usevsync != 0) >= 0)
Con_DPrintf("Vsync %s\n", vid_usevsync ? "activated" : "deactivated");
else
}
}
+vid_mode_t *VID_GetDesktopMode(void)
+{
+#if SDL_MAJOR_VERSION != 1
+ SDL_DisplayMode mode;
+ int bpp;
+ Uint32 rmask, gmask, bmask, amask;
+ SDL_GetDesktopDisplayMode(0, &mode);
+ SDL_PixelFormatEnumToMasks(mode.format, &bpp, &rmask, &gmask, &bmask, &amask);
+ desktop_mode.width = mode.w;
+ desktop_mode.height = mode.h;
+ desktop_mode.bpp = bpp;
+ desktop_mode.refreshrate = mode.refresh_rate;
+ desktop_mode.pixelheight_num = 1;
+ desktop_mode.pixelheight_denom = 1; // SDL does not provide this
+ // TODO check whether this actually works, or whether we do still need
+ // a read-window-size-after-entering-desktop-fullscreen hack for
+ // multiscreen setups.
+#endif
+ return &desktop_mode;
+}
+
size_t VID_ListModes(vid_mode_t *modes, size_t maxcount)
{
size_t k = 0;
#if SDL_MAJOR_VERSION == 1
SDL_Rect **vidmodes;
int bpp = SDL_GetVideoInfo()->vfmt->BitsPerPixel;
+#ifdef WIN64
+ SDL_Rect **ENDRECT = (SDL_Rect**)-1LL;
+#else
+ SDL_Rect **ENDRECT = (SDL_Rect**)-1;
+#endif
- for(vidmodes = SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_HWSURFACE); vidmodes && vidmodes != (SDL_Rect**)(-1) && *vidmodes; ++vidmodes)
+ for(vidmodes = SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_HWSURFACE); vidmodes && vidmodes != ENDRECT && *vidmodes; ++vidmodes)
{
if(k >= maxcount)
break;
continue;
modes[k].width = mode.w;
modes[k].height = mode.h;
+ // FIXME bpp?
modes[k].refreshrate = mode.refresh_rate;
modes[k].pixelheight_num = 1;
- modes[k].pixelheight_num = 1;
modes[k].pixelheight_denom = 1; // SDL does not provide this
k++;
}