def _draw_name_label(name, position):
        screenpos = convert_3dcoor_to_screen(position)
        # set_2d_mode()
        name_text = text.Label(name,
                               font_size=18,
                               color=[0, 0, 0, 255],
                               x=screenpos[0],
                               y=screenpos[1],
                               anchor_x='center',
                               anchor_y='bottom')

        name_length = (name_text.content_width + 5) / 2
        graphics.vertex_list(
            4, ('v2f',
                (screenpos[0] - name_length, screenpos[1], screenpos[0] -
                 name_length, screenpos[1] + 25, screenpos[0] + name_length,
                 screenpos[1] + 25, screenpos[0] + name_length, screenpos[1])),
            ('c3B', (200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200,
                     200))).draw(GL_QUADS)
        graphics.vertex_list(
            4, ('v2f',
                (screenpos[0] - name_length, screenpos[1], screenpos[0] -
                 name_length, screenpos[1] + 25, screenpos[0] + name_length,
                 screenpos[1] + 25, screenpos[0] + name_length, screenpos[1])),
            ('c3B', (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))).draw(GL_LINE_LOOP)
        name_text.draw()
Exemplo n.º 2
0
    def __init__(self, rectangle, color=(0, 0, 0), batch=None):
        """Creates a new cross box graphic.

        Args:
            rectangle (:obj:`engine.geometry.Rectangle`):
                Rectangular area to render the cross box around.

        Kwargs:
            color (tuple of 3 int, optional):
                An rgb tuple of the color to draw with. Defaults to black.
            batch (:obj:`engine.graphics.GraphicsBatch`, optional):
                The batch to render this graphic with. Defaults to None.
        """
        super(CrossBox, self).__init__()
        self._x, self._y = rectangle.x, rectangle.y

        gl_vertices = ('v2i', self._get_vertices(rectangle))
        gl_colors = ('c3B', color * self.VERTEX_COUNT)

        if batch:
            self._graphic = batch.add(
                self.VERTEX_COUNT, GL_LINES, None, gl_vertices, gl_colors)
        else:
            self._graphic = vertex_list(
                self.VERTEX_COUNT, gl_vertices, gl_colors)
Exemplo n.º 3
0
def raster():
    xy = ()
    for x in range(0, 100):
        xy += (x * 10, rnd(90, 110))
    vertices = gfx.vertex_list(
        len(xy) / 2, ('v2i', xy), ('c3B', (0, 0, 255) * (len(xy) / 2)))
    return vertices
Exemplo n.º 4
0
 def prepare_shape(self, s):
     if isinstance(s, Rectangle):
         s.vertex_list = graphics.vertex_list(
             4, ('v2i', (0, 0, s.width, 0, s.width, s.height, 0, s.height)))
         s.gl_type = gl.GL_QUADS
     elif isinstance(s, Trapezium):
         a = s.height / 4
         b = a * 3
         s.vertex_list = graphics.vertex_list(
             4, ('v2i', (0, 0, s.width, a, s.width, b, 0, s.height)))
         s.gl_type = gl.GL_QUADS
     # TODO Ellipsoid
     else:
         s.vertex_list = graphics.vertex_list(
             4, ('v2i', (0, 0, 50, 0, 50, 50, 0, 50)))
         s.gl_type = gl.GL_QUADS
Exemplo n.º 5
0
 def update_lists(self, rect, fill):
     width = self.width
     height = self.height
     buttonType = self.buttonType
     
     if buttonType in (CHECKBOX_BUTTON, RADIO_BUTTON):
         if self.vertex is None and not self.flags['Transparent']:
             self.vertex = graphics.vertex_list(4,
                 ('v2i',
                     (0, 0, width, 0, width, -height, 0, -height)
                 ),
                 ('c3B',
                     (self.backColor * 4)
                 )
             )
         
     elif buttonType in (PUSHTEXT_BUTTON, PUSHTEXTBITMAP_BUTTON):
         if not self.enabled[0]:
             rect = DISABLED_RECT
             fill = DISABLED_FILL
         if rect == self.rect and fill == self.fill:
             return
         self.rect = rect
         self.fill = fill
         if self.vertex is None:
             self.vertex = create_box_vertex(self.width, self.height,
                 BUTTON_BORDER, rect, fill)
         else:
             change_box_color(self.vertex, rect, fill)
