Exemple #1
0
    def draw(self, offset=(0, 0)):
        offset_x, offset_y = offset

        x1, y1 = self.x + offset_x, self.y + offset_y
        x2, y2 = x1 + sin(self.theta1) * self.l1 * self.scale, \
            y1 - cos(self.theta1) * self.l1 * self.scale
        x3, y3 = x2 + sin(self.theta2) * self.l2 * self.scale, \
            y2 - cos(self.theta2) * self.l2 * self.scale
        self.trace.extend([x3, y3])
        self.trace = self.trace[-5000:]

        verts1 = self.makeVertices(x2, y2, self.r1)
        verts2 = self.makeVertices(x3, y3, self.r2)

        trace_group = Group()
        arm_group = Group(trace_group)
        first_circle_group = Group(arm_group)
        second_circle_group = Group(arm_group)
        

        pyglet.gl.glLineWidth(4)
        batch = pyglet.graphics.Batch()
        batch.add(3, pyglet.gl.GL_LINE_STRIP, arm_group,
                  ('v2f', (x1, y1, x2, y2, x3, y3)),
                  )
        batch.add(self.res, pyglet.gl.GL_POLYGON, first_circle_group, ('v2f', verts1))
        batch.add(self.res, pyglet.gl.GL_POLYGON, second_circle_group, ('v2f', verts2))
        batch.add(len(self.trace)//2, pyglet.gl.GL_LINE_STRIP, trace_group, 
                  ('v2f', self.trace),
                  ('c3B', [255, 0, 0]*(len(self.trace)//2)),
                  )
        
        batch.draw()
Exemple #2
0
    def __init__(self, x, y, base, knob, edge=0, batch=None, group=None):
        super().__init__(x, y, base.width, knob.height)
        self._edge = edge
        self._base_img = base
        self._knob_img = knob
        self._half_knob_width = knob.width / 2
        self._half_knob_height = knob.height / 2
        self._knob_img.anchor_y = knob.height / 2

        self._min_knob_x = x + edge
        self._max_knob_x = x + base.width - knob.width - edge

        self._user_group = group
        bg_group = Group(order=0, parent=group)
        fg_group = Group(order=1, parent=group)
        self._base_spr = pyglet.sprite.Sprite(self._base_img,
                                              x,
                                              y,
                                              batch=batch,
                                              group=bg_group)
        self._knob_spr = pyglet.sprite.Sprite(self._knob_img,
                                              x + edge,
                                              y + base.height / 2,
                                              batch=batch,
                                              group=fg_group)

        self._value = 0
        self._in_update = False
Exemple #3
0
    def draw(self, offset=(0, 0)):
        offset_x, offset_y = offset

        x1, y1 = self.x + offset_x, self.y + offset_y
        x2, y2 = x1 + sin(self.theta) * (self.l + self.dl) * self.scale, \
                 y1 - cos(self.theta) * (self.l + self.dl) * self.scale
        self.trace.extend([x2, y2])
        self.trace = self.trace[-2500:]

        verts = self.makeVertices(x2, y2, self.r)

        trace_group = Group()
        arm_group = Group(trace_group)
        circle_group = Group(trace_group)

        pyglet.gl.glLineWidth(4)
        batch = pyglet.graphics.Batch()
        batch.add(
            2,
            pyglet.gl.GL_LINE_STRIP,
            arm_group,
            ('v2f', (x1, y1, x2, y2)),
        )
        batch.add(self.res, pyglet.gl.GL_POLYGON, circle_group, ('v2f', verts))
        batch.add(
            len(self.trace) // 2,
            pyglet.gl.GL_LINE_STRIP,
            trace_group,
            ('v2f', self.trace),
            ('c3B', [255, 0, 0] * (len(self.trace) // 2)),
        )
        batch.draw()
Exemple #4
0
def circle_arc(batch,
               x,
               y,
               r,
               resolution=100,
               color=(255, 255, 255, 255),
               percentage=1,
               angle=0,
               group=None):
    """Adds a vertex list representing a circumference arc to a batch.
    Keyword arguments:
    resolution -- number of lines to form the circle, if it would be full(see percentage) (default 100)
    color -- color of the lines (default (255, 255, 255) or white)
    percentage -- percentage of the circumference to be drawn, between 0 and 1, 1 meaning full (default 1)
    angle -- angle to start the arc, between 0 and 1, 0 meaning to start right, clockwise (default 0)
    group -- group to which the vertex group is added, None for new group (default None)"""
    if not group:
        group = Group()
    points = []
    colors = []
    points_count = int(resolution * percentage + 1)
    for i in range(points_count):
        points += [
            x + r * cos(i * 2 * pi / resolution + angle),
            y + r * sin(i * 2 * pi / resolution + angle)
        ]
        colors += [*color]
    return batch.add(points_count, GL_LINE_STRIP, group, ('v2f', points),
                     ('c4B', colors))
    def __init__(self, x, y, base, knob, edge=0, batch=None, group=None):
        """Create a slider.

        :Parameters:
            `x` : int
                X coordinate of the slider.
            `y` : int
                Y coordinate of the slider.
            `base` : `~pyglet.image.AbstractImage`
                Image to display as the background to the slider.
            `knob` : `~pyglet.image.AbstractImage`
                Knob that moves to show the position of the slider.
            `edge` : int
                Pixels from the maximum and minimum position of the slider,
                to the edge of the base image.
            `batch` : `~pyglet.graphics.Batch`
                Optional batch to add the slider to.
            `group` : `~pyglet.graphics.Group`
                Optional parent group of the slider.
        """
        super().__init__(x, y, base.width, knob.height)
        self._edge = edge
        self._base_img = base
        self._knob_img = knob
        self._half_knob_width = knob.width / 2
        self._half_knob_height = knob.height / 2
        self._knob_img.anchor_y = knob.height / 2

        self._min_knob_x = x + edge
        self._max_knob_x = x + base.width - knob.width - edge

        self._user_group = group
        bg_group = Group(order=0, parent=group)
        fg_group = Group(order=1, parent=group)
        self._base_spr = pyglet.sprite.Sprite(self._base_img,
                                              x,
                                              y,
                                              batch=batch,
                                              group=bg_group)
        self._knob_spr = pyglet.sprite.Sprite(self._knob_img,
                                              x + edge,
                                              y + base.height / 2,
                                              batch=batch,
                                              group=fg_group)

        self._value = 0
        self._in_update = False
    def circle(self, x, y, r, color):
        n = 8
        p_type = GL_TRIANGLE_FAN

        v_list = self.batch.add(n + 1, p_type, Group(), 'v2f', 'c3B')
        v_list.vertices = draw_circle(x, y, r, n)
        v_list.colors = multiply_arr(color, n + 1)
        return primitive(v_list, x, y, r, p_type)
Exemple #7
0
    def __init__(self,
                 text,
                 x,
                 y,
                 width,
                 color=(255, 255, 255, 255),
                 batch=None,
                 group=None):
        self._doc = pyglet.text.document.UnformattedDocument(text)
        self._doc.set_style(0, len(self._doc.text), dict(color=(0, 0, 0, 255)))
        font = self._doc.get_font()
        height = font.ascent - font.descent

        self._user_group = group
        bg_group = Group(order=0, parent=group)
        fg_group = Group(order=1, parent=group)

        # Rectangular outline with 2-pixel pad:
        p = 2
        self._outline = pyglet.shapes.Rectangle(x - p, y - p, width + p + p,
                                                height + p + p, color[:3],
                                                batch, bg_group)
        self._outline.opacity = color[3]

        # Text and Caret:
        self._layout = IncrementalTextLayout(self._doc,
                                             width,
                                             height,
                                             multiline=False,
                                             batch=batch,
                                             group=fg_group)
        self._layout.x = x
        self._layout.y = y
        self._caret = Caret(self._layout)
        self._caret.visible = False

        self._focus = False

        super().__init__(x, y, width, height)
    def __init__(self, memory_reader, actor_id, address, my_coords, raw_name):
        """
        Upon initialization of this class, we immediately initialize the
        DisplayObject parent class as well (to utilize common methods)

        We then set our class variables and perform all of our info collecting
        functions, like finding the actors base address and converting the
        "raw" name to a more readable name per our Mappings. We also create
        a circle and label and add it to our batch for display to the screen.

        All of this data represents a "Ship". If you want to add more, you will
        need to add another class variable under __init__ and in the update()
        function

        :param memory_reader: The SoT MemoryHelper Object we use to read memory
        :param address: The address in which the AActor begins
        :param my_coords: a dictionary of the local players coordinates
        :param raw_name: The raw actor name used to translate w/ mapping.py
        """
        # Initialize our super-class
        super().__init__(memory_reader)

        self.actor_id = actor_id
        self.address = address
        self.actor_root_comp_ptr = self._get_root_comp_address(address)
        self.my_coords = my_coords
        self.raw_name = raw_name

        # Generate our Ship's info
        self.name = ships.get(self.raw_name).get("Name")
        self.coords = self._coord_builder(self.actor_root_comp_ptr,
                                          COORD_OFFSET)
        self.distance = calculate_distance(self.coords, self.my_coords)

        self.screen_coords = object_to_screen(self.my_coords, self.coords)

        # All of our actual display information & rendering
        self.color = SHIP_COLOR
        self.group = Group()
        self.text_str = self._built_text_string()
        self.text_render = self._build_text_render()
        self.icon = self._build_circle_render()

        # Used to track if the display object needs to be removed
        self.to_delete = False
Exemple #9
0
def rectangle_line(batch,
                   x,
                   y,
                   width,
                   height,
                   color=(255, 255, 255, 255),
                   group=None):
    """Adds a vertex list representing rectangular perimeter to a batch.
    Keyword arguments:
    color -- color of the lines (default (255, 255, 255) or white)
    group -- group to which the vertex group is added, None for new group (default None)"""
    if not group:
        group = Group()
    points = [x, y, x + width, y, x + width, y + height, x, y + height, x, y]
    colors = []
    for i in range(5):
        colors += [*color]
    return batch.add(5, GL_LINE_STRIP, group, ('v2f', points), ('c4B', colors))
    def __init__(self,
                 x,
                 y,
                 pressed,
                 depressed,
                 hover=None,
                 batch=None,
                 group=None):
        """Create a push button.

        :Parameters:
            `x` : int
                X coordinate of the push button.
            `y` : int
                Y coordinate of the push button.
            `pressed` : `~pyglet.image.AbstractImage`
                Image to display when the button is pressed.
            `depresseed` : `~pyglet.image.AbstractImage`
                Image to display when the button isn't pressed.
            `hover` : `~pyglet.image.AbstractImage`
                Image to display when the button is being hovered over.
            `batch` : `~pyglet.graphics.Batch`
                Optional batch to add the push button to.
            `group` : `~pyglet.graphics.Group`
                Optional parent group of the push button.
        """
        super().__init__(x, y, depressed.width, depressed.height)
        self._pressed_img = pressed
        self._depressed_img = depressed
        self._hover_img = hover or depressed

        # TODO: add `draw` method or make Batch required.
        self._batch = batch or pyglet.graphics.Batch()
        self._user_group = group
        bg_group = Group(order=0, parent=group)
        self._sprite = pyglet.sprite.Sprite(self._depressed_img,
                                            x,
                                            y,
                                            batch=batch,
                                            group=bg_group)

        self._pressed = False
Exemple #11
0
def rectangle_filled_vertgrad(batch,
                              x,
                              y,
                              width,
                              height,
                              color_top=(255, 255, 255, 255),
                              color_bot=(0, 0, 0, 0),
                              group=None):
    """Adds a vertex list representing a filled rectangle perimeter to a batch.
    Keyword arguments:
    color -- color of the lines (default (255, 255, 255) or white)
    group -- group to which the vertex group is added, None for new group (default None)"""
    if not group:
        group = Group()
    points = [x, y, x + width, y, x + width, y + height, x, y + height, x, y]
    colors = []
    for i in range(5):
        colors += [*color]
    return batch.add(5, GL_TRIANGLE_FAN, group, ('v2f', points),
                     ('c4B', colors))
Exemple #12
0
    def __init__(self,
                 x,
                 y,
                 pressed,
                 depressed,
                 hover=None,
                 batch=None,
                 group=None):
        super().__init__(x, y, depressed.width, depressed.height)
        self._pressed_img = pressed
        self._depressed_img = depressed
        self._hover_img = hover or depressed

        # TODO: add `draw` method or make Batch required.
        self._batch = batch or pyglet.graphics.Batch()
        self._user_group = group
        bg_group = Group(order=0, parent=group)
        self._sprite = pyglet.sprite.Sprite(self._depressed_img,
                                            x,
                                            y,
                                            batch=batch,
                                            group=bg_group)

        self._pressed = False
Exemple #13
0
 def update_groups(self, order):
     self._base_spr.group = Group(order=order + 1, parent=self._user_group)
     self._knob_spr.group = Group(order=order + 2, parent=self._user_group)
Exemple #14
0
 def update_groups(self, order):
     self._sprite.group = Group(order=order + 1, parent=self._user_group)
Exemple #15
0
 def __init__(self, parent=None):
     Group.__init__(self, parent)
    def __init__(self,
                 text,
                 x,
                 y,
                 width,
                 color=(255, 255, 255, 255),
                 text_color=(0, 0, 0, 255),
                 caret_color=(0, 0, 0),
                 batch=None,
                 group=None):
        """Create a text entry widget.

        :Parameters:
            `text` : str
                Initial text to display.
            `x` : int
                X coordinate of the text entry widget.
            `y` : int
                Y coordinate of the text entry widget.
            `width` : int
                The width of the text entry widget.
            `color` : (int, int, int, int)
                The color of the outline box in RGBA format.
            `text_color` : (int, int, int, int)
                The color of the text in RGBA format.
            `text_color` : (int, int, int)
                The color of the caret in RGB format.
            `batch` : `~pyglet.graphics.Batch`
                Optional batch to add the text entry widget to.
            `group` : `~pyglet.graphics.Group`
                Optional parent group of text entry widget.
        """
        self._doc = pyglet.text.document.UnformattedDocument(text)
        self._doc.set_style(0, len(self._doc.text), dict(color=text_color))
        font = self._doc.get_font()
        height = font.ascent - font.descent

        self._user_group = group
        bg_group = Group(order=0, parent=group)
        fg_group = Group(order=1, parent=group)

        # Rectangular outline with 2-pixel pad:
        self._pad = p = 2
        self._outline = pyglet.shapes.Rectangle(x - p, y - p, width + p + p,
                                                height + p + p, color[:3],
                                                batch, bg_group)
        self._outline.opacity = color[3]

        # Text and Caret:
        self._layout = IncrementalTextLayout(self._doc,
                                             width,
                                             height,
                                             multiline=False,
                                             batch=batch,
                                             group=fg_group)
        self._layout.x = x
        self._layout.y = y
        self._caret = Caret(self._layout, color=caret_color)
        self._caret.visible = False

        self._focus = False

        super().__init__(x, y, width, height)
Exemple #17
0
 def update_groups(self, order):
     self._outline.group = Group(order=order + 1, parent=self._user_group)
     self._layout.group = Group(order=order + 2, parent=self._user_group)
Exemple #18
0
 def __init__(self, parent=None):
     Group.__init__(self, parent)