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