From 2ea2f5230863210a5e74cdd574889f48db98aca4 Mon Sep 17 00:00:00 2001 From: Mathieu Virbel Date: Wed, 19 Sep 2012 19:22:01 +0200 Subject: [PATCH] line: start to add width/cap/joint --- kivy/graphics/vertex_instructions.pyx | 133 +------------------------- 1 file changed, 2 insertions(+), 131 deletions(-) diff --git a/kivy/graphics/vertex_instructions.pyx b/kivy/graphics/vertex_instructions.pyx index 56eb818f1..0338f7afc 100644 --- a/kivy/graphics/vertex_instructions.pyx +++ b/kivy/graphics/vertex_instructions.pyx @@ -26,136 +26,7 @@ class GraphicException(Exception): '''Exception fired when a graphic error is fired. ''' -cdef class Line(VertexInstruction): - '''A 2d line. - - .. versionadded:: 1.0.8 - `dash_offset` and `dash_length` have been added - - :Parameters: - `points`: list - List of points in the format (x1, y1, x2, y2...) - `dash_length`: int - length of a segment (if dashed), default 1 - `dash_offset`: int - offset between the end of a segments and the begining of the - next one, default 0, changing this makes it dashed. - ''' - cdef list _points - cdef int _dash_offset, _dash_length - - def __init__(self, **kwargs): - VertexInstruction.__init__(self, **kwargs) - v = kwargs.get('points') - self.points = v if v is not None else [] - self.batch.set_mode('line_strip') - self._dash_length = kwargs.get('dash_length') or 1 - self._dash_offset = kwargs.get('dash_offset') or 0 - - cdef void build(self): - cdef int i, count = len(self.points) / 2 - cdef list p = self.points - cdef vertex_t *vertices = NULL - cdef unsigned short *indices = NULL - cdef float tex_x - cdef char *buf = NULL - cdef Texture texture = self.texture - - if count < 2: - self.batch.clear_data() - return - - if self._dash_offset != 0: - if texture is None or texture._width != \ - (self._dash_length + self._dash_offset) or \ - texture._height != 1: - - self.texture = texture = Texture.create( - size=(self._dash_length + self._dash_offset, 1)) - texture.wrap = 'repeat' - - # create a buffer to fill our texture - buf = malloc(4 * (self._dash_length + self._dash_offset)) - memset(buf, 255, self._dash_length * 4) - memset(buf + self._dash_length * 4, 0, self._dash_offset * 4) - p_str = PyString_FromStringAndSize(buf, (self._dash_length + self._dash_offset) * 4) - - self.texture.blit_buffer(p_str, colorfmt='rgba', bufferfmt='ubyte') - free(buf) - - elif texture is not None: - self.texture = None - - vertices = malloc(count * sizeof(vertex_t)) - if vertices == NULL: - raise MemoryError('vertices') - - indices = malloc(count * sizeof(unsigned short)) - if indices == NULL: - free(vertices) - raise MemoryError('indices') - - tex_x = 0 - for i in xrange(count): - if self._dash_offset != 0 and i > 0: - tex_x += sqrt( - pow(p[i * 2] - p[(i - 1) * 2], 2) + - pow(p[i * 2 + 1] - p[(i - 1) * 2 + 1], 2)) / ( - self._dash_length + self._dash_offset) - - vertices[i].s0 = tex_x - vertices[i].t0 = 0 - - vertices[i].x = p[i * 2] - vertices[i].y = p[i * 2 + 1] - indices[i] = i - - self.batch.set_data(vertices, count, indices, count) - - free(vertices) - free(indices) - - property points: - '''Property for getting/settings points of the line - - .. warning:: - - This will always reconstruct the whole graphics from the new points - list. It can be very CPU expensive. - ''' - def __get__(self): - return self._points - def __set__(self, points): - self._points = list(points) - self.flag_update() - - property dash_length: - '''Property for getting/setting the length of the dashes in the curve - - .. versionadded:: 1.0.8 - ''' - def __get__(self): - return self._dash_length - - def __set__(self, value): - if value < 0: - raise GraphicException('Invalid dash_length value, must be >= 0') - self._dash_length = value - self.flag_update() - - property dash_offset: - '''Property for getting/setting the offset between the dashes in the curve - - .. versionadded:: 1.0.8 - ''' - def __get__(self): - return self._dash_offset - - def __set__(self, value): - if value < 0: - raise GraphicException('Invalid dash_offset value, must be >= 0') - self._dash_offset = value - self.flag_update() +include "vertex_instructions_line.pxi" cdef class Bezier(VertexInstruction): @@ -903,7 +774,7 @@ cdef class BorderImage(Rectangle): hs[0], vs[1], ths[0], tvs[1], #v11 hs[1], vs[1], ths[1], tvs[1], #v12 hs[2], vs[1], ths[2], tvs[1], #v13 - hs[2], vs[2], ths[2], tvs[2], #v14 + hs[2], vs[2], ths[2], tvs[2], #v14 hs[1], vs[2], ths[1], tvs[2]] #v15 cdef unsigned short *indices = [