Exemplo n.º 6
0
 def vertex_list(self) -> VertexList:
     flat_coords = []
     flat_colors = []
     for point in self:
         flat_coords.extend([point.x, point.y])
         flat_colors.extend(point.color.to_list())
     return vertex_list(len(self), ('v2f', tuple(flat_coords)),
                        ('c3B', tuple(flat_colors)))
Exemplo n.º 7
0
 def set_offset(self, top, bottom, left, right):
     if not any((top, bottom, left, right)):
         self.counter_stencil = None
         return
     height, width = self.parent.height, self.parent.width
     self.counter_stencil = graphics.vertex_list(
         4, ('v2f', (left, -top, left, -height + bottom, width - right,
                     -height + bottom, width - right, -top)))
Exemplo n.º 8
0
 def get_vertexlist(self):
     if self.vertex_list is None:
         flatverts = self.get_flat_verts()
         numverts = len(flatverts) / 2
         self.vertex_list = vertex_list(
             numverts, ('v2f/static', flatverts),
             ('c3B/static', self.color * numverts))
     return self.vertex_list
Exemplo n.º 9
0
 def get_vertexlist(self):
     if self.vertex_list is None:
         flatverts = self.get_flat_verts()
         numverts = len(flatverts) / 2
         self.vertex_list = vertex_list(
             numverts, ('v2f/static', flatverts),
             ('c3B/static', self.color * numverts))
     return self.vertex_list
Exemplo n.º 10
0
 def set_offset(self, top, bottom, left, right):
     if not any((top, bottom, left, right)):
         self.counter_stencil = None
         return
     height, width = self.parent.height, self.parent.width
     self.counter_stencil = graphics.vertex_list(
         4, ("v2f", (left, -top, left, -height + bottom, width - right, -height + bottom, width - right, -top))
     )
Exemplo n.º 11
0
 def __init__(self, x, y, width, height, tex_coords):
     super(TexQuad, self).__init__()
     tex_coords = [t for i, t in enumerate(tex_coords) if (i+1) % 3]
     self.ver_list = graphics.vertex_list(
         4, ('0g2f',
             (x, y, x + width, y, x + width, y + height, x, y + height)),
            ('1g2f',
             tex_coords))
Exemplo n.º 12
0
def raster():
	xy=()
	for x in range(0,100):
		xy += (x*10, rnd(90,110))
	vertices = gfx.vertex_list(len(xy)/2,
				('v2i', xy),
				('c3B', (0, 0, 255)*(len(xy)/2)))
	return vertices
Exemplo n.º 13
0
def polygon(n, color, fill=True):
    if fill:
        if n not in psolid_memo:
            psolid_memo[n] = vertex_list(n * 3,
                                         ('v2f/static', solid_polygon(n)),
                                         ('c4f/stream', [1] * 4 * 3 * n))

        vlist = psolid_memo[n]
        vlist.colors = make_color(*color) * n * 3
        vlist.draw(gl.GL_TRIANGLES)
    else:
        if n not in pwired_memo:
            pwired_memo[n] = vertex_list(n, ('v2f/static', wired_polygon(n)),
                                         ('c4f/stream', [1] * 4 * n))

        vlist = pwired_memo[n]
        vlist.colors = make_color(*color) * n
        vlist.draw(gl.GL_LINE_LOOP)
Exemplo n.º 14
0
 def setup_crosshair(self):
     """Creates the crosshair in the middle of the screen.
     """
     width, height = self.get_size()
     size = 10
     x = width/2
     y = height/2
     self.crosshair = vertex_list(4, ('v2i', (x - size, y, x + size, y, x,
                                              y - size, x, y + size)))
 def draw_warning_sign(position):
     screenpos = convert_3dcoor_to_screen(position)
     screenpos[0] -= 18
     screenpos[1] += 36
     # draw in 2d
     # set_2d_mode()
     graphics.vertex_list(
         3, ('v2f', (screenpos[0], screenpos[1], screenpos[0] + 36,
                     screenpos[1], screenpos[0] + 18, screenpos[1] + 36)),
         ('c3B',
          (255, 255, 0, 255, 255, 0, 255, 255, 0))).draw(GL_TRIANGLES)
     text.Label('!',
                font_size=18,
                color=[0, 0, 0, 255],
                x=screenpos[0] + 14,
                y=screenpos[1],
                anchor_x='left',
                anchor_y='bottom').draw()
