-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent_loop.py
32 lines (24 loc) · 908 Bytes
/
event_loop.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import ctypes
import sdl2
from event_dispatcher import EventDispatcher
class EventLoop:
def __init__(self, window):
self._event_dispatcher = EventDispatcher(self, window)
self._running = False
rotate_event = sdl2.SDL_Event()
rotate_event.type = EventDispatcher.ROTATE_EVENT
self._window = window
self._rotate_event_pointer = ctypes.byref(rotate_event)
def run(self):
self._running = True
while self._running:
if self._window.can_rotate:
sdl2.SDL_PushEvent(self._rotate_event_pointer)
self._receive_events()
def stop(self):
self._running = False
def _receive_events(self):
event = sdl2.SDL_Event()
event_pointer = ctypes.byref(event)
while self._running and sdl2.SDL_PollEvent(event_pointer) != 0:
self._event_dispatcher.dispatch(event)