int button_status = MB_NOT_PRESSED;
boolean motion_status = FALSE;
+#if defined(TARGET_SDL2)
+boolean keyrepeat_status = TRUE;
+#endif
int redraw_mask = REDRAW_NONE;
int redraw_tiles = 0;
program.error_file = stderr;
}
+void InitExitMessageFunction(void (*exit_message_function)(char *, va_list))
+{
+ program.exit_message_function = exit_message_function;
+}
+
void InitExitFunction(void (*exit_function)(int))
{
program.exit_function = exit_function;
void InitPlatformDependentStuff(void)
{
+ // this is initialized in GetOptions(), but may already be used before
+ options.verbose = TRUE;
+
#if defined(PLATFORM_MSDOS)
_fmode = O_BINARY;
#endif
#endif
#if defined(TARGET_SDL)
- if (SDL_Init(SDL_INIT_EVENTTHREAD | SDL_INIT_NOPARACHUTE) < 0)
+#if defined(TARGET_SDL2)
+ int sdl_init_flags = SDL_INIT_EVENTS | SDL_INIT_NOPARACHUTE;
+#else
+ int sdl_init_flags = SDL_INIT_EVENTTHREAD | SDL_INIT_NOPARACHUTE;
+#endif
+
+ if (SDL_Init(sdl_init_flags) < 0)
Error(ERR_EXIT, "SDL_Init() failed: %s", SDL_GetError());
SDLNet_Init();
/* execute all pending screen drawing operations */
void FlushDisplay(void)
{
-#ifndef TARGET_SDL
+#if !defined(TARGET_SDL)
XFlush(display);
#endif
}
/* execute and wait for all pending screen drawing operations */
void SyncDisplay(void)
{
-#ifndef TARGET_SDL
+#if !defined(TARGET_SDL)
XSync(display, FALSE);
#endif
}
void KeyboardAutoRepeatOn(void)
{
#if defined(TARGET_SDL)
+#if defined(TARGET_SDL2)
+ keyrepeat_status = TRUE;
+#else
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY / 2,
SDL_DEFAULT_REPEAT_INTERVAL / 2);
SDL_EnableUNICODE(1);
+#endif
#else
if (display)
XAutoRepeatOn(display);
void KeyboardAutoRepeatOff(void)
{
#if defined(TARGET_SDL)
+#if defined(TARGET_SDL2)
+ keyrepeat_status = FALSE;
+#else
SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL);
SDL_EnableUNICODE(0);
+#endif
#else
if (display)
XAutoRepeatOff(display);
if (old_bitmap->surface_masked)
SDL_FreeSurface(old_bitmap->surface_masked);
- SDL_SetColorKey(tmp_surface_1, SDL_SRCCOLORKEY,
+ SDL_SetColorKey(tmp_surface_1, SET_TRANSPARENT_PIXEL,
SDL_MapRGB(tmp_surface_1->format, 0x00, 0x00, 0x00));
if ((old_bitmap->surface_masked = SDL_DisplayFormat(tmp_surface_1)) ==NULL)
Error(ERR_EXIT, "SDL_DisplayFormat() failed");
- SDL_SetColorKey(tmp_surface_1, 0, 0); /* reset transparent pixel */
+ SDL_SetColorKey(tmp_surface_1, UNSET_TRANSPARENT_PIXEL, 0);
#endif
}
#endif
if (old_bitmap->surface_masked)
SDL_FreeSurface(old_bitmap->surface_masked);
- SDL_SetColorKey(old_surface, SDL_SRCCOLORKEY,
+ SDL_SetColorKey(old_surface, SET_TRANSPARENT_PIXEL,
SDL_MapRGB(old_surface->format, 0x00, 0x00, 0x00));
if ((old_bitmap->surface_masked = SDL_DisplayFormat(old_surface)) ==NULL)
Error(ERR_EXIT, "SDL_DisplayFormat() failed");
- SDL_SetColorKey(old_surface, 0, 0); /* reset transparent pixel */
+ SDL_SetColorKey(old_surface, UNSET_TRANSPARENT_PIXEL, 0);
#endif
}
#endif
void InitEventFilter(EventFilter filter_function)
{
-#if defined(TARGET_SDL)
/* set event filter to filter out certain events */
+#if defined(TARGET_SDL)
+#if defined(TARGET_SDL2)
+ SDL_SetEventFilter(filter_function, NULL);
+#else
SDL_SetEventFilter(filter_function);
#endif
+#endif
}
boolean PendingEvent(void)
void PeekEvent(Event *event)
{
#if defined(TARGET_SDL)
+#if defined(TARGET_SDL2)
+ SDL_PeepEvents(event, 1, SDL_PEEKEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT);
+#else
SDL_PeepEvents(event, 1, SDL_PEEKEVENT, SDL_ALLEVENTS);
+#endif
#else
XPeekEvent(display, event);
#endif
Key GetEventKey(KeyEvent *event, boolean with_modifiers)
{
#if defined(TARGET_SDL)
+#if defined(TARGET_SDL2)
+ /* key up/down events in SDL2 do not return text characters anymore */
+ return event->keysym.sym;
+#else
#if 0
printf("unicode == '%d', sym == '%d', mod == '0x%04x'\n",
else
return event->keysym.sym;
+#endif
#else
#if 0