class Rectangle:
def __init__(self, x, y, width, height, color=(255, 255, 255, 255), batch=None, group=None):
self._x = x
self._y = y
self._size = [width, height]
self._color = color
self._batch = batch
self._group = group
self._vertex_list = batch.add(6, GL_TRIANGLES, group, 'v2f', 'c4B')
self._update_vertex_list()
def _update_vertex_list(self):
x = self._x
y = self._y
w, h = self._size
one = x, y
two = x + w, y
three = x + w, y + h
four = x, y + h
self._vertex_list.vertices[:] = one + two + three + three + one + four
self._vertex_list.colors[:] = self._color * 6
@property
def width(self):
return self._size[0]
@width.setter
def width(self, value):
self._size[0] = value
self._update_vertex_list()
@property
def height(self):
return self._size[1]
@height.setter
def height(self, value):
self._size[1] = value
self._update_vertex_list()