rnd-20140430-1-src
[rocksndiamonds.git] / src / libgame / sdl.c
index 3d45ad0ad28d45f1c12018d2205bbb3be6f7f897..0b27fafbfec3ad71b4840a2b885d3c96282cc297 100644 (file)
@@ -255,6 +255,7 @@ void SDLInitVideoBuffer(DrawBuffer **backbuffer, DrawWindow **window,
 #endif
 
   video.window_scaling_percent = setup.window_scaling_percent;
+  video.window_scaling_quality = setup.window_scaling_quality;
 
 #if defined(TARGET_SDL2)
   int num_displays = SDL_GetNumVideoDisplays();
@@ -520,7 +521,8 @@ static SDL_Surface *SDLCreateScreen(DrawBuffer **backbuffer,
     if (sdl_renderer != NULL)
     {
       SDL_RenderSetLogicalSize(sdl_renderer, width, height);
-      SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
+      // SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
+      SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, setup.window_scaling_quality);
 
       sdl_texture = SDL_CreateTexture(sdl_renderer,
                                      SDL_PIXELFORMAT_ARGB8888,
@@ -608,6 +610,8 @@ boolean SDLSetVideoMode(DrawBuffer **backbuffer, boolean fullscreen)
 #endif
   SDL_Surface *new_surface = NULL;
 
+  SetWindowTitle();
+
   if (*backbuffer == NULL)
     *backbuffer = CreateBitmapStruct();
 
@@ -794,6 +798,7 @@ boolean SDLSetVideoMode(DrawBuffer **backbuffer, boolean fullscreen)
 
       video.fullscreen_enabled = FALSE;
       video.window_scaling_percent = setup.window_scaling_percent;
+      video.window_scaling_quality = setup.window_scaling_quality;
 
       success = TRUE;
     }
@@ -811,13 +816,26 @@ boolean SDLSetVideoMode(DrawBuffer **backbuffer, boolean fullscreen)
   {
     SDL_SysWMinfo wminfo;
     HWND hwnd;
+    boolean wminfo_success = FALSE;
 
     SDL_VERSION(&wminfo.version);
-    SDL_GetWMInfo(&wminfo);
+#if defined(TARGET_SDL2)
+    if (sdl_window)
+      wminfo_success = SDL_GetWindowWMInfo(sdl_window, &wminfo);
+#else
+    wminfo_success = (SDL_GetWMInfo(&wminfo) == 1);
+#endif
 
-    hwnd = wminfo.window;
+    if (wminfo_success)
+    {
+#if defined(TARGET_SDL2)
+      hwnd = wminfo.info.win.window;
+#else
+      hwnd = wminfo.window;
+#endif
 
-    DragAcceptFiles(hwnd, TRUE);
+      DragAcceptFiles(hwnd, TRUE);
+    }
   }
 #endif
 #endif
@@ -825,6 +843,15 @@ boolean SDLSetVideoMode(DrawBuffer **backbuffer, boolean fullscreen)
   return success;
 }
 
+void SDLSetWindowTitle()
+{
+#if defined(TARGET_SDL2)
+  SDL_SetWindowTitle(sdl_window, program.window_title);
+#else
+  SDL_WM_SetCaption(program.window_title, program.window_title);
+#endif
+}
+
 #if defined(TARGET_SDL2)
 void SDLSetWindowScaling(int window_scaling_percent)
 {
@@ -844,6 +871,32 @@ void SDLSetWindowScaling(int window_scaling_percent)
   video.window_scaling_percent = window_scaling_percent;
   video.window_width  = new_window_width;
   video.window_height = new_window_height;
+
+  SetWindowTitle();
+}
+
+void SDLSetWindowScalingQuality(char *window_scaling_quality)
+{
+  if (sdl_texture == NULL)
+    return;
+
+  SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, window_scaling_quality);
+
+  SDL_Texture *new_texture = SDL_CreateTexture(sdl_renderer,
+                                              SDL_PIXELFORMAT_ARGB8888,
+                                              SDL_TEXTUREACCESS_STREAMING,
+                                              video.width, video.height);
+
+  if (new_texture != NULL)
+  {
+    SDL_DestroyTexture(sdl_texture);
+
+    sdl_texture = new_texture;
+
+    SDLRedrawWindow();
+  }
+
+  video.window_scaling_quality = window_scaling_quality;
 }
 
 void SDLSetWindowFullscreen(boolean fullscreen)
@@ -2472,9 +2525,17 @@ void SDLHandleWindowManagerEvent(Event *event)
   SDL_SysWMEvent *syswmevent = (SDL_SysWMEvent *)event;
   SDL_SysWMmsg *syswmmsg = (SDL_SysWMmsg *)(syswmevent->msg);
 
+#if defined(TARGET_SDL2)
+  if (syswmmsg->msg.win.msg == WM_DROPFILES)
+#else
   if (syswmmsg->msg == WM_DROPFILES)
+#endif
   {
+#if defined(TARGET_SDL2)
+    HDROP hdrop = (HDROP)syswmmsg->msg.win.wParam;
+#else
     HDROP hdrop = (HDROP)syswmmsg->wParam;
+#endif
     int i, num_files;
 
     printf("::: SDL_SYSWMEVENT:\n");
@@ -2491,7 +2552,11 @@ void SDLHandleWindowManagerEvent(Event *event)
       printf("::: - '%s'\n", buffer);
     }
 
+#if defined(TARGET_SDL2)
+    DragFinish((HDROP)syswmmsg->msg.win.wParam);
+#else
     DragFinish((HDROP)syswmmsg->wParam);
+#endif
   }
 #endif
 }