Mercurial > repos > tabletprog
comparison modules/sdl.tp @ 278:1205c7a43cb4
Add bindings for SDL_ClearError, SDL_GetError, SDL_LoadBMP, SDL_CreateTextureFromSurface and a partial binding for SDL_RendererCopy
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 21 Jul 2014 12:51:38 -0700 |
parents | 2b58eafa360b |
children | eb83863fd33e |
comparison
equal
deleted
inserted
replaced
277:2b58eafa360b | 278:1205c7a43cb4 |
---|---|
76 mcall: value 2 option rend | 76 mcall: value 2 option rend |
77 } else: { | 77 } else: { |
78 mcall: none 1 option | 78 mcall: none 1 option |
79 } | 79 } |
80 } | 80 } |
81 | |
82 llMessage: loadBMP withVars: { | |
83 filename <- string ptr | |
84 makeSurface <- lambda ptr | |
85 surfOpaque <- cpointer ptr | |
86 surf <- object ptr | |
87 } andCode: :filename makeSurface{ | |
88 surfOpaque <- make_object: (addr_of: cpointer_meta) NULL 0 | |
89 surfOpaque val!: (SDL_LoadBMP: (filename data)) | |
90 if: (surfOpaque val) { | |
91 surf <- ccall: makeSurface 1 (surfOpaque castTo: (object ptr)) | |
92 mcall: value 2 option surf | |
93 } else: { | |
94 mcall: none 1 option | |
95 } | |
96 } | |
97 | |
98 llMessage: createTextureFromSurface withVars: { | |
99 rendOpaque <- cpointer ptr | |
100 surfOpaque <- cpointer ptr | |
101 makeTexture <- lambda ptr | |
102 texOpaque <- cpointer ptr | |
103 tex <- object ptr | |
104 } andCode: :rendOpaque surfOpaque makeTexture { | |
105 texOpaque <- make_object: (addr_of: cpointer_meta) NULL 0 | |
106 texOpaque val!: (SDL_CreateTextureFromSurface: (rendOpaque val) (surfOpaque val)) | |
107 if: (texOpaque val) { | |
108 tex <- ccall: makeTexture 1 (texOpaque castTo: (object ptr)) | |
109 mcall: value 2 option tex | |
110 } else: { | |
111 mcall: none 1 option | |
112 } | |
113 } | |
114 } | |
115 | |
116 _makeTexture <- :ptr { | |
117 #{ | |
118 includeSystemHeader: "SDL.h" | |
119 llProperty: texture withType: (SDL_Texture ptr) | |
120 llMessage: opaque withVars: { | |
121 ptr <- cpointer ptr | |
122 } andCode: { | |
123 ptr <- make_object: (addr_of: cpointer_meta) NULL 0 | |
124 ptr val!: texture | |
125 ptr | |
126 } | |
127 llMessage: _ptr_init withVars: { | |
128 ptr <- cpointer ptr | |
129 } andCode: :ptr{ | |
130 texture <- ptr val | |
131 self | |
132 } | |
133 | |
134 llMessage: copyTo withVars: { | |
135 renderer <- object ptr | |
136 rendOpaque <- cpointer ptr | |
137 intret <- obj_int32 ptr | |
138 } andCode: :renderer { | |
139 rendOpaque <- (mcall: opaque 1 renderer) castTo: (cpointer ptr) | |
140 intret <- make_object: (addr_of: obj_int32_meta) NULL 0 | |
141 intret num!: (SDL_RenderCopy: (rendOpaque val) texture NULL NULL) | |
142 intret | |
143 } | |
144 | |
145 llMessage: destroy withVars: {} andCode: { | |
146 SDL_DestroyTexture: texture | |
147 true | |
148 } | |
149 } _ptr_init: ptr | |
150 } | |
151 | |
152 _makeSurface <- :ptr { | |
153 #{ | |
154 includeSystemHeader: "SDL.h" | |
155 llProperty: surface withType: (SDL_Surface ptr) | |
156 llMessage: opaque withVars: { | |
157 ptr <- cpointer ptr | |
158 } andCode: { | |
159 ptr <- make_object: (addr_of: cpointer_meta) NULL 0 | |
160 ptr val!: surface | |
161 ptr | |
162 } | |
163 llMessage: _ptr_init withVars: { | |
164 ptr <- cpointer ptr | |
165 } andCode: :ptr{ | |
166 surface <- ptr val | |
167 self | |
168 } | |
169 | |
170 asTexture <- :renderer { | |
171 _helper createTextureFromSurface: (renderer opaque) opaque _makeTexture | |
172 } | |
173 | |
174 llMessage: free withVars: {} andCode: { | |
175 SDL_FreeSurface: surface | |
176 true | |
177 } | |
178 } _ptr_init: ptr | |
81 } | 179 } |
82 | 180 |
83 #{ | 181 #{ |
84 includeSystemHeader: "SDL.h" | 182 includeSystemHeader: "SDL.h" |
85 includeSystemHeader: "stdlib.h" | 183 includeSystemHeader: "stdlib.h" |
151 createRenderer:flags <- :index :flags { | 249 createRenderer:flags <- :index :flags { |
152 _helper createRenderer: (self opaque) index flags :ptr { | 250 _helper createRenderer: (self opaque) index flags :ptr { |
153 #{ | 251 #{ |
154 includeSystemHeader: "SDL.h" | 252 includeSystemHeader: "SDL.h" |
155 llProperty: renderer withType: (SDL_Renderer ptr) | 253 llProperty: renderer withType: (SDL_Renderer ptr) |
254 llMessage: opaque withVars: { | |
255 op <- cpointer ptr | |
256 } andCode: { | |
257 op <- make_object: (addr_of: cpointer_meta) NULL 0 | |
258 op val!: renderer | |
259 op | |
260 } | |
156 llMessage: _ptr_init withVars: { | 261 llMessage: _ptr_init withVars: { |
157 ptr <- cpointer ptr | 262 ptr <- cpointer ptr |
158 } andCode: :ptr { | 263 } andCode: :ptr { |
159 renderer <- ptr val | 264 renderer <- ptr val |
160 self | 265 self |
205 } | 310 } |
206 } _ptr_init: ptr | 311 } _ptr_init: ptr |
207 } | 312 } |
208 } | 313 } |
209 | 314 |
315 loadBMP <- :filename { | |
316 _helper loadBMP: filename _makeSurface | |
317 } | |
318 | |
210 llMessage: delay withVars: { | 319 llMessage: delay withVars: { |
211 ms <- obj_uint32 ptr | 320 ms <- obj_uint32 ptr |
212 } andCode: :ms { | 321 } andCode: :ms { |
213 SDL_Delay: (ms num) | 322 SDL_Delay: (ms num) |
214 true | 323 true |
215 } | 324 } |
216 | 325 |
326 llMessage: clearError withVars: {} andCode: { | |
327 SDL_ClearError: | |
328 true | |
329 } | |
330 | |
331 llMessage: getError withVars: { | |
332 str <- string ptr | |
333 rawstr <- char ptr | |
334 } andCode: { | |
335 rawstr <- SDL_GetError: | |
336 str <- make_object: (addr_of: string_meta) NULL 0 | |
337 str bytes!: (strlen: rawstr) | |
338 str len!: (str bytes) | |
339 str data!: (GC_MALLOC: (str bytes) + 1) | |
340 memcpy: (str data) rawstr (str bytes) + 1 | |
341 str | |
342 } | |
343 | |
217 subsystems <- { _subsystems } | 344 subsystems <- { _subsystems } |
218 windowOpts <- { _windowOpts } | 345 windowOpts <- { _windowOpts } |
219 } | 346 } |
220 } | 347 } |