1 """ Actor that takes a surface. """
3 from pygame.transform import rotate
4 from pgzero.actor import POS_TOPLEFT, ANCHOR_CENTER
6 from .surf import SurfActor
9 class OrientatedSurfActor(SurfActor):
10 def __init__(self, surf, pos=POS_TOPLEFT, anchor=ANCHOR_CENTER, angle=0,
12 self._handle_unexpected_kwargs(kwargs)
15 self._base_surf = surf
16 super().__init__(surf, pos, anchor)
17 self._init_position(pos, anchor, **kwargs)
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])
29 self._surf = self._orig_surf = rotate(self._base_surf, angle)
33 """ The original surface displaying the actor. """
34 return self._orig_surf
38 self._base_surf = surf
39 self._orig_surf = self._surf = rotate(surf, self._angle)
43 class SelectableSurfActor(OrientatedSurfActor):
44 def __init__(self, seat, selected_seat):
45 self._selected = False
47 self._selected_seat = selected_seat
48 super().__init__(surf=self._seat, angle=0)
55 def selected(self, value):
56 self._selected = value
57 self.surf = self._selected_seat if value else self._seat