annotate samples/sdl.tp @ 291:38bbbf74b735

Initial work on event support in SDL module
author Michael Pavone <pavone@retrodev.com>
date Tue, 22 Jul 2014 23:35:08 -0700
parents b01d7c1b4edd
children 2b045d5b673b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
274
a923b5b7da3d Initial work on an SDL2 binding
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1 #{
a923b5b7da3d Initial work on an SDL2 binding
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2 import: [
a923b5b7da3d Initial work on an SDL2 binding
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
3 video
a923b5b7da3d Initial work on an SDL2 binding
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
4 timer
a923b5b7da3d Initial work on an SDL2 binding
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
5 ] from: (sdl subsystems)
291
38bbbf74b735 Initial work on event support in SDL module
Michael Pavone <pavone@retrodev.com>
parents: 287
diff changeset
6 import: [
38bbbf74b735 Initial work on event support in SDL module
Michael Pavone <pavone@retrodev.com>
parents: 287
diff changeset
7 quit
38bbbf74b735 Initial work on event support in SDL module
Michael Pavone <pavone@retrodev.com>
parents: 287
diff changeset
8 keyDown
38bbbf74b735 Initial work on event support in SDL module
Michael Pavone <pavone@retrodev.com>
parents: 287
diff changeset
9 keyUp
38bbbf74b735 Initial work on event support in SDL module
Michael Pavone <pavone@retrodev.com>
parents: 287
diff changeset
10 mouseDown
38bbbf74b735 Initial work on event support in SDL module
Michael Pavone <pavone@retrodev.com>
parents: 287
diff changeset
11 mouseUp
38bbbf74b735 Initial work on event support in SDL module
Michael Pavone <pavone@retrodev.com>
parents: 287
diff changeset
12 ] from: (sdl eventTypes)
274
a923b5b7da3d Initial work on an SDL2 binding
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
13 main <- {
a923b5b7da3d Initial work on an SDL2 binding
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
14 if: (sdl init: (video or timer)) = 0 {
a923b5b7da3d Initial work on an SDL2 binding
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
15 (sdl createWindow: "SDL Test" pos: 0 0 size: 640 480 flags: 0u32) value: :window {
277
2b58eafa360b Add SDL bindings for creating a renderer, clearing it, presenting it and destroying it
Michael Pavone <pavone@retrodev.com>
parents: 274
diff changeset
16 (window createRenderer: -1 flags: ((window renderOpts) accelerated)) value: :render {
2b58eafa360b Add SDL bindings for creating a renderer, clearing it, presenting it and destroying it
Michael Pavone <pavone@retrodev.com>
parents: 274
diff changeset
17 render drawColor!: (sdl r: 0u8 g: 0u8 b: 255u8)
2b58eafa360b Add SDL bindings for creating a renderer, clearing it, presenting it and destroying it
Michael Pavone <pavone@retrodev.com>
parents: 274
diff changeset
18 render clear
278
1205c7a43cb4 Add bindings for SDL_ClearError, SDL_GetError, SDL_LoadBMP, SDL_CreateTextureFromSurface and a partial binding for SDL_RendererCopy
Michael Pavone <pavone@retrodev.com>
parents: 277
diff changeset
19 (sdl loadBMP: "944.bmp") value: :surf {
1205c7a43cb4 Add bindings for SDL_ClearError, SDL_GetError, SDL_LoadBMP, SDL_CreateTextureFromSurface and a partial binding for SDL_RendererCopy
Michael Pavone <pavone@retrodev.com>
parents: 277
diff changeset
20 (surf asTexture: render) value: :tex {
291
38bbbf74b735 Initial work on event support in SDL module
Michael Pavone <pavone@retrodev.com>
parents: 287
diff changeset
21 surf free
38bbbf74b735 Initial work on event support in SDL module
Michael Pavone <pavone@retrodev.com>
parents: 287
diff changeset
22 angle <- 45.0f32
38bbbf74b735 Initial work on event support in SDL module
Michael Pavone <pavone@retrodev.com>
parents: 287
diff changeset
23 continue? <- true
38bbbf74b735 Initial work on event support in SDL module
Michael Pavone <pavone@retrodev.com>
parents: 287
diff changeset
24 while: { continue? } do: {
38bbbf74b735 Initial work on event support in SDL module
Michael Pavone <pavone@retrodev.com>
parents: 287
diff changeset
25 tex copy
38bbbf74b735 Initial work on event support in SDL module
Michael Pavone <pavone@retrodev.com>
parents: 287
diff changeset
26 tex copyTo: (sdl rect: 160 120 size: 320 224)
38bbbf74b735 Initial work on event support in SDL module
Michael Pavone <pavone@retrodev.com>
parents: 287
diff changeset
27 tex copyRect: (sdl rect: 80 60 size: 160 120) To: (sdl rect: 40 30 size: 320 224)
38bbbf74b735 Initial work on event support in SDL module
Michael Pavone <pavone@retrodev.com>
parents: 287
diff changeset
28 tex copyTo: (sdl rect: 320 240 size: 320 224) rotated: angle
38bbbf74b735 Initial work on event support in SDL module
Michael Pavone <pavone@retrodev.com>
parents: 287
diff changeset
29 render present
38bbbf74b735 Initial work on event support in SDL module
Michael Pavone <pavone@retrodev.com>
parents: 287
diff changeset
30 angle <- angle + 1.0f32
38bbbf74b735 Initial work on event support in SDL module
Michael Pavone <pavone@retrodev.com>
parents: 287
diff changeset
31
38bbbf74b735 Initial work on event support in SDL module
Michael Pavone <pavone@retrodev.com>
parents: 287
diff changeset
32 event <- option none
38bbbf74b735 Initial work on event support in SDL module
Michael Pavone <pavone@retrodev.com>
parents: 287
diff changeset
33 while: {
38bbbf74b735 Initial work on event support in SDL module
Michael Pavone <pavone@retrodev.com>
parents: 287
diff changeset
34 event <- sdl pollEvent
38bbbf74b735 Initial work on event support in SDL module
Michael Pavone <pavone@retrodev.com>
parents: 287
diff changeset
35 event value?
38bbbf74b735 Initial work on event support in SDL module
Michael Pavone <pavone@retrodev.com>
parents: 287
diff changeset
36 } do: {
38bbbf74b735 Initial work on event support in SDL module
Michael Pavone <pavone@retrodev.com>
parents: 287
diff changeset
37 event value: :ev {
38bbbf74b735 Initial work on event support in SDL module
Michael Pavone <pavone@retrodev.com>
parents: 287
diff changeset
38 if: (ev type) = quit {
38bbbf74b735 Initial work on event support in SDL module
Michael Pavone <pavone@retrodev.com>
parents: 287
diff changeset
39 continue? <- false
38bbbf74b735 Initial work on event support in SDL module
Michael Pavone <pavone@retrodev.com>
parents: 287
diff changeset
40 } else: {
38bbbf74b735 Initial work on event support in SDL module
Michael Pavone <pavone@retrodev.com>
parents: 287
diff changeset
41 if: (ev type) = keyDown || (ev type) = keyUp {
38bbbf74b735 Initial work on event support in SDL module
Michael Pavone <pavone@retrodev.com>
parents: 287
diff changeset
42 print: "Key event for: " . (ev keyChar) . ", pressed?: " . (ev pressed?) . "\n"
38bbbf74b735 Initial work on event support in SDL module
Michael Pavone <pavone@retrodev.com>
parents: 287
diff changeset
43 } else: {
38bbbf74b735 Initial work on event support in SDL module
Michael Pavone <pavone@retrodev.com>
parents: 287
diff changeset
44 if: (ev type) = mouseDown || (ev type) = mouseUp {
38bbbf74b735 Initial work on event support in SDL module
Michael Pavone <pavone@retrodev.com>
parents: 287
diff changeset
45 print: "Mouse event at: " . (ev x) . ", " . (ev y) . " for button " . (ev button) . "\n"
38bbbf74b735 Initial work on event support in SDL module
Michael Pavone <pavone@retrodev.com>
parents: 287
diff changeset
46 }
38bbbf74b735 Initial work on event support in SDL module
Michael Pavone <pavone@retrodev.com>
parents: 287
diff changeset
47 }
38bbbf74b735 Initial work on event support in SDL module
Michael Pavone <pavone@retrodev.com>
parents: 287
diff changeset
48 }
38bbbf74b735 Initial work on event support in SDL module
Michael Pavone <pavone@retrodev.com>
parents: 287
diff changeset
49 } none: {}
38bbbf74b735 Initial work on event support in SDL module
Michael Pavone <pavone@retrodev.com>
parents: 287
diff changeset
50 }
278
1205c7a43cb4 Add bindings for SDL_ClearError, SDL_GetError, SDL_LoadBMP, SDL_CreateTextureFromSurface and a partial binding for SDL_RendererCopy
Michael Pavone <pavone@retrodev.com>
parents: 277
diff changeset
51 }
1205c7a43cb4 Add bindings for SDL_ClearError, SDL_GetError, SDL_LoadBMP, SDL_CreateTextureFromSurface and a partial binding for SDL_RendererCopy
Michael Pavone <pavone@retrodev.com>
parents: 277
diff changeset
52 tex destroy
1205c7a43cb4 Add bindings for SDL_ClearError, SDL_GetError, SDL_LoadBMP, SDL_CreateTextureFromSurface and a partial binding for SDL_RendererCopy
Michael Pavone <pavone@retrodev.com>
parents: 277
diff changeset
53 } none: {
1205c7a43cb4 Add bindings for SDL_ClearError, SDL_GetError, SDL_LoadBMP, SDL_CreateTextureFromSurface and a partial binding for SDL_RendererCopy
Michael Pavone <pavone@retrodev.com>
parents: 277
diff changeset
54 surf free
1205c7a43cb4 Add bindings for SDL_ClearError, SDL_GetError, SDL_LoadBMP, SDL_CreateTextureFromSurface and a partial binding for SDL_RendererCopy
Michael Pavone <pavone@retrodev.com>
parents: 277
diff changeset
55 }
1205c7a43cb4 Add bindings for SDL_ClearError, SDL_GetError, SDL_LoadBMP, SDL_CreateTextureFromSurface and a partial binding for SDL_RendererCopy
Michael Pavone <pavone@retrodev.com>
parents: 277
diff changeset
56 } none: {
1205c7a43cb4 Add bindings for SDL_ClearError, SDL_GetError, SDL_LoadBMP, SDL_CreateTextureFromSurface and a partial binding for SDL_RendererCopy
Michael Pavone <pavone@retrodev.com>
parents: 277
diff changeset
57 }
277
2b58eafa360b Add SDL bindings for creating a renderer, clearing it, presenting it and destroying it
Michael Pavone <pavone@retrodev.com>
parents: 274
diff changeset
58 render destroy
2b58eafa360b Add SDL bindings for creating a renderer, clearing it, presenting it and destroying it
Michael Pavone <pavone@retrodev.com>
parents: 274
diff changeset
59 } none: {
2b58eafa360b Add SDL bindings for creating a renderer, clearing it, presenting it and destroying it
Michael Pavone <pavone@retrodev.com>
parents: 274
diff changeset
60 print: "Failed to create renderer\n"
2b58eafa360b Add SDL bindings for creating a renderer, clearing it, presenting it and destroying it
Michael Pavone <pavone@retrodev.com>
parents: 274
diff changeset
61 }
274
a923b5b7da3d Initial work on an SDL2 binding
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
62 window destroy
a923b5b7da3d Initial work on an SDL2 binding
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
63 } none: {
a923b5b7da3d Initial work on an SDL2 binding
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
64 print: "Failed to create window\n"
a923b5b7da3d Initial work on an SDL2 binding
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
65 1
a923b5b7da3d Initial work on an SDL2 binding
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
66 }
a923b5b7da3d Initial work on an SDL2 binding
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
67 } else: {
a923b5b7da3d Initial work on an SDL2 binding
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
68 print: "Failed to initialize SDL\n"
a923b5b7da3d Initial work on an SDL2 binding
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
69 1
a923b5b7da3d Initial work on an SDL2 binding
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
70 }
a923b5b7da3d Initial work on an SDL2 binding
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
71 }
277
2b58eafa360b Add SDL bindings for creating a renderer, clearing it, presenting it and destroying it
Michael Pavone <pavone@retrodev.com>
parents: 274
diff changeset
72 }