Add tests for examples from Nim in Action.
This commit is contained in:
parent
a585748f27
commit
7889c03cbc
34 changed files with 1213 additions and 0 deletions
34
tests/niminaction/Chapter8/sdl/sdl.nim
Normal file
34
tests/niminaction/Chapter8/sdl/sdl.nim
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
when defined(Windows):
|
||||
const libName* = "SDL2.dll"
|
||||
elif defined(Linux):
|
||||
const libName* = "libSDL2.so"
|
||||
elif defined(MacOsX):
|
||||
const libName* = "libSDL2.dylib"
|
||||
|
||||
type
|
||||
SdlWindow = object
|
||||
SdlWindowPtr* = ptr SdlWindow
|
||||
SdlRenderer = object
|
||||
SdlRendererPtr* = ptr SdlRenderer
|
||||
|
||||
const INIT_VIDEO* = 0x00000020
|
||||
|
||||
{.push dynlib: libName.}
|
||||
proc init*(flags: uint32): cint {.importc: "SDL_Init".}
|
||||
|
||||
proc createWindowAndRenderer*(width, height: cint, window_flags: cuint,
|
||||
window: var SdlWindowPtr, renderer: var SdlRendererPtr): cint
|
||||
{.importc: "SDL_CreateWindowAndRenderer".}
|
||||
|
||||
proc pollEvent*(event: pointer): cint {.importc: "SDL_PollEvent".}
|
||||
|
||||
proc setDrawColor*(renderer: SdlRendererPtr, r, g, b, a: uint8): cint
|
||||
{.importc: "SDL_SetRenderDrawColor", discardable.}
|
||||
|
||||
proc present*(renderer: SdlRendererPtr) {.importc: "SDL_RenderPresent".}
|
||||
|
||||
proc clear*(renderer: SdlRendererPtr) {.importc: "SDL_RenderClear".}
|
||||
|
||||
proc drawLines*(renderer: SdlRendererPtr, points: ptr tuple[x, y: cint],
|
||||
count: cint): cint {.importc: "SDL_RenderDrawLines", discardable.}
|
||||
{.pop.}
|
||||
Loading…
Add table
Add a link
Reference in a new issue