Exemplo n.º 16
0
def polygon(n, color, fill=True):
    if fill:
        if n not in psolid_memo:
            psolid_memo[n] = vertex_list(n*3,
                                         ('v2f/static', solid_polygon(n)),
                                         ('c4f/stream', [1]*4 * 3*n))

        vlist = psolid_memo[n]
        vlist.colors = make_color(*color) * n*3
        vlist.draw(gl.GL_TRIANGLES)
    else:
        if n not in pwired_memo:
            pwired_memo[n] = vertex_list(n,
                                         ('v2f/static', wired_polygon(n)),
                                         ('c4f/stream', [1]*4 * n))

        vlist = pwired_memo[n]
        vlist.colors = make_color(*color) * n
        vlist.draw(gl.GL_LINE_LOOP)
Exemplo n.º 17
0
 def prepare_shape(self, s):
   if isinstance(s, Rectangle):
     s.vertex_list = graphics.vertex_list(4,
       ('v2i', (0, 0, s.width, 0, s.width, s.height, 0, s.height))
     )
     s.gl_type = gl.GL_QUADS
   elif isinstance(s, Trapezium):
     a = s.height / 4
     b = a * 3
     s.vertex_list = graphics.vertex_list(4,
       ('v2i', (0, 0, s.width, a, s.width, b, 0, s.height))
     )
     s.gl_type = gl.GL_QUADS
   # TODO Ellipsoid
   else:
     s.vertex_list = graphics.vertex_list(4,
       ('v2i', (0, 0, 50, 0, 50, 50, 0, 50))
     )
     s.gl_type = gl.GL_QUADS
Exemplo n.º 18
0
def create_box_vertex(width, height, border, rect, fill):
    fill1, fill2 = fill
    rect1, rect2 = rect
    return graphics.vertex_list(
        20,
        (
            'v2i',
            # fill
            (
                0,
                0,
                width,
                0,
                width,
                -height,
                0,
                -height,
                # outline
                # top
                0,
                0,
                width,
                0,
                width,
                -border,
                0,
                -border,
                # left
                0,
                0,
                border,
                0,
                border,
                -height,
                0,
                -height,
                # right
                width,
                0,
                width - border,
                0,
                width - border,
                -height,
                width,
                -height,
                # bottom
                0,
                -height,
                width,
                -height,
                width,
                border - height,
                0,
                border - height)),
        ('c3B', fill1 * 2 + fill2 * 2 + rect1 * 4 + rect2 * 12))
Exemplo n.º 19
0
def quad(xy, wh, color=[255, 255, 255, 255], batch=None, group=0, blend=False):
    x, y = xy[0], xy[1]
    w, h = wh[0], wh[1]
    verts = ('v2i', (x, y, x + w, y, x + w, y + h, x, y + h))
    color = ('c4B', (color * 4))

    if batch == None: return pyGra.vertex_list(4, verts, color)
    if blend: group = CustomGroup(pyGra.OrderedGroup(group))
    else: group = genGroup(group)

    return batch.add(4, GL_QUADS, group, verts, color)
Exemplo n.º 20
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)))
Exemplo n.º 21
0
 def _create_vertex_list(self):
     if self._batch is None:
         self._vertex_list = graphics.vertex_list(4,
             'v2i/%s' % self._usage, 
             'c4B', ('t3f', self._texture.tex_coords))
     else:
         self._vertex_list = self._batch.add(4, GL_QUADS, self._group,
             'v2i/%s' % self._usage, 
             'c4B', ('t3f', self._texture.tex_coords))
     self._update_position()
     self._update_color()
Exemplo n.º 22
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)))
Exemplo n.º 23
0
 def _create_vertex_list(self):
     if self._batch is None:
         self._vertex_list = graphics.vertex_list(
             4, "v2i/%s" % self._usage, "c4B", ("t3f", self._texture.tex_coords)
         )
     else:
         self._vertex_list = self._batch.add(
             4, GL_QUADS, self._group, "v2i/%s" % self._usage, "c4B", ("t3f", self._texture.tex_coords)
         )
     self._update_position()
     self._update_color()
Exemplo n.º 24
0
 def _create_vertex_list(self):
     if self._batch is None:
         self._vertex_list = graphics.vertex_list(4,
             'v2f/%s' % self._usage, 
             'c4B', ('t3f', self._texture.tex_coords))
     else:
         self._vertex_list = self._batch.add(4, GL_QUADS, self._group,
             'v2f/%s' % self._usage, 
             'c4B', ('t3f', self._texture.tex_coords))
     self._update_position()
     self._update_color()
