Simplify WIN_CreateHCursor (#12933)

This commit is contained in:
Dimitriy Ryazantcev
2025-05-01 18:32:12 +03:00
committed by GitHub
parent 6a0505c090
commit 3730128e33

View File

@@ -205,39 +205,30 @@ static HBITMAP CreateMaskBitmap(SDL_Surface *surface, bool is_monochrome)
static HCURSOR WIN_CreateHCursor(SDL_Surface *surface, int hot_x, int hot_y) static HCURSOR WIN_CreateHCursor(SDL_Surface *surface, int hot_x, int hot_y)
{ {
HCURSOR hcursor; HCURSOR hcursor = NULL;
ICONINFO ii;
bool is_monochrome = IsMonochromeSurface(surface); bool is_monochrome = IsMonochromeSurface(surface);
ICONINFO ii = {
SDL_zero(ii); .fIcon = FALSE,
ii.fIcon = FALSE; .xHotspot = (DWORD)hot_x,
ii.xHotspot = (DWORD)hot_x; .yHotspot = (DWORD)hot_y,
ii.yHotspot = (DWORD)hot_y; .hbmMask = CreateMaskBitmap(surface, is_monochrome),
ii.hbmMask = CreateMaskBitmap(surface, is_monochrome); .hbmColor = is_monochrome ? NULL : CreateColorBitmap(surface)
ii.hbmColor = is_monochrome ? NULL : CreateColorBitmap(surface); };
if (!ii.hbmMask || (!is_monochrome && !ii.hbmColor)) { if (!ii.hbmMask || (!is_monochrome && !ii.hbmColor)) {
SDL_SetError("Couldn't create cursor bitmaps"); SDL_SetError("Couldn't create cursor bitmaps");
if (ii.hbmMask) { goto cleanup;
DeleteObject(ii.hbmMask);
}
if (ii.hbmColor) {
DeleteObject(ii.hbmColor);
}
return NULL;
} }
hcursor = CreateIconIndirect(&ii); hcursor = CreateIconIndirect(&ii);
if (!hcursor) { if (!hcursor) {
WIN_SetError("CreateIconIndirect()"); WIN_SetError("CreateIconIndirect failed");
DeleteObject(ii.hbmMask);
if (ii.hbmColor) {
DeleteObject(ii.hbmColor);
}
return NULL;
} }
DeleteObject(ii.hbmMask); cleanup:
if (ii.hbmMask) {
DeleteObject(ii.hbmMask);
}
if (ii.hbmColor) { if (ii.hbmColor) {
DeleteObject(ii.hbmColor); DeleteObject(ii.hbmColor);
} }