sync pyglet
This commit is contained in:
parent
f17e4fbd59
commit
fd988f6b5f
@ -192,6 +192,7 @@ class ShapeBase(ABC):
|
||||
"""
|
||||
|
||||
_rgba = (255, 255, 255, 255)
|
||||
_rotation = 0
|
||||
_visible = True
|
||||
_x = 0
|
||||
_y = 0
|
||||
@ -252,6 +253,29 @@ class ShapeBase(ABC):
|
||||
"""
|
||||
raise NotImplementedError("_update_vertices must be defined"
|
||||
"for every ShapeBase subclass")
|
||||
@property
|
||||
def rotation(self) -> float:
|
||||
"""Clockwise rotation of the shape in degrees.
|
||||
|
||||
It will be rotated about its (anchor_x, anchor_y) position,
|
||||
which defaults to the first vertex point of the shape.
|
||||
|
||||
For most shapes, this is the lower left corner. The shapes
|
||||
below default to the points their ``radius`` values are
|
||||
measured from:
|
||||
|
||||
* :py:class:`.Circle`
|
||||
* :py:class:`.Ellipse`
|
||||
* :py:class:`.Arc`
|
||||
* :py:class:`.Sector`
|
||||
* :py:class:`.Star`
|
||||
"""
|
||||
return self._rotation
|
||||
|
||||
@rotation.setter
|
||||
def rotation(self, rotation: float) -> None:
|
||||
self._rotation = rotation
|
||||
self._vertex_list.rotation[:] = (rotation,) * self._num_verts
|
||||
|
||||
def draw(self):
|
||||
"""Draw the shape at its current position.
|
||||
@ -545,22 +569,6 @@ class Arc(ShapeBase):
|
||||
|
||||
self._vertex_list.position[:] = vertices
|
||||
|
||||
@property
|
||||
def rotation(self):
|
||||
"""Clockwise rotation of the arc, in degrees.
|
||||
|
||||
The arc will be rotated about its (anchor_x, anchor_y)
|
||||
position.
|
||||
|
||||
:type: float
|
||||
"""
|
||||
return self._rotation
|
||||
|
||||
@rotation.setter
|
||||
def rotation(self, rotation):
|
||||
self._rotation = rotation
|
||||
self._vertex_list.rotation[:] = (rotation,) * self._num_verts
|
||||
|
||||
@property
|
||||
def angle(self):
|
||||
"""The angle of the arc.
|
||||
@ -623,6 +631,7 @@ class BezierCurve(ShapeBase):
|
||||
Optional parent group of the curve.
|
||||
"""
|
||||
self._points = list(points)
|
||||
self._x, self._y = self._points[0]
|
||||
self._t = t
|
||||
self._segments = segments
|
||||
self._num_verts = self._segments * 2
|
||||
@ -649,7 +658,7 @@ class BezierCurve(ShapeBase):
|
||||
self._vertex_list = self._group.program.vertex_list(
|
||||
self._num_verts, self._draw_mode, self._batch, self._group,
|
||||
colors=('Bn', self._rgba * self._num_verts),
|
||||
translation=('f', (self._points[0]) * self._num_verts))
|
||||
translation=('f', (self._x, self._y) * self._num_verts))
|
||||
|
||||
def _update_vertices(self):
|
||||
if not self._visible:
|
||||
@ -896,22 +905,6 @@ class Ellipse(ShapeBase):
|
||||
self._b = value
|
||||
self._update_vertices()
|
||||
|
||||
@property
|
||||
def rotation(self):
|
||||
"""Clockwise rotation of the arc, in degrees.
|
||||
|
||||
The arc will be rotated about its (anchor_x, anchor_y)
|
||||
position.
|
||||
|
||||
:type: float
|
||||
"""
|
||||
return self._rotation
|
||||
|
||||
@rotation.setter
|
||||
def rotation(self, rotation):
|
||||
self._rotation = rotation
|
||||
self._vertex_list.rotation[:] = (rotation,) * self._num_verts
|
||||
|
||||
|
||||
class Sector(ShapeBase):
|
||||
def __init__(self, x, y, radius, segments=None, angle=math.tau, start_angle=0,
|
||||
@ -1042,22 +1035,6 @@ class Sector(ShapeBase):
|
||||
self._radius = value
|
||||
self._update_vertices()
|
||||
|
||||
@property
|
||||
def rotation(self):
|
||||
"""Clockwise rotation of the sector, in degrees.
|
||||
|
||||
The sector will be rotated about its (anchor_x, anchor_y)
|
||||
position.
|
||||
|
||||
:type: float
|
||||
"""
|
||||
return self._rotation
|
||||
|
||||
@rotation.setter
|
||||
def rotation(self, rotation):
|
||||
self._rotation = rotation
|
||||
self._vertex_list.rotation[:] = (rotation,) * self._num_verts
|
||||
|
||||
|
||||
class Line(ShapeBase):
|
||||
def __init__(self, x, y, x2, y2, width=1, color=(255, 255, 255, 255),
|
||||
@ -1280,22 +1257,6 @@ class Rectangle(ShapeBase):
|
||||
self._height = value
|
||||
self._update_vertices()
|
||||
|
||||
@property
|
||||
def rotation(self):
|
||||
"""Clockwise rotation of the rectangle, in degrees.
|
||||
|
||||
The Rectangle will be rotated about its (anchor_x, anchor_y)
|
||||
position.
|
||||
|
||||
:type: float
|
||||
"""
|
||||
return self._rotation
|
||||
|
||||
@rotation.setter
|
||||
def rotation(self, rotation):
|
||||
self._rotation = rotation
|
||||
self._vertex_list.rotation[:] = (rotation,) * self._num_verts
|
||||
|
||||
|
||||
class BorderedRectangle(ShapeBase):
|
||||
def __init__(self, x, y, width, height, border=1, color=(255, 255, 255),
|
||||
@ -1443,22 +1404,6 @@ class BorderedRectangle(ShapeBase):
|
||||
self._height = value
|
||||
self._update_vertices()
|
||||
|
||||
@property
|
||||
def rotation(self):
|
||||
"""Clockwise rotation of the rectangle, in degrees.
|
||||
|
||||
The Rectangle will be rotated about its (anchor_x, anchor_y)
|
||||
position.
|
||||
|
||||
:type: float
|
||||
"""
|
||||
return self._rotation
|
||||
|
||||
@rotation.setter
|
||||
def rotation(self, rotation):
|
||||
self._rotation = rotation
|
||||
self._vertex_list.rotation[:] = (rotation,) * self._num_verts
|
||||
|
||||
@property
|
||||
def border_color(self):
|
||||
"""The rectangle's border color.
|
||||
@ -1765,17 +1710,6 @@ class Star(ShapeBase):
|
||||
self._num_spikes = value
|
||||
self._update_vertices()
|
||||
|
||||
@property
|
||||
def rotation(self):
|
||||
"""Rotation of the star, in degrees.
|
||||
"""
|
||||
return self._rotation
|
||||
|
||||
@rotation.setter
|
||||
def rotation(self, rotation):
|
||||
self._rotation = rotation
|
||||
self._vertex_list.rotation[:] = (rotation,) * self._num_verts
|
||||
|
||||
|
||||
class Polygon(ShapeBase):
|
||||
def __init__(self, *coordinates, color=(255, 255, 255, 255), batch=None, group=None):
|
||||
@ -1799,6 +1733,7 @@ class Polygon(ShapeBase):
|
||||
# len(self._coordinates) = the number of vertices and sides in the shape.
|
||||
self._rotation = 0
|
||||
self._coordinates = list(coordinates)
|
||||
self._x, self._y = self._coordinates[0]
|
||||
self._num_verts = (len(self._coordinates) - 2) * 3
|
||||
|
||||
r, g, b, *a = color
|
||||
@ -1820,7 +1755,7 @@ class Polygon(ShapeBase):
|
||||
self._vertex_list = self._group.program.vertex_list(
|
||||
self._num_verts, self._draw_mode, self._batch, self._group,
|
||||
colors=('Bn', self._rgba * self._num_verts),
|
||||
translation=('f', (self._coordinates[0]) * self._num_verts))
|
||||
translation=('f', (self._x, self._y) * self._num_verts))
|
||||
|
||||
def _update_vertices(self):
|
||||
if not self._visible:
|
||||
@ -1840,21 +1775,5 @@ class Polygon(ShapeBase):
|
||||
# Flattening the list before setting vertices to it.
|
||||
self._vertex_list.position[:] = tuple(value for coordinate in triangles for value in coordinate)
|
||||
|
||||
@property
|
||||
def rotation(self):
|
||||
"""Clockwise rotation of the polygon, in degrees.
|
||||
|
||||
The Polygon will be rotated about its (anchor_x, anchor_y)
|
||||
position.
|
||||
|
||||
:type: float
|
||||
"""
|
||||
return self._rotation
|
||||
|
||||
@rotation.setter
|
||||
def rotation(self, rotation):
|
||||
self._rotation = rotation
|
||||
self._vertex_list.rotation[:] = (rotation,) * self._num_verts
|
||||
|
||||
|
||||
__all__ = 'Arc', 'BezierCurve', 'Circle', 'Ellipse', 'Line', 'Rectangle', 'BorderedRectangle', 'Triangle', 'Star', 'Polygon', 'Sector'
|
||||
|
Loading…
Reference in New Issue
Block a user