Exemplo n.º 25
0
    def __init__(self, x=0, y=0, rot=0., color=(255, 255, 255, 255)):
        self.x = x
        self.y = y
        self.rot = rot
        self.rot_velocity = 0. #150.0

        self.verts = [(-10, 0), (10, 0), (0, 150)]
        self.vertex_list = graphics.vertex_list(
                                len(self.verts),
                                ('v2f', list(it.chain(*self.verts))),
                                ('c4B', color * 3)
                                )
Exemplo n.º 26
0
 def draw(self):
     width = int(self.max_width * (self.pokemon.get_current_health() /
                                   float(self.pokemon.get_max_health())))
     vertex_list = graphics.vertex_list(4, 'v2f', 'c3b')
     full_bar = graphics.vertex_list(4, 'v2f', 'c3b')
     full_bar.vertices = [
         self.x, self.y, self.x + self.max_width, self.y,
         self.x + self.max_width, self.y + self.height, self.x,
         self.y + self.height
     ]
     full_bar.colors = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
     vertex_list.vertices = [
         self.x, self.y, self.x + width, self.y, self.x + width,
         self.y + self.height, self.x, self.y + self.height
     ]
     vertex_list.colors = (constants.HEALTH_BAR_COLOR +
                           constants.HEALTH_BAR_COLOR +
                           constants.HEALTH_BAR_COLOR +
                           constants.HEALTH_BAR_COLOR)
     full_bar.draw(gl.GL_QUADS)
     vertex_list.draw(gl.GL_QUADS)
Exemplo n.º 27
0
 def __init__(self, pos=[0, 0], size=10):
     super(CrossHair, self).__init__()
     self.pos = pos
     self.x = pos[0]
     self.y = pos[1]
     self.size = size
     self.cross = graphics.vertex_list(4,
                                      ('v2f/stream', (self.x - self.size,
                                       self.y, self.x + self.size, self.y,
                                       self.x, self.y - self.size,
                                       self.x, self.y + self.size)))
     self.drawable = True
Exemplo n.º 28
0
    def on_draw(self):
        self.clear()
        #3d mode
        # shapes
        glEnable(GL_DEPTH_TEST)

        glUseProgram(ShapeShader.shader)
        ShapeShader.use_color(self.GROUND_COLOR)
        graphics.vertex_list(
            4, ('v3f',
                (self.camPos[0] + 500.0, -0.1, self.camPos[2] + 500.0,
                 self.camPos[0] + 500.0, -0.1, self.camPos[2] - 500.0,
                 self.camPos[0] - 500.0, -0.1, self.camPos[2] - 500.0,
                 self.camPos[0] - 500.0, -0.1, self.camPos[2] + 500.0))).draw(
                     GL_QUADS)  #draw the ground

        if self.frame_counter < 5:
            undraw_detected = False
        elif self.frame_counter < 10:
            undraw_detected = True

        for gard in self.gardens:
            gard.draw_garden(undraw_detected=undraw_detected)

        ## objects
        glUseProgram(ObjectShader.shader)
        Mushroom.draw_all_shroom(undraw_detected=undraw_detected)
        Rock.draw_all_rock()

        #2d
        glDisable(GL_DEPTH_TEST)
        glUseProgram(0)
        # MushroomSquare.draw_all_warning_sign()
        MushroomSquare.draw_all_readable_names()
        MushroomSquare.draw_all_family_numbers()
        # Garden.draw_all_warning_sign()
        Garden.draw_all_readable_names()
        self.interface.draw()
Exemplo n.º 29
0
 def _create_vertex_list(self):
     if self._subpixel:
         vertex_format = 'v2f/%s' % self._usage
     else:
         vertex_format = 'v2i/%s' % self._usage
     if self._batch is None:
         self._vertex_list = graphics.vertex_list(
             4, vertex_format, 'c4f', ('t3f', self._texture.tex_coords))
     else:
         self._vertex_list = self._batch.add(
             4, GL_QUADS, self._group, vertex_format, 'c4f',
             ('t3f', self._texture.tex_coords))
     self._update_position()
     self._update_color()
Exemplo n.º 30
0
 def _create_vertex_list(self):
     if self._subpixel:
         vertex_format = 'v3f/%s' % self._usage
     else:
         vertex_format = 'v3i/%s' % self._usage
     if self._batch is None:
         self._vertex_list = graphics.vertex_list(4,
                                                  vertex_format,
                                                  'c4B', ('t3f', self._texture.tex_coords))
     else:
         self._vertex_list = self._batch.add(4, GL_QUADS, self._group,
                                             vertex_format,
                                             'c4B', ('t3f', self._texture.tex_coords))
     self._update_position()
     self._update_color()
