sdl2.nim 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860
  1. import macros
  2. import strutils
  3. export strutils.`%`
  4. # Add for people running sdl 2.0.0
  5. {. deadCodeElim: on .}
  6. {.push warning[user]: off}
  7. when defined(SDL_Static):
  8. static: echo "SDL_Static option is deprecated and will soon be removed. Instead please use --dynlibOverride:SDL2."
  9. else:
  10. when defined(windows):
  11. const LibName* = "SDL2.dll"
  12. elif defined(macosx):
  13. const LibName* = "libSDL2.dylib"
  14. elif defined(openbsd):
  15. const LibName* = "libSDL2.so.0.6"
  16. else:
  17. const LibName* = "libSDL2.so"
  18. {.pop.}
  19. when not defined(android) and not defined(ios):
  20. type csize_t_const* = csize_t
  21. else:
  22. type csize_t_const* = csize
  23. include sdl2/private/keycodes
  24. const
  25. SDL_TEXTEDITINGEVENT_TEXT_SIZE* = 32
  26. SDL_TEXTINPUTEVENT_TEXT_SIZE* = 32
  27. type
  28. WindowEventID* {.size: sizeof(byte).} = enum
  29. WindowEvent_None = 0, WindowEvent_Shown, WindowEvent_Hidden, WindowEvent_Exposed,
  30. WindowEvent_Moved, WindowEvent_Resized, WindowEvent_SizeChanged, WindowEvent_Minimized,
  31. WindowEvent_Maximized, WindowEvent_Restored, WindowEvent_Enter, WindowEvent_Leave,
  32. WindowEvent_FocusGained, WindowEvent_FocusLost, WindowEvent_Close,
  33. WindowEvent_TakeFocus, WindowEvent_HitTest
  34. EventType* {.size: sizeof(uint32).} = enum
  35. QuitEvent = 0x100, AppTerminating, AppLowMemory, AppWillEnterBackground,
  36. AppDidEnterBackground, AppWillEnterForeground, AppDidEnterForeground,
  37. DisplayEvent = 0x150,
  38. WindowEvent = 0x200, SysWMEvent,
  39. KeyDown = 0x300, KeyUp, TextEditing, TextInput, KeymapChanged,
  40. MouseMotion = 0x400, MouseButtonDown, MouseButtonUp, MouseWheel,
  41. JoyAxisMotion = 0x600, JoyBallMotion, JoyHatMotion, JoyButtonDown,
  42. JoyButtonUp, JoyDeviceAdded, JoyDeviceRemoved,
  43. ControllerAxisMotion = 0x650, ControllerButtonDown, ControllerButtonUp,
  44. ControllerDeviceAdded, ControllerDeviceRemoved, ControllerDeviceRemapped,
  45. FingerDown = 0x700, FingerUp, FingerMotion,
  46. DollarGesture = 0x800, DollarRecord, MultiGesture,
  47. ClipboardUpdate = 0x900,
  48. DropFile = 0x1000, DropText, DropBegin, DropComplete,
  49. AudioDeviceAdded = 0x1100, AudioDeviceRemoved = 0x1101,
  50. SensorUpdate = 0x1200,
  51. RenderTargetsReset = 0x2000, RenderDeviceReset,
  52. UserEvent = 0x8000, UserEvent1, UserEvent2, UserEvent3, UserEvent4, UserEvent5,
  53. LastEvent = 0xFFFF,
  54. Event* = object
  55. kind*: EventType
  56. padding: array[56-sizeof(EventType), byte]
  57. QuitEventPtr* = ptr QuitEventObj
  58. QuitEventObj* = object
  59. kind*: EventType
  60. timestamp*: uint32
  61. WindowEventPtr* = ptr WindowEventObj
  62. WindowEventObj* = object
  63. kind*: EventType
  64. timestamp*: uint32
  65. windowID*: uint32
  66. event*: WindowEventID
  67. pad*: array[56-13, byte]
  68. KeyboardEventPtr* = ptr KeyboardEventObj
  69. KeyboardEventObj* = object
  70. kind*: EventType
  71. timestamp*: uint32
  72. windowID*: uint32
  73. state*: uint8
  74. repeat*: bool
  75. keysym*: KeySym
  76. pad*: array[24, byte]
  77. TextEditingEventPtr* = ptr TextEditingEventObj
  78. TextEditingEventObj* = object
  79. kind*: EventType
  80. timestamp*: uint32
  81. windowID*: uint32
  82. text*: array[SDL_TEXTEDITINGEVENT_TEXT_SIZE, char]
  83. start*,length*: int32
  84. pad*: array[8, byte]
  85. TextInputEventPtr* = ptr TextInputEventObj
  86. TextInputEventObj* = object
  87. kind*: EventType
  88. timestamp*: uint32
  89. windowID*: uint32
  90. text*: array[SDL_TEXTINPUTEVENT_TEXT_SIZE,char]
  91. pad*: array[24, byte]
  92. MouseMotionEventPtr* = ptr MouseMotionEventObj
  93. MouseMotionEventObj* = object
  94. kind*: EventType
  95. timestamp*,windowID*: uint32
  96. which*: uint32
  97. state*: uint32
  98. x*,y*, xrel*,yrel*: int32
  99. pad*: array[20, byte]
  100. MouseButtonEventPtr* = ptr MouseButtonEventObj
  101. MouseButtonEventObj* = object
  102. kind*: EventType
  103. timestamp*,windowID*: uint32
  104. which*: uint32
  105. button*: uint8
  106. state*: uint8
  107. clicks*: uint8
  108. x*,y*: cint
  109. pad*: array[28, byte]
  110. MouseWheelEventPtr* = ptr MouseWheelEventObj
  111. MouseWheelEventObj* = object
  112. kind*: EventType
  113. timestamp*,windowID*: uint32
  114. which*: uint32
  115. x*,y*: cint
  116. direction*: MouseWheelDirection
  117. JoyAxisEventPtr* = ptr JoyAxisEventObj
  118. JoyAxisEventObj* = object
  119. kind*: EventType
  120. timestamp*: uint32
  121. which*: int32
  122. axis*: uint8
  123. pad1,pad2,pad3: uint8
  124. value*: int16
  125. JoyBallEventPtr* = ptr JoyBallEventObj
  126. JoyBallEventObj* = object
  127. kind*: EventType
  128. timestamp*: uint32
  129. which*: int32
  130. ball*, pad1,pad2,pad3: uint8
  131. xrel*,yrel*: int16
  132. JoyHatEventPtr* = ptr JoyHatEventObj
  133. JoyHatEventObj* = object
  134. kind*: EventType
  135. timestamp*: uint32
  136. which*: int32
  137. hat*,value*: uint8
  138. JoyButtonEventPtr* = ptr JoyButtonEventObj
  139. JoyButtonEventObj* = object
  140. kind*: EventType
  141. timestamp*: uint32
  142. which*: int32
  143. button*,state*: uint8
  144. JoyDeviceEventPtr* = ptr JoyDeviceEventObj
  145. JoyDeviceEventObj* = object
  146. kind*: EventType
  147. timestamp*: uint32
  148. which*: int32
  149. ControllerAxisEventPtr* = ptr ControllerAxisEventObj
  150. ControllerAxisEventObj* = object
  151. kind*: EventType
  152. timestamp*: uint32
  153. which*: int32
  154. axis*, pad1,pad2,pad3: uint8
  155. value*: int16
  156. ControllerButtonEventPtr* = ptr ControllerButtonEventObj
  157. ControllerButtonEventObj* = object
  158. kind*: EventType
  159. timestamp*: uint32
  160. which*: int32
  161. button*,state*: uint8
  162. ControllerDeviceEventPtr* = ptr ControllerDeviceEventObj
  163. ControllerDeviceEventObj* = object
  164. kind*: EventType
  165. timestamp*: uint32
  166. which*: int32
  167. TouchID* = int64
  168. FingerID* = int64
  169. TouchFingerEventPtr* = ptr TouchFingerEventObj
  170. TouchFingerEventObj* = object
  171. kind*: EventType
  172. timestamp*: uint32
  173. touchID*: TouchID
  174. fingerID*: FingerID
  175. x*,y*,dx*,dy*,pressure*: cfloat
  176. pad*: array[24, byte]
  177. MultiGestureEventPtr* = ptr MultiGestureEventObj
  178. MultiGestureEventObj* = object
  179. kind*: EventType
  180. timestamp*: uint32
  181. touchID*: TouchID
  182. dTheta*,dDist*,x*,y*: cfloat
  183. numFingers*: uint16
  184. Finger* = object
  185. id*: FingerID
  186. x*,y*: cfloat
  187. pressure*: cfloat
  188. GestureID = int64
  189. DollarGestureEventPtr* = ptr DollarGestureEventObj
  190. DollarGestureEventObj* = object
  191. kind*: EventType
  192. timestamp*: uint32
  193. touchID*: TouchID
  194. gestureID*: GestureID
  195. numFingers*: uint32
  196. error*, x*, y*: float
  197. DropEventPtr* = ptr DropEventObj
  198. DropEventObj* = object
  199. kind*: EventType
  200. timestamp*: uint32
  201. file*: cstring
  202. UserEventPtr* = ptr UserEventObj
  203. UserEventObj* = object
  204. kind*: EventType
  205. timestamp*,windowID*: uint32
  206. code*: int32
  207. data1*,data2*: pointer
  208. Eventaction* {.size: sizeof(cint).} = enum
  209. SDL_ADDEVENT, SDL_PEEKEVENT, SDL_GETEVENT
  210. EventFilter* = proc (userdata: pointer; event: ptr Event): Bool32 {.cdecl.}
  211. SDL_Return* {.size: sizeof(cint).} = enum SdlError = -1, SdlSuccess = 0 ##\
  212. ## Return value for many SDL functions. Any function that returns like this \
  213. ## should also be discardable
  214. Bool32* {.size: sizeof(cint).} = enum False32 = 0, True32 = 1 ##\
  215. ## SDL_bool
  216. KeyState* {.size: sizeof(byte).} = enum KeyReleased = 0, KeyPressed
  217. KeySym* {.pure.} = object
  218. scancode*: ScanCode
  219. sym*: cint ##Keycode
  220. modstate*: int16
  221. unicode*: cint
  222. Point* = tuple[x, y: cint]
  223. Rect* = tuple[x, y: cint, w, h: cint]
  224. GLattr*{.size: sizeof(cint).} = enum
  225. SDL_GL_RED_SIZE,
  226. SDL_GL_GREEN_SIZE,
  227. SDL_GL_BLUE_SIZE,
  228. SDL_GL_ALPHA_SIZE,
  229. SDL_GL_BUFFER_SIZE,
  230. SDL_GL_DOUBLEBUFFER,
  231. SDL_GL_DEPTH_SIZE,
  232. SDL_GL_STENCIL_SIZE,
  233. SDL_GL_ACCUM_RED_SIZE,
  234. SDL_GL_ACCUM_GREEN_SIZE,
  235. SDL_GL_ACCUM_BLUE_SIZE,
  236. SDL_GL_ACCUM_ALPHA_SIZE,
  237. SDL_GL_STEREO,
  238. SDL_GL_MULTISAMPLEBUFFERS,
  239. SDL_GL_MULTISAMPLESAMPLES,
  240. SDL_GL_ACCELERATED_VISUAL,
  241. SDL_GL_RETAINED_BACKING,
  242. SDL_GL_CONTEXT_MAJOR_VERSION,
  243. SDL_GL_CONTEXT_MINOR_VERSION,
  244. SDL_GL_CONTEXT_EGL,
  245. SDL_GL_CONTEXT_FLAGS,
  246. SDL_GL_CONTEXT_PROFILE_MASK,
  247. SDL_GL_SHARE_WITH_CURRENT_CONTEXT,
  248. SDL_GL_FRAMEBUFFER_SRGB_CAPABLE,
  249. SDL_GL_CONTEXT_RELEASE_BEHAVIOR,
  250. SDL_GL_CONTEXT_RESET_NOTIFICATION,
  251. SDL_GL_CONTEXT_NO_ERROR
  252. MouseWheelDirection* {.size: sizeof(uint32).} = enum
  253. SDL_MOUSEWHEEL_NORMAL,
  254. SDL_MOUSEWHEEL_FLIPPED
  255. const
  256. # GLprofile enum.
  257. SDL_GL_CONTEXT_PROFILE_CORE*: cint = 0x0001
  258. SDL_GL_CONTEXT_PROFILE_COMPATIBILITY*: cint = 0x0002
  259. SDL_GL_CONTEXT_PROFILE_ES*: cint = 0x0004
  260. # GLcontextFlag enum.
  261. SDL_GL_CONTEXT_DEBUG_FLAG*: cint = 0x0001
  262. SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG*: cint = 0x0002
  263. SDL_GL_CONTEXT_ROBUST_ACCESS_FLAG*: cint = 0x0004
  264. SDL_GL_CONTEXT_RESET_ISOLATION_FLAG*: cint = 0x0008
  265. # GLcontextRelease enum.
  266. SDL_GL_CONTEXT_RELEASE_BEHAVIOR_NONE*: cint = 0x0000
  267. SDL_GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH*: cint = 0x0001
  268. type
  269. DisplayMode* = object
  270. format*: cuint
  271. w*,h*,refresh_rate*: cint
  272. driverData*: pointer
  273. WindowPtr* = ptr object
  274. RendererPtr* = ptr object
  275. TexturePtr* = ptr object
  276. CursorPtr* = ptr object
  277. GlContextPtr* = ptr object
  278. SDL_Version* = object
  279. major*, minor*, patch*: uint8
  280. RendererInfoPtr* = ptr RendererInfo
  281. RendererInfo* {.pure, final.} = object
  282. name*: cstring #*< The name of the renderer
  283. flags*: uint32 #*< Supported ::SDL_RendererFlags
  284. num_texture_formats*: uint32 #*< The number of available texture formats
  285. texture_formats*: array[0..16 - 1, uint32] #*< The available texture formats
  286. max_texture_width*: cint #*< The maximimum texture width
  287. max_texture_height*: cint #*< The maximimum texture height
  288. TextureAccess* {.size: sizeof(cint).} = enum
  289. SDL_TEXTUREACCESS_STATIC, SDL_TEXTUREACCESS_STREAMING, SDL_TEXTUREACCESS_TARGET
  290. TextureModulate*{.size:sizeof(cint).} = enum
  291. SDL_TEXTUREMODULATE_NONE, SDL_TEXTUREMODULATE_COLOR, SDL_TEXTUREMODULATE_ALPHA
  292. RendererFlip* = cint
  293. SysWMType* {.size: sizeof(cint).}=enum
  294. SysWM_Unknown, SysWM_Windows, SysWM_X11, SysWM_DirectFB,
  295. SysWM_Cocoa, SysWM_UIkit, SysWM_Wayland, SysWM_Mir, SysWM_WinRT, SysWM_Android, SysWM_Vivante
  296. WMinfo* = object
  297. version*: SDL_Version
  298. subsystem*: SysWMType
  299. padding*: array[64, byte] ## if the low-level stuff is important to you check \
  300. ## SDL_syswm.h and cast padding to the right type
  301. const ## WindowFlags
  302. SDL_WINDOW_FULLSCREEN*:cuint = 0x00000001# /**< fullscreen window */
  303. SDL_WINDOW_OPENGL*:cuint = 0x00000002# /**< window usable with OpenGL context */
  304. SDL_WINDOW_SHOWN*:cuint = 0x00000004# /**< window is visible */
  305. SDL_WINDOW_HIDDEN*:cuint = 0x00000008# /**< window is not visible */
  306. SDL_WINDOW_BORDERLESS*:cuint = 0x00000010# /**< no window decoration */
  307. SDL_WINDOW_RESIZABLE*:cuint = 0x00000020# /**< window can be resized */
  308. SDL_WINDOW_MINIMIZED*:cuint = 0x00000040# /**< window is minimized */
  309. SDL_WINDOW_MAXIMIZED*:cuint = 0x00000080# /**< window is maximized */
  310. SDL_WINDOW_INPUT_GRABBED*:cuint = 0x00000100# /**< window has grabbed input focus */
  311. SDL_WINDOW_INPUT_FOCUS*:cuint = 0x00000200# /**< window has input focus */
  312. SDL_WINDOW_MOUSE_FOCUS*:cuint = 0x00000400# /**< window has mouse focus */
  313. SDL_WINDOW_FULLSCREEN_DESKTOP*:cuint = ( SDL_WINDOW_FULLSCREEN or 0x00001000 )
  314. SDL_WINDOW_FOREIGN*:cuint = 0x00000800# /**< window not created by SDL */
  315. SDL_WINDOW_ALLOW_HIGHDPI*:cuint = 0x00002000# /**< window should be created in high-DPI mode if supported */
  316. SDL_WINDOW_MOUSE_CAPTURE*:cuint = 0x00004000# /**< window has mouse captured (unrelated to INPUT_GRABBED) */
  317. SDL_WINDOW_VULKAN*:cuint = 0x10000000# /**< window usable for Vulkan surface */
  318. SDL_FLIP_NONE*: cint = 0x00000000 # Do not flip
  319. SDL_FLIP_HORIZONTAL*: cint = 0x00000001 # flip horizontally
  320. SDL_FLIP_VERTICAL*: cint = 0x00000002 # flip vertically
  321. converter toBool*(some: Bool32): bool = bool(some)
  322. converter toBool*(some: SDL_Return): bool = some == SdlSuccess
  323. converter toCint*(some: TextureAccess): cint = some.cint
  324. ## pixel format flags
  325. const
  326. SDL_ALPHA_OPAQUE* = 255
  327. SDL_ALPHA_TRANSPARENT* = 0
  328. # @}
  329. #* Pixel type.
  330. const
  331. SDL_PIXELTYPE_UNKNOWN* = 0
  332. SDL_PIXELTYPE_INDEX1* = 1
  333. SDL_PIXELTYPE_INDEX4* = 2
  334. SDL_PIXELTYPE_INDEX8* = 3
  335. SDL_PIXELTYPE_PACKED8* = 4
  336. SDL_PIXELTYPE_PACKED16* = 5
  337. SDL_PIXELTYPE_PACKED32* = 6
  338. SDL_PIXELTYPE_ARRAYU8* = 7
  339. SDL_PIXELTYPE_ARRAYU16* = 8
  340. SDL_PIXELTYPE_ARRAYU32* = 9
  341. SDL_PIXELTYPE_ARRAYF16* = 10
  342. SDL_PIXELTYPE_ARRAYF32* = 11
  343. #* Bitmap pixel order, high bit -> low bit.
  344. const
  345. SDL_BITMAPORDER_NONE* = 0
  346. SDL_BITMAPORDER_4321* = 1
  347. SDL_BITMAPORDER_1234* = 2
  348. #* Packed component order, high bit -> low bit.
  349. const
  350. SDL_PACKEDORDER_NONE* = 0
  351. SDL_PACKEDORDER_XRGB* = 1
  352. SDL_PACKEDORDER_RGBX* = 2
  353. SDL_PACKEDORDER_ARGB* = 3
  354. SDL_PACKEDORDER_RGBA* = 4
  355. SDL_PACKEDORDER_XBGR* = 5
  356. SDL_PACKEDORDER_BGRX* = 6
  357. SDL_PACKEDORDER_ABGR* = 7
  358. SDL_PACKEDORDER_BGRA* = 8
  359. #* Array component order, low byte -> high byte.
  360. const
  361. SDL_ARRAYORDER_NONE* = 0
  362. SDL_ARRAYORDER_RGB* = 1
  363. SDL_ARRAYORDER_RGBA* = 2
  364. SDL_ARRAYORDER_ARGB* = 3
  365. SDL_ARRAYORDER_BGR* = 4
  366. SDL_ARRAYORDER_BGRA* = 5
  367. SDL_ARRAYORDER_ABGR* = 6
  368. #* Packed component layout.
  369. const
  370. SDL_PACKEDLAYOUT_NONE* = 0
  371. SDL_PACKEDLAYOUT_332* = 1
  372. SDL_PACKEDLAYOUT_4444* = 2
  373. SDL_PACKEDLAYOUT_1555* = 3
  374. SDL_PACKEDLAYOUT_5551* = 4
  375. SDL_PACKEDLAYOUT_565* = 5
  376. SDL_PACKEDLAYOUT_8888* = 6
  377. SDL_PACKEDLAYOUT_2101010* = 7
  378. SDL_PACKEDLAYOUT_1010102* = 8
  379. # /* Define a four character code as a Uint32 */
  380. # #define SDL_FOURCC(A, B, C, D) \
  381. # ((SDL_static_cast(Uint32, SDL_static_cast(Uint8, (A))) << 0) | \
  382. # (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (B))) << 8) | \
  383. # (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (C))) << 16) | \
  384. # (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (D))) << 24))
  385. template SDL_FOURCC (a,b,c,d: uint8): uint32 =
  386. uint32(a) or (uint32(b) shl 8) or (uint32(c) shl 16) or (uint32(d) shl 24)
  387. template SDL_DEFINE_PIXELFOURCC*(A, B, C, D: char): uint32 =
  388. SDL_FOURCC(A.uint8, B.uint8, C.uint8, D.uint8)
  389. template SDL_DEFINE_PIXELFORMAT*(`type`, order, layout, bits, bytes: int): uint32 =
  390. uint32((1 shl 28) or ((`type`) shl 24) or ((order) shl 20) or ((layout) shl 16) or
  391. ((bits) shl 8) or ((bytes) shl 0))
  392. template SDL_PIXELFLAG*(X: uint32): int =
  393. int(((X) shr 28) and 0x0000000F)
  394. template SDL_PIXELTYPE*(X: uint32): int =
  395. int(((X) shr 24) and 0x0000000F)
  396. template SDL_PIXELORDER*(X: uint32): int =
  397. int(((X) shr 20) and 0x0000000F)
  398. template SDL_PIXELLAYOUT*(X: uint32): int =
  399. int(((X) shr 16) and 0x0000000F)
  400. template SDL_BITSPERPIXEL*(X: uint32): int =
  401. int(((X) shr 8) and 0x000000FF)
  402. template SDL_BYTESPERPIXEL*(X: uint32): int =
  403. int(if SDL_ISPIXELFORMAT_FOURCC(X): (if (((X) == SDL_PIXELFORMAT_YUY2) or
  404. ((X) == SDL_PIXELFORMAT_UYVY) or ((X) == SDL_PIXELFORMAT_YVYU)): 2 else: 1) else: (
  405. ((X) shr 0) and 0x000000FF))
  406. template SDL_ISPIXELFORMAT_INDEXED*(format: uint32): bool =
  407. (not SDL_ISPIXELFORMAT_FOURCC(format) and
  408. ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX1) or
  409. (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX4) or
  410. (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX8)))
  411. template SDL_ISPIXELFORMAT_ALPHA*(format: uint32): bool =
  412. (not SDL_ISPIXELFORMAT_FOURCC(format) and
  413. ((SDL_PIXELORDER(format) == SDL_PACKEDORDER_ARGB) or
  414. (SDL_PIXELORDER(format) == SDL_PACKEDORDER_RGBA) or
  415. (SDL_PIXELORDER(format) == SDL_PACKEDORDER_ABGR) or
  416. (SDL_PIXELORDER(format) == SDL_PACKEDORDER_BGRA)))
  417. # The flag is set to 1 because 0x1? is not in the printable ASCII range
  418. template SDL_ISPIXELFORMAT_FOURCC*(format: uint32): bool =
  419. ((format != 0) and (SDL_PIXELFLAG(format) != 1))
  420. # Note: If you modify this list, update SDL_GetPixelFormatName()
  421. const
  422. SDL_PIXELFORMAT_UNKNOWN* = 0
  423. SDL_PIXELFORMAT_INDEX1LSB* = SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX1,
  424. SDL_BITMAPORDER_4321, 0, 1, 0)
  425. SDL_PIXELFORMAT_INDEX1MSB* = SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX1,
  426. SDL_BITMAPORDER_1234, 0, 1, 0)
  427. SDL_PIXELFORMAT_INDEX4LSB* = SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX4,
  428. SDL_BITMAPORDER_4321, 0, 4, 0)
  429. SDL_PIXELFORMAT_INDEX4MSB* = SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX4,
  430. SDL_BITMAPORDER_1234, 0, 4, 0)
  431. SDL_PIXELFORMAT_INDEX8* = SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX8, 0, 0,
  432. 8, 1)
  433. SDL_PIXELFORMAT_RGB332* = SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED8,
  434. SDL_PACKEDORDER_XRGB, SDL_PACKEDLAYOUT_332, 8, 1)
  435. SDL_PIXELFORMAT_RGB444* = SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16,
  436. SDL_PACKEDORDER_XRGB, SDL_PACKEDLAYOUT_4444, 12, 2)
  437. SDL_PIXELFORMAT_RGB555* = SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16,
  438. SDL_PACKEDORDER_XRGB, SDL_PACKEDLAYOUT_1555, 15, 2)
  439. SDL_PIXELFORMAT_BGR555* = SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16,
  440. SDL_PACKEDORDER_XBGR, SDL_PACKEDLAYOUT_1555, 15, 2)
  441. SDL_PIXELFORMAT_ARGB4444* = SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16,
  442. SDL_PACKEDORDER_ARGB, SDL_PACKEDLAYOUT_4444, 16, 2)
  443. SDL_PIXELFORMAT_RGBA4444* = SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16,
  444. SDL_PACKEDORDER_RGBA, SDL_PACKEDLAYOUT_4444, 16, 2)
  445. SDL_PIXELFORMAT_ABGR4444* = SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16,
  446. SDL_PACKEDORDER_ABGR, SDL_PACKEDLAYOUT_4444, 16, 2)
  447. SDL_PIXELFORMAT_BGRA4444* = SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16,
  448. SDL_PACKEDORDER_BGRA, SDL_PACKEDLAYOUT_4444, 16, 2)
  449. SDL_PIXELFORMAT_ARGB1555* = SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16,
  450. SDL_PACKEDORDER_ARGB, SDL_PACKEDLAYOUT_1555, 16, 2)
  451. SDL_PIXELFORMAT_RGBA5551* = SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16,
  452. SDL_PACKEDORDER_RGBA, SDL_PACKEDLAYOUT_5551, 16, 2)
  453. SDL_PIXELFORMAT_ABGR1555* = SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16,
  454. SDL_PACKEDORDER_ABGR, SDL_PACKEDLAYOUT_1555, 16, 2)
  455. SDL_PIXELFORMAT_BGRA5551* = SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16,
  456. SDL_PACKEDORDER_BGRA, SDL_PACKEDLAYOUT_5551, 16, 2)
  457. SDL_PIXELFORMAT_RGB565* = SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16,
  458. SDL_PACKEDORDER_XRGB, SDL_PACKEDLAYOUT_565, 16, 2)
  459. SDL_PIXELFORMAT_BGR565* = SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16,
  460. SDL_PACKEDORDER_XBGR, SDL_PACKEDLAYOUT_565, 16, 2)
  461. SDL_PIXELFORMAT_RGB24* = SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU8,
  462. SDL_ARRAYORDER_RGB, 0, 24, 3)
  463. SDL_PIXELFORMAT_BGR24* = SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU8,
  464. SDL_ARRAYORDER_BGR, 0, 24, 3)
  465. SDL_PIXELFORMAT_RGB888* = SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32,
  466. SDL_PACKEDORDER_XRGB, SDL_PACKEDLAYOUT_8888, 24, 4)
  467. SDL_PIXELFORMAT_RGBX8888* = SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32,
  468. SDL_PACKEDORDER_RGBX, SDL_PACKEDLAYOUT_8888, 24, 4)
  469. SDL_PIXELFORMAT_BGR888* = SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32,
  470. SDL_PACKEDORDER_XBGR, SDL_PACKEDLAYOUT_8888, 24, 4)
  471. SDL_PIXELFORMAT_BGRX8888* = SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32,
  472. SDL_PACKEDORDER_BGRX, SDL_PACKEDLAYOUT_8888, 24, 4)
  473. SDL_PIXELFORMAT_ARGB8888* = SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32,
  474. SDL_PACKEDORDER_ARGB, SDL_PACKEDLAYOUT_8888, 32, 4)
  475. SDL_PIXELFORMAT_RGBA8888* = SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32,
  476. SDL_PACKEDORDER_RGBA, SDL_PACKEDLAYOUT_8888, 32, 4)
  477. SDL_PIXELFORMAT_ABGR8888* = SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32,
  478. SDL_PACKEDORDER_ABGR, SDL_PACKEDLAYOUT_8888, 32, 4)
  479. SDL_PIXELFORMAT_BGRA8888* = SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32,
  480. SDL_PACKEDORDER_BGRA, SDL_PACKEDLAYOUT_8888, 32, 4)
  481. SDL_PIXELFORMAT_ARGB2101010* = SDL_DEFINE_PIXELFORMAT(
  482. SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_ARGB, SDL_PACKEDLAYOUT_2101010,
  483. 32, 4)
  484. SDL_PIXELFORMAT_YV12* = SDL_DEFINE_PIXELFOURCC('Y', 'V', '1', '2') #*< Planar mode: Y + V + U (3 planes)
  485. SDL_PIXELFORMAT_IYUV* = SDL_DEFINE_PIXELFOURCC('I', 'Y', 'U', 'V') #*< Planar mode: Y + U + V (3 planes)
  486. SDL_PIXELFORMAT_YUY2* = SDL_DEFINE_PIXELFOURCC('Y', 'U', 'Y', '2') #*< Packed mode: Y0+U0+Y1+V0 (1 plane)
  487. SDL_PIXELFORMAT_UYVY* = SDL_DEFINE_PIXELFOURCC('U', 'Y', 'V', 'Y') #*< Packed mode: U0+Y0+V0+Y1 (1 plane)
  488. SDL_PIXELFORMAT_YVYU* = SDL_DEFINE_PIXELFOURCC('Y', 'V', 'Y', 'U') #*< Packed mode: Y0+V0+Y1+U0 (1 plane)
  489. type
  490. Color* {.pure, final.} = tuple[
  491. r: uint8,
  492. g: uint8,
  493. b: uint8,
  494. a: uint8]
  495. Palette* {.pure, final.} = object
  496. ncolors*: cint
  497. colors*: ptr Color
  498. version*: uint32
  499. refcount*: cint
  500. PixelFormat* {.pure, final.} = object
  501. format*: uint32
  502. palette*: ptr Palette
  503. BitsPerPixel*: uint8
  504. BytesPerPixel*: uint8
  505. padding*: array[0..2 - 1, uint8]
  506. Rmask*: uint32
  507. Gmask*: uint32
  508. Bmask*: uint32
  509. Amask*: uint32
  510. Rloss*: uint8
  511. Gloss*: uint8
  512. Bloss*: uint8
  513. Aloss*: uint8
  514. Rshift*: uint8
  515. Gshift*: uint8
  516. Bshift*: uint8
  517. Ashift*: uint8
  518. refcount*: cint
  519. next*: ptr PixelFormat
  520. BlitMapPtr*{.pure.} = ptr object ##couldnt find SDL_BlitMap ?
  521. SurfacePtr* = ptr Surface
  522. Surface* {.pure, final.} = object
  523. flags*: uint32 #*< Read-only
  524. format*: ptr PixelFormat #*< Read-only
  525. w*, h*, pitch*: int32 #*< Read-only
  526. pixels*: pointer #*< Read-write
  527. userdata*: pointer #*< Read-write
  528. locked*: int32 #*< Read-only ## see if this should be Bool32
  529. lock_data*: pointer #*< Read-only
  530. clip_rect*: Rect #*< Read-only
  531. map: BlitMapPtr #*< Private
  532. refcount*: cint #*< Read-mostly
  533. BlendMode* {.size: sizeof(cint).} = enum
  534. BlendMode_None = 0x00000000, #*< No blending
  535. BlendMode_Blend = 0x00000001, #*< dst = (src * A) + (dst * (1-A))
  536. BlendMode_Add = 0x00000002, #*< dst = (src * A) + dst
  537. BlendMode_Mod = 0x00000004 #*< dst = src * dst
  538. BlitFunction* = proc(src: SurfacePtr; srcrect: ptr Rect; dst: SurfacePtr;
  539. dstrect: ptr Rect): cint{.cdecl.}
  540. TimerCallback* = proc (interval: uint32; param: pointer): uint32{.cdecl.}
  541. TimerID* = cint
  542. const ##RendererFlags
  543. Renderer_Software*: cint = 0x00000001
  544. Renderer_Accelerated*: cint = 0x00000002
  545. Renderer_PresentVsync*: cint = 0x00000004
  546. Renderer_TargetTexture*: cint = 0x00000008
  547. const ## These are the currently supported flags for the ::SDL_surface.
  548. SDL_SWSURFACE* = 0 #*< Just here for compatibility
  549. SDL_PREALLOC* = 0x00000001 #*< Surface uses preallocated memory
  550. SDL_RLEACCEL* = 0x00000002 #*< Surface is RLE encoded
  551. SDL_DONTFREE* = 0x00000004 #*< Surface is referenced internally
  552. template SDL_MUSTLOCK*(some: SurfacePtr): bool = (some.flags and SDL_RLEACCEL) != 0
  553. const
  554. INIT_TIMER* = 0x00000001
  555. INIT_AUDIO* = 0x00000010
  556. INIT_VIDEO* = 0x00000020
  557. INIT_JOYSTICK* = 0x00000200
  558. INIT_HAPTIC* = 0x00001000
  559. INIT_GAMECONTROLLER* = 0x00002000
  560. INIT_EVENTS* = 0x00004000
  561. INIT_NOPARACHUTE* = 0x00100000
  562. INIT_EVERYTHING* = 0x0000FFFF
  563. const SDL_WINDOWPOS_UNDEFINED_MASK* = 0x1FFF0000
  564. template SDL_WINDOWPOS_UNDEFINED_DISPLAY*(X: cint): untyped = cint(SDL_WINDOWPOS_UNDEFINED_MASK or X)
  565. const SDL_WINDOWPOS_UNDEFINED*: cint = SDL_WINDOWPOS_UNDEFINED_DISPLAY(0)
  566. template SDL_WINDOWPOS_ISUNDEFINED*(X: cint): bool = (((X) and 0xFFFF0000) == SDL_WINDOWPOS_UNDEFINED_MASK)
  567. const SDL_WINDOWPOS_CENTERED_MASK* = 0x2FFF0000
  568. template SDL_WINDOWPOS_CENTERED_DISPLAY*(X: cint): cint = cint(SDL_WINDOWPOS_CENTERED_MASK or X)
  569. const SDL_WINDOWPOS_CENTERED*: cint = SDL_WINDOWPOS_CENTERED_DISPLAY(0)
  570. template SDL_WINDOWPOS_ISCENTERED*(X: cint): bool = (((X) and 0xFFFF0000) == SDL_WINDOWPOS_CENTERED_MASK)
  571. template evConv(name, name2, ptype: untyped; valid: openarray[EventType]): untyped =
  572. proc `name`* (event: Event): ptype =
  573. assert event.kind in valid
  574. return cast[ptype](unsafeAddr event)
  575. proc `name2`* (event: Event): ptype =
  576. assert event.kind in valid
  577. return cast[ptype](unsafeAddr event)
  578. evConv(evWindow, window, WindowEventPtr, [WindowEvent])
  579. evConv(evKeyboard, key, KeyboardEventPtr, [KeyDown, KeyUP])
  580. evConv(evTextEditing, edit, TextEditingEventPtr, [TextEditing])
  581. evConv(evTextInput, text, TextInputEventPtr, [TextInput])
  582. evConv(evMouseMotion, motion, MouseMotionEventPtr, [MouseMotion])
  583. evConv(evMouseButton, button, MouseButtonEventPtr, [MouseButtonDown, MouseButtonUp])
  584. evConv(evMouseWheel, wheel, MouseWheelEventPtr, [MouseWheel])
  585. evConv(EvJoyAxis, jaxis, JoyAxisEventPtr, [JoyAxisMotion])
  586. evConv(EvJoyBall, jball, JoyBallEventPtr, [JoyBallMotion])
  587. evConv(EvJoyHat, jhat, JoyHatEventPtr, [JoyHatMotion])
  588. evConv(EvJoyButton, jbutton, JoyButtonEventPtr, [JoyButtonDown, JoyButtonUp])
  589. evConv(EvJoyDevice, jdevice, JoyDeviceEventPtr, [JoyDeviceAdded, JoyDeviceRemoved])
  590. evConv(EvControllerAxis, caxis, ControllerAxisEventPtr, [ControllerAxisMotion])
  591. evConv(EvControllerButton, cbutton, ControllerButtonEventPtr, [ControllerButtonDown, ControllerButtonUp])
  592. evConv(EvControllerDevice, cdevice, ControllerDeviceEventPtr, [ControllerDeviceAdded, ControllerDeviceRemoved])
  593. evConv(EvTouchFinger, tfinger, TouchFingerEventPtr, [FingerMotion, FingerDown, FingerUp])
  594. evConv(EvMultiGesture, mgesture, MultiGestureEventPtr, [MultiGesture])
  595. evConv(EvDollarGesture, dgesture, DollarGestureEventPtr, [DollarGesture])
  596. evConv(evDropFile, drop, DropEventPtr, [DropFile])
  597. evConv(evQuit, quit, QuitEventPtr, [QuitEvent])
  598. evConv(evUser, user, UserEventPtr, [UserEvent, UserEvent1, UserEvent2, UserEvent3, UserEvent4, UserEvent5])
  599. #evConv(EvSysWM, syswm, SysWMEventPtr, {SysWMEvent})
  600. const ## SDL_MessageBox flags. If supported will display warning icon, etc.
  601. SDL_MESSAGEBOX_ERROR* = 0x00000010 #*< error dialog
  602. SDL_MESSAGEBOX_WARNING* = 0x00000020 #*< warning dialog
  603. SDL_MESSAGEBOX_INFORMATION* = 0x00000040 #*< informational dialog
  604. ## Flags for SDL_MessageBoxButtonData.
  605. SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT* = 0x00000001 #*< Marks the default button when return is hit
  606. SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT* = 0x00000002 #*< Marks the default button when escape is hit
  607. type
  608. MessageBoxColor* {.pure, final.} = object
  609. r*: uint8
  610. g*: uint8
  611. b*: uint8
  612. MessageBoxColorType* = enum
  613. SDL_MESSAGEBOX_COLOR_BACKGROUND, SDL_MESSAGEBOX_COLOR_TEXT,
  614. SDL_MESSAGEBOX_COLOR_BUTTON_BORDER,
  615. SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND,
  616. SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED, SDL_MESSAGEBOX_COLOR_MAX
  617. MessageBoxColorScheme* {.pure, final.} = object
  618. colors*: array[MessageBoxColorType, MessageBoxColor]
  619. MessageBoxButtonData* {.pure, final.} = object
  620. flags*: cint #*< ::SDL_MessageBoxButtonFlags
  621. buttonid*: cint #*< User defined button id (value returned via SDL_MessageBox)
  622. text*: cstring #*< The UTF-8 button text
  623. MessageBoxData* {.pure, final.} = object
  624. flags*: cint #*< ::SDL_MessageBoxFlags
  625. window*: WindowPtr #*< Parent window, can be NULL
  626. title*, message*: cstring #*< UTF-8 title and message text
  627. numbuttons*: cint
  628. buttons*: ptr MessageBoxButtonData
  629. colorScheme*: ptr MessageBoxColorScheme #*< ::SDL_MessageBoxColorScheme, can be NULL to use system settings
  630. RWopsPtr* = ptr RWops
  631. RWops* {.pure, final.} = object
  632. size*: proc (context: RWopsPtr): int64 {.cdecl, tags: [], raises: [].}
  633. seek*: proc (context: RWopsPtr; offset: int64; whence: cint): int64 {.cdecl, tags: [], raises: [].}
  634. read*: proc (context: RWopsPtr; destination: pointer; size, maxnum: csize_t_const): csize_t_const {.cdecl, tags: [ReadIOEffect], raises: [].}
  635. write*: proc (context: RWopsPtr; source: pointer; size: csize_t_const;
  636. num: csize_t_const): csize_t_const {.cdecl, tags: [WriteIOEffect], raises: [].}
  637. close*: proc (context: RWopsPtr): cint {.cdecl, tags: [WriteIOEffect].}
  638. kind*: cint
  639. mem*: Mem
  640. Mem*{.final.} = object
  641. base*: ptr byte
  642. here*: ptr byte
  643. stop*: ptr byte
  644. # SDL_system.h
  645. type VoidCallback* = proc(arg:pointer):void{.cdecl.}
  646. const SDL_ANDROID_EXTERNAL_STORAGE_READ* = cint(0x01)
  647. const SDL_ANDROID_EXTERNAL_STORAGE_WRITE* = cint(0x02)
  648. when not defined(SDL_Static):
  649. {.push callConv: cdecl, dynlib: LibName.}
  650. ## functions whose names have been shortened by elision of a type name
  651. proc getWMInfo*(window: WindowPtr; info: var WMInfo): Bool32 {.
  652. importc: "SDL_GetWindowWMInfo".}
  653. proc setLogicalSize*(renderer: RendererPtr; w, h: cint): cint {.
  654. importc: "SDL_RenderSetLogicalSize".}
  655. proc getLogicalSize*(renderer: RendererPtr; w, h: var cint) {.
  656. importc: "SDL_RenderGetLogicalSize".}
  657. proc setDrawColor*(renderer: RendererPtr; r, g, b: uint8, a = 255'u8): SDL_Return {.
  658. importc: "SDL_SetRenderDrawColor", discardable.}
  659. proc setDrawColor*(renderer: RendererPtr; c: Color) =
  660. setDrawColor(renderer, c.r, c.g, c.b, c.a)
  661. proc getDrawColor*(renderer: RendererPtr; r, g, b, a: var uint8): SDL_Return {.
  662. importc: "SDL_GetRenderDrawColor", discardable.}
  663. proc setDrawBlendMode*(renderer: RendererPtr; blendMode: BlendMode): SDL_Return {.
  664. importc: "SDL_SetRenderDrawBlendMode", discardable.}
  665. proc getDrawBlendMode*(renderer: RendererPtr;
  666. blendMode: var BlendMode): SDL_Return {.
  667. importc: "SDL_GetRenderDrawBlendMode", discardable.}
  668. proc destroy*(texture: TexturePtr) {.importc: "SDL_DestroyTexture".}
  669. proc destroy*(renderer: RendererPtr) {.importc: "SDL_DestroyRenderer".}
  670. #proc destroy* (texture: TexturePtr) {.inline.} = texture.destroyTexture
  671. #proc destroy* (renderer: RendererPtr) {.inline.} = renderer.destroyRenderer
  672. proc getDisplayIndex*(window: WindowPtr): cint {.importc: "SDL_GetWindowDisplayIndex".}
  673. #*
  674. proc setDisplayMode*(window: WindowPtr;
  675. mode: ptr DisplayMode): SDL_Return {.importc: "SDL_SetWindowDisplayMode".}
  676. #*
  677. proc getDisplayMode*(window: WindowPtr; mode: var DisplayMode): cint {.
  678. importc: "SDL_GetWindowDisplayMode".}
  679. #*
  680. proc getPixelFormat*(window: WindowPtr): uint32 {.importc: "SDL_GetWindowPixelFormat".}
  681. #*
  682. # \brief Get the numeric ID of a window, for logging purposes.
  683. #
  684. proc getID*(window: WindowPtr): uint32 {.importc: "SDL_GetWindowID".}
  685. #*
  686. # \brief Get the window flags.
  687. #
  688. proc getFlags*(window: WindowPtr): uint32 {.importc: "SDL_GetWindowFlags".}
  689. #*
  690. # \brief Set the title of a window, in UTF-8 format.
  691. #
  692. # \sa SDL_GetWindowTitle()
  693. #
  694. proc setTitle*(window: WindowPtr; title: cstring) {.importc: "SDL_SetWindowTitle".}
  695. #*
  696. # \brief Get the title of a window, in UTF-8 format.
  697. #
  698. # \sa SDL_SetWindowTitle()
  699. #
  700. proc getTitle*(window: WindowPtr): cstring {.importc: "SDL_GetWindowTitle".}
  701. #*
  702. # \brief Set the icon for a window.
  703. #
  704. # \param icon The icon for the window.
  705. #
  706. proc setIcon*(window: WindowPtr; icon: SurfacePtr) {.importc: "SDL_SetWindowIcon".}
  707. #*
  708. proc setData*(window: WindowPtr; name: cstring;
  709. userdata: pointer): pointer {.importc: "SDL_SetWindowData".}
  710. #*
  711. proc getData*(window: WindowPtr; name: cstring): pointer {.importc: "SDL_GetWindowData".}
  712. #*
  713. proc setPosition*(window: WindowPtr; x, y: cint) {.importc: "SDL_SetWindowPosition".}
  714. proc getPosition*(window: WindowPtr; x, y: var cint) {.importc: "SDL_GetWindowPosition".}
  715. #*
  716. proc setSize*(window: WindowPtr; w, h: cint) {.importc: "SDL_SetWindowSize".}
  717. proc getSize*(window: WindowPtr; w, h: var cint) {.importc: "SDL_GetWindowSize".}
  718. proc setBordered*(window: WindowPtr; bordered: Bool32) {.importc: "SDL_SetWindowBordered".}
  719. proc setFullscreen*(window: WindowPtr; fullscreen: uint32): SDL_Return {.importc: "SDL_SetWindowFullscreen".}
  720. proc getSurface*(window: WindowPtr): SurfacePtr {.importc: "SDL_GetWindowSurface".}
  721. proc updateSurface*(window: WindowPtr): SDL_Return {.importc: "SDL_UpdateWindowSurface".}
  722. proc updateSurfaceRects*(window: WindowPtr; rects: ptr Rect;
  723. numrects: cint): SDL_Return {.importc: "SDL_UpdateWindowSurfaceRects".}
  724. #*
  725. proc setGrab*(window: WindowPtr; grabbed: Bool32) {.importc: "SDL_SetWindowGrab".}
  726. proc getGrab*(window: WindowPtr): Bool32 {.importc: "SDL_GetWindowGrab".}
  727. proc setBrightness*(window: WindowPtr; brightness: cfloat): SDL_Return {.importc: "SDL_SetWindowBrightness".}
  728. proc getBrightness*(window: WindowPtr): cfloat {.importc: "SDL_GetWindowBrightness".}
  729. proc setGammaRamp*(window: WindowPtr;
  730. red, green, blue: ptr uint16): SDL_Return {.importc: "SDL_SetWindowGammaRamp".}
  731. #*
  732. # \brief Get the gamma ramp for a window.
  733. #
  734. # \param red A pointer to a 256 element array of 16-bit quantities to hold
  735. # the translation table for the red channel, or NULL.
  736. # \param green A pointer to a 256 element array of 16-bit quantities to hold
  737. # the translation table for the green channel, or NULL.
  738. # \param blue A pointer to a 256 element array of 16-bit quantities to hold
  739. # the translation table for the blue channel, or NULL.
  740. #
  741. # \return 0 on success, or -1 if gamma ramps are unsupported.
  742. #
  743. # \sa SDL_SetWindowGammaRamp()
  744. #
  745. proc getGammaRamp*(window: WindowPtr; red: ptr uint16;
  746. green: ptr uint16; blue: ptr uint16): cint {.importc: "SDL_GetWindowGammaRamp".}
  747. proc init*(flags: cint): SDL_Return {.discardable,
  748. importc: "SDL_Init".}
  749. #
  750. # This function initializes specific SDL subsystems
  751. #
  752. proc initSubSystem*(flags: uint32):cint {.
  753. importc: "SDL_InitSubSystem".}
  754. #
  755. # This function cleans up specific SDL subsystems
  756. #
  757. proc quitSubSystem*(flags: uint32) {.
  758. importc: "SDL_QuitSubSystem".}
  759. #
  760. # This function returns a mask of the specified subsystems which have
  761. # previously been initialized.
  762. #
  763. # If \c flags is 0, it returns a mask of all initialized subsystems.
  764. #
  765. proc wasInit*(flags: uint32): uint32 {.
  766. importc: "SDL_WasInit".}
  767. proc quit*() {.
  768. importc: "SDL_Quit".}
  769. proc getPlatform*(): cstring {.
  770. importc: "SDL_GetPlatform".}
  771. proc getVersion*(ver: var SDL_Version) {.
  772. importc: "SDL_GetVersion".}
  773. proc getRevision*(): cstring {.
  774. importc: "SDL_GetRevision".}
  775. proc getRevisionNumber*(): cint {.
  776. importc: "SDL_GetRevisionNumber".}
  777. proc getBasePath*(): cstring {.
  778. importc: "SDL_GetBasePath".}
  779. proc getPrefPath*(org, app: cstring): cstring {.
  780. importc: "SDL_GetPrefPath".}
  781. proc getNumRenderDrivers*(): cint {.
  782. importc: "SDL_GetNumRenderDriver".}
  783. proc getRenderDriverInfo*(index: cint; info: var RendererInfo): SDL_Return {.
  784. importc: "SDL_GetRenderDriverInfo".}
  785. proc createWindowAndRenderer*(width, height: cint; window_flags: uint32;
  786. window: var WindowPtr; renderer: var RendererPtr): SDL_Return {.
  787. importc: "SDL_CreateWindowAndRenderer".}
  788. proc createRenderer*(window: WindowPtr; index: cint; flags: cint): RendererPtr {.
  789. importc: "SDL_CreateRenderer".}
  790. proc createSoftwareRenderer*(surface: SurfacePtr): RendererPtr {.
  791. importc: "SDL_CreateSoftwareRenderer".}
  792. proc getRenderer*(window: WindowPtr): RendererPtr {.
  793. importc: "SDL_GetRenderer".}
  794. proc getRendererInfo*(renderer: RendererPtr; info: RendererInfoPtr): cint {.
  795. importc: "SDL_GetRendererInfo".}
  796. proc getRendererOutputSize*(renderer: RendererPtr, w: ptr cint, h: ptr cint): cint {.
  797. importc: "SDL_GetRendererOutputSize".}
  798. proc createTexture*(renderer: RendererPtr; format: uint32;
  799. access, w, h: cint): TexturePtr {.
  800. importc: "SDL_CreateTexture".}
  801. proc createTextureFromSurface*(renderer: RendererPtr; surface: SurfacePtr): TexturePtr {.
  802. importc: "SDL_CreateTextureFromSurface".}
  803. proc createTexture*(renderer: RendererPtr; surface: SurfacePtr): TexturePtr {.
  804. inline.} = renderer.createTextureFromSurface(surface)
  805. proc queryTexture*(texture: TexturePtr; format: ptr uint32;
  806. access, w, h: ptr cint): SDL_Return {.discardable,
  807. importc: "SDL_QueryTexture".}
  808. proc setTextureColorMod*(texture: TexturePtr; r, g, b: uint8): SDL_Return {.
  809. importc: "SDL_SetTextureColorMod".}
  810. proc getTextureColorMod*(texture: TexturePtr; r, g, b: var uint8): SDL_Return {.
  811. importc: "SDL_GetTextureColorMod".}
  812. proc setTextureAlphaMod*(texture: TexturePtr; alpha: uint8): SDL_Return {.
  813. importc: "SDL_SetTextureAlphaMod", discardable.}
  814. proc getTextureAlphaMod*(texture: TexturePtr; alpha: var uint8): SDL_Return {.
  815. importc: "SDL_GetTextureAlphaMod", discardable.}
  816. proc setTextureBlendMode*(texture: TexturePtr; blendMode: BlendMode): SDL_Return {.
  817. importc: "SDL_SetTextureBlendMode", discardable.}
  818. proc getTextureBlendMode*(texture: TexturePtr;
  819. blendMode: var BlendMode): SDL_Return {.importc: "SDL_GetTextureBlendMode", discardable.}
  820. proc updateTexture*(texture: TexturePtr; rect: ptr Rect; pixels: pointer;
  821. pitch: cint): SDL_Return {.importc: "SDL_UpdateTexture", discardable.}
  822. proc lockTexture*(texture: TexturePtr; rect: ptr Rect; pixels: ptr pointer;
  823. pitch: ptr cint): SDL_Return {.importc: "SDL_LockTexture", discardable.}
  824. proc unlockTexture*(texture: TexturePtr) {.importc: "SDL_UnlockTexture".}
  825. proc renderTargetSupported*(renderer: RendererPtr): Bool32 {.
  826. importc: "SDL_RenderTargetSupported".}
  827. proc setRenderTarget*(renderer: RendererPtr; texture: TexturePtr): SDL_Return {.discardable,
  828. importc: "SDL_SetRenderTarget".}
  829. #*
  830. #
  831. proc getRenderTarget*(renderer: RendererPtr): TexturePtr {.
  832. importc: "SDL_GetRenderTarget".}
  833. #*
  834. # \brief Set the drawing area for rendering on the current target.
  835. #
  836. # \param rect The rectangle representing the drawing area, or NULL to set the viewport to the entire target.
  837. #
  838. # The x,y of the viewport rect represents the origin for rendering.
  839. #
  840. # \note When the window is resized, the current viewport is automatically
  841. # centered within the new window size.
  842. #
  843. # \sa SDL_RenderGetViewport()
  844. # \sa SDL_RenderSetLogicalSize()
  845. #
  846. proc setViewport*(renderer: RendererPtr; rect: ptr Rect): SDL_Return {.
  847. importc: "SDL_RenderSetViewport", discardable.}
  848. proc getViewport*(renderer: RendererPtr; rect: var Rect) {.
  849. importc: "SDL_RenderGetViewport".}
  850. proc setScale*(renderer: RendererPtr; scaleX, scaleY: cfloat): SDL_Return {.
  851. importc: "SDL_RenderSetScale", discardable.}
  852. proc getScale*(renderer: RendererPtr; scaleX, scaleY: var cfloat) {.
  853. importc: "SDL_RenderGetScale".}
  854. proc drawPoint*(renderer: RendererPtr; x, y: cint): SDL_Return {.
  855. importc: "SDL_RenderDrawPoint", discardable.}
  856. #*
  857. proc drawPoints*(renderer: RendererPtr; points: ptr Point;
  858. count: cint): SDL_Return {.importc: "SDL_RenderDrawPoints", discardable.}
  859. proc drawLine*(renderer: RendererPtr;
  860. x1, y1, x2, y2: cint): SDL_Return {.
  861. importc: "SDL_RenderDrawLine", discardable.}
  862. #*
  863. proc drawLines*(renderer: RendererPtr; points: ptr Point;
  864. count: cint): SDL_Return {.importc: "SDL_RenderDrawLines", discardable.}
  865. proc drawRect*(renderer: RendererPtr; rect: var Rect): SDL_Return{.
  866. importc: "SDL_RenderDrawRect", discardable.}
  867. proc drawRect*(renderer: RendererPtr; rect: ptr Rect = nil): SDL_Return{.
  868. importc: "SDL_RenderDrawRect", discardable.}
  869. proc drawRects*(renderer: RendererPtr; rects: ptr Rect;
  870. count: cint): SDL_Return {.importc: "SDL_RenderDrawRects".}
  871. proc fillRect*(renderer: RendererPtr; rect: var Rect): SDL_Return {.
  872. importc: "SDL_RenderFillRect", discardable.}
  873. proc fillRect*(renderer: RendererPtr; rect: ptr Rect = nil): SDL_Return {.
  874. importc: "SDL_RenderFillRect", discardable.}
  875. #*
  876. proc fillRects*(renderer: RendererPtr; rects: ptr Rect;
  877. count: cint): SDL_Return {.importc: "SDL_RenderFillRects", discardable.}
  878. proc copy*(renderer: RendererPtr; texture: TexturePtr;
  879. srcrect, dstrect: ptr Rect): SDL_Return {.
  880. importc: "SDL_RenderCopy", discardable.}
  881. proc copyEx*(renderer: RendererPtr; texture: TexturePtr;
  882. srcrect, dstrect: var Rect; angle: cdouble; center: ptr Point;
  883. flip: RendererFlip = SDL_FLIP_NONE): SDL_Return {.
  884. importc: "SDL_RenderCopyEx", discardable.}
  885. proc copyEx*(renderer: RendererPtr; texture: TexturePtr;
  886. srcrect, dstrect: ptr Rect; angle: cdouble; center: ptr Point;
  887. flip: RendererFlip = SDL_FLIP_NONE): SDL_Return {.
  888. importc: "SDL_RenderCopyEx", discardable.}
  889. proc clear*(renderer: RendererPtr): cint {.
  890. importc: "SDL_RenderClear", discardable.}
  891. proc readPixels*(renderer: RendererPtr; rect: var Rect; format: cint;
  892. pixels: pointer; pitch: cint): cint {.importc: "SDL_RenderReadPixels".}
  893. proc readPixels*(renderer: RendererPtr; rect: ptr Rect; format: cint;
  894. pixels: pointer; pitch: cint): cint {.importc: "SDL_RenderReadPixels".}
  895. proc present*(renderer: RendererPtr) {.importc: "SDL_RenderPresent".}
  896. proc glBindTexture*(texture: TexturePtr; texw, texh: var cfloat): cint {.
  897. importc: "SDL_GL_BindTexture".}
  898. proc glUnbindTexture*(texture: TexturePtr) {.
  899. importc: "SDL_GL_UnbindTexture".}
  900. proc createRGBSurface*(flags: cint; width, height, depth: cint;
  901. Rmask, Gmask, BMask, Amask: uint32): SurfacePtr {.
  902. importc: "SDL_CreateRGBSurface".}
  903. proc createRGBSurfaceFrom*(pixels: pointer; width, height, depth, pitch: cint;
  904. Rmask, Gmask, Bmask, Amask: uint32): SurfacePtr {.
  905. importc: "SDL_CreateRGBSurfaceFrom".}
  906. proc freeSurface*(surface: SurfacePtr) {.
  907. importc: "SDL_FreeSurface".}
  908. proc setSurfacePalette*(surface: SurfacePtr; palette: ptr Palette): cint {.
  909. importc:"SDL_SetSurfacePalette".}
  910. #*
  911. # \brief Sets up a surface for directly accessing the pixels.
  912. #
  913. # Between calls to SDL_LockSurface() / SDL_UnlockSurface(), you can write
  914. # to and read from \c surface->pixels, using the pixel format stored in
  915. # \c surface->format. Once you are done accessing the surface, you should
  916. # use SDL_UnlockSurface() to release it.
  917. #
  918. # Not all surfaces require locking. If SDL_MUSTLOCK(surface) evaluates
  919. # to 0, then you can read and write to the surface at any time, and the
  920. # pixel format of the surface will not change.
  921. #
  922. # No operating system or library calls should be made between lock/unlock
  923. # pairs, as critical system locks may be held during this time.
  924. #
  925. # SDL_LockSurface() returns 0, or -1 if the surface couldn't be locked.
  926. #
  927. # \sa SDL_UnlockSurface()
  928. #
  929. proc lockSurface*(surface: SurfacePtr): cint {.importc: "SDL_LockSurface".}
  930. #* \sa SDL_LockSurface()
  931. proc unlockSurface*(surface: SurfacePtr) {.importc: "SDL_UnlockSurface".}
  932. #*
  933. # Load a surface from a seekable SDL data stream (memory or file).
  934. #
  935. # If \c freesrc is non-zero, the stream will be closed after being read.
  936. #
  937. # The new surface should be freed with SDL_FreeSurface().
  938. #
  939. # \return the new surface, or NULL if there was an error.
  940. #
  941. proc loadBMP_RW*(src: RWopsPtr; freesrc: cint): SurfacePtr {.
  942. importc: "SDL_LoadBMP_RW".}
  943. proc rwFromFile*(file: cstring; mode: cstring): RWopsPtr {.importc: "SDL_RWFromFile".}
  944. proc rwFromFP*(fp: File; autoclose: Bool32): RWopsPtr {.importc: "SDL_RWFromFP".}
  945. proc rwFromMem*(mem: pointer; size: cint): RWopsPtr {.importc: "SDL_RWFromMem".}
  946. proc rwFromConstMem*(mem: pointer; size: cint): RWopsPtr {.importc: "SDL_RWFromConstMem".}
  947. proc allocRW* : RWopsPtr {.importc: "SDL_AllocRW".}
  948. proc freeRW* (area: RWopsPtr) {.importc: "SDL_FreeRW".}
  949. #*
  950. # Load a surface from a file.
  951. #
  952. # Convenience macro.
  953. #
  954. #*
  955. proc saveBMP_RW*(surface: SurfacePtr; dst: RWopsPtr;
  956. freedst: cint): SDL_Return {.importc: "SDL_SaveBMP_RW".}
  957. proc setSurfaceRLE*(surface: SurfacePtr; flag: cint): cint {.
  958. importc:"SDL_SetSurfaceRLE".}
  959. proc setColorKey*(surface: SurfacePtr; flag: cint; key: uint32): cint {.
  960. importc: "SDL_SetColorKey".}
  961. proc getColorKey*(surface: SurfacePtr; key: var uint32): cint {.
  962. importc: "SDL_GetColorKey".}
  963. proc setSurfaceColorMod*(surface: SurfacePtr; r, g, b: uint8): cint {.
  964. importc: "SDL_SetSurfaceColorMod".}
  965. proc getSurfaceColorMod*(surface: SurfacePtr; r, g, b: var uint8): cint {.
  966. importc: "SDL_GetSurfaceColorMod".}
  967. proc setSurfaceAlphaMod*(surface: SurfacePtr; alpha: uint8): cint {.
  968. importc: "SDL_SetSurfaceAlphaMod".}
  969. proc getSurfaceAlphaMod*(surface: SurfacePtr; alpha: var uint8): cint {.
  970. importc: "SDL_GetSurfaceAlphaMod".}
  971. proc setSurfaceBlendMode*(surface: SurfacePtr; blendMode: BlendMode): cint {.
  972. importc: "SDL_SetSurfaceBlendMode".}
  973. proc getSurfaceBlendMode*(surface: SurfacePtr; blendMode: ptr BlendMode): cint {.
  974. importc: "SDL_GetSurfaceBlendMode".}
  975. proc setClipRect*(surface: SurfacePtr; rect: ptr Rect): Bool32 {.
  976. importc: "SDL_SetClipRect".}
  977. proc getClipRect*(surface: SurfacePtr; rect: ptr Rect) {.
  978. importc: "SDL_GetClipRect".}
  979. proc setClipRect*(renderer: RendererPtr; rect: ptr Rect): cint {.
  980. importc: "SDL_RenderSetClipRect".}
  981. proc getClipRect*(renderer: RendererPtr; rect: ptr Rect): cint {.
  982. importc: "SDL_RenderGetClipRect".}
  983. proc isClipEnabled*(renderer: RendererPtr): cint {.
  984. importc: "SDL_RenderIsClipEnabled".}
  985. proc convertSurface*(src: SurfacePtr; fmt: ptr PixelFormat;
  986. flags: cint): SurfacePtr {.importc: "SDL_ConvertSurface".}
  987. proc convertSurfaceFormat*(src: SurfacePtr; pixel_format,
  988. flags: uint32): SurfacePtr {.importc: "SDL_ConvertSurfaceFormat".}
  989. proc convertPixels*(width, height: cint; src_format: uint32; src: pointer;
  990. src_pitch: cint; dst_format: uint32; dst: pointer; dst_pitch: cint): cint {.
  991. importc: "SDL_ConvertPixels".}
  992. #*
  993. # Performs a fast fill of the given rectangle with \c color.
  994. #
  995. # If \c rect is NULL, the whole surface will be filled with \c color.
  996. #
  997. # The color should be a pixel of the format used by the surface, and
  998. # can be generated by the SDL_MapRGB() function.
  999. #
  1000. # \return 0 on success, or -1 on error.
  1001. #
  1002. proc fillRect*(dst: SurfacePtr; rect: ptr Rect; color: uint32): SDL_Return {.
  1003. importc: "SDL_FillRect", discardable.}
  1004. proc fillRects*(dst: SurfacePtr; rects: ptr Rect; count: cint;
  1005. color: uint32): cint {.importc: "SDL_FillRects".}
  1006. proc upperBlit*(src: SurfacePtr; srcrect: ptr Rect; dst: SurfacePtr;
  1007. dstrect: ptr Rect): SDL_Return {.importc: "SDL_UpperBlit".}
  1008. proc lowerBlit*(src: SurfacePtr; srcrect: ptr Rect; dst: SurfacePtr;
  1009. dstrect: ptr Rect): SDL_Return {.importc: "SDL_LowerBlit".}
  1010. proc softStretch*(src: SurfacePtr; srcrect: ptr Rect; dst: SurfacePtr;
  1011. dstrect: ptr Rect): SDL_Return {.importc: "SDL_SoftStretch".}
  1012. proc upperBlitScaled*(src: SurfacePtr; srcrect: ptr Rect; dst: SurfacePtr;
  1013. dstrect: ptr Rect): SDL_Return {.importc: "SDL_UpperBlitScaled".}
  1014. proc lowerBlitScaled*(src: SurfacePtr; srcrect: ptr Rect; dst: SurfacePtr;
  1015. dstrect: ptr Rect): SDL_Return {.importc: "SDL_LowerBlitScaled".}
  1016. proc readU8*(src: RWopsPtr): uint8 {.importc: "SDL_ReadU8".}
  1017. proc readLE16*(src: RWopsPtr): uint16 {.importc: "SDL_ReadLE16".}
  1018. proc readBE16*(src: RWopsPtr): uint16 {.importc: "SDL_ReadBE16".}
  1019. proc readLE32*(src: RWopsPtr): uint32 {.importc: "SDL_ReadLE32".}
  1020. proc readBE32*(src: RWopsPtr): uint32 {.importc: "SDL_ReadBE32".}
  1021. proc readLE64*(src: RWopsPtr): uint64 {.importc: "SDL_ReadLE64".}
  1022. proc readBE64*(src: RWopsPtr): uint64 {.importc: "SDL_ReadBE64".}
  1023. proc writeU8*(dst: RWopsPtr; value: uint8): csize_t_const {.importc: "SDL_WriteU8".}
  1024. proc writeLE16*(dst: RWopsPtr; value: uint16): csize_t_const {.importc: "SDL_WriteLE16".}
  1025. proc writeBE16*(dst: RWopsPtr; value: uint16): csize_t_const {.importc: "SDL_WriteBE16".}
  1026. proc writeLE32*(dst: RWopsPtr; value: uint32): csize_t_const {.importc: "SDL_WriteLE32".}
  1027. proc writeBE32*(dst: RWopsPtr; value: uint32): csize_t_const {.importc: "SDL_WriteBE32".}
  1028. proc writeLE64*(dst: RWopsPtr; value: uint64): csize_t_const {.importc: "SDL_WriteLE64".}
  1029. proc writeBE64*(dst: RWopsPtr; value: uint64): csize_t_const {.importc: "SDL_WriteBE64".}
  1030. proc showMessageBox*(messageboxdata: ptr MessageBoxData;
  1031. buttonid: var cint): cint {.importc: "SDL_ShowMessageBox".}
  1032. proc showSimpleMessageBox*(flags: uint32; title, message: cstring;
  1033. window: WindowPtr): cint {.importc: "SDL_ShowSimpleMessageBox".}
  1034. # \return 0 on success, -1 on error
  1035. proc getNumVideoDrivers*(): cint {.importc: "SDL_GetNumVideoDrivers".}
  1036. proc getVideoDriver*(index: cint): cstring {.importc: "SDL_GetVideoDriver".}
  1037. proc videoInit*(driver_name: cstring): SDL_Return {.importc: "SDL_VideoInit".}
  1038. proc videoQuit*() {.importc: "SDL_VideoQuit".}
  1039. proc getCurrentVideoDriver*(): cstring {.importc: "SDL_GetCurrentVideoDriver".}
  1040. proc getNumVideoDisplays*(): cint {.importc: "SDL_GetNumVideoDisplays".}
  1041. proc getDisplayBounds*(displayIndex: cint; rect: var Rect): SDL_Return {.
  1042. importc: "SDL_GetDisplayBounds".}
  1043. proc getNumDisplayModes*(displayIndex: cint): cint {.importc: "SDL_GetNumDisplayModes".}
  1044. #*
  1045. proc getDisplayMode*(displayIndex: cint; modeIndex: cint;
  1046. mode: var DisplayMode): SDL_Return {.importc: "SDL_GetDisplayMode".}
  1047. proc getDesktopDisplayMode*(displayIndex: cint;
  1048. mode: var DisplayMode): SDL_Return {.importc: "SDL_GetDesktopDisplayMode".}
  1049. proc getCurrentDisplayMode*(displayIndex: cint;
  1050. mode: var DisplayMode): SDL_Return {.importc: "SDL_GetCurrentDisplayMode".}
  1051. proc getClosestDisplayMode*(displayIndex: cint; mode: ptr DisplayMode;
  1052. closest: ptr DisplayMode): ptr DisplayMode {.importc: "SDL_GetClosestDisplayMode".}
  1053. proc getDisplayDPI*(displayIndex: cint;
  1054. ddpi, hdpi, vdpi: ptr cfloat): SDL_Return {.importc: "SDL_GetDisplayDPI".}
  1055. #*
  1056. #*
  1057. proc createWindow*(title: cstring; x, y, w, h: cint;
  1058. flags: uint32): WindowPtr {.importc: "SDL_CreateWindow".}
  1059. #*
  1060. proc createWindowFrom*(data: pointer): WindowPtr {.importc: "SDL_CreateWindowFrom".}
  1061. #*
  1062. # \brief Get a window from a stored ID, or NULL if it doesn't exist.
  1063. #
  1064. proc getWindowFromID*(id: uint32): WindowPtr {.importc: "SDL_GetWindowFromID".}
  1065. #
  1066. proc showWindow*(window: WindowPtr) {.importc: "SDL_ShowWindow".}
  1067. proc hideWindow*(window: WindowPtr) {.importc: "SDL_HideWindow".}
  1068. #*
  1069. proc raiseWindow*(window: WindowPtr) {.importc: "SDL_RaiseWindow".}
  1070. proc maximizeWindow*(window: WindowPtr) {.importc: "SDL_MaximizeWindow".}
  1071. proc minimizeWindow*(window: WindowPtr) {.importc: "SDL_MinimizeWindow".}
  1072. #*
  1073. #
  1074. proc restoreWindow*(window: WindowPtr) {.importc: "SDL_RestoreWindow".}
  1075. proc destroyWindow*(window: WindowPtr) {.importc: "SDL_DestroyWindow".}
  1076. proc isScreenSaverEnabled*(): Bool32 {.importc: "SDL_IsScreenSaverEnabled".}
  1077. proc enableScreenSaver*() {.importc: "SDL_EnableScreenSaver".}
  1078. proc disableScreenSaver*() {.importc: "SDL_DisableScreenSaver".}
  1079. proc getTicks*(): uint32 {.importc: "SDL_GetTicks".}
  1080. proc getPerformanceCounter*(): uint64 {.importc: "SDL_GetPerformanceCounter".}
  1081. proc getPerformanceFrequency*(): uint64 {.importc: "SDL_GetPerformanceFrequency".}
  1082. proc delay*(ms: uint32) {.importc: "SDL_Delay".}
  1083. #*
  1084. # \brief Add a new timer to the pool of timers already running.
  1085. #
  1086. # \return A timer ID, or NULL when an error occurs.
  1087. #
  1088. proc addTimer*(interval: uint32; callback: TimerCallback;
  1089. param: pointer): TimerID {.importc: "SDL_AddTimer".}
  1090. #*
  1091. # \brief Remove a timer knowing its ID.
  1092. #
  1093. # \return A boolean value indicating success or failure.
  1094. #
  1095. # \warning It is not safe to remove a timer multiple times.
  1096. #
  1097. proc removeTimer*(id: TimerID): Bool32 {.importc: "SDL_RemoveTimer".}
  1098. #*
  1099. # \name OpenGL support functions
  1100. #
  1101. #@{
  1102. #*
  1103. # \brief Dynamically load an OpenGL library.
  1104. #
  1105. # \param path The platform dependent OpenGL library name, or NULL to open the
  1106. # default OpenGL library.
  1107. #
  1108. # \return 0 on success, or -1 if the library couldn't be loaded.
  1109. #
  1110. # This should be done after initializing the video driver, but before
  1111. # creating any OpenGL windows. If no OpenGL library is loaded, the default
  1112. # library will be loaded upon creation of the first OpenGL window.
  1113. #
  1114. # \note If you do this, you need to retrieve all of the GL functions used in
  1115. # your program from the dynamic library using SDL_GL_GetProcAddress().
  1116. #
  1117. # \sa SDL_GL_GetProcAddress()
  1118. # \sa SDL_GL_UnloadLibrary()
  1119. #
  1120. #extern DECLSPEC int SDLCALL SDL_GL_LoadLibrary(const char *path);
  1121. proc glLoadLibrary* (path: cstring): SDL_Return {.discardable,
  1122. importc: "SDL_GL_LoadLibrary".}
  1123. #extern DECLSPEC void *SDLCALL SDL_GL_GetProcAddress(const char *proc);
  1124. proc glGetProcAddress* (procedure: cstring): pointer {.
  1125. importc: "SDL_GL_GetProcAddress".}
  1126. #extern DECLSPEC void SDLCALL SDL_GL_UnloadLibrary(void);
  1127. proc glUnloadLibrary* {.
  1128. importc: "SDL_GL_UnloadLibrary".}
  1129. #extern DECLSPEC SDL_bool SDLCALL SDL_GL_ExtensionSupported(const char
  1130. # *extension);
  1131. proc glExtensionSupported* (extension: cstring): bool {.
  1132. importc: "SDL_GL_ExtensionSupported".}
  1133. #extern DECLSPEC int SDLCALL SDL_GL_SetAttribute(SDL_GLattr attr, int value);
  1134. proc glSetAttribute* (attr: GLattr; value: cint): cint {.
  1135. importc: "SDL_GL_SetAttribute".}
  1136. #extern DECLSPEC int SDLCALL SDL_GL_GetAttribute(SDL_GLattr attr, int *value);
  1137. proc glGetAttribute* (attr: GLattr; value: var cint): cint {.
  1138. importc: "SDL_GL_GetAttribute".}
  1139. proc glCreateContext*(window: WindowPtr): GlContextPtr {.
  1140. importc: "SDL_GL_CreateContext".}
  1141. ## Create an OpenGL context for use with an OpenGL window, and make it current.
  1142. proc glMakeCurrent* (window: WindowPtr; context: GlContextPtr): cint {.
  1143. importc: "SDL_GL_MakeCurrent".}
  1144. proc glGetCurrentWindow* : WindowPtr {.
  1145. importc: "SDL_GL_GetCurrentWindow".}
  1146. proc glGetCurrentContext*: GlContextPtr {.
  1147. importc: "SDL_GL_GetCurrentContext".}
  1148. proc glGetDrawableSize* (window: WindowPtr; w,h: var cint) {.
  1149. importc: "SDL_GL_GetDrawableSize".}
  1150. proc glSetSwapInterval* (interval: cint): cint {.
  1151. importc: "SDL_GL_SetSwapInterval".}
  1152. proc glGetSwapInterval* : cint {.
  1153. importc: "SDL_GL_GetSwapInterval".}
  1154. proc glSwapWindow*(window: WindowPtr) {.
  1155. importc: "SDL_GL_SwapWindow".}
  1156. ## Swap the OpenGL buffers for a window, if double-buffering is supported.
  1157. proc glDeleteContext* (context: GlContextPtr) {.
  1158. importc: "SDL_GL_DeleteContext".}
  1159. ##SDL_vulkan.h
  1160. type VkHandle = int64
  1161. type VkNonDispatchableHandle = int64
  1162. # Skipped using Vk prefix to stop any potential name clashes with the Vulkan library
  1163. type VulkanInstance* = VkHandle
  1164. type VulkanSurface* = VkNonDispatchableHandle
  1165. #extern DECLSPEC int SDLCALL SDL_Vulkan_LoadLibrary(const char *path);
  1166. proc vulkanLoadLibrary*(path: cstring):cint {.
  1167. importc: "SDL_Vulkan_LoadLibrary".}
  1168. #extern DECLSPEC void *SDLCALL SDL_Vulkan_GetVkGetInstanceProcAddr(void);
  1169. proc vulkanGetVkGetInstanceProcAddr*(): pointer {.
  1170. importc: "SDL_Vulkan_GetVkGetInstanceProcAddr".}
  1171. #extern DECLSPEC void SDLCALL SDL_Vulkan_UnloadLibrary(void);
  1172. proc vulkanUnloadLibrary*() {.
  1173. importc: "SDL_Vulkan_UnloadLibrary".}
  1174. #extern DECLSPEC SDL_bool SDLCALL SDL_Vulkan_GetInstanceExtensions(
  1175. # SDL_Window *window,
  1176. # unsigned int *pCount,
  1177. # const char **pNames);
  1178. proc vulkanGetInstanceExtensions*(window: WindowPtr, pCount: ptr cuint, pNames: cstringArray): Bool32 {.
  1179. importc: "SDL_Vulkan_GetInstanceExtensions".}
  1180. #extern DECLSPEC SDL_bool SDLCALL SDL_Vulkan_CreateSurface(
  1181. # SDL_Window *window,
  1182. # VkInstance instance,
  1183. # VkSurfaceKHR* surface);
  1184. proc vulkanCreateSurface*(window: WindowPtr, instance: VulkanInstance, surface: ptr VulkanSurface): Bool32 {.
  1185. importc: "SDL_Vulkan_CreateSurface".}
  1186. #extern DECLSPEC void SDLCALL SDL_Vulkan_GetDrawableSize(SDL_Window * window,
  1187. # int *w, int *h);
  1188. proc vulkanGetDrawableSize*(window: WindowPtr, w, h: ptr cint) {.
  1189. importc: "SDL_Vulkan_GetDrawableSize".}
  1190. ##SDL_keyboard.h:
  1191. proc getKeyboardFocus*: WindowPtr {.importc: "SDL_GetKeyboardFocus".}
  1192. #Get the window which currently has keyboard focus.
  1193. proc getKeyboardState*(numkeys: ptr int = nil): ptr array[0 .. SDL_NUM_SCANCODES.int, uint8] {.importc: "SDL_GetKeyboardState".}
  1194. #Get the snapshot of the current state of the keyboard
  1195. proc getModState*: Keymod {.importc: "SDL_GetModState".}
  1196. #Get the current key modifier state for the keyboard
  1197. proc setModState*(state: Keymod) {.importc: "SDL_SetModState".}
  1198. #Set the current key modifier state for the keyboard
  1199. proc getKeyFromScancode*(scancode: ScanCode): cint {.importc: "SDL_GetKeyFromScancode".}
  1200. #Get the key code corresponding to the given scancode according to the current keyboard layout
  1201. proc getScancodeFromKey*(key: cint): ScanCode {.importc: "SDL_GetScancodeFromKey".}
  1202. #Get the scancode corresponding to the given key code according to the current keyboard layout
  1203. proc getScancodeName*(scancode: ScanCode): cstring {.importc: "SDL_GetScancodeName".}
  1204. #Get a human-readable name for a scancode
  1205. proc getScancodeFromName*(name: cstring): ScanCode {.importc: "SDL_GetScancodeFromName".}
  1206. #Get a scancode from a human-readable name
  1207. proc getKeyName*(key: cint): cstring {.
  1208. importc: "SDL_GetKeyName".}
  1209. #Get a human-readable name for a key
  1210. proc getKeyFromName*(name: cstring): cint {.
  1211. importc: "SDL_GetKeyFromName".}
  1212. #Get a key code from a human-readable name
  1213. proc startTextInput* {.
  1214. importc: "SDL_StartTextInput".}
  1215. #Start accepting Unicode text input events
  1216. proc isTextInputActive*: bool {.
  1217. importc: "SDL_IsTextInputActive".}
  1218. proc stopTextInput* {.
  1219. importc: "SDL_StopTextInput".}
  1220. proc setTextInputRect*(rect: ptr Rect) {.
  1221. importc: "SDL_SetTextInputRect".}
  1222. proc hasScreenKeyboardSupport*: bool {.importc: "SDL_HasScreenKeyboardSupport".}
  1223. proc isScreenKeyboardShown*(window: WindowPtr): bool {.importc: "SDL_IsScreenKeyboardShown".}
  1224. proc getMouseFocus*(): WindowPtr {.importc: "SDL_GetMouseFocus".}
  1225. #*
  1226. # \brief Retrieve the current state of the mouse.
  1227. #
  1228. # The current button state is returned as a button bitmask, which can
  1229. # be tested using the SDL_BUTTON(X) macros, and x and y are set to the
  1230. # mouse cursor position relative to the focus window for the currently
  1231. # selected mouse. You can pass NULL for either x or y.
  1232. #
  1233. proc getMouseState*(x, y: var cint): uint8 {.importc: "SDL_GetMouseState", discardable.}
  1234. proc getMouseState*(x, y: ptr cint): uint8 {.importc: "SDL_GetMouseState", discardable.}
  1235. #*
  1236. proc getRelativeMouseState*(x, y: var cint): uint8 {.
  1237. importc: "SDL_GetRelativeMouseState".}
  1238. #*
  1239. proc warpMouseInWindow*(window: WindowPtr; x, y: cint) {.
  1240. importc: "SDL_WarpMouseInWindow".}
  1241. #*
  1242. proc setRelativeMouseMode*(enabled: Bool32): SDL_Return {.
  1243. importc: "SDL_SetRelativeMouseMode".}
  1244. #*
  1245. proc captureMouse*(enabled: Bool32): SDL_Return {.
  1246. importc: "SDL_CaptureMouse" .}
  1247. #*
  1248. proc getRelativeMouseMode*(): Bool32 {.importc: "SDL_GetRelativeMouseMode".}
  1249. #*
  1250. proc createCursor*(data, mask: ptr uint8;
  1251. w, h, hot_x, hot_y: cint): CursorPtr {.importc: "SDL_CreateCursor".}
  1252. #*
  1253. proc createColorCursor*(surface: SurfacePtr; hot_x, hot_y: cint): CursorPtr {.
  1254. importc: "SDL_CreateColorCursor".}
  1255. #*
  1256. type
  1257. SystemCursor* = enum
  1258. SDL_SYSTEM_CURSOR_ARROW, ## Arrow
  1259. SDL_SYSTEM_CURSOR_IBEAM, ## I-beam
  1260. SDL_SYSTEM_CURSOR_WAIT, ## Wait
  1261. SDL_SYSTEM_CURSOR_CROSSHAIR, ## Crosshair
  1262. SDL_SYSTEM_CURSOR_WAITARROW, ## Small wait cursor (or Wait if not available)
  1263. SDL_SYSTEM_CURSOR_SIZENWSE, ## Double arrow pointing northwest and southeast
  1264. SDL_SYSTEM_CURSOR_SIZENESW, ## Double arrow pointing northeast and southwest
  1265. SDL_SYSTEM_CURSOR_SIZEWE, ## Double arrow pointing west and east
  1266. SDL_SYSTEM_CURSOR_SIZENS, ## Double arrow pointing north and south
  1267. SDL_SYSTEM_CURSOR_SIZEALL, ## Four pointed arrow pointing north, south, east, and west
  1268. SDL_SYSTEM_CURSOR_NO, ## Slashed circle or crossbones
  1269. SDL_SYSTEM_CURSOR_HAND ## Hand
  1270. proc createSystemCursor*(c: SystemCursor): CursorPtr {.
  1271. importc: "SDL_CreateSystemCursor".}
  1272. proc setCursor*(cursor: CursorPtr) {.importc: "SDL_SetCursor".}
  1273. proc getCursor*(): CursorPtr {.importc: "SDL_GetCursor".}
  1274. proc freeCursor* (cursor: CursorPtr) {.importc: "SDL_FreeCursor".}
  1275. proc showCursor* (toggle: bool): Bool32 {.importc: "SDL_ShowCursor", discardable.}
  1276. # Function prototypes
  1277. #*
  1278. # Pumps the event loop, gathering events from the input devices.
  1279. #
  1280. # This function updates the event queue and internal input device state.
  1281. #
  1282. # This should only be run in the thread that sets the video mode.
  1283. #
  1284. proc pumpEvents*() {.importc: "SDL_PumpEvents".}
  1285. #*
  1286. # Checks the event queue for messages and optionally returns them.
  1287. #
  1288. # If \c action is ::SDL_ADDEVENT, up to \c numevents events will be added to
  1289. # the back of the event queue.
  1290. #
  1291. # If \c action is ::SDL_PEEKEVENT, up to \c numevents events at the front
  1292. # of the event queue, within the specified minimum and maximum type,
  1293. # will be returned and will not be removed from the queue.
  1294. #
  1295. # If \c action is ::SDL_GETEVENT, up to \c numevents events at the front
  1296. # of the event queue, within the specified minimum and maximum type,
  1297. # will be returned and will be removed from the queue.
  1298. #
  1299. # \return The number of events actually stored, or -1 if there was an error.
  1300. #
  1301. # This function is thread-safe.
  1302. #
  1303. proc peepEvents*(events: ptr Event; numevents: cint; action: Eventaction;
  1304. minType: uint32; maxType: uint32): cint {.importc: "SDL_PeepEvents".}
  1305. #@}
  1306. #*
  1307. # Checks to see if certain event types are in the event queue.
  1308. #
  1309. proc hasEvent*(kind: uint32): Bool32 {.importc: "SDL_HasEvent".}
  1310. proc hasEvents*(minType: uint32; maxType: uint32): Bool32 {.importc: "SDL_HasEvents".}
  1311. proc flushEvent*(kind: uint32) {.importc: "SDL_FlushEvent".}
  1312. proc flushEvents*(minType: uint32; maxType: uint32) {.importc: "SDL_FlushEvents".}
  1313. proc pollEvent*(event: var Event): Bool32 {.importc: "SDL_PollEvent".}
  1314. proc waitEvent*(event: var Event): Bool32 {.importc: "SDL_WaitEvent".}
  1315. proc waitEventTimeout*(event: var Event; timeout: cint): Bool32 {.importc: "SDL_WaitEventTimeout".}
  1316. #*
  1317. # \brief Add an event to the event queue.
  1318. #
  1319. # \return 1 on success, 0 if the event was filtered, or -1 if the event queue
  1320. # was full or there was some other error.
  1321. #
  1322. proc pushEvent*(event: ptr Event): cint {.importc: "SDL_PushEvent".}
  1323. #*
  1324. proc setEventFilter*(filter: EventFilter; userdata: pointer) {.importc: "SDL_SetEventFilter".}
  1325. #*
  1326. # Return the current event filter - can be used to "chain" filters.
  1327. # If there is no event filter set, this function returns SDL_FALSE.
  1328. #
  1329. proc getEventFilter*(filter: var EventFilter; userdata: var pointer): Bool32 {.importc: "SDL_GetEventFilter".}
  1330. #*
  1331. # Add a function which is called when an event is added to the queue.
  1332. #
  1333. proc addEventWatch*(filter: EventFilter; userdata: pointer) {.importc: "SDL_AddEventWatch".}
  1334. #*
  1335. # Remove an event watch function added with SDL_AddEventWatch()
  1336. #
  1337. proc delEventWatch*(filter: EventFilter; userdata: pointer) {.importc: "SDL_DelEventWatch".}
  1338. #*
  1339. # Run the filter function on the current event queue, removing any
  1340. # events for which the filter returns 0.
  1341. #
  1342. proc filterEvents*(filter: EventFilter; userdata: pointer) {.importc: "SDL_FilterEvents".}
  1343. #@{
  1344. #
  1345. #/**
  1346. # This function allows you to set the state of processing certain events.
  1347. # - If \c state is set to ::SDL_IGNORE, that event will be automatically
  1348. # dropped from the event queue and will not event be filtered.
  1349. # - If \c state is set to ::SDL_ENABLE, that event will be processed
  1350. # normally.
  1351. # - If \c state is set to ::SDL_QUERY, SDL_EventState() will return the
  1352. # current processing state of the specified event.
  1353. #
  1354. proc eventState*(kind: EventType; state: cint): uint8 {.importc: "SDL_EventState".}
  1355. #@}
  1356. #
  1357. #/**
  1358. # This function allocates a set of user-defined events, and returns
  1359. # the beginning event number for that set of events.
  1360. #
  1361. # If there aren't enough user-defined events left, this function
  1362. # returns (uint32)-1
  1363. #
  1364. proc registerEvents*(numevents: cint): uint32 {.importc: "SDL_RegisterEvents".}
  1365. proc setError*(fmt: cstring) {.varargs, importc: "SDL_SetError".}
  1366. proc getError*(): cstring {.importc: "SDL_GetError".}
  1367. proc clearError*() {.importc: "SDL_ClearError".}
  1368. #extern DECLSPEC const char* SDLCALL SDL_GetPixelFormatName(uint32 format);
  1369. proc getPixelFormatName* (format: uint32): cstring {.
  1370. importc: "SDL_GetPixelFormatName".}
  1371. ## Get the human readable name of a pixel format
  1372. #extern DECLSPEC SDL_bool SDLCALL SDL_PixelFormatEnumToMasks(uint32 format,
  1373. # int *bpp,
  1374. # uint32 * Rmask,
  1375. # uint32 * Gmask,
  1376. # uint32 * Bmask,
  1377. # uint32 * Amask);
  1378. proc pixelFormatEnumToMasks* (format: uint32; bpp: var cint;
  1379. Rmask, Gmask, Bmask, Amask: var uint32): bool {.
  1380. importc: "SDL_PixelFormatEnumToMasks".}
  1381. ##Convert one of the enumerated pixel formats to a bpp and RGBA masks.
  1382. ##Returns TRUE or FALSE if the conversion wasn't possible.
  1383. #extern DECLSPEC uint32 SDLCALL SDL_MasksToPixelFormatEnum(int bpp,
  1384. # uint32 Rmask,
  1385. # uint32 Gmask,
  1386. # uint32 Bmask,
  1387. # uint32 Amask);
  1388. proc masksToPixelFormatEnum* (bpp: cint; Rmask, Gmask, Bmask, Amask: uint32): uint32 {.
  1389. importc: "SDL_MasksToPixelFormatEnum".}
  1390. ##Convert a bpp and RGBA masks to an enumerated pixel format.
  1391. ##The pixel format, or ::SDL_PIXELFORMAT_UNKNOWN if the conversion wasn't possible.
  1392. #extern DECLSPEC SDL_PixelFormat * SDLCALL SDL_AllocFormat(uint32 pixel_format);
  1393. proc allocFormat* (pixelFormat: uint32): ptr PixelFormat {.
  1394. importc: "SDL_AllocFormat".}
  1395. ##Create an SDL_PixelFormat structure from a pixel format enum.
  1396. #extern DECLSPEC void SDLCALL SDL_FreeFormat(SDL_PixelFormat *format);
  1397. proc freeFormat* (format: ptr PixelFormat) {.
  1398. importc: "SDL_FreeFormat".}
  1399. ##Free an SDL_PixelFormat structure.
  1400. #extern DECLSPEC SDL_Palette *SDLCALL SDL_AllocPalette(int ncolors);
  1401. proc allocPalette* (numColors: cint): ptr Palette {.
  1402. importc: "SDL_AllocPalette".}
  1403. ##Create a palette structure with the specified number of color entries.
  1404. ##Returns A new palette, or NULL if there wasn't enough memory.
  1405. ##Note: The palette entries are initialized to white.
  1406. #extern DECLSPEC int SDLCALL SDL_SetPixelFormatPalette(SDL_PixelFormat * format,
  1407. # SDL_Palette *palette);
  1408. proc setPixelFormatPalette* (format: ptr PixelFormat; palette: ptr Palette): cint {.
  1409. importc: "SDL_SetPixelFormatPalette".}
  1410. ##Set the palette for a pixel format structure.
  1411. #extern DECLSPEC int SDLCALL SDL_SetPaletteColors(SDL_Palette * palette,
  1412. # const SDL_Color * colors,
  1413. # int firstcolor, int ncolors);
  1414. proc setPaletteColors* (palette: ptr Palette; colors: ptr Color; first, numColors: cint): SDL_Return {.discardable,
  1415. importc: "SDL_SetPaletteColors".}
  1416. ## Set a range of colors in a palette.
  1417. #extern DECLSPEC void SDLCALL SDL_FreePalette(SDL_Palette * palette);
  1418. proc freePalette* (palette: ptr Palette) {.
  1419. importc: "SDL_FreePalette".}
  1420. ##Free a palette created with SDL_AllocPalette().
  1421. #extern DECLSPEC uint32 SDLCALL SDL_MapRGB(const SDL_PixelFormat * format,
  1422. # uint8 r, uint8 g, uint8 b);
  1423. proc mapRGB* (format: ptr PixelFormat; r,g,b: uint8): uint32 {.
  1424. importc: "SDL_MapRGB".}
  1425. ##Maps an RGB triple to an opaque pixel value for a given pixel format.
  1426. #extern DECLSPEC uint32 SDLCALL SDL_MapRGBA(const SDL_PixelFormat * format,
  1427. # uint8 r, uint8 g, uint8 b,
  1428. # uint8 a);
  1429. proc mapRGBA* (format: ptr PixelFormat; r,g,b,a: uint8): uint32 {.
  1430. importc: "SDL_MapRGBA".}
  1431. ##Maps an RGBA quadruple to a pixel value for a given pixel format.
  1432. #extern DECLSPEC void SDLCALL SDL_GetRGB(uint32 pixel,
  1433. # const SDL_PixelFormat * format,
  1434. # uint8 * r, uint8 * g, uint8 * b);
  1435. proc getRGB* (pixel: uint32; format: ptr PixelFormat; r,g,b: var uint8) {.
  1436. importc: "SDL_GetRGB".}
  1437. ##Get the RGB components from a pixel of the specified format.
  1438. #extern DECLSPEC void SDLCALL SDL_GetRGBA(uint32 pixel,
  1439. # const SDL_PixelFormat * format,
  1440. # uint8 * r, uint8 * g, uint8 * b,
  1441. # uint8 * a);
  1442. proc getRGBA* (pixel: uint32; format: ptr PixelFormat; r,g,b,a: var uint8) {.
  1443. importc: "SDL_GetRGBA".}
  1444. ##Get the RGBA components from a pixel of the specified format.
  1445. #extern DECLSPEC void SDLCALL SDL_CalculateGammaRamp(float gamma, uint16 * ramp);
  1446. proc calculateGammaRamp* (gamma: cfloat; ramp: ptr uint16) {.
  1447. importc: "SDL_CalculateGammaRamp".}
  1448. ##Calculate a 256 entry gamma ramp for a gamma value.
  1449. # SDL_clipboard.h
  1450. proc setClipboardText*(text: cstring): cint {.importc: "SDL_SetClipboardText".}
  1451. proc getClipboardText*(): cstring {.importc: "SDL_GetClipboardText".}
  1452. proc hasClipboardText*(): Bool32 {.importc: "SDL_HasClipboardText".}
  1453. proc freeClipboardText*(text: cstring) {.importc: "SDL_free".}
  1454. proc getNumTouchFingers*(id: TouchID): cint {.importc: "SDL_GetNumTouchFingers".}
  1455. proc getTouchFinger*(id: TouchID, index: cint): ptr Finger {.importc: "SDL_GetTouchFinger".}
  1456. # SDL_system.h
  1457. when defined(windows):
  1458. proc direct3D9GetAdapterIndex* (displayIndex: cint): cint {.
  1459. importc: "SDL_Direct3D9GetAdapterIndex".}
  1460. ## Returns the D3D9 adapter index that matches the specified display index.
  1461. ## This adapter index can be passed to IDirect3D9::CreateDevice and controls
  1462. ## on which monitor a full screen application will appear.
  1463. #extern DECLSPEC IDirect3DDevice9* SDLCALL SDL_RenderGetD3D9Device(SDL_Renderer * renderer);
  1464. proc getD3D9Device* (renderer: RendererPtr): pointer {.
  1465. importc:"SDL_RenderGetD3D9Device".}
  1466. ## Returns the D3D device associated with a renderer, or NULL if it's not a D3D renderer.
  1467. ## Once you are done using the device, you should release it to avoid a resource leak.
  1468. #extern DECLSPEC void SDLCALL SDL_DXGIGetOutputInfo( int displayIndex, int *adapterIndex, int *outputIndex );
  1469. proc dXGIGetOutputInfo* (displayIndex: cint, adapterIndex,outputIndex: ptr cint) {.importc: "SDL_DXGIGetOutputInfo".}
  1470. ## Returns the DXGI Adapter and Output indices for the specified display index.
  1471. ## These can be passed to EnumAdapters and EnumOutputs respectively to get the objects
  1472. ## required to create a DX10 or DX11 device and swap chain.
  1473. elif defined(iPhone) or defined(ios):
  1474. #extern DECLSPEC int SDLCALL SDL_iPhoneSetAnimationCallback(
  1475. # SDL_Window * window, int interval,
  1476. # void (*callback)(void*), void *callbackParam);
  1477. proc iPhoneSetAnimationCallback*(window: WindowPtr, interval:cint, callback: VoidCallback, callbackParam: pointer): cint {.
  1478. importc: "SDL_iPhoneSetAnimationCallback".}
  1479. #extern DECLSPEC void SDLCALL SDL_iPhoneSetEventPump(SDL_bool enabled);
  1480. proc iPhoneSetEventPump*(enabled: bool) {.
  1481. importc: "SDL_iPhoneSetEventPump".}
  1482. #extern DECLSPEC int SDLCALL SDL_iPhoneKeyboardShow(SDL_Window * window);
  1483. proc iPhoneKeyboardShow*(window:WindowPtr): cint {.
  1484. importc: "SDL_iPhoneKeyboardShow".}
  1485. #extern DECLSPEC int SDLCALL SDL_iPhoneKeyboardHide(SDL_Window * window);
  1486. proc iPhoneKeyboardHide*(window:WindowPtr): cint {.
  1487. importc: "SDL_iPhoneKeyboardHide".}
  1488. #extern DECLSPEC SDL_bool SDLCALL SDL_iPhoneKeyboardIsShown(SDL_Window * window);
  1489. proc iPhoneKeyboardIsShown*(window:WindowPtr): bool {.
  1490. importc: "SDL_iPhoneKeyboardIsShown".}
  1491. #extern DECLSPEC int SDLCALL SDL_iPhoneKeyboardToggle(SDL_Window * window);
  1492. proc iPhoneKeyboardToggle*(window:WindowPtr): cint {.
  1493. importc: "SDL_iPhoneKeyboardToggle".}
  1494. elif defined(android):
  1495. #extern DECLSPEC void * SDLCALL SDL_AndroidGetJNIEnv();
  1496. proc androidGetJNIEnv*(): pointer {.importc: "SDL_AndroidGetJNIEnv".}
  1497. #extern DECLSPEC void * SDLCALL SDL_AndroidGetActivity();
  1498. proc androidGetActivity*(): pointer {.importc: "SDL_AndroidGetActivity".}
  1499. #extern DECLSPEC int SDLCALL SDL_AndroidGetExternalStorageState();
  1500. proc androidGetExternalStorageState*(): cint {.
  1501. importc: "SDL_AndroidGetExternalStorageState".}
  1502. #extern DECLSPEC const char * SDLCALL SDL_AndroidGetInternalStoragePath();
  1503. proc androidGetInternalStoragePath* (): cstring {.
  1504. importc: "SDL_AndroidGetInternalStoragePath".}
  1505. #extern DECLSPEC const char * SDLCALL SDL_AndroidGetExternalStoragePath();
  1506. proc androidGetExternalStoragePath* (): cstring {.
  1507. importc: "SDL_AndroidGetExternalStoragePath".}
  1508. const
  1509. SDL_QUERY* = -1
  1510. SDL_IGNORE* = 0
  1511. SDL_DISABLE* = 0
  1512. SDL_ENABLE* = 1
  1513. ##define SDL_GetEventState(type) SDL_EventState(type, SDL_QUERY)
  1514. proc getEventState*(kind: EventType): uint8 {.inline.} = eventState(kind, SDL_QUERY)
  1515. ##define SDL_BUTTON(X) (1 << ((X)-1))
  1516. template SDL_BUTTON*(x: uint8): uint8 = (1'u8 shl (x - 1'u8))
  1517. const
  1518. BUTTON_LEFT* = 1'u8
  1519. BUTTON_MIDDLE* = 2'u8
  1520. BUTTON_RIGHT* = 3'u8
  1521. BUTTON_X1* = 4'u8
  1522. BUTTON_X2* = 5'u8
  1523. BUTTON_LMASK* = SDL_BUTTON(BUTTON_LEFT)
  1524. BUTTON_MMASK* = SDL_BUTTON(BUTTON_MIDDLE)
  1525. BUTTON_RMASK* = SDL_BUTTON(BUTTON_RIGHT)
  1526. BUTTON_X1MASK* = SDL_BUTTON(BUTTON_X1)
  1527. BUTTON_X2MASK* = SDL_BUTTON(BUTTON_X2)
  1528. const SDL_TOUCH_MOUSEID* = high(uint32)
  1529. ## compatibility functions
  1530. proc createRGBSurface* (width, height, depth: int32): SurfacePtr {.inline.} = sdl2.createRGBSurface(
  1531. 0, width, height, depth, 0,0,0,0)
  1532. proc getSize*(window: WindowPtr): Point {.inline.} = getSize(window, result.x, result.y)
  1533. proc destroyTexture*(texture: TexturePtr) {.inline.} = destroy(texture)
  1534. #proc destroy* (texture: TexturePtr) {.inline.} = texture.destroyTexture
  1535. proc destroyRenderer*(renderer: RendererPtr) {.inline.} = destroy(renderer)
  1536. #proc destroy* (renderer: RendererPtr) {.inline.} = renderer.destroyRenderer
  1537. proc destroy* (window: WindowPtr) {.inline.} = window.destroyWindow
  1538. proc destroy* (cursor: CursorPtr) {.inline.} = cursor.freeCursor
  1539. proc destroy* (surface: SurfacePtr) {.inline.} = surface.freeSurface
  1540. proc destroy* (format: ptr PixelFormat) {.inline.} = format.freeFormat
  1541. proc destroy* (palette: ptr Palette) {.inline.} = palette.freePalette
  1542. proc blitSurface*(src: SurfacePtr; srcrect: ptr Rect; dst: SurfacePtr;
  1543. dstrect: ptr Rect): SDL_Return {.inline, discardable.} = upperBlit(src, srcrect, dst, dstrect)
  1544. proc blitScaled*(src: SurfacePtr; srcrect: ptr Rect; dst: SurfacePtr;
  1545. dstrect: ptr Rect): SDL_Return {.inline, discardable.} = upperBlitScaled(src, srcrect, dst, dstrect)
  1546. #proc init*(flags: cint): SDL_Return {.inline, deprecated.} = sdl2.init(flags)
  1547. #proc quit*() {.inline,deprecated.} = sdl2.quit()
  1548. #/#define SDL_LoadBMP(file) SDL_LoadBMP_RW(SDL_RWFromFile(file, "rb"), 1)
  1549. proc loadBMP*(file: string): SurfacePtr {.inline.} = loadBMP_RW(rwFromFile(cstring(file), "rb"), 1)
  1550. ##define SDL_SaveBMP(surface, file) \
  1551. # SDL_SaveBMP_RW(surface, SDL_RWFromFile(file, "wb"), 1)
  1552. proc saveBMP*(surface: SurfacePtr; file: string): SDL_Return {.
  1553. inline, discardable.} = saveBMP_RW(surface, rwFromFile(file, "wb"), 1)
  1554. proc color*(r, g, b, a: range[0..255]): Color = (r.uint8, g.uint8, b.uint8, a.uint8)
  1555. proc rect*(x, y: cint; w = cint(0), h = cint(0)): Rect =
  1556. result.x = x
  1557. result.y = y
  1558. result.w = w
  1559. result.h = h
  1560. proc point*[T: SomeNumber](x, y: T): Point = (x.cint, y.cint)
  1561. proc contains*(some: Rect; point: Point): bool =
  1562. return point.x >= some.x and point.x <= (some.x + some.w) and
  1563. point.y >= some.y and point.y <= (some.y + some.h)
  1564. const
  1565. HINT_RENDER_SCALE_QUALITY* = "SDL_RENDER_SCALE_QUALITY"
  1566. proc setHint*(name: cstring, value: cstring): bool {.
  1567. importc: "SDL_SetHint".}
  1568. proc setHintWithPriority*(name: cstring, value: cstring, priority: cint): bool {.
  1569. importc: "SDL_SetHintWithPriority".}
  1570. proc getHint*(name: cstring): cstring {.
  1571. importc: "SDL_GetHint".}
  1572. proc size* (ctx:RWopsPtr): int64 {.inline.} =
  1573. ctx.size(ctx)
  1574. proc seek* (ctx:RWopsPtr; offset:int64; whence:cint): int64 {.inline.} =
  1575. ctx.seek(ctx,offset,whence)
  1576. proc read* (ctx:RWopsPtr; `ptr`: pointer; size,maxnum:csize_t_const): csize_t_const{.inline.} =
  1577. ctx.read(ctx, `ptr`, size, maxnum)
  1578. proc write* (ctx:RWopsPtr; `ptr`:pointer; size,num:csize_t_const): csize_t_const{.inline.} =
  1579. ctx.write(ctx, `ptr`, size, num)
  1580. proc close* (ctx:RWopsPtr): cint {.inline.} =
  1581. ctx.close(ctx)
  1582. when not defined(SDL_Static):
  1583. {.pop.}
  1584. let defaultEvent* = Event(kind: QuitEvent)
  1585. ## a default "initialized" Event