Skip to content

Improve API #157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
361 changes: 237 additions & 124 deletions src/sdl2.nim

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions src/sdl2/audio.nim
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,8 @@ proc getCurrentAudioDriver*(): cstring {.importc: "SDL_GetCurrentAudioDriver".}
## This procedure returns the name of the current audio driver, or `nil`
## if no driver has been initialized.

proc openAudio*(desired: ptr AudioSpec; obtained: ptr AudioSpec): cint {.
importc: "SDL_OpenAudio".}
proc openAudio*(desired: ptr AudioSpec; obtained: ptr AudioSpec): SDL_Return {.
importc: "SDL_OpenAudio", discardable.}
## This procedure opens the audio device with the desired parameters, and
## returns `0` if successful, placing the actual hardware parameters in the
## object pointed to by `obtained`. If `obtained` is `nil`, the audio
Expand Down Expand Up @@ -457,8 +457,8 @@ proc getQueuedAudioSize*(dev: AudioDeviceID): uint32 {.
## **See also:**
## * `queueAudio proc<#queueAudio,AudioDeviceID,pointer,uint32>`_

proc queueAudio*(dev: AudioDeviceID, data: pointer, len: uint32): cint {.
importc: "SDL_QueueAudio".}
proc queueAudio*(dev: AudioDeviceID, data: pointer, len: uint32): SDL_Return {.
importc: "SDL_QueueAudio", discardable.}
## Queue more audio on non-callback devices.
##
## (If you are looking to retrieve queued audio from a non-callback capture
Expand Down Expand Up @@ -654,7 +654,7 @@ proc buildAudioCVT*(cvt: ptr AudioCVT; src_format: AudioFormat;
## `Return` `0` if no conversion is needed,
## `1` if the audio filter is set up, or `-1` on error.

proc convertAudio*(cvt: ptr AudioCVT): cint {.importc: "SDL_ConvertAudio".}
proc convertAudio*(cvt: ptr AudioCVT): SDL_Return {.importc: "SDL_ConvertAudio", discardable.}
## Once you have initialized the `cvt` object using `buildAudioCVT()`,
## created an audio buffer `cvt.buf`, and filled it with `cvt.len` bytes
## of audio data in the source format, this procedure will convert it
Expand Down Expand Up @@ -757,7 +757,7 @@ proc newAudioStream*(srcSpec, destSpec: AudioSpec): AudioStreamPtr =
proc put*(
stream: AudioStreamPtr,
buf: pointer,
len: cint): cint {.importc: "SDL_AudioStreamPut".}
len: cint): SDL_Return {.importc: "SDL_AudioStreamPut", discardable.}
## (Available since SDL 2.0.7)
## Add data to be converted/resampled to the stream.Returns 0 on success, or -1 on error.
##
Expand Down Expand Up @@ -798,7 +798,7 @@ proc available*(stream: AudioStreamPtr): cint {.
## **See also:**
## * `AudioStreamPtr type<#AudioStreamPtr>`_

proc flush*(stream: AudioStreamPtr): cint {.importc: "SDL_AudioStreamFlush".}
proc flush*(stream: AudioStreamPtr): SDL_Return {.importc: "SDL_AudioStreamFlush", discardable.}
## (Available since SDL 2.0.7)
## Tell the stream that you're done sending data, and anything being buffered
## should be converted/resampled and made available immediately. Returns 0
Expand Down
6 changes: 3 additions & 3 deletions src/sdl2/gfx.nim
Original file line number Diff line number Diff line change
Expand Up @@ -658,23 +658,23 @@ proc gfxPrimitivesSetFontRotation*(rotation: uint32) {.importc.}
## `rotation` Number of 90deg clockwise steps to rotate.

proc characterColor*(renderer: RendererPtr; x: int16; y: int16;
c: char; color: uint32): SDL_Return {.importc.}
c: char; color: uint32): SDL_Return {.importc, discardable.}
## Draw a character of the currently set font.
##
## `x`, `y` Coordinates of the upper left corner of the character.
##
## `c` The character to draw.

proc characterRGBA*(renderer: RendererPtr; x: int16; y: int16; c: char;
r, g, b, a: uint8): SDL_Return {.importc.}
r, g, b, a: uint8): SDL_Return {.importc, discardable.}
## Draw a character of the currently set font.
##
## `x`, `y` Coordinates of the upper left corner of the character.
##
## `c` The character to draw.