Exemplo n.º 31
0
 def _create_vertex_list(self):
     # Slightly changed from the parent, in that it passes v3i instead of v2i
     # SAM GEEN HACK - SUBPIXEL FORMAT ADDED
     format = "i"
     if self._subpixel:
         format = "f"
     if self._batch is None:
         self._vertex_list = graphics.vertex_list(
             4, "v3" + format + "/%s" % self._usage, "c4B", ("t3f", self._texture.tex_coords)
         )
     else:
         self._vertex_list = self._batch.add(
             4, GL_QUADS, self._group, "v3" + format + "/%s" % self._usage, "c4B", ("t3f", self._texture.tex_coords)
         )
     self._update_position()
     self._update_color()
Exemplo n.º 32
0
 def _create_vertex_list(self):
     # Slightly changed from the parent, in that it passes v3i instead of v2i
     # SAM GEEN HACK - SUBPIXEL FORMAT ADDED
     format = 'i'
     if self._subpixel:
         format = 'f'
     if self._batch is None:
         self._vertex_list = graphics.vertex_list(4,
             'v3'+format+'/%s' % self._usage, 
             'c4B', ('t3f', self._texture.tex_coords))
     else:
         self._vertex_list = self._batch.add(4, GL_QUADS, self._group,
             'v3'+format+'/%s' % self._usage, 
             'c4B', ('t3f', self._texture.tex_coords))
     self._update_position()
     self._update_color()
Exemplo n.º 33
0
 def _create_vertex_list(self):
     # Slightly changed from the parent, in that it passes v3f instead of v2i
     if self._subpixel:
         vertex_format = 'v3f/%s' % self._usage
     else:
         vertex_format = 'v3i/%s' % self._usage
     if self._batch is None:
         self._vertex_list = graphics.vertex_list(4,
             vertex_format, 
             'c4B', ('t3f', self._texture.tex_coords))
     else:
         self._vertex_list = self._batch.add(4, GL_QUADS, self._group,
             vertex_format, 
             'c4B', ('t3f', self._texture.tex_coords))
     self._update_position()
     self._update_color()
Exemplo n.º 34
0
 def _create_vertex_list(self):
     # Slightly changed from the parent, in that it passes v3i instead of v2i
     # SAM GEEN HACK - SUBPIXEL FORMAT ADDED
     format = 'i'
     if self._subpixel:
         format = 'f'
     if self._batch is None:
         self._vertex_list = graphics.vertex_list(
             4, 'v3' + format + '/%s' % self._usage, 'c4B',
             ('t3f', self._texture.tex_coords))
     else:
         self._vertex_list = self._batch.add(
             4, GL_QUADS, self._group, 'v3' + format + '/%s' % self._usage,
             'c4B', ('t3f', self._texture.tex_coords))
     self._update_position()
     self._update_color()
Exemplo n.º 35
0
 def __init__(self, x, y, width, height, color=(255, 255, 255),
              isplayer=False, batch=None, **kwargs):
     super(Rect, self).__init__(x, y, width, height, color)
     if not batch:
         self.ver_list = graphics.vertex_list(4,
             ('v2f/stream', (x, y, x, y + height,
              x + width, y + height, x + width, y)),
             ('c3B', (self.color[0], self.color[1], self.color[2],
              self.color[0], self.color[1], self.color[2],
              self.color[0], self.color[1], self.color[2],
              self.color[0], self.color[1], self.color[2])))
     else:
         self.ver_list = batch.add(4, gl.GL_QUADS, None,
                                  ('v2f/stream', (x, y, x, y + height,
                                   x + width, y + height, x + width, y)),
                                  ('c3B', [self.color[0],
                                           self.color[1],
                                           self.color[2]] * 4))
     self.isplayer = isplayer
