Esempio n. 1
0
 def make_border(self):
     if self.drawBorder:
         if self.border is not None:
             self.border.delete()
         radius = min(self.width, self.height) / 2.0 - 20
         vertices = []
         for item in make_ellipse_vertices(radius * 2, radius * 2):
             vertices += item
         self.border = vertex_list(len(vertices) / 2, 
             ('v2f', vertices),
             ('c3B', self.color * (len(vertices) / 2)))
Esempio n. 2
0
 def make_border(self):
     if self.drawBorder:
         if self.border is not None:
             self.border.delete()
         radius = min(self.width, self.height) / 2.0 - 20
         vertices = []
         for item in make_ellipse_vertices(radius * 2, radius * 2):
             vertices += item
         self.border = vertex_list(
             len(vertices) / 2, ('v2f', vertices),
             ('c3B', self.color * (len(vertices) / 2)))
Esempio n. 3
0
    def initialize(self, loader, inverseGradient=False, color1=None, color2=None):
        self.loader = loader
        width = self.parent.width
        height = self.parent.height
        x1 = x2 = y1 = y2 = 0
        self.color1 = color1 or loader.color1
        self.color2 = color2 or loader.color2
        self.inverse_gradient = inverseGradient
        if loader.shape == LINE_SHAPE:
            if loader.lineFlags["InverseX"]:
                x1 += width
            else:
                x2 += width
            if loader.lineFlags["InverseY"]:
                y1 -= height
            else:
                y2 -= height

            self.vertex = graphics.vertex_list(2, ("v2f", (x1, y1, x2, y2)), ("c3B", (loader.borderColor * 2)))
        else:
            x2 += width
            y2 -= height
            if loader.fillType == MOTIF_FILL:
                texture = self.parent.make_image_handle(loader.image).create_texture(Texture)
                # texture = Texture(texture_copy.width, texture_copy.height,
                # texture_copy.target, texture_copy.id)
                texture.anchor_x = 0
                texture.anchor_y = texture.height
            if loader.shape in (RECTANGLE_SHAPE, ELLIPSE_SHAPE):
                if loader.fillType != NONE_FILL:
                    if loader.fillType == SOLID_FILL:
                        colors = (self.color1 + (255,)) * 4
                    elif loader.fillType == GRADIENT_FILL:
                        if inverseGradient:
                            color1 = self.color2 + (255,)
                            color2 = self.color1 + (255,)
                        else:
                            color1 = self.color1 + (255,)
                            color2 = self.color2 + (255,)
                        if loader.gradientFlags == VERTICAL_GRADIENT:
                            colors = color1 + color2 * 2 + color1
                        else:
                            colors = color1 * 2 + color2 * 2
                    if loader.fillType == MOTIF_FILL:
                        tex_width = texture.width
                        tex_height = texture.height
                        motif_batch = self.motif_batch = graphics.Batch()
                        motif_list = self.motif_list = []
                        for y in xrange(0, -height, -tex_height):
                            for x in xrange(0, width, tex_width):
                                motif_list.append(Sprite(texture, x=x, y=y, batch=motif_batch))
                        if loader.shape == RECTANGLE_SHAPE:
                            self.motif_stencil = graphics.vertex_list(4, ("v2f", (x1, y1, x1, y2, x2, y2, x2, y1)))
                    else:
                        self.vertex = graphics.vertex_list(
                            4, ("v2f", (x1, y1, x1, y2, x2, y2, x2, y1)), ("c4B", colors)
                        )
                if loader.shape == RECTANGLE_SHAPE and loader.borderSize > 0:
                    thickness = loader.borderSize
                    self.border = graphics.vertex_list(
                        16,
                        (
                            "v2i",
                            (
                                # top
                                0,
                                0,
                                width,
                                0,
                                width,
                                -thickness,
                                0,
                                -thickness,
                                # bottom
                                0,
                                -height + thickness,
                                width,
                                -height + thickness,
                                width,
                                -height,
                                0,
                                -height,
                                # left
                                0,
                                0,
                                thickness,
                                0,
                                thickness,
                                -height,
                                0,
                                -height,
                                # right
                                width,
                                0,
                                width - thickness,
                                0,
                                width - thickness,
                                -height,
                                width,
                                -height,
                            ),
                        ),
                        ("c4B", (loader.borderColor + (255,)) * 16),
                    )
            if loader.shape == ELLIPSE_SHAPE:
                vertices = make_ellipse_vertices(width, height)
                if loader.fillType != NONE_FILL:
                    fill_vertices = []
                    for i in xrange(len(vertices) - 1):
                        fill_vertices += vertices[i]
                        fill_vertices += vertices[i + 1]
                        fill_vertices += (width / 2, -height / 2)
                    self.stencil = graphics.vertex_list(len(fill_vertices) / 2, ("v2f", fill_vertices))
                if loader.borderSize > 0:
                    thickness = loader.borderSize
                    inner_vertices = make_ellipse_vertices(width - thickness * 2, height - thickness * 2)
                    border_vertices = []
                    for i in xrange(len(vertices) - 1):
                        border_vertices += vertices[i]
                        border_vertices += vertices[i + 1]
                        border_vertices += (
                            (inner_vertices[i + 1][0] + thickness),
                            (inner_vertices[i + 1][1] - thickness),
                        )
                        border_vertices += (inner_vertices[i][0] + thickness), (inner_vertices[i][1] - thickness)
                    colorTuple = loader.borderColor + (255,)
                    self.border = graphics.vertex_list(
                        len(border_vertices) / 2,
                        ("v2f", border_vertices),
                        ("c4B", colorTuple * (len(border_vertices) / 2)),
                    )
