comparison 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
comparison
equal deleted inserted replaced
290:38ca63e0a62e 291:38bbbf74b735
1 #{ 1 #{
2 import: [ 2 import: [
3 video 3 video
4 timer 4 timer
5 ] from: (sdl subsystems) 5 ] from: (sdl subsystems)
6 import: [
7 quit
8 keyDown
9 keyUp
10 mouseDown
11 mouseUp
12 ] from: (sdl eventTypes)
6 main <- { 13 main <- {
7 if: (sdl init: (video or timer)) = 0 { 14 if: (sdl init: (video or timer)) = 0 {
8 (sdl createWindow: "SDL Test" pos: 0 0 size: 640 480 flags: 0u32) value: :window { 15 (sdl createWindow: "SDL Test" pos: 0 0 size: 640 480 flags: 0u32) value: :window {
9 (window createRenderer: -1 flags: ((window renderOpts) accelerated)) value: :render { 16 (window createRenderer: -1 flags: ((window renderOpts) accelerated)) value: :render {
10 render drawColor!: (sdl r: 0u8 g: 0u8 b: 255u8) 17 render drawColor!: (sdl r: 0u8 g: 0u8 b: 255u8)
11 render clear 18 render clear
12 (sdl loadBMP: "944.bmp") value: :surf { 19 (sdl loadBMP: "944.bmp") value: :surf {
13 (surf asTexture: render) value: :tex { 20 (surf asTexture: render) value: :tex {
14 sdl clearError 21 surf free
15 if: (tex copy) != 0 { 22 angle <- 45.0f32
16 print: "Failed to copy texture to renderer: " . (sdl getError) . "\n" 23 continue? <- true
24 while: { continue? } do: {
25 tex copy
26 tex copyTo: (sdl rect: 160 120 size: 320 224)
27 tex copyRect: (sdl rect: 80 60 size: 160 120) To: (sdl rect: 40 30 size: 320 224)
28 tex copyTo: (sdl rect: 320 240 size: 320 224) rotated: angle
29 render present
30 angle <- angle + 1.0f32
31
32 event <- option none
33 while: {
34 event <- sdl pollEvent
35 event value?
36 } do: {
37 event value: :ev {
38 if: (ev type) = quit {
39 continue? <- false
40 } else: {
41 if: (ev type) = keyDown || (ev type) = keyUp {
42 print: "Key event for: " . (ev keyChar) . ", pressed?: " . (ev pressed?) . "\n"
43 } else: {
44 if: (ev type) = mouseDown || (ev type) = mouseUp {
45 print: "Mouse event at: " . (ev x) . ", " . (ev y) . " for button " . (ev button) . "\n"
46 }
47 }
48 }
49 } none: {}
50 }
17 } 51 }
18 surf free
19 tex copyTo: (sdl rect: 160 120 size: 320 224)
20 tex copyRect: (sdl rect: 80 60 size: 160 120) To: (sdl rect: 40 30 size: 320 224)
21 tex copyTo: (sdl rect: 320 240 size: 320 224) rotated: 45.0
22 render present
23 sdl delay: 3000u32
24 tex destroy 52 tex destroy
25 } none: { 53 } none: {
26 surf free 54 surf free
27 } 55 }
28 } none: { 56 } none: {