Exemplo n.º 36
0
def grid(xy, wh, rc, batch=None, group=0):
    verts = [  # Outter Box
        xy[0], xy[1], xy[0] + wh[0], xy[1], xy[0] + wh[0], xy[1],
        xy[0] + wh[0], xy[1] + wh[1], xy[0] + wh[0], xy[1] + wh[1], xy[0],
        xy[1] + wh[1], xy[0], xy[1] + wh[1], xy[0], xy[1]
    ]
    for i in range(1, rc[1]):  # Inner Horizontal Lines
        x = round(xy[0] + wh[0] / rc[1] * i)
        verts.extend([x, xy[1], x, xy[1] + wh[1]])
    for i in range(1, rc[0]):  # Inner Vertical Lines
        y = round(xy[1] + wh[1] / rc[0] * i)
        verts.extend([xy[0], y, xy[0] + wh[0], y])

    if batch:
        grid = batch.add(
            len(verts) // 2, GL_LINES, genGroup(group), ('v2i', verts))
    else:
        grid = pyGra.vertex_list(len(verts) // 2, ('v2i', verts))
    return grid
Exemplo n.º 37
0
 def __init__(self, x, y, dx, dy, length=0, batch=None, color=(255, 255, 0),
              **kwargs):
     super(DrawaAbleLine, self).__init__(x, y, dx, dy, length)
     if length == 0:
         self.length = 1000
     else:
         self.length = length
     if not batch:
         self.ver_list = graphics.vertex_list(2,
                                              ('v2f/stream', (x, y,
                                               x + dx * self.length,
                                               y + dy * self.length)),
                                              ('c3B', color * 2))
     else:
         self.ver_list = batch.add(2, gl.GL_LINES, None,
                                   ('v2f/stream', (x, y,
                                    x + self.unit.x * self.length,
                                    y + self.unit.y * self.length)),
                                   ('c3B', color * 2))
Exemplo n.º 38
0
 def __init__(self,
              width: int,
              height: int,
              n_candles: int,
              up_color=GREEN,
              down_color=RED):
     self.width = width - 50
     self.height = height
     half_candle_width = self.width / (n_candles * 3 - 1)
     candle_width = half_candle_width * 2
     self.candles = [Candle(candle_width) for _ in range(n_candles)]
     self.up_color = up_color
     self.down_color = down_color
     self.low_high = _LowHigh(n_candles)
     self.positions = [
         pos * half_candle_width * 3 for pos in range(n_candles)
     ]
     self.margin = vertex_list(
         4, ('v2i',
             (1, 0, 1, height - 1, width - 1, height - 1, width - 1, 0)),
         ('c3B', (0, 0, 0) * 4))
Exemplo n.º 39
0
def create_box_vertex(width, height, border, rect, fill):
    fill1, fill2 = fill
    rect1, rect2 = rect
    return graphics.vertex_list(20,
        ('v2i',
            # fill
            (0, 0, 
            width, 0,
            width, -height,
            0, -height,
            # outline
            # top
            0, 0,
            width, 0,
            width, -border,
            0, -border,
            # left
            0, 0,
            border, 0,
            border, -height,
            0, -height,
            # right
            width, 0,
            width - border, 0,
            width - border, -height,
            width, -height,
            # bottom
            0, -height,
            width, -height,
            width, border-height,
            0, border-height
            )
        ),
        ('c3B', 
            fill1 * 2 + fill2 * 2 + rect1 * 4 + rect2 * 12
        )
    )
Exemplo n.º 40
0
    def update_lists(self, rect, fill):
        width = self.width
        height = self.height
        buttonType = self.buttonType

        if buttonType in (CHECKBOX_BUTTON, RADIO_BUTTON):
            if self.vertex is None and not self.flags['Transparent']:
                self.vertex = graphics.vertex_list(
                    4, ('v2i', (0, 0, width, 0, width, -height, 0, -height)),
                    ('c3B', (self.backColor * 4)))

        elif buttonType in (PUSHTEXT_BUTTON, PUSHTEXTBITMAP_BUTTON):
            if not self.enabled[0]:
                rect = DISABLED_RECT
                fill = DISABLED_FILL
            if rect == self.rect and fill == self.fill:
                return
            self.rect = rect
            self.fill = fill
            if self.vertex is None:
                self.vertex = create_box_vertex(self.width, self.height,
                                                BUTTON_BORDER, rect, fill)
            else:
                change_box_color(self.vertex, rect, fill)
Exemplo n.º 41
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)))
Exemplo n.º 42
0
    vertex.colors = fill1 * 2 + fill2 * 2 + rect1 * 4 + rect2 * 12

CHECKBOX_VERTEX = create_box_vertex(12, 12, 1, 
    ((0xB7, 0xBA, 0xBC), (0x5E, 0x61, 0x62)),
    ((0xDB, 0xE1, 0xE5), (0x9E, 0xAB, 0xB2)))

