SDL_utils_c.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. // This is included in SDL_internal.h
  19. //#include "SDL_internal.h"
  20. #ifndef SDL_utils_h_
  21. #define SDL_utils_h_
  22. // Common utility functions that aren't in the public API
  23. // Return the smallest power of 2 greater than or equal to 'x'
  24. extern int SDL_powerof2(int x);
  25. extern Uint32 SDL_CalculateGCD(Uint32 a, Uint32 b);
  26. extern void SDL_CalculateFraction(float x, int *numerator, int *denominator);
  27. extern bool SDL_startswith(const char *string, const char *prefix);
  28. extern bool SDL_endswith(const char *string, const char *suffix);
  29. /** Convert URI to a local filename, stripping the "file://"
  30. * preamble and hostname if present, and writes the result
  31. * to the dst buffer. Since URI-encoded characters take
  32. * three times the space of normal characters, src and dst
  33. * can safely point to the same buffer for in situ conversion.
  34. *
  35. * Returns the number of decoded bytes that wound up in
  36. * the destination buffer, excluding the terminating NULL byte.
  37. *
  38. * On error, -1 is returned.
  39. */
  40. extern int SDL_URIToLocal(const char *src, char *dst);
  41. typedef enum
  42. {
  43. SDL_OBJECT_TYPE_UNKNOWN,
  44. SDL_OBJECT_TYPE_WINDOW,
  45. SDL_OBJECT_TYPE_RENDERER,
  46. SDL_OBJECT_TYPE_TEXTURE,
  47. SDL_OBJECT_TYPE_JOYSTICK,
  48. SDL_OBJECT_TYPE_GAMEPAD,
  49. SDL_OBJECT_TYPE_HAPTIC,
  50. SDL_OBJECT_TYPE_SENSOR,
  51. SDL_OBJECT_TYPE_HIDAPI_DEVICE,
  52. SDL_OBJECT_TYPE_HIDAPI_JOYSTICK,
  53. SDL_OBJECT_TYPE_THREAD,
  54. SDL_OBJECT_TYPE_TRAY,
  55. } SDL_ObjectType;
  56. extern Uint32 SDL_GetNextObjectID(void);
  57. extern void SDL_SetObjectValid(void *object, SDL_ObjectType type, bool valid);
  58. extern bool SDL_ObjectValid(void *object, SDL_ObjectType type);
  59. extern int SDL_GetObjects(SDL_ObjectType type, void **objects, int count);
  60. extern void SDL_SetObjectsInvalid(void);
  61. extern const char *SDL_GetPersistentString(const char *string);
  62. extern char *SDL_CreateDeviceName(Uint16 vendor, Uint16 product, const char *vendor_name, const char *product_name, const char *default_name);
  63. #endif // SDL_utils_h_