فهرست منبع

Fixed testshape on high DPI displays

Since the shape is set based on the pixels in the image, we want the window to have the same number of pixels.
Sam Lantinga 3 سال پیش
والد
کامیت
3bba33932f
2فایلهای تغییر یافته به همراه11 افزوده شده و 5 حذف شده
  1. 1 3
      src/video/windows/SDL_windowsshape.c
  2. 10 2
      test/testshape.c

+ 1 - 3
src/video/windows/SDL_windowsshape.c

@@ -80,9 +80,7 @@ int Win32_SetWindowShape(SDL_WindowShaper *shaper, SDL_Surface *shape, SDL_Windo
 
     if ((shaper == NULL) ||
         (shape == NULL) ||
-        ((shape->format->Amask == 0) && (shape_mode->mode != ShapeModeColorKey)) ||
-        (shape->w != shaper->window->w) ||
-        (shape->h != shaper->window->h)) {
+        ((shape->format->Amask == 0) && (shape_mode->mode != ShapeModeColorKey))) {
         return SDL_INVALID_SHAPE_ARGUMENT;
     }
 

+ 10 - 2
test/testshape.c

@@ -42,6 +42,7 @@ int main(int argc, char **argv)
     Uint8 num_pictures;
     LoadedPicture *pictures;
     int i, j;
+    const SDL_DisplayMode *mode;
     SDL_PixelFormat *format = NULL;
     SDL_Window *window;
     SDL_Renderer *renderer;
@@ -66,6 +67,12 @@ int main(int argc, char **argv)
         exit(-2);
     }
 
+    mode = SDL_GetDesktopDisplayMode(SDL_GetPrimaryDisplay());
+    if (!mode) {
+        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't get desktop display mode: %s", SDL_GetError());
+        exit(-2);
+    }
+
     num_pictures = argc - 1;
     pictures = (LoadedPicture *)SDL_malloc(sizeof(LoadedPicture) * num_pictures);
     if (pictures == NULL) {
@@ -151,7 +158,8 @@ int main(int argc, char **argv)
     button_down = 0;
     SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Changing to shaped bmp: %s", pictures[current_picture].name);
     SDL_QueryTexture(pictures[current_picture].texture, &pixelFormat, &access, &w, &h);
-    SDL_SetWindowSize(window, w, h);
+    /* We want to set the window size in pixels */
+    SDL_SetWindowSize(window, (int)SDL_ceilf(w / mode->display_scale), (int)SDL_ceilf(h / mode->display_scale));
     SDL_SetWindowShape(window, pictures[current_picture].surface, &pictures[current_picture].mode);
     while (should_exit == 0) {
         while (SDL_PollEvent(&event)) {
@@ -170,7 +178,7 @@ int main(int argc, char **argv)
                 }
                 SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Changing to shaped bmp: %s", pictures[current_picture].name);
                 SDL_QueryTexture(pictures[current_picture].texture, &pixelFormat, &access, &w, &h);
-                SDL_SetWindowSize(window, w, h);
+                SDL_SetWindowSize(window, (int)SDL_ceilf(w / mode->display_scale), (int)SDL_ceilf(h / mode->display_scale));
                 SDL_SetWindowShape(window, pictures[current_picture].surface, &pictures[current_picture].mode);
             }
             if (event.type == SDL_EVENT_QUIT) {