Skip to content

Commit 4862eac

Browse files
Makes Anchor defined like CustomAnchor
Really? Why hadn't I though of that before?
1 parent 507d1c3 commit 4862eac

1 file changed

Lines changed: 9 additions & 46 deletions

File tree

src/pyrite/types/enums.py

Lines changed: 9 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -135,39 +135,6 @@ def _(cls, index: int) -> Layer:
135135

136136

137137
class Anchor:
138-
"""
139-
Determines where on a surface the position is based.
140-
"""
141-
142-
def __init__(self, target_attribute: str) -> None:
143-
self._target_attribute = target_attribute
144-
145-
def anchor_rect(self, rectangle: RectLike, position: Point) -> pygame.Rect:
146-
"""
147-
Supplies a new rectangle, with the size of the original, but the location of
148-
the rectangle based on the given position, and the anchor point's assigned
149-
attribute.
150-
151-
:param rectangle: A rect-like that will be moved to the position
152-
:param position: A position to move the rectangle to.
153-
:return: The new rectangle, in the position location.
154-
"""
155-
rect = pygame.Rect(rectangle)
156-
rect.__setattr__(self._target_attribute, position)
157-
return rect
158-
159-
def anchor_rect_ip(self, rectangle: pygame.Rect, position: Point) -> None:
160-
"""
161-
Moves the passed rectangle to the position, with that position being based on
162-
the anchorpoint.
163-
164-
:param rectangle: A rectangle that will have its position modified.
165-
:param position: A position to move the rectangle to.
166-
"""
167-
rectangle.__setattr__(self._target_attribute, position)
168-
169-
170-
class CustomAnchor(Anchor):
171138
"""
172139
A custom variant of Anchor, where a supplied offset is used to determine where in
173140
the rectangle the position is based.
@@ -195,21 +162,17 @@ def anchor_rect_ip(self, rectangle: pygame.Rect, position: Point) -> None:
195162
rectangle.topleft = offset
196163

197164

198-
# TODO Add CustomAnchor, which uses an FRect like SurfaceSector to determine relative
199-
# position. Maybe Vector2 instead? We'll see.
200-
201-
202165
class AnchorPoint:
203166
"""
204167
An enum for modifying the position of a rectangle for renderables.
205168
"""
206169

207-
TOPLEFT = Anchor("topleft")
208-
MIDTOP = Anchor("midtop")
209-
TOPRIGHT = Anchor("topright")
210-
MIDLEFT = Anchor("midleft")
211-
CENTER = Anchor("center")
212-
MIDRIGHT = Anchor("midright")
213-
BOTTOMLEFT = Anchor("bottomleft")
214-
MIDBOTTOM = Anchor("midbottom")
215-
BOTTOMRIGHT = Anchor("bottomright")
170+
TOPLEFT = Anchor((0, 0))
171+
MIDTOP = Anchor((0.5, 0))
172+
TOPRIGHT = Anchor((1, 0))
173+
MIDLEFT = Anchor((0, 0.5))
174+
CENTER = Anchor((0.5, 0.5))
175+
MIDRIGHT = Anchor((1, 0.5))
176+
BOTTOMLEFT = Anchor((0, 1))
177+
MIDBOTTOM = Anchor((0.5, 1))
178+
BOTTOMRIGHT = Anchor((1, 1))

0 commit comments

Comments
 (0)