From e469f31f5eccdbe7c38216ca20df335a61bb4ce4 Mon Sep 17 00:00:00 2001 From: lmp Date: Sat, 10 Aug 2024 11:00:00 +0200 Subject: [PATCH] all: run vfmt over files --- .github/workflows/ci.yml | 11 +- README.md | 2 +- atomic.c.v | 137 +- audio.c.v | 1100 +++---------- bits.c.v | 5 - blendmode.c.v | 115 +- c/sdl.c.v | 6 +- clipboard.c.v | 88 +- cpuinfo.c.v | 419 +---- endian.c.v | 10 +- error.c.v | 60 +- events.c.v | 695 ++------ examples/versions/main.v | 1 + filesystem.c.v | 135 +- gamecontroller.c.v | 923 +---------- gesture.c.v | 47 +- guid.c.v | 64 - haptic.c.v | 372 ++--- hidapi.c.v | 419 ----- hints.c.v | 2567 ++++++------------------------ image/c.c.v | 6 +- image/image.c.v | 2 +- joystick.c.v | 853 +--------- keyboard.c.v | 258 +-- keycode.c.v | 15 +- loadso.c.v | 46 +- locale.c.v | 63 - log.c.v | 76 +- main.c.v | 39 +- main_ios.c.v | 22 - main_windows.c.v | 54 +- messagebox.c.v | 83 +- metal.c.v | 78 - misc.c.v | 41 - mixer/c.c.v | 6 +- mixer/mixer.c.v | 4 +- mouse.c.v | 332 +--- mutex.c.v | 346 +--- pixels.c.v | 230 +-- platform.c.v | 15 - power.c.v | 33 +- rect.c.v | 230 +-- render.c.v | 1673 ++++--------------- rwops.c.v | 637 +------- scancode.c.v | 73 +- sdl.c.v | 123 +- sensor.c.v | 311 ---- shape.c.v | 55 +- stdinc.c.v | 230 +-- surface.c.v | 680 ++------ system.c.v | 45 - system_android.c.v | 206 +-- system_ios.c.v | 51 +- system_linux.c.v | 42 - system_windows.c.v | 137 +- thread.c.v | 323 ++-- timer.c.v | 137 +- touch.c.v | 77 +- ttf/c.c.v | 6 +- ttf/ttf.c.v | 24 +- v.mod | 2 +- version.c.v | 68 +- video.c.v | 1743 +++++--------------- vulkan/vulkan.c.v | 234 ++- windows_install_dependencies.vsh | 8 +- 65 files changed, 2796 insertions(+), 14097 deletions(-) delete mode 100644 guid.c.v delete mode 100644 hidapi.c.v delete mode 100644 locale.c.v delete mode 100644 main_ios.c.v delete mode 100644 metal.c.v delete mode 100644 misc.c.v delete mode 100644 sensor.c.v delete mode 100644 system_linux.c.v diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4898cf9c..18688f77 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,12 +14,12 @@ jobs: timeout-minutes: 30 env: VFLAGS: -cc tcc -no-retry-compilation - SDL2_VERSION: 2.30.0 + SDL2_VERSION: 2.0.8 steps: - name: Install dependencies run: | sudo apt-get update - sudo apt-get install --quiet -y libsdl2-ttf-dev + sudo apt-get install --quiet -y libsdl2-dev libsdl2-ttf-dev sudo apt-get install --quiet -y libsdl2-mixer-dev libsdl2-image-dev curl -L https://www.libsdl.org/release/SDL2-${SDL2_VERSION}.tar.gz -o SDL2.tar.gz tar -zxvf SDL2.tar.gz @@ -81,7 +81,7 @@ jobs: runs-on: macos-12 timeout-minutes: 60 env: - SDL2_VERSION: 2.30.0 + SDL2_VERSION: 2.0.8 steps: - name: Checkout V uses: actions/checkout@v2 @@ -150,8 +150,9 @@ jobs: timeout-minutes: 30 env: VFLAGS: -cc gcc -no-retry-compilation - SDL2_VERSION: 2.30.0 + SDL2_VERSION: 2.0.8 steps: + - name: Install V uses: vlang/setup-v@v1 with: @@ -185,7 +186,7 @@ jobs: timeout-minutes: 30 env: VFLAGS: -cc tcc -no-retry-compilation - SDL2_VERSION: 2.30.0 + SDL2_VERSION: 2.0.8 steps: - name: Install V diff --git a/README.md b/README.md index 3879005e..53176fde 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,7 @@ This will create a directory called "thirdparty" which will be used to download To successfully run a provided example or your own projects, the sdl dlls must be copied to the main application directory. e.g.: ```bash -copy thirdparty\SDL2-2.30.0\lib\x64\SDL2.dll examples\basic_window\ +copy thirdparty\SDL2-2.0.8\lib\x64\SDL2.dll examples\basic_window\ cd .. v run sdl\examples\basic_window\main.v ``` diff --git a/atomic.c.v b/atomic.c.v index 99cc216a..54bb0e1c 100644 --- a/atomic.c.v +++ b/atomic.c.v @@ -62,16 +62,9 @@ fn C.SDL_AtomicTryLock(lock_ &C.SDL_SpinLock) bool // atomic_try_lock tries to lock a spin lock by setting it to a non-zero value. // -// ***Please note that spinlocks are dangerous if you don't know what you're -// doing. Please be careful using any sort of spinlock!*** -// `lock_` a pointer to a lock variable +// `lock_` points to the lock. // // returns SDL_TRUE if the lock succeeded, SDL_FALSE if the lock is already held. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_AtomicLock -// See also: SDL_AtomicUnlock pub fn atomic_try_lock(lock_ &SpinLock) bool { return unsafe { C.SDL_AtomicTryLock(&C.SDL_SpinLock(lock_)) } } @@ -80,34 +73,16 @@ fn C.SDL_AtomicLock(lock_ &C.SDL_SpinLock) // atomic_lock locks a spin lock by setting it to a non-zero value. // -// ***Please note that spinlocks are dangerous if you don't know what you're -// doing. Please be careful using any sort of spinlock!*** -// -// `lock_` a pointer to a lock variable -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_AtomicTryLock -// See also: SDL_AtomicUnlock +// `lock_` points to the lock. pub fn atomic_lock(lock_ &SpinLock) { unsafe { C.SDL_AtomicLock(&C.SDL_SpinLock(lock_)) } } fn C.SDL_AtomicUnlock(lock_ &C.SDL_SpinLock) -// atomic_unlock unlocks a spin lock by setting it to 0. -// -// Always returns immediately. -// -// ***Please note that spinlocks are dangerous if you don't know what you're -// doing. Please be careful using any sort of spinlock!*** -// -// `lock_` a pointer to a lock variable -// -// NOTE This function is available since SDL 2.0.0. +// atomic_unlock unlocks a spin lock by setting it to 0. Always returns immediately // -// See also: SDL_AtomicLock -// See also: SDL_AtomicTryLock +// `lock_` Points to the lock. pub fn atomic_unlock(lock_ &SpinLock) { unsafe { C.SDL_AtomicUnlock(&C.SDL_SpinLock(lock_)) } } @@ -115,22 +90,20 @@ pub fn atomic_unlock(lock_ &SpinLock) { // Memory barriers are designed to prevent reads and writes from being // reordered by the compiler and being seen out of order on multi-core CPUs. // -// A typical pattern would be for thread A to write some data and a flag, and -// for thread B to read the flag and get the data. In this case you would -// insert a release barrier between writing the data and the flag, +// A typical pattern would be for thread A to write some data and a flag, +// and for thread B to read the flag and get the data. In this case you +// would insert a release barrier between writing the data and the flag, // guaranteeing that the data write completes no later than the flag is -// written, and you would insert an acquire barrier between reading the flag -// and reading the data, to ensure that all the reads associated with the flag -// have completed. +// written, and you would insert an acquire barrier between reading the +// flag and reading the data, to ensure that all the reads associated +// with the flag have completed. // -// In this pattern you should always see a release barrier paired with an -// acquire barrier and you should gate the data reads/writes with a single -// flag variable. +// In this pattern you should always see a release barrier paired with +// an acquire barrier and you should gate the data reads/writes with a +// single flag variable. // // For more information on these semantics, take a look at the blog post: // http://preshing.com/20120913/acquire-and-release-semantics -// -// NOTE This function is available since SDL 2.0.6. fn C.SDL_MemoryBarrierReleaseFunction() pub fn memory_barrier_release_function() { C.SDL_MemoryBarrierReleaseFunction() @@ -155,17 +128,9 @@ fn C.SDL_AtomicCAS(a &C.SDL_atomic_t, oldval int, newval int) bool // atomic_cas sets an atomic variable to a new value if it is currently an old value. // -// NOTE If you don't know what this function is for, you shouldn't use it! -// -// `a` a pointer to an SDL_atomic_t variable to be modified -// `oldval` the old value -// `newval` the new value // returns SDL_TRUE if the atomic variable was set, SDL_FALSE otherwise. // -// NOTE This function is available since SDL 2.0.0. -// See also: SDL_AtomicCASPtr -// See also: SDL_AtomicGet -// See also: SDL_AtomicSet +// NOTE If you don't know what this function is for, you shouldn't use it! pub fn atomic_cas(a &C.SDL_atomic_t, oldval int, newval int) bool { return unsafe { C.SDL_AtomicCAS(a, oldval, newval) } } @@ -174,35 +139,14 @@ fn C.SDL_AtomicSet(a &C.SDL_atomic_t, v int) int // atomic_set sets an atomic variable to a value. // -// This function also acts as a full memory barrier. -// -// NOTE If you don't know what this function is for, you shouldn't use -// it! -// -// `a` a pointer to an SDL_atomic_t variable to be modified -// `v` the desired value -// returns the previous value of the atomic variable. -// -// NOTE This function is available since SDL 2.0.2. -// -// See also: SDL_AtomicGet +// returns The previous value of the atomic variable. pub fn atomic_set(a &AtomicT, v int) int { return unsafe { C.SDL_AtomicSet(&C.SDL_atomic_t(a), v) } } fn C.SDL_AtomicGet(a &C.SDL_atomic_t) int -// atomic_get gets the value of an atomic variable. -// -// NOTE If you don't know what this function is for, you shouldn't use -// it! -// -// `a` a pointer to an SDL_atomic_t variable -// returns the current value of an atomic variable. -// -// NOTE This function is available since SDL 2.0.2. -// -// See also: SDL_AtomicSet +// atomic_get gets the value of an atomic variable pub fn atomic_get(a &AtomicT) int { return unsafe { C.SDL_AtomicGet(&C.SDL_atomic_t(a)) } } @@ -211,19 +155,9 @@ fn C.SDL_AtomicAdd(a &C.SDL_atomic_t, v int) int // atomic_add adds to an atomic variable. // -// This function also acts as a full memory barrier. -// -// // NOTE If you don't know what this function is for, you shouldn't use -// it! -// -// `a` a pointer to an SDL_atomic_t variable to be modified -// `v` the desired value to add // returns The previous value of the atomic variable. // -// NOTE This function is available since SDL 2.0.2. -// -// See also: SDL_AtomicDecRef -// See also: SDL_AtomicIncRef +// NOTE This same style can be used for any number operation pub fn atomic_add(a &AtomicT, v int) int { return unsafe { C.SDL_AtomicAdd(&C.SDL_atomic_t(a), v) } } @@ -251,19 +185,9 @@ fn C.SDL_AtomicCASPtr(a voidptr, oldval voidptr, newval voidptr) bool // atomic_cas_ptr sets a pointer to a new value if it is currently an old value. // -// NOTE If you don't know what this function is for, you shouldn't use -// it! -// -// `a` a pointer to a pointer -// `oldval` the old pointer value -// `newval` the new pointer value // returns SDL_TRUE if the pointer was set, SDL_FALSE otherwise. // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_AtomicCAS -// See also: SDL_AtomicGetPtr -// See also: SDL_AtomicSetPtr +// NOTE If you don't know what this function is for, you shouldn't use it! // // `a`'s C type is `void **a` pub fn atomic_cas_ptr(a voidptr, oldval voidptr, newval voidptr) bool { @@ -272,20 +196,10 @@ pub fn atomic_cas_ptr(a voidptr, oldval voidptr, newval voidptr) bool { fn C.SDL_AtomicSetPtr(a voidptr, v voidptr) voidptr -// atomic_set_ptr sets a pointer to a value atomically. -// -// NOTE If you don't know what this function is for, you shouldn't use -// it! +// atomic_set_ptr set a pointer to a value atomically. // -// `a` a pointer to a pointer -// `v` the desired pointer value // returns the previous value of the pointer. // -// NOTE This function is available since SDL 2.0.2. -// -// See also: SDL_AtomicCASPtr -// See also: SDL_AtomicGetPtr -// // `a`'s C type is `void **a` pub fn atomic_set_ptr(a voidptr, v voidptr) voidptr { return C.SDL_AtomicSetPtr(a, v) @@ -293,18 +207,7 @@ pub fn atomic_set_ptr(a voidptr, v voidptr) voidptr { fn C.SDL_AtomicGetPtr(a voidptr) voidptr -// atomic_get_ptr gets a pointer to a value atomically. -// -// NOTE If you don't know what this function is for, you shouldn't use -// it! -// -// `a` a pointer to a pointer -// returns the current value of a pointer. -// -// NOTE This function is available since SDL 2.0.2. -// -// See also: SDL_AtomicCASPtr -// See also: SDL_AtomicSetPtr +// atomic_get_ptr gets the value of a pointer atomically. // // `a`'s C type is `void **a` pub fn atomic_get_ptr(a voidptr) voidptr { diff --git a/audio.c.v b/audio.c.v index c97378e4..50cb03b8 100644 --- a/audio.c.v +++ b/audio.c.v @@ -117,8 +117,6 @@ pub const audio_allow_format_change = C.SDL_AUDIO_ALLOW_FORMAT_CHANGE // 0x00000 pub const audio_allow_channels_change = C.SDL_AUDIO_ALLOW_CHANNELS_CHANGE // 0x00000004 -pub const sdl_audio_allow_samples_change = C.SDL_AUDIO_ALLOW_SAMPLES_CHANGE // 0x00000008 - pub const audio_allow_any_change = C.SDL_AUDIO_ALLOW_ANY_CHANGE // This function is called when the audio device needs more data. @@ -142,13 +140,13 @@ pub type AudioCallback = fn (userdata voidptr, stream &u8, len int) // The calculated values in this structure are calculated by SDL_OpenAudio(). // // For multi-channel audio, the default SDL channel mapping is: -// 2: FL FR (stereo) -// 3: FL FR LFE (2.1 surround) -// 4: FL FR BL BR (quad) -// 5: FL FR LFE BL BR (4.1 surround) -// 6: FL FR FC LFE SL SR (5.1 surround - last two can also be BL BR) -// 7: FL FR FC LFE BC SL SR (6.1 surround) -// 8: FL FR FC LFE BL BR SL SR (7.1 surround) +// 2: FL FR (stereo) +// 3: FL FR LFE (2.1 surround) +// 4: FL FR BL BR (quad) +// 5: FL FR FC BL BR (quad + center) +// 6: FL FR FC LFE SL SR (5.1 surround - last two can also be BL BR) +// 7: FL FR FC LFE BC SL SR (6.1 surround) +// 8: FL FR FC LFE BL BR SL SR (7.1 surround) @[typedef] pub struct C.SDL_AudioSpec { @@ -229,163 +227,87 @@ pub type AudioCVT = C.SDL_AudioCVT // // These functions return the list of built in audio drivers, in the // order that they are normally initialized by default. - -fn C.SDL_GetNumAudioDrivers() int - -// get_num_audio_drivers gets the number of built-in audio drivers. -// -// This function returns a hardcoded number. This never returns a negative -// value; if there are no drivers compiled into this build of SDL, this -// function returns zero. The presence of a driver in this list does not mean -// it will function, it just means SDL is capable of interacting with that -// interface. For example, a build of SDL might have esound support, but if -// there's no esound server available, SDL's esound driver would fail if used. -// -// By default, SDL tries all drivers, in its preferred order, until one is -// found to be usable. -// -// returns the number of built-in audio drivers. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetAudioDriver pub fn get_num_audio_drivers() int { return C.SDL_GetNumAudioDrivers() } -fn C.SDL_GetAudioDriver(index int) &char +fn C.SDL_GetNumAudioDrivers() int -// get_audio_driver gets the name of a built in audio driver. -// -// The list of audio drivers is given in the order that they are normally -// initialized by default; the drivers that seem more reasonable to choose -// first (as far as the SDL developers believe) are earlier in the list. -// -// The names of drivers are all simple, low-ASCII identifiers, like "alsa", -// "coreaudio" or "xaudio2". These never have Unicode characters, and are not -// meant to be proper names. -// -// `index` the index of the audio driver; the value ranges from 0 to -// SDL_GetNumAudioDrivers() - 1 -// returns the name of the audio driver at the requested index, or NULL if an -// invalid index was specified. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetNumAudioDrivers pub fn get_audio_driver(index int) &char { return C.SDL_GetAudioDriver(index) } +fn C.SDL_GetAudioDriver(index int) &char + // audio_init // Initialization and cleanup // // These functions are used internally, and should not be used unless // you have a specific need to specify the audio driver you want to // use. You should normally use SDL_Init() or SDL_InitSubSystem(). - -fn C.SDL_AudioInit(driver_name &char) int - -// Use this function to initialize a particular audio driver. -// -// This function is used internally, and should not be used unless you have a -// specific need to designate the audio driver you want to use. You should -// normally use SDL_Init() or SDL_InitSubSystem(). -// -// `driver_name` the name of the desired audio driver -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_AudioQuit pub fn audio_init(driver_name &char) int { return C.SDL_AudioInit(driver_name) } -fn C.SDL_AudioQuit() +fn C.SDL_AudioInit(driver_name &char) int -// Use this function to shut down audio if you initialized it with -// SDL_AudioInit(). -// -// This function is used internally, and should not be used unless you have a -// specific need to specify the audio driver you want to use. You should -// normally use SDL_Quit() or SDL_QuitSubSystem(). -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_AudioInit pub fn audio_quit() { C.SDL_AudioQuit() } -// get_current_audio_driver gets the name of the current audio driver. -// -// The returned string points to internal static memory and thus never becomes -// invalid, even if you quit the audio subsystem and initialize a new driver -// (although such a case would return a different static string from another -// call to this function, of course). As such, you should not modify or free -// the returned string. -// -// returns the name of the current audio driver or NULL if no driver has been -// initialized. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_AudioInit +fn C.SDL_AudioQuit() + +// get_current_audio_driver returns the name of the current audio driver, or NULL +// if no driver has been initialized. pub fn get_current_audio_driver() &char { return C.SDL_GetCurrentAudioDriver() } fn C.SDL_GetCurrentAudioDriver() &char -// This function is a legacy means of opening the audio device. -// -// This function remains for compatibility with SDL 1.2, but also because it's -// slightly easier to use than the new functions in SDL 2.0. The new, more -// powerful, and preferred way to do this is SDL_OpenAudioDevice(). -// -// This function is roughly equivalent to: -// -/* -```c -SDL_OpenAudioDevice(NULL, 0, desired, obtained, SDL_AUDIO_ALLOW_ANY_CHANGE); -``` -*/ -// -// With two notable exceptions: -// -// - If `obtained` is NULL, we use `desired` (and allow no changes), which -// means desired will be modified to have the correct values for silence, -// etc, and SDL will convert any differences between your app's specific -// request and the hardware behind the scenes. -// - The return value is always success or failure, and not a device ID, which -// means you can only have one device open at a time with this function. -// -// `desired` an SDL_AudioSpec structure representing the desired output -// format. Please refer to the SDL_OpenAudioDevice -// documentation for details on how to prepare this structure. -// `obtained` an SDL_AudioSpec structure filled in with the actual -// parameters, or NULL. +// open_audio opens the audio device with the desired parameters, and // returns 0 if successful, placing the actual hardware parameters in the -// structure pointed to by `obtained`. -// -// If `obtained` is NULL, the audio data passed to the callback -// function will be guaranteed to be in the requested format, and -// will be automatically converted to the actual hardware audio -// format if necessary. If `obtained` is NULL, `desired` will have -// fields modified. -// -// This function returns a negative error code on failure to open the -// audio device or failure to set up the audio thread; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_CloseAudio -// See also: SDL_LockAudio -// See also: SDL_PauseAudio -// See also: SDL_UnlockAudio +// structure pointed to by `obtained`. If `obtained` is NULL, the audio +// data passed to the callback function will be guaranteed to be in the +// requested format, and will be automatically converted to the hardware +// audio format if necessary. This function returns -1 if it failed +// to open the audio device, or couldn't set up the audio thread. +// +// When filling in the desired audio spec structure, +// - `desired->freq` should be the desired audio frequency in samples-per- +// second. +// - `desired->format` should be the desired audio format. +// - `desired->samples` is the desired size of the audio buffer, in +// samples. This number should be a power of two, and may be adjusted by +// the audio driver to a value more suitable for the hardware. Good values +// seem to range between 512 and 8096 inclusive, depending on the +// application and CPU speed. Smaller values yield faster response time, +// but can lead to underflow if the application is doing heavy processing +// and cannot fill the audio buffer in time. A stereo sample consists of +// both right and left channels in LR ordering. +// Note that the number of samples is directly related to time by the +// following formula: ` ms = (samples*1000)/freq ` +// - `desired->size` is the size in bytes of the audio buffer, and is +// calculated by SDL_OpenAudio(). +// - `desired->silence` is the value used to set the buffer to silence, +// and is calculated by SDL_OpenAudio(). +// - `desired->callback` should be set to a function that will be called +// when the audio device is ready for more data. It is passed a pointer +// to the audio buffer, and the length in bytes of the audio buffer. +// This function usually runs in a separate thread, and so you should +// protect data structures that it accesses by calling SDL_LockAudio() +// and SDL_UnlockAudio() in your code. Alternately, you may pass a NULL +// pointer here, and call SDL_QueueAudio() with some frequency, to queue +// more audio samples to be played (or for capture devices, call +// SDL_DequeueAudio() with some frequency, to obtain audio samples). +// - `desired->userdata` is passed as the first parameter to your callback +// function. If you passed a NULL callback, this value is ignored. +// +// The audio device starts out playing silence when it's opened, and should +// be enabled for playing by calling `SDL_PauseAudio`(0) when you are ready +// for your audio callback function to be called. Since the audio driver +// may modify the requested size of the audio buffer, you should allocate +// any local mixing buffers after you open the audio device. pub fn open_audio(desired &AudioSpec, obtained &AudioSpec) int { return C.SDL_OpenAudio(desired, obtained) } @@ -404,255 +326,53 @@ fn C.SDL_OpenAudio(desired &C.SDL_AudioSpec, obtained &C.SDL_AudioSpec) int // `typedef Uint32 SDL_AudioDeviceID;` pub type AudioDeviceID = u32 -fn C.SDL_GetNumAudioDevices(iscapture int) int - -// get_num_audio_devices gets the number of built-in audio devices. -// -// This function is only valid after successfully initializing the audio -// subsystem. -// -// Note that audio capture support is not implemented as of SDL 2.0.4, so the -// `iscapture` parameter is for future expansion and should always be zero for -// now. -// -// This function will return -1 if an explicit list of devices can't be -// determined. Returning -1 is not an error. For example, if SDL is set up to -// talk to a remote audio server, it can't list every one available on the -// Internet, but it will still allow a specific host to be specified in -// SDL_OpenAudioDevice(). +// get_num_audio_devices gets the number of available +// devices exposed by the current driver. +// Only valid after a successfully initializing the audio subsystem. +// Returns -1 if an explicit list of devices can't be determined; this is +// not an error. For example, if SDL is set up to talk to a remote audio +// server, it can't list every one available on the Internet, but it will +// still allow a specific host to be specified to SDL_OpenAudioDevice(). // // In many common cases, when this function returns a value <= 0, it can still // successfully open the default device (NULL for first argument of // SDL_OpenAudioDevice()). -// -// This function may trigger a complete redetect of available hardware. It -// should not be called for each iteration of a loop, but rather once at the -// start of a loop: -// -/* -```c -// Don't do this: -for (int i = 0; i < SDL_GetNumAudioDevices(0); i++) - -// do this instead: -const int count = SDL_GetNumAudioDevices(0); -for (int i = 0; i < count; ++i) { do_something_here(); } -``` -*/ -// -// `iscapture` zero to request playback devices, non-zero to request -// recording devices -// returns the number of available devices exposed by the current driver or -// -1 if an explicit list of devices can't be determined. A return -// value of -1 does not necessarily mean an error condition. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetAudioDeviceName -// See also: SDL_OpenAudioDevice pub fn get_num_audio_devices(iscapture int) int { return C.SDL_GetNumAudioDevices(iscapture) } -fn C.SDL_GetAudioDeviceName(index int, iscapture int) &char +fn C.SDL_GetNumAudioDevices(iscapture int) int -// get_audio_device_name gets the human-readable name of a specific audio device. -// -// This function is only valid after successfully initializing the audio -// subsystem. The values returned by this function reflect the latest call to -// SDL_GetNumAudioDevices(); re-call that function to redetect available +// get_audio_device_name gets the human-readable +// name of a specific audio device. +// Must be a value between 0 and (number of audio devices-1). +// Only valid after a successfully initializing the audio subsystem. +// The values returned by this function reflect the latest call to +// SDL_GetNumAudioDevices(); recall that function to redetect available // hardware. // // The string returned by this function is UTF-8 encoded, read-only, and -// managed internally. You are not to free it. If you need to keep the string -// for any length of time, you should make your own copy of it, as it will be -// invalid next time any of several other SDL functions are called. -// -// `index` the index of the audio device; valid values range from 0 to -// SDL_GetNumAudioDevices() - 1 -// `iscapture` non-zero to query the list of recording devices, zero to -// query the list of output devices. -// returns the name of the audio device at the requested index, or NULL on -// error. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetNumAudioDevices -// See also: SDL_GetDefaultAudioInfo +// managed internally. You are not to free it. If you need to keep the +// string for any length of time, you should make your own copy of it, as it +// will be invalid next time any of several other SDL functions is called. pub fn get_audio_device_name(index int, iscapture int) &char { return C.SDL_GetAudioDeviceName(index, iscapture) } -fn C.SDL_GetAudioDeviceSpec(index int, iscapture int, spec &C.SDL_AudioSpec) int - -// get_audio_device_spec gets the preferred audio format of a specific audio device. -// -// This function is only valid after a successfully initializing the audio -// subsystem. The values returned by this function reflect the latest call to -// SDL_GetNumAudioDevices(); re-call that function to redetect available -// hardware. -// -// `spec` will be filled with the sample rate, sample format, and channel -// count. -// -// `index` the index of the audio device; valid values range from 0 to -// SDL_GetNumAudioDevices() - 1 -// `iscapture` non-zero to query the list of recording devices, zero to -// query the list of output devices. -// `spec` The SDL_AudioSpec to be initialized by this function. -// returns 0 on success, nonzero on error -// -// NOTE This function is available since SDL 2.0.16. -// -// See also: SDL_GetNumAudioDevices -// See also: SDL_GetDefaultAudioInfo -pub fn get_audio_device_spec(index int, iscapture int, spec &AudioSpec) int { - return C.SDL_GetAudioDeviceSpec(index, iscapture, spec) -} - -fn C.SDL_GetDefaultAudioInfo(name &&char, spec &AudioSpec, iscapture int) int - -// get_default_audio_info gets the name and preferred format of the default audio device. -// -// Some (but not all!) platforms have an isolated mechanism to get information -// about the "default" device. This can actually be a completely different -// device that's not in the list you get from SDL_GetAudioDeviceSpec(). It can -// even be a network address! (This is discussed in SDL_OpenAudioDevice().) -// -// As a result, this call is not guaranteed to be performant, as it can query -// the sound server directly every time, unlike the other query functions. You -// should call this function sparingly! -// -// `spec` will be filled with the sample rate, sample format, and channel -// count, if a default device exists on the system. If `name` is provided, -// will be filled with either a dynamically-allocated UTF-8 string or NULL. -// -// `name`` A pointer to be filled with the name of the default device (can -// be NULL). Please call SDL_free() when you are done with this -// pointer! -// `spec`` The SDL_AudioSpec to be initialized by this function. -// `iscapture` non-zero to query the default recording device, zero to -// query the default output device. -// returns 0 on success, nonzero on error -// -// NOTE This function is available since SDL 2.24.0. -// -// See also: SDL_GetAudioDeviceName -// See also: SDL_GetAudioDeviceSpec -// See also: SDL_OpenAudioDevice -pub fn get_default_audio_info(name &&char, spec &AudioSpec, iscapture int) int { - return C.SDL_GetDefaultAudioInfo(name, spec, iscapture) -} +fn C.SDL_GetAudioDeviceName(index int, iscapture int) &char // open_audio_device opens a specific audio device. +// Passing in a device name of NULL requests +// the most reasonable default (and is equivalent to calling SDL_OpenAudio()). // -// SDL_OpenAudio(), unlike this function, always acts on device ID 1. As such, -// this function will never return a 1 so as not to conflict with the legacy -// function. -// -// Please note that SDL 2.0 before 2.0.5 did not support recording; as such, -// this function would fail if `iscapture` was not zero. Starting with SDL -// 2.0.5, recording is implemented and this value can be non-zero. -// -// Passing in a `device` name of NULL requests the most reasonable default -// (and is equivalent to what SDL_OpenAudio() does to choose a device). The -// `device` name is a UTF-8 string reported by SDL_GetAudioDeviceName(), but +// The device name is a UTF-8 string reported by SDL_GetAudioDeviceName(), but // some drivers allow arbitrary and driver-specific strings, such as a // hostname/IP address for a remote audio server, or a filename in the // diskaudio driver. // -// An opened audio device starts out paused, and should be enabled for playing -// by calling SDL_PauseAudioDevice(devid, 0) when you are ready for your audio -// callback function to be called. Since the audio driver may modify the -// requested size of the audio buffer, you should allocate any local mixing -// buffers after you open the audio device. -// -// The audio callback runs in a separate thread in most cases; you can prevent -// race conditions between your callback and other threads without fully -// pausing playback with SDL_LockAudioDevice(). For more information about the -// callback, see SDL_AudioSpec. -// -// Managing the audio spec via 'desired' and 'obtained': -// -// When filling in the desired audio spec structure: -// -// - `desired->freq` should be the frequency in sample-frames-per-second (Hz). -// - `desired->format` should be the audio format (`AUDIO_S16SYS`, etc). -// - `desired->samples` is the desired size of the audio buffer, in _sample -// frames_ (with stereo output, two samples--left and right--would make a -// single sample frame). This number should be a power of two, and may be -// adjusted by the audio driver to a value more suitable for the hardware. -// Good values seem to range between 512 and 8096 inclusive, depending on -// the application and CPU speed. Smaller values reduce latency, but can -// lead to underflow if the application is doing heavy processing and cannot -// fill the audio buffer in time. Note that the number of sample frames is -// directly related to time by the following formula: `ms = -// (sampleframes*1000)/freq` -// - `desired->size` is the size in _bytes_ of the audio buffer, and is -// calculated by SDL_OpenAudioDevice(). You don't initialize this. -// - `desired->silence` is the value used to set the buffer to silence, and is -// calculated by SDL_OpenAudioDevice(). You don't initialize this. -// - `desired->callback` should be set to a function that will be called when -// the audio device is ready for more data. It is passed a pointer to the -// audio buffer, and the length in bytes of the audio buffer. This function -// usually runs in a separate thread, and so you should protect data -// structures that it accesses by calling SDL_LockAudioDevice() and -// SDL_UnlockAudioDevice() in your code. Alternately, you may pass a NULL -// pointer here, and call SDL_QueueAudio() with some frequency, to queue -// more audio samples to be played (or for capture devices, call -// SDL_DequeueAudio() with some frequency, to obtain audio samples). -// - `desired->userdata` is passed as the first parameter to your callback -// function. If you passed a NULL callback, this value is ignored. -// -// `allowed_changes` can have the following flags OR'd together: -// -// - `SDL_AUDIO_ALLOW_FREQUENCY_CHANGE` -// - `SDL_AUDIO_ALLOW_FORMAT_CHANGE` -// - `SDL_AUDIO_ALLOW_CHANNELS_CHANGE` -// - `SDL_AUDIO_ALLOW_SAMPLES_CHANGE` -// - `SDL_AUDIO_ALLOW_ANY_CHANGE` -// -// These flags specify how SDL should behave when a device cannot offer a -// specific feature. If the application requests a feature that the hardware -// doesn't offer, SDL will always try to get the closest equivalent. -// -// For example, if you ask for float32 audio format, but the sound card only -// supports int16, SDL will set the hardware to int16. If you had set -// SDL_AUDIO_ALLOW_FORMAT_CHANGE, SDL will change the format in the `obtained` -// structure. If that flag was *not* set, SDL will prepare to convert your -// callback's float32 audio to int16 before feeding it to the hardware and -// will keep the originally requested format in the `obtained` structure. -// -// The resulting audio specs, varying depending on hardware and on what -// changes were allowed, will then be written back to `obtained`. -// -// If your application can only handle one specific data format, pass a zero -// for `allowed_changes` and let SDL transparently handle any differences. -// -// `device` a UTF-8 string reported by SDL_GetAudioDeviceName() or a -// driver-specific name as appropriate. NULL requests the most -// reasonable default device. -// `iscapture` non-zero to specify a device should be opened for -// recording, not playback -// `desired` an SDL_AudioSpec structure representing the desired output -// format; see SDL_OpenAudio() for more information -// `obtained` an SDL_AudioSpec structure filled in with the actual output -// format; see SDL_OpenAudio() for more information -// `allowed_changes` 0, or one or more flags OR'd together -// returns a valid device ID that is > 0 on success or 0 on failure; call -// SDL_GetError() for more information. -// -// For compatibility with SDL 1.2, this will never return 1, since -// SDL reserves that ID for the legacy SDL_OpenAudio() function. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_CloseAudioDevice -// See also: SDL_GetAudioDeviceName -// See also: SDL_LockAudioDevice -// See also: SDL_OpenAudio -// See also: SDL_PauseAudioDevice -// See also: SDL_UnlockAudioDevice +// returns 0 on error, a valid device ID that is >= 2 on success. +// +// SDL_OpenAudio(), unlike this function, always acts on device ID 1. pub fn open_audio_device(const_device &char, iscapture int, const_desired &AudioSpec, obtained &AudioSpec, allowed_changes int) AudioDeviceID { return u32(C.SDL_OpenAudioDevice(const_device, iscapture, const_desired, obtained, allowed_changes)) @@ -672,43 +392,18 @@ pub enum AudioStatus { audio_paused = C.SDL_AUDIO_PAUSED } -fn C.SDL_GetAudioStatus() AudioStatus - -// get_audio_status is a legacy means of querying the audio device. -// -// New programs might want to use SDL_GetAudioDeviceStatus() instead. This -// function is equivalent to calling... -// -// ```c -// SDL_GetAudioDeviceStatus(1); -// ``` -// -// ...and is only useful if you used the legacy SDL_OpenAudio() function. -// -// returns the SDL_AudioStatus of the audio device opened by SDL_OpenAudio(). -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetAudioDeviceStatus pub fn get_audio_status() AudioStatus { return AudioStatus(C.SDL_GetAudioStatus()) } -fn C.SDL_GetAudioDeviceStatus(dev AudioDeviceID) AudioStatus +fn C.SDL_GetAudioStatus() AudioStatus -// get_audio_device_status gets the current audio state of an audio device. -// -// `dev` the ID of an audio device previously opened with -// SDL_OpenAudioDevice() -// returns the SDL_AudioStatus of the specified audio device. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_PauseAudioDevice pub fn get_audio_device_status(dev AudioDeviceID) AudioStatus { return AudioStatus(C.SDL_GetAudioDeviceStatus(dev)) } +fn C.SDL_GetAudioDeviceStatus(dev AudioDeviceID) AudioStatus + // Pause audio functions // // These functions pause and unpause the audio callback processing. @@ -716,149 +411,37 @@ pub fn get_audio_device_status(dev AudioDeviceID) AudioStatus { // device to start playing sound. This is so you can safely initialize // data for your callback function after opening the audio device. // Silence will be written to the audio device during the pause. - -fn C.SDL_PauseAudio(pause_on int) - -// pause_audio is a legacy means of pausing the audio device. -// -// New programs might want to use SDL_PauseAudioDevice() instead. This -// function is equivalent to calling... -// -/* -```c - SDL_PauseAudioDevice(1, pause_on); -``` -*/ -// -// ...and is only useful if you used the legacy SDL_OpenAudio() function. -// -// `pause_on` non-zero to pause, 0 to unpause -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetAudioStatus -// See also: SDL_PauseAudioDevice pub fn pause_audio(pause_on int) { C.SDL_PauseAudio(pause_on) } -fn C.SDL_PauseAudioDevice(dev C.SDL_AudioDeviceID, pause_on int) +fn C.SDL_PauseAudio(pause_on int) -// Use this function to pause and unpause audio playback on a specified -// device. -// -// This function pauses and unpauses the audio callback processing for a given -// device. Newly-opened audio devices start in the paused state, so you must -// call this function with **pause_on**=0 after opening the specified audio -// device to start playing sound. This allows you to safely initialize data -// for your callback function after opening the audio device. Silence will be -// written to the audio device while paused, and the audio callback is -// guaranteed to not be called. Pausing one device does not prevent other -// unpaused devices from running their callbacks. -// -// Pausing state does not stack; even if you pause a device several times, a -// single unpause will start the device playing again, and vice versa. This is -// different from how SDL_LockAudioDevice() works. -// -// If you just need to protect a few variables from race conditions vs your -// callback, you shouldn't pause the audio device, as it will lead to dropouts -// in the audio playback. Instead, you should use SDL_LockAudioDevice(). -// -// `dev` a device opened by SDL_OpenAudioDevice() -// `pause_on` non-zero to pause, 0 to unpause -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_LockAudioDevice +fn C.SDL_PauseAudioDevice(dev C.SDL_AudioDeviceID, pause_on int) pub fn pause_audio_device(dev AudioDeviceID, pause_on int) { C.SDL_PauseAudioDevice(C.SDL_AudioDeviceID(dev), pause_on) } fn C.SDL_LoadWAV_RW(src &C.SDL_RWops, freesrc int, spec &C.SDL_AudioSpec, audio_buf &&u8, audio_len &u32) &C.SDL_AudioSpec -// load_wav_rw loads the audio data of a WAVE file into memory. -// -// Loading a WAVE file requires `src`, `spec`, `audio_buf` and `audio_len` to -// be valid pointers. The entire data portion of the file is then loaded into -// memory and decoded if necessary. -// -// If `freesrc` is non-zero, the data source gets automatically closed and -// freed before the function returns. -// -// Supported formats are RIFF WAVE files with the formats PCM (8, 16, 24, and -// 32 bits), IEEE Float (32 bits), Microsoft ADPCM and IMA ADPCM (4 bits), and -// A-law and mu-law (8 bits). Other formats are currently unsupported and -// cause an error. -// -// If this function succeeds, the pointer returned by it is equal to `spec` -// and the pointer to the audio data allocated by the function is written to -// `audio_buf` and its length in bytes to `audio_len`. The SDL_AudioSpec -// members `freq`, `channels`, and `format` are set to the values of the audio -// data in the buffer. The `samples` member is set to a sane default and all -// others are set to zero. -// -// It's necessary to use SDL_FreeWAV() to free the audio data returned in -// `audio_buf` when it is no longer used. -// -// Because of the underspecification of the .WAV format, there are many -// problematic files in the wild that cause issues with strict decoders. To -// provide compatibility with these files, this decoder is lenient in regards -// to the truncation of the file, the fact chunk, and the size of the RIFF -// chunk. The hints `SDL_HINT_WAVE_RIFF_CHUNK_SIZE`, -// `SDL_HINT_WAVE_TRUNCATION`, and `SDL_HINT_WAVE_FACT_CHUNK` can be used to -// tune the behavior of the loading process. -// -// Any file that is invalid (due to truncation, corruption, or wrong values in -// the headers), too big, or unsupported causes an error. Additionally, any -// critical I/O error from the data source will terminate the loading process -// with an error. The function returns NULL on error and in all cases (with -// the exception of `src` being NULL), an appropriate error message will be -// set. -// -// It is required that the data source supports seeking. -// -// Example: -// +// load_wav_rw loads a WAVE from the data source, automatically freeing +// that source if `freesrc` is non-zero. For example, to load a WAVE file, +// you could do: /* -```c - SDL_LoadWAV_RW(SDL_RWFromFile("sample.wav", "rb"), 1, &spec, &buf, &len); ``` -*/ -// -// Note that the SDL_LoadWAV macro does this same thing for you, but in a less -// messy way: -// -/* -```c - SDL_LoadWAV("sample.wav", &spec, &buf, &len); + SDL_LoadWAV_RW(SDL_RWFromFile("sample.wav", "rb"), 1, ...); ``` */ -// -// `src` The data source for the WAVE data -// `freesrc` If non-zero, SDL will _always_ free the data source -// `spec` An SDL_AudioSpec that will be filled in with the wave file's -// format details -// `audio_buf` A pointer filled with the audio data, allocated by the -// function. -// `audio_len` A pointer filled with the length of the audio data buffer -// in bytes -// returns This function, if successfully called, returns `spec`, which will -// be filled with the audio data format of the wave source data. -// `audio_buf` will be filled with a pointer to an allocated buffer -// containing the audio data, and `audio_len` is filled with the -// length of that audio buffer in bytes. -// -// This function returns NULL if the .WAV file cannot be opened, uses -// an unknown data format, or is corrupt; call SDL_GetError() for -// more information. -// -// When the application is done with the data returned in -// `audio_buf`, it should call SDL_FreeWAV() to dispose of it. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_FreeWAV -// See also: SDL_LoadWAV +// If this function succeeds, it returns the given SDL_AudioSpec, +// filled with the audio data format of the wave data, and sets +// `audio_buf` to a malloc()'d buffer containing the audio data, +// and sets `audio_len` to the length of that audio buffer, in bytes. +// You need to free the audio buffer with SDL_FreeWAV() when you are +// done with it. +// +// This function returns NULL and sets the SDL error message if the +// wave file cannot be opened, uses an unknown data format, or is +// corrupt. Currently raw and MS-ADPCM WAVE files are supported. pub fn load_wav_rw(src &RWops, freesrc int, spec &AudioSpec, audio_buf &&u8, audio_len &u32) &AudioSpec { return C.SDL_LoadWAV_RW(src, freesrc, spec, audio_buf, audio_len) } @@ -873,55 +456,20 @@ pub fn load_wav(file &char, spec &AudioSpec, audio_buf &&u8, audio_len &u32) &Au fn C.SDL_FreeWAV(audio_buf &u8) -// free_wav frees data previously allocated with SDL_LoadWAV() or SDL_LoadWAV_RW(). -// -// After a WAVE file has been opened with SDL_LoadWAV() or SDL_LoadWAV_RW() -// its data can eventually be freed with SDL_FreeWAV(). It is safe to call -// this function with a NULL pointer. -// -// `audio_buf` a pointer to the buffer created by SDL_LoadWAV() or -// SDL_LoadWAV_RW() -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_LoadWAV -// See also: SDL_LoadWAV_RW +// free_wav frees data previously allocated with SDL_LoadWAV_RW() pub fn free_wav(audio_buf &u8) { C.SDL_FreeWAV(audio_buf) } fn C.SDL_BuildAudioCVT(cvt &C.SDL_AudioCVT, src_format C.SDL_AudioFormat, src_channels u8, src_rate int, dst_format C.SDL_AudioFormat, dst_channels u8, dst_rate int) int -// build_audio_cvt initializes an SDL_AudioCVT structure for conversion. -// -// Before an SDL_AudioCVT structure can be used to convert audio data it must -// be initialized with source and destination information. -// -// This function will zero out every field of the SDL_AudioCVT, so it must be -// called before the application fills in the final buffer information. -// -// Once this function has returned successfully, and reported that a -// conversion is necessary, the application fills in the rest of the fields in -// SDL_AudioCVT, now that it knows how large a buffer it needs to allocate, -// and then can call SDL_ConvertAudio() to complete the conversion. -// -// `cvt` an SDL_AudioCVT structure filled in with audio conversion -// information -// `src_format` the source format of the audio data; for more info see -// SDL_AudioFormat -// `src_channels` the number of channels in the source -// `src_rate` the frequency (sample-frames-per-second) of the source -// `dst_format` the destination format of the audio data; for more info -// see SDL_AudioFormat -// `dst_channels` the number of channels in the destination -// `dst_rate` the frequency (sample-frames-per-second) of the destination -// returns 1 if the audio filter is prepared, 0 if no conversion is needed, -// or a negative error code on failure; call SDL_GetError() for more -// information. -// -// NOTE This function is available since SDL 2.0.0. +// build_audio_cvt takes a source format and rate and a destination format +// and rate, and initializes the `cvt` structure with information needed +// by SDL_ConvertAudio() to convert a buffer of audio data from one format +// to the other. An unsupported format causes an error and -1 will be returned. // -// See also: SDL_ConvertAudio +// returns 0 if no conversion is needed, 1 if the audio filter is set up, +// or -1 on error. pub fn build_audio_cvt(cvt &AudioCVT, src_format AudioFormat, src_channels u8, src_rate int, dst_format AudioFormat, dst_channels u8, dst_rate int) int { return C.SDL_BuildAudioCVT(cvt, C.SDL_AudioFormat(src_format), src_channels, src_rate, C.SDL_AudioFormat(dst_format), dst_channels, dst_rate) @@ -929,42 +477,17 @@ pub fn build_audio_cvt(cvt &AudioCVT, src_format AudioFormat, src_channels u8, s fn C.SDL_ConvertAudio(cvt &C.SDL_AudioCVT) int -// convert_audio converts audio data to a desired audio format. -// -// This function does the actual audio data conversion, after the application -// has called SDL_BuildAudioCVT() to prepare the conversion information and -// then filled in the buffer details. -// -// Once the application has initialized the `cvt` structure using -// SDL_BuildAudioCVT(), allocated an audio buffer and filled it with audio -// data in the source format, this function will convert the buffer, in-place, +// convert_audio +// Once you have initialized the `cvt` structure using SDL_BuildAudioCVT(), +// created an audio buffer `cvt->buf`, and filled it with `cvt->len` bytes of +// audio data in the source format, this function will convert it in-place // to the desired format. // -// The data conversion may go through several passes; any given pass may -// possibly temporarily increase the size of the data. For example, SDL might -// expand 16-bit data to 32 bits before resampling to a lower frequency, -// shrinking the data size after having grown it briefly. Since the supplied -// buffer will be both the source and destination, converting as necessary -// in-place, the application must allocate a buffer that will fully contain -// the data during its largest conversion pass. After SDL_BuildAudioCVT() -// returns, the application should set the `cvt->len` field to the size, in -// bytes, of the source data, and allocate a buffer that is `cvt->len * -// cvt->len_mult` bytes long for the `buf` field. -// -// The source data should be copied into this buffer before the call to -// SDL_ConvertAudio(). Upon successful return, this buffer will contain the -// converted audio, and `cvt->len_cvt` will be the size of the converted data, -// in bytes. Any bytes in the buffer past `cvt->len_cvt` are undefined once -// this function returns. -// -// `cvt` an SDL_AudioCVT structure that was previously set up by -// SDL_BuildAudioCVT(). -// returns 0 if the conversion was completed successfully or a negative error -// code on failure; call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_BuildAudioCVT +// The data conversion may expand the size of the audio data, so the buffer +// `cvt->buf` should be allocated after the `cvt` structure is initialized by +// SDL_BuildAudioCVT(), and should be `cvt->len` * `cvt->len_mult` bytes long. +// +// returns 0 on success or -1 if `cvt->buf` is NULL. pub fn convert_audio(cvt &AudioCVT) int { return C.SDL_ConvertAudio(cvt) } @@ -997,8 +520,6 @@ fn C.SDL_NewAudioStream(const_src_format C.SDL_AudioFormat, const_src_channels u // `dst_rate` The sampling rate of the desired audio output // returns 0 on success, or -1 on error. // -// NOTE This function is available since SDL 2.0.7. -// // See also: SDL_AudioStreamPut // See also: SDL_AudioStreamGet // See also: SDL_AudioStreamAvailable @@ -1019,8 +540,6 @@ fn C.SDL_AudioStreamPut(stream &C.SDL_AudioStream, const_buf voidptr, len int) i // `len` The number of bytes to write to the stream // returns 0 on success, or -1 on error. // -// NOTE This function is available since SDL 2.0.7. -// // See also: SDL_NewAudioStream // See also: SDL_AudioStreamGet // See also: SDL_AudioStreamAvailable @@ -1038,9 +557,7 @@ fn C.SDL_AudioStreamGet(stream &C.SDL_AudioStream, buf voidptr, len int) int // `stream` The stream the audio is being requested from // `buf` A buffer to fill with audio data // `len` The maximum number of bytes to fill -// returns the number of bytes read from the stream, or -1 on error -// -// NOTE This function is available since SDL 2.0.7. +// returns The number of bytes read from the stream, or -1 on error // // See also: SDL_NewAudioStream // See also: SDL_AudioStreamPut @@ -1054,13 +571,11 @@ pub fn audio_stream_get(stream &AudioStream, buf voidptr, len int) int { fn C.SDL_AudioStreamAvailable(stream &C.SDL_AudioStream) int -// audio_stream_available gets the number of converted/resampled bytes available. -// -// The stream may be buffering data behind the scenes until it has enough to -// resample correctly, so this number might be lower than what you expect, or -// even be zero. Add more data or flush the stream if you need the data now. -// -// NOTE This function is available since SDL 2.0.7. +// audio_stream_available gets the number of converted/resampled +// bytes available. The stream may be +// buffering data behind the scenes until it has enough to resample +// correctly, so this number might be lower than what you expect, or even +// be zero. Add more data or flush the stream if you need the data now. // // See also: SDL_NewAudioStream // See also: SDL_AudioStreamPut @@ -1074,14 +589,13 @@ pub fn audio_stream_available(stream &AudioStream) int { fn C.SDL_AudioStreamFlush(stream &C.SDL_AudioStream) int -// audio_stream_flush tells the stream that you're done sending data, and anything being buffered +// audio_stream_flush tella the stream that you're done +// sending data, and anything being buffered // should be converted/resampled and made available immediately. // -// It is legal to add more data to a stream after flushing, but there will be -// audio gaps in the output. Generally this is intended to signal the end of -// input, so the complete output becomes available. -// -// NOTE This function is available since SDL 2.0.7. +// It is legal to add more data to a stream after flushing, but there will +// be audio gaps in the output. Generally this is intended to signal the +// end of input, so the complete output becomes available. // // See also: SDL_NewAudioStream // See also: SDL_AudioStreamPut @@ -1098,8 +612,6 @@ fn C.SDL_AudioStreamClear(stream &C.SDL_AudioStream) // audio_stream_clear cleara any pending data in // the stream without converting it // -// NOTE This function is available since SDL 2.0.7. -// // See also: SDL_NewAudioStream // See also: SDL_AudioStreamPut // See also: SDL_AudioStreamGet @@ -1114,8 +626,6 @@ fn C.SDL_FreeAudioStream(stream &C.SDL_AudioStream) // free_audio_stream frees an audio stream // -// NOTE This function is available since SDL 2.0.7. -// // See also: SDL_NewAudioStream // See also: SDL_AudioStreamPut // See also: SDL_AudioStreamGet @@ -1128,62 +638,20 @@ pub fn free_audio_stream(stream &AudioStream) { fn C.SDL_MixAudio(dst &u8, const_src &u8, len u32, volume int) -// mix_audio this function is a legacy means of mixing audio. -// -// This function is equivalent to calling -// -/* -```c - SDL_MixAudioFormat(dst, src, format, len, volume); -``` -*/ -// -// where `format` is the obtained format of the audio device from the -// legacy SDL_OpenAudio() function. -// -// `dst` the destination for the mixed audio -// `src` the source audio buffer to be mixed -// `len` the length of the audio buffer in bytes -// `volume` ranges from 0 - 128, and should be set to SDL_MIX_MAXVOLUME -// for full audio volume -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_MixAudioFormat +// mix_audio takes two audio buffers of the playing audio format and mixes +// them, performing addition, volume adjustment, and overflow clipping. +// The volume ranges from 0 - 128, and should be set to ::SDL_MIX_MAXVOLUME +// for full audio volume. Note this does not change hardware volume. +// This is provided for convenience -- you can mix your own audio data. pub fn mix_audio(dst &u8, const_src &u8, len u32, volume int) { C.SDL_MixAudio(dst, const_src, len, volume) } fn C.SDL_MixAudioFormat(dst &u8, const_src &u8, format C.SDL_AudioFormat, len u32, volume int) -// mix_audio_format mixes audio data in a specified format. -// -// This takes an audio buffer `src` of `len` bytes of `format` data and mixes -// it into `dst`, performing addition, volume adjustment, and overflow -// clipping. The buffer pointed to by `dst` must also be `len` bytes of -// `format` data. -// -// This is provided for convenience -- you can mix your own audio data. -// -// Do not use this function for mixing together more than two streams of -// sample data. The output from repeated application of this function may be -// distorted by clipping, because there is no accumulator with greater range -// than the input (not to mention this being an inefficient way of doing it). -// -// It is a common misconception that this function is required to write audio -// data to an output stream in an audio callback. While you can do that, -// SDL_MixAudioFormat() is really only needed when you're mixing a single -// audio stream with a volume adjustment. -// -// `dst` the destination for the mixed audio -// `src` the source audio buffer to be mixed -// `format` the SDL_AudioFormat structure representing the desired audio -// format -// `len` the length of the audio buffer in bytes -// `volume` ranges from 0 - 128, and should be set to SDL_MIX_MAXVOLUME -// for full audio volume -// -// NOTE This function is available since SDL 2.0.0. +// mix_audio_format works like SDL_MixAudio(), but you specify the audio format instead of +// using the format of audio device 1. Thus it can be used when no audio +// device is open at all. pub fn mix_audio_format(dst &u8, const_src &u8, format AudioFormat, len u32, volume int) { C.SDL_MixAudioFormat(dst, const_src, C.SDL_AudioFormat(format), len, volume) } @@ -1192,48 +660,41 @@ fn C.SDL_QueueAudio(dev C.SDL_AudioDeviceID, const_data voidptr, len u32) int // queue_audio queues more audio on non-callback devices. // -// If you are looking to retrieve queued audio from a non-callback capture -// device, you want SDL_DequeueAudio() instead. SDL_QueueAudio() will return -// -1 to signify an error if you use it with capture devices. +// (If you are looking to retrieve queued audio from a non-callback capture +// device, you want SDL_DequeueAudio() instead. This will return -1 to +// signify an error if you use it with capture devices.) // // SDL offers two ways to feed audio to the device: you can either supply a -// callback that SDL triggers with some frequency to obtain more audio (pull -// method), or you can supply no callback, and then SDL will expect you to -// supply data at regular intervals (push method) with this function. +// callback that SDL triggers with some frequency to obtain more audio +// (pull method), or you can supply no callback, and then SDL will expect +// you to supply data at regular intervals (push method) with this function. // // There are no limits on the amount of data you can queue, short of // exhaustion of address space. Queued data will drain to the device as -// necessary without further intervention from you. If the device needs audio -// but there is not enough queued, it will play silence to make up the -// difference. This means you will have skips in your audio playback if you -// aren't routinely queueing sufficient data. +// necessary without further intervention from you. If the device needs +// audio but there is not enough queued, it will play silence to make up +// the difference. This means you will have skips in your audio playback +// if you aren't routinely queueing sufficient data. // -// This function copies the supplied data, so you are safe to free it when the -// function returns. This function is thread-safe, but queueing to the same -// device from two threads at once does not promise which buffer will be -// queued first. +// This function copies the supplied data, so you are safe to free it when +// the function returns. This function is thread-safe, but queueing to the +// same device from two threads at once does not promise which buffer will +// be queued first. // // You may not queue audio on a device that is using an application-supplied -// callback; doing so returns an error. You have to use the audio callback or -// queue audio with this function, but not both. +// callback; doing so returns an error. You have to use the audio callback +// or queue audio with this function, but not both. // // You should not call SDL_LockAudio() on the device before queueing; SDL // handles locking internally for this function. // -// Note that SDL2 does not support planar audio. You will need to resample -// from planar audio formats into a non-planar one (see SDL_AudioFormat) -// before queuing audio. -// -// `dev` the device ID to which we will queue audio -// `data` the data to queue to the device for later playback -// `len` the number of bytes (not samples!) to which `data` points -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.4. +// `dev` The device ID to which we will queue audio. +// `data` The data to queue to the device for later playback. +// `len` The number of bytes (not samples!) to which (data) points. +// returns 0 on success, or -1 on error. // -// See also: SDL_ClearQueuedAudio // See also: SDL_GetQueuedAudioSize +// See also: SDL_ClearQueuedAudio pub fn queue_audio(dev AudioDeviceID, const_data voidptr, len u32) int { return C.SDL_QueueAudio(C.SDL_AudioDeviceID(dev), const_data, len) } @@ -1242,48 +703,46 @@ fn C.SDL_DequeueAudio(dev C.SDL_AudioDeviceID, data voidptr, len u32) u32 // dequeue_audio dequeues more audio on non-callback devices. // -// If you are looking to queue audio for output on a non-callback playback -// device, you want SDL_QueueAudio() instead. SDL_DequeueAudio() will always -// return 0 if you use it with playback devices. +// (If you are looking to queue audio for output on a non-callback playback +// device, you want SDL_QueueAudio() instead. This will always return 0 +// if you use it with playback devices.) // -// SDL offers two ways to retrieve audio from a capture device: you can either -// supply a callback that SDL triggers with some frequency as the device -// records more audio data, (push method), or you can supply no callback, and -// then SDL will expect you to retrieve data at regular intervals (pull -// method) with this function. +// SDL offers two ways to retrieve audio from a capture device: you can +// either supply a callback that SDL triggers with some frequency as the +// device records more audio data, (push method), or you can supply no +// callback, and then SDL will expect you to retrieve data at regular +// intervals (pull method) with this function. // // There are no limits on the amount of data you can queue, short of // exhaustion of address space. Data from the device will keep queuing as // necessary without further intervention from you. This means you will // eventually run out of memory if you aren't routinely dequeueing data. // -// Capture devices will not queue data when paused; if you are expecting to -// not need captured audio for some length of time, use SDL_PauseAudioDevice() -// to stop the capture device from queueing more data. This can be useful -// during, say, level loading times. When unpaused, capture devices will start -// queueing data from that point, having flushed any capturable data available -// while paused. +// Capture devices will not queue data when paused; if you are expecting +// to not need captured audio for some length of time, use +// SDL_PauseAudioDevice() to stop the capture device from queueing more +// data. This can be useful during, say, level loading times. When +// unpaused, capture devices will start queueing data from that point, +// having flushed any capturable data available while paused. // -// This function is thread-safe, but dequeueing from the same device from two -// threads at once does not promise which thread will dequeue data first. +// This function is thread-safe, but dequeueing from the same device from +// two threads at once does not promise which thread will dequeued data +// first. // // You may not dequeue audio from a device that is using an // application-supplied callback; doing so returns an error. You have to use // the audio callback, or dequeue audio with this function, but not both. // -// You should not call SDL_LockAudio() on the device before dequeueing; SDL +// You should not call SDL_LockAudio() on the device before queueing; SDL // handles locking internally for this function. // -// `dev` the device ID from which we will dequeue audio -// `data` a pointer into where audio data should be copied -// `len` the number of bytes (not samples!) to which (data) points -// returns the number of bytes dequeued, which could be less than requested; -// call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.5. +// `dev` The device ID from which we will dequeue audio. +// `data` A pointer into where audio data should be copied. +// `len` The number of bytes (not samples!) to which (data) points. +// returns number of bytes dequeued, which could be less than requested. // -// See also: SDL_ClearQueuedAudio // See also: SDL_GetQueuedAudioSize +// See also: SDL_ClearQueuedAudio pub fn dequeue_audio(dev AudioDeviceID, data voidptr, len u32) u32 { return C.SDL_DequeueAudio(C.SDL_AudioDeviceID(dev), data, len) } @@ -1292,224 +751,115 @@ fn C.SDL_GetQueuedAudioSize(dev C.SDL_AudioDeviceID) u32 // get_queued_audio_size gets the number of bytes of still-queued audio. // -// For playback devices: this is the number of bytes that have been queued for -// playback with SDL_QueueAudio(), but have not yet been sent to the hardware. +// For playback device: // -// Once we've sent it to the hardware, this function can not decide the exact -// byte boundary of what has been played. It's possible that we just gave the -// hardware several kilobytes right before you called this function, but it -// hasn't played any of it yet, or maybe half of it, etc. +// This is the number of bytes that have been queued for playback with +// SDL_QueueAudio(), but have not yet been sent to the hardware. This +// number may shrink at any time, so this only informs of pending data. // -// For capture devices, this is the number of bytes that have been captured by -// the device and are waiting for you to dequeue. This number may grow at any -// time, so this only informs of the lower-bound of available data. +// Once we've sent it to the hardware, this function can not decide the +// exact byte boundary of what has been played. It's possible that we just +// gave the hardware several kilobytes right before you called this +// function, but it hasn't played any of it yet, or maybe half of it, etc. // -// You may not queue or dequeue audio on a device that is using an -// application-supplied callback; calling this function on such a device -// always returns 0. You have to use the audio callback or queue audio, but -// not both. +// For capture devices: +// +// This is the number of bytes that have been captured by the device and +// are waiting for you to dequeue. This number may grow at any time, so +// this only informs of the lower-bound of available data. +// +// You may not queue audio on a device that is using an application-supplied +// callback; calling this function on such a device always returns 0. +// You have to queue audio with SDL_QueueAudio()/SDL_DequeueAudio(), or use +// the audio callback, but not both. // // You should not call SDL_LockAudio() on the device before querying; SDL // handles locking internally for this function. // -// `dev` the device ID of which we will query queued audio size -// returns the number of bytes (not samples!) of queued audio. -// -// NOTE This function is available since SDL 2.0.4. +// `dev` The device ID of which we will query queued audio size. +// returns Number of bytes (not samples!) of queued audio. // -// See also: SDL_ClearQueuedAudio // See also: SDL_QueueAudio -// See also: SDL_DequeueAudio +// See also: SDL_ClearQueuedAudio pub fn get_queued_audio_size(dev AudioDeviceID) u32 { return C.SDL_GetQueuedAudioSize(C.SDL_AudioDeviceID(dev)) } fn C.SDL_ClearQueuedAudio(dev C.SDL_AudioDeviceID) -// clear_queued_audio drops any queued audio data waiting to be sent to the hardware. +// clear_queued_audio drops any queued audio data. +// For playback devices, this is any queued data +// still waiting to be submitted to the hardware. For capture devices, this +// is any data that was queued by the device that hasn't yet been dequeued by +// the application. // // Immediately after this call, SDL_GetQueuedAudioSize() will return 0. For -// output devices, the hardware will start playing silence if more audio isn't -// queued. For capture devices, the hardware will start filling the empty -// queue with new data if the capture device isn't paused. +// playback devices, the hardware will start playing silence if more audio +// isn't queued. Unpaused capture devices will start filling the queue again +// as soon as they have more data available (which, depending on the state +// of the hardware and the thread, could be before this function call +// returns!). +// +// This will not prevent playback of queued audio that's already been sent +// to the hardware, as we can not undo that, so expect there to be some +// fraction of a second of audio that might still be heard. This can be +// useful if you want to, say, drop any pending music during a level change +// in your game. // -// This will not prevent playback of queued audio that's already been sent to -// the hardware, as we can not undo that, so expect there to be some fraction -// of a second of audio that might still be heard. This can be useful if you -// want to, say, drop any pending music or any unprocessed microphone input -// during a level change in your game. -// -// You may not queue or dequeue audio on a device that is using an -// application-supplied callback; calling this function on such a device -// always returns 0. You have to use the audio callback or queue audio, but -// not both. +// You may not queue audio on a device that is using an application-supplied +// callback; calling this function on such a device is always a no-op. +// You have to queue audio with SDL_QueueAudio()/SDL_DequeueAudio(), or use +// the audio callback, but not both. // // You should not call SDL_LockAudio() on the device before clearing the // queue; SDL handles locking internally for this function. // // This function always succeeds and thus returns void. // -// `dev` the device ID of which to clear the audio queue +// `dev` The device ID of which to clear the audio queue. // -// NOTE This function is available since SDL 2.0.4. -// -// See also: SDL_GetQueuedAudioSize // See also: SDL_QueueAudio -// See also: SDL_DequeueAudio +// See also: SDL_GetQueuedAudioSize pub fn clear_queued_audio(dev AudioDeviceID) { C.SDL_ClearQueuedAudio(C.SDL_AudioDeviceID(dev)) } +fn C.SDL_LockAudio() + // Audio lock functions // // The lock manipulated by these functions protects the callback function. // During a SDL_LockAudio()/SDL_UnlockAudio() pair, you can be guaranteed that // the callback function is not running. Do not call these from the callback // function or you will cause deadlock. - -fn C.SDL_LockAudio() - -// lock_audio is a legacy means of locking the audio device. -// -// New programs might want to use SDL_LockAudioDevice() instead. This function -// is equivalent to calling... -// -// ```c -// SDL_LockAudioDevice(1); -// ``` -// -// ...and is only useful if you used the legacy SDL_OpenAudio() function. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_LockAudioDevice -// See also: SDL_UnlockAudio -// See also: SDL_UnlockAudioDevice pub fn lock_audio() { C.SDL_LockAudio() } fn C.SDL_LockAudioDevice(dev C.SDL_AudioDeviceID) -// lock_audio_device locks out the audio callback function for a specified -// device. -// -// The lock manipulated by these functions protects the audio callback -// function specified in SDL_OpenAudioDevice(). During a -// SDL_LockAudioDevice()/SDL_UnlockAudioDevice() pair, you can be guaranteed -// that the callback function for that device is not running, even if the -// device is not paused. While a device is locked, any other unpaused, -// unlocked devices may still run their callbacks. -// -// Calling this function from inside your audio callback is unnecessary. SDL -// obtains this lock before calling your function, and releases it when the -// function returns. -// -// You should not hold the lock longer than absolutely necessary. If you hold -// it too long, you'll experience dropouts in your audio playback. Ideally, -// your application locks the device, sets a few variables and unlocks again. -// Do not do heavy work while holding the lock for a device. -// -// It is safe to lock the audio device multiple times, as long as you unlock -// it an equivalent number of times. The callback will not run until the -// device has been unlocked completely in this way. If your application fails -// to unlock the device appropriately, your callback will never run, you might -// hear repeating bursts of audio, and SDL_CloseAudioDevice() will probably -// deadlock. -// -// Internally, the audio device lock is a mutex; if you lock from two threads -// at once, not only will you block the audio callback, you'll block the other -// thread. -// -// `dev` the ID of the device to be locked -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_UnlockAudioDevice pub fn lock_audio_device(dev AudioDeviceID) { C.SDL_LockAudioDevice(C.SDL_AudioDeviceID(dev)) } fn C.SDL_UnlockAudio() - -// unlock_audio is a legacy means of unlocking the audio device. -// -// New programs might want to use SDL_UnlockAudioDevice() instead. This -// function is equivalent to calling... -// -// ```c -// SDL_UnlockAudioDevice(1); -// ``` -// -// ...and is only useful if you used the legacy SDL_OpenAudio() function. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_LockAudio -// See also: SDL_UnlockAudioDevice pub fn unlock_audio() { C.SDL_UnlockAudio() } fn C.SDL_UnlockAudioDevice(dev C.SDL_AudioDeviceID) - -// unlock_audio_device unlocks the audio callback function for a specified -// device. -// -// This function should be paired with a previous SDL_LockAudioDevice() call. -// -// `dev` the ID of the device to be unlocked -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_LockAudioDevice pub fn unlock_audio_device(dev AudioDeviceID) { C.SDL_UnlockAudioDevice(C.SDL_AudioDeviceID(dev)) } fn C.SDL_CloseAudio() -// close_audio is legacy means of closing the audio device. -// -// This function is equivalent to calling... -// -/* -```c - SDL_CloseAudioDevice(1); -``` -*/ -// -// ...and is only useful if you used the legacy SDL_OpenAudio() function. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_OpenAudio +// close_audio shuts down audio processing and closes the audio device. pub fn close_audio() { C.SDL_CloseAudio() } fn C.SDL_CloseAudioDevice(dev C.SDL_AudioDeviceID) - -// close_audio_device uses this function to shut down audio processing and close the audio device. -// -// The application should close open audio devices once they are no longer -// needed. Calling this function will wait until the device's audio callback -// is not running, release the audio hardware and then clean up internal -// state. No further audio will play from this device once this function -// returns. -// -// This function may block briefly while pending audio data is played by the -// hardware, so that applications don't drop the last buffer of data they -// supplied. -// -// The device ID is invalid as soon as the device is closed, and is eligible -// for reuse in a new SDL_OpenAudioDevice() call immediately. -// -// `dev` an audio device previously opened with SDL_OpenAudioDevice() -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_OpenAudioDevice pub fn close_audio_device(dev AudioDeviceID) { C.SDL_CloseAudioDevice(C.SDL_AudioDeviceID(dev)) } diff --git a/bits.c.v b/bits.c.v index 223671f9..f359d01d 100644 --- a/bits.c.v +++ b/bits.c.v @@ -19,9 +19,4 @@ fn C.SDL_MostSignificantBitIndex32(x u32) int pub fn most_significant_bit_index32(x u32) int { return C.SDL_MostSignificantBitIndex32(x) } - -fn C.SDL_HasExactlyOneBitSet32(x u32) bool -pub fn has_exactly_one_bit_set32(x u32) bool { - return C.SDL_HasExactlyOneBitSet32(x) -} */ diff --git a/blendmode.c.v b/blendmode.c.v index 214f12d4..bbf42ea2 100644 --- a/blendmode.c.v +++ b/blendmode.c.v @@ -14,7 +14,6 @@ pub enum BlendMode { blend = C.SDL_BLENDMODE_BLEND // 0x00000001, alpha blending dstRGB = (srcRGB * srcA) + (dstRGB * (1-srcA)) dstA = srcA + (dstA * (1-srcA)) add = C.SDL_BLENDMODE_ADD // 0x00000002, additive blending dstRGB = (srcRGB * srcA) + dstRGB dstA = dstA mod = C.SDL_BLENDMODE_MOD // 0x00000004, color modulate dstRGB = srcRGB * dstRGB dstA = dstA - mul = C.SDL_BLENDMODE_MUL // 0x00000008, color multiply dstRGB = (srcRGB * dstRGB) + (dstRGB * (1-srcA)) dstA = dstA invalid = C.SDL_BLENDMODE_INVALID // 0x7FFFFFFF } @@ -22,10 +21,10 @@ pub enum BlendMode { // BlendOperation is C.SDL_BlendOperation pub enum BlendOperation { add = C.SDL_BLENDOPERATION_ADD // 0x1, dst + src: supported by all renderers - subtract = C.SDL_BLENDOPERATION_SUBTRACT // 0x2, src - dst : supported by D3D9, D3D11, OpenGL, OpenGLES - rev_subtract = C.SDL_BLENDOPERATION_REV_SUBTRACT // 0x3, dst - src : supported by D3D9, D3D11, OpenGL, OpenGLES - minimum = C.SDL_BLENDOPERATION_MINIMUM // 0x4, min(dst, src) : supported by D3D9, D3D11 - maximum = C.SDL_BLENDOPERATION_MAXIMUM // 0x5 max(dst, src) : supported by D3D9, D3D11 + subtract = C.SDL_BLENDOPERATION_SUBTRACT // 0x2, dst - src : supported by D3D9, D3D11, OpenGL, OpenGLES + rev_subtract = C.SDL_BLENDOPERATION_REV_SUBTRACT // 0x3, src - dst : supported by D3D9, D3D11, OpenGL, OpenGLES + minimum = C.SDL_BLENDOPERATION_MINIMUM // 0x4, min(dst, src) : supported by D3D11 + maximum = C.SDL_BLENDOPERATION_MAXIMUM // 0x5 max(dst, src) : supported by D3D11 } // BlendFactor is the normalized factor used to multiply pixel components @@ -45,98 +44,20 @@ pub enum BlendFactor { fn C.SDL_ComposeCustomBlendMode(src_color_factor C.SDL_BlendFactor, dst_color_factor C.SDL_BlendFactor, color_operation C.SDL_BlendOperation, src_alpha_factor C.SDL_BlendFactor, dst_alpha_factor C.SDL_BlendFactor, alpha_operation C.SDL_BlendOperation) BlendMode -// compose_custom_blend_mode composes a custom blend mode for renderers. -// -// The functions SDL_SetRenderDrawBlendMode and SDL_SetTextureBlendMode accept -// the SDL_BlendMode returned by this function if the renderer supports it. -// -// A blend mode controls how the pixels from a drawing operation (source) get -// combined with the pixels from the render target (destination). First, the -// components of the source and destination pixels get multiplied with their -// blend factors. Then, the blend operation takes the two products and -// calculates the result that will get stored in the render target. -// -// Expressed in pseudocode, it would look like this: -// -/* -```c - dstRGB = colorOperation(srcRGB * srcColorFactor, dstRGB * dstColorFactor); - dstA = alphaOperation(srcA * srcAlphaFactor, dstA * dstAlphaFactor); -``` -*/ -// -// Where the functions `colorOperation(src, dst)` and `alphaOperation(src, -// dst)` can return one of the following: -// -// - `src + dst` -// - `src - dst` -// - `dst - src` -// - `min(src, dst)` -// - `max(src, dst)` -// -// The red, green, and blue components are always multiplied with the first, -// second, and third components of the SDL_BlendFactor, respectively. The -// fourth component is not used. -// -// The alpha component is always multiplied with the fourth component of the -// SDL_BlendFactor. The other components are not used in the alpha -// calculation. -// -// Support for these blend modes varies for each renderer. To check if a -// specific SDL_BlendMode is supported, create a renderer and pass it to -// either SDL_SetRenderDrawBlendMode or SDL_SetTextureBlendMode. They will -// return with an error if the blend mode is not supported. -// -// This list describes the support of custom blend modes for each renderer in -// SDL 2.0.6. All renderers support the four blend modes listed in the -// SDL_BlendMode enumeration. -// -// - **direct3d**: Supports all operations with all factors. However, some -// factors produce unexpected results with `SDL_BLENDOPERATION_MINIMUM` and -// `SDL_BLENDOPERATION_MAXIMUM`. -// - **direct3d11**: Same as Direct3D 9. -// - **opengl**: Supports the `SDL_BLENDOPERATION_ADD` operation with all -// factors. OpenGL versions 1.1, 1.2, and 1.3 do not work correctly with SDL -// 2.0.6. -// - **opengles**: Supports the `SDL_BLENDOPERATION_ADD` operation with all -// factors. Color and alpha factors need to be the same. OpenGL ES 1 -// implementation specific: May also support `SDL_BLENDOPERATION_SUBTRACT` -// and `SDL_BLENDOPERATION_REV_SUBTRACT`. May support color and alpha -// operations being different from each other. May support color and alpha -// factors being different from each other. -// - **opengles2**: Supports the `SDL_BLENDOPERATION_ADD`, -// `SDL_BLENDOPERATION_SUBTRACT`, `SDL_BLENDOPERATION_REV_SUBTRACT` -// operations with all factors. -// - **psp**: No custom blend mode support. -// - **software**: No custom blend mode support. -// -// Some renderers do not provide an alpha component for the default render -// target. The `SDL_BLENDFACTOR_DST_ALPHA` and -// `SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA` factors do not have an effect in this -// case. -// -// `srcColorFactor` the SDL_BlendFactor applied to the red, green, and -// blue components of the source pixels -// `dstColorFactor` the SDL_BlendFactor applied to the red, green, and -// blue components of the destination pixels -// `colorOperation` the SDL_BlendOperation used to combine the red, -// green, and blue components of the source and -// destination pixels -// `srcAlphaFactor` the SDL_BlendFactor applied to the alpha component of -// the source pixels -// `dstAlphaFactor` the SDL_BlendFactor applied to the alpha component of -// the destination pixels -// `alphaOperation` the SDL_BlendOperation used to combine the alpha -// component of the source and destination pixels -// returns an SDL_BlendMode that represents the chosen factors and -// operations. -// -// NOTE This function is available since SDL 2.0.6. -// -// See also: SDL_SetRenderDrawBlendMode -// See also: SDL_GetRenderDrawBlendMode -// See also: SDL_SetTextureBlendMode -// See also: SDL_GetTextureBlendMode +// compose_custom_blend_mode creates a custom blend mode, which may +// or may not be supported by a given renderer +// +// `srcColorFactor` +// `dstColorFactor` +// `colorOperation` +// `srcAlphaFactor` +// `dstAlphaFactor` +// `alphaOperation` +// +// The result of the blend mode operation will be: +// dstRGB = dstRGB * dstColorFactor colorOperation srcRGB * srcColorFactor +// and +// dstA = dstA * dstAlphaFactor alphaOperation srcA * srcAlphaFactor pub fn compose_custom_blend_mode(src_color_factor BlendFactor, dst_color_factor BlendFactor, color_operation BlendOperation, src_alpha_factor BlendFactor, dst_alpha_factor BlendFactor, alpha_operation BlendOperation) BlendMode { return unsafe { BlendMode(int(C.SDL_ComposeCustomBlendMode(C.SDL_BlendFactor(src_color_factor), diff --git a/c/sdl.c.v b/c/sdl.c.v index 794d171c..d2d90710 100644 --- a/c/sdl.c.v +++ b/c/sdl.c.v @@ -26,11 +26,11 @@ $if !windows { #flag -DSDL_DISABLE_IMMINTRIN_H $if x64 { - #flag windows -L @VMODROOT/thirdparty/SDL2-2.30.0/lib/x64 + #flag windows -L @VMODROOT/thirdparty/SDL2-2.0.8/lib/x64 } $else { - #flag windows -L @VMODROOT/thirdparty/SDL2-2.30.0/lib/x86 + #flag windows -L @VMODROOT/thirdparty/SDL2-2.0.8/lib/x86 } -#flag windows -I @VMODROOT/thirdparty/SDL2-2.30.0/include +#flag windows -I @VMODROOT/thirdparty/SDL2-2.0.8/include #flag windows -Dmain=SDL_main #flag windows -lSDL2main -lSDL2 diff --git a/clipboard.c.v b/clipboard.c.v index d4c60958..a9479a9c 100644 --- a/clipboard.c.v +++ b/clipboard.c.v @@ -9,103 +9,27 @@ module sdl fn C.SDL_SetClipboardText(text &char) int -// set_clipboard_text puts UTF-8 text into the clipboard. +// set_clipboard_text puts UTF-8 text into the clipboard // -// `text` the text to store in the clipboard -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetClipboardText -// See also: SDL_HasClipboardText +// See also: SDL_GetClipboardText() pub fn set_clipboard_text(text &char) int { return C.SDL_SetClipboardText(text) } fn C.SDL_GetClipboardText() &char -// get_clipboard_text gets UTF-8 text from the clipboard, which must be freed with SDL_free(). -// -// This functions returns empty string if there was not enough memory left for -// a copy of the clipboard's content. -// -// returns the clipboard text on success or an empty string on failure; call -// SDL_GetError() for more information. Caller must call SDL_free() -// on the returned pointer when done with it (even if there was an -// error). +// get_clipboard_text gets UTF-8 text from the clipboard, which must be freed with SDL_free() // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_HasClipboardText -// See also: SDL_SetClipboardText +// See also: SDL_SetClipboardText() pub fn get_clipboard_text() &char { return C.SDL_GetClipboardText() } fn C.SDL_HasClipboardText() bool -// has_clipboard_text queries whether the clipboard exists and contains a non-empty text string. -// -// returns SDL_TRUE if the clipboard has text, or SDL_FALSE if it does not. -// -// NOTE This function is available since SDL 2.0.0. +// has_clipboard_text returns a flag indicating whether the clipboard exists and contains a text string that is non-empty // -// See also: SDL_GetClipboardText -// See also: SDL_SetClipboardText +// See also: SDL_GetClipboardText() pub fn has_clipboard_text() bool { return C.SDL_HasClipboardText() } - -fn C.SDL_SetPrimarySelectionText(const_text &char) int - -// set_primary_selection_text puts UTF-8 text into the primary selection. -// -// `text` the text to store in the primary selection -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.26.0. -// -// See also: SDL_GetPrimarySelectionText -// See also: SDL_HasPrimarySelectionText -pub fn set_primary_selection_text(const_text &char) int { - return C.SDL_SetPrimarySelectionText(const_text) -} - -fn C.SDL_GetPrimarySelectionText() &char - -// get_primary_selection_text gets UTF-8 text from the primary selection, which must be freed with -// SDL_free(). -// -// This functions returns empty string if there was not enough memory left for -// a copy of the primary selection's content. -// -// returns the primary selection text on success or an empty string on -// failure; call SDL_GetError() for more information. Caller must -// call SDL_free() on the returned pointer when done with it (even if -// there was an error). -// -// NOTE This function is available since SDL 2.26.0. -// -// See also: SDL_HasPrimarySelectionText -// See also: SDL_SetPrimarySelectionText -pub fn get_primary_selection_text() &char { - return C.SDL_GetPrimarySelectionText() -} - -fn C.SDL_HasPrimarySelectionText() bool - -// has_primary_selection_text querys whether the primary selection exists and contains a non-empty text -// string. -// -// returns SDL_TRUE if the primary selection has text, or SDL_FALSE if it -// does not. -// -// NOTE This function is available since SDL 2.26.0. -// -// See also: SDL_GetPrimarySelectionText -// See also: SDL_SetPrimarySelectionText -pub fn has_primary_selection_text() bool { - return C.SDL_HasPrimarySelectionText() -} diff --git a/cpuinfo.c.v b/cpuinfo.c.v index d9f79054..e73fce49 100644 --- a/cpuinfo.c.v +++ b/cpuinfo.c.v @@ -9,492 +9,107 @@ module sdl fn C.SDL_GetCPUCount() int -// get_cpu_count gets the number of CPU cores available. -// -// returns the total number of logical CPU cores. On CPUs that include -// technologies such as hyperthreading, the number of logical cores -// may be more than the number of physical cores. -// -// NOTE This function is available since SDL 2.0.0. +// get_cpu_count returns the number of CPU cores available. pub fn get_cpu_count() int { return C.SDL_GetCPUCount() } fn C.SDL_GetCPUCacheLineSize() int -// get_cpu_cache_line_size determines the L1 cache line size of the CPU. -// -// This is useful for determining multi-threaded structure padding or SIMD -// prefetch sizes. -// -// returns the L1 cache line size of the CPU, in bytes. -// -// NOTE This function is available since SDL 2.0.0. +// get_cpu_cache_line_size returns the L1 cache line size of the CPU +// This is useful for determining multi-threaded structure padding +// or SIMD prefetch sizes. pub fn get_cpu_cache_line_size() int { return C.SDL_GetCPUCacheLineSize() } fn C.SDL_HasRDTSC() bool -// has_rdtsc determines whether the CPU has the RDTSC instruction. -// -// This always returns false on CPUs that aren't using Intel instruction sets. -// -// returns SDL_TRUE if the CPU has the RDTSC instruction or SDL_FALSE if not. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_Has3DNow -// See also: SDL_HasAltiVec -// See also: SDL_HasAVX -// See also: SDL_HasAVX2 -// See also: SDL_HasMMX -// See also: SDL_HasSSE -// See also: SDL_HasSSE2 -// See also: SDL_HasSSE3 -// See also: SDL_HasSSE41 -// See also: SDL_HasSSE42 +// has_rdtsc returns true if the CPU has the RDTSC instruction. pub fn has_rdtsc() bool { return C.SDL_HasRDTSC() } fn C.SDL_HasAltiVec() bool -// has_alti_vec determines whether the CPU has AltiVec features. -// -// This always returns false on CPUs that aren't using PowerPC instruction -// sets. -// -// returns SDL_TRUE if the CPU has AltiVec features or SDL_FALSE if not. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_Has3DNow -// See also: SDL_HasAVX -// See also: SDL_HasAVX2 -// See also: SDL_HasMMX -// See also: SDL_HasRDTSC -// See also: SDL_HasSSE -// See also: SDL_HasSSE2 -// See also: SDL_HasSSE3 -// See also: SDL_HasSSE41 -// See also: SDL_HasSSE42 +// has_alti_vec returns true if the CPU has AltiVec features. pub fn has_alti_vec() bool { return C.SDL_HasAltiVec() } fn C.SDL_HasMMX() bool -// has_mmx determines whether the CPU has MMX features. -// -// This always returns false on CPUs that aren't using Intel instruction sets. -// -// returns SDL_TRUE if the CPU has MMX features or SDL_FALSE if not. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_Has3DNow -// See also: SDL_HasAltiVec -// See also: SDL_HasAVX -// See also: SDL_HasAVX2 -// See also: SDL_HasRDTSC -// See also: SDL_HasSSE -// See also: SDL_HasSSE2 -// See also: SDL_HasSSE3 -// See also: SDL_HasSSE41 -// See also: SDL_HasSSE42 +// has_mmx returns true if the CPU has MMX features. pub fn has_mmx() bool { return C.SDL_HasMMX() } fn C.SDL_Has3DNow() bool -// has_3d_now determines whether the CPU has 3DNow! features. -// -// This always returns false on CPUs that aren't using AMD instruction sets. -// -// returns SDL_TRUE if the CPU has 3DNow! features or SDL_FALSE if not. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_HasAltiVec -// See also: SDL_HasAVX -// See also: SDL_HasAVX2 -// See also: SDL_HasMMX -// See also: SDL_HasRDTSC -// See also: SDL_HasSSE -// See also: SDL_HasSSE2 -// See also: SDL_HasSSE3 -// See also: SDL_HasSSE41 -// See also: SDL_HasSSE42 +// has_3d_now returns true if the CPU has 3DNow! features. pub fn has_3d_now() bool { return C.SDL_Has3DNow() } fn C.SDL_HasSSE() bool -// has_sse determines whether the CPU has SSE features. -// -// This always returns false on CPUs that aren't using Intel instruction sets. -// -// returns SDL_TRUE if the CPU has SSE features or SDL_FALSE if not. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_Has3DNow -// See also: SDL_HasAltiVec -// See also: SDL_HasAVX -// See also: SDL_HasAVX2 -// See also: SDL_HasMMX -// See also: SDL_HasRDTSC -// See also: SDL_HasSSE2 -// See also: SDL_HasSSE3 -// See also: SDL_HasSSE41 -// See also: SDL_HasSSE42 +// has_sse returns true if the CPU has SSE features. pub fn has_sse() bool { return C.SDL_HasSSE() } fn C.SDL_HasSSE2() bool -// has_sse2 determines whether the CPU has SSE2 features. -// -// This always returns false on CPUs that aren't using Intel instruction sets. -// -// returns SDL_TRUE if the CPU has SSE2 features or SDL_FALSE if not. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_Has3DNow -// See also: SDL_HasAltiVec -// See also: SDL_HasAVX -// See also: SDL_HasAVX2 -// See also: SDL_HasMMX -// See also: SDL_HasRDTSC -// See also: SDL_HasSSE -// See also: SDL_HasSSE3 -// See also: SDL_HasSSE41 -// See also: SDL_HasSSE42 +// has_sse2 returns true if the CPU has SSE2 features. pub fn has_sse2() bool { return C.SDL_HasSSE2() } fn C.SDL_HasSSE3() bool -// has_sse3 determines whether the CPU has SSE3 features. -// -// This always returns false on CPUs that aren't using Intel instruction sets. -// -// returns SDL_TRUE if the CPU has SSE3 features or SDL_FALSE if not. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_Has3DNow -// See also: SDL_HasAltiVec -// See also: SDL_HasAVX -// See also: SDL_HasAVX2 -// See also: SDL_HasMMX -// See also: SDL_HasRDTSC -// See also: SDL_HasSSE -// See also: SDL_HasSSE2 -// See also: SDL_HasSSE41 -// See also: SDL_HasSSE42 +// has_sse3 returns true if the CPU has SSE3 features. pub fn has_sse3() bool { return C.SDL_HasSSE3() } fn C.SDL_HasSSE41() bool -// has_sse41 determines whether the CPU has SSE4.1 features. -// -// This always returns false on CPUs that aren't using Intel instruction sets. -// -// returns SDL_TRUE if the CPU has SSE4.1 features or SDL_FALSE if not. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_Has3DNow -// See also: SDL_HasAltiVec -// See also: SDL_HasAVX -// See also: SDL_HasAVX2 -// See also: SDL_HasMMX -// See also: SDL_HasRDTSC -// See also: SDL_HasSSE -// See also: SDL_HasSSE2 -// See also: SDL_HasSSE3 -// See also: SDL_HasSSE42 +// has_sse41 returns true if the CPU has SSE4.1 features. pub fn has_sse41() bool { return C.SDL_HasSSE41() } fn C.SDL_HasSSE42() bool -// has_sse42 determines whether the CPU has SSE4.2 features. -// -// This always returns false on CPUs that aren't using Intel instruction sets. -// -// returns SDL_TRUE if the CPU has SSE4.2 features or SDL_FALSE if not. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_Has3DNow -// See also: SDL_HasAltiVec -// See also: SDL_HasAVX -// See also: SDL_HasAVX2 -// See also: SDL_HasMMX -// See also: SDL_HasRDTSC -// See also: SDL_HasSSE -// See also: SDL_HasSSE2 -// See also: SDL_HasSSE3 -// See also: SDL_HasSSE41 +// has_sse42 returns true if the CPU has SSE4.2 features. pub fn has_sse42() bool { return C.SDL_HasSSE42() } fn C.SDL_HasAVX() bool -// has_avx determines whether the CPU has AVX features. -// -// This always returns false on CPUs that aren't using Intel instruction sets. -// -// returns SDL_TRUE if the CPU has AVX features or SDL_FALSE if not. -// -// NOTE This function is available since SDL 2.0.2. -// -// See also: SDL_Has3DNow -// See also: SDL_HasAltiVec -// See also: SDL_HasAVX2 -// See also: SDL_HasMMX -// See also: SDL_HasRDTSC -// See also: SDL_HasSSE -// See also: SDL_HasSSE2 -// See also: SDL_HasSSE3 -// See also: SDL_HasSSE41 -// See also: SDL_HasSSE42 +// has_avx returns true if the CPU has AVX features. pub fn has_avx() bool { return C.SDL_HasAVX() } fn C.SDL_HasAVX2() bool -// has_avx2 determines whether the CPU has AVX2 features. -// -// This always returns false on CPUs that aren't using Intel instruction sets. -// -// returns SDL_TRUE if the CPU has AVX2 features or SDL_FALSE if not. -// -// NOTE This function is available since SDL 2.0.4. -// -// See also: SDL_Has3DNow -// See also: SDL_HasAltiVec -// See also: SDL_HasAVX -// See also: SDL_HasMMX -// See also: SDL_HasRDTSC -// See also: SDL_HasSSE -// See also: SDL_HasSSE2 -// See also: SDL_HasSSE3 -// See also: SDL_HasSSE41 -// See also: SDL_HasSSE42 +// has_avx2 returns true if the CPU has AVX2 features. pub fn has_avx2() bool { return C.SDL_HasAVX2() } -fn C.SDL_HasAVX512F() bool - -// has_avx512f determines whether the CPU has AVX-512F (foundation) features. -// -// This always returns false on CPUs that aren't using Intel instruction sets. -// -// returns SDL_TRUE if the CPU has AVX-512F features or SDL_FALSE if not. -// -// NOTE This function is available since SDL 2.0.9. -// -// See also: SDL_HasAVX -pub fn has_avx512f() bool { - return C.SDL_HasAVX512F() -} - -fn C.SDL_HasARMSIMD() bool - -// has_arm_simd determines whether the CPU has ARM SIMD (ARMv6) features. -// -// This is different from ARM NEON, which is a different instruction set. -// -// This always returns false on CPUs that aren't using ARM instruction sets. -// -// returns SDL_TRUE if the CPU has ARM SIMD features or SDL_FALSE if not. -// -// NOTE This function is available since SDL 2.0.12. -// -// See also: SDL_HasNEON -pub fn has_arm_simd() bool { - return C.SDL_HasARMSIMD() -} - fn C.SDL_HasNEON() bool -// has_neon determines whether the CPU has NEON (ARM SIMD) features. -// -// This always returns false on CPUs that aren't using ARM instruction sets. -// -// NOTE This function is available since SDL 2.0.6. -// -// returns SDL_TRUE if the CPU has ARM NEON features or SDL_FALSE if not. +// has_neon returns true if the CPU has NEON (ARM SIMD) features. pub fn has_neon() bool { return C.SDL_HasNEON() } -fn C.SDL_HasLSX() bool - -// has_lsx determines whether the CPU has LSX (LOONGARCH SIMD) features. -// -// This always returns false on CPUs that aren't using LOONGARCH instruction -// sets. -// -// returns SDL_TRUE if the CPU has LOONGARCH LSX features or SDL_FALSE if -// not. -// -// NOTE This function is available since SDL 2.24.0. -pub fn has_lsx() bool { - return C.SDL_HasLSX() -} - -fn C.SDL_HasLASX() bool - -// has_lasx determines whether the CPU has LASX (LOONGARCH SIMD) features. -// -// This always returns false on CPUs that aren't using LOONGARCH instruction -// sets. -// -// returns SDL_TRUE if the CPU has LOONGARCH LASX features or SDL_FALSE if -// not. -// -// NOTE This function is available since SDL 2.24.0. -pub fn has_lasx() bool { - return C.SDL_HasLASX() -} - fn C.SDL_GetSystemRAM() int -// get_system_ram gets the amount of RAM configured in the system. -// -// returns the amount of RAM configured in the system in MiB. -// -// NOTE This function is available since SDL 2.0.1. +// get_system_ram returns the amount of RAM configured in the system, in MB. pub fn get_system_ram() int { return C.SDL_GetSystemRAM() } - -fn C.SDL_SIMDGetAlignment() usize - -// simd_get_alignment reports the alignment this system needs for SIMD allocations. -// -// This will return the minimum number of bytes to which a pointer must be -// aligned to be compatible with SIMD instructions on the current machine. For -// example, if the machine supports SSE only, it will return 16, but if it -// supports AVX-512F, it'll return 64 (etc). This only reports values for -// instruction sets SDL knows about, so if your SDL build doesn't have -// SDL_HasAVX512F(), then it might return 16 for the SSE support it sees and -// not 64 for the AVX-512 instructions that exist but SDL doesn't know about. -// Plan accordingly. -// -// returns the alignment in bytes needed for available, known SIMD -// instructions. -// -// NOTE This function is available since SDL 2.0.10. -pub fn simd_get_alignment() usize { - return C.SDL_SIMDGetAlignment() -} - -fn C.SDL_SIMDAlloc(len usize) voidptr - -// simd_alloc allocates memory in a SIMD-friendly way. -// -// This will allocate a block of memory that is suitable for use with SIMD -// instructions. Specifically, it will be properly aligned and padded for the -// system's supported vector instructions. -// -// The memory returned will be padded such that it is safe to read or write an -// incomplete vector at the end of the memory block. This can be useful so you -// don't have to drop back to a scalar fallback at the end of your SIMD -// processing loop to deal with the final elements without overflowing the -// allocated buffer. -// -// You must free this memory with SDL_FreeSIMD(), not free() or SDL_free() or -// delete[], etc. -// -// Note that SDL will only deal with SIMD instruction sets it is aware of; for -// example, SDL 2.0.8 knows that SSE wants 16-byte vectors (SDL_HasSSE()), and -// AVX2 wants 32 bytes (SDL_HasAVX2()), but doesn't know that AVX-512 wants -// 64. To be clear: if you can't decide to use an instruction set with an -// SDL_Has*() function, don't use that instruction set with memory allocated -// through here. -// -// SDL_AllocSIMD(0) will return a non-NULL pointer, assuming the system isn't -// out of memory, but you are not allowed to dereference it (because you only -// own zero bytes of that buffer). -// -// `len` The length, in bytes, of the block to allocate. The actual -// allocated block might be larger due to padding, etc. -// returns a pointer to the newly-allocated block, NULL if out of memory. -// -// NOTE This function is available since SDL 2.0.10. -// -// See also: SDL_SIMDGetAlignment -// See also: SDL_SIMDRealloc -// See also: SDL_SIMDFree -pub fn simd_alloc(len usize) voidptr { - return C.SDL_SIMDAlloc(len) -} - -fn C.SDL_SIMDRealloc(mem voidptr, len usize) voidptr - -// simd_realloc reallocates memory obtained from SDL_SIMDAlloc -// -// It is not valid to use this function on a pointer from anything but -// SDL_SIMDAlloc(). It can't be used on pointers from malloc, realloc, -// SDL_malloc, memalign, new[], etc. -// -// `mem` The pointer obtained from SDL_SIMDAlloc. This function also -// accepts NULL, at which point this function is the same as -// calling SDL_SIMDAlloc with a NULL pointer. -// `len` The length, in bytes, of the block to allocated. The actual -// allocated block might be larger due to padding, etc. Passing 0 -// will return a non-NULL pointer, assuming the system isn't out of -// memory. -// returns a pointer to the newly-reallocated block, NULL if out of memory. -// -// NOTE This function is available since SDL 2.0.14. -// -// See also: SDL_SIMDGetAlignment -// See also: SDL_SIMDAlloc -// See also: SDL_SIMDFree -pub fn simd_realloc(mem voidptr, len usize) voidptr { - return C.SDL_SIMDRealloc(mem, len) -} - -fn C.SDL_SIMDFree(ptr voidptr) - -// simd_free deallocates memory obtained from SDL_SIMDAlloc -// -// It is not valid to use this function on a pointer from anything but -// SDL_SIMDAlloc() or SDL_SIMDRealloc(). It can't be used on pointers from -// malloc, realloc, SDL_malloc, memalign, new[], etc. -// -// However, SDL_SIMDFree(NULL) is a legal no-op. -// -// The memory pointed to by `ptr` is no longer valid for access upon return, -// and may be returned to the system or reused by a future allocation. The -// pointer passed to this function is no longer safe to dereference once this -// function returns, and should be discarded. -// -// `ptr` The pointer, returned from SDL_SIMDAlloc or SDL_SIMDRealloc, to -// deallocate. NULL is a legal no-op. -// -// NOTE This function is available since SDL 2.0.10. -// -// See also: SDL_SIMDAlloc -// See also: SDL_SIMDRealloc -pub fn simd_free(ptr voidptr) { - C.SDL_SIMDFree(ptr) -} diff --git a/endian.c.v b/endian.c.v index 152e2143..9c7be1eb 100644 --- a/endian.c.v +++ b/endian.c.v @@ -11,12 +11,10 @@ pub const lil_endian = C.SDL_LIL_ENDIAN pub const big_endian = C.SDL_BIG_ENDIAN pub const byteorder = C.SDL_BYTEORDER -// TODO SDL_endian.h fails on `tcc` with: -// 2.0.18/include/SDL2/SDL_endian.h:125: error: unknown constraint 'Q' -// fn C.SDL_Swap16(x u16) u16 -// pub fn swap16(x u16) u16 { -// return C.SDL_Swap16(x) -// } +fn C.SDL_Swap16(x u16) u16 +pub fn swap16(x u16) u16 { + return C.SDL_Swap16(x) +} fn C.SDL_Swap32(x u32) u32 pub fn swap32(x u32) u32 { diff --git a/error.c.v b/error.c.v index a4ffa435..354d729f 100644 --- a/error.c.v +++ b/error.c.v @@ -13,70 +13,12 @@ extern DECLSPEC int SDLCALL SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fm */ fn C.SDL_GetError() &char -// get_error retrieves a message about the last error that occurred on the current -// thread. -// -// It is possible for multiple errors to occur before calling SDL_GetError(). -// Only the last error is returned. -// -// The message is only applicable when an SDL function has signaled an error. -// You must check the return values of SDL function calls to determine when to -// appropriately call SDL_GetError(). You should *not* use the results of -// SDL_GetError() to decide if an error has occurred! Sometimes SDL will set -// an error string even when reporting success. -// -// SDL will *not* clear the error string for successful API calls. You *must* -// check return values for failure cases before you can assume the error -// string applies. -// -// Error strings are set per-thread, so an error set in a different thread -// will not interfere with the current thread's operation. -// -// The returned string is internally allocated and must not be freed by the -// application. -// -// returns a message with information about the specific error that occurred, -// or an empty string if there hasn't been an error message set since -// the last call to SDL_ClearError(). The message is only applicable -// when an SDL function has signaled an error. You must check the -// return values of SDL function calls to determine when to -// appropriately call SDL_GetError(). -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_ClearError -// See also: SDL_SetError +// get_error SDL_SetError() unconditionally returns -1. pub fn get_error() &char { return C.SDL_GetError() } -fn C.SDL_GetErrorMsg(errstr &char, maxlen int) &char - -// get_error_msg gets the last error message that was set for the current thread. -// -// This allows the caller to copy the error string into a provided buffer, but -// otherwise operates exactly the same as SDL_GetError(). -// -// `errstr` A buffer to fill with the last error message that was set for -// the current thread -// `maxlen` The size of the buffer pointed to by the errstr parameter -// returns the pointer passed in as the `errstr` parameter. -// -// NOTE This function is available since SDL 2.0.14. -// -// See also: SDL_GetError -pub fn get_error_msg(errstr &char, maxlen int) &char { - return C.SDL_GetErrorMsg(errstr, maxlen) -} - fn C.SDL_ClearError() - -// clear_error clears any previous error message for this thread. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetError -// See also: SDL_SetError pub fn clear_error() { C.SDL_ClearError() } diff --git a/events.c.v b/events.c.v index 17624a73..b0e43d63 100644 --- a/events.c.v +++ b/events.c.v @@ -23,119 +23,92 @@ pub const disable = C.SDL_DISABLE // 0 pub const enable = C.SDL_ENABLE // 1 -// EventFilter is a function pointer used for callbacks that watch the event queue. -// -// `userdata` what was passed as `userdata` to SDL_SetEventFilter() -// or SDL_AddEventWatch, etc -// `event` the event that triggered the callback -// returns 1 to permit event to be added to the queue, and 0 to disallow -// it. When used with SDL_AddEventWatch, the return value is ignored. -// -// See also: SDL_SetEventFilter -// See also: SDL_AddEventWatch -// // EventFilter is equivalent to the SDL C callback: // `typedef int (SDLCALL * SDL_EventFilter) (void *userdata, SDL_Event * event);` pub type EventFilter = fn (userdata voidptr, event &Event) // EventType is C.SDL_EventType pub enum EventType { - firstevent = C.SDL_FIRSTEVENT // Unused (do not remove) - quit = C.SDL_QUIT // 0x100 User-requested quit + firstevent = C.SDL_FIRSTEVENT // Unused (do not remove) + quit = C.SDL_QUIT // 0x100 User-requested quit // These application events have special meaning on iOS, see README-ios.md in SDL for details // The application is being terminated by the OS // Called on iOS in applicationWillTerminate() // Called on Android in onDestroy() - app_terminating = C.SDL_APP_TERMINATING + app_terminating = C.SDL_APP_TERMINATING // The application is low on memory, free memory if possible. // Called on iOS in applicationDidReceiveMemoryWarning() // Called on Android in onLowMemory() - app_lowmemory = C.SDL_APP_LOWMEMORY + app_lowmemory = C.SDL_APP_LOWMEMORY // The application is about to enter the background // Called on iOS in applicationWillResignActive() // Called on Android in onPause() - app_willenterbackground = C.SDL_APP_WILLENTERBACKGROUND + app_willenterbackground = C.SDL_APP_WILLENTERBACKGROUND // The application did enter the background and may not get CPU for some time // Called on iOS in applicationDidEnterBackground() // Called on Android in onPause() - app_didenterbackground = C.SDL_APP_DIDENTERBACKGROUND + app_didenterbackground = C.SDL_APP_DIDENTERBACKGROUND // The application is about to enter the foreground // Called on iOS in applicationWillEnterForeground() // Called on Android in onResume() - app_willenterforeground = C.SDL_APP_WILLENTERFOREGROUND + app_willenterforeground = C.SDL_APP_WILLENTERFOREGROUND // The application is now interactive // Called on iOS in applicationDidBecomeActive() // Called on Android in onResume() - app_didenterforeground = C.SDL_APP_DIDENTERFOREGROUND - localechanged = C.SDL_LOCALECHANGED // The user's locale preferences have changed. - // Display events - displayevent = C.SDL_DISPLAYEVENT // 0x150 Display state change + app_didenterforeground = C.SDL_APP_DIDENTERFOREGROUND // Window events - windowevent = C.SDL_WINDOWEVENT // 0x200 Window state change - syswmevent = C.SDL_SYSWMEVENT + windowevent = C.SDL_WINDOWEVENT // 0x200 Window state change + syswmevent = C.SDL_SYSWMEVENT // Keyboard events - keydown = C.SDL_KEYDOWN // 0x300, Key pressed - keyup = C.SDL_KEYUP // Key released - textediting = C.SDL_TEXTEDITING // Keyboard text editing (composition) - textinput = C.SDL_TEXTINPUT // Keyboard text input - keymapchanged = C.SDL_KEYMAPCHANGED // Keymap changed due to a system event such as an input language or keyboard layout change. - textediting_ext = C.SDL_TEXTEDITING_EXT // Extended keyboard text editing (composition) + keydown = C.SDL_KEYDOWN // 0x300, Key pressed + keyup = C.SDL_KEYUP // Key released + textediting = C.SDL_TEXTEDITING // Keyboard text editing (composition) + textinput = C.SDL_TEXTINPUT // Keyboard text input + keymapchanged = C.SDL_KEYMAPCHANGED // Keymap changed due to a system event such as an input language or keyboard layout change. // Mouse events - mousemotion = C.SDL_MOUSEMOTION // 0x400, Mouse moved - mousebuttondown = C.SDL_MOUSEBUTTONDOWN // Mouse button pressed - mousebuttonup = C.SDL_MOUSEBUTTONUP // Mouse button released - mousewheel = C.SDL_MOUSEWHEEL // Mouse wheel motion + mousemotion = C.SDL_MOUSEMOTION // 0x400, Mouse moved + mousebuttondown = C.SDL_MOUSEBUTTONDOWN // Mouse button pressed + mousebuttonup = C.SDL_MOUSEBUTTONUP // Mouse button released + mousewheel = C.SDL_MOUSEWHEEL // Mouse wheel motion // Joystick events - joyaxismotion = C.SDL_JOYAXISMOTION // 0x600, Joystick axis motion - joyballmotion = C.SDL_JOYBALLMOTION // Joystick trackball motion - joyhatmotion = C.SDL_JOYHATMOTION // Joystick hat position change - joybuttondown = C.SDL_JOYBUTTONDOWN // Joystick button pressed - joybuttonup = C.SDL_JOYBUTTONUP // Joystick button released - joydeviceadded = C.SDL_JOYDEVICEADDED // A new joystick has been inserted into the system - joydeviceremoved = C.SDL_JOYDEVICEREMOVED // An opened joystick has been removed - joybatteryupdated = C.SDL_JOYBATTERYUPDATED // Joystick battery level change + joyaxismotion = C.SDL_JOYAXISMOTION // 0x600, Joystick axis motion + joyballmotion = C.SDL_JOYBALLMOTION // Joystick trackball motion + joyhatmotion = C.SDL_JOYHATMOTION // Joystick hat position change + joybuttondown = C.SDL_JOYBUTTONDOWN // Joystick button pressed + joybuttonup = C.SDL_JOYBUTTONUP // Joystick button released + joydeviceadded = C.SDL_JOYDEVICEADDED // A new joystick has been inserted into the system + joydeviceremoved = C.SDL_JOYDEVICEREMOVED // An opened joystick has been removed // Game controller events - controlleraxismotion = C.SDL_CONTROLLERAXISMOTION // 0x650, Game controller axis motion - controllerbuttondown = C.SDL_CONTROLLERBUTTONDOWN // Game controller button pressed - controllerbuttonup = C.SDL_CONTROLLERBUTTONUP // Game controller button released - controllerdeviceadded = C.SDL_CONTROLLERDEVICEADDED // A new Game controller has been inserted into the system - controllerdeviceremoved = C.SDL_CONTROLLERDEVICEREMOVED // An opened Game controller has been removed - controllerdeviceremapped = C.SDL_CONTROLLERDEVICEREMAPPED // The controller mapping was updated - controllertouchpaddown = C.SDL_CONTROLLERTOUCHPADDOWN // Game controller touchpad was touched - controllertouchpadmotion = C.SDL_CONTROLLERTOUCHPADMOTION // Game controller touchpad finger was moved - controllertouchpadup = C.SDL_CONTROLLERTOUCHPADUP // Game controller touchpad finger was lifted - controllersensorupdate = C.SDL_CONTROLLERSENSORUPDATE // Game controller sensor was updated - controllerupdatecomplete_reserved_for_sdl3 = C.SDL_CONTROLLERUPDATECOMPLETE_RESERVED_FOR_SDL3 - controllersteamhandleupdated = C.SDL_CONTROLLERSTEAMHANDLEUPDATED // Game controller Steam handle has changed + controlleraxismotion = C.SDL_CONTROLLERAXISMOTION // 0x650, Game controller axis motion + controllerbuttondown = C.SDL_CONTROLLERBUTTONDOWN // Game controller button pressed + controllerbuttonup = C.SDL_CONTROLLERBUTTONUP // Game controller button released + controllerdeviceadded = C.SDL_CONTROLLERDEVICEADDED // A new Game controller has been inserted into the system + controllerdeviceremoved = C.SDL_CONTROLLERDEVICEREMOVED // An opened Game controller has been removed + controllerdeviceremapped = C.SDL_CONTROLLERDEVICEREMAPPED // The controller mapping was updated // Touch events - fingerdown = C.SDL_FINGERDOWN // 0x700 - fingerup = C.SDL_FINGERUP - fingermotion = C.SDL_FINGERMOTION + fingerdown = C.SDL_FINGERDOWN // 0x700 + fingerup = C.SDL_FINGERUP + fingermotion = C.SDL_FINGERMOTION // Gesture events - dollargesture = C.SDL_DOLLARGESTURE // 0x800 - dollarrecord = C.SDL_DOLLARRECORD - multigesture = C.SDL_MULTIGESTURE + dollargesture = C.SDL_DOLLARGESTURE // 0x800 + dollarrecord = C.SDL_DOLLARRECORD + multigesture = C.SDL_MULTIGESTURE // Clipboard events - clipboardupdate = C.SDL_CLIPBOARDUPDATE // 0x900 The clipboard or primary selection changed + clipboardupdate = C.SDL_CLIPBOARDUPDATE // 0x900 The clipboard changed // Drag and drop events - dropfile = C.SDL_DROPFILE // 0x1000 The system requests a file open - droptext = C.SDL_DROPTEXT // text/plain drag-and-drop event - dropbegin = C.SDL_DROPBEGIN // A new set of drops is beginning (NULL filename) - dropcomplete = C.SDL_DROPCOMPLETE // Current set of drops is now complete (NULL filename) + dropfile = C.SDL_DROPFILE // 0x1000 The system requests a file open + droptext = C.SDL_DROPTEXT // text/plain drag-and-drop event + dropbegin = C.SDL_DROPBEGIN // A new set of drops is beginning (NULL filename) + dropcomplete = C.SDL_DROPCOMPLETE // Current set of drops is now complete (NULL filename) // Audio hotplug events - audiodeviceadded = C.SDL_AUDIODEVICEADDED // 0x1100 A new audio device is available - audiodeviceremoved = C.SDL_AUDIODEVICEREMOVED // An audio device has been removed. - // Sensor events - sensorupdate = C.SDL_SENSORUPDATE // 0x1200 A sensor was updated + audiodeviceadded = C.SDL_AUDIODEVICEADDED // 0x1100 A new audio device is available + audiodeviceremoved = C.SDL_AUDIODEVICEREMOVED // An audio device has been removed. // Render events - render_targets_reset = C.SDL_RENDER_TARGETS_RESET // 0x2000 The render targets have been reset and their contents need to be updated - render_device_reset = C.SDL_RENDER_DEVICE_RESET // The device has been reset and all textures need to be recreated - // Internal events - pollsentinel = C.SDL_POLLSENTINEL // 0x7F00, Signals the end of an event poll cycle - // Events ::SDL_USEREVENT through ::SDL_LASTEVENT are for your use, and should be allocated with SDL_RegisterEvents() - userevent = C.SDL_USEREVENT + render_targets_reset = C.SDL_RENDER_TARGETS_RESET // 0x2000 The render targets have been reset and their contents need to be updated + render_device_reset = C.SDL_RENDER_DEVICE_RESET /// The device has been reset and all textures need to be recreated + userevent = C.SDL_USEREVENT // Events ::SDL_USEREVENT through ::SDL_LASTEVENT are for your use, and should be allocated with SDL_RegisterEvents() // This last event is only for bounding internal arrays - lastevent = C.SDL_LASTEVENT // 0xFFFF + lastevent = C.SDL_LASTEVENT // 0xFFFF } // CommonEvent is fields shared by every event @@ -148,23 +121,6 @@ pub: pub type CommonEvent = C.SDL_CommonEvent -// DisplayEvent is display state change event data (event.display.*) -// DisplayEvent is C.SDL_DisplayEvent -@[typedef] -pub struct C.SDL_DisplayEvent { -pub: - @type u32 // ::SDL_DISPLAYEVENT - timestamp u32 // In milliseconds, populated using SDL_GetTicks() - display u32 // The associated display index - event u8 // ::SDL_DisplayEventID - padding1 u8 // - padding2 u8 // - padding3 u8 // - data1 int // event dependent data -} - -pub type DisplayEvent = C.SDL_DisplayEvent - // WindowEvent is window state change event data (event.window.*) @[typedef] pub struct C.SDL_WindowEvent { @@ -212,20 +168,6 @@ pub: pub type TextEditingEvent = C.SDL_TextEditingEvent -// TextEditingExtEvent is an extended keyboard text editing event structure (event.editExt.*) when text would be -// truncated if stored in the text buffer SDL_TextEditingEvent -@[typedef] -pub struct C.SDL_TextEditingExtEvent { - @type u32 // ::SDL_TEXTEDITING_EXT - timestamp u32 // In milliseconds, populated using SDL_GetTicks() - windowID u32 // The window with keyboard focus, if any - text &char // The editing text, which should be freed with SDL_free(), and will not be NULL - start int // The start cursor of selected editing text - length int // The length of selected editing text -} - -pub type TextEditingExtEvent = C.SDL_TextEditingExtEvent - // TextInputEvent is keyboard text input event structure (event.text.*) @[typedef] pub struct C.SDL_TextInputEvent { @@ -284,10 +226,6 @@ pub: x int // The amount scrolled horizontally, positive to the right and negative to the left y int // The amount scrolled vertically, positive away from the user and negative toward the user direction u32 // Set to one of the SDL_MOUSEWHEEL_* defines. When FLIPPED the values in X and Y will be opposite. Multiply by -1 to change them back - preciseX f32 // The amount scrolled horizontally, positive to the right and negative to the left, with float precision (added in 2.0.18) - preciseY f32 // The amount scrolled vertically, positive away from the user and negative toward the user, with float precision (added in 2.0.18) - mouseX int // X coordinate, relative to window (added in 2.26.0) - mouseY int // Y coordinate, relative to window (added in 2.26.0) } pub type MouseWheelEvent = C.SDL_MouseWheelEvent @@ -371,17 +309,6 @@ pub: pub type JoyDeviceEvent = C.SDL_JoyDeviceEvent -// JoyBatteryEvent is joysick battery level change event structure (event.jbattery.*) -@[typedef] -pub struct C.SDL_JoyBatteryEvent { - @type u32 // ::SDL_JOYBATTERYUPDATED - timestamp u32 // In milliseconds, populated using SDL_GetTicks() - which JoystickID // The joystick instance id - level JoystickPowerLevel // The joystick battery level -} - -pub type JoyBatteryEvent = C.SDL_JoyBatteryEvent - // ControllerAxisEvent is game controller axis motion event structure (event.caxis.*) @[typedef] pub struct C.SDL_ControllerAxisEvent { @@ -418,42 +345,13 @@ pub type ControllerButtonEvent = C.SDL_ControllerButtonEvent @[typedef] pub struct C.SDL_ControllerDeviceEvent { pub: - @type EventType // ::SDL_CONTROLLERDEVICEADDED, ::SDL_CONTROLLERDEVICEREMOVED, ::SDL_CONTROLLERDEVICEREMAPPED, or ::SDL_CONTROLLERSTEAMHANDLEUPDATED + @type EventType // ::SDL_CONTROLLERDEVICEADDED, ::SDL_CONTROLLERDEVICEREMOVED, or ::SDL_CONTROLLERDEVICEREMAPPED timestamp u32 // In milliseconds, populated using SDL_GetTicks() which int // The joystick device index for the ADDED event, instance id for the REMOVED or REMAPPED event } pub type ControllerDeviceEvent = C.SDL_ControllerDeviceEvent -// ControllerTouchpadEvent is game controller touchpad event structure (event.ctouchpad.*) -@[typedef] -pub struct C.SDL_ControllerTouchpadEvent { -pub: - @type u32 // ::SDL_CONTROLLERTOUCHPADDOWN or ::SDL_CONTROLLERTOUCHPADMOTION or ::SDL_CONTROLLERTOUCHPADUP - timestamp u32 // In milliseconds, populated using SDL_GetTicks() - which JoystickID // The joystick instance id - touchpad int // The index of the touchpad - finger int // The index of the finger on the touchpad - x f32 // Normalized in the range 0...1 with 0 being on the left - y f32 // Normalized in the range 0...1 with 0 being at the top - pressure f32 // Normalized in the range 0...1 -} - -pub type ControllerTouchpadEvent = C.SDL_ControllerTouchpadEvent - -@[typedef] -pub struct C.SDL_ControllerSensorEvent { -pub: - @type u32 // ::SDL_CONTROLLERSENSORUPDATE - timestamp u32 // In milliseconds, populated using SDL_GetTicks() - which JoystickID // The joystick instance id - sensor int // The type of the sensor, one of the values of ::SDL_SensorType - data [3]f32 // Up to 3 values from the sensor, as defined in SDL_sensor.h - timestamp_us u64 // The timestamp of the sensor reading in microseconds, if the hardware provides this information. -} - -pub type ControllerSensorEvent = C.SDL_ControllerSensorEvent - // AudioDeviceEvent is audio device event structure (event.adevice.*) @[typedef] pub struct C.SDL_AudioDeviceEvent { @@ -482,7 +380,6 @@ pub: dx f32 // Normalized in the range -1...1 dy f32 // Normalized in the range -1...1 pressure f32 // Normalized in the range 0...1 - windowID u32 // The window underneath the finger, if any } pub type TouchFingerEvent = C.SDL_TouchFingerEvent @@ -535,29 +432,25 @@ pub: pub type DropEvent = C.SDL_DropEvent -// SensorEvent is sensor event structure (event.sensor.*) -// SensorEvent is C.SDL_SensorEvent +// QuitEvent is the "quit requested" event @[typedef] -pub struct C.SDL_SensorEvent { +pub struct C.SDL_QuitEvent { pub: - @type u32 // ::SDL_SENSORUPDATE - timestamp u32 // In milliseconds, populated using SDL_GetTicks() - which int // The instance ID of the sensor - data [6]f32 // Up to 6 values from the sensor - additional values can be queried using SDL_SensorGetData() - timestamp_us u64 // The timestamp of the sensor reading in microseconds, if the hardware provides this information. + @type EventType // ::SDL_QUIT + timestamp u32 // In milliseconds, populated using SDL_GetTicks() } -pub type SensorEvent = C.SDL_SensorEvent +pub type QuitEvent = C.SDL_QuitEvent -// QuitEvent is the "quit requested" event +// OSEvent is an OS Specific event @[typedef] -pub struct C.SDL_QuitEvent { +pub struct C.SDL_OSEvent { pub: @type EventType // ::SDL_QUIT timestamp u32 // In milliseconds, populated using SDL_GetTicks() } -pub type QuitEvent = C.SDL_QuitEvent +pub type OSEvent = C.SDL_OSEvent // UserEvent is an user-defined event type (event.user.*) @[typedef] @@ -593,49 +486,29 @@ pub: pub type SysWMEvent = C.SDL_SysWMEvent -/* -TODO -const v_event_padding_size = v_get_event_padding_size() - -fn v_get_event_padding_size() int { - if sizeof(voidptr) <= 8 { - return 56 - } else if sizeof(voidptr) == 16 { - return 64 - } - return 3 * sizeof(voidptr) -} -*/ - // Event is a general event structure. @[typedef] pub union C.SDL_Event { pub: @type EventType // Event type, shared with all events // - common CommonEvent // C.SDL_CommonEvent // Common event data - display DisplayEvent // C.SDL_DisplayEvent // Display event data - window WindowEvent // C.SDL_WindowEvent // Window event data - key KeyboardEvent // C.SDL_KeyboardEvent // Keyboard event data - edit TextEditingEvent // C.SDL_TextEditingEvent // Text editing event data - editExt TextEditingExtEvent // C.SDL_TextEditingExtEvent // Extended text editing event data - text TextInputEvent // C.SDL_TextInputEvent // Text input event data - motion MouseMotionEvent // C.SDL_MouseMotionEvent // Mouse motion event data - button MouseButtonEvent // C.SDL_MouseButtonEvent // Mouse button event data - wheel MouseWheelEvent // C.SDL_MouseWheelEvent // Mouse wheel event data - jaxis JoyAxisEvent // C.SDL_JoyAxisEvent // Joystick axis event data - jball JoyBallEvent // C.SDL_JoyBallEvent // Joystick ball event data - jhat JoyHatEvent // C.SDL_JoyHatEvent // Joystick hat event data - jbutton JoyButtonEvent // C.SDL_JoyButtonEvent // Joystick button event data - jdevice JoyDeviceEvent // C.SDL_JoyDeviceEvent // Joystick device change event data - jbattery JoyBatteryEvent // C.SDL_JoyBatteryEvent // Joystick battery event data - caxis ControllerAxisEvent // C.SDL_ControllerAxisEvent // Game Controller axis event data - cbutton ControllerButtonEvent // C.SDL_ControllerButtonEvent // Game Controller button event data - cdevice ControllerDeviceEvent // C.SDL_ControllerDeviceEvent // Game Controller device event data - ctouchpad ControllerTouchpadEvent // C.SDL_ControllerTouchpadEvent // Game Controller touchpad event data - csensor ControllerSensorEvent // C.SDL_ControllerSensorEvent // Game Controller sensor event data - adevice AudioDeviceEvent // C.SDL_AudioDeviceEvent // Audio device event data - sensor SensorEvent // C.SDL_SensorEvent // Sensor event data + common CommonEvent // C.SDL_CommonEvent // Common event data + window WindowEvent // C.SDL_WindowEvent // Window event data + key KeyboardEvent // C.SDL_KeyboardEvent // Keyboard event data + edit TextEditingEvent // C.SDL_TextEditingEvent // Text editing event data + text TextInputEvent // C.SDL_TextInputEvent // Text input event data + motion MouseMotionEvent // C.SDL_MouseMotionEvent // Mouse motion event data + button MouseButtonEvent // C.SDL_MouseButtonEvent // Mouse button event data + wheel MouseWheelEvent // C.SDL_MouseWheelEvent // Mouse wheel event data + jaxis JoyAxisEvent // C.SDL_JoyAxisEvent // Joystick axis event data + jball JoyBallEvent // C.SDL_JoyBallEvent // Joystick ball event data + jhat JoyHatEvent // C.SDL_JoyHatEvent // Joystick hat event data + jbutton JoyButtonEvent // C.SDL_JoyButtonEvent // Joystick button event data + jdevice JoyDeviceEvent // C.SDL_JoyDeviceEvent // Joystick device change event data + caxis ControllerAxisEvent // C.SDL_ControllerAxisEvent // Game Controller axis event data + cbutton ControllerButtonEvent // C.SDL_ControllerButtonEvent // Game Controller button event data + cdevice ControllerDeviceEvent // C.SDL_ControllerDeviceEvent // Game Controller device event data + adevice AudioDeviceEvent // C.SDL_AudioDeviceEvent // Audio device event data // quit QuitEvent // C.SDL_QuitEvent // Quit request event data @@ -645,20 +518,12 @@ pub: mgesture MultiGestureEvent // C.SDL_MultiGestureEvent // Gesture event data dgesture DollarGestureEvent // C.SDL_DollarGestureEvent // Gesture event data drop DropEvent // C.SDL_DropEvent // Drag and drop event data - // This is necessary for ABI compatibility between Visual C++ and GCC. - // Visual C++ will respect the push pack pragma and use 52 bytes (size of - // SDL_TextEditingEvent, the largest structure for 32-bit and 64-bit - // architectures) for this union, and GCC will use the alignment of the - // largest datatype within the union, which is 8 bytes on 64-bit - // architectures. - // + // This is necessary for ABI compatibility between Visual C++ and GCC + // Visual C++ will respect the push pack pragma and use 52 bytes for + // this structure, and GCC will use the alignment of the largest datatype + // within the union, which is 8 bytes. // So... we'll add padding to force the size to be 56 bytes for both. - // - // On architectures where pointers are 16 bytes, this needs rounding up to - // the next multiple of 16, 64, and on architectures where pointers are - // even larger the size of SDL_UserEvent will dominate as being 3 pointers. - padding [56]u8 // TODO v_event_padding_size?? - // Uint8 padding[sizeof(void *) <= 8 ? 56 : sizeof(void *) == 16 ? 64 : 3 * sizeof(void *)]; + padding [56]u8 } pub type Event = C.SDL_Event @@ -669,22 +534,7 @@ fn C.SDL_PumpEvents() // // This function updates the event queue and internal input device state. // -// **WARNING**: This should only be run in the thread that initialized the -// video subsystem, and for extra safety, you should consider only doing those -// things on the main thread in any case. -// -// SDL_PumpEvents() gathers all the pending input information from devices and -// places it in the event queue. Without calls to SDL_PumpEvents() no events -// would ever be placed on the queue. Often the need for calls to -// SDL_PumpEvents() is hidden from the user since SDL_PollEvent() and -// SDL_WaitEvent() implicitly call SDL_PumpEvents(). However, if you are not -// polling or waiting for events (e.g. you are filtering them), then you must -// call SDL_PumpEvents() to force an event queue update. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_PollEvent -// See also: SDL_WaitEvent +// This should only be run in the thread that sets the video mode. pub fn pump_events() { C.SDL_PumpEvents() } @@ -700,40 +550,20 @@ fn C.SDL_PeepEvents(events &C.SDL_Event, numevents int, action C.SDL_eventaction // peep_events checks the event queue for messages and optionally returns them. // -// `action` may be any of the following: -// -// - `SDL_ADDEVENT`: up to `numevents` events will be added to the back of the -// event queue. -// - `SDL_PEEKEVENT`: `numevents` events at the front of the event queue, -// within the specified minimum and maximum type, will be returned to the -// caller and will _not_ be removed from the queue. -// - `SDL_GETEVENT`: up to `numevents` events at the front of the event queue, -// within the specified minimum and maximum type, will be returned to the -// caller and will be removed from the queue.the back of the event queue. +// If `action` is ::SDL_ADDEVENT, up to `numevents` events will be added to +// the back of the event queue. // -// You may have to call SDL_PumpEvents() before calling this function. -// Otherwise, the events may not be ready to be filtered when you call -// SDL_PeepEvents(). -// -// This function is thread-safe. +// If `action` is ::SDL_PEEKEVENT, up to `numevents` events at the front +// of the event queue, within the specified minimum and maximum type, +// will be returned and will not be removed from the queue. // -// `events` destination buffer for the retrieved events -// `numevents` if action is SDL_ADDEVENT, the number of events to add -// back to the event queue; if action is SDL_PEEKEVENT or -// SDL_GETEVENT, the maximum number of events to retrieve -// `action` action to take; see [[#action|Remarks]] for details -// `minType` minimum value of the event type to be considered; -// SDL_FIRSTEVENT is a safe choice -// `maxType` maximum value of the event type to be considered; -// SDL_LASTEVENT is a safe choice -// returns the number of events actually stored or a negative error code on -// failure; call SDL_GetError() for more information. +// If `action` is ::SDL_GETEVENT, up to `numevents` events at the front +// of the event queue, within the specified minimum and maximum type, +// will be returned and will be removed from the queue. // -// NOTE This function is available since SDL 2.0.0. +// returns The number of events actually stored, or -1 if there was an error. // -// See also: SDL_PollEvent -// See also: SDL_PumpEvents -// See also: SDL_PushEvent +// This function is thread-safe. pub fn peep_events(events &Event, numevents int, action EventAction, min_type u32, max_type u32) int { return C.SDL_PeepEvents(unsafe { &C.SDL_Event(events) }, numevents, unsafe { C.SDL_eventaction(action) }, min_type, max_type) @@ -741,89 +571,27 @@ pub fn peep_events(events &Event, numevents int, action EventAction, min_type u3 fn C.SDL_HasEvent(@type u32) bool -// has_event checks for the existence of a certain event type in the event queue. -// -// If you need to check for a range of event types, use SDL_HasEvents() -// instead. -// -// `type` the type of event to be queried; see SDL_EventType for details -// returns SDL_TRUE if events matching `type` are present, or SDL_FALSE if -// events matching `type` are not present. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_HasEvents +// has_event checks to see if certain event types are in the event queue. pub fn has_event(@type EventType) bool { return C.SDL_HasEvent(u32(@type)) } fn C.SDL_HasEvents(min_type u32, max_type u32) bool - -// has_events checks for the existence of certain event types in the event queue. -// -// If you need to check for a single event type, use SDL_HasEvent() instead. -// -// `minType` the low end of event type to be queried, inclusive; see -// SDL_EventType for details -// `maxType` the high end of event type to be queried, inclusive; see -// SDL_EventType for details -// returns SDL_TRUE if events with type >= `minType` and <= `maxType` are -// present, or SDL_FALSE if not. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_HasEvent pub fn has_events(min_type u32, max_type u32) bool { return C.SDL_HasEvents(min_type, max_type) } fn C.SDL_FlushEvent(@type u32) -// flush_event clears events of a specific type from the event queue. -// -// This will unconditionally remove any events from the queue that match -// `type`. If you need to remove a range of event types, use SDL_FlushEvents() -// instead. -// -// It's also normal to just ignore events you don't care about in your event -// loop without calling this function. -// +// flush_event clears events from the event queue // This function only affects currently queued events. If you want to make // sure that all pending OS events are flushed, you can call SDL_PumpEvents() // on the main thread immediately before the flush call. -// -// `type` the type of event to be cleared; see SDL_EventType for details -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_FlushEvents pub fn flush_event(@type u32) { C.SDL_FlushEvent(@type) } fn C.SDL_FlushEvents(min_type u32, max_type u32) - -// Clear events of a range of types from the event queue. -// -// This will unconditionally remove any events from the queue that are in the -// range of `minType` to `maxType`, inclusive. If you need to remove a single -// event type, use SDL_FlushEvent() instead. -// -// It's also normal to just ignore events you don't care about in your event -// loop without calling this function. -// -// This function only affects currently queued events. If you want to make -// sure that all pending OS events are flushed, you can call SDL_PumpEvents() -// on the main thread immediately before the flush call. -// -// `minType` the low end of event type to be cleared, inclusive; see -// SDL_EventType for details -// `maxType` the high end of event type to be cleared, inclusive; see -// SDL_EventType for details -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_FlushEvent pub fn flush_events(min_type u32, max_type u32) { C.SDL_FlushEvents(min_type, max_type) } @@ -832,49 +600,10 @@ fn C.SDL_PollEvent(event &C.SDL_Event) int // poll_event polls for currently pending events. // -// If `event` is not NULL, the next event is removed from the queue and stored -// in the SDL_Event structure pointed to by `event`. The 1 returned refers to -// this event, immediately stored in the SDL Event structure -- not an event -// to follow. -// -// If `event` is NULL, it simply returns 1 if there is an event in the queue, -// but will not remove it from the queue. -// -// As this function may implicitly call SDL_PumpEvents(), you can only call -// this function in the thread that set the video mode. -// -// SDL_PollEvent() is the favored way of receiving system events since it can -// be done from the main loop and does not suspend the main loop while waiting -// on an event to be posted. -// -// The common practice is to fully process the event queue once every frame, -// usually as a first step before updating the game's state: -// -/* -```c - while (game_is_still_running) { - SDL_Event event; - while (SDL_PollEvent(&event)) { // poll until all events are handled! - // decide what to do with this event. - } - - // update game state, draw the current frame - } -``` -*/ -// -// `event` the SDL_Event structure to be filled with the next event from -// the queue, or NULL -// returns 1 if there is a pending event or 0 if there are none available. -// -// NOTE This function is available since SDL 2.0.0. +// returns 1 if there are any pending events, or 0 if there are none available. // -// See also: SDL_GetEventFilter -// See also: SDL_PeepEvents -// See also: SDL_PushEvent -// See also: SDL_SetEventFilter -// See also: SDL_WaitEvent -// See also: SDL_WaitEventTimeout +// `event` If not NULL, the next event is removed from the queue and +// stored in that area. pub fn poll_event(event &Event) int { return C.SDL_PollEvent(event) } @@ -883,50 +612,24 @@ fn C.SDL_WaitEvent(event &C.SDL_Event) int // wait_event waits indefinitely for the next available event. // -// If `event` is not NULL, the next event is removed from the queue and stored -// in the SDL_Event structure pointed to by `event`. -// stored in that area. -// As this function may implicitly call SDL_PumpEvents(), you can only call -// this function in the thread that initialized the video subsystem. -// -// `event` the SDL_Event structure to be filled in with the next event -// from the queue, or NULL -// returns 1 on success or 0 if there was an error while waiting for events; -// call SDL_GetError() for more information. +// returns 1, or 0 if there was an error while waiting for events. // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_PollEvent -// See also: SDL_PumpEvents -// See also: SDL_WaitEventTimeout +// `event` If not NULL, the next event is removed from the queue and +// stored in that area. pub fn wait_event(event &Event) int { return C.SDL_WaitEvent(event) } fn C.SDL_WaitEventTimeout(event &C.SDL_Event, timeout int) int -// wait_event_timeout waits until the specified timeout (in milliseconds) for the next available -// event. -// -// If `event` is not NULL, the next event is removed from the queue and stored -// in the SDL_Event structure pointed to by `event`. +// wait_event_timeout waits until the specified timeout (in milliseconds) for the next +// available event. // -// As this function may implicitly call SDL_PumpEvents(), you can only call -// this function in the thread that initialized the video subsystem. +// returns 1, or 0 if there was an error while waiting for events. // -// `event` the SDL_Event structure to be filled in with the next event -// from the queue, or NULL -// `timeout` the maximum number of milliseconds to wait for the next -// available event -// returns 1 on success or 0 if there was an error while waiting for events; -// call SDL_GetError() for more information. This also returns 0 if -// the timeout elapsed without an event arriving. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_PollEvent -// See also: SDL_PumpEvents -// See also: SDL_WaitEvent +// `event` If not NULL, the next event is removed from the queue and +// stored in that area. +// `timeout` The timeout (in milliseconds) to wait for next event. pub fn wait_event_timeout(event &Event, timeout int) int { return C.SDL_WaitEventTimeout(event, timeout) } @@ -935,34 +638,8 @@ fn C.SDL_PushEvent(event &C.SDL_Event) int // push_event adds an event to the event queue. // -// The event queue can actually be used as a two way communication channel. -// Not only can events be read from the queue, but the user can also push -// their own events onto it. `event` is a pointer to the event structure you -// wish to push onto the queue. The event is copied into the queue, and the -// caller may dispose of the memory pointed to after SDL_PushEvent() returns. -// -// NOTE Pushing device input events onto the queue doesn't modify the state -// of the device within SDL. -// -// This function is thread-safe, and can be called from other threads safely. -// -// NOTE Events pushed onto the queue with SDL_PushEvent() get passed through -// the event filter but events added with SDL_PeepEvents() do not. -// -// For pushing application-specific events, please use SDL_RegisterEvents() to -// get an event type that does not conflict with other code that also wants -// its own custom event types. -// -// `event` the SDL_Event to be added to the queue -// returns 1 on success, 0 if the event was filtered, or a negative error -// code on failure; call SDL_GetError() for more information. A -// common reason for error is the event queue being full. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_PeepEvents -// See also: SDL_PollEvent -// See also: SDL_RegisterEvents +// returns 1 on success, 0 if the event was filtered, or -1 if the event queue +// was full or there was some other error. pub fn push_event(event &Event) int { return C.SDL_PushEvent(event) } @@ -972,174 +649,82 @@ fn C.SDL_SetEventFilter(filter EventFilter, userdata voidptr) // set_event_filter sets up a filter to process all events before they change // internal state and are posted to the internal event queue. // -// If the filter function returns 1 when called, then the event will be added -// to the internal queue. If it returns 0, then the event will be dropped from -// the queue, but the internal state will still be updated. This allows -// selective filtering of dynamically arriving events. +// The filter is prototyped as: +/* +``` +int SDL_EventFilter(void *userdata, SDL_Event * event); +``` +*/ // -// **WARNING**: Be very careful of what you do in the event filter function, -// as it may run in a different thread! +// If the filter returns 1, then the event will be added to the internal queue. +// If it returns 0, then the event will be dropped from the queue, but the +// internal state will still be updated. This allows selective filtering of +// dynamically arriving events. // -// On platforms that support it, if the quit event is generated by an -// interrupt signal (e.g. pressing Ctrl-C), it will be delivered to the -// application at the next event poll. +// WARNING Be very careful of what you do in the event filter function, as +// it may run in a different thread! // -// There is one caveat when dealing with the ::SDL_QuitEvent event type. The +// There is one caveat when dealing with the ::SDL_QuitEvent event type. The // event filter is only called when the window manager desires to close the -// application window. If the event filter returns 1, then the window will be -// closed, otherwise the window will remain open if possible. -// -// Note: Disabled events never make it to the event filter function; see -// SDL_EventState(). -// -// Note: If you just want to inspect events without filtering, you should use -// SDL_AddEventWatch() instead. -// -// Note: Events pushed onto the queue with SDL_PushEvent() get passed through -// the event filter, but events pushed onto the queue with SDL_PeepEvents() do -// not. -// -// `filter` An SDL_EventFilter function to call when an event happens -// `userdata` a pointer that is passed to `filter` +// application window. If the event filter returns 1, then the window will +// be closed, otherwise the window will remain open if possible. // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_AddEventWatch -// See also: SDL_EventState -// See also: SDL_GetEventFilter -// See also: SDL_PeepEvents -// See also: SDL_PushEvent +// If the quit event is generated by an interrupt signal, it will bypass the +// internal queue and be delivered to the application at the next event poll. pub fn set_event_filter(filter EventFilter, userdata voidptr) { C.SDL_SetEventFilter(filter, userdata) } fn C.SDL_GetEventFilter(filter &EventFilter, userdata voidptr) bool -// get_event_filter queries the current event filter. -// -// This function can be used to "chain" filters, by saving the existing filter -// before replacing it with a function that will call that saved filter. -// -// `filter` the current callback function will be stored here -// `userdata` the pointer that is passed to the current event filter will -// be stored here -// returns SDL_TRUE on success or SDL_FALSE if there is no event filter set. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_SetEventFilter +// get_event_filter returns the current event filter - can be used to "chain" filters. +// If there is no event filter set, this function returns SDL_FALSE. pub fn get_event_filter(filter &EventFilter, userdata voidptr) bool { return C.SDL_GetEventFilter(filter, userdata) } fn C.SDL_AddEventWatch(filter EventFilter, userdata voidptr) -// add_event_watch adds a callback to be triggered when an event is added to the event queue. -// -// `filter` will be called when an event happens, and its return value is -// ignored. -// -// **WARNING**: Be very careful of what you do in the event filter function, -// as it may run in a different thread! -// -// If the quit event is generated by a signal (e.g. SIGINT), it will bypass -// the internal queue and be delivered to the watch callback immediately, and -// arrive at the next event poll. -// -// NOTE the callback is called for events posted by the user through -// SDL_PushEvent(), but not for disabled events, nor for events by a filter -// callback set with SDL_SetEventFilter(), nor for events posted by the user -// through SDL_PeepEvents(). -// -// `filter` an SDL_EventFilter function to call when an event happens. -// `userdata` a pointer that is passed to `filter` -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_DelEventWatch -// See also: SDL_SetEventFilter +// add_event_watch add a function which is called when an event is added to the queue. pub fn add_event_watch(filter EventFilter, userdata voidptr) { C.SDL_AddEventWatch(filter, userdata) } fn C.SDL_DelEventWatch(filter EventFilter, userdata voidptr) -// del_event_watch removes an event watch callback added with SDL_AddEventWatch(). -// -// This function takes the same input as SDL_AddEventWatch() to identify and -// delete the corresponding callback. -// -// `filter` the function originally passed to SDL_AddEventWatch() -// `userdata` the pointer originally passed to SDL_AddEventWatch() -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_AddEventWatch +// del_event_watch removes an event watch function added with SDL_AddEventWatch() pub fn del_event_watch(filter EventFilter, userdata voidptr) { C.SDL_DelEventWatch(filter, userdata) } fn C.SDL_FilterEvents(filter EventFilter, userdata voidptr) -// filter_events runs a specific filter function on the current event queue, removing any +// filter_events runs the filter function on the current event queue, removing any // events for which the filter returns 0. -// -// See SDL_SetEventFilter() for more information. Unlike SDL_SetEventFilter(), -// this function does not change the filter permanently, it only uses the -// supplied filter until this function returns. -// -// `filter` the SDL_EventFilter function to call when an event happens -// `userdata` a pointer that is passed to `filter` -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetEventFilter -// See also: SDL_SetEventFilter pub fn filter_events(filter EventFilter, userdata voidptr) { C.SDL_FilterEvents(filter, userdata) } fn C.SDL_EventState(@type u32, state int) u8 -// Set the state of processing events by type. -// -// `state` may be any of the following: -// -// - `SDL_QUERY`: returns the current processing state of the specified event -// - `SDL_IGNORE` (aka `SDL_DISABLE`): the event will automatically be dropped -// from the event queue and will not be filtered -// - `SDL_ENABLE`: the event will be processed normally -// -// `type` the type of event; see SDL_EventType for details -// `state` how to process the event -// returns `SDL_DISABLE` or `SDL_ENABLE`, representing the processing state -// of the event before this function makes any changes to it. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetEventState +// event_state allows you to set the state of processing certain events. +// - If `state` is set to ::SDL_IGNORE, that event will be automatically +// dropped from the event queue and will not be filtered. +// - If `state` is set to ::SDL_ENABLE, that event will be processed +// normally. +// - If `state` is set to ::SDL_QUERY, SDL_EventState() will return the +// current processing state of the specified event. pub fn event_state(@type u32, state int) u8 { return C.SDL_EventState(@type, state) } fn C.SDL_RegisterEvents(numevents int) u32 -// Allocate a set of user-defined events, and return the beginning event -// number for that set of events. -// -// Calling this function with `numevents` <= 0 is an error and will return -// (Uint32)-1. -// -// Note, (Uint32)-1 means the maximum unsigned 32-bit integer value (or -// 0xFFFFFFFF), but is clearer to write. -// -// `numevents` the number of events to be allocated -// returns the beginning event number, or (Uint32)-1 if there are not enough -// user-defined events left. -// -// NOTE This function is available since SDL 2.0.0. +// register_events allocates a set of user-defined events, and returns +// the beginning event number for that set of events. // -// See also: SDL_PushEvent +// If there aren't enough user-defined events left, this function +// returns (Uint32)-1 pub fn register_events(numevents int) u32 { return C.SDL_RegisterEvents(numevents) } diff --git a/examples/versions/main.v b/examples/versions/main.v index 2ef95fd0..215f7f44 100644 --- a/examples/versions/main.v +++ b/examples/versions/main.v @@ -11,4 +11,5 @@ fn main() { mut linked_version := sdl.Version{} sdl.get_version(mut linked_version) println('Runtime loaded version ${linked_version.str()}') + println('Revision ${sdl.get_revision_number()} / ${sdl.get_revision()}') } diff --git a/filesystem.c.v b/filesystem.c.v index f76ac118..26b26ed6 100644 --- a/filesystem.c.v +++ b/filesystem.c.v @@ -9,44 +9,25 @@ module sdl fn C.SDL_GetBasePath() &char -// get_base_path gets the directory where the application was run from. +// get_base_path gets the path where the application resides. // -// This is not necessarily a fast call, so you should call this once near -// startup and save the string if you need it. +// Get the "base path". This is the directory where the application was run +// from, which is probably the installation directory, and may or may not +// be the process's current working directory. // -// **Mac OS X and iOS Specific Functionality**: If the application is in a -// ".app" bundle, this function returns the Resource directory (e.g. -// MyApp.app/Contents/Resources/). This behaviour can be overridden by adding -// a property to the Info.plist file. Adding a string key with the name -// SDL_FILESYSTEM_BASE_DIR_TYPE with a supported value will change the -// behaviour. +// This returns an absolute path in UTF-8 encoding, and is guaranteed to +// end with a path separator ('\\' on Windows, '/' most other places). // -// Supported values for the SDL_FILESYSTEM_BASE_DIR_TYPE property (Given an -// application in /Applications/SDLApp/MyApp.app): +// The pointer returned by this function is owned by you. Please call +// SDL_free() on the pointer when you are done with it, or it will be a +// memory leak. This is not necessarily a fast call, though, so you should +// call this once near startup and save the string if you need it. // -// - `resource`: bundle resource directory (the default). For example: -// `/Applications/SDLApp/MyApp.app/Contents/Resources` -// - `bundle`: the Bundle directory. For example: -// `/Applications/SDLApp/MyApp.app/` -// - `parent`: the containing directory of the bundle. For example: -// `/Applications/SDLApp/` +// Some platforms can't determine the application's path, and on other +// platforms, this might be meaningless. In such cases, this function will +// return NULL. // -// **Nintendo 3DS Specific Functionality**: This function returns "romfs" -// directory of the application as it is uncommon to store resources outside -// the executable. As such it is not a writable directory. -// -// The returned path is guaranteed to end with a path separator ('\\' on -// Windows, '/' on most other platforms). -// -// The pointer returned is owned by the caller. Please call SDL_free() on the -// pointer when done with it. -// -// returns an absolute path in UTF-8 encoding to the application data -// directory. NULL will be returned on error or when the platform -// doesn't implement this functionality, call SDL_GetError() for more -// information. -// -// NOTE This function is available since SDL 2.0.1. +// returns String of base dir in UTF-8 encoding, or NULL on error. // // See also: SDL_GetPrefPath pub fn get_base_path() &char { @@ -58,54 +39,60 @@ fn C.SDL_GetPrefPath(const_org &char, const_app &char) &char // get_pref_path gets the user-and-app-specific path where files can be written. // // Get the "pref dir". This is meant to be where users can write personal -// files (preferences and save games, etc) that are specific to your -// application. This directory is unique per user, per application. +// files (preferences and save games, etc) that are specific to your +// application. This directory is unique per user, per application. // -// This function will decide the appropriate location in the native -// filesystem, create the directory if necessary, and return a string of the -// absolute path to the directory in UTF-8 encoding. +// This function will decide the appropriate location in the native filesystem, +// create the directory if necessary, and return a string of the absolute +// path to the directory in UTF-8 encoding. // // On Windows, the string might look like: -// -// `C:\\Users\\bob\\AppData\\Roaming\\My Company\\My Program Name\\` +// "C:\\Users\\bob\\AppData\\Roaming\\My Company\\My Program Name\\" // // On Linux, the string might look like: -// -// `/home/bob/.local/share/My Program Name/` +// "/home/bob/.local/share/My Program Name/" // // On Mac OS X, the string might look like: -// -// `/Users/bob/Library/Application Support/My Program Name/` -// -// You should assume the path returned by this function is the only safe place -// to write files (and that SDL_GetBasePath(), while it might be writable, or -// even the parent of the returned path, isn't where you should be writing -// things). -// -// Both the org and app strings may become part of a directory name, so please -// follow these rules: -// -// - Try to use the same org string (_including case-sensitivity_) for all -// your applications that use this function. -// - Always use a unique app string for each one, and make sure it never -// changes for an app once you've decided on it. -// - Unicode characters are legal, as long as it's UTF-8 encoded, but... -// - ...only use letters, numbers, and spaces. Avoid punctuation like "Game -// Name 2: Bad Guy's Revenge!" ... "Game Name 2" is sufficient. -// -// The returned path is guaranteed to end with a path separator ('\\' on -// Windows, '/' on most other platforms). -// -// The pointer returned is owned by the caller. Please call SDL_free() on the -// pointer when done with it. -// -// `org` the name of your organization -// `app` the name of your application -// returns a UTF-8 string of the user directory in platform-dependent -// notation. NULL if there's a problem (creating directory failed, -// etc.). -// -// NOTE This function is available since SDL 2.0.1. +// "/Users/bob/Library/Application Support/My Program Name/" +// +// (etc.) +// +// You specify the name of your organization (if it's not a real organization, +// your name or an Internet domain you own might do) and the name of your +// application. These should be untranslated proper names. +// +// Both the org and app strings may become part of a directory name, so +// please follow these rules: +// +// - Try to use the same org string (including case-sensitivity) for +// all your applications that use this function. +// - Always use a unique app string for each one, and make sure it never +// changes for an app once you've decided on it. +// - Unicode characters are legal, as long as it's UTF-8 encoded, but... +// - ...only use letters, numbers, and spaces. Avoid punctuation like +// "Game Name 2: Bad Guy's Revenge!" ... "Game Name 2" is sufficient. +// +// This returns an absolute path in UTF-8 encoding, and is guaranteed to +// end with a path separator ('\\' on Windows, '/' most other places). +// +// The pointer returned by this function is owned by you. Please call +// SDL_free() on the pointer when you are done with it, or it will be a +// memory leak. This is not necessarily a fast call, though, so you should +// call this once near startup and save the string if you need it. +// +// You should assume the path returned by this function is the only safe +// place to write files (and that SDL_GetBasePath(), while it might be +// writable, or even the parent of the returned path, aren't where you +// should be writing things). +// +// Some platforms can't determine the pref path, and on other +// platforms, this might be meaningless. In such cases, this function will +// return NULL. +// +// `org` The name of your organization. +// `app` The name of your application. +// returns UTF-8 string of user dir in platform-dependent notation. NULL +// if there's a problem (creating directory failed, etc). // // See also: SDL_GetBasePath pub fn get_pref_path(const_org &char, const_app &char) &char { diff --git a/gamecontroller.c.v b/gamecontroller.c.v index 2464728f..e29f3999 100644 --- a/gamecontroller.c.v +++ b/gamecontroller.c.v @@ -23,25 +23,6 @@ pub struct C.SDL_GameController { pub type GameController = C.SDL_GameController -// GameControllerType is C.SDL_GameControllerType -pub enum GameControllerType { - unknown = C.SDL_CONTROLLER_TYPE_UNKNOWN // 0 - xbox360 = C.SDL_CONTROLLER_TYPE_XBOX360 - xboxone = C.SDL_CONTROLLER_TYPE_XBOXONE - ps3 = C.SDL_CONTROLLER_TYPE_PS3 - ps4 = C.SDL_CONTROLLER_TYPE_PS4 - nintendo_switch_pro = C.SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO - virtual = C.SDL_CONTROLLER_TYPE_VIRTUAL - ps5 = C.SDL_CONTROLLER_TYPE_PS5 - amazon_luna = C.SDL_CONTROLLER_TYPE_AMAZON_LUNA - google_stadia = C.SDL_CONTROLLER_TYPE_GOOGLE_STADIA - nvidia_shield = C.SDL_CONTROLLER_TYPE_NVIDIA_SHIELD - nintendo_switch_joycon_left = C.SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_LEFT - nintendo_switch_joycon_right = C.SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_RIGHT - nintendo_switch_joycon_pair = C.SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_PAIR - max = C.SDL_CONTROLLER_TYPE_MAX -} - // GameControllerBindType is C.SDL_GameControllerBindType pub enum GameControllerBindType { @none = C.SDL_CONTROLLER_BINDTYPE_NONE // 0 @@ -73,17 +54,13 @@ pub: pub type GameControllerButtonBind = C.SDL_GameControllerButtonBind // To count the number of game controllers in the system for the following: -/* -```c - int nJoysticks = SDL_NumJoysticks(); - int nGameControllers = 0; - for (int i = 0; i < nJoysticks; i++) { - if (SDL_IsGameController(i)) { - nGameControllers++; - } - } -``` -*/ +// int nJoysticks = SDL_NumJoysticks(); +// int nGameControllers = 0; +// for (int i = 0; i < nJoysticks; i++) { +// if (SDL_IsGameController(i)) { +// nGameControllers++; +// } +// } // // Using the SDL_HINT_GAMECONTROLLERCONFIG hint or the SDL_GameControllerAddMapping() you can add support for controllers SDL is unaware of or cause an existing controller to have a different binding. The format is: // guid,name,mappings @@ -97,41 +74,18 @@ pub type GameControllerButtonBind = C.SDL_GameControllerButtonBind // Buttons can be used as a controller axis and vice versa. // // This string shows an example of a valid mapping for a controller -/* -```c - "03000000341a00003608000000000000,PS3 Controller,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b8,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftshoulder:b4,rightshoulder:b5,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7", -``` -*/ +// "03000000341a00003608000000000000,PS3 Controller,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b8,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftshoulder:b4,rightshoulder:b5,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7", // +/// fn C.SDL_GameControllerAddMappingsFromRW(rw &C.SDL_RWops, freerw int) int -// game_controller_add_mappings_from_rw loads a set of Game Controller mappings from a seekable SDL data stream. -// -// You can call this function several times, if needed, to load different -// database files. -// -// If a new mapping is loaded for an already known controller GUID, the later -// version will overwrite the one currently loaded. -// -// Mappings not belonging to the current platform or with no platform field -// specified will be ignored (i.e. mappings for Linux will be ignored in -// Windows, etc). +// game_controller_add_mappings_from_rw loads a set of mappings from a seekable SDL data stream (memory or file), filtered by the current SDL_GetPlatform() +// A community sourced database of controllers is available at https://raw.github.com/gabomdq/SDL_GameControllerDB/master/gamecontrollerdb.txt // -// This function will load the text database entirely in memory before -// processing it, so take this into consideration if you are in a memory -// constrained environment. +// If `freerw` is non-zero, the stream will be closed after being read. // -// `rw` the data stream for the mappings to be added -// `freerw` non-zero to close the stream after being read -// returns the number of mappings added or -1 on error; call SDL_GetError() -// for more information. -// -// NOTE This function is available since SDL 2.0.2. -// -// See also: SDL_GameControllerAddMapping -// See also: SDL_GameControllerAddMappingsFromFile -// See also: SDL_GameControllerMappingForGUID +// returns number of mappings added, -1 on error pub fn game_controller_add_mappings_from_rw(rw &RWops, freerw int) int { return C.SDL_GameControllerAddMappingsFromRW(rw, freerw) } @@ -147,33 +101,9 @@ pub fn game_controller_add_mappings_from_file(file &char) int { fn C.SDL_GameControllerAddMapping(mapping_string &char) int -// game_controller_add_mapping adds support for controllers that SDL is unaware of or to cause an existing -// controller to have a different binding. -// -// The mapping string has the format "GUID,name,mapping", where GUID is the -// string value from SDL_JoystickGetGUIDString(), name is the human readable -// string for the device and mappings are controller mappings to joystick -// ones. Under Windows there is a reserved GUID of "xinput" that covers all -// XInput devices. The mapping format for joystick is: {| |bX |a joystick -// button, index X |- |hX.Y |hat X with value Y |- |aX |axis X of the joystick -// |} Buttons can be used as a controller axes and vice versa. -// -// This string shows an example of a valid mapping for a controller: +// game_controller_add_mapping adds or updates an existing mapping configuration // -/* -```c - "341a3608000000000000504944564944,Afterglow PS3 Controller,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b8,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftshoulder:b4,rightshoulder:b5,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7" -``` -*/ -// -// `mappingString` the mapping string -// returns 1 if a new mapping is added, 0 if an existing mapping is updated, -// -1 on error; call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GameControllerMapping -// See also: SDL_GameControllerMappingForGUID +// returns 1 if mapping is added, 0 if updated, -1 on error pub fn game_controller_add_mapping(mapping_string &char) int { return C.SDL_GameControllerAddMapping(mapping_string) } @@ -183,8 +113,6 @@ fn C.SDL_GameControllerNumMappings() int // game_controller_num_mappings gets the number of mappings installed // // returns the number of mappings -// -// NOTE This function is available since SDL 2.0.6. pub fn game_controller_num_mappings() int { return C.SDL_GameControllerNumMappings() } @@ -193,297 +121,76 @@ fn C.SDL_GameControllerMappingForIndex(mapping_index int) &char // game_controller_mapping_for_index gets the mapping at a particular index. // -// returns the mapping string. Must be freed with SDL_free(). Returns NULL if -// the index is out of range. -// -// NOTE This function is available since SDL 2.0.6. +// returns the mapping string. Must be freed with SDL_free(). Returns NULL if the index is out of range. pub fn game_controller_mapping_for_index(mapping_index int) &char { return C.SDL_GameControllerMappingForIndex(mapping_index) } fn C.SDL_GameControllerMappingForGUID(guid C.SDL_JoystickGUID) &char -// game_controller_mapping_for_guid gets the game controller mapping string for a given GUID. +// Get a mapping string for a GUID // -// The returned string must be freed with SDL_free(). -// -// `guid` a structure containing the GUID for which a mapping is desired -// returns a mapping string or NULL on error; call SDL_GetError() for more -// information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_JoystickGetDeviceGUID -// See also: SDL_JoystickGetGUID +// returns the mapping string. Must be freed with SDL_free(). Returns NULL if no mapping is available pub fn game_controller_mapping_for_guid(guid JoystickGUID) &char { - return C.SDL_GameControllerMappingForGUID(C.SDL_JoystickGUID(guid)) + return C.SDL_GameControllerMappingForGUID(guid) } fn C.SDL_GameControllerMapping(gamecontroller &C.SDL_GameController) &char -// game_controller_mapping gets the current mapping of a Game Controller. -// -// The returned string must be freed with SDL_free(). +// game_controller_mapping gets a mapping string for an open GameController // -// Details about mappings are discussed with SDL_GameControllerAddMapping(). -// -// `gamecontroller` the game controller you want to get the current -// mapping for -// returns a string that has the controller's mapping or NULL if no mapping -// is available; call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GameControllerAddMapping -// See also: SDL_GameControllerMappingForGUID +// returns the mapping string. Must be freed with SDL_free(). Returns NULL if no mapping is available pub fn game_controller_mapping(gamecontroller &GameController) &char { return C.SDL_GameControllerMapping(gamecontroller) } fn C.SDL_IsGameController(joystick_index int) bool -// is_game_controller checks if the given joystick is supported by the game controller interface. -// -// `joystick_index` is the same as the `device_index` passed to -// SDL_JoystickOpen(). -// -// `joystick_index` the device_index of a device, up to -// SDL_NumJoysticks() -// returns SDL_TRUE if the given joystick is supported by the game controller -// interface, SDL_FALSE if it isn't or it's an invalid index. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GameControllerNameForIndex -// See also: SDL_GameControllerOpen +// is_game_controller returns whether the joystick on this index supported by the game controller interface? pub fn is_game_controller(joystick_index int) bool { return C.SDL_IsGameController(joystick_index) } fn C.SDL_GameControllerNameForIndex(joystick_index int) &char -// game_controller_name_for_index gets the implementation dependent name for the game controller. -// -// This function can be called before any controllers are opened. -// -// `joystick_index` is the same as the `device_index` passed to -// SDL_JoystickOpen(). -// -// `joystick_index` the device_index of a device, from zero to -// SDL_NumJoysticks()-1 -// returns the implementation-dependent name for the game controller, or NULL -// if there is no name or the index is invalid. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GameControllerName -// See also: SDL_GameControllerOpen -// See also: SDL_IsGameController +// game_controller_name_for_index gets the implementation dependent name of a game controller. +// This can be called before any controllers are opened. +// If no name can be found, this function returns NULL. pub fn game_controller_name_for_index(joystick_index int) &char { return C.SDL_GameControllerNameForIndex(joystick_index) } -fn C.SDL_GameControllerPathForIndex(joystick_index int) &char - -// game_controller_path_for_index gets the implementation dependent path for the game controller. -// -// This function can be called before any controllers are opened. -// -// `joystick_index` is the same as the `device_index` passed to -// SDL_JoystickOpen(). -// -// `joystick_index` the device_index of a device, from zero to -// SDL_NumJoysticks()-1 -// returns the implementation-dependent path for the game controller, or NULL -// if there is no path or the index is invalid. -// -// NOTE This function is available since SDL 2.24.0. -// -// See also: SDL_GameControllerPath -pub fn game_controller_path_for_index(joystick_index int) &char { - return C.SDL_GameControllerPathForIndex(joystick_index) -} - -fn C.SDL_GameControllerTypeForIndex(joystick_index int) GameControllerType - -// game_controller_type_for_index gets the type of a game controller. -// -// This can be called before any controllers are opened. -// -// `joystick_index` the device_index of a device, from zero to -// SDL_NumJoysticks()-1 -// returns the controller type. -// -// NOTE This function is available since SDL 2.0.12. -pub fn game_controller_type_for_index(joystick_index int) GameControllerType { - return unsafe { GameControllerType(int(C.SDL_GameControllerTypeForIndex(joystick_index))) } -} - -fn C.SDL_GameControllerMappingForDeviceIndex(joystick_index int) &char - -// game_controller_mapping_for_device_index gets the mapping of a game controller. -// -// This can be called before any controllers are opened. -// -// `joystick_index` the device_index of a device, from zero to -// SDL_NumJoysticks()-1 -// returns the mapping string. Must be freed with SDL_free(). Returns NULL if -// no mapping is available. -// -// NOTE This function is available since SDL 2.0.9. -pub fn game_controller_mapping_for_device_index(joystick_index int) &char { - return C.SDL_GameControllerMappingForDeviceIndex(joystick_index) -} - fn C.SDL_GameControllerOpen(joystick_index int) &C.SDL_GameController // game_controller_open opens a game controller for use. +// The index passed as an argument refers to the N'th game controller on the system. +// This index is not the value which will identify this controller in future +// controller events. The joystick's instance id (::SDL_JoystickID) will be +// used there instead. // -// `joystick_index` is the same as the `device_index` passed to -// SDL_JoystickOpen(). -// -// The index passed as an argument refers to the N'th game controller on the -// system. This index is not the value which will identify this controller in -// future controller events. The joystick's instance id (SDL_JoystickID) will -// be used there instead. -// -// `joystick_index` the device_index of a device, up to -// SDL_NumJoysticks() -// returns a gamecontroller identifier or NULL if an error occurred; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GameControllerClose -// See also: SDL_GameControllerNameForIndex -// See also: SDL_IsGameController +// returns A controller identifier, or NULL if an error occurred. pub fn game_controller_open(joystick_index int) &GameController { return C.SDL_GameControllerOpen(joystick_index) } fn C.SDL_GameControllerFromInstanceID(joyid JoystickID) &C.SDL_GameController -// game_controller_from_instance_id gets the SDL_GameController associated with an instance id. -// -// `joyid` the instance id to get the SDL_GameController for -// returns an SDL_GameController on success or NULL on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.4. +// game_controller_from_instance_id returns the SDL_GameController associated with an instance id. pub fn game_controller_from_instance_id(joyid JoystickID) &GameController { return C.SDL_GameControllerFromInstanceID(joyid) } -fn C.SDL_GameControllerFromPlayerIndex(player_index int) &C.SDL_GameController +fn C.SDL_GameControllerName(gamecontroller &C.SDL_GameController) &char -// game_controller_from_player_index gets the SDL_GameController associated with a player index. -// -// Please note that the player index is _not_ the device index, nor is it the -// instance id! -// -// `player_index` the player index, which is not the device index or the -// instance id! -// returns the SDL_GameController associated with a player index. -// -// NOTE This function is available since SDL 2.0.12. -// -// See also: SDL_GameControllerGetPlayerIndex -// See also: SDL_GameControllerSetPlayerIndex -pub fn game_controller_from_player_index(player_index int) &GameController { - return C.SDL_GameControllerFromPlayerIndex(player_index) -} - -fn C.SDL_GameControllerName(gamecontroller &GameController) &char - -// game_controller_name gets the implementation-dependent name for an opened game controller. -// -// This is the same name as returned by SDL_GameControllerNameForIndex(), but -// it takes a controller identifier instead of the (unstable) device index. -// -// `gamecontroller` a game controller identifier previously returned by -// SDL_GameControllerOpen() -// returns the implementation dependent name for the game controller, or NULL -// if there is no name or the identifier passed is invalid. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GameControllerNameForIndex -// See also: SDL_GameControllerOpen +// game_controller_name returns the name for this currently opened controller pub fn game_controller_name(gamecontroller &GameController) &char { return C.SDL_GameControllerName(gamecontroller) } -fn C.SDL_GameControllerPath(gamecontroller &C.SDL_GameController) &char - -// game_controller_path gets the implementation-dependent path for an opened game controller. -// -// This is the same path as returned by SDL_GameControllerNameForIndex(), but -// it takes a controller identifier instead of the (unstable) device index. -// -// `gamecontroller` a game controller identifier previously returned by -// SDL_GameControllerOpen() -// returns the implementation dependent path for the game controller, or NULL -// if there is no path or the identifier passed is invalid. -// -// NOTE This function is available since SDL 2.24.0. -// -// See also: SDL_GameControllerPathForIndex -pub fn game_controller_path(gamecontroller &GameController) &char { - return C.SDL_GameControllerPath(gamecontroller) -} - -fn C.SDL_GameControllerGetType(gamecontroller &C.SDL_GameController) GameControllerType - -// game_controller_get_type gets the type of this currently opened controller -// -// This is the same name as returned by SDL_GameControllerTypeForIndex(), but -// it takes a controller identifier instead of the (unstable) device index. -// -// `gamecontroller` the game controller object to query. -// returns the controller type. -// -// NOTE This function is available since SDL 2.0.12. -pub fn game_controller_get_type(gamecontroller &GameController) GameControllerType { - return unsafe { GameControllerType(int(C.SDL_GameControllerGetType(gamecontroller))) } -} - -fn C.SDL_GameControllerGetPlayerIndex(gamecontroller &C.SDL_GameController) int - -// game_controller_get_player_index gets the player index of an opened game controller. -// -// For XInput controllers this returns the XInput user index. -// -// `gamecontroller` the game controller object to query. -// returns the player index for controller, or -1 if it's not available. -// -// NOTE This function is available since SDL 2.0.9. -pub fn game_controller_get_player_index(gamecontroller &GameController) int { - return C.SDL_GameControllerGetPlayerIndex(gamecontroller) -} - -fn C.SDL_GameControllerSetPlayerIndex(gamecontroller &C.SDL_GameController, player_index int) - -// game_controller_set_player_index sets the player index of an opened game controller. -// -// `gamecontroller` the game controller object to adjust. -// `player_index` Player index to assign to this controller, or -1 to -// clear the player index and turn off player LEDs. -// -// NOTE This function is available since SDL 2.0.12. -pub fn game_controller_set_player_index(gamecontroller &GameController, player_index int) { - C.SDL_GameControllerSetPlayerIndex(gamecontroller, player_index) -} - fn C.SDL_GameControllerGetVendor(gamecontroller &C.SDL_GameController) u16 // game_controller_get_vendor gets the USB vendor ID of an opened controller, if available. -// // If the vendor ID isn't available this function returns 0. -// -// `gamecontroller` the game controller object to query. -// returns the USB vendor ID, or zero if unavailable. -// -// NOTE This function is available since SDL 2.0.6. pub fn game_controller_get_vendor(gamecontroller &GameController) u16 { return C.SDL_GameControllerGetVendor(gamecontroller) } @@ -491,13 +198,7 @@ pub fn game_controller_get_vendor(gamecontroller &GameController) u16 { fn C.SDL_GameControllerGetProduct(gamecontroller &C.SDL_GameController) u16 // game_controller_get_product gets the USB product ID of an opened controller, if available. -// // If the product ID isn't available this function returns 0. -// -// `gamecontroller` the game controller object to query. -// returns the USB product ID, or zero if unavailable. -// -// NOTE This function is available since SDL 2.0.6. pub fn game_controller_get_product(gamecontroller &GameController) u16 { return C.SDL_GameControllerGetProduct(gamecontroller) } @@ -505,132 +206,45 @@ pub fn game_controller_get_product(gamecontroller &GameController) u16 { fn C.SDL_GameControllerGetProductVersion(gamecontroller &C.SDL_GameController) u16 // game_controller_get_product_version gets the product version of an opened controller, if available. -// // If the product version isn't available this function returns 0. -// -// `gamecontroller` the game controller object to query. -// returns the USB product version, or zero if unavailable. -// -// NOTE This function is available since SDL 2.0.6. pub fn game_controller_get_product_version(gamecontroller &GameController) u16 { return C.SDL_GameControllerGetProductVersion(gamecontroller) } -fn C.SDL_GameControllerGetFirmwareVersion(gamecontroller &C.SDL_GameController) u16 - -// game_controller_get_firmware_version gets the firmware version of an opened controller, if available. -// -// If the firmware version isn't available this function returns 0. -// -// `gamecontroller` the game controller object to query. -// returns the controller firmware version, or zero if unavailable. -// -// NOTE This function is available since SDL 2.24.0. -pub fn game_controller_get_firmware_version(gamecontroller &GameController) u16 { - return C.SDL_GameControllerGetFirmwareVersion(gamecontroller) -} - -fn C.SDL_GameControllerGetSerial(gamecontroller &C.SDL_GameController) &char - -// game_controller_get_serial gets the serial number of an opened controller, if available. -// -// Returns the serial number of the controller, or NULL if it is not -// available. -// -// `gamecontroller` the game controller object to query. -// returns the serial number, or NULL if unavailable. -// -// NOTE This function is available since SDL 2.0.14. -pub fn game_controller_get_serial(gamecontroller &GameController) &char { - return C.SDL_GameControllerGetSerial(gamecontroller) -} - -fn C.SDL_GameControllerGetSteamHandle(gamecontroller &GameController) u64 - -// Get the Steam Input handle of an opened controller, if available. -// -// Returns an InputHandle_t for the controller that can be used with Steam Input API: -// https://partner.steamgames.com/doc/api/ISteamInput -// -// `gamecontroller` the game controller object to query. -// returns the gamepad handle, or 0 if unavailable. -// -// NOTE This function is available since SDL 2.30.0. -pub fn game_controller_get_steam_handle(gamecontroller &GameController) u64 { - return C.SDL_GameControllerGetSteamHandle(gamecontroller) -} - fn C.SDL_GameControllerGetAttached(gamecontroller &C.SDL_GameController) bool -// game_controller_get_attached checks if a controller has been opened and is currently connected. -// -// `gamecontroller` a game controller identifier previously returned by -// SDL_GameControllerOpen() -// returns SDL_TRUE if the controller has been opened and is currently -// connected, or SDL_FALSE if not. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GameControllerClose -// See also: SDL_GameControllerOpen +// game_controller_get_attached returns SDL_TRUE if the controller has been opened and currently connected, +// or SDL_FALSE if it has not. pub fn game_controller_get_attached(gamecontroller &GameController) bool { return C.SDL_GameControllerGetAttached(gamecontroller) } fn C.SDL_GameControllerGetJoystick(gamecontroller &C.SDL_GameController) &C.SDL_Joystick -// game_controller_get_joystick gets the Joystick ID from a Game Controller. -// -// This function will give you a SDL_Joystick object, which allows you to use -// the SDL_Joystick functions with a SDL_GameController object. This would be -// useful for getting a joystick's position at any given time, even if it -// hasn't moved (moving it would produce an event, which would have the axis' -// value). -// -// The pointer returned is owned by the SDL_GameController. You should not -// call SDL_JoystickClose() on it, for example, since doing so will likely -// cause SDL to crash. -// -// `gamecontroller` the game controller object that you want to get a -// joystick from -// returns a SDL_Joystick object; call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. +// game_controller_get_joystick gets the underlying joystick object used by a controller pub fn game_controller_get_joystick(gamecontroller &GameController) &Joystick { return C.SDL_GameControllerGetJoystick(gamecontroller) } fn C.SDL_GameControllerEventState(state int) int -// game_controller_event_state queries or change current state of Game Controller events. +// game_controller_event_state enables/disables controller event polling. // // If controller events are disabled, you must call SDL_GameControllerUpdate() // yourself and check the state of the controller when you want controller // information. // -// Any number can be passed to SDL_GameControllerEventState(), but only -1, 0, -// and 1 will have any effect. Other numbers will just be returned. -// -// `state` can be one of `SDL_QUERY`, `SDL_IGNORE`, or `SDL_ENABLE` -// returns the same value passed to the function, with exception to -1 -// (SDL_QUERY), which will return the current state. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_JoystickEventState +// The state can be one of ::SDL_QUERY, ::SDL_ENABLE or ::SDL_IGNORE. pub fn game_controller_event_state(state int) int { return C.SDL_GameControllerEventState(state) } fn C.SDL_GameControllerUpdate() -// game_controller_update manually pump game controller updates if not using the loop. +// game_controller_update updates the current state of the open game controllers. // -// This function is called automatically by the event loop if events are -// enabled. Under such circumstances, it will not be necessary to call this -// function. -// -// NOTE This function is available since SDL 2.0.0. +// This is called automatically by the event loop if any game controller +// events are enabled. pub fn game_controller_update() { C.SDL_GameControllerUpdate() } @@ -641,9 +255,7 @@ pub fn game_controller_update() { // and are centered within ~8000 of zero, though advanced UI will allow users to set // or autodetect the dead zone, which varies between controllers. // -// Trigger axis values range from 0 (released) to SDL_JOYSTICK_AXIS_MAX -// (fully pressed) when reported by SDL_GameControllerGetAxis(). Note that this is not the -// same range that will be reported by the lower-level SDL_GetJoystickAxis(). +// Trigger axis values range from 0 to SDL_JOYSTICK_AXIS_MAX. // // GameControllerAxis is C.SDL_GameControllerAxis pub enum GameControllerAxis { @@ -657,103 +269,35 @@ pub enum GameControllerAxis { max = C.SDL_CONTROLLER_AXIS_MAX } -fn C.SDL_GameControllerGetAxisFromString(const_str &char) GameControllerAxis +fn C.SDL_GameControllerGetAxisFromString(pch_string &char) GameControllerAxis -// game_controller_get_axis_from_string converts a string into SDL_GameControllerAxis enum. -// -// This function is called internally to translate SDL_GameController mapping -// strings for the underlying joystick device into the consistent -// SDL_GameController mapping. You do not normally need to call this function -// unless you are parsing SDL_GameController mappings in your own code. -// -// Note specially that "righttrigger" and "lefttrigger" map to -// `SDL_CONTROLLER_AXIS_TRIGGERRIGHT` and `SDL_CONTROLLER_AXIS_TRIGGERLEFT`, -// respectively. -// -// `str` string representing a SDL_GameController axis -// returns the SDL_GameControllerAxis enum corresponding to the input string, -// or `SDL_CONTROLLER_AXIS_INVALID` if no match was found. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GameControllerGetStringForAxis -pub fn game_controller_get_axis_from_string(const_str &char) GameControllerAxis { - return GameControllerAxis(C.SDL_GameControllerGetAxisFromString(const_str)) +// game_controller_get_axis_from_string turns the string into an axis mapping +pub fn game_controller_get_axis_from_string(pch_string &char) GameControllerAxis { + return GameControllerAxis(C.SDL_GameControllerGetAxisFromString(pch_string)) } fn C.SDL_GameControllerGetStringForAxis(axis C.SDL_GameControllerAxis) &char -// game_controller_get_string_for_axis converts from an SDL_GameControllerAxis enum to a string. -// -// The caller should not SDL_free() the returned string. -// -// `axis` an enum value for a given SDL_GameControllerAxis -// returns a string for the given axis, or NULL if an invalid axis is -// specified. The string returned is of the format used by -// SDL_GameController mapping strings. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GameControllerGetAxisFromString +// game_controller_get_string_for_axis turns the axis enum into a string mapping pub fn game_controller_get_string_for_axis(axis GameControllerAxis) &char { return C.SDL_GameControllerGetStringForAxis(C.SDL_GameControllerAxis(axis)) } fn C.SDL_GameControllerGetBindForAxis(gamecontroller &C.SDL_GameController, axis C.SDL_GameControllerAxis) C.SDL_GameControllerButtonBind -// game_controller_get_bind_for_axis gets the SDL joystick layer binding for a controller axis mapping. -// -// `gamecontroller` a game controller -// `axis` an axis enum value (one of the SDL_GameControllerAxis values) -// returns a SDL_GameControllerButtonBind describing the bind. On failure -// (like the given Controller axis doesn't exist on the device), its -// `.bindType` will be `SDL_CONTROLLER_BINDTYPE_NONE`. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GameControllerGetBindForButton +// Get the SDL joystick layer binding for this controller button mapping pub fn game_controller_get_bind_for_axis(gamecontroller &GameController, axis GameControllerAxis) GameControllerButtonBind { return C.SDL_GameControllerGetBindForAxis(gamecontroller, C.SDL_GameControllerAxis(axis)) } -fn C.SDL_GameControllerHasAxis(gamecontroller &C.SDL_GameController, axis C.SDL_GameControllerAxis) bool - -// game_controller_has_axis queries whether a game controller has a given axis. -// -// This merely reports whether the controller's mapping defined this axis, as -// that is all the information SDL has about the physical device. -// -// `gamecontroller` a game controller -// `axis` an axis enum value (an SDL_GameControllerAxis value) -// returns SDL_TRUE if the controller has this axis, SDL_FALSE otherwise. -// -// NOTE This function is available since SDL 2.0.14. -pub fn game_controller_has_axis(gamecontroller &GameController, axis GameControllerAxis) bool { - return C.SDL_GameControllerHasAxis(gamecontroller, C.SDL_GameControllerAxis(axis)) -} - fn C.SDL_GameControllerGetAxis(gamecontroller &C.SDL_GameController, axis C.SDL_GameControllerAxis) i16 -// game_controller_get_axis gets the current state of an axis control on a game controller. -// -// The axis indices start at index 0. -// -// For thumbsticks, the state is a value ranging from -32768 (up/left) -// to 32767 (down/right). -// -// Triggers range from 0 when released to 32767 when fully pressed, and -// never return a negative value. Note that this differs from the value -// reported by the lower-level SDL_GetJoystickAxis(), which normally uses -// the full range. -// -// `gamecontroller` a game controller -// `axis` an axis index (one of the SDL_GameControllerAxis values) -// returns axis state (including 0) on success or 0 (also) on failure; call -// SDL_GetError() for more information. +// Get the current state of an axis control on a game controller. // -// NOTE This function is available since SDL 2.0.0. +// The state is a value ranging from -32768 to 32767 (except for the triggers, +// which range from 0 to 32767). // -// See also: SDL_GameControllerGetButton +// The axis indices start at index 0. pub fn game_controller_get_axis(gamecontroller &GameController, axis GameControllerAxis) i16 { return C.SDL_GameControllerGetAxis(gamecontroller, C.SDL_GameControllerAxis(axis)) } @@ -777,389 +321,42 @@ pub enum GameControllerButton { dpad_down = C.SDL_CONTROLLER_BUTTON_DPAD_DOWN dpad_left = C.SDL_CONTROLLER_BUTTON_DPAD_LEFT dpad_right = C.SDL_CONTROLLER_BUTTON_DPAD_RIGHT - misc1 = C.SDL_CONTROLLER_BUTTON_MISC1 // Xbox Series X share button, PS5 microphone button, Nintendo Switch Pro capture button, Amazon Luna microphone button - paddle1 = C.SDL_CONTROLLER_BUTTON_PADDLE1 // Xbox Elite paddle P1 (upper left, facing the back) - paddle2 = C.SDL_CONTROLLER_BUTTON_PADDLE2 // Xbox Elite paddle P3 (upper right, facing the back) - paddle3 = C.SDL_CONTROLLER_BUTTON_PADDLE3 // Xbox Elite paddle P2 (lower left, facing the back) - paddle4 = C.SDL_CONTROLLER_BUTTON_PADDLE4 // Xbox Elite paddle P4 (lower right, facing the back) - touchpad = C.SDL_CONTROLLER_BUTTON_TOUCHPAD // PS4/PS5 touchpad button max = C.SDL_CONTROLLER_BUTTON_MAX } -fn C.SDL_GameControllerGetButtonFromString(const_str &char) GameControllerButton +fn C.SDL_GameControllerGetButtonFromString(pch_string &char) GameControllerButton -// game_controller_get_button_from_string converts a string into an SDL_GameControllerButton enum. -// -// This function is called internally to translate SDL_GameController mapping -// strings for the underlying joystick device into the consistent -// SDL_GameController mapping. You do not normally need to call this function -// unless you are parsing SDL_GameController mappings in your own code. -// -// `str` string representing a SDL_GameController axis -// returns the SDL_GameControllerButton enum corresponding to the input -// string, or `SDL_CONTROLLER_AXIS_INVALID` if no match was found. -// -// NOTE This function is available since SDL 2.0.0. -pub fn game_controller_get_button_from_string(const_str &char) GameControllerButton { - return GameControllerButton(C.SDL_GameControllerGetButtonFromString(const_str)) +// game_controller_get_button_from_string turns the string into a button mapping +pub fn game_controller_get_button_from_string(pch_string &char) GameControllerButton { + return GameControllerButton(C.SDL_GameControllerGetButtonFromString(pch_string)) } fn C.SDL_GameControllerGetStringForButton(button C.SDL_GameControllerButton) &char -// game_controller_get_string_for_button converts from an SDL_GameControllerButton enum to a string. -// -// The caller should not SDL_free() the returned string. -// -// `button` an enum value for a given SDL_GameControllerButton -// returns a string for the given button, or NULL if an invalid button is -// specified. The string returned is of the format used by -// SDL_GameController mapping strings. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GameControllerGetButtonFromString +// game_controller_get_string_for_button turns the button enum into a string mapping pub fn game_controller_get_string_for_button(button GameControllerButton) &char { return C.SDL_GameControllerGetStringForButton(C.SDL_GameControllerButton(button)) } fn C.SDL_GameControllerGetBindForButton(gamecontroller &C.SDL_GameController, button C.SDL_GameControllerButton) C.SDL_GameControllerButtonBind -// game_controller_get_bind_for_button gets the SDL joystick layer binding for a controller button mapping. -// -// `gamecontroller` a game controller -// `button` an button enum value (an SDL_GameControllerButton value) -// returns a SDL_GameControllerButtonBind describing the bind. On failure -// (like the given Controller button doesn't exist on the device), -// its `.bindType` will be `SDL_CONTROLLER_BINDTYPE_NONE`. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GameControllerGetBindForAxis +// game_controller_get_bind_for_button gets the SDL joystick layer binding for this controller button mapping pub fn game_controller_get_bind_for_button(gamecontroller &GameController, button GameControllerButton) GameControllerButtonBind { return C.SDL_GameControllerGetBindForButton(gamecontroller, C.SDL_GameControllerButton(button)) } -fn C.SDL_GameControllerHasButton(gamecontroller &C.SDL_GameController, button C.SDL_GameControllerButton) bool - -// game_controller_has_button queries whether a game controller has a given button. -// -// This merely reports whether the controller's mapping defined this button, -// as that is all the information SDL has about the physical device. -// -// `gamecontroller` a game controller -// `button` a button enum value (an SDL_GameControllerButton value) -// returns SDL_TRUE if the controller has this button, SDL_FALSE otherwise. -// -// NOTE This function is available since SDL 2.0.14. -pub fn game_controller_has_button(gamecontroller &GameController, button GameControllerButton) bool { - return C.SDL_GameControllerHasButton(gamecontroller, C.SDL_GameControllerButton(button)) -} - fn C.SDL_GameControllerGetButton(gamecontroller &C.SDL_GameController, button C.SDL_GameControllerButton) u8 // game_controller_get_button gets the current state of a button on a game controller. // -// `gamecontroller` a game controller -// `button` a button index (one of the SDL_GameControllerButton values) -// returns 1 for pressed state or 0 for not pressed state or error; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GameControllerGetAxis +// The button indices start at index 0. pub fn game_controller_get_button(gamecontroller &GameController, button GameControllerButton) u8 { return C.SDL_GameControllerGetButton(gamecontroller, C.SDL_GameControllerButton(button)) } -fn C.SDL_GameControllerGetNumTouchpads(gamecontroller &C.SDL_GameController) int - -// game_controller_get_num_touchpads gets the number of touchpads on a game controller. -// -// NOTE This function is available since SDL 2.0.14. -pub fn game_controller_get_num_touchpads(gamecontroller &GameController) int { - return C.SDL_GameControllerGetNumTouchpads(gamecontroller) -} - -fn C.SDL_GameControllerGetNumTouchpadFingers(gamecontroller &C.SDL_GameController, touchpad int) int - -// game_controller_get_num_touchpad_fingers gets the number of supported simultaneous fingers on a touchpad on a game -// controller. -// -// NOTE This function is available since SDL 2.0.14. -pub fn game_controller_get_num_touchpad_fingers(gamecontroller &GameController, touchpad int) int { - return C.SDL_GameControllerGetNumTouchpadFingers(gamecontroller, touchpad) -} - -fn C.SDL_GameControllerGetTouchpadFinger(gamecontroller &GameController, touchpad int, finger int, state &u8, x &f32, y &f32, pressure &f32) int - -// game_controller_get_touchpad_finger gets the current state of a finger on a touchpad on a game controller. -// -// NOTE This function is available since SDL 2.0.14. -pub fn game_controller_get_touchpad_finger(gamecontroller &GameController, touchpad int, finger int, state &u8, x &f32, y &f32, pressure &f32) int { - return C.SDL_GameControllerGetTouchpadFinger(gamecontroller, touchpad, finger, state, - x, y, pressure) -} - -fn C.SDL_GameControllerHasSensor(gamecontroller &C.SDL_GameController, @type C.SDL_SensorType) bool - -// game_controller_has_sensor returns whether a game controller has a particular sensor. -// -// `gamecontroller` The controller to query -// `type` The type of sensor to query -// returns SDL_TRUE if the sensor exists, SDL_FALSE otherwise. -// -// NOTE This function is available since SDL 2.0.14. -pub fn game_controller_has_sensor(gamecontroller &GameController, @type SensorType) bool { - return C.SDL_GameControllerHasSensor(gamecontroller, C.SDL_SensorType(@type)) -} - -fn C.SDL_GameControllerSetSensorEnabled(gamecontroller &C.SDL_GameController, @type C.SDL_SensorType, enabled bool) int - -// game_controller_set_sensor_enabled sets whether data reporting for a game controller sensor is enabled. -// -// `gamecontroller` The controller to update -// `type` The type of sensor to enable/disable -// `enabled` Whether data reporting should be enabled -// returns 0 or -1 if an error occurred. -// -// NOTE This function is available since SDL 2.0.14. -pub fn game_controller_set_sensor_enabled(gamecontroller &GameController, @type SensorType, enabled bool) int { - return C.SDL_GameControllerSetSensorEnabled(gamecontroller, C.SDL_SensorType(@type), - enabled) -} - -fn C.SDL_GameControllerIsSensorEnabled(gamecontroller &C.SDL_GameController, @type C.SDL_SensorType) bool - -// game_controller_is_sensor_enabled query whether sensor data reporting is enabled for a game controller. -// -// `gamecontroller` The controller to query -// `type` The type of sensor to query -// returns SDL_TRUE if the sensor is enabled, SDL_FALSE otherwise. -pub fn game_controller_is_sensor_enabled(gamecontroller &GameController, @type SensorType) bool { - return C.SDL_GameControllerIsSensorEnabled(gamecontroller, C.SDL_SensorType(@type)) -} - -fn C.SDL_GameControllerGetSensorDataRate(gamecontroller &C.SDL_GameController, @type C.SDL_SensorType) f32 - -// game_controller_get_sensor_data_rate gets the data rate (number of events per second) of a game controller -// sensor. -// -// `gamecontroller` The controller to query -// `type` The type of sensor to query -// returns the data rate, or 0.0f if the data rate is not available. -// -// NOTE This function is available since SDL 2.0.16. -pub fn game_controller_get_sensor_data_rate(gamecontroller &GameController, @type SensorType) f32 { - return C.SDL_GameControllerGetSensorDataRate(gamecontroller, C.SDL_SensorType(@type)) -} - -fn C.SDL_GameControllerGetSensorData(gamecontroller &C.SDL_GameController, @type C.SDL_SensorType, data &f32, num_values int) int - -// game_controller_get_sensor_data gets the current state of a game controller sensor. -// -// The number of values and interpretation of the data is sensor dependent. -// See SDL_sensor.h for the details for each type of sensor. -// -// `gamecontroller` The controller to query -// `type` The type of sensor to query -// `data` A pointer filled with the current sensor state -// `num_values` The number of values to write to data -// returns 0 or -1 if an error occurred. -// -// NOTE This function is available since SDL 2.0.14. -pub fn game_controller_get_sensor_data(gamecontroller &GameController, @type SensorType, data &f32, num_values int) int { - return C.SDL_GameControllerGetSensorData(gamecontroller, C.SDL_SensorType(@type), - data, num_values) -} - -fn C.SDL_GameControllerGetSensorDataWithTimestamp(gamecontroller &C.SDL_GameController, @type C.SDL_SensorType, timestamp &u64, data &f32, num_values int) int - -// game_controller_get_sensor_data_with_timestamp gets the current state of a game controller sensor with the timestamp of the -// last update. -// -// The number of values and interpretation of the data is sensor dependent. -// See SDL_sensor.h for the details for each type of sensor. -// -// `gamecontroller` The controller to query -// `type` The type of sensor to query -// `timestamp` A pointer filled with the timestamp in microseconds of the -// current sensor reading if available, or 0 if not -// `data` A pointer filled with the current sensor state -// `num_values` The number of values to write to data -// returns 0 or -1 if an error occurred. -// -// NOTE This function is available since SDL 2.26.0. -pub fn game_controller_get_sensor_data_with_timestamp(gamecontroller &GameController, @type SensorType, timestamp &u64, data &f32, num_values int) int { - return C.SDL_GameControllerGetSensorDataWithTimestamp(gamecontroller, C.SDL_SensorType(@type), - timestamp, data, num_values) -} - -fn C.SDL_GameControllerRumble(gamecontroller &C.SDL_GameController, low_frequency_rumble u16, high_frequency_rumble u16, duration_ms u32) int - -// game_controller_rumble starts a rumble effect on a game controller. -// -// Each call to this function cancels any previous rumble effect, and calling -// it with 0 intensity stops any rumbling. -// -// `gamecontroller` The controller to vibrate -// `low_frequency_rumble` The intensity of the low frequency (left) -// rumble motor, from 0 to 0xFFFF -// `high_frequency_rumble` The intensity of the high frequency (right) -// rumble motor, from 0 to 0xFFFF -// `duration_ms` The duration of the rumble effect, in milliseconds -// returns 0, or -1 if rumble isn't supported on this controller -// -// NOTE This function is available since SDL 2.0.9. -// -// See also: SDL_GameControllerHasRumble -pub fn game_controller_rumble(gamecontroller &GameController, low_frequency_rumble u16, high_frequency_rumble u16, duration_ms u32) int { - return C.SDL_GameControllerRumble(gamecontroller, low_frequency_rumble, high_frequency_rumble, - duration_ms) -} - -fn C.SDL_GameControllerRumbleTriggers(gamecontroller &C.SDL_GameController, left_rumble u16, right_rumble u16, duration_ms u32) int - -// game_controller_rumble_triggers starts a rumble effect in the game controller's triggers. -// -// Each call to this function cancels any previous trigger rumble effect, and -// calling it with 0 intensity stops any rumbling. -// -// Note that this is rumbling of the _triggers_ and not the game controller as -// a whole. This is currently only supported on Xbox One controllers. If you -// want the (more common) whole-controller rumble, use -// SDL_GameControllerRumble() instead. -// -// `gamecontroller` The controller to vibrate -// `left_rumble` The intensity of the left trigger rumble motor, from 0 -// to 0xFFFF -// `right_rumble` The intensity of the right trigger rumble motor, from 0 -// to 0xFFFF -// `duration_ms` The duration of the rumble effect, in milliseconds -// returns 0, or -1 if trigger rumble isn't supported on this controller -// -// NOTE This function is available since SDL 2.0.14. -// -// See also: SDL_GameControllerHasRumbleTriggers -pub fn game_controller_rumble_triggers(gamecontroller &GameController, left_rumble u16, right_rumble u16, duration_ms u32) int { - return C.SDL_GameControllerRumbleTriggers(gamecontroller, left_rumble, right_rumble, - duration_ms) -} - -fn C.SDL_GameControllerHasLED(gamecontroller &C.SDL_GameController) bool - -// game_controller_has_led queries whether a game controller has an LED. -// -// `gamecontroller` The controller to query -// returns SDL_TRUE, or SDL_FALSE if this controller does not have a -// modifiable LED -// -// NOTE This function is available since SDL 2.0.14. -pub fn game_controller_has_led(gamecontroller &GameController) bool { - return C.SDL_GameControllerHasLED(gamecontroller) -} - -fn C.SDL_GameControllerHasRumble(gamecontroller &C.SDL_GameController) bool - -// game_controller_has_rumble querys whether a game controller has rumble support. -// -// `gamecontroller` The controller to query -// returns SDL_TRUE, or SDL_FALSE if this controller does not have rumble -// support -// -// NOTE This function is available since SDL 2.0.18. -// -// See also: SDL_GameControllerRumble -pub fn game_controller_has_rumble(gamecontroller &C.SDL_GameController) bool { - return C.SDL_GameControllerHasRumble(gamecontroller) -} - -fn C.SDL_GameControllerHasRumbleTriggers(gamecontroller &C.SDL_GameController) bool - -// game_controller_has_rumble_triggers querys whether a game controller has rumble support on triggers. -// -// `gamecontroller` The controller to query -// returns SDL_TRUE, or SDL_FALSE if this controller does not have trigger -// rumble support -// -// NOTE This function is available since SDL 2.0.18. -// -// See also: SDL_GameControllerRumbleTriggers -pub fn game_controller_has_rumble_triggers(gamecontroller &C.SDL_GameController) bool { - return C.SDL_GameControllerHasRumbleTriggers(gamecontroller) -} - -fn C.SDL_GameControllerSetLED(gamecontroller &C.SDL_GameController, red u8, green u8, blue u8) int - -// game_controller_set_led updates a game controller's LED color. -// -// `gamecontroller` The controller to update -// `red` The intensity of the red LED -// `green` The intensity of the green LED -// `blue` The intensity of the blue LED -// returns 0, or -1 if this controller does not have a modifiable LED -// -// NOTE This function is available since SDL 2.0.14. -pub fn game_controller_set_led(gamecontroller &GameController, red u8, green u8, blue u8) int { - return C.SDL_GameControllerSetLED(gamecontroller, red, green, blue) -} - -fn C.SDL_GameControllerSendEffect(gamecontroller &C.SDL_GameController, const_data voidptr, size int) int - -// game_controller_send_effect sends a controller specific effect packet -// -// `gamecontroller` The controller to affect -// `data` The data to send to the controller -// `size` The size of the data to send to the controller -// returns 0, or -1 if this controller or driver doesn't support effect -// packets -// -// NOTE This function is available since SDL 2.0.16. -pub fn game_controller_send_effect(gamecontroller &GameController, const_data voidptr, size int) int { - return C.SDL_GameControllerSendEffect(gamecontroller, const_data, size) -} - fn C.SDL_GameControllerClose(gamecontroller &C.SDL_GameController) -// game_controller_close closes a game controller previously opened with SDL_GameControllerOpen(). -// -// `gamecontroller` a game controller identifier previously returned by -// SDL_GameControllerOpen() -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GameControllerOpen +// game_controller_close closes a controller previously opened with SDL_GameControllerOpen(). pub fn game_controller_close(gamecontroller &GameController) { C.SDL_GameControllerClose(gamecontroller) } - -fn C.SDL_GameControllerGetAppleSFSymbolsNameForButton(gamecontroller &GameController, button GameControllerButton) &char - -// game_controller_get_apple_sf_symbols_name_for_button returns the sfSymbolsName for a given button on a game controller on Apple -// platforms. -// -// `gamecontroller` the controller to query -// `button` a button on the game controller -// returns the sfSymbolsName or NULL if the name can't be found -// -// NOTE This function is available since SDL 2.0.18. -// -// See also: SDL_GameControllerGetAppleSFSymbolsNameForAxis -pub fn game_controller_get_apple_sf_symbols_name_for_button(gamecontroller &GameController, button GameControllerButton) &char { - return C.SDL_GameControllerGetAppleSFSymbolsNameForButton(gamecontroller, button) -} - -fn C.SDL_GameControllerGetAppleSFSymbolsNameForAxis(gamecontroller &GameController, axis GameControllerAxis) &char - -// game_controller_get_apple_sf_symbols_name_for_axis returns the sfSymbolsName for a given axis on a game controller on Apple -// platforms. -// -// `gamecontroller` the controller to query -// `axis` an axis on the game controller -// returns the sfSymbolsName or NULL if the name can't be found -// -// NOTE This function is available since SDL 2.0.18. -// -// See also: SDL_GameControllerGetAppleSFSymbolsNameForButton -pub fn game_controller_get_apple_sf_symbols_name_for_axis(gamecontroller &GameController, axis GameControllerAxis) &char { - return C.SDL_GameControllerGetAppleSFSymbolsNameForAxis(gamecontroller, axis) -} diff --git a/gesture.c.v b/gesture.c.v index b80de554..dd5f912e 100644 --- a/gesture.c.v +++ b/gesture.c.v @@ -13,67 +13,28 @@ pub type GestureID = i64 fn C.SDL_RecordGesture(touch_id C.SDL_TouchID) int -// record_gesture begins recording a gesture on a specified touch device or all touch devices. -// -// If the parameter `touchId` is -1 (i.e., all devices), this function will -// always return 1, regardless of whether there actually are any devices. -// -// `touchId` the touch device id, or -1 for all touch devices -// returns 1 on success or 0 if the specified device could not be found. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetTouchDevice +// record_gesture begins recording a gesture on the specified touch, or all touches (-1) pub fn record_gesture(touch_id TouchID) int { return C.SDL_RecordGesture(C.SDL_TouchID(touch_id)) } fn C.SDL_SaveAllDollarTemplates(dst &C.SDL_RWops) int -// save_all_dollar_templates saves all currently loaded Dollar Gesture templates. -// -// `dst` a SDL_RWops to save to -// returns the number of saved templates on success or 0 on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_LoadDollarTemplates -// See also: SDL_SaveDollarTemplate +// save_all_dollar_templates saves all currently loaded Dollar Gesture templates pub fn save_all_dollar_templates(dst &RWops) int { return C.SDL_SaveAllDollarTemplates(dst) } fn C.SDL_SaveDollarTemplate(gesture_id C.SDL_GestureID, dst &C.SDL_RWops) int -// save_dollar_template saves a currently loaded Dollar Gesture template. -// -// `gestureId` a gesture id -// `dst` a SDL_RWops to save to -// returns 1 on success or 0 on failure; call SDL_GetError() for more -// information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_LoadDollarTemplates -// See also: SDL_SaveAllDollarTemplates +// save_dollar_template saves a currently loaded Dollar Gesture template pub fn save_dollar_template(gesture_id GestureID, dst &RWops) int { return C.SDL_SaveDollarTemplate(C.SDL_GestureID(gesture_id), dst) } fn C.SDL_LoadDollarTemplates(touch_id C.SDL_TouchID, src &C.SDL_RWops) int -// load_dollar_templates loads Dollar Gesture templates from a file. -// -// `touchId` a touch id -// `src` a SDL_RWops to load from -// returns the number of loaded templates on success or a negative error code -// (or 0) on failure; call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_SaveAllDollarTemplates -// See also: SDL_SaveDollarTemplate +// load_dollar_templates loads Dollar Gesture templates from a file pub fn load_dollar_templates(touch_id TouchID, src &RWops) int { return C.SDL_LoadDollarTemplates(C.SDL_TouchID(touch_id), src) } diff --git a/guid.c.v b/guid.c.v deleted file mode 100644 index 42fb3be5..00000000 --- a/guid.c.v +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright(C) 2021 Lars Pontoppidan. All rights reserved. -// Use of this source code is governed by an MIT license -// that can be found in the LICENSE file. -module sdl - -// -// SDL_guid.h -// - -// GUID -// An SDL_GUID is a 128-bit identifier for an input device that -// identifies that device across runs of SDL programs on the same -// platform. If the device is detached and then re-attached to a -// different port, or if the base system is rebooted, the device -// should still report the same GUID. -// -// GUIDs are as precise as possible but are not guaranteed to -// distinguish physically distinct but equivalent devices. For -// example, two game controllers from the same vendor with the same -// product ID and revision may have the same GUID. -// -// GUIDs may be platform-dependent (i.e., the same device may report -// different GUIDs on different operating systems). -@[typedef] -struct C.SDL_GUID { - data [16]u8 -} - -pub type GUID = C.SDL_GUID - -fn C.SDL_GUIDToString(guid C.SDL_GUID, psz_guid &char, cb_guid int) - -// guid_to_string gets an ASCII string representation for a given ::SDL_GUID. -// -// You should supply at least 33 bytes for pszGUID. -// -// `guid` the ::SDL_GUID you wish to convert to string -// `pszGUID` buffer in which to write the ASCII string -// `cbGUID` the size of pszGUID -// -// NOTE This function is available since SDL 2.24.0. -// -// See also: SDL_GUIDFromString -pub fn guid_to_string(guid GUID, psz_guid &char, cb_guid int) { - C.SDL_GUIDToString(guid, psz_guid, cb_guid) -} - -fn C.SDL_GUIDFromString(const_pch_guid &char) C.SDL_GUID - -// guid_from_string converts a GUID string into a ::SDL_GUID structure. -// -// Performs no error checking. If this function is given a string containing -// an invalid GUID, the function will silently succeed, but the GUID generated -// will not be useful. -// -// `pchGUID` string containing an ASCII representation of a GUID -// returns a ::SDL_GUID structure. -// -// NOTE This function is available since SDL 2.24.0. -// -// See also: SDL_GUIDToString -pub fn guid_from_string(const_pch_guid &char) GUID { - return C.SDL_GUIDFromString(const_pch_guid) -} diff --git a/haptic.c.v b/haptic.c.v index 241ae422..22380f21 100644 --- a/haptic.c.v +++ b/haptic.c.v @@ -143,12 +143,6 @@ pub const haptic_cartesian = C.SDL_HAPTIC_CARTESIAN // 1 // See also: SDL_HapticDirection pub const haptic_spherical = C.SDL_HAPTIC_SPHERICAL // 2 -// Use this value to play an effect on the steering wheel axis. This -// provides better compatibility across platforms and devices as SDL will guess -// the correct axis. -// See also: SDL_HapticDirection -pub const haptic_steering_axis = C.SDL_HAPTIC_STEERING_AXIS - // Used to play a device an infinite number of times. // // See also: SDL_HapticRunEffect @@ -255,7 +249,6 @@ direction.dir[0] = 9000; // Since we only have two axes we don't need more param // See also: SDL_HAPTIC_POLAR // See also: SDL_HAPTIC_CARTESIAN // See also: SDL_HAPTIC_SPHERICAL -// See also: SDL_HAPTIC_STEERING_AXIS // See also: SDL_HapticEffect // See also: SDL_HapticNumAxes @@ -450,8 +443,8 @@ pub type HapticRamp = C.SDL_HapticRamp // This struct is exclusively for the ::SDL_HAPTIC_LEFTRIGHT effect. // // The Left/Right effect is used to explicitly control the large and small -// motors, commonly found in modern game controllers. The small (right) motor -// is high frequency, and the large (left) motor is low frequency. +// motors, commonly found in modern game controllers. One motor is high +// frequency, the other is low frequency. // // See also: SDL_HAPTIC_LEFTRIGHT // See also: SDL_HapticEffect @@ -459,7 +452,7 @@ pub type HapticRamp = C.SDL_HapticRamp pub struct C.SDL_HapticLeftRight { pub mut: @type u16 // ::SDL_HAPTIC_LEFTRIGHT - length u32 // Duration of the effect in milliseconds. + length u32 // Duration of the effect. large_magnitude u16 // Control of the large controller motor. small_magnitude u16 // Control of the small controller motor. } @@ -592,12 +585,7 @@ fn C.SDL_NumHaptics() int // num_haptics counts the number of haptic devices attached to the system. // -// returns the number of haptic devices detected on the system or a negative -// error code on failure; call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_HapticName +// returns Number of haptic devices detected on the system. pub fn num_haptics() int { return C.SDL_NumHaptics() } @@ -606,14 +594,11 @@ fn C.SDL_HapticName(device_index int) &char // haptic_name gets the implementation dependent name of a haptic device. // -// This can be called before any joysticks are opened. If no name can be -// found, this function returns NULL. -// -// `device_index` index of the device to query. -// returns the name of the device or NULL on failure; call SDL_GetError() for -// more information. +// This can be called before any joysticks are opened. +// If no name can be found, this function returns NULL. // -// NOTE This function is available since SDL 2.0.0. +// `device_index` Index of the device to get its name. +// returns Name of the device or NULL on error. // // See also: SDL_NumHaptics pub fn haptic_name(device_index int) &char { @@ -628,22 +613,19 @@ fn C.SDL_HapticOpen(device_index int) &C.SDL_Haptic // system. // // When opening a haptic device, its gain will be set to maximum and -// autocenter will be disabled. To modify these values use SDL_HapticSetGain() -// and SDL_HapticSetAutocenter(). +// autocenter will be disabled. To modify these values use +// SDL_HapticSetGain() and SDL_HapticSetAutocenter(). // -// `device_index` index of the device to open -// returns the device identifier or NULL on failure; call SDL_GetError() for -// more information. +// `device_index` Index of the device to open. +// returns Device identifier or NULL on error. // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_HapticClose // See also: SDL_HapticIndex -// See also: SDL_HapticOpenFromJoystick // See also: SDL_HapticOpenFromMouse -// See also: SDL_HapticPause -// See also: SDL_HapticSetAutocenter +// See also: SDL_HapticOpenFromJoystick +// See also: SDL_HapticClose // See also: SDL_HapticSetGain +// See also: SDL_HapticSetAutocenter +// See also: SDL_HapticPause // See also: SDL_HapticStopAll pub fn haptic_open(device_index int) &Haptic { return C.SDL_HapticOpen(device_index) @@ -651,16 +633,13 @@ pub fn haptic_open(device_index int) &Haptic { fn C.SDL_HapticOpened(device_index int) int -// haptic_opened checks if the haptic device at the designated index has been opened. -// -// `device_index` the index of the device to query -// returns 1 if it has been opened, 0 if it hasn't or on failure; call -// SDL_GetError() for more information. +// haptic_opened checks if the haptic device at index has been opened. // -// NOTE This function is available since SDL 2.0.0. +// `device_index` Index to check to see if it has been opened. +// returns 1 if it has been opened or 0 if it hasn't. // -// See also: SDL_HapticIndex // See also: SDL_HapticOpen +// See also: SDL_HapticIndex pub fn haptic_opened(device_index int) int { return C.SDL_HapticOpened(device_index) } @@ -669,11 +648,8 @@ fn C.SDL_HapticIndex(haptic &C.SDL_Haptic) int // haptic_index gets the index of a haptic device. // -// `haptic` the SDL_Haptic device to query -// returns the index of the specified haptic device or a negative error code -// on failure; call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. +// `haptic` Haptic device to get the index of. +// returns The index of the haptic device or -1 on error. // // See also: SDL_HapticOpen // See also: SDL_HapticOpened @@ -683,11 +659,9 @@ pub fn haptic_index(haptic &Haptic) int { fn C.SDL_MouseIsHaptic() int -// mouse_is_haptic querys whether or not the current mouse has haptic capabilities. -// -// returns SDL_TRUE if the mouse is haptic or SDL_FALSE if it isn't. +// mouse_is_haptic gets whether or not the current mouse has haptic capabilities. // -// NOTE This function is available since SDL 2.0.0. +// returns SDL_TRUE if the mouse is haptic, SDL_FALSE if it isn't. // // See also: SDL_HapticOpenFromMouse pub fn mouse_is_haptic() int { @@ -696,29 +670,23 @@ pub fn mouse_is_haptic() int { fn C.SDL_HapticOpenFromMouse() &C.SDL_Haptic -// haptic_open_from_mouse trys to open a haptic device from the current mouse. +// haptic_open_from_mouse tries to open a haptic device from the current mouse. // -// returns the haptic device identifier or NULL on failure; call -// SDL_GetError() for more information. +// returns The haptic device identifier or NULL on error. // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_HapticOpen // See also: SDL_MouseIsHaptic +// See also: SDL_HapticOpen pub fn haptic_open_from_mouse() &Haptic { return C.SDL_HapticOpenFromMouse() } fn C.SDL_JoystickIsHaptic(joystick &C.SDL_Joystick) int -// joystick_is_haptic querys if a joystick has haptic features. +// joystick_is_haptic checks to see if a joystick has haptic features. // -// `joystick` the SDL_Joystick to test for haptic capabilities -// returns SDL_TRUE if the joystick is haptic, SDL_FALSE if it isn't, or a -// negative error code on failure; call SDL_GetError() for more -// information. -// -// NOTE This function is available since SDL 2.0.0. +// `joystick` Joystick to test for haptic capabilities. +// returns SDL_TRUE if the joystick is haptic, SDL_FALSE if it isn't +// or -1 if an error occurred. // // See also: SDL_HapticOpenFromJoystick pub fn joystick_is_haptic(joystick &Joystick) int { @@ -729,23 +697,19 @@ fn C.SDL_HapticOpenFromJoystick(joystick &C.SDL_Joystick) &C.SDL_Haptic // haptic_open_from_joystick opens a haptic device for use from a joystick device. // -// You must still close the haptic device separately. It will not be closed +// You must still close the haptic device separately. It will not be closed // with the joystick. // -// When opened from a joystick you should first close the haptic device before -// closing the joystick device. If not, on some implementations the haptic +// When opening from a joystick you should first close the haptic device before +// closing the joystick device. If not, on some implementations the haptic // device will also get unallocated and you'll be unable to use force feedback // on that device. // -// `joystick` the SDL_Joystick to create a haptic device from -// returns a valid haptic device identifier on success or NULL on failure; -// call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. +// `joystick` Joystick to create a haptic device from. +// returns A valid haptic device identifier on success or NULL on error. // -// See also: SDL_HapticClose // See also: SDL_HapticOpen -// See also: SDL_JoystickIsHaptic +// See also: SDL_HapticClose pub fn haptic_open_from_joystick(joystick &Joystick) &Haptic { return C.SDL_HapticOpenFromJoystick(joystick) } @@ -754,28 +718,22 @@ fn C.SDL_HapticClose(haptic &C.SDL_Haptic) // haptic_close closes a haptic device previously opened with SDL_HapticOpen(). // -// `haptic` the SDL_Haptic device to close -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_HapticOpen +// `haptic` Haptic device to close. pub fn haptic_close(haptic &Haptic) { C.SDL_HapticClose(haptic) } fn C.SDL_HapticNumEffects(haptic &C.SDL_Haptic) int -// haptic_num_effects gets the number of effects a haptic device can store. +// haptic_num_effects returns the number of effects a haptic device can store. // // On some platforms this isn't fully supported, and therefore is an -// approximation. Always check to see if your created effect was actually +// approximation. Always check to see if your created effect was actually // created and do not rely solely on SDL_HapticNumEffects(). // -// `haptic` the SDL_Haptic device to query -// returns the number of effects the haptic device can store or a negative -// error code on failure; call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. +// `haptic` The haptic device to query effect max. +// returns The number of effects the haptic device can store or +// -1 on error. // // See also: SDL_HapticNumEffectsPlaying // See also: SDL_HapticQuery @@ -785,16 +743,15 @@ pub fn haptic_num_effects(haptic &Haptic) int { fn C.SDL_HapticNumEffectsPlaying(haptic &C.SDL_Haptic) int -// haptic_num_effects_playing gets the number of effects a haptic device can play at the same time. +// haptic_num_effects_playing returns the number of effects a haptic device can play at the same +// time. // // This is not supported on all platforms, but will always return a value. +// Added here for the sake of completeness. // -// `haptic` the SDL_Haptic device to query maximum playing effects -// returns the number of effects the haptic device can play at the same time -// or a negative error code on failure; call SDL_GetError() for more -// information. -// -// NOTE This function is available since SDL 2.0.0. +// `haptic` The haptic device to query maximum playing effects. +// returns The number of effects the haptic device can play at the same time +// or -1 on error. // // See also: SDL_HapticNumEffects // See also: SDL_HapticQuery @@ -806,14 +763,20 @@ fn C.SDL_HapticQuery(haptic &C.SDL_Haptic) u32 // haptic_query gets the haptic device's supported features in bitwise manner. // -// `haptic` the SDL_Haptic device to query -// returns a list of supported haptic features in bitwise manner (OR'd), or 0 -// on failure; call SDL_GetError() for more information. +// Example: +/* +``` + if (SDL_HapticQuery(haptic) & SDL_HAPTIC_CONSTANT) { + printf("We have constant haptic effect!\n"); +} +``` +*/ // -// NOTE This function is available since SDL 2.0.0. +// `haptic` The haptic device to query. +// returns Haptic features in bitwise manner (OR'd). // -// See also: SDL_HapticEffectSupported // See also: SDL_HapticNumEffects +// See also: SDL_HapticEffectSupported pub fn haptic_query(haptic &Haptic) u32 { return C.SDL_HapticQuery(haptic) } @@ -822,51 +785,36 @@ fn C.SDL_HapticNumAxes(haptic &C.SDL_Haptic) int // haptic_num_axes gets the number of haptic axes the device has. // -// The number of haptic axes might be useful if working with the -// SDL_HapticDirection effect. -// -// `haptic` the SDL_Haptic device to query -// returns the number of axes on success or a negative error code on failure; -// call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. +// See also: SDL_HapticDirection pub fn haptic_num_axes(haptic &Haptic) int { return C.SDL_HapticNumAxes(haptic) } fn C.SDL_HapticEffectSupported(haptic &C.SDL_Haptic, effect &C.SDL_HapticEffect) int -// haptic_effect_supported checks to see if an effect is supported by a haptic device. +// haptic_effect_supported checks to see if effect is supported by haptic. // -// `haptic` the SDL_Haptic device to query -// `effect` the desired effect to query -// returns SDL_TRUE if effect is supported, SDL_FALSE if it isn't, or a -// negative error code on failure; call SDL_GetError() for more -// information. +// `haptic` Haptic device to check on. +// `effect` Effect to check to see if it is supported. +// returns SDL_TRUE if effect is supported, SDL_FALSE if it isn't or -1 on error. // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_HapticNewEffect // See also: SDL_HapticQuery +// See also: SDL_HapticNewEffect pub fn haptic_effect_supported(haptic &Haptic, effect &HapticEffect) int { return C.SDL_HapticEffectSupported(haptic, effect) } fn C.SDL_HapticNewEffect(haptic &C.SDL_Haptic, effect &C.SDL_HapticEffect) int -// haptic_new_effect creates a new haptic effect on a specified device. -// -// `haptic` an SDL_Haptic device to create the effect on -// `effect` an SDL_HapticEffect structure containing the properties of -// the effect to create -// returns the ID of the effect on success or a negative error code on -// failure; call SDL_GetError() for more information. +// haptic_new_effect creates a new haptic effect on the device. // -// NOTE This function is available since SDL 2.0.0. +// `haptic` Haptic device to create the effect on. +// `effect` Properties of the effect to create. +// returns The identifier of the effect on success or -1 on error. // -// See also: SDL_HapticDestroyEffect -// See also: SDL_HapticRunEffect // See also: SDL_HapticUpdateEffect +// See also: SDL_HapticRunEffect +// See also: SDL_HapticDestroyEffect pub fn haptic_new_effect(haptic &Haptic, effect &HapticEffect) int { return C.SDL_HapticNewEffect(haptic, effect) } @@ -876,22 +824,18 @@ fn C.SDL_HapticUpdateEffect(haptic &C.SDL_Haptic, effect int, data &C.SDL_Haptic // haptic_update_effect updates the properties of an effect. // // Can be used dynamically, although behavior when dynamically changing -// direction may be strange. Specifically the effect may re-upload itself and -// start playing from the start. You also cannot change the type either when +// direction may be strange. Specifically the effect may reupload itself +// and start playing from the start. You cannot change the type either when // running SDL_HapticUpdateEffect(). // -// `haptic` the SDL_Haptic device that has the effect -// `effect` the identifier of the effect to update -// `data` an SDL_HapticEffect structure containing the new effect -// properties to use -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. +// `haptic` Haptic device that has the effect. +// `effect` Identifier of the effect to update. +// `data` New effect properties to use. +// returns 0 on success or -1 on error. // -// See also: SDL_HapticDestroyEffect // See also: SDL_HapticNewEffect // See also: SDL_HapticRunEffect +// See also: SDL_HapticDestroyEffect pub fn haptic_update_effect(haptic &Haptic, effect int, data &HapticEffect) int { return C.SDL_HapticUpdateEffect(haptic, effect, data) } @@ -900,24 +844,20 @@ fn C.SDL_HapticRunEffect(haptic &C.SDL_Haptic, effect int, iterations u32) int // haptic_run_effect runs the haptic effect on its associated haptic device. // -// To repeat the effect over and over indefinitely, set `iterations` to -// `SDL_HAPTIC_INFINITY`. (Repeats the envelope - attack and fade.) To make -// one instance of the effect last indefinitely (so the effect does not fade), -// set the effect's `length` in its structure/union to `SDL_HAPTIC_INFINITY` -// instead. -// -// `haptic` the SDL_Haptic device to run the effect on -// `effect` the ID of the haptic effect to run -// `iterations` the number of iterations to run the effect; use -// `SDL_HAPTIC_INFINITY` to repeat forever -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. +// If iterations are ::SDL_HAPTIC_INFINITY, it'll run the effect over and over +// repeating the envelope (attack and fade) every time. If you only want the +// effect to last forever, set ::SDL_HAPTIC_INFINITY in the effect's length +// parameter. // -// NOTE This function is available since SDL 2.0.0. +// `haptic` Haptic device to run the effect on. +// `effect` Identifier of the haptic effect to run. +// `iterations` Number of iterations to run the effect. Use +// ::SDL_HAPTIC_INFINITY for infinity. +// returns 0 on success or -1 on error. // +// See also: SDL_HapticStopEffect // See also: SDL_HapticDestroyEffect // See also: SDL_HapticGetEffectStatus -// See also: SDL_HapticStopEffect pub fn haptic_run_effect(haptic &Haptic, effect int, iterations u32) int { return C.SDL_HapticRunEffect(haptic, effect, iterations) } @@ -926,15 +866,12 @@ fn C.SDL_HapticStopEffect(haptic &C.SDL_Haptic, effect int) int // haptic_stop_effect stops the haptic effect on its associated haptic device. // -// `haptic` the SDL_Haptic device to stop the effect on -// `effect` the ID of the haptic effect to stop -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. +// `haptic` Haptic device to stop the effect on. +// `effect` Identifier of the effect to stop. +// returns 0 on success or -1 on error. // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_HapticDestroyEffect // See also: SDL_HapticRunEffect +// See also: SDL_HapticDestroyEffect pub fn haptic_stop_effect(haptic &Haptic, effect int) int { return C.SDL_HapticStopEffect(haptic, effect) } @@ -943,13 +880,11 @@ fn C.SDL_HapticDestroyEffect(haptic &C.SDL_Haptic, effect int) // haptic_destroy_effect destroys a haptic effect on the device. // -// This will stop the effect if it's running. Effects are automatically +// This will stop the effect if it's running. Effects are automatically // destroyed when the device is closed. // -// `haptic` the SDL_Haptic device to destroy the effect on -// `effect` the ID of the haptic effect to destroy -// -// NOTE This function is available since SDL 2.0.0. +// `haptic` Device to destroy the effect on. +// `effect` Identifier of the effect to destroy. // // See also: SDL_HapticNewEffect pub fn haptic_destroy_effect(haptic &Haptic, effect int) { @@ -958,16 +893,13 @@ pub fn haptic_destroy_effect(haptic &Haptic, effect int) { fn C.SDL_HapticGetEffectStatus(haptic &C.SDL_Haptic, effect int) int -// haptic_get_effect_status gets the status of the current effect on the specified haptic device. -// -// Device must support the SDL_HAPTIC_STATUS feature. +// haptic_get_effect_status gets the status of the current effect on the haptic device. // -// `haptic` the SDL_Haptic device to query for the effect status on -// `effect` the ID of the haptic effect to query its status -// returns 0 if it isn't playing, 1 if it is playing, or a negative error -// code on failure; call SDL_GetError() for more information. +// Device must support the ::SDL_HAPTIC_STATUS feature. // -// NOTE This function is available since SDL 2.0.0. +// `haptic` Haptic device to query the effect status on. +// `effect` Identifier of the effect to query its status. +// returns 0 if it isn't playing, 1 if it is playing or -1 on error. // // See also: SDL_HapticRunEffect // See also: SDL_HapticStopEffect @@ -977,21 +909,18 @@ pub fn haptic_get_effect_status(haptic &Haptic, effect int) int { fn C.SDL_HapticSetGain(haptic &C.SDL_Haptic, gain int) int -// haptic_set_gain sets the global gain of the specified haptic device. +// haptic_set_gain sets the global gain of the device. // -// Device must support the SDL_HAPTIC_GAIN feature. +// Device must support the ::SDL_HAPTIC_GAIN feature. // // The user may specify the maximum gain by setting the environment variable -// `SDL_HAPTIC_GAIN_MAX` which should be between 0 and 100. All calls to -// SDL_HapticSetGain() will scale linearly using `SDL_HAPTIC_GAIN_MAX` as the +// SDL_HAPTIC_GAIN_MAX which should be between 0 and 100. All calls to +// SDL_HapticSetGain() will scale linearly using SDL_HAPTIC_GAIN_MAX as the // maximum. // -// `haptic` the SDL_Haptic device to set the gain on -// `gain` value to set the gain to, should be between 0 and 100 (0 - 100) -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. +// `haptic` Haptic device to set the gain on. +// `gain` Value to set the gain to, should be between 0 and 100. +// returns 0 on success or -1 on error. // // See also: SDL_HapticQuery pub fn haptic_set_gain(haptic &Haptic, gain int) int { @@ -1002,17 +931,14 @@ fn C.SDL_HapticSetAutocenter(haptic &C.SDL_Haptic, autocenter int) int // haptic_set_autocenter sets the global autocenter of the device. // -// Autocenter should be between 0 and 100. Setting it to 0 will disable +// Autocenter should be between 0 and 100. Setting it to 0 will disable // autocentering. // -// Device must support the SDL_HAPTIC_AUTOCENTER feature. -// -// `haptic` the SDL_Haptic device to set autocentering on -// `autocenter` value to set autocenter to (0-100) -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. +// Device must support the ::SDL_HAPTIC_AUTOCENTER feature. // -// NOTE This function is available since SDL 2.0.0. +// `haptic` Haptic device to set autocentering on. +// `autocenter` Value to set autocenter to, 0 disables autocentering. +// returns 0 on success or -1 on error. // // See also: SDL_HapticQuery pub fn haptic_set_autocenter(haptic &Haptic, autocenter int) int { @@ -1023,17 +949,14 @@ fn C.SDL_HapticPause(haptic &C.SDL_Haptic) int // haptic_pause pauses a haptic device. // -// Device must support the `SDL_HAPTIC_PAUSE` feature. Call +// Device must support the ::SDL_HAPTIC_PAUSE feature. Call // SDL_HapticUnpause() to resume playback. // -// Do not modify the effects nor add new ones while the device is paused. That -// can cause all sorts of weird errors. +// Do not modify the effects nor add new ones while the device is paused. +// That can cause all sorts of weird errors. // -// `haptic` the SDL_Haptic device to pause -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. +// `haptic` Haptic device to pause. +// returns 0 on success or -1 on error. // // See also: SDL_HapticUnpause pub fn haptic_pause(haptic &Haptic) int { @@ -1046,11 +969,8 @@ fn C.SDL_HapticUnpause(haptic &C.SDL_Haptic) int // // Call to unpause after SDL_HapticPause(). // -// `haptic` the SDL_Haptic device to unpause -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. +// `haptic` Haptic device to unpause. +// returns 0 on success or -1 on error. // // See also: SDL_HapticPause pub fn haptic_unpause(haptic &Haptic) int { @@ -1061,25 +981,18 @@ fn C.SDL_HapticStopAll(haptic &C.SDL_Haptic) int // haptic_stop_all stops all the currently playing effects on a haptic device. // -// `haptic` the SDL_Haptic device to stop -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. +// `haptic` Haptic device to stop. +// returns 0 on success or -1 on error. pub fn haptic_stop_all(haptic &Haptic) int { return C.SDL_HapticStopAll(haptic) } fn C.SDL_HapticRumbleSupported(haptic &C.SDL_Haptic) int -// haptic_rumble_supported checks whether rumble is supported on a haptic device. -// -// `haptic` haptic device to check for rumble support -// returns SDL_TRUE if effect is supported, SDL_FALSE if it isn't, or a -// negative error code on failure; call SDL_GetError() for more -// information. +// haptic_rumble_supported checks to see if rumble is supported on a haptic device. // -// NOTE This function is available since SDL 2.0.0. +// `haptic` Haptic device to check to see if it supports rumble. +// returns SDL_TRUE if effect is supported, SDL_FALSE if it isn't or -1 on error. // // See also: SDL_HapticRumbleInit // See also: SDL_HapticRumblePlay @@ -1090,37 +1003,31 @@ pub fn haptic_rumble_supported(haptic &Haptic) int { fn C.SDL_HapticRumbleInit(haptic &C.SDL_Haptic) int -// haptic_rumble_init initializes a haptic device for simple rumble playback. +// haptic_rumble_init initializes the haptic device for simple rumble playback. // -// `haptic` the haptic device to initialize for simple rumble playback -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. +// `haptic` Haptic device to initialize for simple rumble playback. +// returns 0 on success or -1 on error. // // See also: SDL_HapticOpen +// See also: SDL_HapticRumbleSupported // See also: SDL_HapticRumblePlay // See also: SDL_HapticRumbleStop -// See also: SDL_HapticRumbleSupported pub fn haptic_rumble_init(haptic &Haptic) int { return C.SDL_HapticRumbleInit(haptic) } fn C.SDL_HapticRumblePlay(haptic &C.SDL_Haptic, strength f32, length u32) int -// haptic_rumble_play runs a simple rumble effect on a haptic device. +// haptic_rumble_play runs simple rumble on a haptic device // -// `haptic` the haptic device to play the rumble effect on -// `strength` strength of the rumble to play as a 0-1 float value -// `length` length of the rumble to play in milliseconds -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. +// `haptic` Haptic device to play rumble effect on. +// `strength` Strength of the rumble to play as a 0-1 float value. +// `length` Length of the rumble to play in milliseconds. +// returns 0 on success or -1 on error. // +// See also: SDL_HapticRumbleSupported // See also: SDL_HapticRumbleInit // See also: SDL_HapticRumbleStop -// See also: SDL_HapticRumbleSupported pub fn haptic_rumble_play(haptic &Haptic, strength f32, length u32) int { return C.SDL_HapticRumblePlay(haptic, strength, length) } @@ -1129,15 +1036,12 @@ fn C.SDL_HapticRumbleStop(haptic &C.SDL_Haptic) int // haptic_rumble_stop stops the simple rumble on a haptic device. // -// `haptic` the haptic device to stop the rumble effect on -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. +// `haptic` Haptic to stop the rumble on. +// returns 0 on success or -1 on error. // +// See also: SDL_HapticRumbleSupported // See also: SDL_HapticRumbleInit // See also: SDL_HapticRumblePlay -// See also: SDL_HapticRumbleSupported pub fn haptic_rumble_stop(haptic &Haptic) int { return C.SDL_HapticRumbleStop(haptic) } diff --git a/hidapi.c.v b/hidapi.c.v deleted file mode 100644 index 179c1a94..00000000 --- a/hidapi.c.v +++ /dev/null @@ -1,419 +0,0 @@ -// Copyright(C) 2021 Lars Pontoppidan. All rights reserved. -// Use of this source code is governed by an MIT license -// that can be found in the LICENSE file. -module sdl - -// -// SDL_hidapi.h -// - -@[typedef] -pub struct C.SDL_hid_device { -} - -// HidDevice is a handle representing an open HID device -// HidDevice is C.SDL_hid_device -pub type HidDevice = C.SDL_hid_device - -@[typedef] -pub struct C.SDL_hid_device_info { - // Platform-specific device path - path &char - // Device Vendor ID - vendor_id u16 - // Device Product ID - product_id u16 - // Serial Number - serial_number &u16 // NOTE wchar_t* in C - // Device Release Number in binary-coded decimal, - // also known as Device Version Number - release_number u16 - // Manufacturer String - manufacturer_string &u16 // NOTE wchar_t* in C - // Product string - product_string &u16 // NOTE wchar_t* in C - // Usage Page for this Device/Interface - // (Windows/Mac only). - usage_page u16 - // Usage for this Device/Interface - // (Windows/Mac only). - usage u16 - // The USB interface which this logical device - // represents. - // - // * Valid on both Linux implementations in all cases. - // * Valid on the Windows implementation only if the device - // contains more than one interface. - interface_number int - // Additional information about the USB interface. - // Valid on libusb and Android implementations. - interface_class int - interface_subclass int - interface_protocol int - // Pointer to the next device - next &HidDeviceInfo -} - -// HidDeviceInfo carries information about a connected HID device -// HidDeviceInfo is C.SDL_hid_device_info -pub type HidDeviceInfo = C.SDL_hid_device_info - -fn C.SDL_hid_init() int - -// hid_init initializes the HIDAPI library. -// -// This function initializes the HIDAPI library. Calling it is not strictly -// necessary, as it will be called automatically by SDL_hid_enumerate() and -// any of the SDL_hid_open_*() functions if it is needed. This function should -// be called at the beginning of execution however, if there is a chance of -// HIDAPI handles being opened by different threads simultaneously. -// -// Each call to this function should have a matching call to SDL_hid_exit() -// -// returns 0 on success and -1 on error. -// -// NOTE This function is available since SDL 2.0.18. -// -// See also: SDL_hid_exit -pub fn hid_init() int { - return C.SDL_hid_init() -} - -fn C.SDL_hid_exit() int - -// hid_exit finalizes the HIDAPI library. -// -// This function frees all of the static data associated with HIDAPI. It -// should be called at the end of execution to avoid memory leaks. -// -// returns 0 on success and -1 on error. -// -// NOTE This function is available since SDL 2.0.18. -// -// See also: SDL_hid_init -pub fn hid_exit() int { - return C.SDL_hid_exit() -} - -fn C.SDL_hid_device_change_count() u32 - -// hid_device_change_count checks to see if devices may have been added or removed. -// -// Enumerating the HID devices is an expensive operation, so you can call this -// to see if there have been any system device changes since the last call to -// this function. A change in the counter returned doesn't necessarily mean -// that anything has changed, but you can call SDL_hid_enumerate() to get an -// updated device list. -// -// Calling this function for the first time may cause a thread or other system -// resource to be allocated to track device change notifications. -// -// returns a change counter that is incremented with each potential device -// change, or 0 if device change detection isn't available. -// -// NOTE This function is available since SDL 2.0.18. -// -// See also: SDL_hid_enumerate -pub fn hid_device_change_count() u32 { - return C.SDL_hid_device_change_count() -} - -fn C.SDL_hid_enumerate(vendor_id u16, product_id u16) &C.SDL_hid_device_info - -// hid_enumerate enumerates the HID Devices. -// -// This function returns a linked list of all the HID devices attached to the -// system which match vendor_id and product_id. If `vendor_id` is set to 0 -// then any vendor matches. If `product_id` is set to 0 then any product -// matches. If `vendor_id` and `product_id` are both set to 0, then all HID -// devices will be returned. -// -// `vendor_id` The Vendor ID (VID) of the types of device to open. -// `product_id` The Product ID (PID) of the types of device to open. -// returns a pointer to a linked list of type SDL_hid_device_info, containing -// information about the HID devices attached to the system, or NULL -// in the case of failure. Free this linked list by calling -// SDL_hid_free_enumeration(). -// -// NOTE This function is available since SDL 2.0.18. -// -// See also: SDL_hid_device_change_count -pub fn hid_enumerate(vendor_id u16, product_id u16) &HidDeviceInfo { - return C.SDL_hid_enumerate(vendor_id, product_id) -} - -fn C.SDL_hid_free_enumeration(devs &C.SDL_hid_device_info) - -// hid_free_enumeration frees an enumeration Linked List -// -// This function frees a linked list created by SDL_hid_enumerate(). -// -// `devs` Pointer to a list of struct_device returned from -// SDL_hid_enumerate(). -// -// NOTE This function is available since SDL 2.0.18. -pub fn hid_free_enumeration(devs &HidDeviceInfo) { - C.SDL_hid_free_enumeration(devs) -} - -fn C.SDL_hid_open(vendor_id u16, product_id u16, const_serial_number &C.wchar_t) &C.SDL_hid_device - -// hid_open opens a HID device using a Vendor ID (VID), Product ID (PID) and optionally -// a serial number. -// -// If `serial_number` is NULL, the first device with the specified VID and PID -// is opened. -// -// `vendor_id` The Vendor ID (VID) of the device to open. -// `product_id` The Product ID (PID) of the device to open. -// `serial_number` The Serial Number of the device to open (Optionally -// NULL). -// returns a pointer to a SDL_hid_device object on success or NULL on -// failure. -// -// NOTE This function is available since SDL 2.0.18. -// -// NOTE const_serial_number is &C.wchar_t in C -// Use 'V string'.to_wide() to pass a V string as the `const_serial_number` argument -pub fn hid_open(vendor_id u16, product_id u16, const_serial_number &u16) &HidDevice { - return C.SDL_hid_open(vendor_id, product_id, &C.wchar_t(voidptr(const_serial_number))) -} - -fn C.SDL_hid_open_path(const_path &char, b_exclusive int) &C.SDL_hid_device - -// Open a HID device by its path name. -// -// The path name be determined by calling SDL_hid_enumerate(), or a -// platform-specific path name can be used (eg: /dev/hidraw0 on Linux). -// -// `path` The path name of the device to open -// returns a pointer to a SDL_hid_device object on success or NULL on -// failure. -// -// NOTE This function is available since SDL 2.0.18. -pub fn hid_open_path(const_path &char, b_exclusive int) &HidDevice { - return C.SDL_hid_open_path(const_path, b_exclusive) -} - -fn C.SDL_hid_write(dev &C.SDL_hid_device, const_data &u8, length usize) int - -// hid_write writes an Output report to a HID device. -// -// The first byte of `data` must contain the Report ID. For devices which only -// support a single report, this must be set to 0x0. The remaining bytes -// contain the report data. Since the Report ID is mandatory, calls to -// SDL_hid_write() will always contain one more byte than the report contains. -// For example, if a hid report is 16 bytes long, 17 bytes must be passed to -// SDL_hid_write(), the Report ID (or 0x0, for devices with a single report), -// followed by the report data (16 bytes). In this example, the length passed -// in would be 17. -// -// SDL_hid_write() will send the data on the first OUT endpoint, if one -// exists. If it does not, it will send the data through the Control Endpoint -// (Endpoint 0). -// -// `dev` A device handle returned from SDL_hid_open(). -// `data` The data to send, including the report number as the first -// byte. -// `length` The length in bytes of the data to send. -// returns the actual number of bytes written and -1 on error. -// -// NOTE This function is available since SDL 2.0.18. -pub fn hid_write(dev &HidDevice, const_data &u8, length usize) int { - return C.SDL_hid_write(dev, const_data, length) -} - -fn C.SDL_hid_read_timeout(dev &C.SDL_hid_device, data &u8, length usize, milliseconds int) int - -// hid_read_timeout reads an Input report from a HID device with timeout. -// -// Input reports are returned to the host through the INTERRUPT IN endpoint. -// The first byte will contain the Report number if the device uses numbered -// reports. -// -// `dev` A device handle returned from SDL_hid_open(). -// `data` A buffer to put the read data into. -// `length` The number of bytes to read. For devices with multiple -// reports, make sure to read an extra byte for the report -// number. -// `milliseconds` timeout in milliseconds or -1 for blocking wait. -// returns the actual number of bytes read and -1 on error. If no packet was -// available to be read within the timeout period, this function -// returns 0. -// -// NOTE This function is available since SDL 2.0.18. -pub fn hid_read_timeout(dev &HidDevice, data &u8, length usize, milliseconds int) int { - return C.SDL_hid_read_timeout(dev, data, length, milliseconds) -} - -fn C.SDL_hid_read(dev &C.SDL_hid_device, data &u8, length usize) int - -// hid_read reads an Input report from a HID device. -// -// Input reports are returned to the host through the INTERRUPT IN endpoint. -// The first byte will contain the Report number if the device uses numbered -// reports. -// -// `dev` A device handle returned from SDL_hid_open(). -// `data` A buffer to put the read data into. -// `length` The number of bytes to read. For devices with multiple -// reports, make sure to read an extra byte for the report -// number. -// returns the actual number of bytes read and -1 on error. If no packet was -// available to be read and the handle is in non-blocking mode, this -// function returns 0. -// -// NOTE This function is available since SDL 2.0.18. -pub fn hid_read(dev &HidDevice, data &u8, length usize) int { - return C.SDL_hid_read(dev, data, length) -} - -fn C.SDL_hid_set_nonblocking(dev &C.SDL_hid_device, nonblock int) int - -// hid_set_nonblocking sets the device handle to be non-blocking. -// -// In non-blocking mode calls to SDL_hid_read() will return immediately with a -// value of 0 if there is no data to be read. In blocking mode, SDL_hid_read() -// will wait (block) until there is data to read before returning. -// -// Nonblocking can be turned on and off at any time. -// -// `dev` A device handle returned from SDL_hid_open(). -// `nonblock` enable or not the nonblocking reads - 1 to enable -// nonblocking - 0 to disable nonblocking. -// returns 0 on success and -1 on error. -// -// NOTE This function is available since SDL 2.0.18. -pub fn hid_set_nonblocking(dev &HidDevice, nonblock int) int { - return C.SDL_hid_set_nonblocking(dev, nonblock) -} - -fn C.SDL_hid_send_feature_report(dev &C.SDL_hid_device, const_data &u8, length usize) int - -// hid_send_feature_report sends a Feature report to the device. -// -// Feature reports are sent over the Control endpoint as a Set_Report -// transfer. The first byte of `data` must contain the Report ID. For devices -// which only support a single report, this must be set to 0x0. The remaining -// bytes contain the report data. Since the Report ID is mandatory, calls to -// SDL_hid_send_feature_report() will always contain one more byte than the -// report contains. For example, if a hid report is 16 bytes long, 17 bytes -// must be passed to SDL_hid_send_feature_report(): the Report ID (or 0x0, for -// devices which do not use numbered reports), followed by the report data (16 -// bytes). In this example, the length passed in would be 17. -// -// `dev` A device handle returned from SDL_hid_open(). -// `data` The data to send, including the report number as the first -// byte. -// `length` The length in bytes of the data to send, including the report -// number. -// returns the actual number of bytes written and -1 on error. -// -// NOTE This function is available since SDL 2.0.18. -pub fn hid_send_feature_report(dev &HidDevice, const_data &u8, length usize) int { - return C.SDL_hid_send_feature_report(dev, const_data, length) -} - -fn C.SDL_hid_get_feature_report(dev &C.SDL_hid_device, data &u8, length usize) int - -// hid_get_feature_report gets a feature report from a HID device. -// -// Set the first byte of `data` to the Report ID of the report to be read. -// Make sure to allow space for this extra byte in `data`. Upon return, the -// first byte will still contain the Report ID, and the report data will start -// in data[1]. -// -// `dev` A device handle returned from SDL_hid_open(). -// `data` A buffer to put the read data into, including the Report ID. -// Set the first byte of `data` to the Report ID of the report to -// be read, or set it to zero if your device does not use numbered -// reports. -// `length` The number of bytes to read, including an extra byte for the -// report ID. The buffer can be longer than the actual report. -// returns the number of bytes read plus one for the report ID (which is -// still in the first byte), or -1 on error. -// -// NOTE This function is available since SDL 2.0.18. -pub fn hid_get_feature_report(dev &HidDevice, data &u8, length usize) int { - return C.SDL_hid_get_feature_report(dev, data, length) -} - -fn C.SDL_hid_close(dev &C.SDL_hid_device) - -// hid_close closes a HID device. -// -// `dev` A device handle returned from SDL_hid_open(). -// -// NOTE This function is available since SDL 2.0.18. -pub fn hid_close(dev &HidDevice) { - C.SDL_hid_close(dev) -} - -fn C.SDL_hid_get_manufacturer_string(dev &C.SDL_hid_device, string_ &C.wchar_t, maxlen usize) int - -// hid_get_manufacturer_string gets The Manufacturer String from a HID device. -// -// `dev` A device handle returned from SDL_hid_open(). -// `string` A wide string buffer to put the data into. -// `maxlen` The length of the buffer in multiples of wchar_t. -// returns 0 on success and -1 on error. -// -// NOTE This function is available since SDL 2.0.18. -pub fn hid_get_manufacturer_string(dev &HidDevice, string_ &u16, maxlen usize) int { - return C.SDL_hid_get_manufacturer_string(dev, &C.wchar_t(voidptr(string_)), maxlen) -} - -fn C.SDL_hid_get_product_string(dev &C.SDL_hid_device, string_ &C.wchar_t, maxlen usize) int - -// hid_get_product_string gets The Product String from a HID device. -// -// `dev` A device handle returned from SDL_hid_open(). -// `string` A wide string buffer to put the data into. -// `maxlen` The length of the buffer in multiples of wchar_t. -// returns 0 on success and -1 on error. -// -// NOTE This function is available since SDL 2.0.18. -pub fn hid_get_product_string(dev &HidDevice, string_ &u16, maxlen usize) int { - return C.SDL_hid_get_product_string(dev, &C.wchar_t(voidptr(string_)), maxlen) -} - -fn C.SDL_hid_get_serial_number_string(dev &C.SDL_hid_device, string_ &C.wchar_t, maxlen usize) int - -// hid_get_serial_number_string gets The Serial Number String from a HID device. -// -// `dev` A device handle returned from SDL_hid_open(). -// `string` A wide string buffer to put the data into. -// `maxlen` The length of the buffer in multiples of wchar_t. -// returns 0 on success and -1 on error. -// -// NOTE This function is available since SDL 2.0.18. -pub fn hid_get_serial_number_string(dev &HidDevice, string_ &u16, maxlen usize) int { - return C.SDL_hid_get_serial_number_string(dev, &C.wchar_t(voidptr(string_)), maxlen) -} - -fn C.SDL_hid_get_indexed_string(dev &C.SDL_hid_device, string_index int, string_ &C.wchar_t, maxlen usize) int - -// hid_get_indexed_string gets a string from a HID device, based on its string index. -// -// `dev` A device handle returned from SDL_hid_open(). -// `string_index` The index of the string to get. -// `string` A wide string buffer to put the data into. -// `maxlen` The length of the buffer in multiples of wchar_t. -// returns 0 on success and -1 on error. -// -// NOTE This function is available since SDL 2.0.18. -pub fn hid_get_indexed_string(dev &C.SDL_hid_device, string_index int, string_ &u16, maxlen usize) int { - return C.SDL_hid_get_indexed_string(dev, string_index, &C.wchar_t(voidptr(string_)), - maxlen) -} - -fn C.SDL_hid_ble_scan(active bool) - -// hid_ble_scan starts or stop a BLE scan on iOS and tvOS to pair Steam Controllers -// -// `active` SDL_TRUE to start the scan, SDL_FALSE to stop the scan -// -// NOTE This function is available since SDL 2.0.18. -pub fn hid_ble_scan(active bool) { - C.SDL_hid_ble_scan(active) -} diff --git a/hints.c.v b/hints.c.v index 15ec09bf..77160173 100644 --- a/hints.c.v +++ b/hints.c.v @@ -6,1312 +6,58 @@ module sdl // // SDL_hints.h // -// A variable controlling whether the Android / iOS built-in -// accelerometer should be listed as a joystick device. -// -// This variable can be set to the following values: -// "0" - The accelerometer is not listed as a joystick -// "1" - The accelerometer is available as a 3 axis joystick (the default). -pub const hint_accelerometer_as_joystick = 'SDL_ACCELEROMETER_AS_JOYSTICK' - -// Specify the behavior of Alt+Tab while the keyboard is grabbed. -// -// By default, SDL emulates Alt+Tab functionality while the keyboard is grabbed -// and your window is full-screen. This prevents the user from getting stuck in -// your application if you've enabled keyboard grab. -// -// The variable can be set to the following values: -// "0" - SDL will not handle Alt+Tab. Your application is responsible -// for handling Alt+Tab while the keyboard is grabbed. -// "1" - SDL will minimize your window when Alt+Tab is pressed (default) -pub const hint_allow_alt_tab_while_grabbed = 'SDL_ALLOW_ALT_TAB_WHILE_GRABBED' - -// If set to "0" then never set the top most bit on a SDL Window, even if the video mode expects it. -// This is a debugging aid for developers and not expected to be used by end users. The default is "1" -// -// This variable can be set to the following values: -// "0" - don't allow topmost -// "1" - allow topmost -pub const hint_allow_topmost = 'SDL_ALLOW_TOPMOST' - -// Android APK expansion main file version. Should be a string number like "1", "2" etc. -// -// Must be set together with SDL_HINT_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION. -// -// If both hints were set then SDL_RWFromFile() will look into expansion files -// after a given relative path was not found in the internal storage and assets. -// -// By default this hint is not set and the APK expansion files are not searched. -pub const hint_android_apk_expansion_main_file_version = 'SDL_ANDROID_APK_EXPANSION_MAIN_FILE_VERSION' - -// Android APK expansion patch file version. Should be a string number like "1", "2" etc. -// -// Must be set together with SDL_HINT_ANDROID_APK_EXPANSION_MAIN_FILE_VERSION. -// -// If both hints were set then SDL_RWFromFile() will look into expansion files -// after a given relative path was not found in the internal storage and assets. -// -// By default this hint is not set and the APK expansion files are not searched. -pub const hint_android_apk_expansion_patch_file_version = 'SDL_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION' - -// A variable to control whether the event loop will block itself when the app is paused. -// -// The variable can be set to the following values: -// "0" - Non blocking. -// "1" - Blocking. (default) -// -// The value should be set before SDL is initialized. -pub const hint_android_block_on_pause = 'SDL_ANDROID_BLOCK_ON_PAUSE' - -// A variable to control whether SDL will pause audio in background -// (Requires SDL_ANDROID_BLOCK_ON_PAUSE as "Non blocking") -// -// The variable can be set to the following values: -// "0" - Non paused. -// "1" - Paused. (default) -// -// The value should be set before SDL is initialized. -pub const hint_android_block_on_pause_pauseaudio = 'SDL_ANDROID_BLOCK_ON_PAUSE_PAUSEAUDIO' - -// A variable to control whether we trap the Android back button to handle it manually. -// This is necessary for the right mouse button to work on some Android devices, or -// to be able to trap the back button for use in your code reliably. If set to true, -// the back button will show up as an SDL_KEYDOWN / SDL_KEYUP pair with a keycode of -// SDL_SCANCODE_AC_BACK. -// -// The variable can be set to the following values: -// "0" - Back button will be handled as usual for system. (default) -// "1" - Back button will be trapped, allowing you to handle the key press -// manually. (This will also let right mouse click work on systems -// where the right mouse button functions as back.) -// -// The value of this hint is used at runtime, so it can be changed at any time. -pub const hint_android_trap_back_button = 'SDL_ANDROID_TRAP_BACK_BUTTON' - -// Specify an application name. -// -// This hint lets you specify the application name sent to the OS when -// required. For example, this will often appear in volume control applets for -// audio streams, and in lists of applications which are inhibiting the -// screensaver. You should use a string that describes your program ("My Game -// 2: The Revenge") -// -// Setting this to "" or leaving it unset will have SDL use a reasonable -// default: probably the application's name or "SDL Application" if SDL -// doesn't have any better information. -// -// Note that, for audio streams, this can be overridden with -// SDL_HINT_AUDIO_DEVICE_APP_NAME. -// -// On targets where this is not supported, this hint does nothing. -pub const hint_app_name = 'SDL_APP_NAME' - -// A variable controlling whether controllers used with the Apple TV -// generate UI events. -// -// When UI events are generated by controller input, the app will be -// backgrounded when the Apple TV remote's menu button is pressed, and when the -// pause or B buttons on gamepads are pressed. -// -// More information about properly making use of controllers for the Apple TV -// can be found here: -// https://developer.apple.com/tvos/human-interface-guidelines/remote-and-controllers/ -// -// This variable can be set to the following values: -// "0" - Controller input does not generate UI events (the default). -// "1" - Controller input generates UI events. -pub const hint_apple_tv_controller_ui_events = 'SDL_APPLE_TV_CONTROLLER_UI_EVENTS' - -// A variable controlling whether the Apple TV remote's joystick axes -// will automatically match the rotation of the remote. -// -// This variable can be set to the following values: -// "0" - Remote orientation does not affect joystick axes (the default). -// "1" - Joystick axes are based on the orientation of the remote. -pub const hint_apple_tv_remote_allow_rotation = 'SDL_APPLE_TV_REMOTE_ALLOW_ROTATION' - -// A variable controlling the audio category on iOS and Mac OS X -// -// This variable can be set to the following values: -// -// "ambient" - Use the AVAudioSessionCategoryAmbient audio category, will be muted by the phone mute switch (default) -// "playback" - Use the AVAudioSessionCategoryPlayback category -// -// For more information, see Apple's documentation: -// https://developer.apple.com/library/content/documentation/Audio/Conceptual/AudioSessionProgrammingGuide/AudioSessionCategoriesandModes/AudioSessionCategoriesandModes.html -pub const hint_audio_category = 'SDL_AUDIO_CATEGORY' - -// Specify an application name for an audio device. -// -// Some audio backends (such as PulseAudio) allow you to describe your audio -// stream. Among other things, this description might show up in a system -// control panel that lets the user adjust the volume on specific audio -// streams instead of using one giant master volume slider. -// -// This hints lets you transmit that information to the OS. The contents of -// this hint are used while opening an audio device. You should use a string -// that describes your program ("My Game 2: The Revenge") -// -// Setting this to "" or leaving it unset will have SDL use a reasonable -// default: this will be the name set with SDL_HINT_APP_NAME, if that hint is -// set. Otherwise, it'll probably the application's name or "SDL Application" -// if SDL doesn't have any better information. -// -// On targets where this is not supported, this hint does nothing. -pub const hint_audio_device_app_name = 'SDL_AUDIO_DEVICE_APP_NAME' - -// Specify an application name for an audio device. -// -// Some audio backends (such as PulseAudio) allow you to describe your audio -// stream. Among other things, this description might show up in a system -// control panel that lets the user adjust the volume on specific audio -// streams instead of using one giant master volume slider. -// -// This hints lets you transmit that information to the OS. The contents of -// this hint are used while opening an audio device. You should use a string -// that describes your what your program is playing ("audio stream" is -// probably sufficient in many cases, but this could be useful for something -// like "team chat" if you have a headset playing VoIP audio separately). -// -// Setting this to "" or leaving it unset will have SDL use a reasonable -// default: "audio stream" or something similar. -// -// On targets where this is not supported, this hint does nothing. -pub const hint_audio_device_stream_name = 'SDL_AUDIO_DEVICE_STREAM_NAME' - -// Specify an application role for an audio device. -// -// Some audio backends (such as Pipewire) allow you to describe the role of -// your audio stream. Among other things, this description might show up in -// a system control panel or software for displaying and manipulating media -// playback/capture graphs. -// -// This hints lets you transmit that information to the OS. The contents of -// this hint are used while opening an audio device. You should use a string -// that describes your what your program is playing (Game, Music, Movie, -// etc...). -// -// Setting this to "" or leaving it unset will have SDL use a reasonable -// default: "Game" or something similar. -// -// On targets where this is not supported, this hint does nothing. -pub const hint_audio_device_stream_role = 'SDL_AUDIO_DEVICE_STREAM_ROLE' - -// A variable controlling speed/quality tradeoff of audio resampling. -// -// If available, SDL can use libsamplerate ( http://www.mega-nerd.com/SRC/ ) -// to handle audio resampling. There are different resampling modes available -// that produce different levels of quality, using more CPU. -// -// If this hint isn't specified to a valid setting, or libsamplerate isn't -// available, SDL will use the default, internal resampling algorithm. -// -// As of SDL 2.26, SDL_ConvertAudio() respects this hint when libsamplerate is available. -// -// This hint is currently only checked at audio subsystem initialization. -// -// This variable can be set to the following values: -// -// "0" or "default" - Use SDL's internal resampling (Default when not set - low quality, fast) -// "1" or "fast" - Use fast, slightly higher quality resampling, if available -// "2" or "medium" - Use medium quality resampling, if available -// "3" or "best" - Use high quality resampling, if available -pub const hint_audio_resampling_mode = 'SDL_AUDIO_RESAMPLING_MODE' - -// A variable controlling whether SDL updates joystick state when getting input events -// -// This variable can be set to the following values: -// -// "0" - You'll call SDL_JoystickUpdate() manually -// "1" - SDL will automatically call SDL_JoystickUpdate() (default) -// -// This hint can be toggled on and off at runtime. -pub const hint_auto_update_joysticks = 'SDL_AUTO_UPDATE_JOYSTICKS' - -// A variable controlling whether SDL updates sensor state when getting input events -// -// This variable can be set to the following values: -// -// "0" - You'll call SDL_SensorUpdate() manually -// "1" - SDL will automatically call SDL_SensorUpdate() (default) -// -// This hint can be toggled on and off at runtime. -pub const hint_auto_update_sensors = 'SDL_AUTO_UPDATE_SENSORS' - -// Prevent SDL from using version 4 of the bitmap header when saving BMPs. -// -// The bitmap header version 4 is required for proper alpha channel support and -// SDL will use it when required. Should this not be desired, this hint can -// force the use of the 40 byte header version which is supported everywhere. -// -// The variable can be set to the following values: -// "0" - Surfaces with a colorkey or an alpha channel are saved to a -// 32-bit BMP file with an alpha mask. SDL will use the bitmap -// header version 4 and set the alpha mask accordingly. -// "1" - Surfaces with a colorkey or an alpha channel are saved to a -// 32-bit BMP file without an alpha mask. The alpha channel data -// will be in the file, but applications are going to ignore it. -// -// The default value is "0". -pub const hint_bmp_save_legacy_format = 'SDL_BMP_SAVE_LEGACY_FORMAT' - -// Override for SDL_GetDisplayUsableBounds() -// -// If set, this hint will override the expected results for -// SDL_GetDisplayUsableBounds() for display index 0. Generally you don't want -// to do this, but this allows an embedded system to request that some of the -// screen be reserved for other uses when paired with a well-behaved -// application. -// -// The contents of this hint must be 4 comma-separated integers, the first -// is the bounds x, then y, width and height, in that order. -pub const hint_display_usable_bounds = 'SDL_DISPLAY_USABLE_BOUNDS' - -// Disable giving back control to the browser automatically -// when running with asyncify -// -// With -s ASYNCIFY, SDL2 calls emscripten_sleep during operations -// such as refreshing the screen or polling events. -// -// This hint only applies to the emscripten platform -// -// The variable can be set to the following values: -// "0" - Disable emscripten_sleep calls (if you give back browser control manually or use asyncify for other purposes) -// "1" - Enable emscripten_sleep calls (the default) -pub const hint_emscripten_asyncify = 'SDL_EMSCRIPTEN_ASYNCIFY' - -// override the binding element for keyboard inputs for Emscripten builds -// -// This hint only applies to the emscripten platform -// -// The variable can be one of -// "#window" - The javascript window object (this is the default) -// "#document" - The javascript document object -// "#screen" - the javascript window.screen object -// "#canvas" - the WebGL canvas element -// any other string without a leading # sign applies to the element on the page with that ID. -pub const hint_emscripten_keyboard_element = 'SDL_EMSCRIPTEN_KEYBOARD_ELEMENT' - -// A variable that controls whether the on-screen keyboard should be shown when text input is active -// -// The variable can be set to the following values: -// "0" - Do not show the on-screen keyboard -// "1" - Show the on-screen keyboard -// -// The default value is "1". This hint must be set before text input is activated. -pub const hint_enable_screen_keyboard = 'SDL_ENABLE_SCREEN_KEYBOARD' - -// A variable that controls whether Steam Controllers should be exposed using the SDL joystick and game controller APIs -// -// The variable can be set to the following values: -// "0" - Do not scan for Steam Controllers -// "1" - Scan for Steam Controllers (the default) -// -// The default value is "1". This hint must be set before initializing the joystick subsystem. -pub const hint_enable_steam_controllers = 'SDL_ENABLE_STEAM_CONTROLLERS' - -// A variable controlling verbosity of the logging of SDL events pushed onto the internal queue. -// -// This variable can be set to the following values, from least to most verbose: -// -// "0" - Don't log any events (default) -// "1" - Log most events (other than the really spammy ones). -// "2" - Include mouse and finger motion events. -// "3" - Include SDL_SysWMEvent events. -// -// on in the event queue. Logged events are sent through SDL_Log(), which -// means by default they appear on stdout on most platforms or maybe -// OutputDebugString() on Windows, and can be funneled by the app with -// SDL_LogSetOutputFunction(), etc. -// -// This hint can be toggled on and off at runtime, if you only need to log -// events for a small subset of program execution. -pub const hint_event_logging = 'SDL_EVENT_LOGGING' - -// A variable controlling whether raising the window should be done more forcefully -// -// This variable can be set to the following values: -// "0" - No forcing (the default) -// "1" - Extra level of forcing -// -// At present, this is only an issue under MS Windows, which makes it nearly impossible to -// programmatically move a window to the foreground, for "security" reasons. See -// http://stackoverflow.com/a/34414846 for a discussion. -pub const hint_force_raisewindow = 'SDL_HINT_FORCE_RAISEWINDOW' - -// A variable controlling how 3D acceleration is used to accelerate the SDL screen surface. -// -// SDL can try to accelerate the SDL screen surface by using streaming -// textures with a 3D rendering engine. This variable controls whether and -// how this is done. -// -// This variable can be set to the following values: -// "0" - Disable 3D acceleration -// "1" - Enable 3D acceleration, using the default renderer. -// "X" - Enable 3D acceleration, using X where X is one of the valid rendering drivers. (e.g. "direct3d", "opengl", etc.) -// -// By default SDL tries to make a best guess for each platform whether -// to use acceleration or not. -pub const hint_framebuffer_acceleration = 'SDL_FRAMEBUFFER_ACCELERATION' - -// A variable that lets you manually hint extra gamecontroller db entries. -// -// The variable should be newline delimited rows of gamecontroller config data, see SDL_gamecontroller.h -// -// This hint must be set before calling SDL_Init(SDL_INIT_GAMECONTROLLER) -// You can update mappings after the system is initialized with SDL_GameControllerMappingForGUID() and SDL_GameControllerAddMapping() -pub const hint_gamecontrollerconfig = 'SDL_GAMECONTROLLERCONFIG' - -// A variable that lets you provide a file with extra gamecontroller db entries. -// -// The file should contain lines of gamecontroller config data, see SDL_gamecontroller.h -// -// This hint must be set before calling SDL_Init(SDL_INIT_GAMECONTROLLER) -// You can update mappings after the system is initialized with SDL_GameControllerMappingForGUID() and SDL_GameControllerAddMapping() -pub const hint_gamecontrollerconfig_file = 'SDL_GAMECONTROLLERCONFIG_FILE' - -// A variable that overrides the automatic controller type detection -// -// The variable should be comma separated entries, in the form: VID/PID=type -// -// The VID and PID should be hexadecimal with exactly 4 digits, e.g. 0x00fd -// -// The type should be one of: -// Xbox360 -// XboxOne -// PS3 -// PS4 -// PS5 -// SwitchPro -// -// This hint affects what driver is used, and must be set before calling SDL_Init(SDL_INIT_GAMECONTROLLER) -pub const hint_gamecontrollertype = 'SDL_GAMECONTROLLERTYPE' - -// A variable containing a list of devices to skip when scanning for game controllers. -// -// The format of the string is a comma separated list of USB VID/PID pairs -// in hexadecimal form, e.g. -// -// 0xAAAA/0xBBBB,0xCCCC/0xDDDD -// -// The variable can also take the form of @file, in which case the named -// file will be loaded and interpreted as the value of the variable. -pub const hint_gamecontroller_ignore_devices = 'SDL_GAMECONTROLLER_IGNORE_DEVICES' - -// If set, all devices will be skipped when scanning for game controllers except for the ones listed in this variable. -// -// The format of the string is a comma separated list of USB VID/PID pairs -// in hexadecimal form, e.g. -// -// 0xAAAA/0xBBBB,0xCCCC/0xDDDD -// -// The variable can also take the form of @file, in which case the named -// file will be loaded and interpreted as the value of the variable. -pub const hint_gamecontroller_ignore_devices_except = 'SDL_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT' - -// If set, game controller face buttons report their values according to their labels instead of their positional layout. -// -// For example, on Nintendo Switch controllers, normally you'd get: -// -// (Y) -// (X) (B) -// (A) -// -// but if this hint is set, you'll get: -// -// (X) -// (Y) (A) -// (B) -// -// The variable can be set to the following values: -// "0" - Report the face buttons by position, as though they were on an Xbox controller. -// "1" - Report the face buttons by label instead of position -// -// The default value is "1". This hint may be set at any time. -pub const hint_gamecontroller_use_button_labels = 'SDL_GAMECONTROLLER_USE_BUTTON_LABELS' - -// A variable controlling whether grabbing input grabs the keyboard -// -// This variable can be set to the following values: -// "0" - Grab will affect only the mouse -// "1" - Grab will affect mouse and keyboard -// -// By default SDL will not grab the keyboard so system shortcuts still work. -pub const hint_grab_keyboard = 'SDL_GRAB_KEYBOARD' - -// A variable containing a list of devices to ignore in SDL_hid_enumerate() -// -// For example, to ignore the Shanwan DS3 controller and any Valve controller, you might -// have the string "0x2563/0x0523,0x28de/0x0000" -pub const hint_hidapi_ignore_devices = 'SDL_HIDAPI_IGNORE_DEVICES' - -// A variable controlling whether the idle timer is disabled on iOS. -// -// When an iOS app does not receive touches for some time, the screen is -// dimmed automatically. For games where the accelerometer is the only input -// this is problematic. This functionality can be disabled by setting this -// hint. -// -// As of SDL 2.0.4, SDL_EnableScreenSaver() and SDL_DisableScreenSaver() -// accomplish the same thing on iOS. They should be preferred over this hint. -// -// This variable can be set to the following values: -// "0" - Enable idle timer -// "1" - Disable idle timer -pub const hint_idle_timer_disabled = 'SDL_IOS_IDLE_TIMER_DISABLED' - -// A variable to control whether certain IMEs should handle text editing internally instead of sending SDL_TEXTEDITING events. -// -// The variable can be set to the following values: -// "0" - SDL_TEXTEDITING events are sent, and it is the application's -// responsibility to render the text from these events and -// differentiate it somehow from committed text. (default) -// "1" - If supported by the IME then SDL_TEXTEDITING events are not sent, -// and text that is being composed will be rendered in its own UI. -pub const hint_ime_internal_editing = 'SDL_IME_INTERNAL_EDITING' - -// A variable to control whether certain IMEs should show native UI components (such as the Candidate List) instead of suppressing them. -// -// The variable can be set to the following values: -// "0" - Native UI components are not display. (default) -// "1" - Native UI components are displayed. -pub const hint_ime_show_ui = 'SDL_IME_SHOW_UI' - -// A variable to control if extended IME text support is enabled. -// If enabled then SDL_TextEditingExtEvent will be issued if the text would be truncated otherwise. -// Additionally SDL_TextInputEvent will be dispatched multiple times so that it is not truncated. -// -// The variable can be set to the following values: -// "0" - Legacy behavior. Text can be truncated, no heap allocations. (default) -// "1" - Modern behavior. -pub const hint_ime_support_extended_text = 'SDL_IME_SUPPORT_EXTENDED_TEXT' - -// A variable controlling whether the home indicator bar on iPhone X -// should be hidden. -// -// This variable can be set to the following values: -// "0" - The indicator bar is not hidden (default for windowed applications) -// "1" - The indicator bar is hidden and is shown when the screen is touched (useful for movie playback applications) -// "2" - The indicator bar is dim and the first swipe makes it visible and the second swipe performs the "home" action (default for fullscreen applications) -pub const hint_ios_hide_home_indicator = 'SDL_IOS_HIDE_HOME_INDICATOR' - -// A variable that lets you enable joystick (and gamecontroller) events even when your app is in the background. -// -// The variable can be set to the following values: -// "0" - Disable joystick & gamecontroller input events when the -// application is in the background. -// "1" - Enable joystick & gamecontroller input events when the -// application is in the background. -// -// The default value is "0". This hint may be set at any time. -pub const hint_joystick_allow_background_events = 'SDL_JOYSTICK_ALLOW_BACKGROUND_EVENTS' - -// A variable containing a list of arcade stick style controllers. -// -// The format of the string is a comma separated list of USB VID/PID pairs -// in hexadecimal form, e.g. -// -// 0xAAAA/0xBBBB,0xCCCC/0xDDDD -// -// The variable can also take the form of @file, in which case the named -// file will be loaded and interpreted as the value of the variable. -pub const hint_joystick_arcadestick_devices = 'SDL_JOYSTICK_ARCADESTICK_DEVICES' - -// A variable containing a list of devices that are not arcade stick style controllers. This will override SDL_HINT_JOYSTICK_ARCADESTICK_DEVICES and the built in device list. -// -// The format of the string is a comma separated list of USB VID/PID pairs -// in hexadecimal form, e.g. -// -// 0xAAAA/0xBBBB,0xCCCC/0xDDDD -// -// The variable can also take the form of @file, in which case the named -// file will be loaded and interpreted as the value of the variable. -pub const hint_joystick_arcadestick_devices_excluded = 'SDL_JOYSTICK_ARCADESTICK_DEVICES_EXCLUDED' - -// A variable containing a list of devices that should not be considerd joysticks. -// -// The format of the string is a comma separated list of USB VID/PID pairs -// in hexadecimal form, e.g. -// -// 0xAAAA/0xBBBB,0xCCCC/0xDDDD -// -// The variable can also take the form of @file, in which case the named -// file will be loaded and interpreted as the value of the variable. -pub const hint_joystick_blacklist_devices = 'SDL_JOYSTICK_BLACKLIST_DEVICES' - -// A variable containing a list of devices that should be considered joysticks. This will override SDL_HINT_JOYSTICK_BLACKLIST_DEVICES and the built in device list. -// -// The format of the string is a comma separated list of USB VID/PID pairs -// in hexadecimal form, e.g. -// -// 0xAAAA/0xBBBB,0xCCCC/0xDDDD -// -// The variable can also take the form of @file, in which case the named -// file will be loaded and interpreted as the value of the variable. -pub const hint_joystick_blacklist_devices_excluded = 'SDL_JOYSTICK_BLACKLIST_DEVICES_EXCLUDED' - -// A variable containing a list of flightstick style controllers. -// -// The format of the string is a comma separated list of USB VID/PID pairs -// in hexadecimal form, e.g. -// -// 0xAAAA/0xBBBB,0xCCCC/0xDDDD -// -// The variable can also take the form of @file, in which case the named -// file will be loaded and interpreted as the value of the variable. -pub const hint_joystick_flightstick_devices = 'SDL_JOYSTICK_FLIGHTSTICK_DEVICES' - -// A variable containing a list of devices that are not flightstick style controllers. This will override SDL_HINT_JOYSTICK_FLIGHTSTICK_DEVICES and the built in device list. -// -// The format of the string is a comma separated list of USB VID/PID pairs -// in hexadecimal form, e.g. -// -// 0xAAAA/0xBBBB,0xCCCC/0xDDDD -// -// The variable can also take the form of @file, in which case the named -// file will be loaded and interpreted as the value of the variable. -pub const hint_joystick_flightstick_devices_excluded = 'SDL_JOYSTICK_FLIGHTSTICK_DEVICES_EXCLUDED' - -// A variable containing a list of devices known to have a GameCube form factor. -// -// The format of the string is a comma separated list of USB VID/PID pairs -// in hexadecimal form, e.g. -// -// 0xAAAA/0xBBBB,0xCCCC/0xDDDD -// -// The variable can also take the form of @file, in which case the named -// file will be loaded and interpreted as the value of the variable. -pub const hint_joystick_gamecube_devices = 'SDL_JOYSTICK_GAMECUBE_DEVICES' - -// A variable containing a list of devices known not to have a GameCube form factor. This will override SDL_HINT_JOYSTICK_GAMECUBE_DEVICES and the built in device list. -// -// The format of the string is a comma separated list of USB VID/PID pairs -// in hexadecimal form, e.g. -// -// 0xAAAA/0xBBBB,0xCCCC/0xDDDD -// -// The variable can also take the form of @file, in which case the named -// file will be loaded and interpreted as the value of the variable. -pub const hint_joystick_gamecube_devices_excluded = 'SDL_JOYSTICK_GAMECUBE_DEVICES_EXCLUDED' - -// A variable controlling whether the HIDAPI joystick drivers should be used. -// -// This variable can be set to the following values: -// "0" - HIDAPI drivers are not used -// "1" - HIDAPI drivers are used (the default) -// -// This variable is the default for all drivers, but can be overridden by the hints for specific drivers below. -pub const hint_joystick_hidapi = 'SDL_JOYSTICK_HIDAPI' - -// A variable controlling whether the HIDAPI driver for Nintendo GameCube controllers should be used. -// -// This variable can be set to the following values: -// "0" - HIDAPI driver is not used -// "1" - HIDAPI driver is used -// -// The default is the value of SDL_HINT_JOYSTICK_HIDAPI -pub const hint_joystick_hidapi_gamecube = 'SDL_JOYSTICK_HIDAPI_GAMECUBE' - -// A variable controlling whether "low_frequency_rumble" and "high_frequency_rumble" is used to implement -// the GameCube controller's 3 rumble modes, Stop(0), Rumble(1), and StopHard(2) -// this is useful for applications that need full compatibility for things like ADSR envelopes. -// Stop is implemented by setting "low_frequency_rumble" to "0" and "high_frequency_rumble" ">0" -// Rumble is both at any arbitrary value, -// StopHard is implemented by setting both "low_frequency_rumble" and "high_frequency_rumble" to "0" -// -// This variable can be set to the following values: -// "0" - Normal rumble behavior is behavior is used (default) -// "1" - Proper GameCube controller rumble behavior is used -// -pub const hint_joystick_gamecube_rumble_brake = 'SDL_JOYSTICK_GAMECUBE_RUMBLE_BRAKE' - -// A variable controlling whether the HIDAPI driver for Nintendo Switch Joy-Cons should be used. -// -// This variable can be set to the following values: -// "0" - HIDAPI driver is not used -// "1" - HIDAPI driver is used -// -// The default is the value of SDL_HINT_JOYSTICK_HIDAPI -pub const hint_joystick_hidapi_joy_cons = 'SDL_JOYSTICK_HIDAPI_JOY_CONS' - -// A variable controlling whether Nintendo Switch Joy-Con controllers will be combined into a single Pro-like controller when using the HIDAPI driver -// -// This variable can be set to the following values: -// "0" - Left and right Joy-Con controllers will not be combined and each will be a mini-gamepad -// "1" - Left and right Joy-Con controllers will be combined into a single controller (the default) -pub const hint_joystick_hidapi_combine_joy_cons = 'SDL_JOYSTICK_HIDAPI_COMBINE_JOY_CONS' - -// A variable controlling whether Nintendo Switch Joy-Con controllers will be in vertical mode when using the HIDAPI driver -// -// This variable can be set to the following values: -// "0" - Left and right Joy-Con controllers will not be in vertical mode (the default) -// "1" - Left and right Joy-Con controllers will be in vertical mode -// -// This hint must be set before calling SDL_Init(SDL_INIT_GAMECONTROLLER) -pub const hint_joystick_hidapi_vertical_joy_cons = 'SDL_JOYSTICK_HIDAPI_VERTICAL_JOY_CONS' - -// A variable controlling whether the HIDAPI driver for Amazon Luna controllers connected via Bluetooth should be used. -// -// This variable can be set to the following values: -// "0" - HIDAPI driver is not used -// "1" - HIDAPI driver is used -// -// The default is the value of SDL_HINT_JOYSTICK_HIDAPI -pub const hint_joystick_hidapi_luna = 'SDL_JOYSTICK_HIDAPI_LUNA' - -// A variable controlling whether the HIDAPI driver for Nintendo Online classic controllers should be used. -// -// This variable can be set to the following values: -// "0" - HIDAPI driver is not used -// "1" - HIDAPI driver is used -// -// The default is the value of SDL_HINT_JOYSTICK_HIDAPI -pub const hint_joystick_hidapi_nintendo_classic = 'SDL_JOYSTICK_HIDAPI_NINTENDO_CLASSIC' - -// A variable controlling whether the HIDAPI driver for NVIDIA SHIELD controllers should be used. -// -// This variable can be set to the following values: -// "0" - HIDAPI driver is not used -// "1" - HIDAPI driver is used -// -// The default is the value of SDL_HINT_JOYSTICK_HIDAPI -pub const hint_joystick_hidapi_shield = 'SDL_JOYSTICK_HIDAPI_SHIELD' - -// A variable controlling whether the HIDAPI driver for PS3 controllers should be used. -// -// This variable can be set to the following values: -// "0" - HIDAPI driver is not used -// "1" - HIDAPI driver is used -// -// The default is the value of SDL_HINT_JOYSTICK_HIDAPI on macOS, and "0" on other platforms. -// -// It is not possible to use this driver on Windows, due to limitations in the default drivers -// installed. See https://github.com/ViGEm/DsHidMini for an alternative driver on Windows. -pub const hint_joystick_hidapi_ps3 = 'SDL_JOYSTICK_HIDAPI_PS3' - -// A variable controlling whether the HIDAPI driver for PS4 controllers should be used. -// -// This variable can be set to the following values: -// "0" - HIDAPI driver is not used -// "1" - HIDAPI driver is used -// -// The default is the value of SDL_HINT_JOYSTICK_HIDAPI -pub const hint_joystick_hidapi_ps4 = 'SDL_JOYSTICK_HIDAPI_PS4' - -// A variable controlling whether extended input reports should be used for PS4 controllers when using the HIDAPI driver. -// -// This variable can be set to the following values: -// "0" - extended reports are not enabled (the default) -// "1" - extended reports -// -// Extended input reports allow rumble on Bluetooth PS4 controllers, but -// break DirectInput handling for applications that don't use SDL. -// -// Once extended reports are enabled, they can not be disabled without -// power cycling the controller. -// -// For compatibility with applications written for versions of SDL prior -// to the introduction of PS5 controller support, this value will also -// control the state of extended reports on PS5 controllers when the -// SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE hint is not explicitly set. -pub const hint_joystick_hidapi_ps4_rumble = 'SDL_JOYSTICK_HIDAPI_PS4_RUMBLE' - -// A variable controlling whether the HIDAPI driver for PS5 controllers should be used. -// -// This variable can be set to the following values: -// "0" - HIDAPI driver is not used -// "1" - HIDAPI driver is used -// -// The default is the value of SDL_HINT_JOYSTICK_HIDAPI -pub const hint_joystick_hidapi_ps5 = 'SDL_JOYSTICK_HIDAPI_PS5' - -// A variable controlling whether the player LEDs should be lit to indicate which player is associated with a PS5 controller. -// -// This variable can be set to the following values: -// "0" - player LEDs are not enabled -// "1" - player LEDs are enabled (the default) -pub const hint_joystick_hidapi_ps5_player_led = 'SDL_JOYSTICK_HIDAPI_PS5_PLAYER_LED' - -// A variable controlling whether extended input reports should be used for PS5 controllers when using the HIDAPI driver. -// -// This variable can be set to the following values: -// "0" - extended reports are not enabled (the default) -// "1" - extended reports -// -// Extended input reports allow rumble on Bluetooth PS5 controllers, but -// break DirectInput handling for applications that don't use SDL. -// -// Once extended reports are enabled, they can not be disabled without -// power cycling the controller. -// -// For compatibility with applications written for versions of SDL prior -// to the introduction of PS5 controller support, this value defaults to -// the value of SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE. -pub const hint_joystick_hidapi_ps5_rumble = 'SDL_JOYSTICK_HIDAPI_PS5_RUMBLE' - -// A variable controlling whether the HIDAPI driver for Google Stadia controllers should be used. -// -// This variable can be set to the following values: -// "0" - HIDAPI driver is not used -// "1" - HIDAPI driver is used -// -// The default is the value of SDL_HINT_JOYSTICK_HIDAPI -pub const hint_joystick_hidapi_stadia = 'SDL_JOYSTICK_HIDAPI_STADIA' - -// A variable controlling whether the HIDAPI driver for Bluetooth Steam Controllers should be used. -// -// This variable can be set to the following values: -// "0" - HIDAPI driver is not used -// "1" - HIDAPI driver is used for Steam Controllers, which requires Bluetooth access -// and may prompt the user for permission on iOS and Android. -// -// The default is "0" -pub const hint_joystick_hidapi_steam = 'SDL_JOYSTICK_HIDAPI_STEAM' - -// A variable controlling whether the HIDAPI driver for the Steam Deck builtin controller should be used. -// -// This variable can be set to the following values: -// "0" - HIDAPI driver is not used -// "1" - HIDAPI driver is used -// -// The default is the value of SDL_HINT_JOYSTICK_HIDAPI -pub const hint_joystick_hidapi_steamdeck = 'SDL_JOYSTICK_HIDAPI_STEAMDECK' - -// A variable controlling whether the HIDAPI driver for Nintendo Switch controllers should be used. -// -// This variable can be set to the following values: -// "0" - HIDAPI driver is not used -// "1" - HIDAPI driver is used -// -// The default is the value of SDL_HINT_JOYSTICK_HIDAPI -pub const hint_joystick_hidapi_switch = 'SDL_JOYSTICK_HIDAPI_SWITCH' - -// A variable controlling whether the Home button LED should be turned on when a Nintendo Switch Pro controller is opened -// -// This variable can be set to the following values: -// "0" - home button LED is turned off -// "1" - home button LED is turned on -// -// By default the Home button LED state is not changed. This hint can also be set to a floating point value between 0.0 and 1.0 which controls the brightness of the Home button LED. -pub const hint_joystick_hidapi_switch_home_led = 'SDL_JOYSTICK_HIDAPI_SWITCH_HOME_LED' - -// A variable controlling whether the Home button LED should be turned on when a Nintendo Switch Joy-Con controller is opened -// -// This variable can be set to the following values: -// "0" - home button LED is turned off -// "1" - home button LED is turned on -// -// By default the Home button LED state is not changed. This hint can also be set to a floating point value between 0.0 and 1.0 which controls the brightness of the Home button LED. -pub const hint_joystick_hidapi_joycon_home_led = 'SDL_JOYSTICK_HIDAPI_JOYCON_HOME_LED' - -// A variable controlling whether the player LEDs should be lit to indicate which player is associated with a Nintendo Switch controller. -// -// This variable can be set to the following values: -// "0" - player LEDs are not enabled -// "1" - player LEDs are enabled (the default) -pub const hint_joystick_hidapi_switch_player_led = 'SDL_JOYSTICK_HIDAPI_SWITCH_PLAYER_LED' - -// A variable controlling whether the HIDAPI driver for Nintendo Wii and Wii U controllers should be used. -// -// This variable can be set to the following values: -// "0" - HIDAPI driver is not used -// "1" - HIDAPI driver is used -// -// This driver doesn't work with the dolphinbar, so the default is SDL_FALSE for now. -pub const hint_joystick_hidapi_wii = 'SDL_JOYSTICK_HIDAPI_WII' - -// A variable controlling whether the player LEDs should be lit to indicate which player is associated with a Wii controller. -// -// This variable can be set to the following values: -// "0" - player LEDs are not enabled -// "1" - player LEDs are enabled (the default) -pub const hint_joystick_hidapi_wii_player_led = 'SDL_JOYSTICK_HIDAPI_WII_PLAYER_LED' - -// A variable controlling whether the HIDAPI driver for XBox controllers should be used. -// -// This variable can be set to the following values: -// "0" - HIDAPI driver is not used -// "1" - HIDAPI driver is used -// -// The default is "0" on Windows, otherwise the value of SDL_HINT_JOYSTICK_HIDAPI -pub const hint_joystick_hidapi_xbox = 'SDL_JOYSTICK_HIDAPI_XBOX' - -// A variable controlling whether the HIDAPI driver for XBox 360 controllers should be used. -// -// This variable can be set to the following values: -// "0" - HIDAPI driver is not used -// "1" - HIDAPI driver is used -// -// The default is the value of SDL_HINT_JOYSTICK_HIDAPI_XBOX -pub const hint_joystick_hidapi_xbox_360 = 'SDL_JOYSTICK_HIDAPI_XBOX_360' - -// A variable controlling whether the player LEDs should be lit to indicate which player is associated with an Xbox 360 controller. -// -// This variable can be set to the following values: -// "0" - player LEDs are not enabled -// "1" - player LEDs are enabled (the default) -pub const hint_joystick_hidapi_xbox_360_player_led = 'SDL_JOYSTICK_HIDAPI_XBOX_360_PLAYER_LED' - -// A variable controlling whether the HIDAPI driver for XBox 360 wireless controllers should be used. -// -// This variable can be set to the following values: -// "0" - HIDAPI driver is not used -// "1" - HIDAPI driver is used -// -// The default is the value of SDL_HINT_JOYSTICK_HIDAPI_XBOX_360 -pub const hint_joystick_hidapi_xbox_360_wireless = 'SDL_JOYSTICK_HIDAPI_XBOX_360_WIRELESS' - -// A variable controlling whether the HIDAPI driver for XBox One controllers should be used. -// -// This variable can be set to the following values: -// "0" - HIDAPI driver is not used -// "1" - HIDAPI driver is used -// -// The default is the value of SDL_HINT_JOYSTICK_HIDAPI_XBOX -pub const hint_joystick_hidapi_xbox_one = 'SDL_JOYSTICK_HIDAPI_XBOX_ONE' - -// A variable controlling whether the Home button LED should be turned on when an Xbox One controller is opened -// -// This variable can be set to the following values: -// "0" - home button LED is turned off -// "1" - home button LED is turned on -// -// By default the Home button LED state is not changed. This hint can also be set to a floating point value between 0.0 and 1.0 which controls the brightness of the Home button LED. The default brightness is 0.4. -pub const hint_joystick_hidapi_xbox_one_home_led = 'SDL_JOYSTICK_HIDAPI_XBOX_ONE_HOME_LED' - -// A variable controlling whether IOKit should be used for controller handling. -// -// This variable can be set to the following values: -// "0" - IOKit is not used -// "1" - IOKit is used (the default) -pub const hint_joystick_iokit = 'SDL_JOYSTICK_IOKIT' - -// A variable controlling whether GCController should be used for controller handling. -// -// This variable can be set to the following values: -// "0" - GCController is not used -// "1" - GCController is used (the default) -pub const hint_joystick_mfi = 'SDL_JOYSTICK_MFI' - -// A variable controlling whether the RAWINPUT joystick drivers should be used for better handling XInput-capable devices. -// -// This variable can be set to the following values: -// "0" - RAWINPUT drivers are not used -// "1" - RAWINPUT drivers are used (the default) -// -pub const hint_joystick_rawinput = 'SDL_JOYSTICK_RAWINPUT' - -// A variable controlling whether the RAWINPUT driver should pull correlated data from XInput. -// -// This variable can be set to the following values: -// "0" - RAWINPUT driver will only use data from raw input APIs -// "1" - RAWINPUT driver will also pull data from XInput, providing -// better trigger axes, guide button presses, and rumble support -// for Xbox controllers -// -// The default is "1". This hint applies to any joysticks opened after setting the hint. -pub const hint_joystick_rawinput_correlate_xinput = 'SDL_JOYSTICK_RAWINPUT_CORRELATE_XINPUT' - -// A variable controlling whether the ROG Chakram mice should show up as joysticks -// -// This variable can be set to the following values: -// "0" - ROG Chakram mice do not show up as joysticks (the default) -// "1" - ROG Chakram mice show up as joysticks -pub const hint_joystick_rog_chakram = 'SDL_JOYSTICK_ROG_CHAKRAM' - -// A variable controlling whether a separate thread should be used -// for handling joystick detection and raw input messages on Windows -// -// This variable can be set to the following values: -// "0" - A separate thread is not used (the default) -// "1" - A separate thread is used for handling raw input messages -// -pub const hint_joystick_thread = 'SDL_JOYSTICK_THREAD' - -// A variable containing a list of throttle style controllers. -// -// The format of the string is a comma separated list of USB VID/PID pairs -// in hexadecimal form, e.g. -// -// 0xAAAA/0xBBBB,0xCCCC/0xDDDD -// -// The variable can also take the form of @file, in which case the named -// file will be loaded and interpreted as the value of the variable. -pub const hint_joystick_throttle_devices = 'SDL_JOYSTICK_THROTTLE_DEVICES' - -// A variable containing a list of devices that are not throttle style controllers. This will override SDL_HINT_JOYSTICK_THROTTLE_DEVICES and the built in device list. -// -// The format of the string is a comma separated list of USB VID/PID pairs -// in hexadecimal form, e.g. -// -// 0xAAAA/0xBBBB,0xCCCC/0xDDDD -// -// The variable can also take the form of @file, in which case the named -// file will be loaded and interpreted as the value of the variable. -pub const hint_joystick_throttle_devices_excluded = 'SDL_JOYSTICK_THROTTLE_DEVICES_EXCLUDED' - -// A variable controlling whether Windows.Gaming.Input should be used for controller handling. -// -// This variable can be set to the following values: -// "0" - WGI is not used -// "1" - WGI is used (the default) -pub const hint_joystick_wgi = 'SDL_JOYSTICK_WGI' - -// A variable containing a list of wheel style controllers. -// -// The format of the string is a comma separated list of USB VID/PID pairs -// in hexadecimal form, e.g. -// -// 0xAAAA/0xBBBB,0xCCCC/0xDDDD -// -// The variable can also take the form of @file, in which case the named -// file will be loaded and interpreted as the value of the variable. -pub const hint_joystick_wheel_devices = 'SDL_JOYSTICK_WHEEL_DEVICES' - -// A variable containing a list of devices that are not wheel style controllers. This will override SDL_HINT_JOYSTICK_WHEEL_DEVICES and the built in device list. -// -// The format of the string is a comma separated list of USB VID/PID pairs -// in hexadecimal form, e.g. -// -// 0xAAAA/0xBBBB,0xCCCC/0xDDDD -// -// The variable can also take the form of @file, in which case the named -// file will be loaded and interpreted as the value of the variable. -pub const hint_joystick_wheel_devices_excluded = 'SDL_JOYSTICK_WHEEL_DEVICES_EXCLUDED' - -// A variable containing a list of devices known to have all axes centered at zero. -// -// The format of the string is a comma separated list of USB VID/PID pairs -// in hexadecimal form, e.g. -// -// 0xAAAA/0xBBBB,0xCCCC/0xDDDD -// -// The variable can also take the form of @file, in which case the named -// file will be loaded and interpreted as the value of the variable. -pub const hint_joystick_zero_centered_devices = 'SDL_JOYSTICK_ZERO_CENTERED_DEVICES' - -// Determines whether SDL enforces that DRM master is required in order -// to initialize the KMSDRM video backend. -// -// The DRM subsystem has a concept of a "DRM master" which is a DRM client that -// has the ability to set planes, set cursor, etc. When SDL is DRM master, it -// can draw to the screen using the SDL rendering APIs. Without DRM master, SDL -// is still able to process input and query attributes of attached displays, -// but it cannot change display state or draw to the screen directly. -// -// In some cases, it can be useful to have the KMSDRM backend even if it cannot -// be used for rendering. An app may want to use SDL for input processing while -// using another rendering API (such as an MMAL overlay on Raspberry Pi) or -// using its own code to render to DRM overlays that SDL doesn't support. -// -// This hint must be set before initializing the video subsystem. -// -// This variable can be set to the following values: -// "0" - SDL will allow usage of the KMSDRM backend without DRM master -// "1" - SDL Will require DRM master to use the KMSDRM backend (default) -pub const hint_kmsdrm_require_drm_master = 'SDL_KMSDRM_REQUIRE_DRM_MASTER' - -// A comma separated list of devices to open as joysticks -// -// This variable is currently only used by the Linux joystick driver. -pub const hint_joystick_device = 'SDL_JOYSTICK_DEVICE' - -// A variable controlling whether joysticks on Linux will always treat 'hat' axis inputs (ABS_HAT0X - ABS_HAT3Y) as 8-way digital hats without checking whether they may be analog. -// -// This variable can be set to the following values: -// "0" - Only map hat axis inputs to digital hat outputs if the input axes appear to actually be digital (the default) -// "1" - Always handle the input axes numbered ABS_HAT0X to ABS_HAT3Y as digital hats -pub const hint_linux_digital_hats = 'SDL_LINUX_DIGITAL_HATS' - -// A variable controlling whether digital hats on Linux will apply deadzones to their underlying input axes or use unfiltered values. -// -// This variable can be set to the following values: -// "0" - Return digital hat values based on unfiltered input axis values -// "1" - Return digital hat values with deadzones on the input axes taken into account (the default) -// -pub const hint_linux_hat_deadzones = 'SDL_LINUX_HAT_DEADZONES' - -// A variable controlling whether to use the classic /dev/input/js* joystick interface or the newer /dev/input/event* joystick interface on Linux -// -// This variable can be set to the following values: -// "0" - Use /dev/input/event* -// "1" - Use /dev/input/js* -// -// By default the /dev/input/event* interfaces are used -pub const hint_linux_joystick_classic = 'SDL_LINUX_JOYSTICK_CLASSIC' - -// A variable controlling whether joysticks on Linux adhere to their HID-defined deadzones or return unfiltered values. -// -// This variable can be set to the following values: -// "0" - Return unfiltered joystick axis values (the default) -// "1" - Return axis values with deadzones taken into account -pub const hint_linux_joystick_deadzones = 'SDL_LINUX_JOYSTICK_DEADZONES' - -// A variable controlling the default SDL log levels. -// -// This variable is a comma separated set of category=level tokens that define the default logging levels for SDL applications. -// -// The category can be a numeric category, one of "app", "error", "assert", "system", "audio", "video", "render", "input", "test", or `*` for any unspecified category. -// -// The level can be a numeric level, one of "verbose", "debug", "info", "warn", "error", "critical", or "quiet" to disable that category. -// -// You can omit the category if you want to set the logging level for all categories. -// -// If this hint isn't set, the default log levels are equivalent to: -// "app=info,assert=warn,test=verbose,*=error" -pub const hint_logging = 'SDL_LOGGING' - -// When set don't force the SDL app to become a foreground process -// -// This hint only applies to Mac OS X. -// -pub const hint_mac_background_app = 'SDL_MAC_BACKGROUND_APP' - -// A variable that determines whether ctrl+click should generate a right-click event on Mac -// -// If present, holding ctrl while left clicking will generate a right click -// event when on Mac. -pub const hint_mac_ctrl_click_emulate_right_click = 'SDL_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK' - -// A variable controlling whether dispatching OpenGL context updates should block the dispatching thread until the main thread finishes processing -// -// This variable can be set to the following values: -// "0" - Dispatching OpenGL context updates will block the dispatching thread until the main thread finishes processing (default). -// "1" - Dispatching OpenGL context updates will allow the dispatching thread to continue execution. -// -// Generally you want the default, but if you have OpenGL code in a background thread on a Mac, and the main thread -// hangs because it's waiting for that background thread, but that background thread is also hanging because it's -// waiting for the main thread to do an update, this might fix your issue. -// -// This hint only applies to macOS. -// -// This hint is available since SDL 2.24.0. -pub const hint_mac_opengl_async_dispatch = 'SDL_MAC_OPENGL_ASYNC_DISPATCH' - -// A variable setting the double click radius, in pixels. -pub const hint_mouse_double_click_radius = 'SDL_MOUSE_DOUBLE_CLICK_RADIUS' - -// A variable setting the double click time, in milliseconds. -pub const hint_mouse_double_click_time = 'SDL_MOUSE_DOUBLE_CLICK_TIME' - -// Allow mouse click events when clicking to focus an SDL window -// -// This variable can be set to the following values: -// "0" - Ignore mouse clicks that activate a window -// "1" - Generate events for mouse clicks that activate a window -// -// By default SDL will ignore mouse clicks that activate a window -pub const hint_mouse_focus_clickthrough = 'SDL_MOUSE_FOCUS_CLICKTHROUGH' - -// A variable setting the speed scale for mouse motion, in floating point, when the mouse is not in relative mode -pub const hint_mouse_normal_speed_scale = 'SDL_MOUSE_NORMAL_SPEED_SCALE' - -// A variable controlling whether relative mouse mode constrains the mouse to the center of the window -// -// This variable can be set to the following values: -// "0" - Relative mouse mode constrains the mouse to the window -// "1" - Relative mouse mode constrains the mouse to the center of the window -// -// Constraining to the center of the window works better for FPS games and when the -// application is running over RDP. Constraining to the whole window works better -// for 2D games and increases the chance that the mouse will be in the correct -// position when using high DPI mice. -// -// By default SDL will constrain the mouse to the center of the window -pub const hint_mouse_relative_mode_center = 'SDL_MOUSE_RELATIVE_MODE_CENTER' - -// A variable controlling whether relative mouse mode is implemented using mouse warping -// -// This variable can be set to the following values: -// "0" - Relative mouse mode uses raw input -// "1" - Relative mouse mode uses mouse warping -// -// By default SDL will use raw input for relative mouse mode -pub const hint_mouse_relative_mode_warp = 'SDL_MOUSE_RELATIVE_MODE_WARP' - -// A variable controlling whether relative mouse motion is affected by renderer scaling -// -// This variable can be set to the following values: -// "0" - Relative motion is unaffected by DPI or renderer's logical size -// "1" - Relative motion is scaled according to DPI scaling and logical size -// -// By default relative mouse deltas are affected by DPI and renderer scaling -pub const hint_mouse_relative_scaling = 'SDL_MOUSE_RELATIVE_SCALING' - -// A variable setting the scale for mouse motion, in floating point, when the mouse is in relative mode -pub const hint_mouse_relative_speed_scale = 'SDL_MOUSE_RELATIVE_SPEED_SCALE' - -// A variable controlling whether the system mouse acceleration curve is used for relative mouse motion. -// -// This variable can be set to the following values: -// "0" - Relative mouse motion will be unscaled (the default) -// "1" - Relative mouse motion will be scaled using the system mouse acceleration curve. -// -// If SDL_HINT_MOUSE_RELATIVE_SPEED_SCALE is set, that will override the system speed scale. -pub const hint_mouse_relative_system_scale = 'SDL_MOUSE_RELATIVE_SYSTEM_SCALE' - -// A variable controlling whether a motion event should be generated for mouse warping in relative mode. -// -// This variable can be set to the following values: -// "0" - Warping the mouse will not generate a motion event in relative mode -// "1" - Warping the mouse will generate a motion event in relative mode -// -// By default warping the mouse will not generate motion events in relative mode. This avoids the application having to filter out large relative motion due to warping. -pub const hint_mouse_relative_warp_motion = 'SDL_MOUSE_RELATIVE_WARP_MOTION' - -// A variable controlling whether mouse events should generate synthetic touch events -// -// This variable can be set to the following values: -// "0" - Mouse events will not generate touch events (default for desktop platforms) -// "1" - Mouse events will generate touch events (default for mobile platforms, such as Android and iOS) -pub const hint_mouse_touch_events = 'SDL_MOUSE_TOUCH_EVENTS' - -// A variable controlling whether the mouse is captured while mouse buttons are pressed -// -// This variable can be set to the following values: -// "0" - The mouse is not captured while mouse buttons are pressed -// "1" - The mouse is captured while mouse buttons are pressed -// -// By default the mouse is captured while mouse buttons are pressed so if the mouse is dragged -// outside the window, the application continues to receive mouse events until the button is -// released. -pub const hint_mouse_auto_capture = 'SDL_MOUSE_AUTO_CAPTURE' - -// Tell SDL not to catch the SIGINT or SIGTERM signals. -// -// This hint only applies to Unix-like platforms, and should set before -// any calls to SDL_Init() -// -// The variable can be set to the following values: -// "0" - SDL will install a SIGINT and SIGTERM handler, and when it -// catches a signal, convert it into an SDL_QUIT event. -// "1" - SDL will not install a signal handler at all. -pub const hint_no_signal_handlers = 'SDL_NO_SIGNAL_HANDLERS' - -// A variable controlling what driver to use for OpenGL ES contexts. -// -// On some platforms, currently Windows and X11, OpenGL drivers may support -// creating contexts with an OpenGL ES profile. By default SDL uses these -// profiles, when available, otherwise it attempts to load an OpenGL ES -// library, e.g. that provided by the ANGLE project. This variable controls -// whether SDL follows this default behaviour or will always load an -// OpenGL ES library. -// -// Circumstances where this is useful include -// - Testing an app with a particular OpenGL ES implementation, e.g ANGLE, -// or emulator, e.g. those from ARM, Imagination or Qualcomm. -// - Resolving OpenGL ES function addresses at link time by linking with -// the OpenGL ES library instead of querying them at run time with -// SDL_GL_GetProcAddress(). -// -// Caution: for an application to work with the default behaviour across -// different OpenGL drivers it must query the OpenGL ES function -// addresses at run time using SDL_GL_GetProcAddress(). -// -// This variable is ignored on most platforms because OpenGL ES is native -// or not supported. +// A variable controlling how 3D acceleration is used to accelerate the SDL screen surface. // -// This variable can be set to the following values: -// "0" - Use ES profile of OpenGL, if available. (Default when not set.) -// "1" - Load OpenGL ES library using the default library names. -// -pub const hint_opengl_es_driver = 'SDL_OPENGL_ES_DRIVER' - -// A variable controlling which orientations are allowed on iOS/Android. -// -// In some circumstances it is necessary to be able to explicitly control -// which UI orientations are allowed. -// -// This variable is a space delimited list of the following values: -// "LandscapeLeft", "LandscapeRight", "Portrait" "PortraitUpsideDown" -pub const hint_orientations = 'SDL_IOS_ORIENTATIONS' - -// A variable controlling the use of a sentinel event when polling the event queue +// SDL can try to accelerate the SDL screen surface by using streaming +// textures with a 3D rendering engine. This variable controls whether and +// how this is done. // // This variable can be set to the following values: -// "0" - Disable poll sentinels -// "1" - Enable poll sentinels -// -// When polling for events, SDL_PumpEvents is used to gather new events from devices. -// If a device keeps producing new events between calls to SDL_PumpEvents, a poll loop will -// become stuck until the new events stop. -// This is most noticeable when moving a high frequency mouse. -// -// By default, poll sentinels are enabled. -pub const hint_poll_sentinel = 'SDL_POLL_SENTINEL' - -// Override for SDL_GetPreferredLocales() -// -// If set, this will be favored over anything the OS might report for the -// user's preferred locales. Changing this hint at runtime will not generate -// a SDL_LOCALECHANGED event (but if you can change the hint, you can push -// your own event, if you want). +// "0" - Disable 3D acceleration +// "1" - Enable 3D acceleration, using the default renderer. +// "X" - Enable 3D acceleration, using X where X is one of the valid rendering drivers. (e.g. "direct3d", "opengl", etc.) // -// The format of this hint is a comma-separated list of language and locale, -// combined with an underscore, as is a common format: "en_GB". Locale is -// optional: "en". So you might have a list like this: "en_GB,jp,es_PT" -pub const hint_preferred_locales = 'SDL_PREFERRED_LOCALES' +// By default SDL tries to make a best guess for each platform whether +// to use acceleration or not. +pub const hint_framebuffer_acceleration = 'SDL_FRAMEBUFFER_ACCELERATION' -// A variable describing the content orientation on QtWayland-based platforms. -// -// On QtWayland platforms, windows are rotated client-side to allow for custom -// transitions. In order to correctly position overlays (e.g. volume bar) and -// gestures (e.g. events view, close/minimize gestures), the system needs to -// know in which orientation the application is currently drawing its contents. +// A variable specifying which render driver to use. // -// This does not cause the window to be rotated or resized, the application -// needs to take care of drawing the content in the right orientation (the -// framebuffer is always in portrait mode). -// -// This variable can be one of the following values: -// "primary" (default), "portrait", "landscape", "inverted-portrait", "inverted-landscape" -// -// Since SDL 2.0.22 this variable accepts a comma-separated list of values above. -pub const hint_qtwayland_content_orientation = 'SDL_QTWAYLAND_CONTENT_ORIENTATION' - -// Flags to set on QtWayland windows to integrate with the native window manager. +// If the application doesn't pick a specific renderer to use, this variable +// specifies the name of the preferred renderer. If the preferred renderer +// can't be initialized, the normal default renderer is used. // -// On QtWayland platforms, this hint controls the flags to set on the windows. -// For example, on Sailfish OS "OverridesSystemGestures" disables swipe gestures. +// This variable is case insensitive and can be set to the following values: +// "direct3d" +// "opengl" +// "opengles2" +// "opengles" +// "metal" +// "software" // -// This variable is a space-separated list of the following values (empty = no flags): -// "OverridesSystemGestures", "StaysOnTop", "BypassWindowManager" -pub const hint_qtwayland_window_flags = 'SDL_QTWAYLAND_WINDOW_FLAGS' +// The default varies by platform, but it's the first one in the list that +// is available on the current platform. +pub const hint_render_driver = 'SDL_RENDER_DRIVER' -// A variable controlling whether the 2D render API is compatible or efficient. +// A variable controlling whether the OpenGL render driver uses shaders if they are available. // // This variable can be set to the following values: +// "0" - Disable shaders +// "1" - Enable shaders // -// "0" - Don't use batching to make rendering more efficient. -// "1" - Use batching, but might cause problems if app makes its own direct OpenGL calls. -// -// Up to SDL 2.0.9, the render API would draw immediately when requested. Now -// it batches up draw requests and sends them all to the GPU only when forced -// to (during SDL_RenderPresent, when changing render targets, by updating a -// texture that the batch needs, etc). This is significantly more efficient, -// but it can cause problems for apps that expect to render on top of the -// render API's output. As such, SDL will disable batching if a specific -// render backend is requested (since this might indicate that the app is -// planning to use the underlying graphics API directly). This hint can -// be used to explicitly request batching in this instance. It is a contract -// that you will either never use the underlying graphics API directly, or -// if you do, you will call SDL_RenderFlush() before you do so any current -// batch goes to the GPU before your work begins. Not following this contract -// will result in undefined behavior. -pub const hint_render_batching = 'SDL_RENDER_BATCHING' - -// A variable controlling how the 2D render API renders lines +// By default shaders are used if OpenGL supports them. +pub const hint_render_opengl_shaders = 'SDL_RENDER_OPENGL_SHADERS' + +// A variable controlling whether the Direct3D device is initialized for thread-safe operations. // // This variable can be set to the following values: -// "0" - Use the default line drawing method (Bresenham's line algorithm as of SDL 2.0.20) -// "1" - Use the driver point API using Bresenham's line algorithm (correct, draws many points) -// "2" - Use the driver line API (occasionally misses line endpoints based on hardware driver quirks, was the default before 2.0.20) -// "3" - Use the driver geometry API (correct, draws thicker diagonal lines) +// "0" - Thread-safety is not enabled (faster) +// "1" - Thread-safety is enabled // -// This variable should be set when the renderer is created. -pub const hint_render_line_method = 'SDL_RENDER_LINE_METHOD' +// By default the Direct3D device is created with thread-safety disabled. +pub const hint_render_direct3d_threadsafe = 'SDL_RENDER_DIRECT3D_THREADSAFE' -// A variable controlling whether to enable Direct3D 11+'s Debug Layer. +// A variable controlling whether to enable Direct3D 11+'s Debug Layer. // // This variable does not have any effect on the Direct3D 9 based renderer. // @@ -1322,36 +68,7 @@ pub const hint_render_line_method = 'SDL_RENDER_LINE_METHOD' // By default, SDL does not use Direct3D Debug Layer. pub const hint_render_direct3d11_debug = 'SDL_RENDER_DIRECT3D11_DEBUG' -// A variable controlling whether the Direct3D device is initialized for thread-safe operations. -// -// This variable can be set to the following values: -// "0" - Thread-safety is not enabled (faster) -// "1" - Thread-safety is enabled -// -// By default the Direct3D device is created with thread-safety disabled. -pub const hint_render_direct3d_threadsafe = 'SDL_RENDER_DIRECT3D_THREADSAFE' - -// A variable specifying which render driver to use. -// -// If the application doesn't pick a specific renderer to use, this variable -// specifies the name of the preferred renderer. If the preferred renderer -// can't be initialized, the normal default renderer is used. -// -// This variable is case insensitive and can be set to the following values: -// "direct3d" -// "direct3d11" -// "direct3d12" -// "opengl" -// "opengles2" -// "opengles" -// "metal" -// "software" -// -// The default varies by platform, but it's the first one in the list that -// is available on the current platform. -pub const hint_render_driver = 'SDL_RENDER_DRIVER' - -// A variable controlling the scaling policy for SDL_RenderSetLogicalSize. +// A variable controlling the scaling policy for SDL_RenderSetLogicalSize. // // This variable can be set to the following values: // "0" or "letterbox" - Uses letterbox/sidebars to fit the entire rendering on screen @@ -1360,16 +77,7 @@ pub const hint_render_driver = 'SDL_RENDER_DRIVER' // By default letterbox is used pub const hint_render_logical_size_mode = 'SDL_RENDER_LOGICAL_SIZE_MODE' -// A variable controlling whether the OpenGL render driver uses shaders if they are available. -// -// This variable can be set to the following values: -// "0" - Disable shaders -// "1" - Enable shaders -// -// By default shaders are used if OpenGL supports them. -pub const hint_render_opengl_shaders = 'SDL_RENDER_OPENGL_SHADERS' - -// A variable controlling the scaling quality +// A variable controlling the scaling quality // // This variable can be set to the following values: // "0" or "nearest" - Nearest pixel sampling @@ -1379,7 +87,7 @@ pub const hint_render_opengl_shaders = 'SDL_RENDER_OPENGL_SHADERS' // By default nearest pixel sampling is used pub const hint_render_scale_quality = 'SDL_RENDER_SCALE_QUALITY' -// A variable controlling whether updates to the SDL screen surface should be synchronized with the vertical refresh, to avoid tearing. +// A variable controlling whether updates to the SDL screen surface should be synchronized with the vertical refresh, to avoid tearing. // // This variable can be set to the following values: // "0" - Disable vsync @@ -1388,614 +96,397 @@ pub const hint_render_scale_quality = 'SDL_RENDER_SCALE_QUALITY' // By default SDL does not sync screen surface updates with vertical refresh. pub const hint_render_vsync = 'SDL_RENDER_VSYNC' -// A variable controlling whether the Metal render driver select low power device over default one +// A variable controlling whether the screensaver is enabled. // // This variable can be set to the following values: -// "0" - Use the prefered OS device -// "1" - Select a low power one -// -// By default the prefered OS device is used. -pub const hint_render_metal_prefer_low_power_device = 'SDL_RENDER_METAL_PREFER_LOW_POWER_DEVICE' - -// A variable containing a list of ROG gamepad capable mice. -// -// The format of the string is a comma separated list of USB VID/PID pairs -// in hexadecimal form, e.g. -// -// 0xAAAA/0xBBBB,0xCCCC/0xDDDD -// -// The variable can also take the form of @file, in which case the named -// file will be loaded and interpreted as the value of the variable. -pub const hint_rog_gamepad_mice = 'SDL_ROG_GAMEPAD_MICE' - -// A variable containing a list of devices that are not ROG gamepad capable mice. This will override SDL_HINT_ROG_GAMEPAD_MICE and the built in device list. -// -// The format of the string is a comma separated list of USB VID/PID pairs -// in hexadecimal form, e.g. -// -// 0xAAAA/0xBBBB,0xCCCC/0xDDDD +// "0" - Disable screensaver +// "1" - Enable screensaver // -// The variable can also take the form of @file, in which case the named -// file will be loaded and interpreted as the value of the variable. -pub const hint_rog_gamepad_mice_excluded = 'SDL_ROG_GAMEPAD_MICE_EXCLUDED' +// By default SDL will disable the screensaver. +pub const hint_video_allow_screensaver = 'SDL_VIDEO_ALLOW_SCREENSAVER' -// A variable controlling if VSYNC is automatically disable if doesn't reach the enough FPS +// A variable controlling whether the X11 VidMode extension should be used. // // This variable can be set to the following values: -// "0" - It will be using VSYNC as defined in the main flag. Default -// "1" - If VSYNC was previously enabled, then it will disable VSYNC if doesn't reach enough speed -// -// By default SDL does not enable the automatic VSYNC -pub const hint_ps2_dynamic_vsync = 'SDL_PS2_DYNAMIC_VSYNC' - -// A variable to control whether the return key on the soft keyboard -// should hide the soft keyboard on Android and iOS. -// -// The variable can be set to the following values: -// "0" - The return key will be handled as a key event. This is the behaviour of SDL <= 2.0.3. (default) -// "1" - The return key will hide the keyboard. -// -// The value of this hint is used at runtime, so it can be changed at any time. -pub const hint_return_key_hides_ime = 'SDL_RETURN_KEY_HIDES_IME' - -// Tell SDL which Dispmanx layer to use on a Raspberry PI -// -// Also known as Z-order. The variable can take a negative or positive value. -// The default is 10000. -pub const hint_rpi_video_layer = 'SDL_RPI_VIDEO_LAYER' - -// Specify an "activity name" for screensaver inhibition. -// -// Some platforms, notably Linux desktops, list the applications which are -// inhibiting the screensaver or other power-saving features. +// "0" - Disable XVidMode +// "1" - Enable XVidMode // -// This hint lets you specify the "activity name" sent to the OS when -// SDL_DisableScreenSaver() is used (or the screensaver is automatically -// disabled). The contents of this hint are used when the screensaver is -// disabled. You should use a string that describes what your program is doing -// (and, therefore, why the screensaver is disabled). For example, "Playing a -// game" or "Watching a video". -// -// Setting this to "" or leaving it unset will have SDL use a reasonable -// default: "Playing a game" or something similar. -// -// On targets where this is not supported, this hint does nothing. -pub const hint_screensaver_inhibit_activity_name = 'SDL_SCREENSAVER_INHIBIT_ACTIVITY_NAME' +// By default SDL will use XVidMode if it is available. +pub const hint_video_x11_xvidmode = 'SDL_VIDEO_X11_XVIDMODE' -// Specifies whether SDL_THREAD_PRIORITY_TIME_CRITICAL should be treated as realtime. -// -// On some platforms, like Linux, a realtime priority thread may be subject to restrictions -// that require special handling by the application. This hint exists to let SDL know that -// the app is prepared to handle said restrictions. -// -// On Linux, SDL will apply the following configuration to any thread that becomes realtime: -// * The SCHED_RESET_ON_FORK bit will be set on the scheduling policy, -// * An RLIMIT_RTTIME budget will be configured to the rtkit specified limit. -// * Exceeding this limit will result in the kernel sending SIGKILL to the app, -// * Refer to the man pages for more information. +// A variable controlling whether the X11 Xinerama extension should be used. // // This variable can be set to the following values: -// "0" - default platform specific behaviour -// "1" - Force SDL_THREAD_PRIORITY_TIME_CRITICAL to a realtime scheduling policy -pub const hint_thread_force_realtime_time_critical = 'SDL_THREAD_FORCE_REALTIME_TIME_CRITICAL' - -// A string specifying additional information to use with SDL_SetThreadPriority. -// -// By default SDL_SetThreadPriority will make appropriate system changes in order to -// apply a thread priority. For example on systems using pthreads the scheduler policy -// is changed automatically to a policy that works well with a given priority. -// Code which has specific requirements can override SDL's default behavior with this hint. -// -// pthread hint values are "current", "other", "fifo" and "rr". -// Currently no other platform hint values are defined but may be in the future. -// -// NOTE On Linux, the kernel may send SIGKILL to realtime tasks which exceed the distro -// configured execution budget for rtkit. This budget can be queried through RLIMIT_RTTIME -// after calling SDL_SetThreadPriority(). -pub const hint_thread_priority_policy = 'SDL_THREAD_PRIORITY_POLICY' - -// A string specifying SDL's threads stack size in bytes or "0" for the backend's default size -// -// Use this hint in case you need to set SDL's threads stack size to other than the default. -// This is specially useful if you build SDL against a non glibc libc library (such as musl) which -// provides a relatively small default thread stack size (a few kilobytes versus the default 8MB glibc uses). -// Support for this hint is currently available only in the pthread, Windows, and PSP backend. -// -// Instead of this hint, in 2.0.9 and later, you can use -// SDL_CreateThreadWithStackSize(). This hint only works with the classic -// SDL_CreateThread(). -pub const hint_thread_stack_size = 'SDL_THREAD_STACK_SIZE' - -// A variable that controls the timer resolution, in milliseconds. -// -// The higher resolution the timer, the more frequently the CPU services -// timer interrupts, and the more precise delays are, but this takes up -// power and CPU time. This hint is only used on Windows. -// -// See this blog post for more information: -// http://randomascii.wordpress.com/2013/07/08/windows-timer-resolution-megawatts-wasted/ -// -// If this variable is set to "0", the system timer resolution is not set. +// "0" - Disable Xinerama +// "1" - Enable Xinerama // -// The default value is "1". This hint may be set at any time. -pub const hint_timer_resolution = 'SDL_TIMER_RESOLUTION' +// By default SDL will use Xinerama if it is available. +pub const hint_video_x11_xinerama = 'SDL_VIDEO_X11_XINERAMA' -// A variable controlling whether touch events should generate synthetic mouse events +// A variable controlling whether the X11 XRandR extension should be used. // // This variable can be set to the following values: -// "0" - Touch events will not generate mouse events -// "1" - Touch events will generate mouse events +// "0" - Disable XRandR +// "1" - Enable XRandR // -// By default SDL will generate mouse events for touch events -pub const hint_touch_mouse_events = 'SDL_TOUCH_MOUSE_EVENTS' +// By default SDL will not use XRandR because of window manager issues. +pub const hint_video_x11_xrandr = 'SDL_VIDEO_X11_XRANDR' -// A variable controlling which touchpad should generate synthetic mouse events +// A variable controlling whether the X11 _NET_WM_PING protocol should be supported. // // This variable can be set to the following values: -// "0" - Only front touchpad should generate mouse events. Default -// "1" - Only back touchpad should generate mouse events. -// "2" - Both touchpads should generate mouse events. -// -// By default SDL will generate mouse events for all touch devices -pub const hint_vita_touch_mouse_device = 'SDL_HINT_VITA_TOUCH_MOUSE_DEVICE' - -// A variable controlling whether the Android / tvOS remotes -// should be listed as joystick devices, instead of sending keyboard events. +// "0" - Disable _NET_WM_PING +// "1" - Enable _NET_WM_PING // -// This variable can be set to the following values: -// "0" - Remotes send enter/escape/arrow key events -// "1" - Remotes are available as 2 axis, 2 button joysticks (the default). -pub const hint_tv_remote_as_joystick = 'SDL_TV_REMOTE_AS_JOYSTICK' +// By default SDL will use _NET_WM_PING, but for applications that know they +// will not always be able to respond to ping requests in a timely manner they can +// turn it off to avoid the window manager thinking the app is hung. +// The hint is checked in CreateWindow. +pub const hint_video_x11_net_wm_ping = 'SDL_VIDEO_X11_NET_WM_PING' -// A variable controlling whether the screensaver is enabled. +// A variable controlling whether the X11 _NET_WM_BYPASS_COMPOSITOR hint should be used. // // This variable can be set to the following values: -// "0" - Disable screensaver -// "1" - Enable screensaver -// -// By default SDL will disable the screensaver. -pub const hint_video_allow_screensaver = 'SDL_VIDEO_ALLOW_SCREENSAVER' - -// Tell the video driver that we only want a double buffer. -// -// By default, most lowlevel 2D APIs will use a triple buffer scheme that -// wastes no CPU time on waiting for vsync after issuing a flip, but -// introduces a frame of latency. On the other hand, using a double buffer -// scheme instead is recommended for cases where low latency is an important -// factor because we save a whole frame of latency. -// We do so by waiting for vsync immediately after issuing a flip, usually just -// after eglSwapBuffers call in the backend's *_SwapWindow function. -// -// Since it's driver-specific, it's only supported where possible and -// implemented. Currently supported the following drivers: +// "0" - Disable _NET_WM_BYPASS_COMPOSITOR +// "1" - Enable _NET_WM_BYPASS_COMPOSITOR // -// - KMSDRM (kmsdrm) -// - Raspberry Pi (raspberrypi) -pub const hint_video_double_buffer = 'SDL_VIDEO_DOUBLE_BUFFER' - -// A variable controlling whether the EGL window is allowed to be -// composited as transparent, rather than opaque. +// By default SDL will use _NET_WM_BYPASS_COMPOSITOR // -// Most window systems will always render windows opaque, even if the surface -// format has an alpha channel. This is not always true, however, so by default -// SDL will try to enforce opaque composition. To override this behavior, you -// can set this hint to "1". -pub const hint_video_egl_allow_transparency = 'SDL_VIDEO_EGL_ALLOW_TRANSPARENCY' +pub const hint_video_x11_net_wm_bypass_compositor = 'SDL_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR' -// A variable controlling whether the graphics context is externally managed. +// A variable controlling whether the window frame and title bar are interactive when the cursor is hidden // // This variable can be set to the following values: -// "0" - SDL will manage graphics contexts that are attached to windows. -// "1" - Disable graphics context management on windows. +// "0" - The window frame is not interactive when the cursor is hidden (no move, resize, etc) +// "1" - The window frame is interactive when the cursor is hidden // -// By default SDL will manage OpenGL contexts in certain situations. For example, on Android the -// context will be automatically saved and restored when pausing the application. Additionally, some -// platforms will assume usage of OpenGL if Vulkan isn't used. Setting this to "1" will prevent this -// behavior, which is desireable when the application manages the graphics context, such as -// an externally managed OpenGL context or attaching a Vulkan surface to the window. -pub const hint_video_external_context = 'SDL_VIDEO_EXTERNAL_CONTEXT' +// By default SDL will allow interaction with the window frame when the cursor is hidden +pub const hint_window_frame_usable_while_cursor_hidden = 'SDL_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN' -// If set to 1, then do not allow high-DPI windows. ("Retina" on Mac and iOS) -pub const hint_video_highdpi_disabled = 'SDL_VIDEO_HIGHDPI_DISABLED' +// A variable to specify custom icon resource id from RC file on Windows platform +pub const hint_windows_intresource_icon = 'SDL_WINDOWS_INTRESOURCE_ICON' +pub const hint_windows_intresource_icon_small = 'SDL_WINDOWS_INTRESOURCE_ICON_SMALL' -// A variable that dictates policy for fullscreen Spaces on Mac OS X. -// -// This hint only applies to Mac OS X. -// -// The variable can be set to the following values: -// "0" - Disable Spaces support (FULLSCREEN_DESKTOP won't use them and -// SDL_WINDOW_RESIZABLE windows won't offer the "fullscreen" -// button on their titlebars). -// "1" - Enable Spaces support (FULLSCREEN_DESKTOP will use them and -// SDL_WINDOW_RESIZABLE windows will offer the "fullscreen" -// button on their titlebars). +// A variable controlling whether the windows message loop is processed by SDL // -// The default value is "1". This hint must be set before any windows are created. -pub const hint_video_mac_fullscreen_spaces = 'SDL_VIDEO_MAC_FULLSCREEN_SPACES' - -// Minimize your SDL_Window if it loses key focus when in fullscreen mode. Defaults to false. -// WARNING Before SDL 2.0.14, this defaulted to true! In 2.0.14, we're -// seeing if "true" causes more problems than it solves in modern times. +// This variable can be set to the following values: +// "0" - The window message loop is not run +// "1" - The window message loop is processed in SDL_PumpEvents() // -pub const hint_video_minimize_on_focus_loss = 'SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS' +// By default SDL will process the windows message loop +pub const hint_windows_enable_messageloop = 'SDL_WINDOWS_ENABLE_MESSAGELOOP' -// A variable controlling whether the libdecor Wayland backend is allowed to be used. +// A variable controlling whether grabbing input grabs the keyboard // // This variable can be set to the following values: -// "0" - libdecor use is disabled. -// "1" - libdecor use is enabled (default). +// "0" - Grab will affect only the mouse +// "1" - Grab will affect mouse and keyboard // -// libdecor is used over xdg-shell when xdg-decoration protocol is unavailable. -pub const hint_video_wayland_allow_libdecor = 'SDL_VIDEO_WAYLAND_ALLOW_LIBDECOR' +// By default SDL will not grab the keyboard so system shortcuts still work. +pub const hint_grab_keyboard = 'SDL_GRAB_KEYBOARD' -// A variable controlling whether the libdecor Wayland backend is preferred over native decrations. -// -// When this hint is set, libdecor will be used to provide window decorations, even if xdg-decoration is -// available. (Note that, by default, libdecor will use xdg-decoration itself if available). +// A variable setting the speed scale for mouse motion, in floating point, when the mouse is not in relative mode +pub const hint_mouse_normal_speed_scale = 'SDL_MOUSE_NORMAL_SPEED_SCALE' + +// A variable setting the scale for mouse motion, in floating point, when the mouse is in relative mode +pub const hint_mouse_relative_speed_scale = 'SDL_MOUSE_RELATIVE_SPEED_SCALE' + +// A variable controlling whether relative mouse mode is implemented using mouse warping // // This variable can be set to the following values: -// "0" - libdecor is enabled only if server-side decorations are unavailable. -// "1" - libdecor is always enabled if available. +// "0" - Relative mouse mode uses raw input +// "1" - Relative mouse mode uses mouse warping // -// libdecor is used over xdg-shell when xdg-decoration protocol is unavailable. -pub const hint_video_wayland_prefer_libdecor = 'SDL_VIDEO_WAYLAND_PREFER_LIBDECOR' +// By default SDL will use raw input for relative mouse mode +pub const hint_mouse_relative_mode_warp = 'SDL_MOUSE_RELATIVE_MODE_WARP' -// A variable controlling whether video mode emulation is enabled underi Wayland. -// -// When this hint is set, a standard set of emulated CVT video modes will be exposed for use by the application. -// If it is disabled, the only modes exposed will be the logical desktop size and, in the case of a scaled -// desktop, the native display resolution. +// Allow mouse click events when clicking to focus an SDL window // // This variable can be set to the following values: -// "0" - Video mode emulation is disabled. -// "1" - Video mode emulation is enabled. +// "0" - Ignore mouse clicks that activate a window +// "1" - Generate events for mouse clicks that activate a window // -// By default video mode emulation is enabled. -pub const hint_video_wayland_mode_emulation = 'SDL_VIDEO_WAYLAND_MODE_EMULATION' +// By default SDL will ignore mouse clicks that activate a window +pub const hint_mouse_focus_clickthrough = 'SDL_MOUSE_FOCUS_CLICKTHROUGH' -// Enable or disable mouse pointer warp emulation, needed by some older games. -// -// When this hint is set, any SDL will emulate mouse warps using relative mouse mode. -// This is required for some older games (such as Source engine games), which warp the -// mouse to the centre of the screen rather than using relative mouse motion. Note that -// relative mouse mode may have different mouse acceleration behaviour than pointer warps. +// A variable controlling whether touch events should generate synthetic mouse events // // This variable can be set to the following values: -// "0" - All mouse warps fail, as mouse warping is not available under wayland. -// "1" - Some mouse warps will be emulated by forcing relative mouse mode. +// "0" - Touch events will not generate mouse events +// "1" - Touch events will generate mouse events // -// If not set, this is automatically enabled unless an application uses relative mouse -// mode directly. -pub const hint_video_wayland_emulate_mouse_warp = 'SDL_VIDEO_WAYLAND_EMULATE_MOUSE_WARP' +// By default SDL will generate mouse events for touch events +pub const hint_touch_mouse_events = 'SDL_TOUCH_MOUSE_EVENTS' -// A variable that is the address of another SDL_Window* (as a hex string formatted with "%p"). +// Minimize your SDL_Window if it loses key focus when in fullscreen mode. Defaults to true. // -// If this hint is set before SDL_CreateWindowFrom() and the SDL_Window* it is set to has -// SDL_WINDOW_OPENGL set (and running on WGL only, currently), then two things will occur on the newly -// created SDL_Window: +pub const hint_video_minimize_on_focus_loss = 'SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS' + +// A variable controlling whether the idle timer is disabled on iOS. // -// 1. Its pixel format will be set to the same pixel format as this SDL_Window. This is -// needed for example when sharing an OpenGL context across multiple windows. +// When an iOS app does not receive touches for some time, the screen is +// dimmed automatically. For games where the accelerometer is the only input +// this is problematic. This functionality can be disabled by setting this +// hint. // -// 2. The flag SDL_WINDOW_OPENGL will be set on the new window so it can be used for -// OpenGL rendering. +// As of SDL 2.0.4, SDL_EnableScreenSaver() and SDL_DisableScreenSaver() +// accomplish the same thing on iOS. They should be preferred over this hint. // // This variable can be set to the following values: -// The address (as a string "%p") of the SDL_Window* that new windows created with SDL_CreateWindowFrom() should -// share a pixel format with. -pub const hint_video_window_share_pixel_format = 'SDL_VIDEO_WINDOW_SHARE_PIXEL_FORMAT' +// "0" - Enable idle timer +// "1" - Disable idle timer +pub const hint_idle_timer_disabled = 'SDL_IOS_IDLE_TIMER_DISABLED' -// When calling SDL_CreateWindowFrom(), make the window compatible with OpenGL. +// A variable controlling which orientations are allowed on iOS. // -// This variable can be set to the following values: -// "0" - Don't add any graphics flags to the SDL_WindowFlags -// "1" - Add SDL_WINDOW_OPENGL to the SDL_WindowFlags +// In some circumstances it is necessary to be able to explicitly control +// which UI orientations are allowed. // -// By default SDL will not make the foreign window compatible with OpenGL. -pub const hint_video_foreign_window_opengl = 'SDL_VIDEO_FOREIGN_WINDOW_OPENGL' +// This variable is a space delimited list of the following values: +// "LandscapeLeft", "LandscapeRight", "Portrait" "PortraitUpsideDown" +pub const hint_orientations = 'SDL_IOS_ORIENTATIONS' -// When calling SDL_CreateWindowFrom(), make the window compatible with Vulkan. -// -// This variable can be set to the following values: -// "0" - Don't add any graphics flags to the SDL_WindowFlags -// "1" - Add SDL_WINDOW_VULKAN to the SDL_WindowFlags +// A variable controlling whether controllers used with the Apple TV +// generate UI events. // -// By default SDL will not make the foreign window compatible with Vulkan. -pub const hint_video_foreign_window_vulkan = 'SDL_VIDEO_FOREIGN_WINDOW_VULKAN' - -// A variable specifying which shader compiler to preload when using the Chrome ANGLE binaries +// When UI events are generated by controller input, the app will be +// backgrounded when the Apple TV remote's menu button is pressed, and when the +// pause or B buttons on gamepads are pressed. // -// SDL has EGL and OpenGL ES2 support on Windows via the ANGLE project. It -// can use two different sets of binaries, those compiled by the user from source -// or those provided by the Chrome browser. In the later case, these binaries require -// that SDL loads a DLL providing the shader compiler. +// More information about properly making use of controllers for the Apple TV +// can be found here: +// https://developer.apple.com/tvos/human-interface-guidelines/remote-and-controllers/ // // This variable can be set to the following values: -// "d3dcompiler_46.dll" - default, best for Vista or later. -// "d3dcompiler_43.dll" - for XP support. -// "none" - do not load any library, useful if you compiled ANGLE from source and included the compiler in your binaries. -// -pub const hint_video_win_d3dcompiler = 'SDL_VIDEO_WIN_D3DCOMPILER' +// "0" - Controller input does not generate UI events (the default). +// "1" - Controller input generates UI events. +pub const hint_apple_tv_controller_ui_events = 'SDL_APPLE_TV_CONTROLLER_UI_EVENTS' -// A variable controlling whether X11 should use GLX or EGL by default +// A variable controlling whether the Apple TV remote's joystick axes +// will automatically match the rotation of the remote. // // This variable can be set to the following values: -// "0" - Use GLX -// "1" - Use EGL -// -// By default SDL will use GLX when both are present. -pub const hint_video_x11_force_egl = 'SDL_VIDEO_X11_FORCE_EGL' +// "0" - Remote orientation does not affect joystick axes (the default). +// "1" - Joystick axes are based on the orientation of the remote. +pub const hint_apple_tv_remote_allow_rotation = 'SDL_APPLE_TV_REMOTE_ALLOW_ROTATION' -// A variable controlling whether the X11 _NET_WM_BYPASS_COMPOSITOR hint should be used. +// A variable controlling whether the home indicator bar on iPhone X +// should be hidden. // // This variable can be set to the following values: -// "0" - Disable _NET_WM_BYPASS_COMPOSITOR -// "1" - Enable _NET_WM_BYPASS_COMPOSITOR -// -// By default SDL will use _NET_WM_BYPASS_COMPOSITOR -// -pub const hint_video_x11_net_wm_bypass_compositor = 'SDL_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR' +// "0" - The indicator bar is not hidden (default for windowed applications) +// "1" - The indicator bar is hidden and is shown when the screen is touched (useful for movie playback applications) +// "2" - The indicator bar is dim and the first swipe makes it visible and the second swipe performs the "home" action (default for fullscreen applications) +pub const hint_ios_hide_home_indicator = 'SDL_IOS_HIDE_HOME_INDICATOR' -// A variable controlling whether the X11 _NET_WM_PING protocol should be supported. +// A variable controlling whether the Android / iOS built-in +// accelerometer should be listed as a joystick device. // // This variable can be set to the following values: -// "0" - Disable _NET_WM_PING -// "1" - Enable _NET_WM_PING -// -// By default SDL will use _NET_WM_PING, but for applications that know they -// will not always be able to respond to ping requests in a timely manner they can -// turn it off to avoid the window manager thinking the app is hung. -// The hint is checked in CreateWindow. -pub const hint_video_x11_net_wm_ping = 'SDL_VIDEO_X11_NET_WM_PING' +// "0" - The accelerometer is not listed as a joystick +// "1" - The accelerometer is available as a 3 axis joystick (the default). +pub const hint_accelerometer_as_joystick = 'SDL_ACCELEROMETER_AS_JOYSTICK' -// A variable forcing the visual ID chosen for new X11 windows +// A variable controlling whether the Android / tvOS remotes +// should be listed as joystick devices, instead of sending keyboard events. // -pub const hint_video_x11_window_visualid = 'SDL_VIDEO_X11_WINDOW_VISUALID' +// This variable can be set to the following values: +// "0" - Remotes send enter/escape/arrow key events +// "1" - Remotes are available as 2 axis, 2 button joysticks (the default). +pub const hint_tv_remote_as_joystick = 'SDL_TV_REMOTE_AS_JOYSTICK' -// A no-longer-used variable controlling whether the X11 Xinerama extension should be used. +// A variable that lets you disable the detection and use of Xinput gamepad devices // -// Before SDL 2.0.24, this would let apps and users disable Xinerama support on X11. -// Now SDL never uses Xinerama, and does not check for this hint at all. -// The preprocessor define is left here for source compatibility. -pub const hint_video_x11_xinerama = 'SDL_VIDEO_X11_XINERAMA' +// The variable can be set to the following values: +// "0" - Disable XInput detection (only uses direct input) +// "1" - Enable XInput detection (the default) +pub const hint_xinput_enabled = 'SDL_XINPUT_ENABLED' -// A variable controlling whether the X11 XRandR extension should be used. +// A variable that causes SDL to use the old axis and button mapping for XInput devices. // -// This variable can be set to the following values: -// "0" - Disable XRandR -// "1" - Enable XRandR +// This hint is for backwards compatibility only and will be removed in SDL 2.1 // -// By default SDL will use XRandR. -pub const hint_video_x11_xrandr = 'SDL_VIDEO_X11_XRANDR' +// The default value is "0". This hint must be set before SDL_Init() +pub const hint_xinput_use_old_joystick_mapping = 'SDL_XINPUT_USE_OLD_JOYSTICK_MAPPING' -// A no-longer-used variable controlling whether the X11 VidMode extension should be used. +// A variable that lets you manually hint extra gamecontroller db entries. // -// Before SDL 2.0.24, this would let apps and users disable XVidMode support on X11. -// Now SDL never uses XVidMode, and does not check for this hint at all. -// The preprocessor define is left here for source compatibility. -pub const hint_video_x11_xvidmode = 'SDL_VIDEO_X11_XVIDMODE' - -// Controls how the fact chunk affects the loading of a WAVE file. +// The variable should be newline delimited rows of gamecontroller config data, see SDL_gamecontroller.h // -// The fact chunk stores information about the number of samples of a WAVE -// file. The Standards Update from Microsoft notes that this value can be used -// to 'determine the length of the data in seconds'. This is especially useful -// for compressed formats (for which this is a mandatory chunk) if they produce -// multiple sample frames per block and truncating the block is not allowed. -// The fact chunk can exactly specify how many sample frames there should be -// in this case. +// This hint must be set before calling SDL_Init(SDL_INIT_GAMECONTROLLER) +// You can update mappings after the system is initialized with SDL_GameControllerMappingForGUID() and SDL_GameControllerAddMapping() +pub const hint_gamecontrollerconfig = 'SDL_GAMECONTROLLERCONFIG' + +// A variable containing a list of devices to skip when scanning for game controllers. // -// Unfortunately, most application seem to ignore the fact chunk and so SDL -// ignores it by default as well. +// The format of the string is a comma separated list of USB VID/PID pairs +// in hexadecimal form, e.g. // -// This variable can be set to the following values: +// 0xAAAA/0xBBBB,0xCCCC/0xDDDD // -// "truncate" - Use the number of samples to truncate the wave data if -// the fact chunk is present and valid -// "strict" - Like "truncate", but raise an error if the fact chunk -// is invalid, not present for non-PCM formats, or if the -// data chunk doesn't have that many samples -// "ignorezero" - Like "truncate", but ignore fact chunk if the number of -// samples is zero -// "ignore" - Ignore fact chunk entirely (default) -pub const hint_wave_fact_chunk = 'SDL_WAVE_FACT_CHUNK' +// The variable can also take the form of @file, in which case the named +// file will be loaded and interpreted as the value of the variable. +pub const hint_gamecontroller_ignore_devices = 'SDL_GAMECONTROLLER_IGNORE_DEVICES' -// Controls how the size of the RIFF chunk affects the loading of a WAVE file. +// If set, all devices will be skipped when scanning for game controllers except for the ones listed in this variable. // -// The size of the RIFF chunk (which includes all the sub-chunks of the WAVE -// file) is not always reliable. In case the size is wrong, it's possible to -// just ignore it and step through the chunks until a fixed limit is reached. -// -// Note that files that have trailing data unrelated to the WAVE file or -// corrupt files may slow down the loading process without a reliable boundary. -// By default, SDL stops after 10000 chunks to prevent wasting time. Use the -// environment variable SDL_WAVE_CHUNK_LIMIT to adjust this value. +// The format of the string is a comma separated list of USB VID/PID pairs +// in hexadecimal form, e.g. // -// This variable can be set to the following values: +// 0xAAAA/0xBBBB,0xCCCC/0xDDDD // -// "force" - Always use the RIFF chunk size as a boundary for the chunk search -// "ignorezero" - Like "force", but a zero size searches up to 4 GiB (default) -// "ignore" - Ignore the RIFF chunk size and always search up to 4 GiB -// "maximum" - Search for chunks until the end of file (not recommended) -pub const hint_wave_riff_chunk_size = 'SDL_WAVE_RIFF_CHUNK_SIZE' +// The variable can also take the form of @file, in which case the named +// file will be loaded and interpreted as the value of the variable. +pub const hint_gamecontroller_ignore_devices_except = 'SDL_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT' -// Controls how a truncated WAVE file is handled. +// A variable that lets you enable joystick (and gamecontroller) events even when your app is in the background. // -// A WAVE file is considered truncated if any of the chunks are incomplete or -// the data chunk size is not a multiple of the block size. By default, SDL -// decodes until the first incomplete block, as most applications seem to do. -// -// This variable can be set to the following values: +// The variable can be set to the following values: +// "0" - Disable joystick & gamecontroller input events when the +// application is in the background. +// "1" - Enable joystick & gamecontroller input events when the +// application is in the background. // -// "verystrict" - Raise an error if the file is truncated -// "strict" - Like "verystrict", but the size of the RIFF chunk is ignored -// "dropframe" - Decode until the first incomplete sample frame -// "dropblock" - Decode until the first incomplete block (default) -pub const hint_wave_truncation = 'SDL_WAVE_TRUNCATION' +// The default value is "0". This hint may be set at any time. +pub const hint_joystick_allow_background_events = 'SDL_JOYSTICK_ALLOW_BACKGROUND_EVENTS' -// Tell SDL not to name threads on Windows with the 0x406D1388 Exception. -// The 0x406D1388 Exception is a trick used to inform Visual Studio of a -// thread's name, but it tends to cause problems with other debuggers, -// and the .NET runtime. Note that SDL 2.0.6 and later will still use -// the (safer) SetThreadDescription API, introduced in the Windows 10 -// Creators Update, if available. +// If set to "0" then never set the top most bit on a SDL Window, even if the video mode expects it. +// This is a debugging aid for developers and not expected to be used by end users. The default is "1" // -// The variable can be set to the following values: -// "0" - SDL will raise the 0x406D1388 Exception to name threads. -// This is the default behavior of SDL <= 2.0.4. -// "1" - SDL will not raise this exception, and threads will be unnamed. (default) -// This is necessary with .NET languages or debuggers that aren't Visual Studio. -pub const hint_windows_disable_thread_naming = 'SDL_WINDOWS_DISABLE_THREAD_NAMING' +// This variable can be set to the following values: +// "0" - don't allow topmost +// "1" - allow topmost +pub const hint_allow_topmost = 'SDL_ALLOW_TOPMOST' -// Controls whether menus can be opened with their keyboard shortcut (Alt+mnemonic). +// A variable that controls the timer resolution, in milliseconds. // -// If the mnemonics are enabled, then menus can be opened by pressing the Alt -// key and the corresponding mnemonic (for example, Alt+F opens the File menu). -// However, in case an invalid mnemonic is pressed, Windows makes an audible -// beep to convey that nothing happened. This is true even if the window has -// no menu at all! +// The higher resolution the timer, the more frequently the CPU services +// timer interrupts, and the more precise delays are, but this takes up +// power and CPU time. This hint is only used on Windows 7 and earlier. // -// Because most SDL applications don't have menus, and some want to use the Alt -// key for other purposes, SDL disables mnemonics (and the beeping) by default. +// See this blog post for more information: +// http://randomascii.wordpress.com/2013/07/08/windows-timer-resolution-megawatts-wasted/ // -// Note: This also affects keyboard events: with mnemonics enabled, when a -// menu is opened from the keyboard, you will not receive a KEYUP event for -// the mnemonic key, and *might* not receive one for Alt. +// If this variable is set to "0", the system timer resolution is not set. // -// This variable can be set to the following values: -// "0" - Alt+mnemonic does nothing, no beeping. (default) -// "1" - Alt+mnemonic opens menus, invalid mnemonics produce a beep. -pub const hint_windows_enable_menu_mnemonics = 'SDL_WINDOWS_ENABLE_MENU_MNEMONICS' +// The default value is "1". This hint may be set at any time. +pub const hint_timer_resolution = 'SDL_TIMER_RESOLUTION' -// A variable controlling whether the windows message loop is processed by SDL -// -// This variable can be set to the following values: -// "0" - The window message loop is not run -// "1" - The window message loop is processed in SDL_PumpEvents() +// A variable describing the content orientation on QtWayland-based platforms. // -// By default SDL will process the windows message loop -pub const hint_windows_enable_messageloop = 'SDL_WINDOWS_ENABLE_MESSAGELOOP' - -// Force SDL to use Critical Sections for mutexes on Windows. -// On Windows 7 and newer, Slim Reader/Writer Locks are available. -// They offer better performance, allocate no kernel ressources and -// use less memory. SDL will fall back to Critical Sections on older -// OS versions or if forced to by this hint. +// On QtWayland platforms, windows are rotated client-side to allow for custom +// transitions. In order to correctly position overlays (e.g. volume bar) and +// gestures (e.g. events view, close/minimize gestures), the system needs to +// know in which orientation the application is currently drawing its contents. // -// This variable can be set to the following values: -// "0" - Use SRW Locks when available. If not, fall back to Critical Sections. (default) -// "1" - Force the use of Critical Sections in all cases. +// This does not cause the window to be rotated or resized, the application +// needs to take care of drawing the content in the right orientation (the +// framebuffer is always in portrait mode). // -pub const hint_windows_force_mutex_critical_sections = 'SDL_WINDOWS_FORCE_MUTEX_CRITICAL_SECTIONS' +// This variable can be one of the following values: +// "primary" (default), "portrait", "landscape", "inverted-portrait", "inverted-landscape" +pub const hint_qtwayland_content_orientation = 'SDL_QTWAYLAND_CONTENT_ORIENTATION' -// Force SDL to use Kernel Semaphores on Windows. -// Kernel Semaphores are inter-process and require a context -// switch on every interaction. On Windows 8 and newer, the -// WaitOnAddress API is available. Using that and atomics to -// implement semaphores increases performance. -// SDL will fall back to Kernel Objects on older OS versions -// or if forced to by this hint. +// Flags to set on QtWayland windows to integrate with the native window manager. // -// This variable can be set to the following values: -// "0" - Use Atomics and WaitOnAddress API when available. If not, fall back to Kernel Objects. (default) -// "1" - Force the use of Kernel Objects in all cases. +// On QtWayland platforms, this hint controls the flags to set on the windows. +// For example, on Sailfish OS "OverridesSystemGestures" disables swipe gestures. // -pub const hint_windows_force_semaphore_kernel = 'SDL_WINDOWS_FORCE_SEMAPHORE_KERNEL' +// This variable is a space-separated list of the following values (empty = no flags): +// "OverridesSystemGestures", "StaysOnTop", "BypassWindowManager" +pub const hint_qtwayland_window_flags = 'SDL_QTWAYLAND_WINDOW_FLAGS' -// A variable to specify custom icon resource id from RC file on Windows platform -pub const hint_windows_intresource_icon = 'SDL_WINDOWS_INTRESOURCE_ICON' +// A string specifying SDL's threads stack size in bytes or "0" for the backend's default size +// +// Use this hint in case you need to set SDL's threads stack size to other than the default. +// This is specially useful if you build SDL against a non glibc libc library (such as musl) which +// provides a relatively small default thread stack size (a few kilobytes versus the default 8MB glibc uses). +// Support for this hint is currently available only in the pthread, Windows, and PSP backend. +pub const hint_thread_stack_size = 'SDL_THREAD_STACK_SIZE' -pub const hint_windows_intresource_icon_small = 'SDL_WINDOWS_INTRESOURCE_ICON_SMALL' +// If set to 1, then do not allow high-DPI windows. ("Retina" on Mac and iOS) +pub const hint_video_highdpi_disabled = 'SDL_VIDEO_HIGHDPI_DISABLED' -// Tell SDL not to generate window-close events for Alt+F4 on Windows. +// A variable that determines whether ctrl+click should generate a right-click event on Mac // -// The variable can be set to the following values: -// "0" - SDL will generate a window-close event when it sees Alt+F4. -// "1" - SDL will only do normal key handling for Alt+F4. -pub const hint_windows_no_close_on_alt_f4 = 'SDL_WINDOWS_NO_CLOSE_ON_ALT_F4' +// If present, holding ctrl while left clicking will generate a right click +// event when on Mac. +pub const hint_mac_ctrl_click_emulate_right_click = 'SDL_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK' -// Use the D3D9Ex API introduced in Windows Vista, instead of normal D3D9. -// Direct3D 9Ex contains changes to state management that can eliminate device -// loss errors during scenarios like Alt+Tab or UAC prompts. D3D9Ex may require -// some changes to your application to cope with the new behavior, so this -// is disabled by default. +// A variable specifying which shader compiler to preload when using the Chrome ANGLE binaries // -// This hint must be set before initializing the video subsystem. -// -// For more information on Direct3D 9Ex, see: -// - https://docs.microsoft.com/en-us/windows/win32/direct3darticles/graphics-apis-in-windows-vista#direct3d-9ex -// - https://docs.microsoft.com/en-us/windows/win32/direct3darticles/direct3d-9ex-improvements +// SDL has EGL and OpenGL ES2 support on Windows via the ANGLE project. It +// can use two different sets of binaries, those compiled by the user from source +// or those provided by the Chrome browser. In the later case, these binaries require +// that SDL loads a DLL providing the shader compiler. // // This variable can be set to the following values: -// "0" - Use the original Direct3D 9 API (default) -// "1" - Use the Direct3D 9Ex API on Vista and later (and fall back if D3D9Ex is unavailable) +// "d3dcompiler_46.dll" - default, best for Vista or later. +// "d3dcompiler_43.dll" - for XP support. +// "none" - do not load any library, useful if you compiled ANGLE from source and included the compiler in your binaries. // -pub const hint_windows_use_d3d9ex = 'SDL_WINDOWS_USE_D3D9EX' +pub const hint_video_win_d3dcompiler = 'SDL_VIDEO_WIN_D3DCOMPILER' -// Controls whether SDL will declare the process to be DPI aware. -// -// This hint must be set before initializing the video subsystem. +// A variable that is the address of another SDL_Window* (as a hex string formatted with "%p"). // -// The main purpose of declaring DPI awareness is to disable OS bitmap scaling of SDL windows on monitors with -// a DPI scale factor. +// If this hint is set before SDL_CreateWindowFrom() and the SDL_Window* it is set to has +// SDL_WINDOW_OPENGL set (and running on WGL only, currently), then two things will occur on the newly +// created SDL_Window: // -// This hint is equivalent to requesting DPI awareness via external means (e.g. calling SetProcessDpiAwarenessContext) -// and does not cause SDL to use a virtualized coordinate system, so it will generally give you 1 SDL coordinate = 1 pixel -// even on high-DPI displays. +// 1. Its pixel format will be set to the same pixel format as this SDL_Window. This is +// needed for example when sharing an OpenGL context across multiple windows. // -// For more information, see: -// https://docs.microsoft.com/en-us/windows/win32/hidpi/high-dpi-desktop-application-development-on-windows +// 2. The flag SDL_WINDOW_OPENGL will be set on the new window so it can be used for +// OpenGL rendering. // // This variable can be set to the following values: -// "" - Do not change the DPI awareness (default). -// "unaware" - Declare the process as DPI unaware. (Windows 8.1 and later). -// "system" - Request system DPI awareness. (Vista and later). -// "permonitor" - Request per-monitor DPI awareness. (Windows 8.1 and later). -// "permonitorv2" - Request per-monitor V2 DPI awareness. (Windows 10, version 1607 and later). -// The most visible difference from "permonitor" is that window title bar will be scaled -// to the visually correct size when dragging between monitors with different scale factors. -// This is the preferred DPI awareness level. -// -// If the requested DPI awareness is not available on the currently running OS, SDL will try to request the best -// available match. -pub const hint_windows_dpi_awareness = 'SDL_WINDOWS_DPI_AWARENESS' +// The address (as a string "%p") of the SDL_Window* that new windows created with SDL_CreateWindowFrom() should +// share a pixel format with. +pub const hint_video_window_share_pixel_format = 'SDL_VIDEO_WINDOW_SHARE_PIXEL_FORMAT' -// Uses DPI-scaled points as the SDL coordinate system on Windows. +// A URL to a WinRT app's privacy policy // -// This changes the SDL coordinate system units to be DPI-scaled points, rather than pixels everywhere. -// This means windows will be appropriately sized, even when created on high-DPI displays with scaling. +// All network-enabled WinRT apps must make a privacy policy available to its +// users. On Windows 8, 8.1, and RT, Microsoft mandates that this policy be +// be available in the Windows Settings charm, as accessed from within the app. +// SDL provides code to add a URL-based link there, which can point to the app's +// privacy policy. +// +// To setup a URL to an app's privacy policy, set SDL_HINT_WINRT_PRIVACY_POLICY_URL +// before calling any SDL_Init() functions. The contents of the hint should +// be a valid URL. For example, "http://www.example.com". // -// e.g. requesting a 640x480 window from SDL, on a display with 125% scaling in Windows display settings, -// will create a window with an 800x600 client area (in pixels). +// The default value is "", which will prevent SDL from adding a privacy policy +// link to the Settings charm. This hint should only be set during app init. // -// Setting this to "1" implicitly requests process DPI awareness (setting SDL_WINDOWS_DPI_AWARENESS is unnecessary), -// and forces SDL_WINDOW_ALLOW_HIGHDPI on all windows. +// The label text of an app's "Privacy Policy" link may be customized via another +// hint, SDL_HINT_WINRT_PRIVACY_POLICY_LABEL. // -// This variable can be set to the following values: -// "0" - SDL coordinates equal Windows coordinates. No automatic window resizing when dragging -// between monitors with different scale factors (unless this is performed by -// Windows itself, which is the case when the process is DPI unaware). -// "1" - SDL coordinates are in DPI-scaled points. Automatically resize windows as needed on -// displays with non-100% scale factors. -pub const hint_windows_dpi_scaling = 'SDL_WINDOWS_DPI_SCALING' +// Please note that on Windows Phone, Microsoft does not provide standard UI +// for displaying a privacy policy link, and as such, SDL_HINT_WINRT_PRIVACY_POLICY_URL +// will not get used on that platform. Network-enabled phone apps should display +// their privacy policy through some other, in-app means. +pub const hint_winrt_privacy_policy_url = 'SDL_WINRT_PRIVACY_POLICY_URL' -// A variable controlling whether the window frame and title bar are interactive when the cursor is hidden +// Label text for a WinRT app's privacy policy link // -// This variable can be set to the following values: -// "0" - The window frame is not interactive when the cursor is hidden (no move, resize, etc) -// "1" - The window frame is interactive when the cursor is hidden +// Network-enabled WinRT apps must include a privacy policy. On Windows 8, 8.1, and RT, +// Microsoft mandates that this policy be available via the Windows Settings charm. +// SDL provides code to add a link there, with its label text being set via the +// optional hint, SDL_HINT_WINRT_PRIVACY_POLICY_LABEL. // -// By default SDL will allow interaction with the window frame when the cursor is hidden -pub const hint_window_frame_usable_while_cursor_hidden = 'SDL_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN' - -// A variable controlling whether the window is activated when the SDL_ShowWindow function is called +// Please note that a privacy policy's contents are not set via this hint. A separate +// hint, SDL_HINT_WINRT_PRIVACY_POLICY_URL, is used to link to the actual text of the +// policy. // -// This variable can be set to the following values: -// "0" - The window is activated when the SDL_ShowWindow function is called -// "1" - The window is not activated when the SDL_ShowWindow function is called +// The contents of this hint should be encoded as a UTF8 string. +// +// The default value is "Privacy Policy". This hint should only be set during app +// initialization, preferably before any calls to SDL_Init(). // -// By default SDL will activate the window when the SDL_ShowWindow function is called -pub const hint_window_no_activation_when_shown = 'SDL_WINDOW_NO_ACTIVATION_WHEN_SHOWN' +// For additional information on linking to a privacy policy, see the documentation for +// SDL_HINT_WINRT_PRIVACY_POLICY_URL. +pub const hint_winrt_privacy_policy_label = 'SDL_WINRT_PRIVACY_POLICY_LABEL' // Allows back-button-press events on Windows Phone to be marked as handled // @@ -2048,224 +539,224 @@ pub const hint_window_no_activation_when_shown = 'SDL_WINDOW_NO_ACTIVATION_WHEN_ // http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj247550(v=vs.105).aspx pub const hint_winrt_handle_back_button = 'SDL_WINRT_HANDLE_BACK_BUTTON' -// Label text for a WinRT app's privacy policy link -// -// Network-enabled WinRT apps must include a privacy policy. On Windows 8, 8.1, and RT, -// Microsoft mandates that this policy be available via the Windows Settings charm. -// SDL provides code to add a link there, with its label text being set via the -// optional hint, SDL_HINT_WINRT_PRIVACY_POLICY_LABEL. -// -// Please note that a privacy policy's contents are not set via this hint. A separate -// hint, SDL_HINT_WINRT_PRIVACY_POLICY_URL, is used to link to the actual text of the -// policy. +// A variable that dictates policy for fullscreen Spaces on Mac OS X. // -// The contents of this hint should be encoded as a UTF8 string. +// This hint only applies to Mac OS X. // -// The default value is "Privacy Policy". This hint should only be set during app -// initialization, preferably before any calls to SDL_Init(). +// The variable can be set to the following values: +// "0" - Disable Spaces support (FULLSCREEN_DESKTOP won't use them and +// SDL_WINDOW_RESIZABLE windows won't offer the "fullscreen" +// button on their titlebars). +// "1" - Enable Spaces support (FULLSCREEN_DESKTOP will use them and +// SDL_WINDOW_RESIZABLE windows will offer the "fullscreen" +// button on their titlebars). // -// For additional information on linking to a privacy policy, see the documentation for -// SDL_HINT_WINRT_PRIVACY_POLICY_URL. -pub const hint_winrt_privacy_policy_label = 'SDL_WINRT_PRIVACY_POLICY_LABEL' +// The default value is "1". Spaces are disabled regardless of this hint if +// the OS isn't at least Mac OS X Lion (10.7). This hint must be set before +// any windows are created. +pub const hint_video_mac_fullscreen_spaces = 'SDL_VIDEO_MAC_FULLSCREEN_SPACES' -// A URL to a WinRT app's privacy policy +// When set don't force the SDL app to become a foreground process // -// All network-enabled WinRT apps must make a privacy policy available to its -// users. On Windows 8, 8.1, and RT, Microsoft mandates that this policy be -// be available in the Windows Settings charm, as accessed from within the app. -// SDL provides code to add a URL-based link there, which can point to the app's -// privacy policy. +// This hint only applies to Mac OS X. // -// To setup a URL to an app's privacy policy, set SDL_HINT_WINRT_PRIVACY_POLICY_URL -// before calling any SDL_Init() functions. The contents of the hint should -// be a valid URL. For example, "http://www.example.com". +pub const hint_mac_background_app = 'SDL_MAC_BACKGROUND_APP' + +// Android APK expansion main file version. Should be a string number like "1", "2" etc. // -// The default value is "", which will prevent SDL from adding a privacy policy -// link to the Settings charm. This hint should only be set during app init. +// Must be set together with SDL_HINT_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION. // -// The label text of an app's "Privacy Policy" link may be customized via another -// hint, SDL_HINT_WINRT_PRIVACY_POLICY_LABEL. +// If both hints were set then SDL_RWFromFile() will look into expansion files +// after a given relative path was not found in the internal storage and assets. // -// Please note that on Windows Phone, Microsoft does not provide standard UI -// for displaying a privacy policy link, and as such, SDL_HINT_WINRT_PRIVACY_POLICY_URL -// will not get used on that platform. Network-enabled phone apps should display -// their privacy policy through some other, in-app means. -pub const hint_winrt_privacy_policy_url = 'SDL_WINRT_PRIVACY_POLICY_URL' +// By default this hint is not set and the APK expansion files are not searched. +pub const hint_android_apk_expansion_main_file_version = 'SDL_ANDROID_APK_EXPANSION_MAIN_FILE_VERSION' -// Mark X11 windows as override-redirect. +// Android APK expansion patch file version. Should be a string number like "1", "2" etc. // -// If set, this _might_ increase framerate at the expense of the desktop -// not working as expected. Override-redirect windows aren't noticed by the -// window manager at all. +// Must be set together with SDL_HINT_ANDROID_APK_EXPANSION_MAIN_FILE_VERSION. // -// You should probably only use this for fullscreen windows, and you probably -// shouldn't even use it for that. But it's here if you want to try! -pub const hint_x11_force_override_redirect = 'SDL_X11_FORCE_OVERRIDE_REDIRECT' - -// A variable that lets you disable the detection and use of Xinput gamepad devices +// If both hints were set then SDL_RWFromFile() will look into expansion files +// after a given relative path was not found in the internal storage and assets. // -// The variable can be set to the following values: -// "0" - Disable XInput detection (only uses direct input) -// "1" - Enable XInput detection (the default) -pub const hint_xinput_enabled = 'SDL_XINPUT_ENABLED' +// By default this hint is not set and the APK expansion files are not searched. +pub const hint_android_apk_expansion_patch_file_version = 'SDL_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION' -// A variable that lets you disable the detection and use of DirectInput gamepad devices +// A variable to control whether certain IMEs should handle text editing internally instead of sending SDL_TEXTEDITING events. // // The variable can be set to the following values: -// "0" - Disable DirectInput detection (only uses XInput) -// "1" - Enable DirectInput detection (the default) -pub const hint_directinput_enabled = 'SDL_DIRECTINPUT_ENABLED' +// "0" - SDL_TEXTEDITING events are sent, and it is the application's +// responsibility to render the text from these events and +// differentiate it somehow from committed text. (default) +// "1" - If supported by the IME then SDL_TEXTEDITING events are not sent, +// and text that is being composed will be rendered in its own UI. +pub const hint_ime_internal_editing = 'SDL_IME_INTERNAL_EDITING' -// A variable that causes SDL to use the old axis and button mapping for XInput devices. +// A variable to control whether mouse and touch events are to be treated together or separately // -// This hint is for backwards compatibility only and will be removed in SDL 2.1 +// The variable can be set to the following values: +// "0" - Mouse events will be handled as touch events, and touch will raise fake mouse +// events. This is the behaviour of SDL <= 2.0.3. (default) +// "1" - Mouse events will be handled separately from pure touch events. // -// The default value is "0". This hint must be set before SDL_Init() -pub const hint_xinput_use_old_joystick_mapping = 'SDL_XINPUT_USE_OLD_JOYSTICK_MAPPING' +// The value of this hint is used at runtime, so it can be changed at any time. +pub const hint_android_separate_mouse_and_touch = 'SDL_ANDROID_SEPARATE_MOUSE_AND_TOUCH' -// A variable that causes SDL to not ignore audio "monitors" -// -// This is currently only used for PulseAudio and ignored elsewhere. -// -// By default, SDL ignores audio devices that aren't associated with physical -// hardware. Changing this hint to "1" will expose anything SDL sees that -// appears to be an audio source or sink. This will add "devices" to the list -// that the user probably doesn't want or need, but it can be useful in -// scenarios where you want to hook up SDL to some sort of virtual device, -// etc. +// A variable to control whether the return key on the soft keyboard +// should hide the soft keyboard on Android and iOS. // -// The default value is "0". This hint must be set before SDL_Init(). +// The variable can be set to the following values: +// "0" - The return key will be handled as a key event. This is the behaviour of SDL <= 2.0.3. (default) +// "1" - The return key will hide the keyboard. // -// This hint is available since SDL 2.0.16. Before then, virtual devices are -// always ignored. -pub const hint_audio_include_monitors = 'SDL_AUDIO_INCLUDE_MONITORS' +// The value of this hint is used at runtime, so it can be changed at any time. +pub const hint_return_key_hides_ime = 'SDL_RETURN_KEY_HIDES_IME' -// A variable that forces X11 windows to create as a custom type. +// override the binding element for keyboard inputs for Emscripten builds // -// This is currently only used for X11 and ignored elsewhere. +// This hint only applies to the emscripten platform // -// During SDL_CreateWindow, SDL uses the _NET_WM_WINDOW_TYPE X11 property -// to report to the window manager the type of window it wants to create. -// This might be set to various things if SDL_WINDOW_TOOLTIP or -// SDL_WINDOW_POPUP_MENU, etc, were specified. For "normal" windows that -// haven't set a specific type, this hint can be used to specify a custom -// type. For example, a dock window might set this to -// "_NET_WM_WINDOW_TYPE_DOCK". +// The variable can be one of +// "#window" - The javascript window object (this is the default) +// "#document" - The javascript document object +// "#screen" - the javascript window.screen object +// "#canvas" - the WebGL canvas element +// any other string without a leading # sign applies to the element on the page with that ID. +pub const hint_emscripten_keyboard_element = 'SDL_EMSCRIPTEN_KEYBOARD_ELEMENT' + +// Tell SDL not to catch the SIGINT or SIGTERM signals. // -// If not set or set to "", this hint is ignored. This hint must be set -// before the SDL_CreateWindow() call that it is intended to affect. +// This hint only applies to Unix-like platforms. // -// This hint is available since SDL 2.0.22. -pub const hint_x11_window_type = 'SDL_X11_WINDOW_TYPE' +// The variable can be set to the following values: +// "0" - SDL will install a SIGINT and SIGTERM handler, and when it +// catches a signal, convert it into an SDL_QUIT event. +// "1" - SDL will not install a signal handler at all. +pub const hint_no_signal_handlers = 'SDL_NO_SIGNAL_HANDLERS' -// A variable that decides whether to send SDL_QUIT when closing the final window. -// -// By default, SDL sends an SDL_QUIT event when there is only one window -// and it receives an SDL_WINDOWEVENT_CLOSE event, under the assumption most -// apps would also take the loss of this window as a signal to terminate the -// program. +// Tell SDL not to generate window-close events for Alt+F4 on Windows. // -// However, it's not unreasonable in some cases to have the program continue -// to live on, perhaps to create new windows later. +// The variable can be set to the following values: +// "0" - SDL will generate a window-close event when it sees Alt+F4. +// "1" - SDL will only do normal key handling for Alt+F4. +pub const hint_windows_no_close_on_alt_f4 = 'SDL_WINDOWS_NO_CLOSE_ON_ALT_F4' + +// Prevent SDL from using version 4 of the bitmap header when saving BMPs. // -// Changing this hint to "0" will cause SDL to not send an SDL_QUIT event -// when the final window is requesting to close. Note that in this case, -// there are still other legitimate reasons one might get an SDL_QUIT -// event: choosing "Quit" from the macOS menu bar, sending a SIGINT (ctrl-c) -// on Unix, etc. +// The bitmap header version 4 is required for proper alpha channel support and +// SDL will use it when required. Should this not be desired, this hint can +// force the use of the 40 byte header version which is supported everywhere. // -// The default value is "1". This hint can be changed at any time. +// The variable can be set to the following values: +// "0" - Surfaces with a colorkey or an alpha channel are saved to a +// 32-bit BMP file with an alpha mask. SDL will use the bitmap +// header version 4 and set the alpha mask accordingly. +// "1" - Surfaces with a colorkey or an alpha channel are saved to a +// 32-bit BMP file without an alpha mask. The alpha channel data +// will be in the file, but applications are going to ignore it. // -// This hint is available since SDL 2.0.22. Before then, you always get -// an SDL_QUIT event when closing the final window. -pub const hint_quit_on_last_window_close = 'SDL_QUIT_ON_LAST_WINDOW_CLOSE' +// The default value is "0". +pub const hint_bmp_save_legacy_format = 'SDL_BMP_SAVE_LEGACY_FORMAT' -// A variable that decides what video backend to use. +// Tell SDL not to name threads on Windows with the 0x406D1388 Exception. +// The 0x406D1388 Exception is a trick used to inform Visual Studio of a +// thread's name, but it tends to cause problems with other debuggers, +// and the .NET runtime. Note that SDL 2.0.6 and later will still use +// the (safer) SetThreadDescription API, introduced in the Windows 10 +// Creators Update, if available. // -// By default, SDL will try all available video backends in a reasonable -// order until it finds one that can work, but this hint allows the app -// or user to force a specific target, such as "x11" if, say, you are -// on Wayland but want to try talking to the X server instead. +// The variable can be set to the following values: +// "0" - SDL will raise the 0x406D1388 Exception to name threads. +// This is the default behavior of SDL <= 2.0.4. +// "1" - SDL will not raise this exception, and threads will be unnamed. (default) +// This is necessary with .NET languages or debuggers that aren't Visual Studio. +pub const hint_windows_disable_thread_naming = 'SDL_WINDOWS_DISABLE_THREAD_NAMING' + +// Tell SDL which Dispmanx layer to use on a Raspberry PI // -// This functionality has existed since SDL 2.0.0 (indeed, before that) -// but before 2.0.22 this was an environment variable only. In 2.0.22, -// it was upgraded to a full SDL hint, so you can set the environment -// variable as usual or programatically set the hint with SDL_SetHint, -// which won't propagate to child processes. +// Also known as Z-order. The variable can take a negative or positive value. +// The default is 10000. +pub const hint_rpi_video_layer = 'SDL_RPI_VIDEO_LAYER' + +// Tell the video driver that we only want a double buffer. // -// The default value is unset, in which case SDL will try to figure out -// the best video backend on your behalf. This hint needs to be set -// before SDL_Init() is called to be useful. +// By default, most lowlevel 2D APIs will use a triple buffer scheme that +// wastes no CPU time on waiting for vsync after issuing a flip, but +// introduces a frame of latency. On the other hand, using a double buffer +// scheme instead is recommended for cases where low latency is an important +// factor because we save a whole frame of latency. +// We do so by waiting for vsync immediately after issuing a flip, usually just +// after eglSwapBuffers call in the backend's *_SwapWindow function. // -// This hint is available since SDL 2.0.22. Before then, you could set -// the environment variable to get the same effect. -pub const hint_videodriver = 'SDL_VIDEODRIVER' +// Since it's driver-specific, it's only supported where possible and +// implemented. Currently supported the following drivers: +// - KMSDRM (kmsdrm) +// - Raspberry Pi (raspberrypi) +pub const hint_video_double_buffer = 'SDL_VIDEO_DOUBLE_BUFFER' -// A variable that decides what audio backend to use. +// A variable controlling what driver to use for OpenGL ES contexts. // -// By default, SDL will try all available audio backends in a reasonable -// order until it finds one that can work, but this hint allows the app -// or user to force a specific target, such as "alsa" if, say, you are -// on PulseAudio but want to try talking to the lower level instead. -// -// This functionality has existed since SDL 2.0.0 (indeed, before that) -// but before 2.0.22 this was an environment variable only. In 2.0.22, -// it was upgraded to a full SDL hint, so you can set the environment -// variable as usual or programatically set the hint with SDL_SetHint, -// which won't propagate to child processes. +// On some platforms, currently Windows and X11, OpenGL drivers may support +// creating contexts with an OpenGL ES profile. By default SDL uses these +// profiles, when available, otherwise it attempts to load an OpenGL ES +// library, e.g. that provided by the ANGLE project. This variable controls +// whether SDL follows this default behaviour or will always load an +// OpenGL ES library. // -// The default value is unset, in which case SDL will try to figure out -// the best audio backend on your behalf. This hint needs to be set -// before SDL_Init() is called to be useful. +// Circumstances where this is useful include +// - Testing an app with a particular OpenGL ES implementation, e.g ANGLE, +// or emulator, e.g. those from ARM, Imagination or Qualcomm. +// - Resolving OpenGL ES function addresses at link time by linking with +// the OpenGL ES library instead of querying them at run time with +// SDL_GL_GetProcAddress(). // -// This hint is available since SDL 2.0.22. Before then, you could set -// the environment variable to get the same effect. -pub const hint_audiodriver = 'SDL_AUDIODRIVER' - -// A variable that decides what KMSDRM device to use. +// Caution: for an application to work with the default behaviour across +// different OpenGL drivers it must query the OpenGL ES function +// addresses at run time using SDL_GL_GetProcAddress(). // -// Internally, SDL might open something like "/dev/dri/cardNN" to -// access KMSDRM functionality, where "NN" is a device index number. +// This variable is ignored on most platforms because OpenGL ES is native +// or not supported. // -// SDL makes a guess at the best index to use (usually zero), but the -// app or user can set this hint to a number between 0 and 99 to -// force selection. +// This variable can be set to the following values: +// "0" - Use ES profile of OpenGL, if available. (Default when not set.) +// "1" - Load OpenGL ES library using the default library names. // -// This hint is available since SDL 2.24.0. -pub const hint_kmsdrm_device_index = 'SDL_KMSDRM_DEVICE_INDEX' +pub const hint_opengl_es_driver = 'SDL_OPENGL_ES_DRIVER' -// A variable that treats trackpads as touch devices. +// A variable controlling speed/quality tradeoff of audio resampling. +// +// If available, SDL can use libsamplerate ( http://www.mega-nerd.com/SRC/ ) +// to handle audio resampling. There are different resampling modes available +// that produce different levels of quality, using more CPU. // -// On macOS (and possibly other platforms in the future), SDL will report -// touches on a trackpad as mouse input, which is generally what users -// expect from this device; however, these are often actually full -// multitouch-capable touch devices, so it might be preferable to some apps -// to treat them as such. +// If this hint isn't specified to a valid setting, or libsamplerate isn't +// available, SDL will use the default, internal resampling algorithm. // -// Setting this hint to true will make the trackpad input report as a -// multitouch device instead of a mouse. The default is false. +// Note that this is currently only applicable to resampling audio that is +// being written to a device for playback or audio being read from a device +// for capture. SDL_AudioCVT always uses the default resampler (although this +// might change for SDL 2.1). // -// Note that most platforms don't support this hint. As of 2.24.0, it -// only supports MacBooks' trackpads on macOS. Others may follow later. +// This hint is currently only checked at audio subsystem initialization. // -// This hint is checked during SDL_Init and can not be changed after. +// This variable can be set to the following values: // -// This hint is available since SDL 2.24.0. -pub const hint_trackpad_is_touch_only = 'SDL_TRACKPAD_IS_TOUCH_ONLY' +// "0" or "default" - Use SDL's internal resampling (Default when not set - low quality, fast) +// "1" or "fast" - Use fast, slightly higher quality resampling, if available +// "2" or "medium" - Use medium quality resampling, if available +// "3" or "best" - Use high quality resampling, if available +pub const hint_audio_resampling_mode = 'SDL_AUDIO_RESAMPLING_MODE' -// Cause SDL to call dbus_shutdown() on quit. -// -// This is useful as a debug tool to validate memory leaks, but shouldn't ever -// be set in production applications, as other libraries used by the application -// might use dbus under the hood and this cause cause crashes if they continue -// after SDL_Quit(). +// A variable controlling the audio category on iOS and Mac OS X // // This variable can be set to the following values: -// "0" - SDL will not call dbus_shutdown() on quit (default) -// "1" - SDL will call dbus_shutdown() on quit // -// This hint is available since SDL 2.30.0. -pub const hint_shutdown_dbus_on_quit = 'SDL_SHUTDOWN_DBUS_ON_QUIT' +// "ambient" - Use the AVAudioSessionCategoryAmbient audio category, will be muted by the phone mute switch (default) +// "playback" - Use the AVAudioSessionCategoryPlayback category +// +// For more information, see Apple's documentation: +// https://developer.apple.com/library/content/documentation/Audio/Conceptual/AudioSessionProgrammingGuide/AudioSessionCategoriesandModes/AudioSessionCategoriesandModes.html +pub const hint_audio_category = 'SDL_AUDIO_CATEGORY' // HintPriority is C.SDL_HintPriority pub enum HintPriority { @@ -2276,109 +767,40 @@ pub enum HintPriority { fn C.SDL_SetHintWithPriority(const_name &char, const_value &char, priority C.SDL_HintPriority) bool -// set_hint_with_priority sets a hint with a specific priority. -// -// The priority controls the behavior when setting a hint that already has a -// value. Hints will replace existing hints of their priority and lower. -// Environment variables are considered to have override priority. +// set_hint_with_priority sets a hint with a specific priority // -// `name` the hint to set -// `value` the value of the hint variable -// `priority` the SDL_HintPriority level for the hint -// returns SDL_TRUE if the hint was set, SDL_FALSE otherwise. +// The priority controls the behavior when setting a hint that already +// has a value. Hints will replace existing hints of their priority and +// lower. Environment variables are considered to have override priority. // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetHint -// See also: SDL_SetHint +// returns SDL_TRUE if the hint was set, SDL_FALSE otherwise pub fn set_hint_with_priority(const_name &char, const_value &char, priority HintPriority) bool { return C.SDL_SetHintWithPriority(const_name, const_value, C.SDL_HintPriority(priority)) } fn C.SDL_SetHint(const_name &char, const_value &char) bool -// set_hint sets a hint with normal priority. -// -// Hints will not be set if there is an existing override hint or environment -// variable that takes precedence. You can use SDL_SetHintWithPriority() to -// set the hint with override priority instead. -// -// `name` the hint to set -// `value` the value of the hint variable -// returns SDL_TRUE if the hint was set, SDL_FALSE otherwise. -// -// NOTE This function is available since SDL 2.0.0. +// set_hint sets a hint with normal priority // -// See also: SDL_GetHint -// See also: SDL_SetHintWithPriority +// returns SDL_TRUE if the hint was set, SDL_FALSE otherwise pub fn set_hint(const_name &char, const_value &char) bool { return C.SDL_SetHint(const_name, const_value) } -pub fn C.SDL_ResetHint(const_name &char) bool - -// reset_hint resets a hint to the default value. -// -// This will reset a hint to the value of the environment variable, or NULL if -// the environment isn't set. Callbacks will be called normally with this -// change. -// -// `name` the hint to set -// returns SDL_TRUE if the hint was set, SDL_FALSE otherwise. -// -// NOTE This function is available since SDL 2.24.0. -// -// See also: SDL_GetHint -// See also: SDL_SetHint -pub fn reset_hint(const_name &char) bool { - return C.SDL_ResetHint(const_name) -} - -fn C.SDL_ResetHints() - -// reset_hints resets all hints to the default values. -// -// This will reset all hints to the value of the associated environment -// variable, or NULL if the environment isn't set. Callbacks will be called -// normally with this change. -// -// NOTE This function is available since SDL 2.26.0. -// -// See also: SDL_GetHint -// See also: SDL_SetHint -// See also: SDL_ResetHint -pub fn reset_hints() { - C.SDL_ResetHints() -} - fn C.SDL_GetHint(name &char) &char -// get_hint gets the value of a hint. -// -// `name` the hint to query -// returns the string value of a hint or NULL if the hint isn't set. +// get_hint gets a hint // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_SetHint -// See also: SDL_SetHintWithPriority +// returns The string value of a hint variable. pub fn get_hint(name &char) &char { return C.SDL_GetHint(name) } fn C.SDL_GetHintBoolean(name &char, default_value bool) bool -// get_hint_boolean gets the boolean value of a hint variable. -// -// `name` the name of the hint to get the boolean value from -// `default_value` the value to return if the hint does not exist -// returns the boolean value of a hint or the provided default value if the -// hint does not exist. +// get_hint_boolean gets a hint // -// NOTE This function is available since SDL 2.0.5. -// -// See also: SDL_GetHint -// See also: SDL_SetHint +// returns The boolean value of a hint variable. pub fn get_hint_boolean(name &char, default_value bool) bool { return C.SDL_GetHintBoolean(name, default_value) } @@ -2389,50 +811,31 @@ pub type HintCallback = fn (userdata voidptr, const_name &char, const_old_value fn C.SDL_AddHintCallback(name &char, callback HintCallback, userdata voidptr) -// add_hint_callback adds a function to watch a particular hint. -// -// `name` the hint to watch -// `callback` An SDL_HintCallback function that will be called when the -// hint value changes -// `userdata` a pointer to pass to the callback function +// add_hint_callback adds a function to watch a particular hint // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_DelHintCallback +// `name` The hint to watch +// `callback` The function to call when the hint value changes +// `userdata` A pointer to pass to the callback function pub fn add_hint_callback(name &char, callback HintCallback, userdata voidptr) { C.SDL_AddHintCallback(name, callback, userdata) } fn C.SDL_DelHintCallback(name &char, callback HintCallback, userdata voidptr) -// del_hint_callback removes a function watching a particular hint. -// -// `name` the hint being watched -// `callback` An SDL_HintCallback function that will be called when the -// hint value changes -// `userdata` a pointer being passed to the callback function +// del_hint_callback removes a function watching a particular hint // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_AddHintCallback +// `name` The hint being watched +// `callback` The function being called when the hint value changes +// `userdata` A pointer being passed to the callback function pub fn del_hint_callback(name &char, callback HintCallback, userdata voidptr) { C.SDL_DelHintCallback(name, callback, userdata) } fn C.SDL_ClearHints() -// clear_hints clears all hints. -// -// This function is automatically called during SDL_Quit(), and deletes all -// callbacks without calling them and frees all memory associated with hints. -// If you're calling this from application code you probably want to call -// SDL_ResetHints() instead. -// -// This function will be removed from the API the next time we rev the ABI. -// -// NOTE This function is available since SDL 2.0.0. +// clear_hints clears all hints // -// See also: SDL_ResetHints +// This function is called during SDL_Quit() to free stored hints. pub fn clear_hints() { C.SDL_ClearHints() } diff --git a/image/c.c.v b/image/c.c.v index 6dec1f78..0aa809be 100644 --- a/image/c.c.v +++ b/image/c.c.v @@ -14,11 +14,11 @@ $if !windows { } $if x64 { - #flag windows -L @VMODROOT/thirdparty/SDL2_image-2.0.5/lib/x64 + #flag windows -L @VMODROOT/thirdparty/SDL2_image-2.0.3/lib/x64 } $else { - #flag windows -L @VMODROOT/thirdparty/SDL2_image-2.0.5/lib/x86 + #flag windows -L @VMODROOT/thirdparty/SDL2_image-2.0.3/lib/x86 } -#flag windows -I @VMODROOT/thirdparty/SDL2_image-2.0.5/include +#flag windows -I @VMODROOT/thirdparty/SDL2_image-2.0.3/include #flag windows -lSDL2_image #include diff --git a/image/image.c.v b/image/image.c.v index 2259e8e3..058b1e9f 100644 --- a/image/image.c.v +++ b/image/image.c.v @@ -12,7 +12,7 @@ pub const major_version = C.SDL_IMAGE_MAJOR_VERSION // 2 pub const minor_version = C.SDL_IMAGE_MINOR_VERSION // 0 -pub const patchlevel = C.SDL_IMAGE_PATCHLEVEL // 5 +pub const patchlevel = C.SDL_IMAGE_PATCHLEVEL // 3 fn C.SDL_IMAGE_VERSION(v &sdl.Version) diff --git a/joystick.c.v b/joystick.c.v index 03502bd0..08257960 100644 --- a/joystick.c.v +++ b/joystick.c.v @@ -36,7 +36,13 @@ pub struct C.SDL_Joystick { pub type Joystick = C.SDL_Joystick -pub type JoystickGUID = C.SDL_GUID +@[typedef] +pub struct C.SDL_JoystickGUID { +pub: + data [16]u8 +} + +pub type JoystickGUID = C.SDL_JoystickGUID // JoystickType is C.SDL_JoystickType pub enum JoystickType { @@ -58,18 +64,14 @@ pub type JoystickID = i32 // JoystickPowerLevel is C.SDL_JoystickPowerLevel pub enum JoystickPowerLevel { unknown = -1 - empty // <= 5% - low // <= 20% - medium // <= 70% - full // <= 100% + empty + low + medium + full wired max } -// Set max recognized G-force from accelerometer -// See src/joystick/uikit/SDL_sysjoystick.m for notes on why this is needed -pub const iphone_max_gforce = C.SDL_IPHONE_MAX_GFORCE // 5.0 - fn C.SDL_LockJoysticks() // lock_joysticks provides locking for multi-threaded access to the joystick API @@ -80,45 +82,19 @@ fn C.SDL_LockJoysticks() // In particular, you are guaranteed that the joystick list won't change, so // the API functions that take a joystick index will be valid, and joystick // and game controller events will not be delivered. -// -// As of SDL 2.26.0, you can take the joystick lock around reinitializing the -// joystick subsystem, to prevent other threads from seeing joysticks in an -// uninitialized state. However, all open joysticks will be closed and SDL -// functions called with them will fail. -// -// NOTE This function is available since SDL 2.0.7. pub fn lock_joysticks() { C.SDL_LockJoysticks() } fn C.SDL_UnlockJoysticks() -// unlock_joysticks unlockings for multi-threaded access to the joystick API -// -// If you are using the joystick API or handling events from multiple threads -// you should use these locking functions to protect access to the joysticks. -// -// In particular, you are guaranteed that the joystick list won't change, so -// the API functions that take a joystick index will be valid, and joystick -// and game controller events will not be delivered. -// -// NOTE This function is available since SDL 2.0.7. pub fn unlock_joysticks() { C.SDL_UnlockJoysticks() } fn C.SDL_NumJoysticks() int -// num_joysticks counts the number of joysticks attached to the system. -// -// returns the number of attached joysticks on success or a negative error -// code on failure; call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_JoystickName -// See also: SDL_JoystickPath -// See also: SDL_JoystickOpen +// num_joysticks counts the number of joysticks attached to the system right now pub fn num_joysticks() int { return C.SDL_NumJoysticks() } @@ -126,67 +102,16 @@ pub fn num_joysticks() int { fn C.SDL_JoystickNameForIndex(device_index int) &char // joystick_name_for_index gets the implementation dependent name of a joystick. -// // This can be called before any joysticks are opened. -// -// `device_index` the index of the joystick to query (the N'th joystick -// on the system) -// returns the name of the selected joystick. If no name can be found, this -// function returns NULL; call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_JoystickName -// See also: SDL_JoystickOpen +// If no name can be found, this function returns NULL. pub fn joystick_name_for_index(device_index int) &char { return C.SDL_JoystickNameForIndex(device_index) } -fn C.SDL_JoystickPathForIndex(device_index int) &char +fn C.SDL_JoystickGetDeviceGUID(device_index int) C.SDL_JoystickGUID -// joystick_path_for_index gets the implementation dependent path of a joystick. -// +// joystick_get_device_gui returns the GUID for the joystick at this index // This can be called before any joysticks are opened. -// -// `device_index` the index of the joystick to query (the N'th joystick -// on the system) -// returns the path of the selected joystick. If no path can be found, this -// function returns NULL; call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.24.0. -// -// See also: SDL_JoystickPath -// See also: SDL_JoystickOpen -pub fn joystick_path_for_index(device_index int) &char { - return C.SDL_JoystickPathForIndex(device_index) -} - -fn C.SDL_JoystickGetDevicePlayerIndex(device_index int) int - -// joystick_get_device_player_index gets the player index of a joystick, or -1 if it's not available This can be -// called before any joysticks are opened. -// -// NOTE This function is available since SDL 2.0.9. -pub fn joystick_get_device_player_index(device_index int) int { - return C.SDL_JoystickGetDevicePlayerIndex(device_index) -} - -fn C.SDL_JoystickGetDeviceGUID(device_index int) JoystickGUID - -// joystick_get_device_guid gets the implementation-dependent GUID for the joystick at a given device -// index. -// -// This function can be called before any joysticks are opened. -// -// `device_index` the index of the joystick to query (the N'th joystick -// on the system -// returns the GUID of the selected joystick. If called on an invalid index, -// this function returns a zero GUID -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_JoystickGetGUID -// See also: SDL_JoystickGetGUIDString pub fn joystick_get_device_guid(device_index int) JoystickGUID { return C.SDL_JoystickGetDeviceGUID(device_index) } @@ -194,33 +119,17 @@ pub fn joystick_get_device_guid(device_index int) JoystickGUID { fn C.SDL_JoystickGetDeviceVendor(device_index int) u16 // joystick_get_device_vendor gets the USB vendor ID of a joystick, if available. -// -// This can be called before any joysticks are opened. If the vendor ID isn't -// available this function returns 0. -// -// `device_index` the index of the joystick to query (the N'th joystick -// on the system -// returns the USB vendor ID of the selected joystick. If called on an -// invalid index, this function returns zero -// -// NOTE This function is available since SDL 2.0.6. +// This can be called before any joysticks are opened. +// If the vendor ID isn't available this function returns 0. pub fn joystick_get_device_vendor(device_index int) u16 { return C.SDL_JoystickGetDeviceVendor(device_index) } fn C.SDL_JoystickGetDeviceProduct(device_index int) u16 -// joystick_get_device_product gets the USB product ID of a joystick, if available. -// -// This can be called before any joysticks are opened. If the product ID isn't -// available this function returns 0. -// -// `device_index` the index of the joystick to query (the N'th joystick -// on the system -// returns the USB product ID of the selected joystick. If called on an -// invalid index, this function returns zero -// -// NOTE This function is available since SDL 2.0.6. +// joystick_get_device_produc gets the USB product ID of a joystick, if available. +// This can be called before any joysticks are opened. +// If the product ID isn't available this function returns 0. pub fn joystick_get_device_product(device_index int) u16 { return C.SDL_JoystickGetDeviceProduct(device_index) } @@ -228,16 +137,8 @@ pub fn joystick_get_device_product(device_index int) u16 { fn C.SDL_JoystickGetDeviceProductVersion(device_index int) u16 // joystick_get_device_product_version gets the product version of a joystick, if available. -// -// This can be called before any joysticks are opened. If the product version -// isn't available this function returns 0. -// -// `device_index` the index of the joystick to query (the N'th joystick -// on the system -// returns the product version of the selected joystick. If called on an -// invalid index, this function returns zero -// -// NOTE This function is available since SDL 2.0.6. +// This can be called before any joysticks are opened. +// If the product version isn't available this function returns 0. pub fn joystick_get_device_product_version(device_index int) u16 { return C.SDL_JoystickGetDeviceProductVersion(device_index) } @@ -245,15 +146,7 @@ pub fn joystick_get_device_product_version(device_index int) u16 { fn C.SDL_JoystickGetDeviceType(device_index int) JoystickType // joystick_get_device_type gets the type of a joystick, if available. -// // This can be called before any joysticks are opened. -// -// `device_index` the index of the joystick to query (the N'th joystick -// on the system -// returns the SDL_JoystickType of the selected joystick. If called on an -// invalid index, this function returns `SDL_JOYSTICK_TYPE_UNKNOWN` -// -// NOTE This function is available since SDL 2.0.6. pub fn joystick_get_device_type(device_index int) JoystickType { return unsafe { JoystickType(int(C.SDL_JoystickGetDeviceType(device_index))) } } @@ -261,15 +154,8 @@ pub fn joystick_get_device_type(device_index int) JoystickType { fn C.SDL_JoystickGetDeviceInstanceID(device_index int) JoystickID // joystick_get_device_instance_id gets the instance ID of a joystick. -// // This can be called before any joysticks are opened. -// -// `device_index` the index of the joystick to query (the N'th joystick -// on the system -// returns the instance id of the selected joystick. If called on an invalid -// index, this function returns -1. -// -// NOTE This function is available since SDL 2.0.6. +// If the index is out of range, this function will return -1. pub fn joystick_get_device_instance_id(device_index int) JoystickID { return unsafe { int(C.SDL_JoystickGetDeviceInstanceID(device_index)) } } @@ -277,273 +163,34 @@ pub fn joystick_get_device_instance_id(device_index int) JoystickID { fn C.SDL_JoystickOpen(device_index int) &C.SDL_Joystick // joystick_open opens a joystick for use. +// The index passed as an argument refers to the N'th joystick on the system. +// This index is not the value which will identify this joystick in future +// joystick events. The joystick's instance id (::SDL_JoystickID) will be used +// there instead. // -// The `device_index` argument refers to the N'th joystick presently -// recognized by SDL on the system. It is **NOT** the same as the instance ID -// used to identify the joystick in future events. See -// SDL_JoystickInstanceID() for more details about instance IDs. -// -// The joystick subsystem must be initialized before a joystick can be opened -// for use. -// -// `device_index` the index of the joystick to query -// returns a joystick identifier or NULL if an error occurred; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_JoystickClose -// See also: SDL_JoystickInstanceID +// returns A joystick identifier, or NULL if an error occurred. pub fn joystick_open(device_index int) &Joystick { return C.SDL_JoystickOpen(device_index) } -fn C.SDL_JoystickFromInstanceID(instance_id C.SDL_JoystickID) &C.SDL_Joystick - -// joystick_from_instance_id gets the SDL_Joystick associated with an instance id. -// -// `instance_id` the instance id to get the SDL_Joystick for -// returns an SDL_Joystick on success or NULL on failure; call SDL_GetError() -// for more information. -// -// NOTE This function is available since SDL 2.0.4. -pub fn joystick_from_instance_id(instance_id JoystickID) &Joystick { - return C.SDL_JoystickFromInstanceID(C.SDL_JoystickID(instance_id)) -} - -fn C.SDL_JoystickFromPlayerIndex(player_index int) &C.SDL_Joystick +fn C.SDL_JoystickFromInstanceID(joyid C.SDL_JoystickID) &C.SDL_Joystick -// joystick_from_player_index gets the SDL_Joystick associated with a player index. -// -// `player_index` the player index to get the SDL_Joystick for -// returns an SDL_Joystick on success or NULL on failure; call SDL_GetError() -// for more information. -// -// NOTE This function is available since SDL 2.0.12. -pub fn joystick_from_player_index(player_index int) &Joystick { - return C.SDL_JoystickFromPlayerIndex(player_index) -} - -fn C.SDL_JoystickAttachVirtual(@type C.SDL_JoystickType, naxes int, nbuttons int, nhats int) int - -// joystick_attach_virtual attaches a new virtual joystick. -// -// returns the joystick's device index, or -1 if an error occurred. -// -// NOTE This function is available since SDL 2.0.14. -pub fn joystick_attach_virtual(@type JoystickType, naxes int, nbuttons int, nhats int) int { - return C.SDL_JoystickAttachVirtual(C.SDL_JoystickType(@type), naxes, nbuttons, nhats) -} - -// The structure that defines an extended virtual joystick description -// -// The caller must zero the structure and then initialize the version with `SDL_VIRTUAL_JOYSTICK_DESC_VERSION` before passing it to SDL_JoystickAttachVirtualEx() -// All other elements of this structure are optional and can be left 0. -// -// See also: SDL_JoystickAttachVirtualEx -@[typedef] -pub struct C.SDL_VirtualJoystickDesc { -pub mut: - version u16 // `SDL_VIRTUAL_JOYSTICK_DESC_VERSION` - @type u16 // `SDL_JoystickType` - naxes u16 // the number of axes on this joystick - nbuttons u16 // the number of buttons on this joystick - nhats u16 // the number of hats on this joystick - vendor_id u16 // the USB vendor ID of this joystick - product_id u16 // the USB product ID of this joystick - padding u16 // unused - button_mask u32 // A mask of which buttons are valid for this controllere.g. (1 << SDL_CONTROLLER_BUTTON_A) - axis_mask u32 // A mask of which axes are valid for this controllere.g. (1 << SDL_CONTROLLER_AXIS_LEFTX) - name &char // the name of the joystick - userdata voidptr // User data pointer passed to callbacks - // - Update fn (userdata voidptr) // Called when the joystick state should be updated - SetPlayerIndex fn (userdata voidptr, player_index int) // Called when the player index is set - Rumble fn (userdata voidptr, low_frequency_rumble u16, high_frequency_rumble u16) // Implements SDL_JoystickRumble() - RumbleTrigger fn (userdata voidptr, left_rumble u16, right_rumble u16) // Implements SDL_JoystickRumbleTriggers() - SetLED fn (userdata voidptr, red u8, green u8, blue u8) // Implements SDL_JoystickSetLED() - SendEffect fn (userdata voidptr, const_data voidptr, size int) // Implements SDL_JoystickSendEffect() -} - -pub type VirtualJoystickDesc = C.SDL_VirtualJoystickDesc - -// virtual_joystick_desc_version is the current version of the SDL_VirtualJoystickDesc structure -pub const virtual_joystick_desc_version = C.SDL_VIRTUAL_JOYSTICK_DESC_VERSION // 1 - -fn C.SDL_JoystickAttachVirtualEx(const_desc &C.SDL_VirtualJoystickDesc) int - -// joystick_attach_virtual_ex attachs a new virtual joystick with extended properties. -// -// returns the joystick's device index, or -1 if an error occurred. -// -// NOTE This function is available since SDL 2.24.0. -pub fn joystick_attach_virtual_ex(const_desc &VirtualJoystickDesc) int { - return C.SDL_JoystickAttachVirtualEx(const_desc) -} - -fn C.SDL_JoystickDetachVirtual(device_index int) int - -// joystick_detach_virtual detachs a virtual joystick. -// -// `device_index` a value previously returned from -// SDL_JoystickAttachVirtual() -// returns 0 on success, or -1 if an error occurred. -// -// NOTE This function is available since SDL 2.0.14. -pub fn joystick_detach_virtual(device_index int) int { - return C.SDL_JoystickDetachVirtual(device_index) -} - -fn C.SDL_JoystickIsVirtual(device_index int) bool - -// joystick_is_virtual queries whether or not the joystick at a given device index is virtual. -// -// `device_index` a joystick device index. -// returns SDL_TRUE if the joystick is virtual, SDL_FALSE otherwise. -// -// NOTE This function is available since SDL 2.0.14. -pub fn joystick_is_virtual(device_index int) bool { - return C.SDL_JoystickIsVirtual(device_index) -} - -fn C.SDL_JoystickSetVirtualAxis(joystick &C.SDL_Joystick, axis int, value i16) int - -// joystick_set_virtual_axis sets values on an opened, virtual-joystick's axis. -// -// Please note that values set here will not be applied until the next call to -// SDL_JoystickUpdate, which can either be called directly, or can be called -// indirectly through various other SDL APIs, including, but not limited to -// the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout, -// SDL_WaitEvent. -// -// Note that when sending trigger axes, you should scale the value to the full -// range of Sint16. For example, a trigger at rest would have the value of -// `SDL_JOYSTICK_AXIS_MIN`. -// -// `joystick` the virtual joystick on which to set state. -// `axis` the specific axis on the virtual joystick to set. -// `value` the new value for the specified axis. -// returns 0 on success, -1 on error. -// -// NOTE This function is available since SDL 2.0.14. -pub fn joystick_set_virtual_axis(joystick &Joystick, axis int, value i16) int { - return C.SDL_JoystickSetVirtualAxis(joystick, axis, value) -} - -fn C.SDL_JoystickSetVirtualButton(joystick &C.SDL_Joystick, button int, value u8) int - -// joystick_set_virtual_button sets values on an opened, virtual-joystick's button. -// -// Please note that values set here will not be applied until the next call to -// SDL_JoystickUpdate, which can either be called directly, or can be called -// indirectly through various other SDL APIs, including, but not limited to -// the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout, -// SDL_WaitEvent. -// -// `joystick` the virtual joystick on which to set state. -// `button` the specific button on the virtual joystick to set. -// `value` the new value for the specified button. -// returns 0 on success, -1 on error. -// -// NOTE This function is available since SDL 2.0.14. -pub fn joystick_set_virtual_button(joystick &Joystick, button int, value u8) int { - return C.SDL_JoystickSetVirtualButton(joystick, button, value) -} - -fn C.SDL_JoystickSetVirtualHat(joystick &C.SDL_Joystick, hat int, value u8) int - -// joystick_set_virtual_hat sets values on an opened, virtual-joystick's hat. -// -// Please note that values set here will not be applied until the next call to -// SDL_JoystickUpdate, which can either be called directly, or can be called -// indirectly through various other SDL APIs, including, but not limited to -// the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout, -// SDL_WaitEvent. -// -// `joystick` the virtual joystick on which to set state. -// `hat` the specific hat on the virtual joystick to set. -// `value` the new value for the specified hat. -// returns 0 on success, -1 on error. -// -// NOTE This function is available since SDL 2.0.14. -pub fn joystick_set_virtual_hat(joystick &C.SDL_Joystick, hat int, value u8) int { - return C.SDL_JoystickSetVirtualHat(joystick, hat, value) +// joystick_from_instance_id returns the SDL_Joystick associated with an instance id. +pub fn joystick_from_instance_id(joyid JoystickID) &Joystick { + return C.SDL_JoystickFromInstanceID(C.SDL_JoystickID(joyid)) } fn C.SDL_JoystickName(joystick &C.SDL_Joystick) &char -// joystick_name gets the implementation dependent name of a joystick. -// -// `joystick` the SDL_Joystick obtained from SDL_JoystickOpen() -// returns the name of the selected joystick. If no name can be found, this -// function returns NULL; call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_JoystickNameForIndex -// See also: SDL_JoystickOpen +// joystick_name returns the name for this currently opened joystick. +// If no name can be found, this function returns NULL. pub fn joystick_name(joystick &Joystick) &char { return C.SDL_JoystickName(joystick) } -fn C.SDL_JoystickPath(joystick &C.SDL_Joystick) &char +fn C.SDL_JoystickGetGUID(joystick &C.SDL_Joystick) C.SDL_JoystickGUID -// joystick_path gets the implementation dependent path of a joystick. -// -// `joystick` the SDL_Joystick obtained from SDL_JoystickOpen() -// returns the path of the selected joystick. If no path can be found, this -// function returns NULL; call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.24.0. -// -// See also: SDL_JoystickPathForIndex -pub fn joystick_path(joystick &Joystick) &char { - return C.SDL_JoystickPath(joystick) -} - -fn C.SDL_JoystickGetPlayerIndex(joystick &C.SDL_Joystick) int - -// joystick_get_player_index gets the player index of an opened joystick. -// -// For XInput controllers this returns the XInput user index. Many joysticks -// will not be able to supply this information. -// -// `joystick` the SDL_Joystick obtained from SDL_JoystickOpen() -// returns the player index, or -1 if it's not available. -// -// NOTE This function is available since SDL 2.0.9. -pub fn joystick_get_player_index(joystick &Joystick) int { - return C.SDL_JoystickGetPlayerIndex(joystick) -} - -fn C.SDL_JoystickSetPlayerIndex(joystick &C.SDL_Joystick, player_index int) - -// joystick_set_player_index sets the player index of an opened joystick. -// -// `joystick` the SDL_Joystick obtained from SDL_JoystickOpen() -// `player_index` Player index to assign to this joystick, or -1 to clear -// the player index and turn off player LEDs. -// -// NOTE This function is available since SDL 2.0.12. -pub fn joystick_set_player_index(joystick &Joystick, player_index int) { - C.SDL_JoystickSetPlayerIndex(joystick, player_index) -} - -fn C.SDL_JoystickGetGUID(joystick &C.SDL_Joystick) JoystickGUID - -// joystick_get_guid gets the implementation-dependent GUID for the joystick. -// -// This function requires an open joystick. -// -// `joystick` the SDL_Joystick obtained from SDL_JoystickOpen() -// returns the GUID of the given joystick. If called on an invalid index, -// this function returns a zero GUID; call SDL_GetError() for more -// information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_JoystickGetDeviceGUID -// See also: SDL_JoystickGetGUIDString +// joystick_get_guid returns the GUID for this opened joystick pub fn joystick_get_guid(joystick &Joystick) JoystickGUID { return C.SDL_JoystickGetGUID(joystick) } @@ -551,13 +198,7 @@ pub fn joystick_get_guid(joystick &Joystick) JoystickGUID { fn C.SDL_JoystickGetVendor(joystick &C.SDL_Joystick) u16 // joystick_get_vendor gets the USB vendor ID of an opened joystick, if available. -// // If the vendor ID isn't available this function returns 0. -// -// `joystick` the SDL_Joystick obtained from SDL_JoystickOpen() -// returns the USB vendor ID of the selected joystick, or 0 if unavailable. -// -// NOTE This function is available since SDL 2.0.6. pub fn joystick_get_vendor(joystick &Joystick) u16 { return C.SDL_JoystickGetVendor(joystick) } @@ -565,13 +206,7 @@ pub fn joystick_get_vendor(joystick &Joystick) u16 { fn C.SDL_JoystickGetProduct(joystick &C.SDL_Joystick) u16 // joystick_get_product gets the USB product ID of an opened joystick, if available. -// // If the product ID isn't available this function returns 0. -// -// `joystick` the SDL_Joystick obtained from SDL_JoystickOpen() -// returns the USB product ID of the selected joystick, or 0 if unavailable. -// -// NOTE This function is available since SDL 2.0.6. pub fn joystick_get_product(joystick &Joystick) u16 { return C.SDL_JoystickGetProduct(joystick) } @@ -579,144 +214,43 @@ pub fn joystick_get_product(joystick &Joystick) u16 { fn C.SDL_JoystickGetProductVersion(joystick &C.SDL_Joystick) u16 // joystick_get_product_version gets the product version of an opened joystick, if available. -// // If the product version isn't available this function returns 0. -// -// `joystick` the SDL_Joystick obtained from SDL_JoystickOpen() -// returns the product version of the selected joystick, or 0 if unavailable. -// -// NOTE This function is available since SDL 2.0.6. pub fn joystick_get_product_version(joystick &Joystick) u16 { return C.SDL_JoystickGetProductVersion(joystick) } -fn C.SDL_JoystickGetFirmwareVersion(joystick &C.SDL_Joystick) u16 - -// joystick_get_firmware_version gets the firmware version of an opened joystick, if available. -// -// If the firmware version isn't available this function returns 0. -// -// `joystick` the SDL_Joystick obtained from SDL_JoystickOpen() -// returns the firmware version of the selected joystick, or 0 if -// unavailable. -// -// NOTE This function is available since SDL 2.24.0. -pub fn joystick_get_firmware_version(joystick &Joystick) u16 { - return C.SDL_JoystickGetFirmwareVersion(joystick) -} - -fn C.SDL_JoystickGetSerial(joystick &C.SDL_Joystick) &char - -// joystick_get_serial gets the serial number of an opened joystick, if available. -// -// Returns the serial number of the joystick, or NULL if it is not available. -// -// `joystick` the SDL_Joystick obtained from SDL_JoystickOpen() -// returns the serial number of the selected joystick, or NULL if -// unavailable. -// -// NOTE This function is available since SDL 2.0.14. -pub fn joystick_get_serial(joystick &Joystick) &char { - return C.SDL_JoystickGetSerial(joystick) -} - fn C.SDL_JoystickGetType(joystick &C.SDL_Joystick) JoystickType // joystick_get_type gets the type of an opened joystick. -// -// `joystick` the SDL_Joystick obtained from SDL_JoystickOpen() -// returns the SDL_JoystickType of the selected joystick. -// -// NOTE This function is available since SDL 2.0.6. pub fn joystick_get_type(joystick &Joystick) JoystickType { return unsafe { JoystickType(int(C.SDL_JoystickGetType(joystick))) } } fn C.SDL_JoystickGetGUIDString(guid C.SDL_JoystickGUID, psz_guid &char, cb_guid int) -// joystick_get_guid_string gets an ASCII string representation for a given SDL_JoystickGUID. -// -// You should supply at least 33 bytes for pszGUID. -// -// `guid` the SDL_JoystickGUID you wish to convert to string -// `pszGUID` buffer in which to write the ASCII string -// `cbGUID` the size of pszGUID -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_JoystickGetDeviceGUID -// See also: SDL_JoystickGetGUID -// See also: SDL_JoystickGetGUIDFromString +// joystick_get_guid_string returns a string representation for this guid. pszGUID must point to at least 33 bytes +// (32 for the string plus a NULL terminator). pub fn joystick_get_guid_string(guid JoystickGUID, psz_guid &char, cb_guid int) { - C.SDL_JoystickGetGUIDString(C.SDL_JoystickGUID(guid), psz_guid, cb_guid) + C.SDL_JoystickGetGUIDString(guid, psz_guid, cb_guid) } -fn C.SDL_JoystickGetGUIDFromString(pch_guid &char) JoystickGUID +fn C.SDL_JoystickGetGUIDFromString(pch_guid &char) C.SDL_JoystickGUID -// joystick_get_guid_from_string converts a GUID string into a SDL_JoystickGUID structure. -// -// Performs no error checking. If this function is given a string containing -// an invalid GUID, the function will silently succeed, but the GUID generated -// will not be useful. -// -// `pchGUID` string containing an ASCII representation of a GUID -// returns a SDL_JoystickGUID structure. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_JoystickGetGUIDString -pub fn joystick_get_guid_from_string(pch_guid &char) JoystickGUID { +// joystick_get_guid_from_string converts a string into a joystick guid +pub fn joystick_get_guid_from_string(pch_guid &char) C.SDL_JoystickGUID { return C.SDL_JoystickGetGUIDFromString(pch_guid) } -fn C.SDL_GetJoystickGUIDInfo(guid C.SDL_JoystickGUID, vendor &u16, product &u16, version &u16, crc16 &u16) - -// get_joystick_guid_info gets the device information encoded in a SDL_JoystickGUID structure -// -// `guid` the SDL_JoystickGUID you wish to get info about -// `vendor` A pointer filled in with the device VID, or 0 if not -// available -// `product` A pointer filled in with the device PID, or 0 if not -// available -// `version` A pointer filled in with the device version, or 0 if not -// available -// `crc16` A pointer filled in with a CRC used to distinguish different -// products with the same VID/PID, or 0 if not available -// -// NOTE This function is available since SDL 2.26.0. -// -// See also: SDL_JoystickGetDeviceGUID -pub fn get_joystick_guid_info(guid JoystickGUID, vendor &u16, product &u16, version &u16, crc16 &u16) { - C.SDL_GetJoystickGUIDInfo(C.SDL_JoystickGUID(guid), vendor, product, version, crc16) -} - fn C.SDL_JoystickGetAttached(joystick &C.SDL_Joystick) bool -// joystick_get_attached gets the status of a specified joystick. -// -// `joystick` the joystick to query -// returns SDL_TRUE if the joystick has been opened, SDL_FALSE if it has not; -// call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_JoystickClose -// See also: SDL_JoystickOpen +// joystick_get_attached returns SDL_TRUE if the joystick has been opened and currently connected, or SDL_FALSE if it has not. pub fn joystick_get_attached(joystick &Joystick) bool { return C.SDL_JoystickGetAttached(joystick) } fn C.SDL_JoystickInstanceID(joystick &C.SDL_Joystick) JoystickID -// joystick_instance_id gets the instance ID of an opened joystick. -// -// `joystick` an SDL_Joystick structure containing joystick information -// returns the instance ID of the specified joystick on success or a negative -// error code on failure; call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_JoystickOpen +// joystick_instance_id gets the instance ID of an opened joystick or -1 if the joystick is invalid. pub fn joystick_instance_id(joystick &Joystick) JoystickID { return C.SDL_JoystickInstanceID(joystick) } @@ -724,20 +258,6 @@ pub fn joystick_instance_id(joystick &Joystick) JoystickID { fn C.SDL_JoystickNumAxes(joystick &C.SDL_Joystick) int // joystick_num_axes gets the number of general axis controls on a joystick. -// -// Often, the directional pad on a game controller will either look like 4 -// separate buttons or a POV hat, and not axes, but all of this is up to the -// device and platform. -// -// `joystick` an SDL_Joystick structure containing joystick information -// returns the number of axis controls/number of axes on success or a -// negative error code on failure; call SDL_GetError() for more -// information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_JoystickGetAxis -// See also: SDL_JoystickOpen pub fn joystick_num_axes(joystick &Joystick) int { return C.SDL_JoystickNumAxes(joystick) } @@ -746,18 +266,8 @@ fn C.SDL_JoystickNumBalls(joystick &C.SDL_Joystick) int // joystick_num_balls gets the number of trackballs on a joystick. // -// Joystick trackballs have only relative motion events associated with them -// and their state cannot be polled. -// -// Most joysticks do not have trackballs. -// -// `joystick` an SDL_Joystick structure containing joystick information -// returns the number of trackballs on success or a negative error code on -// failure; call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_JoystickGetBall +// Joystick trackballs have only relative motion events associated +// with them and their state cannot be polled. pub fn joystick_num_balls(joystick &Joystick) int { return C.SDL_JoystickNumBalls(joystick) } @@ -765,72 +275,36 @@ pub fn joystick_num_balls(joystick &Joystick) int { fn C.SDL_JoystickNumHats(joystick &C.SDL_Joystick) int // joystick_num_hats gets the number of POV hats on a joystick. -// -// `joystick` an SDL_Joystick structure containing joystick information -// returns the number of POV hats on success or a negative error code on -// failure; call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_JoystickGetHat -// See also: SDL_JoystickOpen pub fn joystick_num_hats(joystick &Joystick) int { return C.SDL_JoystickNumHats(joystick) } +fn C.SDL_JoystickUpdate() + fn C.SDL_JoystickNumButtons(joystick &C.SDL_Joystick) int // joystick_num_buttons gets the number of buttons on a joystick. -// -// `joystick` an SDL_Joystick structure containing joystick information -// returns the number of buttons on success or a negative error code on -// failure; call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_JoystickGetButton -// See also: SDL_JoystickOpen pub fn joystick_num_buttons(joystick &Joystick) int { return C.SDL_JoystickNumButtons(joystick) } -fn C.SDL_JoystickUpdate() - // joystick_update updates the current state of the open joysticks. // -// This is called automatically by the event loop if any joystick events are -// enabled. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_JoystickEventState +// This is called automatically by the event loop if any joystick +// events are enabled. pub fn joystick_update() { C.SDL_JoystickUpdate() } fn C.SDL_JoystickEventState(state int) int -// joystick_event_state enable/disables joystick event polling. +// joystick_event_state enables/disables joystick event polling. // // If joystick events are disabled, you must call SDL_JoystickUpdate() -// yourself and manually check the state of the joystick when you want -// joystick information. -// -// It is recommended that you leave joystick event handling enabled. -// -// **WARNING**: Calling this function may delete all events currently in SDL's -// event queue. +// yourself and check the state of the joystick when you want joystick +// information. // -// `state` can be one of `SDL_QUERY`, `SDL_IGNORE`, or `SDL_ENABLE` -// returns 1 if enabled, 0 if disabled, or a negative error code on failure; -// call SDL_GetError() for more information. -// -// If `state` is `SDL_QUERY` then the current state is returned, -// otherwise the new processing state is returned. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GameControllerEventState +// The state can be one of ::SDL_QUERY, ::SDL_ENABLE or ::SDL_IGNORE. pub fn joystick_event_state(state int) int { return C.SDL_JoystickEventState(state) } @@ -839,24 +313,9 @@ fn C.SDL_JoystickGetAxis(joystick &C.SDL_Joystick, axis int) i16 // joystick_get_axis gets the current state of an axis control on a joystick. // -// SDL makes no promises about what part of the joystick any given axis refers -// to. Your game should have some sort of configuration UI to let users -// specify what each axis should be bound to. Alternately, SDL's higher-level -// Game Controller API makes a great effort to apply order to this lower-level -// interface, so you know that a specific axis is the "left thumb stick," etc. -// -// The value returned by SDL_JoystickGetAxis() is a signed integer (-32768 to -// 32767) representing the current position of the axis. It may be necessary -// to impose certain tolerances on these values to account for jitter. -// -// `joystick` an SDL_Joystick structure containing joystick information -// `axis` the axis to query; the axis indices start at index 0 -// returns a 16-bit signed integer representing the current position of the -// axis or 0 on failure; call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. +// The state is a value ranging from -32768 to 32767. // -// See also: SDL_JoystickNumAxes +// The axis indices start at index 0. pub fn joystick_get_axis(joystick &Joystick, axis int) i16 { return C.SDL_JoystickGetAxis(joystick, axis) } @@ -869,12 +328,7 @@ fn C.SDL_JoystickGetAxisInitialState(joystick &C.SDL_Joystick, axis int, state & // // The axis indices start at index 0. // -// `joystick` an SDL_Joystick structure containing joystick information -// `axis` the axis to query; the axis indices start at index 0 -// `state` Upon return, the initial value is supplied here. // returns SDL_TRUE if this axis has any initial value, or SDL_FALSE if not. -// -// NOTE This function is available since SDL 2.0.6. pub fn joystick_get_axis_initial_state(joystick &Joystick, axis int, state &i16) bool { return C.SDL_JoystickGetAxisInitialState(joystick, axis, state) } @@ -883,25 +337,18 @@ fn C.SDL_JoystickGetHat(joystick &C.SDL_Joystick, hat int) u8 // joystick_get_hat gets the current state of a POV hat on a joystick. // -// The returned value will be one of the following positions: -// -// - `SDL_HAT_CENTERED` -// - `SDL_HAT_UP` -// - `SDL_HAT_RIGHT` -// - `SDL_HAT_DOWN` -// - `SDL_HAT_LEFT` -// - `SDL_HAT_RIGHTUP` -// - `SDL_HAT_RIGHTDOWN` -// - `SDL_HAT_LEFTUP` -// - `SDL_HAT_LEFTDOWN` -// -// `joystick` an SDL_Joystick structure containing joystick information -// `hat` the hat index to get the state from; indices start at index 0 -// returns the current hat position. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_JoystickNumHats +// The hat indices start at index 0. +// +// returns The return value is one of the following positions: +// - ::SDL_HAT_CENTERED +// - ::SDL_HAT_UP +// - ::SDL_HAT_RIGHT +// - ::SDL_HAT_DOWN +// - ::SDL_HAT_LEFT +// - ::SDL_HAT_RIGHTUP +// - ::SDL_HAT_RIGHTDOWN +// - ::SDL_HAT_LEFTUP +// - ::SDL_HAT_LEFTDOWN pub fn joystick_get_hat(joystick &Joystick, hat int) u8 { return C.SDL_JoystickGetHat(joystick, hat) } @@ -910,21 +357,9 @@ fn C.SDL_JoystickGetBall(joystick &C.SDL_Joystick, ball int, dx &int, dy &int) i // joystick_get_ball gets the ball axis change since the last poll. // -// Trackballs can only return relative motion since the last call to -// SDL_JoystickGetBall(), these motion deltas are placed into `dx` and `dy`. +// returns 0, or -1 if you passed it invalid parameters. // -// Most joysticks do not have trackballs. -// -// `joystick` the SDL_Joystick to query -// `ball` the ball index to query; ball indices start at index 0 -// `dx` stores the difference in the x axis position since the last poll -// `dy` stores the difference in the y axis position since the last poll -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_JoystickNumBalls +// The ball indices start at index 0. pub fn joystick_get_ball(joystick &Joystick, ball int, dx &int, dy &int) int { return C.SDL_JoystickGetBall(joystick, ball, dx, dy) } @@ -933,165 +368,21 @@ fn C.SDL_JoystickGetButton(joystick &C.SDL_Joystick, button int) u8 // joystick_get_button gets the current state of a button on a joystick. // -// `joystick` an SDL_Joystick structure containing joystick information -// `button` the button index to get the state from; indices start at -// index 0 -// returns 1 if the specified button is pressed, 0 otherwise. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_JoystickNumButtons +// The button indices start at index 0. pub fn joystick_get_button(joystick &Joystick, button int) u8 { return C.SDL_JoystickGetButton(joystick, button) } -fn C.SDL_JoystickRumble(joystick &C.SDL_Joystick, low_frequency_rumble u16, high_frequency_rumble u16, duration_ms u32) int - -// joystick_rumble starts a rumble effect. -// -// Each call to this function cancels any previous rumble effect, and calling -// it with 0 intensity stops any rumbling. -// -// `joystick` The joystick to vibrate -// `low_frequency_rumble` The intensity of the low frequency (left) -// rumble motor, from 0 to 0xFFFF -// `high_frequency_rumble` The intensity of the high frequency (right) -// rumble motor, from 0 to 0xFFFF -// `duration_ms` The duration of the rumble effect, in milliseconds -// returns 0, or -1 if rumble isn't supported on this joystick -// -// NOTE This function is available since SDL 2.0.9. -// -// See also: SDL_JoystickHasRumble -pub fn joystick_rumble(joystick &Joystick, low_frequency_rumble u16, high_frequency_rumble u16, duration_ms u32) int { - return C.SDL_JoystickRumble(joystick, low_frequency_rumble, high_frequency_rumble, - duration_ms) -} - -fn C.SDL_JoystickRumbleTriggers(joystick &C.SDL_Joystick, left_rumble u16, right_rumble u16, duration_ms u32) int - -// joystick_rumble_triggers starts a rumble effect in the joystick's triggers -// -// Each call to this function cancels any previous trigger rumble effect, and -// calling it with 0 intensity stops any rumbling. -// -// Note that this is rumbling of the _triggers_ and not the game controller as -// a whole. This is currently only supported on Xbox One controllers. If you -// want the (more common) whole-controller rumble, use SDL_JoystickRumble() -// instead. -// -// `joystick` The joystick to vibrate -// `left_rumble` The intensity of the left trigger rumble motor, from 0 -// to 0xFFFF -// `right_rumble` The intensity of the right trigger rumble motor, from 0 -// to 0xFFFF -// `duration_ms` The duration of the rumble effect, in milliseconds -// returns 0, or -1 if trigger rumble isn't supported on this joystick -// -// NOTE This function is available since SDL 2.0.14. -// -// See also: SDL_JoystickHasRumbleTriggers -pub fn joystick_rumble_triggers(joystick &Joystick, left_rumble u16, right_rumble u16, duration_ms u32) int { - return C.SDL_JoystickRumbleTriggers(joystick, left_rumble, right_rumble, duration_ms) -} - -fn C.SDL_JoystickHasLED(joystick &C.SDL_Joystick) bool - -// joystick_has_led querys whether a joystick has an LED. -// -// An example of a joystick LED is the light on the back of a PlayStation 4's -// DualShock 4 controller. -// -// `joystick` The joystick to query -// returns SDL_TRUE if the joystick has a modifiable LED, SDL_FALSE otherwise. -// -// NOTE This function is available since SDL 2.0.14. -pub fn joystick_has_led(joystick &Joystick) bool { - return C.SDL_JoystickHasLED(joystick) -} - -fn C.SDL_JoystickHasRumble(joystick &C.SDL_Joystick) bool - -// joystick_has_rumble querys whether a joystick has rumble support. -// -// `joystick` The joystick to query -// returns SDL_TRUE if the joystick has rumble, SDL_FALSE otherwise. -// -// NOTE This function is available since SDL 2.0.18. -// -// See also: SDL_JoystickRumble -pub fn joystick_has_rumble(joystick &Joystick) bool { - return C.SDL_JoystickHasRumble(joystick) -} - -fn C.SDL_JoystickHasRumbleTriggers(joystick &C.SDL_Joystick) bool - -// joystick_has_rumble_triggers querys whether a joystick has rumble support on triggers. -// -// `joystick` The joystick to query -// returns SDL_TRUE if the joystick has trigger rumble, SDL_FALSE otherwise. -// -// NOTE This function is available since SDL 2.0.18. -// -// See also: SDL_JoystickRumbleTriggers -pub fn joystick_has_rumble_triggers(joystick &Joystick) bool { - return C.SDL_JoystickHasRumbleTriggers(joystick) -} - -fn C.SDL_JoystickSetLED(joystick &Joystick, red u8, green u8, blue u8) int - -// joystick_set_led updates a joystick's LED color. -// -// An example of a joystick LED is the light on the back of a PlayStation 4's -// DualShock 4 controller. -// -// `joystick` The joystick to update -// `red` The intensity of the red LED -// `green` The intensity of the green LED -// `blue` The intensity of the blue LED -// returns 0 on success, -1 if this joystick does not have a modifiable LED -// -// NOTE This function is available since SDL 2.0.14. -pub fn joystick_set_led(joystick &Joystick, red u8, green u8, blue u8) int { - return C.SDL_JoystickSetLED(joystick, red, green, blue) -} - -fn C.SDL_JoystickSendEffect(joystick &C.SDL_Joystick, const_data voidptr, size int) int - -// joystick_send_effect sends a joystick specific effect packet -// -// `joystick` The joystick to affect -// `data` The data to send to the joystick -// `size` The size of the data to send to the joystick -// returns 0, or -1 if this joystick or driver doesn't support effect packets -// -// NOTE This function is available since SDL 2.0.16. -pub fn joystick_send_effect(joystick &Joystick, const_data voidptr, size int) int { - return C.SDL_JoystickSendEffect(joystick, const_data, size) -} - fn C.SDL_JoystickClose(joystick &C.SDL_Joystick) // joystick_close closes a joystick previously opened with SDL_JoystickOpen(). -// -// `joystick` The joystick device to close -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_JoystickOpen pub fn joystick_close(joystick &Joystick) { C.SDL_JoystickClose(joystick) } fn C.SDL_JoystickCurrentPowerLevel(joystick &C.SDL_Joystick) JoystickPowerLevel -// joystick_current_power_level gets the battery level of a joystick as SDL_JoystickPowerLevel. -// -// `joystick` the SDL_Joystick to query -// returns the current battery level as SDL_JoystickPowerLevel on success or -// `SDL_JOYSTICK_POWER_UNKNOWN` if it is unknown -// -// NOTE This function is available since SDL 2.0.4. +// joystick_current_power_level returns the battery level of this joystick pub fn joystick_current_power_level(joystick &Joystick) JoystickPowerLevel { return unsafe { JoystickPowerLevel(int(C.SDL_JoystickCurrentPowerLevel(joystick))) } } diff --git a/keyboard.c.v b/keyboard.c.v index 9fc06ba1..73a09619 100644 --- a/keyboard.c.v +++ b/keyboard.c.v @@ -24,11 +24,7 @@ pub type Keysym = C.SDL_Keysym fn C.SDL_GetKeyboardFocus() &C.SDL_Window -// get_keyboard_focus queries the window which currently has keyboard focus. -// -// returns the window with keyboard focus. -// -// NOTE This function is available since SDL 2.0.0. +// get_keyboard_focus gets the window which currently has keyboard focus. pub fn get_keyboard_focus() &Window { return C.SDL_GetKeyboardFocus() } @@ -37,59 +33,26 @@ fn C.SDL_GetKeyboardState(numkeys &int) &u8 // get_keyboard_state gets a snapshot of the current state of the keyboard. // -// The pointer returned is a pointer to an internal SDL array. It will be -// valid for the whole lifetime of the application and should not be freed by -// the caller. -// -// A array element with a value of 1 means that the key is pressed and a value -// of 0 means that it is not. Indexes into this array are obtained by using -// SDL_Scancode values. -// -// Use SDL_PumpEvents() to update the state array. -// -// This function gives you the current state after all events have been -// processed, so if a key or button has been pressed and released before you -// process events, then the pressed state will never show up in the -// SDL_GetKeyboardState() calls. -// -// Note: This function doesn't take into account whether shift has been -// pressed or not. -// -// `numkeys` if non-NULL, receives the length of the returned array -// returns a pointer to an array of key states. +// `numkeys` if non-NULL, receives the length of the returned array. // -// NOTE This function is available since SDL 2.0.0. +// returns An array of key states. Indexes into this array are obtained by using ::SDL_Scancode values. // -// See also: SDL_PumpEvents -// See also: SDL_ResetKeyboard +// **Example**: +/* +``` +const Uint8//state = SDL_GetKeyboardState(NULL); +if ( state[SDL_SCANCODE_RETURN] ) { + printf(" is pressed.\n"); +} +``` +*/ pub fn get_keyboard_state(numkeys &int) &u8 { return C.SDL_GetKeyboardState(numkeys) } -fn C.SDL_ResetKeyboard() - -// reset_keyboard clears the state of the keyboard -// -// This function will generate key up events for all pressed keys. -// -// NOTE This function is available since SDL 2.24.0. -// -// See also: SDL_GetKeyboardState -pub fn reset_keyboard() { - C.SDL_ResetKeyboard() -} - fn C.SDL_GetModState() Keymod // get_mod_state gets the current key modifier state for the keyboard. -// -// returns an OR'd combination of the modifier keys for the keyboard. See -// SDL_Keymod for details. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetKeyboardState -// See also: SDL_SetModState pub fn get_mod_state() Keymod { return unsafe { Keymod(int(C.SDL_GetModState())) } } @@ -98,37 +61,19 @@ fn C.SDL_SetModState(modstate C.SDL_Keymod) // set_mod_state sets the current key modifier state for the keyboard. // -// The inverse of SDL_GetModState(), SDL_SetModState() allows you to impose -// modifier key states on your application. Simply pass your desired modifier -// states into `modstate`. This value may be a bitwise, OR'd combination of -// SDL_Keymod values. -// -// This does not change the keyboard state, only the key modifier flags that -// SDL reports. -// -// `modstate` the desired SDL_Keymod for the keyboard -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetModState +// NOTE This does not change the keyboard state, only the key modifier flags. pub fn set_mod_state(modstate Keymod) { C.SDL_SetModState(C.SDL_Keymod(modstate)) } fn C.SDL_GetKeyFromScancode(scancode C.SDL_Scancode) Keycode -// get_key_from_scancode gets the key code corresponding to the given scancode according to the -// current keyboard layout. -// -// See SDL_Keycode for details. -// -// `scancode` the desired SDL_Scancode to query -// returns the SDL_Keycode that corresponds to the given SDL_Scancode. +// get_key_from_scancode gets the key code corresponding to the given scancode according +// to the current keyboard layout. // -// NOTE This function is available since SDL 2.0.0. +// See ::SDL_Keycode for details. // -// See also: SDL_GetKeyName -// See also: SDL_GetScancodeFromKey +// See also: SDL_GetKeyName() pub fn get_key_from_scancode(scancode Scancode) Keycode { return Keycode(int(C.SDL_GetKeyFromScancode(C.SDL_Scancode(scancode)))) } @@ -136,17 +81,11 @@ pub fn get_key_from_scancode(scancode Scancode) Keycode { fn C.SDL_GetScancodeFromKey(key C.SDL_Keycode) Scancode // get_scancode_from_key gets the scancode corresponding to the given key code according to the -// current keyboard layout. +// current keyboard layout. // -// See SDL_Scancode for details. +// See ::SDL_Scancode for details. // -// `key` the desired SDL_Keycode to query -// returns the SDL_Scancode that corresponds to the given SDL_Keycode. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetKeyFromScancode -// See also: SDL_GetScancodeName +// See also: SDL_GetScancodeName() pub fn get_scancode_from_key(key Keycode) Scancode { return unsafe { Scancode(int(C.SDL_GetScancodeFromKey(C.SDL_Keycode(key)))) } } @@ -155,42 +94,22 @@ fn C.SDL_GetScancodeName(scancode C.SDL_Scancode) &char // get_scancode_name gets a human-readable name for a scancode. // -// See SDL_Scancode for details. -// -// **WARNING**: The returned name is by design not stable across platforms, -// e.g. the name for `SDL_SCANCODE_LGUI` is "Left GUI" under Linux but "Left -// Windows" under Microsoft Windows, and some scancodes like -// `SDL_SCANCODE_NONUSBACKSLASH` don't have any name at all. There are even -// scancodes that share names, e.g. `SDL_SCANCODE_RETURN` and -// `SDL_SCANCODE_RETURN2` (both called "Return"). This function is therefore -// unsuitable for creating a stable cross-platform two-way mapping between -// strings and scancodes. +// returns A pointer to the name for the scancode. +// If the scancode doesn't have a name, this function returns +// an empty string (""). // -// `scancode` the desired SDL_Scancode to query -// returns a pointer to the name for the scancode. If the scancode doesn't -// have a name this function returns an empty string (""). -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetScancodeFromKey -// See also: SDL_GetScancodeFromName +// See also: SDL_Scancode pub fn get_scancode_name(scancode Scancode) &char { return C.SDL_GetScancodeName(C.SDL_Scancode(scancode)) } fn C.SDL_GetScancodeFromName(name &char) Scancode -// get_scancode_from_name gets a scancode from a human-readable name. +// get_scancode_from_name gets a scancode from a human-readable name // -// `name` the human-readable scancode name -// returns the SDL_Scancode, or `SDL_SCANCODE_UNKNOWN` if the name wasn't -// recognized; call SDL_GetError() for more information. +// returns scancode, or SDL_SCANCODE_UNKNOWN if the name wasn't recognized // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetKeyFromName -// See also: SDL_GetScancodeFromKey -// See also: SDL_GetScancodeName +// See also: SDL_Scancode pub fn get_scancode_from_name(name &char) Scancode { return unsafe { Scancode(int(C.SDL_GetScancodeFromName(name))) } } @@ -199,36 +118,23 @@ fn C.SDL_GetKeyName(key C.SDL_Keycode) &char // get_key_name gets a human-readable name for a key. // -// See SDL_Scancode and SDL_Keycode for details. -// -// `key` the desired SDL_Keycode to query -// returns a pointer to a UTF-8 string that stays valid at least until the -// next call to this function. If you need it around any longer, you -// must copy it. If the key doesn't have a name, this function -// returns an empty string (""). +// returns A pointer to a UTF-8 string that stays valid at least until the next +// call to this function. If you need it around any longer, you must +// copy it. If the key doesn't have a name, this function returns an +// empty string (""). // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetKeyFromName -// See also: SDL_GetKeyFromScancode -// See also: SDL_GetScancodeFromKey +// See also: SDL_Keycode pub fn get_key_name(key Keycode) &char { return C.SDL_GetKeyName(C.SDL_Keycode(key)) } fn C.SDL_GetKeyFromName(name &char) Keycode -// get_key_from_name gets a key code from a human-readable name. -// -// `name` the human-readable key name -// returns key code, or `SDLK_UNKNOWN` if the name wasn't recognized; call -// SDL_GetError() for more information. +// get_key_from_name gets a key code from a human-readable name // -// NOTE This function is available since SDL 2.0.0. +// returns key code, or SDLK_UNKNOWN if the name wasn't recognized // -// See also: SDL_GetKeyFromScancode -// See also: SDL_GetKeyName -// See also: SDL_GetScancodeFromName +// See also: SDL_Keycode pub fn get_key_from_name(name &char) Keycode { return Keycode(int(C.SDL_GetKeyFromName(name))) } @@ -236,31 +142,21 @@ pub fn get_key_from_name(name &char) Keycode { fn C.SDL_StartTextInput() // start_text_input starts accepting Unicode text input events. +// This function will show the on-screen keyboard if supported. // -// This function will start accepting Unicode text input events in the focused -// SDL window, and start emitting SDL_TextInputEvent (SDL_TEXTINPUT) and -// SDL_TextEditingEvent (SDL_TEXTEDITING) events. Please use this function in -// pair with SDL_StopTextInput(). -// -// On some platforms using this function activates the screen keyboard. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_SetTextInputRect -// See also: SDL_StopTextInput +// See also: SDL_StopTextInput() +// See also: SDL_SetTextInputRect() +// See also: SDL_HasScreenKeyboardSupport() pub fn start_text_input() { C.SDL_StartTextInput() } fn C.SDL_IsTextInputActive() bool -// is_text_input_active checks whether or not Unicode text input events are enabled. -// -// returns SDL_TRUE if text input events are enabled else SDL_FALSE. +// is_text_input_active returns whether or not Unicode text input events are enabled. // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_StartTextInput +// See also: SDL_StartTextInput() +// See also: SDL_StopTextInput() pub fn is_text_input_active() bool { return C.SDL_IsTextInputActive() } @@ -268,84 +164,46 @@ pub fn is_text_input_active() bool { fn C.SDL_StopTextInput() // stop_text_input stops receiving any text input events. +// This function will hide the on-screen keyboard if supported. // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_StartTextInput +// See also: SDL_StartTextInput() +// See also: SDL_HasScreenKeyboardSupport() pub fn stop_text_input() { C.SDL_StopTextInput() } -fn C.SDL_ClearComposition() - -// clear_composition dismiss the composition window/IME without disabling the subsystem. -// -// NOTE This function is available since SDL 2.0.22. -// -// See also: SDL_StartTextInput -// See also: SDL_StopTextInput -pub fn clear_composition() { - C.SDL_ClearComposition() -} - -fn C.SDL_IsTextInputShown() bool - -// is_text_input_shown returns if an IME Composite or Candidate window is currently shown. -// -// NOTE This function is available since SDL 2.0.22. -pub fn is_text_input_shown() bool { - return C.SDL_IsTextInputShown() -} - fn C.SDL_SetTextInputRect(rect &C.SDL_Rect) -// set_text_input_rect sets the rectangle used to type Unicode text inputs. Native input methods -// will place a window with word suggestions near it, without covering the -// text being inputted. -// -// To start text input in a given location, this function is intended to be -// called before SDL_StartTextInput, although some platforms support moving -// the rectangle even while text input (and a composition) is active. -// -// Note: If you want to use the system native IME window, try setting hint -// **SDL_HINT_IME_SHOW_UI** to **1**, otherwise this function won't give you -// any feedback. -// -// `rect` the SDL_Rect structure representing the rectangle to receive -// text (ignored if NULL) -// -// NOTE This function is available since SDL 2.0.0. +// set_text_input_rect sets the rectangle used to type Unicode text inputs. +// This is used as a hint for IME and on-screen keyboard placement. // -// See also: SDL_StartTextInput -pub fn set_text_input_rect(const_rect &Rect) { - C.SDL_SetTextInputRect(const_rect) +// See also: SDL_StartTextInput() +pub fn set_text_input_rect(rect &Rect) { + C.SDL_SetTextInputRect(rect) } fn C.SDL_HasScreenKeyboardSupport() bool -// has_screen_keyboard_support checks whether the platform has screen keyboard support. +// has_screen_keyboard_support returns whether the platform has some screen keyboard support. // -// returns SDL_TRUE if the platform has some screen keyboard support or -// SDL_FALSE if not. +// returns SDL_TRUE if some keyboard support is available else SDL_FALSE. // -// NOTE This function is available since SDL 2.0.0. +// NOTE Not all screen keyboard functions are supported on all platforms. // -// See also: SDL_StartTextInput -// See also: SDL_IsScreenKeyboardShown +// See also: SDL_IsScreenKeyboardShown() pub fn has_screen_keyboard_support() bool { return C.SDL_HasScreenKeyboardSupport() } fn C.SDL_IsScreenKeyboardShown(window &C.SDL_Window) bool -// is_screen_keyboard_shown checks whether the screen keyboard is shown for given window. +// is_screen_keyboard_shown returns whether the screen keyboard is shown for given window. // -// `window` the window for which screen keyboard should be queried -// returns SDL_TRUE if screen keyboard is shown or SDL_FALSE if not. +// `window` The window for which screen keyboard should be queried. // -// NOTE This function is available since SDL 2.0.0. +// returns SDL_TRUE if screen keyboard is shown else SDL_FALSE. // -// See also: SDL_HasScreenKeyboardSupport +// See also: SDL_HasScreenKeyboardSupport() pub fn is_screen_keyboard_shown(window &Window) bool { return C.SDL_IsScreenKeyboardShown(window) } diff --git a/keycode.c.v b/keycode.c.v index 0258c8a6..0c50dec8 100644 --- a/keycode.c.v +++ b/keycode.c.v @@ -15,7 +15,7 @@ module sdl // an SDLK_* constant for those keys that do not generate characters. // // A special exception is the number keys at the top of the keyboard which -// map to SDLK_0...SDLK_9 on AZERTY layouts. +// always map to SDLK_0...SDLK_9, regardless of layout. // Sint32 C.SDL_Keycode; pub type Keycode = int @@ -42,20 +42,18 @@ pub enum Keymod { num = C.KMOD_NUM // 0x1000 caps = C.KMOD_CAPS // 0x2000 mode = C.KMOD_MODE // 0x4000 - scroll = C.KMOD_SCROLL // 0x8000 + reserved = C.KMOD_RESERVED // 0x8000 // ctrl = C.KMOD_CTRL shift = C.KMOD_SHIFT alt = C.KMOD_ALT gui = C.KMOD_GUI - // - reserved = C.KMOD_RESERVED // (KMOD_SCROLL) This is for source-level compatibility with SDL 2.0.0. } pub enum KeyCode { unknown = C.SDLK_UNKNOWN // 0 @return = C.SDLK_RETURN // '\r' - escape = C.SDLK_ESCAPE // '\x1B' + escape = C.SDLK_ESCAPE // '\033' backspace = C.SDLK_BACKSPACE // '\b' tab = C.SDLK_TAB // '\t' space = C.SDLK_SPACE // ' ' @@ -148,7 +146,7 @@ pub enum KeyCode { insert = C.SDLK_INSERT home = C.SDLK_HOME pageup = C.SDLK_PAGEUP - delete = C.SDLK_DELETE // '\x7F' + delete = C.SDLK_DELETE // '\177' end = C.SDLK_END pagedown = C.SDLK_PAGEDOWN right = C.SDLK_RIGHT @@ -306,9 +304,4 @@ pub enum KeyCode { app2 = C.SDLK_APP2 audiorewind = C.SDLK_AUDIOREWIND audiofastforward = C.SDLK_AUDIOFASTFORWARD - // - softleft = C.SDLK_SOFTLEFT - softright = C.SDLK_SOFTRIGHT - call = C.SDLK_CALL - endcall = C.SDLK_ENDCALL } diff --git a/loadso.c.v b/loadso.c.v index 82da21c7..7a9c8c44 100644 --- a/loadso.c.v +++ b/loadso.c.v @@ -8,45 +8,18 @@ module sdl // fn C.SDL_LoadObject(sofile &char) voidptr -// load_object dynamicallys load a shared object. -// -// `sofile` a system-dependent name of the object file -// returns an opaque pointer to the object handle or NULL if there was an -// error; call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_LoadFunction -// See also: SDL_UnloadObject +// load_object dynamically loads a shared object and returns a pointer +// to the object handle (or NULL if there was an error). +// The 'sofile' parameter is a system dependent name of the object file. pub fn load_object(sofile &char) voidptr { return C.SDL_LoadObject(sofile) } fn C.SDL_LoadFunction(handle voidptr, const_name &char) voidptr -// load_function looks up the address of the named function in a shared object. -// -// This function pointer is no longer valid after calling SDL_UnloadObject(). -// -// This function can only look up C function names. Other languages may have -// name mangling and intrinsic language support that varies from compiler to -// compiler. -// -// Make sure you declare your function pointers with the same calling -// convention as the actual library function. Your code will crash -// mysteriously if you do not do this. -// -// If the requested function doesn't exist, NULL is returned. -// -// `handle` a valid shared object handle returned by SDL_LoadObject() -// `name` the name of the function to look up -// returns a pointer to the function or NULL if there was an error; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_LoadObject -// See also: SDL_UnloadObject +// load_function, given an object handle, looks up the address of the +// named function in the shared object and returns it. This address +// is no longer valid after calling SDL_UnloadObject(). pub fn load_function(handle voidptr, const_name &char) voidptr { return C.SDL_LoadFunction(handle, const_name) } @@ -54,13 +27,6 @@ pub fn load_function(handle voidptr, const_name &char) voidptr { fn C.SDL_UnloadObject(handle voidptr) // unload_object unloads a shared object from memory. -// -// `handle` a valid shared object handle returned by SDL_LoadObject() -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_LoadFunction -// See also: SDL_LoadObject pub fn unload_object(handle voidptr) { C.SDL_UnloadObject(handle) } diff --git a/locale.c.v b/locale.c.v deleted file mode 100644 index 02217aa1..00000000 --- a/locale.c.v +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright(C) 2021 Lars Pontoppidan. All rights reserved. -// Use of this source code is governed by an MIT license -// that can be found in the LICENSE file. -module sdl - -// -// SDL_locale.h -// - -@[typedef] -pub struct C.SDL_Locale { -pub: - language &char // const, A language name, like "en" for English. - country &char // const, A country, like "US" for America. Can be NULL. -} - -pub type Locale = C.SDL_Locale - -fn C.SDL_GetPreferredLocales() &C.SDL_Locale - -// get_preferred_locales reports the user's preferred locale. -// -// This returns an array of SDL_Locale structs, the final item zeroed out. -// When the caller is done with this array, it should call SDL_free() on the -// returned value; all the memory involved is allocated in a single block, so -// a single SDL_free() will suffice. -// -// Returned language strings are in the format xx, where 'xx' is an ISO-639 -// language specifier (such as "en" for English, "de" for German, etc). -// Country strings are in the format YY, where "YY" is an ISO-3166 country -// code (such as "US" for the United States, "CA" for Canada, etc). Country -// might be NULL if there's no specific guidance on them (so you might get { -// "en", "US" } for American English, but { "en", NULL } means "English -// language, generically"). Language strings are never NULL, except to -// terminate the array. -// -// Please note that not all of these strings are 2 characters; some are three -// or more. -// -// The returned list of locales are in the order of the user's preference. For -// example, a German citizen that is fluent in US English and knows enough -// Japanese to navigate around Tokyo might have a list like: { "de", "en_US", -// "jp", NULL }. Someone from England might prefer British English (where -// "color" is spelled "colour", etc), but will settle for anything like it: { -// "en_GB", "en", NULL }. -// -// This function returns NULL on error, including when the platform does not -// supply this information at all. -// -// This might be a "slow" call that has to query the operating system. It's -// best to ask for this once and save the results. However, this list can -// change, usually because the user has changed a system preference outside of -// your program; SDL will send an SDL_LOCALECHANGED event in this case, if -// possible, and you can call this function again to get an updated copy of -// preferred locales. -// -// returns array of locales, terminated with a locale with a NULL language -// field. Will return NULL on error. -// -// NOTE This function is available since SDL 2.0.14. -pub fn get_preferred_locales() &Locale { - return C.SDL_GetPreferredLocales() -} diff --git a/log.c.v b/log.c.v index 351d36cd..af9423ae 100644 --- a/log.c.v +++ b/log.c.v @@ -3,9 +3,6 @@ // that can be found in the LICENSE file. module sdl -// The maximum size of a log message prior to SDL 2.0.24 -// -// As of 2.0.24 there is no limit to the length of SDL log messages. pub const max_log_message = C.SDL_MAX_LOG_MESSAGE // 4096 // LogOutputFunction is the prototype for the log output function @@ -18,7 +15,7 @@ pub type LogOutputFunction = fn (userdata voidptr, category int, priority LogPri // By default the application category is enabled at the INFO level, // the assert category is enabled at the WARN level, test is enabled // at the VERBOSE level and all other categories are enabled at the -// ERROR level. +// CRITICAL level. // // LogCategory is C.SDL_LogCategory pub enum LogCategory { @@ -66,42 +63,21 @@ pub enum LogPriority { fn C.SDL_LogSetAllPriority(priority C.SDL_LogPriority) -// log_set_all_priority sets the priority of all log categories. -// -// `priority` the SDL_LogPriority to assign -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_LogSetPriority +// log_set_all_priority sets the priority of all log categories pub fn log_set_all_priority(priority LogPriority) { C.SDL_LogSetAllPriority(C.SDL_LogPriority(int(priority))) } fn C.SDL_LogSetPriority(category int, priority C.SDL_LogPriority) -// log_set_priority sets the priority of a particular log category. -// -// `category` the category to assign a priority to -// `priority` the SDL_LogPriority to assign -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_LogGetPriority -// See also: SDL_LogSetAllPriority +// log_set_priority sets the priority of a particular log category pub fn log_set_priority(category int, priority LogPriority) { C.SDL_LogSetPriority(category, C.SDL_LogPriority(int(priority))) } fn C.SDL_LogGetPriority(category int) LogPriority -// log_get_priority gets the priority of a particular log category. -// -// `category` the category to query -// returns the SDL_LogPriority for the requested category -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_LogSetPriority +// log_get_priority gets the priority of a particular log category pub fn log_get_priority(category int) LogPriority { return unsafe { LogPriority(int(C.SDL_LogGetPriority(category))) } } @@ -110,12 +86,7 @@ fn C.SDL_LogResetPriorities() // log_reset_priorities resets all priorities to default. // -// This is called by SDL_Quit(). -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_LogSetAllPriority -// See also: SDL_LogSetPriority +// NOTE This is called in SDL_Quit(). pub fn log_reset_priorities() { C.SDL_LogResetPriorities() } @@ -133,38 +104,13 @@ pub fn log_reset_priorities() { fn C.SDL_LogMessageV(category int, priority C.SDL_LogPriority, const_fmt &char, ap C.va_list) // log_message_v logs a message with the specified category and priority. -// -// `category` the category of the message -// `priority` the priority of the message -// `fmt` a printf() style message format string -// `ap` a variable argument list -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_Log -// See also: SDL_LogCritical -// See also: SDL_LogDebug -// See also: SDL_LogError -// See also: SDL_LogInfo -// See also: SDL_LogMessage -// See also: SDL_LogVerbose -// See also: SDL_LogWarn pub fn log_message_v(category int, priority LogPriority, const_fmt &char, ap C.va_list) { C.SDL_LogMessageV(category, C.SDL_LogPriority(priority), const_fmt, ap) } fn C.SDL_LogGetOutputFunction(callback &LogOutputFunction, userdata voidptr) -// log_get_output_function gets the current log output function. -// -// `callback` an SDL_LogOutputFunction filled in with the current log -// callback -// `userdata` a pointer filled in with the pointer that is passed to -// `callback` -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_LogSetOutputFunction +// log_get_output_function get the current log output function. // NOTE `userdata` is `**` pub fn log_get_output_function(callback &LogOutputFunction, userdata voidptr) { C.SDL_LogGetOutputFunction(callback, userdata) @@ -172,14 +118,8 @@ pub fn log_get_output_function(callback &LogOutputFunction, userdata voidptr) { fn C.SDL_LogSetOutputFunction(callback LogOutputFunction, userdata voidptr) -// log_set_output_function replaces the default log output function with one of your own. -// -// `callback` an SDL_LogOutputFunction to call instead of the default -// `userdata` a pointer that is passed to `callback` -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_LogGetOutputFunction +// log_set_output_function allows you to replace the default log output +// function with one of your own. pub fn log_set_output_function(callback LogOutputFunction, userdata voidptr) { C.SDL_LogSetOutputFunction(callback, userdata) } diff --git a/main.c.v b/main.c.v index 5cea6b7f..f0857250 100644 --- a/main.c.v +++ b/main.c.v @@ -7,39 +7,26 @@ module sdl // SDL_main.h // -// The prototype for the application's main() function -// `typedef int (*SDL_main_func)(int argc, char *argv[]);` -pub type MainFunc = fn (argc int, argv &&char) int - -fn C.SDL_SetMainReady() - -// set_main_ready circumvents failure of SDL_Init() when not using SDL_main() as an entry -// point. -// -// This function is defined in SDL_main.h, along with the preprocessor rule to -// redefine main() as SDL_main(). Thus to ensure that your main() function -// will not be changed it is necessary to define SDL_MAIN_HANDLED before -// including SDL.h. +// set_main_ready is called by the real SDL main function to let the rest of the +// library know that initialization was done properly. // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_Init +// Calling this yourself without knowing what you're doing can cause +// crashes and hard to diagnose problems with your application. +fn C.SDL_SetMainReady() pub fn set_main_ready() { C.SDL_SetMainReady() } // TODO //$if winrt ? { -// fn C.SDL_WinRTRunApp(SDL_main_func MainFunc, reserved voidptr) int -// win_rt_run_app initializes and launch an SDL/WinRT application. -// -// `mainFunction` the SDL app's C-style main(), an SDL_main_func -// `reserved` reserved for future use; should be NULL -// returns 0 on success or -1 on failure; call SDL_GetError() to retrieve -// more information on the failure. +// fn C.SDL_WinRTRunApp((*main_function)(int, char* *) int, reserved voidptr) int +// win_rt_run_app Initializes and launches an SDL/WinRT application. // -// NOTE This function is available since SDL 2.0.3. -// pub fn win_rt_run_app(main_func MainFunc, reserved voidptr) int{ -// return C.SDL_WinRTRunApp(main_func, reserved) +// `mainFunction` The SDL app's C-style main(). +// `reserved` Reserved for future use; should be NULL +// returns 0 on success, -1 on failure. On failure, use SDL_GetError to retrieve more +// information on the failure. +// pub fn win_rt_run_app((*main_function)(int, char* *) int, reserved voidptr) int{ +// return C.SDL_WinRTRunApp((*main_function)(int, char* *), reserved) //} //} diff --git a/main_ios.c.v b/main_ios.c.v deleted file mode 100644 index 7ae1c15b..00000000 --- a/main_ios.c.v +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright(C) 2021 Lars Pontoppidan. All rights reserved. -// Use of this source code is governed by an MIT license -// that can be found in the LICENSE file. -module sdl - -// -// SDL_main.h -// - -fn C.SDL_UIKitRunApp(argc int, argv &&char, main_function MainFunc) int - -// ui_kit_run_app initializes and launches an SDL application. -// -// `argc` The argc parameter from the application's main() function -// `argv` The argv parameter from the application's main() function -// `mainFunction` The SDL app's C-style main(), an SDL_main_func -// returns the return value from mainFunction -// -// NOTE This function is available since SDL 2.0.10. -pub fn ui_kit_run_app(argc int, argv &&char, main_function MainFunc) int { - return C.SDL_UIKitRunApp(argc, argv, main_function) -} diff --git a/main_windows.c.v b/main_windows.c.v index 49b40613..57a0511e 100644 --- a/main_windows.c.v +++ b/main_windows.c.v @@ -9,64 +9,12 @@ module sdl fn C.SDL_RegisterApp(name &char, style u32, h_inst voidptr) int -// register_app registers a win32 window class for SDL's use. -// -// This can be called to set the application window class at startup. It is -// safe to call this multiple times, as long as every call is eventually -// paired with a call to SDL_UnregisterApp, but a second registration attempt -// while a previous registration is still active will be ignored, other than -// to increment a counter. -// -// Most applications do not need to, and should not, call this directly; SDL -// will call it when initializing the video subsystem. -// -// `name` the window class name, in UTF-8 encoding. If NULL, SDL -// currently uses "SDL_app" but this isn't guaranteed. -// `style` the value to use in WNDCLASSEX::style. If `name` is NULL, SDL -// currently uses `(CS_BYTEALIGNCLIENT | CS_OWNDC)` regardless of -// what is specified here. -// `hInst` the HINSTANCE to use in WNDCLASSEX::hInstance. If zero, SDL -// will use `GetModuleHandle(NULL)` instead. -// returns 0 on success, -1 on error. SDL_GetError() may have details. -// -// NOTE This function is available since SDL 2.0.2. +// register_app can be called to set the application class at startup pub fn register_app(name &char, style u32, h_inst voidptr) int { return C.SDL_RegisterApp(name, style, h_inst) } fn C.SDL_UnregisterApp() - -// unregister_app deregisters the win32 window class from an SDL_RegisterApp call. -// -// This can be called to undo the effects of SDL_RegisterApp. -// -// Most applications do not need to, and should not, call this directly; SDL -// will call it when deinitializing the video subsystem. -// -// It is safe to call this multiple times, as long as every call is eventually -// paired with a prior call to SDL_RegisterApp. The window class will only be -// deregistered when the registration counter in SDL_RegisterApp decrements to -// zero through calls to this function. -// -// NOTE This function is available since SDL 2.0.2. pub fn unregister_app() { C.SDL_UnregisterApp() } - -/* -TODO support GDK? -$if gdk ? { - fn C.SDL_GDKRunApp(main_function C.SDL_main_func, reserved voidptr) int - // Initialize and launch an SDL GDK application. - // - // `main_function` the SDL app's C-style main(), an SDL_main_func - // `reserved` reserved for future use; should be NULL - // returns 0 on success or -1 on failure; call SDL_GetError() to retrieve - // more information on the failure. - // - // NOTE This function is available since SDL 2.24.0. - gdk_run_app(main_function C.SDL_main_func, reserved voidptr) int { - return C.SDL_GDKRunApp(main_function, reserved) - } -} -*/ diff --git a/messagebox.c.v b/messagebox.c.v index 53066cd3..e192bbff 100644 --- a/messagebox.c.v +++ b/messagebox.c.v @@ -10,11 +10,9 @@ module sdl // MessageBoxFlags is C.SDL_MessageBoxFlags // MessageBox flags. If supported will display warning icon, etc. pub enum MessageBoxFlags { - error = C.SDL_MESSAGEBOX_ERROR // 0x00000010, error dialog - warning = C.SDL_MESSAGEBOX_WARNING // 0x00000020, warning dialog - information = C.SDL_MESSAGEBOX_INFORMATION // 0x00000040, informational dialog - buttons_left_to_right = C.SDL_MESSAGEBOX_BUTTONS_LEFT_TO_RIGHT // 0x00000080, buttons placed left to right - buttons_right_to_left = C.SDL_MESSAGEBOX_BUTTONS_RIGHT_TO_LEFT // 0x00000100, buttons placed right to left + error = C.SDL_MESSAGEBOX_ERROR // 0x00000010, error dialog + warning = C.SDL_MESSAGEBOX_WARNING // 0x00000020, warning dialog + information = C.SDL_MESSAGEBOX_INFORMATION // 0x00000040, informational dialog } // MessageBoxButtonFlags is C.SDL_MessageBoxButtonFlags @@ -84,77 +82,30 @@ fn C.SDL_ShowMessageBox(messageboxdata &C.SDL_MessageBoxData, buttonid &int) int // show_message_box creates a modal message box. // -// If your needs aren't complex, it might be easier to use -// SDL_ShowSimpleMessageBox. +// `messageboxdata` The SDL_MessageBoxData structure with title, text, etc. +// `buttonid` The pointer to which user id of hit button should be copied. // -// This function should be called on the thread that created the parent -// window, or on the main thread if the messagebox has no parent. It will -// block execution of that thread until the user clicks a button or closes the -// messagebox. +// returns -1 on error, otherwise 0 and buttonid contains user id of button +// hit or -1 if dialog was closed. // -// This function may be called at any time, even before SDL_Init(). This makes -// it useful for reporting errors like a failure to create a renderer or -// OpenGL context. -// -// On X11, SDL rolls its own dialog box with X11 primitives instead of a -// formal toolkit like GTK+ or Qt. -// -// Note that if SDL_Init() would fail because there isn't any available video -// target, this function is likely to fail for the same reasons. If this is a -// concern, check the return value from this function and fall back to writing -// to stderr if you can. -// -// `messageboxdata` the SDL_MessageBoxData structure with title, text and -// other options -// `buttonid` the pointer to which user id of hit button should be copied -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_ShowSimpleMessageBox +// NOTE This function should be called on the thread that created the parent +// window, or on the main thread if the messagebox has no parent. It will +// block execution of that thread until the user clicks a button or +// closes the messagebox. pub fn show_message_box(messageboxdata &MessageBoxData, buttonid &int) int { return C.SDL_ShowMessageBox(messageboxdata, buttonid) } fn C.SDL_ShowSimpleMessageBox(flags u32, const_title &char, const_message &char, window &C.SDL_Window) int -// show_simple_message_box displays a simple modal message box. -// -// If your needs aren't complex, this function is preferred over -// SDL_ShowMessageBox. -// -// `flags` may be any of the following: -// -// - `SDL_MESSAGEBOX_ERROR`: error dialog -// - `SDL_MESSAGEBOX_WARNING`: warning dialog -// - `SDL_MESSAGEBOX_INFORMATION`: informational dialog -// -// This function should be called on the thread that created the parent -// window, or on the main thread if the messagebox has no parent. It will -// block execution of that thread until the user clicks a button or closes the -// messagebox. -// -// This function may be called at any time, even before SDL_Init(). This makes -// it useful for reporting errors like a failure to create a renderer or -// OpenGL context. -// -// On X11, SDL rolls its own dialog box with X11 primitives instead of a -// formal toolkit like GTK+ or Qt. -// -// Note that if SDL_Init() would fail because there isn't any available video -// target, this function is likely to fail for the same reasons. If this is a -// concern, check the return value from this function and fall back to writing -// to stderr if you can. +// show_simple_message_box creates a simple modal message box // -// `flags` an SDL_MessageBoxFlags value -// `title` UTF-8 title text -// `message` UTF-8 message text -// `window` the parent window, or NULL for no parent -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. +// `flags` ::SDL_MessageBoxFlags +// `title` UTF-8 title text +// `message` UTF-8 message text +// `window` The parent window, or NULL for no parent // -// NOTE This function is available since SDL 2.0.0. +// returns 0 on success, -1 on error // // See also: SDL_ShowMessageBox pub fn show_simple_message_box(flags u32, const_title &char, const_message &char, window &Window) int { diff --git a/metal.c.v b/metal.c.v deleted file mode 100644 index 70fbf03f..00000000 --- a/metal.c.v +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright(C) 2021 Lars Pontoppidan. All rights reserved. -// Use of this source code is governed by an MIT license -// that can be found in the LICENSE file. -module sdl - -// -// SDL_metal.h -// - -// A handle to a CAMetalLayer-backed NSView (macOS) or UIView (iOS/tvOS). -// -// NOTE This can be cast directly to an NSView or UIView. -// -// `typedef void *SDL_MetalView;` -// C.SDL_MetalView -pub type MetalView = voidptr - -// Metal support functions -fn C.SDL_Metal_CreateView(window &C.SDL_Window) MetalView - -// metal_create_view creates a CAMetalLayer-backed NSView/UIView and attach it to the specified -// window. -// -// On macOS, this does *not* associate a MTLDevice with the CAMetalLayer on -// its own. It is up to user code to do that. -// -// The returned handle can be casted directly to a NSView or UIView. To access -// the backing CAMetalLayer, call SDL_Metal_GetLayer(). -// -// NOTE This function is available since SDL 2.0.12. -// -// See also: SDL_Metal_DestroyView -// See also: SDL_Metal_GetLayer -pub fn metal_create_view(window &Window) MetalView { - return MetalView(voidptr(C.SDL_Metal_CreateView(window))) -} - -fn C.SDL_Metal_DestroyView(view C.SDL_MetalView) - -// metal_destroy_view destroys an existing SDL_MetalView object. -// -// This should be called before SDL_DestroyWindow, if SDL_Metal_CreateView was -// called after SDL_CreateWindow. -// -// NOTE This function is available since SDL 2.0.12. -// -// See also: SDL_Metal_CreateView -pub fn metal_destroy_view(view MetalView) { - C.SDL_Metal_DestroyView(voidptr(view)) -} - -fn C.SDL_Metal_GetLayer(view C.SDL_MetalView) voidptr - -// metal_get_layer gets a pointer to the backing CAMetalLayer for the given view. -// -// NOTE This function is available since SDL 2.0.14. -// -// See also: SDL_MetalCreateView -pub fn metal_get_layer(view MetalView) voidptr { - return C.SDL_Metal_GetLayer(voidptr(view)) -} - -fn C.SDL_Metal_GetDrawableSize(window &C.SDL_Window, w &int, h &int) - -// metal_get_drawable_size gets the size of a window's underlying drawable in pixels (for use with -// setting viewport, scissor & etc). -// -// `window` SDL_Window from which the drawable size should be queried -// `w` Pointer to variable for storing the width in pixels, may be NULL -// `h` Pointer to variable for storing the height in pixels, may be NULL -// -// NOTE This function is available since SDL 2.0.14. -// -// See also: SDL_GetWindowSize -// See also: SDL_CreateWindow -pub fn metal_get_drawable_size(window &Window, w &int, h &int) { - C.SDL_Metal_GetDrawableSize(window, w, h) -} diff --git a/misc.c.v b/misc.c.v deleted file mode 100644 index 2df34e80..00000000 --- a/misc.c.v +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright(C) 2021 Lars Pontoppidan. All rights reserved. -// Use of this source code is governed by an MIT license -// that can be found in the LICENSE file. -module sdl - -// -// SDL_misc.h -// - -fn C.SDL_OpenURL(url &char) int - -// open_url opens a URL/URI in the browser or other appropriate external application. -// -// Open a URL in a separate, system-provided application. How this works will -// vary wildly depending on the platform. This will likely launch what makes -// sense to handle a specific URL's protocol (a web browser for `http://`, -// etc), but it might also be able to launch file managers for directories and -// other things. -// -// What happens when you open a URL varies wildly as well: your game window -// may lose focus (and may or may not lose focus if your game was fullscreen -// or grabbing input at the time). On mobile devices, your app will likely -// move to the background or your process might be paused. Any given platform -// may or may not handle a given URL. -// -// If this is unimplemented (or simply unavailable) for a platform, this will -// fail with an error. A successful result does not mean the URL loaded, just -// that we launched _something_ to handle it (or at least believe we did). -// -// All this to say: this function can be useful, but you should definitely -// test it on every platform you target. -// -// `url` A valid URL/URI to open. Use `file:///full/path/to/file` for -// local files, if supported. -// returns 0 on success, or -1 on error; call SDL_GetError() for more -// information. -// -// NOTE This function is available since SDL 2.0.14. -pub fn open_url(url &char) int { - return C.SDL_OpenURL(url) -} diff --git a/mixer/c.c.v b/mixer/c.c.v index fd8f495c..967c6f43 100644 --- a/mixer/c.c.v +++ b/mixer/c.c.v @@ -17,11 +17,11 @@ $if !windows { } $if x64 { - #flag windows -L @VMODROOT/thirdparty/SDL2_mixer-2.0.4/lib/x64 + #flag windows -L @VMODROOT/thirdparty/SDL2_mixer-2.0.2/lib/x64 } $else { - #flag windows -L @VMODROOT/thirdparty/SDL2_mixer-2.0.4/lib/x86 + #flag windows -L @VMODROOT/thirdparty/SDL2_mixer-2.0.2/lib/x86 } -#flag windows -I @VMODROOT/thirdparty/SDL2_mixer-2.0.4/include +#flag windows -I @VMODROOT/thirdparty/SDL2_mixer-2.0.2/include #flag windows -lSDL2_mixer #include diff --git a/mixer/mixer.c.v b/mixer/mixer.c.v index 974f0a84..c6429a80 100644 --- a/mixer/mixer.c.v +++ b/mixer/mixer.c.v @@ -12,7 +12,7 @@ pub const major_version = C.SDL_MIXER_MAJOR_VERSION // 2 pub const minor_version = C.SDL_MIXER_MINOR_VERSION // 0 -pub const patchlevel = C.SDL_MIXER_PATCHLEVEL // 4 +pub const patchlevel = C.SDL_MIXER_PATCHLEVEL // 2 fn C.SDL_MIXER_VERSION(v &sdl.Version) @@ -52,7 +52,6 @@ pub enum InitFlags { mp3 = C.MIX_INIT_MP3 // 0x00000008 ogg = C.MIX_INIT_OGG // 0x00000010 mid = C.MIX_INIT_MID // 0x00000020 - opus = C.MIX_INIT_OPUS // 0x00000040 } fn C.Mix_Init(flags int) int @@ -118,7 +117,6 @@ pub enum MusicType { mp3_mad_unused = C.MUS_MP3_MAD_UNUSED flac = C.MUS_FLAC modplug_unused = C.MUS_MODPLUG_UNUSED - opus = C.MUS_OPUS } pub const channel_post = C.MIX_CHANNEL_POST // -2 diff --git a/mouse.c.v b/mouse.c.v index f6e96c74..32c9d90f 100644 --- a/mouse.c.v +++ b/mouse.c.v @@ -15,11 +15,9 @@ pub type Cursor = C.SDL_Cursor fn C.SDL_BUTTON(x int) int // button is used as a mask when testing buttons in buttonstate. -// // - Button 1: Left mouse button // - Button 2: Middle mouse button // - Button 3: Right mouse button -// // Example /* ``` @@ -83,10 +81,6 @@ pub enum MouseWheelDirection { fn C.SDL_GetMouseFocus() &C.SDL_Window // get_mouse_focus gets the window which currently has mouse focus. -// -// returns the window with mouse focus. -// -// NOTE This function is available since SDL 2.0.0. pub fn get_mouse_focus() &Window { return C.SDL_GetMouseFocus() } @@ -95,54 +89,37 @@ fn C.SDL_GetMouseState(x &int, y &int) u32 // get_mouse_state retrieves the current state of the mouse. // -// The current button state is returned as a button bitmask, which can be -// tested using the `SDL_BUTTON(X)` macros (where `X` is generally 1 for the -// left, 2 for middle, 3 for the right button), and `x` and `y` are set to the -// mouse cursor position relative to the focus window. You can pass NULL for -// either `x` or `y`. -// -// `x` the x coordinate of the mouse cursor position relative to the -// focus window -// `y` the y coordinate of the mouse cursor position relative to the -// focus window -// returns a 32-bit button bitmask of the current button state. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetGlobalMouseState -// See also: SDL_GetRelativeMouseState -// See also: SDL_PumpEvents +// The current button state is returned as a button bitmask, which can +// be tested using the SDL_BUTTON(X) macros, and x and y are set to the +// mouse cursor position relative to the focus window for the currently +// selected mouse. You can pass NULL for either x or y. pub fn get_mouse_state(x &int, y &int) u32 { return C.SDL_GetMouseState(x, y) } fn C.SDL_GetGlobalMouseState(x &int, y &int) u32 -// get_global_mouse_state gets the current state of the mouse in relation to the desktop. +// get_global_mouse_state gets the current state of the mouse, in relation to the desktop // -// This works similarly to SDL_GetMouseState(), but the coordinates will be -// reported relative to the top-left of the desktop. This can be useful if you -// need to track the mouse outside of a specific window and SDL_CaptureMouse() -// doesn't fit your needs. For example, it could be useful if you need to -// track the mouse while dragging a window, where coordinates relative to a -// window might not be in sync at all times. +// This works just like SDL_GetMouseState(), but the coordinates will be +// reported relative to the top-left of the desktop. This can be useful if +// you need to track the mouse outside of a specific window and +// SDL_CaptureMouse() doesn't fit your needs. For example, it could be +// useful if you need to track the mouse while dragging a window, where +// coordinates relative to a window might not be in sync at all times. // -// Note: SDL_GetMouseState() returns the mouse position as SDL understands it -// from the last pump of the event queue. This function, however, queries the -// OS for the current mouse position, and as such, might be a slightly less -// efficient function. Unless you know what you're doing and have a good -// reason to use this function, you probably want SDL_GetMouseState() instead. +// NOTE SDL_GetMouseState() returns the mouse position as SDL understands +// it from the last pump of the event queue. This function, however, +// queries the OS for the current mouse position, and as such, might +// be a slightly less efficient function. Unless you know what you're +// doing and have a good reason to use this function, you probably want +// SDL_GetMouseState() instead. // -// `x` filled in with the current X coord relative to the desktop; can be -// NULL -// `y` filled in with the current Y coord relative to the desktop; can be -// NULL -// returns the current button state as a bitmask which can be tested using -// the SDL_BUTTON(X) macros. +// `x` Returns the current X coord, relative to the desktop. Can be NULL. +// `y` Returns the current Y coord, relative to the desktop. Can be NULL. +// returns The current button state as a bitmask, which can be tested using the SDL_BUTTON(X) macros. // -// NOTE This function is available since SDL 2.0.4. -// -// See also: SDL_CaptureMouse +// See also: SDL_GetMouseState pub fn get_global_mouse_state(x &int, y &int) u32 { return C.SDL_GetGlobalMouseState(x, y) } @@ -151,42 +128,22 @@ fn C.SDL_GetRelativeMouseState(x &int, y &int) u32 // get_relative_mouse_state retrieves the relative state of the mouse. // -// The current button state is returned as a button bitmask, which can be -// tested using the `SDL_BUTTON(X)` macros (where `X` is generally 1 for the -// left, 2 for middle, 3 for the right button), and `x` and `y` are set to the -// mouse deltas since the last call to SDL_GetRelativeMouseState() or since -// event initialization. You can pass NULL for either `x` or `y`. -// -// `x` a pointer filled with the last recorded x coordinate of the mouse -// `y` a pointer filled with the last recorded y coordinate of the mouse -// returns a 32-bit button bitmask of the relative button state. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetMouseState +// The current button state is returned as a button bitmask, which can +// be tested using the SDL_BUTTON(X) macros, and x and y are set to the +// mouse deltas since the last call to SDL_GetRelativeMouseState(). pub fn get_relative_mouse_state(x &int, y &int) u32 { return C.SDL_GetRelativeMouseState(x, y) } fn C.SDL_WarpMouseInWindow(window &C.SDL_Window, x int, y int) -// warp_mouse_in_window moves the mouse cursor to the given position within the window. +// warp_mouse_in_window moves the mouse to the given position within the window. // -// This function generates a mouse motion event if relative mode is not -// enabled. If relative mode is enabled, you can force mouse events for the -// warp by setting the SDL_HINT_MOUSE_RELATIVE_WARP_MOTION hint. +// `window` The window to move the mouse into, or NULL for the current mouse focus +// `x` The x coordinate within the window +// `y` The y coordinate within the window // -// Note that this function will appear to succeed, but not actually move the -// mouse when used over Microsoft Remote Desktop. -// -// `window` the window to move the mouse into, or NULL for the current -// mouse focus -// `x` the x coordinate within the window -// `y` the y coordinate within the window -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_WarpMouseGlobal +// NOTE This function generates a mouse motion event pub fn warp_mouse_in_window(window &Window, x int, y int) { C.SDL_WarpMouseInWindow(window, x, y) } @@ -195,22 +152,11 @@ fn C.SDL_WarpMouseGlobal(x int, y int) int // warp_mouse_global moves the mouse to the given position in global screen space. // -// This function generates a mouse motion event. -// -// A failure of this function usually means that it is unsupported by a -// platform. -// -// Note that this function will appear to succeed, but not actually move the -// mouse when used over Microsoft Remote Desktop. -// -// `x` the x coordinate -// `y` the y coordinate -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.4. +// `x` The x coordinate +// `y` The y coordinate +// returns 0 on success, -1 on error (usually: unsupported by a platform). // -// See also: SDL_WarpMouseInWindow +// NOTE This function generates a mouse motion event pub fn warp_mouse_global(x int, y int) int { return C.SDL_WarpMouseGlobal(x, y) } @@ -219,69 +165,51 @@ fn C.SDL_SetRelativeMouseMode(enabled bool) int // set_relative_mouse_mode sets relative mouse mode. // -// While the mouse is in relative mode, the cursor is hidden, the mouse -// position is constrained to the window, and SDL will report continuous -// relative mouse motion even if the mouse is at the edge of the window. +// `enabled` Whether or not to enable relative mode // -// This function will flush any pending mouse motion. +// returns 0 on success, or -1 if relative mode is not supported. // -// `enabled` SDL_TRUE to enable relative mode, SDL_FALSE to disable. -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. +// While the mouse is in relative mode, the cursor is hidden, and the +// driver will try to report continuous motion in the current window. +// Only relative motion events will be delivered, the mouse position +// will not change. // -// If relative mode is not supported, this returns -1. +// NOTE This function will flush any pending mouse motion. // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetRelativeMouseMode +// See also: SDL_GetRelativeMouseMode() pub fn set_relative_mouse_mode(enabled bool) int { return C.SDL_SetRelativeMouseMode(enabled) } fn C.SDL_CaptureMouse(enabled bool) int -// capture_mouse captures the mouse and to track input outside an SDL window. +// capture_mouse capture the mouse, to track input outside an SDL window. +// +// `enabled` Whether or not to enable capturing // -// Capturing enables your app to obtain mouse events globally, instead of just -// within your window. Not all video targets support this function. When -// capturing is enabled, the current window will get all mouse events, but -// unlike relative mode, no change is made to the cursor and it is not -// restrained to your window. +// Capturing enables your app to obtain mouse events globally, instead of +// just within your window. Not all video targets support this function. +// When capturing is enabled, the current window will get all mouse events, +// but unlike relative mode, no change is made to the cursor and it is +// not restrained to your window. // // This function may also deny mouse input to other windows--both those in -// your application and others on the system--so you should use this function -// sparingly, and in small bursts. For example, you might want to track the -// mouse while the user is dragging something, until the user releases a mouse -// button. It is not recommended that you capture the mouse for long periods -// of time, such as the entire time your app is running. For that, you should -// probably use SDL_SetRelativeMouseMode() or SDL_SetWindowGrab(), depending -// on your goals. +// your application and others on the system--so you should use this +// function sparingly, and in small bursts. For example, you might want to +// track the mouse while the user is dragging something, until the user +// releases a mouse button. It is not recommended that you capture the mouse +// for long periods of time, such as the entire time your app is running. // // While captured, mouse events still report coordinates relative to the // current (foreground) window, but those coordinates may be outside the -// bounds of the window (including negative values). Capturing is only allowed -// for the foreground window. If the window loses focus while capturing, the -// capture will be disabled automatically. +// bounds of the window (including negative values). Capturing is only +// allowed for the foreground window. If the window loses focus while +// capturing, the capture will be disabled automatically. // // While capturing is enabled, the current window will have the -// `SDL_WINDOW_MOUSE_CAPTURE` flag set. -// -// Please note that as of SDL 2.0.22, SDL will attempt to "auto capture" the -// mouse while the user is pressing a button; this is to try and make mouse -// behavior more consistent between platforms, and deal with the common case -// of a user dragging the mouse outside of the window. This means that if you -// are calling SDL_CaptureMouse() only to deal with this situation, you no -// longer have to (although it is safe to do so). If this causes problems for -// your app, you can disable auto capture by setting the -// `SDL_HINT_MOUSE_AUTO_CAPTURE` hint to zero. +// SDL_WINDOW_MOUSE_CAPTURE flag set. // -// `enabled` SDL_TRUE to enable capturing, SDL_FALSE to disable. -// returns 0 on success or -1 if not supported; call SDL_GetError() for more -// information. -// -// NOTE This function is available since SDL 2.0.4. -// -// See also: SDL_GetGlobalMouseState +// returns 0 on success, or -1 if not supported. pub fn capture_mouse(enabled bool) int { return C.SDL_CaptureMouse(enabled) } @@ -290,56 +218,31 @@ fn C.SDL_GetRelativeMouseMode() bool // get_relative_mouse_mode queries whether relative mouse mode is enabled. // -// returns SDL_TRUE if relative mode is enabled or SDL_FALSE otherwise. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_SetRelativeMouseMode +// See also: SDL_SetRelativeMouseMode() pub fn get_relative_mouse_mode() bool { return C.SDL_GetRelativeMouseMode() } fn C.SDL_CreateCursor(const_data &u8, const_mask &u8, w int, h int, hot_x int, hot_y int) &C.SDL_Cursor -// create_cursor creates a cursor using the specified bitmap data and mask (in MSB format). -// -// `mask` has to be in MSB (Most Significant Bit) format. +// create_cursor creates a cursor, using the specified bitmap data and +// mask (in MSB format). // -// The cursor width (`w`) must be a multiple of 8 bits. +// The cursor width must be a multiple of 8 bits. // // The cursor is created in black and white according to the following: +/* + + + + + + +
data mask resulting pixel on screen
0 1 White
1 1 Black
0 0 Transparent
1 0 Inverted color if possible, black + if not.
+*/ // -// - data=0, mask=1: white -// - data=1, mask=1: black -// - data=0, mask=0: transparent -// - data=1, mask=0: inverted color if possible, black if not. -// -// Cursors created with this function must be freed with SDL_FreeCursor(). -// -// If you want to have a color cursor, or create your cursor from an -// SDL_Surface, you should use SDL_CreateColorCursor(). Alternately, you can -// hide the cursor and draw your own as part of your game's rendering, but it -// will be bound to the framerate. -// -// Also, since SDL 2.0.0, SDL_CreateSystemCursor() is available, which -// provides twelve readily available system cursors to pick from. -// -// `data` the color value for each pixel of the cursor -// `mask` the mask value for each pixel of the cursor -// `w` the width of the cursor -// `h` the height of the cursor -// `hot_x` the X-axis location of the upper left corner of the cursor -// relative to the actual mouse position -// `hot_y` the Y-axis location of the upper left corner of the cursor -// relative to the actual mouse position -// returns a new cursor with the specified parameters on success or NULL on -// failure; call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_FreeCursor -// See also: SDL_SetCursor -// See also: SDL_ShowCursor +// See also: SDL_FreeCursor() pub fn create_cursor(const_data &u8, const_mask &u8, w int, h int, hot_x int, hot_y int) &Cursor { return C.SDL_CreateCursor(const_data, const_mask, w, h, hot_x, hot_y) } @@ -348,16 +251,7 @@ fn C.SDL_CreateColorCursor(surface &C.SDL_Surface, hot_x int, hot_y int) &C.SDL_ // create_color_cursor creates a color cursor. // -// `surface` an SDL_Surface structure representing the cursor image -// `hot_x` the x position of the cursor hot spot -// `hot_y` the y position of the cursor hot spot -// returns the new cursor on success or NULL on failure; call SDL_GetError() -// for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_CreateCursor -// See also: SDL_FreeCursor +// See also: SDL_FreeCursor() pub fn create_color_cursor(surface &Surface, hot_x int, hot_y int) &Cursor { return C.SDL_CreateColorCursor(surface, hot_x, hot_y) } @@ -366,13 +260,7 @@ fn C.SDL_CreateSystemCursor(id C.SDL_SystemCursor) &C.SDL_Cursor // create_system_cursor creates a system cursor. // -// `id` an SDL_SystemCursor enum value -// returns a cursor on success or NULL on failure; call SDL_GetError() for -// more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_FreeCursor +// See also: SDL_FreeCursor() pub fn create_system_cursor(id SystemCursor) &Cursor { return C.SDL_CreateSystemCursor(C.SDL_SystemCursor(int(id))) } @@ -380,69 +268,31 @@ pub fn create_system_cursor(id SystemCursor) &Cursor { fn C.SDL_SetCursor(cursor &C.SDL_Cursor) // set_cursor sets the active cursor. -// -// This function sets the currently active cursor to the specified one. If the -// cursor is currently visible, the change will be immediately represented on -// the display. SDL_SetCursor(NULL) can be used to force cursor redraw, if -// this is desired for any reason. -// -// `cursor` a cursor to make active -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_CreateCursor -// See also: SDL_GetCursor -// See also: SDL_ShowCursor pub fn set_cursor(cursor &Cursor) { C.SDL_SetCursor(cursor) } fn C.SDL_GetCursor() &C.SDL_Cursor -// get_cursor gets the active cursor. -// -// This function returns a pointer to the current cursor which is owned by the -// library. It is not necessary to free the cursor with SDL_FreeCursor(). -// -// returns the active cursor or NULL if there is no mouse. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_SetCursor +// get_cursor returns the active cursor. pub fn get_cursor() &Cursor { return C.SDL_GetCursor() } fn C.SDL_GetDefaultCursor() &C.SDL_Cursor -// get_default_cursor gets the default cursor. -// -// You do not have to call SDL_FreeCursor() on the return value, but it is -// safe to do so. -// -// returns the default cursor on success or NULL on failure. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_CreateSystemCursor +// get_default_cursor returns the default cursor. pub fn get_default_cursor() &Cursor { return C.SDL_GetDefaultCursor() } fn C.SDL_FreeCursor(cursor &C.SDL_Cursor) -// free_cursor frees a previously-created cursor. +// free_cursor frees a cursor created with SDL_CreateCursor() or similar functions. // -// Use this function to free cursor resources created with SDL_CreateCursor(), -// SDL_CreateColorCursor() or SDL_CreateSystemCursor(). -// -// `cursor` the cursor to free -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_CreateColorCursor -// See also: SDL_CreateCursor -// See also: SDL_CreateSystemCursor +// See also: SDL_CreateCursor() +// See also: SDL_CreateColorCursor() +// See also: SDL_CreateSystemCursor() pub fn free_cursor(cursor &Cursor) { C.SDL_FreeCursor(cursor) } @@ -451,22 +301,10 @@ fn C.SDL_ShowCursor(toggle int) int // show_cursor toggles whether or not the cursor is shown. // -// The cursor starts off displayed but can be turned off. Passing `SDL_ENABLE` -// displays the cursor and passing `SDL_DISABLE` hides it. -// -// The current state of the mouse cursor can be queried by passing -// `SDL_QUERY`; either `SDL_DISABLE` or `SDL_ENABLE` will be returned. -// -// `toggle` `SDL_ENABLE` to show the cursor, `SDL_DISABLE` to hide it, -// `SDL_QUERY` to query the current state without changing it. -// returns `SDL_ENABLE` if the cursor is shown, or `SDL_DISABLE` if the -// cursor is hidden, or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. +// `toggle` 1 to show the cursor, 0 to hide it, -1 to query the current +// state. // -// See also: SDL_CreateCursor -// See also: SDL_SetCursor +// returns 1 if the cursor is shown, or 0 if the cursor is hidden. pub fn show_cursor(toggle int) int { return C.SDL_ShowCursor(toggle) } diff --git a/mutex.c.v b/mutex.c.v index 13ca46bb..2ada3f41 100644 --- a/mutex.c.v +++ b/mutex.c.v @@ -9,10 +9,14 @@ module sdl // mutex_timeout. Synchronization functions which can time out return this value // if they time out. -pub const mutex_timeout = C.SDL_MUTEX_TIMEDOUT // 1 +pub const mutex_timeout = C.SDL_MUTEX_TIMEDOUT + +// 1 // mutex_maxwait is the timeout value which corresponds to never time out. -pub const mutex_maxwait = C.SDL_MUTEX_MAXWAIT // (~(Uint32)0) +pub const mutex_maxwait = C.SDL_MUTEX_MAXWAIT + +// (~(Uint32)0) // Mutex is the SDL mutex structure, defined in SDL_sysmutex.c // Mutex is C.SDL_mutex @@ -24,24 +28,7 @@ pub type Mutex = C.SDL_mutex fn C.SDL_CreateMutex() &C.SDL_mutex -// create_mutex creates a new mutex. -// -// All newly-created mutexes begin in the _unlocked_ state. -// -// Calls to SDL_LockMutex() will not return while the mutex is locked by -// another thread. See SDL_TryLockMutex() to attempt to lock without blocking. -// -// SDL mutexes are reentrant. -// -// returns the initialized and unlocked mutex or NULL on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_DestroyMutex -// See also: SDL_LockMutex -// See also: SDL_TryLockMutex -// See also: SDL_UnlockMutex +// create_mutex creates a mutex, initialized unlocked. pub fn create_mutex() &C.SDL_mutex { return C.SDL_CreateMutex() } @@ -50,42 +37,16 @@ fn C.SDL_LockMutex(mutex &C.SDL_mutex) int // lock_mutex locks the mutex. // -// This will block until the mutex is available, which is to say it is in the -// unlocked state and the OS has chosen the caller as the next thread to lock -// it. Of all threads waiting to lock the mutex, only one may do so at a time. -// -// It is legal for the owning thread to lock an already-locked mutex. It must -// unlock it the same number of times before it is actually made available for -// other threads in the system (this is known as a "recursive mutex"). -// -// `mutex` the mutex to lock // returns 0, or -1 on error. -// -// NOTE This function is available since SDL 2.0.0. pub fn lock_mutex(mutex &Mutex) int { return C.SDL_LockMutex(mutex) } fn C.SDL_TryLockMutex(mutex &C.SDL_mutex) int -// try_lock_mutex trys to lock a mutex without blocking. -// -// This works just like SDL_LockMutex(), but if the mutex is not available, -// this function returns `SDL_MUTEX_TIMEOUT` immediately. +// try_lock_mutex tries to lock the mutex // -// This technique is useful if you need exclusive access to a resource but -// don't want to wait for it, and will return to it to try again later. -// -// `mutex` the mutex to try to lock -// returns 0, `SDL_MUTEX_TIMEDOUT`, or -1 on error; call SDL_GetError() for -// more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_CreateMutex -// See also: SDL_DestroyMutex -// See also: SDL_LockMutex -// See also: SDL_UnlockMutex +// returns 0, SDL_MUTEX_TIMEDOUT, or -1 on error pub fn try_lock_mutex(mutex &Mutex) int { return C.SDL_TryLockMutex(mutex) } @@ -94,41 +55,17 @@ fn C.SDL_UnlockMutex(mutex &C.SDL_mutex) int // unlock_mutex unlocks the mutex. // -// It is legal for the owning thread to lock an already-locked mutex. It must -// unlock it the same number of times before it is actually made available for -// other threads in the system (this is known as a "recursive mutex"). -// -// It is an error to unlock a mutex that has not been locked by the current -// thread, and doing so results in undefined behavior. -// -// It is also an error to unlock a mutex that isn't locked at all. -// -// `mutex` the mutex to unlock. // returns 0, or -1 on error. // -// NOTE This function is available since SDL 2.0.0. +// WARNING It is an error to unlock a mutex that has not been locked by +// the current thread, and doing so results in undefined behavior. pub fn unlock_mutex(mutex &Mutex) int { return C.SDL_UnlockMutex(mutex) } fn C.SDL_DestroyMutex(mutex &C.SDL_mutex) -// destroy_mutex destroys a mutex created with SDL_CreateMutex(). -// -// This function must be called on any mutex that is no longer needed. Failure -// to destroy a mutex will result in a system memory or resource leak. While -// it is safe to destroy a mutex that is _unlocked_, it is not safe to attempt -// to destroy a locked mutex, and may result in undefined behavior depending -// on the platform. -// -// `mutex` the mutex to destroy -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_CreateMutex -// See also: SDL_LockMutex -// See also: SDL_TryLockMutex -// See also: SDL_UnlockMutex +// destroy_mutex destroys a mutex. pub fn destroy_mutex(mutex &Mutex) { C.SDL_DestroyMutex(mutex) } @@ -143,26 +80,7 @@ pub type Sem = C.SDL_sem fn C.SDL_CreateSemaphore(initial_value u32) &C.SDL_sem -// create_semaphore creates a semaphore. -// -// This function creates a new semaphore and initializes it with the value -// `initial_value`. Each wait operation on the semaphore will atomically -// decrement the semaphore value and potentially block if the semaphore value -// is 0. Each post operation will atomically increment the semaphore value and -// wake waiting threads and allow them to retry the wait operation. -// -// `initial_value` the starting value of the semaphore -// returns a new semaphore or NULL on failure; call SDL_GetError() for more -// information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_DestroySemaphore -// See also: SDL_SemPost -// See also: SDL_SemTryWait -// See also: SDL_SemValue -// See also: SDL_SemWait -// See also: SDL_SemWaitTimeout +// create_semaphore creates a semaphore, initialized with value, returns NULL on failure. pub fn create_semaphore(initial_value u32) &Sem { return C.SDL_CreateSemaphore(initial_value) } @@ -170,136 +88,54 @@ pub fn create_semaphore(initial_value u32) &Sem { fn C.SDL_DestroySemaphore(sem &C.SDL_sem) // destroy_semaphore destroys a semaphore. -// -// It is not safe to destroy a semaphore if there are threads currently -// waiting on it. -// -// `sem` the semaphore to destroy -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_CreateSemaphore -// See also: SDL_SemPost -// See also: SDL_SemTryWait -// See also: SDL_SemValue -// See also: SDL_SemWait -// See also: SDL_SemWaitTimeout pub fn destroy_semaphore(sem &Sem) { C.SDL_DestroySemaphore(sem) } fn C.SDL_SemWait(sem &C.SDL_sem) int -// sem_wait waits until a semaphore has a positive value and then decrements it. -// -// This function suspends the calling thread until either the semaphore -// pointed to by `sem` has a positive value or the call is interrupted by a -// signal or error. If the call is successful it will atomically decrement the -// semaphore value. -// -// This function is the equivalent of calling SDL_SemWaitTimeout() with a time -// length of `SDL_MUTEX_MAXWAIT`. -// -// `sem` the semaphore wait on -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_CreateSemaphore -// See also: SDL_DestroySemaphore -// See also: SDL_SemPost -// See also: SDL_SemTryWait -// See also: SDL_SemValue -// See also: SDL_SemWait -// See also: SDL_SemWaitTimeout +// sem_wait this function suspends the calling thread until the semaphore pointed +// to by `sem` has a positive count. It then atomically decreases the +// semaphore count. pub fn sem_wait(sem &Sem) int { return C.SDL_SemWait(sem) } fn C.SDL_SemTryWait(sem &C.SDL_sem) int -// sem_try_wait sees if a semaphore has a positive value and decrement it if it does. +// sem_try_wait is a non-blocking variant of SDL_SemWait(). // -// This function checks to see if the semaphore pointed to by `sem` has a -// positive value and atomically decrements the semaphore value if it does. If -// the semaphore doesn't have a positive value, the function immediately -// returns SDL_MUTEX_TIMEDOUT. -// -// `sem` the semaphore to wait on -// returns 0 if the wait succeeds, `SDL_MUTEX_TIMEDOUT` if the wait would -// block, or a negative error code on failure; call SDL_GetError() -// for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_CreateSemaphore -// See also: SDL_DestroySemaphore -// See also: SDL_SemPost -// See also: SDL_SemValue -// See also: SDL_SemWait -// See also: SDL_SemWaitTimeout +// returns 0 if the wait succeeds, ::SDL_MUTEX_TIMEDOUT if the wait would +// block, and -1 on error. pub fn sem_try_wait(sem &Sem) int { return C.SDL_SemTryWait(sem) } -fn C.SDL_SemWaitTimeout(sem &C.SDL_sem, timeout u32) int +fn C.SDL_SemWaitTimeout(sem &C.SDL_sem, ms u32) int -// sem_wait_timeout waits until a semaphore has a positive value and then decrements it. -// -// This function suspends the calling thread until either the semaphore -// pointed to by `sem` has a positive value, the call is interrupted by a -// signal or error, or the specified time has elapsed. If the call is -// successful it will atomically decrement the semaphore value. +// sem_wait_timeout variants of SDL_SemWait() with a timeout in milliseconds. // -// `sem` the semaphore to wait on -// `timeout` the length of the timeout, in milliseconds -// returns 0 if the wait succeeds, `SDL_MUTEX_TIMEDOUT` if the wait does not -// succeed in the allotted time, or a negative error code on failure; -// call SDL_GetError() for more information. +// returns 0 if the wait succeeds, ::SDL_MUTEX_TIMEDOUT if the wait does not +// succeed in the allotted time, and -1 on error. // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_CreateSemaphore -// See also: SDL_DestroySemaphore -// See also: SDL_SemPost -// See also: SDL_SemTryWait -// See also: SDL_SemValue -// See also: SDL_SemWait -pub fn sem_wait_timeout(sem &Sem, timeout u32) int { - return C.SDL_SemWaitTimeout(sem, timeout) +// WARNING On some platforms this function is implemented by looping with a +// delay of 1 ms, and so should be avoided if possible. +pub fn sem_wait_timeout(sem &Sem, ms u32) int { + return C.SDL_SemWaitTimeout(sem, ms) } fn C.SDL_SemPost(sem &C.SDL_sem) int -// sem_post atomically increments a semaphore's value and wake waiting threads. -// -// `sem` the semaphore to increment -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. +// sem_post atomically increases the semaphore's count (not blocking). // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_CreateSemaphore -// See also: SDL_DestroySemaphore -// See also: SDL_SemTryWait -// See also: SDL_SemValue -// See also: SDL_SemWait -// See also: SDL_SemWaitTimeout +// returns 0, or -1 on error. pub fn sem_post(sem &Sem) int { return C.SDL_SemPost(sem) } fn C.SDL_SemValue(sem &C.SDL_sem) u32 -// sem_value gets the current value of a semaphore. -// -// `sem` the semaphore to query -// returns the current value of the semaphore. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_CreateSemaphore +// sem_value returns the current count of the semaphore. pub fn sem_value(sem &Sem) u32 { return C.SDL_SemValue(sem) } @@ -316,16 +152,30 @@ fn C.SDL_CreateCond() &C.SDL_cond // create_cond creates a condition variable. // -// returns a new condition variable or NULL on failure; call SDL_GetError() -// for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_CondBroadcast -// See also: SDL_CondSignal -// See also: SDL_CondWait -// See also: SDL_CondWaitTimeout -// See also: SDL_DestroyCond +// Typical use of condition variables: +// +// Thread A: +// SDL_LockMutex(lock); +// while ( ! condition ) { +// SDL_CondWait(cond, lock); +// } +// SDL_UnlockMutex(lock); +// +// Thread B: +// SDL_LockMutex(lock); +// ... +// condition = true; +// ... +// SDL_CondSignal(cond); +// SDL_UnlockMutex(lock); +// +// There is some discussion whether to signal the condition variable +// with the mutex locked or not. There is some potential performance +// benefit to unlocking first on some platforms, but there are some +// potential race conditions depending on how your code is structured. +// +// In general it's safer to signal the condition variable while the +// mutex is locked. pub fn create_cond() &Cond { return C.SDL_CreateCond() } @@ -333,16 +183,6 @@ pub fn create_cond() &Cond { fn C.SDL_DestroyCond(cond &C.SDL_cond) // destroy_cond destroys a condition variable. -// -// `cond` the condition variable to destroy -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_CondBroadcast -// See also: SDL_CondSignal -// See also: SDL_CondWait -// See also: SDL_CondWaitTimeout -// See also: SDL_CreateCond pub fn destroy_cond(cond &Cond) { C.SDL_DestroyCond(cond) } @@ -351,17 +191,7 @@ fn C.SDL_CondSignal(cond &C.SDL_cond) int // cond_signal restarts one of the threads that are waiting on the condition variable. // -// `cond` the condition variable to signal -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_CondBroadcast -// See also: SDL_CondWait -// See also: SDL_CondWaitTimeout -// See also: SDL_CreateCond -// See also: SDL_DestroyCond +// returns 0 or -1 on error. pub fn cond_signal(cond &Cond) int { return C.SDL_CondSignal(cond) } @@ -370,78 +200,32 @@ fn C.SDL_CondBroadcast(cond &C.SDL_cond) int // cond_broadcast restarts all threads that are waiting on the condition variable. // -// `cond` the condition variable to signal -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_CondSignal -// See also: SDL_CondWait -// See also: SDL_CondWaitTimeout -// See also: SDL_CreateCond -// See also: SDL_DestroyCond +// returns 0 or -1 on error. pub fn cond_broadcast(cond &Cond) int { return C.SDL_CondBroadcast(cond) } fn C.SDL_CondWait(cond &C.SDL_cond, mutex &C.SDL_mutex) int -// cond_wait waits until a condition variable is signaled. +// cond_wait waits on the condition variable, unlocking the provided mutex. // -// This function unlocks the specified `mutex` and waits for another thread to -// call SDL_CondSignal() or SDL_CondBroadcast() on the condition variable -// `cond`. Once the condition variable is signaled, the mutex is re-locked and -// the function returns. +// WARNING The mutex must be locked before entering this function! // -// The mutex must be locked before calling this function. +// The mutex is re-locked once the condition variable is signaled. // -// This function is the equivalent of calling SDL_CondWaitTimeout() with a -// time length of `SDL_MUTEX_MAXWAIT`. -// -// `cond` the condition variable to wait on -// `mutex` the mutex used to coordinate thread access -// returns 0 when it is signaled or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_CondBroadcast -// See also: SDL_CondSignal -// See also: SDL_CondWaitTimeout -// See also: SDL_CreateCond -// See also: SDL_DestroyCond +// returns 0 when it is signaled, or -1 on error. pub fn cond_wait(cond &Cond, mutex &Mutex) int { return C.SDL_CondWait(cond, mutex) } fn C.SDL_CondWaitTimeout(cond &C.SDL_cond, mutex &C.SDL_mutex, ms u32) int -// cond_wait_timeout waits until a condition variable is signaled or a certain time has passed. -// -// This function unlocks the specified `mutex` and waits for another thread to -// call SDL_CondSignal() or SDL_CondBroadcast() on the condition variable -// `cond`, or for the specified time to elapse. Once the condition variable is -// signaled or the time elapsed, the mutex is re-locked and the function -// returns. -// -// The mutex must be locked before calling this function. -// -// `cond` the condition variable to wait on -// `mutex` the mutex used to coordinate thread access -// `ms` the maximum time to wait, in milliseconds, or `SDL_MUTEX_MAXWAIT` -// to wait indefinitely -// returns 0 if the condition variable is signaled, `SDL_MUTEX_TIMEDOUT` if -// the condition is not signaled in the allotted time, or a negative -// error code on failure; call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. +// cond_wait_timeout waits for at most `ms` milliseconds, and returns 0 if the condition +// variable is signaled, ::SDL_MUTEX_TIMEDOUT if the condition is not +// signaled in the allotted time, and -1 on error. // -// See also: SDL_CondBroadcast -// See also: SDL_CondSignal -// See also: SDL_CondWait -// See also: SDL_CreateCond -// See also: SDL_DestroyCond +// WARNING On some platforms this function is implemented by looping with a +// delay of 1 ms, and so should be avoided if possible. pub fn cond_wait_timeout(cond &Cond, mutex &Mutex, ms u32) int { return C.SDL_CondWaitTimeout(cond, mutex, ms) } diff --git a/pixels.c.v b/pixels.c.v index ae774d82..5249fcc7 100644 --- a/pixels.c.v +++ b/pixels.c.v @@ -29,8 +29,6 @@ pub enum PixelType { arrayu32 = C.SDL_PIXELTYPE_ARRAYU32 arrayf16 = C.SDL_PIXELTYPE_ARRAYF16 arrayf32 = C.SDL_PIXELTYPE_ARRAYF32 - // This must be at the end of the list to avoid breaking the existing ABI - index2 = C.SDL_PIXELTYPE_INDEX2 } // Bitmap pixel order, high bit -> low bit. @@ -85,19 +83,12 @@ pub enum Format { unknown = C.SDL_PIXELFORMAT_UNKNOWN index1lsb = C.SDL_PIXELFORMAT_INDEX1LSB index1msb = C.SDL_PIXELFORMAT_INDEX1MSB - index2lsb = C.SDL_PIXELFORMAT_INDEX2LSB - index2msb = C.SDL_PIXELFORMAT_INDEX2MSB index4lsb = C.SDL_PIXELFORMAT_INDEX4LSB index4msb = C.SDL_PIXELFORMAT_INDEX4MSB index8 = C.SDL_PIXELFORMAT_INDEX8 rgb332 = C.SDL_PIXELFORMAT_RGB332 - xrgb4444 = C.SDL_PIXELFORMAT_XRGB4444 rgb444 = C.SDL_PIXELFORMAT_RGB444 - xbgr4444 = C.SDL_PIXELFORMAT_XBGR4444 - bgr444 = C.SDL_PIXELFORMAT_BGR444 - xrgb1555 = C.SDL_PIXELFORMAT_XRGB1555 rgb555 = C.SDL_PIXELFORMAT_RGB555 - xbgr1555 = C.SDL_PIXELFORMAT_XBGR1555 bgr555 = C.SDL_PIXELFORMAT_BGR555 argb4444 = C.SDL_PIXELFORMAT_ARGB4444 rgba4444 = C.SDL_PIXELFORMAT_RGBA4444 @@ -111,10 +102,8 @@ pub enum Format { bgr565 = C.SDL_PIXELFORMAT_BGR565 rgb24 = C.SDL_PIXELFORMAT_RGB24 bgr24 = C.SDL_PIXELFORMAT_BGR24 - xrgb8888 = C.SDL_PIXELFORMAT_XRGB8888 rgb888 = C.SDL_PIXELFORMAT_RGB888 rgbx8888 = C.SDL_PIXELFORMAT_RGBX8888 - xbgr8888 = C.SDL_PIXELFORMAT_XBGR8888 bgr888 = C.SDL_PIXELFORMAT_BGR888 bgrx8888 = C.SDL_PIXELFORMAT_BGRX8888 argb8888 = C.SDL_PIXELFORMAT_ARGB8888 @@ -145,11 +134,6 @@ pub mut: a u8 } -// Color structure -// The bits of this structure can be directly reinterpreted as an integer-packed -// color which uses the SDL_PIXELFORMAT_RGBA32 format (SDL_PIXELFORMAT_ABGR8888 -// on little-endian systems and SDL_PIXELFORMAT_RGBA8888 on big-endian systems). -// Color is C.SDL_Color pub type Color = C.SDL_Color @[typedef] @@ -193,119 +177,65 @@ pub type PixelFormat = C.SDL_PixelFormat fn C.SDL_GetPixelFormatName(format Format) &char -// get_pixel_format_name gets the human readable name of a pixel format. -// -// `format` the pixel format to query -// returns the human readable name of the specified pixel format or -// `SDL_PIXELFORMAT_UNKNOWN` if the format isn't recognized. -// -// NOTE This function is available since SDL 2.0.0. +// get the human readable name of a pixel format pub fn get_pixel_format_name(format Format) &char { return C.SDL_GetPixelFormatName(format) } fn C.SDL_PixelFormatEnumToMasks(format Format, bpp &int, rmask &u32, gmask &u32, bmask &u32, amask &u32) bool -// pixel_format_enum_to_masks converts one of the enumerated pixel formats to a bpp value and RGBA masks. -// -// `format` one of the SDL_PixelFormatEnum values -// `bpp` a bits per pixel value; usually 15, 16, or 32 -// `Rmask` a pointer filled in with the red mask for the format -// `Gmask` a pointer filled in with the green mask for the format -// `Bmask` a pointer filled in with the blue mask for the format -// `Amask` a pointer filled in with the alpha mask for the format -// returns SDL_TRUE on success or SDL_FALSE if the conversion wasn't -// possible; call SDL_GetError() for more information. +// pixel_format_enum_to_masks converts one of the enumerated pixel formats to a bpp and RGBA masks. // -// NOTE This function is available since SDL 2.0.0. +// returns SDL_TRUE, or SDL_FALSE if the conversion wasn't possible. // -// See also: SDL_MasksToPixelFormatEnum +// See also: SDL_MasksToPixelFormatEnum() pub fn pixel_format_enum_to_masks(format Format, bpp &int, rmask &u32, gmask &u32, bmask &u32, amask &u32) bool { return C.SDL_PixelFormatEnumToMasks(format, bpp, rmask, gmask, bmask, amask) } fn C.SDL_MasksToPixelFormatEnum(bpp int, rmask u32, gmask u32, bmask u32, amask u32) u32 -// masks_to_pixel_format_enum converts a bpp value and RGBA masks to an enumerated pixel format. +// masks_to_pixel_format_enum converts a bpp and RGBA masks to an enumerated pixel format. // -// This will return `SDL_PIXELFORMAT_UNKNOWN` if the conversion wasn't -// possible. +// returns The pixel format, or ::SDL_PIXELFORMAT_UNKNOWN if the conversion +// wasn't possible. // -// `bpp` a bits per pixel value; usually 15, 16, or 32 -// `Rmask` the red mask for the format -// `Gmask` the green mask for the format -// `Bmask` the blue mask for the format -// `Amask` the alpha mask for the format -// returns one of the SDL_PixelFormatEnum values -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_PixelFormatEnumToMasks +// See also: SDL_PixelFormatEnumToMasks() pub fn masks_to_pixel_format_enum(bpp int, rmask u32, gmask u32, bmask u32, amask u32) Format { return unsafe { Format(C.SDL_MasksToPixelFormatEnum(bpp, rmask, gmask, bmask, amask)) } } fn C.SDL_AllocFormat(pixel_format Format) &C.SDL_PixelFormat -// alloc_format creates an SDL_PixelFormat structure corresponding to a pixel format. -// -// Returned structure may come from a shared global cache (i.e. not newly -// allocated), and hence should not be modified, especially the palette. Weird -// errors such as `Blit combination not supported` may occur. -// -// `pixel_format` one of the SDL_PixelFormatEnum values -// returns the new SDL_PixelFormat structure or NULL on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_FreeFormat +// alloc_format creates an SDL_PixelFormat structure from a pixel format enum. pub fn alloc_format(pixel_format Format) &PixelFormat { return C.SDL_AllocFormat(pixel_format) } fn C.SDL_FreeFormat(format &C.SDL_PixelFormat) -// free_format frees an SDL_PixelFormat structure allocated by SDL_AllocFormat(). -// -// `format` the SDL_PixelFormat structure to free -// -// See also: SDL_AllocFormat +// free_format frees an SDL_PixelFormat structure. pub fn free_format(format &PixelFormat) { C.SDL_FreeFormat(format) } fn C.SDL_AllocPalette(ncolors int) &C.SDL_Palette -// alloc_palette creates a palette structure with the specified number of color entries. -// -// The palette entries are initialized to white. +// alloc_palette create a palette structure with the specified +// number of color entries. // -// `ncolors` represents the number of color entries in the color palette -// returns a new SDL_Palette structure on success or NULL on failure (e.g. if -// there wasn't enough memory); call SDL_GetError() for more -// information. +// returns A new palette, or NULL if there wasn't enough memory. // -// NOTE This function is available since SDL 2.0.0. +// NOTE The palette entries are initialized to white. // -// See also: SDL_FreePalette +// See also: SDL_FreePalette() pub fn alloc_palette(ncolors int) &Palette { return C.SDL_AllocPalette(ncolors) } fn C.SDL_SetPixelFormatPalette(format &C.SDL_PixelFormat, palette &C.SDL_Palette) int -// set_pixel_format_palette sets the palette for a pixel format structure. -// -// `format` the SDL_PixelFormat structure that will use the palette -// `palette` the SDL_Palette structure that will be used -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_AllocPalette -// See also: SDL_FreePalette +// set_pixel_format_palette set the palette for a pixel format structure. pub fn set_pixel_format_palette(format &PixelFormat, palette &Palette) int { return C.SDL_SetPixelFormatPalette(format, palette) } @@ -314,17 +244,12 @@ fn C.SDL_SetPaletteColors(palette &C.SDL_Palette, const_colors &C.SDL_Color, fir // set_palette_colors sets a range of colors in a palette. // -// `palette` the SDL_Palette structure to modify -// `colors` an array of SDL_Color structures to copy into the palette -// `firstcolor` the index of the first palette entry to modify -// `ncolors` the number of entries to modify -// returns 0 on success or a negative error code if not all of the colors -// could be set; call SDL_GetError() for more information. +// `palette` The palette to modify. +// `colors` An array of colors to copy into the palette. +// `firstcolor` The index of the first palette entry to modify. +// `ncolors` The number of entries to modify. // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_AllocPalette -// See also: SDL_CreateRGBSurface +// returns 0 on success, or -1 if not all of the colors could be set. pub fn set_palette_colors(palette &Palette, const_colors &Color, firstcolor int, nconst_colors int) int { return C.SDL_SetPaletteColors(palette, const_colors, firstcolor, nconst_colors) } @@ -332,12 +257,6 @@ pub fn set_palette_colors(palette &Palette, const_colors &Color, firstcolor int, fn C.SDL_FreePalette(palette &C.SDL_Palette) // free_palette frees a palette created with SDL_AllocPalette(). -// -// `palette` the SDL_Palette structure to be freed -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_AllocPalette pub fn free_palette(palette &Palette) { C.SDL_FreePalette(palette) } @@ -345,33 +264,6 @@ pub fn free_palette(palette &Palette) { fn C.SDL_MapRGB(format &C.SDL_PixelFormat, r u8, g u8, b u8) u32 // map_rgb maps an RGB triple to an opaque pixel value for a given pixel format. -// -// This function maps the RGB color value to the specified pixel format and -// returns the pixel value best approximating the given RGB color value for -// the given pixel format. -// -// If the format has a palette (8-bit) the index of the closest matching color -// in the palette will be returned. -// -// If the specified pixel format has an alpha component it will be returned as -// all 1 bits (fully opaque). -// -// If the pixel format bpp (color depth) is less than 32-bpp then the unused -// upper bits of the return value can safely be ignored (e.g., with a 16-bpp -// format the return value can be assigned to a Uint16, and similarly a Uint8 -// for an 8-bpp format). -// -// `format` an SDL_PixelFormat structure describing the pixel format -// `r` the red component of the pixel in the range 0-255 -// `g` the green component of the pixel in the range 0-255 -// `b` the blue component of the pixel in the range 0-255 -// returns a pixel value -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetRGB -// See also: SDL_GetRGBA -// See also: SDL_MapRGBA pub fn map_rgb(format &PixelFormat, r u8, g u8, b u8) u32 { return C.SDL_MapRGB(format, r, g, b) } @@ -379,89 +271,20 @@ pub fn map_rgb(format &PixelFormat, r u8, g u8, b u8) u32 { fn C.SDL_MapRGBA(format &C.SDL_PixelFormat, r u8, g u8, b u8, a u8) u32 // map_rgba maps an RGBA quadruple to a pixel value for a given pixel format. -// -// This function maps the RGBA color value to the specified pixel format and -// returns the pixel value best approximating the given RGBA color value for -// the given pixel format. -// -// If the specified pixel format has no alpha component the alpha value will -// be ignored (as it will be in formats with a palette). -// -// If the format has a palette (8-bit) the index of the closest matching color -// in the palette will be returned. -// -// If the pixel format bpp (color depth) is less than 32-bpp then the unused -// upper bits of the return value can safely be ignored (e.g., with a 16-bpp -// format the return value can be assigned to a Uint16, and similarly a Uint8 -// for an 8-bpp format). -// -// `format` an SDL_PixelFormat structure describing the format of the -// pixel -// `r` the red component of the pixel in the range 0-255 -// `g` the green component of the pixel in the range 0-255 -// `b` the blue component of the pixel in the range 0-255 -// `a` the alpha component of the pixel in the range 0-255 -// returns a pixel value -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetRGB -// See also: SDL_GetRGBA -// See also: SDL_MapRGB pub fn map_rgba(format &PixelFormat, r u8, g u8, b u8, a u8) u32 { return C.SDL_MapRGBA(format, r, g, b, a) } fn C.SDL_GetRGB(pixel u32, const_format &C.SDL_PixelFormat, r &u8, g &u8, b &u8) -// get_rgb gets RGB values from a pixel in the specified format. -// -// This function uses the entire 8-bit [0..255] range when converting color -// components from pixel formats with less than 8-bits per RGB component -// (e.g., a completely white pixel in 16-bit RGB565 format would return [0xff, -// 0xff, 0xff] not [0xf8, 0xfc, 0xf8]). -// -// `pixel` a pixel value -// `format` an SDL_PixelFormat structure describing the format of the -// pixel -// `r` a pointer filled in with the red component -// `g` a pointer filled in with the green component -// `b` a pointer filled in with the blue component -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetRGBA -// See also: SDL_MapRGB -// See also: SDL_MapRGBA +// get_rgb gets the RGB components from a pixel of the specified format. pub fn get_rgb(pixel u32, const_format &PixelFormat, r &u8, g &u8, b &u8) { C.SDL_GetRGB(pixel, const_format, r, g, b) } fn C.SDL_GetRGBA(pixel u32, const_format &C.SDL_PixelFormat, r &u8, g &u8, b &u8, a &u8) -// get_rgba gets RGBA values from a pixel in the specified format. -// -// This function uses the entire 8-bit [0..255] range when converting color -// components from pixel formats with less than 8-bits per RGB component -// (e.g., a completely white pixel in 16-bit RGB565 format would return [0xff, -// 0xff, 0xff] not [0xf8, 0xfc, 0xf8]). -// -// If the surface has no alpha component, the alpha will be returned as 0xff -// (100% opaque). -// -// `pixel` a pixel value -// `format` an SDL_PixelFormat structure describing the format of the -// pixel -// `r` a pointer filled in with the red component -// `g` a pointer filled in with the green component -// `b` a pointer filled in with the blue component -// `a` a pointer filled in with the alpha component -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetRGB -// See also: SDL_MapRGB -// See also: SDL_MapRGBA +// get_rgba gets the RGBA components from a pixel of the specified format. pub fn get_rgba(pixel u32, const_format &PixelFormat, r &u8, g &u8, b &u8, a &u8) { C.SDL_GetRGBA(pixel, const_format, r, g, b, a) } @@ -469,13 +292,6 @@ pub fn get_rgba(pixel u32, const_format &PixelFormat, r &u8, g &u8, b &u8, a &u8 fn C.SDL_CalculateGammaRamp(gamma f32, ramp &u16) // calculate_gamma_ramp calculates a 256 entry gamma ramp for a gamma value. -// -// `gamma` a gamma value where 0.0 is black and 1.0 is identity -// `ramp` an array of 256 values filled in with the gamma ramp -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_SetWindowGammaRamp pub fn calculate_gamma_ramp(gamma f32, ramp &u16) { C.SDL_CalculateGammaRamp(gamma, ramp) } diff --git a/platform.c.v b/platform.c.v index 32dccaef..ede06608 100644 --- a/platform.c.v +++ b/platform.c.v @@ -10,21 +10,6 @@ module sdl fn C.SDL_GetPlatform() &char // get_platform gets the name of the platform. -// -// Here are the names returned for some (but not all) supported platforms: -// -// - "Windows" -// - "Mac OS X" -// - "Linux" -// - "iOS" -// - "Android" -// -// returns the name of the platform. If the correct platform name is not -// available, returns a string beginning with the text "Unknown". -// -// NOTE This function is available since SDL 2.0.0. -// -// NOTE the returned &char is const pub fn get_platform() &char { return C.SDL_GetPlatform() } diff --git a/power.c.v b/power.c.v index 1629d47d..28d4d801 100644 --- a/power.c.v +++ b/power.c.v @@ -17,32 +17,19 @@ pub enum PowerState { charged = C.SDL_POWERSTATE_CHARGED // Plugged in, battery charged } -fn C.SDL_GetPowerInfo(seconds &int, percent &int) PowerState +fn C.SDL_GetPowerInfo(secs &int, pct &int) PowerState // get_power_info gets the current power supply details. // -// You should never take a battery status as absolute truth. Batteries -// (especially failing batteries) are delicate hardware, and the values -// reported here are best estimates based on what that hardware reports. It's -// not uncommon for older batteries to lose stored power much faster than it -// reports, or completely drain when reporting it has 20 percent left, etc. +// `secs` Seconds of battery life left. You can pass a NULL here if +// you don't care. Will return -1 if we can't determine a +// value, or we're not running on a battery. // -// Battery status can change at any time; if you are concerned with power -// state, you should call this function frequently, and perhaps ignore changes -// until they seem to be stable for a few seconds. +// `pct` Percentage of battery life left, between 0 and 100. You can +// pass a NULL here if you don't care. Will return -1 if we +// can't determine a value, or we're not running on a battery. // -// It's possible a platform can only report battery percentage or time left -// but not both. -// -// `seconds` seconds of battery life left, you can pass a NULL here if -// you don't care, will return -1 if we can't determine a -// value, or we're not running on a battery -// `percent` percentage of battery life left, between 0 and 100, you can -// pass a NULL here if you don't care, will return -1 if we -// can't determine a value, or we're not running on a battery -// returns an SDL_PowerState enum representing the current battery state. -// -// NOTE This function is available since SDL 2.0.0. -pub fn get_power_info(seconds &int, percent &int) PowerState { - return PowerState(C.SDL_GetPowerInfo(seconds, percent)) +// returns The state of the battery (if any). +pub fn get_power_info(secs &int, pct &int) PowerState { + return PowerState(C.SDL_GetPowerInfo(secs, pct)) } diff --git a/rect.c.v b/rect.c.v index ac8e0b7e..51dd81fd 100644 --- a/rect.c.v +++ b/rect.c.v @@ -7,7 +7,7 @@ module sdl // SDL_rect.h // -// Point is the structure that defines a point (integer) +// Point is the structure that defines a point // // See also: SDL_EnclosePoints // See also: SDL_PointInRect @@ -21,27 +21,12 @@ pub mut: pub type Point = C.SDL_Point -// FPoint is the structure that defines a point (floating point) -// -// See also: SDL_EncloseFPoints -// See also: SDL_PointInFRect -// FPoint is C.SDL_FPoint -@[typedef] -pub struct C.SDL_FPoint { -pub mut: - x f32 - y f32 -} - -pub type FPoint = C.SDL_FPoint - -// Rect is a rectangle, with the origin at the upper left (integer). +// Rect is a rectangle, with the origin at the upper left. // // See also: SDL_RectEmpty // See also: SDL_RectEquals // See also: SDL_HasIntersection // See also: SDL_IntersectRect -// See also: SDL_IntersectRectAndLine // See also: SDL_UnionRect // See also: SDL_EnclosePoints // Rect is C.SDL_Rect @@ -56,30 +41,6 @@ pub mut: pub type Rect = C.SDL_Rect -// FRect is a rectangle, with the origin at the upper left (floating point). -// -// See also: SDL_FRectEmpty -// See also: SDL_FRectEquals -// See also: SDL_FRectEqualsEpsilon -// See also: SDL_HasIntersectionF -// See also: SDL_IntersectFRect -// See also: SDL_IntersectFRectAndLine -// See also: SDL_UnionFRect -// See also: SDL_EncloseFPoints -// See also: SDL_PointInFRect -// -// FRect is C.SDL_FRect -@[typedef] -pub struct C.SDL_FRect { -pub mut: - x f32 - y f32 - w f32 - h f32 -} - -pub type FRect = C.SDL_FRect - fn C.SDL_PointInRect(const_p &C.SDL_Point, const_r &C.SDL_Rect) bool // point_in_rect returns true if point resides inside a rectangle. @@ -103,17 +64,9 @@ pub fn rect_equals(const_a &Rect, const_b &Rect) bool { fn C.SDL_HasIntersection(const_a &C.SDL_Rect, const_b &C.SDL_Rect) bool -// has_intersection determines whether two rectangles intersect. +// has_intersection determine whether two rectangles intersect. // -// If either pointer is NULL the function will return SDL_FALSE. -// -// `A` an SDL_Rect structure representing the first rectangle -// `B` an SDL_Rect structure representing the second rectangle // returns SDL_TRUE if there is an intersection, SDL_FALSE otherwise. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_IntersectRect @[inline] pub fn has_intersection(const_a &Rect, const_b &Rect) bool { return C.SDL_HasIntersection(const_a, const_b) @@ -121,19 +74,9 @@ pub fn has_intersection(const_a &Rect, const_b &Rect) bool { fn C.SDL_IntersectRect(const_a &C.SDL_Rect, const_b &C.SDL_Rect, result &C.SDL_Rect) bool -// intersect_rect calculates the intersection of two rectangles. -// -// If `result` is NULL then this function will return SDL_FALSE. +// intersect_rect calculate the intersection of two rectangles. // -// `A` an SDL_Rect structure representing the first rectangle -// `B` an SDL_Rect structure representing the second rectangle -// `result` an SDL_Rect structure filled in with the intersection of -// rectangles `A` and `B` // returns SDL_TRUE if there is an intersection, SDL_FALSE otherwise. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_HasIntersection pub fn intersect_rect(const_a &Rect, const_b &Rect, result &Rect) bool { return C.SDL_IntersectRect(const_a, const_b, result) } @@ -141,34 +84,15 @@ pub fn intersect_rect(const_a &Rect, const_b &Rect, result &Rect) bool { fn C.SDL_UnionRect(const_a &C.SDL_Rect, const_b &C.SDL_Rect, result &C.SDL_Rect) // union_rect calculates the union of two rectangles. -// -// `A` an SDL_Rect structure representing the first rectangle -// `B` an SDL_Rect structure representing the second rectangle -// `result` an SDL_Rect structure filled in with the union of rectangles -// `A` and `B` -// -// NOTE This function is available since SDL 2.0.0. pub fn union_rect(const_a &Rect, const_b &Rect, result &Rect) { C.SDL_UnionRect(const_a, const_b, result) } fn C.SDL_EnclosePoints(const_points &C.SDL_Point, count int, const_clip &C.SDL_Rect, result &C.SDL_Rect) bool -// enclose_points calculates a minimal rectangle enclosing a set of points. -// -// If `clip` is not NULL then only points inside of the clipping rectangle are -// considered. -// -// `points` an array of SDL_Point structures representing points to be -// enclosed -// `count` the number of structures in the `points` array -// `clip` an SDL_Rect used for clipping or NULL to enclose all points -// `result` an SDL_Rect structure filled in with the minimal enclosing -// rectangle -// returns SDL_TRUE if any points were enclosed or SDL_FALSE if all the -// points were outside of the clipping rectangle. +// enclose_points calculates a minimal rectangle enclosing a set of points // -// NOTE This function is available since SDL 2.0.0. +// returns SDL_TRUE if any points were within the clipping rect pub fn enclose_points(const_points &Point, count int, const_clip &Rect, result &Rect) bool { return C.SDL_EnclosePoints(const_points, count, const_clip, result) } @@ -177,149 +101,7 @@ fn C.SDL_IntersectRectAndLine(rect &C.SDL_Rect, x1 &int, y1 &int, x2 &int, y2 &i // intersect_rect_and_line calculates the intersection of a rectangle and line segment. // -// This function is used to clip a line segment to a rectangle. A line segment -// contained entirely within the rectangle or that does not intersect will -// remain unchanged. A line segment that crosses the rectangle at either or -// both ends will be clipped to the boundary of the rectangle and the new -// coordinates saved in `X1`, `Y1`, `X2`, and/or `Y2` as necessary. -// -// `rect` an SDL_Rect structure representing the rectangle to intersect -// `X1` a pointer to the starting X-coordinate of the line -// `Y1` a pointer to the starting Y-coordinate of the line -// `X2` a pointer to the ending X-coordinate of the line -// `Y2` a pointer to the ending Y-coordinate of the line // returns SDL_TRUE if there is an intersection, SDL_FALSE otherwise. -// -// NOTE This function is available since SDL 2.0.0. pub fn intersect_rect_and_line(rect &Rect, x1 &int, y1 &int, x2 &int, y2 &int) bool { return C.SDL_IntersectRectAndLine(rect, x1, y1, x2, y2) } - -// SDL_FRect versions... - -fn C.SDL_PointInFRect(const_p &C.SDL_FPoint, const_r &C.SDL_FRect) bool - -// point_in_frect returns true if point resides inside a rectangle. -pub fn point_in_frect(const_p &FPoint, const_r &FRect) bool { - return C.SDL_PointInFRect(const_p, const_r) -} - -fn C.SDL_FRectEmpty(const_r &C.SDL_FRect) bool - -// frect_empty returns true if the rectangle has no area. -pub fn frect_empty(const_r &FRect) bool { - return C.SDL_FRectEmpty(const_r) -} - -fn C.SDL_FRectEqualsEpsilon(const_a &C.SDL_FRect, const_b &C.SDL_FRect, const_epsilon f32) bool - -// frect_equals_epsilon returns true if the two rectangles are equal, within some given epsilon. -// -// NOTE This function is available since SDL 2.0.22. -pub fn frect_equals_epsilon(const_a &FRect, const_b &FRect, const_epsilon f32) bool { - return C.SDL_FRectEqualsEpsilon(const_a, const_b, const_epsilon) -} - -fn C.SDL_FRectEquals(const_a &C.SDL_FRect, const_b &C.SDL_FRect) bool - -// frect_equals returns true if the two rectangles are equal, using a default epsilon. -// -// NOTE This function is available since SDL 2.0.22. -pub fn frect_equals(const_a &FRect, const_b &FRect) bool { - return C.SDL_FRectEquals(const_a, const_b) -} - -fn C.SDL_HasIntersectionF(const_a &C.SDL_FRect, const_b &C.SDL_FRect) bool - -// has_intersection_f determines whether two rectangles intersect with float precision. -// -// If either pointer is NULL the function will return SDL_FALSE. -// -// `A` an SDL_FRect structure representing the first rectangle -// `B` an SDL_FRect structure representing the second rectangle -// returns SDL_TRUE if there is an intersection, SDL_FALSE otherwise. -// -// NOTE This function is available since SDL 2.0.22. -// -// See also: SDL_IntersectRect -pub fn has_intersection_f(const_a &FRect, const_b &FRect) bool { - return C.SDL_HasIntersectionF(const_a, const_b) -} - -fn C.SDL_IntersectFRect(const_a &C.SDL_FRect, const_b &C.SDL_FRect, result &C.SDL_FRect) bool - -// intersect_frect calculates the intersection of two rectangles with float precision. -// -// If `result` is NULL then this function will return SDL_FALSE. -// -// `A` an SDL_FRect structure representing the first rectangle -// `B` an SDL_FRect structure representing the second rectangle -// `result` an SDL_FRect structure filled in with the intersection of -// rectangles `A` and `B` -// returns SDL_TRUE if there is an intersection, SDL_FALSE otherwise. -// -// NOTE This function is available since SDL 2.0.22. -// -// See also: SDL_HasIntersectionF -pub fn intersect_frect(const_a &FRect, const_b &FRect, result &FRect) bool { - return C.SDL_IntersectFRect(const_a, const_b, result) -} - -fn C.SDL_UnionFRect(const_a &C.SDL_FRect, const_b &C.SDL_FRect, result &C.SDL_FRect) - -// union_frect calculates the union of two rectangles with float precision. -// -// `A` an SDL_FRect structure representing the first rectangle -// `B` an SDL_FRect structure representing the second rectangle -// `result` an SDL_FRect structure filled in with the union of rectangles -// `A` and `B` -// -// NOTE This function is available since SDL 2.0.22. -pub fn union_frect(const_a &FRect, const_b &FRect, result &FRect) { - C.SDL_UnionFRect(const_a, const_b, result) -} - -fn C.SDL_EncloseFPoints(const_points &C.SDL_FPoint, count int, const_clip &C.SDL_FRect, result &C.SDL_FRect) bool - -// enclose_f_points calculates a minimal rectangle enclosing a set of points with float -// precision. -// -// If `clip` is not NULL then only points inside of the clipping rectangle are -// considered. -// -// `points` an array of SDL_FPoint structures representing points to be -// enclosed -// `count` the number of structures in the `points` array -// `clip` an SDL_FRect used for clipping or NULL to enclose all points -// `result` an SDL_FRect structure filled in with the minimal enclosing -// rectangle -// returns SDL_TRUE if any points were enclosed or SDL_FALSE if all the -// points were outside of the clipping rectangle. -// -// NOTE This function is available since SDL 2.0.22. -pub fn enclose_f_points(const_points &FPoint, count int, const_clip &FRect, result &FRect) bool { - return C.SDL_EncloseFPoints(const_points, count, const_clip, result) -} - -fn C.SDL_IntersectFRectAndLine(const_rect &C.SDL_FRect, x1 &f32, y1 &f32, x2 &f32, y2 &f32) bool - -// intersect_frect_and_line calculates the intersection of a rectangle and line segment with float -// precision. -// -// This function is used to clip a line segment to a rectangle. A line segment -// contained entirely within the rectangle or that does not intersect will -// remain unchanged. A line segment that crosses the rectangle at either or -// both ends will be clipped to the boundary of the rectangle and the new -// coordinates saved in `X1`, `Y1`, `X2`, and/or `Y2` as necessary. -// -// `rect` an SDL_FRect structure representing the rectangle to intersect -// `X1` a pointer to the starting X-coordinate of the line -// `Y1` a pointer to the starting Y-coordinate of the line -// `X2` a pointer to the ending X-coordinate of the line -// `Y2` a pointer to the ending Y-coordinate of the line -// returns SDL_TRUE if there is an intersection, SDL_FALSE otherwise. -// -// NOTE This function is available since SDL 2.0.22. -pub fn intersect_frect_and_line(const_rect &FRect, x1 &f32, y1 &f32, x2 &f32, y2 &f32) bool { - return C.SDL_IntersectFRectAndLine(const_rect, x1, y1, x2, y2) -} diff --git a/render.c.v b/render.c.v index 40ecc1b1..939a1821 100644 --- a/render.c.v +++ b/render.c.v @@ -24,7 +24,7 @@ module sdl // of the many good 3D engines. // // These functions must be called from the main thread. -// See this bug for details: https://github.com/libsdl-org/SDL/issues/986 +// See this bug for details: http://bugzilla.libsdl.org/show_bug.cgi?id=1995 // RendererFlags is C.SDL_RendererFlags pub enum RendererFlags { @@ -47,25 +47,6 @@ pub: pub type RendererInfo = C.SDL_RendererInfo -@[typedef] -pub struct C.SDL_Vertex { - position FPoint // Vertex position, in SDL_Renderer coordinates - color Color // Vertex color - tex_coord FPoint // Normalized texture coordinates, if needed -} - -// Vertex structure -// Vertex is C.SDL_Vertex -pub type Vertex = C.SDL_Vertex - -// The scaling mode for a texture. -// ScaleMode is C.SDL_ScaleMode -pub enum ScaleMode { - nearest = C.SDL_ScaleModeNearest // nearest pixel sampling - linear = C.SDL_ScaleModeLinear // linear filtering - best = C.SDL_ScaleModeBest // anisotropic filtering -} - // TextureAccess is C.SDL_TextureAccess pub enum TextureAccess { @static = C.SDL_TEXTUREACCESS_STATIC // Changes rarely, not lockable @@ -101,60 +82,46 @@ pub type Texture = C.SDL_Texture fn C.SDL_GetNumRenderDrivers() int -// get_num_render_drivers gets the number of 2D rendering drivers available for the current display. +// get_num_render_drivers gets the number of 2D rendering drivers available for the current +// display. // // A render driver is a set of code that handles rendering and texture -// management on a particular display. Normally there is only one, but some -// drivers may have several available with different capabilities. +// management on a particular display. Normally there is only one, but +// some drivers may have several available with different capabilities. // -// There may be none if SDL was compiled without render support. -// -// returns a number >= 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_CreateRenderer -// See also: SDL_GetRenderDriverInfo +// See also: SDL_GetRenderDriverInfo() +// See also: SDL_CreateRenderer() pub fn get_num_render_drivers() int { return C.SDL_GetNumRenderDrivers() } fn C.SDL_GetRenderDriverInfo(index int, info &C.SDL_RendererInfo) int -// get_render_driver_info gets info about a specific 2D rendering driver for the current display. +// get_render_driver_info gets information about a specific 2D rendering driver for the current +// display. // -// `index` the index of the driver to query information about -// `info` an SDL_RendererInfo structure to be filled with information on -// the rendering driver -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. +// `index` The index of the driver to query information about. +// `info` A pointer to an SDL_RendererInfo struct to be filled with +// information on the rendering driver. // -// NOTE This function is available since SDL 2.0.0. +// returns 0 on success, -1 if the index was out of range. // -// See also: SDL_CreateRenderer -// See also: SDL_GetNumRenderDrivers +// See also: SDL_CreateRenderer() pub fn get_render_driver_info(index int, info &RendererInfo) int { return C.SDL_GetRenderDriverInfo(index, info) } fn C.SDL_CreateWindowAndRenderer(width int, height int, window_flags u32, window &&C.SDL_Window, renderer &&C.SDL_Renderer) int -// create_window_and_renderer creates a window and default renderer. +// create_window_and_renderer creates a window and default renderer // -// `width` the width of the window -// `height` the height of the window -// `window_flags` the flags used to create the window (see -// SDL_CreateWindow()) -// `window` a pointer filled with the window, or NULL on error -// `renderer` a pointer filled with the renderer, or NULL on error -// returns 0 on success, or -1 on error; call SDL_GetError() for more -// information. +// `width` The width of the window +// `height` The height of the window +// `window_flags` The flags used to create the window +// `window` A pointer filled with the window, or NULL on error +// `renderer` A pointer filled with the renderer, or NULL on error // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_CreateRenderer -// See also: SDL_CreateWindow +// returns 0 on success, or -1 on error pub fn create_window_and_renderer(width int, height int, window_flags u32, window &&Window, renderer &&Renderer) int { return C.SDL_CreateWindowAndRenderer(width, height, window_flags, window, renderer) } @@ -163,19 +130,16 @@ fn C.SDL_CreateRenderer(window &C.SDL_Window, index int, flags u32) &C.SDL_Rende // create_renderer creates a 2D rendering context for a window. // -// `window` the window where rendering is displayed -// `index` the index of the rendering driver to initialize, or -1 to -// initialize the first one supporting the requested flags -// `flags` 0, or one or more SDL_RendererFlags OR'd together -// returns a valid rendering context or NULL if there was an error; call -// SDL_GetError() for more information. +// `window` The window where rendering is displayed. +// `index` The index of the rendering driver to initialize, or -1 to +// initialize the first one supporting the requested flags. +// `flags` ::SDL_RendererFlags. // -// NOTE This function is available since SDL 2.0.0. +// returns A valid rendering context or NULL if there was an error. // -// See also: SDL_CreateSoftwareRenderer -// See also: SDL_DestroyRenderer -// See also: SDL_GetNumRenderDrivers -// See also: SDL_GetRendererInfo +// See also: SDL_CreateSoftwareRenderer() +// See also: SDL_GetRendererInfo() +// See also: SDL_DestroyRenderer() pub fn create_renderer(window &Window, index int, flags u32) &Renderer { return C.SDL_CreateRenderer(window, index, flags) } @@ -184,21 +148,12 @@ fn C.SDL_CreateSoftwareRenderer(surface &C.SDL_Surface) &C.SDL_Renderer // create_software_renderer creates a 2D software rendering context for a surface. // -// Two other API which can be used to create SDL_Renderer: -// SDL_CreateRenderer() and SDL_CreateWindowAndRenderer(). These can _also_ -// create a software renderer, but they are intended to be used with an -// SDL_Window as the final destination and not an SDL_Surface. +// `surface` The surface where rendering is done. // -// `surface` the SDL_Surface structure representing the surface where -// rendering is done -// returns a valid rendering context or NULL if there was an error; call -// SDL_GetError() for more information. +// returns A valid rendering context or NULL if there was an error. // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_CreateRenderer -// See also: SDL_CreateWindowRenderer -// See also: SDL_DestroyRenderer +// See also: SDL_CreateRenderer() +// See also: SDL_DestroyRenderer() pub fn create_software_renderer(surface &Surface) &Renderer { return C.SDL_CreateSoftwareRenderer(surface) } @@ -206,44 +161,13 @@ pub fn create_software_renderer(surface &Surface) &Renderer { fn C.SDL_GetRenderer(window &C.SDL_Window) &C.SDL_Renderer // get_renderer gets the renderer associated with a window. -// -// `window` the window to query -// returns the rendering context on success or NULL on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_CreateRenderer pub fn get_renderer(window &Window) &Renderer { return C.SDL_GetRenderer(window) } -fn C.SDL_RenderGetWindow(renderer &C.SDL_Renderer) &C.SDL_Window - -// render_get_window gets the window associated with a renderer. -// -// `renderer` the renderer to query -// returns the window on success or NULL on failure; call SDL_GetError() for -// more information. -// -// NOTE This function is available since SDL 2.0.22. -pub fn render_get_window(renderer &Renderer) &Window { - return C.SDL_RenderGetWindow(renderer) -} - fn C.SDL_GetRendererInfo(renderer &C.SDL_Renderer, info &C.SDL_RendererInfo) int // get_renderer_info gets information about a rendering context. -// -// `renderer` the rendering context -// `info` an SDL_RendererInfo structure filled with information about the -// current renderer -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_CreateRenderer pub fn get_renderer_info(renderer &Renderer, info &RendererInfo) int { return C.SDL_GetRendererInfo(renderer, info) } @@ -251,20 +175,6 @@ pub fn get_renderer_info(renderer &Renderer, info &RendererInfo) int { fn C.SDL_GetRendererOutputSize(renderer &C.SDL_Renderer, w &int, h &int) int // get_renderer_output_size gets the output size in pixels of a rendering context. -// -// Due to high-dpi displays, you might end up with a rendering context that -// has more pixels than the window that contains it, so use this instead of -// SDL_GetWindowSize() to decide how much drawing area you have. -// -// `renderer` the rendering context -// `w` an int filled with the width -// `h` an int filled with the height -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetRenderer pub fn get_renderer_output_size(renderer &Renderer, w &int, h &int) int { return C.SDL_GetRendererOutputSize(renderer, w, h) } @@ -273,24 +183,21 @@ fn C.SDL_CreateTexture(renderer &C.SDL_Renderer, format u32, access int, w int, // create_texture creates a texture for a rendering context. // -// You can set the texture scaling method by setting -// `SDL_HINT_RENDER_SCALE_QUALITY` before creating the texture. +// `renderer` The renderer. +// `format` The format of the texture. +// `access` One of the enumerated values in ::SDL_TextureAccess. +// `w` The width of the texture in pixels. +// `h` The height of the texture in pixels. // -// `renderer` the rendering context -// `format` one of the enumerated values in SDL_PixelFormatEnum -// `access` one of the enumerated values in SDL_TextureAccess -// `w` the width of the texture in pixels -// `h` the height of the texture in pixels -// returns a pointer to the created texture or NULL if no rendering context -// was active, the format was unsupported, or the width or height -// were out of range; call SDL_GetError() for more information. +// returns The created texture is returned, or NULL if no rendering context was +// active, the format was unsupported, or the width or height were out +// of range. // -// NOTE This function is available since SDL 2.0.0. +// NOTE The contents of the texture are not defined at creation. // -// See also: SDL_CreateTextureFromSurface -// See also: SDL_DestroyTexture -// See also: SDL_QueryTexture -// See also: SDL_UpdateTexture +// See also: SDL_QueryTexture() +// See also: SDL_UpdateTexture() +// See also: SDL_DestroyTexture() pub fn create_texture(renderer &Renderer, format Format, access TextureAccess, w int, h int) &Texture { return C.SDL_CreateTexture(renderer, u32(format), int(access), w, h) } @@ -299,161 +206,112 @@ fn C.SDL_CreateTextureFromSurface(renderer &C.SDL_Renderer, surface &C.SDL_Surfa // create_texture_from_surface creates a texture from an existing surface. // -// The surface is not modified or freed by this function. -// -// The SDL_TextureAccess hint for the created texture is -// `SDL_TEXTUREACCESS_STATIC`. -// -// The pixel format of the created texture may be different from the pixel -// format of the surface. Use SDL_QueryTexture() to query the pixel format of -// the texture. +// `renderer` The renderer. +// `surface` The surface containing pixel data used to fill the texture. // -// `renderer` the rendering context -// `surface` the SDL_Surface structure containing pixel data used to fill -// the texture -// returns the created texture or NULL on failure; call SDL_GetError() for -// more information. +// returns The created texture is returned, or NULL on error. // -// NOTE This function is available since SDL 2.0.0. +// NOTE The surface is not modified or freed by this function. // -// See also: SDL_CreateTexture -// See also: SDL_DestroyTexture -// See also: SDL_QueryTexture +// See also: SDL_QueryTexture() +// See also: SDL_DestroyTexture() pub fn create_texture_from_surface(renderer &Renderer, surface &Surface) &Texture { return C.SDL_CreateTextureFromSurface(renderer, surface) } fn C.SDL_QueryTexture(texture &C.SDL_Texture, format &u32, access &int, w &int, h &int) int -// query_texture querys the attributes of a texture. -// -// `texture` the texture to query -// `format` a pointer filled in with the raw format of the texture; the -// actual format may differ, but pixel transfers will use this -// format (one of the SDL_PixelFormatEnum values). This argument -// can be NULL if you don't need this information. -// `access` a pointer filled in with the actual access to the texture -// (one of the SDL_TextureAccess values). This argument can be -// NULL if you don't need this information. -// `w` a pointer filled in with the width of the texture in pixels. This -// argument can be NULL if you don't need this information. -// `h` a pointer filled in with the height of the texture in pixels. This -// argument can be NULL if you don't need this information. -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_CreateTexture +// query_texture queries the attributes of a texture +// +// `texture` A texture to be queried. +// `format` A pointer filled in with the raw format of the texture. The +// actual format may differ, but pixel transfers will use this +// format. +// `access` A pointer filled in with the actual access to the texture. +// `w` A pointer filled in with the width of the texture in pixels. +// `h` A pointer filled in with the height of the texture in pixels. +// +// returns 0 on success, or -1 if the texture is not valid. pub fn query_texture(texture &Texture, format &u32, access &int, w &int, h &int) int { return C.SDL_QueryTexture(texture, format, access, w, h) } fn C.SDL_SetTextureColorMod(texture &C.SDL_Texture, r u8, g u8, b u8) int -// set_texture_color_mod sets an additional color value multiplied into render copy operations. -// -// When this texture is rendered, during the copy operation each source color -// channel is modulated by the appropriate color value according to the -// following formula: -// -// `srcC = srcC * (color / 255)` +// set_texture_color_mod sets an additional color value used in render copy operations. // -// Color modulation is not always supported by the renderer; it will return -1 -// if color modulation is not supported. -// -// `texture` the texture to update -// `r` the red color value multiplied into copy operations -// `g` the green color value multiplied into copy operations -// `b` the blue color value multiplied into copy operations -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. +// `texture` The texture to update. +// `r` The red color value multiplied into copy operations. +// `g` The green color value multiplied into copy operations. +// `b` The blue color value multiplied into copy operations. // -// NOTE This function is available since SDL 2.0.0. +// returns 0 on success, or -1 if the texture is not valid or color modulation +// is not supported. // -// See also: SDL_GetTextureColorMod -// See also: SDL_SetTextureAlphaMod +// See also: SDL_GetTextureColorMod() pub fn set_texture_color_mod(texture &Texture, r u8, g u8, b u8) int { return C.SDL_SetTextureColorMod(texture, r, g, b) } fn C.SDL_GetTextureColorMod(texture &C.SDL_Texture, r &u8, g &u8, b &u8) int -// get_texture_color_mod gets the additional color value multiplied into render copy operations. +// get_texture_color_mod gets the additional color value used in render copy operations. // -// `texture` the texture to query -// `r` a pointer filled in with the current red color value -// `g` a pointer filled in with the current green color value -// `b` a pointer filled in with the current blue color value -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. +// `texture` The texture to query. +// `r` A pointer filled in with the current red color value. +// `g` A pointer filled in with the current green color value. +// `b` A pointer filled in with the current blue color value. // -// NOTE This function is available since SDL 2.0.0. +// returns 0 on success, or -1 if the texture is not valid. // -// See also: SDL_GetTextureAlphaMod -// See also: SDL_SetTextureColorMod +// See also: SDL_SetTextureColorMod() pub fn get_texture_color_mod(texture &Texture, r &u8, g &u8, b &u8) int { return C.SDL_GetTextureColorMod(texture, r, g, b) } fn C.SDL_SetTextureAlphaMod(texture &C.SDL_Texture, alpha u8) int -// set_texture_alpha_mod sets an additional alpha value multiplied into render copy operations. -// -// When this texture is rendered, during the copy operation the source alpha -// value is modulated by this alpha value according to the following formula: -// -// `srcA = srcA * (alpha / 255)` -// -// Alpha modulation is not always supported by the renderer; it will return -1 -// if alpha modulation is not supported. +// set_texture_alpha_mod sets an additional alpha value used in render copy operations. // -// `texture` the texture to update -// `alpha` the source alpha value multiplied into copy operations -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. +// `texture` The texture to update. +// `alpha` The alpha value multiplied into copy operations. // -// NOTE This function is available since SDL 2.0.0. +// returns 0 on success, or -1 if the texture is not valid or alpha modulation +// is not supported. // -// See also: SDL_GetTextureAlphaMod -// See also: SDL_SetTextureColorMod +// See also: SDL_GetTextureAlphaMod() pub fn set_texture_alpha_mod(texture &Texture, alpha u8) int { return C.SDL_SetTextureAlphaMod(texture, alpha) } fn C.SDL_GetTextureAlphaMod(texture &C.SDL_Texture, alpha &u8) int -// get_texture_alpha_mod gets the additional alpha value multiplied into render copy operations. +// get_texture_alpha_mod gets the additional alpha value used in render copy operations. // -// `texture` the texture to query -// `alpha` a pointer filled in with the current alpha value -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. +// `texture` The texture to query. +// `alpha` A pointer filled in with the current alpha value. // -// NOTE This function is available since SDL 2.0.0. +// returns 0 on success, or -1 if the texture is not valid. // -// See also: SDL_GetTextureColorMod -// See also: SDL_SetTextureAlphaMod +// See also: SDL_SetTextureAlphaMod() pub fn get_texture_alpha_mod(texture &Texture, alpha &u8) int { return C.SDL_GetTextureAlphaMod(texture, alpha) } fn C.SDL_SetTextureBlendMode(texture &C.SDL_Texture, blend_mode C.SDL_BlendMode) int -// set_texture_blend_mode sets the blend mode for a texture, used by SDL_RenderCopy(). +// set_texture_blend_mode sets the blend mode used for texture copy operations. // -// If the blend mode is not supported, the closest supported mode is chosen -// and this function returns -1. +// `texture` The texture to update. +// `blendMode` ::SDL_BlendMode to use for texture blending. // -// `texture` the texture to update -// `blendMode` the SDL_BlendMode to use for texture blending -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. +// returns 0 on success, or -1 if the texture is not valid or the blend mode is +// not supported. // -// NOTE This function is available since SDL 2.0.0. +// NOTE If the blend mode is not supported, the closest supported mode is +// chosen. // -// See also: SDL_GetTextureBlendMode -// See also: SDL_RenderCopy +// See also: SDL_GetTextureBlendMode() pub fn set_texture_blend_mode(texture &Texture, blend_mode BlendMode) int { return C.SDL_SetTextureBlendMode(texture, C.SDL_BlendMode(blend_mode)) } @@ -462,268 +320,95 @@ fn C.SDL_GetTextureBlendMode(texture &C.SDL_Texture, blend_mode &C.SDL_BlendMode // get_texture_blend_mode gets the blend mode used for texture copy operations. // -// `texture` the texture to query -// `blendMode` a pointer filled in with the current SDL_BlendMode -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. +// `texture` The texture to query. +// `blendMode` A pointer filled in with the current blend mode. // -// NOTE This function is available since SDL 2.0.0. +// returns 0 on success, or -1 if the texture is not valid. // -// See also: SDL_SetTextureBlendMode +// See also: SDL_SetTextureBlendMode() pub fn get_texture_blend_mode(texture &Texture, blend_mode &BlendMode) int { return C.SDL_GetTextureBlendMode(texture, unsafe { &C.SDL_BlendMode(blend_mode) }) } -fn C.SDL_SetTextureScaleMode(texture &C.SDL_Texture, scale_mode C.SDL_ScaleMode) int - -// set_texture_scale_mode sets the scale mode used for texture scale operations. -// -// If the scale mode is not supported, the closest supported mode is chosen. -// -// `texture` The texture to update. -// `scaleMode` the SDL_ScaleMode to use for texture scaling. -// returns 0 on success, or -1 if the texture is not valid. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetTextureScaleMode -pub fn set_texture_scale_mode(texture &Texture, scale_mode ScaleMode) int { - return C.SDL_SetTextureScaleMode(texture, C.SDL_ScaleMode(int(scale_mode))) -} - -fn C.SDL_GetTextureScaleMode(texture &C.SDL_Texture, scale_mode &C.SDL_ScaleMode) int - -// get_texture_scale_mode gets the scale mode used for texture scale operations. -// -// `texture` the texture to query. -// `scaleMode` a pointer filled in with the current scale mode. -// returns 0 on success, or -1 if the texture is not valid. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_SetTextureScaleMode -pub fn get_texture_scale_mode(texture &Texture, scale_mode &ScaleMode) int { - return unsafe { C.SDL_GetTextureScaleMode(texture, &C.SDL_ScaleMode(scale_mode)) } -} - -fn C.SDL_SetTextureUserData(texture &C.SDL_Texture, userdata voidptr) int - -// set_texture_user_data associates a user-specified pointer with a texture. -// -// `texture` the texture to update. -// `userdata` the pointer to associate with the texture. -// returns 0 on success, or -1 if the texture is not valid. -// -// NOTE This function is available since SDL 2.0.18. -// -// See also: SDL_GetTextureUserData -pub fn set_texture_user_data(texture &Texture, userdata voidptr) int { - return C.SDL_SetTextureUserData(texture, userdata) -} - -fn C.SDL_GetTextureUserData(texture &Texture) voidptr - -// get_texture_user_data gets the user-specified pointer associated with a texture -// -// `texture` the texture to query. -// returns the pointer associated with the texture, or NULL if the texture is -// not valid. -// -// NOTE This function is available since SDL 2.0.18. -// -// See also: SDL_SetTextureUserData -pub fn get_texture_user_data(texture &C.SDL_Texture) voidptr { - return C.SDL_GetTextureUserData(texture) -} - fn C.SDL_UpdateTexture(texture &C.SDL_Texture, const_rect &C.SDL_Rect, const_pixels voidptr, pitch int) int // update_texture updates the given texture rectangle with new pixel data. // -// The pixel data must be in the pixel format of the texture. Use -// SDL_QueryTexture() to query the pixel format of the texture. -// -// This is a fairly slow function, intended for use with static textures that -// do not change often. -// -// If the texture is intended to be updated often, it is preferred to create -// the texture as streaming and use the locking functions referenced below. -// While this function will work with streaming textures, for optimization -// reasons you may not get the pixels back if you lock the texture afterward. +// `texture` The texture to update +// `rect` A pointer to the rectangle of pixels to update, or NULL to +// update the entire texture. +// `pixels` The raw pixel data in the format of the texture. +// `pitch` The number of bytes in a row of pixel data, including padding between lines. // -// `texture` the texture to update -// `rect` an SDL_Rect structure representing the area to update, or NULL -// to update the entire texture -// `pixels` the raw pixel data in the format of the texture -// `pitch` the number of bytes in a row of pixel data, including padding -// between lines -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. +// The pixel data must be in the format of the texture. The pixel format can be +// queried with SDL_QueryTexture. // -// NOTE This function is available since SDL 2.0.0. +// returns 0 on success, or -1 if the texture is not valid. // -// See also: SDL_CreateTexture -// See also: SDL_LockTexture -// See also: SDL_UnlockTexture +// NOTE This is a fairly slow function. pub fn update_texture(texture &Texture, const_rect &Rect, const_pixels voidptr, pitch int) int { return C.SDL_UpdateTexture(texture, const_rect, const_pixels, pitch) } fn C.SDL_UpdateYUVTexture(texture &C.SDL_Texture, const_rect &C.SDL_Rect, const_yplane &u8, ypitch int, const_uplane &u8, upitch int, const_vplane &u8, vpitch int) int -// update_yuv_texture updates a rectangle within a planar YV12 or IYUV texture with new pixel -// data. -// -// You can use SDL_UpdateTexture() as long as your pixel data is a contiguous -// block of Y and U/V planes in the proper order, but this function is -// available if your pixel data is not contiguous. -// -// `texture` the texture to update -// `rect` a pointer to the rectangle of pixels to update, or NULL to -// update the entire texture -// `Yplane` the raw pixel data for the Y plane -// `Ypitch` the number of bytes between rows of pixel data for the Y -// plane -// `Uplane` the raw pixel data for the U plane -// `Upitch` the number of bytes between rows of pixel data for the U -// plane -// `Vplane` the raw pixel data for the V plane -// `Vpitch` the number of bytes between rows of pixel data for the V -// plane -// returns 0 on success or -1 if the texture is not valid; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.1. -// -// See also: SDL_UpdateTexture -pub fn update_yuv_texture(texture &Texture, const_rect &Rect, const_yplane &u8, ypitch int, const_uplane &u8, upitch int, const_vplane &u8, vpitch int) int { - return C.SDL_UpdateYUVTexture(texture, const_rect, const_yplane, ypitch, const_uplane, - upitch, const_vplane, vpitch) -} - -fn C.SDL_UpdateNVTexture(texture &C.SDL_Texture, const_rect &C.SDL_Rect, const_yplane &u8, ypitch int, const_u_vplane &u8, u_vpitch int) int - -// update_nv_texture updates a rectangle within a planar NV12 or NV21 texture with new pixels. +// update_yuv_texture updates a rectangle within a planar YV12 or IYUV texture with new pixel data. // -// You can use SDL_UpdateTexture() as long as your pixel data is a contiguous -// block of NV12/21 planes in the proper order, but this function is available -// if your pixel data is not contiguous. +// `texture` The texture to update +// `rect` A pointer to the rectangle of pixels to update, or NULL to +// update the entire texture. +// `Yplane` The raw pixel data for the Y plane. +// `Ypitch` The number of bytes between rows of pixel data for the Y plane. +// `Uplane` The raw pixel data for the U plane. +// `Upitch` The number of bytes between rows of pixel data for the U plane. +// `Vplane` The raw pixel data for the V plane. +// `Vpitch` The number of bytes between rows of pixel data for the V plane. // -// `texture` the texture to update -// `rect` a pointer to the rectangle of pixels to update, or NULL to -// update the entire texture. -// `Yplane` the raw pixel data for the Y plane. -// `Ypitch` the number of bytes between rows of pixel data for the Y -// plane. -// `UVplane` the raw pixel data for the UV plane. -// `UVpitch` the number of bytes between rows of pixel data for the UV -// plane. // returns 0 on success, or -1 if the texture is not valid. // -// NOTE This function is available since SDL 2.0.16. -pub fn update_nv_texture(texture &C.SDL_Texture, const_rect &Rect, const_yplane &u8, ypitch int, const_u_vplane &u8, u_vpitch int) int { - return C.SDL_UpdateNVTexture(texture, const_rect, const_yplane, ypitch, const_u_vplane, - u_vpitch) +// NOTE You can use SDL_UpdateTexture() as long as your pixel data is +// a contiguous block of Y and U/V planes in the proper order, but +// this function is available if your pixel data is not contiguous. +pub fn update_yuv_texture(texture &Texture, const_rect &Rect, const_yplane &u8, ypitch int, const_uplane &u8, upitch int, const_vplane &u8, vpitch int) int { + return C.SDL_UpdateYUVTexture(texture, const_rect, const_yplane, ypitch, const_uplane, + upitch, const_vplane, vpitch) } fn C.SDL_LockTexture(texture &C.SDL_Texture, const_rect &C.SDL_Rect, pixels voidptr, pitch &int) int -// lock_texture locks a portion of the texture for **write-only** pixel access. -// -// As an optimization, the pixels made available for editing don't necessarily -// contain the old texture data. This is a write-only operation, and if you -// need to keep a copy of the texture data you should do that at the -// application level. -// -// You must use SDL_UnlockTexture() to unlock the pixels and apply any -// changes. +// lock_texture locks a portion of the texture for write-only pixel access. // -// `texture` the texture to lock for access, which was created with -// `SDL_TEXTUREACCESS_STREAMING` -// `rect` an SDL_Rect structure representing the area to lock for access; -// NULL to lock the entire texture -// `pixels` this is filled in with a pointer to the locked pixels, -// appropriately offset by the locked area -// `pitch` this is filled in with the pitch of the locked pixels; the -// pitch is the length of one row in bytes -// returns 0 on success or a negative error code if the texture is not valid -// or was not created with `SDL_TEXTUREACCESS_STREAMING`; call -// SDL_GetError() for more information. +// `texture` The texture to lock for access, which was created with +// ::SDL_TEXTUREACCESS_STREAMING. +// `rect` A pointer to the rectangle to lock for access. If the rect +// is NULL, the entire texture will be locked. +// `pixels` This is filled in with a pointer to the locked pixels, +// appropriately offset by the locked area. +// `pitch` This is filled in with the pitch of the locked pixels. // -// NOTE This function is available since SDL 2.0.0. +// returns 0 on success, or -1 if the texture is not valid or was not created with ::SDL_TEXTUREACCESS_STREAMING. // -// See also: SDL_UnlockTexture +// See also: SDL_UnlockTexture() pub fn lock_texture(texture &Texture, const_rect &Rect, pixels voidptr, pitch &int) int { return C.SDL_LockTexture(texture, const_rect, pixels, pitch) } -fn C.SDL_LockTextureToSurface(texture &C.SDL_Texture, const_rect &C.SDL_Rect, surface &&C.SDL_Surface) int - -// lock_texture_to_surface locks a portion of the texture for **write-only** pixel access, and expose -// it as a SDL surface. -// -// Besides providing an SDL_Surface instead of raw pixel data, this function -// operates like SDL_LockTexture. -// -// As an optimization, the pixels made available for editing don't necessarily -// contain the old texture data. This is a write-only operation, and if you -// need to keep a copy of the texture data you should do that at the -// application level. -// -// You must use SDL_UnlockTexture() to unlock the pixels and apply any -// changes. -// -// The returned surface is freed internally after calling SDL_UnlockTexture() -// or SDL_DestroyTexture(). The caller should not free it. -// -// `texture` the texture to lock for access, which was created with -// `SDL_TEXTUREACCESS_STREAMING` -// `rect` a pointer to the rectangle to lock for access. If the rect is -// NULL, the entire texture will be locked -// `surface` this is filled in with an SDL surface representing the -// locked area -// returns 0 on success, or -1 if the texture is not valid or was not created -// with `SDL_TEXTUREACCESS_STREAMING` -// -// NOTE This function is available since SDL 2.0.12. -// -// See also: SDL_LockTexture -// See also: SDL_UnlockTexture -pub fn lock_texture_to_surface(texture &Texture, const_rect &Rect, surface &&Surface) int { - return C.SDL_LockTextureToSurface(texture, const_rect, surface) -} - fn C.SDL_UnlockTexture(texture &C.SDL_Texture) // unlock_texture unlocks a texture, uploading the changes to video memory, if needed. // -// **WARNING**: Please note that SDL_LockTexture() is intended to be -// write-only; it will not guarantee the previous contents of the texture will -// be provided. You must fully initialize any area of a texture that you lock -// before unlocking it, as the pixels might otherwise be uninitialized memory. -// -// Which is to say: locking and immediately unlocking a texture can result in -// corrupted textures, depending on the renderer in use. -// -// `texture` a texture locked by SDL_LockTexture() -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_LockTexture +// See also: SDL_LockTexture() pub fn unlock_texture(texture &Texture) { C.SDL_UnlockTexture(texture) } fn C.SDL_RenderTargetSupported(renderer &C.SDL_Renderer) bool -// render_target_supported determines whether a renderer supports the use of render targets. -// -// `renderer` the renderer that will be checked -// returns SDL_TRUE if supported or SDL_FALSE if not. +// render_target_supported determines whether a window supports the use of render targets // -// NOTE This function is available since SDL 2.0.0. +// `renderer` The renderer that will be checked // -// See also: SDL_SetRenderTarget +// returns SDL_TRUE if supported, SDL_FALSE if not. pub fn render_target_supported(renderer &Renderer) bool { return C.SDL_RenderTargetSupported(renderer) } @@ -732,129 +417,90 @@ fn C.SDL_SetRenderTarget(renderer &C.SDL_Renderer, texture &C.SDL_Texture) int // set_render_target sets a texture as the current rendering target. // -// Before using this function, you should check the -// `SDL_RENDERER_TARGETTEXTURE` bit in the flags of SDL_RendererInfo to see if -// render targets are supported. -// -// The default render target is the window for which the renderer was created. -// To stop rendering to a texture and render to the window again, call this -// function with a NULL `texture`. -// -// `renderer` the rendering context -// `texture` the targeted texture, which must be created with the -// `SDL_TEXTUREACCESS_TARGET` flag, or NULL to render to the -// window instead of a texture. -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. +// `renderer` The renderer. +// `texture` The targeted texture, which must be created with the SDL_TEXTUREACCESS_TARGET flag, or NULL for the default render target // -// NOTE This function is available since SDL 2.0.0. +// returns 0 on success, or -1 on error // -// See also: SDL_GetRenderTarget +// See also: SDL_GetRenderTarget() pub fn set_render_target(renderer &Renderer, texture &Texture) int { return C.SDL_SetRenderTarget(renderer, texture) } fn C.SDL_GetRenderTarget(renderer &C.SDL_Renderer) &C.SDL_Texture -// get_render_target gets the current render target. -// -// The default render target is the window for which the renderer was created, -// and is reported a NULL here. -// -// `renderer` the rendering context -// returns the current render target or NULL for the default render target. +// get_render_target gets the current render target or NULL for the default render target. // -// NOTE This function is available since SDL 2.0.0. +// returns The current render target // -// See also: SDL_SetRenderTarget +// See also: SDL_SetRenderTarget() pub fn get_render_target(renderer &Renderer) &Texture { return C.SDL_GetRenderTarget(renderer) } fn C.SDL_RenderSetLogicalSize(renderer &C.SDL_Renderer, w int, h int) int -// render_set_logical_size sets a device independent resolution for rendering. +// render_set_logical_size sets device independent resolution for rendering // -// This function uses the viewport and scaling functionality to allow a fixed -// logical resolution for rendering, regardless of the actual output -// resolution. If the actual output resolution doesn't have the same aspect -// ratio the output rendering will be centered within the output display. +// `renderer` The renderer for which resolution should be set. +// `w` The width of the logical resolution +// `h` The height of the logical resolution // -// If the output display is a window, mouse and touch events in the window -// will be filtered and scaled so they seem to arrive within the logical -// resolution. The SDL_HINT_MOUSE_RELATIVE_SCALING hint controls whether -// relative motion events are also scaled. +// This function uses the viewport and scaling functionality to allow a fixed logical +// resolution for rendering, regardless of the actual output resolution. If the actual +// output resolution doesn't have the same aspect ratio the output rendering will be +// centered within the output display. // -// If this function results in scaling or subpixel drawing by the rendering -// backend, it will be handled using the appropriate quality hints. +// If the output display is a window, mouse events in the window will be filtered +// and scaled so they seem to arrive within the logical resolution. // -// `renderer` the renderer for which resolution should be set -// `w` the width of the logical resolution -// `h` the height of the logical resolution -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. +// NOTE If this function results in scaling or subpixel drawing by the +// rendering backend, it will be handled using the appropriate +// quality hints. // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_RenderGetLogicalSize +// See also: SDL_RenderGetLogicalSize() +// See also: SDL_RenderSetScale() +// See also: SDL_RenderSetViewport() pub fn render_set_logical_size(renderer &Renderer, w int, h int) int { return C.SDL_RenderSetLogicalSize(renderer, w, h) } fn C.SDL_RenderGetLogicalSize(renderer &C.SDL_Renderer, w &int, h &int) -// render_get_logical_size gets device independent resolution for rendering. -// -// When using the main rendering target (eg no target texture is set): this -// may return 0 for `w` and `h` if the SDL_Renderer has never had its logical -// size set by SDL_RenderSetLogicalSize(). Otherwise it returns the logical -// width and height. +// render_get_logical_size gets device independent resolution for rendering // -// When using a target texture: Never return 0 for `w` and `h` at first. Then -// it returns the logical width and height that are set.// -// `renderer` a rendering context -// `w` an int to be filled with the width -// `h` an int to be filled with the height +// `renderer` The renderer from which resolution should be queried. +// `w` A pointer filled with the width of the logical resolution +// `h` A pointer filled with the height of the logical resolution // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_RenderSetLogicalSize +// See also: SDL_RenderSetLogicalSize() pub fn render_get_logical_size(renderer &Renderer, w &int, h &int) { C.SDL_RenderGetLogicalSize(renderer, w, h) } fn C.SDL_RenderSetIntegerScale(renderer &C.SDL_Renderer, enable bool) int -// render_set_integer_scale sets whether to force integer scales for resolution-independent rendering. -// -// This function restricts the logical viewport to integer values - that is, -// when a resolution is between two multiples of a logical size, the viewport -// size is rounded down to the lower multiple. +// render_set_integer_scale sets whether to force integer scales for resolution-independent rendering // -// `renderer` the renderer for which integer scaling should be set -// `enable` enable or disable the integer scaling for rendering -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. +// `renderer` The renderer for which integer scaling should be set. +// `enable` Enable or disable integer scaling // -// NOTE This function is available since SDL 2.0.5. +// This function restricts the logical viewport to integer values - that is, when +// a resolution is between two multiples of a logical size, the viewport size is +// rounded down to the lower multiple. // -// See also: SDL_RenderGetIntegerScale -// See also: SDL_RenderSetLogicalSize +// See also: SDL_RenderSetLogicalSize() pub fn render_set_integer_scale(renderer &Renderer, enable bool) int { return C.SDL_RenderSetIntegerScale(renderer, enable) } fn C.SDL_RenderGetIntegerScale(renderer &C.SDL_Renderer) bool -// render_get_integer_scale gets whether integer scales are forced for resolution-independent rendering. -// -// `renderer` the renderer from which integer scaling should be queried -// returns SDL_TRUE if integer scales are forced or SDL_FALSE if not and on -// failure; call SDL_GetError() for more information. +// render_get_integer_scale gets whether integer scales are forced for resolution-independent rendering // -// NOTE This function is available since SDL 2.0.5. +// `renderer` The renderer from which integer scaling should be queried. // -// See also: SDL_RenderSetIntegerScale +// See also: SDL_RenderSetIntegerScale() pub fn render_get_integer_scale(renderer &Renderer) bool { return C.SDL_RenderGetIntegerScale(renderer) } @@ -863,18 +509,17 @@ fn C.SDL_RenderSetViewport(renderer &C.SDL_Renderer, const_rect &C.SDL_Rect) int // render_set_viewport sets the drawing area for rendering on the current target. // -// When the window is resized, the viewport is reset to fill the entire new -// window size. +// `renderer` The renderer for which the drawing area should be set. +// `rect` The rectangle representing the drawing area, or NULL to set the viewport to the entire target. // -// `renderer` the rendering context -// `rect` the SDL_Rect structure representing the drawing area, or NULL -// to set the viewport to the entire target -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. +// The x,y of the viewport rect represents the origin for rendering. +// +// returns 0 on success, or -1 on error // -// NOTE This function is available since SDL 2.0.0. +// NOTE If the window associated with the renderer is resized, the viewport is automatically reset. // -// See also: SDL_RenderGetViewport +// See also: SDL_RenderGetViewport() +// See also: SDL_RenderSetLogicalSize() pub fn render_set_viewport(renderer &Renderer, const_rect &Rect) int { return C.SDL_RenderSetViewport(renderer, const_rect) } @@ -883,31 +528,22 @@ fn C.SDL_RenderGetViewport(renderer &C.SDL_Renderer, rect &C.SDL_Rect) // render_get_viewport gets the drawing area for the current target. // -// `renderer` the rendering context -// `rect` an SDL_Rect structure filled in with the current drawing area -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_RenderSetViewport +// See also: SDL_RenderSetViewport() pub fn render_get_viewport(renderer &Renderer, rect &Rect) { C.SDL_RenderGetViewport(renderer, rect) } fn C.SDL_RenderSetClipRect(renderer &C.SDL_Renderer, const_rect &C.SDL_Rect) int -// render_set_clip_rect sets the clip rectangle for rendering on the specified target. +// render_set_clip_rect sets the clip rectangle for the current target. // -// `renderer` the rendering context for which clip rectangle should be -// set -// `rect` an SDL_Rect structure representing the clip area, relative to -// the viewport, or NULL to disable clipping -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. +// `renderer` The renderer for which clip rectangle should be set. +// `rect` A pointer to the rectangle to set as the clip rectangle, or +// NULL to disable clipping. // -// NOTE This function is available since SDL 2.0.0. +// returns 0 on success, or -1 on error // -// See also: SDL_RenderGetClipRect -// See also: SDL_RenderIsClipEnabled +// See also: SDL_RenderGetClipRect() pub fn render_set_clip_rect(renderer &Renderer, const_rect &Rect) int { return C.SDL_RenderSetClipRect(renderer, const_rect) } @@ -916,15 +552,11 @@ fn C.SDL_RenderGetClipRect(renderer &Renderer, rect &C.SDL_Rect) // render_get_clip_rect gets the clip rectangle for the current target. // -// `renderer` the rendering context from which clip rectangle should be -// queried -// `rect` an SDL_Rect structure filled in with the current clipping area -// or an empty rectangle if clipping is disabled -// -// NOTE This function is available since SDL 2.0.0. +// `renderer` The renderer from which clip rectangle should be queried. +// `rect` A pointer filled in with the current clip rectangle, or +// an empty rectangle if clipping is disabled. // -// See also: SDL_RenderIsClipEnabled -// See also: SDL_RenderSetClipRect +// See also: SDL_RenderSetClipRect() pub fn render_get_clip_rect(renderer &Renderer, rect &Rect) { C.SDL_RenderGetClipRect(renderer, rect) } @@ -933,14 +565,9 @@ fn C.SDL_RenderIsClipEnabled(renderer &C.SDL_Renderer) bool // render_is_clip_enabled gets whether clipping is enabled on the given renderer. // -// `renderer` the renderer from which clip state should be queried -// returns SDL_TRUE if clipping is enabled or SDL_FALSE if not; call -// SDL_GetError() for more information. +// `renderer` The renderer from which clip state should be queried. // -// NOTE This function is available since SDL 2.0.4. -// -// See also: SDL_RenderGetClipRect -// See also: SDL_RenderSetClipRect +// See also: SDL_RenderGetClipRect() pub fn render_is_clip_enabled(renderer &Renderer) bool { return C.SDL_RenderIsClipEnabled(renderer) } @@ -949,24 +576,20 @@ fn C.SDL_RenderSetScale(renderer &C.SDL_Renderer, scale_x f32, scale_y f32) int // render_set_scale sets the drawing scale for rendering on the current target. // -// The drawing coordinates are scaled by the x/y scaling factors before they -// are used by the renderer. This allows resolution independent drawing with a -// single coordinate system. -// -// If this results in scaling or subpixel drawing by the rendering backend, it -// will be handled using the appropriate quality hints. For best results use -// integer scaling factors. +// `renderer` The renderer for which the drawing scale should be set. +// `scaleX` The horizontal scaling factor +// `scaleY` The vertical scaling factor // -// `renderer` a rendering context -// `scaleX` the horizontal scaling factor -// `scaleY` the vertical scaling factor -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. +// The drawing coordinates are scaled by the x/y scaling factors +// before they are used by the renderer. This allows resolution +// independent drawing with a single coordinate system. // -// NOTE This function is available since SDL 2.0.0. +// NOTE If this results in scaling or subpixel drawing by the +// rendering backend, it will be handled using the appropriate +// quality hints. For best results use integer scaling factors. // -// See also: SDL_RenderGetScale -// See also: SDL_RenderSetLogicalSize +// See also: SDL_RenderGetScale() +// See also: SDL_RenderSetLogicalSize() pub fn render_set_scale(renderer &Renderer, scale_x f32, scale_y f32) int { return C.SDL_RenderSetScale(renderer, scale_x, scale_y) } @@ -975,96 +598,27 @@ fn C.SDL_RenderGetScale(renderer &C.SDL_Renderer, scale_x &f32, scale_y &f32) // render_get_scale gets the drawing scale for the current target. // -// `renderer` the renderer from which drawing scale should be queried -// `scaleX` a pointer filled in with the horizontal scaling factor -// `scaleY` a pointer filled in with the vertical scaling factor -// -// NOTE This function is available since SDL 2.0.0. +// `renderer` The renderer from which drawing scale should be queried. +// `scaleX` A pointer filled in with the horizontal scaling factor +// `scaleY` A pointer filled in with the vertical scaling factor // -// See also: SDL_RenderSetScale +// See also: SDL_RenderSetScale() pub fn render_get_scale(renderer &Renderer, scale_x &f32, scale_y &f32) { C.SDL_RenderGetScale(renderer, scale_x, scale_y) } -fn C.SDL_RenderWindowToLogical(renderer &C.SDL_Renderer, window_x int, window_y int, logical_x &f32, logical_y &f32) - -// render_window_to_logical gets logical coordinates of point in renderer when given real coordinates of -// point in window. -// -// Logical coordinates will differ from real coordinates when render is scaled -// and logical renderer size set -// -// `renderer` the renderer from which the logical coordinates should be -// calculated -// `windowX` the real X coordinate in the window -// `windowY` the real Y coordinate in the window -// `logicalX` the pointer filled with the logical x coordinate -// `logicalY` the pointer filled with the logical y coordinate -// -// NOTE This function is available since SDL 2.0.18. -// -// See also: SDL_RenderGetScale -// See also: SDL_RenderSetScale -// See also: SDL_RenderGetLogicalSize -// See also: SDL_RenderSetLogicalSize -pub fn render_window_to_logical(renderer &Renderer, window_x int, window_y int, logical_x &f32, logical_y &f32) { - C.SDL_RenderWindowToLogical(renderer, window_x, window_y, logical_x, logical_y) -} - -fn C.SDL_RenderLogicalToWindow(renderer &C.SDL_Renderer, logical_x f32, logical_y f32, window_x &int, window_y &int) - -// render_logical_to_window gets real coordinates of point in window when given logical coordinates of -// point in renderer. -// -// Logical coordinates will differ from real coordinates when render is scaled -// and logical renderer size set -// -// `renderer` the renderer from which the window coordinates should be -// calculated -// `logicalX` the logical x coordinate -// `logicalY` the logical y coordinate -// `windowX` the pointer filled with the real X coordinate in the window -// `windowY` the pointer filled with the real Y coordinate in the window -// -// NOTE This function is available since SDL 2.0.18. -// -// See also: SDL_RenderGetScale -// See also: SDL_RenderSetScale -// See also: SDL_RenderGetLogicalSize -// See also: SDL_RenderSetLogicalSize -pub fn render_logical_to_window(renderer &Renderer, logical_x f32, logical_y f32, window_x &int, window_y &int) { - C.SDL_RenderLogicalToWindow(renderer, logical_x, logical_y, window_x, window_y) -} - fn C.SDL_SetRenderDrawColor(renderer &C.SDL_Renderer, r u8, g u8, b u8, a u8) int // set_render_draw_color sets the color used for drawing operations (Rect, Line and Clear). // -// Set the color for drawing or filling rectangles, lines, and points, and for -// SDL_RenderClear(). -// -// `renderer` the rendering context -// `r` the red value used to draw on the rendering target -// `g` the green value used to draw on the rendering target -// `b` the blue value used to draw on the rendering target -// `a` the alpha value used to draw on the rendering target; usually -// `SDL_ALPHA_OPAQUE` (255). Use SDL_SetRenderDrawBlendMode to -// specify how the alpha channel is used -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetRenderDrawColor -// See also: SDL_RenderClear -// See also: SDL_RenderDrawLine -// See also: SDL_RenderDrawLines -// See also: SDL_RenderDrawPoint -// See also: SDL_RenderDrawPoints -// See also: SDL_RenderDrawRect -// See also: SDL_RenderDrawRects -// See also: SDL_RenderFillRect -// See also: SDL_RenderFillRects +// `renderer` The renderer for which drawing color should be set. +// `r` The red value used to draw on the rendering target. +// `g` The green value used to draw on the rendering target. +// `b` The blue value used to draw on the rendering target. +// `a` The alpha value used to draw on the rendering target, usually +// ::SDL_ALPHA_OPAQUE (255). +// +// returns 0 on success, or -1 on error pub fn set_render_draw_color(renderer &Renderer, r u8, g u8, b u8, a u8) int { return C.SDL_SetRenderDrawColor(renderer, r, g, b, a) } @@ -1073,21 +627,14 @@ fn C.SDL_GetRenderDrawColor(renderer &C.SDL_Renderer, r &u8, g &u8, b &u8, a &u8 // get_render_draw_color gets the color used for drawing operations (Rect, Line and Clear). // -// `renderer` the rendering context -// `r` a pointer filled in with the red value used to draw on the -// rendering target -// `g` a pointer filled in with the green value used to draw on the -// rendering target -// `b` a pointer filled in with the blue value used to draw on the -// rendering target -// `a` a pointer filled in with the alpha value used to draw on the -// rendering target; usually `SDL_ALPHA_OPAQUE` (255) -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_SetRenderDrawColor +// `renderer` The renderer from which drawing color should be queried. +// `r` A pointer to the red value used to draw on the rendering target. +// `g` A pointer to the green value used to draw on the rendering target. +// `b` A pointer to the blue value used to draw on the rendering target. +// `a` A pointer to the alpha value used to draw on the rendering target, +// usually ::SDL_ALPHA_OPAQUE (255). +// +// returns 0 on success, or -1 on error pub fn get_render_draw_color(renderer &Renderer, r &u8, g &u8, b &u8, a &u8) int { return C.SDL_GetRenderDrawColor(renderer, r, g, b, a) } @@ -1096,24 +643,15 @@ fn C.SDL_SetRenderDrawBlendMode(renderer &C.SDL_Renderer, blend_mode C.SDL_Blend // set_render_draw_blend_mode sets the blend mode used for drawing operations (Fill and Line). // -// If the blend mode is not supported, the closest supported mode is chosen. +// `renderer` The renderer for which blend mode should be set. +// `blendMode` ::SDL_BlendMode to use for blending. // -// `renderer` the rendering context -// `blendMode` the SDL_BlendMode to use for blending -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. +// returns 0 on success, or -1 on error // -// NOTE This function is available since SDL 2.0.0. +// NOTE If the blend mode is not supported, the closest supported mode is +// chosen. // -// See also: SDL_GetRenderDrawBlendMode -// See also: SDL_RenderDrawLine -// See also: SDL_RenderDrawLines -// See also: SDL_RenderDrawPoint -// See also: SDL_RenderDrawPoints -// See also: SDL_RenderDrawRect -// See also: SDL_RenderDrawRects -// See also: SDL_RenderFillRect -// See also: SDL_RenderFillRects +// See also: SDL_GetRenderDrawBlendMode() pub fn set_render_draw_blend_mode(renderer &Renderer, blend_mode BlendMode) int { return C.SDL_SetRenderDrawBlendMode(renderer, C.SDL_BlendMode(blend_mode)) } @@ -1122,32 +660,24 @@ fn C.SDL_GetRenderDrawBlendMode(renderer &C.SDL_Renderer, blend_mode &C.SDL_Blen // get_render_draw_blend_mode gets the blend mode used for drawing operations. // -// `renderer` the rendering context -// `blendMode` a pointer filled in with the current SDL_BlendMode -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. +// `renderer` The renderer from which blend mode should be queried. +// `blendMode` A pointer filled in with the current blend mode. // -// NOTE This function is available since SDL 2.0.0. +// returns 0 on success, or -1 on error // -// See also: SDL_SetRenderDrawBlendMode +// See also: SDL_SetRenderDrawBlendMode() pub fn get_render_draw_blend_mode(renderer &Renderer, blend_mode &BlendMode) int { return C.SDL_GetRenderDrawBlendMode(renderer, unsafe { &C.SDL_BlendMode(blend_mode) }) } fn C.SDL_RenderClear(renderer &C.SDL_Renderer) int -// render_clear clears the current rendering target with the drawing color. +// render_clear clears the current rendering target with the drawing color // // This function clears the entire rendering target, ignoring the viewport and // the clip rectangle. // -// `renderer` the rendering context -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_SetRenderDrawColor +// returns 0 on success, or -1 on error pub fn render_clear(renderer &Renderer) int { return C.SDL_RenderClear(renderer) } @@ -1156,27 +686,11 @@ fn C.SDL_RenderDrawPoint(renderer &C.SDL_Renderer, x int, y int) int // render_draw_point draws a point on the current rendering target. // -// SDL_RenderDrawPoint() draws a single point. If you want to draw multiple, -// use SDL_RenderDrawPoints() instead. -// -// `renderer` the rendering context -// `x` the x coordinate of the point -// `y` the y coordinate of the point -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_RenderDrawLine -// See also: SDL_RenderDrawLines -// See also: SDL_RenderDrawPoints -// See also: SDL_RenderDrawRect -// See also: SDL_RenderDrawRects -// See also: SDL_RenderFillRect -// See also: SDL_RenderFillRects -// See also: SDL_RenderPresent -// See also: SDL_SetRenderDrawBlendMode -// See also: SDL_SetRenderDrawColor +// `renderer` The renderer which should draw a point. +// `x` The x coordinate of the point. +// `y` The y coordinate of the point. +// +// returns 0 on success, or -1 on error pub fn render_draw_point(renderer &Renderer, x int, y int) int { return C.SDL_RenderDrawPoint(renderer, x, y) } @@ -1185,25 +699,11 @@ fn C.SDL_RenderDrawPoints(renderer &C.SDL_Renderer, const_points &C.SDL_Point, c // render_draw_points draws multiple points on the current rendering target. // -// `renderer` the rendering context -// `points` an array of SDL_Point structures that represent the points to -// draw -// `count` the number of points to draw -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_RenderDrawLine -// See also: SDL_RenderDrawLines -// See also: SDL_RenderDrawPoint -// See also: SDL_RenderDrawRect -// See also: SDL_RenderDrawRects -// See also: SDL_RenderFillRect -// See also: SDL_RenderFillRects -// See also: SDL_RenderPresent -// See also: SDL_SetRenderDrawBlendMode -// See also: SDL_SetRenderDrawColor +// `renderer` The renderer which should draw multiple points. +// `points` The points to draw +// `count` The number of points to draw +// +// returns 0 on success, or -1 on error pub fn render_draw_points(renderer &Renderer, const_points &Point, count int) int { return C.SDL_RenderDrawPoints(renderer, const_points, count) } @@ -1212,29 +712,13 @@ fn C.SDL_RenderDrawLine(renderer &C.SDL_Renderer, x1 int, y1 int, x2 int, y2 int // render_draw_line draws a line on the current rendering target. // -// SDL_RenderDrawLine() draws the line to include both end points. If you want -// to draw multiple, connecting lines use SDL_RenderDrawLines() instead. -// -// `renderer` the rendering context -// `x1` the x coordinate of the start point -// `y1` the y coordinate of the start point -// `x2` the x coordinate of the end point -// `y2` the y coordinate of the end point -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_RenderDrawLines -// See also: SDL_RenderDrawPoint -// See also: SDL_RenderDrawPoints -// See also: SDL_RenderDrawRect -// See also: SDL_RenderDrawRects -// See also: SDL_RenderFillRect -// See also: SDL_RenderFillRects -// See also: SDL_RenderPresent -// See also: SDL_SetRenderDrawBlendMode -// See also: SDL_SetRenderDrawColor +// `renderer` The renderer which should draw a line. +// `x`1 The x coordinate of the start point. +// `y`1 The y coordinate of the start point. +// `x`2 The x coordinate of the end point. +// `y`2 The y coordinate of the end point. +// +// returns 0 on success, or -1 on error pub fn render_draw_line(renderer &Renderer, x1 int, y1 int, x2 int, y2 int) int { return C.SDL_RenderDrawLine(renderer, x1, y1, x2, y2) } @@ -1243,25 +727,11 @@ fn C.SDL_RenderDrawLines(renderer &C.SDL_Renderer, const_points &C.SDL_Point, co // render_draw_lines draws a series of connected lines on the current rendering target. // -// `renderer` the rendering context -// `points` an array of SDL_Point structures representing points along -// the lines -// `count` the number of points, drawing count-1 lines -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_RenderDrawLine -// See also: SDL_RenderDrawPoint -// See also: SDL_RenderDrawPoints -// See also: SDL_RenderDrawRect -// See also: SDL_RenderDrawRects -// See also: SDL_RenderFillRect -// See also: SDL_RenderFillRects -// See also: SDL_RenderPresent -// See also: SDL_SetRenderDrawBlendMode -// See also: SDL_SetRenderDrawColor +// `renderer` The renderer which should draw multiple lines. +// `points` The points along the lines +// `count` The number of points, drawing count-1 lines +// +// returns 0 on success, or -1 on error pub fn render_draw_lines(renderer &Renderer, const_points &Point, count int) int { return C.SDL_RenderDrawLines(renderer, const_points, count) } @@ -1270,24 +740,10 @@ fn C.SDL_RenderDrawRect(renderer &C.SDL_Renderer, const_rect &C.SDL_Rect) int // render_draw_rect draws a rectangle on the current rendering target. // -// `renderer` the rendering context -// `rect` an SDL_Rect structure representing the rectangle to draw, or -// NULL to outline the entire rendering target -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_RenderDrawLine -// See also: SDL_RenderDrawLines -// See also: SDL_RenderDrawPoint -// See also: SDL_RenderDrawPoints -// See also: SDL_RenderDrawRects -// See also: SDL_RenderFillRect -// See also: SDL_RenderFillRects -// See also: SDL_RenderPresent -// See also: SDL_SetRenderDrawBlendMode -// See also: SDL_SetRenderDrawColor +// `renderer` The renderer which should draw a rectangle. +// `rect` A pointer to the destination rectangle, or NULL to outline the entire rendering target. +// +// returns 0 on success, or -1 on error pub fn render_draw_rect(renderer &Renderer, const_rect &Rect) int { return C.SDL_RenderDrawRect(renderer, const_rect) } @@ -1296,25 +752,11 @@ fn C.SDL_RenderDrawRects(renderer &C.SDL_Renderer, const_rects &C.SDL_Rect, coun // render_draw_rects draws some number of rectangles on the current rendering target. // -// `renderer` the rendering context -// `rects` an array of SDL_Rect structures representing the rectangles to -// be drawn -// `count` the number of rectangles -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_RenderDrawLine -// See also: SDL_RenderDrawLines -// See also: SDL_RenderDrawPoint -// See also: SDL_RenderDrawPoints -// See also: SDL_RenderDrawRect -// See also: SDL_RenderFillRect -// See also: SDL_RenderFillRects -// See also: SDL_RenderPresent -// See also: SDL_SetRenderDrawBlendMode -// See also: SDL_SetRenderDrawColor +// `renderer` The renderer which should draw multiple rectangles. +// `rects` A pointer to an array of destination rectangles. +// `count` The number of rectangles. +// +// returns 0 on success, or -1 on error pub fn render_draw_rects(renderer &Renderer, const_rects &Rect, count int) int { return C.SDL_RenderDrawRects(renderer, const_rects, count) } @@ -1323,54 +765,24 @@ fn C.SDL_RenderFillRect(renderer &C.SDL_Renderer, const_rect &C.SDL_Rect) int // render_fill_rect fills a rectangle on the current rendering target with the drawing color. // -// The current drawing color is set by SDL_SetRenderDrawColor(), and the -// color's alpha value is ignored unless blending is enabled with the -// appropriate call to SDL_SetRenderDrawBlendMode(). -// -// `renderer` the rendering context -// `rect` the SDL_Rect structure representing the rectangle to fill, or -// NULL for the entire rendering target -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_RenderDrawLine -// See also: SDL_RenderDrawLines -// See also: SDL_RenderDrawPoint -// See also: SDL_RenderDrawPoints -// See also: SDL_RenderDrawRect -// See also: SDL_RenderDrawRects -// See also: SDL_RenderFillRects -// See also: SDL_RenderPresent -// See also: SDL_SetRenderDrawBlendMode -// See also: SDL_SetRenderDrawColor +// `renderer` The renderer which should fill a rectangle. +// `rect` A pointer to the destination rectangle, or NULL for the entire +// rendering target. +// +// returns 0 on success, or -1 on error pub fn render_fill_rect(renderer &Renderer, const_rect &Rect) int { return C.SDL_RenderFillRect(renderer, const_rect) } fn C.SDL_RenderFillRects(renderer &C.SDL_Renderer, const_rects &C.SDL_Rect, count int) int -// render_fill_rects fills some number of rectangles on the current rendering target with the -// drawing color. -// -// `renderer` the rendering context -// `rects` an array of SDL_Rect structures representing the rectangles to -// be filled -// `count` the number of rectangles -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_RenderDrawLine -// See also: SDL_RenderDrawLines -// See also: SDL_RenderDrawPoint -// See also: SDL_RenderDrawPoints -// See also: SDL_RenderDrawRect -// See also: SDL_RenderDrawRects -// See also: SDL_RenderFillRect -// See also: SDL_RenderPresent +// render_fill_rects fills some number of rectangles on the current rendering target with the drawing color. +// +// `renderer` The renderer which should fill multiple rectangles. +// `rects` A pointer to an array of destination rectangles. +// `count` The number of rectangles. +// +// returns 0 on success, or -1 on error pub fn render_fill_rects(renderer &Renderer, const_rects &Rect, count int) int { return C.SDL_RenderFillRects(renderer, const_rects, count) } @@ -1379,365 +791,60 @@ fn C.SDL_RenderCopy(renderer &C.SDL_Renderer, texture &C.SDL_Texture, const_srcr // render_copy copies a portion of the texture to the current rendering target. // -// The texture is blended with the destination based on its blend mode set -// with SDL_SetTextureBlendMode(). -// -// The texture color is affected based on its color modulation set by -// SDL_SetTextureColorMod(). -// -// The texture alpha is affected based on its alpha modulation set by -// SDL_SetTextureAlphaMod(). -// -// `renderer` the rendering context -// `texture` the source texture -// `srcrect` the source SDL_Rect structure or NULL for the entire texture -// `dstrect` the destination SDL_Rect structure or NULL for the entire -// rendering target; the texture will be stretched to fill the -// given rectangle -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. +// `renderer` The renderer which should copy parts of a texture. +// `texture` The source texture. +// `srcrect` A pointer to the source rectangle, or NULL for the entire +// texture. +// `dstrect` A pointer to the destination rectangle, or NULL for the +// entire rendering target. // -// See also: SDL_RenderCopyEx -// See also: SDL_SetTextureAlphaMod -// See also: SDL_SetTextureBlendMode -// See also: SDL_SetTextureColorMod +// returns 0 on success, or -1 on error pub fn render_copy(renderer &Renderer, texture &Texture, const_srcrect &Rect, const_dstrect &Rect) int { return C.SDL_RenderCopy(renderer, texture, const_srcrect, const_dstrect) } fn C.SDL_RenderCopyEx(renderer &C.SDL_Renderer, texture &C.SDL_Texture, const_srcrect &C.SDL_Rect, const_dstrect &C.SDL_Rect, const_angle f64, const_center &C.SDL_Point, const_flip C.SDL_RendererFlip) int -// render_copy_ex copies a portion of the texture to the current rendering, with optional -// rotation and flipping. -// -// Copy a portion of the texture to the current rendering target, optionally -// rotating it by angle around the given center and also flipping it -// top-bottom and/or left-right. -// -// The texture is blended with the destination based on its blend mode set -// with SDL_SetTextureBlendMode(). -// -// The texture color is affected based on its color modulation set by -// SDL_SetTextureColorMod(). -// -// The texture alpha is affected based on its alpha modulation set by -// SDL_SetTextureAlphaMod(). -// -// `renderer` the rendering context -// `texture` the source texture -// `srcrect` the source SDL_Rect structure or NULL for the entire texture -// `dstrect` the destination SDL_Rect structure or NULL for the entire -// rendering target -// `angle` an angle in degrees that indicates the rotation that will be -// applied to dstrect, rotating it in a clockwise direction -// `center` a pointer to a point indicating the point around which -// dstrect will be rotated (if NULL, rotation will be done -// around `dstrect.w / 2`, `dstrect.h / 2`) -// `flip` a SDL_RendererFlip value stating which flipping actions should -// be performed on the texture -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_RenderCopy -// See also: SDL_SetTextureAlphaMod -// See also: SDL_SetTextureBlendMode -// See also: SDL_SetTextureColorMod -pub fn render_copy_ex(renderer &Renderer, texture &Texture, const_srcrect &Rect, const_dstrect &Rect, const_angle f64, const_center &Point, const_flip RendererFlip) int { - return C.SDL_RenderCopyEx(renderer, texture, const_srcrect, const_dstrect, const_angle, - const_center, C.SDL_RendererFlip(int(const_flip))) -} - -fn C.SDL_RenderDrawPointF(renderer &C.SDL_Renderer, x f32, y f32) int - -// render_draw_point_f draws a point on the current rendering target at subpixel precision. -// -// `renderer` The renderer which should draw a point. -// `x` The x coordinate of the point. -// `y` The y coordinate of the point. -// returns 0 on success, or -1 on error -// -// NOTE This function is available since SDL 2.0.10. -pub fn render_draw_point_f(renderer &Renderer, x f32, y f32) int { - return C.SDL_RenderDrawPointF(renderer, x, y) -} - -fn C.SDL_RenderDrawPointsF(renderer &C.SDL_Renderer, const_points &C.SDL_FPoint, count int) int - -// render_draw_points_f draws multiple points on the current rendering target at subpixel precision. -// -// `renderer` The renderer which should draw multiple points. -// `points` The points to draw -// `count` The number of points to draw -// returns 0 on success, or -1 on error -// -// NOTE This function is available since SDL 2.0.10. -pub fn render_draw_points_f(renderer &Renderer, const_points &FPoint, count int) int { - return C.SDL_RenderDrawPointsF(renderer, const_points, count) -} - -fn C.SDL_RenderDrawLineF(renderer &C.SDL_Renderer, x1 f32, y1 f32, x2 f32, y2 f32) int - -// render_draw_line_f draws a line on the current rendering target at subpixel precision. -// -// `renderer` The renderer which should draw a line. -// `x1` The x coordinate of the start point. -// `y1` The y coordinate of the start point. -// `x2` The x coordinate of the end point. -// `y2` The y coordinate of the end point. -// returns 0 on success, or -1 on error -// -// NOTE This function is available since SDL 2.0.10. -pub fn render_draw_line_f(renderer &Renderer, x1 f32, y1 f32, x2 f32, y2 f32) int { - return C.SDL_RenderDrawLineF(renderer, x1, y1, x2, y2) -} - -fn C.SDL_RenderDrawLinesF(renderer &C.SDL_Renderer, const_points &C.SDL_FPoint, count int) int - -// render_draw_lines_f draws a series of connected lines on the current rendering target at -// subpixel precision. -// -// `renderer` The renderer which should draw multiple lines. -// `points` The points along the lines -// `count` The number of points, drawing count-1 lines -// returns 0 on success, or -1 on error -// -// NOTE This function is available since SDL 2.0.10. -pub fn render_draw_lines_f(renderer &Renderer, const_points &FPoint, count int) int { - return C.SDL_RenderDrawLinesF(renderer, const_points, count) -} - -fn C.SDL_RenderDrawRectF(renderer &C.SDL_Renderer, const_rect &C.SDL_FRect) int - -// render_draw_rect_f draws a rectangle on the current rendering target at subpixel precision. -// -// `renderer` The renderer which should draw a rectangle. -// `rect` A pointer to the destination rectangle, or NULL to outline the -// entire rendering target. -// returns 0 on success, or -1 on error -// -// NOTE This function is available since SDL 2.0.10. -pub fn render_draw_rect_f(renderer &Renderer, const_rect &FRect) int { - return C.SDL_RenderDrawRectF(renderer, const_rect) -} - -fn C.SDL_RenderDrawRectsF(renderer &C.SDL_Renderer, const_rects &C.SDL_FRect, count int) int - -// render_draw_rects_f draws some number of rectangles on the current rendering target at subpixel -// precision. -// -// `renderer` The renderer which should draw multiple rectangles. -// `rects` A pointer to an array of destination rectangles. -// `count` The number of rectangles. -// returns 0 on success, or -1 on error -// -// NOTE This function is available since SDL 2.0.10. -pub fn render_draw_rects_f(renderer &Renderer, const_rects &FRect, count int) int { - return C.SDL_RenderDrawRectsF(renderer, const_rects, count) -} - -fn C.SDL_RenderFillRectF(renderer &C.SDL_Renderer, const_rect &C.SDL_FRect) int - -// render_fill_rect_f fills a rectangle on the current rendering target with the drawing color at -// subpixel precision. -// -// `renderer` The renderer which should fill a rectangle. -// `rect` A pointer to the destination rectangle, or NULL for the entire -// rendering target. -// returns 0 on success, or -1 on error -// -// NOTE This function is available since SDL 2.0.10. -pub fn render_fill_rect_f(renderer &Renderer, const_rect &FRect) int { - return C.SDL_RenderFillRectF(renderer, const_rect) -} - -fn C.SDL_RenderFillRectsF(renderer &C.SDL_Renderer, const_rects &C.SDL_FRect, count int) int - -// render_fill_rects_f fills some number of rectangles on the current rendering target with the -// drawing color at subpixel precision. -// -// `renderer` The renderer which should fill multiple rectangles. -// `rects` A pointer to an array of destination rectangles. -// `count` The number of rectangles. -// returns 0 on success, or -1 on error -// -// NOTE This function is available since SDL 2.0.10. -pub fn render_fill_rects_f(renderer &Renderer, const_rects &FRect, count int) int { - return C.SDL_RenderFillRectsF(renderer, const_rects, count) -} - -fn C.SDL_RenderCopyF(renderer &C.SDL_Renderer, texture &C.SDL_Texture, const_srcrect &C.SDL_Rect, const_dstrect &C.SDL_FRect) int - -// render_copy_f copies a portion of the texture to the current rendering target at subpixel -// precision. +// render_copy_ex copies a portion of the source texture to the current rendering target, rotating it by angle around the given center // // `renderer` The renderer which should copy parts of a texture. // `texture` The source texture. -// `srcrect` A pointer to the source rectangle, or NULL for the entire -// texture. -// `dstrect` A pointer to the destination rectangle, or NULL for the -// entire rendering target. -// returns 0 on success, or -1 on error -// -// NOTE This function is available since SDL 2.0.10. -pub fn render_copy_f(renderer &Renderer, texture &Texture, const_srcrect &Rect, const_dstrect &FRect) int { - return C.SDL_RenderCopyF(renderer, texture, const_srcrect, const_dstrect) -} - -fn C.SDL_RenderCopyExF(renderer &C.SDL_Renderer, texture &C.SDL_Texture, const_srcrect &C.SDL_Rect, const_dstrect &C.SDL_FRect, const_angle f64, const_center &C.SDL_FPoint, const_flip C.SDL_RendererFlip) int - -// render_copy_ex_f copies a portion of the source texture to the current rendering target, with -// rotation and flipping, at subpixel precision. +// `srcrect` A pointer to the source rectangle, or NULL for the entire +// texture. +// `dstrect` A pointer to the destination rectangle, or NULL for the +// entire rendering target. +// `angle` An angle in degrees that indicates the rotation that will be applied to dstrect, rotating it in a clockwise direction +// `center` A pointer to a point indicating the point around which dstrect will be rotated (if NULL, rotation will be done around dstrect.w/2, dstrect.h/2). +// `flip` An SDL_RendererFlip value stating which flipping actions should be performed on the texture // -// `renderer` The renderer which should copy parts of a texture. -// `texture` The source texture. -// `srcrect` A pointer to the source rectangle, or NULL for the entire -// texture. -// `dstrect` A pointer to the destination rectangle, or NULL for the -// entire rendering target. -// `angle` An angle in degrees that indicates the rotation that will be -// applied to dstrect, rotating it in a clockwise direction -// `center` A pointer to a point indicating the point around which -// dstrect will be rotated (if NULL, rotation will be done -// around dstrect.w/2, dstrect.h/2). -// `flip` An SDL_RendererFlip value stating which flipping actions should -// be performed on the texture // returns 0 on success, or -1 on error -// -// NOTE This function is available since SDL 2.0.10. -pub fn render_copy_ex_f(renderer &Renderer, texture &Texture, const_srcrect &Rect, const_dstrect &FRect, const_angle f64, const_center &FPoint, const_flip RendererFlip) int { - return C.SDL_RenderCopyExF(renderer, texture, const_srcrect, const_dstrect, const_angle, +pub fn render_copy_ex(renderer &Renderer, texture &Texture, const_srcrect &Rect, const_dstrect &Rect, const_angle f64, const_center &Point, const_flip RendererFlip) int { + return C.SDL_RenderCopyEx(renderer, texture, const_srcrect, const_dstrect, const_angle, const_center, C.SDL_RendererFlip(int(const_flip))) } -fn C.SDL_RenderGeometry(renderer &C.SDL_Renderer, texture &C.SDL_Texture, const_vertices &C.SDL_Vertex, num_vertices int, const_indices &int, num_indices int) int +fn C.SDL_RenderReadPixels(renderer &C.SDL_Renderer, const_rect &C.SDL_Rect, format u32, pixels voidptr, pitch int) int -// render_geometry renders a list of triangles, optionally using a texture and indices into the -// vertex array Color and alpha modulation is done per vertex -// (SDL_SetTextureColorMod and SDL_SetTextureAlphaMod are ignored). -// -// `renderer` The rendering context. -// `texture` (optional) The SDL texture to use. -// `vertices` Vertices. -// `num_vertices` Number of vertices. -// `indices` (optional) An array of integer indices into the 'vertices' -// array, if NULL all vertices will be rendered in sequential -// order. -// `num_indices` Number of indices. -// returns 0 on success, or -1 if the operation is not supported +// render_read_pixels reads pixels from the current rendering target. // -// NOTE This function is available since SDL 2.0.18. -// -// See also: SDL_RenderGeometryRaw -// See also: SDL_Vertex -pub fn render_geometry(renderer &Renderer, texture &Texture, const_vertices &Vertex, num_vertices int, const_indices &int, num_indices int) int { - return C.SDL_RenderGeometry(renderer, texture, const_vertices, num_vertices, const_indices, - num_indices) -} - -fn C.SDL_RenderGeometryRaw(renderer &C.SDL_Renderer, texture &C.SDL_Texture, const_xy &f32, xy_stride int, const_color &C.SDL_Color, color_stride int, const_uv &f32, uv_stride int, num_vertices int, const_indices voidptr, num_indices int, size_indices int) int - -// render_geometry_raw renders a list of triangles, optionally using a texture and indices into the -// vertex arrays Color and alpha modulation is done per vertex -// (SDL_SetTextureColorMod and SDL_SetTextureAlphaMod are ignored). -// -// `renderer` The rendering context. -// `texture` (optional) The SDL texture to use. -// `xy` Vertex positions -// `xy_stride` Byte size to move from one element to the next element -// `color` Vertex colors (as SDL_Color) -// `color_stride` Byte size to move from one element to the next element -// `uv` Vertex normalized texture coordinates -// `uv_stride` Byte size to move from one element to the next element -// `num_vertices` Number of vertices. -// `indices` (optional) An array of indices into the 'vertices' arrays, -// if NULL all vertices will be rendered in sequential order. -// `num_indices` Number of indices. -// `size_indices` Index size: 1 (byte), 2 (short), 4 (int) -// returns 0 on success, or -1 if the operation is not supported +// `renderer` The renderer from which pixels should be read. +// `rect` A pointer to the rectangle to read, or NULL for the entire +// render target. +// `format` The desired format of the pixel data, or 0 to use the format +// of the rendering target +// `pixels` A pointer to be filled in with the pixel data +// `pitch` The pitch of the pixels parameter. // -// NOTE This function is available since SDL 2.0.18. +// returns 0 on success, or -1 if pixel reading is not supported. // -// See also: SDL_RenderGeometry -// See also: SDL_Vertex -pub fn render_geometry_raw(renderer &Renderer, texture &Texture, const_xy &f32, xy_stride int, const_color &Color, color_stride int, const_uv &f32, uv_stride int, num_vertices int, const_indices voidptr, num_indices int, size_indices int) int { - return C.SDL_RenderGeometryRaw(renderer, texture, const_xy, xy_stride, const_color, - color_stride, const_uv, uv_stride, num_vertices, const_indices, num_indices, size_indices) -} - -fn C.SDL_RenderReadPixels(renderer &C.SDL_Renderer, const_rect &C.SDL_Rect, format u32, pixels voidptr, pitch int) int - -// render_read_pixels reads pixels from the current rendering target to an array of pixels. -// -// **WARNING**: This is a very slow operation, and should not be used -// frequently. If you're using this on the main rendering target, it should be -// called after rendering and before SDL_RenderPresent(). -// -// `pitch` specifies the number of bytes between rows in the destination -// `pixels` data. This allows you to write to a subrectangle or have padded -// rows in the destination. Generally, `pitch` should equal the number of -// pixels per row in the `pixels` data times the number of bytes per pixel, -// but it might contain additional padding (for example, 24bit RGB Windows -// Bitmap data pads all rows to multiples of 4 bytes). -// -// `renderer` the rendering context -// `rect` an SDL_Rect structure representing the area to read, or NULL -// for the entire render target -// `format` an SDL_PixelFormatEnum value of the desired format of the -// pixel data, or 0 to use the format of the rendering target -// `pixels` a pointer to the pixel data to copy into -// `pitch` the pitch of the `pixels` parameter -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. +// WARNING This is a very slow operation, and should not be used frequently. pub fn render_read_pixels(renderer &Renderer, const_rect &Rect, format u32, pixels voidptr, pitch int) int { return C.SDL_RenderReadPixels(renderer, const_rect, format, pixels, pitch) } fn C.SDL_RenderPresent(renderer &C.SDL_Renderer) -// render_present updates the screen with any rendering performed since the previous call. -// -// SDL's rendering functions operate on a backbuffer; that is, calling a -// rendering function such as SDL_RenderDrawLine() does not directly put a -// line on the screen, but rather updates the backbuffer. As such, you compose -// your entire scene and *present* the composed backbuffer to the screen as a -// complete picture. -// -// Therefore, when using SDL's rendering API, one does all drawing intended -// for the frame, and then calls this function once per frame to present the -// final drawing to the user. -// -// The backbuffer should be considered invalidated after each present; do not -// assume that previous contents will exist between frames. You are strongly -// encouraged to call SDL_RenderClear() to initialize the backbuffer before -// starting each new frame's drawing, even if you plan to overwrite every -// pixel. -// -// `renderer` the rendering context -// -// NOTE (thread safety) You may only call this function on the main thread. If this -// happens to work on a background thread on any given platform -// or backend, it's purely by luck and you should not rely on it -// to work next time. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_RenderClear -// See also: SDL_RenderDrawLine -// See also: SDL_RenderDrawLines -// See also: SDL_RenderDrawPoint -// See also: SDL_RenderDrawPoints -// See also: SDL_RenderDrawRect -// See also: SDL_RenderDrawRects -// See also: SDL_RenderFillRect -// See also: SDL_RenderFillRects -// See also: SDL_SetRenderDrawBlendMode -// See also: SDL_SetRenderDrawColor +// render_present updates the screen with rendering performed. pub fn render_present(renderer &Renderer) { C.SDL_RenderPresent(renderer) } @@ -1746,138 +853,56 @@ fn C.SDL_DestroyTexture(texture &C.SDL_Texture) // destroy_texture destroys the specified texture. // -// Passing NULL or an otherwise invalid texture will set the SDL error message -// to "Invalid texture". -// -// `texture` the texture to destroy -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_CreateTexture -// See also: SDL_CreateTextureFromSurface +// See also: SDL_CreateTexture() +// See also: SDL_CreateTextureFromSurface() pub fn destroy_texture(texture &Texture) { C.SDL_DestroyTexture(texture) } fn C.SDL_DestroyRenderer(renderer &C.SDL_Renderer) -// destroy_renderer destroys the rendering context for a window and free associated textures. -// -// If `renderer` is NULL, this function will return immediately after setting -// the SDL error message to "Invalid renderer". See SDL_GetError(). -// -// `renderer` the rendering context -// -// NOTE This function is available since SDL 2.0.0. +// destroy_renderer destroys the rendering context for a window and free associated +// textures. // -// See also: SDL_CreateRenderer +// See also: SDL_CreateRenderer() pub fn destroy_renderer(renderer &Renderer) { C.SDL_DestroyRenderer(renderer) } -fn C.SDL_RenderFlush(renderer &C.SDL_Renderer) int - -// render_flush forces the rendering context to flush any pending commands to the underlying -// rendering API. -// -// You do not need to (and in fact, shouldn't) call this function unless you -// are planning to call into OpenGL/Direct3D/Metal/whatever directly in -// addition to using an SDL_Renderer. -// -// This is for a very-specific case: if you are using SDL's render API, you -// asked for a specific renderer backend (OpenGL, Direct3D, etc), you set -// SDL_HINT_RENDER_BATCHING to "1", and you plan to make OpenGL/D3D/whatever -// calls in addition to SDL render API calls. If all of this applies, you -// should call SDL_RenderFlush() between calls to SDL's render API and the -// low-level API you're using in cooperation. -// -// In all other cases, you can ignore this function. This is only here to get -// maximum performance out of a specific situation. In all other cases, SDL -// will do the right thing, perhaps at a performance loss. -// -// This function is first available in SDL 2.0.10, and is not needed in 2.0.9 -// and earlier, as earlier versions did not queue rendering commands at all, -// instead flushing them to the OS immediately. -// -// `renderer` the rendering context -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.10. -pub fn render_flush(renderer &Renderer) int { - return C.SDL_RenderFlush(renderer) -} - fn C.SDL_GL_BindTexture(texture &C.SDL_Texture, texw &f32, texh &f32) int -// gl_bind_texture binds an OpenGL/ES/ES2 texture to the current context. -// -// This is for use with OpenGL instructions when rendering OpenGL primitives -// directly. +// gl_bind_texture binds the texture to the current OpenGL/ES/ES2 context for use with +// OpenGL instructions. // -// If not NULL, `texw` and `texh` will be filled with the width and height -// values suitable for the provided texture. In most cases, both will be 1.0, -// however, on systems that support the GL_ARB_texture_rectangle extension, -// these values will actually be the pixel width and height used to create the -// texture, so this factor needs to be taken into account when providing -// texture coordinates to OpenGL. +// `texture` The SDL texture to bind +// `texw` A pointer to a float that will be filled with the texture width +// `texh` A pointer to a float that will be filled with the texture height // -// You need a renderer to create an SDL_Texture, therefore you can only use -// this function with an implicit OpenGL context from SDL_CreateRenderer(), -// not with your own OpenGL context. If you need control over your OpenGL -// context, you need to write your own texture-loading methods. -// -// Also note that SDL may upload RGB textures as BGR (or vice-versa), and -// re-order the color channels in the shaders phase, so the uploaded texture -// may have swapped color channels. -// -// `texture` the texture to bind to the current OpenGL/ES/ES2 context -// `texw` a pointer to a float value which will be filled with the -// texture width or NULL if you don't need that value -// `texh` a pointer to a float value which will be filled with the -// texture height or NULL if you don't need that value -// returns 0 on success, or -1 if the operation is not supported; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GL_MakeCurrent -// See also: SDL_GL_UnbindTexture +// returns 0 on success, or -1 if the operation is not supported pub fn gl_bind_texture(texture &Texture, texw &f32, texh &f32) int { return C.SDL_GL_BindTexture(texture, texw, texh) } fn C.SDL_GL_UnbindTexture(texture &C.SDL_Texture) int -// gl_unbind_texture unbinds an OpenGL/ES/ES2 texture from the current context. +// gl_unbind_texture unbinds a texture from the current OpenGL/ES/ES2 context. // -// See SDL_GL_BindTexture() for examples on how to use these functions +// `texture` The SDL texture to unbind // -// `texture` the texture to unbind from the current OpenGL/ES/ES2 context // returns 0 on success, or -1 if the operation is not supported -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GL_BindTexture -// See also: SDL_GL_MakeCurrent pub fn gl_unbind_texture(texture &Texture) int { return C.SDL_GL_UnbindTexture(texture) } fn C.SDL_RenderGetMetalLayer(renderer &C.SDL_Renderer) voidptr -// render_get_metal_layer gets the CAMetalLayer associated with the given Metal renderer. -// -// This function returns `void *`, so SDL doesn't have to include Metal's -// headers, but it can be safely cast to a `CAMetalLayer *`. +// render_get_metal_layer gets the CAMetalLayer associated with the given Metal renderer // // `renderer` The renderer to query -// returns a `CAMetalLayer *` on success, or NULL if the renderer isn't a -// Metal renderer // -// NOTE This function is available since SDL 2.0.8. +// returns CAMetalLayer* on success, or NULL if the renderer isn't a Metal renderer // -// See also: SDL_RenderGetMetalCommandEncoder +// See also: SDL_RenderGetMetalCommandEncoder() pub fn render_get_metal_layer(renderer &Renderer) voidptr { return C.SDL_RenderGetMetalLayer(renderer) } @@ -1886,47 +911,11 @@ fn C.SDL_RenderGetMetalCommandEncoder(renderer &C.SDL_Renderer) voidptr // render_get_metal_command_encoder gets the Metal command encoder for the current frame // -// This function returns `void *`, so SDL doesn't have to include Metal's -// headers, but it can be safely cast to an `id`. -// -// Note that as of SDL 2.0.18, this will return NULL if Metal refuses to give -// SDL a drawable to render to, which might happen if the window is -// hidden/minimized/offscreen. This doesn't apply to command encoders for -// render targets, just the window's backbuffer. Check your return values! -// // `renderer` The renderer to query -// returns an `id` on success, or NULL if the -// renderer isn't a Metal renderer or there was an error. // -// NOTE This function is available since SDL 2.0.8. +// returns id on success, or NULL if the renderer isn't a Metal renderer // -// See also: SDL_RenderGetMetalLayer +// See also: SDL_RenderGetMetalLayer() pub fn render_get_metal_command_encoder(renderer &Renderer) voidptr { return C.SDL_RenderGetMetalCommandEncoder(renderer) } - -fn C.SDL_RenderSetVSync(renderer &C.SDL_Renderer, vsync int) int - -// render_set_v_sync toggles VSync of the given renderer. -// -// `renderer` The renderer to toggle -// `vsync` 1 for on, 0 for off. All other values are reserved -// returns a 0 int on success, or non-zero on failure -// -// NOTE This function is available since SDL 2.0.18. -@[deprecated: 'use render_set_vsync instead'] -@[deprecated_after: '2024-07-04'] -pub fn render_set_v_sync(renderer &Renderer, vsync int) int { - return C.SDL_RenderSetVSync(renderer, vsync) -} - -// render_set_vsync toggles VSync of the given renderer. -// -// `renderer` The renderer to toggle -// `vsync` 1 for on, 0 for off. All other values are reserved -// returns a 0 int on success, or non-zero on failure -// -// NOTE This function is available since SDL 2.0.18. -pub fn render_set_vsync(renderer &Renderer, vsync int) int { - return C.SDL_RenderSetVSync(renderer, vsync) -} diff --git a/rwops.c.v b/rwops.c.v index 149b7e38..fde131c9 100644 --- a/rwops.c.v +++ b/rwops.c.v @@ -25,188 +25,15 @@ pub const rw_seek_cur = C.RW_SEEK_CUR // 1, Seek relative to current read point pub const rw_seek_end = C.RW_SEEK_END // 2, Seek relative to the end of data -fn C.SDL_RWsize(context &C.SDL_RWops) i64 - -// rw_size gets the size of the data stream in an SDL_RWops. -// -// Prior to SDL 2.0.10, this function was a macro. -// -// `context` the SDL_RWops to get the size of the data stream from -// returns the size of the data stream in the SDL_RWops on success, -1 if -// unknown or a negative error code on failure; call SDL_GetError() -// for more information. -// -// NOTE This function is available since SDL 2.0.10. -pub fn rw_size(context &RWops) i64 { - return C.SDL_RWsize(context) -} - -fn C.SDL_RWseek(context &C.SDL_RWops, offset i64, whence int) i64 - -// rw_seek seeks within an SDL_RWops data stream. -// -// This function seeks to byte `offset`, relative to `whence`. -// -// `whence` may be any of the following values: -// -// - `RW_SEEK_SET`: seek from the beginning of data -// - `RW_SEEK_CUR`: seek relative to current read point -// - `RW_SEEK_END`: seek relative to the end of data -// -// If this stream can not seek, it will return -1. -// -// SDL_RWseek() is actually a wrapper function that calls the SDL_RWops's -// `seek` method appropriately, to simplify application development. -// -// Prior to SDL 2.0.10, this function was a macro. -// -// `context` a pointer to an SDL_RWops structure -// `offset` an offset in bytes, relative to **whence** location; can be -// negative -// `whence` any of `RW_SEEK_SET`, `RW_SEEK_CUR`, `RW_SEEK_END` -// returns the final offset in the data stream after the seek or -1 on error. -// -// NOTE This function is available since SDL 2.0.10. -// -// See also: SDL_RWclose -// See also: SDL_RWFromConstMem -// See also: SDL_RWFromFile -// See also: SDL_RWFromFP -// See also: SDL_RWFromMem -// See also: SDL_RWread -// See also: SDL_RWtell -// See also: SDL_RWwrite -pub fn rw_seek(context &RWops, offset i64, whence int) i64 { - return C.SDL_RWseek(context, offset, whence) -} - -fn C.SDL_RWtell(context &C.SDL_RWops) i64 - -// rw_tell determines the current read/write offset in an SDL_RWops data stream. -// -// SDL_RWtell is actually a wrapper function that calls the SDL_RWops's `seek` -// method, with an offset of 0 bytes from `RW_SEEK_CUR`, to simplify -// application development. -// -// Prior to SDL 2.0.10, this function was a macro. -// -// `context` a SDL_RWops data stream object from which to get the current -// offset -// returns the current offset in the stream, or -1 if the information can not -// be determined. -// -// NOTE This function is available since SDL 2.0.10. -// -// See also: SDL_RWclose -// See also: SDL_RWFromConstMem -// See also: SDL_RWFromFile -// See also: SDL_RWFromFP -// See also: SDL_RWFromMem -// See also: SDL_RWread -// See also: SDL_RWseek -// See also: SDL_RWwrite -pub fn rw_tell(context &RWops) i64 { - return C.SDL_RWtell(context) -} - -fn C.SDL_RWread(context &C.SDL_RWops, ptr voidptr, size usize, maxnum usize) usize - -// rw_read reads from a data source. -// -// This function reads up to `maxnum` objects each of size `size` from the -// data source to the area pointed at by `ptr`. This function may read less -// objects than requested. It will return zero when there has been an error or -// the data stream is completely read. -// -// SDL_RWread() is actually a function wrapper that calls the SDL_RWops's -// `read` method appropriately, to simplify application development. -// -// Prior to SDL 2.0.10, this function was a macro. -// -// `context` a pointer to an SDL_RWops structure -// `ptr` a pointer to a buffer to read data into -// `size` the size of each object to read, in bytes -// `maxnum` the maximum number of objects to be read -// returns the number of objects read, or 0 at error or end of file; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.10. -// -// See also: SDL_RWclose -// See also: SDL_RWFromConstMem -// See also: SDL_RWFromFile -// See also: SDL_RWFromFP -// See also: SDL_RWFromMem -// See also: SDL_RWseek -// See also: SDL_RWwrite -pub fn rw_read(context &RWops, ptr voidptr, size usize, maxnum usize) usize { - return C.SDL_RWread(context, ptr, size, maxnum) -} - -fn C.SDL_RWwrite(context &C.SDL_RWops, ptr voidptr, size usize, num usize) usize - -// rw_write writes to an SDL_RWops data stream. -// -// This function writes exactly `num` objects each of size `size` from the -// area pointed at by `ptr` to the stream. If this fails for any reason, it'll -// return less than `num` to demonstrate how far the write progressed. On -// success, it returns `num`. -// -// SDL_RWwrite is actually a function wrapper that calls the SDL_RWops's -// `write` method appropriately, to simplify application development. -// -// Prior to SDL 2.0.10, this function was a macro. -// -// `context` a pointer to an SDL_RWops structure -// `ptr` a pointer to a buffer containing data to write -// `size` the size of an object to write, in bytes -// `num` the number of objects to write -// returns the number of objects written, which will be less than **num** on -// error; call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.10. -// -// See also: SDL_RWclose -// See also: SDL_RWFromConstMem -// See also: SDL_RWFromFile -// See also: SDL_RWFromFP -// See also: SDL_RWFromMem -// See also: SDL_RWread -// See also: SDL_RWseek -pub fn rw_write(context &RWops, ptr voidptr, size usize, num usize) usize { - return C.SDL_RWwrite(context, ptr, size, num) -} - -fn C.SDL_RWclose(context &C.SDL_RWops) int - -// rw_close closes and free an allocated SDL_RWops structure. -// -// SDL_RWclose() closes and cleans up the SDL_RWops stream. It releases any -// resources used by the stream and frees the SDL_RWops itself with -// SDL_FreeRW(). This returns 0 on success, or -1 if the stream failed to -// flush to its output (e.g. to disk). +// Read/write macros // -// Note that if this fails to flush the stream to disk, this function reports -// an error, but the SDL_RWops is still invalid once this function returns. -// -// Prior to SDL 2.0.10, this function was a macro. -// -// `context` SDL_RWops structure to close -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.10. -// -// See also: SDL_RWFromConstMem -// See also: SDL_RWFromFile -// See also: SDL_RWFromFP -// See also: SDL_RWFromMem -// See also: SDL_RWread -// See also: SDL_RWseek -// See also: SDL_RWwrite -pub fn rw_close(context &RWops) int { - return C.SDL_RWclose(context) -} +// Macros to easily read and write from an SDL_RWops structure. +fn C.SDL_RWsize(ctx &C.SDL_RWops) i64 +fn C.SDL_RWseek(ctx &C.SDL_RWops, offset i64, whence int) i64 +fn C.SDL_RWtell(ctx &C.SDL_RWops) i64 +fn C.SDL_RWread(ctx &C.SDL_RWops, ptr voidptr, size usize, n usize) usize +fn C.SDL_RWwrite(ctx &C.SDL_RWops, ptr voidptr, size usize, n usize) usize +fn C.SDL_RWclose(ctx &C.SDL_RWops) int // This is the read/write operation structure -- very basic. @[typedef] @@ -286,66 +113,6 @@ pub fn (rwo &RWops) close() int { // // Functions to create SDL_RWops structures from various data streams. fn C.SDL_RWFromFile(const_file &char, const_mode &char) &C.SDL_RWops - -// rw_from_file uses this function to create a new SDL_RWops structure for reading from -// and/or writing to a named file. -// -// The `mode` string is treated roughly the same as in a call to the C -// library's fopen(), even if SDL doesn't happen to use fopen() behind the -// scenes. -// -// Available `mode` strings: -// -// - "r": Open a file for reading. The file must exist. -// - "w": Create an empty file for writing. If a file with the same name -// already exists its content is erased and the file is treated as a new -// empty file. -// - "a": Append to a file. Writing operations append data at the end of the -// file. The file is created if it does not exist. -// - "r+": Open a file for update both reading and writing. The file must -// exist. -// - "w+": Create an empty file for both reading and writing. If a file with -// the same name already exists its content is erased and the file is -// treated as a new empty file. -// - "a+": Open a file for reading and appending. All writing operations are -// performed at the end of the file, protecting the previous content to be -// overwritten. You can reposition (fseek, rewind) the internal pointer to -// anywhere in the file for reading, but writing operations will move it -// back to the end of file. The file is created if it does not exist. -// -// **NOTE**: In order to open a file as a binary file, a "b" character has to -// be included in the `mode` string. This additional "b" character can either -// be appended at the end of the string (thus making the following compound -// modes: "rb", "wb", "ab", "r+b", "w+b", "a+b") or be inserted between the -// letter and the "+" sign for the mixed modes ("rb+", "wb+", "ab+"). -// Additional characters may follow the sequence, although they should have no -// effect. For example, "t" is sometimes appended to make explicit the file is -// a text file. -// -// This function supports Unicode filenames, but they must be encoded in UTF-8 -// format, regardless of the underlying operating system. -// -// As a fallback, SDL_RWFromFile() will transparently open a matching filename -// in an Android app's `assets`. -// -// Closing the SDL_RWops will close the file handle SDL is holding internally. -// -// `file` a UTF-8 string representing the filename to open -// `mode` an ASCII string representing the mode to be used for opening -// the file. -// returns a pointer to the SDL_RWops structure that is created, or NULL on -// failure; call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_RWclose -// See also: SDL_RWFromConstMem -// See also: SDL_RWFromFP -// See also: SDL_RWFromMem -// See also: SDL_RWread -// See also: SDL_RWseek -// See also: SDL_RWtell -// See also: SDL_RWwrite pub fn rw_from_file(const_file &char, const_mode &char) &RWops { return C.SDL_RWFromFile(const_file, const_mode) } @@ -359,358 +126,82 @@ pub fn rw_from_fp(fp &C.FILE, autoclose bool) &RWops{ } */ fn C.SDL_RWFromFP(fp voidptr, autoclose bool) &C.SDL_RWops - -// rw_from_fp creates a new SDL_RWops structure for reading from -// and/or writing to a named file. -// -// The `mode` string is treated roughly the same as in a call to the C -// library's fopen(), even if SDL doesn't happen to use fopen() behind the -// scenes. -// -// Available `mode` strings: -// -// - "r": Open a file for reading. The file must exist. -// - "w": Create an empty file for writing. If a file with the same name -// already exists its content is erased and the file is treated as a new -// empty file. -// - "a": Append to a file. Writing operations append data at the end of the -// file. The file is created if it does not exist. -// - "r+": Open a file for update both reading and writing. The file must -// exist. -// - "w+": Create an empty file for both reading and writing. If a file with -// the same name already exists its content is erased and the file is -// treated as a new empty file. -// - "a+": Open a file for reading and appending. All writing operations are -// performed at the end of the file, protecting the previous content to be -// overwritten. You can reposition (fseek, rewind) the internal pointer to -// anywhere in the file for reading, but writing operations will move it -// back to the end of file. The file is created if it does not exist. -// -// **NOTE**: In order to open a file as a binary file, a "b" character has to -// be included in the `mode` string. This additional "b" character can either -// be appended at the end of the string (thus making the following compound -// modes: "rb", "wb", "ab", "r+b", "w+b", "a+b") or be inserted between the -// letter and the "+" sign for the mixed modes ("rb+", "wb+", "ab+"). -// Additional characters may follow the sequence, although they should have no -// effect. For example, "t" is sometimes appended to make explicit the file is -// a text file. -// -// This function supports Unicode filenames, but they must be encoded in UTF-8 -// format, regardless of the underlying operating system. -// -// As a fallback, SDL_RWFromFile() will transparently open a matching filename -// in an Android app's `assets`. -// -// Closing the SDL_RWops will close the file handle SDL is holding internally. -// -// `file` a UTF-8 string representing the filename to open -// `mode` an ASCII string representing the mode to be used for opening -// the file. -// returns a pointer to the SDL_RWops structure that is created, or NULL on -// failure; call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_RWclose -// See also: SDL_RWFromConstMem -// See also: SDL_RWFromFP -// See also: SDL_RWFromMem -// See also: SDL_RWread -// See also: SDL_RWseek -// See also: SDL_RWtell -// See also: SDL_RWwrite pub fn rw_from_fp(fp voidptr, autoclose bool) &RWops { return C.SDL_RWFromFP(fp, autoclose) } fn C.SDL_RWFromMem(mem voidptr, size int) &C.SDL_RWops - -// rw_from_mem prepares a read-write memory buffer for use with -// SDL_RWops. -// -// This function sets up an SDL_RWops struct based on a memory area of a -// certain size, for both read and write access. -// -// This memory buffer is not copied by the RWops; the pointer you provide must -// remain valid until you close the stream. Closing the stream will not free -// the original buffer. -// -// If you need to make sure the RWops never writes to the memory buffer, you -// should use SDL_RWFromConstMem() with a read-only buffer of memory instead. -// -// `mem` a pointer to a buffer to feed an SDL_RWops stream -// `size` the buffer size, in bytes -// returns a pointer to a new SDL_RWops structure, or NULL if it fails; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_RWclose -// See also: SDL_RWFromConstMem -// See also: SDL_RWFromFile -// See also: SDL_RWFromFP -// See also: SDL_RWFromMem -// See also: SDL_RWread -// See also: SDL_RWseek -// See also: SDL_RWtell -// See also: SDL_RWwrite pub fn rw_from_mem(mem voidptr, size int) &RWops { return C.SDL_RWFromMem(mem, size) } fn C.SDL_RWFromConstMem(mem voidptr, size int) &C.SDL_RWops - -// rw_from_const_mem prepares a read-only memory buffer for use with RWops. -// -// This function sets up an SDL_RWops struct based on a memory area of a -// certain size. It assumes the memory area is not writable. -// -// Attempting to write to this RWops stream will report an error without -// writing to the memory buffer. -// -// This memory buffer is not copied by the RWops; the pointer you provide must -// remain valid until you close the stream. Closing the stream will not free -// the original buffer. -// -// If you need to write to a memory buffer, you should use SDL_RWFromMem() -// with a writable buffer of memory instead. -// -// `mem` a pointer to a read-only buffer to feed an SDL_RWops stream -// `size` the buffer size, in bytes -// returns a pointer to a new SDL_RWops structure, or NULL if it fails; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_RWclose -// See also: SDL_RWFromConstMem -// See also: SDL_RWFromFile -// See also: SDL_RWFromFP -// See also: SDL_RWFromMem -// See also: SDL_RWread -// See also: SDL_RWseek -// See also: SDL_RWtell pub fn rw_from_const_mem(mem voidptr, size int) &RWops { return C.SDL_RWFromConstMem(mem, size) } fn C.SDL_AllocRW() &C.SDL_RWops - -// alloc_rw allocates an empty, unpopulated SDL_RWops structure. -// -// Applications do not need to use this function unless they are providing -// their own SDL_RWops implementation. If you just need a SDL_RWops to -// read/write a common data source, you should use the built-in -// implementations in SDL, like SDL_RWFromFile() or SDL_RWFromMem(), etc. -// -// You must free the returned pointer with SDL_FreeRW(). Depending on your -// operating system and compiler, there may be a difference between the -// malloc() and free() your program uses and the versions SDL calls -// internally. Trying to mix the two can cause crashing such as segmentation -// faults. Since all SDL_RWops must free themselves when their **close** -// method is called, all SDL_RWops must be allocated through this function, so -// they can all be freed correctly with SDL_FreeRW(). -// -// returns a pointer to the allocated memory on success, or NULL on failure; -// call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_FreeRW pub fn alloc_rw() &RWops { return C.SDL_AllocRW() } fn C.SDL_FreeRW(area &C.SDL_RWops) - -// free_rw frees an SDL_RWops structure allocated by -// SDL_AllocRW(). -// -// Applications do not need to use this function unless they are providing -// their own SDL_RWops implementation. If you just need a SDL_RWops to -// read/write a common data source, you should use the built-in -// implementations in SDL, like SDL_RWFromFile() or SDL_RWFromMem(), etc, and -// call the **close** method on those SDL_RWops pointers when you are done -// with them. -// -// Only use SDL_FreeRW() on pointers returned by SDL_AllocRW(). The pointer is -// invalid as soon as this function returns. Any extra memory allocated during -// creation of the SDL_RWops is not freed by SDL_FreeRW(); the programmer must -// be responsible for managing that memory in their **close** method. -// -// `area` the SDL_RWops structure to be freed -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_AllocRW pub fn free_rw(area &RWops) { C.SDL_FreeRW(area) } -fn C.SDL_LoadFile_RW(src &C.SDL_RWops, datasize &usize, freesrc int) voidptr - -// load_file_rw loads all the data from an SDL data stream. +// Load all the data from an SDL data stream. +// +// The data is allocated with a zero byte at the end (null terminated) +// +// If `datasize` is not NULL, it is filled with the size of the data read. // -// The data is allocated with a zero byte at the end (null terminated) for -// convenience. This extra byte is not included in the value reported via -// `datasize`. +// If `freesrc` is non-zero, the stream will be closed after being read. // // The data should be freed with SDL_free(). // -// `src` the SDL_RWops to read all available data from -// `datasize` if not NULL, will store the number of bytes read -// `freesrc` if non-zero, calls SDL_RWclose() on `src` before returning // returns the data, or NULL if there was an error. -// -// NOTE This function is available since SDL 2.0.6. +fn C.SDL_LoadFile_RW(src &C.SDL_RWops, datasize &usize, freesrc int) voidptr pub fn load_file_rw(src &RWops, datasize &usize, freesrc int) voidptr { return C.SDL_LoadFile_RW(src, datasize, freesrc) } fn C.SDL_LoadFile(file &char, datasize &usize) voidptr -// load_file loads all the data from a file path. -// -// The data is allocated with a zero byte at the end (null terminated) for -// convenience. This extra byte is not included in the value reported via -// `datasize`. -// -// The data should be freed with SDL_free(). -// -// Prior to SDL 2.0.10, this function was a macro wrapping around -// SDL_LoadFile_RW. -// -// `file` the path to read all available data from -// `datasize` if not NULL, will store the number of bytes read -// returns the data, or NULL if there was an error. -// -// NOTE This function is available since SDL 2.0.10. -pub fn load_file(file &char, datasize &usize) voidptr { - return C.SDL_LoadFile(file, datasize) -} - // Read endian functions // // Read an item of the specified endianness and return in native format. fn C.SDL_ReadU8(src &C.SDL_RWops) u8 - -// read_u8 reads a byte from an SDL_RWops. -// -// `src` the SDL_RWops to read from -// returns the read byte on success or 0 on failure; call SDL_GetError() for -// more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_WriteU8 pub fn read_u8(src &RWops) u8 { return C.SDL_ReadU8(src) } fn C.SDL_ReadLE16(src &C.SDL_RWops) u16 - -// read_le16 reads 16 bits of little-endian data from an SDL_RWops -// and return in native format. -// -// SDL byteswaps the data only if necessary, so the data returned will be in -// the native byte order. -// -// `src` the stream from which to read data -// returns 16 bits of data in the native byte order of the platform. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_ReadBE16 pub fn read_le16(src &RWops) u16 { return C.SDL_ReadLE16(src) } fn C.SDL_ReadBE16(src &C.SDL_RWops) u16 - -// read_be16 reads 16 bits of big-endian data from an SDL_RWops and -// return in native format. -// -// SDL byteswaps the data only if necessary, so the data returned will be in -// the native byte order. -// -// `src` the stream from which to read data -// returns 16 bits of data in the native byte order of the platform. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_ReadLE16 pub fn read_be16(src &RWops) u16 { return C.SDL_ReadBE16(src) } fn C.SDL_ReadLE32(src &C.SDL_RWops) u32 - -// read_le32 reads 32 bits of little-endian data from an SDL_RWops -// and return in native format. -// -// SDL byteswaps the data only if necessary, so the data returned will be in -// the native byte order. -// -// `src` the stream from which to read data -// returns 32 bits of data in the native byte order of the platform. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_ReadBE32 pub fn read_le32(src &RWops) u32 { return C.SDL_ReadLE32(src) } fn C.SDL_ReadBE32(src &C.SDL_RWops) u32 - -// read_be32 reads 32 bits of big-endian data from an SDL_RWops and -// return in native format. -// -// SDL byteswaps the data only if necessary, so the data returned will be in -// the native byte order. -// -// `src` the stream from which to read data -// returns 32 bits of data in the native byte order of the platform. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_ReadLE32 pub fn read_be32(src &RWops) u32 { return C.SDL_ReadBE32(src) } fn C.SDL_ReadLE64(src &C.SDL_RWops) u64 - -// read_le64 reads 64 bits of little-endian data from an SDL_RWops -// and return in native format. -// -// SDL byteswaps the data only if necessary, so the data returned will be in -// the native byte order. -// -// `src` the stream from which to read data -// returns 64 bits of data in the native byte order of the platform. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_ReadBE64 pub fn read_le64(src &RWops) u64 { return C.SDL_ReadLE64(src) } fn C.SDL_ReadBE64(src &C.SDL_RWops) u64 - -// read_be64 reads 64 bits of big-endian data from an SDL_RWops and -// return in native format. -// -// SDL byteswaps the data only if necessary, so the data returned will be in -// the native byte order. -// -// `src` the stream from which to read data -// returns 64 bits of data in the native byte order of the platform. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_ReadLE64 pub fn read_be64(src &RWops) u64 { return C.SDL_ReadBE64(src) } @@ -719,134 +210,36 @@ pub fn read_be64(src &RWops) u64 { // // Write an item of native format to the specified endianness. fn C.SDL_WriteU8(dst &C.SDL_RWops, value u8) usize - -// write_u8 writes a byte to an SDL_RWops. -// -// `dst` the SDL_RWops to write to -// `value` the byte value to write -// returns 1 on success or 0 on failure; call SDL_GetError() for more -// information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_ReadU8 pub fn write_u8(dst &RWops, value u8) usize { return C.SDL_WriteU8(dst, value) } fn C.SDL_WriteLE16(dst &C.SDL_RWops, value u16) usize - -// write_le16 uses this function to write 16 bits in native format to a SDL_RWops as -// little-endian data. -// -// SDL byteswaps the data only if necessary, so the application always -// specifies native format, and the data written will be in little-endian -// format. -// -// `dst` the stream to which data will be written -// `value` the data to be written, in native format -// returns 1 on successful write, 0 on error. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_WriteBE16 pub fn write_le16(dst &RWops, value u16) usize { return C.SDL_WriteLE16(dst, value) } fn C.SDL_WriteBE16(dst &C.SDL_RWops, value u16) usize - -// write_be16 writes 16 bits in native format to a SDL_RWops as -// big-endian data. -// -// SDL byteswaps the data only if necessary, so the application always -// specifies native format, and the data written will be in big-endian format. -// -// `dst` the stream to which data will be written -// `value` the data to be written, in native format -// returns 1 on successful write, 0 on error. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_WriteLE16 pub fn write_be16(dst &RWops, value u16) usize { return C.SDL_WriteBE16(dst, value) } fn C.SDL_WriteLE32(dst &C.SDL_RWops, value u32) usize - -// write_le32 writes 32 bits in native format to a SDL_RWops as -// little-endian data. -// -// SDL byteswaps the data only if necessary, so the application always -// specifies native format, and the data written will be in little-endian -// format. -// -// `dst` the stream to which data will be written -// `value` the data to be written, in native format -// returns 1 on successful write, 0 on error. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_WriteBE32 pub fn write_le32(dst &RWops, value u32) usize { return C.SDL_WriteLE32(dst, value) } fn C.SDL_WriteBE32(dst &C.SDL_RWops, value u32) usize - -// write_be32 writes 32 bits in native format to a SDL_RWops as -// big-endian data. -// -// SDL byteswaps the data only if necessary, so the application always -// specifies native format, and the data written will be in big-endian format. -// -// `dst` the stream to which data will be written -// `value` the data to be written, in native format -// returns 1 on successful write, 0 on error. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_WriteLE32 pub fn write_be32(dst &RWops, value u32) usize { return C.SDL_WriteBE32(dst, value) } fn C.SDL_WriteLE64(dst &C.SDL_RWops, value u64) usize - -// write_le64 writes 64 bits in native format to a SDL_RWops as -// little-endian data. -// -// SDL byteswaps the data only if necessary, so the application always -// specifies native format, and the data written will be in little-endian -// format. -// -// `dst` the stream to which data will be written -// `value` the data to be written, in native format -// returns 1 on successful write, 0 on error. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_WriteBE64 pub fn write_le64(dst &RWops, value u64) usize { return C.SDL_WriteLE64(dst, value) } fn C.SDL_WriteBE64(dst &C.SDL_RWops, value u64) usize - -// write_be64 writes 64 bits in native format to a SDL_RWops as -// big-endian data. -// -// SDL byteswaps the data only if necessary, so the application always -// specifies native format, and the data written will be in big-endian format. -// -// `dst` the stream to which data will be written -// `value` the data to be written, in native format -// returns 1 on successful write, 0 on error. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_WriteLE64 pub fn write_be64(dst &RWops, value u64) usize { return C.SDL_WriteBE64(dst, value) } diff --git a/scancode.c.v b/scancode.c.v index 7cb63ec5..b449771e 100644 --- a/scancode.c.v +++ b/scancode.c.v @@ -14,7 +14,7 @@ module sdl // SDL_Event structure. // // The values in this enumeration are based on the USB usage page standard: -// https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf +// http://www.usb.org/developers/hidpage/Hut1_12v2.pdf // Scancode is C.SDL_Scancode pub enum Scancode { scancode_unknown = C.SDL_SCANCODE_UNKNOWN // 0 @@ -202,16 +202,16 @@ pub enum Scancode { scancode_f23 = C.SDL_SCANCODE_F23 // 114 scancode_f24 = C.SDL_SCANCODE_F24 // 115 scancode_execute = C.SDL_SCANCODE_EXECUTE // 116 - scancode_help = C.SDL_SCANCODE_HELP // 117 AL Integrated Help Center - scancode_menu = C.SDL_SCANCODE_MENU // 118 Menu (show menu) + scancode_help = C.SDL_SCANCODE_HELP // 117 + scancode_menu = C.SDL_SCANCODE_MENU // 118 scancode_select = C.SDL_SCANCODE_SELECT // 119 - scancode_stop = C.SDL_SCANCODE_STOP // 120 AC Stop - scancode_again = C.SDL_SCANCODE_AGAIN // 121 AC Redo/Repeat - scancode_undo = C.SDL_SCANCODE_UNDO // 122 AC Undo - scancode_cut = C.SDL_SCANCODE_CUT // 123 AC Cut - scancode_copy = C.SDL_SCANCODE_COPY // 124 AC Copy - scancode_paste = C.SDL_SCANCODE_PASTE // 125 AC Paste - scancode_find = C.SDL_SCANCODE_FIND // 126 AC Find + scancode_stop = C.SDL_SCANCODE_STOP // 120 + scancode_again = C.SDL_SCANCODE_AGAIN // 121< redo + scancode_undo = C.SDL_SCANCODE_UNDO // 122 + scancode_cut = C.SDL_SCANCODE_CUT // 123 + scancode_copy = C.SDL_SCANCODE_COPY // 124 + scancode_paste = C.SDL_SCANCODE_PASTE // 125 + scancode_find = C.SDL_SCANCODE_FIND // 126 scancode_mute = C.SDL_SCANCODE_MUTE // 127 scancode_volumeup = C.SDL_SCANCODE_VOLUMEUP // 128 scancode_volumedown = C.SDL_SCANCODE_VOLUMEDOWN // 129 @@ -239,7 +239,7 @@ pub enum Scancode { // scancode_alterase = C.SDL_SCANCODE_ALTERASE // 153 Erase-Eaze scancode_sysreq = C.SDL_SCANCODE_SYSREQ // 154 - scancode_cancel = C.SDL_SCANCODE_CANCEL // 155 AC Cancel + scancode_cancel = C.SDL_SCANCODE_CANCEL // 155 scancode_clear = C.SDL_SCANCODE_CLEAR // 156 scancode_prior = C.SDL_SCANCODE_PRIOR // 157 scancode_return2 = C.SDL_SCANCODE_RETURN2 // 158 @@ -312,32 +312,23 @@ pub enum Scancode { // I'm not sure if this is really not covered // by any of the above, but since there's a // special KMOD_MODE for it I'm adding it here - // - // Usage page 0x0C (additional media keys) - // - // These values are mapped from usage page 0x0C (USB consumer page). - // See https://usb.org/sites/default/files/hut1_2.pdf - // - // There are way more keys in the spec than we can represent in the - // current scancode range, so pick the ones that commonly come up in - // real world usage. scancode_audionext = C.SDL_SCANCODE_AUDIONEXT // 258 scancode_audioprev = C.SDL_SCANCODE_AUDIOPREV // 259 scancode_audiostop = C.SDL_SCANCODE_AUDIOSTOP // 260 scancode_audioplay = C.SDL_SCANCODE_AUDIOPLAY // 261 scancode_audiomute = C.SDL_SCANCODE_AUDIOMUTE // 262 scancode_mediaselect = C.SDL_SCANCODE_MEDIASELECT // 263 - scancode_www = C.SDL_SCANCODE_WWW // 264 AL Internet Browser + scancode_www = C.SDL_SCANCODE_WWW // 264 scancode_mail = C.SDL_SCANCODE_MAIL // 265 - scancode_calculator = C.SDL_SCANCODE_CALCULATOR // 266 AL Calculator + scancode_calculator = C.SDL_SCANCODE_CALCULATOR // 266 scancode_computer = C.SDL_SCANCODE_COMPUTER // 267 - scancode_ac_search = C.SDL_SCANCODE_AC_SEARCH // 268 AC Search - scancode_ac_home = C.SDL_SCANCODE_AC_HOME // 269 AC Home - scancode_ac_back = C.SDL_SCANCODE_AC_BACK // 270 AC Back - scancode_ac_forward = C.SDL_SCANCODE_AC_FORWARD // 271 AC Forward - scancode_ac_stop = C.SDL_SCANCODE_AC_STOP // 272 AC Stop - scancode_ac_refresh = C.SDL_SCANCODE_AC_REFRESH // 273 AC Refresh - scancode_ac_bookmarks = C.SDL_SCANCODE_AC_BOOKMARKS // 274 AC Bookmarks + scancode_ac_search = C.SDL_SCANCODE_AC_SEARCH // 268 + scancode_ac_home = C.SDL_SCANCODE_AC_HOME // 269 + scancode_ac_back = C.SDL_SCANCODE_AC_BACK // 270 + scancode_ac_forward = C.SDL_SCANCODE_AC_FORWARD // 271 + scancode_ac_stop = C.SDL_SCANCODE_AC_STOP // 272 + scancode_ac_refresh = C.SDL_SCANCODE_AC_REFRESH // 273 + scancode_ac_bookmarks = C.SDL_SCANCODE_AC_BOOKMARKS // 274 // Walther keys // // These are values that Christian Walther added (for mac keyboard?). @@ -350,32 +341,16 @@ pub enum Scancode { scancode_kbdillumdown = C.SDL_SCANCODE_KBDILLUMDOWN // 279 scancode_kbdillumup = C.SDL_SCANCODE_KBDILLUMUP // 280 scancode_eject = C.SDL_SCANCODE_EJECT // 281 - scancode_sleep = C.SDL_SCANCODE_SLEEP // 282 SC System Sleep + scancode_sleep = C.SDL_SCANCODE_SLEEP // 282 // scancode_app1 = C.SDL_SCANCODE_APP1 // 283 scancode_app2 = C.SDL_SCANCODE_APP2 // 284 // + // Usage page 0x0C (additional media keys) + // + // These values are mapped from usage page 0x0C (USB consumer page). scancode_audiorewind = C.SDL_SCANCODE_AUDIOREWIND // 285 scancode_audiofastforward = C.SDL_SCANCODE_AUDIOFASTFORWARD // 286 - // - // Mobile keys - // - // These are values that are often used on mobile phones. - // - // Usually situated below the display on phones and - // used as a multi-function feature key for selecting - // a software defined function shown on the bottom left - // of the display. - scancode_softleft = C.SDL_SCANCODE_SOFTLEFT // 287 - // Usually situated below the display on phones and - // used as a multi-function feature key for selecting - // a software defined function shown on the bottom right - // of the display. - scancode_softright = C.SDL_SCANCODE_SOFTRIGHT // 288 - // - scancode_call = C.SDL_SCANCODE_CALL // 289 // Used for accepting phone calls. - scancode_endcall = C.SDL_SCANCODE_ENDCALL // 290 // Used for rejecting phone calls. - // // Add any other keys here. num_scancodes = C.SDL_NUM_SCANCODES // 512 } diff --git a/sdl.c.v b/sdl.c.v index ef227351..b8dca1f7 100644 --- a/sdl.c.v +++ b/sdl.c.v @@ -25,146 +25,51 @@ pub const init_gamecontroller = u32(C.SDL_INIT_GAMECONTROLLER) // 0x00002000u SD pub const init_events = u32(C.SDL_INIT_EVENTS) // 0x00004000u -pub const init_sensor = u32(C.SDL_INIT_SENSOR) // 0x00008000u - pub const init_noparachute = u32(C.SDL_INIT_NOPARACHUTE) // 0x00100000u compatibility; this flag is ignored. -pub const init_everything = u32(C.SDL_INIT_EVERYTHING) // ( SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | INIT_GAMECONTROLLER | SDL_INIT_SENSOR ) +pub const init_everything = u32(C.SDL_INIT_EVERYTHING) // ( SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | INIT_GAMECONTROLLER ) fn C.SDL_Init(flags u32) int -// init initializes the SDL library. -// -// SDL_Init() simply forwards to calling SDL_InitSubSystem(). Therefore, the -// two may be used interchangeably. Though for readability of your code -// SDL_InitSubSystem() might be preferred. -// -// The file I/O (for example: SDL_RWFromFile) and threading (SDL_CreateThread) -// subsystems are initialized by default. Message boxes -// (SDL_ShowSimpleMessageBox) also attempt to work without initializing the -// video subsystem, in hopes of being useful in showing an error dialog when -// SDL_Init fails. You must specifically initialize other subsystems if you -// use them in your application. -// -// Logging (such as SDL_Log) works without initialization, too. -// -// `flags` may be any of the following OR'd together: -// -// - `SDL_INIT_TIMER`: timer subsystem -// - `SDL_INIT_AUDIO`: audio subsystem -// - `SDL_INIT_VIDEO`: video subsystem; automatically initializes the events -// subsystem -// - `SDL_INIT_JOYSTICK`: joystick subsystem; automatically initializes the -// events subsystem -// - `SDL_INIT_HAPTIC`: haptic (force feedback) subsystem -// - `SDL_INIT_GAMECONTROLLER`: controller subsystem; automatically -// initializes the joystick subsystem -// - `SDL_INIT_EVENTS`: events subsystem -// - `SDL_INIT_EVERYTHING`: all of the above subsystems -// - `SDL_INIT_NOPARACHUTE`: compatibility; this flag is ignored -// -// Subsystem initialization is ref-counted, you must call SDL_QuitSubSystem() -// for each SDL_InitSubSystem() to correctly shutdown a subsystem manually (or -// call SDL_Quit() to force shutdown). If a subsystem is already loaded then -// this call will increase the ref-count and return. -// -// `flags` subsystem initialization flags -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_InitSubSystem -// See also: SDL_Quit -// See also: SDL_SetMainReady -// See also: SDL_WasInit +// init initializes the subsystems specified by `flags` pub fn init(flags u32) int { return C.SDL_Init(flags) } fn C.SDL_InitSubSystem(flags u32) int -// init_sub_system is a compatibility function to initialize the SDL library. -// -// In SDL2, this function and SDL_Init() are interchangeable. -// -// `flags` any of the flags used by SDL_Init(); see SDL_Init for details. -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. +// init_sub_system initializes specific SDL subsystems // -// See also: SDL_Init -// See also: SDL_Quit -// See also: SDL_QuitSubSystem +// Subsystem initialization is ref-counted, you must call +// SDL_QuitSubSystem() for each SDL_InitSubSystem() to correctly +// shutdown a subsystem manually (or call SDL_Quit() to force shutdown). +// If a subsystem is already loaded then this call will +// increase the ref-count and return. pub fn init_sub_system(flags u32) int { return C.SDL_InitSubSystem(flags) } fn C.SDL_QuitSubSystem(flags u32) -// quit_sub_system shuts down specific SDL subsystems. -// -// If you start a subsystem using a call to that subsystem's init function -// (for example SDL_VideoInit()) instead of SDL_Init() or SDL_InitSubSystem(), -// SDL_QuitSubSystem() and SDL_WasInit() will not work. You will need to use -// that subsystem's quit function (SDL_VideoQuit()) directly instead. But -// generally, you should not be using those functions directly anyhow; use -// SDL_Init() instead. -// -// You still need to call SDL_Quit() even if you close all open subsystems -// with SDL_QuitSubSystem(). -// -// `flags` any of the flags used by SDL_Init(); see SDL_Init for details. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_InitSubSystem -// See also: SDL_Quit +// quit_sub_system cleans up specific SDL subsystems pub fn quit_sub_system(flags u32) { C.SDL_QuitSubSystem(flags) } fn C.SDL_WasInit(flags u32) u32 -// was_init gets a mask of the specified subsystems which are currently initialized. -// -// `flags` any of the flags used by SDL_Init(); see SDL_Init for details. -// returns a mask of all initialized subsystems if `flags` is 0, otherwise it -// returns the initialization status of the specified subsystems. -// -// The return value does not include SDL_INIT_NOPARACHUTE. +// was_init returns a mask of the specified subsystems which have +// previously been initialized. // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_Init -// See also: SDL_InitSubSystem +// If `flags` is 0, it returns a mask of all initialized subsystems. pub fn was_init(flags u32) u32 { return C.SDL_WasInit(flags) } fn C.SDL_Quit() -// quit cleans up all initialized subsystems. -// -// You should call this function even if you have already shutdown each -// initialized subsystem with SDL_QuitSubSystem(). It is safe to call this -// function even in the case of errors in initialization. -// -// If you start a subsystem using a call to that subsystem's init function -// (for example SDL_VideoInit()) instead of SDL_Init() or SDL_InitSubSystem(), -// then you must use that subsystem's quit function (SDL_VideoQuit()) to shut -// it down before calling SDL_Quit(). But generally, you should not be using -// those functions directly anyhow; use SDL_Init() instead. -// -// You can use this function with atexit() to ensure that it is run when your -// application is shutdown, but it is not wise to do this from a library or -// other dynamically loaded code. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_Init -// See also: SDL_QuitSubSystem +// quit cleans up all initialized subsystems. You should +// call it upon all exit conditions. pub fn quit() { C.SDL_Quit() } diff --git a/sensor.c.v b/sensor.c.v deleted file mode 100644 index 93a04079..00000000 --- a/sensor.c.v +++ /dev/null @@ -1,311 +0,0 @@ -// Copyright(C) 2021 Lars Pontoppidan. All rights reserved. -// Use of this source code is governed by an MIT license -// that can be found in the LICENSE file. -module sdl - -// -// SDL_sensor.h -// - -// In order to use these functions, SDL_Init() must have been called -// with the ::SDL_INIT_SENSOR flag. This causes SDL to scan the system -// for sensors, and load appropriate drivers. -// -// Sensor is C.SDL_Sensor -@[typedef] -pub struct C.SDL_Sensor { -} - -pub type Sensor = C.SDL_Sensor - -// This is a unique ID for a sensor for the time it is connected to the system, -// and is never reused for the lifetime of the application. -// -// The ID value starts at 0 and increments from there. The value -1 is an invalid ID. -// `typedef Sint32 SDL_SensorID;` -pub type SensorID = int - -// SensorType is C.SDL_SensorType -pub enum SensorType { - invalid = C.SDL_SENSOR_INVALID // -1, Returned for an invalid sensor - unknown = C.SDL_SENSOR_UNKNOWN // Unknown sensor type - accel = C.SDL_SENSOR_ACCEL // Accelerometer - gyro = C.SDL_SENSOR_GYRO // Gyroscope - sensor_accel_l = C.SDL_SENSOR_ACCEL_L // Accelerometer for left Joy-Con controller and Wii nunchuk - sensor_gyro_l = C.SDL_SENSOR_GYRO_L // Gyroscope for left Joy-Con controller - sensor_accel_r = C.SDL_SENSOR_ACCEL_R // Accelerometer for right Joy-Con controller - sensor_gyro_r = C.SDL_SENSOR_GYRO_R // Gyroscope for right Joy-Con controller -} - -// Accelerometer sensor -// -// The accelerometer returns the current acceleration in SI meters per -// second squared. This measurement includes the force of gravity, so -// a device at rest will have an value of SDL_STANDARD_GRAVITY away -// from the center of the earth, which is a positive Y value. -// -// values[0]: Acceleration on the x axis -// values[1]: Acceleration on the y axis -// values[2]: Acceleration on the z axis -// -// For phones held in portrait mode and game controllers held in front of you, -// the axes are defined as follows: -// -X ... +X : left ... right -// -Y ... +Y : bottom ... top -// -Z ... +Z : farther ... closer -// -// The axis data is not changed when the phone is rotated. -// -// See also: SDL_GetDisplayOrientation() -const standard_gravity = C.SDL_STANDARD_GRAVITY - -// 9.80665f - -// Gyroscope sensor -// -// The gyroscope returns the current rate of rotation in radians per second. -// The rotation is positive in the counter-clockwise direction. That is, -// an observer looking from a positive location on one of the axes would -// see positive rotation on that axis when it appeared to be rotating -// counter-clockwise. -// -// values[0]: Angular speed around the x axis (pitch) -// values[1]: Angular speed around the y axis (yaw) -// values[2]: Angular speed around the z axis (roll) -// -// For phones held in portrait mode and game controllers held in front of you, -// the axes are defined as follows: -// -X ... +X : left ... right -// -Y ... +Y : bottom ... top -// -Z ... +Z : farther ... closer -// -// The axis data is not changed when the phone or controller is rotated. -// -// See also: SDL_GetDisplayOrientation() - -fn C.SDL_LockSensors() - -// lock_sensors provides locking for multi-threaded access to the sensor API -// -// If you are using the sensor API or handling events from multiple threads -// you should use these locking functions to protect access to the sensors. -// -// In particular, you are guaranteed that the sensor list won't change, so the -// API functions that take a sensor index will be valid, and sensor events -// will not be delivered. -// -// NOTE This function is available since SDL 2.0.14. -pub fn lock_sensors() { - C.SDL_LockSensors() -} - -fn C.SDL_UnlockSensors() - -// unlock_sensors provides unlocking for multi-threaded access to the sensor API -// -// If you are using the sensor API or handling events from multiple threads -// you should use these locking functions to protect access to the sensors. -// -// In particular, you are guaranteed that the sensor list won't change, so the -// API functions that take a sensor index will be valid, and sensor events -// will not be delivered. -// -// NOTE This function is available since SDL 2.0.14. -pub fn unlock_sensors() { - C.SDL_UnlockSensors() -} - -fn C.SDL_NumSensors() int - -// num_sensors counts the number of sensors attached to the system right now. -// -// returns the number of sensors detected. -// -// NOTE This function is available since SDL 2.0.9. -pub fn num_sensors() int { - return C.SDL_NumSensors() -} - -fn C.SDL_SensorGetDeviceName(device_index int) &char - -// sensor_get_device_name gets the implementation dependent name of a sensor. -// -// `device_index` The sensor to obtain name from -// returns the sensor name, or NULL if `device_index` is out of range. -// -// NOTE This function is available since SDL 2.0.9. -pub fn sensor_get_device_name(device_index int) &char { - return C.SDL_SensorGetDeviceName(device_index) -} - -fn C.SDL_SensorGetDeviceType(device_index int) SensorType - -// sensor_get_device_type gets the type of a sensor. -// -// `device_index` The sensor to get the type from -// returns the SDL_SensorType, or `SDL_SENSOR_INVALID` if `device_index` is -// out of range. -// -// NOTE This function is available since SDL 2.0.9. -pub fn sensor_get_device_type(device_index int) SensorType { - return SensorType(C.SDL_SensorGetDeviceType(device_index)) -} - -fn C.SDL_SensorGetDeviceNonPortableType(device_index int) int - -// sensor_get_device_non_portable_type gets the platform dependent type of a sensor. -// -// `device_index` The sensor to check -// returns the sensor platform dependent type, or -1 if `device_index` is out -// of range. -// -// NOTE This function is available since SDL 2.0.9. -pub fn sensor_get_device_non_portable_type(device_index int) int { - return C.SDL_SensorGetDeviceNonPortableType(device_index) -} - -fn C.SDL_SensorGetDeviceInstanceID(device_index int) SensorID - -// sensor_get_device_instance_id gets the instance ID of a sensor. -// -// `device_index` The sensor to get instance id from -// returns the sensor instance ID, or -1 if `device_index` is out of range. -// -// NOTE This function is available since SDL 2.0.9. -pub fn sensor_get_device_instance_id(device_index int) SensorID { - return SensorID(int(C.SDL_SensorGetDeviceInstanceID(device_index))) -} - -fn C.SDL_SensorOpen(device_index int) &C.SDL_Sensor - -// sensor_open opens a sensor for use. -// -// `device_index` The sensor to open -// returns an SDL_Sensor sensor object, or NULL if an error occurred. -// -// NOTE This function is available since SDL 2.0.9. -pub fn sensor_open(device_index int) &Sensor { - return C.SDL_SensorOpen(device_index) -} - -fn C.SDL_SensorFromInstanceID(instance_id SensorID) &Sensor - -// sensor_from_instance_id returns the SDL_Sensor associated with an instance id. -// -// `instance_id` The sensor from instance id -// returns an SDL_Sensor object. -// -// NOTE This function is available since SDL 2.0.9. -pub fn sensor_from_instance_id(instance_id SensorID) &Sensor { - return C.SDL_SensorFromInstanceID(instance_id) -} - -fn C.SDL_SensorGetName(sensor &C.SDL_Sensor) &char - -// sensor_get_name gets the implementation dependent name of a sensor -// -// `sensor` The SDL_Sensor object -// returns the sensor name, or NULL if `sensor` is NULL. -// -// NOTE This function is available since SDL 2.0.9. -pub fn sensor_get_name(sensor &Sensor) &char { - return C.SDL_SensorGetName(sensor) -} - -fn C.SDL_SensorGetType(sensor &C.SDL_Sensor) SensorType - -// sensor_get_type gets the type of a sensor. -// -// `sensor` The SDL_Sensor object to inspect -// returns the SDL_SensorType type, or `SDL_SENSOR_INVALID` if `sensor` is -// NULL. -// -// NOTE This function is available since SDL 2.0.9. -pub fn sensor_get_type(sensor &Sensor) SensorType { - return SensorType(C.SDL_SensorGetType(sensor)) -} - -fn C.SDL_SensorGetNonPortableType(sensor &C.SDL_Sensor) int - -// sensor_get_non_portable_type gets the platform dependent type of a sensor. -// -// `sensor` The SDL_Sensor object to inspect -// returns the sensor platform dependent type, or -1 if `sensor` is NULL. -// -// NOTE This function is available since SDL 2.0.9. -pub fn sensor_get_non_portable_type(sensor &Sensor) int { - return C.SDL_SensorGetNonPortableType(sensor) -} - -fn C.SDL_SensorGetInstanceID(sensor &C.SDL_Sensor) SensorID - -// sensor_get_instance_id gets the instance ID of a sensor. -// -// `sensor` The SDL_Sensor object to inspect -// returns the sensor instance ID, or -1 if `sensor` is NULL. -// -// NOTE This function is available since SDL 2.0.9. -pub fn sensor_get_instance_id(sensor &Sensor) SensorID { - return SensorID(int(C.SDL_SensorGetInstanceID(sensor))) -} - -fn C.SDL_SensorGetData(sensor &C.SDL_Sensor, data &f32, num_values int) int - -// sensor_get_data gets the current state of an opened sensor. -// -// The number of values and interpretation of the data is sensor dependent. -// -// `sensor` The SDL_Sensor object to query -// `data` A pointer filled with the current sensor state -// `num_values` The number of values to write to data -// returns 0 or -1 if an error occurred. -// -// NOTE This function is available since SDL 2.0.9. -pub fn sensor_get_data(sensor &Sensor, data &f32, num_values int) int { - return C.SDL_SensorGetData(sensor, data, num_values) -} - -fn C.SDL_SensorGetDataWithTimestamp(sensor &C.SDL_Sensor, timestamp &u64, data &f32, num_values int) int - -// sensor_get_data_with_timestamp gets the current state of an opened sensor with the timestamp of the last -// update. -// -// The number of values and interpretation of the data is sensor dependent. -// -// `sensor` The SDL_Sensor object to query -// `timestamp` A pointer filled with the timestamp in microseconds of the -// current sensor reading if available, or 0 if not -// `data` A pointer filled with the current sensor state -// `num_values` The number of values to write to data -// returns 0 or -1 if an error occurred. -// -// NOTE This function is available since SDL 2.26.0. -pub fn sensor_get_data_with_timestamp(sensor &Sensor, timestamp &u64, data &f32, num_values int) int { - return C.SDL_SensorGetDataWithTimestamp(sensor, timestamp, data, num_values) -} - -fn C.SDL_SensorClose(sensor &C.SDL_Sensor) - -// sensor_close closes a sensor previously opened with SDL_SensorOpen(). -// -// `sensor` The SDL_Sensor object to close -// -// NOTE This function is available since SDL 2.0.9. -pub fn sensor_close(sensor &Sensor) { - C.SDL_SensorClose(sensor) -} - -fn C.SDL_SensorUpdate() - -// sensor_update updates the current state of the open sensors. -// -// This is called automatically by the event loop if sensor events are -// enabled. -// -// This needs to be called from the thread that initialized the sensor -// subsystem. -// -// NOTE This function is available since SDL 2.0.9. -pub fn sensor_update() { - C.SDL_SensorUpdate() -} diff --git a/shape.c.v b/shape.c.v index b25eadc3..47cf7844 100644 --- a/shape.c.v +++ b/shape.c.v @@ -15,27 +15,24 @@ pub const window_lacks_shape = C.SDL_WINDOW_LACKS_SHAPE // -3 fn C.SDL_CreateShapedWindow(title &char, x u32, y u32, w u32, h u32, flags u32) &C.SDL_Window -// create_shaped_window creates a window that can be shaped with the specified position, dimensions, -// and flags. +// create_shaped_window creates a window that can be shaped with the specified position, dimensions, and flags. // // `title` The title of the window, in UTF-8 encoding. -// `x` The x position of the window, ::SDL_WINDOWPOS_CENTERED, or -// ::SDL_WINDOWPOS_UNDEFINED. -// `y` The y position of the window, ::SDL_WINDOWPOS_CENTERED, or -// ::SDL_WINDOWPOS_UNDEFINED. -// `w` The width of the window. -// `h` The height of the window. -// `flags` The flags for the window, a mask of SDL_WINDOW_BORDERLESS with -// any of the following: ::SDL_WINDOW_OPENGL, -// ::SDL_WINDOW_INPUT_GRABBED, ::SDL_WINDOW_HIDDEN, -// ::SDL_WINDOW_RESIZABLE, ::SDL_WINDOW_MAXIMIZED, -// ::SDL_WINDOW_MINIMIZED, ::SDL_WINDOW_BORDERLESS is always set, -// and ::SDL_WINDOW_FULLSCREEN is always unset. -// returns the window created, or NULL if window creation failed. +// `x` The x position of the window, ::SDL_WINDOWPOS_CENTERED, or +// ::SDL_WINDOWPOS_UNDEFINED. +// `y` The y position of the window, ::SDL_WINDOWPOS_CENTERED, or +// ::SDL_WINDOWPOS_UNDEFINED. +// `w` The width of the window. +// `h` The height of the window. +// `flags` The flags for the window, a mask of SDL_WINDOW_BORDERLESS with any of the following: +// ::SDL_WINDOW_OPENGL, ::SDL_WINDOW_INPUT_GRABBED, +// ::SDL_WINDOW_HIDDEN, ::SDL_WINDOW_RESIZABLE, +// ::SDL_WINDOW_MAXIMIZED, ::SDL_WINDOW_MINIMIZED, +// ::SDL_WINDOW_BORDERLESS is always set, and ::SDL_WINDOW_FULLSCREEN is always unset. // -// NOTE This function is available since SDL 2.0.0. +// returns The window created, or NULL if window creation failed. // -// See also: SDL_DestroyWindow +// See also: SDL_DestroyWindow() pub fn create_shaped_window(title &char, x u32, y u32, w u32, h u32, flags u32) &Window { return C.SDL_CreateShapedWindow(title, x, y, w, h, flags) } @@ -45,10 +42,8 @@ fn C.SDL_IsShapedWindow(window &C.SDL_Window) bool // is_shaped_window returns whether the given window is a shaped window. // // `window` The window to query for being shaped. -// returns SDL_TRUE if the window is a window that can be shaped, SDL_FALSE if -// the window is unshaped or NULL. // -// NOTE This function is available since SDL 2.0.0. +// returns SDL_TRUE if the window is a window that can be shaped, SDL_FALSE if the window is unshaped or NULL. // // See also: SDL_CreateShapedWindow pub fn is_shaped_window(window &Window) bool { @@ -99,14 +94,12 @@ fn C.SDL_SetWindowShape(window &C.SDL_Window, shape &C.SDL_Surface, shape_mode & // `window` The shaped window whose parameters should be set. // `shape` A surface encoding the desired shape for the window. // `shape_mode` The parameters to set for the shaped window. -// returns 0 on success, SDL_INVALID_SHAPE_ARGUMENT on an invalid shape -// argument, or SDL_NONSHAPEABLE_WINDOW if the SDL_Window given does -// not reference a valid shaped window. // -// NOTE This function is available since SDL 2.0.0. +// returns 0 on success, SDL_INVALID_SHAPE_ARGUMENT on an invalid shape argument, or SDL_NONSHAPEABLE_WINDOW +// if the SDL_Window given does not reference a valid shaped window. // // See also: SDL_WindowShapeMode -// See also: SDL_GetShapedWindowMode +// See also: SDL_GetShapedWindowMode. pub fn set_window_shape(window &Window, shape &Surface, shape_mode &WindowShapeMode) int { return C.SDL_SetWindowShape(window, shape, shape_mode) } @@ -116,15 +109,11 @@ fn C.SDL_GetShapedWindowMode(window &C.SDL_Window, shape_mode &C.SDL_WindowShape // get_shaped_window_mode gets the shape parameters of a shaped window. // // `window` The shaped window whose parameters should be retrieved. -// `shape_mode` An empty shape-mode structure to fill, or NULL to check -// whether the window has a shape. -// returns 0 if the window has a shape and, provided shape_mode was not NULL, -// shape_mode has been filled with the mode data, -// SDL_NONSHAPEABLE_WINDOW if the SDL_Window given is not a shaped -// window, or SDL_WINDOW_LACKS_SHAPE if the SDL_Window given is a -// shapeable window currently lacking a shape. +// `shape_mode` An empty shape-mode structure to fill, or NULL to check whether the window has a shape. // -// NOTE This function is available since SDL 2.0.0. +// returns 0 if the window has a shape and, provided shape_mode was not NULL, shape_mode has been filled with the mode +// data, SDL_NONSHAPEABLE_WINDOW if the SDL_Window given is not a shaped window, or SDL_WINDOW_LACKS_SHAPE if +// the SDL_Window given is a shapeable window currently lacking a shape. // // See also: SDL_WindowShapeMode // See also: SDL_SetWindowShape diff --git a/stdinc.c.v b/stdinc.c.v index a2f46ff7..2e534504 100644 --- a/stdinc.c.v +++ b/stdinc.c.v @@ -18,7 +18,7 @@ pub const min_sint8 = C.SDL_MIN_SINT8 // -128 // An unsigned 8-bit integer type. // typedef uint8_t Uint8; -// u8 +// byte pub const max_uint8 = C.SDL_MAX_UINT8 // 255 pub const min_uint8 = C.SDL_MIN_UINT8 // 0 @@ -65,9 +65,6 @@ pub const max_uint64 = C.SDL_MAX_UINT64 // 18446744073709551615 pub const min_uint64 = C.SDL_MIN_UINT64 // 0 -// Floating-point constants -const flt_epsilon = C.SDL_FLT_EPSILON - /* // bool pub enum C.SDL_bool { @@ -112,20 +109,9 @@ pub type CallocFunc = C.SDL_calloc_func // fn(nmemb usize, size usize) voidptr pub type ReallocFunc = C.SDL_realloc_func // fn(mem voidptr, size usize) voidptr pub type FreeFunc = C.SDL_free_func //fn(mem voidptr) -fn C.SDL_GetOriginalMemoryFunctions(malloc_func &C.SDL_malloc_func, calloc_func &C.SDL_calloc_func, realloc_func &C.SDL_realloc_func, free_func &C.SDL_free_func) - -// get_original_memory_functions gets the original set of SDL memory functions -// -// NOTE This function is available since SDL 2.24.0. -pub fn get_original_memory_functions(malloc_func &C.SDL_malloc_func, calloc_func &C.SDL_calloc_func, realloc_func &C.SDL_realloc_func, free_func &C.SDL_free_func){ - C.SDL_GetOriginalMemoryFunctions(malloc_func, calloc_func, realloc_func, free_func) -} - fn C.SDL_GetMemoryFunctions(malloc_func &C.SDL_malloc_func, calloc_func &C.SDL_calloc_func, realloc_func &C.SDL_realloc_func, free_func &C.SDL_free_func) // get_memory_functions gets the current set of SDL memory functions -// -// NOTE This function is available since SDL 2.0.7. pub fn get_memory_functions(malloc_func &MallocFunc, calloc_func &CallocFunc, realloc_func &ReallocFunc, free_func &FreeFunc){ C.SDL_GetMemoryFunctions(malloc_func, calloc_func, realloc_func, free_func) } @@ -138,8 +124,6 @@ fn C.SDL_SetMemoryFunctions(malloc_func C.SDL_malloc_func, calloc_func C.SDL_cal // SDL_GetNumAllocations() and be very careful if it returns non-zero. // That means that your free function will be called with memory // allocated by the previous memory allocation functions. -// -// NOTE This function is available since SDL 2.0.7. pub fn set_memory_functions(malloc_func MallocFunc, calloc_func CallocFunc, realloc_func ReallocFunc, free_func FreeFunc) int{ return C.SDL_SetMemoryFunctions(malloc_func, calloc_func, realloc_func, free_func) } @@ -148,8 +132,6 @@ pub fn set_memory_functions(malloc_func MallocFunc, calloc_func CallocFunc, real fn C.SDL_GetNumAllocations() int // get_num_allocations gets the number of outstanding (unfreed) allocations -// -// NOTE This function is available since SDL 2.0.7. pub fn get_num_allocations() int { return C.SDL_GetNumAllocations() } @@ -172,78 +154,21 @@ pub fn qsort(base voidptr, nmemb usize, size usize, compare QSortCompare) { C.SDL_qsort(base, nmemb, size, compare) } -fn C.SDL_bsearch(const_key voidptr, const_base voidptr, nmemb usize, size usize, compare fn (voidptr, voidptr)) voidptr - -// bsearch gets the number of outstanding (unfreed) allocations -pub fn bsearch(const_key voidptr, const_base voidptr, nmemb usize, size usize, compare fn (voidptr, voidptr)) voidptr { - return C.SDL_bsearch(const_key, const_base, nmemb, size, compare) -} - fn C.SDL_abs(x int) int pub fn abs(x int) int { return C.SDL_abs(x) } -fn C.SDL_isalpha(x int) int -pub fn isalpha(x int) int { - return C.SDL_isalpha(x) -} - -fn C.SDL_isalnum(x int) int -pub fn isalnum(x int) int { - return C.SDL_isalnum(x) -} - -fn C.SDL_isblank(x int) int -pub fn isblank(x int) int { - return C.SDL_isblank(x) -} - -fn C.SDL_iscntrl(x int) int -pub fn iscntrl(x int) int { - return C.SDL_iscntrl(x) -} - fn C.SDL_isdigit(x int) int pub fn isdigit(x int) int { return C.SDL_isdigit(x) } -fn C.SDL_isxdigit(x int) int -pub fn isxdigit(x int) int { - return C.SDL_isxdigit(x) -} - -fn C.SDL_ispunct(x int) int -pub fn ispunct(x int) int { - return C.SDL_ispunct(x) -} - fn C.SDL_isspace(x int) int pub fn isspace(x int) int { return C.SDL_isspace(x) } -fn C.SDL_isupper(x int) int -pub fn isupper(x int) int { - return C.SDL_isupper(x) -} - -fn C.SDL_islower(x int) int -pub fn islower(x int) int { - return C.SDL_islower(x) -} - -fn C.SDL_isprint(x int) int -pub fn isprint(x int) int { - return C.SDL_isprint(x) -} - -fn C.SDL_isgraph(x int) int -pub fn isgraph(x int) int { - return C.SDL_isgraph(x) -} - fn C.SDL_toupper(x int) int pub fn toupper(x int) int { return C.SDL_toupper(x) @@ -254,16 +179,6 @@ pub fn tolower(x int) int { return C.SDL_tolower(x) } -fn C.SDL_crc16(crc u16, const_data voidptr, len usize) u16 -pub fn crc16(crc u16, const_data voidptr, len usize) u16 { - return C.SDL_crc16(crc, const_data, len) -} - -fn C.SDL_crc32(crc u32, const_data voidptr, len usize) u32 -pub fn crc32(crc u32, const_data voidptr, len usize) u32 { - return C.SDL_crc32(crc, const_data, len) -} - /* // TODO // extern DECLSPEC void *SDLCALL SDL_memset(SDL_OUT_BYTECAP(len) void *dst, int c, size_t len) @@ -297,12 +212,6 @@ pub fn memcmp(const_s1 voidptr, const_s2 voidptr, len usize) int { } /* -// extern DECLSPEC wchar_t *SDLCALL SDL_wcsdup(const wchar_t *wstr) -fn C.SDL_wcsdup(wstr &C.wchar_t) &C.wchar_t -pub fn wcsdup(wstr &C.wchar_t) &C.wchar_t{ - return C.SDL_wcsdup(wstr) -} - // extern DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t *wstr) fn C.SDL_wcslen(wstr &C.wchar_t) usize pub fn wcslen(wstr &C.wchar_t) usize{ @@ -321,41 +230,11 @@ pub fn wcslcat(dst &C.SDL_INOUT_Z_CAP(maxlen) wchar_t, src &C.wchar_t, maxlen us return C.SDL_wcslcat(dst, src, maxlen) } -// extern DECLSPEC wchar_t *SDLCALL SDL_wcsdup(const wchar_t *wstr) -fn C.SDL_wcsdup(wstr &C.wchar_t) &C.wchar_t -pub fn wcsdup(wstr &C.wchar_t) &C.wchar_t{ - return C.SDL_wcsdup(wstr) -} - -// extern DECLSPEC wchar_t *SDLCALL SDL_wcsstr(const wchar_t *haystack, const wchar_t *needle) -fn C.SDL_wcsstr(haystack &C.wchar_t, needle &C.wchar_t) &C.wchar_t -pub fn wcsstr(haystack &C.wchar_t, needle &C.wchar_t) &C.wchar_t{ - return C.SDL_wcsstr(haystack, needle) -} - // extern DECLSPEC int SDLCALL SDL_wcscmp(const wchar_t *str1, const wchar_t *str2) fn C.SDL_wcscmp(str1 &C.wchar_t, str2 &C.wchar_t) int pub fn wcscmp(str1 &C.wchar_t, str2 &C.wchar_t) int{ return C.SDL_wcscmp(str1, str2) } - -// extern DECLSPEC int SDLCALL SDL_wcsncmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen) -fn C.SDL_wcsncmp(str1 &C.wchar_t, str2 &C.wchar_t, maxlen usize) int -pub fn wcsncmp(str1 &C.wchar_t, str2 &C.wchar_t, maxlen usize) int{ - return C.SDL_wcsncmp(str1, str2, maxlen) -} - -extern DECLSPEC int SDLCALL SDL_wcscasecmp(const wchar_t *str1, const wchar_t *str2) -fn C.SDL_wcscasecmp(str1 &C.wchar_t, str2 &C.wchar_t) int -pub fn wcscasecmp(str1 &C.wchar_t, str2 &C.wchar_t) int{ - return C.SDL_wcscasecmp(str1, str2) -} - -extern DECLSPEC int SDLCALL SDL_wcsncasecmp(const wchar_t *str1, const wchar_t *str2, size_t len) -fn C.SDL_wcsncasecmp(str1 &C.wchar_t, str2 &C.wchar_t, len usize) int -pub fn wcsncasecmp(str1 &C.wchar_t, str2 &C.wchar_t, len usize) int{ - return C.SDL_wcsncasecmp(str1, str2, len) -} */ fn C.SDL_strlen(str &char) usize @@ -419,26 +298,11 @@ pub fn strstr(const_haystack &char, const_needle &char) &char { return C.SDL_strstr(const_haystack, const_needle) } -fn C.SDL_strcasestr(const_haystack &char, const_needle &char) &char -pub fn strcasestr(const_haystack &char, const_needle &char) &char { - return C.SDL_strcasestr(const_haystack, const_needle) -} - -fn C.SDL_strtokr(s1 &char, const_s2 &char, saveptr &&char) &char -pub fn strtokr(s1 &char, const_s2 &char, saveptr &&char) &char { - return C.SDL_strtokr(s1, const_s2, saveptr) -} - fn C.SDL_utf8strlen(str &char) usize pub fn utf8strlen(str &char) usize { return C.SDL_utf8strlen(str) } -fn C.SDL_utf8strnlen(const_str &char, bytes usize) usize -pub fn utf8strnlen(const_str &char, bytes usize) usize { - return C.SDL_utf8strnlen(const_str, bytes) -} - fn C.SDL_itoa(value int, str &char, radix int) &char pub fn itoa(value int, str &char, radix int) &char { return C.SDL_itoa(value, str, radix) @@ -551,19 +415,6 @@ pub fn vsnprintf(text &C.SDL_OUT_Z_CAP(maxlen) char, maxlen usize, fmt &char, ap pub const m_pi = C.M_PI // 3.14159265358979323846264338327950288 // pi fn C.SDL_acos(x f64) f64 - -// acos computes arc cosine of `x`. -// -// The definition of `y = acos(x)` is `x = cos(y)`. -// -// Domain: `-1 <= x <= 1` -// -// Range: `0 <= y <= Pi` -// -// `x` floating point value, in radians. -// returns arc cosine of `x`. -// -// NOTE This function is available since SDL 2.0.2. pub fn acos(x f64) f64 { return C.SDL_acos(x) } @@ -593,14 +444,14 @@ pub fn atanf(x f32) f32 { return C.SDL_atanf(x) } -fn C.SDL_atan2(y f64, x f64) f64 -pub fn atan2(y f64, x f64) f64 { - return C.SDL_atan2(y, x) +fn C.SDL_atan2(x f64, y f64) f64 +pub fn atan2(x f64, y f64) f64 { + return C.SDL_atan2(x, y) } -fn C.SDL_atan2f(y f32, x f32) f32 -pub fn atan2f(y f32, x f32) f32 { - return C.SDL_atan2f(y, x) +fn C.SDL_atan2f(x f32, y f32) f32 +pub fn atan2f(x f32, y f32) f32 { + return C.SDL_atan2f(x, y) } fn C.SDL_ceil(x f64) f64 @@ -633,16 +484,6 @@ pub fn cosf(x f32) f32 { return C.SDL_cosf(x) } -fn C.SDL_exp(x f64) f64 -pub fn exp(x f64) f64 { - return C.SDL_exp(x) -} - -fn C.SDL_expf(x f32) f32 -pub fn expf(x f32) f32 { - return C.SDL_expf(x) -} - fn C.SDL_fabs(x f64) f64 pub fn fabs(x f64) f64 { return C.SDL_fabs(x) @@ -663,16 +504,6 @@ pub fn floorf(x f32) f32 { return C.SDL_floorf(x) } -fn C.SDL_trunc(x f64) f64 -pub fn trunc(x f64) f64 { - return C.SDL_trunc(x) -} - -fn C.SDL_truncf(x f32) f32 -pub fn truncf(x f32) f32 { - return C.SDL_truncf(x) -} - fn C.SDL_fmod(x f64, y f64) f64 pub fn fmod(x f64, y f64) f64 { return C.SDL_fmod(x, y) @@ -713,26 +544,6 @@ pub fn powf(x f32, y f32) f32 { return C.SDL_powf(x, y) } -fn C.SDL_round(x f64) f64 -pub fn round(x f64) f64 { - return C.SDL_round(x) -} - -fn C.SDL_roundf(x f32) f32 -pub fn roundf(x f32) f32 { - return C.SDL_roundf(x) -} - -fn C.SDL_lround(x f64) int -pub fn lround(x f64) int { - return C.SDL_lround(x) -} - -fn C.SDL_lroundf(x f32) int -pub fn lroundf(x f32) int { - return C.SDL_lroundf(x) -} - fn C.SDL_scalbn(x f64, n int) f64 pub fn scalbn(x f64, n int) f64 { return C.SDL_scalbn(x, n) @@ -807,10 +618,8 @@ pub fn iconv(cd C.SDL_iconv_t, const_inbuf &&char, inbytesleft &usize, outbuf && fn C.SDL_iconv_string(const_tocode &char, const_fromcode &char, const_inbuf &char, inbytesleft usize) &char -// iconv_string converts a buffer or string between encodings in one pass, -// returning a string that must be freed with SDL_free() or NULL on error. -// -// NOTE This function is available since SDL 2.0.0. +// This function converts a string between encodings in one pass, returning a +// string that must be freed with SDL_free() or NULL on error. pub fn iconv_string(const_tocode &char, const_fromcode &char, const_inbuf &char, inbytesleft usize) &char { return C.SDL_iconv_string(const_tocode, const_fromcode, const_inbuf, inbytesleft) } @@ -818,24 +627,3 @@ pub fn iconv_string(const_tocode &char, const_fromcode &char, const_inbuf &char, fn C.SDL_iconv_utf8_locale(inbuf &char) &char fn C.SDL_iconv_utf8_ucs2(inbuf &char) &char fn C.SDL_iconv_utf8_ucs4(inbuf &char) &char -fn C.SDL_iconv_wchar_utf8(inbuf &u16) - -fn C.SDL_size_mul_overflow(a usize, b usize, ret &usize) int - -// If a * b would overflow, return -1. Otherwise store a * b via ret -// and return 0. -// -// NOTE This function is available since SDL 2.24.0. -pub fn size_mul_overflow(a usize, b usize, ret &usize) int { - return C.SDL_size_mul_overflow(a, b, ret) -} - -fn C.SDL_size_add_overflow(a usize, b usize, ret &usize) int - -// If a + b would overflow, return -1. Otherwise store a + b via ret -// and return 0. -// -// NOTE This function is available since SDL 2.24.0. -pub fn size_add_overflow(a usize, b usize, ret &usize) int { - return C.SDL_size_add_overflow(a, b, ret) -} diff --git a/surface.c.v b/surface.c.v index 27aaf323..bec8b3d9 100644 --- a/surface.c.v +++ b/surface.c.v @@ -7,12 +7,6 @@ module sdl // SDL_surface.h // -@[typedef] -struct C.SDL_BlitMap {} - -// BlitMap is an opaque type. -pub type BlitMap = C.SDL_BlitMap - // Surface is a collection of pixels used in software blitting. // // NOTE This structure should be treated as read-only, except for `pixels`, @@ -27,12 +21,11 @@ pub: h int // Read-only pitch int // Read-only // information needed for surfaces requiring locks - locked int // Read-only - // list of BlitMap that hold a reference to this surface - // list_blitmap voidptr // Private + locked int // Read-only + lock_data voidptr // Read-only // clipping information clip_rect C.SDL_Rect // Read-only - // @map &BlitMap // Private + // @map &C.SDL_BlitMap // Private // Reference count -- used when freeing surface refcount int // Read-mostly pub mut: @@ -60,158 +53,43 @@ pub enum YUVConversionMode { fn C.SDL_CreateRGBSurface(flags u32, width int, height int, depth int, rmask u32, gmask u32, bmask u32, amask u32) &C.SDL_Surface -// create_rgb_surface allocates a new RGB surface. -// -// If `depth` is 4 or 8 bits, an empty palette is allocated for the surface. -// If `depth` is greater than 8 bits, the pixel format is set using the -// [RGBA]mask parameters. -// -// The [RGBA]mask parameters are the bitmasks used to extract that color from -// a pixel. For instance, `Rmask` being 0xFF000000 means the red data is -// stored in the most significant byte. Using zeros for the RGB masks sets a -// default value, based on the depth. For example: -// -/* -```c++ - SDL_CreateRGBSurface(0,w,h,32,0,0,0,0); -``` -*/ +// create_rgb_surface allocates and frees an RGB surface. // -// However, using zero for the Amask results in an Amask of 0. +// If the depth is 4 or 8 bits, an empty palette is allocated for the surface. +// If the depth is greater than 8 bits, the pixel format is set using the +// flags '[RGB]mask'. // -// By default surfaces with an alpha mask are set up for blending as with: +// If the function runs out of memory, it will return NULL. // -/* -```c++ - SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_BLEND) -``` -*/ -// -// You can change this by calling SDL_SetSurfaceBlendMode() and selecting a -// different `blendMode`. -// -// `flags` the flags are unused and should be set to 0 -// `width` the width of the surface -// `height` the height of the surface -// `depth` the depth of the surface in bits -// `Rmask` the red mask for the pixels -// `Gmask` the green mask for the pixels -// `Bmask` the blue mask for the pixels -// `Amask` the alpha mask for the pixels -// returns the new SDL_Surface structure that is created or NULL if it fails; -// call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_CreateRGBSurfaceFrom -// See also: SDL_CreateRGBSurfaceWithFormat -// See also: SDL_FreeSurface +// `flags` The `flags` are obsolete and should be set to 0. +// `width` The width in pixels of the surface to create. +// `height` The height in pixels of the surface to create. +// `depth` The depth in bits of the surface to create. +// `Rmask` The red mask of the surface to create. +// `Gmask` The green mask of the surface to create. +// `Bmask` The blue mask of the surface to create. +// `Amask` The alpha mask of the surface to create. pub fn create_rgb_surface(flags u32, width int, height int, depth int, rmask u32, gmask u32, bmask u32, amask u32) &Surface { return C.SDL_CreateRGBSurface(flags, width, height, depth, rmask, gmask, bmask, amask) } fn C.SDL_CreateRGBSurfaceWithFormat(flags u32, width int, height int, depth int, format u32) &C.SDL_Surface - -// create_rgb_surface_with_format allocates a new RGB surface with a specific pixel format. -// -// This function operates mostly like SDL_CreateRGBSurface(), except instead -// of providing pixel color masks, you provide it with a predefined format -// from SDL_PixelFormatEnum. -// -// `flags` the flags are unused and should be set to 0 -// `width` the width of the surface -// `height` the height of the surface -// `depth` the depth of the surface in bits -// `format` the SDL_PixelFormatEnum for the new surface's pixel format. -// returns the new SDL_Surface structure that is created or NULL if it fails; -// call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.5. -// -// See also: SDL_CreateRGBSurface -// See also: SDL_CreateRGBSurfaceFrom -// See also: SDL_FreeSurface pub fn create_rgb_surface_with_format(flags u32, width int, height int, depth int, format u32) &Surface { return C.SDL_CreateRGBSurfaceWithFormat(flags, width, height, depth, format) } fn C.SDL_CreateRGBSurfaceFrom(pixels voidptr, width int, height int, depth int, pitch int, rmask u32, gmask u32, bmask u32, amask u32) &C.SDL_Surface - -// create_rgb_surface_from allocates a new RGB surface with existing pixel data. -// -// This function operates mostly like SDL_CreateRGBSurface(), except it does -// not allocate memory for the pixel data, instead the caller provides an -// existing buffer of data for the surface to use. -// -// No copy is made of the pixel data. Pixel data is not managed automatically; -// you must free the surface before you free the pixel data. -// -// `pixels` a pointer to existing pixel data -// `width` the width of the surface -// `height` the height of the surface -// `depth` the depth of the surface in bits -// `pitch` the pitch of the surface in bytes -// `Rmask` the red mask for the pixels -// `Gmask` the green mask for the pixels -// `Bmask` the blue mask for the pixels -// `Amask` the alpha mask for the pixels -// returns the new SDL_Surface structure that is created or NULL if it fails; -// call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_CreateRGBSurface -// See also: SDL_CreateRGBSurfaceWithFormat -// See also: SDL_FreeSurface pub fn create_rgb_surface_from(pixels voidptr, width int, height int, depth int, pitch int, rmask u32, gmask u32, bmask u32, amask u32) &Surface { return C.SDL_CreateRGBSurfaceFrom(pixels, width, height, depth, pitch, rmask, gmask, bmask, amask) } fn C.SDL_CreateRGBSurfaceWithFormatFrom(pixels voidptr, width int, height int, depth int, pitch int, format u32) &C.SDL_Surface - -// create_rgb_surface_with_format_from allocates a new RGB surface with with a specific pixel format and existing -// pixel data. -// -// This function operates mostly like SDL_CreateRGBSurfaceFrom(), except -// instead of providing pixel color masks, you provide it with a predefined -// format from SDL_PixelFormatEnum. -// -// No copy is made of the pixel data. Pixel data is not managed automatically; -// you must free the surface before you free the pixel data. -// -// `pixels` a pointer to existing pixel data -// `width` the width of the surface -// `height` the height of the surface -// `depth` the depth of the surface in bits -// `pitch` the pitch of the surface in bytes -// `format` the SDL_PixelFormatEnum for the new surface's pixel format. -// returns the new SDL_Surface structure that is created or NULL if it fails; -// call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.5. -// -// See also: SDL_CreateRGBSurfaceFrom -// See also: SDL_CreateRGBSurfaceWithFormat -// See also: SDL_FreeSurface pub fn create_rgb_surface_with_format_from(pixels voidptr, width int, height int, depth int, pitch int, format u32) &Surface { return C.SDL_CreateRGBSurfaceWithFormatFrom(pixels, width, height, depth, pitch, format) } fn C.SDL_FreeSurface(surface &C.SDL_Surface) - -// free_surface frees an RGB surface. -// -// It is safe to pass NULL to this function. -// -// `surface` the SDL_Surface to free. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_CreateRGBSurface -// See also: SDL_CreateRGBSurfaceFrom -// See also: SDL_LoadBMP -// See also: SDL_LoadBMP_RW pub fn free_surface(surface &Surface) { C.SDL_FreeSurface(surface) } @@ -220,14 +98,9 @@ fn C.SDL_SetSurfacePalette(surface &C.SDL_Surface, palette &C.SDL_Palette) int // set_surface_palette sets the palette used by a surface. // -// A single palette can be shared with many surfaces. -// -// `surface` the SDL_Surface structure to update -// `palette` the SDL_Palette structure to use -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. +// returns 0, or -1 if the surface format doesn't use a palette. // -// NOTE This function is available since SDL 2.0.0. +// NOTE A single palette can be shared with many surfaces. pub fn set_surface_palette(surface &Surface, palette &Palette) int { return C.SDL_SetSurfacePalette(surface, palette) } @@ -236,62 +109,39 @@ fn C.SDL_LockSurface(surface &C.SDL_Surface) int // lock_surface sets up a surface for directly accessing the pixels. // -// Between calls to SDL_LockSurface() / SDL_UnlockSurface(), you can write to -// and read from `surface->pixels`, using the pixel format stored in -// `surface->format`. Once you are done accessing the surface, you should use -// SDL_UnlockSurface() to release it. +// Between calls to SDL_LockSurface() / SDL_UnlockSurface(), you can write +// to and read from `surface->pixels`, using the pixel format stored in +// `surface->format`. Once you are done accessing the surface, you should +// use SDL_UnlockSurface() to release it. // -// Not all surfaces require locking. If `SDL_MUSTLOCK(surface)` evaluates to -// 0, then you can read and write to the surface at any time, and the pixel -// format of the surface will not change. +// Not all surfaces require locking. If SDL_MUSTLOCK(surface) evaluates +// to 0, then you can read and write to the surface at any time, and the +// pixel format of the surface will not change. // -// `surface` the SDL_Surface structure to be locked -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. +// No operating system or library calls should be made between lock/unlock +// pairs, as critical system locks may be held during this time. // -// NOTE This function is available since SDL 2.0.0. +// SDL_LockSurface() returns 0, or -1 if the surface couldn't be locked. // -// See also: SDL_MUSTLOCK -// See also: SDL_UnlockSurface +// See also: SDL_UnlockSurface() pub fn lock_surface(surface &Surface) int { return C.SDL_LockSurface(surface) } fn C.SDL_UnlockSurface(surface &C.SDL_Surface) - -// unlock_surface releases a surface after directly accessing the pixels. -// -// `surface` the SDL_Surface structure to be unlocked -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_LockSurface pub fn unlock_surface(surface &Surface) { C.SDL_UnlockSurface(surface) } fn C.SDL_LoadBMP_RW(src &C.SDL_RWops, freesrc int) &C.SDL_Surface -// load_bmp_rw loads a BMP image from a seekable SDL data stream. +// load_bmp_rw loads a surface from a seekable SDL data stream (memory or file). // -// The new surface should be freed with SDL_FreeSurface(). Not doing so will -// result in a memory leak. +// If `freesrc` is non-zero, the stream will be closed after being read. // -// src is an open SDL_RWops buffer, typically loaded with SDL_RWFromFile. -// Alternitavely, you might also use the macro SDL_LoadBMP to load a bitmap -// from a file, convert it to an SDL_Surface and then close the file. +// The new surface should be freed with SDL_FreeSurface(). // -// `src` the data stream for the surface -// `freesrc` non-zero to close the stream after being read -// returns a pointer to a new SDL_Surface structure or NULL if there was an -// error; call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_FreeSurface -// See also: SDL_RWFromFile -// See also: SDL_LoadBMP -// See also: SDL_SaveBMP_RW +// returns the new surface, or NULL if there was an error. pub fn load_bmp_rw(src &RWops, freesrc int) &Surface { return C.SDL_LoadBMP_RW(src, freesrc) } @@ -307,7 +157,7 @@ pub fn load_bmp(path &char) &Surface { fn C.SDL_SaveBMP_RW(surface &C.SDL_Surface, dst &C.SDL_RWops, freedst int) int -// save_bmp_rw saves a surface to a seekable SDL data stream in BMP format. +// save_bmp_rw saves a surface to a seekable SDL data stream (memory or file). // // Surfaces with a 24-bit, 32-bit and paletted 8-bit format get saved in the // BMP directly. Other RGB formats with 8-bit or higher get converted to a @@ -315,16 +165,9 @@ fn C.SDL_SaveBMP_RW(surface &C.SDL_Surface, dst &C.SDL_RWops, freedst int) int // surface before they are saved. YUV and paletted 1-bit and 4-bit formats are // not supported. // -// `surface` the SDL_Surface structure containing the image to be saved -// `dst` a data stream to save to -// `freedst` non-zero to close the stream after being written -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. +// If `freedst` is non-zero, the stream will be closed after being written. // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_LoadBMP_RW -// See also: SDL_SaveBMP +// returns 0 if successful or -1 if there was an error. pub fn save_bmp_rw(surface &Surface, dst &RWops, freedst int) int { return C.SDL_SaveBMP_RW(surface, dst, freedst) } @@ -342,146 +185,71 @@ fn C.SDL_SetSurfaceRLE(surface &C.SDL_Surface, flag int) int // set_surface_rle sets the RLE acceleration hint for a surface. // -// If RLE is enabled, color key and alpha blending blits are much faster, but -// the surface must be locked before directly accessing the pixels. -// -// `surface` the SDL_Surface structure to optimize -// `flag` 0 to disable, non-zero to enable RLE acceleration -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. +// returns 0 on success, or -1 if the surface is not valid // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_BlitSurface -// See also: SDL_LockSurface -// See also: SDL_UnlockSurface +// NOTE If RLE is enabled, colorkey and alpha blending blits are much faster, +// but the surface must be locked before directly accessing the pixels. pub fn set_surface_rle(surface &Surface, flag int) int { return C.SDL_SetSurfaceRLE(surface, flag) } -fn C.SDL_HasSurfaceRLE(surface &C.SDL_Surface) bool - -// has_surface_rle returns whether the surface is RLE enabled -// -// It is safe to pass a NULL `surface` here; it will return SDL_FALSE. -// -// `surface` the SDL_Surface structure to query -// returns SDL_TRUE if the surface is RLE enabled, SDL_FALSE otherwise. -// -// NOTE This function is available since SDL 2.0.14. -// -// See also: SDL_SetSurfaceRLE -pub fn has_surface_rle(surface &Surface) bool { - return C.SDL_HasSurfaceRLE(surface) -} - fn C.SDL_SetColorKey(surface &C.SDL_Surface, flag int, key u32) int -// set_color_key sets the color key (transparent pixel) in a surface. +// set_color_key sets the color key (transparent pixel) in a blittable surface. // -// The color key defines a pixel value that will be treated as transparent in -// a blit. For example, one can use this to specify that cyan pixels should be -// considered transparent, and therefore not rendered. +// `surface` The surface to update +// `flag` Non-zero to enable colorkey and 0 to disable colorkey +// `key` The transparent pixel in the native surface format // -// It is a pixel of the format used by the surface, as generated by -// SDL_MapRGB(). +// returns 0 on success, or -1 if the surface is not valid // -// RLE acceleration can substantially speed up blitting of images with large -// horizontal runs of transparent pixels. See SDL_SetSurfaceRLE() for details. -// -// `surface` the SDL_Surface structure to update -// `flag` SDL_TRUE to enable color key, SDL_FALSE to disable color key -// `key` the transparent pixel -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_BlitSurface -// See also: SDL_GetColorKey +// You can pass SDL_RLEACCEL to enable RLE accelerated blits. pub fn set_color_key(surface &Surface, flag int, key u32) int { return C.SDL_SetColorKey(surface, flag, key) } -fn C.SDL_HasColorKey(surface &C.SDL_Surface) bool - -// has_color_key returns whether the surface has a color key -// -// It is safe to pass a NULL `surface` here; it will return SDL_FALSE. -// -// `surface` the SDL_Surface structure to query -// returns SDL_TRUE if the surface has a color key, SDL_FALSE otherwise. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_SetColorKey -// See also: SDL_GetColorKey -pub fn has_color_key(surface &Surface) bool { - return C.SDL_HasColorKey(surface) -} - fn C.SDL_GetColorKey(surface &C.SDL_Surface, key &u32) int -// get_color_key gets the color key (transparent pixel) for a surface. -// -// The color key is a pixel of the format used by the surface, as generated by -// SDL_MapRGB(). +// get_color_key gets the color key (transparent pixel) in a blittable surface. // -// If the surface doesn't have color key enabled this function returns -1. +// `surface` The surface to update +// `key` A pointer filled in with the transparent pixel in the native +// surface format // -// `surface` the SDL_Surface structure to query -// `key` a pointer filled in with the transparent pixel -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_BlitSurface -// See also: SDL_SetColorKey +// returns 0 on success, or -1 if the surface is not valid or colorkey is not +// enabled. pub fn get_color_key(surface &Surface, key &u32) int { return C.SDL_GetColorKey(surface, key) } fn C.SDL_SetSurfaceColorMod(surface &C.SDL_Surface, r u8, g u8, b u8) int -// set_surface_color_mod sets an additional color value multiplied into blit operations. -// -// When this surface is blitted, during the blit operation each source color -// channel is modulated by the appropriate color value according to the -// following formula: -// -// `srcC = srcC * (color / 255)` +// set_surface_color_mod sets an additional color value used in blit operations. // -// `surface` the SDL_Surface structure to update -// `r` the red color value multiplied into blit operations -// `g` the green color value multiplied into blit operations -// `b` the blue color value multiplied into blit operations -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. +// `surface` The surface to update. +// `r` The red color value multiplied into blit operations. +// `g` The green color value multiplied into blit operations. +// `b` The blue color value multiplied into blit operations. // -// NOTE This function is available since SDL 2.0.0. +// returns 0 on success, or -1 if the surface is not valid. // -// See also: SDL_GetSurfaceColorMod -// See also: SDL_SetSurfaceAlphaMod +// See also: SDL_GetSurfaceColorMod() pub fn set_surface_color_mod(surface &Surface, r u8, g u8, b u8) int { return C.SDL_SetSurfaceColorMod(surface, r, g, b) } fn C.SDL_GetSurfaceColorMod(surface &C.SDL_Surface, r &u8, g &u8, b &u8) int -// get_surface_color_mod gets the additional color value multiplied into blit operations. +// get_surface_color_mod gets the additional color value used in blit operations. // -// `surface` the SDL_Surface structure to query -// `r` a pointer filled in with the current red color value -// `g` a pointer filled in with the current green color value -// `b` a pointer filled in with the current blue color value -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. +// `surface` The surface to query. +// `r` A pointer filled in with the current red color value. +// `g` A pointer filled in with the current green color value. +// `b` A pointer filled in with the current blue color value. // -// NOTE This function is available since SDL 2.0.0. +// returns 0 on success, or -1 if the surface is not valid. // -// See also: SDL_GetSurfaceAlphaMod -// See also: SDL_SetSurfaceColorMod +// See also: SDL_SetSurfaceColorMod() pub fn get_surface_color_mod(surface &Surface, r &u8, g &u8, b &u8) int { return C.SDL_GetSurfaceColorMod(surface, r, g, b) } @@ -490,20 +258,12 @@ fn C.SDL_SetSurfaceAlphaMod(surface &C.SDL_Surface, alpha u8) int // set_surface_alpha_mod sets an additional alpha value used in blit operations. // -// When this surface is blitted, during the blit operation the source alpha -// value is modulated by this alpha value according to the following formula: +// `surface` The surface to update. +// `alpha` The alpha value multiplied into blit operations. // -// `srcA = srcA * (alpha / 255)` +// returns 0 on success, or -1 if the surface is not valid. // -// `surface` the SDL_Surface structure to update -// `alpha` the alpha value multiplied into blit operations -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetSurfaceAlphaMod -// See also: SDL_SetSurfaceColorMod +// See also: SDL_GetSurfaceAlphaMod() pub fn set_surface_alpha_mod(surface &Surface, alpha u8) int { return C.SDL_SetSurfaceAlphaMod(surface, alpha) } @@ -512,15 +272,12 @@ fn C.SDL_GetSurfaceAlphaMod(surface &C.SDL_Surface, alpha &u8) int // get_surface_alpha_mod gets the additional alpha value used in blit operations. // -// `surface` the SDL_Surface structure to query -// `alpha` a pointer filled in with the current alpha value -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. +// `surface` The surface to query. +// `alpha` A pointer filled in with the current alpha value. // -// NOTE This function is available since SDL 2.0.0. +// returns 0 on success, or -1 if the surface is not valid. // -// See also: SDL_GetSurfaceColorMod -// See also: SDL_SetSurfaceAlphaMod +// See also: SDL_SetSurfaceAlphaMod() pub fn get_surface_alpha_mod(surface &Surface, alpha &u8) int { return C.SDL_GetSurfaceAlphaMod(surface, alpha) } @@ -529,18 +286,12 @@ fn C.SDL_SetSurfaceBlendMode(surface &C.SDL_Surface, blend_mode C.SDL_BlendMode) // set_surface_blend_mode sets the blend mode used for blit operations. // -// To copy a surface to another surface (or texture) without blending with the -// existing data, the blendmode of the SOURCE surface should be set to -// `SDL_BLENDMODE_NONE`. +// `surface` The surface to update. +// `blendMode` ::SDL_BlendMode to use for blit blending. // -// `surface` the SDL_Surface structure to update -// `blendMode` the SDL_BlendMode to use for blit blending -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. +// returns 0 on success, or -1 if the parameters are not valid. // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetSurfaceBlendMode +// See also: SDL_GetSurfaceBlendMode() pub fn set_surface_blend_mode(surface &Surface, blend_mode BlendMode) int { return C.SDL_SetSurfaceBlendMode(surface, C.SDL_BlendMode(int(blend_mode))) } @@ -549,223 +300,94 @@ fn C.SDL_GetSurfaceBlendMode(surface &C.SDL_Surface, blend_mode &C.SDL_BlendMode // get_surface_blend_mode gets the blend mode used for blit operations. // -// `surface` the SDL_Surface structure to query -// `blendMode` a pointer filled in with the current SDL_BlendMode -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. +// `surface` The surface to query. +// `blendMode` A pointer filled in with the current blend mode. // -// NOTE This function is available since SDL 2.0.0. +// returns 0 on success, or -1 if the surface is not valid. // -// See also: SDL_SetSurfaceBlendMode +// See also: SDL_SetSurfaceBlendMode() pub fn get_surface_blend_mode(surface &Surface, blend_mode &BlendMode) int { return C.SDL_GetSurfaceBlendMode(surface, &C.SDL_BlendMode(int(blend_mode))) } fn C.SDL_SetClipRect(surface &C.SDL_Surface, const_rect &C.SDL_Rect) bool -// set_clip_rect sets the clipping rectangle for a surface. -// -// When `surface` is the destination of a blit, only the area within the clip -// rectangle is drawn into. +// set_clip_rect sets the clipping rectangle for the destination surface in a blit. // -// Note that blits are automatically clipped to the edges of the source and -// destination surfaces. +// If the clip rectangle is NULL, clipping will be disabled. // -// `surface` the SDL_Surface structure to be clipped -// `rect` the SDL_Rect structure representing the clipping rectangle, or -// NULL to disable clipping -// returns SDL_TRUE if the rectangle intersects the surface, otherwise -// SDL_FALSE and blits will be completely clipped. +// If the clip rectangle doesn't intersect the surface, the function will +// return SDL_FALSE and blits will be completely clipped. Otherwise the +// function returns SDL_TRUE and blits to the surface will be clipped to +// the intersection of the surface area and the clipping rectangle. // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_BlitSurface -// See also: SDL_GetClipRect +// Note that blits are automatically clipped to the edges of the source +// and destination surfaces. pub fn set_clip_rect(surface &Surface, const_rect &Rect) bool { return C.SDL_SetClipRect(surface, const_rect) } fn C.SDL_GetClipRect(surface &C.SDL_Surface, rect &C.SDL_Rect) -// get_clip_rect gets the clipping rectangle for a surface. -// -// When `surface` is the destination of a blit, only the area within the clip -// rectangle is drawn into. -// -// `surface` the SDL_Surface structure representing the surface to be -// clipped -// `rect` an SDL_Rect structure filled in with the clipping rectangle for -// the surface -// -// NOTE This function is available since SDL 2.0.0. +// get_clip_rect gets the clipping rectangle for the destination surface in a blit. // -// See also: SDL_BlitSurface -// See also: SDL_SetClipRect +// `rect` must be a pointer to a valid rectangle which will be filled +// with the correct values. pub fn get_clip_rect(surface &Surface, rect &Rect) { C.SDL_GetClipRect(surface, rect) } fn C.SDL_DuplicateSurface(surface &C.SDL_Surface) &C.SDL_Surface -// duplicate_surface creates a new surface identical to the existing surface. -// -// The returned surface should be freed with SDL_FreeSurface(). -// -// `surface` the surface to duplicate. -// returns a copy of the surface, or NULL on failure; call SDL_GetError() for -// more information. +// duplicate_surface creates a new surface identical to the existing surface pub fn duplicate_surface(surface &Surface) &Surface { return C.SDL_DuplicateSurface(surface) } fn C.SDL_ConvertSurface(src &C.SDL_Surface, const_fmt &C.SDL_PixelFormat, flags u32) &C.SDL_Surface -// convert_surface copies an existing surface to a new surface of the specified format. -// -// This function is used to optimize images for faster *repeat* blitting. This -// is accomplished by converting the original and storing the result as a new -// surface. The new, optimized surface can then be used as the source for -// future blits, making them faster. -// -// `src` the existing SDL_Surface structure to convert -// `fmt` the SDL_PixelFormat structure that the new surface is optimized -// for -// `flags` the flags are unused and should be set to 0; this is a -// leftover from SDL 1.2's API -// returns the new SDL_Surface structure that is created or NULL if it fails; -// call SDL_GetError() for more information. +// convert_surface creates a new surface of the specified format, and then copies and maps +// the given surface to it so the blit of the converted surface will be as +// fast as possible. If this function fails, it returns NULL. // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_AllocFormat -// See also: SDL_ConvertSurfaceFormat -// See also: SDL_CreateRGBSurface +// The `flags` parameter is passed to SDL_CreateRGBSurface() and has those +// semantics. You can also pass ::SDL_RLEACCEL in the flags parameter and +// SDL will try to RLE accelerate colorkey and alpha blits in the resulting +// surface. pub fn convert_surface(src &Surface, const_fmt &PixelFormat, flags u32) &Surface { return C.SDL_ConvertSurface(src, const_fmt, flags) } fn C.SDL_ConvertSurfaceFormat(src &C.SDL_Surface, pixel_format u32, flags u32) &C.SDL_Surface - -// convert_surface_format copies an existing surface to a new surface of the specified format enum. -// -// This function operates just like SDL_ConvertSurface(), but accepts an -// SDL_PixelFormatEnum value instead of an SDL_PixelFormat structure. As such, -// it might be easier to call but it doesn't have access to palette -// information for the destination surface, in case that would be important. -// -// `src` the existing SDL_Surface structure to convert -// `pixel_format` the SDL_PixelFormatEnum that the new surface is -// optimized for -// `flags` the flags are unused and should be set to 0; this is a -// leftover from SDL 1.2's API -// returns the new SDL_Surface structure that is created or NULL if it fails; -// call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_AllocFormat -// See also: SDL_ConvertSurface -// See also: SDL_CreateRGBSurface pub fn convert_surface_format(src &Surface, pixel_format u32, flags u32) &Surface { return C.SDL_ConvertSurfaceFormat(src, pixel_format, flags) } fn C.SDL_ConvertPixels(width int, height int, const_src_format u32, const_src voidptr, const_src_pitch int, dst_format u32, dst voidptr, dst_pitch int) int -// convert_pixels copies a block of pixels of one format to another format. +// convert_pixels copies a block of pixels of one format to another format // -// `width` the width of the block to copy, in pixels -// `height` the height of the block to copy, in pixels -// `src_format` an SDL_PixelFormatEnum value of the `src` pixels format -// `src` a pointer to the source pixels -// `src_pitch` the pitch of the source pixels, in bytes -// `dst_format` an SDL_PixelFormatEnum value of the `dst` pixels format -// `dst` a pointer to be filled in with new pixel data -// `dst_pitch` the pitch of the destination pixels, in bytes -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. +// returns 0 on success, or -1 if there was an error pub fn convert_pixels(width int, height int, const_src_format u32, const_src voidptr, const_src_pitch int, dst_format u32, dst voidptr, dst_pitch int) int { return C.SDL_ConvertPixels(width, height, const_src_format, const_src, const_src_pitch, dst_format, dst, dst_pitch) } -fn C.SDL_PremultiplyAlpha(width int, height int, src_format u32, const_src voidptr, src_pitch int, dst_format u32, dst voidptr, dst_pitch int) int - -// premultiply_alpha premultiplys the alpha on a block of pixels. -// -// This is safe to use with src == dst, but not for other overlapping areas. -// -// This function is currently only implemented for SDL_PIXELFORMAT_ARGB8888. -// -// `width` the width of the block to convert, in pixels -// `height` the height of the block to convert, in pixels -// `src_format` an SDL_PixelFormatEnum value of the `src` pixels format -// `src` a pointer to the source pixels -// `src_pitch` the pitch of the source pixels, in bytes -// `dst_format` an SDL_PixelFormatEnum value of the `dst` pixels format -// `dst` a pointer to be filled in with premultiplied pixel data -// `dst_pitch` the pitch of the destination pixels, in bytes -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.18. -pub fn premultiply_alpha(width int, height int, src_format u32, const_src voidptr, src_pitch int, dst_format u32, dst voidptr, dst_pitch int) int { - return C.SDL_PremultiplyAlpha(width, height, src_format, const_src, src_pitch, dst_format, - dst, dst_pitch) -} - fn C.SDL_FillRect(dst &C.SDL_Surface, const_rect &C.SDL_Rect, color u32) int -// fill_rect performs a fast fill of a rectangle with a specific color. -// -// `color` should be a pixel of the format used by the surface, and can be -// generated by SDL_MapRGB() or SDL_MapRGBA(). If the color value contains an -// alpha component then the destination is simply filled with that alpha -// information, no blending takes place. +// fill_rect performs a fast fill of the given rectangle with `color`. // -// If there is a clip rectangle set on the destination (set via -// SDL_SetClipRect()), then this function will fill based on the intersection -// of the clip rectangle and `rect`. +// If `rect` is NULL, the whole surface will be filled with `color`. // -// `dst` the SDL_Surface structure that is the drawing target -// `rect` the SDL_Rect structure representing the rectangle to fill, or -// NULL to fill the entire surface -// `color` the color to fill with -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. +// The color should be a pixel of the format used by the surface, and +// can be generated by the SDL_MapRGB() function. // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_FillRects +// returns 0 on success, or -1 on error. pub fn fill_rect(dst &Surface, const_rect &Rect, color u32) int { return C.SDL_FillRect(dst, const_rect, color) } fn C.SDL_FillRects(dst &C.SDL_Surface, const_rects &C.SDL_Rect, count int, color u32) int - -// fill_rects performs a fast fill of a set of rectangles with a specific color. -// -// `color` should be a pixel of the format used by the surface, and can be -// generated by SDL_MapRGB() or SDL_MapRGBA(). If the color value contains an -// alpha component then the destination is simply filled with that alpha -// information, no blending takes place. -// -// If there is a clip rectangle set on the destination (set via -// SDL_SetClipRect()), then this function will fill based on the intersection -// of the clip rectangle and `rect`. -// -// `dst` the SDL_Surface structure that is the drawing target -// `rects` an array of SDL_Rects representing the rectangles to fill. -// `count` the number of rectangles in the array -// `color` the color to fill with -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_FillRect pub fn fill_rects(dst &Surface, const_rects &Rect, count int, color u32) int { return C.SDL_FillRects(dst, const_rects, count, color) } @@ -835,65 +457,30 @@ pub fn blit_surface(src &Surface, srcrect &Rect, dst &Surface, dstrect &Rect) in fn C.SDL_UpperBlit(src &C.SDL_Surface, const_srcrect &C.SDL_Rect, dst &C.SDL_Surface, dstrect &C.SDL_Rect) int -// upper_blit performs a fast blit from the source surface to the destination surface. -// -// SDL_UpperBlit() has been replaced by SDL_BlitSurface(), which is merely a -// macro for this function with a less confusing name. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_BlitSurface +// upper_blit is the public blit function, SDL_BlitSurface(), and it performs +// rectangle validation and clipping before passing it to SDL_LowerBlit() pub fn upper_blit(src &Surface, const_srcrect &Rect, dst &Surface, dstrect &Rect) int { return C.SDL_UpperBlit(src, const_srcrect, dst, dstrect) } fn C.SDL_LowerBlit(src &C.SDL_Surface, srcrect &C.SDL_Rect, dst &C.SDL_Surface, dstrect &C.SDL_Rect) int -// lower_blit performs low-level surface blitting only. -// -// This is a semi-private blit function and it performs low-level surface -// blitting, assuming the input rectangles have already been clipped. -// -// Unless you know what you're doing, you should be using SDL_BlitSurface() -// instead. -// -// `src` the SDL_Surface structure to be copied from -// `srcrect` the SDL_Rect structure representing the rectangle to be -// copied, or NULL to copy the entire surface -// `dst` the SDL_Surface structure that is the blit target -// `dstrect` the SDL_Rect structure representing the rectangle that is -// copied into -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_BlitSurface +// lower_blit is a semi-private blit function and it performs low-level surface +// blitting only. pub fn lower_blit(src &Surface, srcrect &Rect, dst &Surface, dstrect &Rect) int { return C.SDL_LowerBlit(src, srcrect, dst, dstrect) } fn C.SDL_SoftStretch(src &C.SDL_Surface, const_srcrect &C.SDL_Rect, dst &C.SDL_Surface, const_dstrect &C.SDL_Rect) int -// soft_stretch performs a fast, low quality, stretch blit between two surfaces of the same -// format. +// soft_stretch performs a fast, low quality, stretch blit between two surfaces of the +// same pixel format. // -// Please use SDL_BlitScaled() instead. -// -// NOTE This function is available since SDL 2.0.0. +// NOTE This function uses a static buffer, and is not thread-safe. pub fn soft_stretch(src &Surface, const_srcrect &Rect, dst &Surface, const_dstrect &Rect) int { return C.SDL_SoftStretch(src, const_srcrect, dst, const_dstrect) } -fn C.SDL_SoftStretchLinear(src &C.SDL_Surface, const_srcrect &C.SDL_Rect, dst &C.SDL_Surface, const_dstrect &C.SDL_Rect) int - -// soft_stretch_linear performs bilinear scaling between two surfaces of the same format, 32BPP. -// -// NOTE This function is available since SDL 2.0.16. -pub fn soft_stretch_linear(src &Surface, const_srcrect &Rect, dst &Surface, const_dstrect &Rect) int { - return C.SDL_SoftStretchLinear(src, const_srcrect, dst, const_dstrect) -} - fn C.SDL_BlitScaled(src &C.SDL_Surface, srcrect &C.SDL_Rect, dst &C.SDL_Surface, dstrect &C.SDL_Rect) int pub fn blit_scaled(src &Surface, srcrect &Rect, dst &Surface, dstrect &Rect) int { return C.SDL_UpperBlitScaled(src, srcrect, dst, dstrect) @@ -901,37 +488,16 @@ pub fn blit_scaled(src &Surface, srcrect &Rect, dst &Surface, dstrect &Rect) int fn C.SDL_UpperBlitScaled(src &C.SDL_Surface, const_srcrect &C.SDL_Rect, dst &C.SDL_Surface, dstrect &C.SDL_Rect) int -// upper_blit_scaled performs a scaled surface copy to a destination surface. -// -// SDL_UpperBlitScaled() has been replaced by SDL_BlitScaled(), which is -// merely a macro for this function with a less confusing name. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_BlitScaled +// upper_blit_scaled is the public scaled blit function, SDL_BlitScaled(), and it performs +// rectangle validation and clipping before passing it to SDL_LowerBlitScaled() pub fn upper_blit_scaled(src &Surface, const_srcrect &Rect, dst &Surface, dstrect &Rect) int { return C.SDL_UpperBlitScaled(src, const_srcrect, dst, dstrect) } fn C.SDL_LowerBlitScaled(src &C.SDL_Surface, srcrect &C.SDL_Rect, dst &C.SDL_Surface, dstrect &C.SDL_Rect) int -// lower_blit_scaled performs low-level surface scaled blitting only. -// -// This is a semi-private function and it performs low-level surface blitting, -// assuming the input rectangles have already been clipped. -// -// `src` the SDL_Surface structure to be copied from -// `srcrect` the SDL_Rect structure representing the rectangle to be -// copied -// `dst` the SDL_Surface structure that is the blit target -// `dstrect` the SDL_Rect structure representing the rectangle that is -// copied into -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_BlitScaled +// lower_blit_scaled is a semi-private blit function and it performs low-level surface +// scaled blitting only. pub fn lower_blit_scaled(src &Surface, srcrect &Rect, dst &Surface, dstrect &Rect) int { return C.SDL_LowerBlitScaled(src, srcrect, dst, dstrect) } @@ -939,8 +505,6 @@ pub fn lower_blit_scaled(src &Surface, srcrect &Rect, dst &Surface, dstrect &Rec fn C.SDL_SetYUVConversionMode(mode C.SDL_YUV_CONVERSION_MODE) // set_yuv_conversion_mode sets the YUV conversion mode -// -// NOTE This function is available since SDL 2.0.8. pub fn set_yuv_conversion_mode(mode YUVConversionMode) { C.SDL_SetYUVConversionMode(C.SDL_YUV_CONVERSION_MODE(int(mode))) } @@ -948,18 +512,14 @@ pub fn set_yuv_conversion_mode(mode YUVConversionMode) { fn C.SDL_GetYUVConversionMode() YUVConversionMode // get_yuv_conversion_mode gets the YUV conversion mode -// -// NOTE This function is available since SDL 2.0.8. pub fn get_yuv_conversion_mode() YUVConversionMode { return unsafe { YUVConversionMode(int(C.SDL_GetYUVConversionMode())) } } fn C.SDL_GetYUVConversionModeForResolution(width int, height int) YUVConversionMode -// get_yuv_conversion_mode_for_resolution gets the YUV conversion mode, returning the correct mode for the resolution -// when the current conversion mode is SDL_YUV_CONVERSION_AUTOMATIC -// -// NOTE This function is available since SDL 2.0.8. +// get_yuv_conversion_mode_for_resolution gets the YUV conversion mode, returning the correct mode for the resolution when +// the current conversion mode is SDL_YUV_CONVERSION_AUTOMATIC pub fn get_yuv_conversion_mode_for_resolution(width int, height int) YUVConversionMode { return unsafe { YUVConversionMode(int(C.SDL_GetYUVConversionModeForResolution(width, height))) diff --git a/system.c.v b/system.c.v index ce8318b3..78856637 100644 --- a/system.c.v +++ b/system.c.v @@ -35,48 +35,3 @@ pub fn win_r_t_get_device_family() C.SDL_WinRT_DeviceFamily{ return C.SDL_WinRTGetDeviceFamily() } */ - -fn C.SDL_IsTablet() bool - -// is_tablet queries if the current device is a tablet. -// -// If SDL can't determine this, it will return SDL_FALSE. -// -// returns SDL_TRUE if the device is a tablet, SDL_FALSE otherwise. -// -// NOTE This function is available since SDL 2.0.9. -pub fn is_tablet() bool { - return C.SDL_IsTablet() -} - -// Functions used by iOS application delegates to notify SDL about state changes - -fn C.SDL_OnApplicationWillTerminate() -pub fn on_application_will_terminate() { - C.SDL_OnApplicationWillTerminate() -} - -fn C.SDL_OnApplicationDidReceiveMemoryWarning() -pub fn on_application_did_receive_memory_warning() { - C.SDL_OnApplicationDidReceiveMemoryWarning() -} - -fn C.SDL_OnApplicationWillResignActive() -pub fn on_application_will_resign_active() { - C.SDL_OnApplicationWillResignActive() -} - -fn C.SDL_OnApplicationDidEnterBackground() -pub fn on_application_did_enter_background() { - C.SDL_OnApplicationDidEnterBackground() -} - -fn C.SDL_OnApplicationWillEnterForeground() -pub fn on_application_will_enter_foreground() { - C.SDL_OnApplicationWillEnterForeground() -} - -fn C.SDL_OnApplicationDidBecomeActive() -pub fn on_application_did_become_active() { - C.SDL_OnApplicationDidBecomeActive() -} diff --git a/system_android.c.v b/system_android.c.v index 18417769..9cbbc9b2 100644 --- a/system_android.c.v +++ b/system_android.c.v @@ -9,125 +9,32 @@ module sdl fn C.SDL_AndroidGetJNIEnv() voidptr -// android_get_jni_env gets the Android Java Native Interface Environment of the current thread. +// android_get_jni_env gets the JNI environment for the current thread // -// This is the JNIEnv one needs to access the Java virtual machine from native -// code, and is needed for many Android APIs to be usable from C. -// -// The prototype of the function in SDL's code actually declare a void* return -// type, even if the implementation returns a pointer to a JNIEnv. The -// rationale being that the SDL headers can avoid including jni.h. -// -// returns a pointer to Java native interface object (JNIEnv) to which the -// current thread is attached, or 0 on error. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_AndroidGetActivity +// returns JNIEnv*, but the prototype is void* so we don't need jni.h pub fn android_get_jni_env() voidptr { return C.SDL_AndroidGetJNIEnv() } fn C.SDL_AndroidGetActivity() voidptr -// android_get_activity retrieves the Java instance of the Android activity class. -// -// The prototype of the function in SDL's code actually declares a void* -// return type, even if the implementation returns a jobject. The rationale -// being that the SDL headers can avoid including jni.h. -// -// The jobject returned by the function is a local reference and must be -// released by the caller. See the PushLocalFrame() and PopLocalFrame() or -// DeleteLocalRef() functions of the Java native interface: -// -// https://docs.oracle.com/javase/1.5.0/docs/guide/jni/spec/functions.html -// -// returns the jobject representing the instance of the Activity class of the -// Android application, or NULL on error. -// -// NOTE This function is available since SDL 2.0.0. +// android_get_activity gets the SDL Activity object for the application // -// See also: SDL_AndroidGetJNIEnv +// returns jobject, but the prototype is void* so we don't need jni.h +// The jobject returned by SDL_AndroidGetActivity is a local reference. +// It is the caller's responsibility to properly release it +// (using env->Push/PopLocalFrame or manually with env->DeleteLocalRef) pub fn android_get_activity() voidptr { return C.SDL_AndroidGetActivity() } -fn C.SDL_GetAndroidSDKVersion() int - -// get_android_sdk_version queries Android API level of the current device. -// -// - API level 31: Android 12 -// - API level 30: Android 11 -// - API level 29: Android 10 -// - API level 28: Android 9 -// - API level 27: Android 8.1 -// - API level 26: Android 8.0 -// - API level 25: Android 7.1 -// - API level 24: Android 7.0 -// - API level 23: Android 6.0 -// - API level 22: Android 5.1 -// - API level 21: Android 5.0 -// - API level 20: Android 4.4W -// - API level 19: Android 4.4 -// - API level 18: Android 4.3 -// - API level 17: Android 4.2 -// - API level 16: Android 4.1 -// - API level 15: Android 4.0.3 -// - API level 14: Android 4.0 -// - API level 13: Android 3.2 -// - API level 12: Android 3.1 -// - API level 11: Android 3.0 -// - API level 10: Android 2.3.3 -// -// returns the Android API level. -// -// NOTE This function is available since SDL 2.0.12. -pub fn get_android_sdk_version() int { - return C.SDL_GetAndroidSDKVersion() -} - fn C.SDL_IsAndroidTV() bool -// is_android_tv queries if the application is running on Android TV. -// -// returns SDL_TRUE if this is Android TV, SDL_FALSE otherwise. -// -// NOTE This function is available since SDL 2.0.8. +// is_android_tv returns true if the application is running on Android TV pub fn is_android_tv() bool { return C.SDL_IsAndroidTV() } -fn C.SDL_IsChromebook() bool - -// is_chromebook queries if the application is running on a Chromebook. -// -// returns SDL_TRUE if this is a Chromebook, SDL_FALSE otherwise. -// -// NOTE This function is available since SDL 2.0.9. -pub fn is_chromebook() bool { - return C.SDL_IsChromebook() -} - -fn C.SDL_IsDeXMode() bool - -// is_dex_mode queries if the application is running on a Samsung DeX docking station. -// -// returns SDL_TRUE if this is a DeX docking station, SDL_FALSE otherwise. -// -// NOTE This function is available since SDL 2.0.9. -pub fn is_dex_mode() bool { - return C.SDL_IsDeXMode() -} - -fn C.SDL_AndroidBackButton() - -// android_back_button triggers the Android system back button behavior. -// -// NOTE This function is available since SDL 2.0.9. -pub fn android_back_button() { - C.SDL_AndroidBackButton() -} - // See the official Android developer guide for more information: // http://developer.android.com/guide/topics/data/data-storage.html pub const android_external_storage_read = C.SDL_ANDROID_EXTERNAL_STORAGE_READ // 0x01 @@ -138,37 +45,19 @@ fn C.SDL_AndroidGetInternalStoragePath() &char // android_get_internal_storage_path gets the path used for internal storage for this application. // -// This path is unique to your application and cannot be written to by other -// applications. -// -// Your internal storage path is typically: -// `/data/data/your.app.package/files`. -// -// returns the path used for internal storage or NULL on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_AndroidGetExternalStorageState +// This path is unique to your application and cannot be written to +// by other applications. pub fn android_get_internal_storage_path() &char { return C.SDL_AndroidGetInternalStoragePath() } fn C.SDL_AndroidGetExternalStorageState() int -// android_get_external_storage_state gets the current state of external storage. -// -// The current state of external storage, a bitmask of these values: -// `SDL_ANDROID_EXTERNAL_STORAGE_READ`, `SDL_ANDROID_EXTERNAL_STORAGE_WRITE`. +// android_get_external_storage_state gets the current state of external storage, a bitmask of these values: +// SDL_ANDROID_EXTERNAL_STORAGE_READ +// SDL_ANDROID_EXTERNAL_STORAGE_WRITE // // If external storage is currently unavailable, this will return 0. -// -// returns the current state of external storage on success or 0 on failure; -// call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_AndroidGetExternalStoragePath pub fn android_get_external_storage_state() int { return C.SDL_AndroidGetExternalStorageState() } @@ -177,73 +66,8 @@ fn C.SDL_AndroidGetExternalStoragePath() &char // android_get_external_storage_path gets the path used for external storage for this application. // -// This path is unique to your application, but is public and can be written -// to by other applications. -// -// Your external storage path is typically: -// `/storage/sdcard0/Android/data/your.app.package/files`. -// -// returns the path used for external storage for this application on success -// or NULL on failure; call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_AndroidGetExternalStorageState +// This path is unique to your application, but is public and can be +// written to by other applications. pub fn android_get_external_storage_path() &char { return C.SDL_AndroidGetExternalStoragePath() } - -fn C.SDL_AndroidRequestPermission(permission &char) bool - -// android_request_permission requests permissions at runtime. -// -// This blocks the calling thread until the permission is granted or denied. -// -// `permission` The permission to request. -// returns SDL_TRUE if the permission was granted, SDL_FALSE otherwise. -// -// NOTE This function is available since SDL 2.0.14. -pub fn android_request_permission(permission &char) bool { - return C.SDL_AndroidRequestPermission(permission) -} - -fn C.SDL_AndroidShowToast(const_message &char, duration int, gravity int, xoffset int, yoffset int) int - -// android_show_toast shows an Android toast notification. -// -// Toasts are a sort of lightweight notification that are unique to Android. -// -// https://developer.android.com/guide/topics/ui/notifiers/toasts -// -// Shows toast in UI thread. -// -// For the `gravity` parameter, choose a value from here, or -1 if you don't -// have a preference: -// -// https://developer.android.com/reference/android/view/Gravity -// -// `message` text message to be shown -// `duration` 0=short, 1=long -// `gravity` where the notification should appear on the screen. -// `xoffset` set this parameter only when gravity >=0 -// `yoffset` set this parameter only when gravity >=0 -// returns 0 if success, -1 if any error occurs. -// -// NOTE This function is available since SDL 2.0.16. -pub fn android_show_toast(const_message &char, duration int, gravity int, xoffset int, yoffset int) int { - return C.SDL_AndroidShowToast(const_message, duration, gravity, xoffset, yoffset) -} - -fn C.SDL_AndroidSendMessage(command u32, param int) int - -// android_send_message sends a user command to SDLActivity. -// -// Override "boolean onUnhandledMessage(Message msg)" to handle the message. -// -// `command` user command that must be greater or equal to 0x8000 -// `param` user parameter -// -// NOTE This function is available since SDL 2.0.22. -pub fn android_send_message(command u32, param int) int { - return C.SDL_AndroidSendMessage(command, param) -} diff --git a/system_ios.c.v b/system_ios.c.v index 7e4cc15f..1a60f8a6 100644 --- a/system_ios.c.v +++ b/system_ios.c.v @@ -12,42 +12,11 @@ module sdl pub type IOSAnimationCallback = fn (params voidptr) fn C.SDL_iOSSetAnimationCallback(window &C.SDL_Window, interval int, callback IOSAnimationCallback, callbackParam voidptr) int -pub fn ios_set_animation_callback(window &Window, interval int, callback IOSAnimationCallback, callback_param voidptr) int { +pub fn iphone_set_animation_callback(window &Window, interval int, callback IOSAnimationCallback, callback_param voidptr) int { return C.SDL_iOSSetAnimationCallback(window, interval, callback, callback_param) } fn C.SDL_iPhoneSetAnimationCallback(window &C.SDL_Window, interval int, callback IOSAnimationCallback, callback_param voidptr) int - -// iphone_set_animation_callback sets the animation callback on Apple iOS. -// -// The function prototype for `callback` is: -// -// ```c -// void callback(void* callbackParam); -// ``` -// -// Where its parameter, `callbackParam`, is what was passed as `callbackParam` -// to SDL_iPhoneSetAnimationCallback(). -// -// This function is only available on Apple iOS. -// -// For more information see: -// https://github.com/libsdl-org/SDL/blob/main/docs/README-ios.md -// -// This functions is also accessible using the macro -// SDL_iOSSetAnimationCallback() since SDL 2.0.4. -// -// `window` the window for which the animation callback should be set -// `interval` the number of frames after which **callback** will be -// called -// `callback` the function to call for every frame. -// `callbackParam` a pointer that is passed to `callback`. -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_iPhoneSetEventPump pub fn iphone_set_animation_callback(window &Window, interval int, callback IOSAnimationCallback, callback_param voidptr) int { return C.SDL_iPhoneSetAnimationCallback(window, interval, callback, callback_param) } @@ -58,24 +27,6 @@ pub fn ios_set_event_pump(enabled bool) { } fn C.SDL_iPhoneSetEventPump(enabled bool) - -// iphone_set_event_pump uses this function to enable or disable the SDL event pump on Apple iOS. -// -// This function is only available on Apple iOS. -// -// This functions is also accessible using the macro SDL_iOSSetEventPump() -// since SDL 2.0.4. -// -// `enabled` SDL_TRUE to enable the event pump, SDL_FALSE to disable it -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_iPhoneSetAnimationCallback pub fn iphone_set_event_pump(enabled bool) { C.SDL_iPhoneSetEventPump(enabled) } - -fn C.SDL_OnApplicationDidChangeStatusBarOrientation() -pub fn on_application_did_change_status_bar_orientation() { - C.SDL_OnApplicationDidChangeStatusBarOrientation() -} diff --git a/system_linux.c.v b/system_linux.c.v deleted file mode 100644 index b14b9bb0..00000000 --- a/system_linux.c.v +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright(C) 2021 Lars Pontoppidan. All rights reserved. -// Use of this source code is governed by an MIT license -// that can be found in the LICENSE file. -module sdl - -// -// SDL_system.h -// - -// Platform specific functions for Linux - -fn C.SDL_LinuxSetThreadPriority(thread_id i64, priority int) int - -// linux_set_thread_priority sets the UNIX nice value for a thread. -// -// This uses setpriority() if possible, and RealtimeKit if available. -// -// `threadID` the Unix thread ID to change priority of. -// `priority` The new, Unix-specific, priority value. -// returns 0 on success, or -1 on error. -// -// NOTE This function is available since SDL 2.0.9. -pub fn linux_set_thread_priority(thread_id i64, priority int) int { - return C.SDL_LinuxSetThreadPriority(thread_id, priority) -} - -fn C.SDL_LinuxSetThreadPriorityAndPolicy(thread_id i64, sdl_priority int, sched_policy int) int - -// linux_set_thread_priority_and_policy sets the priority (not nice level) and scheduling policy for a thread. -// -// This uses setpriority() if possible, and RealtimeKit if available. -// -// `threadID` The Unix thread ID to change priority of. -// `sdlPriority` The new SDL_ThreadPriority value. -// `schedPolicy` The new scheduling policy (SCHED_FIFO, SCHED_RR, -// SCHED_OTHER, etc...) -// returns 0 on success, or -1 on error. -// -// NOTE This function is available since SDL 2.0.18. -pub fn linux_set_thread_priority_and_policy(thread_id i64, sdl_priority int, sched_policy int) int { - return C.SDL_LinuxSetThreadPriorityAndPolicy(thread_id, sdl_priority, sched_policy) -} diff --git a/system_windows.c.v b/system_windows.c.v index ac5961a5..9a5c1c97 100644 --- a/system_windows.c.v +++ b/system_windows.c.v @@ -14,29 +14,17 @@ pub type WindowsMessageHook = fn (userdata voidptr, h_wnd voidptr, message u32, fn C.SDL_SetWindowsMessageHook(callback WindowsMessageHook, userdata voidptr) -// set_windows_message_hook sets a callback for every Windows message, run before TranslateMessage(). -// -// `callback` The SDL_WindowsMessageHook function to call. -// `userdata` a pointer to pass to every iteration of `callback` -// -// NOTE This function is available since SDL 2.0.4. +// set_windows_message_hook sets a function that is called for every windows message, before TranslateMessage() pub fn set_windows_message_hook(callback WindowsMessageHook, userdata voidptr) { C.SDL_SetWindowsMessageHook(callback, userdata) } fn C.SDL_Direct3D9GetAdapterIndex(display_index int) int -// direct_3d9_get_adapter_index gets the D3D9 adapter index that matches the specified display index. -// -// The returned adapter index can be passed to `IDirect3D9::CreateDevice` and -// controls on which monitor a full screen application will appear. +// direct_3d9_get_adapter_index returns the D3D9 adapter index that matches the specified display index. // -// `displayIndex` the display index for which to get the D3D9 adapter -// index -// returns the D3D9 adapter index on success or a negative error code on -// failure; call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.1. +// This adapter index can be passed to IDirect3D9::CreateDevice and controls +// on which monitor a full screen application will appear. pub fn direct_3d9_get_adapter_index(display_index int) int { return C.SDL_Direct3D9GetAdapterIndex(display_index) } @@ -49,126 +37,19 @@ pub type IDirect3DDevice9 = C.IDirect3DDevice9 fn C.SDL_RenderGetD3D9Device(renderer &C.SDL_Renderer) &C.IDirect3DDevice9 -// render_get_d3d9_device gets the D3D9 device associated with a renderer. -// -// Once you are done using the device, you should release it to avoid a -// resource leak. +// render_get_d3d9_device returns the D3D device associated with a renderer, or NULL if it's not a D3D renderer. // -// `renderer` the renderer from which to get the associated D3D device -// returns the D3D9 device associated with given renderer or NULL if it is -// not a D3D9 renderer; call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.1. +// Once you are done using the device, you should release it to avoid a resource leak. pub fn render_get_d3d9_device(renderer &Renderer) &IDirect3DDevice9 { return C.SDL_RenderGetD3D9Device(renderer) } -@[typedef] -pub struct C.ID3D11Device { -} - -pub type ID3D11Device = C.ID3D11Device - -fn C.SDL_RenderGetD3D11Device(renderer &C.SDL_Renderer) &C.ID3D11Device - -// render_get_d3_d11_device gets the D3D11 device associated with a renderer. -// -// Once you are done using the device, you should release it to avoid a -// resource leak. -// -// `renderer` the renderer from which to get the associated D3D11 device -// returns the D3D11 device associated with given renderer or NULL if it is -// not a D3D11 renderer; call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.16. -pub fn render_get_d3_d11_device(renderer &Renderer) &ID3D11Device { - return C.SDL_RenderGetD3D11Device(renderer) -} - -@[typedef] -struct C.ID3D12Device { -} - -pub type ID3D12Device = C.ID3D12Device - -fn C.SDL_RenderGetD3D12Device(renderer &C.SDL_Renderer) &C.ID3D12Device - -// render_get_d3_d12_device gets the D3D12 device associated with a renderer. -// -// Once you are done using the device, you should release it to avoid a -// resource leak. -// -// `renderer` the renderer from which to get the associated D3D12 device -// returns the D3D12 device associated with given renderer or NULL if it is -// not a D3D12 renderer; call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.24.0. -pub fn render_get_d3_d12_device(renderer &Renderer) &ID3D12Device { - return C.SDL_RenderGetD3D12Device(renderer) -} - fn C.SDL_DXGIGetOutputInfo(display_index int, adapter_index &int, output_index &int) bool -// dxgi_get_output_info gets the DXGI Adapter and Output indices for the specified display index. +// dxgi_get_output_info returns the DXGI Adapter and Output indices for the specified display index. // -// The DXGI Adapter and Output indices can be passed to `EnumAdapters` and -// `EnumOutputs` respectively to get the objects required to create a DX10 or -// DX11 device and swap chain. -// -// Before SDL 2.0.4 this function did not return a value. Since SDL 2.0.4 it -// returns an SDL_bool. -// -// `displayIndex` the display index for which to get both indices -// `adapterIndex` a pointer to be filled in with the adapter index -// `outputIndex` a pointer to be filled in with the output index -// returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError() -// for more information. -// -// NOTE This function is available since SDL 2.0.2. +// These can be passed to EnumAdapters and EnumOutputs respectively to get the objects +// required to create a DX10 or DX11 device and swap chain. pub fn dxgi_get_output_info(display_index int, adapter_index &int, output_index &int) bool { return C.SDL_DXGIGetOutputInfo(display_index, adapter_index, output_index) } - -/* -TODO support GDK? -$if gdk ? { - [typedef] - struct C.XTaskQueueHandle {} // XTaskQueueObject - pub type XTaskQueueHandle = C.XTaskQueueHandle - - [typedef] - struct C.XUserHandle {} // XUser - pub type XUserHandle = C.XUserHandle - - fn C.SDL_GDKGetTaskQueue(out_task_queue &C.XTaskQueueHandle) int - // gdk_get_task_queue gets a reference to the global async task queue handle for GDK, - // initializing if needed. - // - // Once you are done with the task queue, you should call - // XTaskQueueCloseHandle to reduce the reference count to avoid a resource - // leak. - // - // `outTaskQueue` a pointer to be filled in with task queue handle. - // returns 0 if success, -1 if any error occurs. - // - // NOTE This function is available since SDL 2.24.0. - pub fn gdk_get_task_queue(out_task_queue &XTaskQueueHandle) int{ - return C.SDL_GDKGetTaskQueue(out_task_queue) - } - - fn C.SDL_GDKGetDefaultUser(XUserHandle * outUserHandle) int - // Gets a reference to the default user handle for GDK. - // - // This is effectively a synchronous version of XUserAddAsync, which always - // prefers the default user and allows a sign-in UI. - // - // `outUserHandle` a pointer to be filled in with the default user - // handle. - // returns 0 if success, -1 if any error occurs. - // - // NOTE This function is available since SDL 2.28.0. - pub fn gdk_get_default_user(out_user_handle &XUserHandle) int { - return C.SDL_GDKGetDefaultUser(out_user_handle) - } -} -*/ diff --git a/thread.c.v b/thread.c.v index 00ef5524..0c5967c9 100644 --- a/thread.c.v +++ b/thread.c.v @@ -7,12 +7,13 @@ module sdl // SDL_thread.h // +// Thread is the SDL thread structure, defined in SDL_thread.c +// Thread is C.SDL_Thread + @[noinit; typedef] pub struct C.SDL_Thread { } -// Thread is the SDL thread structure, defined in SDL_thread.c -// Thread is C.SDL_Thread pub type Thread = C.SDL_Thread // The SDL thread ID @@ -25,45 +26,30 @@ pub type TLSID = u32 // ThreadPriority is the SDL thread priority. // -// SDL will make system changes as necessary in order to apply the thread priority. -// Code which attempts to control thread state related to priority should be aware -// that calling SDL_SetThreadPriority may alter such state. -// SDL_HINT_THREAD_PRIORITY_POLICY can be used to control aspects of this behavior. -// -// NOTE On many systems you require special privileges to set high or time critical priority. +// NOTE On many systems you require special privileges to set high priority. // // ThreadPriority is C.SDL_ThreadPriority pub enum ThreadPriority { - low = C.SDL_THREAD_PRIORITY_LOW - normal = C.SDL_THREAD_PRIORITY_NORMAL - high = C.SDL_THREAD_PRIORITY_HIGH - time_critical = C.SDL_THREAD_PRIORITY_TIME_CRITICAL + low = C.SDL_THREAD_PRIORITY_LOW + normal = C.SDL_THREAD_PRIORITY_NORMAL + high = C.SDL_THREAD_PRIORITY_HIGH } -// The function passed to SDL_CreateThread(). -// -// `data` what was passed as `data` to SDL_CreateThread() -// returns a value that can be reported through SDL_WaitThread(). -// +// ThreadFunction is the function passed to SDL_CreateThread(). +// It is passed a void* user context parameter and returns an int. // `typedef int (SDLCALL * SDL_ThreadFunction) (void *data);` pub type ThreadFunction = fn (data voidptr) int /* // TODO win32 & OS2 ??? -// extern DECLSPEC SDL_Thread *SDLCALL SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread) +// extern DECLSPEC SDL_Thread *SDLCALLSDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread) fn C.SDL_CreateThread(func C.SDL_ThreadFunction, name &char, data voidptr, pfn_begin_thread C.pfnSDL_CurrentBeginThread, pfn_end_thread C.pfnSDL_CurrentEndThread) &C.SDL_Thread pub fn create_thread(func C.SDL_ThreadFunction, name &char, data voidptr, pfn_begin_thread C.pfnSDL_CurrentBeginThread, pfn_end_thread C.pfnSDL_CurrentEndThread) &C.SDL_Thread{ return C.SDL_CreateThread(func, name, data, pfn_begin_thread, pfn_end_thread) } -// extern DECLSPEC SDL_Thread *SDLCALL SDL_CreateThreadWithStackSize(SDL_ThreadFunction fn, const char *name, const size_t stacksize, void *data, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread) -fn C.SDL_CreateThreadWithStackSize(func C.SDL_ThreadFunction, const_name &char, const_stacksize usize, data voidptr, pfn_begin_thread C.pfnSDL_CurrentBeginThread, pfn_end_thread C.pfnSDL_CurrentEndThread) &C.SDL_Thread -pub fn create_thread_with_stack_size(func C.SDL_ThreadFunction, const_name &char, const_stacksize usize, data voidptr, pfn_begin_thread C.pfnSDL_CurrentBeginThread, pfn_end_thread C.pfnSDL_CurrentEndThread) &C.SDL_Thread{ - return C.SDL_CreateThreadWithStackSize(func, const_name, const_stacksize, data, pfn_begin_thread, pfn_end_thread) -} - -// extern DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread(SDL_ThreadFunction fn, const char * name, void * data, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread) +// extern DECLSPEC SDL_Thread * SDLCALLSDL_CreateThread(SDL_ThreadFunction fn, const char * name, void * data, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread) fn C.SDL_CreateThread(func C.SDL_ThreadFunction, name &char, data voidptr, pfn_begin_thread C.pfnSDL_CurrentBeginThread, pfn_end_thread C.pfnSDL_CurrentEndThread) &C.SDL_Thread pub fn create_thread(func C.SDL_ThreadFunction, name &char, data voidptr, pfn_begin_thread C.pfnSDL_CurrentBeginThread, pfn_end_thread C.pfnSDL_CurrentEndThread) &C.SDL_Thread{ return C.SDL_CreateThread(func, name, data, pfn_begin_thread, pfn_end_thread) @@ -72,97 +58,33 @@ pub fn create_thread(func C.SDL_ThreadFunction, name &char, data voidptr, pfn_be fn C.SDL_CreateThread(func ThreadFunction, const_name &char, data voidptr) &C.SDL_Thread -// create_thread creates a new thread with a default stack size. -// -// This is equivalent to calling: -// -/* -```c - SDL_CreateThreadWithStackSize(fn, name, 0, data); -``` -*/ +// create_thread createa a thread. // -// `fn` the SDL_ThreadFunction function to call in the new thread -// `name` the name of the thread -// `data` a pointer that is passed to `fn` -// returns an opaque pointer to the new thread object on success, NULL if the -// new thread could not be created; call SDL_GetError() for more -// information. +// Thread naming is a little complicated: Most systems have very small +// limits for the string length (Haiku has 32 bytes, Linux currently has 16, +// Visual C++ 6.0 has nine!), and possibly other arbitrary rules. You'll +// have to see what happens with your system's debugger. The name should be +// UTF-8 (but using the naming limits of C identifiers is a better bet). +// There are no requirements for thread naming conventions, so long as the +// string is null-terminated UTF-8, but these guidelines are helpful in +// choosing a name: // -// NOTE This function is available since SDL 2.0.0. +// http://stackoverflow.com/questions/149932/naming-conventions-for-threads // -// See also: SDL_CreateThreadWithStackSize -// See also: SDL_WaitThread +// If a system imposes requirements, SDL will try to munge the string for +// it (truncate, etc), but the original string contents will be available +// from SDL_GetThreadName(). pub fn create_thread(func ThreadFunction, const_name &char, data voidptr) &Thread { return C.SDL_CreateThread(func, const_name, data) } -fn C.SDL_CreateThreadWithStackSize(func ThreadFunction, const_name &char, const_stacksize usize, data voidptr) &C.SDL_Thread - -// create_thread_with_stack_size creates a new thread with a specific stack size. -// -// SDL makes an attempt to report `name` to the system, so that debuggers can -// display it. Not all platforms support this. -// -// Thread naming is a little complicated: Most systems have very small limits -// for the string length (Haiku has 32 bytes, Linux currently has 16, Visual -// C++ 6.0 has _nine_!), and possibly other arbitrary rules. You'll have to -// see what happens with your system's debugger. The name should be UTF-8 (but -// using the naming limits of C identifiers is a better bet). There are no -// requirements for thread naming conventions, so long as the string is -// null-terminated UTF-8, but these guidelines are helpful in choosing a name: -// -// https://stackoverflow.com/questions/149932/naming-conventions-for-threads -// -// If a system imposes requirements, SDL will try to munge the string for it -// (truncate, etc), but the original string contents will be available from -// SDL_GetThreadName(). -// -// The size (in bytes) of the new stack can be specified. Zero means "use the -// system default" which might be wildly different between platforms. x86 -// Linux generally defaults to eight megabytes, an embedded device might be a -// few kilobytes instead. You generally need to specify a stack that is a -// multiple of the system's page size (in many cases, this is 4 kilobytes, but -// check your system documentation). -// -// In SDL 2.1, stack size will be folded into the original SDL_CreateThread -// function, but for backwards compatibility, this is currently a separate -// function. -// -// `fn` the SDL_ThreadFunction function to call in the new thread -// `name` the name of the thread -// `stacksize` the size, in bytes, to allocate for the new thread stack. -// `data` a pointer that is passed to `fn` -// returns an opaque pointer to the new thread object on success, NULL if the -// new thread could not be created; call SDL_GetError() for more -// information. -// -// NOTE This function is available since SDL 2.0.9. -// -// See also: SDL_WaitThread -pub fn create_thread_with_stack_size(func ThreadFunction, const_name &char, const_stacksize usize, data voidptr) &Thread { - $if !windows { - return C.SDL_CreateThreadWithStackSize(func, const_name, const_stacksize, data) - } $else { - panic('TODO support this call on Windows') - } - return unsafe { nil } -} - fn C.SDL_GetThreadName(pthread &C.SDL_Thread) &char -// get_thread_name gets the thread name as it was specified in SDL_CreateThread(). -// -// This is internal memory, not to be freed by the caller, and remains valid -// until the specified thread is cleaned up by SDL_WaitThread(). -// -// `pthread` the thread to query -// returns a pointer to a UTF-8 string that names the specified thread, or -// NULL if it doesn't have a name. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_CreateThread +// get_thread_name gets the thread name, as it was specified in SDL_CreateThread(). +// This function returns a pointer to a UTF-8 string that names the +// specified thread, or NULL if it doesn't have a name. This is internal +// memory, not to be free()'d by the caller, and remains valid until the +// specified thread is cleaned up by SDL_WaitThread(). pub fn get_thread_name(pthread &Thread) &char { return C.SDL_GetThreadName(pthread) } @@ -170,19 +92,6 @@ pub fn get_thread_name(pthread &Thread) &char { fn C.SDL_ThreadID() ThreadID // thread_id gets the thread identifier for the current thread. -// -// This thread identifier is as reported by the underlying operating system. -// If SDL is running on a platform that does not support threads the return -// value will always be zero. -// -// This function also returns a valid thread ID when called from the main -// thread. -// -// returns the ID of the current thread. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetThreadID pub fn thread_id() ThreadID { return ThreadID(u32(C.SDL_ThreadID())) } @@ -191,180 +100,132 @@ fn C.SDL_GetThreadID(thrd &C.SDL_Thread) ThreadID // get_thread_id gets the thread identifier for the specified thread. // -// This thread identifier is as reported by the underlying operating system. -// If SDL is running on a platform that does not support threads the return -// value will always be zero. -// -// `thread` the thread to query -// returns the ID of the specified thread, or the ID of the current thread if -// `thread` is NULL. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_ThreadID +// Equivalent to SDL_ThreadID() if the specified thread is NULL. pub fn get_thread_id(thrd &Thread) ThreadID { return ThreadID(u32(C.SDL_GetThreadID(thrd))) } fn C.SDL_SetThreadPriority(priority C.SDL_ThreadPriority) int -// set_thread_priority sets the priority for the current thread. -// -// Note that some platforms will not let you alter the priority (or at least, -// promote the thread to a higher priority) at all, and some require you to be -// an administrator account. Be prepared for this to fail. -// -// `priority` the SDL_ThreadPriority to set -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. +// set_thread_priority sets the priority for the current thread pub fn set_thread_priority(priority ThreadPriority) int { return C.SDL_SetThreadPriority(C.SDL_ThreadPriority(priority)) } fn C.SDL_WaitThread(thrd &C.SDL_Thread, status &int) -// wait_thread waits for a thread to finish. -// -// Threads that haven't been detached will remain (as a "zombie") until this -// function cleans them up. Not doing so is a resource leak. +// wait_thread waits for a thread to finish. Threads that haven't been detached will +// remain (as a "zombie") until this function cleans them up. Not doing so +// is a resource leak. // // Once a thread has been cleaned up through this function, the SDL_Thread -// that references it becomes invalid and should not be referenced again. As -// such, only one thread may call SDL_WaitThread() on another. +// that references it becomes invalid and should not be referenced again. +// As such, only one thread may call SDL_WaitThread() on another. // -// The return code for the thread function is placed in the area pointed to by -// `status`, if `status` is not NULL. +// The return code for the thread function is placed in the area +// pointed to by `status`, if `status` is not NULL. // // You may not wait on a thread that has been used in a call to -// SDL_DetachThread(). Use either that function or this one, but not both, or -// behavior is undefined. +// SDL_DetachThread(). Use either that function or this one, but not +// both, or behavior is undefined. // -// It is safe to pass a NULL thread to this function; it is a no-op. -// -// Note that the thread pointer is freed by this function and is not valid -// afterward. -// -// `thread` the SDL_Thread pointer that was returned from the -// SDL_CreateThread() call that started this thread -// `status` pointer to an integer that will receive the value returned -// from the thread function by its 'return', or NULL to not -// receive such value back. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_CreateThread -// See also: SDL_DetachThread +// It is safe to pass NULL to this function; it is a no-op. pub fn wait_thread(thrd &Thread, status &int) { C.SDL_WaitThread(thrd, status) } fn C.SDL_DetachThread(thrd &C.SDL_Thread) -// detach_thread lets a thread clean up on exit without intervention. -// -// A thread may be "detached" to signify that it should not remain until -// another thread has called SDL_WaitThread() on it. Detaching a thread is -// useful for long-running threads that nothing needs to synchronize with or -// further manage. When a detached thread is done, it simply goes away. +// detach_thread. A thread may be "detached" to signify that it should not remain until +// another thread has called SDL_WaitThread() on it. Detaching a thread +// is useful for long-running threads that nothing needs to synchronize +// with or further manage. When a detached thread is done, it simply +// goes away. // // There is no way to recover the return code of a detached thread. If you // need this, don't detach the thread and instead use SDL_WaitThread(). // // Once a thread is detached, you should usually assume the SDL_Thread isn't -// safe to reference again, as it will become invalid immediately upon the -// detached thread's exit, instead of remaining until someone has called +// safe to reference again, as it will become invalid immediately upon +// the detached thread's exit, instead of remaining until someone has called // SDL_WaitThread() to finally clean it up. As such, don't detach the same // thread more than once. // // If a thread has already exited when passed to SDL_DetachThread(), it will -// stop waiting for a call to SDL_WaitThread() and clean up immediately. It is -// not safe to detach a thread that might be used with SDL_WaitThread(). +// stop waiting for a call to SDL_WaitThread() and clean up immediately. +// It is not safe to detach a thread that might be used with SDL_WaitThread(). // -// You may not call SDL_WaitThread() on a thread that has been detached. Use -// either that function or this one, but not both, or behavior is undefined. +// You may not call SDL_WaitThread() on a thread that has been detached. +// Use either that function or this one, but not both, or behavior is +// undefined. // // It is safe to pass NULL to this function; it is a no-op. -// -// `thread` the SDL_Thread pointer that was returned from the -// SDL_CreateThread() call that started this thread -// -// NOTE This function is available since SDL 2.0.2. -// -// See also: SDL_CreateThread -// See also: SDL_WaitThread pub fn detach_thread(thrd &Thread) { C.SDL_DetachThread(thrd) } fn C.SDL_TLSCreate() TLSID -// tls_create creates a piece of thread-local storage. -// -// This creates an identifier that is globally visible to all threads but -// refers to data that is thread-specific. +// tls_create create an identifier that is globally visible to all threads but refers to data that is thread-specific. // -// returns the newly created thread local storage identifier or 0 on error. +// returns The newly created thread local storage identifier, or 0 on error // -// NOTE This function is available since SDL 2.0.0. +/* +``` + static SDL_SpinLock tls_lock; + static SDL_TLSID thread_local_storage; + + void SetMyThreadData(void * value) + { + if (!thread_local_storage) { + SDL_AtomicLock(&tls_lock); + if (!thread_local_storage) { + thread_local_storage = SDL_TLSCreate(); + } + SDL_AtomicUnlock(&tls_lock); + } + SDL_TLSSet(thread_local_storage, value, 0); + } + + void * GetMyThreadData(void) + { + return SDL_TLSGet(thread_local_storage); + } +``` +*/ // -// See also: SDL_TLSGet -// See also: SDL_TLSSet +// See also: SDL_TLSGet() +// See also: SDL_TLSSet() pub fn tls_create() TLSID { return TLSID(u32(C.SDL_TLSCreate())) } fn C.SDL_TLSGet(id C.SDL_TLSID) voidptr -// tls_get gets the current thread's value associated with a thread local storage ID. +// tls_get gets the value associated with a thread local storage ID for the current thread. // -// `id` the thread local storage ID -// returns the value associated with the ID for the current thread or NULL if -// no value has been set; call SDL_GetError() for more information. +// `id` The thread local storage ID // -// NOTE This function is available since SDL 2.0.0. +// returns The value associated with the ID for the current thread, or NULL if no value has been set. // -// See also: SDL_TLSCreate -// See also: SDL_TLSSet +// See also: SDL_TLSCreate() +// See also: SDL_TLSSet() pub fn tls_get(id TLSID) voidptr { return C.SDL_TLSGet(C.SDL_TLSID(id)) } fn C.SDL_TLSSet(id C.SDL_TLSID, const_value voidptr, destructor fn (voidptr)) int -// tls_set sets the current thread's value associated with a thread local storage ID. -// -// The function prototype for `destructor` is: -// -/* -```c - void destructor(void *value) -``` -*/ -// -// where its parameter `value` is what was passed as `value` to SDL_TLSSet(). +// tls_set sets the value associated with a thread local storage ID for the current thread. // -// `id` the thread local storage ID -// `value` the value to associate with the ID for the current thread -// `destructor` a function called when the thread exits, to free the -// value -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. +// `id` The thread local storage ID +// `value` The value to associate with the ID for the current thread +// `destructor` A function called when the thread exits, to free the value. // -// NOTE This function is available since SDL 2.0.0. +// returns 0 on success, -1 on error // -// See also: SDL_TLSCreate -// See also: SDL_TLSGet +// See also: SDL_TLSCreate() +// See also: SDL_TLSGet() pub fn tls_set(id TLSID, const_value voidptr, destructor fn (voidptr)) int { return C.SDL_TLSSet(C.SDL_TLSID(id), const_value, destructor) } - -fn C.SDL_TLSCleanup() - -// tls_cleanup cleanups all TLS data for this thread. -// -// NOTE This function is available since SDL 2.0.16. -pub fn tls_cleanup() { - C.SDL_TLSCleanup() -} diff --git a/timer.c.v b/timer.c.v index 90f6b8fa..309675ae 100644 --- a/timer.c.v +++ b/timer.c.v @@ -24,108 +24,40 @@ pub type TimerID = int fn C.SDL_GetTicks() u32 -// get_ticks gets the number of milliseconds since SDL library initialization. +// get_ticks gets the number of milliseconds since the SDL library initialization. // -// This value wraps if the program runs for more than ~49 days. -// -// This function is not recommended as of SDL 2.0.18; use SDL_GetTicks64() -// instead, where the value doesn't wrap every ~49 days. There are places in -// SDL where we provide a 32-bit timestamp that can not change without -// breaking binary compatibility, though, so this function isn't officially -// deprecated. -// -// returns an unsigned 32-bit value representing the number of milliseconds -// since the SDL library initialized. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_TICKS_PASSED +// NOTE This value wraps if the program runs for more than ~49 days. pub fn get_ticks() u32 { return C.SDL_GetTicks() } -fn C.SDL_GetTicks64() u64 - -// get_ticks64 gets the number of milliseconds since SDL library initialization. -// -// Note that you should not use the SDL_TICKS_PASSED macro with values -// returned by this function, as that macro does clever math to compensate for -// the 32-bit overflow every ~49 days that SDL_GetTicks() suffers from. 64-bit -// values from this function can be safely compared directly. -// -// For example, if you want to wait 100 ms, you could do this: -// -// ```c -// const Uint64 timeout = SDL_GetTicks64() + 100; -// while (SDL_GetTicks64() < timeout) { -// // ... do work until timeout has elapsed -// } -// ``` -// -// returns an unsigned 64-bit value representing the number of milliseconds -// since the SDL library initialized. -// -// NOTE This function is available since SDL 2.0.18. -pub fn get_ticks64() u64 { - return C.SDL_GetTicks64() -} - fn C.SDL_TICKS_PASSED(a u32, b u32) bool -// ticks_passed compares 32-bit SDL tick values, and return true if `A` has passed `B`. -// -// This should be used with results from SDL_GetTicks(), as this macro -// attempts to deal with the 32-bit counter wrapping back to zero every ~49 -// days, but should _not_ be used with SDL_GetTicks64(), which does not have -// that problem. -// -// For example, with SDL_GetTicks(), if you want to wait 100 ms, you could -// do this: +// ticks_passed compares SDL ticks values, and return true if A has passed B // +// e.g. if you want to wait 100 ms, you could do this: /* -```c - const Uint32 timeout = SDL_GetTicks() + 100; - while (!SDL_TICKS_PASSED(SDL_GetTicks(), timeout)) { - // ... do work until timeout has elapsed +``` +timeout := sdl.get_ticks() + 100 +for !ticks_passed(sdl.get_ticks(), timeout) { + ... do work until timeout has elapsed } ``` */ -// -// Note that this does not handle tick differences greater -// than 2^31 so take care when using the above kind of code -// with large timeout delays (tens of days). pub fn ticks_passed(a u32, b u32) bool { return C.SDL_TICKS_PASSED(a, b) } fn C.SDL_GetPerformanceCounter() u64 -// get_performance_counter gets the current value of the high resolution counter. -// -// This function is typically used for profiling. -// -// The counter values are only meaningful relative to each other. Differences -// between values can be converted to times by using -// SDL_GetPerformanceFrequency(). -// -// returns the current counter value. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetPerformanceFrequency +// get_performance_counter gets the current value of the high resolution counter pub fn get_performance_counter() u64 { return C.SDL_GetPerformanceCounter() } fn C.SDL_GetPerformanceFrequency() u64 -// get_performance_frequency gets the count per second of the high resolution counter. -// -// returns a platform-specific count per second. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetPerformanceCounter +// get_performance_frequency gets the count per second of the high resolution counter pub fn get_performance_frequency() u64 { return C.SDL_GetPerformanceFrequency() } @@ -133,65 +65,26 @@ pub fn get_performance_frequency() u64 { fn C.SDL_Delay(ms u32) // delay waits a specified number of milliseconds before returning. -// -// This function waits a specified number of milliseconds before returning. It -// waits at least the specified time, but possibly longer due to OS -// scheduling. -// -// NOTE This function is available since SDL 2.0.0. -// -// `ms` the number of milliseconds to delay pub fn delay(ms u32) { C.SDL_Delay(ms) } fn C.SDL_AddTimer(interval u32, callback C.SDL_TimerCallback, param voidptr) TimerID -// add_timer calls a callback function at a future time. +// add_timer adds a new timer to the pool of timers already running. // -// If you use this function, you must pass `SDL_INIT_TIMER` to SDL_Init(). -// -// The callback function is passed the current timer interval and the user -// supplied parameter from the SDL_AddTimer() call and should return the next -// timer interval. If the value returned from the callback is 0, the timer is -// canceled. -// -// The callback is run on a separate thread. -// -// Timers take into account the amount of time it took to execute the -// callback. For example, if the callback took 250 ms to execute and returned -// 1000 (ms), the timer would only wait another 750 ms before its next -// iteration. -// -// Timing may be inexact due to OS scheduling. Be sure to note the current -// time with SDL_GetTicks() or SDL_GetPerformanceCounter() in case your -// callback needs to adjust for variances. -// -// `interval` the timer delay, in milliseconds, passed to `callback` -// `callback` the SDL_TimerCallback function to call when the specified -// `interval` elapses -// `param` a pointer that is passed to `callback` -// returns a timer ID or 0 if an error occurs; call SDL_GetError() for more -// information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_RemoveTimer +// returns A timer ID, or 0 when an error occurs. pub fn add_timer(interval u32, callback TimerCallback, param voidptr) TimerID { return int(C.SDL_AddTimer(interval, C.SDL_TimerCallback(callback), param)) } fn C.SDL_RemoveTimer(id C.SDL_TimerID) bool -// remove_timer removes a timer created with SDL_AddTimer(). -// -// `id` the ID of the timer to remove -// returns SDL_TRUE if the timer is removed or SDL_FALSE if the timer wasn't -// found. +// remove_timer removes a timer knowing its ID. // -// NOTE This function is available since SDL 2.0.0. +// returns A boolean value indicating success or failure. // -// See also: SDL_AddTimer +// WARNING It is not safe to remove a timer multiple times. pub fn remove_timer(id TimerID) bool { return C.SDL_RemoveTimer(C.SDL_TimerID(id)) } diff --git a/touch.c.v b/touch.c.v index 925eef06..6a30e87d 100644 --- a/touch.c.v +++ b/touch.c.v @@ -13,19 +13,7 @@ pub type TouchID = i64 // `typedef Sint64 SDL_FingerID;` pub type FingerID = i64 -// Used as the device ID for mouse events simulated with touch input -pub const touch_mouseid = C.SDL_TOUCH_MOUSEID // ((Uint32)-1) - -// Used as the SDL_TouchID for touch events simulated with mouse input -pub const mouse_touch_id = C.SDL_MOUSE_TOUCHID // ((Sint64)-1) - -// TouchDeviceType is C.SDL_TouchDeviceType -pub enum TouchDeviceType { - invalid = C.SDL_TOUCH_DEVICE_INVALID // -1 - direct = C.SDL_TOUCH_DEVICE_DIRECT // touch screen with window-relative coordinates - indirect_absolute = C.SDL_TOUCH_DEVICE_INDIRECT_ABSOLUTE // trackpad with absolute device coordinates - indirect_relative = C.SDL_TOUCH_DEVICE_INDIRECT_RELATIVE // trackpad with screen cursor-relative coordinates -} +pub const touch_mouseid = C.SDL_TOUCH_MOUSEID @[typedef] pub struct C.SDL_Finger { @@ -41,19 +29,6 @@ pub type Finger = C.SDL_Finger fn C.SDL_GetNumTouchDevices() int // get_num_touch_devices gets the number of registered touch devices. -// -// On some platforms SDL first sees the touch device if it was actually used. -// Therefore SDL_GetNumTouchDevices() may return 0 although devices are -// available. After using all devices at least once the number will be -// correct. -// -// This was fixed for Android in SDL 2.0.1. -// -// returns the number of registered touch devices. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetTouchDevice pub fn get_num_touch_devices() int { return C.SDL_GetNumTouchDevices() } @@ -62,67 +37,21 @@ fn C.SDL_GetTouchDevice(index int) TouchID // C.SDL_TouchID -// get_touch_device gets the touch ID with the given index. -// -// `index` the touch device index -// returns the touch ID with the given index on success or 0 if the index is -// invalid; call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetNumTouchDevices +// get_touch_device gets the touch ID with the given index, or 0 if the index is invalid. pub fn get_touch_device(index int) TouchID { return C.SDL_GetTouchDevice(index) } -fn C.SDL_GetTouchName(index int) &char - -// get_touch_name gets the touch device name as reported from the driver or NULL if the index -// is invalid. -// -// NOTE This function is available since SDL 2.0.22. -pub fn get_touch_name(index int) &char { - return C.SDL_GetTouchName(index) -} - -fn C.SDL_GetTouchDeviceType(touch_id TouchID) TouchDeviceType - -// get_touch_device_type gets the type of the given touch device. -// -// NOTE This function is available since SDL 2.0.10. -pub fn get_touch_device_type(touch_id TouchID) TouchDeviceType { - return unsafe { TouchDeviceType(int(C.SDL_GetTouchDeviceType(touch_id))) } -} - fn C.SDL_GetNumTouchFingers(touch_id TouchID) int // get_num_touch_fingers gets the number of active fingers for a given touch device. -// -// `touchID` the ID of a touch device -// returns the number of active fingers for a given touch device on success -// or 0 on failure; call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetTouchFinger pub fn get_num_touch_fingers(touch_id TouchID) int { return C.SDL_GetNumTouchFingers(touch_id) } fn C.SDL_GetTouchFinger(touch_id TouchID, index int) &C.SDL_Finger -// get_touch_finger gets the finger object for specified touch device ID and finger index. -// -// The returned resource is owned by SDL and should not be deallocated. -// -// `touchID` the ID of the requested touch device -// `index` the index of the requested finger -// returns a pointer to the SDL_Finger object or NULL if no object at the -// given ID and index could be found. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_RecordGesture +// get_touch_finger gets the finger object of the given touch, with the given index. pub fn get_touch_finger(touch_id TouchID, index int) &Finger { return C.SDL_GetTouchFinger(touch_id, index) } diff --git a/ttf/c.c.v b/ttf/c.c.v index ed3ad1e7..7387aa02 100644 --- a/ttf/c.c.v +++ b/ttf/c.c.v @@ -17,12 +17,12 @@ $if !windows { } $if x64 { - #flag windows -L @VMODROOT/thirdparty/SDL2_ttf-2.0.15/lib/x64 + #flag windows -L @VMODROOT/thirdparty/SDL2_ttf-2.0.14/lib/x64 } $else { - #flag windows -L @VMODROOT/thirdparty/SDL2_ttf-2.0.15/lib/x86 + #flag windows -L @VMODROOT/thirdparty/SDL2_ttf-2.0.14/lib/x86 } -#flag windows -I @VMODROOT/thirdparty/SDL2_ttf-2.0.15/include +#flag windows -I @VMODROOT/thirdparty/SDL2_ttf-2.0.14/include #flag windows -lSDL2_ttf #include diff --git a/ttf/ttf.c.v b/ttf/ttf.c.v index 78bd5756..b2c3d096 100644 --- a/ttf/ttf.c.v +++ b/ttf/ttf.c.v @@ -12,31 +12,11 @@ pub const major_version = C.SDL_TTF_MAJOR_VERSION // 2 pub const minor_version = C.SDL_TTF_MINOR_VERSION // 0 -pub const patchlevel = C.SDL_TTF_PATCHLEVEL // 15 +pub const patchlevel = C.SDL_TTF_PATCHLEVEL // 14 // This macro can be used to fill a version structure with the compile-time // version of the SDL_ttf library. -fn C.SDL_TTF_VERSION(v &sdl.Version) - -// ttf_version macro is used to fill a version structure with the compile-time -// version of the SDL_ttf library. -pub fn ttf_version(v &sdl.Version) { - C.SDL_TTF_VERSION(v) -} - -fn C.SDL_TTF_COMPILEDVERSION() int - -// compiledversion is the version number macro for the current SDL_ttf version. -pub fn compiledversion() int { - return C.SDL_VERSIONNUM(ttf.major_version, ttf.minor_version, ttf.patchlevel) -} - -pub fn C.SDL_TTF_VERSION_ATLEAST(x int, y int, z int) bool - -// ttf_version_atleast macro evaluates to true if compiled with SDL_ttf at least X.Y.Z. -pub fn ttf_version_atleast(x int, y int, z int) bool { - return C.SDL_TTF_VERSION_ATLEAST(x, y, z) -} +pub fn C.SDL_TTF_VERSION(v &sdl.Version) fn C.TTF_Linked_Version() &C.SDL_version pub fn linked_version() &sdl.Version { diff --git a/v.mod b/v.mod index eb7181a4..41ea5729 100644 --- a/v.mod +++ b/v.mod @@ -1,7 +1,7 @@ Module { name: 'sdl' description: 'V SDL2 wrapper' - version: '2.30.0' + version: '2.0.8' license: 'MIT' repo_url: 'https://github.com/vlang/sdl' dependencies: [] diff --git a/version.c.v b/version.c.v index 174ea86b..e52651c0 100644 --- a/version.c.v +++ b/version.c.v @@ -9,11 +9,11 @@ module sdl pub const major_version = C.SDL_MAJOR_VERSION // 2 -pub const minor_version = C.SDL_MINOR_VERSION // 30 +pub const minor_version = C.SDL_MINOR_VERSION // 0 -pub const patchlevel = C.SDL_PATCHLEVEL // 0 +pub const patchlevel = C.SDL_PATCHLEVEL // 8 -// Version is information about the version of SDL in use. +// Version is information of the version of SDL in use. // // Represents the library's version as three levels: major revision // (increments with massive changes, additions, and enhancements), @@ -62,22 +62,10 @@ pub fn version(mut ver Version) { (1,2,3) -> (1203) ``` */ -// // This assumes that there will never be more than 100 patchlevels. -// -// In versions higher than 2.9.0, the minor version overflows into -// the thousands digit: for example, 2.23.0 is encoded as 4300, -// and 2.255.99 would be encoded as 25799. -// This macro will not be available in SDL 3.x. pub fn C.SDL_VERSIONNUM(x int, y int, z int) int // SDL_COMPILEDVERSION is the version number macro for the current SDL 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. -// -// Deprecated, use SDL_VERSION_ATLEAST or SDL_VERSION instead. pub fn C.SDL_COMPILEDVERSION() int // SDL_VERSION_ATLEAST macro will evaluate to true if compiled with SDL at least X.Y.Z. @@ -106,12 +94,7 @@ printf("But we linked against SDL version %d.%d.%d.\n", linked.major, linked.min // // This function may be called safely at any time, even before SDL_Init(). // -// `ver` the SDL_version structure that contains the version information -// -// NOTE This function is available since SDL 2.0.0. -// // See also: SDL_VERSION -// Seealso: SDL_GetRevision pub fn get_version(mut ver Version) { C.SDL_GetVersion(&ver) } @@ -120,55 +103,20 @@ fn C.SDL_GetRevision() &char // get_revision gets the code revision of SDL that is linked against your program. // -// This value is the revision of the code you are linked with and may be -// different from the code you are compiling with, which is found in the -// constant SDL_REVISION. -// -// The revision is arbitrary string (a hash value) uniquely identifying the +// Returns an arbitrary string (a hash value) uniquely identifying the // exact revision of the SDL library in use, and is only useful in comparing // against other revisions. It is NOT an incrementing number. -// -// If SDL wasn't built from a git repository with the appropriate tools, this -// will return an empty string. -// -// Prior to SDL 2.0.16, before development moved to GitHub, this returned a -// hash for a Mercurial repository. -// -// You shouldn't use this function for anything but logging it for debugging -// purposes. The string is not intended to be reliable in any way. -// -// returns an arbitrary string, uniquely identifying the exact revision of -// the SDL library in use. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetVersion pub fn get_revision() &char { return C.SDL_GetRevision() } fn C.SDL_GetRevisionNumber() int -// get_revision_number is an obsolete function, do not use. -// -// When SDL was hosted in a Mercurial repository, and was built carefully, -// this would return the revision number that the build was created from. This -// number was not reliable for several reasons, but more importantly, SDL is -// now hosted in a git repository, which does not offer numbers at all, only -// hashes. This function only ever returns zero now. Don't use it. -// -// Before SDL 2.0.16, this might have returned an unreliable, but non-zero -// number. -// -// deprecated Use SDL_GetRevision() instead; if SDL was carefully built, it -// will return a git hash. -// -// returns zero, always, in modern SDL releases. -// -// NOTE This function is available since SDL 2.0.0. +// get_revision_number gets the revision number of SDL that is linked against your program. // -// See also SDL_GetRevision -@[deprecated: 'Use SDL_GetRevision() instead; if SDL was carefully built, it will return a git hash.'] +// Returns a number uniquely identifying the exact revision of the SDL +// library in use. It is an incrementing number based on commits to +// hg.libsdl.org. pub fn get_revision_number() int { return C.SDL_GetRevisionNumber() } diff --git a/video.c.v b/video.c.v index 977615df..7bb82455 100644 --- a/video.c.v +++ b/video.c.v @@ -33,12 +33,9 @@ pub type DisplayMode = C.SDL_DisplayMode // See also: SDL_CreateWindow() // See also: SDL_CreateWindowFrom() // See also: SDL_DestroyWindow() -// See also: SDL_FlashWindow() // See also: SDL_GetWindowData() // See also: SDL_GetWindowFlags() // See also: SDL_GetWindowGrab() -// See also: SDL_GetWindowKeyboardGrab() -// See also: SDL_GetWindowMouseGrab() // See also: SDL_GetWindowPosition() // See also: SDL_GetWindowSize() // See also: SDL_GetWindowTitle() @@ -50,8 +47,6 @@ pub type DisplayMode = C.SDL_DisplayMode // See also: SDL_SetWindowData() // See also: SDL_SetWindowFullscreen() // See also: SDL_SetWindowGrab() -// See also: SDL_SetWindowKeyboardGrab() -// See also: SDL_SetWindowMouseGrab() // See also: SDL_SetWindowIcon() // See also: SDL_SetWindowPosition() // See also: SDL_SetWindowSize() @@ -80,22 +75,19 @@ pub enum WindowFlags { resizable = C.SDL_WINDOW_RESIZABLE // 0x00000020 window can be resized minimized = C.SDL_WINDOW_MINIMIZED // 0x00000040 window is minimized maximized = C.SDL_WINDOW_MAXIMIZED // 0x00000080 window is maximized - mouse_grabbed = C.SDL_WINDOW_MOUSE_GRABBED // 0x00000100 window has grabbed mouse input + input_grabbed = C.SDL_WINDOW_INPUT_GRABBED // 0x00000100 window has grabbed input focus input_focus = C.SDL_WINDOW_INPUT_FOCUS // 0x00000200 window has input focus mouse_focus = C.SDL_WINDOW_MOUSE_FOCUS // 0x00000400 window has mouse focus fullscreen_desktop = C.SDL_WINDOW_FULLSCREEN_DESKTOP // ( SDL_WINDOW_FULLSCREEN | 0x00001000 ) foreign = C.SDL_WINDOW_FOREIGN // 0x00000800 window not created by SDL allow_highdpi = C.SDL_WINDOW_ALLOW_HIGHDPI // 0x00002000 window should be created in high-DPI mode if supported. On macOS NSHighResolutionCapable must be set true in the application's Info.plist for this to have any effect. - mouse_capture = C.SDL_WINDOW_MOUSE_CAPTURE // 0x00004000 window has mouse captured (unrelated to MOUSE_GRABBED) + mouse_capture = C.SDL_WINDOW_MOUSE_CAPTURE // 0x00004000 window has mouse captured (unrelated to INPUT_GRABBED) always_on_top = C.SDL_WINDOW_ALWAYS_ON_TOP // 0x00008000 window should always be above others skip_taskbar = C.SDL_WINDOW_SKIP_TASKBAR // 0x00010000 window should not be added to the taskbar utility = C.SDL_WINDOW_UTILITY // 0x00020000 window should be treated as a utility window tooltip = C.SDL_WINDOW_TOOLTIP // 0x00040000 window should be treated as a tooltip popup_menu = C.SDL_WINDOW_POPUP_MENU // 0x00080000 window should be treated as a popup menu vulkan = C.SDL_WINDOW_VULKAN // 0x10000000 window usable for Vulkan surface - metal = C.SDL_WINDOW_METAL // 0x20000000 window usable for Metal view - // - input_grabbed = C.SDL_WINDOW_MOUSE_GRABBED // equivalent to SDL_WINDOW_MOUSE_GRABBED for compatibility } // Used to indicate that you don't care what the window position is. @@ -132,53 +124,23 @@ pub fn windowpos_iscentered(x u32) bool { // // WindowEventID is C.SDL_WindowEventID pub enum WindowEventID { - @none = C.SDL_WINDOWEVENT_NONE // Never used - shown = C.SDL_WINDOWEVENT_SHOWN // Window has been shown - hidden = C.SDL_WINDOWEVENT_HIDDEN // Window has been hidden - exposed = C.SDL_WINDOWEVENT_EXPOSED // Window has been exposed and should be redrawn - moved = C.SDL_WINDOWEVENT_MOVED // Window has been moved to data1, data2 - resized = C.SDL_WINDOWEVENT_RESIZED // Window has been resized to data1xdata2 - size_changed = C.SDL_WINDOWEVENT_SIZE_CHANGED // The window size has changed, either as a result of an API call or through the system or user changing the window size. - minimized = C.SDL_WINDOWEVENT_MINIMIZED // Window has been minimized - maximized = C.SDL_WINDOWEVENT_MAXIMIZED // Window has been maximized - restored = C.SDL_WINDOWEVENT_RESTORED // Window has been restored to normal size and position - enter = C.SDL_WINDOWEVENT_ENTER // Window has gained mouse focus - leave = C.SDL_WINDOWEVENT_LEAVE // Window has lost mouse focus - focus_gained = C.SDL_WINDOWEVENT_FOCUS_GAINED // Window has gained keyboard focus - focus_lost = C.SDL_WINDOWEVENT_FOCUS_LOST // Window has lost keyboard focus - close = C.SDL_WINDOWEVENT_CLOSE // The window manager requests that the window be closed - take_focus = C.SDL_WINDOWEVENT_TAKE_FOCUS // Window is being offered a focus (should SetWindowInputFocus() on itself or a subwindow, or ignore) - hit_test = C.SDL_WINDOWEVENT_HIT_TEST // Window had a hit test that wasn't SDL_HITTEST_NORMAL. - iccprof_changed = C.SDL_WINDOWEVENT_ICCPROF_CHANGED // The ICC profile of the window's display has changed. - display_changed = C.SDL_WINDOWEVENT_DISPLAY_CHANGED // Window has been moved to display data1. -} - -// DisplayEventID is an event subtype for display events -// DisplayEventID is C.SDL_DisplayEventID -pub enum DisplayEventID { - @none = C.SDL_DISPLAYEVENT_NONE // Never used - orientation = C.SDL_DISPLAYEVENT_ORIENTATION // Display orientation has changed to data1 - connected = C.SDL_DISPLAYEVENT_CONNECTED // Display has been added to the system - disconnected = C.SDL_DISPLAYEVENT_DISCONNECTED // Display has been removed from the system - moved = C.SDL_DISPLAYEVENT_MOVED // Display has changed position -} - -// Display orientation -// DisplayOrientation is C.SDL_DisplayOrientation -pub enum DisplayOrientation { - unknown = C.SDL_ORIENTATION_UNKNOWN // The display orientation can't be determined - landscape = C.SDL_ORIENTATION_LANDSCAPE // The display is in landscape mode, with the right side up, relative to portrait mode - landscape_flipped = C.SDL_ORIENTATION_LANDSCAPE_FLIPPED // The display is in landscape mode, with the left side up, relative to portrait mode - portrait = C.SDL_ORIENTATION_PORTRAIT // The display is in portrait mode - portrait_flipped = C.SDL_ORIENTATION_PORTRAIT_FLIPPED // The display is in portrait mode, upside down -} - -// Window flash operation -// FlashOperation is SDL_FlashOperation -pub enum FlashOperation { - cancel = C.SDL_FLASH_CANCEL // Cancel any window flash state - briefly = C.SDL_FLASH_BRIEFLY // Flash the window briefly to get attention - until_focused = C.SDL_FLASH_UNTIL_FOCUSED // Flash the window until it gets focus + @none = C.SDL_WINDOWEVENT_NONE // Never used + shown = C.SDL_WINDOWEVENT_SHOWN // Window has been shown + hidden = C.SDL_WINDOWEVENT_HIDDEN // Window has been hidden + exposed = C.SDL_WINDOWEVENT_EXPOSED // Window has been exposed and should be redrawn + moved = C.SDL_WINDOWEVENT_MOVED // Window has been moved to data1, data2 + resized = C.SDL_WINDOWEVENT_RESIZED // Window has been resized to data1xdata2 + size_changed = C.SDL_WINDOWEVENT_SIZE_CHANGED // The window size has changed, either as a result of an API call or through the system or user changing the window size. + minimized = C.SDL_WINDOWEVENT_MINIMIZED // Window has been minimized + maximized = C.SDL_WINDOWEVENT_MAXIMIZED // Window has been maximized + restored = C.SDL_WINDOWEVENT_RESTORED // Window has been restored to normal size and position + enter = C.SDL_WINDOWEVENT_ENTER // Window has gained mouse focus + leave = C.SDL_WINDOWEVENT_LEAVE // Window has lost mouse focus + focus_gained = C.SDL_WINDOWEVENT_FOCUS_GAINED // Window has gained keyboard focus + focus_lost = C.SDL_WINDOWEVENT_FOCUS_LOST // Window has lost keyboard focus + close = C.SDL_WINDOWEVENT_CLOSE // The window manager requests that the window be closed + take_focus = C.SDL_WINDOWEVENT_TAKE_FOCUS // Window is being offered a focus (should SetWindowInputFocus() on itself or a subwindow, or ignore) + hit_test = C.SDL_WINDOWEVENT_HIT_TEST // Window had a hit test that wasn't SDL_HITTEST_NORMAL. } // typedef void *SDL_GLContext; @@ -217,7 +179,6 @@ pub enum GLattr { context_release_behavior = C.SDL_GL_CONTEXT_RELEASE_BEHAVIOR context_reset_notification = C.SDL_GL_CONTEXT_RESET_NOTIFICATION context_no_error = C.SDL_GL_CONTEXT_NO_ERROR - floatbuffers = C.SDL_GL_FLOATBUFFERS } // GLprofile is C.SDL_GLprofile @@ -282,14 +243,9 @@ pub type HitTest = fn (win &Window, const_area &Point, data voidptr) HitTestResu fn C.SDL_GetNumVideoDrivers() int -// get_num_video_drivers gets the number of video drivers compiled into SDL. +// get_num_video_drivers gets the number of video drivers compiled into SDL // -// returns a number >= 1 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetVideoDriver +// See also: SDL_GetVideoDriver() pub fn get_num_video_drivers() int { return C.SDL_GetNumVideoDrivers() } @@ -298,15 +254,10 @@ fn C.SDL_GetVideoDriver(index int) &char // get_video_driver gets the name of a built in video driver. // -// The video drivers are presented in the order in which they are normally -// checked during initialization. -// -// `index` the index of a video driver -// returns the name of the video driver with the given **index**. +// NOTE The video drivers are presented in the order in which they are +// normally checked during initialization. // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetNumVideoDrivers +// See also: SDL_GetNumVideoDrivers() pub fn get_video_driver(index int) &char { return C.SDL_GetVideoDriver(index) } @@ -315,286 +266,145 @@ fn C.SDL_VideoInit(driver_name &char) int // video_init initializes the video subsystem, optionally specifying a video driver. // -// This function initializes the video subsystem, setting up a connection to -// the window manager, etc, and determines the available display modes and -// pixel formats, but does not initialize a window or graphics mode. -// -// If you use this function and you haven't used the SDL_INIT_VIDEO flag with -// either SDL_Init() or SDL_InitSubSystem(), you should call SDL_VideoQuit() -// before calling SDL_Quit(). +// `driver_name` Initialize a specific driver by name, or NULL for the +// default video driver. // -// It is safe to call this function multiple times. SDL_VideoInit() will call -// SDL_VideoQuit() itself if the video subsystem has already been initialized. +// returns 0 on success, -1 on error // -// You can use SDL_GetNumVideoDrivers() and SDL_GetVideoDriver() to find a -// specific `driver_name`. +// This function initializes the video subsystem; setting up a connection +// to the window manager, etc, and determines the available display modes +// and pixel formats, but does not initialize a window or graphics mode. // -// `driver_name` the name of a video driver to initialize, or NULL for -// the default driver -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetNumVideoDrivers -// See also: SDL_GetVideoDriver -// See also: SDL_InitSubSystem -// See also: SDL_VideoQuit +// See also: SDL_VideoQuit() pub fn video_init(driver_name &char) int { return C.SDL_VideoInit(driver_name) } fn C.SDL_VideoQuit() -// video_quit shuts down the video subsystem, if initialized with SDL_VideoInit(). +// video_quit shuts down the video subsystem. // // This function closes all windows, and restores the original video mode. // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_VideoInit +// See also: SDL_VideoInit() pub fn video_quit() { C.SDL_VideoQuit() } fn C.SDL_GetCurrentVideoDriver() &char -// get_current_video_driver gets the name of the currently initialized video driver. +// get_current_video_driver returns the name of the currently initialized video driver. // -// returns the name of the current video driver or NULL if no driver has been -// initialized. +// returns The name of the current video driver or NULL if no driver +// has been initialized // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetNumVideoDrivers -// See also: SDL_GetVideoDriver +// See also: SDL_GetNumVideoDrivers() +// See also: SDL_GetVideoDriver() pub fn get_current_video_driver() &char { return C.SDL_GetCurrentVideoDriver() } fn C.SDL_GetNumVideoDisplays() int -// get_num_video_displays gets the number of available video displays. -// -// returns a number >= 1 or a negative error code on failure; call -// SDL_GetError() for more information. +// get_num_video_displays returns the number of available video displays. // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetDisplayBounds +// See also: SDL_GetDisplayBounds() pub fn get_num_video_displays() int { return C.SDL_GetNumVideoDisplays() } fn C.SDL_GetDisplayName(display_index int) &char -// get_display_name gets the name of a display in UTF-8 encoding. -// -// `displayIndex` the index of display from which the name should be -// queried -// returns the name of a display or NULL for an invalid display index or -// failure; call SDL_GetError() for more information. +// get_display_name gets the name of a display in UTF-8 encoding // -// NOTE This function is available since SDL 2.0.0. +// returns The name of a display, or NULL for an invalid display index. // -// See also: SDL_GetNumVideoDisplays +// See also: SDL_GetNumVideoDisplays() pub fn get_display_name(display_index int) &char { return C.SDL_GetDisplayName(display_index) } fn C.SDL_GetDisplayBounds(display_index int, rect &C.SDL_Rect) int -// get_display_bounds gets the desktop area represented by a display. -// -// The primary display (`displayIndex` zero) is always located at 0,0. +// get_display_bounds gets the desktop area represented by a display, with the primary +// display located at 0,0 // -// `displayIndex` the index of the display to query -// `rect` the SDL_Rect structure filled in with the display bounds -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. +// returns 0 on success, or -1 if the index is out of range. // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetNumVideoDisplays +// See also: SDL_GetNumVideoDisplays() pub fn get_display_bounds(display_index int, rect &Rect) int { return C.SDL_GetDisplayBounds(display_index, rect) } -fn C.SDL_GetDisplayUsableBounds(display_index int, rect &C.SDL_Rect) int +fn C.SDL_GetDisplayDPI(display_index int, ddpi &f32, hdpi &f32, vdpi &f32) int -// get_display_usable_bounds gets the usable desktop area represented by a display. -// -// The primary display (`displayIndex` zero) is always located at 0,0. -// -// This is the same area as SDL_GetDisplayBounds() reports, but with portions -// reserved by the system removed. For example, on Apple's macOS, this -// subtracts the area occupied by the menu bar and dock. -// -// Setting a window to be fullscreen generally bypasses these unusable areas, -// so these are good guidelines for the maximum space available to a -// non-fullscreen window. -// -// The parameter `rect` is ignored if it is NULL. -// -// This function also returns -1 if the parameter `displayIndex` is out of -// range. +// get_display_dpi gets the dots/pixels-per-inch for a display // -// `displayIndex` the index of the display to query the usable bounds -// from -// `rect` the SDL_Rect structure filled in with the display bounds -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. +// NOTE Diagonal, horizontal and vertical DPI can all be optionally +// returned if the parameter is non-NULL. // -// NOTE This function is available since SDL 2.0.5. +// returns 0 on success, or -1 if no DPI information is available or the index is out of range. // -// See also: SDL_GetDisplayBounds -// See also: SDL_GetNumVideoDisplays -pub fn get_display_usable_bounds(display_index int, rect &Rect) int { - return C.SDL_GetDisplayUsableBounds(display_index, rect) -} - -fn C.SDL_GetDisplayDPI(display_index int, ddpi &f32, hdpi &f32, vdpi &f32) int - -// get_display_dpi gets the dots/pixels-per-inch for a display. -// -// Diagonal, horizontal and vertical DPI can all be optionally returned if the -// appropriate parameter is non-NULL. -// -// A failure of this function usually means that either no DPI information is -// available or the `displayIndex` is out of range. -// -// **WARNING**: This reports the DPI that the hardware reports, and it is not -// always reliable! It is almost always better to use SDL_GetWindowSize() to -// find the window size, which might be in logical points instead of pixels, -// and then SDL_GL_GetDrawableSize(), SDL_Vulkan_GetDrawableSize(), -// SDL_Metal_GetDrawableSize(), or SDL_GetRendererOutputSize(), and compare -// the two values to get an actual scaling value between the two. We will be -// rethinking how high-dpi details should be managed in SDL3 to make things -// more consistent, reliable, and clear. -// -// `displayIndex` the index of the display from which DPI information -// should be queried -// `ddpi` a pointer filled in with the diagonal DPI of the display; may -// be NULL -// `hdpi` a pointer filled in with the horizontal DPI of the display; may -// be NULL -// `vdpi` a pointer filled in with the vertical DPI of the display; may -// be NULL -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.4. -// -// See also: SDL_GetNumVideoDisplays +// See also: SDL_GetNumVideoDisplays() pub fn get_display_dpi(display_index int, ddpi &f32, hdpi &f32, vdpi &f32) int { return C.SDL_GetDisplayDPI(display_index, ddpi, hdpi, vdpi) } -fn C.SDL_GetDisplayOrientation(display_index int) DisplayOrientation +fn C.SDL_GetDisplayUsableBounds(display_index int, rect &C.SDL_Rect) int -// get_display_orientation gets the orientation of a display. +// get_display_usable_bounds gets the usable desktop area represented by a display, with the +// primary display located at 0,0 // -// `displayIndex` the index of the display to query -// returns The SDL_DisplayOrientation enum value of the display, or -// `SDL_ORIENTATION_UNKNOWN` if it isn't available. +// This is the same area as SDL_GetDisplayBounds() reports, but with portions +// reserved by the system removed. For example, on Mac OS X, this subtracts +// the area occupied by the menu bar and dock. +// +// Setting a window to be fullscreen generally bypasses these unusable areas, +// so these are good guidelines for the maximum space available to a +// non-fullscreen window. // -// NOTE This function is available since SDL 2.0.0. +// returns 0 on success, or -1 if the index is out of range. // -// See also: SDL_GetNumVideoDisplays -pub fn get_display_orientation(display_index int) DisplayOrientation { - return DisplayOrientation(C.SDL_GetDisplayOrientation(display_index)) +// See also: SDL_GetDisplayBounds() +// See also: SDL_GetNumVideoDisplays() +pub fn get_display_usable_bounds(display_index int, rect &Rect) int { + return C.SDL_GetDisplayUsableBounds(display_index, rect) } fn C.SDL_GetNumDisplayModes(display_index int) int -// get_num_display_modes gets the number of available display modes. -// -// The `displayIndex` needs to be in the range from 0 to -// SDL_GetNumVideoDisplays() - 1. +// get_num_display_modes returns the number of available display modes. // -// `displayIndex` the index of the display to query -// returns a number >= 1 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetDisplayMode -// See also: SDL_GetNumVideoDisplays +// See also: SDL_GetDisplayMode() pub fn get_num_display_modes(display_index int) int { return C.SDL_GetNumDisplayModes(display_index) } fn C.SDL_GetDisplayMode(display_index int, mode_index int, mode &C.SDL_DisplayMode) int -// get_display_mode gets information about a specific display mode. -// -// The display modes are sorted in this priority: -// -// - width -> largest to smallest -// - height -> largest to smallest -// - bits per pixel -> more colors to fewer colors -// - packed pixel layout -> largest to smallest -// - refresh rate -> highest to lowest +// get_display_mode fills in information about a specific display mode. // -// `displayIndex` the index of the display to query -// `modeIndex` the index of the display mode to query -// `mode` an SDL_DisplayMode structure filled in with the mode at -// `modeIndex` -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. +// NOTE The display modes are sorted in this priority: +// * bits per pixel -> more colors to fewer colors +// * width -> largest to smallest +// * height -> largest to smallest +// * refresh rate -> highest to lowest // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetNumDisplayModes +// See also: SDL_GetNumDisplayModes() pub fn get_display_mode(display_index int, mode_index int, mode &DisplayMode) int { return C.SDL_GetDisplayMode(display_index, mode_index, mode) } fn C.SDL_GetDesktopDisplayMode(display_index int, mode &C.SDL_DisplayMode) int -// get_desktop_display_mode gets information about the desktop's display mode. -// -// There's a difference between this function and SDL_GetCurrentDisplayMode() -// when SDL runs fullscreen and has changed the resolution. In that case this -// function will return the previous native display mode, and not the current -// display mode. -// -// `displayIndex` the index of the display to query -// `mode` an SDL_DisplayMode structure filled in with the current display -// mode -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetCurrentDisplayMode -// See also: SDL_GetDisplayMode -// See also: SDL_SetWindowDisplayMode +// get_desktop_display_mode fills in information about the desktop display mode. pub fn get_desktop_display_mode(display_index int, mode &DisplayMode) int { return C.SDL_GetDesktopDisplayMode(display_index, mode) } fn C.SDL_GetCurrentDisplayMode(display_index int, mode &C.SDL_DisplayMode) int -// get_current_display_mode gets information about the current display mode. -// -// There's a difference between this function and SDL_GetDesktopDisplayMode() -// when SDL runs fullscreen and has changed the resolution. In that case this -// function will return the current display mode, and not the previous native -// display mode. -// -// `displayIndex` the index of the display to query -// `mode` an SDL_DisplayMode structure filled in with the current display -// mode -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetDesktopDisplayMode -// See also: SDL_GetDisplayMode -// See also: SDL_GetNumVideoDisplays -// See also: SDL_SetWindowDisplayMode +// get_current_display_mode fills in information about the current display mode. pub fn get_current_display_mode(display_index int, mode &DisplayMode) int { return C.SDL_GetCurrentDisplayMode(display_index, mode) } @@ -603,146 +413,69 @@ fn C.SDL_GetClosestDisplayMode(display_index int, const_mode &C.SDL_DisplayMode, // get_closest_display_mode gets the closest match to the requested display mode. // -// The available display modes are scanned and `closest` is filled in with the -// closest mode matching the requested mode and returned. The mode format and -// refresh rate default to the desktop mode if they are set to 0. The modes -// are scanned with size being first priority, format being second priority, -// and finally checking the refresh rate. If all the available modes are too -// small, then NULL is returned. +// `displayIndex` The index of display from which mode should be queried. +// `mode` The desired display mode +// `closest` A pointer to a display mode to be filled in with the closest +// match of the available display modes. // -// `displayIndex` the index of the display to query -// `mode` an SDL_DisplayMode structure containing the desired display -// mode -// `closest` an SDL_DisplayMode structure filled in with the closest -// match of the available display modes -// returns the passed in value `closest` or NULL if no matching video mode -// was available; call SDL_GetError() for more information. +// returns The passed in value `closest`, or NULL if no matching video mode +// was available. // -// NOTE This function is available since SDL 2.0.0. +// The available display modes are scanned, and `closest` is filled in with the +// closest mode matching the requested mode and returned. The mode format and +// refresh_rate default to the desktop mode if they are 0. The modes are +// scanned with size being first priority, format being second priority, and +// finally checking the refresh_rate. If all the available modes are too +// small, then NULL is returned. // -// See also: SDL_GetDisplayMode -// See also: SDL_GetNumDisplayModes +// See also: SDL_GetNumDisplayModes() +// See also: SDL_GetDisplayMode() pub fn get_closest_display_mode(display_index int, const_mode &DisplayMode, closest &DisplayMode) &DisplayMode { return C.SDL_GetClosestDisplayMode(display_index, const_mode, closest) } -fn C.SDL_GetPointDisplayIndex(const_point &C.SDL_Point) int - -// get_point_display_index gets the index of the display containing a point -// -// `point` the point to query -// returns the index of the display containing the point or a negative error -// code on failure; call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.24.0. -// -// See also: SDL_GetDisplayBounds -// See also: SDL_GetNumVideoDisplays -pub fn get_point_display_index(const_point &Point) int { - return C.SDL_GetPointDisplayIndex(const_point) -} - -fn C.SDL_GetRectDisplayIndex(const_rect &C.SDL_Rect) int - -// get_rect_display_index gets the index of the display primarily containing a rect -// -// `rect` the rect to query -// returns the index of the display entirely containing the rect or closest -// to the center of the rect on success or a negative error code on -// failure; call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.24.0. -// -// See also: SDL_GetDisplayBounds -// See also: SDL_GetNumVideoDisplays -pub fn get_rect_display_index(const_rect &Rect) int { - return C.SDL_GetRectDisplayIndex(const_rect) -} - fn C.SDL_GetWindowDisplayIndex(window &C.SDL_Window) int -// get_window_display_index gets the index of the display associated with a window. -// -// `window` the window to query -// returns the index of the display containing the center of the window on -// success or a negative error code on failure; call SDL_GetError() -// for more information. -// -// NOTE This function is available since SDL 2.0.0. +// get_window_display_index gets the display index associated with a window. // -// See also: SDL_GetDisplayBounds -// See also: SDL_GetNumVideoDisplays +// returns the display index of the display containing the center of the +// window, or -1 on error. pub fn get_window_display_index(window &Window) int { return C.SDL_GetWindowDisplayIndex(window) } fn C.SDL_SetWindowDisplayMode(window &C.SDL_Window, const_mode &C.SDL_DisplayMode) int -// set_window_display_mode sets the display mode to use when a window is visible at fullscreen. +// set_window_display_mode sets the display mode used when a fullscreen window is visible. // -// This only affects the display mode used when the window is fullscreen. To -// change the window size when the window is not fullscreen, use -// SDL_SetWindowSize(). +// By default the window's dimensions and the desktop format and refresh rate +// are used. // -// `window` the window to affect -// `mode` the SDL_DisplayMode structure representing the mode to use, or -// NULL to use the window's dimensions and the desktop's format -// and refresh rate -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. +// `window` The window for which the display mode should be set. +// `mode` The mode to use, or NULL for the default mode. // -// NOTE This function is available since SDL 2.0.0. +// returns 0 on success, or -1 if setting the display mode failed. // -// See also: SDL_GetWindowDisplayMode -// See also: SDL_SetWindowFullscreen +// See also: SDL_GetWindowDisplayMode() +// See also: SDL_SetWindowFullscreen() pub fn set_window_display_mode(window &Window, const_mode &DisplayMode) int { return C.SDL_SetWindowDisplayMode(window, const_mode) } fn C.SDL_GetWindowDisplayMode(window &C.SDL_Window, mode &C.SDL_DisplayMode) int -// get_window_display_mode queries the display mode to use when a window is visible at fullscreen. +// get_window_display_mode fills in information about the display mode used when a fullscreen +// window is visible. // -// `window` the window to query -// `mode` an SDL_DisplayMode structure filled in with the fullscreen -// display mode -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_SetWindowDisplayMode -// See also: SDL_SetWindowFullscreen +// See also: SDL_SetWindowDisplayMode() +// See also: SDL_SetWindowFullscreen() pub fn get_window_display_mode(window &Window, mode &DisplayMode) int { return C.SDL_GetWindowDisplayMode(window, mode) } -fn C.SDL_GetWindowICCProfile(window &C.SDL_Window, size &usize) voidptr - -// get_window_icc_profile gets the raw ICC profile data for the screen the window is currently on. -// -// Data returned should be freed with SDL_free. -// -// `window` the window to query -// `size` the size of the ICC profile -// returns the raw ICC profile data on success or NULL on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.18. -pub fn get_window_icc_profile(window &Window, size &usize) voidptr { - return C.SDL_GetWindowICCProfile(window, size) -} - fn C.SDL_GetWindowPixelFormat(window &C.SDL_Window) u32 // get_window_pixel_format gets the pixel format associated with the window. -// -// `window` the window to query -// returns the pixel format of the window on success or -// SDL_PIXELFORMAT_UNKNOWN on failure; call SDL_GetError() for more -// information. -// -// NOTE This function is available since SDL 2.0.0. pub fn get_window_pixel_format(window &Window) u32 { return C.SDL_GetWindowPixelFormat(window) } @@ -751,42 +484,28 @@ fn C.SDL_CreateWindow(title &char, x int, y int, w int, h int, flags u32) &C.SDL // create_window creates a window with the specified position, dimensions, and flags. // -// `flags` may be any of the following OR'd together: -// -// - `SDL_WINDOW_FULLSCREEN`: fullscreen window -// - `SDL_WINDOW_FULLSCREEN_DESKTOP`: fullscreen window at desktop resolution -// - `SDL_WINDOW_OPENGL`: window usable with an OpenGL context -// - `SDL_WINDOW_VULKAN`: window usable with a Vulkan instance -// - `SDL_WINDOW_METAL`: window usable with a Metal instance -// - `SDL_WINDOW_HIDDEN`: window is not visible -// - `SDL_WINDOW_BORDERLESS`: no window decoration -// - `SDL_WINDOW_RESIZABLE`: window can be resized -// - `SDL_WINDOW_MINIMIZED`: window is minimized -// - `SDL_WINDOW_MAXIMIZED`: window is maximized -// - `SDL_WINDOW_INPUT_GRABBED`: window has grabbed input focus -// - `SDL_WINDOW_ALLOW_HIGHDPI`: window should be created in high-DPI mode if -// supported (>= SDL 2.0.1) -// -// `SDL_WINDOW_SHOWN` is ignored by SDL_CreateWindow(). The SDL_Window is -// implicitly shown if SDL_WINDOW_HIDDEN is not set. `SDL_WINDOW_SHOWN` may be -// queried later using SDL_GetWindowFlags(). -// -// On Apple's macOS, you **must** set the NSHighResolutionCapable Info.plist -// property to YES, otherwise you will not receive a High-DPI OpenGL canvas. -// -// If the window is created with the `SDL_WINDOW_ALLOW_HIGHDPI` flag, its size +// `title` The title of the window, in UTF-8 encoding. +// `x` The x position of the window, ::SDL_WINDOWPOS_CENTERED, or +// ::SDL_WINDOWPOS_UNDEFINED. +// `y` The y position of the window, ::SDL_WINDOWPOS_CENTERED, or +// ::SDL_WINDOWPOS_UNDEFINED. +// `w` The width of the window, in screen coordinates. +// `h` The height of the window, in screen coordinates. +// `flags` The flags for the window, a mask of any of the following: +// ::SDL_WINDOW_FULLSCREEN, ::SDL_WINDOW_OPENGL, +// ::SDL_WINDOW_HIDDEN, ::SDL_WINDOW_BORDERLESS, +// ::SDL_WINDOW_RESIZABLE, ::SDL_WINDOW_MAXIMIZED, +// ::SDL_WINDOW_MINIMIZED, ::SDL_WINDOW_INPUT_GRABBED, +// ::SDL_WINDOW_ALLOW_HIGHDPI, ::SDL_WINDOW_VULKAN. +// +// returns The created window, or NULL if window creation failed. +// +// If the window is created with the SDL_WINDOW_ALLOW_HIGHDPI flag, its size // in pixels may differ from its size in screen coordinates on platforms with -// high-DPI support (e.g. iOS and macOS). Use SDL_GetWindowSize() to query the -// client area's size in screen coordinates, and SDL_GL_GetDrawableSize() or -// SDL_GetRendererOutputSize() to query the drawable size in pixels. Note that -// when this flag is set, the drawable size can vary after the window is -// created and should be queried after major window events such as when the -// window is resized or moved between displays. -// -// If the window is set fullscreen, the width and height parameters `w` and -// `h` will not be used. However, invalid size parameters (e.g. too large) may -// still fail. Window size is actually limited to 16384 x 16384 for all -// platforms at window creation. +// high-DPI support (e.g. iOS and Mac OS X). Use SDL_GetWindowSize() to query +// the client area's size in screen coordinates, and SDL_GL_GetDrawableSize(), +// SDL_Vulkan_GetDrawableSize(), or SDL_GetRendererOutputSize() to query the +// drawable size in pixels. // // If the window is created with any of the SDL_WINDOW_OPENGL or // SDL_WINDOW_VULKAN flags, then the corresponding LoadLibrary function @@ -796,28 +515,13 @@ fn C.SDL_CreateWindow(title &char, x int, y int, w int, h int, flags u32) &C.SDL // If SDL_WINDOW_VULKAN is specified and there isn't a working Vulkan driver, // SDL_CreateWindow() will fail because SDL_Vulkan_LoadLibrary() will fail. // -// If SDL_WINDOW_METAL is specified on an OS that does not support Metal, -// SDL_CreateWindow() will fail. -// -// On non-Apple devices, SDL requires you to either not link to the Vulkan -// loader or link to a dynamic library version. This limitation may be removed -// in a future version of SDL. -// -// `title` the title of the window, in UTF-8 encoding -// `x` the x position of the window, `SDL_WINDOWPOS_CENTERED`, or -// `SDL_WINDOWPOS_UNDEFINED` -// `y` the y position of the window, `SDL_WINDOWPOS_CENTERED`, or -// `SDL_WINDOWPOS_UNDEFINED` -// `w` the width of the window, in screen coordinates -// `h` the height of the window, in screen coordinates -// `flags` 0, or one or more SDL_WindowFlags OR'd together -// returns the window that was created or NULL on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. +// NOTE On non-Apple devices, SDL requires you to either not link to the +// Vulkan loader or link to a dynamic library version. This limitation +// may be removed in a future version of SDL. // -// See also: SDL_CreateWindowFrom -// See also: SDL_DestroyWindow +// See also: SDL_DestroyWindow() +// See also: SDL_GL_LoadLibrary() +// See also: SDL_Vulkan_LoadLibrary() pub fn create_window(title &char, x int, y int, w int, h int, flags u32) &Window { return C.SDL_CreateWindow(title, x, y, w, h, flags) } @@ -826,55 +530,25 @@ fn C.SDL_CreateWindowFrom(data voidptr) &C.SDL_Window // create_window_from creates an SDL window from an existing native window. // -// In some cases (e.g. OpenGL) and on some platforms (e.g. Microsoft Windows) -// the hint `SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT` needs to be configured -// before using SDL_CreateWindowFrom(). -// -// `data` a pointer to driver-dependent window creation data, typically -// your native window cast to a void* -// returns the window that was created or NULL on failure; call -// SDL_GetError() for more information. +// `data` A pointer to driver-dependent window creation data // -// NOTE This function is available since SDL 2.0.0. +// returns The created window, or NULL if window creation failed. // -// See also: SDL_CreateWindow -// See also: SDL_DestroyWindow +// See also: SDL_DestroyWindow() pub fn create_window_from(data voidptr) &Window { return C.SDL_CreateWindowFrom(data) } fn C.SDL_GetWindowID(window &C.SDL_Window) u32 -// get_window_id gets the numeric ID of a window. -// -// The numeric ID is what SDL_WindowEvent references, and is necessary to map -// these events to specific SDL_Window objects. -// -// `window` the window to query -// returns the ID of the window on success or 0 on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetWindowFromID +// get_window_id gets the numeric ID of a window, for logging purposes. pub fn get_window_id(window &Window) u32 { return C.SDL_GetWindowID(window) } fn C.SDL_GetWindowFromID(id u32) &C.SDL_Window -// get_window_from_id gets a window from a stored ID. -// -// The numeric ID is what SDL_WindowEvent references, and is necessary to map -// these events to specific SDL_Window objects. -// -// `id` the ID of the window -// returns the window associated with `id` or NULL if it doesn't exist; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetWindowID +// get_window_from_id gets a window from a stored ID, or NULL if it doesn't exist. pub fn get_window_from_id(id u32) &Window { return C.SDL_GetWindowFromID(id) } @@ -882,50 +556,24 @@ pub fn get_window_from_id(id u32) &Window { fn C.SDL_GetWindowFlags(window &C.SDL_Window) u32 // get_window_flags gets the window flags. -// -// `window` the window to query -// returns a mask of the SDL_WindowFlags associated with `window` -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_CreateWindow -// See also: SDL_HideWindow -// See also: SDL_MaximizeWindow -// See also: SDL_MinimizeWindow -// See also: SDL_SetWindowFullscreen -// See also: SDL_SetWindowGrab -// See also: SDL_ShowWindow pub fn get_window_flags(window &Window) u32 { return C.SDL_GetWindowFlags(window) } fn C.SDL_SetWindowTitle(window &C.SDL_Window, const_title &char) -// set_window_title sets the title of a window. -// -// This string is expected to be in UTF-8 encoding. +// set_window_title sets the title of a window, in UTF-8 format. // -// `window` the window to change -// `title` the desired window title in UTF-8 format -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetWindowTitle +// See also: SDL_GetWindowTitle() pub fn set_window_title(window &Window, const_title &char) { C.SDL_SetWindowTitle(window, const_title) } fn C.SDL_GetWindowTitle(window &C.SDL_Window) &char -// get_window_title gets the title of a window. -// -// `window` the window to query -// returns the title of the window in UTF-8 format or "" if there is no -// title. -// -// NOTE This function is available since SDL 2.0.0. +// get_window_title gets the title of a window, in UTF-8 format. // -// See also: SDL_SetWindowTitle +// See also: SDL_SetWindowTitle() pub fn get_window_title(window &Window) &char { return C.SDL_GetWindowTitle(window) } @@ -934,10 +582,8 @@ fn C.SDL_SetWindowIcon(window &C.SDL_Window, icon &C.SDL_Surface) // set_window_icon sets the icon for a window. // -// `window` the window to change -// `icon` an SDL_Surface structure containing the icon for the window -// -// NOTE This function is available since SDL 2.0.0. +// `window` The window for which the icon should be set. +// `icon` The icon for the window. pub fn set_window_icon(window &Window, icon &Surface) { C.SDL_SetWindowIcon(window, icon) } @@ -946,16 +592,15 @@ fn C.SDL_SetWindowData(window &C.SDL_Window, const_name &char, userdata voidptr) // set_window_data associates an arbitrary named pointer with a window. // -// `name` is case-sensitive. +// `window` The window to associate with the pointer. +// `name` The name of the pointer. +// `userdata` The associated pointer. // -// `window` the window to associate with the pointer -// `name` the name of the pointer -// `userdata` the associated pointer -// returns the previous value associated with `name`. +// returns The previous value associated with 'name' // -// NOTE This function is available since SDL 2.0.0. +// NOTE The name is case-sensitive. // -// See also: SDL_GetWindowData +// See also: SDL_GetWindowData() pub fn set_window_data(window &Window, const_name &char, userdata voidptr) voidptr { return C.SDL_SetWindowData(window, const_name, userdata) } @@ -964,13 +609,12 @@ fn C.SDL_GetWindowData(window &C.SDL_Window, const_name &char) voidptr // get_window_data retrieves the data pointer associated with a window. // -// `window` the window to query -// `name` the name of the pointer -// returns the value associated with `name`. +// `window` The window to query. +// `name` The name of the pointer. // -// NOTE This function is available since SDL 2.0.0. +// returns The value associated with 'name' // -// See also: SDL_SetWindowData +// See also: SDL_SetWindowData() pub fn get_window_data(window &Window, const_name &char) voidptr { return C.SDL_GetWindowData(window, const_name) } @@ -979,17 +623,15 @@ fn C.SDL_SetWindowPosition(window &C.SDL_Window, x int, y int) // set_window_position sets the position of a window. // -// The window coordinate origin is the upper left of the display. -// -// `window` the window to reposition -// `x` the x coordinate of the window in screen coordinates, or -// `SDL_WINDOWPOS_CENTERED` or `SDL_WINDOWPOS_UNDEFINED` -// `y` the y coordinate of the window in screen coordinates, or -// `SDL_WINDOWPOS_CENTERED` or `SDL_WINDOWPOS_UNDEFINED` +// `window` The window to reposition. +// `x` The x coordinate of the window in screen coordinates, or +// ::SDL_WINDOWPOS_CENTERED or ::SDL_WINDOWPOS_UNDEFINED. +// `y` The y coordinate of the window in screen coordinates, or +// ::SDL_WINDOWPOS_CENTERED or ::SDL_WINDOWPOS_UNDEFINED. // -// NOTE This function is available since SDL 2.0.0. +// NOTE The window coordinate origin is the upper left of the display. // -// See also: SDL_GetWindowPosition +// See also: SDL_GetWindowPosition() pub fn set_window_position(window &Window, x int, y int) { C.SDL_SetWindowPosition(window, x, y) } @@ -998,18 +640,13 @@ fn C.SDL_GetWindowPosition(window &C.SDL_Window, x &int, y &int) // get_window_position gets the position of a window. // -// If you do not need the value for one of the positions a NULL may be passed -// in the `x` or `y` parameter. -// -// `window` the window to query -// `x` a pointer filled in with the x position of the window, in screen -// coordinates, may be NULL -// `y` a pointer filled in with the y position of the window, in screen -// coordinates, may be NULL -// -// NOTE This function is available since SDL 2.0.0. +// `window` The window to query. +// `x` Pointer to variable for storing the x position, in screen +// coordinates. May be NULL. +// `y` Pointer to variable for storing the y position, in screen +// coordinates. May be NULL. // -// See also: SDL_SetWindowPosition +// See also: SDL_SetWindowPosition() pub fn get_window_position(window &Window, x &int, y &int) { C.SDL_GetWindowPosition(window, x, y) } @@ -1018,24 +655,20 @@ fn C.SDL_SetWindowSize(window &C.SDL_Window, w int, h int) // set_window_size sets the size of a window's client area. // -// The window size in screen coordinates may differ from the size in pixels, -// if the window was created with `SDL_WINDOW_ALLOW_HIGHDPI` on a platform -// with high-dpi support (e.g. iOS or macOS). Use SDL_GL_GetDrawableSize() or -// SDL_GetRendererOutputSize() to get the real client area size in pixels. -// -// Fullscreen windows automatically match the size of the display mode, and -// you should use SDL_SetWindowDisplayMode() to change their size. +// `window` The window to resize. +// `w` The width of the window, in screen coordinates. Must be >0. +// `h` The height of the window, in screen coordinates. Must be >0. // -// `window` the window to change -// `w` the width of the window in pixels, in screen coordinates, must be -// > 0 -// `h` the height of the window in pixels, in screen coordinates, must be -// > 0 +// NOTE Fullscreen windows automatically match the size of the display mode, +// and you should use SDL_SetWindowDisplayMode() to change their size. // -// NOTE This function is available since SDL 2.0.0. +// The window size in screen coordinates may differ from the size in pixels, if +// the window was created with SDL_WINDOW_ALLOW_HIGHDPI on a platform with +// high-dpi support (e.g. iOS or OS X). Use SDL_GL_GetDrawableSize() or +// SDL_GetRendererOutputSize() to get the real client area size in pixels. // -// See also: SDL_GetWindowSize -// See also: SDL_SetWindowDisplayMode +// See also: SDL_GetWindowSize() +// See also: SDL_SetWindowDisplayMode() pub fn set_window_size(window &Window, w int, h int) { C.SDL_SetWindowSize(window, w, h) } @@ -1044,26 +677,18 @@ fn C.SDL_GetWindowSize(window &C.SDL_Window, w &int, h &int) // get_window_size gets the size of a window's client area. // -// NULL can safely be passed as the `w` or `h` parameter if the width or -// height value is not desired. -// -// The window size in screen coordinates may differ from the size in pixels, -// if the window was created with `SDL_WINDOW_ALLOW_HIGHDPI` on a platform -// with high-dpi support (e.g. iOS or macOS). Use SDL_GL_GetDrawableSize(), -// SDL_Vulkan_GetDrawableSize(), or SDL_GetRendererOutputSize() to get the -// real client area size in pixels. +// `window` The window to query. +// `w` Pointer to variable for storing the width, in screen +// coordinates. May be NULL. +// `h` Pointer to variable for storing the height, in screen +// coordinates. May be NULL. // -// `window` the window to query the width and height from -// `w` a pointer filled in with the width of the window, in screen -// coordinates, may be NULL -// `h` a pointer filled in with the height of the window, in screen -// coordinates, may be NULL -// -// NOTE This function is available since SDL 2.0.0. +// The window size in screen coordinates may differ from the size in pixels, if +// the window was created with SDL_WINDOW_ALLOW_HIGHDPI on a platform with +// high-dpi support (e.g. iOS or OS X). Use SDL_GL_GetDrawableSize() or +// SDL_GetRendererOutputSize() to get the real client area size in pixels. // -// See also: SDL_GL_GetDrawableSize -// See also: SDL_Vulkan_GetDrawableSize -// See also: SDL_SetWindowSize +// See also: SDL_SetWindowSize() pub fn get_window_size(window &Window, w &int, h &int) { C.SDL_GetWindowSize(window, w, h) } @@ -1072,72 +697,34 @@ fn C.SDL_GetWindowBordersSize(window &C.SDL_Window, top &int, left &int, bottom // get_window_borders_size gets the size of a window's borders (decorations) around the client area. // -// Note: If this function fails (returns -1), the size values will be -// initialized to 0, 0, 0, 0 (if a non-NULL pointer is provided), as if the -// window in question was borderless. -// -// Note: This function may fail on systems where the window has not yet been -// decorated by the display server (for example, immediately after calling -// SDL_CreateWindow). It is recommended that you wait at least until the -// window has been presented and composited, so that the window system has a -// chance to decorate the window and provide the border dimensions to SDL. -// -// This function also returns -1 if getting the information is not supported. -// -// `window` the window to query the size values of the border -// (decorations) from -// `top` pointer to variable for storing the size of the top border; NULL -// is permitted -// `left` pointer to variable for storing the size of the left border; -// NULL is permitted -// `bottom` pointer to variable for storing the size of the bottom -// border; NULL is permitted -// `right` pointer to variable for storing the size of the right border; -// NULL is permitted -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.5. -// -// See also: SDL_GetWindowSize -pub fn get_window_borders_size(window &Window, top &int, left &int, bottom &int, right &int) int { - return C.SDL_GetWindowBordersSize(window, top, left, bottom, right) -} - -fn C.SDL_GetWindowSizeInPixels(window &C.SDL_Window, w &int, h &int) - -// get_window_size_in_pixels gets the size of a window in pixels. -// -// This may differ from SDL_GetWindowSize() if we're rendering to a high-DPI -// drawable, i.e. the window was created with `SDL_WINDOW_ALLOW_HIGHDPI` on a -// platform with high-DPI support (Apple calls this "Retina"), and not -// disabled by the `SDL_HINT_VIDEO_HIGHDPI_DISABLED` hint. -// -// `window` the window from which the drawable size should be queried -// `w` a pointer to variable for storing the width in pixels, may be NULL -// `h` a pointer to variable for storing the height in pixels, may be -// NULL +// `window` The window to query. +// `top` Pointer to variable for storing the size of the top border. NULL is permitted. +// `left` Pointer to variable for storing the size of the left border. NULL is permitted. +// `bottom` Pointer to variable for storing the size of the bottom border. NULL is permitted. +// `right` Pointer to variable for storing the size of the right border. NULL is permitted. // -// NOTE This function is available since SDL 2.26.0. +// returns 0 on success, or -1 if getting this information is not supported. // -// See also: SDL_CreateWindow -// See also: SDL_GetWindowSize -pub fn get_window_size_in_pixels(window &Window, w &int, h &int) { - C.SDL_GetWindowSizeInPixels(window, w, h) +// NOTE if this function fails (returns -1), the size values will be +// initialized to 0, 0, 0, 0 (if a non-NULL pointer is provided), as +// if the window in question was borderless. +pub fn get_window_borders_size(window &Window, top &int, left &int, bottom &int, right &int) int { + return C.SDL_GetWindowBordersSize(window, top, left, bottom, right) } fn C.SDL_SetWindowMinimumSize(window &C.SDL_Window, min_w int, min_h int) // set_window_minimum_size sets the minimum size of a window's client area. // -// `window` the window to change -// `min_w` the minimum width of the window in pixels -// `min_h` the minimum height of the window in pixels +// `window` The window to set a new minimum size. +// `min_w` The minimum width of the window, must be >0 +// `min_h` The minimum height of the window, must be >0 // -// NOTE This function is available since SDL 2.0.0. +// NOTE You can't change the minimum size of a fullscreen window, it +// automatically matches the size of the display mode. // -// See also: SDL_GetWindowMinimumSize -// See also: SDL_SetWindowMaximumSize +// See also: SDL_GetWindowMinimumSize() +// See also: SDL_SetWindowMaximumSize() pub fn set_window_minimum_size(window &Window, min_w int, min_h int) { C.SDL_SetWindowMinimumSize(window, min_w, min_h) } @@ -1146,16 +733,12 @@ fn C.SDL_GetWindowMinimumSize(window &C.SDL_Window, w &int, h &int) // get_window_minimum_size gets the minimum size of a window's client area. // -// `window` the window to query -// `w` a pointer filled in with the minimum width of the window, may be -// NULL -// `h` a pointer filled in with the minimum height of the window, may be -// NULL +// `window` The window to query. +// `w` Pointer to variable for storing the minimum width, may be NULL +// `h` Pointer to variable for storing the minimum height, may be NULL // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetWindowMaximumSize -// See also: SDL_SetWindowMinimumSize +// See also: SDL_GetWindowMaximumSize() +// See also: SDL_SetWindowMinimumSize() pub fn get_window_minimum_size(window &Window, w &int, h &int) { C.SDL_GetWindowMinimumSize(window, w, h) } @@ -1164,14 +747,15 @@ fn C.SDL_SetWindowMaximumSize(window &C.SDL_Window, max_w int, max_h int) // set_window_maximum_size sets the maximum size of a window's client area. // -// `window` the window to change -// `max_w` the maximum width of the window in pixels -// `max_h` the maximum height of the window in pixels +// `window` The window to set a new maximum size. +// `max_w` The maximum width of the window, must be >0 +// `max_h` The maximum height of the window, must be >0 // -// NOTE This function is available since SDL 2.0.0. +// NOTE You can't change the maximum size of a fullscreen window, it +// automatically matches the size of the display mode. // -// See also: SDL_GetWindowMaximumSize -// See also: SDL_SetWindowMinimumSize +// See also: SDL_GetWindowMaximumSize() +// See also: SDL_SetWindowMinimumSize() pub fn set_window_maximum_size(window &Window, max_w int, max_h int) { C.SDL_SetWindowMaximumSize(window, max_w, max_h) } @@ -1180,16 +764,12 @@ fn C.SDL_GetWindowMaximumSize(window &C.SDL_Window, w &int, h &int) // get_window_maximum_size gets the maximum size of a window's client area. // -// `window` the window to query -// `w` a pointer filled in with the maximum width of the window, may be -// NULL -// `h` a pointer filled in with the maximum height of the window, may be -// NULL -// -// NOTE This function is available since SDL 2.0.0. +// `window` The window to query. +// `w` Pointer to variable for storing the maximum width, may be NULL +// `h` Pointer to variable for storing the maximum height, may be NULL // -// See also: SDL_GetWindowMinimumSize -// See also: SDL_SetWindowMaximumSize +// See also: SDL_GetWindowMinimumSize() +// See also: SDL_SetWindowMaximumSize() pub fn get_window_maximum_size(window &Window, w &int, h &int) { C.SDL_GetWindowMaximumSize(window, w, h) } @@ -1198,18 +778,16 @@ fn C.SDL_SetWindowBordered(window &C.SDL_Window, bordered bool) // set_window_bordered sets the border state of a window. // -// This will add or remove the window's `SDL_WINDOW_BORDERLESS` flag and add -// or remove the border from the actual window. This is a no-op if the +// This will add or remove the window's SDL_WINDOW_BORDERLESS flag and +// add or remove the border from the actual window. This is a no-op if the // window's border already matches the requested state. // -// You can't change the border state of a fullscreen window. +// `window` The window of which to change the border state. +// `bordered` SDL_FALSE to remove border, SDL_TRUE to add border. // -// `window` the window of which to change the border state -// `bordered` SDL_FALSE to remove border, SDL_TRUE to add border +// NOTE You can't change the border state of a fullscreen window. // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetWindowFlags +// See also: SDL_GetWindowFlags() pub fn set_window_bordered(window &Window, bordered bool) { C.SDL_SetWindowBordered(window, bordered) } @@ -1218,50 +796,25 @@ fn C.SDL_SetWindowResizable(window &C.SDL_Window, resizable bool) // set_window_resizable sets the user-resizable state of a window. // -// This will add or remove the window's `SDL_WINDOW_RESIZABLE` flag and -// allow/disallow user resizing of the window. This is a no-op if the window's -// resizable state already matches the requested state. -// -// You can't change the resizable state of a fullscreen window. +// This will add or remove the window's SDL_WINDOW_RESIZABLE flag and +// allow/disallow user resizing of the window. This is a no-op if the +// window's resizable state already matches the requested state. // -// `window` the window of which to change the resizable state -// `resizable` SDL_TRUE to allow resizing, SDL_FALSE to disallow +// `window` The window of which to change the resizable state. +// `resizable` SDL_TRUE to allow resizing, SDL_FALSE to disallow. // -// NOTE This function is available since SDL 2.0.5. +// NOTE You can't change the resizable state of a fullscreen window. // -// See also: SDL_GetWindowFlags +// See also: SDL_GetWindowFlags() pub fn set_window_resizable(window &Window, resizable bool) { C.SDL_SetWindowResizable(window, resizable) } -fn C.SDL_SetWindowAlwaysOnTop(window &C.SDL_Window, on_top bool) - -// set_window_always_on_top sets the window to always be above the others. -// -// This will add or remove the window's `SDL_WINDOW_ALWAYS_ON_TOP` flag. This -// will bring the window to the front and keep the window above the rest. -// -// `window` The window of which to change the always on top state -// `on_top` SDL_TRUE to set the window always on top, SDL_FALSE to -// disable -// -// NOTE This function is available since SDL 2.0.16. -// -// See also: SDL_GetWindowFlags -pub fn set_window_always_on_top(window &C.SDL_Window, on_top bool) { - C.SDL_SetWindowAlwaysOnTop(window, on_top) -} - fn C.SDL_ShowWindow(window &C.SDL_Window) // show_window shows a window. // -// `window` the window to show -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_HideWindow -// See also: SDL_RaiseWindow +// See also: SDL_HideWindow() pub fn show_window(window &Window) { C.SDL_ShowWindow(window) } @@ -1270,11 +823,7 @@ fn C.SDL_HideWindow(window &C.SDL_Window) // hide_window hides a window. // -// `window` the window to hide -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_ShowWindow +// See also: SDL_ShowWindow() pub fn hide_window(window &Window) { C.SDL_HideWindow(window) } @@ -1282,10 +831,6 @@ pub fn hide_window(window &Window) { fn C.SDL_RaiseWindow(window &C.SDL_Window) // raise_window raises a window above other windows and set the input focus. -// -// NOTE This function is available since SDL 2.0.0. -// -// `window` the window to raise pub fn raise_window(window &Window) { C.SDL_RaiseWindow(window) } @@ -1294,12 +839,7 @@ fn C.SDL_MaximizeWindow(window &C.SDL_Window) // maximize_window makes a window as large as possible. // -// `window` the window to maximize -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_MinimizeWindow -// See also: SDL_RestoreWindow +// See also: SDL_RestoreWindow() pub fn maximize_window(window &Window) { C.SDL_MaximizeWindow(window) } @@ -1308,12 +848,7 @@ fn C.SDL_MinimizeWindow(window &C.SDL_Window) // minimize_window minimizes a window to an iconic representation. // -// `window` the window to minimize -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_MaximizeWindow -// See also: SDL_RestoreWindow +// See also: SDL_RestoreWindow() pub fn minimize_window(window &Window) { C.SDL_MinimizeWindow(window) } @@ -1322,12 +857,8 @@ fn C.SDL_RestoreWindow(window &C.SDL_Window) // restore_window restores the size and position of a minimized or maximized window. // -// `window` the window to restore -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_MaximizeWindow -// See also: SDL_MinimizeWindow +// See also: SDL_MaximizeWindow() +// See also: SDL_MinimizeWindow() pub fn restore_window(window &Window) { C.SDL_RestoreWindow(window) } @@ -1336,62 +867,27 @@ fn C.SDL_SetWindowFullscreen(window &C.SDL_Window, flags u32) int // set_window_fullscreen sets a window's fullscreen state. // -// `flags` may be `SDL_WINDOW_FULLSCREEN`, for "real" fullscreen with a -// videomode change; `SDL_WINDOW_FULLSCREEN_DESKTOP` for "fake" fullscreen -// that takes the size of the desktop; and 0 for windowed mode. -// -// `window` the window to change -// `flags` `SDL_WINDOW_FULLSCREEN`, `SDL_WINDOW_FULLSCREEN_DESKTOP` or 0 -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. +// returns 0 on success, or -1 if setting the display mode failed. // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetWindowDisplayMode -// See also: SDL_SetWindowDisplayMode +// See also: SDL_SetWindowDisplayMode() +// See also: SDL_GetWindowDisplayMode() pub fn set_window_fullscreen(window &Window, flags u32) int { return C.SDL_SetWindowFullscreen(window, flags) } -fn C.SDL_HasWindowSurface(window &C.SDL_Window) bool - -// has_window_surface returna whether the window has a surface associated with it. -// -// returns SDL_TRUE if there is a surface associated with the window, or -// SDL_FALSE otherwise. -// -// NOTE This function is available since SDL 2.28.0. -// -// See also: SDL_GetWindowSurface -pub fn has_window_surface(window &Window) bool { - return C.SDL_HasWindowSurface(window) -} - fn C.SDL_GetWindowSurface(window &C.SDL_Window) &C.SDL_Surface // get_window_surface gets the SDL surface associated with the window. // -// A new surface will be created with the optimal format for the window, if -// necessary. This surface will be freed when the window is destroyed. Do not -// free this surface. -// -// This surface will be invalidated if the window is resized. After resizing a -// window this function must be called again to return a valid surface. +// returns The window's framebuffer surface, or NULL on error. // -// You may not combine this with 3D or the rendering API on this window. +// A new surface will be created with the optimal format for the window, +// if necessary. This surface will be freed when the window is destroyed. // -// This function is affected by `SDL_HINT_FRAMEBUFFER_ACCELERATION`. +// NOTE You may not combine this with 3D or the rendering API on this window. // -// `window` the window to query -// returns the surface associated with the window, or NULL on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_DestroyWindowSurface -// See also: SDL_HasWindowSurface -// See also: SDL_UpdateWindowSurface -// See also: SDL_UpdateWindowSurfaceRects +// See also: SDL_UpdateWindowSurface() +// See also: SDL_UpdateWindowSurfaceRects() pub fn get_window_surface(window &Window) &Surface { return C.SDL_GetWindowSurface(window) } @@ -1400,302 +896,97 @@ fn C.SDL_UpdateWindowSurface(window &C.SDL_Window) int // update_window_surface copies the window surface to the screen. // -// This is the function you use to reflect any changes to the surface on the -// screen. -// -// This function is equivalent to the SDL 1.2 API SDL_Flip(). -// -// `window` the window to update -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. +// returns 0 on success, or -1 on error. // -// See also: SDL_GetWindowSurface -// See also: SDL_UpdateWindowSurfaceRects +// See also: SDL_GetWindowSurface() +// See also: SDL_UpdateWindowSurfaceRects() pub fn update_window_surface(window &Window) int { return C.SDL_UpdateWindowSurface(window) } fn C.SDL_UpdateWindowSurfaceRects(window &C.SDL_Window, const_rects &C.SDL_Rect, numconst_rects int) int -// update_window_surface_rects copies areas of the window surface to the screen. +// update_window_surface_rects copies a number of rectangles on the window surface to the screen. // -// This is the function you use to reflect changes to portions of the surface -// on the screen. +// returns 0 on success, or -1 on error. // -// This function is equivalent to the SDL 1.2 API SDL_UpdateRects(). -// -// Note that this function will update _at least_ the rectangles specified, -// but this is only intended as an optimization; in practice, this might -// update more of the screen (or all of the screen!), depending on what -// method SDL uses to send pixels to the system. -// -// `window` the window to update -// `rects` an array of SDL_Rect structures representing areas of the -// surface to copy, in pixels -// `numrects` the number of rectangles -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetWindowSurface -// See also: SDL_UpdateWindowSurface +// See also: SDL_GetWindowSurface() +// See also: SDL_UpdateWindowSurface() pub fn update_window_surface_rects(window &Window, const_rects &Rect, numconst_rects int) int { return C.SDL_UpdateWindowSurfaceRects(window, const_rects, numconst_rects) } -fn C.SDL_DestroyWindowSurface(window &C.SDL_Window) int - -// destroy_window_surface destroys the surface associated with the window. -// -// `window` the window to update -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.28.0. -// -// See also: SDL_GetWindowSurface -// See also: SDL_HasWindowSurface -pub fn destroy_window_surface(window &Window) int { - return C.SDL_DestroyWindowSurface(window) -} - fn C.SDL_SetWindowGrab(window &C.SDL_Window, grabbed bool) // set_window_grab sets a window's input grab mode. // -// When input is grabbed, the mouse is confined to the window. This function -// will also grab the keyboard if `SDL_HINT_GRAB_KEYBOARD` is set. To grab the -// keyboard without also grabbing the mouse, use SDL_SetWindowKeyboardGrab(). +// `window` The window for which the input grab mode should be set. +// `grabbed` This is SDL_TRUE to grab input, and SDL_FALSE to release input. // -// If the caller enables a grab while another window is currently grabbed, the -// other window loses its grab in favor of the caller's window. +// If the caller enables a grab while another window is currently grabbed, +// the other window loses its grab in favor of the caller's window. // -// `window` the window for which the input grab mode should be set -// `grabbed` SDL_TRUE to grab input or SDL_FALSE to release input -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetGrabbedWindow -// See also: SDL_GetWindowGrab +// See also: SDL_GetWindowGrab() pub fn set_window_grab(window &Window, grabbed bool) { C.SDL_SetWindowGrab(window, grabbed) } -fn C.SDL_SetWindowKeyboardGrab(window &C.SDL_Window, grabbed bool) - -// set_window_keyboard_grab sets a window's keyboard grab mode. -// -// Keyboard grab enables capture of system keyboard shortcuts like Alt+Tab or -// the Meta/Super key. Note that not all system keyboard shortcuts can be -// captured by applications (one example is Ctrl+Alt+Del on Windows). -// -// This is primarily intended for specialized applications such as VNC clients -// or VM frontends. Normal games should not use keyboard grab. -// -// When keyboard grab is enabled, SDL will continue to handle Alt+Tab when the -// window is full-screen to ensure the user is not trapped in your -// application. If you have a custom keyboard shortcut to exit fullscreen -// mode, you may suppress this behavior with -// `SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED`. -// -// If the caller enables a grab while another window is currently grabbed, the -// other window loses its grab in favor of the caller's window. -// -// `window` The window for which the keyboard grab mode should be set. -// `grabbed` This is SDL_TRUE to grab keyboard, and SDL_FALSE to release. -// -// NOTE This function is available since SDL 2.0.16. -// -// See also: SDL_GetWindowKeyboardGrab -// See also: SDL_SetWindowMouseGrab -// See also: SDL_SetWindowGrab -pub fn set_window_keyboard_grab(window &Window, grabbed bool) { - C.SDL_SetWindowKeyboardGrab(window, grabbed) -} - -fn C.SDL_SetWindowMouseGrab(window &C.SDL_Window, grabbed bool) - -// set_window_mouse_grab sets a window's mouse grab mode. -// -// Mouse grab confines the mouse cursor to the window. -// -// `window` The window for which the mouse grab mode should be set. -// `grabbed` This is SDL_TRUE to grab mouse, and SDL_FALSE to release. -// -// NOTE This function is available since SDL 2.0.16. -// -// See also: SDL_GetWindowMouseGrab -// See also: SDL_SetWindowKeyboardGrab -// See also: SDL_SetWindowGrab -pub fn set_window_mouse_grab(window &Window, grabbed bool) { - C.SDL_SetWindowMouseGrab(window, grabbed) -} - fn C.SDL_GetWindowGrab(window &C.SDL_Window) bool // get_window_grab gets a window's input grab mode. // -// `window` the window to query -// returns SDL_TRUE if input is grabbed, SDL_FALSE otherwise. +// returns This returns SDL_TRUE if input is grabbed, and SDL_FALSE otherwise. // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_SetWindowGrab +// See also: SDL_SetWindowGrab() pub fn get_window_grab(window &Window) bool { return C.SDL_GetWindowGrab(window) } -fn C.SDL_GetWindowKeyboardGrab(window &C.SDL_Window) bool - -// get_window_keyboard_grab gets a window's keyboard grab mode. -// -// `window` the window to query -// returns SDL_TRUE if keyboard is grabbed, and SDL_FALSE otherwise. -// -// NOTE This function is available since SDL 2.0.16. -// -// See also: SDL_SetWindowKeyboardGrab -// See also: SDL_GetWindowGrab -pub fn get_window_keyboard_grab(window &Window) bool { - return C.SDL_GetWindowKeyboardGrab(window) -} - -fn C.SDL_GetWindowMouseGrab(window &C.SDL_Window) bool - -// get_window_mouse_grab gets a window's mouse grab mode. -// -// `window` the window to query -// returns SDL_TRUE if mouse is grabbed, and SDL_FALSE otherwise. -// -// NOTE This function is available since SDL 2.0.16. -// -// See also: SDL_SetWindowKeyboardGrab -// See also: SDL_GetWindowGrab -pub fn get_window_mouse_grab(window &Window) bool { - return C.SDL_GetWindowMouseGrab(window) -} - fn C.SDL_GetGrabbedWindow() &C.SDL_Window // get_grabbed_window gets the window that currently has an input grab enabled. // -// returns the window if input is grabbed or NULL otherwise. -// -// NOTE This function is available since SDL 2.0.4. +// returns This returns the window if input is grabbed, and NULL otherwise. // -// See also: SDL_GetWindowGrab -// See also: SDL_SetWindowGrab +// See also: SDL_SetWindowGrab() pub fn get_grabbed_window() &Window { return C.SDL_GetGrabbedWindow() } -fn C.SDL_SetWindowMouseRect(window &C.SDL_Window, const_rect &C.SDL_Rect) int - -// set_window_mouse_rect confines the cursor to the specified area of a window. -// -// Note that this does NOT grab the cursor, it only defines the area a cursor -// is restricted to when the window has mouse focus. -// -// `window` The window that will be associated with the barrier. -// `rect` A rectangle area in window-relative coordinates. If NULL the -// barrier for the specified window will be destroyed. -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.18. -// -// See also: SDL_GetWindowMouseRect -// See also: SDL_SetWindowMouseGrab -pub fn set_window_mouse_rect(window &Window, const_rect &Rect) int { - return C.SDL_SetWindowMouseRect(window, const_rect) -} - -fn C.SDL_GetWindowMouseRect(window &C.SDL_Window) &C.SDL_Rect - -// get_window_mouse_rect gets the mouse confinement rectangle of a window. -// -// `window` The window to query -// returns A pointer to the mouse confinement rectangle of a window, or NULL -// if there isn't one. -// -// NOTE This function is available since SDL 2.0.18. -// -// See also: SDL_SetWindowMouseRect -pub fn get_window_mouse_rect(window &Window) &Rect { - return C.SDL_GetWindowMouseRect(window) -} - fn C.SDL_SetWindowBrightness(window &C.SDL_Window, brightness f32) int -// set_window_brightness sets the brightness (gamma multiplier) for a given window's display. -// -// Despite the name and signature, this method sets the brightness of the -// entire display, not an individual window. A window is considered to be -// owned by the display that contains the window's center pixel. (The index of -// this display can be retrieved using SDL_GetWindowDisplayIndex().) The -// brightness set will not follow the window if it is moved to another -// display. +// set_window_brightness sets the brightness (gamma correction) for a window. // -// Many platforms will refuse to set the display brightness in modern times. -// You are better off using a shader to adjust gamma during rendering, or -// something similar. +// returns 0 on success, or -1 if setting the brightness isn't supported. // -// `window` the window used to select the display whose brightness will -// be changed -// `brightness` the brightness (gamma multiplier) value to set where 0.0 -// is completely dark and 1.0 is normal brightness -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetWindowBrightness -// See also: SDL_SetWindowGammaRamp +// See also: SDL_GetWindowBrightness() +// See also: SDL_SetWindowGammaRamp() pub fn set_window_brightness(window &Window, brightness f32) int { return C.SDL_SetWindowBrightness(window, brightness) } fn C.SDL_GetWindowBrightness(window &C.SDL_Window) f32 -// get_window_brightness gets the brightness (gamma multiplier) for a given window's display. -// -// Despite the name and signature, this method retrieves the brightness of the -// entire display, not an individual window. A window is considered to be -// owned by the display that contains the window's center pixel. (The index of -// this display can be retrieved using SDL_GetWindowDisplayIndex().) +// get_window_brightness gets the brightness (gamma correction) for a window. // -// `window` the window used to select the display whose brightness will -// be queried -// returns the brightness for the display where 0.0 is completely dark and -// 1.0 is normal brightness. +// returns The last brightness value passed to SDL_SetWindowBrightness() // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_SetWindowBrightness +// See also: SDL_SetWindowBrightness() pub fn get_window_brightness(window &Window) f32 { return C.SDL_GetWindowBrightness(window) } fn C.SDL_SetWindowOpacity(window &C.SDL_Window, opacity f32) int -// set_window_opacity sets the opacity for a window. -// -// The parameter `opacity` will be clamped internally between 0.0f -// (transparent) and 1.0f (opaque). +// set_window_opacity sets the opacity for a window // -// This function also returns -1 if setting the opacity isn't supported. +// `window` The window which will be made transparent or opaque +// `opacity` Opacity (0.0f - transparent, 1.0f - opaque) This will be +// clamped internally between 0.0f and 1.0f. // -// `window` the window which will be made transparent or opaque -// `opacity` the opacity value (0.0f - transparent, 1.0f - opaque) -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. +// returns 0 on success, or -1 if setting the opacity isn't supported. // -// NOTE This function is available since SDL 2.0.5. -// -// See also: SDL_GetWindowOpacity +// See also: SDL_GetWindowOpacity() pub fn set_window_opacity(window &Window, opacity f32) int { return C.SDL_SetWindowOpacity(window, opacity) } @@ -1707,112 +998,81 @@ fn C.SDL_GetWindowOpacity(window &C.SDL_Window, out_opacity &f32) int // If transparency isn't supported on this platform, opacity will be reported // as 1.0f without error. // -// The parameter `opacity` is ignored if it is NULL. -// -// This function also returns -1 if an invalid window was provided. -// -// `window` the window to get the current opacity value from -// `out_opacity` the float filled in (0.0f - transparent, 1.0f - opaque) -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. +// `window` The window in question. +// `out_opacity` Opacity (0.0f - transparent, 1.0f - opaque) // -// NOTE This function is available since SDL 2.0.5. +// returns 0 on success, or -1 on error (invalid window, etc). // -// See also: SDL_SetWindowOpacity +// See also: SDL_SetWindowOpacity() pub fn get_window_opacity(window &Window, out_opacity &f32) int { return C.SDL_GetWindowOpacity(window, out_opacity) } fn C.SDL_SetWindowModalFor(modal_window &C.SDL_Window, parent_window &C.SDL_Window) int -// set_window_modal_for sets the window as a modal for another window. +// set_window_modal_for sets the window as a modal for another window (TODO: reconsider this function and/or its name) // -// `modal_window` the window that should be set modal -// `parent_window` the parent window for the modal window -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. +// `modal_window` The window that should be modal +// `parent_window` The parent window // -// NOTE This function is available since SDL 2.0.5. +// returns 0 on success, or -1 otherwise. pub fn set_window_modal_for(modal_window &Window, parent_window &Window) int { return C.SDL_SetWindowModalFor(modal_window, parent_window) } fn C.SDL_SetWindowInputFocus(window &C.SDL_Window) int -// set_window_input_focus explicitlys set input focus to the window. +// set_window_input_focus explicitly sets input focus to the window. // // You almost certainly want SDL_RaiseWindow() instead of this function. Use -// this with caution, as you might give focus to a window that is completely +// this with caution, as you might give focus to a window that's completely // obscured by other windows. // -// `window` the window that should get the input focus -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. +// `window` The window that should get the input focus // -// NOTE This function is available since SDL 2.0.5. -// -// See also: SDL_RaiseWindow +// returns 0 on success, or -1 otherwise. +// See also: SDL_RaiseWindow() pub fn set_window_input_focus(window &Window) int { return C.SDL_SetWindowInputFocus(window) } fn C.SDL_SetWindowGammaRamp(window &C.SDL_Window, const_red &u16, const_green &u16, const_blue &u16) int -// set_window_gamma_ramp sets the gamma ramp for the display that owns a given window. -// -// Set the gamma translation table for the red, green, and blue channels of -// the video hardware. Each table is an array of 256 16-bit quantities, -// representing a mapping between the input and output for that channel. The -// input is the index into the array, and the output is the 16-bit gamma value -// at that index, scaled to the output color precision. -// -// Despite the name and signature, this method sets the gamma ramp of the -// entire display, not an individual window. A window is considered to be -// owned by the display that contains the window's center pixel. (The index of -// this display can be retrieved using SDL_GetWindowDisplayIndex().) The gamma -// ramp set will not follow the window if it is moved to another display. -// -// `window` the window used to select the display whose gamma ramp will -// be changed -// `red` a 256 element array of 16-bit quantities representing the -// translation table for the red channel, or NULL -// `green` a 256 element array of 16-bit quantities representing the -// translation table for the green channel, or NULL -// `blue` a 256 element array of 16-bit quantities representing the -// translation table for the blue channel, or NULL -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GetWindowGammaRamp +// set_window_gamma_ramp sets the gamma ramp for a window. +// +// `window` The window for which the gamma ramp should be set. +// `red` The translation table for the red channel, or NULL. +// `green` The translation table for the green channel, or NULL. +// `blue` The translation table for the blue channel, or NULL. +// +// returns 0 on success, or -1 if gamma ramps are unsupported. +// +// Set the gamma translation table for the red, green, and blue channels +// of the video hardware. Each table is an array of 256 16-bit quantities, +// representing a mapping between the input and output for that channel. +// The input is the index into the array, and the output is the 16-bit +// gamma value at that index, scaled to the output color precision. +// +// See also: SDL_GetWindowGammaRamp() pub fn set_window_gamma_ramp(window &Window, const_red &u16, const_green &u16, const_blue &u16) int { return C.SDL_SetWindowGammaRamp(window, const_red, const_green, const_blue) } fn C.SDL_GetWindowGammaRamp(window &C.SDL_Window, red &u16, green &u16, blue &u16) int -// get_window_gamma_ramp gets the gamma ramp for a given window's display. -// -// Despite the name and signature, this method retrieves the gamma ramp of the -// entire display, not an individual window. A window is considered to be -// owned by the display that contains the window's center pixel. (The index of -// this display can be retrieved using SDL_GetWindowDisplayIndex().) +// get_window_gamma_ramp gets the gamma ramp for a window. // -// `window` the window used to select the display whose gamma ramp will -// be queried -// `red` a 256 element array of 16-bit quantities filled in with the -// translation table for the red channel, or NULL -// `green` a 256 element array of 16-bit quantities filled in with the -// translation table for the green channel, or NULL -// `blue` a 256 element array of 16-bit quantities filled in with the -// translation table for the blue channel, or NULL -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. +// `window` The window from which the gamma ramp should be queried. +// `red` A pointer to a 256 element array of 16-bit quantities to hold +// the translation table for the red channel, or NULL. +// `green` A pointer to a 256 element array of 16-bit quantities to hold +// the translation table for the green channel, or NULL. +// `blue` A pointer to a 256 element array of 16-bit quantities to hold +// the translation table for the blue channel, or NULL. // -// NOTE This function is available since SDL 2.0.0. +// returns 0 on success, or -1 if gamma ramps are unsupported. // -// See also: SDL_SetWindowGammaRamp +// See also: SDL_SetWindowGammaRamp() pub fn get_window_gamma_ramp(window &Window, red &u16, green &u16, blue &u16) int { return C.SDL_GetWindowGammaRamp(window, red, green, blue) } @@ -1824,16 +1084,16 @@ fn C.SDL_SetWindowHitTest(window &C.SDL_Window, callback C.SDL_HitTest, callback // Normally windows are dragged and resized by decorations provided by the // system window manager (a title bar, borders, etc), but for some apps, it // makes sense to drag them from somewhere else inside the window itself; for -// example, one might have a borderless window that wants to be draggable from -// any part, or simulate its own title bar, etc. +// example, one might have a borderless window that wants to be draggable +// from any part, or simulate its own title bar, etc. // -// This function lets the app provide a callback that designates pieces of a -// given window as special. This callback is run during event processing if we -// need to tell the OS to treat a region of the window specially; the use of -// this callback is known as "hit testing." +// This function lets the app provide a callback that designates pieces of +// a given window as special. This callback is run during event processing +// if we need to tell the OS to treat a region of the window specially; the +// use of this callback is known as "hit testing." // -// Mouse input may not be delivered to your application if it is within a -// special area; the OS will often apply that input to moving the window or +// Mouse input may not be delivered to your application if it is within +// a special area; the OS will often apply that input to moving the window or // resizing the window and not deliver it to the application. // // Specifying NULL for a callback disables hit-testing. Hit-testing is @@ -1843,101 +1103,54 @@ fn C.SDL_SetWindowHitTest(window &C.SDL_Window, callback C.SDL_HitTest, callback // unconditionally, even if you're attempting to disable hit-testing. // // Your callback may fire at any time, and its firing does not indicate any -// specific behavior (for example, on Windows, this certainly might fire when -// the OS is deciding whether to drag your window, but it fires for lots of -// other reasons, too, some unrelated to anything you probably care about _and -// when the mouse isn't actually at the location it is testing_). Since this -// can fire at any time, you should try to keep your callback efficient, -// devoid of allocations, etc. -// -// `window` the window to set hit-testing on -// `callback` the function to call when doing a hit-test -// `callback_data` an app-defined void pointer passed to **callback** -// returns 0 on success or -1 on error (including unsupported); call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.4. +// specific behavior (for example, on Windows, this certainly might fire +// when the OS is deciding whether to drag your window, but it fires for lots +// of other reasons, too, some unrelated to anything you probably care about +// _and when the mouse isn't actually at the location it is testing_). +// Since this can fire at any time, you should try to keep your callback +// efficient, devoid of allocations, etc. +// +// `window` The window to set hit-testing on. +// `callback` The callback to call when doing a hit-test. +// `callback_data` An app-defined void pointer passed to the callback. +// returns 0 on success, -1 on error (including unsupported). pub fn set_window_hit_test(window &Window, callback HitTest, callback_data voidptr) int { return C.SDL_SetWindowHitTest(window, C.SDL_HitTest(callback), callback_data) } -fn C.SDL_FlashWindow(window &C.SDL_Window, operation C.SDL_FlashOperation) int - -// flash_window requests a window to demand attention from the user. -// -// `window` the window to be flashed -// `operation` the flash operation -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.16. -pub fn flash_window(window &Window, operation FlashOperation) int { - return C.SDL_FlashWindow(window, C.SDL_FlashOperation(operation)) -} - fn C.SDL_DestroyWindow(window &C.SDL_Window) // destroy_window destroys a window. -// -// If `window` is NULL, this function will return immediately after setting -// the SDL error message to "Invalid window". See SDL_GetError(). -// -// `window` the window to destroy -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_CreateWindow -// See also: SDL_CreateWindowFrom pub fn destroy_window(window &Window) { C.SDL_DestroyWindow(window) } fn C.SDL_IsScreenSaverEnabled() bool -// is_screen_saver_enabled checks whether the screensaver is currently enabled. -// -// The screensaver is disabled by default since SDL 2.0.2. Before SDL 2.0.2 -// the screensaver was enabled by default. +// is_screen_saver_enabled returns whether the screensaver is currently enabled (default off). // -// The default can also be changed using `SDL_HINT_VIDEO_ALLOW_SCREENSAVER`. -// -// returns SDL_TRUE if the screensaver is enabled, SDL_FALSE if it is -// disabled. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_DisableScreenSaver -// See also: SDL_EnableScreenSaver +// See also: SDL_EnableScreenSaver() +// See also: SDL_DisableScreenSaver() pub fn is_screen_saver_enabled() bool { return C.SDL_IsScreenSaverEnabled() } fn C.SDL_EnableScreenSaver() -// enable_screen_saver allows the screen to be blanked by a screen saver. +// enable_screen_saver allows the screen to be blanked by a screensaver // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_DisableScreenSaver -// See also: SDL_IsScreenSaverEnabled +// See also: SDL_IsScreenSaverEnabled() +// See also: SDL_DisableScreenSaver() pub fn enable_screen_saver() { C.SDL_EnableScreenSaver() } fn C.SDL_DisableScreenSaver() -// disable_screen_saver prevents the screen from being blanked by a screen saver. -// -// If you disable the screensaver, it is automatically re-enabled when SDL -// quits. +// disable_screen_saver prevents the screen from being blanked by a screensaver // -// The screensaver is disabled by default since SDL 2.0.2. Before SDL 2.0.2 -// the screensaver was enabled by default. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_EnableScreenSaver -// See also: SDL_IsScreenSaverEnabled +// See also: SDL_IsScreenSaverEnabled() +// See also: SDL_EnableScreenSaver() pub fn disable_screen_saver() { C.SDL_DisableScreenSaver() } @@ -1948,79 +1161,29 @@ pub fn disable_screen_saver() { fn C.SDL_GL_LoadLibrary(path &char) int -// gl_load_library dynamicallys load an OpenGL library. +// gl_load_library dynamically load an OpenGL library. // -// This should be done after initializing the video driver, but before -// creating any OpenGL windows. If no OpenGL library is loaded, the default -// library will be loaded upon creation of the first OpenGL window. +// `path` The platform dependent OpenGL library name, or NULL to open the +// default OpenGL library. // -// If you do this, you need to retrieve all of the GL functions used in your -// program from the dynamic library using SDL_GL_GetProcAddress(). +// returns 0 on success, or -1 if the library couldn't be loaded. // -// `path` the platform dependent OpenGL library name, or NULL to open the -// default OpenGL library -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. +// This should be done after initializing the video driver, but before +// creating any OpenGL windows. If no OpenGL library is loaded, the default +// library will be loaded upon creation of the first OpenGL window. // -// NOTE This function is available since SDL 2.0.0. +// NOTE If you do this, you need to retrieve all of the GL functions used in +// your program from the dynamic library using SDL_GL_GetProcAddress(). // -// See also: SDL_GL_GetProcAddress -// See also: SDL_GL_UnloadLibrary +// See also: SDL_GL_GetProcAddress() +// See also: SDL_GL_UnloadLibrary() pub fn gl_load_library(path &char) int { return C.SDL_GL_LoadLibrary(path) } fn C.SDL_GL_GetProcAddress(proc &char) voidptr -// gl_get_proc_address gets an OpenGL function by name. -// -// If the GL library is loaded at runtime with SDL_GL_LoadLibrary(), then all -// GL functions must be retrieved this way. Usually this is used to retrieve -// function pointers to OpenGL extensions. -// -// There are some quirks to looking up OpenGL functions that require some -// extra care from the application. If you code carefully, you can handle -// these quirks without any platform-specific code, though: -// -// - On Windows, function pointers are specific to the current GL context; -// this means you need to have created a GL context and made it current -// before calling SDL_GL_GetProcAddress(). If you recreate your context or -// create a second context, you should assume that any existing function -// pointers aren't valid to use with it. This is (currently) a -// Windows-specific limitation, and in practice lots of drivers don't suffer -// this limitation, but it is still the way the wgl API is documented to -// work and you should expect crashes if you don't respect it. Store a copy -// of the function pointers that comes and goes with context lifespan. -// - On X11, function pointers returned by this function are valid for any -// context, and can even be looked up before a context is created at all. -// This means that, for at least some common OpenGL implementations, if you -// look up a function that doesn't exist, you'll get a non-NULL result that -// is _NOT_ safe to call. You must always make sure the function is actually -// available for a given GL context before calling it, by checking for the -// existence of the appropriate extension with SDL_GL_ExtensionSupported(), -// or verifying that the version of OpenGL you're using offers the function -// as core functionality. -// - Some OpenGL drivers, on all platforms, *will* return NULL if a function -// isn't supported, but you can't count on this behavior. Check for -// extensions you use, and if you get a NULL anyway, act as if that -// extension wasn't available. This is probably a bug in the driver, but you -// can code defensively for this scenario anyhow. -// - Just because you're on Linux/Unix, don't assume you'll be using X11. -// Next-gen display servers are waiting to replace it, and may or may not -// make the same promises about function pointers. -// - OpenGL function pointers must be declared `APIENTRY` as in the example -// code. This will ensure the proper calling convention is followed on -// platforms where this matters (Win32) thereby avoiding stack corruption. -// -// `proc` the name of an OpenGL function -// returns a pointer to the named OpenGL function. The returned pointer -// should be cast to the appropriate function signature. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GL_ExtensionSupported -// See also: SDL_GL_LoadLibrary -// See also: SDL_GL_UnloadLibrary +// gl_get_proc_address gets the address of an OpenGL function. pub fn gl_get_proc_address(proc &char) voidptr { return C.SDL_GL_GetProcAddress(proc) } @@ -2029,44 +1192,22 @@ fn C.SDL_GL_UnloadLibrary() // gl_unload_library unloads the OpenGL library previously loaded by SDL_GL_LoadLibrary(). // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GL_LoadLibrary +// See also: SDL_GL_LoadLibrary() pub fn gl_unload_library() { C.SDL_GL_UnloadLibrary() } fn C.SDL_GL_ExtensionSupported(extension &char) bool -// gl_extension_supported checks if an OpenGL extension is supported for the current context. -// -// This function operates on the current GL context; you must have created a -// context and it must be current before calling this function. Do not assume -// that all contexts you create will have the same set of extensions -// available, or that recreating an existing context will offer the same -// extensions again. -// -// While it's probably not a massive overhead, this function is not an O(1) -// operation. Check the extensions you care about after creating the GL -// context and save that information somewhere instead of calling the function -// every time you need to know. -// -// `extension` the name of the extension to check -// returns SDL_TRUE if the extension is supported, SDL_FALSE otherwise. -// -// NOTE This function is available since SDL 2.0.0. +// gl_extension_supported returns true if an OpenGL extension is supported for the current +// context. pub fn gl_extension_supported(extension &char) bool { return C.SDL_GL_ExtensionSupported(extension) } fn C.SDL_GL_ResetAttributes() -// gl_reset_attributes resets all previously set OpenGL context attributes to their default values. -// -// NOTE This function is available since SDL 2.0.2. -// -// See also: SDL_GL_GetAttribute -// See also: SDL_GL_SetAttribute +// gl_reset_attributes resets all previously set OpenGL context attributes to their default values pub fn gl_reset_attributes() { C.SDL_GL_ResetAttributes() } @@ -2075,20 +1216,7 @@ fn C.SDL_GL_SetAttribute(attr C.SDL_GLattr, value int) int // gl_set_attribute sets an OpenGL window attribute before window creation. // -// This function sets the OpenGL attribute `attr` to `value`. The requested -// attributes should be set before creating an OpenGL window. You should use -// SDL_GL_GetAttribute() to check the values after creating the OpenGL -// context, since the values obtained can differ from the requested ones. -// -// `attr` an SDL_GLattr enum value specifying the OpenGL attribute to set -// `value` the desired value for the attribute -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GL_GetAttribute -// See also: SDL_GL_ResetAttributes +// returns 0 on success, or -1 if the attribute could not be set. pub fn gl_set_attribute(attr GLattr, value int) int { return C.SDL_GL_SetAttribute(C.SDL_GLattr(int(attr)), value) } @@ -2097,39 +1225,18 @@ fn C.SDL_GL_GetAttribute(attr C.SDL_GLattr, value &int) int // gl_get_attribute gets the actual value for an attribute from the current context. // -// `attr` an SDL_GLattr enum value specifying the OpenGL attribute to get -// `value` a pointer filled in with the current value of `attr` -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GL_ResetAttributes -// See also: SDL_GL_SetAttribute +// returns 0 on success, or -1 if the attribute could not be retrieved. +// The integer at `value` will be modified in either case. pub fn gl_get_attribute(attr GLattr, value &int) int { return C.SDL_GL_GetAttribute(C.SDL_GLattr(int(attr)), value) } fn C.SDL_GL_CreateContext(window &C.SDL_Window) GLContext -// gl_create_context creates an OpenGL context for an OpenGL window, and make it current. -// -// Windows users new to OpenGL should note that, for historical reasons, GL -// functions added after OpenGL version 1.1 are not available by default. -// Those functions must be loaded at run-time, either with an OpenGL -// extension-handling library or with SDL_GL_GetProcAddress() and its related -// functions. -// -// SDL_GLContext is an alias for `void *`. It's opaque to the application. +// gl_create_context creates an OpenGL context for use with an OpenGL window, and make it +// current. // -// `window` the window to associate with the context -// returns the OpenGL context associated with `window` or NULL on error; call -// SDL_GetError() for more details. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GL_DeleteContext -// See also: SDL_GL_MakeCurrent +// See also: SDL_GL_DeleteContext() pub fn gl_create_context(window &Window) GLContext { return GLContext(voidptr(C.SDL_GL_CreateContext(window))) } @@ -2138,16 +1245,7 @@ fn C.SDL_GL_MakeCurrent(window &C.SDL_Window, context C.SDL_GLContext) int // gl_make_current sets up an OpenGL context for rendering into an OpenGL window. // -// The context must have been created with a compatible window. -// -// `window` the window to associate with the context -// `context` the OpenGL context to associate with the window -// returns 0 on success or a negative error code on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GL_CreateContext +// NOTE The context must have been created with a compatible window. pub fn gl_make_current(window &Window, context GLContext) int { return C.SDL_GL_MakeCurrent(window, voidptr(context)) } @@ -2155,11 +1253,6 @@ pub fn gl_make_current(window &Window, context GLContext) int { fn C.SDL_GL_GetCurrentWindow() &C.SDL_Window // gl_get_current_window gets the currently active OpenGL window. -// -// returns the currently active OpenGL window on success or NULL on failure; -// call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. pub fn gl_get_current_window() &Window { return C.SDL_GL_GetCurrentWindow() } @@ -2167,37 +1260,26 @@ pub fn gl_get_current_window() &Window { fn C.SDL_GL_GetCurrentContext() GLContext // gl_get_current_context gets the currently active OpenGL context. -// -// returns the currently active OpenGL context or NULL on failure; call -// SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GL_MakeCurrent pub fn gl_get_current_context() GLContext { return GLContext(voidptr(C.SDL_GL_GetCurrentContext())) } fn C.SDL_GL_GetDrawableSize(window &C.SDL_Window, w &int, h &int) -// gl_get_drawable_size gets the size of a window's underlying drawable in pixels. +// gl_get_drawable_size gets the size of a window's underlying drawable in pixels (for use +// with glViewport). // -// This returns info useful for calling glViewport(). +// `window` Window from which the drawable size should be queried +// `w` Pointer to variable for storing the width in pixels, may be NULL +// `h` Pointer to variable for storing the height in pixels, may be NULL // // This may differ from SDL_GetWindowSize() if we're rendering to a high-DPI -// drawable, i.e. the window was created with `SDL_WINDOW_ALLOW_HIGHDPI` on a -// platform with high-DPI support (Apple calls this "Retina"), and not -// disabled by the `SDL_HINT_VIDEO_HIGHDPI_DISABLED` hint. +// drawable, i.e. the window was created with SDL_WINDOW_ALLOW_HIGHDPI on a +// platform with high-DPI support (Apple calls this "Retina"), and not disabled +// by the SDL_HINT_VIDEO_HIGHDPI_DISABLED hint. // -// `window` the window from which the drawable size should be queried -// `w` a pointer to variable for storing the width in pixels, may be NULL -// `h` a pointer to variable for storing the height in pixels, may be -// NULL -// -// NOTE This function is available since SDL 2.0.1. -// -// See also: SDL_CreateWindow -// See also: SDL_GetWindowSize +// See also: SDL_GetWindowSize() +// See also: SDL_CreateWindow() pub fn gl_get_drawable_size(window &Window, w &int, h &int) { C.SDL_GL_GetDrawableSize(window, w, h) } @@ -2206,29 +1288,14 @@ fn C.SDL_GL_SetSwapInterval(interval int) int // gl_set_swap_interval sets the swap interval for the current OpenGL context. // -// Some systems allow specifying -1 for the interval, to enable adaptive -// vsync. Adaptive vsync works the same as vsync, but if you've already missed -// the vertical retrace for a given frame, it swaps buffers immediately, which -// might be less jarring for the user during occasional framerate drops. If an -// application requests adaptive vsync and the system does not support it, -// this function will fail and return -1. In such a case, you should probably -// retry the call with 1 for the interval. -// -// Adaptive vsync is implemented for some glX drivers with -// GLX_EXT_swap_control_tear, and for some Windows drivers with -// WGL_EXT_swap_control_tear. +// `interval` 0 for immediate updates, 1 for updates synchronized with the +// vertical retrace. If the system supports it, you may +// specify -1 to allow late swaps to happen immediately +// instead of waiting for the next retrace. // -// Read more on the Khronos wiki: -// https://www.khronos.org/opengl/wiki/Swap_Interval#Adaptive_Vsync +// returns 0 on success, or -1 if setting the swap interval is not supported. // -// `interval` 0 for immediate updates, 1 for updates synchronized with -// the vertical retrace, -1 for adaptive vsync -// returns 0 on success or -1 if setting the swap interval is not supported; -// call SDL_GetError() for more information. -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GL_GetSwapInterval +// See also: SDL_GL_GetSwapInterval() pub fn gl_set_swap_interval(interval int) int { return C.SDL_GL_SetSwapInterval(interval) } @@ -2237,35 +1304,21 @@ fn C.SDL_GL_GetSwapInterval() int // gl_get_swap_interval gets the swap interval for the current OpenGL context. // -// If the system can't determine the swap interval, or there isn't a valid -// current context, this function will return 0 as a safe default. -// // returns 0 if there is no vertical retrace synchronization, 1 if the buffer -// swap is synchronized with the vertical retrace, and -1 if late -// swaps happen immediately instead of waiting for the next retrace; -// call SDL_GetError() for more information. +// swap is synchronized with the vertical retrace, and -1 if late +// swaps happen immediately instead of waiting for the next retrace. +// If the system can't determine the swap interval, or there isn't a +// valid current context, this will return 0 as a safe default. // -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GL_SetSwapInterval +// See also: SDL_GL_SetSwapInterval() pub fn gl_get_swap_interval() int { return C.SDL_GL_GetSwapInterval() } fn C.SDL_GL_SwapWindow(window &C.SDL_Window) -// gl_swap_window updates a window with OpenGL rendering. -// -// This is used with double-buffered OpenGL contexts, which are the default. -// -// On macOS, make sure you bind 0 to the draw framebuffer before swapping the -// window, otherwise nothing will happen. If you aren't using -// glBindFramebuffer(), this is the default and you won't have to do anything -// extra. -// -// `window` the window to change -// -// NOTE This function is available since SDL 2.0.0. +// gl_swap_window swaps the OpenGL buffers for a window, if double-buffering is +// supported. pub fn gl_swap_window(window &Window) { C.SDL_GL_SwapWindow(window) } @@ -2274,11 +1327,7 @@ fn C.SDL_GL_DeleteContext(context C.SDL_GLContext) // gl_delete_context deletes an OpenGL context. // -// `context` the OpenGL context to be deleted -// -// NOTE This function is available since SDL 2.0.0. -// -// See also: SDL_GL_CreateContext +// See also: SDL_GL_CreateContext() pub fn gl_delete_context(context GLContext) { C.SDL_GL_DeleteContext(voidptr(context)) } diff --git a/vulkan/vulkan.c.v b/vulkan/vulkan.c.v index 0246284f..d943bdef 100644 --- a/vulkan/vulkan.c.v +++ b/vulkan/vulkan.c.v @@ -23,45 +23,52 @@ pub struct C.SDL_vulkanSurface { fn C.SDL_Vulkan_LoadLibrary(path &char) int -// vulkan_load_library dynamically loads the Vulkan loader library. +// vulkan_load_library dynamically load a Vulkan loader library. +// +// `path` [in] The platform dependent Vulkan loader library name, or +// `NULL`. +// +// returns `0` on success, or `-1` if the library couldn't be loaded. +// +// If `path` is NULL SDL will use the value of the environment variable +// `SDL_VULKAN_LIBRARY`, if set, otherwise it loads the default Vulkan +// loader library. // // This should be called after initializing the video driver, but before // creating any Vulkan windows. If no Vulkan loader library is loaded, the // default library will be loaded upon creation of the first Vulkan window. // -// It is fairly common for Vulkan applications to link with libvulkan instead -// of explicitly loading it at run time. This will work with SDL provided the -// application links to a dynamic library and both it and SDL use the same -// search path. -// -// If you specify a non-NULL `path`, an application should retrieve all of the -// Vulkan functions it uses from the dynamic library using -// SDL_Vulkan_GetVkGetInstanceProcAddr unless you can guarantee `path` points -// to the same vulkan loader library the application linked to. -// -// On Apple devices, if `path` is NULL, SDL will attempt to find the -// `vkGetInstanceProcAddr` address within all the Mach-O images of the current -// process. This is because it is fairly common for Vulkan applications to -// link with libvulkan (and historically MoltenVK was provided as a static -// library). If it is not found, on macOS, SDL will attempt to load -// `vulkan.framework/vulkan`, `libvulkan.1.dylib`, -// `MoltenVK.framework/MoltenVK`, and `libMoltenVK.dylib`, in that order. On -// iOS, SDL will attempt to load `libMoltenVK.dylib`. Applications using a -// dynamic framework or .dylib must ensure it is included in its application -// bundle. -// -// On non-Apple devices, application linking with a static libvulkan is not -// supported. Either do not link to the Vulkan loader or link to a dynamic -// library version. -// -// `path` The platform dependent Vulkan loader library name or NULL -// returns 0 on success or -1 if the library couldn't be loaded; call -// SDL_GetError() for more information. -// -// NOTE This function is available in SDL 2.0.6 -// -// See also: SDL_Vulkan_GetVkInstanceProcAddr -// See also: SDL_Vulkan_UnloadLibrary +// NOTE It is fairly common for Vulkan applications to link with `libvulkan` +// instead of explicitly loading it at run time. This will work with +// SDL provided the application links to a dynamic library and both it +// and SDL use the same search path. +// +// NOTE If you specify a non-NULL `path`, an application should retrieve all +// of the Vulkan functions it uses from the dynamic library using +// `SDL_Vulkan_GetVkGetInstanceProcAddr`() unless you can guarantee +// `path` points to the same vulkan loader library the application +// linked to. +// +// NOTE On Apple devices, if `path` is NULL, SDL will attempt to find +// the vkGetInstanceProcAddr address within all the mach-o images of +// the current process. This is because it is fairly common for Vulkan +// applications to link with libvulkan (and historically MoltenVK was +// provided as a static library). If it is not found then, on macOS, SDL +// will attempt to load `vulkan.framework/vulkan`, `libvulkan.1.dylib`, +// `MoltenVK.framework/MoltenVK` and `libMoltenVK.dylib` in that order. +// On iOS SDL will attempt to load `libMoltenVK.dylib`. Applications +// using a dynamic framework or .dylib must ensure it is included in its +// application bundle. +// +// NOTE On non-Apple devices, application linking with a static libvulkan is +// not supported. Either do not link to the Vulkan loader or link to a +// dynamic library version. +// +// NOTE This function will fail if there are no working Vulkan drivers +// installed. +// +// See also: SDL_Vulkan_GetVkGetInstanceProcAddr() +// See also: SDL_Vulkan_UnloadLibrary() pub fn vulkan_load_library(path &char) int { return C.SDL_Vulkan_LoadLibrary(path) } @@ -70,75 +77,125 @@ fn C.SDL_Vulkan_GetVkGetInstanceProcAddr() voidptr // vulkan_get_vk_get_instance_proc_addr gets the address of the `vkGetInstanceProcAddr` function. // -// This should be called after either calling SDL_Vulkan_LoadLibrary() or -// creating an SDL_Window with the `SDL_WINDOW_VULKAN` flag. -// -// returns the function pointer for `vkGetInstanceProcAddr` or NULL on error. -// -// NOTE This function is available since SDL 2.0.6. +// NOTE This should be called after either calling SDL_Vulkan_LoadLibrary +// or creating an SDL_Window with the SDL_WINDOW_VULKAN flag. pub fn vulkan_get_vk_get_instance_proc_addr() voidptr { return C.SDL_Vulkan_GetVkGetInstanceProcAddr() } fn C.SDL_Vulkan_UnloadLibrary() -// vulkan_unload_library unloads the Vulkan library previously loaded by SDL_Vulkan_LoadLibrary() -// -// NOTE This function is available in SDL 2.0.6 +// vulkan_unload_library unload the Vulkan loader library previously loaded by +// `SDL_Vulkan_LoadLibrary`(). // -// See also: SDL_Vulkan_LoadLibrary +// See also: SDL_Vulkan_LoadLibrary() pub fn vulkan_unload_library() { C.SDL_Vulkan_UnloadLibrary() } fn C.SDL_Vulkan_GetInstanceExtensions(window &C.SDL_Window, p_count &u32, p_names &&char) bool -// vulkan_get_instance_extensions gets the names of the Vulkan instance extensions needed to create a surface -// with SDL_Vulkan_CreateSurface. +// vulkan_get_instance_extensions gets the names of the Vulkan instance extensions needed to create +// a surface with `SDL_Vulkan_CreateSurface()`. // -// If `pNames` is NULL, then the number of required Vulkan instance extensions -// is returned in `pCount`. Otherwise, `pCount` must point to a variable set -// to the number of elements in the `pNames` array, and on return the variable -// is overwritten with the number of names actually written to `pNames`. If -// `pCount` is less than the number of required extensions, at most `pCount` -// structures will be written. If `pCount` is smaller than the number of -// required extensions, SDL_FALSE will be returned instead of SDL_TRUE, to -// indicate that not all the required extensions were returned. +// `window` [in] Window for which the required Vulkan instance +// extensions should be retrieved +// `count` [in,out] pointer to an `unsigned` related to the number of +// required Vulkan instance extensions +// `names` [out] `NULL` or a pointer to an array to be filled with the +// required Vulkan instance extensions // -// The `window` parameter is currently needed to be valid as of SDL 2.0.8, -// however, this parameter will likely be removed in future releases +// returns `SDL_TRUE` on success, `SDL_FALSE` on error. // -// `window` A window for which the required Vulkan instance extensions -// should be retrieved (will be deprecated in a future release) -// `pCount` A pointer to an unsigned int corresponding to the number of -// extensions to be returned -// `pNames` NULL or a pointer to an array to be filled with required -// Vulkan instance extensions -// returns SDL_TRUE on success, SDL_FALSE on error. +// If `pNames` is `NULL`, then the number of required Vulkan instance +// extensions is returned in pCount. Otherwise, `pCount` must point to a +// variable set to the number of elements in the `pNames` array, and on +// return the variable is overwritten with the number of names actually +// written to `pNames`. If `pCount` is less than the number of required +// extensions, at most `pCount` structures will be written. If `pCount` +// is smaller than the number of required extensions, `SDL_FALSE` will be +// returned instead of `SDL_TRUE`, to indicate that not all the required +// extensions were returned. // -// NOTE This function is available in SDL 2.0.6 +// NOTE The returned list of extensions will contain `VK_KHR_surface` +// and zero or more platform specific extensions +// +// NOTE The extension names queried here must be enabled when calling +// VkCreateInstance, otherwise surface creation will fail. +// +// NOTE `window` should have been created with the `SDL_WINDOW_VULKAN` flag. +// +/* +``` + unsigned int count; + // get count of required extensions + if(!SDL_Vulkan_GetInstanceExtensions(window, &count, NULL)) + handle_error(); + + static const char *const additionalExtensions[] = + { + VK_EXT_DEBUG_REPORT_EXTENSION_NAME, // example additional extension + }; + size_t additionalExtensionsCount = sizeof(additionalExtensions) / sizeof(additionalExtensions[0]); + size_t extensionCount = count + additionalExtensionsCount; + const char **names = malloc(sizeof(const char *) * extensionCount); + if(!names) + handle_error(); + + // get names of required extensions + if(!SDL_Vulkan_GetInstanceExtensions(window, &count, names)) + handle_error(); + + // copy additional extensions after required extensions + for(size_t i = 0; i < additionalExtensionsCount; i++) + names[i + count] = additionalExtensions[i]; + + VkInstanceCreateInfo instanceCreateInfo = {}; + instanceCreateInfo.enabledExtensionCount = extensionCount; + instanceCreateInfo.ppEnabledExtensionNames = names; + // fill in rest of instanceCreateInfo + + VkInstance instance; + // create the Vulkan instance + VkResult result = vkCreateInstance(&instanceCreateInfo, NULL, &instance); + free(names); +``` +*/ // -// See also: SDL_Vulkan_CreateSurface +// See also: SDL_Vulkan_CreateSurface() pub fn vulkan_get_instance_extensions(window &sdl.Window, p_count &u32, p_names &&char) bool { return C.SDL_Vulkan_GetInstanceExtensions(window, p_count, p_names) } // vulkan_create_surface creates a Vulkan rendering surface for a window. // -// The `window` must have been created with the `SDL_WINDOW_VULKAN` flag and -// `instance` must have been created with extensions returned by -// SDL_Vulkan_GetInstanceExtensions() enabled. +// `window` [in] SDL_Window to which to attach the rendering surface. +// `instance` [in] handle to the Vulkan instance to use. +// `surface` [out] pointer to a VkSurfaceKHR handle to receive the +// handle of the newly created surface. +// +// returns `SDL_TRUE` on success, `SDL_FALSE` on error. +// +/* +``` +VkInstance instance; +SDL_Window *window; + +// create instance and window + +// create the Vulkan surface +VkSurfaceKHR surface; +if(!SDL_Vulkan_CreateSurface(window, instance, &surface)) + handle_error(); +``` +*/ // -// `window` The window to which to attach the Vulkan surface -// `instance` The Vulkan instance handle -// `surface` A pointer to a VkSurfaceKHR handle to output the newly -// created surface -// returns SDL_TRUE on success, SDL_FALSE on error. +// NOTE `window` should have been created with the `SDL_WINDOW_VULKAN` flag. // -// NOTE This function is available in SDL 2.0.6 +// NOTE `instance` should have been created with the extensions returned +// by `SDL_Vulkan_CreateSurface`() enabled. // -// See also: SDL_Vulkan_GetInstanceExtensions -// See also: SDL_Vulkan_GetDrawableSize +// See also: SDL_Vulkan_GetInstanceExtensions() /* TODO fn C.SDL_Vulkan_CreateSurface(window &C.SDL_Window, instance C.VkInstance, surface &C.VkSurfaceKHR) bool @@ -149,22 +206,23 @@ pub fn vulkan_create_surface(window &Window, instance C.VkInstance, surface &C.V fn C.SDL_Vulkan_GetDrawableSize(window &C.SDL_Window, w &int, h &int) -// vulkan_get_drawable_size gets the size of the window's underlying drawable dimensions in pixels. +// vulkan_get_drawable_size gets the size of a window's underlying drawable in pixels (for use +// with setting viewport, scissor & etc). // -// This may differ from SDL_GetWindowSize() if we're rendering to a high-DPI -// drawable, i.e. the window was created with `SDL_WINDOW_ALLOW_HIGHDPI` on a -// platform with high-DPI support (Apple calls this "Retina"), and not -// disabled by the `SDL_HINT_VIDEO_HIGHDPI_DISABLED` hint. +// `window` SDL_Window from which the drawable size should be queried +// `w` Pointer to variable for storing the width in pixels, may be NULL +// `h` Pointer to variable for storing the height in pixels, may be NULL // -// `window` an SDL_Window for which the size is to be queried -// `w` Pointer to the variable to write the width to or NULL -// `h` Pointer to the variable to write the height to or NULL +// This may differ from SDL_GetWindowSize() if we're rendering to a high-DPI +// drawable, i.e. the window was created with SDL_WINDOW_ALLOW_HIGHDPI on a +// platform with high-DPI support (Apple calls this "Retina"), and not disabled +// by the `SDL_HINT_VIDEO_HIGHDPI_DISABLED` hint. // -// NOTE This function is available in SDL 2.0.6 +// NOTE On macOS high-DPI support must be enabled for an application by +// setting NSHighResolutionCapable to true in its Info.plist. // -// See also: SDL_GetWindowSize -// See also: SDL_CreateWindow -// See also: SDL_Vulkan_CreateSurface +// See also: SDL_GetWindowSize() +// See also: SDL_CreateWindow() pub fn vulkan_get_drawable_size(window &sdl.Window, w &int, h &int) { C.SDL_Vulkan_GetDrawableSize(window, w, h) } diff --git a/windows_install_dependencies.vsh b/windows_install_dependencies.vsh index bfa0e43f..2d59ebcd 100644 --- a/windows_install_dependencies.vsh +++ b/windows_install_dependencies.vsh @@ -3,10 +3,10 @@ import szip import net.http const urls = [ - 'https://www.libsdl.org/release/SDL2-devel-2.30.0-VC.zip', - 'https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-devel-2.0.15-VC.zip', - 'https://www.libsdl.org/projects/SDL_image/release/SDL2_image-devel-2.0.5-VC.zip', - 'https://www.libsdl.org/projects/SDL_mixer/release/SDL2_mixer-devel-2.0.4-VC.zip', + 'https://www.libsdl.org/release/SDL2-devel-2.0.8-VC.zip', + 'https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-devel-2.0.14-VC.zip', + 'https://www.libsdl.org/projects/SDL_image/release/SDL2_image-devel-2.0.3-VC.zip', + 'https://www.libsdl.org/projects/SDL_mixer/release/SDL2_mixer-devel-2.0.2-VC.zip', ] fn main() {