CHECKBOX_OVER_VERTEX = create_box_vertex(12, 12, 1, 
    ((0x00, 0x9D, 0xFF), (0x00, 0x76, 0xC1)),
    ((0xE8, 0xED, 0xEF), (0xC7, 0xCF, 0xD2)))

CHECKBOX_DISABLED_VERTEX = create_box_vertex(12, 12, 1, 
    ((0x00, 0x9D, 0xFF), (0x00, 0x76, 0xC1)),
    ((0xE8, 0xED, 0xEF), (0xC7, 0xCF, 0xD2)))

CHECK_VERTEX = graphics.vertex_list(4,
        ('v2i', (10, -3, 5, -10, 5, -10, 3, -5)),
        ('c3B', (0, 0, 0) * 4))

class DefaultObject(ObjectPlayer):
    items = None
    fill = None
    rect = None
    vertex = None
    label = None
    labels = None
    batch = None
    values = None
    overBox = None
    enabled = None
    currentRadio = 0
    def created(self, data):
Exemplo n.º 43
0
 def vertices(self):
     points = tuple(dim for v in self.vectors
                    for dim in (*v.as_tuple, self.z))
     print(len(self.vectors))
     return graphics.vertex_list(len(self.vectors), ('v3f', points),
                                 ('c3B', self.colors))
Exemplo n.º 44
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)),
                    )
Exemplo n.º 45
0
import pyglet
from pyglet.graphics import vertex_list
from pyglet import gl
from pyglet.window import key

window = pyglet.window.Window(width=800, height=600, resizable=True)

fps_display = pyglet.clock.ClockDisplay()

num_points = 12
num_lines = 10
num_points = 12
num_lines = 12
epsilon = 0.01
lines = [[0 for i in range(num_points)] for i in range(num_lines)]
vlists = [vertex_list(num_points, 'v2f', 'c4B') for i in range(num_lines)]

for vlist in vlists:
    for i in range(len(vlist.colors)):
        vlist.colors[i] = 255

@window.event
def on_resize(w, h):
    print "on resize %d %d" % (w,h)

@window.event
def on_draw():
    window.clear()
    for vlist in vlists:
        vlist.draw(gl.GL_LINE_STRIP)
    fps_display.draw()
Exemplo n.º 46
0
CHECKBOX_VERTEX = create_box_vertex(12, 12, 1,
                                    ((0xB7, 0xBA, 0xBC), (0x5E, 0x61, 0x62)),
                                    ((0xDB, 0xE1, 0xE5), (0x9E, 0xAB, 0xB2)))

CHECKBOX_OVER_VERTEX = create_box_vertex(12, 12, 1, ((0x00, 0x9D, 0xFF),
                                                     (0x00, 0x76, 0xC1)),
                                         ((0xE8, 0xED, 0xEF),
                                          (0xC7, 0xCF, 0xD2)))

CHECKBOX_DISABLED_VERTEX = create_box_vertex(12, 12, 1, ((0x00, 0x9D, 0xFF),
                                                         (0x00, 0x76, 0xC1)),
                                             ((0xE8, 0xED, 0xEF),
                                              (0xC7, 0xCF, 0xD2)))

CHECK_VERTEX = graphics.vertex_list(4,
                                    ('v2i', (10, -3, 5, -10, 5, -10, 3, -5)),
                                    ('c3B', (0, 0, 0) * 4))


class DefaultObject(ObjectPlayer):
    items = None
    fill = None
    rect = None
    vertex = None
    label = None
    labels = None
    batch = None
    values = None
    overBox = None
    enabled = None
    currentRadio = 0
