import a.sdl2 import a.time canvas = sdl2::Canvas('sdl test', 800, 600, fullscreen=false) canvas.set_draw_color([66, 24, 255]) canvas.clear() canvas.present() canvas.set_draw_color([25, 100, 25]) canvas.fill_rect([0, 0, 400, 300]) canvas.present() running = true while running { for event in sdl2::poll() { switch event.type { :KeyDown => { switch event.keycode { :Escape => { running = false } :F => { canvas.set_size([300, 300]) canvas.present() } :J => { canvas.set_size([800, 600]) canvas.present() } => print('KeyDown %r' % [event.keycode]) } } :MouseDown => { canvas.set_draw_color([66, 24, 255]) canvas.clear() canvas.set_draw_color([20, 100, 0]) canvas.fill_rect([event.x - 20, event.y - 20, 40, 40]) canvas.present() } :MouseUp => { canvas.set_draw_color([66, 24, 255]) canvas.clear() canvas.set_draw_color([20, 100, 0]) canvas.fill_rect([event.x - 20, event.y - 20, 40, 40]) canvas.present() } :MouseMove => { if event.state.has(:Left) { canvas.set_draw_color([66, 24, 255]) canvas.clear() canvas.set_draw_color([20, 100, 0]) canvas.fill_rect([event.x - 20, event.y - 20, 40, 40]) canvas.present() } } => { # print('event = %r' % [event]) } } } if running { time::sleep(1 / 20) } }