proc stringColor*(renderer: RendererPtr; x: int16; y: int16;
s: cstring; color: uint32): SDL_Return {.importc.}
s: cstring; color: uint32): SDL_Return {.importc, discardable.}
## Draw a string in the currently set font.
##
## `x`, `y` Coordinates of the upper left corner of the string.
Expand Down
26 changes: 13 additions & 13 deletions src/sdl2/haptic.nim
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ proc newEffect*(haptic: HapticPtr, effect: ptr HapticEffect): cint {.
## * `destroyEffect proc<#destroyEffect,HapticPtr,cint>`_

proc updateEffect*(haptic: HapticPtr, effect: cint,
data: ptr HapticEffect): cint {.importc: "SDL_HapticUpdateEffect".}
data: ptr HapticEffect): SDL_Return {.importc: "SDL_HapticUpdateEffect", discardable.}
## Updates the properties of an effect.
##
## Can be used dynamically, although behavior when dynamically changing
Expand All @@ -883,7 +883,7 @@ proc updateEffect*(haptic: HapticPtr, effect: cint,
## * `destroyEffect proc<#destroyEffect,HapticPtr,cint>`_

proc runEffect*(haptic: HapticPtr, effect: cint,
iterations: uint32): cint {.importc: "SDL_HapticRunEffect".}
iterations: uint32): SDL_Return {.importc: "SDL_HapticRunEffect", discardable.}
## Runs the haptic effect on its associated haptic device.
##
## If iterations are `HAPTIC_INFINITY`, it'll run the effect over and over
Expand All @@ -906,7 +906,7 @@ proc runEffect*(haptic: HapticPtr, effect: cint,
## * `getEffectStatus proc<#getEffectStatus,HapticPtr,cint>`_

proc stopEffect*(haptic: HapticPtr,
effect: cint): cint {.importc: "SDL_HapticStopEffect".}
effect: cint): SDL_Return {.importc: "SDL_HapticStopEffect", discardable.}
## Stops the haptic effect on its associated haptic device.
##
## `haptic` Haptic device to stop the effect on.
Expand Down Expand Up @@ -951,7 +951,7 @@ proc getEffectStatus*(haptic: HapticPtr, effect: cint): cint {.
## * `stopEffect proc<#stopEffect,HapticPtr,cint>`_

proc setGain*(haptic: HapticPtr,
gain: int): cint {.importc: "SDL_HapticSetGain".}
gain: int): SDL_Return {.importc: "SDL_HapticSetGain", discardable.}
## Sets the global gain of the device.
##
## Device must support the `HAPTIC_GAIN` feature.
Expand All @@ -970,8 +970,8 @@ proc setGain*(haptic: HapticPtr,
## **See also:**
## * `query proc<#query,HapticPtr>`_

proc setAutocenter*(haptic: HapticPtr, autocenter: int): cint {.
importc: "SDL_HapticSetAutocenter".}
proc setAutocenter*(haptic: HapticPtr, autocenter: int): SDL_Return {.
importc: "SDL_HapticSetAutocenter", discardable.}
## Sets the global autocenter of the device.
##
## Autocenter should be between `0` and `100`.
Expand All @@ -988,7 +988,7 @@ proc setAutocenter*(haptic: HapticPtr, autocenter: int): cint {.
## **See also:**
## * `query proc<#query,HapticPtr>`_

proc pause*(haptic: HapticPtr): cint {.importc: "SDL_HapticPause".}
proc pause*(haptic: HapticPtr): SDL_Return {.importc: "SDL_HapticPause", discardable.}
## Pauses a haptic device.
##
## Device must support the `HAPTIC_PAUSE` feature.
Expand All @@ -1004,7 +1004,7 @@ proc pause*(haptic: HapticPtr): cint {.importc: "SDL_HapticPause".}
## **See also:**
## * `unpause proc<#unpause,HapticPtr>`_

proc unpause*(haptic: HapticPtr): cint {.importc: "SDL_HapticUnpause".}
proc unpause*(haptic: HapticPtr): SDL_Return {.importc: "SDL_HapticUnpause", discardable.}
## Unpauses a haptic device.
##
## Call to unpause after `pause()`.
Expand All @@ -1016,7 +1016,7 @@ proc unpause*(haptic: HapticPtr): cint {.importc: "SDL_HapticUnpause".}
## **See also:**
## * `pause proc<#pause,HapticPtr>`_

proc stopAll*(haptic: HapticPtr): cint {.importc: "SDL_HapticStopAll".}
proc stopAll*(haptic: HapticPtr): SDL_Return {.importc: "SDL_HapticStopAll", discardable.}
## Stops all the currently playing effects on a haptic device.
##
## `haptic` Haptic device to stop.
Expand All @@ -1037,7 +1037,7 @@ proc rumbleSupported*(haptic: HapticPtr): cint {.
## * `rumblePlay proc<#rumblePlay,HapticPtr,float,uint32>`_
## * `rumbleStop proc<#rumbleStop,HapticPtr>`_

proc rumbleInit*(haptic: HapticPtr): cint {.importc: "SDL_HapticRumbleInit".}
proc rumbleInit*(haptic: HapticPtr): SDL_Return {.importc: "SDL_HapticRumbleInit", discardable.}
## Initializes the haptic device for simple rumble playback.
##
## `haptic` Haptic device to initialize for simple rumble playback.
Expand All @@ -1050,8 +1050,8 @@ proc rumbleInit*(haptic: HapticPtr): cint {.importc: "SDL_HapticRumbleInit".}
## * `rumblePlay proc<#rumblePlay,HapticPtr,float,uint32>`_
## * `rumbleStop proc<#rumbleStop,HapticPtr>`_

proc rumblePlay*(haptic: HapticPtr, strength: float, length: uint32): cint {.
importc: "SDL_HapticRumblePlay".}
proc rumblePlay*(haptic: HapticPtr, strength: float, length: uint32): SDL_Return {.
importc: "SDL_HapticRumblePlay", discardable.}
## Runs simple rumble on a haptic device
##
## `haptic` Haptic device to play rumble effect on.
Expand All @@ -1067,7 +1067,7 @@ proc rumblePlay*(haptic: HapticPtr, strength: float, length: uint32): cint {.
## * `rumbleInit proc<#rumbleInit,HapticPtr>`_
## * `rumbleStop proc<#rumbleStop,HapticPtr>`_

proc rumbleStop*(haptic: HapticPtr):cint {.importc: "SDL_HapticRumbleStop".}
proc rumbleStop*(haptic: HapticPtr): SDL_Return {.importc: "SDL_HapticRumbleStop", discardable.}
## Stops the simple rumble on a haptic device.
##
## `haptic` Haptic to stop the rumble on.
Expand Down
4 changes: 2 additions & 2 deletions src/sdl2/image.nim
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ proc loadXCF*(src: RWopsPtr): SurfacePtr {.importc: "IMG_LoadXCF_RW".}
proc loadXPM_RW*(src: RWopsPtr): SurfacePtr {.importc: "IMG_LoadXPM_RW".}
proc loadXPM*(src: RWopsPtr): SurfacePtr {.importc: "IMG_LoadXPM_RW".}
proc loadXV_RW*(src: RWopsPtr): SurfacePtr {.importc: "IMG_LoadXV_RW".}
proc loadXV(src: RWopsPtr): SurfacePtr {.importc: "IMG_LoadXV_RW".}
proc loadXV*(src: RWopsPtr): SurfacePtr {.importc: "IMG_LoadXV_RW".}
proc loadWEBP_RW*(src: RWopsPtr): SurfacePtr {.importc: "IMG_LoadWEBP_RW".}
proc loadWEBP*(src: RWopsPtr): SurfacePtr {.importc: "IMG_LoadWEBP_RW".}
proc readXPMFromArray*(xpm: cstringArray): SurfacePtr {.importc: "IMG_ReadXPMFromArray".}
proc readXPM*(xpm: cstringArray): SurfacePtr {.importc: "IMG_ReadXPMFromArray".}
# Saving functions
proc savePNG*(surface: SurfacePtr, file: cstring): cint {.importc: "IMG_SavePNG".}
proc savePNG*(surface: SurfacePtr, file: cstring): SDL_Return {.importc: "IMG_SavePNG", discardable.}

when not defined(SDL_Static):
{.pop.}
6 changes: 3 additions & 3 deletions src/sdl2/joystick.nim
Original file line number Diff line number Diff line change
Expand Up @@ -258,15 +258,15 @@ proc getHat*(joystick: JoystickPtr, hat: cint): uint8 {.inline.} =
## * SDL_HAT_LEFTDOWN
joystick.joystickGetHat(hat)

proc joystickGetBall*(joystick: JoystickPtr, ball: cint, dx: ptr cint, dy: ptr cint): cint {.
importc: "SDL_JoystickGetBall".}
proc joystickGetBall*(joystick: JoystickPtr, ball: cint, dx: ptr cint, dy: ptr cint): SDL_Return {.
importc: "SDL_JoystickGetBall", discardable.}
## Get the ball axis change since the last poll.
##
## `Return` `0`, or `-1` if you passed it invalid parameters.
##
## The ball indices start at index `0`.

proc getBall*(joystick: JoystickPtr, ball: cint, dx: ptr cint, dy: ptr cint): cint {.inline.} =
proc getBall*(joystick: JoystickPtr, ball: cint, dx: ptr cint, dy: ptr cint): SDL_Return {.inline, discardable.} =
## Get the ball axis change since the last poll.
##
## `Return` `0`, or `-1` if you passed it invalid parameters.
Expand Down
24 changes: 12 additions & 12 deletions src/sdl2/mixer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ type
# Open the mixer with a certain audio format

proc openAudio*(frequency: cint; format: uint16; channels: cint;
chunksize: cint): cint {.importc: "Mix_OpenAudio".}
chunksize: cint): SDL_Return {.importc: "Mix_OpenAudio", discardable.}
## Open the mixer with a certain audio format.
##
## `frequency` Output sampling frequency in samples per second (Hz).
Expand Down Expand Up @@ -1084,8 +1084,8 @@ template playChannel*(channel, chunk, loops: untyped): untyped =
## On any errors, `-1` is returned.
playChannelTimed(channel, chunk, loops, - 1)

proc playMusic*(music: ptr Music; loops: cint): cint {.importc: "Mix_PlayMusic".}
proc play*(music: ptr Music; loops: cint): cint {.importc: "Mix_PlayMusic".}
proc playMusic*(music: ptr Music; loops: cint): SDL_Return {.importc: "Mix_PlayMusic", discardable.}
proc play*(music: ptr Music; loops: cint): SDL_Return {.importc: "Mix_PlayMusic", discardable.}
## Play the loaded `music` `loops` times through from start to finish.
##
## `music` Pointer to `mixer.Music` to play.
Expand All @@ -1099,10 +1099,10 @@ proc play*(music: ptr Music; loops: cint): cint {.importc: "Mix_PlayMusic".}
##
## `Return` `0` on success, or `-1` on errors.

proc fadeInMusic*(music: ptr Music; loops: cint; ms: cint): cint {.
importc: "Mix_FadeInMusic".}
proc fadeIn*(music: ptr Music; loops: cint; ms: cint): cint {.
importc: "Mix_FadeInMusic".}
proc fadeInMusic*(music: ptr Music; loops: cint; ms: cint): SDL_Return {.
importc: "Mix_FadeInMusic", discardable.}
proc fadeIn*(music: ptr Music; loops: cint; ms: cint): SDL_Return {.
importc: "Mix_FadeInMusic", discardable.}
## Fade in over `ms` milliseconds of time, the loaded `music`,
## playing it `loops` times through from start to finish.
##
Expand All @@ -1123,9 +1123,9 @@ proc fadeIn*(music: ptr Music; loops: cint; ms: cint): cint {.
## `Return` `0` on success, or `-1` on errors.

proc fadeInMusicPos*(music: ptr Music; loops: cint; ms: cint;
position: cdouble): cint {.importc: "Mix_FadeInMusicPos".}
position: cdouble): SDL_Return {.importc: "Mix_FadeInMusicPos", discardable.}
proc fadeInPos*(music: ptr Music; loops: cint; ms: cint;
position: cdouble): cint {.importc: "Mix_FadeInMusicPos".}
position: cdouble): SDL_Return {.importc: "Mix_FadeInMusicPos", discardable.}
## Fade in over `ms` milliseconds of time, the loaded `music`,
## playing it `loops` times through from start to finish.
##
Expand Down Expand Up @@ -1444,8 +1444,8 @@ proc pausedMusic*(): cint {.importc: "Mix_PausedMusic".}
##
## `Return` `0` if music is not paused. `1` if it is paused.

proc setMusicPosition*(position: cdouble): cint {.
importc: "Mix_SetMusicPosition".}
proc setMusicPosition*(position: cdouble): SDL_Return {.
importc: "Mix_SetMusicPosition", discardable.}
## Set the current `position` in the music stream.
##
## `position` Posistion to play from.
Expand Down Expand Up @@ -1493,7 +1493,7 @@ proc playingMusic*(): cint {.importc: "Mix_PlayingMusic".}
##
## `Return` `0` if the music is not playing, or `1` if it is playing.

proc setMusicCMD*(command: cstring): cint {.importc: "Mix_SetMusicCMD".}
proc setMusicCMD*(command: cstring): SDL_Return {.importc: "Mix_SetMusicCMD", discardable.}
## Stop music and set external music playback command.
##
## `command` System command to play the music.
Expand Down
4 changes: 2 additions & 2 deletions src/sdl2/net.nim
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ proc quit*() {.importc: "SDLNet_Quit".}
# IPv4 hostname resolution API
#*********************************************************************

proc resolveHost*(address: ptr IpAddress; host: cstring; port: uint16): cint {.
importc: "SDLNet_ResolveHost".}
proc resolveHost*(address: ptr IpAddress; host: cstring; port: uint16): SDL_Return {.
importc: "SDLNet_ResolveHost", discardable.}
## Resolve a host name and port to an IP address in network form.
##
## `address` points to the `IPaddress` that will be filled in.
Expand Down
4 changes: 2 additions & 2 deletions src/sdl2/ttf.nim
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ proc fontFaceIsFixedWidth*(font: FontPtr): cint {.importc: "TTF_FontFaceIsFixedW
proc fontFaceFamilyName*(font: FontPtr): cstring {.importc: "TTF_FontFaceFamilyName".}
proc fontFaceStyleName*(font: FontPtr): cstring {.importc: "TTF_FontFaceStyleName".}

proc glyphIsProvided*(font: FontPtr; ch: uint16): cint {.
proc glyphIsProvided*(font: FontPtr; ch: uint16): Bool32 {.
importc: "TTF_GlyphIsProvided".}
## Check wether a glyph is provided by the font or not.

Expand Down Expand Up @@ -269,7 +269,7 @@ proc close*(font: FontPtr) {.importc: "TTF_CloseFont".}
proc ttfQuit*() {.importc: "TTF_Quit".}
## De-initialize the TTF engine.

proc ttfWasInit*(): bool {.importc: "TTF_WasInit".}
proc ttfWasInit*(): Bool32 {.importc: "TTF_WasInit".}
## Check if the TTF engine is initialized.

proc getFontKerningSize*(font: FontPtr; prev_index, indx: cint): cint {.
Expand Down