rnd-20000908-1-src
[rocksndiamonds.git] / src / system.c
index 3c1823572889f7cc36416aaf537e798d4ba0feb5..dd329f1cd6a194276f2223268cce99d15cda19b8 100644 (file)
@@ -13,6 +13,8 @@
 ***********************************************************/
 
 #include "main.h"
+#include "misc.h"
+#include "tools.h"
 
 inline void ClearRectangle(Bitmap bitmap, int x, int y, int width, int height)
 {
@@ -84,7 +86,7 @@ inline void DrawSimpleWhiteLine(Bitmap bitmap, int from_x, int from_y,
 }
 
 /* execute all pending screen drawing operations */
-inline void FlushDisplay()
+inline void FlushDisplay(void)
 {
 #ifndef USE_SDL_LIBRARY
   XFlush(display);
@@ -92,14 +94,14 @@ inline void FlushDisplay()
 }
 
 /* execute and wait for all pending screen drawing operations */
-inline void SyncDisplay()
+inline void SyncDisplay(void)
 {
 #ifndef USE_SDL_LIBRARY
   XSync(display, FALSE);
 #endif
 }
 
-inline void KeyboardAutoRepeatOn()
+inline void KeyboardAutoRepeatOn(void)
 {
 #ifdef USE_SDL_LIBRARY
   SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY / 2,
@@ -110,7 +112,7 @@ inline void KeyboardAutoRepeatOn()
 #endif
 }
 
-inline void KeyboardAutoRepeatOff()
+inline void KeyboardAutoRepeatOff(void)
 {
 #ifdef USE_SDL_LIBRARY
   SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL);
@@ -120,24 +122,24 @@ inline void KeyboardAutoRepeatOff()
 #endif
 }
 
-inline boolean QueryPointer(DrawWindow window, int *win_x, int *win_y)
+inline boolean PointerInWindow(DrawWindow window)
 {
 #ifdef USE_SDL_LIBRARY
-  SDL_GetMouseState(win_x, win_y);
   return TRUE;
 #else
   DrawWindow root, child;
   int root_x, root_y;
   unsigned int mask;
+  int win_x, win_y;
 
   /* if XQueryPointer() returns False, the pointer
      is not on the same screen as the specified window */
   return XQueryPointer(display, window, &root, &child, &root_x, &root_y,
-                      win_x, win_y, &mask);
+                      &win_x, &win_y, &mask);
 #endif
 }
 
-inline boolean PendingEvent()
+inline boolean PendingEvent(void)
 {
 #ifdef USE_SDL_LIBRARY
   return (SDL_PollEvent(NULL) ? TRUE : FALSE);
@@ -158,11 +160,24 @@ inline void NextEvent(Event *event)
 inline Key GetEventKey(KeyEvent *event, boolean with_modifiers)
 {
 #ifdef USE_SDL_LIBRARY
+#if 0
+  printf("unicode == '%d', sym == '%d', mod == '0x%04x'\n",
+        (int)event->keysym.unicode,
+        (int)event->keysym.sym,
+        (int)SDL_GetModState());
+#endif
+
   if (with_modifiers && event->keysym.unicode != 0)
     return event->keysym.unicode;
   else
     return event->keysym.sym;
 #else
+#if 0
+  printf("with modifiers == '0x%04x', without modifiers == '0x%04x'\n",
+        (int)XLookupKeysym(event, event->state),
+        (int)XLookupKeysym(event, 0));
+#endif
+
   if (with_modifiers)
     return XLookupKeysym(event, event->state);
   else
@@ -170,7 +185,90 @@ inline Key GetEventKey(KeyEvent *event, boolean with_modifiers)
 #endif
 }
 
-inline void dummy()
+inline boolean SetVideoMode(void)
+{
+  boolean success = TRUE;
+
+#ifdef USE_SDL_LIBRARY
+  if (setup.fullscreen && !fullscreen_enabled && fullscreen_available)
+  {
+    /* switch display to fullscreen mode, if available */
+    DrawWindow window_old = window;
+    DrawWindow window_new;
+
+    if ((window_new = SDL_SetVideoMode(WIN_XSIZE, WIN_YSIZE, WIN_SDL_DEPTH,
+                                      SDL_HWSURFACE|SDL_FULLSCREEN))
+       == NULL)
+    {
+      /* switching display to fullscreen mode failed */
+      Error(ERR_WARN, "SDL_SetVideoMode() failed: %s", SDL_GetError());
+
+      /* do not try it again */
+      fullscreen_available = FALSE;
+      success = FALSE;
+    }
+    else
+    {
+      if (window_old)
+       SDL_FreeSurface(window_old);
+      window = window_new;
+
+      fullscreen_enabled = TRUE;
+      success = TRUE;
+    }
+  }
+
+  if ((!setup.fullscreen && fullscreen_enabled) || !window)
+  {
+    /* switch display to window mode */
+    DrawWindow window_old = window;
+    DrawWindow window_new;
+
+    if ((window_new = SDL_SetVideoMode(WIN_XSIZE, WIN_YSIZE, WIN_SDL_DEPTH,
+                                      SDL_HWSURFACE))
+       == NULL)
+    {
+      /* switching display to window mode failed -- should not happen */
+      Error(ERR_WARN, "SDL_SetVideoMode() failed: %s", SDL_GetError());
+
+      success = FALSE;
+    }
+    else
+    {
+      if (window_old)
+       SDL_FreeSurface(window_old);
+      window = window_new;
+
+      fullscreen_enabled = FALSE;
+      success = TRUE;
+    }
+  }
+#else
+  if (setup.fullscreen && fullscreen_available)
+  {
+    Error(ERR_WARN, "fullscreen not available in X11 version");
+
+    /* display error message only once */
+    fullscreen_available = FALSE;
+
+    success = FALSE;
+  }
+#endif
+
+  return success;
+}
+
+inline void ChangeVideoModeIfNeeded(void)
+{
+#ifdef USE_SDL_LIBRARY
+  if ((setup.fullscreen && !fullscreen_enabled && fullscreen_available) ||
+      (!setup.fullscreen && fullscreen_enabled))
+    SetVideoMode();
+  SetDrawtoField(DRAW_BACKBUFFER);
+#endif
+}
+
+inline void dummy(void)
 {
 #ifdef USE_SDL_LIBRARY
 #else