Skip to content

Commit 0905921

Browse files
committed
Set the cursor hotspot properties when loading CUR images
1 parent be3ddf2 commit 0905921

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

CHANGES.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
3.2.2:
22
* Fixed partial alpha in ICO and CUR images
3+
* Set the cursor hotspot properties when loading CUR images
34

45
3.0.0:
56
* Added support for loading HDR AVIF images

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
1010
set(MAJOR_VERSION 3)
1111
set(MINOR_VERSION 2)
1212
set(MICRO_VERSION 1)
13-
set(SDL_REQUIRED_VERSION 3.2.0)
13+
set(SDL_REQUIRED_VERSION 3.2.5)
1414

1515
project(SDL3_image
1616
LANGUAGES C

src/IMG_bmp.c

+26-13
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434

3535
#ifdef LOAD_BMP
3636

37+
#define ICON_TYPE_ICO 1
38+
#define ICON_TYPE_CUR 2
39+
3740
/* See if an image is contained in a data source */
3841
bool IMG_isBMP(SDL_IOStream *src)
3942
{
@@ -85,12 +88,12 @@ static bool IMG_isICOCUR(SDL_IOStream *src, int type)
8588

8689
bool IMG_isICO(SDL_IOStream *src)
8790
{
88-
return IMG_isICOCUR(src, 1);
91+
return IMG_isICOCUR(src, ICON_TYPE_ICO);
8992
}
9093

9194
bool IMG_isCUR(SDL_IOStream *src)
9295
{
93-
return IMG_isICOCUR(src, 2);
96+
return IMG_isICOCUR(src, ICON_TYPE_CUR);
9497
}
9598

9699
#include <SDL3/SDL_error.h>
@@ -105,13 +108,12 @@ bool IMG_isCUR(SDL_IOStream *src)
105108
#define BI_BITFIELDS 3
106109
#endif
107110

108-
static SDL_Surface *LoadBMP_IO (SDL_IOStream *src, bool closeio)
111+
static SDL_Surface *LoadBMP_IO(SDL_IOStream *src, bool closeio)
109112
{
110113
return SDL_LoadBMP_IO(src, closeio);
111114
}
112115

113-
static SDL_Surface *
114-
LoadICOCUR_IO(SDL_IOStream * src, int type, bool closeio)
116+
static SDL_Surface *LoadICOCUR_IO(SDL_IOStream * src, int type, bool closeio)
115117
{
116118
bool was_error = true;
117119
Sint64 fp_offset = 0;
@@ -127,6 +129,8 @@ LoadICOCUR_IO(SDL_IOStream * src, int type, bool closeio)
127129
int ExpandBMP;
128130
Uint8 maxCol = 0;
129131
Uint32 icoOfs = 0;
132+
int nHotX = 0;
133+
int nHotY = 0;
130134
Uint32 palette[256];
131135

132136
/* The Win32 ICO file header (14 bytes) */
@@ -171,22 +175,20 @@ LoadICOCUR_IO(SDL_IOStream * src, int type, bool closeio)
171175
Uint8 bWidth; /* Uint8, but 0 = 256 ! */
172176
Uint8 bHeight; /* Uint8, but 0 = 256 ! */
173177
Uint8 bColorCount; /* Uint8, but 0 = 256 ! */
174-
/*
175178
Uint8 bReserved;
176179
Uint16 wPlanes;
177180
Uint16 wBitCount;
178181
Uint32 dwBytesInRes;
179-
*/
180182
Uint32 dwImageOffset;
181183
int nWidth, nHeight, nColorCount;
182184

183185
if (!SDL_ReadU8(src, &bWidth) ||
184186
!SDL_ReadU8(src, &bHeight) ||
185187
!SDL_ReadU8(src, &bColorCount) ||
186-
!SDL_ReadU8(src, NULL /* bReserved */) ||
187-
!SDL_ReadU16LE(src, NULL /* wPlanes */) ||
188-
!SDL_ReadU16LE(src, NULL /* wBitCount */) ||
189-
!SDL_ReadU32LE(src, NULL /* dwBytesInRes */) ||
188+
!SDL_ReadU8(src, &bReserved) ||
189+
!SDL_ReadU16LE(src, &wPlanes) ||
190+
!SDL_ReadU16LE(src, &wBitCount) ||
191+
!SDL_ReadU32LE(src, &dwBytesInRes) ||
190192
!SDL_ReadU32LE(src, &dwImageOffset)) {
191193
goto done;
192194
}
@@ -207,6 +209,11 @@ LoadICOCUR_IO(SDL_IOStream * src, int type, bool closeio)
207209
nColorCount = 256;
208210
}
209211

212+
if (type == ICON_TYPE_CUR) {
213+
nHotX = wPlanes;
214+
nHotY = wBitCount;
215+
}
216+
210217
//SDL_Log("%dx%d@%d - %08x\n", nWidth, nHeight, nColorCount, dwImageOffset);
211218
(void)nWidth;
212219
(void)nHeight;
@@ -417,6 +424,12 @@ LoadICOCUR_IO(SDL_IOStream * src, int type, bool closeio)
417424
}
418425
}
419426

427+
if (type == ICON_TYPE_CUR) {
428+
SDL_PropertiesID props = SDL_GetSurfaceProperties(surface);
429+
SDL_SetNumberProperty(props, SDL_PROP_SURFACE_HOTSPOT_X_NUMBER, nHotX);
430+
SDL_SetNumberProperty(props, SDL_PROP_SURFACE_HOTSPOT_Y_NUMBER, nHotY);
431+
}
432+
420433
was_error = false;
421434

422435
done:
@@ -444,13 +457,13 @@ SDL_Surface *IMG_LoadBMP_IO(SDL_IOStream *src)
444457
/* Load a ICO type image from an SDL datasource */
445458
SDL_Surface *IMG_LoadICO_IO(SDL_IOStream *src)
446459
{
447-
return LoadICOCUR_IO(src, 1, false);
460+
return LoadICOCUR_IO(src, ICON_TYPE_ICO, false);
448461
}
449462

450463
/* Load a CUR type image from an SDL datasource */
451464
SDL_Surface *IMG_LoadCUR_IO(SDL_IOStream *src)
452465
{
453-
return LoadICOCUR_IO(src, 2, false);
466+
return LoadICOCUR_IO(src, ICON_TYPE_CUR, false);
454467
}
455468

456469
#else

0 commit comments

Comments
 (0)