ps-sdl2.scm 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. ;;; ps-sdl2 --- Pre-Scheme wrappers for SDL2
  2. ;;; Core
  3. (define SDL_INIT_VIDEO (external "SDL_INIT_VIDEO" integer))
  4. (define (sdl-init flags)
  5. (zero? ((external "SDL_Init" (=> (integer) integer)) flags)))
  6. (define (sdl-quit)
  7. ((external "SDL_Quit" (=> () unit))))
  8. (define (sdl-get-error)
  9. ((external "SDL_GetError" (=> () (^ char)))))
  10. (define (sdl-delay ms)
  11. ((external "SDL_Delay" (=> (integer) unit)) ms))
  12. ;;; Window
  13. (define-wrapper-type sdl-window)
  14. (define SDL_WINDOWPOS_CENTERED (external "SDL_WINDOWPOS_CENTERED" integer))
  15. (define SDL_WINDOW_SHOWN (external "SDL_WINDOW_SHOWN" integer))
  16. (define (sdl-create-window title x y w h flags)
  17. ((external "PS_SDL_CreateWindow" (=> ((^ char) integer integer integer integer integer) sdl-window))
  18. title x y w h flags))
  19. (define (sdl-destroy-window window)
  20. ((external "PS_SDL_DestroyWindow" (=> (sdl-window) unit))
  21. window))
  22. ;;; Renderer
  23. (define-wrapper-type sdl-renderer)
  24. (define SDL_RENDERER_ACCELERATED (external "SDL_RENDERER_ACCELERATED" integer))
  25. (define (sdl-create-renderer window index flags)
  26. ((external "PS_SDL_CreateRenderer" (=> (sdl-window integer integer) sdl-renderer))
  27. window index flags))
  28. (define (sdl-destroy-renderer renderer)
  29. ((external "PS_SDL_DestroyRenderer" (=> (sdl-renderer) unit))
  30. renderer))
  31. (define (sdl-set-render-draw-color renderer r g b a)
  32. (zero? ((external "PS_SDL_SetRenderDrawColor" (=> (sdl-renderer integer integer integer integer) integer))
  33. renderer r g b a)))
  34. (define (sdl-render-clear renderer)
  35. (zero? ((external "PS_SDL_RenderClear" (=> (sdl-renderer) integer))
  36. renderer)))
  37. (define (sdl-render-present renderer)
  38. ((external "PS_SDL_RenderPresent" (=> (sdl-renderer) unit))
  39. renderer))
  40. (define (sdl-render-fill-rect renderer x y w h)
  41. (zero? ((external "PS_SDL_RenderFillRect" (=> (sdl-renderer integer integer integer integer) integer))
  42. renderer x y w h)))
  43. ;;; Event
  44. (define-wrapper-type sdl-event)
  45. (define SDL_QUIT (external "SDL_QUIT" integer))
  46. (define (sdl-create-event)
  47. ((external "PS_SDL_CreateEvent" (=> () sdl-event))))
  48. (define (sdl-destroy-event event)
  49. ((external "PS_SDL_DestroyEvent" (=> (sdl-event) unit))
  50. event))
  51. (define (sdl-poll-event event)
  52. (one? ((external "PS_SDL_PollEvent" (=> (sdl-event) integer))
  53. event)))
  54. (define (sdl-event-type event)
  55. ((external "PS_SDL_EventType" (=> (sdl-event) integer))
  56. event))