-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindow.py
More file actions
37 lines (29 loc) · 919 Bytes
/
window.py
File metadata and controls
37 lines (29 loc) · 919 Bytes
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
import ctypes
import sdl2
from rendrer import Renderer
class Window:
DEFAULT_WIDTH = 800
DEFAULT_HEIGHT = 800
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 close(self):
sdl2.SDL_DestroyWindow(self.sdl_window)
sdl2.SDL_Quit()