-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindow.py
More file actions
executable file
·43 lines (33 loc) · 1.06 KB
/
window.py
File metadata and controls
executable file
·43 lines (33 loc) · 1.06 KB
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
33
34
35
36
37
38
39
40
41
42
import ctypes
import sdl2
from rendrer import Renderer
class Window:
DEFAULT_WIDTH = 400
DEFAULT_HEIGHT = 400
def __init__(self, title, width=DEFAULT_WIDTH, height=DEFAULT_HEIGHT):
sdl2.SDL_Init(sdl2.SDL_INIT_VIDEO)
self.sdl_window = sdl2.SDL_CreateWindow(
title,
sdl2.SDL_WINDOWPOS_CENTERED,
sdl2.SDL_WINDOWPOS_CENTERED,
width,
height,
sdl2.SDL_WINDOW_RESIZABLE
)
self._renderer = Renderer(self)
self.resize()
@property
def size(self):
width = ctypes.c_int()
height = ctypes.c_int()
sdl2.SDL_GetWindowSize(self.sdl_window, ctypes.byref(width), ctypes.byref(height))
return width.value, height.value
def resize(self):
self._renderer.resize()
def on_key_pressed(self, key_code):
self._renderer.on_key_pressed(key_code)
def on_key_up(self, key_code):
self._renderer.on_key_up(key_code)
def close(self):
sdl2.SDL_DestroyWindow(self.sdl_window)
sdl2.SDL_Quit()