diff options
| author | 3gg <3gg@shellblade.net> | 2025-12-27 12:03:39 -0800 |
|---|---|---|
| committer | 3gg <3gg@shellblade.net> | 2025-12-27 12:03:39 -0800 |
| commit | 5a079a2d114f96d4847d1ee305d5b7c16eeec50e (patch) | |
| tree | 8926ab44f168acf787d8e19608857b3af0f82758 /contrib/SDL-3.2.8/src/video/windows/SDL_windowsshape.c | |
Initial commit
Diffstat (limited to 'contrib/SDL-3.2.8/src/video/windows/SDL_windowsshape.c')
| -rw-r--r-- | contrib/SDL-3.2.8/src/video/windows/SDL_windowsshape.c | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/contrib/SDL-3.2.8/src/video/windows/SDL_windowsshape.c b/contrib/SDL-3.2.8/src/video/windows/SDL_windowsshape.c new file mode 100644 index 0000000..db4e4a0 --- /dev/null +++ b/contrib/SDL-3.2.8/src/video/windows/SDL_windowsshape.c | |||
| @@ -0,0 +1,125 @@ | |||
| 1 | /* | ||
| 2 | Simple DirectMedia Layer | ||
| 3 | Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org> | ||
| 4 | |||
| 5 | This software is provided 'as-is', without any express or implied | ||
| 6 | warranty. In no event will the authors be held liable for any damages | ||
| 7 | arising from the use of this software. | ||
| 8 | |||
| 9 | Permission is granted to anyone to use this software for any purpose, | ||
| 10 | including commercial applications, and to alter it and redistribute it | ||
| 11 | freely, subject to the following restrictions: | ||
| 12 | |||
| 13 | 1. The origin of this software must not be misrepresented; you must not | ||
| 14 | claim that you wrote the original software. If you use this software | ||
| 15 | in a product, an acknowledgment in the product documentation would be | ||
| 16 | appreciated but is not required. | ||
| 17 | 2. Altered source versions must be plainly marked as such, and must not be | ||
| 18 | misrepresented as being the original software. | ||
| 19 | 3. This notice may not be removed or altered from any source distribution. | ||
| 20 | */ | ||
| 21 | #include "SDL_internal.h" | ||
| 22 | |||
| 23 | #if defined(SDL_VIDEO_DRIVER_WINDOWS) && !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES) | ||
| 24 | |||
| 25 | #include "SDL_windowsvideo.h" | ||
| 26 | #include "SDL_windowsshape.h" | ||
| 27 | |||
| 28 | |||
| 29 | static void AddRegion(HRGN *mask, int x1, int y1, int x2, int y2) | ||
| 30 | { | ||
| 31 | HRGN region = CreateRectRgn(x1, y1, x2, y2); | ||
| 32 | if (*mask) { | ||
| 33 | CombineRgn(*mask, *mask, region, RGN_OR); | ||
| 34 | DeleteObject(region); | ||
| 35 | } else { | ||
| 36 | *mask = region; | ||
| 37 | } | ||
| 38 | } | ||
| 39 | |||
| 40 | static HRGN GenerateSpanListRegion(SDL_Surface *shape, int offset_x, int offset_y) | ||
| 41 | { | ||
| 42 | HRGN mask = NULL; | ||
| 43 | int x, y; | ||
| 44 | int span_start = -1; | ||
| 45 | |||
| 46 | for (y = 0; y < shape->h; ++y) { | ||
| 47 | const Uint8 *a = (const Uint8 *)shape->pixels + y * shape->pitch; | ||
| 48 | for (x = 0; x < shape->w; ++x) { | ||
| 49 | if (*a == SDL_ALPHA_TRANSPARENT) { | ||
| 50 | if (span_start != -1) { | ||
| 51 | AddRegion(&mask, offset_x + span_start, offset_y + y, offset_x + x, offset_y + y + 1); | ||
| 52 | span_start = -1; | ||
| 53 | } | ||
| 54 | } else { | ||
| 55 | if (span_start == -1) { | ||
| 56 | span_start = x; | ||
| 57 | } | ||
| 58 | } | ||
| 59 | a += 4; | ||
| 60 | } | ||
| 61 | if (span_start != -1) { | ||
| 62 | // Add the final span | ||
| 63 | AddRegion(&mask, offset_x + span_start, offset_y + y, offset_x + x, offset_y + y + 1); | ||
| 64 | span_start = -1; | ||
| 65 | } | ||
| 66 | } | ||
| 67 | return mask; | ||
| 68 | } | ||
| 69 | |||
| 70 | bool WIN_UpdateWindowShape(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *shape) | ||
| 71 | { | ||
| 72 | SDL_WindowData *data = window->internal; | ||
| 73 | HRGN mask = NULL; | ||
| 74 | |||
| 75 | // Generate a set of spans for the region | ||
| 76 | if (shape) { | ||
| 77 | SDL_Surface *stretched = NULL; | ||
| 78 | RECT rect; | ||
| 79 | |||
| 80 | if (shape->w != window->w || shape->h != window->h) { | ||
| 81 | stretched = SDL_CreateSurface(window->w, window->h, SDL_PIXELFORMAT_ARGB32); | ||
| 82 | if (!stretched) { | ||
| 83 | return false; | ||
| 84 | } | ||
| 85 | if (!SDL_StretchSurface(shape, NULL, stretched, NULL, SDL_SCALEMODE_LINEAR)) { | ||
| 86 | SDL_DestroySurface(stretched); | ||
| 87 | return false; | ||
| 88 | } | ||
| 89 | shape = stretched; | ||
| 90 | } | ||
| 91 | |||
| 92 | rect.top = 0; | ||
| 93 | rect.left = 0; | ||
| 94 | rect.bottom = 0; | ||
| 95 | rect.right = 0; | ||
| 96 | if (!(SDL_GetWindowFlags(data->window) & SDL_WINDOW_BORDERLESS)) { | ||
| 97 | WIN_AdjustWindowRectForHWND(data->hwnd, &rect, 0); | ||
| 98 | } | ||
| 99 | |||
| 100 | mask = GenerateSpanListRegion(shape, -rect.left, -rect.top); | ||
| 101 | |||
| 102 | if (!(SDL_GetWindowFlags(data->window) & SDL_WINDOW_BORDERLESS)) { | ||
| 103 | // Add the window borders | ||
| 104 | // top | ||
| 105 | AddRegion(&mask, 0, 0, -rect.left + shape->w + rect.right + 1, -rect.top + 1); | ||
| 106 | // left | ||
| 107 | AddRegion(&mask, 0, -rect.top, -rect.left + 1, -rect.top + shape->h + 1); | ||
| 108 | // right | ||
| 109 | AddRegion(&mask, -rect.left + shape->w, -rect.top, -rect.left + shape->w + rect.right + 1, -rect.top + shape->h + 1); | ||
| 110 | // bottom | ||
| 111 | AddRegion(&mask, 0, -rect.top + shape->h, -rect.left + shape->w + rect.right + 1, -rect.top + shape->h + rect.bottom + 1); | ||
| 112 | } | ||
| 113 | |||
| 114 | if (stretched) { | ||
| 115 | SDL_DestroySurface(stretched); | ||
| 116 | } | ||
| 117 | } | ||
| 118 | if (!SetWindowRgn(data->hwnd, mask, TRUE)) { | ||
| 119 | DeleteObject(mask); | ||
| 120 | return WIN_SetError("SetWindowRgn failed"); | ||
| 121 | } | ||
| 122 | return true; | ||
| 123 | } | ||
| 124 | |||
| 125 | #endif // defined(SDL_VIDEO_DRIVER_WINDOWS) && !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES) | ||