Exemplo n.º 47
0
    def _update(self, init=False):
        """
        Recalculates vertex list

        """
        x = self.x
        y = self.y
        w = self.w  #* self.factor
        h = self.h

        if self.text_f and not init:
            self.text.element.text = self.text_f(self.factor)


        OUTLINE_THICKNESS = 2

        tex = self._texes["unfilled"]#.get_image_data()#.get_data("RGBA", 4)
        #h = self.h = tex.height
        tw = w/tex.width
        th = h/tex.height #self.h/tex.width

        length_of_fill = self.w - self._texes["left"].width*2
        tx = x + self._texes["left"].width
        pw = w - self._texes["left"].width - self._texes["right"].width
        pw *= self.factor
        unw = w - self._texes["left"].width - self._texes["right"].width  # This is the same as pw, just not modified by factor (yes, needs some refactoring)

        _pos = (tx, y,
                     tx+pw, y,
                     tx+pw, y+h,
                     tx, y+h)
        _tex = (0,0, tw,0, tw,th, 0,th)

        fh = h - self._texes["fill_color_border"] * 2
        fy = y + self._texes["fill_color_border"]
        _fill_pos = (tx, fy,
                            tx+pw, fy,
                            tx+pw, fy+fh,
                            tx, fy+fh)
        _unfill_pos = (tx, y,
                         tx+unw, y,
                         tx+unw, y+h,
                         tx, y+h)

        th = OUTLINE_THICKNESS
        _outline_pos = (x - th, y - th,
                     x+w + th, y - th,
                     x+w + th, y+h + th,
                     x - th, y+h + th)


        #self.outline_vlist = graphics.vertex_list(4,
        #                                          ("v2f", _outline_pos),
        #                                          ("c3B", (0,)*3*4))


        self.unfill_vlist = graphics.vertex_list(4,
                                                ("v2f", _unfill_pos),
                                                ("t2f", _tex))

        self.vertex_list = graphics.vertex_list(4,
                                                ("v2f", _pos),
                                                ("t2f", _tex))

        self.fill_colour_vlist = graphics.vertex_list(4,
                                                         ("v2f", _fill_pos),
                                                         ("c3B", self.color))
Exemplo n.º 48
0
 def vertex_list(self) -> VertexList:
     return vertex_list(1, ('v2f', (self.x, self.y)),
                        ('c3B', self.color.to_tuple()))
Exemplo n.º 49
0
 def __init__(self, width):
     self.width = width
     self.body = vertex_list(4, 'v2f', 'c3B')
     self.low_high = vertex_list(2, 'v2f', 'c3B')
Exemplo n.º 50
0
    def on_draw(self):
         
        glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA)

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        glLoadIdentity()
        
        glTranslate(self.translatex, self.translatey, self.depth)
        
        if self.autoRun:
            glRotate(self.rotx,  0, 1, 0)
        
        else:
            # Perform arcball rotation.
            glScale(1,-1,1)
            glMultMatrixf(self.arcball.transform)
            glScale(1,-1,1)
        
        with displayListify("cubeTranslate") as shouldLeave:
            if shouldLeave: raise LeaveWith
                
            # Scale the co-ordinates so that they are correct
            glScale(2/128, 2/128, 2/128)
            
            glColor(0.25, 0.25, 0.25, 1)
            glutWireCube(255)
            
            glTranslate(-128, -128, -128)
        
        with displayListify("allPoints") as shouldLeave:
            if shouldLeave: raise LeaveWith
            
            with SaveMatrix():
                # Flip the co-ordinates and translate upwards
                glScale(1,-1,1)
                glColor(0.25, 0.25, 0.25, 0.5)
                glTranslate(0,-255,0)
                glPointSize(pointSize)
                for dat in reversed(vLists):
                    glTranslate(0., 0., 1./nChunks*255)
                    dat.draw(GL_POINTS)

        with displayListify("axisLabels") as shouldLeave:
            if shouldLeave: raise LeaveWith
        #if True:
            with SaveMatrix():
                glTranslate(128,0,0)
                self.makeLabel("End").draw()
                
                glTranslate(0,0,255)
                self.makeLabel("Beginning").draw()
                
                with SaveMatrix():
                    glTranslate(-128,128,0)
                    glRotate(90,0,0,1)
                    self.makeLabel("Byte 1").draw()
                
                glTranslate(0,255,0)
                self.makeLabel("Byte 2").draw()
        
        with displayListify("fileName") as shouldLeave:
            if shouldLeave: raise LeaveWith
            glLoadIdentity()
            
            with SaveMatrix():
                glColor(1,0,0)
                glTranslate(0,-2.2,-4)
                glScale(1/64, 1/64, 1/64)
                l = self.makeLabel(basename(currentInputFile))
                l.color = (0, 128, 230, 255)
                l.draw()
        
        glTranslate(0,0,-1)
        
        if self.autoRun:
        
            if self.rotx > 360 - 45:
                vlist = vertex_list(4, ('v2i', (-1, -1, 1, -1, 1, 1, -1, 1)))
                glColor(0,0,0,(self.rotx-(360-45))/45)
                vlist.draw(GL_QUADS)
                
            if self.rotx < 45:
                vlist = vertex_list(4, ('v2i', (-1, -1, 1, -1, 1, 1, -1, 1)))
                glColor(0,0,0,1-(self.rotx/45))
                vlist.draw(GL_QUADS)