|
1 | 1 | __all__ = ('touch_indicator', )
|
2 | 2 |
|
3 | 3 | from functools import partial
|
4 |
| -from typing import Unpack, Self |
| 4 | +from typing import Unpack |
5 | 5 |
|
6 | 6 | import pygame
|
7 | 7 | from pygame import Color, Event
|
|
12 | 12 | class Ring:
|
13 | 13 | __slots__ = ('draw', 'pos', )
|
14 | 14 |
|
15 |
| - def __init__(self, draw_target, color, pos, radius, line_width): |
16 |
| - self.draw = partial(self._draw, draw_target, color, radius, line_width, self) |
17 |
| - self.pos = pos |
| 15 | + def __init__(self, draw_target: pygame.Surface, color, initial_pos, radius, line_width): |
| 16 | + ring_img = pygame.Surface((radius * 2, radius * 2)).convert(draw_target) |
| 17 | + color = Color(color) |
| 18 | + bgcolor = Color("black") |
| 19 | + if color == bgcolor: |
| 20 | + bgcolor = Color("white") |
| 21 | + ring_img.fill(bgcolor) |
| 22 | + ring_img.set_colorkey(bgcolor) |
| 23 | + pygame.draw.circle(ring_img, color, (radius, radius), radius, line_width) |
18 | 24 |
|
19 |
| - def _draw(pygame_draw_circle, draw_target, color, radius, line_width, self: Self): |
20 |
| - pygame_draw_circle(draw_target, color, self.pos, radius, line_width) |
| 25 | + self.draw = partial(self.__class__._draw, self, draw_target.blit, ring_img, ring_img.get_rect()) |
| 26 | + self.pos = initial_pos |
21 | 27 |
|
22 |
| - _draw = partial(_draw, pygame.draw.circle) |
| 28 | + def _draw(self, blit, ring_img, ring_dest): |
| 29 | + ring_dest.center = self.pos |
| 30 | + blit(ring_img, ring_dest) |
23 | 31 |
|
24 | 32 |
|
25 | 33 | async def touch_indicator(*, color="white", radius=60, line_width=4, priority, **kwargs: Unpack[apg.CommonParams]):
|
|
0 commit comments