diff --git a/.gitattributes b/.gitattributes index 881b5c55..d8705098 100644 --- a/.gitattributes +++ b/.gitattributes @@ -27,3 +27,5 @@ libs/zwin32/bin/x64/libdxcompiler.so.3.7 filter=lfs diff=lfs merge=lfs -text libs/zsdl/libs/macos/Frameworks/SDL2.framework/SDL2 filter=lfs diff=lfs merge=lfs -text libs/zsdl/libs/macos/Frameworks/SDL2.framework/Versions/A/SDL2 filter=lfs diff=lfs merge=lfs -text .dds filter=lfs diff=lfs merge=lfs -text +libs/zsdl/libs/macos/Frameworks/SDL2_ttf.framework/SDL2_ttf filter=lfs diff=lfs merge=lfs -text +libs/zsdl/libs/macos/Frameworks/SDL2_ttf.framework/Versions/A/SDL2_ttf filter=lfs diff=lfs merge=lfs -text diff --git a/libs/zsdl/build.zig b/libs/zsdl/build.zig index 6fac2614..185e8519 100644 --- a/libs/zsdl/build.zig +++ b/libs/zsdl/build.zig @@ -4,6 +4,7 @@ const assert = std.debug.assert; pub const Package = struct { zsdl: *std.Build.Module, install: *std.Build.Step, + ttf: bool, pub fn link(pkg: Package, exe: *std.Build.CompileStep) void { exe.linkLibC(); @@ -22,6 +23,10 @@ pub const Package = struct { exe.addLibraryPath(thisDir() ++ "/libs/x86_64-windows-gnu/lib"); exe.linkSystemLibraryName("SDL2"); exe.linkSystemLibraryName("SDL2main"); + + if (pkg.ttf) { + exe.linkSystemLibraryName("SDL2_ttf"); + } }, .linux => { assert(target.cpu.arch.isX86()); @@ -30,11 +35,19 @@ pub const Package = struct { exe.addLibraryPath(thisDir() ++ "/libs/x86_64-linux-gnu/lib"); exe.linkSystemLibraryName("SDL2-2.0"); exe.addRPath("$ORIGIN"); + + if (pkg.ttf) { + exe.linkSystemLibraryName("SDL2_ttf-2.0"); + } }, .macos => { exe.addFrameworkPath(thisDir() ++ "/libs/macos/Frameworks"); exe.linkFramework("SDL2"); exe.addRPath("@executable_path/Frameworks"); + + if (pkg.ttf) { + exe.linkFramework("SDL2_ttf"); + } }, else => unreachable, } @@ -45,7 +58,9 @@ pub fn package( b: *std.Build, target: std.zig.CrossTarget, _: std.builtin.Mode, - _: struct {}, + args: struct { + ttf: bool = false, + }, ) Package { const zsdl = b.createModule(.{ .source_file = .{ .path = thisDir() ++ "/src/zsdl.zig" }, @@ -61,6 +76,14 @@ pub fn package( "bin/SDL2.dll", ).step, ); + if (args.ttf) { + install_step.dependOn( + &b.addInstallFile( + .{ .path = thisDir() ++ "/libs/x86_64-windows-gnu/bin/SDL2_ttf.dll" }, + "bin/SDL2_ttf.dll", + ).step, + ); + } } else if (target.isLinux()) { install_step.dependOn( &b.addInstallFile( @@ -68,18 +91,37 @@ pub fn package( "bin/libSDL2-2.0.so.0", ).step, ); + if (args.ttf) { + install_step.dependOn( + &b.addInstallFile( + .{ .path = thisDir() ++ "/libs/x86_64-linux-gnu/lib/libSDL2_ttf-2.0.so" }, + "bin/libSDL2_ttf-2.0.so.0", + ).step, + ); + } } else if (target.isDarwin()) { - const install_dir_step = b.addInstallDirectory(.{ - .source_dir = .{ .path = thisDir() ++ "/libs/macos/Frameworks/SDL2.framework" }, - .install_dir = .{ .custom = "" }, - .install_subdir = "bin/Frameworks/SDL2.framework", - }); - install_step.dependOn(&install_dir_step.step); + install_step.dependOn( + &b.addInstallDirectory(.{ + .source_dir = .{ .path = thisDir() ++ "/libs/macos/Frameworks/SDL2.framework" }, + .install_dir = .{ .custom = "" }, + .install_subdir = "bin/Frameworks/SDL2.framework", + }).step, + ); + if (args.ttf) { + install_step.dependOn( + &b.addInstallDirectory(.{ + .source_dir = .{ .path = thisDir() ++ "/libs/macos/Frameworks/SDL2_ttf.framework" }, + .install_dir = .{ .custom = "" }, + .install_subdir = "bin/Frameworks/SDL2_ttf.framework", + }).step, + ); + } } else unreachable; return .{ .zsdl = zsdl, .install = install_step, + .ttf = args.ttf, }; } diff --git a/libs/zsdl/libs/macos/Frameworks/SDL2_ttf.framework/Headers b/libs/zsdl/libs/macos/Frameworks/SDL2_ttf.framework/Headers new file mode 120000 index 00000000..a177d2a6 --- /dev/null +++ b/libs/zsdl/libs/macos/Frameworks/SDL2_ttf.framework/Headers @@ -0,0 +1 @@ +Versions/Current/Headers \ No newline at end of file diff --git a/libs/zsdl/libs/macos/Frameworks/SDL2_ttf.framework/Resources b/libs/zsdl/libs/macos/Frameworks/SDL2_ttf.framework/Resources new file mode 120000 index 00000000..953ee36f --- /dev/null +++ b/libs/zsdl/libs/macos/Frameworks/SDL2_ttf.framework/Resources @@ -0,0 +1 @@ +Versions/Current/Resources \ No newline at end of file diff --git a/libs/zsdl/libs/macos/Frameworks/SDL2_ttf.framework/SDL2_ttf b/libs/zsdl/libs/macos/Frameworks/SDL2_ttf.framework/SDL2_ttf new file mode 120000 index 00000000..bda75a39 --- /dev/null +++ b/libs/zsdl/libs/macos/Frameworks/SDL2_ttf.framework/SDL2_ttf @@ -0,0 +1 @@ +Versions/Current/SDL2_ttf \ No newline at end of file diff --git a/libs/zsdl/libs/macos/Frameworks/SDL2_ttf.framework/Versions/A/Headers/SDL_ttf.h b/libs/zsdl/libs/macos/Frameworks/SDL2_ttf.framework/Versions/A/Headers/SDL_ttf.h new file mode 100644 index 00000000..7f8dea24 --- /dev/null +++ b/libs/zsdl/libs/macos/Frameworks/SDL2_ttf.framework/Versions/A/Headers/SDL_ttf.h @@ -0,0 +1,2316 @@ +/* + SDL_ttf: A companion library to SDL for working with TrueType (tm) fonts + Copyright (C) 2001-2023 Sam Lantinga + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + + +/** + * \file SDL_ttf.h + * + * Header file for SDL_ttf library + * + * This library is a wrapper around the excellent FreeType 2.0 library, + * available at: https://www.freetype.org/ + * + * Note: In many places, SDL_ttf will say "glyph" when it means "code point." + * Unicode is hard, we learn as we go, and we apologize for adding to the + * confusion. + * + */ +#ifndef SDL_TTF_H_ +#define SDL_TTF_H_ + +#include +#include + +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Printable format: "%d.%d.%d", MAJOR, MINOR, PATCHLEVEL + */ +#define SDL_TTF_MAJOR_VERSION 2 +#define SDL_TTF_MINOR_VERSION 20 +#define SDL_TTF_PATCHLEVEL 2 + +/** + * This macro can be used to fill a version structure with the compile-time + * version of the SDL_ttf library. + */ +#define SDL_TTF_VERSION(X) \ +{ \ + (X)->major = SDL_TTF_MAJOR_VERSION; \ + (X)->minor = SDL_TTF_MINOR_VERSION; \ + (X)->patch = SDL_TTF_PATCHLEVEL; \ +} + +/** + * Backwards compatibility + */ +#define TTF_MAJOR_VERSION SDL_TTF_MAJOR_VERSION +#define TTF_MINOR_VERSION SDL_TTF_MINOR_VERSION +#define TTF_PATCHLEVEL SDL_TTF_PATCHLEVEL +#define TTF_VERSION(X) SDL_TTF_VERSION(X) + +#if SDL_TTF_MAJOR_VERSION < 3 && SDL_MAJOR_VERSION < 3 +/** + * This is the version number macro for the current SDL_ttf version. + * + * In versions higher than 2.9.0, the minor version overflows into + * the thousands digit: for example, 2.23.0 is encoded as 4300. + * This macro will not be available in SDL 3.x or SDL_ttf 3.x. + * + * \deprecated, use SDL_TTF_VERSION_ATLEAST or SDL_TTF_VERSION instead. + */ +#define SDL_TTF_COMPILEDVERSION \ + SDL_VERSIONNUM(SDL_TTF_MAJOR_VERSION, SDL_TTF_MINOR_VERSION, SDL_TTF_PATCHLEVEL) +#endif /* SDL_TTF_MAJOR_VERSION < 3 && SDL_MAJOR_VERSION < 3 */ + +/** + * This macro will evaluate to true if compiled with SDL_ttf at least X.Y.Z. + */ +#define SDL_TTF_VERSION_ATLEAST(X, Y, Z) \ + ((SDL_TTF_MAJOR_VERSION >= X) && \ + (SDL_TTF_MAJOR_VERSION > X || SDL_TTF_MINOR_VERSION >= Y) && \ + (SDL_TTF_MAJOR_VERSION > X || SDL_TTF_MINOR_VERSION > Y || SDL_TTF_PATCHLEVEL >= Z)) + +/* Make sure this is defined (only available in newer SDL versions) */ +#ifndef SDL_DEPRECATED +#define SDL_DEPRECATED +#endif + +/** + * Query the version of SDL_ttf that the program is linked against. + * + * This function gets the version of the dynamically linked SDL_ttf library. + * This is separate from the SDL_TTF_VERSION() macro, which tells you what + * version of the SDL_ttf headers you compiled against. + * + * This returns static internal data; do not free or modify it! + * + * \returns a pointer to the version information. + * + * \since This function is available since SDL_ttf 2.0.12. + */ +extern DECLSPEC const SDL_version * SDLCALL TTF_Linked_Version(void); + +/** + * Query the version of the FreeType library in use. + * + * TTF_Init() should be called before calling this function. + * + * \param major to be filled in with the major version number. Can be NULL. + * \param minor to be filled in with the minor version number. Can be NULL. + * \param patch to be filled in with the param version number. Can be NULL. + * + * \since This function is available since SDL_ttf 2.0.18. + * + * \sa TTF_Init + */ +extern DECLSPEC void SDLCALL TTF_GetFreeTypeVersion(int *major, int *minor, int *patch); + +/** + * Query the version of the HarfBuzz library in use. + * + * If HarfBuzz is not available, the version reported is 0.0.0. + * + * \param major to be filled in with the major version number. Can be NULL. + * \param minor to be filled in with the minor version number. Can be NULL. + * \param patch to be filled in with the param version number. Can be NULL. + * + * \since This function is available since SDL_ttf 2.0.18. + */ +extern DECLSPEC void SDLCALL TTF_GetHarfBuzzVersion(int *major, int *minor, int *patch); + +/** + * ZERO WIDTH NO-BREAKSPACE (Unicode byte order mark) + */ +#define UNICODE_BOM_NATIVE 0xFEFF +#define UNICODE_BOM_SWAPPED 0xFFFE + +/** + * Tell SDL_ttf whether UNICODE text is generally byteswapped. + * + * A UNICODE BOM character in a string will override this setting for the + * remainder of that string. + * + * \param swapped boolean to indicate whether text is byteswapped + * + * \since This function is available since SDL_ttf 2.0.12. + */ +extern DECLSPEC void SDLCALL TTF_ByteSwappedUNICODE(SDL_bool swapped); + +/** + * The internal structure containing font information. Opaque data! + */ +typedef struct _TTF_Font TTF_Font; + +/** + * Initialize SDL_ttf. + * + * You must successfully call this function before it is safe to call any + * other function in this library, with one exception: a human-readable error + * message can be retrieved from TTF_GetError() if this function fails. + * + * SDL must be initialized before calls to functions in this library, because + * this library uses utility functions from the SDL library. + * + * It is safe to call this more than once; the library keeps a counter of init + * calls, and decrements it on each call to TTF_Quit, so you must pair your + * init and quit calls. + * + * \returns 0 on success, -1 on error. + * + * \since This function is available since SDL_ttf 2.0.12. + * + * \sa TTF_Quit + */ +extern DECLSPEC int SDLCALL TTF_Init(void); + +/** + * Create a font from a file, using a specified point size. + * + * Some .fon fonts will have several sizes embedded in the file, so the point + * size becomes the index of choosing which size. If the value is too high, + * the last indexed size will be the default. + * + * When done with the returned TTF_Font, use TTF_CloseFont() to dispose of it. + * + * \param file path to font file. + * \param ptsize point size to use for the newly-opened font. + * \returns a valid TTF_Font, or NULL on error. + * + * \since This function is available since SDL_ttf 2.0.12. + * + * \sa TTF_CloseFont + */ +extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFont(const char *file, int ptsize); + +/** + * Create a font from a file, using a specified face index. + * + * Some .fon fonts will have several sizes embedded in the file, so the point + * size becomes the index of choosing which size. If the value is too high, + * the last indexed size will be the default. + * + * Some fonts have multiple "faces" included. The index specifies which face + * to use from the font file. Font files with only one face should specify + * zero for the index. + * + * When done with the returned TTF_Font, use TTF_CloseFont() to dispose of it. + * + * \param file path to font file. + * \param ptsize point size to use for the newly-opened font. + * \param index index of the face in the font file. + * \returns a valid TTF_Font, or NULL on error. + * + * \since This function is available since SDL_ttf 2.0.12. + * + * \sa TTF_CloseFont + */ +extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFontIndex(const char *file, int ptsize, long index); + +/** + * Create a font from an SDL_RWops, using a specified point size. + * + * Some .fon fonts will have several sizes embedded in the file, so the point + * size becomes the index of choosing which size. If the value is too high, + * the last indexed size will be the default. + * + * If `freesrc` is non-zero, the RWops will be closed before returning, + * whether this function succeeds or not. SDL_ttf reads everything it needs + * from the RWops during this call in any case. + * + * When done with the returned TTF_Font, use TTF_CloseFont() to dispose of it. + * + * \param src an SDL_RWops to provide a font file's data. + * \param freesrc non-zero to close the RWops before returning, zero to leave + * it open. + * \param ptsize point size to use for the newly-opened font. + * \returns a valid TTF_Font, or NULL on error. + * + * \since This function is available since SDL_ttf 2.0.12. + * + * \sa TTF_CloseFont + */ +extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFontRW(SDL_RWops *src, int freesrc, int ptsize); + +/** + * Create a font from an SDL_RWops, using a specified face index. + * + * Some .fon fonts will have several sizes embedded in the file, so the point + * size becomes the index of choosing which size. If the value is too high, + * the last indexed size will be the default. + * + * If `freesrc` is non-zero, the RWops will be closed before returning, + * whether this function succeeds or not. SDL_ttf reads everything it needs + * from the RWops during this call in any case. + * + * Some fonts have multiple "faces" included. The index specifies which face + * to use from the font file. Font files with only one face should specify + * zero for the index. + * + * When done with the returned TTF_Font, use TTF_CloseFont() to dispose of it. + * + * \param src an SDL_RWops to provide a font file's data. + * \param freesrc non-zero to close the RWops before returning, zero to leave + * it open. + * \param ptsize point size to use for the newly-opened font. + * \param index index of the face in the font file. + * \returns a valid TTF_Font, or NULL on error. + * + * \since This function is available since SDL_ttf 2.0.12. + * + * \sa TTF_CloseFont + */ +extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFontIndexRW(SDL_RWops *src, int freesrc, int ptsize, long index); + +/** + * Create a font from a file, using target resolutions (in DPI). + * + * DPI scaling only applies to scalable fonts (e.g. TrueType). + * + * Some .fon fonts will have several sizes embedded in the file, so the point + * size becomes the index of choosing which size. If the value is too high, + * the last indexed size will be the default. + * + * When done with the returned TTF_Font, use TTF_CloseFont() to dispose of it. + * + * \param file path to font file. + * \param ptsize point size to use for the newly-opened font. + * \param hdpi the target horizontal DPI. + * \param vdpi the target vertical DPI. + * \returns a valid TTF_Font, or NULL on error. + * + * \since This function is available since SDL_ttf 2.0.18. + * + * \sa TTF_CloseFont + */ +extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFontDPI(const char *file, int ptsize, unsigned int hdpi, unsigned int vdpi); + +/** + * Create a font from a file, using target resolutions (in DPI). + * + * DPI scaling only applies to scalable fonts (e.g. TrueType). + * + * Some .fon fonts will have several sizes embedded in the file, so the point + * size becomes the index of choosing which size. If the value is too high, + * the last indexed size will be the default. + * + * Some fonts have multiple "faces" included. The index specifies which face + * to use from the font file. Font files with only one face should specify + * zero for the index. + * + * When done with the returned TTF_Font, use TTF_CloseFont() to dispose of it. + * + * \param file path to font file. + * \param ptsize point size to use for the newly-opened font. + * \param index index of the face in the font file. + * \param hdpi the target horizontal DPI. + * \param vdpi the target vertical DPI. + * \returns a valid TTF_Font, or NULL on error. + * + * \since This function is available since SDL_ttf 2.0.18. + * + * \sa TTF_CloseFont + */ +extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFontIndexDPI(const char *file, int ptsize, long index, unsigned int hdpi, unsigned int vdpi); + +/** + * Opens a font from an SDL_RWops with target resolutions (in DPI). + * + * DPI scaling only applies to scalable fonts (e.g. TrueType). + * + * Some .fon fonts will have several sizes embedded in the file, so the point + * size becomes the index of choosing which size. If the value is too high, + * the last indexed size will be the default. + * + * If `freesrc` is non-zero, the RWops will be closed before returning, + * whether this function succeeds or not. SDL_ttf reads everything it needs + * from the RWops during this call in any case. + * + * When done with the returned TTF_Font, use TTF_CloseFont() to dispose of it. + * + * \param src an SDL_RWops to provide a font file's data. + * \param freesrc non-zero to close the RWops before returning, zero to leave + * it open. + * \param ptsize point size to use for the newly-opened font. + * \param hdpi the target horizontal DPI. + * \param vdpi the target vertical DPI. + * \returns a valid TTF_Font, or NULL on error. + * + * \since This function is available since SDL_ttf 2.0.18. + * + * \sa TTF_CloseFont + */ +extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFontDPIRW(SDL_RWops *src, int freesrc, int ptsize, unsigned int hdpi, unsigned int vdpi); + +/** + * Opens a font from an SDL_RWops with target resolutions (in DPI). + * + * DPI scaling only applies to scalable fonts (e.g. TrueType). + * + * Some .fon fonts will have several sizes embedded in the file, so the point + * size becomes the index of choosing which size. If the value is too high, + * the last indexed size will be the default. + * + * If `freesrc` is non-zero, the RWops will be closed before returning, + * whether this function succeeds or not. SDL_ttf reads everything it needs + * from the RWops during this call in any case. + * + * Some fonts have multiple "faces" included. The index specifies which face + * to use from the font file. Font files with only one face should specify + * zero for the index. + * + * When done with the returned TTF_Font, use TTF_CloseFont() to dispose of it. + * + * \param src an SDL_RWops to provide a font file's data. + * \param freesrc non-zero to close the RWops before returning, zero to leave + * it open. + * \param ptsize point size to use for the newly-opened font. + * \param index index of the face in the font file. + * \param hdpi the target horizontal DPI. + * \param vdpi the target vertical DPI. + * \returns a valid TTF_Font, or NULL on error. + * + * \since This function is available since SDL_ttf 2.0.18. + * + * \sa TTF_CloseFont + */ +extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFontIndexDPIRW(SDL_RWops *src, int freesrc, int ptsize, long index, unsigned int hdpi, unsigned int vdpi); + +/** + * Set a font's size dynamically. + * + * This clears already-generated glyphs, if any, from the cache. + * + * \param font the font to resize. + * \param ptsize the new point size. + * \returns 0 if successful, -1 on error + * + * \since This function is available since SDL_ttf 2.0.18. + */ +extern DECLSPEC int SDLCALL TTF_SetFontSize(TTF_Font *font, int ptsize); + +/** + * Set font size dynamically with target resolutions (in DPI). + * + * This clears already-generated glyphs, if any, from the cache. + * + * \param font the font to resize. + * \param ptsize the new point size. + * \param hdpi the target horizontal DPI. + * \param vdpi the target vertical DPI. + * \returns 0 if successful, -1 on error. + * + * \since This function is available since SDL_ttf 2.0.18. + */ +extern DECLSPEC int SDLCALL TTF_SetFontSizeDPI(TTF_Font *font, int ptsize, unsigned int hdpi, unsigned int vdpi); + +/** + * Font style flags + */ +#define TTF_STYLE_NORMAL 0x00 +#define TTF_STYLE_BOLD 0x01 +#define TTF_STYLE_ITALIC 0x02 +#define TTF_STYLE_UNDERLINE 0x04 +#define TTF_STYLE_STRIKETHROUGH 0x08 + +/** + * Query a font's current style. + * + * The font styles are a set of bit flags, OR'd together: + * + * - `TTF_STYLE_NORMAL` (is zero) + * - `TTF_STYLE_BOLD` + * - `TTF_STYLE_ITALIC` + * - `TTF_STYLE_UNDERLINE` + * - `TTF_STYLE_STRIKETHROUGH` + * + * \param font the font to query. + * \returns the current font style, as a set of bit flags. + * + * \since This function is available since SDL_ttf 2.0.12. + * + * \sa TTF_SetFontStyle + */ +extern DECLSPEC int SDLCALL TTF_GetFontStyle(const TTF_Font *font); + +/** + * Set a font's current style. + * + * Setting the style clears already-generated glyphs, if any, from the cache. + * + * The font styles are a set of bit flags, OR'd together: + * + * - `TTF_STYLE_NORMAL` (is zero) + * - `TTF_STYLE_BOLD` + * - `TTF_STYLE_ITALIC` + * - `TTF_STYLE_UNDERLINE` + * - `TTF_STYLE_STRIKETHROUGH` + * + * \param font the font to set a new style on. + * \param style the new style values to set, OR'd together. + * + * \since This function is available since SDL_ttf 2.0.12. + * + * \sa TTF_GetFontStyle + */ +extern DECLSPEC void SDLCALL TTF_SetFontStyle(TTF_Font *font, int style); + +/** + * Query a font's current outline. + * + * \param font the font to query. + * \returns the font's current outline value. + * + * \since This function is available since SDL_ttf 2.0.12. + * + * \sa TTF_SetFontOutline + */ +extern DECLSPEC int SDLCALL TTF_GetFontOutline(const TTF_Font *font); + +/** + * Set a font's current outline. + * + * \param font the font to set a new outline on. + * \param outline positive outline value, 0 to default. + * + * \since This function is available since SDL_ttf 2.0.12. + * + * \sa TTF_GetFontOutline + */ +extern DECLSPEC void SDLCALL TTF_SetFontOutline(TTF_Font *font, int outline); + + +/** + * Hinting flags + */ +#define TTF_HINTING_NORMAL 0 +#define TTF_HINTING_LIGHT 1 +#define TTF_HINTING_MONO 2 +#define TTF_HINTING_NONE 3 +#define TTF_HINTING_LIGHT_SUBPIXEL 4 + +/** + * Query a font's current FreeType hinter setting. + * + * The hinter setting is a single value: + * + * - `TTF_HINTING_NORMAL` + * - `TTF_HINTING_LIGHT` + * - `TTF_HINTING_MONO` + * - `TTF_HINTING_NONE` + * - `TTF_HINTING_LIGHT_SUBPIXEL` (available in SDL_ttf 2.0.18 and later) + * + * \param font the font to query. + * \returns the font's current hinter value. + * + * \since This function is available since SDL_ttf 2.0.12. + * + * \sa TTF_SetFontHinting + */ +extern DECLSPEC int SDLCALL TTF_GetFontHinting(const TTF_Font *font); + +/** + * Set a font's current hinter setting. + * + * Setting it clears already-generated glyphs, if any, from the cache. + * + * The hinter setting is a single value: + * + * - `TTF_HINTING_NORMAL` + * - `TTF_HINTING_LIGHT` + * - `TTF_HINTING_MONO` + * - `TTF_HINTING_NONE` + * - `TTF_HINTING_LIGHT_SUBPIXEL` (available in SDL_ttf 2.0.18 and later) + * + * \param font the font to set a new hinter setting on. + * \param hinting the new hinter setting. + * + * \since This function is available since SDL_ttf 2.0.12. + * + * \sa TTF_GetFontHinting + */ +extern DECLSPEC void SDLCALL TTF_SetFontHinting(TTF_Font *font, int hinting); + +/** + * Special layout option for rendering wrapped text + */ +#define TTF_WRAPPED_ALIGN_LEFT 0 +#define TTF_WRAPPED_ALIGN_CENTER 1 +#define TTF_WRAPPED_ALIGN_RIGHT 2 + +/** + * Query a font's current wrap alignment option. + * + * The wrap alignment option can be one of the following: + * + * - `TTF_WRAPPED_ALIGN_LEFT` + * - `TTF_WRAPPED_ALIGN_CENTER` + * - `TTF_WRAPPED_ALIGN_RIGHT` + * + * \param font the font to query. + * \returns the font's current wrap alignment option. + * + * \since This function is available since SDL_ttf 2.20.0. + * + * \sa TTF_SetFontWrappedAlign + */ +extern DECLSPEC int SDLCALL TTF_GetFontWrappedAlign(const TTF_Font *font); + +/** + * Set a font's current wrap alignment option. + * + * The wrap alignment option can be one of the following: + * + * - `TTF_WRAPPED_ALIGN_LEFT` + * - `TTF_WRAPPED_ALIGN_CENTER` + * - `TTF_WRAPPED_ALIGN_RIGHT` + * + * \param font the font to set a new wrap alignment option on. + * \param align the new wrap alignment option. + * + * \since This function is available since SDL_ttf 2.20.0. + * + * \sa TTF_GetFontWrappedAlign + */ +extern DECLSPEC void SDLCALL TTF_SetFontWrappedAlign(TTF_Font *font, int align); + +/** + * Query the total height of a font. + * + * This is usually equal to point size. + * + * \param font the font to query. + * \returns the font's height. + * + * \since This function is available since SDL_ttf 2.0.12. + */ +extern DECLSPEC int SDLCALL TTF_FontHeight(const TTF_Font *font); + +/** + * Query the offset from the baseline to the top of a font. + * + * This is a positive value, relative to the baseline. + * + * \param font the font to query. + * \returns the font's ascent. + * + * \since This function is available since SDL_ttf 2.0.12. + */ +extern DECLSPEC int SDLCALL TTF_FontAscent(const TTF_Font *font); + +/** + * Query the offset from the baseline to the bottom of a font. + * + * This is a negative value, relative to the baseline. + * + * \param font the font to query. + * \returns the font's descent. + * + * \since This function is available since SDL_ttf 2.0.12. + */ +extern DECLSPEC int SDLCALL TTF_FontDescent(const TTF_Font *font); + +/** + * Query the recommended spacing between lines of text for a font. + * + * \param font the font to query. + * \returns the font's recommended spacing. + * + * \since This function is available since SDL_ttf 2.0.12. + */ +extern DECLSPEC int SDLCALL TTF_FontLineSkip(const TTF_Font *font); + +/** + * Query whether or not kerning is allowed for a font. + * + * \param font the font to query. + * \returns non-zero if kerning is enabled, zero otherwise. + * + * \since This function is available since SDL_ttf 2.0.12. + */ +extern DECLSPEC int SDLCALL TTF_GetFontKerning(const TTF_Font *font); + +/** + * Set if kerning is allowed for a font. + * + * Newly-opened fonts default to allowing kerning. This is generally a good + * policy unless you have a strong reason to disable it, as it tends to + * produce better rendering (with kerning disabled, some fonts might render + * the word `kerning` as something that looks like `keming` for example). + * + * \param font the font to set kerning on. + * \param allowed non-zero to allow kerning, zero to disallow. + * + * \since This function is available since SDL_ttf 2.0.12. + */ +extern DECLSPEC void SDLCALL TTF_SetFontKerning(TTF_Font *font, int allowed); + +/** + * Query the number of faces of a font. + * + * \param font the font to query. + * \returns the number of FreeType font faces. + * + * \since This function is available since SDL_ttf 2.0.12. + */ +extern DECLSPEC long SDLCALL TTF_FontFaces(const TTF_Font *font); + +/** + * Query whether a font is fixed-width. + * + * A "fixed-width" font means all glyphs are the same width across; a + * lowercase 'i' will be the same size across as a capital 'W', for example. + * This is common for terminals and text editors, and other apps that treat + * text as a grid. Most other things (WYSIWYG word processors, web pages, etc) + * are more likely to not be fixed-width in most cases. + * + * \param font the font to query. + * \returns non-zero if fixed-width, zero if not. + * + * \since This function is available since SDL_ttf 2.0.12. + */ +extern DECLSPEC int SDLCALL TTF_FontFaceIsFixedWidth(const TTF_Font *font); + +/** + * Query a font's family name. + * + * This string is dictated by the contents of the font file. + * + * Note that the returned string is to internal storage, and should not be + * modifed or free'd by the caller. The string becomes invalid, with the rest + * of the font, when `font` is handed to TTF_CloseFont(). + * + * \param font the font to query. + * \returns the font's family name. + * + * \since This function is available since SDL_ttf 2.0.12. + */ +extern DECLSPEC const char * SDLCALL TTF_FontFaceFamilyName(const TTF_Font *font); + +/** + * Query a font's style name. + * + * This string is dictated by the contents of the font file. + * + * Note that the returned string is to internal storage, and should not be + * modifed or free'd by the caller. The string becomes invalid, with the rest + * of the font, when `font` is handed to TTF_CloseFont(). + * + * \param font the font to query. + * \returns the font's style name. + * + * \since This function is available since SDL_ttf 2.0.12. + */ +extern DECLSPEC const char * SDLCALL TTF_FontFaceStyleName(const TTF_Font *font); + +/** + * Check whether a glyph is provided by the font for a 16-bit codepoint. + * + * Note that this version of the function takes a 16-bit character code, which + * covers the Basic Multilingual Plane, but is insufficient to cover the + * entire set of possible Unicode values, including emoji glyphs. You should + * use TTF_GlyphIsProvided32() instead, which offers the same functionality + * but takes a 32-bit codepoint instead. + * + * The only reason to use this function is that it was available since the + * beginning of time, more or less. + * + * \param font the font to query. + * \param ch the character code to check. + * \returns non-zero if font provides a glyph for this character, zero if not. + * + * \since This function is available since SDL_ttf 2.0.12. + * + * \sa TTF_GlyphIsProvided32 + */ +extern DECLSPEC int SDLCALL TTF_GlyphIsProvided(TTF_Font *font, Uint16 ch); + +/** + * Check whether a glyph is provided by the font for a 32-bit codepoint. + * + * This is the same as TTF_GlyphIsProvided(), but takes a 32-bit character + * instead of 16-bit, and thus can query a larger range. If you are sure + * you'll have an SDL_ttf that's version 2.0.18 or newer, there's no reason + * not to use this function exclusively. + * + * \param font the font to query. + * \param ch the character code to check. + * \returns non-zero if font provides a glyph for this character, zero if not. + * + * \since This function is available since SDL_ttf 2.0.18. + */ +extern DECLSPEC int SDLCALL TTF_GlyphIsProvided32(TTF_Font *font, Uint32 ch); + +/** + * Query the metrics (dimensions) of a font's 16-bit glyph. + * + * To understand what these metrics mean, here is a useful link: + * + * https://freetype.sourceforge.net/freetype2/docs/tutorial/step2.html + * + * Note that this version of the function takes a 16-bit character code, which + * covers the Basic Multilingual Plane, but is insufficient to cover the + * entire set of possible Unicode values, including emoji glyphs. You should + * use TTF_GlyphMetrics32() instead, which offers the same functionality but + * takes a 32-bit codepoint instead. + * + * The only reason to use this function is that it was available since the + * beginning of time, more or less. + * + * \param font the font to query. + * \param ch the character code to check. + * + * \since This function is available since SDL_ttf 2.0.12. + * + * \sa TTF_GlyphMetrics32 + */ +extern DECLSPEC int SDLCALL TTF_GlyphMetrics(TTF_Font *font, Uint16 ch, + int *minx, int *maxx, + int *miny, int *maxy, int *advance); + +/** + * Query the metrics (dimensions) of a font's 32-bit glyph. + * + * To understand what these metrics mean, here is a useful link: + * + * https://freetype.sourceforge.net/freetype2/docs/tutorial/step2.html + * + * This is the same as TTF_GlyphMetrics(), but takes a 32-bit character + * instead of 16-bit, and thus can query a larger range. If you are sure + * you'll have an SDL_ttf that's version 2.0.18 or newer, there's no reason + * not to use this function exclusively. + * + * \param font the font to query. + * \param ch the character code to check. + * + * \since This function is available since SDL_ttf 2.0.18. + */ +extern DECLSPEC int SDLCALL TTF_GlyphMetrics32(TTF_Font *font, Uint32 ch, + int *minx, int *maxx, + int *miny, int *maxy, int *advance); + +/** + * Calculate the dimensions of a rendered string of Latin1 text. + * + * This will report the width and height, in pixels, of the space that the + * specified string will take to fully render. + * + * This does not need to render the string to do this calculation. + * + * You almost certainly want TTF_SizeUTF8() unless you're sure you have a + * 1-byte Latin1 encoding. US ASCII characters will work with either function, + * but most other Unicode characters packed into a `const char *` will need + * UTF-8. + * + * \param font the font to query. + * \param text text to calculate, in Latin1 encoding. + * \param w will be filled with width, in pixels, on return. + * \param h will be filled with height, in pixels, on return. + * \returns 0 if successful, -1 on error. + * + * \since This function is available since SDL_ttf 2.0.12. + * + * \sa TTF_SizeUTF8 + * \sa TTF_SizeUNICODE + */ +extern DECLSPEC int SDLCALL TTF_SizeText(TTF_Font *font, const char *text, int *w, int *h); + +/** + * Calculate the dimensions of a rendered string of UTF-8 text. + * + * This will report the width and height, in pixels, of the space that the + * specified string will take to fully render. + * + * This does not need to render the string to do this calculation. + * + * \param font the font to query. + * \param text text to calculate, in Latin1 encoding. + * \param w will be filled with width, in pixels, on return. + * \param h will be filled with height, in pixels, on return. + * \returns 0 if successful, -1 on error. + * + * \since This function is available since SDL_ttf 2.0.12. + * + * \sa TTF_SizeUNICODE + */ +extern DECLSPEC int SDLCALL TTF_SizeUTF8(TTF_Font *font, const char *text, int *w, int *h); + +/** + * Calculate the dimensions of a rendered string of UCS-2 text. + * + * This will report the width and height, in pixels, of the space that the + * specified string will take to fully render. + * + * This does not need to render the string to do this calculation. + * + * Please note that this function is named "Unicode" but currently expects + * UCS-2 encoding (16 bits per codepoint). This does not give you access to + * large Unicode values, such as emoji glyphs. These codepoints are accessible + * through the UTF-8 version of this function. + * + * \param font the font to query. + * \param text text to calculate, in UCS-2 encoding. + * \param w will be filled with width, in pixels, on return. + * \param h will be filled with height, in pixels, on return. + * \returns 0 if successful, -1 on error. + * + * \since This function is available since SDL_ttf 2.0.12. + * + * \sa TTF_SizeUTF8 + */ +extern DECLSPEC int SDLCALL TTF_SizeUNICODE(TTF_Font *font, const Uint16 *text, int *w, int *h); + +/** + * Calculate how much of a Latin1 string will fit in a given width. + * + * This reports the number of characters that can be rendered before reaching + * `measure_width`. + * + * This does not need to render the string to do this calculation. + * + * You almost certainly want TTF_MeasureUTF8() unless you're sure you have a + * 1-byte Latin1 encoding. US ASCII characters will work with either function, + * but most other Unicode characters packed into a `const char *` will need + * UTF-8. + * + * \param font the font to query. + * \param text text to calculate, in Latin1 encoding. + * \param measure_width maximum width, in pixels, available for the string. + * \param count on return, filled with number of characters that can be + * rendered. + * \param extent on return, filled with latest calculated width. + * \returns 0 if successful, -1 on error. + * + * \since This function is available since SDL_ttf 2.0.18. + * + * \sa TTF_MeasureText + * \sa TTF_MeasureUTF8 + * \sa TTF_MeasureUNICODE + */ +extern DECLSPEC int SDLCALL TTF_MeasureText(TTF_Font *font, const char *text, int measure_width, int *extent, int *count); + +/** + * Calculate how much of a UTF-8 string will fit in a given width. + * + * This reports the number of characters that can be rendered before reaching + * `measure_width`. + * + * This does not need to render the string to do this calculation. + * + * \param font the font to query. + * \param text text to calculate, in UTF-8 encoding. + * \param measure_width maximum width, in pixels, available for the string. + * \param count on return, filled with number of characters that can be + * rendered. + * \param extent on return, filled with latest calculated width. + * \returns 0 if successful, -1 on error. + * + * \since This function is available since SDL_ttf 2.0.18. + * + * \sa TTF_MeasureText + * \sa TTF_MeasureUTF8 + * \sa TTF_MeasureUNICODE + */ +extern DECLSPEC int SDLCALL TTF_MeasureUTF8(TTF_Font *font, const char *text, int measure_width, int *extent, int *count); + +/** + * Calculate how much of a UCS-2 string will fit in a given width. + * + * This reports the number of characters that can be rendered before reaching + * `measure_width`. + * + * This does not need to render the string to do this calculation. + * + * Please note that this function is named "Unicode" but currently expects + * UCS-2 encoding (16 bits per codepoint). This does not give you access to + * large Unicode values, such as emoji glyphs. These codepoints are accessible + * through the UTF-8 version of this function. + * + * \param font the font to query. + * \param text text to calculate, in UCS-2 encoding. + * \param measure_width maximum width, in pixels, available for the string. + * \param count on return, filled with number of characters that can be + * rendered. + * \param extent on return, filled with latest calculated width. + * \returns 0 if successful, -1 on error. + * + * \since This function is available since SDL_ttf 2.0.18. + * + * \sa TTF_MeasureText + * \sa TTF_MeasureUTF8 + * \sa TTF_MeasureUNICODE + */ +extern DECLSPEC int SDLCALL TTF_MeasureUNICODE(TTF_Font *font, const Uint16 *text, int measure_width, int *extent, int *count); + +/** + * Render Latin1 text at fast quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the colorkey, giving a transparent background. The 1 pixel + * will be set to the text color. + * + * This will not word-wrap the string; you'll get a surface with a single line + * of text, as long as the string requires. You can use + * TTF_RenderText_Solid_Wrapped() instead if you need to wrap the output to + * multiple lines. + * + * This will not wrap on newline characters. + * + * You almost certainly want TTF_RenderUTF8_Solid() unless you're sure you + * have a 1-byte Latin1 encoding. US ASCII characters will work with either + * function, but most other Unicode characters packed into a `const char *` + * will need UTF-8. + * + * You can render at other quality levels with TTF_RenderText_Shaded, + * TTF_RenderText_Blended, and TTF_RenderText_LCD. + * + * \param font the font to render with. + * \param text text to render, in Latin1 encoding. + * \param fg the foreground color for the text. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \since This function is available since SDL_ttf 2.0.12. + * + * \sa TTF_RenderUTF8_Solid + * \sa TTF_RenderUNICODE_Solid + */ +extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Solid(TTF_Font *font, + const char *text, SDL_Color fg); + +/** + * Render UTF-8 text at fast quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the colorkey, giving a transparent background. The 1 pixel + * will be set to the text color. + * + * This will not word-wrap the string; you'll get a surface with a single line + * of text, as long as the string requires. You can use + * TTF_RenderUTF8_Solid_Wrapped() instead if you need to wrap the output to + * multiple lines. + * + * This will not wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderUTF8_Shaded, + * TTF_RenderUTF8_Blended, and TTF_RenderUTF8_LCD. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param fg the foreground color for the text. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \since This function is available since SDL_ttf 2.0.12. + * + * \sa TTF_RenderUTF8_Shaded + * \sa TTF_RenderUTF8_Blended + * \sa TTF_RenderUTF8_LCD + */ +extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUTF8_Solid(TTF_Font *font, + const char *text, SDL_Color fg); + +/** + * Render UCS-2 text at fast quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the colorkey, giving a transparent background. The 1 pixel + * will be set to the text color. + * + * This will not word-wrap the string; you'll get a surface with a single line + * of text, as long as the string requires. You can use + * TTF_RenderUNICODE_Solid_Wrapped() instead if you need to wrap the output to + * multiple lines. + * + * This will not wrap on newline characters. + * + * Please note that this function is named "Unicode" but currently expects + * UCS-2 encoding (16 bits per codepoint). This does not give you access to + * large Unicode values, such as emoji glyphs. These codepoints are accessible + * through the UTF-8 version of this function. + * + * You can render at other quality levels with TTF_RenderUNICODE_Shaded, + * TTF_RenderUNICODE_Blended, and TTF_RenderUNICODE_LCD. + * + * \param font the font to render with. + * \param text text to render, in UCS-2 encoding. + * \param fg the foreground color for the text. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \since This function is available since SDL_ttf 2.0.12. + * + * \sa TTF_RenderUTF8_Solid + */ +extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUNICODE_Solid(TTF_Font *font, + const Uint16 *text, SDL_Color fg); + +/** + * Render word-wrapped Latin1 text at fast quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the colorkey, giving a transparent background. The 1 pixel + * will be set to the text color. + * + * Text is wrapped to multiple lines on line endings and on word boundaries if + * it extends beyond `wrapLength` in pixels. + * + * If wrapLength is 0, this function will only wrap on newline characters. + * + * You almost certainly want TTF_RenderUTF8_Solid_Wrapped() unless you're sure + * you have a 1-byte Latin1 encoding. US ASCII characters will work with + * either function, but most other Unicode characters packed into a `const + * char *` will need UTF-8. + * + * You can render at other quality levels with TTF_RenderText_Shaded_Wrapped, + * TTF_RenderText_Blended_Wrapped, and TTF_RenderText_LCD_Wrapped. + * + * \param font the font to render with. + * \param text text to render, in Latin1 encoding. + * \param fg the foreground color for the text. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \since This function is available since SDL_ttf 2.0.18. + * + * \sa TTF_RenderUTF8_Solid_Wrapped + * \sa TTF_RenderUNICODE_Solid_Wrapped + */ +extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Solid_Wrapped(TTF_Font *font, + const char *text, SDL_Color fg, Uint32 wrapLength); + +/** + * Render word-wrapped UTF-8 text at fast quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the colorkey, giving a transparent background. The 1 pixel + * will be set to the text color. + * + * Text is wrapped to multiple lines on line endings and on word boundaries if + * it extends beyond `wrapLength` in pixels. + * + * If wrapLength is 0, this function will only wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderUTF8_Shaded_Wrapped, + * TTF_RenderUTF8_Blended_Wrapped, and TTF_RenderUTF8_LCD_Wrapped. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param fg the foreground color for the text. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \since This function is available since SDL_ttf 2.0.18. + * + * \sa TTF_RenderUTF8_Shaded_Wrapped + * \sa TTF_RenderUTF8_Blended_Wrapped + * \sa TTF_RenderUTF8_LCD_Wrapped + */ +extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUTF8_Solid_Wrapped(TTF_Font *font, + const char *text, SDL_Color fg, Uint32 wrapLength); + +/** + * Render word-wrapped UCS-2 text at fast quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the colorkey, giving a transparent background. The 1 pixel + * will be set to the text color. + * + * Text is wrapped to multiple lines on line endings and on word boundaries if + * it extends beyond `wrapLength` in pixels. + * + * If wrapLength is 0, this function will only wrap on newline characters. + * + * Please note that this function is named "Unicode" but currently expects + * UCS-2 encoding (16 bits per codepoint). This does not give you access to + * large Unicode values, such as emoji glyphs. These codepoints are accessible + * through the UTF-8 version of this function. + * + * You can render at other quality levels with + * TTF_RenderUNICODE_Shaded_Wrapped, TTF_RenderUNICODE_Blended_Wrapped, and + * TTF_RenderUNICODE_LCD_Wrapped. + * + * \param font the font to render with. + * \param text text to render, in UCS-2 encoding. + * \param fg the foreground color for the text. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \since This function is available since SDL_ttf 2.0.18. + * + * \sa TTF_RenderUTF8_Solid_Wrapped + */ +extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUNICODE_Solid_Wrapped(TTF_Font *font, + const Uint16 *text, SDL_Color fg, Uint32 wrapLength); + +/** + * Render a single 16-bit glyph at fast quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the colorkey, giving a transparent background. The 1 pixel + * will be set to the text color. + * + * The glyph is rendered without any padding or centering in the X direction, + * and aligned normally in the Y direction. + * + * Note that this version of the function takes a 16-bit character code, which + * covers the Basic Multilingual Plane, but is insufficient to cover the + * entire set of possible Unicode values, including emoji glyphs. You should + * use TTF_RenderGlyph32_Solid() instead, which offers the same functionality + * but takes a 32-bit codepoint instead. + * + * The only reason to use this function is that it was available since the + * beginning of time, more or less. + * + * You can render at other quality levels with TTF_RenderGlyph_Shaded, + * TTF_RenderGlyph_Blended, and TTF_RenderGlyph_LCD. + * + * \param font the font to render with. + * \param ch the character to render. + * \param fg the foreground color for the text. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \since This function is available since SDL_ttf 2.0.12. + * + * \sa TTF_RenderGlyph32_Solid + */ +extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph_Solid(TTF_Font *font, + Uint16 ch, SDL_Color fg); + +/** + * Render a single 32-bit glyph at fast quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the colorkey, giving a transparent background. The 1 pixel + * will be set to the text color. + * + * The glyph is rendered without any padding or centering in the X direction, + * and aligned normally in the Y direction. + * + * This is the same as TTF_RenderGlyph_Solid(), but takes a 32-bit character + * instead of 16-bit, and thus can render a larger range. If you are sure + * you'll have an SDL_ttf that's version 2.0.18 or newer, there's no reason + * not to use this function exclusively. + * + * You can render at other quality levels with TTF_RenderGlyph32_Shaded, + * TTF_RenderGlyph32_Blended, and TTF_RenderGlyph32_LCD. + * + * \param font the font to render with. + * \param ch the character to render. + * \param fg the foreground color for the text. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \since This function is available since SDL_ttf 2.0.18. + * + * \sa TTF_RenderGlyph32_Shaded + * \sa TTF_RenderGlyph32_Blended + * \sa TTF_RenderGlyph32_LCD + */ +extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph32_Solid(TTF_Font *font, + Uint32 ch, SDL_Color fg); + +/** + * Render Latin1 text at high quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the specified background color, while other pixels have + * varying degrees of the foreground color. This function returns the new + * surface, or NULL if there was an error. + * + * This will not word-wrap the string; you'll get a surface with a single line + * of text, as long as the string requires. You can use + * TTF_RenderText_Shaded_Wrapped() instead if you need to wrap the output to + * multiple lines. + * + * This will not wrap on newline characters. + * + * You almost certainly want TTF_RenderUTF8_Shaded() unless you're sure you + * have a 1-byte Latin1 encoding. US ASCII characters will work with either + * function, but most other Unicode characters packed into a `const char *` + * will need UTF-8. + * + * You can render at other quality levels with TTF_RenderText_Solid, + * TTF_RenderText_Blended, and TTF_RenderText_LCD. + * + * \param font the font to render with. + * \param text text to render, in Latin1 encoding. + * \param fg the foreground color for the text. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \since This function is available since SDL_ttf 2.0.12. + * + * \sa TTF_RenderUTF8_Shaded + * \sa TTF_RenderUNICODE_Shaded + */ +extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Shaded(TTF_Font *font, + const char *text, SDL_Color fg, SDL_Color bg); + +/** + * Render UTF-8 text at high quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the specified background color, while other pixels have + * varying degrees of the foreground color. This function returns the new + * surface, or NULL if there was an error. + * + * This will not word-wrap the string; you'll get a surface with a single line + * of text, as long as the string requires. You can use + * TTF_RenderUTF8_Shaded_Wrapped() instead if you need to wrap the output to + * multiple lines. + * + * This will not wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderUTF8_Solid, + * TTF_RenderUTF8_Blended, and TTF_RenderUTF8_LCD. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param fg the foreground color for the text. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \since This function is available since SDL_ttf 2.0.12. + * + * \sa TTF_RenderUNICODE_Shaded + */ +extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUTF8_Shaded(TTF_Font *font, + const char *text, SDL_Color fg, SDL_Color bg); + +/** + * Render UCS-2 text at high quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the specified background color, while other pixels have + * varying degrees of the foreground color. This function returns the new + * surface, or NULL if there was an error. + * + * This will not word-wrap the string; you'll get a surface with a single line + * of text, as long as the string requires. You can use + * TTF_RenderUNICODE_Shaded_Wrapped() instead if you need to wrap the output + * to multiple lines. + * + * This will not wrap on newline characters. + * + * Please note that this function is named "Unicode" but currently expects + * UCS-2 encoding (16 bits per codepoint). This does not give you access to + * large Unicode values, such as emoji glyphs. These codepoints are accessible + * through the UTF-8 version of this function. + * + * You can render at other quality levels with TTF_RenderUNICODE_Solid, + * TTF_RenderUNICODE_Blended, and TTF_RenderUNICODE_LCD. + * + * \param font the font to render with. + * \param text text to render, in UCS-2 encoding. + * \param fg the foreground color for the text. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \since This function is available since SDL_ttf 2.0.12. + * + * \sa TTF_RenderUTF8_Shaded + */ +extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUNICODE_Shaded(TTF_Font *font, + const Uint16 *text, SDL_Color fg, SDL_Color bg); + +/** + * Render word-wrapped Latin1 text at high quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the specified background color, while other pixels have + * varying degrees of the foreground color. This function returns the new + * surface, or NULL if there was an error. + * + * Text is wrapped to multiple lines on line endings and on word boundaries if + * it extends beyond `wrapLength` in pixels. + * + * If wrapLength is 0, this function will only wrap on newline characters. + * + * You almost certainly want TTF_RenderUTF8_Shaded_Wrapped() unless you're + * sure you have a 1-byte Latin1 encoding. US ASCII characters will work with + * either function, but most other Unicode characters packed into a `const + * char *` will need UTF-8. + * + * You can render at other quality levels with TTF_RenderText_Solid_Wrapped, + * TTF_RenderText_Blended_Wrapped, and TTF_RenderText_LCD_Wrapped. + * + * \param font the font to render with. + * \param text text to render, in Latin1 encoding. + * \param fg the foreground color for the text. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \since This function is available since SDL_ttf 2.0.18. + * + * \sa TTF_RenderUTF8_Shaded_Wrapped + * \sa TTF_RenderUNICODE_Shaded_Wrapped + */ +extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Shaded_Wrapped(TTF_Font *font, + const char *text, SDL_Color fg, SDL_Color bg, Uint32 wrapLength); + +/** + * Render word-wrapped UTF-8 text at high quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the specified background color, while other pixels have + * varying degrees of the foreground color. This function returns the new + * surface, or NULL if there was an error. + * + * Text is wrapped to multiple lines on line endings and on word boundaries if + * it extends beyond `wrapLength` in pixels. + * + * If wrapLength is 0, this function will only wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderUTF8_Solid_Wrapped, + * TTF_RenderUTF8_Blended_Wrapped, and TTF_RenderUTF8_LCD_Wrapped. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param fg the foreground color for the text. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \since This function is available since SDL_ttf 2.0.18. + * + * \sa TTF_RenderUTF8_Solid_Wrapped + * \sa TTF_RenderUTF8_Blended_Wrapped + * \sa TTF_RenderUTF8_LCD_Wrapped + */ +extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUTF8_Shaded_Wrapped(TTF_Font *font, + const char *text, SDL_Color fg, SDL_Color bg, Uint32 wrapLength); + +/** + * Render word-wrapped UCS-2 text at high quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the specified background color, while other pixels have + * varying degrees of the foreground color. This function returns the new + * surface, or NULL if there was an error. + * + * Text is wrapped to multiple lines on line endings and on word boundaries if + * it extends beyond `wrapLength` in pixels. + * + * If wrapLength is 0, this function will only wrap on newline characters. + * + * Please note that this function is named "Unicode" but currently expects + * UCS-2 encoding (16 bits per codepoint). This does not give you access to + * large Unicode values, such as emoji glyphs. These codepoints are accessible + * through the UTF-8 version of this function. + * + * You can render at other quality levels with + * TTF_RenderUNICODE_Solid_Wrapped, TTF_RenderUNICODE_Blended_Wrapped, and + * TTF_RenderUNICODE_LCD_Wrapped. + * + * \param font the font to render with. + * \param text text to render, in UCS-2 encoding. + * \param fg the foreground color for the text. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \since This function is available since SDL_ttf 2.0.18. + * + * \sa TTF_RenderUTF8_Shaded_Wrapped + */ +extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUNICODE_Shaded_Wrapped(TTF_Font *font, + const Uint16 *text, SDL_Color fg, SDL_Color bg, Uint32 wrapLength); + +/** + * Render a single 16-bit glyph at high quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the specified background color, while other pixels have + * varying degrees of the foreground color. This function returns the new + * surface, or NULL if there was an error. + * + * The glyph is rendered without any padding or centering in the X direction, + * and aligned normally in the Y direction. + * + * Note that this version of the function takes a 16-bit character code, which + * covers the Basic Multilingual Plane, but is insufficient to cover the + * entire set of possible Unicode values, including emoji glyphs. You should + * use TTF_RenderGlyph32_Shaded() instead, which offers the same functionality + * but takes a 32-bit codepoint instead. + * + * The only reason to use this function is that it was available since the + * beginning of time, more or less. + * + * You can render at other quality levels with TTF_RenderGlyph_Solid, + * TTF_RenderGlyph_Blended, and TTF_RenderGlyph_LCD. + * + * \param font the font to render with. + * \param ch the character to render. + * \param fg the foreground color for the text. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \since This function is available since SDL_ttf 2.0.12. + * + * \sa TTF_RenderGlyph32_Shaded + */ +extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph_Shaded(TTF_Font *font, + Uint16 ch, SDL_Color fg, SDL_Color bg); + +/** + * Render a single 32-bit glyph at high quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the specified background color, while other pixels have + * varying degrees of the foreground color. This function returns the new + * surface, or NULL if there was an error. + * + * The glyph is rendered without any padding or centering in the X direction, + * and aligned normally in the Y direction. + * + * This is the same as TTF_RenderGlyph_Shaded(), but takes a 32-bit character + * instead of 16-bit, and thus can render a larger range. If you are sure + * you'll have an SDL_ttf that's version 2.0.18 or newer, there's no reason + * not to use this function exclusively. + * + * You can render at other quality levels with TTF_RenderGlyph32_Solid, + * TTF_RenderGlyph32_Blended, and TTF_RenderGlyph32_LCD. + * + * \param font the font to render with. + * \param ch the character to render. + * \param fg the foreground color for the text. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \since This function is available since SDL_ttf 2.0.18. + * + * \sa TTF_RenderGlyph32_Solid + * \sa TTF_RenderGlyph32_Blended + * \sa TTF_RenderGlyph32_LCD + */ +extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph32_Shaded(TTF_Font *font, + Uint32 ch, SDL_Color fg, SDL_Color bg); + +/** + * Render Latin1 text at high quality to a new ARGB surface. + * + * This function will allocate a new 32-bit, ARGB surface, using alpha + * blending to dither the font with the given color. This function returns the + * new surface, or NULL if there was an error. + * + * This will not word-wrap the string; you'll get a surface with a single line + * of text, as long as the string requires. You can use + * TTF_RenderText_Blended_Wrapped() instead if you need to wrap the output to + * multiple lines. + * + * This will not wrap on newline characters. + * + * You almost certainly want TTF_RenderUTF8_Blended() unless you're sure you + * have a 1-byte Latin1 encoding. US ASCII characters will work with either + * function, but most other Unicode characters packed into a `const char *` + * will need UTF-8. + * + * You can render at other quality levels with TTF_RenderText_Solid, + * TTF_RenderText_Blended, and TTF_RenderText_LCD. + * + * \param font the font to render with. + * \param text text to render, in Latin1 encoding. + * \param fg the foreground color for the text. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \since This function is available since SDL_ttf 2.0.12. + * + * \sa TTF_RenderUTF8_Shaded + * \sa TTF_RenderUNICODE_Shaded + */ +extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Blended(TTF_Font *font, + const char *text, SDL_Color fg); + +/** + * Render UTF-8 text at high quality to a new ARGB surface. + * + * This function will allocate a new 32-bit, ARGB surface, using alpha + * blending to dither the font with the given color. This function returns the + * new surface, or NULL if there was an error. + * + * This will not word-wrap the string; you'll get a surface with a single line + * of text, as long as the string requires. You can use + * TTF_RenderUTF8_Blended_Wrapped() instead if you need to wrap the output to + * multiple lines. + * + * This will not wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderUTF8_Solid, + * TTF_RenderUTF8_Shaded, and TTF_RenderUTF8_LCD. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param fg the foreground color for the text. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \since This function is available since SDL_ttf 2.0.12. + * + * \sa TTF_RenderUNICODE_Blended + */ +extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUTF8_Blended(TTF_Font *font, + const char *text, SDL_Color fg); + +/** + * Render UCS-2 text at high quality to a new ARGB surface. + * + * This function will allocate a new 32-bit, ARGB surface, using alpha + * blending to dither the font with the given color. This function returns the + * new surface, or NULL if there was an error. + * + * This will not word-wrap the string; you'll get a surface with a single line + * of text, as long as the string requires. You can use + * TTF_RenderUNICODE_Blended_Wrapped() instead if you need to wrap the output + * to multiple lines. + * + * This will not wrap on newline characters. + * + * Please note that this function is named "Unicode" but currently expects + * UCS-2 encoding (16 bits per codepoint). This does not give you access to + * large Unicode values, such as emoji glyphs. These codepoints are accessible + * through the UTF-8 version of this function. + * + * You can render at other quality levels with TTF_RenderUNICODE_Solid, + * TTF_RenderUNICODE_Shaded, and TTF_RenderUNICODE_LCD. + * + * \param font the font to render with. + * \param text text to render, in UCS-2 encoding. + * \param fg the foreground color for the text. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \since This function is available since SDL_ttf 2.0.12. + * + * \sa TTF_RenderUTF8_Blended + */ +extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUNICODE_Blended(TTF_Font *font, + const Uint16 *text, SDL_Color fg); + +/** + * Render word-wrapped Latin1 text at high quality to a new ARGB surface. + * + * This function will allocate a new 32-bit, ARGB surface, using alpha + * blending to dither the font with the given color. This function returns the + * new surface, or NULL if there was an error. + * + * Text is wrapped to multiple lines on line endings and on word boundaries if + * it extends beyond `wrapLength` in pixels. + * + * If wrapLength is 0, this function will only wrap on newline characters. + * + * You almost certainly want TTF_RenderUTF8_Blended_Wrapped() unless you're + * sure you have a 1-byte Latin1 encoding. US ASCII characters will work with + * either function, but most other Unicode characters packed into a `const + * char *` will need UTF-8. + * + * You can render at other quality levels with TTF_RenderText_Solid_Wrapped, + * TTF_RenderText_Shaded_Wrapped, and TTF_RenderText_LCD_Wrapped. + * + * \param font the font to render with. + * \param text text to render, in Latin1 encoding. + * \param fg the foreground color for the text. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \since This function is available since SDL_ttf 2.0.18. + * + * \sa TTF_RenderUTF8_Blended_Wrapped + * \sa TTF_RenderUNICODE_Blended_Wrapped + */ +extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Blended_Wrapped(TTF_Font *font, + const char *text, SDL_Color fg, Uint32 wrapLength); + +/** + * Render word-wrapped UTF-8 text at high quality to a new ARGB surface. + * + * This function will allocate a new 32-bit, ARGB surface, using alpha + * blending to dither the font with the given color. This function returns the + * new surface, or NULL if there was an error. + * + * Text is wrapped to multiple lines on line endings and on word boundaries if + * it extends beyond `wrapLength` in pixels. + * + * If wrapLength is 0, this function will only wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderUTF8_Solid_Wrapped, + * TTF_RenderUTF8_Shaded_Wrapped, and TTF_RenderUTF8_LCD_Wrapped. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param fg the foreground color for the text. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \since This function is available since SDL_ttf 2.0.18. + * + * \sa TTF_RenderUTF8_Solid_Wrapped + * \sa TTF_RenderUTF8_Shaded_Wrapped + * \sa TTF_RenderUTF8_LCD_Wrapped + */ +extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUTF8_Blended_Wrapped(TTF_Font *font, + const char *text, SDL_Color fg, Uint32 wrapLength); + +/** + * Render word-wrapped UCS-2 text at high quality to a new ARGB surface. + * + * This function will allocate a new 32-bit, ARGB surface, using alpha + * blending to dither the font with the given color. This function returns the + * new surface, or NULL if there was an error. + * + * Text is wrapped to multiple lines on line endings and on word boundaries if + * it extends beyond `wrapLength` in pixels. + * + * If wrapLength is 0, this function will only wrap on newline characters. + * + * Please note that this function is named "Unicode" but currently expects + * UCS-2 encoding (16 bits per codepoint). This does not give you access to + * large Unicode values, such as emoji glyphs. These codepoints are accessible + * through the UTF-8 version of this function. + * + * You can render at other quality levels with + * TTF_RenderUNICODE_Solid_Wrapped, TTF_RenderUNICODE_Shaded_Wrapped, and + * TTF_RenderUNICODE_LCD_Wrapped. + * + * \param font the font to render with. + * \param text text to render, in UCS-2 encoding. + * \param fg the foreground color for the text. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \since This function is available since SDL_ttf 2.0.18. + * + * \sa TTF_RenderUTF8_Blended_Wrapped + */ +extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUNICODE_Blended_Wrapped(TTF_Font *font, + const Uint16 *text, SDL_Color fg, Uint32 wrapLength); + +/** + * Render a single 16-bit glyph at high quality to a new ARGB surface. + * + * This function will allocate a new 32-bit, ARGB surface, using alpha + * blending to dither the font with the given color. This function returns the + * new surface, or NULL if there was an error. + * + * The glyph is rendered without any padding or centering in the X direction, + * and aligned normally in the Y direction. + * + * Note that this version of the function takes a 16-bit character code, which + * covers the Basic Multilingual Plane, but is insufficient to cover the + * entire set of possible Unicode values, including emoji glyphs. You should + * use TTF_RenderGlyph32_Blended() instead, which offers the same + * functionality but takes a 32-bit codepoint instead. + * + * The only reason to use this function is that it was available since the + * beginning of time, more or less. + * + * You can render at other quality levels with TTF_RenderGlyph_Solid, + * TTF_RenderGlyph_Shaded, and TTF_RenderGlyph_LCD. + * + * \param font the font to render with. + * \param ch the character to render. + * \param fg the foreground color for the text. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \since This function is available since SDL_ttf 2.0.12. + * + * \sa TTF_RenderGlyph32_Blended + */ +extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph_Blended(TTF_Font *font, + Uint16 ch, SDL_Color fg); + +/** + * Render a single 32-bit glyph at high quality to a new ARGB surface. + * + * This function will allocate a new 32-bit, ARGB surface, using alpha + * blending to dither the font with the given color. This function returns the + * new surface, or NULL if there was an error. + * + * The glyph is rendered without any padding or centering in the X direction, + * and aligned normally in the Y direction. + * + * This is the same as TTF_RenderGlyph_Blended(), but takes a 32-bit character + * instead of 16-bit, and thus can render a larger range. If you are sure + * you'll have an SDL_ttf that's version 2.0.18 or newer, there's no reason + * not to use this function exclusively. + * + * You can render at other quality levels with TTF_RenderGlyph32_Solid, + * TTF_RenderGlyph32_Shaded, and TTF_RenderGlyph32_LCD. + * + * \param font the font to render with. + * \param ch the character to render. + * \param fg the foreground color for the text. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \since This function is available since SDL_ttf 2.0.18. + * + * \sa TTF_RenderGlyph32_Solid + * \sa TTF_RenderGlyph32_Shaded + * \sa TTF_RenderGlyph32_LCD + */ +extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph32_Blended(TTF_Font *font, + Uint32 ch, SDL_Color fg); + +/** + * Render Latin1 text at LCD subpixel quality to a new ARGB surface. + * + * This function will allocate a new 32-bit, ARGB surface, and render + * alpha-blended text using FreeType's LCD subpixel rendering. This function + * returns the new surface, or NULL if there was an error. + * + * This will not word-wrap the string; you'll get a surface with a single line + * of text, as long as the string requires. You can use + * TTF_RenderText_LCD_Wrapped() instead if you need to wrap the output to + * multiple lines. + * + * This will not wrap on newline characters. + * + * You almost certainly want TTF_RenderUTF8_LCD() unless you're sure you have + * a 1-byte Latin1 encoding. US ASCII characters will work with either + * function, but most other Unicode characters packed into a `const char *` + * will need UTF-8. + * + * You can render at other quality levels with TTF_RenderText_Solid, + * TTF_RenderText_Shaded, and TTF_RenderText_Blended. + * + * \param font the font to render with. + * \param text text to render, in Latin1 encoding. + * \param fg the foreground color for the text. + * \param bg the background color for the text. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \since This function is available since SDL_ttf 2.20.0. + * + * \sa TTF_RenderUTF8_LCD + * \sa TTF_RenderUNICODE_LCD + */ +extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_LCD(TTF_Font *font, + const char *text, SDL_Color fg, SDL_Color bg); + +/** + * Render UTF-8 text at LCD subpixel quality to a new ARGB surface. + * + * This function will allocate a new 32-bit, ARGB surface, and render + * alpha-blended text using FreeType's LCD subpixel rendering. This function + * returns the new surface, or NULL if there was an error. + * + * This will not word-wrap the string; you'll get a surface with a single line + * of text, as long as the string requires. You can use + * TTF_RenderUTF8_LCD_Wrapped() instead if you need to wrap the output to + * multiple lines. + * + * This will not wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderUTF8_Solid, + * TTF_RenderUTF8_Shaded, and TTF_RenderUTF8_Blended. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param fg the foreground color for the text. + * \param bg the background color for the text. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \since This function is available since SDL_ttf 2.20.0. + * + * \sa TTF_RenderUNICODE_LCD + */ +extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUTF8_LCD(TTF_Font *font, + const char *text, SDL_Color fg, SDL_Color bg); + +/** + * Render UCS-2 text at LCD subpixel quality to a new ARGB surface. + * + * This function will allocate a new 32-bit, ARGB surface, and render + * alpha-blended text using FreeType's LCD subpixel rendering. This function + * returns the new surface, or NULL if there was an error. + * + * This will not word-wrap the string; you'll get a surface with a single line + * of text, as long as the string requires. You can use + * TTF_RenderUNICODE_LCD_Wrapped() instead if you need to wrap the output to + * multiple lines. + * + * This will not wrap on newline characters. + * + * Please note that this function is named "Unicode" but currently expects + * UCS-2 encoding (16 bits per codepoint). This does not give you access to + * large Unicode values, such as emoji glyphs. These codepoints are accessible + * through the UTF-8 version of this function. + * + * You can render at other quality levels with TTF_RenderUNICODE_Solid, + * TTF_RenderUNICODE_Shaded, and TTF_RenderUNICODE_Blended. + * + * \param font the font to render with. + * \param text text to render, in UCS-2 encoding. + * \param fg the foreground color for the text. + * \param bg the background color for the text. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \since This function is available since SDL_ttf 2.20.0. + * + * \sa TTF_RenderUTF8_LCD + */ +extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUNICODE_LCD(TTF_Font *font, + const Uint16 *text, SDL_Color fg, SDL_Color bg); + +/** + * Render word-wrapped Latin1 text at LCD subpixel quality to a new ARGB + * surface. + * + * This function will allocate a new 32-bit, ARGB surface, and render + * alpha-blended text using FreeType's LCD subpixel rendering. This function + * returns the new surface, or NULL if there was an error. + * + * Text is wrapped to multiple lines on line endings and on word boundaries if + * it extends beyond `wrapLength` in pixels. + * + * If wrapLength is 0, this function will only wrap on newline characters. + * + * You almost certainly want TTF_RenderUTF8_LCD_Wrapped() unless you're sure + * you have a 1-byte Latin1 encoding. US ASCII characters will work with + * either function, but most other Unicode characters packed into a `const + * char *` will need UTF-8. + * + * You can render at other quality levels with TTF_RenderText_Solid_Wrapped, + * TTF_RenderText_Shaded_Wrapped, and TTF_RenderText_Blended_Wrapped. + * + * \param font the font to render with. + * \param text text to render, in Latin1 encoding. + * \param fg the foreground color for the text. + * \param bg the background color for the text. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \since This function is available since SDL_ttf 2.20.0. + * + * \sa TTF_RenderUTF8_LCD_Wrapped + * \sa TTF_RenderUNICODE_LCD_Wrapped + */ +extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_LCD_Wrapped(TTF_Font *font, + const char *text, SDL_Color fg, SDL_Color bg, Uint32 wrapLength); + +/** + * Render word-wrapped UTF-8 text at LCD subpixel quality to a new ARGB + * surface. + * + * This function will allocate a new 32-bit, ARGB surface, and render + * alpha-blended text using FreeType's LCD subpixel rendering. This function + * returns the new surface, or NULL if there was an error. + * + * Text is wrapped to multiple lines on line endings and on word boundaries if + * it extends beyond `wrapLength` in pixels. + * + * If wrapLength is 0, this function will only wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderUTF8_Solid_Wrapped, + * TTF_RenderUTF8_Shaded_Wrapped, and TTF_RenderUTF8_Blended_Wrapped. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param fg the foreground color for the text. + * \param bg the background color for the text. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \since This function is available since SDL_ttf 2.20.0. + * + * \sa TTF_RenderUTF8_Solid_Wrapped + * \sa TTF_RenderUTF8_Shaded_Wrapped + * \sa TTF_RenderUTF8_Blended_Wrapped + */ +extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUTF8_LCD_Wrapped(TTF_Font *font, + const char *text, SDL_Color fg, SDL_Color bg, Uint32 wrapLength); + +/** + * Render word-wrapped UCS-2 text at LCD subpixel quality to a new ARGB + * surface. + * + * This function will allocate a new 32-bit, ARGB surface, and render + * alpha-blended text using FreeType's LCD subpixel rendering. This function + * returns the new surface, or NULL if there was an error. + * + * Text is wrapped to multiple lines on line endings and on word boundaries if + * it extends beyond `wrapLength` in pixels. + * + * If wrapLength is 0, this function will only wrap on newline characters. + * + * Please note that this function is named "Unicode" but currently expects + * UCS-2 encoding (16 bits per codepoint). This does not give you access to + * large Unicode values, such as emoji glyphs. These codepoints are accessible + * through the UTF-8 version of this function. + * + * You can render at other quality levels with + * TTF_RenderUNICODE_Solid_Wrapped, TTF_RenderUNICODE_Shaded_Wrapped, and + * TTF_RenderUNICODE_Blended_Wrapped. + * + * \param font the font to render with. + * \param text text to render, in UCS-2 encoding. + * \param fg the foreground color for the text. + * \param bg the background color for the text. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \since This function is available since SDL_ttf 2.20.0. + * + * \sa TTF_RenderUTF8_LCD_Wrapped + */ +extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUNICODE_LCD_Wrapped(TTF_Font *font, + const Uint16 *text, SDL_Color fg, SDL_Color bg, Uint32 wrapLength); + +/** + * Render a single 16-bit glyph at LCD subpixel quality to a new ARGB surface. + * + * This function will allocate a new 32-bit, ARGB surface, and render + * alpha-blended text using FreeType's LCD subpixel rendering. This function + * returns the new surface, or NULL if there was an error. + * + * The glyph is rendered without any padding or centering in the X direction, + * and aligned normally in the Y direction. + * + * Note that this version of the function takes a 16-bit character code, which + * covers the Basic Multilingual Plane, but is insufficient to cover the + * entire set of possible Unicode values, including emoji glyphs. You should + * use TTF_RenderGlyph32_LCD() instead, which offers the same functionality + * but takes a 32-bit codepoint instead. + * + * This function only exists for consistency with the existing API at the time + * of its addition. + * + * You can render at other quality levels with TTF_RenderGlyph_Solid, + * TTF_RenderGlyph_Shaded, and TTF_RenderGlyph_Blended. + * + * \param font the font to render with. + * \param ch the character to render. + * \param fg the foreground color for the text. + * \param bg the background color for the text. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \since This function is available since SDL_ttf 2.20.0. + * + * \sa TTF_RenderGlyph32_LCD + */ +extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph_LCD(TTF_Font *font, + Uint16 ch, SDL_Color fg, SDL_Color bg); + +/** + * Render a single 32-bit glyph at LCD subpixel quality to a new ARGB surface. + * + * This function will allocate a new 32-bit, ARGB surface, and render + * alpha-blended text using FreeType's LCD subpixel rendering. This function + * returns the new surface, or NULL if there was an error. + * + * The glyph is rendered without any padding or centering in the X direction, + * and aligned normally in the Y direction. + * + * This is the same as TTF_RenderGlyph_LCD(), but takes a 32-bit character + * instead of 16-bit, and thus can render a larger range. Between the two, you + * should always use this function. + * + * You can render at other quality levels with TTF_RenderGlyph32_Solid, + * TTF_RenderGlyph32_Shaded, and TTF_RenderGlyph32_Blended. + * + * \param font the font to render with. + * \param ch the character to render. + * \param fg the foreground color for the text. + * \param bg the background color for the text. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \since This function is available since SDL_ttf 2.20.0. + * + * \sa TTF_RenderGlyph32_Solid + * \sa TTF_RenderGlyph32_Shaded + * \sa TTF_RenderGlyph32_Blended + */ +extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph32_LCD(TTF_Font *font, + Uint32 ch, SDL_Color fg, SDL_Color bg); + + +/* For compatibility with previous versions, here are the old functions */ +#define TTF_RenderText(font, text, fg, bg) \ + TTF_RenderText_Shaded(font, text, fg, bg) +#define TTF_RenderUTF8(font, text, fg, bg) \ + TTF_RenderUTF8_Shaded(font, text, fg, bg) +#define TTF_RenderUNICODE(font, text, fg, bg) \ + TTF_RenderUNICODE_Shaded(font, text, fg, bg) + +/** + * Dispose of a previously-created font. + * + * Call this when done with a font. This function will free any resources + * associated with it. + * + * The font is not valid after being passed to this function. String pointers + * from functions that return information on this font, such as + * TTF_FontFaceFamilyName() and TTF_FontFaceStyleName(), are no longer valid + * after this call, as well. + * + * \param font the font to dispose of. + * + * \since This function is available since SDL_ttf 2.0.12. + * + * \sa TTF_OpenFontIndexDPIRW + * \sa TTF_OpenFontRW + * \sa TTF_OpenFontDPI + * \sa TTF_OpenFontDPIRW + * \sa TTF_OpenFontIndex + * \sa TTF_OpenFontIndexDPI + * \sa TTF_OpenFontIndexDPIRW + * \sa TTF_OpenFontIndexRW + */ +extern DECLSPEC void SDLCALL TTF_CloseFont(TTF_Font *font); + +/** + * Deinitialize SDL_ttf. + * + * You must call this when done with the library, to free internal resources. + * It is safe to call this when the library isn't initialized, as it will just + * return immediately. + * + * Once you have as many quit calls as you have had successful calls to + * TTF_Init, the library will actually deinitialize. + * + * Please note that this does not automatically close any fonts that are still + * open at the time of deinitialization, and it is possibly not safe to close + * them afterwards, as parts of the library will no longer be initialized to + * deal with it. A well-written program should call TTF_CloseFont() on any + * open fonts before calling this function! + * + * \since This function is available since SDL_ttf 2.0.12. + */ +extern DECLSPEC void SDLCALL TTF_Quit(void); + +/** + * Check if SDL_ttf is initialized. + * + * This reports the number of times the library has been initialized by a call + * to TTF_Init(), without a paired deinitialization request from TTF_Quit(). + * + * In short: if it's greater than zero, the library is currently initialized + * and ready to work. If zero, it is not initialized. + * + * Despite the return value being a signed integer, this function should not + * return a negative number. + * + * \returns the current number of initialization calls, that need to + * eventually be paired with this many calls to TTF_Quit(). + * + * \since This function is available since SDL_ttf 2.0.12. + * + * \sa TTF_Init + * \sa TTF_Quit + */ +extern DECLSPEC int SDLCALL TTF_WasInit(void); + +/** + * Query the kerning size of two glyphs indices. + * + * \deprecated This function accidentally requires FreeType font indexes, + * not codepoints, which we don't expose through this API, so + * it could give wildly incorrect results, especially with + * non-ASCII values. Going forward, please use + * TTF_GetFontKerningSizeGlyphs() instead, which does what you + * probably expected this function to do. + * + * \param font the font to query. + * \param prev_index the font index, NOT codepoint, of the previous character. + * \param index the font index, NOT codepoint, of the current character. + * \returns The kerning size between the two specified characters, in pixels, or -1 on error. + * + * \since This function is available since SDL_ttf 2.0.12. + * + * \sa TTF_GetFontKerningSizeGlyphs + */ +extern SDL_DEPRECATED DECLSPEC int TTF_GetFontKerningSize(TTF_Font *font, int prev_index, int index); + +/** + * Query the kerning size of two 16-bit glyphs. + * + * Note that this version of the function takes 16-bit character + * codes, which covers the Basic Multilingual Plane, but is insufficient + * to cover the entire set of possible Unicode values, including emoji + * glyphs. You should use TTF_GetFontKerningSizeGlyphs32() instead, which + * offers the same functionality but takes a 32-bit codepoints instead. + * + * The only reason to use this function is that it was available since + * the beginning of time, more or less. + * + * \param font the font to query. + * \param previous_ch the previous character's code, 16 bits. + * \param ch the current character's code, 16 bits. + * \returns The kerning size between the two specified characters, in pixels, or -1 on error. + * + * \since This function is available since SDL_ttf 2.0.14. + * + * \sa TTF_GetFontKerningSizeGlyphs32 + */ +extern DECLSPEC int TTF_GetFontKerningSizeGlyphs(TTF_Font *font, Uint16 previous_ch, Uint16 ch); + +/** + * Query the kerning size of two 32-bit glyphs. + * + * This is the same as TTF_GetFontKerningSizeGlyphs(), but takes 32-bit + * characters instead of 16-bit, and thus can manage a larger range. If + * you are sure you'll have an SDL_ttf that's version 2.0.18 or newer, + * there's no reason not to use this function exclusively. + * + * \param font the font to query. + * \param previous_ch the previous character's code, 32 bits. + * \param ch the current character's code, 32 bits. + * \returns The kerning size between the two specified characters, in pixels, or -1 on error. + * + * \since This function is available since SDL_ttf 2.0.18. + */ +extern DECLSPEC int TTF_GetFontKerningSizeGlyphs32(TTF_Font *font, Uint32 previous_ch, Uint32 ch); + +/** + * Enable Signed Distance Field rendering for a font. + * + * This works with the Blended APIs. SDF is a technique that + * helps fonts look sharp even when scaling and rotating. + * + * This clears already-generated glyphs, if any, from the cache. + * + * \param font the font to set SDF support on. + * \param on_off SDL_TRUE to enable SDF, SDL_FALSE to disable. + * + * \returns 0 on success, -1 on error. + * + * \since This function is available since SDL_ttf 2.0.18. + * + * \sa TTF_GetFontSDF + */ +extern DECLSPEC int TTF_SetFontSDF(TTF_Font *font, SDL_bool on_off); + +/** + * Query whether Signed Distance Field rendering is enabled for a font. + * + * \param font the font to query + * + * \returns SDL_TRUE if enabled, SDL_FALSE otherwise. + * + * \since This function is available since SDL_ttf 2.0.18. + * + * \sa TTF_SetFontSDF + */ +extern DECLSPEC SDL_bool TTF_GetFontSDF(const TTF_Font *font); + +/** + * Report SDL_ttf errors + * + * \sa TTF_GetError + */ +#define TTF_SetError SDL_SetError + +/** + * Get last SDL_ttf error + * + * \sa TTF_SetError + */ +#define TTF_GetError SDL_GetError + +/** + * Direction flags + * + * \sa TTF_SetFontDirection + */ +typedef enum +{ + TTF_DIRECTION_LTR = 0, /* Left to Right */ + TTF_DIRECTION_RTL, /* Right to Left */ + TTF_DIRECTION_TTB, /* Top to Bottom */ + TTF_DIRECTION_BTT /* Bottom to Top */ +} TTF_Direction; + +/** + * Set a global direction to be used for text shaping. + * + * \deprecated This function expects an hb_direction_t value, from HarfBuzz, + * cast to an int, and affects all fonts globally. Please use + * TTF_SetFontDirection() instead, which uses an enum supplied by + * SDL_ttf itself and operates on a per-font basis. + * + * This is a global setting; fonts will favor a value set with + * TTF_SetFontDirection(), but if they have not had one explicitly + * set, they will use the value specified here. + * + * The default value is `HB_DIRECTION_LTR` (left-to-right text + * flow). + * + * \param direction an hb_direction_t value. + * \returns 0, or -1 if SDL_ttf is not compiled with HarfBuzz support. + * + * \since This function is available since SDL_ttf 2.0.18. + * + * \sa TTF_SetFontDirection + */ +extern SDL_DEPRECATED DECLSPEC int SDLCALL TTF_SetDirection(int direction); /* hb_direction_t */ + +/** + * Set a global script to be used for text shaping. + * + * \deprecated This function expects an hb_script_t value, from HarfBuzz, cast + * to an int, and affects all fonts globally. Please use + * TTF_SetFontScriptName() instead, which accepts a string that is + * converted to an equivalent int internally, and operates on a + * per-font basis. + * + * This is a global setting; fonts will favor a value set with + * TTF_SetFontScriptName(), but if they have not had one + * explicitly set, they will use the value specified here. + * + * The default value is `HB_SCRIPT_UNKNOWN`. + * + * \returns 0, or -1 if SDL_ttf is not compiled with HarfBuzz support. + * + * \since This function is available since SDL_ttf 2.0.18. + * + * \sa TTF_SetFontScriptName + */ +extern SDL_DEPRECATED DECLSPEC int SDLCALL TTF_SetScript(int script); /* hb_script_t */ + +/** + * Set direction to be used for text shaping by a font. + * + * Any value supplied here will override the global direction set with the + * deprecated TTF_SetDirection(). + * + * Possible direction values are: + * + * - `TTF_DIRECTION_LTR` (Left to Right) + * - `TTF_DIRECTION_RTL` (Right to Left) + * - `TTF_DIRECTION_TTB` (Top to Bottom) + * - `TTF_DIRECTION_BTT` (Bottom to Top) + * + * If SDL_ttf was not built with HarfBuzz support, this function returns -1. + * + * \param font the font to specify a direction for. + * \param direction the new direction for text to flow. + * \returns 0 on success, or -1 on error. + * + * \since This function is available since SDL_ttf 2.20.0. + */ +extern DECLSPEC int SDLCALL TTF_SetFontDirection(TTF_Font *font, TTF_Direction direction); + +/** + * Set script to be used for text shaping by a font. + * + * Any value supplied here will override the global script set with the + * deprecated TTF_SetScript(). + * + * The supplied script value must be a null-terminated string of exactly four + * characters. + * + * If SDL_ttf was not built with HarfBuzz support, this function returns -1. + * + * \param font the font to specify a direction for. + * \param script null-terminated string of exactly 4 characters. + * \returns 0 on success, or -1 on error. + * + * \since This function is available since SDL_ttf 2.20.0. + */ +extern DECLSPEC int SDLCALL TTF_SetFontScriptName(TTF_Font *font, const char *script); + +/* Ends C function definitions when using C++ */ +#ifdef __cplusplus +} +#endif +#include + +#endif /* SDL_TTF_H_ */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/libs/zsdl/libs/macos/Frameworks/SDL2_ttf.framework/Versions/A/Resources/CMake/sdl2_ttf-config-version.cmake b/libs/zsdl/libs/macos/Frameworks/SDL2_ttf.framework/Versions/A/Resources/CMake/sdl2_ttf-config-version.cmake new file mode 100644 index 00000000..fb6bfe1a --- /dev/null +++ b/libs/zsdl/libs/macos/Frameworks/SDL2_ttf.framework/Versions/A/Resources/CMake/sdl2_ttf-config-version.cmake @@ -0,0 +1,48 @@ +# based on the files generated by CMake's write_basic_package_version_file + +# SDL2_ttf CMake version configuration file: +# This file is meant to be placed in Resources/CMake of a SDL2_ttf framework + +if(NOT EXISTS "${CMAKE_CURRENT_LIST_DIR}/../../Headers/SDL_ttf.h") + message(AUTHOR_WARNING "Could not find SDL_ttf.h. This script is meant to be placed in the Resources/CMake directory of SDL2_ttf.framework") + return() +endif() + +file(READ "${CMAKE_CURRENT_LIST_DIR}/../../Headers/SDL_ttf.h" _sdl_ttf_h) +string(REGEX MATCH "#define[ \t]+SDL_TTF_MAJOR_VERSION[ \t]+([0-9]+)" _sdl_major_re "${_sdl_ttf_h}") +set(_sdl_major "${CMAKE_MATCH_1}") +string(REGEX MATCH "#define[ \t]+SDL_TTF_MINOR_VERSION[ \t]+([0-9]+)" _sdl_minor_re "${_sdl_ttf_h}") +set(_sdl_minor "${CMAKE_MATCH_1}") +string(REGEX MATCH "#define[ \t]+SDL_TTF_PATCHLEVEL[ \t]+([0-9]+)" _sdl_patch_re "${_sdl_ttf_h}") +set(_sdl_patch "${CMAKE_MATCH_1}") +if(_sdl_major_re AND _sdl_minor_re AND _sdl_patch_re) + set(PACKAGE_VERSION "${_sdl_major}.${_sdl_minor}.${_sdl_patch}") +else() + message(AUTHOR_WARNING "Could not extract version from SDL_ttf.h.") + return() +endif() + +if(PACKAGE_FIND_VERSION_RANGE) + # Package version must be in the requested version range + if ((PACKAGE_FIND_VERSION_RANGE_MIN STREQUAL "INCLUDE" AND PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION_MIN) + OR ((PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "INCLUDE" AND PACKAGE_VERSION VERSION_GREATER PACKAGE_FIND_VERSION_MAX) + OR (PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "EXCLUDE" AND PACKAGE_VERSION VERSION_GREATER_EQUAL PACKAGE_FIND_VERSION_MAX))) + set(PACKAGE_VERSION_COMPATIBLE FALSE) + else() + set(PACKAGE_VERSION_COMPATIBLE TRUE) + endif() +else() + if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION) + set(PACKAGE_VERSION_COMPATIBLE FALSE) + else() + set(PACKAGE_VERSION_COMPATIBLE TRUE) + if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION) + set(PACKAGE_VERSION_EXACT TRUE) + endif() + endif() +endif() + +# if the using project doesn't have CMAKE_SIZEOF_VOID_P set, fail. +if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "") + set(PACKAGE_VERSION_UNSUITABLE TRUE) +endif() diff --git a/libs/zsdl/libs/macos/Frameworks/SDL2_ttf.framework/Versions/A/Resources/CMake/sdl2_ttf-config.cmake b/libs/zsdl/libs/macos/Frameworks/SDL2_ttf.framework/Versions/A/Resources/CMake/sdl2_ttf-config.cmake new file mode 100644 index 00000000..7b84fe7f --- /dev/null +++ b/libs/zsdl/libs/macos/Frameworks/SDL2_ttf.framework/Versions/A/Resources/CMake/sdl2_ttf-config.cmake @@ -0,0 +1,39 @@ +# SDL2_ttf CMake configuration file: +# This file is meant to be placed in Resources/CMake of a SDL2_ttf framework + +# INTERFACE_LINK_OPTIONS needs CMake 3.12 +cmake_minimum_required(VERSION 3.12) + +include(FeatureSummary) +set_package_properties(SDL2_ttf PROPERTIES + URL "https://www.libsdl.org/projects/SDL_ttf/" + DESCRIPTION "Support for TrueType (.ttf) font files with Simple Directmedia Layer" +) + +set(SDL2_ttf_FOUND TRUE) + +set(SDL2TTF_VENDORED TRUE) + +set(SDL2TTF_HARFBUZZ TRUE) +set(SDL2TTF_FREETYPE TRUE) + +string(REGEX REPLACE "SDL2_ttf\\.framework.*" "SDL2_ttf.framework" _sdl2ttf_framework_path "${CMAKE_CURRENT_LIST_DIR}") +string(REGEX REPLACE "SDL2_ttf\\.framework.*" "" _sdl2ttf_framework_parent_path "${CMAKE_CURRENT_LIST_DIR}") + +# All targets are created, even when some might not be requested though COMPONENTS. +# This is done for compatibility with CMake generated SDL2_ttf-target.cmake files. + +if(NOT TARGET SDL2_ttf::SDL2_ttf) + add_library(SDL2_ttf::SDL2_ttf INTERFACE IMPORTED) + set_target_properties(SDL2_ttf::SDL2_ttf + PROPERTIES + INTERFACE_COMPILE_OPTIONS "SHELL:-F \"${_sdl2ttf_framework_parent_path}\"" + INTERFACE_INCLUDE_DIRECTORIES "${_sdl2ttf_framework_path}/Headers" + INTERFACE_LINK_OPTIONS "SHELL:-F \"${_sdl2ttf_framework_parent_path}\";SHELL:-framework SDL2_ttf" + COMPATIBLE_INTERFACE_BOOL "SDL2_SHARED" + INTERFACE_SDL2_SHARED "ON" + ) +endif() + +unset(_sdl2ttf_framework_path) +unset(_sdl2ttf_framework_parent_path) diff --git a/libs/zsdl/libs/macos/Frameworks/SDL2_ttf.framework/Versions/A/Resources/FTL.TXT b/libs/zsdl/libs/macos/Frameworks/SDL2_ttf.framework/Versions/A/Resources/FTL.TXT new file mode 100644 index 00000000..c406d150 --- /dev/null +++ b/libs/zsdl/libs/macos/Frameworks/SDL2_ttf.framework/Versions/A/Resources/FTL.TXT @@ -0,0 +1,169 @@ + The FreeType Project LICENSE + ---------------------------- + + 2006-Jan-27 + + Copyright 1996-2002, 2006 by + David Turner, Robert Wilhelm, and Werner Lemberg + + + +Introduction +============ + + The FreeType Project is distributed in several archive packages; + some of them may contain, in addition to the FreeType font engine, + various tools and contributions which rely on, or relate to, the + FreeType Project. + + This license applies to all files found in such packages, and + which do not fall under their own explicit license. The license + affects thus the FreeType font engine, the test programs, + documentation and makefiles, at the very least. + + This license was inspired by the BSD, Artistic, and IJG + (Independent JPEG Group) licenses, which all encourage inclusion + and use of free software in commercial and freeware products + alike. As a consequence, its main points are that: + + o We don't promise that this software works. However, we will be + interested in any kind of bug reports. (`as is' distribution) + + o You can use this software for whatever you want, in parts or + full form, without having to pay us. (`royalty-free' usage) + + o You may not pretend that you wrote this software. If you use + it, or only parts of it, in a program, you must acknowledge + somewhere in your documentation that you have used the + FreeType code. (`credits') + + We specifically permit and encourage the inclusion of this + software, with or without modifications, in commercial products. + We disclaim all warranties covering The FreeType Project and + assume no liability related to The FreeType Project. + + + Finally, many people asked us for a preferred form for a + credit/disclaimer to use in compliance with this license. We thus + encourage you to use the following text: + + """ + Portions of this software are copyright © The FreeType + Project (www.freetype.org). All rights reserved. + """ + + Please replace with the value from the FreeType version you + actually use. + + +Legal Terms +=========== + +0. Definitions +-------------- + + Throughout this license, the terms `package', `FreeType Project', + and `FreeType archive' refer to the set of files originally + distributed by the authors (David Turner, Robert Wilhelm, and + Werner Lemberg) as the `FreeType Project', be they named as alpha, + beta or final release. + + `You' refers to the licensee, or person using the project, where + `using' is a generic term including compiling the project's source + code as well as linking it to form a `program' or `executable'. + This program is referred to as `a program using the FreeType + engine'. + + This license applies to all files distributed in the original + FreeType Project, including all source code, binaries and + documentation, unless otherwise stated in the file in its + original, unmodified form as distributed in the original archive. + If you are unsure whether or not a particular file is covered by + this license, you must contact us to verify this. + + The FreeType Project is copyright (C) 1996-2000 by David Turner, + Robert Wilhelm, and Werner Lemberg. All rights reserved except as + specified below. + +1. No Warranty +-------------- + + THE FREETYPE PROJECT IS PROVIDED `AS IS' WITHOUT WARRANTY OF ANY + KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + PURPOSE. IN NO EVENT WILL ANY OF THE AUTHORS OR COPYRIGHT HOLDERS + BE LIABLE FOR ANY DAMAGES CAUSED BY THE USE OR THE INABILITY TO + USE, OF THE FREETYPE PROJECT. + +2. Redistribution +----------------- + + This license grants a worldwide, royalty-free, perpetual and + irrevocable right and license to use, execute, perform, compile, + display, copy, create derivative works of, distribute and + sublicense the FreeType Project (in both source and object code + forms) and derivative works thereof for any purpose; and to + authorize others to exercise some or all of the rights granted + herein, subject to the following conditions: + + o Redistribution of source code must retain this license file + (`FTL.TXT') unaltered; any additions, deletions or changes to + the original files must be clearly indicated in accompanying + documentation. The copyright notices of the unaltered, + original files must be preserved in all copies of source + files. + + o Redistribution in binary form must provide a disclaimer that + states that the software is based in part of the work of the + FreeType Team, in the distribution documentation. We also + encourage you to put an URL to the FreeType web page in your + documentation, though this isn't mandatory. + + These conditions apply to any software derived from or based on + the FreeType Project, not just the unmodified files. If you use + our work, you must acknowledge us. However, no fee need be paid + to us. + +3. Advertising +-------------- + + Neither the FreeType authors and contributors nor you shall use + the name of the other for commercial, advertising, or promotional + purposes without specific prior written permission. + + We suggest, but do not require, that you use one or more of the + following phrases to refer to this software in your documentation + or advertising materials: `FreeType Project', `FreeType Engine', + `FreeType library', or `FreeType Distribution'. + + As you have not signed this license, you are not required to + accept it. However, as the FreeType Project is copyrighted + material, only this license, or another one contracted with the + authors, grants you the right to use, distribute, and modify it. + Therefore, by using, distributing, or modifying the FreeType + Project, you indicate that you understand and accept all the terms + of this license. + +4. Contacts +----------- + + There are two mailing lists related to FreeType: + + o freetype@nongnu.org + + Discusses general use and applications of FreeType, as well as + future and wanted additions to the library and distribution. + If you are looking for support, start in this list if you + haven't found anything to help you in the documentation. + + o freetype-devel@nongnu.org + + Discusses bugs, as well as engine internals, design issues, + specific licenses, porting, etc. + + Our home page can be found at + + https://www.freetype.org + + +--- end of FTL.TXT --- diff --git a/libs/zsdl/libs/macos/Frameworks/SDL2_ttf.framework/Versions/A/Resources/FreeType-LICENSE.txt b/libs/zsdl/libs/macos/Frameworks/SDL2_ttf.framework/Versions/A/Resources/FreeType-LICENSE.txt new file mode 100644 index 00000000..af5a1c50 --- /dev/null +++ b/libs/zsdl/libs/macos/Frameworks/SDL2_ttf.framework/Versions/A/Resources/FreeType-LICENSE.txt @@ -0,0 +1,39 @@ + +The FreeType 2 font engine is copyrighted work and cannot be used +legally without a software license. In order to make this project +usable to a vast majority of developers, we distribute it under two +mutually exclusive open-source licenses. + +This means that *you* must choose *one* of the two licenses described +below, then obey all its terms and conditions when using FreeType 2 in +any of your projects or products. + + - The FreeType License, found in the file `FTL.TXT', which is similar + to the original BSD license *with* an advertising clause that forces + you to explicitly cite the FreeType project in your product's + documentation. All details are in the license file. This license + is suited to products which don't use the GNU General Public + License. + + Note that this license is compatible to the GNU General Public + License version 3, but not version 2. + + - The GNU General Public License version 2, found in `GPLv2.TXT' (any + later version can be used also), for programs which already use the + GPL. Note that the FTL is incompatible with GPLv2 due to its + advertisement clause. + +The contributed BDF and PCF drivers come with a license similar to that +of the X Window System. It is compatible to the above two licenses (see +file src/bdf/README and src/pcf/README). The same holds for the files +`fthash.c' and `fthash.h'; their code was part of the BDF driver in +earlier FreeType versions. + +The gzip module uses the zlib license (see src/gzip/zlib.h) which too is +compatible to the above two licenses. + +The MD5 checksum support (only used for debugging in development builds) +is in the public domain. + + +--- end of LICENSE.TXT --- diff --git a/libs/zsdl/libs/macos/Frameworks/SDL2_ttf.framework/Versions/A/Resources/HarfBuzz-LICENSE.txt b/libs/zsdl/libs/macos/Frameworks/SDL2_ttf.framework/Versions/A/Resources/HarfBuzz-LICENSE.txt new file mode 100644 index 00000000..57343164 --- /dev/null +++ b/libs/zsdl/libs/macos/Frameworks/SDL2_ttf.framework/Versions/A/Resources/HarfBuzz-LICENSE.txt @@ -0,0 +1,38 @@ +HarfBuzz is licensed under the so-called "Old MIT" license. Details follow. +For parts of HarfBuzz that are licensed under different licenses see individual +files names COPYING in subdirectories where applicable. + +Copyright © 2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020 Google, Inc. +Copyright © 2018,2019,2020 Ebrahim Byagowi +Copyright © 2019,2020 Facebook, Inc. +Copyright © 2012 Mozilla Foundation +Copyright © 2011 Codethink Limited +Copyright © 2008,2010 Nokia Corporation and/or its subsidiary(-ies) +Copyright © 2009 Keith Stribley +Copyright © 2009 Martin Hosken and SIL International +Copyright © 2007 Chris Wilson +Copyright © 2006 Behdad Esfahbod +Copyright © 2005 David Turner +Copyright © 2004,2007,2008,2009,2010 Red Hat, Inc. +Copyright © 1998-2004 David Turner and Werner Lemberg + +For full copyright notices consult the individual files in the package. + + +Permission is hereby granted, without written agreement and without +license or royalty fees, to use, copy, modify, and distribute this +software and its documentation for any purpose, provided that the +above copyright notice and the following two paragraphs appear in +all copies of this software. + +IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR +DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES +ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN +IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGE. + +THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, +BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS +ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO +PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. diff --git a/libs/zsdl/libs/macos/Frameworks/SDL2_ttf.framework/Versions/A/Resources/Info.plist b/libs/zsdl/libs/macos/Frameworks/SDL2_ttf.framework/Versions/A/Resources/Info.plist new file mode 100644 index 00000000..f7d08166 --- /dev/null +++ b/libs/zsdl/libs/macos/Frameworks/SDL2_ttf.framework/Versions/A/Resources/Info.plist @@ -0,0 +1,46 @@ + + + + + BuildMachineOSBuild + 22A400 + CFBundleDevelopmentRegion + English + CFBundleExecutable + SDL2_ttf + CFBundleIdentifier + org.libsdl.SDL2-ttf + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + SDL2_ttf + CFBundlePackageType + FMWK + CFBundleShortVersionString + 2.20.2 + CFBundleSupportedPlatforms + + MacOSX + + CFBundleVersion + 2.20.2 + DTCompiler + com.apple.compilers.llvm.clang.1_0 + DTPlatformBuild + 14C18 + DTPlatformName + macosx + DTPlatformVersion + 13.1 + DTSDKBuild + 22C55 + DTSDKName + macosx13.1 + DTXcode + 1420 + DTXcodeBuild + 14C18 + LSMinimumSystemVersion + 10.7 + + diff --git a/libs/zsdl/libs/macos/Frameworks/SDL2_ttf.framework/Versions/A/Resources/ReadMe.txt b/libs/zsdl/libs/macos/Frameworks/SDL2_ttf.framework/Versions/A/Resources/ReadMe.txt new file mode 100644 index 00000000..e114a47a --- /dev/null +++ b/libs/zsdl/libs/macos/Frameworks/SDL2_ttf.framework/Versions/A/Resources/ReadMe.txt @@ -0,0 +1,28 @@ +SDL_ttf is an example portable font rendering library for use with SDL. + +The source code is available from: http://www.libsdl.org/projects/SDL_ttf + +This library is distributed under the terms of the zlib license: http://www.zlib.net/zlib_license.html + +Portions of this software are copyright © 2013 The FreeType Project (www.freetype.org). All rights reserved. + +This packages contains the SDL2_ttf.framework for OS X. Conforming with Apple guidelines, this framework contains both the SDL runtime component and development header files. + +Requirements: +You must have the SDL2.framework installed. + +To Install: +Copy the SDL2_ttf.framework to /Library/Frameworks + +You may alternatively install it in /Library/Frameworks if your access privileges are not high enough. (Be aware that the Xcode templates we provide in the SDL Developer Extras package may require some adjustment for your system if you do this.) + + +(Partial) History of PB/Xcode projects: +2009-09-21 - Updated for 64-bit (Snow Leopard) Universal Binaries. + Switched to 10.4 minimum requirement. + Now dynamic linking Mac OS X bundled freetype directly in /usr/X11R6. (We used to just copy this one into our package since older versions of Mac OS X didn't ship with the library.) + Reason: We no longer statically link libfreetype.a into the binary because Apple stopped supplying a libfreetype.a in the 10.5 and 10.6 SDKs. + For static library target, you will need to link against libfreetype.dylib for your final app. + +2006-01-31 - First entry in history. Updated for Universal Binaries. Static library of libfreetype has been updated by copying the version Apple provides from the 10.4u SDK. + diff --git a/libs/zsdl/libs/macos/Frameworks/SDL2_ttf.framework/Versions/A/SDL2_ttf b/libs/zsdl/libs/macos/Frameworks/SDL2_ttf.framework/Versions/A/SDL2_ttf new file mode 100644 index 00000000..d8ed460b --- /dev/null +++ b/libs/zsdl/libs/macos/Frameworks/SDL2_ttf.framework/Versions/A/SDL2_ttf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c6d077882fdcbcd52ba521dac60608799c8e7910535435cf449506d17f1d3ef0 +size 3371536 diff --git a/libs/zsdl/libs/macos/Frameworks/SDL2_ttf.framework/Versions/A/_CodeSignature/CodeResources b/libs/zsdl/libs/macos/Frameworks/SDL2_ttf.framework/Versions/A/_CodeSignature/CodeResources new file mode 100644 index 00000000..6285b3a9 --- /dev/null +++ b/libs/zsdl/libs/macos/Frameworks/SDL2_ttf.framework/Versions/A/_CodeSignature/CodeResources @@ -0,0 +1,233 @@ + + + + + files + + Resources/CMake/sdl2_ttf-config-version.cmake + + 2H0oVk3V+kXlw2xJrtkplR8uzZk= + + Resources/CMake/sdl2_ttf-config.cmake + + BnA2e1CmuuadQ4WmodFyIid1EAo= + + Resources/FTL.TXT + + aTfQN2a6wPh5l5DbBXHTetZHhw8= + + Resources/FreeType-LICENSE.txt + + ZLfyE93XJpXZSGahqVMu5bOkcqg= + + Resources/HarfBuzz-LICENSE.txt + + GMGU+yuWtqYCiaeSZedpdv/bMD0= + + Resources/Info.plist + + OOVyvVBcUvPbIq/C1ppKHIYu7JM= + + Resources/ReadMe.txt + + 6McVk9LCuB72GPNUFfitazzPTSs= + + + files2 + + Headers/SDL_ttf.h + + hash + + 4+ZefqoD9HA5z8lHT5i3lh6GLrI= + + hash2 + + RtPoc6u/bhG6XOP0JMhPf8KuxCY/61Cf4kSU0ktp5J0= + + + Resources/CMake/sdl2_ttf-config-version.cmake + + hash + + 2H0oVk3V+kXlw2xJrtkplR8uzZk= + + hash2 + + PfjH4G+WE/+w6VOYm4THELt28ySVkCpaiqk0eqEWK2w= + + + Resources/CMake/sdl2_ttf-config.cmake + + hash + + BnA2e1CmuuadQ4WmodFyIid1EAo= + + hash2 + + UXGxuOqwWrvD/blIrqL0Y58GXloOCxbZzGzoWI/51QE= + + + Resources/FTL.TXT + + hash + + aTfQN2a6wPh5l5DbBXHTetZHhw8= + + hash2 + + CME1dV3ViQOUcPH9u0ANqquqpQ0LNm0Zzr/00imGuqE= + + + Resources/FreeType-LICENSE.txt + + hash + + ZLfyE93XJpXZSGahqVMu5bOkcqg= + + hash2 + + /QVt5BlpA6Z2II71jP3a/H1YPR8o+i5EwwnPhKWeYvs= + + + Resources/HarfBuzz-LICENSE.txt + + hash + + GMGU+yuWtqYCiaeSZedpdv/bMD0= + + hash2 + + vrPwF860E4dmf3gjenzs+E3voO0lfFBYlGY9ap8TIRs= + + + Resources/Info.plist + + hash + + OOVyvVBcUvPbIq/C1ppKHIYu7JM= + + hash2 + + A+LX07DOgTlN2hjyvdv4MWJQQMamT82SVeURsGCJ+eI= + + + Resources/ReadMe.txt + + hash + + 6McVk9LCuB72GPNUFfitazzPTSs= + + hash2 + + qiHN8zxBBJMv8RKGQFiuwXPpgMW7quHFipUT1qlq2wk= + + + + rules + + ^Resources/ + + ^Resources/.*\.lproj/ + + optional + + weight + 1000 + + ^Resources/.*\.lproj/locversion.plist$ + + omit + + weight + 1100 + + ^Resources/Base\.lproj/ + + weight + 1010 + + ^version.plist$ + + + rules2 + + .*\.dSYM($|/) + + weight + 11 + + ^(.*/)?\.DS_Store$ + + omit + + weight + 2000 + + ^(Frameworks|SharedFrameworks|PlugIns|Plug-ins|XPCServices|Helpers|MacOS|Library/(Automator|Spotlight|LoginItems))/ + + nested + + weight + 10 + + ^.* + + ^Info\.plist$ + + omit + + weight + 20 + + ^PkgInfo$ + + omit + + weight + 20 + + ^Resources/ + + weight + 20 + + ^Resources/.*\.lproj/ + + optional + + weight + 1000 + + ^Resources/.*\.lproj/locversion.plist$ + + omit + + weight + 1100 + + ^Resources/Base\.lproj/ + + weight + 1010 + + ^[^/]+$ + + nested + + weight + 10 + + ^embedded\.provisionprofile$ + + weight + 20 + + ^version\.plist$ + + weight + 20 + + + + diff --git a/libs/zsdl/libs/macos/Frameworks/SDL2_ttf.framework/Versions/Current b/libs/zsdl/libs/macos/Frameworks/SDL2_ttf.framework/Versions/Current new file mode 120000 index 00000000..8c7e5a66 --- /dev/null +++ b/libs/zsdl/libs/macos/Frameworks/SDL2_ttf.framework/Versions/Current @@ -0,0 +1 @@ +A \ No newline at end of file diff --git a/libs/zsdl/libs/x86_64-linux-gnu/lib/libSDL2_ttf-2.0.so b/libs/zsdl/libs/x86_64-linux-gnu/lib/libSDL2_ttf-2.0.so new file mode 100755 index 00000000..82d6225a --- /dev/null +++ b/libs/zsdl/libs/x86_64-linux-gnu/lib/libSDL2_ttf-2.0.so @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cb1e7c5b8211613b63f542a2d6d30925c95daa7883f854ed736950895bd75406 +size 82384 diff --git a/libs/zsdl/libs/x86_64-windows-gnu/bin/SDL2_ttf.dll b/libs/zsdl/libs/x86_64-windows-gnu/bin/SDL2_ttf.dll new file mode 100755 index 00000000..92c49bf2 --- /dev/null +++ b/libs/zsdl/libs/x86_64-windows-gnu/bin/SDL2_ttf.dll @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d96cb0005270afe9925c0bde9c95e29dd7a3f287f79aea17ca381fe3daa28e0e +size 1561088 diff --git a/libs/zsdl/src/sdl2.zig b/libs/zsdl/src/sdl2.zig new file mode 100644 index 00000000..b5896f79 --- /dev/null +++ b/libs/zsdl/src/sdl2.zig @@ -0,0 +1,1556 @@ +const builtin = @import("builtin"); +const std = @import("std"); +const assert = std.debug.assert; +//-------------------------------------------------------------------------------------------------- +// +// Init +// +//-------------------------------------------------------------------------------------------------- +pub const InitFlags = packed struct(u32) { + timer: bool = false, + __unused1: bool = false, + __unused2: bool = false, + __unused3: bool = false, + audio: bool = false, + video: bool = false, + __unused6: bool = false, + __unused7: bool = false, + __unused8: bool = false, + joystick: bool = false, + __unused10: bool = false, + __unused11: bool = false, + haptic: bool = false, + gamecontroller: bool = false, + events: bool = false, + sensor: bool = false, + __unused16: bool = false, + __unused17: bool = false, + __unused18: bool = false, + __unused19: bool = false, + noparachute: bool = false, + __unused: u11 = 0, + + pub const everything: InitFlags = .{ + .timer = true, + .audio = true, + .video = true, + .events = true, + .joystick = true, + .haptic = true, + .gamecontroller = true, + .sensor = true, + }; +}; + +pub fn init(flags: InitFlags) Error!void { + if (SDL_Init(flags) < 0) return makeError(); +} +extern fn SDL_Init(flags: InitFlags) i32; + +/// `pub fn quit() void` +pub const quit = SDL_Quit; +extern fn SDL_Quit() void; +//-------------------------------------------------------------------------------------------------- +// +// Error +// +//-------------------------------------------------------------------------------------------------- +pub fn getError() ?[:0]const u8 { + if (SDL_GetError()) |ptr| { + return std.mem.sliceTo(ptr, 0); + } + return null; +} +extern fn SDL_GetError() ?[*:0]const u8; + +pub const Error = error{SdlError}; + +pub fn makeError() error{SdlError} { + if (getError()) |str| { + std.log.debug("SDL2: {s}", .{str}); + } + return error.SdlError; +} +//-------------------------------------------------------------------------------------------------- +// +// Video driver +// +//-------------------------------------------------------------------------------------------------- +/// `pub fn getNumVideoDrivers() i32` +pub const getNumVideoDrivers = SDL_GetNumVideoDrivers; +extern fn SDL_GetNumVideoDrivers() i32; + +pub fn getVideoDriver(index: i32) ?[:0]const u8 { + if (SDL_GetVideoDriver(index)) |ptr| { + return std.mem.sliceTo(ptr, 0); + } + return null; +} +extern fn SDL_GetVideoDriver(index: i32) ?[*:0]const u8; +//-------------------------------------------------------------------------------------------------- +// +// Display +// +//-------------------------------------------------------------------------------------------------- +pub const DisplayId = u32; + +pub const DisplayMode = extern struct { + format: u32, + w: i32, + h: i32, + refresh_rate: i32, + driverdata: ?*anyopaque, +}; + +//-------------------------------------------------------------------------------------------------- +// +// Window +// +//-------------------------------------------------------------------------------------------------- +pub const Window = opaque { + pub const Flags = packed struct(u32) { + fullscreen: bool = false, + opengl: bool = false, + shown: bool = false, + hidden: bool = false, + borderless: bool = false, // 0x10 + resizable: bool = false, + minimized: bool = false, + maximized: bool = false, + mouse_grabbed: bool = false, // 0x100 + input_focus: bool = false, + mouse_focus: bool = false, + foreign: bool = false, + _desktop: bool = false, // 0x1000 + allow_highdpi: bool = false, + mouse_capture: bool = false, + always_on_top: bool = false, + skip_taskbar: bool = false, // 0x10000 + utility: bool = false, + tooltip: bool = false, + popup_menu: bool = false, + keyboard_grabbed: bool = false, + + __unused21: bool = false, + __unused22: bool = false, + __unused23: bool = false, + __unused24: bool = false, + + vulkan: bool = false, + metal: bool = false, + + __unused: u5 = 0, + + pub const fullscreen_desktop: Flags = .{ .fullscreen = true, ._desktop = true }; + pub const input_grabbed: Flags = .{ .mouse_grabbed = true }; + }; + + pub const pos_undefined = posUndefinedDisplay(0); + pub const pos_centered = posCenteredDisplay(0); + + pub fn posUndefinedDisplay(x: i32) i32 { + return pos_undefined_mask | x; + } + pub fn posCenteredDisplay(x: i32) i32 { + return pos_centered_mask | x; + } + + const pos_undefined_mask: i32 = 0x1fff_0000; + const pos_centered_mask: i32 = 0x2fff_0000; + + pub fn create(title: [:0]const u8, x: i32, y: i32, w: i32, h: i32, flags: Flags) Error!*Window { + return SDL_CreateWindow(title, x, y, w, h, flags) orelse return makeError(); + } + extern fn SDL_CreateWindow(title: ?[*:0]const u8, x: i32, y: i32, w: i32, h: i32, flags: Flags) ?*Window; + + /// `pub fn destroy(window: *Window) void` + pub const destroy = SDL_DestroyWindow; + extern fn SDL_DestroyWindow(window: *Window) void; + + pub fn getDisplayMode(window: *Window) Error!DisplayMode { + var mode: DisplayMode = undefined; + if (SDL_GetWindowDisplayMode(window, &mode) < 0) return makeError(); + return mode; + } + extern fn SDL_GetWindowDisplayMode(window: *Window, mode: *DisplayMode) i32; + + pub fn getPosition(window: *Window, w: ?*i32, h: ?*i32) Error!void { + if (SDL_GetWindowPosition(window, w, h) < 0) return makeError(); + } + extern fn SDL_GetWindowPosition(window: *Window, x: ?*i32, y: ?*i32) i32; + + pub fn getSize(window: *Window, w: ?*i32, h: ?*i32) Error!void { + if (SDL_GetWindowSize(window, w, h) < 0) return makeError(); + } + extern fn SDL_GetWindowSize(window: *Window, w: ?*i32, h: ?*i32) i32; + + pub fn setTitle(window: *Window, title: [:0]const u8) void { + SDL_SetWindowTitle(window, title); + } + extern fn SDL_SetWindowTitle(window: *Window, title: ?[*:0]const u8) void; +}; +//-------------------------------------------------------------------------------------------------- +// +// Rect/Point +// +//-------------------------------------------------------------------------------------------------- +pub const Rect = extern struct { + x: i32, + y: i32, + w: i32, + h: i32, + + pub fn hasIntersection(a: *const Rect, b: *const Rect) bool { + return SDL_HasIntersection(a, b) == 1; + } + extern fn SDL_HasIntersection(a: *const Rect, b: *const Rect) i32; + + pub fn intersectRect(a: *const Rect, b: *const Rect, result: *Rect) bool { + return SDL_IntersectRect(a, b, result) == 1; + } + extern fn SDL_IntersectRect(a: *const Rect, b: *const Rect, result: *Rect) i32; + + pub fn intersectRectAndLine(rect: *const Rect, x1: *i32, y1: *i32, x2: *i32, y2: *i32) bool { + return SDL_IntersectRectAndLine(rect, x1, y1, x2, y2) == 1; + } + extern fn SDL_IntersectRectAndLine(r: *const Rect, x1: *i32, y1: *i32, x2: *i32, y2: *i32) i32; +}; + +pub const RectF = extern struct { + x: f32, + y: f32, + w: f32, + h: f32, + + pub fn hasIntersection(a: *const Rect, b: *const Rect) bool { + return SDL_HasIntersectionF(a, b); + } + extern fn SDL_HasIntersectionF(a: *const Rect, b: *const Rect) bool; + + pub fn intersectRect(a: *const Rect, b: *const Rect, result: *Rect) bool { + return SDL_IntersectFRect(a, b, result); + } + extern fn SDL_IntersectFRect(a: *const Rect, b: *const Rect, result: *Rect) bool; + + pub fn intersectRectAndLine(rect: *const Rect, x1: *i32, y1: *i32, x2: *i32, y2: *i32) bool { + return SDL_IntersectFRectAndLine(rect, x1, y1, x2, y2); + } + extern fn SDL_IntersectFRectAndLine(r: *const Rect, x1: *i32, y1: *i32, x2: *i32, y2: *i32) bool; +}; + +pub const Point = extern struct { + x: i32, + y: i32, +}; + +pub const PointF = extern struct { + x: f32, + y: f32, +}; + +pub const Size = extern struct { + width: i32, + height: i32, +}; + +//-------------------------------------------------------------------------------------------------- +// +// Surface +// +//-------------------------------------------------------------------------------------------------- +pub const Surface = opaque { + pub fn free(surface: *Surface) void { + SDL_FreeSurface(surface); + } + extern fn SDL_FreeSurface(surface: *Surface) void; +}; + +//-------------------------------------------------------------------------------------------------- +// +// Texture +// +//-------------------------------------------------------------------------------------------------- +const PixelType = enum(u32) { + none = 0, + index1, + index4, + index8, + packed8, + packed16, + packed32, + arrayu8, + arrayu16, + arrayu32, + arrayf16, + arrayf32, +}; +const BitmapOrder = enum(u32) { + none = 0, + @"4321", + @"1234", +}; +const PackedOrder = enum(u32) { + none = 0, + xrgb, + rgbx, + argb, + rgba, + xbgr, + bgrx, + abgr, + bgra, +}; +const ArrayOrder = enum(u32) { + none = 0, + rgb, + rgba, + argb, + bgr, + bgra, + abgr, +}; +const PackedLayout = enum(u32) { + none = 0, + @"332", + @"4444", + @"1555", + @"5551", + @"565", + @"8888", + @"2101010", + @"1010102", +}; +fn definePixelFormat( + _type: PixelType, + order: anytype, + layout: u32, + bits: u32, + bytes: u32, +) u32 { + switch (_type) { + .index1, .index4, .index8 => { + assert(@TypeOf(order) == BitmapOrder); + }, + .packed8, .packed16, .packed32 => { + assert(@TypeOf(order) == PackedOrder); + }, + .arrayu8, .arrayu16, .arrayu32, .arrayf16, .arrayf32 => { + assert(@TypeOf(order) == ArrayOrder); + }, + .none => unreachable, + } + return ((1 << 28) | ((@intFromEnum(_type)) << 24) | ((@intFromEnum(order)) << 20) | + ((layout) << 16) | ((bits) << 8) | ((bytes) << 0)); +} +pub const PixelFormat = enum(u32) { + index1lsb = definePixelFormat(.index1, BitmapOrder.@"4321", 0, 1, 0), + index1msb = definePixelFormat(.index1, BitmapOrder.@"1234", 0, 1, 0), + index4lsb = definePixelFormat(.index4, BitmapOrder.@"4321", 0, 4, 0), + index4msb = definePixelFormat(.index4, BitmapOrder.@"1234", 0, 4, 0), + index8 = definePixelFormat(.index8, BitmapOrder.none, 0, 8, 1), + rgb332 = definePixelFormat(.packed8, PackedOrder.xrgb, @intFromEnum(PackedLayout.@"332"), 8, 1), + xrgb4444 = definePixelFormat(.packed16, PackedOrder.xrgb, @intFromEnum(PackedLayout.@"4444"), 12, 2), + xbgr4444 = definePixelFormat(.packed16, PackedOrder.xbgr, @intFromEnum(PackedLayout.@"4444"), 12, 2), + xrgb1555 = definePixelFormat(.packed16, PackedOrder.xrgb, @intFromEnum(PackedLayout.@"1555"), 15, 2), + xbgr1555 = definePixelFormat(.packed16, PackedOrder.xbgr, @intFromEnum(PackedLayout.@"1555"), 15, 2), + argb4444 = definePixelFormat(.packed16, PackedOrder.argb, @intFromEnum(PackedLayout.@"4444"), 16, 2), + rgba4444 = definePixelFormat(.packed16, PackedOrder.rgba, @intFromEnum(PackedLayout.@"4444"), 16, 2), + abgr4444 = definePixelFormat(.packed16, PackedOrder.abgr, @intFromEnum(PackedLayout.@"4444"), 16, 2), + bgra4444 = definePixelFormat(.packed16, PackedOrder.bgra, @intFromEnum(PackedLayout.@"4444"), 16, 2), + argb1555 = definePixelFormat(.packed16, PackedOrder.argb, @intFromEnum(PackedLayout.@"1555"), 16, 2), + rgba5551 = definePixelFormat(.packed16, PackedOrder.rgba, @intFromEnum(PackedLayout.@"5551"), 16, 2), + abgr1555 = definePixelFormat(.packed16, PackedOrder.abgr, @intFromEnum(PackedLayout.@"1555"), 16, 2), + bgra5551 = definePixelFormat(.packed16, PackedOrder.bgra, @intFromEnum(PackedLayout.@"5551"), 16, 2), + rgb565 = definePixelFormat(.packed16, PackedOrder.xrgb, @intFromEnum(PackedLayout.@"565"), 16, 2), + bgr565 = definePixelFormat(.packed16, PackedOrder.xbgr, @intFromEnum(PackedLayout.@"565"), 16, 2), + rgb24 = definePixelFormat(.arrayu8, ArrayOrder.rgb, 0, 24, 3), + bgr24 = definePixelFormat(.arrayu8, ArrayOrder.bgr, 0, 24, 3), + xrgb8888 = definePixelFormat(.packed32, PackedOrder.xrgb, @intFromEnum(PackedLayout.@"8888"), 24, 4), + rgbx8888 = definePixelFormat(.packed32, PackedOrder.rgbx, @intFromEnum(PackedLayout.@"8888"), 24, 4), + xbgr8888 = definePixelFormat(.packed32, PackedOrder.xbgr, @intFromEnum(PackedLayout.@"8888"), 24, 4), + bgrx8888 = definePixelFormat(.packed32, PackedOrder.bgrx, @intFromEnum(PackedLayout.@"8888"), 24, 4), + argb8888 = definePixelFormat(.packed32, PackedOrder.argb, @intFromEnum(PackedLayout.@"8888"), 32, 4), + rgba8888 = definePixelFormat(.packed32, PackedOrder.rgba, @intFromEnum(PackedLayout.@"8888"), 32, 4), + abgr8888 = definePixelFormat(.packed32, PackedOrder.abgr, @intFromEnum(PackedLayout.@"8888"), 32, 4), + bgra8888 = definePixelFormat(.packed32, PackedOrder.bgra, @intFromEnum(PackedLayout.@"8888"), 32, 4), + argb2101010 = definePixelFormat(.packed32, PackedOrder.argb, @intFromEnum(PackedLayout.@"2101010"), 32, 4), +}; + +pub const Access = enum(i32) { + static, + streaming, + target, +}; + +pub const Texture = opaque { + pub fn destroy(tex: *Texture) void { + SDL_DestroyTexture(tex); + } + extern fn SDL_DestroyTexture(texture: ?*Texture) void; + + pub fn query(texture: *Texture, format: ?*PixelFormat, access: ?*Access, w: ?*i32, h: ?*i32) !void { + if (SDL_QueryTexture(texture, @as(?*u32, @ptrCast(format)), @as(?*c_int, @ptrCast(access)), w, h) != 0) { + return makeError(); + } + } + extern fn SDL_QueryTexture(texture: *Texture, format: ?*u32, access: ?*c_int, w: ?*c_int, h: ?*c_int) c_int; +}; + +pub const Color = extern struct { + pub const black = rgb(0x00, 0x00, 0x00); + pub const white = rgb(0xFF, 0xFF, 0xFF); + pub const red = rgb(0xFF, 0x00, 0x00); + pub const green = rgb(0x00, 0xFF, 0x00); + pub const blue = rgb(0x00, 0x00, 0xFF); + pub const magenta = rgb(0xFF, 0x00, 0xFF); + pub const cyan = rgb(0x00, 0xFF, 0xFF); + pub const yellow = rgb(0xFF, 0xFF, 0x00); + + r: u8, + g: u8, + b: u8, + a: u8, + + /// Returns a initialized color struct with alpha = 255 + pub fn rgb(r: u8, g: u8, b: u8) Color { + return Color{ .r = r, .g = g, .b = b, .a = 255 }; + } + + /// Returns a initialized color struct + pub fn rgba(r: u8, g: u8, b: u8, a: u8) Color { + return Color{ .r = r, .g = g, .b = b, .a = a }; + } + + pub const ParseError = error{ + UnknownFormat, + InvalidCharacter, + Overflow, + }; + + /// Parses a hex string color literal. + /// allowed formats are: + /// - `RGB` + /// - `RGBA` + /// - `#RGB` + /// - `#RGBA` + /// - `RRGGBB` + /// - `#RRGGBB` + /// - `RRGGBBAA` + /// - `#RRGGBBAA` + pub fn parse(str: []const u8) ParseError!Color { + switch (str.len) { + // RGB + 3 => { + const r = try std.fmt.parseInt(u8, str[0..1], 16); + const g = try std.fmt.parseInt(u8, str[1..2], 16); + const b = try std.fmt.parseInt(u8, str[2..3], 16); + + return rgb( + r | (r << 4), + g | (g << 4), + b | (b << 4), + ); + }, + + // #RGB, RGBA + 4 => { + if (str[0] == '#') + return parse(str[1..]); + + const r = try std.fmt.parseInt(u8, str[0..1], 16); + const g = try std.fmt.parseInt(u8, str[1..2], 16); + const b = try std.fmt.parseInt(u8, str[2..3], 16); + const a = try std.fmt.parseInt(u8, str[3..4], 16); + + // bit-expand the patters to a uniform range + return rgba( + r | (r << 4), + g | (g << 4), + b | (b << 4), + a | (a << 4), + ); + }, + + // #RGBA + 5 => return parse(str[1..]), + + // RRGGBB + 6 => { + const r = try std.fmt.parseInt(u8, str[0..2], 16); + const g = try std.fmt.parseInt(u8, str[2..4], 16); + const b = try std.fmt.parseInt(u8, str[4..6], 16); + + return rgb(r, g, b); + }, + + // #RRGGBB + 7 => return parse(str[1..]), + + // RRGGBBAA + 8 => { + const r = try std.fmt.parseInt(u8, str[0..2], 16); + const g = try std.fmt.parseInt(u8, str[2..4], 16); + const b = try std.fmt.parseInt(u8, str[4..6], 16); + const a = try std.fmt.parseInt(u8, str[6..8], 16); + + return rgba(r, g, b, a); + }, + + // #RRGGBBAA + 9 => return parse(str[1..]), + + else => return error.UnknownFormat, + } + } +}; + +pub const Vertex = extern struct { + position: PointF, + color: Color, + tex_coord: PointF = undefined, +}; + +pub const BlendMode = enum(i32) { + none = 0x00000000, + blend = 0x00000001, + add = 0x00000002, + mod = 0x00000004, + multiply = 0x00000008, + invalid = 0x7fffffff, +}; + +pub const ScaleMode = enum(i32) { + nearest = 0x0000, + linear = 0x0001, + best = 0x0001, +}; + +pub const RendererFlip = enum(i32) { + none = 0x0000, + horizontal = 0x0001, + vertical = 0x0002, + both = 0x0003, +}; + +pub const RendererInfo = extern struct { + name: [*c]const u8, + flags: u32, + num_texture_formats: u32, + texture_formats: [16]u32, + max_texture_width: i32, + max_texture_height: i32, +}; + +//-------------------------------------------------------------------------------------------------- +// +// Renderer +// +//-------------------------------------------------------------------------------------------------- +pub const Renderer = opaque { + pub const Flags = packed struct(u32) { + software: bool = false, + accelerated: bool = false, + present_vsync: bool = false, + target_texture: bool = false, + __unused1: bool = false, + __unused2: bool = false, + __unused3: bool = false, + __unused4: bool = false, + __unused5: bool = false, + __unused6: bool = false, + __unused7: bool = false, + __unused8: bool = false, + __unused9: bool = false, + __unused10: bool = false, + __unused11: bool = false, + __unused12: bool = false, + __unused13: bool = false, + __unused14: bool = false, + __unused15: bool = false, + __unused16: bool = false, + __unused17: bool = false, + __unused18: bool = false, + __unused19: bool = false, + __unused20: bool = false, + __unused21: bool = false, + __unused22: bool = false, + __unused23: bool = false, + __unused24: bool = false, + __unused25: bool = false, + __unused26: bool = false, + __unused27: bool = false, + __unused28: bool = false, + }; + + pub fn create(window: *Window, index: ?i32, flags: Flags) !*Renderer { + return SDL_CreateRenderer(window, index orelse -1, flags) orelse makeError(); + } + extern fn SDL_CreateRenderer( + window: *Window, + index: i32, + flags: Flags, + ) ?*Renderer; + + pub fn destroy(r: *Renderer) void { + SDL_DestroyRenderer(r); + } + extern fn SDL_DestroyRenderer(r: *Renderer) void; + + pub fn clear(r: *Renderer) !void { + if (SDL_RenderClear(r) < 0) return makeError(); + } + extern fn SDL_RenderClear(r: *Renderer) i32; + + pub fn present(r: *Renderer) void { + SDL_RenderPresent(r); + } + extern fn SDL_RenderPresent(r: *Renderer) void; + + pub fn copy( + r: *Renderer, + tex: *Texture, + src: ?*const Rect, + dst: ?*const Rect, + ) !void { + if (SDL_RenderCopy(r, tex, src, dst) < 0) return makeError(); + } + extern fn SDL_RenderCopy( + r: *Renderer, + t: *Texture, + srcrect: ?*const Rect, + dstrect: ?*const Rect, + ) i32; + + pub fn copyF( + r: *Renderer, + tex: *Texture, + src: ?*const Rect, + dst: ?*const RectF, + ) !void { + if (SDL_RenderCopyF(r, tex, src, dst) < 0) return makeError(); + } + extern fn SDL_RenderCopyF( + r: *Renderer, + t: *Texture, + srcrect: ?*const Rect, + dstrect: ?*const RectF, + ) i32; + + pub fn copyEx( + r: *Renderer, + tex: *Texture, + src: ?*const Rect, + dst: ?*const Rect, + angle: f64, + center: ?*const Point, + flip: RendererFlip, + ) !void { + if (SDL_RenderCopyEx(r, tex, src, dst, angle, center, flip) < 0) return makeError(); + } + extern fn SDL_RenderCopyEx( + r: *Renderer, + t: *Texture, + srcrect: ?*const Rect, + dstrect: ?*const Rect, + angle: f64, + center: *const Point, + flip: RendererFlip, + ) i32; + + pub fn copyExF( + r: *Renderer, + tex: *Texture, + src: ?*const Rect, + dst: ?*const RectF, + angle: f64, + center: ?*const PointF, + flip: RendererFlip, + ) !void { + if (SDL_RenderCopyExF(r, tex, src, dst, angle, center, @intFromEnum(flip)) < 0) return makeError(); + } + extern fn SDL_RenderCopyExF( + r: *Renderer, + t: *Texture, + srcrect: ?*const Rect, + dstrect: ?*const RectF, + angle: f64, + center: *const PointF, + flip: RendererFlip, + ) i32; + + pub fn setScale(r: *Renderer, x: f32, y: f32) !void { + if (SDL_RenderSetScale(r, x, y) > 0) return makeError(); + } + extern fn SDL_RenderSetScale(renderer: *Renderer, scaleX: f32, scaleY: f32) i32; + + pub fn drawLine(r: *Renderer, x0: i32, y0: i32, x1: i32, y1: i32) !void { + if (SDL_RenderDrawLine(r, x0, y0, x1, y1) < 0) return makeError(); + } + extern fn SDL_RenderDrawLine(renderer: *Renderer, x1: i32, y1: i32, x2: i32, y2: i32) i32; + + pub fn drawLineF(r: *Renderer, x0: f32, y0: f32, x1: f32, y1: f32) !void { + if (SDL_RenderDrawLineF(r, x0, y0, x1, y1) < 0) return makeError(); + } + extern fn SDL_RenderDrawLineF(renderer: *Renderer, x1: f32, y1: f32, x2: f32, y2: f32) i32; + + pub fn drawPoint(r: *Renderer, x: i32, y: i32) !void { + if (SDL_RenderDrawPoint(r, x, y) < 0) return makeError(); + } + extern fn SDL_RenderDrawPoint(renderer: *Renderer, x: c_int, y: c_int) c_int; + + pub fn drawPointF(r: *Renderer, x: f32, y: f32) !void { + if (SDL_RenderDrawPointF(r, x, y) < 0) return makeError(); + } + extern fn SDL_RenderDrawPointF(renderer: *Renderer, x: f32, y: f32) i32; + + pub fn fillRect(r: *Renderer, rect: Rect) !void { + if (SDL_RenderFillRect(r, &rect) < 0) return makeError(); + } + extern fn SDL_RenderFillRect(renderer: ?*Renderer, rect: *const Rect) i32; + + pub fn fillRectF(r: *Renderer, rect: RectF) !void { + if (SDL_RenderFillRectF(r, &rect) < 0) return makeError(); + } + extern fn SDL_RenderFillRectF(renderer: *Renderer, rect: *const RectF) i32; + + pub fn drawRect(r: *Renderer, rect: Rect) !void { + if (SDL_RenderDrawRect(r, &rect) < 0) return makeError(); + } + extern fn SDL_RenderDrawRect(renderer: *Renderer, rect: *const Rect) i32; + + pub fn drawRectF(r: *Renderer, rect: RectF) !void { + if (SDL_RenderDrawRectF(r, &rect) < 0) return makeError(); + } + extern fn SDL_RenderDrawRectF(renderer: *Renderer, rect: *const RectF) c_int; + + pub fn drawGeometry( + r: *Renderer, + tex: ?*const Texture, + vertices: []const Vertex, + indices: ?[]const u32, + ) !void { + if (SDL_RenderGeometry( + r, + tex, + vertices.ptr, + @as(i32, @intCast(vertices.len)), + if (indices) |idx| @as([*]const i32, @ptrCast(idx.ptr)) else null, + if (indices) |idx| @as(i32, @intCast(idx.len)) else 0, + ) < 0) + return makeError(); + } + extern fn SDL_RenderGeometry( + renderer: *Renderer, + texture: ?*const Texture, + vertices: [*c]const Vertex, + num_vertices: i32, + indices: [*c]const i32, + num_indices: i32, + ) i32; + + pub fn setDrawColor(r: *Renderer, color: Color) !void { + if (SDL_SetRenderDrawColor(r, color.r, color.g, color.b, color.a) < 0) return makeError(); + } + + pub fn setDrawColorRGB(r: *Renderer, _r: u8, g: u8, b: u8) !void { + if (SDL_SetRenderDrawColor(r, _r, g, b, 255) < 0) return makeError(); + } + + pub fn setDrawColorRGBA(r: *Renderer, _r: u8, g: u8, b: u8, a: u8) !void { + if (SDL_SetRenderDrawColor(r, _r, g, b, a) < 0) return makeError(); + } + extern fn SDL_SetRenderDrawColor(r: *Renderer, _r: u8, g: u8, b: u8, a: u8) i32; + + pub fn getDrawColor(r: *Renderer) !Color { + var color: Color = undefined; + if (SDL_GetRenderDrawColor(r, &color.r, &color.g, &color.b, &color.a) < 0) return makeError(); + return color; + } + extern fn SDL_GetRenderDrawColor(renderer: *Renderer, r: *u8, g: *u8, b: *u8, a: *u8) i32; + + pub fn getDrawBlendMode(r: *Renderer) !BlendMode { + var blend_mode: BlendMode = undefined; + if (SDL_GetRenderDrawBlendMode(r, &blend_mode) < 0) return makeError(); + return blend_mode; + } + extern fn SDL_GetRenderDrawBlendMode(renderer: *Renderer, blendMode: *BlendMode) i32; + + pub fn setDrawBlendMode(r: *Renderer, blend_mode: BlendMode) !void { + if (SDL_SetRenderDrawBlendMode(r, blend_mode) < 0) return makeError(); + } + extern fn SDL_SetRenderDrawBlendMode(renderer: *Renderer, blendMode: BlendMode) i32; + + pub const OutputSize = struct { width_pixels: i32, height_pixels: i32 }; + pub fn getOutputSize(r: *Renderer) !OutputSize { + var width_pixels: i32 = undefined; + var height_pixels: i32 = undefined; + if (SDL_GetRendererOutputSize(r, &width_pixels, &height_pixels) < 0) return makeError(); + return OutputSize{ .width_pixels = width_pixels, .height_pixels = height_pixels }; + } + extern fn SDL_GetRendererOutputSize(renderer: *Renderer, w: *i32, h: *i32) i32; + + pub fn createTexture( + renderer: *Renderer, + format: PixelFormat, + access: Access, + width: i32, + height: i32, + ) !*Texture { + return SDL_CreateTexture(renderer, @intFromEnum(format), @intFromEnum(access), width, height) orelse makeError(); + } + extern fn SDL_CreateTexture(renderer: *Renderer, format: u32, access: i32, w: i32, h: i32) ?*Texture; + + pub fn createTextureFromSurface(renderer: *Renderer, surface: *Surface) !*Texture { + return SDL_CreateTextureFromSurface(renderer, surface) orelse makeError(); + } + extern fn SDL_CreateTextureFromSurface(renderer: *Renderer, surface: *Surface) ?*Texture; + + pub fn getInfo(r: *Renderer) !RendererInfo { + var result: RendererInfo = undefined; + if (SDL_GetRendererInfo(r, &result) < 0) return makeError(); + return result; + } + extern fn SDL_GetRendererInfo(renderer: *Renderer, info: *RendererInfo) i32; + + pub fn setClipRect(r: *Renderer, clip_rectangle: ?*const Rect) !void { + if (SDL_RenderSetClipRect(r, clip_rectangle) < 0) return makeError(); + } + extern fn SDL_RenderSetClipRect(renderer: *Renderer, rect: *const Rect) c_int; + + pub fn getClipRect(r: *Renderer) !?*const Rect { + if (SDL_RenderIsClipEnabled(r) == 1) return null; + var clip_rectangle: Rect = undefined; + SDL_RenderGetClipRect(r, &clip_rectangle); + return clip_rectangle; + } + extern fn SDL_RenderIsClipEnabled(renderer: *Renderer) i32; + extern fn SDL_RenderGetClipRect(renderer: *Renderer, rect: *Rect) void; + + pub fn getLogicalSize(r: *Renderer) !Size { + var width_pixels: i32 = undefined; + var height_pixels: i32 = undefined; + + if (SDL_RenderGetLogicalSize(r, &width_pixels, &height_pixels) < 0) return makeError(); + return Size{ + .width = width_pixels, + .height = height_pixels, + }; + } + extern fn SDL_RenderGetLogicalSize(renderer: *Renderer, w: *i32, h: *i32) void; + + pub fn setLogicalSize(r: *Renderer, width_pixels: i32, height_pixels: i32) !void { + if (SDL_RenderSetLogicalSize(r, width_pixels, height_pixels) < 0) return makeError(); + } + extern fn SDL_RenderSetLogicalSize(renderer: *Renderer, w: i32, h: i32) i32; + + pub fn getViewport(r: *Renderer) Rect { + var result: Rect = undefined; + SDL_RenderGetViewport(r, &result); + return result; + } + extern fn SDL_RenderGetViewport(renderer: *Renderer, rect: *Rect) void; + + pub fn setViewport(r: *Renderer, rect: Rect) !void { + if (SDL_RenderSetViewport(r, &rect) < 0) return makeError(); + } + extern fn SDL_RenderSetViewport(renderer: *Renderer, rect: *const Rect) i32; + + pub fn setTarget(r: *Renderer, tex: ?*const Texture) !void { + if (SDL_SetRenderTarget(r, tex) < 0) return makeError(); + } + extern fn SDL_SetRenderTarget(renderer: *Renderer, texture: ?*const Texture) i32; + + pub fn readPixels( + r: *Renderer, + rect: ?*const Rect, + format: ?PixelFormat, + pixels: [*]u8, + pitch: u32, + ) !void { + if (SDL_RenderReadPixels( + r, + rect, + if (format) |f| @intFromEnum(f) else 0, + pixels, + @as(i32, @intCast(pitch)), + ) < 0) return makeError(); + } + extern fn SDL_RenderReadPixels( + renderer: *Renderer, + rect: ?*const Rect, + format: u32, + pixels: ?*anyopaque, + pitch: i32, + ) i32; +}; + +//-------------------------------------------------------------------------------------------------- +// +// Events +// +//-------------------------------------------------------------------------------------------------- +pub const EventType = enum(u32) { + firstevent = 0, + + quit = 0x100, + app_terminating, + app_lowmemory, + app_willenterbackground, + app_didenterbackground, + app_willenterforeground, + app_didenterforeground, + localechanged, + + displayevent = 0x150, + + windowevent = 0x200, + syswmevent, + + keydown = 0x300, + keyup, + textediting, + textinput, + keymapchanged, + textediting_ext, + mousemotion = 0x400, + mousebuttondown, + mousebuttonup, + mousewheel, + + joyaxismotion = 0x600, + joyballmotion, + joyhatmotion, + joybuttondown, + joybuttonup, + joydeviceadded, + joydeviceremoved, + joybatteryupdated, + + controlleraxismotion = 0x650, + controllerbuttondown, + controllerbuttonup, + controllerdeviceadded, + controllerdeviceremoved, + controllerdeviceremapped, + controllertouchpaddown, + controllertouchpadmotion, + controllertouchpadup, + controllersensorupdate, + + fingerdown = 0x700, + fingerup, + fingermotion, + + dollargesture = 0x800, + dollarrecord, + multigesture, + + clipboardupdate = 0x900, + + dropfile = 0x1000, + droptext, + dropbegin, + dropcomplete, + + audiodeviceadded = 0x1100, + audiodeviceremoved, + + sensorupdate = 0x1200, + + render_targets_reset = 0x2000, + render_device_reset, + + pollsentinel = 0x7f00, + + userevent = 0x8000, + + lastevent = 0xffff, +}; + +pub const DisplayEventId = enum(u8) { + none, + orientation, + connected, + disconnected, +}; + +pub const WindowEventId = enum(u8) { + none, + shown, + hidden, + exposed, + + moved, + + resized, + size_changed, + + minimized, + maximized, + restored, + + enter, + leave, + focus_gained, + focus_lost, + close, + take_focus, + hit_test, + iccprof_changed, + display_changed, +}; + +pub const ReleasedOrPressed = enum(u8) { + released, + pressed, +}; + +pub const MouseWheelDirection = enum(u32) { + normal, + flipped, +}; + +pub const Scancode = @import("keyboard.zig").Scancode; + +pub const Keycode = @import("keyboard.zig").Keycode; + +pub const Keysym = extern struct { + scancode: Scancode, + sym: Keycode, + mod: u16, + unused: u32, +}; + +pub const CommonEvent = extern struct { + type: EventType, + timestamp: u32, +}; + +pub const DisplayEvent = extern struct { + type: EventType, + timestamp: u32, + display: u32, + event: DisplayEventId, + padding1: u8, + padding2: u8, + padding3: u8, + data1: i32, +}; + +pub const WindowEvent = extern struct { + type: EventType, + timestamp: u32, + window_id: u32, + event: WindowEventId, + padding1: u8, + padding2: u8, + padding3: u8, + data1: i32, + data2: i32, +}; + +pub const KeyboardEvent = extern struct { + type: EventType, + timestamp: u32, + window_id: u32, + state: ReleasedOrPressed, + repeat: u8, + padding2: u8, + padding3: u8, + keysym: Keysym, +}; + +pub const TextEditingEvent = extern struct { + type: EventType, + timestamp: u32, + window_id: u32, + text: [text_size]u8, + start: i32, + length: i32, + + const text_size = 32; +}; + +pub const TextEditingExtEvent = extern struct { + type: EventType, + timestamp: u32, + window_id: u32, + text: [*:0]u8, + start: i32, + length: i32, +}; + +pub const TextInputEvent = extern struct { + type: EventType, + timestamp: u32, + window_id: u32, + text: [text_size]u8, + + const text_size = 32; +}; + +pub const MouseMotionEvent = extern struct { + type: EventType, + timestamp: u32, + window_id: u32, + which: u32, + state: u32, + x: i32, + y: i32, + xrel: i32, + yrel: i32, +}; + +pub const MouseButtonEvent = extern struct { + type: EventType, + timestamp: u32, + window_id: u32, + which: u32, + button: u8, + state: ReleasedOrPressed, + clicks: u8, + padding1: u8, + x: i32, + y: i32, +}; + +pub const MouseWheelEvent = extern struct { + type: EventType, + timestamp: u32, + window_id: u32, + which: u32, + x: i32, + y: i32, + direction: MouseWheelDirection, + preciseX: f32, + preciseY: f32, +}; + +pub const QuitEvent = extern struct { + type: EventType, + timestamp: u32, +}; + +pub const DropEvent = extern struct { + type: EventType, + timestamp: u32, + file: ?[*:0]u8, + window_id: u32, +}; + +pub const ControllerDeviceEvent = extern struct { + type: EventType, + timestamp: u32, + which: i32, +}; + +pub const Event = extern union { + type: EventType, + common: CommonEvent, + display: DisplayEvent, + window: WindowEvent, + key: KeyboardEvent, + edit: TextEditingEvent, + editExt: TextEditingExtEvent, + text: TextInputEvent, + motion: MouseMotionEvent, + button: MouseButtonEvent, + wheel: MouseWheelEvent, + controllerdevice: ControllerDeviceEvent, + quit: QuitEvent, + drop: DropEvent, + + padding: [size]u8, + + const size = if (@sizeOf(usize) <= 8) 56 else if (@sizeOf(usize) == 16) 64 else 3 * @sizeOf(usize); + + comptime { + assert(@sizeOf(Event) == size); + } +}; + +pub const JOYSTICK_AXIS_MAX = 32767; +pub const JOYSTICK_AXIS_MIN = -32768; + +pub const GameController = opaque { + pub const Axis = enum(c_int) { + leftx, + lefty, + rightx, + righty, + triggerleft, + triggerright, + }; + pub const Button = enum(c_int) { + a, + b, + x, + y, + back, + guide, + start, + leftstick, + rightstick, + leftshoulder, + rightshoulder, + dpad_up, + dpad_down, + dpad_left, + dpad_right, + misc1, + paddle1, + paddle2, + paddle3, + paddle4, + touchpad, + }; + + pub fn open(joystick_index: i32) ?*GameController { + return SDL_GameControllerOpen(joystick_index); + } + extern fn SDL_GameControllerOpen(joystick_index: i32) ?*GameController; + + pub fn close(controller: *GameController) void { + SDL_GameControllerClose(controller); + } + extern fn SDL_GameControllerClose(joystick: *GameController) void; + + pub fn getAxis(controller: *GameController, axis: Axis) i16 { + return SDL_GameControllerGetAxis(controller, @intFromEnum(axis)); + } + extern fn SDL_GameControllerGetAxis(*GameController, axis: c_int) i16; + + pub fn getButton(controller: *GameController, button: Button) bool { + return (SDL_GameControllerGetButton(controller, @intFromEnum(button)) != 0); + } + extern fn SDL_GameControllerGetButton(controller: *GameController, button: c_int) u8; +}; + +pub fn pollEvent(event: ?*Event) bool { + return SDL_PollEvent(event) != 0; +} +extern fn SDL_PollEvent(event: ?*Event) i32; + +/// `pub fn SDL_GetKeyboardState(numkeys: ?*i32) ?[*]const u8` +pub fn getKeyboardState() []const u8 { + var numkeys: i32 = 0; + const ptr = SDL_GetKeyboardState(&numkeys).?; + return ptr[0..@as(usize, @intCast(numkeys))]; +} +extern fn SDL_GetKeyboardState(numkeys: ?*i32) ?[*]const u8; + +/// `pub fn getMouseFocus() ?*Window` +pub const getMouseFocus = SDL_GetMouseFocus; +extern fn SDL_GetMouseFocus() ?*Window; + +/// `pub fn getMouseState(x: ?*i32, y: ?*i32) u32` +pub const getMouseState = SDL_GetMouseState; +extern fn SDL_GetMouseState(x: ?*i32, y: ?*i32) u32; +//-------------------------------------------------------------------------------------------------- +// +// Hints +// +//-------------------------------------------------------------------------------------------------- +pub const hint_windows_dpi_awareness = "SDL_WINDOWS_DPI_AWARENESS"; + +pub fn setHint(name: [:0]const u8, value: [:0]const u8) bool { + return SDL_SetHint(name, value) != 0; +} +extern fn SDL_SetHint(name: [*:0]const u8, value: [*:0]const u8) i32; +//-------------------------------------------------------------------------------------------------- +// +// Message box +// +//-------------------------------------------------------------------------------------------------- +pub const MessageBoxFlags = packed struct(u32) { + err: bool = false, + warning: bool = false, + information: bool = false, + buttons_left_to_right: bool = false, + buttons_right_to_left: bool = false, + __unused: u27 = 0, +}; + +pub fn showSimpleMessageBox( + flags: MessageBoxFlags, + title: [:0]const u8, + message: [:0]const u8, + window: ?*Window, +) Error!void { + if (SDL_ShowSimpleMessageBox(flags, title, message, window) < 0) return makeError(); +} +extern fn SDL_ShowSimpleMessageBox( + flags: MessageBoxFlags, + title: ?[*:0]const u8, + message: ?[*:0]const u8, + window: ?*Window, +) i32; +//-------------------------------------------------------------------------------------------------- +// +// Audio +// +//-------------------------------------------------------------------------------------------------- +pub const AUDIO_MASK_BITSIZE = @as(c_int, 0xFF); +pub const AUDIO_MASK_DATATYPE = @as(c_int, 1) << @as(c_int, 8); +pub const AUDIO_MASK_ENDIAN = @as(c_int, 1) << @as(c_int, 12); +pub const AUDIO_MASK_SIGNED = @as(c_int, 1) << @as(c_int, 15); +pub inline fn AUDIO_BITSIZE(x: c_int) c_int { + return x & AUDIO_MASK_BITSIZE; +} +pub inline fn AUDIO_ISFLOAT(x: c_int) bool { + return (x & AUDIO_MASK_DATATYPE) != 0; +} +pub inline fn AUDIO_ISBIGENDIAN(x: c_int) bool { + return (x & AUDIO_MASK_ENDIAN) != 0; +} +pub inline fn AUDIO_ISSIGNED(x: c_int) bool { + return (x & AUDIO_MASK_SIGNED) != 0; +} +pub inline fn AUDIO_ISINT(x: c_int) bool { + return !AUDIO_ISFLOAT(x); +} +pub inline fn AUDIO_ISLITTLEENDIAN(x: c_int) bool { + return !AUDIO_ISBIGENDIAN(x); +} +pub inline fn AUDIO_ISUNSIGNED(x: c_int) bool { + return !AUDIO_ISSIGNED(x); +} +pub const AUDIO_U8 = 0x0008; +pub const AUDIO_S8 = 0x8008; +pub const AUDIO_U16LSB = 0x0010; +pub const AUDIO_S16LSB = 0x8010; +pub const AUDIO_U16MSB = 0x1010; +pub const AUDIO_S16MSB = 0x9010; +pub const AUDIO_U16 = AUDIO_U16LSB; +pub const AUDIO_S16 = AUDIO_S16LSB; +pub const AUDIO_S32LSB = 0x8020; +pub const AUDIO_S32MSB = 0x9020; +pub const AUDIO_S32 = AUDIO_S32LSB; +pub const AUDIO_F32LSB = 0x8120; +pub const AUDIO_F32MSB = 0x9120; +pub const AUDIO_F32 = AUDIO_F32LSB; +pub const AUDIO_U16SYS = switch (builtin.target.cpu.arch.endian()) { + .Little => AUDIO_U16LSB, + .Big => AUDIO_U16MSB, +}; +pub const AUDIO_S16SYS = switch (builtin.target.cpu.arch.endian()) { + .Little => AUDIO_S16LSB, + .Big => AUDIO_S16MSB, +}; +pub const AUDIO_S32SYS = switch (builtin.target.cpu.arch.endian()) { + .Little => AUDIO_S32LSB, + .Big => AUDIO_S32MSB, +}; +pub const AUDIO_F32SYS = switch (builtin.target.cpu.arch.endian()) { + .Little => AUDIO_F32LSB, + .Big => AUDIO_F32MSB, +}; + +pub const AudioCallback = *const fn ( + userdata: ?*anyopaque, + stream: [*c]u8, + len: c_int, +) callconv(.C) void; + +pub const AudioFormat = u16; + +pub const AudioSpec = extern struct { + freq: c_int, + format: AudioFormat, + channels: u8, + silence: u8 = 0, + samples: u16, + size: u32 = undefined, + callback: ?AudioCallback = null, + userdata: ?*anyopaque = null, +}; + +pub const AudioDeviceId = u32; + +pub fn openAudioDevice( + maybe_device: ?[:0]const u8, + iscapture: bool, + desired: *const AudioSpec, + obtained: *AudioSpec, + allowed_changes: c_int, +) AudioDeviceId { + return SDL_OpenAudioDevice( + if (maybe_device) |device| device.ptr else null, + if (iscapture) 1 else 0, + desired, + obtained, + allowed_changes, + ); +} +extern fn SDL_OpenAudioDevice( + device: ?[*:0]const u8, + iscapture: c_int, + desired: *const AudioSpec, + obtained: *AudioSpec, + allowed_changes: c_int, +) AudioDeviceId; + +pub fn pauseAudioDevice(device: AudioDeviceId, pause: bool) void { + SDL_PauseAudioDevice(device, if (pause) 1 else 0); +} +extern fn SDL_PauseAudioDevice(AudioDeviceId, pause: c_int) void; + +pub fn queueAudio(comptime SampleType: type, device: AudioDeviceId, data: []const SampleType) bool { + return SDL_QueueAudio(device, data.ptr, @sizeOf(SampleType) * @as(u32, @intCast(data.len))) == 0; +} +extern fn SDL_QueueAudio(AudioDeviceId, data: *const anyopaque, len: u32) c_int; + +/// `pub fn getQueuedAudioSize(device: AudioDeviceId) u32` +pub const getQueuedAudioSize = SDL_GetQueuedAudioSize; +extern fn SDL_GetQueuedAudioSize(AudioDeviceId) u32; + +/// `pub fn clearQueueAudio(device: AudioDeviceId) void` +pub const clearQueuedAudio = SDL_ClearQueuedAudio; +extern fn SDL_ClearQueuedAudio(AudioDeviceId) void; +//-------------------------------------------------------------------------------------------------- +// +// Timer +// +//-------------------------------------------------------------------------------------------------- +/// `pub fn getPerformanceCounter() u64` +pub const getPerformanceCounter = SDL_GetPerformanceCounter; +extern fn SDL_GetPerformanceCounter() u64; + +/// `pub fn getPerformanceFrequency() u64` +pub const getPerformanceFrequency = SDL_GetPerformanceFrequency; +extern fn SDL_GetPerformanceFrequency() u64; + +/// `pub fn delay(ms: u32) void` +pub const delay = SDL_Delay; +extern fn SDL_Delay(ms: u32) void; +//-------------------------------------------------------------------------------------------------- +// +// File Abstraction +// +//-------------------------------------------------------------------------------------------------- +pub fn getBasePath() ?[]const u8 { + return if (SDL_GetBasePath()) |path| std.mem.span(path) else null; +} +extern fn SDL_GetBasePath() [*c]const u8; + +pub fn getPrefPath(org: [:0]const u8, app: [:0]const u8) ?[]const u8 { + return if (SDL_GetPrefPath(org.ptr, app.ptr)) |path| std.mem.span(path) else null; +} +extern fn SDL_GetPrefPath(org: [*c]const u8, app: [*c]const u8) [*c]const u8; +//-------------------------------------------------------------------------------------------------- +// +// OpenGL +// +//-------------------------------------------------------------------------------------------------- +pub const gl = struct { + pub const Context = *anyopaque; + + pub const Attr = enum(i32) { + red_size, + green_size, + blue_size, + alpha_size, + buffer_size, + doublebuffer, + depth_size, + stencil_size, + accum_red_size, + accum_green_size, + accum_blue_size, + accum_alpha_size, + stereo, + multisamplebuffers, + multisamplesamples, + accelerated_visual, + retained_backing, + context_major_version, + context_minor_version, + context_egl, + context_flags, + context_profile_mask, + share_with_current_context, + framebuffer_srgb_capable, + context_release_behavior, + context_reset_notification, + context_no_error, + floatbuffers, + }; + + pub const Profile = enum(i32) { + core = 0x0001, + compatibility = 0x0002, + es = 0x0004, + }; + + pub const ContextFlags = packed struct(i32) { + debug: bool = false, + forward_compatible: bool = false, + robust_access: bool = false, + reset_isolation: bool = false, + __unused: i28 = 0, + }; + + pub const ContextReleaseFlags = packed struct(i32) { + flush: bool = false, + __unused: i31 = 0, + }; + + pub const ContextResetNotification = enum(i32) { + no_notification = 0x0000, + lose_context = 0x0001, + }; + + pub fn setAttribute(attr: Attr, value: i32) Error!void { + if (SDL_GL_SetAttribute(attr, value) < 0) return makeError(); + } + extern fn SDL_GL_SetAttribute(attr: Attr, value: i32) i32; + + pub fn getAttribute(attr: Attr) Error!i32 { + var value: i32 = undefined; + if (SDL_GL_GetAttribute(attr, &value) < 0) return makeError(); + return value; + } + extern fn SDL_GL_GetAttribute(attr: Attr, value: i32) i32; + + pub fn setSwapInterval(interval: i32) Error!void { + if (SDL_GL_SetSwapInterval(interval) < 0) return makeError(); + } + extern fn SDL_GL_SetSwapInterval(interval: i32) i32; + + /// `pub fn getSwapInterval() i32` + pub const getSwapInterval = SDL_GL_GetSwapInterval; + extern fn SDL_GL_GetSwapInterval() i32; + + /// `pub fn swapWindow(window: *Window) void` + pub const swapWindow = SDL_GL_SwapWindow; + extern fn SDL_GL_SwapWindow(window: *Window) void; + + pub fn getProcAddress(proc: [:0]const u8) ?*anyopaque { + return SDL_GL_GetProcAddress(proc); + } + extern fn SDL_GL_GetProcAddress(proc: ?[*:0]const u8) ?*anyopaque; + + pub fn isExtensionSupported(extension: [:0]const u8) bool { + return SDL_GL_ExtensionSupported(extension) != 0; + } + extern fn SDL_GL_ExtensionSupported(extension: ?[*:0]const u8) i32; + + pub fn createContext(window: *Window) Error!Context { + return SDL_GL_CreateContext(window) orelse return makeError(); + } + extern fn SDL_GL_CreateContext(window: *Window) ?Context; + + pub fn makeCurrent(window: *Window, context: Context) Error!void { + if (SDL_GL_MakeCurrent(window, context) < 0) return makeError(); + } + extern fn SDL_GL_MakeCurrent(window: *Window, context: Context) i32; + + /// `pub fn deleteContext(context: Context) void` + pub const deleteContext = SDL_GL_DeleteContext; + extern fn SDL_GL_DeleteContext(context: Context) void; + + /// `pub fn getDrawableSize(window: *Window, w: ?*i32, h: ?*i32) void` + pub const getDrawableSize = SDL_GL_GetDrawableSize; + extern fn SDL_GL_GetDrawableSize(window: *Window, w: ?*i32, h: ?*i32) void; +}; +//-------------------------------------------------------------------------------------------------- diff --git a/libs/zsdl/src/ttf.zig b/libs/zsdl/src/ttf.zig new file mode 100644 index 00000000..3ecb4065 --- /dev/null +++ b/libs/zsdl/src/ttf.zig @@ -0,0 +1,43 @@ +const sdl = @import("sdl2.zig"); + +pub fn init() !void { + if (TTF_Init() < 0) return sdl.makeError(); +} +extern fn TTF_Init() c_int; + +pub fn wasInit() bool { + return TTF_WasInit() == 1; +} +extern fn TTF_WasInit() c_int; + +pub fn quit() void { + TTF_Quit(); +} +extern fn TTF_Quit() void; + +pub const Font = opaque { + pub fn open(file: [:0]const u8, ptsize: i32) !*Font { + return TTF_OpenFont(file, ptsize) orelse sdl.makeError(); + } + extern fn TTF_OpenFont(file: [*c]const u8, ptsize: c_int) ?*Font; + + pub fn close(font: *Font) void { + TTF_CloseFont(font); + } + extern fn TTF_CloseFont(font: *Font) void; + + pub fn renderTextSolid(font: *Font, text: [:0]const u8, fg: sdl.Color) !*sdl.Surface { + return TTF_RenderText_Solid(font, text, fg) orelse sdl.makeError(); + } + extern fn TTF_RenderText_Solid(font: *Font, text: [*c]const u8, fg: sdl.Color) ?*sdl.Surface; + + pub fn renderTextShaded(font: *Font, text: [:0]const u8, fg: sdl.Color, bg: sdl.Color) !*sdl.Surface { + return TTF_RenderText_Shaded(font, text, fg, bg) orelse sdl.makeError(); + } + extern fn TTF_RenderText_Shaded(font: *Font, text: [*c]const u8, fg: sdl.Color, bg: sdl.Color) ?*sdl.Surface; + + pub fn renderTextBlended(font: *Font, text: [:0]const u8, fg: sdl.Color) !*sdl.Surface { + return TTF_RenderText_Blended(font, text, fg) orelse sdl.makeError(); + } + extern fn TTF_RenderText_Blended(font: *Font, text: [*c]const u8, fg: sdl.Color) ?*sdl.Surface; +}; diff --git a/libs/zsdl/src/zsdl.zig b/libs/zsdl/src/zsdl.zig index b5896f79..181b0d7b 100644 --- a/libs/zsdl/src/zsdl.zig +++ b/libs/zsdl/src/zsdl.zig @@ -1,1556 +1,4 @@ -const builtin = @import("builtin"); -const std = @import("std"); -const assert = std.debug.assert; -//-------------------------------------------------------------------------------------------------- -// -// Init -// -//-------------------------------------------------------------------------------------------------- -pub const InitFlags = packed struct(u32) { - timer: bool = false, - __unused1: bool = false, - __unused2: bool = false, - __unused3: bool = false, - audio: bool = false, - video: bool = false, - __unused6: bool = false, - __unused7: bool = false, - __unused8: bool = false, - joystick: bool = false, - __unused10: bool = false, - __unused11: bool = false, - haptic: bool = false, - gamecontroller: bool = false, - events: bool = false, - sensor: bool = false, - __unused16: bool = false, - __unused17: bool = false, - __unused18: bool = false, - __unused19: bool = false, - noparachute: bool = false, - __unused: u11 = 0, +pub usingnamespace @import("sdl2.zig"); - pub const everything: InitFlags = .{ - .timer = true, - .audio = true, - .video = true, - .events = true, - .joystick = true, - .haptic = true, - .gamecontroller = true, - .sensor = true, - }; -}; +pub const ttf = @import("ttf.zig"); -pub fn init(flags: InitFlags) Error!void { - if (SDL_Init(flags) < 0) return makeError(); -} -extern fn SDL_Init(flags: InitFlags) i32; - -/// `pub fn quit() void` -pub const quit = SDL_Quit; -extern fn SDL_Quit() void; -//-------------------------------------------------------------------------------------------------- -// -// Error -// -//-------------------------------------------------------------------------------------------------- -pub fn getError() ?[:0]const u8 { - if (SDL_GetError()) |ptr| { - return std.mem.sliceTo(ptr, 0); - } - return null; -} -extern fn SDL_GetError() ?[*:0]const u8; - -pub const Error = error{SdlError}; - -pub fn makeError() error{SdlError} { - if (getError()) |str| { - std.log.debug("SDL2: {s}", .{str}); - } - return error.SdlError; -} -//-------------------------------------------------------------------------------------------------- -// -// Video driver -// -//-------------------------------------------------------------------------------------------------- -/// `pub fn getNumVideoDrivers() i32` -pub const getNumVideoDrivers = SDL_GetNumVideoDrivers; -extern fn SDL_GetNumVideoDrivers() i32; - -pub fn getVideoDriver(index: i32) ?[:0]const u8 { - if (SDL_GetVideoDriver(index)) |ptr| { - return std.mem.sliceTo(ptr, 0); - } - return null; -} -extern fn SDL_GetVideoDriver(index: i32) ?[*:0]const u8; -//-------------------------------------------------------------------------------------------------- -// -// Display -// -//-------------------------------------------------------------------------------------------------- -pub const DisplayId = u32; - -pub const DisplayMode = extern struct { - format: u32, - w: i32, - h: i32, - refresh_rate: i32, - driverdata: ?*anyopaque, -}; - -//-------------------------------------------------------------------------------------------------- -// -// Window -// -//-------------------------------------------------------------------------------------------------- -pub const Window = opaque { - pub const Flags = packed struct(u32) { - fullscreen: bool = false, - opengl: bool = false, - shown: bool = false, - hidden: bool = false, - borderless: bool = false, // 0x10 - resizable: bool = false, - minimized: bool = false, - maximized: bool = false, - mouse_grabbed: bool = false, // 0x100 - input_focus: bool = false, - mouse_focus: bool = false, - foreign: bool = false, - _desktop: bool = false, // 0x1000 - allow_highdpi: bool = false, - mouse_capture: bool = false, - always_on_top: bool = false, - skip_taskbar: bool = false, // 0x10000 - utility: bool = false, - tooltip: bool = false, - popup_menu: bool = false, - keyboard_grabbed: bool = false, - - __unused21: bool = false, - __unused22: bool = false, - __unused23: bool = false, - __unused24: bool = false, - - vulkan: bool = false, - metal: bool = false, - - __unused: u5 = 0, - - pub const fullscreen_desktop: Flags = .{ .fullscreen = true, ._desktop = true }; - pub const input_grabbed: Flags = .{ .mouse_grabbed = true }; - }; - - pub const pos_undefined = posUndefinedDisplay(0); - pub const pos_centered = posCenteredDisplay(0); - - pub fn posUndefinedDisplay(x: i32) i32 { - return pos_undefined_mask | x; - } - pub fn posCenteredDisplay(x: i32) i32 { - return pos_centered_mask | x; - } - - const pos_undefined_mask: i32 = 0x1fff_0000; - const pos_centered_mask: i32 = 0x2fff_0000; - - pub fn create(title: [:0]const u8, x: i32, y: i32, w: i32, h: i32, flags: Flags) Error!*Window { - return SDL_CreateWindow(title, x, y, w, h, flags) orelse return makeError(); - } - extern fn SDL_CreateWindow(title: ?[*:0]const u8, x: i32, y: i32, w: i32, h: i32, flags: Flags) ?*Window; - - /// `pub fn destroy(window: *Window) void` - pub const destroy = SDL_DestroyWindow; - extern fn SDL_DestroyWindow(window: *Window) void; - - pub fn getDisplayMode(window: *Window) Error!DisplayMode { - var mode: DisplayMode = undefined; - if (SDL_GetWindowDisplayMode(window, &mode) < 0) return makeError(); - return mode; - } - extern fn SDL_GetWindowDisplayMode(window: *Window, mode: *DisplayMode) i32; - - pub fn getPosition(window: *Window, w: ?*i32, h: ?*i32) Error!void { - if (SDL_GetWindowPosition(window, w, h) < 0) return makeError(); - } - extern fn SDL_GetWindowPosition(window: *Window, x: ?*i32, y: ?*i32) i32; - - pub fn getSize(window: *Window, w: ?*i32, h: ?*i32) Error!void { - if (SDL_GetWindowSize(window, w, h) < 0) return makeError(); - } - extern fn SDL_GetWindowSize(window: *Window, w: ?*i32, h: ?*i32) i32; - - pub fn setTitle(window: *Window, title: [:0]const u8) void { - SDL_SetWindowTitle(window, title); - } - extern fn SDL_SetWindowTitle(window: *Window, title: ?[*:0]const u8) void; -}; -//-------------------------------------------------------------------------------------------------- -// -// Rect/Point -// -//-------------------------------------------------------------------------------------------------- -pub const Rect = extern struct { - x: i32, - y: i32, - w: i32, - h: i32, - - pub fn hasIntersection(a: *const Rect, b: *const Rect) bool { - return SDL_HasIntersection(a, b) == 1; - } - extern fn SDL_HasIntersection(a: *const Rect, b: *const Rect) i32; - - pub fn intersectRect(a: *const Rect, b: *const Rect, result: *Rect) bool { - return SDL_IntersectRect(a, b, result) == 1; - } - extern fn SDL_IntersectRect(a: *const Rect, b: *const Rect, result: *Rect) i32; - - pub fn intersectRectAndLine(rect: *const Rect, x1: *i32, y1: *i32, x2: *i32, y2: *i32) bool { - return SDL_IntersectRectAndLine(rect, x1, y1, x2, y2) == 1; - } - extern fn SDL_IntersectRectAndLine(r: *const Rect, x1: *i32, y1: *i32, x2: *i32, y2: *i32) i32; -}; - -pub const RectF = extern struct { - x: f32, - y: f32, - w: f32, - h: f32, - - pub fn hasIntersection(a: *const Rect, b: *const Rect) bool { - return SDL_HasIntersectionF(a, b); - } - extern fn SDL_HasIntersectionF(a: *const Rect, b: *const Rect) bool; - - pub fn intersectRect(a: *const Rect, b: *const Rect, result: *Rect) bool { - return SDL_IntersectFRect(a, b, result); - } - extern fn SDL_IntersectFRect(a: *const Rect, b: *const Rect, result: *Rect) bool; - - pub fn intersectRectAndLine(rect: *const Rect, x1: *i32, y1: *i32, x2: *i32, y2: *i32) bool { - return SDL_IntersectFRectAndLine(rect, x1, y1, x2, y2); - } - extern fn SDL_IntersectFRectAndLine(r: *const Rect, x1: *i32, y1: *i32, x2: *i32, y2: *i32) bool; -}; - -pub const Point = extern struct { - x: i32, - y: i32, -}; - -pub const PointF = extern struct { - x: f32, - y: f32, -}; - -pub const Size = extern struct { - width: i32, - height: i32, -}; - -//-------------------------------------------------------------------------------------------------- -// -// Surface -// -//-------------------------------------------------------------------------------------------------- -pub const Surface = opaque { - pub fn free(surface: *Surface) void { - SDL_FreeSurface(surface); - } - extern fn SDL_FreeSurface(surface: *Surface) void; -}; - -//-------------------------------------------------------------------------------------------------- -// -// Texture -// -//-------------------------------------------------------------------------------------------------- -const PixelType = enum(u32) { - none = 0, - index1, - index4, - index8, - packed8, - packed16, - packed32, - arrayu8, - arrayu16, - arrayu32, - arrayf16, - arrayf32, -}; -const BitmapOrder = enum(u32) { - none = 0, - @"4321", - @"1234", -}; -const PackedOrder = enum(u32) { - none = 0, - xrgb, - rgbx, - argb, - rgba, - xbgr, - bgrx, - abgr, - bgra, -}; -const ArrayOrder = enum(u32) { - none = 0, - rgb, - rgba, - argb, - bgr, - bgra, - abgr, -}; -const PackedLayout = enum(u32) { - none = 0, - @"332", - @"4444", - @"1555", - @"5551", - @"565", - @"8888", - @"2101010", - @"1010102", -}; -fn definePixelFormat( - _type: PixelType, - order: anytype, - layout: u32, - bits: u32, - bytes: u32, -) u32 { - switch (_type) { - .index1, .index4, .index8 => { - assert(@TypeOf(order) == BitmapOrder); - }, - .packed8, .packed16, .packed32 => { - assert(@TypeOf(order) == PackedOrder); - }, - .arrayu8, .arrayu16, .arrayu32, .arrayf16, .arrayf32 => { - assert(@TypeOf(order) == ArrayOrder); - }, - .none => unreachable, - } - return ((1 << 28) | ((@intFromEnum(_type)) << 24) | ((@intFromEnum(order)) << 20) | - ((layout) << 16) | ((bits) << 8) | ((bytes) << 0)); -} -pub const PixelFormat = enum(u32) { - index1lsb = definePixelFormat(.index1, BitmapOrder.@"4321", 0, 1, 0), - index1msb = definePixelFormat(.index1, BitmapOrder.@"1234", 0, 1, 0), - index4lsb = definePixelFormat(.index4, BitmapOrder.@"4321", 0, 4, 0), - index4msb = definePixelFormat(.index4, BitmapOrder.@"1234", 0, 4, 0), - index8 = definePixelFormat(.index8, BitmapOrder.none, 0, 8, 1), - rgb332 = definePixelFormat(.packed8, PackedOrder.xrgb, @intFromEnum(PackedLayout.@"332"), 8, 1), - xrgb4444 = definePixelFormat(.packed16, PackedOrder.xrgb, @intFromEnum(PackedLayout.@"4444"), 12, 2), - xbgr4444 = definePixelFormat(.packed16, PackedOrder.xbgr, @intFromEnum(PackedLayout.@"4444"), 12, 2), - xrgb1555 = definePixelFormat(.packed16, PackedOrder.xrgb, @intFromEnum(PackedLayout.@"1555"), 15, 2), - xbgr1555 = definePixelFormat(.packed16, PackedOrder.xbgr, @intFromEnum(PackedLayout.@"1555"), 15, 2), - argb4444 = definePixelFormat(.packed16, PackedOrder.argb, @intFromEnum(PackedLayout.@"4444"), 16, 2), - rgba4444 = definePixelFormat(.packed16, PackedOrder.rgba, @intFromEnum(PackedLayout.@"4444"), 16, 2), - abgr4444 = definePixelFormat(.packed16, PackedOrder.abgr, @intFromEnum(PackedLayout.@"4444"), 16, 2), - bgra4444 = definePixelFormat(.packed16, PackedOrder.bgra, @intFromEnum(PackedLayout.@"4444"), 16, 2), - argb1555 = definePixelFormat(.packed16, PackedOrder.argb, @intFromEnum(PackedLayout.@"1555"), 16, 2), - rgba5551 = definePixelFormat(.packed16, PackedOrder.rgba, @intFromEnum(PackedLayout.@"5551"), 16, 2), - abgr1555 = definePixelFormat(.packed16, PackedOrder.abgr, @intFromEnum(PackedLayout.@"1555"), 16, 2), - bgra5551 = definePixelFormat(.packed16, PackedOrder.bgra, @intFromEnum(PackedLayout.@"5551"), 16, 2), - rgb565 = definePixelFormat(.packed16, PackedOrder.xrgb, @intFromEnum(PackedLayout.@"565"), 16, 2), - bgr565 = definePixelFormat(.packed16, PackedOrder.xbgr, @intFromEnum(PackedLayout.@"565"), 16, 2), - rgb24 = definePixelFormat(.arrayu8, ArrayOrder.rgb, 0, 24, 3), - bgr24 = definePixelFormat(.arrayu8, ArrayOrder.bgr, 0, 24, 3), - xrgb8888 = definePixelFormat(.packed32, PackedOrder.xrgb, @intFromEnum(PackedLayout.@"8888"), 24, 4), - rgbx8888 = definePixelFormat(.packed32, PackedOrder.rgbx, @intFromEnum(PackedLayout.@"8888"), 24, 4), - xbgr8888 = definePixelFormat(.packed32, PackedOrder.xbgr, @intFromEnum(PackedLayout.@"8888"), 24, 4), - bgrx8888 = definePixelFormat(.packed32, PackedOrder.bgrx, @intFromEnum(PackedLayout.@"8888"), 24, 4), - argb8888 = definePixelFormat(.packed32, PackedOrder.argb, @intFromEnum(PackedLayout.@"8888"), 32, 4), - rgba8888 = definePixelFormat(.packed32, PackedOrder.rgba, @intFromEnum(PackedLayout.@"8888"), 32, 4), - abgr8888 = definePixelFormat(.packed32, PackedOrder.abgr, @intFromEnum(PackedLayout.@"8888"), 32, 4), - bgra8888 = definePixelFormat(.packed32, PackedOrder.bgra, @intFromEnum(PackedLayout.@"8888"), 32, 4), - argb2101010 = definePixelFormat(.packed32, PackedOrder.argb, @intFromEnum(PackedLayout.@"2101010"), 32, 4), -}; - -pub const Access = enum(i32) { - static, - streaming, - target, -}; - -pub const Texture = opaque { - pub fn destroy(tex: *Texture) void { - SDL_DestroyTexture(tex); - } - extern fn SDL_DestroyTexture(texture: ?*Texture) void; - - pub fn query(texture: *Texture, format: ?*PixelFormat, access: ?*Access, w: ?*i32, h: ?*i32) !void { - if (SDL_QueryTexture(texture, @as(?*u32, @ptrCast(format)), @as(?*c_int, @ptrCast(access)), w, h) != 0) { - return makeError(); - } - } - extern fn SDL_QueryTexture(texture: *Texture, format: ?*u32, access: ?*c_int, w: ?*c_int, h: ?*c_int) c_int; -}; - -pub const Color = extern struct { - pub const black = rgb(0x00, 0x00, 0x00); - pub const white = rgb(0xFF, 0xFF, 0xFF); - pub const red = rgb(0xFF, 0x00, 0x00); - pub const green = rgb(0x00, 0xFF, 0x00); - pub const blue = rgb(0x00, 0x00, 0xFF); - pub const magenta = rgb(0xFF, 0x00, 0xFF); - pub const cyan = rgb(0x00, 0xFF, 0xFF); - pub const yellow = rgb(0xFF, 0xFF, 0x00); - - r: u8, - g: u8, - b: u8, - a: u8, - - /// Returns a initialized color struct with alpha = 255 - pub fn rgb(r: u8, g: u8, b: u8) Color { - return Color{ .r = r, .g = g, .b = b, .a = 255 }; - } - - /// Returns a initialized color struct - pub fn rgba(r: u8, g: u8, b: u8, a: u8) Color { - return Color{ .r = r, .g = g, .b = b, .a = a }; - } - - pub const ParseError = error{ - UnknownFormat, - InvalidCharacter, - Overflow, - }; - - /// Parses a hex string color literal. - /// allowed formats are: - /// - `RGB` - /// - `RGBA` - /// - `#RGB` - /// - `#RGBA` - /// - `RRGGBB` - /// - `#RRGGBB` - /// - `RRGGBBAA` - /// - `#RRGGBBAA` - pub fn parse(str: []const u8) ParseError!Color { - switch (str.len) { - // RGB - 3 => { - const r = try std.fmt.parseInt(u8, str[0..1], 16); - const g = try std.fmt.parseInt(u8, str[1..2], 16); - const b = try std.fmt.parseInt(u8, str[2..3], 16); - - return rgb( - r | (r << 4), - g | (g << 4), - b | (b << 4), - ); - }, - - // #RGB, RGBA - 4 => { - if (str[0] == '#') - return parse(str[1..]); - - const r = try std.fmt.parseInt(u8, str[0..1], 16); - const g = try std.fmt.parseInt(u8, str[1..2], 16); - const b = try std.fmt.parseInt(u8, str[2..3], 16); - const a = try std.fmt.parseInt(u8, str[3..4], 16); - - // bit-expand the patters to a uniform range - return rgba( - r | (r << 4), - g | (g << 4), - b | (b << 4), - a | (a << 4), - ); - }, - - // #RGBA - 5 => return parse(str[1..]), - - // RRGGBB - 6 => { - const r = try std.fmt.parseInt(u8, str[0..2], 16); - const g = try std.fmt.parseInt(u8, str[2..4], 16); - const b = try std.fmt.parseInt(u8, str[4..6], 16); - - return rgb(r, g, b); - }, - - // #RRGGBB - 7 => return parse(str[1..]), - - // RRGGBBAA - 8 => { - const r = try std.fmt.parseInt(u8, str[0..2], 16); - const g = try std.fmt.parseInt(u8, str[2..4], 16); - const b = try std.fmt.parseInt(u8, str[4..6], 16); - const a = try std.fmt.parseInt(u8, str[6..8], 16); - - return rgba(r, g, b, a); - }, - - // #RRGGBBAA - 9 => return parse(str[1..]), - - else => return error.UnknownFormat, - } - } -}; - -pub const Vertex = extern struct { - position: PointF, - color: Color, - tex_coord: PointF = undefined, -}; - -pub const BlendMode = enum(i32) { - none = 0x00000000, - blend = 0x00000001, - add = 0x00000002, - mod = 0x00000004, - multiply = 0x00000008, - invalid = 0x7fffffff, -}; - -pub const ScaleMode = enum(i32) { - nearest = 0x0000, - linear = 0x0001, - best = 0x0001, -}; - -pub const RendererFlip = enum(i32) { - none = 0x0000, - horizontal = 0x0001, - vertical = 0x0002, - both = 0x0003, -}; - -pub const RendererInfo = extern struct { - name: [*c]const u8, - flags: u32, - num_texture_formats: u32, - texture_formats: [16]u32, - max_texture_width: i32, - max_texture_height: i32, -}; - -//-------------------------------------------------------------------------------------------------- -// -// Renderer -// -//-------------------------------------------------------------------------------------------------- -pub const Renderer = opaque { - pub const Flags = packed struct(u32) { - software: bool = false, - accelerated: bool = false, - present_vsync: bool = false, - target_texture: bool = false, - __unused1: bool = false, - __unused2: bool = false, - __unused3: bool = false, - __unused4: bool = false, - __unused5: bool = false, - __unused6: bool = false, - __unused7: bool = false, - __unused8: bool = false, - __unused9: bool = false, - __unused10: bool = false, - __unused11: bool = false, - __unused12: bool = false, - __unused13: bool = false, - __unused14: bool = false, - __unused15: bool = false, - __unused16: bool = false, - __unused17: bool = false, - __unused18: bool = false, - __unused19: bool = false, - __unused20: bool = false, - __unused21: bool = false, - __unused22: bool = false, - __unused23: bool = false, - __unused24: bool = false, - __unused25: bool = false, - __unused26: bool = false, - __unused27: bool = false, - __unused28: bool = false, - }; - - pub fn create(window: *Window, index: ?i32, flags: Flags) !*Renderer { - return SDL_CreateRenderer(window, index orelse -1, flags) orelse makeError(); - } - extern fn SDL_CreateRenderer( - window: *Window, - index: i32, - flags: Flags, - ) ?*Renderer; - - pub fn destroy(r: *Renderer) void { - SDL_DestroyRenderer(r); - } - extern fn SDL_DestroyRenderer(r: *Renderer) void; - - pub fn clear(r: *Renderer) !void { - if (SDL_RenderClear(r) < 0) return makeError(); - } - extern fn SDL_RenderClear(r: *Renderer) i32; - - pub fn present(r: *Renderer) void { - SDL_RenderPresent(r); - } - extern fn SDL_RenderPresent(r: *Renderer) void; - - pub fn copy( - r: *Renderer, - tex: *Texture, - src: ?*const Rect, - dst: ?*const Rect, - ) !void { - if (SDL_RenderCopy(r, tex, src, dst) < 0) return makeError(); - } - extern fn SDL_RenderCopy( - r: *Renderer, - t: *Texture, - srcrect: ?*const Rect, - dstrect: ?*const Rect, - ) i32; - - pub fn copyF( - r: *Renderer, - tex: *Texture, - src: ?*const Rect, - dst: ?*const RectF, - ) !void { - if (SDL_RenderCopyF(r, tex, src, dst) < 0) return makeError(); - } - extern fn SDL_RenderCopyF( - r: *Renderer, - t: *Texture, - srcrect: ?*const Rect, - dstrect: ?*const RectF, - ) i32; - - pub fn copyEx( - r: *Renderer, - tex: *Texture, - src: ?*const Rect, - dst: ?*const Rect, - angle: f64, - center: ?*const Point, - flip: RendererFlip, - ) !void { - if (SDL_RenderCopyEx(r, tex, src, dst, angle, center, flip) < 0) return makeError(); - } - extern fn SDL_RenderCopyEx( - r: *Renderer, - t: *Texture, - srcrect: ?*const Rect, - dstrect: ?*const Rect, - angle: f64, - center: *const Point, - flip: RendererFlip, - ) i32; - - pub fn copyExF( - r: *Renderer, - tex: *Texture, - src: ?*const Rect, - dst: ?*const RectF, - angle: f64, - center: ?*const PointF, - flip: RendererFlip, - ) !void { - if (SDL_RenderCopyExF(r, tex, src, dst, angle, center, @intFromEnum(flip)) < 0) return makeError(); - } - extern fn SDL_RenderCopyExF( - r: *Renderer, - t: *Texture, - srcrect: ?*const Rect, - dstrect: ?*const RectF, - angle: f64, - center: *const PointF, - flip: RendererFlip, - ) i32; - - pub fn setScale(r: *Renderer, x: f32, y: f32) !void { - if (SDL_RenderSetScale(r, x, y) > 0) return makeError(); - } - extern fn SDL_RenderSetScale(renderer: *Renderer, scaleX: f32, scaleY: f32) i32; - - pub fn drawLine(r: *Renderer, x0: i32, y0: i32, x1: i32, y1: i32) !void { - if (SDL_RenderDrawLine(r, x0, y0, x1, y1) < 0) return makeError(); - } - extern fn SDL_RenderDrawLine(renderer: *Renderer, x1: i32, y1: i32, x2: i32, y2: i32) i32; - - pub fn drawLineF(r: *Renderer, x0: f32, y0: f32, x1: f32, y1: f32) !void { - if (SDL_RenderDrawLineF(r, x0, y0, x1, y1) < 0) return makeError(); - } - extern fn SDL_RenderDrawLineF(renderer: *Renderer, x1: f32, y1: f32, x2: f32, y2: f32) i32; - - pub fn drawPoint(r: *Renderer, x: i32, y: i32) !void { - if (SDL_RenderDrawPoint(r, x, y) < 0) return makeError(); - } - extern fn SDL_RenderDrawPoint(renderer: *Renderer, x: c_int, y: c_int) c_int; - - pub fn drawPointF(r: *Renderer, x: f32, y: f32) !void { - if (SDL_RenderDrawPointF(r, x, y) < 0) return makeError(); - } - extern fn SDL_RenderDrawPointF(renderer: *Renderer, x: f32, y: f32) i32; - - pub fn fillRect(r: *Renderer, rect: Rect) !void { - if (SDL_RenderFillRect(r, &rect) < 0) return makeError(); - } - extern fn SDL_RenderFillRect(renderer: ?*Renderer, rect: *const Rect) i32; - - pub fn fillRectF(r: *Renderer, rect: RectF) !void { - if (SDL_RenderFillRectF(r, &rect) < 0) return makeError(); - } - extern fn SDL_RenderFillRectF(renderer: *Renderer, rect: *const RectF) i32; - - pub fn drawRect(r: *Renderer, rect: Rect) !void { - if (SDL_RenderDrawRect(r, &rect) < 0) return makeError(); - } - extern fn SDL_RenderDrawRect(renderer: *Renderer, rect: *const Rect) i32; - - pub fn drawRectF(r: *Renderer, rect: RectF) !void { - if (SDL_RenderDrawRectF(r, &rect) < 0) return makeError(); - } - extern fn SDL_RenderDrawRectF(renderer: *Renderer, rect: *const RectF) c_int; - - pub fn drawGeometry( - r: *Renderer, - tex: ?*const Texture, - vertices: []const Vertex, - indices: ?[]const u32, - ) !void { - if (SDL_RenderGeometry( - r, - tex, - vertices.ptr, - @as(i32, @intCast(vertices.len)), - if (indices) |idx| @as([*]const i32, @ptrCast(idx.ptr)) else null, - if (indices) |idx| @as(i32, @intCast(idx.len)) else 0, - ) < 0) - return makeError(); - } - extern fn SDL_RenderGeometry( - renderer: *Renderer, - texture: ?*const Texture, - vertices: [*c]const Vertex, - num_vertices: i32, - indices: [*c]const i32, - num_indices: i32, - ) i32; - - pub fn setDrawColor(r: *Renderer, color: Color) !void { - if (SDL_SetRenderDrawColor(r, color.r, color.g, color.b, color.a) < 0) return makeError(); - } - - pub fn setDrawColorRGB(r: *Renderer, _r: u8, g: u8, b: u8) !void { - if (SDL_SetRenderDrawColor(r, _r, g, b, 255) < 0) return makeError(); - } - - pub fn setDrawColorRGBA(r: *Renderer, _r: u8, g: u8, b: u8, a: u8) !void { - if (SDL_SetRenderDrawColor(r, _r, g, b, a) < 0) return makeError(); - } - extern fn SDL_SetRenderDrawColor(r: *Renderer, _r: u8, g: u8, b: u8, a: u8) i32; - - pub fn getDrawColor(r: *Renderer) !Color { - var color: Color = undefined; - if (SDL_GetRenderDrawColor(r, &color.r, &color.g, &color.b, &color.a) < 0) return makeError(); - return color; - } - extern fn SDL_GetRenderDrawColor(renderer: *Renderer, r: *u8, g: *u8, b: *u8, a: *u8) i32; - - pub fn getDrawBlendMode(r: *Renderer) !BlendMode { - var blend_mode: BlendMode = undefined; - if (SDL_GetRenderDrawBlendMode(r, &blend_mode) < 0) return makeError(); - return blend_mode; - } - extern fn SDL_GetRenderDrawBlendMode(renderer: *Renderer, blendMode: *BlendMode) i32; - - pub fn setDrawBlendMode(r: *Renderer, blend_mode: BlendMode) !void { - if (SDL_SetRenderDrawBlendMode(r, blend_mode) < 0) return makeError(); - } - extern fn SDL_SetRenderDrawBlendMode(renderer: *Renderer, blendMode: BlendMode) i32; - - pub const OutputSize = struct { width_pixels: i32, height_pixels: i32 }; - pub fn getOutputSize(r: *Renderer) !OutputSize { - var width_pixels: i32 = undefined; - var height_pixels: i32 = undefined; - if (SDL_GetRendererOutputSize(r, &width_pixels, &height_pixels) < 0) return makeError(); - return OutputSize{ .width_pixels = width_pixels, .height_pixels = height_pixels }; - } - extern fn SDL_GetRendererOutputSize(renderer: *Renderer, w: *i32, h: *i32) i32; - - pub fn createTexture( - renderer: *Renderer, - format: PixelFormat, - access: Access, - width: i32, - height: i32, - ) !*Texture { - return SDL_CreateTexture(renderer, @intFromEnum(format), @intFromEnum(access), width, height) orelse makeError(); - } - extern fn SDL_CreateTexture(renderer: *Renderer, format: u32, access: i32, w: i32, h: i32) ?*Texture; - - pub fn createTextureFromSurface(renderer: *Renderer, surface: *Surface) !*Texture { - return SDL_CreateTextureFromSurface(renderer, surface) orelse makeError(); - } - extern fn SDL_CreateTextureFromSurface(renderer: *Renderer, surface: *Surface) ?*Texture; - - pub fn getInfo(r: *Renderer) !RendererInfo { - var result: RendererInfo = undefined; - if (SDL_GetRendererInfo(r, &result) < 0) return makeError(); - return result; - } - extern fn SDL_GetRendererInfo(renderer: *Renderer, info: *RendererInfo) i32; - - pub fn setClipRect(r: *Renderer, clip_rectangle: ?*const Rect) !void { - if (SDL_RenderSetClipRect(r, clip_rectangle) < 0) return makeError(); - } - extern fn SDL_RenderSetClipRect(renderer: *Renderer, rect: *const Rect) c_int; - - pub fn getClipRect(r: *Renderer) !?*const Rect { - if (SDL_RenderIsClipEnabled(r) == 1) return null; - var clip_rectangle: Rect = undefined; - SDL_RenderGetClipRect(r, &clip_rectangle); - return clip_rectangle; - } - extern fn SDL_RenderIsClipEnabled(renderer: *Renderer) i32; - extern fn SDL_RenderGetClipRect(renderer: *Renderer, rect: *Rect) void; - - pub fn getLogicalSize(r: *Renderer) !Size { - var width_pixels: i32 = undefined; - var height_pixels: i32 = undefined; - - if (SDL_RenderGetLogicalSize(r, &width_pixels, &height_pixels) < 0) return makeError(); - return Size{ - .width = width_pixels, - .height = height_pixels, - }; - } - extern fn SDL_RenderGetLogicalSize(renderer: *Renderer, w: *i32, h: *i32) void; - - pub fn setLogicalSize(r: *Renderer, width_pixels: i32, height_pixels: i32) !void { - if (SDL_RenderSetLogicalSize(r, width_pixels, height_pixels) < 0) return makeError(); - } - extern fn SDL_RenderSetLogicalSize(renderer: *Renderer, w: i32, h: i32) i32; - - pub fn getViewport(r: *Renderer) Rect { - var result: Rect = undefined; - SDL_RenderGetViewport(r, &result); - return result; - } - extern fn SDL_RenderGetViewport(renderer: *Renderer, rect: *Rect) void; - - pub fn setViewport(r: *Renderer, rect: Rect) !void { - if (SDL_RenderSetViewport(r, &rect) < 0) return makeError(); - } - extern fn SDL_RenderSetViewport(renderer: *Renderer, rect: *const Rect) i32; - - pub fn setTarget(r: *Renderer, tex: ?*const Texture) !void { - if (SDL_SetRenderTarget(r, tex) < 0) return makeError(); - } - extern fn SDL_SetRenderTarget(renderer: *Renderer, texture: ?*const Texture) i32; - - pub fn readPixels( - r: *Renderer, - rect: ?*const Rect, - format: ?PixelFormat, - pixels: [*]u8, - pitch: u32, - ) !void { - if (SDL_RenderReadPixels( - r, - rect, - if (format) |f| @intFromEnum(f) else 0, - pixels, - @as(i32, @intCast(pitch)), - ) < 0) return makeError(); - } - extern fn SDL_RenderReadPixels( - renderer: *Renderer, - rect: ?*const Rect, - format: u32, - pixels: ?*anyopaque, - pitch: i32, - ) i32; -}; - -//-------------------------------------------------------------------------------------------------- -// -// Events -// -//-------------------------------------------------------------------------------------------------- -pub const EventType = enum(u32) { - firstevent = 0, - - quit = 0x100, - app_terminating, - app_lowmemory, - app_willenterbackground, - app_didenterbackground, - app_willenterforeground, - app_didenterforeground, - localechanged, - - displayevent = 0x150, - - windowevent = 0x200, - syswmevent, - - keydown = 0x300, - keyup, - textediting, - textinput, - keymapchanged, - textediting_ext, - mousemotion = 0x400, - mousebuttondown, - mousebuttonup, - mousewheel, - - joyaxismotion = 0x600, - joyballmotion, - joyhatmotion, - joybuttondown, - joybuttonup, - joydeviceadded, - joydeviceremoved, - joybatteryupdated, - - controlleraxismotion = 0x650, - controllerbuttondown, - controllerbuttonup, - controllerdeviceadded, - controllerdeviceremoved, - controllerdeviceremapped, - controllertouchpaddown, - controllertouchpadmotion, - controllertouchpadup, - controllersensorupdate, - - fingerdown = 0x700, - fingerup, - fingermotion, - - dollargesture = 0x800, - dollarrecord, - multigesture, - - clipboardupdate = 0x900, - - dropfile = 0x1000, - droptext, - dropbegin, - dropcomplete, - - audiodeviceadded = 0x1100, - audiodeviceremoved, - - sensorupdate = 0x1200, - - render_targets_reset = 0x2000, - render_device_reset, - - pollsentinel = 0x7f00, - - userevent = 0x8000, - - lastevent = 0xffff, -}; - -pub const DisplayEventId = enum(u8) { - none, - orientation, - connected, - disconnected, -}; - -pub const WindowEventId = enum(u8) { - none, - shown, - hidden, - exposed, - - moved, - - resized, - size_changed, - - minimized, - maximized, - restored, - - enter, - leave, - focus_gained, - focus_lost, - close, - take_focus, - hit_test, - iccprof_changed, - display_changed, -}; - -pub const ReleasedOrPressed = enum(u8) { - released, - pressed, -}; - -pub const MouseWheelDirection = enum(u32) { - normal, - flipped, -}; - -pub const Scancode = @import("keyboard.zig").Scancode; - -pub const Keycode = @import("keyboard.zig").Keycode; - -pub const Keysym = extern struct { - scancode: Scancode, - sym: Keycode, - mod: u16, - unused: u32, -}; - -pub const CommonEvent = extern struct { - type: EventType, - timestamp: u32, -}; - -pub const DisplayEvent = extern struct { - type: EventType, - timestamp: u32, - display: u32, - event: DisplayEventId, - padding1: u8, - padding2: u8, - padding3: u8, - data1: i32, -}; - -pub const WindowEvent = extern struct { - type: EventType, - timestamp: u32, - window_id: u32, - event: WindowEventId, - padding1: u8, - padding2: u8, - padding3: u8, - data1: i32, - data2: i32, -}; - -pub const KeyboardEvent = extern struct { - type: EventType, - timestamp: u32, - window_id: u32, - state: ReleasedOrPressed, - repeat: u8, - padding2: u8, - padding3: u8, - keysym: Keysym, -}; - -pub const TextEditingEvent = extern struct { - type: EventType, - timestamp: u32, - window_id: u32, - text: [text_size]u8, - start: i32, - length: i32, - - const text_size = 32; -}; - -pub const TextEditingExtEvent = extern struct { - type: EventType, - timestamp: u32, - window_id: u32, - text: [*:0]u8, - start: i32, - length: i32, -}; - -pub const TextInputEvent = extern struct { - type: EventType, - timestamp: u32, - window_id: u32, - text: [text_size]u8, - - const text_size = 32; -}; - -pub const MouseMotionEvent = extern struct { - type: EventType, - timestamp: u32, - window_id: u32, - which: u32, - state: u32, - x: i32, - y: i32, - xrel: i32, - yrel: i32, -}; - -pub const MouseButtonEvent = extern struct { - type: EventType, - timestamp: u32, - window_id: u32, - which: u32, - button: u8, - state: ReleasedOrPressed, - clicks: u8, - padding1: u8, - x: i32, - y: i32, -}; - -pub const MouseWheelEvent = extern struct { - type: EventType, - timestamp: u32, - window_id: u32, - which: u32, - x: i32, - y: i32, - direction: MouseWheelDirection, - preciseX: f32, - preciseY: f32, -}; - -pub const QuitEvent = extern struct { - type: EventType, - timestamp: u32, -}; - -pub const DropEvent = extern struct { - type: EventType, - timestamp: u32, - file: ?[*:0]u8, - window_id: u32, -}; - -pub const ControllerDeviceEvent = extern struct { - type: EventType, - timestamp: u32, - which: i32, -}; - -pub const Event = extern union { - type: EventType, - common: CommonEvent, - display: DisplayEvent, - window: WindowEvent, - key: KeyboardEvent, - edit: TextEditingEvent, - editExt: TextEditingExtEvent, - text: TextInputEvent, - motion: MouseMotionEvent, - button: MouseButtonEvent, - wheel: MouseWheelEvent, - controllerdevice: ControllerDeviceEvent, - quit: QuitEvent, - drop: DropEvent, - - padding: [size]u8, - - const size = if (@sizeOf(usize) <= 8) 56 else if (@sizeOf(usize) == 16) 64 else 3 * @sizeOf(usize); - - comptime { - assert(@sizeOf(Event) == size); - } -}; - -pub const JOYSTICK_AXIS_MAX = 32767; -pub const JOYSTICK_AXIS_MIN = -32768; - -pub const GameController = opaque { - pub const Axis = enum(c_int) { - leftx, - lefty, - rightx, - righty, - triggerleft, - triggerright, - }; - pub const Button = enum(c_int) { - a, - b, - x, - y, - back, - guide, - start, - leftstick, - rightstick, - leftshoulder, - rightshoulder, - dpad_up, - dpad_down, - dpad_left, - dpad_right, - misc1, - paddle1, - paddle2, - paddle3, - paddle4, - touchpad, - }; - - pub fn open(joystick_index: i32) ?*GameController { - return SDL_GameControllerOpen(joystick_index); - } - extern fn SDL_GameControllerOpen(joystick_index: i32) ?*GameController; - - pub fn close(controller: *GameController) void { - SDL_GameControllerClose(controller); - } - extern fn SDL_GameControllerClose(joystick: *GameController) void; - - pub fn getAxis(controller: *GameController, axis: Axis) i16 { - return SDL_GameControllerGetAxis(controller, @intFromEnum(axis)); - } - extern fn SDL_GameControllerGetAxis(*GameController, axis: c_int) i16; - - pub fn getButton(controller: *GameController, button: Button) bool { - return (SDL_GameControllerGetButton(controller, @intFromEnum(button)) != 0); - } - extern fn SDL_GameControllerGetButton(controller: *GameController, button: c_int) u8; -}; - -pub fn pollEvent(event: ?*Event) bool { - return SDL_PollEvent(event) != 0; -} -extern fn SDL_PollEvent(event: ?*Event) i32; - -/// `pub fn SDL_GetKeyboardState(numkeys: ?*i32) ?[*]const u8` -pub fn getKeyboardState() []const u8 { - var numkeys: i32 = 0; - const ptr = SDL_GetKeyboardState(&numkeys).?; - return ptr[0..@as(usize, @intCast(numkeys))]; -} -extern fn SDL_GetKeyboardState(numkeys: ?*i32) ?[*]const u8; - -/// `pub fn getMouseFocus() ?*Window` -pub const getMouseFocus = SDL_GetMouseFocus; -extern fn SDL_GetMouseFocus() ?*Window; - -/// `pub fn getMouseState(x: ?*i32, y: ?*i32) u32` -pub const getMouseState = SDL_GetMouseState; -extern fn SDL_GetMouseState(x: ?*i32, y: ?*i32) u32; -//-------------------------------------------------------------------------------------------------- -// -// Hints -// -//-------------------------------------------------------------------------------------------------- -pub const hint_windows_dpi_awareness = "SDL_WINDOWS_DPI_AWARENESS"; - -pub fn setHint(name: [:0]const u8, value: [:0]const u8) bool { - return SDL_SetHint(name, value) != 0; -} -extern fn SDL_SetHint(name: [*:0]const u8, value: [*:0]const u8) i32; -//-------------------------------------------------------------------------------------------------- -// -// Message box -// -//-------------------------------------------------------------------------------------------------- -pub const MessageBoxFlags = packed struct(u32) { - err: bool = false, - warning: bool = false, - information: bool = false, - buttons_left_to_right: bool = false, - buttons_right_to_left: bool = false, - __unused: u27 = 0, -}; - -pub fn showSimpleMessageBox( - flags: MessageBoxFlags, - title: [:0]const u8, - message: [:0]const u8, - window: ?*Window, -) Error!void { - if (SDL_ShowSimpleMessageBox(flags, title, message, window) < 0) return makeError(); -} -extern fn SDL_ShowSimpleMessageBox( - flags: MessageBoxFlags, - title: ?[*:0]const u8, - message: ?[*:0]const u8, - window: ?*Window, -) i32; -//-------------------------------------------------------------------------------------------------- -// -// Audio -// -//-------------------------------------------------------------------------------------------------- -pub const AUDIO_MASK_BITSIZE = @as(c_int, 0xFF); -pub const AUDIO_MASK_DATATYPE = @as(c_int, 1) << @as(c_int, 8); -pub const AUDIO_MASK_ENDIAN = @as(c_int, 1) << @as(c_int, 12); -pub const AUDIO_MASK_SIGNED = @as(c_int, 1) << @as(c_int, 15); -pub inline fn AUDIO_BITSIZE(x: c_int) c_int { - return x & AUDIO_MASK_BITSIZE; -} -pub inline fn AUDIO_ISFLOAT(x: c_int) bool { - return (x & AUDIO_MASK_DATATYPE) != 0; -} -pub inline fn AUDIO_ISBIGENDIAN(x: c_int) bool { - return (x & AUDIO_MASK_ENDIAN) != 0; -} -pub inline fn AUDIO_ISSIGNED(x: c_int) bool { - return (x & AUDIO_MASK_SIGNED) != 0; -} -pub inline fn AUDIO_ISINT(x: c_int) bool { - return !AUDIO_ISFLOAT(x); -} -pub inline fn AUDIO_ISLITTLEENDIAN(x: c_int) bool { - return !AUDIO_ISBIGENDIAN(x); -} -pub inline fn AUDIO_ISUNSIGNED(x: c_int) bool { - return !AUDIO_ISSIGNED(x); -} -pub const AUDIO_U8 = 0x0008; -pub const AUDIO_S8 = 0x8008; -pub const AUDIO_U16LSB = 0x0010; -pub const AUDIO_S16LSB = 0x8010; -pub const AUDIO_U16MSB = 0x1010; -pub const AUDIO_S16MSB = 0x9010; -pub const AUDIO_U16 = AUDIO_U16LSB; -pub const AUDIO_S16 = AUDIO_S16LSB; -pub const AUDIO_S32LSB = 0x8020; -pub const AUDIO_S32MSB = 0x9020; -pub const AUDIO_S32 = AUDIO_S32LSB; -pub const AUDIO_F32LSB = 0x8120; -pub const AUDIO_F32MSB = 0x9120; -pub const AUDIO_F32 = AUDIO_F32LSB; -pub const AUDIO_U16SYS = switch (builtin.target.cpu.arch.endian()) { - .Little => AUDIO_U16LSB, - .Big => AUDIO_U16MSB, -}; -pub const AUDIO_S16SYS = switch (builtin.target.cpu.arch.endian()) { - .Little => AUDIO_S16LSB, - .Big => AUDIO_S16MSB, -}; -pub const AUDIO_S32SYS = switch (builtin.target.cpu.arch.endian()) { - .Little => AUDIO_S32LSB, - .Big => AUDIO_S32MSB, -}; -pub const AUDIO_F32SYS = switch (builtin.target.cpu.arch.endian()) { - .Little => AUDIO_F32LSB, - .Big => AUDIO_F32MSB, -}; - -pub const AudioCallback = *const fn ( - userdata: ?*anyopaque, - stream: [*c]u8, - len: c_int, -) callconv(.C) void; - -pub const AudioFormat = u16; - -pub const AudioSpec = extern struct { - freq: c_int, - format: AudioFormat, - channels: u8, - silence: u8 = 0, - samples: u16, - size: u32 = undefined, - callback: ?AudioCallback = null, - userdata: ?*anyopaque = null, -}; - -pub const AudioDeviceId = u32; - -pub fn openAudioDevice( - maybe_device: ?[:0]const u8, - iscapture: bool, - desired: *const AudioSpec, - obtained: *AudioSpec, - allowed_changes: c_int, -) AudioDeviceId { - return SDL_OpenAudioDevice( - if (maybe_device) |device| device.ptr else null, - if (iscapture) 1 else 0, - desired, - obtained, - allowed_changes, - ); -} -extern fn SDL_OpenAudioDevice( - device: ?[*:0]const u8, - iscapture: c_int, - desired: *const AudioSpec, - obtained: *AudioSpec, - allowed_changes: c_int, -) AudioDeviceId; - -pub fn pauseAudioDevice(device: AudioDeviceId, pause: bool) void { - SDL_PauseAudioDevice(device, if (pause) 1 else 0); -} -extern fn SDL_PauseAudioDevice(AudioDeviceId, pause: c_int) void; - -pub fn queueAudio(comptime SampleType: type, device: AudioDeviceId, data: []const SampleType) bool { - return SDL_QueueAudio(device, data.ptr, @sizeOf(SampleType) * @as(u32, @intCast(data.len))) == 0; -} -extern fn SDL_QueueAudio(AudioDeviceId, data: *const anyopaque, len: u32) c_int; - -/// `pub fn getQueuedAudioSize(device: AudioDeviceId) u32` -pub const getQueuedAudioSize = SDL_GetQueuedAudioSize; -extern fn SDL_GetQueuedAudioSize(AudioDeviceId) u32; - -/// `pub fn clearQueueAudio(device: AudioDeviceId) void` -pub const clearQueuedAudio = SDL_ClearQueuedAudio; -extern fn SDL_ClearQueuedAudio(AudioDeviceId) void; -//-------------------------------------------------------------------------------------------------- -// -// Timer -// -//-------------------------------------------------------------------------------------------------- -/// `pub fn getPerformanceCounter() u64` -pub const getPerformanceCounter = SDL_GetPerformanceCounter; -extern fn SDL_GetPerformanceCounter() u64; - -/// `pub fn getPerformanceFrequency() u64` -pub const getPerformanceFrequency = SDL_GetPerformanceFrequency; -extern fn SDL_GetPerformanceFrequency() u64; - -/// `pub fn delay(ms: u32) void` -pub const delay = SDL_Delay; -extern fn SDL_Delay(ms: u32) void; -//-------------------------------------------------------------------------------------------------- -// -// File Abstraction -// -//-------------------------------------------------------------------------------------------------- -pub fn getBasePath() ?[]const u8 { - return if (SDL_GetBasePath()) |path| std.mem.span(path) else null; -} -extern fn SDL_GetBasePath() [*c]const u8; - -pub fn getPrefPath(org: [:0]const u8, app: [:0]const u8) ?[]const u8 { - return if (SDL_GetPrefPath(org.ptr, app.ptr)) |path| std.mem.span(path) else null; -} -extern fn SDL_GetPrefPath(org: [*c]const u8, app: [*c]const u8) [*c]const u8; -//-------------------------------------------------------------------------------------------------- -// -// OpenGL -// -//-------------------------------------------------------------------------------------------------- -pub const gl = struct { - pub const Context = *anyopaque; - - pub const Attr = enum(i32) { - red_size, - green_size, - blue_size, - alpha_size, - buffer_size, - doublebuffer, - depth_size, - stencil_size, - accum_red_size, - accum_green_size, - accum_blue_size, - accum_alpha_size, - stereo, - multisamplebuffers, - multisamplesamples, - accelerated_visual, - retained_backing, - context_major_version, - context_minor_version, - context_egl, - context_flags, - context_profile_mask, - share_with_current_context, - framebuffer_srgb_capable, - context_release_behavior, - context_reset_notification, - context_no_error, - floatbuffers, - }; - - pub const Profile = enum(i32) { - core = 0x0001, - compatibility = 0x0002, - es = 0x0004, - }; - - pub const ContextFlags = packed struct(i32) { - debug: bool = false, - forward_compatible: bool = false, - robust_access: bool = false, - reset_isolation: bool = false, - __unused: i28 = 0, - }; - - pub const ContextReleaseFlags = packed struct(i32) { - flush: bool = false, - __unused: i31 = 0, - }; - - pub const ContextResetNotification = enum(i32) { - no_notification = 0x0000, - lose_context = 0x0001, - }; - - pub fn setAttribute(attr: Attr, value: i32) Error!void { - if (SDL_GL_SetAttribute(attr, value) < 0) return makeError(); - } - extern fn SDL_GL_SetAttribute(attr: Attr, value: i32) i32; - - pub fn getAttribute(attr: Attr) Error!i32 { - var value: i32 = undefined; - if (SDL_GL_GetAttribute(attr, &value) < 0) return makeError(); - return value; - } - extern fn SDL_GL_GetAttribute(attr: Attr, value: i32) i32; - - pub fn setSwapInterval(interval: i32) Error!void { - if (SDL_GL_SetSwapInterval(interval) < 0) return makeError(); - } - extern fn SDL_GL_SetSwapInterval(interval: i32) i32; - - /// `pub fn getSwapInterval() i32` - pub const getSwapInterval = SDL_GL_GetSwapInterval; - extern fn SDL_GL_GetSwapInterval() i32; - - /// `pub fn swapWindow(window: *Window) void` - pub const swapWindow = SDL_GL_SwapWindow; - extern fn SDL_GL_SwapWindow(window: *Window) void; - - pub fn getProcAddress(proc: [:0]const u8) ?*anyopaque { - return SDL_GL_GetProcAddress(proc); - } - extern fn SDL_GL_GetProcAddress(proc: ?[*:0]const u8) ?*anyopaque; - - pub fn isExtensionSupported(extension: [:0]const u8) bool { - return SDL_GL_ExtensionSupported(extension) != 0; - } - extern fn SDL_GL_ExtensionSupported(extension: ?[*:0]const u8) i32; - - pub fn createContext(window: *Window) Error!Context { - return SDL_GL_CreateContext(window) orelse return makeError(); - } - extern fn SDL_GL_CreateContext(window: *Window) ?Context; - - pub fn makeCurrent(window: *Window, context: Context) Error!void { - if (SDL_GL_MakeCurrent(window, context) < 0) return makeError(); - } - extern fn SDL_GL_MakeCurrent(window: *Window, context: Context) i32; - - /// `pub fn deleteContext(context: Context) void` - pub const deleteContext = SDL_GL_DeleteContext; - extern fn SDL_GL_DeleteContext(context: Context) void; - - /// `pub fn getDrawableSize(window: *Window, w: ?*i32, h: ?*i32) void` - pub const getDrawableSize = SDL_GL_GetDrawableSize; - extern fn SDL_GL_GetDrawableSize(window: *Window, w: ?*i32, h: ?*i32) void; -}; -//--------------------------------------------------------------------------------------------------