SDL_utils_c.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
  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. #include "SDL_internal.h"
  19. #ifndef SDL_utils_h_
  20. #define SDL_utils_h_
  21. // Common utility functions that aren't in the public API
  22. // Return the smallest power of 2 greater than or equal to 'x'
  23. extern int SDL_powerof2(int x);
  24. extern Uint32 SDL_CalculateGCD(Uint32 a, Uint32 b);
  25. extern void SDL_CalculateFraction(float x, int *numerator, int *denominator);
  26. extern bool SDL_startswith(const char *string, const char *prefix);
  27. extern bool SDL_endswith(const char *string, const char *suffix);
  28. /** Convert URI to a local filename, stripping the "file://"
  29. * preamble and hostname if present, and writes the result
  30. * to the dst buffer. Since URI-encoded characters take
  31. * three times the space of normal characters, src and dst
  32. * can safely point to the same buffer for in situ conversion.
  33. *
  34. * Returns the number of decoded bytes that wound up in
  35. * the destination buffer, excluding the terminating NULL byte.
  36. *
  37. * On error, -1 is returned.
  38. */
  39. extern int SDL_URIToLocal(const char *src, char *dst);
  40. typedef enum SDL_InitStatus
  41. {
  42. SDL_INIT_STATUS_UNINITIALIZED,
  43. SDL_INIT_STATUS_INITIALIZING,
  44. SDL_INIT_STATUS_INITIALIZED,
  45. SDL_INIT_STATUS_UNINITIALIZING
  46. } SDL_InitStatus;
  47. typedef struct SDL_InitState
  48. {
  49. SDL_AtomicInt status;
  50. SDL_ThreadID thread;
  51. } SDL_InitState;
  52. extern bool SDL_ShouldInit(SDL_InitState *state);
  53. extern bool SDL_ShouldQuit(SDL_InitState *state);
  54. extern void SDL_SetInitialized(SDL_InitState *state, bool initialized);
  55. typedef enum
  56. {
  57. SDL_OBJECT_TYPE_UNKNOWN,
  58. SDL_OBJECT_TYPE_WINDOW,
  59. SDL_OBJECT_TYPE_RENDERER,
  60. SDL_OBJECT_TYPE_TEXTURE,
  61. SDL_OBJECT_TYPE_JOYSTICK,
  62. SDL_OBJECT_TYPE_GAMEPAD,
  63. SDL_OBJECT_TYPE_HAPTIC,
  64. SDL_OBJECT_TYPE_SENSOR,
  65. SDL_OBJECT_TYPE_HIDAPI_DEVICE,
  66. SDL_OBJECT_TYPE_HIDAPI_JOYSTICK,
  67. } SDL_ObjectType;
  68. extern Uint32 SDL_GetNextObjectID(void);
  69. extern void SDL_SetObjectValid(void *object, SDL_ObjectType type, bool valid);
  70. extern bool SDL_ObjectValid(void *object, SDL_ObjectType type);
  71. extern void SDL_SetObjectsInvalid(void);
  72. extern const char *SDL_GetPersistentString(const char *string);
  73. #endif // SDL_utils_h_