Skip to content

Commit

Permalink
custom cursor support
Browse files Browse the repository at this point in the history
  • Loading branch information
timbergeron committed Aug 26, 2024
1 parent c45f9e8 commit 0ff9ccd
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 0 deletions.
Binary file added Misc/qssm_pak/gfx/qssmcursor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions Quake/gl_screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,8 @@ void SCR_Init (void)
SCR_LoadPics (); //johnfitz

scr_initialized = true;

LoadCustomCursorImage (); // woods #customcursor
}

//============================================================================
Expand Down
65 changes: 65 additions & 0 deletions Quake/gl_vidsdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,7 @@ static void VID_Restart (void)
// update mouse grab
//
IN_UpdateGrabs();
LoadCustomCursorImage (); // woods #customcursor
}

/*
Expand Down Expand Up @@ -2600,6 +2601,70 @@ void VID_SetCursor(qcvm_t *vm, const char *cursorname, float hotspot[2], float c
SDL_FreeCursor(oldcursor);
}

/*
===================
LoadCustomCursorImage -- woods #customcursor
===================
*/
void LoadCustomCursorImage (void)
{
int width, height;
enum srcformat fmt;
qboolean malloced;

if (!COM_FileExists("gfx/qssmcursor.png", NULL))
{
Con_DPrintf("No cursor image found\n");
return;
}

byte* cursorData = Image_LoadImage("gfx/qssmcursor", &width, &height, &fmt, &malloced);

Con_DPrintf("Loaded cursor image: %dx%d\n", width, height);

const int baseWidth = 40, baseHeight = 40;
const int baseResolutionWidth = 1920, baseResolutionHeight = 1080;

int targetWidth = (baseWidth * vid_width.value) / baseResolutionWidth;
int targetHeight = (baseHeight * vid_height.value) / baseResolutionHeight;

targetWidth = SDL_clamp(targetWidth, 32, 128);
targetHeight = SDL_clamp(targetHeight, 32, 128);

SDL_Surface* surface = SDL_CreateRGBSurfaceWithFormatFrom(
cursorData, width, height, 32, width * 4, SDL_PIXELFORMAT_RGBA32
);

if (width != targetWidth || height != targetHeight)
{
SDL_Surface* scaledSurface = SDL_CreateRGBSurfaceWithFormat(0, targetWidth, targetHeight, 32, SDL_PIXELFORMAT_RGBA32);
if (SDL_BlitScaled(surface, NULL, scaledSurface, NULL) < 0)
{
Con_DPrintf("Failed to scale surface: %s\n", SDL_GetError());
SDL_FreeSurface(surface);
SDL_FreeSurface(scaledSurface);
if (malloced) free(cursorData);
return;
}
SDL_FreeSurface(surface);
surface = scaledSurface;
}

SDL_Cursor* cursor = SDL_CreateColorCursor(surface, 30, 2);
if (cursor)
{
SDL_SetCursor(cursor);
Con_DPrintf("Custom cursor set successfully\n");
}
else
{
Con_DPrintf("Failed to create custom cursor: %s\n", SDL_GetError());
}

SDL_FreeSurface(surface);
if (malloced) free(cursorData);
}

void VID_Minimize (void) // woods for mac command-tab
{
SDL_MinimizeWindow(draw_context);
Expand Down
Binary file modified Quake/qssm.pak
Binary file not shown.
1 change: 1 addition & 0 deletions Quake/vid.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ void VID_SetWindowCaption(const char *newcaption);
void VID_SetWindowTitle(const char* title); // github.com/andrei-drexler/ironwail (Show game summary in window title)

void VID_UpdateCursor(void);
void LoadCustomCursorImage (void); // woods #customcursor
void VID_SetCursor(qcvm_t *vm, const char *cursorname, float hotspot[2], float cursorscale);

#endif /* __VID_DEFS_H */
Expand Down

0 comments on commit 0ff9ccd

Please sign in to comment.