z_mirror/sdl-osu
git clone https://git.raiguard.me/z_mirror/sdl-osu
836a89c
trunk
1#include "util.h" 2#include <SDL3/SDL.h> 3#include <stdio.h> 4#include <stdlib.h> 5 6bool Osu_HasPrefix (const char * str ,const char * prefix ) { 7if (!str || !prefix ) { 8return false; 9 } 10 11int strLen = strlen (str ); 12int prefixLen = strlen (prefix ); 13if (strLen < prefixLen ) { 14return false; 15 } 16 17return strncmp (str ,prefix ,prefixLen )== 0 ; 18} 19 20bool Osu_HasSuffix (const char * str ,const char * suffix ) { 21if (!str || !suffix ) { 22return false; 23 } 24 25int strLen = strlen (str ); 26int suffixLen = strlen (suffix ); 27if (strLen < suffixLen ) { 28return false; 29 } 30 31return strncmp (str + strLen - suffixLen ,suffix ,suffixLen )== 0 ; 32} 33 34struct SDL_FRect Osu_GetTextureRect (struct SDL_Texture * texture ) { 35float texW ,texH ; 36SDL_GetTextureSize (texture ,& texW ,& texH ); 37SDL_assert (texW > 0 ); 38SDL_assert (texH > 0 ); 39return (SDL_FRect ){ 40 .x = 0 , 41 .y = 0 , 42 .w = texW , 43 .h = texH , 44 }; 45} 46 47void Osu_Panic (const char * title ,const char * description ) { 48char * descriptionCopy ; 49SDL_asprintf (& descriptionCopy ,"%s" ,description ); 50fprintf (stderr ,"%s: %s\n" ,title ,descriptionCopy ); 51if (!SDL_ShowSimpleMessageBox (SDL_MESSAGEBOX_ERROR ,title ,descriptionCopy ,NULL )) { 52fprintf (stderr ,"Failed to show message box: %s\n" ,SDL_GetError ()); 53 } 54free (descriptionCopy ); 55exit (EXIT_FAILURE ); 56} 57 58int Osu_Random (int min ,int max ) { 59return rand () % (max + 1 - min )+ min ; 60}