Poppable.
[koperkapel.git] / koperkapel / actors / orientatedsurf.py
1 """ Actor that takes a surface. """
2
3 from pygame.transform import rotate
4 from pgzero.actor import POS_TOPLEFT, ANCHOR_CENTER
5
6 from .surf import SurfActor
7
8
9 class OrientatedSurfActor(SurfActor):
10     def __init__(self, surf, pos=POS_TOPLEFT, anchor=ANCHOR_CENTER, angle=0,
11                  **kwargs):
12         self._handle_unexpected_kwargs(kwargs)
13
14         self._angle = angle
15         self._base_surf = surf
16         super().__init__(surf, pos, anchor)
17         self._init_position(pos, anchor, **kwargs)
18
19     @property
20     def angle(self):
21         return self._angle
22
23     @angle.setter
24     def angle(self, angle):
25         cur_anchor = self._anchor_value
26         if angle not in (self._angle, self._angle + 180, self._angle - 180):
27             self._anchor_value = (cur_anchor[1], cur_anchor[0])
28         self._angle = angle
29         self._surf = self._orig_surf = rotate(self._base_surf, angle)
30
31     @property
32     def surf(self):
33         """ The original surface displaying the actor. """
34         return self._orig_surf
35
36     @surf.setter
37     def surf(self, surf):
38         self._base_surf = surf
39         self._orig_surf = self._surf = rotate(surf, self._angle)
40         self._update_pos()
41
42
43 class SelectableSurfActor(OrientatedSurfActor):
44     def __init__(self, seat, selected_seat):
45         self._selected = False
46         self._seat = seat
47         self._selected_seat = selected_seat
48         super().__init__(surf=self._seat, angle=0)
49
50     @property
51     def selected(self):
52         return self._selected
53
54     @selected.setter
55     def selected(self, value):
56         self._selected = value
57         self.surf = self._selected_seat if value else self._seat