Mercurial > repos > tabletprog
view samples/sdl.tp @ 306:8dbb2d2522a5
Fix a crash in from:withLength when given a negative length. Fix a bug in trim that was causing it to give a negative length to from:withLength
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 27 Jul 2014 13:01:08 -0700 |
parents | 2b045d5b673b |
children | 4c669942c30d |
line wrap: on
line source
#{ import: [ video timer ] from: (sdl subsystems) import: [ quit keyDown keyUp mouseDown mouseUp mouseMotion ] from: (sdl eventTypes) main <- { if: (sdl init: (video or timer)) = 0 { (sdl createWindow: "SDL Test" pos: 0 0 size: 640 480 flags: 0u32) value: :window { (window createRenderer: -1 flags: ((window renderOpts) accelerated)) value: :render { render drawColor!: (sdl r: 0u8 g: 0u8 b: 255u8) render clear (sdl loadBMP: "944.bmp") value: :surf { (surf asTexture: render) value: :tex { surf free angle <- 45.0f32 continue? <- true while: { continue? } do: { tex copy tex copyTo: (sdl rect: 160 120 size: 320 224) tex copyRect: (sdl rect: 80 60 size: 160 120) To: (sdl rect: 40 30 size: 320 224) tex copyTo: (sdl rect: 320 240 size: 320 224) rotated: angle render present angle <- angle + 1.0f32 event <- option none while: { event <- sdl pollEvent event value? } do: { event value: :ev { if: (ev type) = quit { continue? <- false } else: { if: (ev type) = keyDown || (ev type) = keyUp { print: "Key event for: " . (ev keyChar) . ", pressed?: " . (ev pressed?) . "\n" } else: { if: (ev type) = mouseDown || (ev type) = mouseUp { print: "Mouse button event at: " . (ev x) . ", " . (ev y) . " for button " . (ev button) . "\n" } else: { if: (ev type) = mouseMotion { print: "Mouse motion event: " . (ev xRel) . ", " . (ev yRel) . "\n" } } } } } none: {} } } tex destroy } none: { surf free } } none: { } render destroy } none: { print: "Failed to create renderer\n" } window destroy } none: { print: "Failed to create window\n" 1 } } else: { print: "Failed to initialize SDL\n" 1 } } }