From 6bd2d2b32456f464dce72b562dfd690e064b5415 Mon Sep 17 00:00:00 2001 From: James Turk Date: Sat, 4 Jun 2011 00:03:54 -0400 Subject: [PATCH] mouse demo --- demo/mouse.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 demo/mouse.py diff --git a/demo/mouse.py b/demo/mouse.py new file mode 100644 index 0000000..1efab31 --- /dev/null +++ b/demo/mouse.py @@ -0,0 +1,42 @@ +from photon import init, InitFlags, mouse, video, keyboard +from photon.events import poll_event, EventType, WindowEventType + +def main(): + init(InitFlags.EVERYTHING) + + w = video.Window('mouse test', 10, 10, 300, 300) + running = True + points = [] + + while running: + + # event loop + while True: + event = poll_event() + if not event: + break + elif event.type == EventType.QUIT: + running = False + elif event.type == EventType.WINDOWEVENT: + if event.window.event == WindowEventType.CLOSE: + running = False + elif event.type == EventType.MOUSEBUTTONDOWN: + pass + elif event.type == EventType.MOUSEBUTTONUP: + x, y, buttons = mouse.get_mouse_state() + points.append((x,y)) + elif event.type == EventType.KEYDOWN: + if event.key.keysym.scancode == keyboard.Scancode.SPACE: + points = [] + elif event.key.keysym.scancode == keyboard.Scancode.BACKSPACE: + points.pop() + + w.renderer.set_draw_color(0,0,0,255) + w.renderer.clear() + w.renderer.set_draw_color(255,0,0,255) + w.renderer.draw_lines(points) + w.renderer.present() + + +if __name__ == '__main__': + main()