sdl2.nim 74 KB

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