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.
This commit is contained in:
Sam Lantinga committed 2023-03-02 10:15:14 -08:00
1 parent 59ca0c8b22
commit 3bba33932f
2 files changed
+11 -5

No files matched your search

+1 -3
View File
@@ -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
View File
@@ -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) {