Esempio n. 4
0
    def initialize(self,
                   loader,
                   inverseGradient=False,
                   color1=None,
                   color2=None):
        self.loader = loader
        width = self.parent.width
        height = self.parent.height
        x1 = x2 = y1 = y2 = 0
        self.color1 = color1 or loader.color1
        self.color2 = color2 or loader.color2
        self.inverse_gradient = inverseGradient
        if loader.shape == LINE_SHAPE:
            if loader.lineFlags['InverseX']:
                x1 += width
            else:
                x2 += width
            if loader.lineFlags['InverseY']:
                y1 -= height
            else:
                y2 -= height

            self.vertex = graphics.vertex_list(2, ('v2f', (x1, y1, x2, y2)),
                                               ('c3B',
                                                (loader.borderColor * 2)))
        else:
            x2 += width
            y2 -= height
            if loader.fillType == MOTIF_FILL:
                texture = self.parent.make_image_handle(
                    loader.image).create_texture(Texture)
                # texture = Texture(texture_copy.width, texture_copy.height,
                # texture_copy.target, texture_copy.id)
                texture.anchor_x = 0
                texture.anchor_y = texture.height
            if loader.shape in (RECTANGLE_SHAPE, ELLIPSE_SHAPE):
                if loader.fillType != NONE_FILL:
                    if loader.fillType == SOLID_FILL:
                        colors = (self.color1 + (255, )) * 4
                    elif loader.fillType == GRADIENT_FILL:
                        if inverseGradient:
                            color1 = self.color2 + (255, )
                            color2 = self.color1 + (255, )
                        else:
                            color1 = self.color1 + (255, )
                            color2 = self.color2 + (255, )
                        if loader.gradientFlags == VERTICAL_GRADIENT:
                            colors = (color1 + color2 * 2 + color1)
                        else:
                            colors = color1 * 2 + color2 * 2
                    if loader.fillType == MOTIF_FILL:
                        tex_width = texture.width
                        tex_height = texture.height
                        motif_batch = self.motif_batch = graphics.Batch()
                        motif_list = self.motif_list = []
                        for y in xrange(0, -height, -tex_height):
                            for x in xrange(0, width, tex_width):
                                motif_list.append(
                                    Sprite(texture,
                                           x=x,
                                           y=y,
                                           batch=motif_batch))
                        if loader.shape == RECTANGLE_SHAPE:
                            self.motif_stencil = graphics.vertex_list(
                                4, ('v2f', (x1, y1, x1, y2, x2, y2, x2, y1)))
                    else:
                        self.vertex = graphics.vertex_list(
                            4, ('v2f', (x1, y1, x1, y2, x2, y2, x2, y1)),
                            ('c4B', colors))
                if loader.shape == RECTANGLE_SHAPE and loader.borderSize > 0:
                    thickness = loader.borderSize
                    self.border = graphics.vertex_list(
                        16,
                        (
                            'v2i',
                            (
                                # top
                                0,
                                0,
                                width,
                                0,
                                width,
                                -thickness,
                                0,
                                -thickness,
                                # bottom
                                0,
                                -height + thickness,
                                width,
                                -height + thickness,
                                width,
                                -height,
                                0,
                                -height,
                                # left
                                0,
                                0,
                                thickness,
                                0,
                                thickness,
                                -height,
                                0,
                                -height,
                                # right
                                width,
                                0,
                                width - thickness,
                                0,
                                width - thickness,
                                -height,
                                width,
                                -height,
                            )),
                        ('c4B', (loader.borderColor + (255, )) * 16))
            if loader.shape == ELLIPSE_SHAPE:
                vertices = make_ellipse_vertices(width, height)
                if loader.fillType != NONE_FILL:
                    fill_vertices = []
                    for i in xrange(len(vertices) - 1):
                        fill_vertices += vertices[i]
                        fill_vertices += vertices[i + 1]
                        fill_vertices += (width / 2, -height / 2)
                    self.stencil = graphics.vertex_list(
                        len(fill_vertices) / 2, ('v2f', fill_vertices))
                if loader.borderSize > 0:
                    thickness = loader.borderSize
                    inner_vertices = make_ellipse_vertices(
                        width - thickness * 2, height - thickness * 2)
                    border_vertices = []
                    for i in xrange(len(vertices) - 1):
                        border_vertices += vertices[i]
                        border_vertices += vertices[i + 1]
                        border_vertices += (
                            inner_vertices[i + 1][0] +
                            thickness), (inner_vertices[i + 1][1] - thickness)
                        border_vertices += (inner_vertices[i][0] +
                                            thickness), (inner_vertices[i][1] -
                                                         thickness)
                    colorTuple = loader.borderColor + (255, )
                    self.border = graphics.vertex_list(
                        len(border_vertices) / 2, ('v2f', border_vertices),
                        ('c4B', colorTuple * (len(border_vertices) / 2)))