comparison modules/sdl.tp @ 274:a923b5b7da3d

Initial work on an SDL2 binding
author Michael Pavone <pavone@retrodev.com>
date Sun, 20 Jul 2014 00:13:01 -0700
parents
children 2b58eafa360b
comparison
equal deleted inserted replaced
273:0dc7322590da 274:a923b5b7da3d
1 {
2 _constant <- macro: :name cname {
3 quote: (llMessage: name withVars: {
4 uintret <- obj_uint32 ptr
5 } andCode: {
6 uintret <- make_object: (addr_of: obj_uint32_meta) NULL 0
7 uintret num!: cname
8 uintret
9 })
10 }
11 _subsystems <- #{
12 _constant: timer SDL_INIT_TIMER
13 _constant: audio SDL_INIT_AUDIO
14 _constant: video SDL_INIT_VIDEO
15 _constant: joystick SDL_INIT_JOYSTICK
16 _constant: haptic SDL_INIT_HAPTIC
17 _constant: gameController SDL_INIT_GAMECONTROLLER
18 _constant: events SDL_INIT_EVENTS
19 _constant: everything SDL_INIT_EVERYTHING
20 }
21
22 _windowOpts <- #{
23 _constant: fullscreen SDL_WINDOW_FULLSCREEN
24 _constant: fullscreenDesktop SDL_WINDOW_FULLSCREEN_DESKTOP
25 _constant: opengl SDL_WINDOW_OPENGL
26 _constant: hidden SDL_WINDOW_HIDDEN
27 _constant: borderless SDL_WINDOW_BORDERLESS
28 _constant: minimized SDL_WINDOW_MINIMIZED
29 _constant: maximized SDL_WINDOW_MAXIMIZED
30 _constant: inputGrabbed SDL_WINDOW_INPUT_GRABBED
31 _constant: allowHighDPI SDL_WINDOW_ALLOW_HIGHDPI
32 }
33
34 _helper <- #{
35 llMessage: createWindow withVars: {
36 title <- string ptr
37 x <- obj_int32 ptr
38 y <- obj_int32 ptr
39 w <- obj_int32 ptr
40 h <- obj_int32 ptr
41 flags <- obj_uint32 ptr
42 makeWindow <- lambda ptr
43 windowOpaque <- cpointer ptr
44 win <- object ptr
45 } andCode: :title x y w h flags makeWindow {
46 windowOpaque <- make_object: (addr_of: cpointer_meta) NULL 0
47 windowOpaque val!: (SDL_CreateWindow: (title data) (x num) (y num) (w num) (h num) (flags num))
48 if: (windowOpaque val) {
49 win <- ccall: makeWindow 1 (windowOpaque castTo: (object ptr))
50 mcall: value 2 option win
51 } else: {
52 mcall: none 1 option
53 }
54 }
55 }
56
57 #{
58 includeSystemHeader: "SDL.h"
59 includeSystemHeader: "stdlib.h"
60
61 llMessage: init withVars: {
62 flags <- obj_uint32 ptr
63 intret <- obj_int32 ptr
64 } andCode: :flags {
65 intret <- make_object: (addr_of: obj_int32_meta) NULL 0
66 intret num!: (SDL_Init: (flags num))
67 if: (intret num) {
68 atexit: SDL_Quit
69 }
70 intret
71 }
72
73 llMessage: initSubSystem withVars: {
74 flags <- obj_uint32 ptr
75 intret <- obj_int32 ptr
76 } andCode: :flags {
77 intret <- make_object: (addr_of: obj_int32_meta) NULL 0
78 intret num!: (SDL_InitSubSystem: (flags num))
79 intret
80 }
81
82 llMessage: quitSubSystem withVars: {
83 flags <- obj_uint32 ptr
84 } andCode: :flags {
85 SDL_QuitSubSystem: (flags num)
86 true
87 }
88
89 createWindow:pos:size:flags <- :title :x y :w h :flags{
90 _helper createWindow: title x y w h flags :ptr {
91 #{
92 includeSystemHeader: "SDL.h"
93 llProperty: window withType: (SDL_Window ptr)
94
95 llMessage: _ptr_init withVars: {
96 ptr <- cpointer ptr
97 } andCode: :ptr {
98 window <- ptr val
99 self
100 }
101
102 llMessage: destroy withVars: {
103 } andCode: {
104 SDL_DestroyWindow: window
105 true
106 }
107 } _ptr_init
108 }
109 }
110
111 llMessage: delay withVars: {
112 ms <- obj_uint32 ptr
113 } andCode: :ms {
114 SDL_Delay: (ms num)
115 true
116 }
117
118 subsystems <- { _subsystems }
119 windowOpts <- { _windowOpts }
120 }
121 }