sync pyglet update (shape)

This commit is contained in:
shenjack 2023-07-06 18:36:42 +08:00
parent f87ae43a10
commit a46b46ead6

View File

@ -527,7 +527,7 @@ class Arc(ShapeBase):
def _update_vertices(self):
if not self._visible:
vertices = (0,) * (self._segments + 1) * 4
vertices = (0, 0) * self._num_verts
else:
x = -self._anchor_x
y = -self._anchor_y
@ -659,7 +659,7 @@ class BezierCurve(ShapeBase):
def _update_vertices(self):
if not self._visible:
vertices = (0,) * self._segments * 4
vertices = (0, 0) * self._num_verts
else:
x = -self._anchor_x
y = -self._anchor_y
@ -762,7 +762,7 @@ class Circle(ShapeBase):
def _update_vertices(self):
if not self._visible:
vertices = (0,) * self._segments * 6
vertices = (0, 0) * self._num_verts
else:
x = -self._anchor_x
y = -self._anchor_y
@ -858,7 +858,7 @@ class Ellipse(ShapeBase):
def _update_vertices(self):
if not self._visible:
vertices = (0,) * self._num_verts * 6
vertices = (0, 0) * self._num_verts
else:
x = -self._anchor_x
y = -self._anchor_y
@ -989,7 +989,7 @@ class Sector(ShapeBase):
def _update_vertices(self):
if not self._visible:
vertices = (0,) * self._segments * 6
vertices = (0, 0) * self._num_verts
else:
x = -self._anchor_x
y = -self._anchor_y
@ -1114,11 +1114,11 @@ class Line(ShapeBase):
def __contains__(self, point):
assert len(point) == 2
vec_AB = Vec2(self._x2 - self._x, self._y2 - self._y)
vec_BA = Vec2(self._x - self._x2, self._y - self._y2)
vec_AP = Vec2(point[0] - self._x - self._anchor_x, point[1] - self._y + self._anchor_y)
vec_BP = Vec2(point[0] - self._x2 - self._anchor_x, point[1] - self._y2 + self._anchor_y)
if vec_AB.dot(vec_AP) * vec_BA.dot(vec_BP) < 0:
vec_ab = Vec2(self._x2 - self._x, self._y2 - self._y)
vec_ba = Vec2(self._x - self._x2, self._y - self._y2)
vec_ap = Vec2(point[0] - self._x - self._anchor_x, point[1] - self._y + self._anchor_y)
vec_bp = Vec2(point[0] - self._x2 - self._anchor_x, point[1] - self._y2 + self._anchor_y)
if vec_ab.dot(vec_ap) * vec_ba.dot(vec_bp) < 0:
return False
a, b = point[0] + self._anchor_x, point[1] - self._anchor_y
@ -1137,7 +1137,7 @@ class Line(ShapeBase):
def _update_vertices(self):
if not self._visible:
self._vertex_list.position[:] = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
self._vertex_list.position[:] = (0, 0) * self._num_verts
else:
x1 = -self._anchor_x
y1 = self._anchor_y - self._width / 2
@ -1158,6 +1158,15 @@ class Line(ShapeBase):
self._vertex_list.position[:] = (ax, ay, bx, by, cx, cy, ax, ay, cx, cy, dx, dy)
@property
def width(self):
return self._width
@width.setter
def width(self, width):
self._width = width
self._update_vertices()
@property
def x2(self):
"""Second X coordinate of the shape.
@ -1242,7 +1251,7 @@ class Rectangle(ShapeBase):
def _update_vertices(self):
if not self._visible:
self._vertex_list.position[:] = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
self._vertex_list.position[:] = (0, 0) * self._num_verts
else:
x1 = -self._anchor_x
y1 = -self._anchor_y
@ -1386,7 +1395,7 @@ class BorderedRectangle(ShapeBase):
def _update_vertices(self):
if not self._visible:
self._vertex_list.position[:] = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
self._vertex_list.position[:] = (0, 0) * self._num_verts
else:
bx1 = -self._anchor_x
by1 = -self._anchor_y
@ -1565,7 +1574,7 @@ class Triangle(ShapeBase):
def _update_vertices(self):
if not self._visible:
self._vertex_list.position[:] = (0, 0, 0, 0, 0, 0)
self._vertex_list.position[:] = (0, 0) * self._num_verts
else:
x1 = -self._anchor_x
y1 = -self._anchor_y
@ -1693,7 +1702,7 @@ class Star(ShapeBase):
def _update_vertices(self):
if not self._visible:
vertices = (0, 0) * self._num_spikes * 6
vertices = (0, 0) * self._num_verts
else:
x = -self._anchor_x
y = -self._anchor_y
@ -1808,7 +1817,7 @@ class Polygon(ShapeBase):
def _update_vertices(self):
if not self._visible:
self._vertex_list.position[:] = tuple([0] * ((len(self._coordinates) - 2) * 6))
self._vertex_list.position[:] = (0, 0) * self._num_verts
else:
# Adjust all coordinates by the anchor.
trans_x, trans_y = self._coordinates[0]