forked from R-Ianni/AT2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdraw_process_funcs.py
More file actions
79 lines (66 loc) · 2.15 KB
/
draw_process_funcs.py
File metadata and controls
79 lines (66 loc) · 2.15 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import pathlib
from typing import Any, Literal, Optional, Sequence
import pygame
def init(dim: Sequence[int]) -> None:
pygame.init()
global window # pylint: disable=global-variable-undefined
window = pygame.display.set_mode(dim) # type: ignore[name-defined]
pygame.key.set_repeat(25)
def construct_and_blit(
surf_as_bytes: tuple[
bytes,
Sequence[int] | tuple[int, int],
Literal["P", "RGB", "BGR", "BGRA", "RGBX", "RGBA", "ARGB"],
],
rect: pygame.Rect,
mask: Optional[pygame.Rect] = None,
) -> pygame.Rect:
global window # pylint: disable=global-variable-not-assigned
surf: pygame.Surface = pygame.image.frombuffer(
surf_as_bytes[0],
surf_as_bytes[1],
surf_as_bytes[2],
)
return window.blit(surf, rect, mask) # type: ignore[name-defined]
def fill_screen(colour: Sequence[int] | tuple[int, int, int]) -> pygame.Rect:
global window # pylint: disable=global-variable-not-assigned
return window.fill(color=colour) # type: ignore[name-defined]
def load_image(
path: pathlib.Path | str,
) -> tuple[
bytes,
Sequence[int] | tuple[int, int],
Literal["P", "RGB", "BGR", "BGRA", "RGBX", "RGBA", "ARGB"],
]:
surf: pygame.Surface = pygame.image.load(path)
surf = surf.convert_alpha()
return (
pygame.image.tobytes(surf, "RGBA"),
[surf.get_width(), surf.get_height()],
"RGBA",
)
def convert(
surf_as_bytes: tuple[
bytes,
Sequence[int] | tuple[int, int],
Literal["P", "RGB", "RGBX", "RGBA", "ARGB", "BGRA"],
]
) -> tuple[
bytes,
Sequence[int] | tuple[int, int],
Literal["P", "RGB", "RGBX", "RGBA", "ARGB", "BGRA"],
]:
surf: pygame.Surface = pygame.image.frombuffer(
surf_as_bytes[0],
surf_as_bytes[1],
surf_as_bytes[2],
)
surf = surf.convert_alpha()
return (
pygame.image.tobytes(surf, surf_as_bytes[2]),
[surf.get_width(), surf.get_height()],
surf_as_bytes[2],
)
def get_events() -> list[tuple[int, dict[str, Any]]]:
events: list[pygame.event.Event] = pygame.event.get()
return [(evt.type, evt.dict) for evt in events]