Пример #1
0
    def __init__(self, pos, color, angle):
        super(Note, self).__init__()
        self.pos = np.array(pos, dtype=np.float)

        self.pos[0] += 25
        self.pos[1] += 10

        self.color = Color(*color)
        self.add(self.color)
        # adds a translation and rotation and another translation to the note
        self.add(PushMatrix())

        self.translate = Translate(*self.pos)
        self.add(self.translate)

        self._angle = Rotate(angle=angle)
        self.add(self._angle)

        self.translate2 = Translate(0, 40)
        self.add(self.translate2)

        self.note = Rectangle(texture=Image("particle/texture.png").texture,
                              pos=(-15, -15),
                              size=(30, 30))

        self.add(self.note)

        self.add(PopMatrix())

        self.vel = np.array((0, 60), dtype=np.float)

        self.color.a = 1
Пример #2
0
    def draw_ticks(self):
        scangle = self.angle_stop - self.angle_start
        inc = scangle / (
            (self.scale_max - self.scale_min) / self.scale_increment)
        inc /= self.tic_frequency
        cnt = 0

        # create an instruction group so we can remove it and recall draw_ticks to update when pos or size changes
        self.ticks = InstructionGroup()

        self.ticks.add(Color(*self.tic_color))

        labi = self.scale_min
        x = -180.0 + self.angle_start + self.angle_offset  # start
        while x <= self.angle_stop - 180 + self.angle_offset:
            a = x if (x < 0.0) else x + 360.0

            need_label = True
            ticlen = self.tic_length

            if (cnt % self.tic_frequency != 0):
                ticlen = self.tic_length / 2
                need_label = False

            cnt += 1

            self.ticks.add(PushMatrix())
            self.ticks.add(
                Rotate(angle=a,
                       axis=(0, 0, -1),
                       origin=(self.dial_center[0], self.dial_center[1])))
            self.ticks.add(Translate(0, self.tic_radius - ticlen))
            self.ticks.add(
                Line(points=[
                    self.dial_center[0], self.dial_center[1],
                    self.dial_center[0], self.dial_center[1] + ticlen
                ],
                     width=self.tic_width,
                     cap='none',
                     joint='none'))

            if need_label:
                #print("label: " + str(labi))
                #kw['font_size'] = self.tic_length * 2
                label = CoreLabel(text=str(int(round(labi))),
                                  font_size=self.scale_font_size)
                label.refresh()
                texture = label.texture
                self.ticks.add(
                    Translate(-texture.size[0] / 2, -texture.size[1] - 2))
                self.ticks.add(
                    Rectangle(texture=texture,
                              pos=self.dial_center,
                              size=texture.size))
                labi += self.scale_increment

            self.ticks.add(PopMatrix())
            x += inc

        self.canvas.add(self.ticks)
Пример #3
0
    def __init__(self, **kwargs):
        super(LinearGauge, self).__init__(**kwargs)
        # these values match the actual dimensions of the referenced graphic assets
        self.gauge_width = 2000
        self.gauge_height = 500
        x = self.pos[0]
        y = self.pos[1]

        scale_x = self.width / self.gauge_width
        scale_y = self.height / self.gauge_height

        with self.canvas:
            PushMatrix()
            self.dial_color = Color(rgba=self.color)
            self.gauge_translate = Translate(x, y, 0)
            self.gauge_scale = Scale(x=scale_x, y=scale_y)
            Rectangle(source='resource/gauge/horizontal_bar_gauge.png', pos=self.pos, size=(self.gauge_width, self.gauge_height))
            PopMatrix()
            PushMatrix()
            self.mask_translate = Translate(x, y, 0)
            self.mask_scale = Scale(x=scale_x, y=scale_y)
            Rectangle(source='resource/gauge/horizontal_bar_gauge_mask.png', pos=self.pos, size=(self.gauge_width, self.gauge_height))
            PopMatrix()

        with self.canvas.after:
            PushMatrix()
            Color(1, 1, 1, 1)
            self.shadow_translate = Translate(x, y, 0)
            self.shadow_scale = Scale(x=scale_x, y=scale_y)
            Rectangle(source='resource/gauge/horizontal_bar_gauge_shadow.png', pos=self.pos, size=(self.gauge_width, self.gauge_height))
            PopMatrix()

        self.bind(pos=self.update_all, size=self.update_all)
Пример #4
0
    def add_teeth(self, center, num_teeth):
        for tooth in self.teeth:
            self.remove(tooth)

        self.teeth = []
        self.add(self.color)
        self.add(PushMatrix())
        self.add(Translate(center))

        # use this Rotate to animate rotation for the whole flower
        self.rot = Rotate(angle=0, origin=self.storage_pos)
        self.add(self.rot)

        # make petals ellipses with these width and height:
        self.middle_size = self.size / 2
        w = self.size / 5
        h = self.size / 5

        # how much to rotate each petal.
        d_theta = 360. / num_teeth

        for n in range(num_teeth):
            self.add(Rotate(angle=d_theta, origin=center))
            self.add(Translate(self.middle_size, 0))
            rect = CRectangle(cpos=center, csize=(h, w))
            self.teeth.append(rect)
            self.add(rect)
            self.add(Translate(-self.middle_size, 0))

        self.add(PopMatrix())
Пример #5
0
    def __init__(self, speed):
        super(ParallaxLayer, self).__init__()
        self.speed = speed
        self.translator = Translate(0, 0)
        self.add(self.translator)

        self.objects = InstructionGroup()
        self.add(self.objects)

        self.rev_translator = Translate(0, 0)
        self.add(self.rev_translator)
Пример #6
0
def draw_tile(tile, rotated = False):
	if rotated:
		Rotate(90, 0, 0, 1)
		# no idea why pos isn't 80 or 120
		Rectangle(pos=(0,-100), size=(80, 95),
				source=tilelist[tile / 4])
		Rotate(-90, 0, 0, 1)
		Translate(120, 0, 0)
	else:
		Rectangle(pos=(0,0), size=(80, 95),
			source=tilelist[tile / 4])
		Translate(80, 0, 0)
Пример #7
0
    def happen(self):
        super().happen()
        self.slug.shooting = True
        self.slug.eye_animation.cancel(self.slug)
        self.slug.rot_angle = 0

        with self.slug.left_eye.canvas.before:
            self.slug.translation_left = Translate(x=0)

        with self.slug.right_eye.canvas.before:
            self.slug.translation_right = Translate(x=0)

        self.shoot_event = Clock.schedule_interval(self.move_eyes, 1 / 60)
Пример #8
0
    def __init__(self, foreground, background):
        super(Camera, self).__init__()

        self.background = background
        self.add(background)

        self.translator = Translate(0, 0)
        self.add(self.translator)

        self.add(foreground)

        self.rev_translator = Translate(0, 0)
        self.add(self.rev_translator)
Пример #9
0
 def reinit_before(self, base_angle=None):
     """Initialize the “before” canvas, i.e., whatever's below the MazeBoard
     """
     cell_size = self.board.cell_size
     if base_angle is None:
         base_angle = 180 if self.current_solver else 0
     self.canvas.before.clear()
     with self.canvas.before:
         for player, rotation in enumerate((90, 270)):
             # Win/lose messages at end of game
             if self.round_number < NUM_ROUNDS:
                 text = ''
             elif player ^ (self.times[0] < self.times[1]):
                 text = 'Winner!'
             else:
                 text = 'Second place'
             PushMatrix()
             Translate(
                 self.board.window_width / 2,
                 self.board.window_height / 2,
                 0,
             )
             Rotate(rotation, 0, 0, 1)
             l = Label(
                 text=text,
                 pos=(
                     -self.board.window_height / 2,
                     -self.board.window_width / 2 + cell_size,
                 ),
                 size=(self.board.window_height, cell_size * 4),
                 bold=True,
                 font_size=cell_size * 2,
                 color=(1, 1, 0),
             )
             PopMatrix()
         PushMatrix()
         Translate(
             self.board.window_width / 2,
             self.board.window_height / 2,
             0,
         )
         # Instructions for animating the board
         self.scale_instruction = Scale(1)
         self.rotate_instruction = Rotate(base_angle, 0, 0, 1)
         Translate(
             -self.board.window_width / 2,
             -self.board.window_height / 2,
             0,
         )
Пример #10
0
 def draw_quad(self, star_list):
     star_tex = Image('star1.png').texture
    
     with self.canvas:
         for star in star_list:
             size = .5*star[2]
             PushMatrix()
             t = Translate()
             r = Rotate()
             r.angle = star[3]
             Quad(texture = star_tex, points = (-size, 
                 -size, size, -size,
                 size, size, -size, size))
             t.xy = star[0], star[1]
             PopMatrix()
Пример #11
0
    def draw_quad(self, star_list):
        star_tex = Image('star1.png').texture

        with self.canvas:
            for star in star_list:
                size = .5 * star[2]
                PushMatrix()
                t = Translate()
                r = Rotate()
                r.angle = star[3]
                Quad(texture=star_tex,
                     points=(-size, -size, size, -size, size, size, -size,
                             size))
                t.xy = star[0], star[1]
                PopMatrix()
Пример #12
0
    def __init__(self, norm, pos, tempo, clock, tempo_map, touch_points,
                 block_handler):
        super(TempoCursor, self).__init__()
        self.norm = norm
        self.pos = pos
        self.size = self.norm.nt((70, 70))

        self.cursor = CEllipse(cpos=pos, csize=self.size)
        self.add(Color(1, 1, 1))
        self.add(self.cursor)

        self.tempo = tempo
        self.clock = clock
        self.tempo_map = tempo_map
        self.sched = Scheduler(self.clock, self.tempo_map)

        self.block_handler = block_handler

        # 0..15, for 16th note granularity
        self.touch_points = touch_points
        self.index = 0

        # add touch markers
        self.add(PushMatrix())
        self.add(Translate(*pos))
        for touch_point in self.touch_points:
            self.add(Rotate(angle=-360 * touch_point / 16))
            self.add(Color(159 / 255, 187 / 255, 208 / 255))  # blue
            self.add(Line(points=(0, 0, 0, self.norm.nv(25)), width=2))
            self.add(Rotate(angle=360 * touch_point / 16))
        self.add(PopMatrix())

        # add current time marker
        self.add(PushMatrix())
        self.add(Translate(*pos))
        self.time_marker = Line(points=(0, 0, 0, self.norm.nv(30)), width=3)
        self.rotate = Rotate(angle=0)
        self.add(self.rotate)
        self.add(Color(0, 0, 0))
        self.add(self.time_marker)
        self.add(PopMatrix())

        self.on_update(0)

        cur_tick = self.sched.get_tick()
        next_tick = quantize_tick_up(cur_tick, kTicksPerQuarter * 4)
        next_tick += self.calculate_tick_interval(0, self.touch_points[0])
        self.sched.post_at_tick(self.touch_down, next_tick)
Пример #13
0
    def get_root_pixels(self):
        """Returns all the pixels values of the widget containing the shapes,
        as well as the size of that widget.

        This is how you can save an image of whatever is currently displayed on
        screen.
        """
        widget = self.root.ids.display_canvas

        canvas_parent_index = widget.parent.canvas.indexof(widget.canvas)
        if canvas_parent_index > -1:
            widget.parent.canvas.remove(widget.canvas)

        fbo = Fbo(size=widget.size, with_stencilbuffer=True)

        with fbo:
            ClearColor(0, 0, 0, 1)
            ClearBuffers()
            Scale(1, -1, 1)
            Translate(0, -widget.height, 0)

        fbo.add(widget.canvas)
        fbo.draw()
        pixels = fbo.pixels
        fbo.remove(widget.canvas)

        if canvas_parent_index > -1:
            widget.parent.canvas.insert(canvas_parent_index, widget.canvas)
        return pixels, widget.size
Пример #14
0
    def create_instructions(self):
        margin = self.grid.tile_side_len // 2
        self.instructions_window_color = Color(rgba=(1, 1, 1, 1))
        self.instructions_window = Rectangle(
            pos=(margin, margin),
            size=(
                self.grid.grid_side_len - 2 * margin -
                2 * self.grid.tile_side_len,
                3 * self.grid.tile_side_len - 2 * margin,
            ),
        )
        self.instructions_text_color = Color(rgba=(0, 0, 0, 1))
        self.instructions_text = CLabelRect(
            (self.win_size[0] // 2, self.win_size[1] // 4.3),
            "Move around the room with the arrow keys\n" +
            "Press 'a' to interact with objects",
            34,
        )

        self.add(PushMatrix())
        self.add(Translate(*self.grid.pos))

        self.add(self.instructions_window_color)
        self.add(self.instructions_window)

        self.add(PopMatrix())

        self.add(self.instructions_text_color)
        self.add(self.instructions_text)
Пример #15
0
    def on_linecolor(self, *args):
        """If I don't yet have the instructions for drawing the selection box
        in my canvas, put them there. In any case, set the
        :class:`Color` instruction to match my current ``linecolor``.

        """
        if hasattr(self, 'color'):
            self.color.rgba = self.linecolor
            return

        def upd_box_translate(*args):
            self.box_translate.xy = self.pos

        def upd_box_points(*args):
            self.box.points = [
                0, 0, self.width, 0, self.width, self.height, 0, self.height,
                0, 0
            ]

        self.boxgrp = boxgrp = InstructionGroup()
        self.color = Color(*self.linecolor)
        self.box_translate = Translate(*self.pos)
        boxgrp.add(PushMatrix())
        boxgrp.add(self.box_translate)
        boxgrp.add(self.color)
        self.box = Line()
        upd_box_points()
        self.bind(size=upd_box_points, pos=upd_box_translate)
        boxgrp.add(self.box)
        boxgrp.add(Color(1., 1., 1.))
        boxgrp.add(PopMatrix())
Пример #16
0
    def move_block(self, new_location, x, y):
        obj_loc = (new_location[0] + x, new_location[1] + y)

        if self.is_valid_pos(obj_loc) and self.valid_block_move(
                obj_loc, self.objects[new_location].move_range):
            self.remove(self.objects[new_location])
            obj = MovingBlock(
                self.objects[new_location].size,
                self.grid.grid_to_pixel(obj_loc),
                self.objects[new_location].move_range,
                self.objects[new_location].color,
                self.objects[new_location].icon_source,
                self.objects[new_location].final_position,
            )
            del self.objects[new_location]

            self.add(PushMatrix())
            self.add(Translate(*self.grid.pos))
            self.add(obj)
            self.add(PopMatrix())

            self.objects[obj_loc] = obj
            self.blocks_placed += self.objects[obj_loc].on_block_placement(
                obj_loc)
            return True
        else:
            return False
Пример #17
0
    def bitmap(self):
        # self.export_to_png('test.png')

        # remove cross
        self.canvas.after.clear()

        image_scale = 36 / self.width

        fbo = Fbo(size=(36, 27), with_stencilbuffer=True)

        with fbo:
            ClearColor(0, 0, 0, 0)
            ClearBuffers()
            Scale(image_scale, -image_scale, image_scale)
            Translate(-self.x, -self.y - self.height, 0)

        fbo.add(self.canvas)
        fbo.draw()
        # fbo.texture.save('test_small.png', flipped=False)
        bm = np.fromstring(fbo.pixels, dtype=np.uint8).reshape(fbo.size[1], fbo.size[0], 4)
        fbo.remove(self.canvas)

        # return cross
        self.add_cross()

        return np.int64(np.all(bm[:, :, :3] == 0, axis=2))
Пример #18
0
 def draw_markers(self, gc, marker_path, marker_trans, path,
     trans, rgbFace=None):
     '''Markers graphics instructions are stored on a dictionary and
        hashed through graphics context and rgbFace values. If a marker_path
        with the corresponding graphics context exist then the instructions
        are pulled from the markers dictionary.
     '''
     if not len(path.vertices):
         return
     # get a string representation of the path
     path_data = self._convert_path(
         marker_path,
         marker_trans + Affine2D().scale(1.0, -1.0),
         simplify=False)
     # get a string representation of the graphics context and rgbFace.
     style = str(gc._get_style_dict(rgbFace))
     dictkey = (path_data, str(style))
     # check whether this marker has been created before.
     list_instructions = self._markers.get(dictkey)
     # creating a list of instructions for the specific marker.
     if list_instructions is None:
         polygons = marker_path.to_polygons(marker_trans)
         self._markers[dictkey] = self.get_path_instructions(gc,
                                     polygons, rgbFace=rgbFace)
     # Traversing all the positions where a marker should be rendered
     for vertices, codes in path.iter_segments(trans, simplify=False):
         if len(vertices):
             x, y = vertices[-2:]
             for widget, instructions in self._markers[dictkey]:
                 widget.canvas.add(PushMatrix())
                 widget.canvas.add(Translate(x, y))
                 widget.canvas.add(instructions)
                 widget.canvas.add(PopMatrix())
Пример #19
0
 def on_update(self):
     self.animations.on_update()
     self.actual_sound.on_update()
     self.user_sound.on_update()
     self.key_label.set_text(f"Key: {self.user_key}")
     if not self.game_over and self.is_game_over():
         for pos, obj in self.objects.items():
             if isinstance(obj, MovingBlock):
                 obj.moveable = False
         if self.level == max(levels.keys()):
             self.on_finished_puzzle()
             self.on_game_over()
         else:
             if (-1, 4) not in self.objects:
                 size = (self.grid.tile_side_len, self.grid.tile_side_len)
                 self.objects[(-1, 4)] = DoorTile(
                     size,
                     self.grid.grid_to_pixel((-1, 4)),
                     PianoPuzzle,
                     source=self.door_sources[(-1, 4)],
                 )
             self.add(PushMatrix())
             self.add(Translate(*self.grid.pos))
             self.add(self.objects[(-1, 4)])
             self.add(PopMatrix())
def export_to_png(self, filename, *args):
    '''Saves an image of the widget and its children in png format at the
    specified filename. Works by removing the widget canvas from its
    parent, rendering to an :class:`~kivy.graphics.fbo.Fbo`, and calling
    :meth:`~kivy.graphics.texture.Texture.save`.
    '''

    if self.parent is not None:
        canvas_parent_index = self.parent.canvas.indexof(self.canvas)
        self.parent.canvas.remove(self.canvas)

    fbo = Fbo(size=self.size)

    with fbo:
        ClearColor(0, 0, 0, 1)
        ClearBuffers()
        Translate(-self.x, -self.y, 0)

    fbo.add(self.canvas)
    fbo.draw()
    fbo.texture.save(filename)
    fbo.remove(self.canvas)

    if self.parent is not None:
        self.parent.canvas.insert(canvas_parent_index, self.canvas)

    return True
Пример #21
0
    def _get_fbo(self,widget):
        '''get frame buffer object of widget.
        Args:
            widget: subclass of kivy.uix.widget.
        Returns:
            kivy.graphics.fbo
        '''
        if widget.parent is not None:
            canvas_parent_index = widget.parent.canvas.indexof(self.canvas)
            if canvas_parent_index > -1:
                widget.parent.canvas.remove(widget.canvas)

        fbo = Fbo(size=widget.size, with_stencilbuffer=True)

        with fbo:
            PushMatrix()
            ClearColor(0, 0, 0, 0)
            ClearBuffers()
            Scale(1, -1, 1)
            Translate(-widget.x, -widget.y - widget.height, 0)
            Rotate(origin=widget.center,
                axis=(widget.center_x,0,0),
                angle=-180)

        return fbo
Пример #22
0
    def draw_setpoint(self, *args):
        # draw a setpoint
        if self.setpoint_canvas:
            self.canvas.after.remove(self.setpoint_canvas)
            self.setpoint_canvas = None

        if math.isnan(self.setpoint_value):
            return

        v = self.value_to_angle(self.setpoint_value)
        length = self.dial_diameter / 2.0 - self.tic_length if not self.setpoint_length else self.setpoint_length
        self.setpoint_canvas = InstructionGroup()

        self.setpoint_canvas.add(PushMatrix())
        self.setpoint_canvas.add(Color(*self.setpoint_color))
        self.setpoint_canvas.add(
            Rotate(angle=v, axis=(0, 0, -1), origin=self.dial_center))
        self.setpoint_canvas.add(
            Translate(self.dial_center[0], self.dial_center[1]))
        self.setpoint_canvas.add(
            Line(points=[0, 0, 0, length],
                 width=self.setpoint_thickness,
                 cap='none'))
        #self.setpoint_canvas.add(SmoothLine(points=[0, 0, 0, length], width=self.setpoint_thickness))
        self.setpoint_canvas.add(PopMatrix())

        self.canvas.after.add(self.setpoint_canvas)
Пример #23
0
    def capture_image(self, filename):
        """
        Capture only the visible part of the camera, without the black border.
        Similar to export_to_png but with adjusted coordinates.
        :param filename: path to the target file name
        :return True
        """
        if self.parent is not None:
            canvas_parent_index = self.parent.canvas.indexof(self.canvas)
            if canvas_parent_index > -1:
                self.parent.canvas.remove(self.canvas)

        nw, nh = self.norm_image_size
        fbo = Fbo(size=(nw, nh), with_stencilbuffer=True)

        with fbo:
            ClearColor(0, 0, 0, 0)
            ClearBuffers()
            Scale(1, -1, 1)
            x = -self.x-(self.width-nw)/2
            y = -self.y-(self.height-nh)/2 - nh
            Translate(x, y, 0)

        fbo.add(self.canvas)
        fbo.draw()
        fbo.texture.save(filename, flipped=False)
        fbo.remove(self.canvas)

        if self.parent is not None and canvas_parent_index > -1:
            self.parent.canvas.insert(canvas_parent_index, self.canvas)

        return True
Пример #24
0
    def get_frame_data(self, *args):
        """Return the content of this display as buffer.

        @see: widget.export_to_png
        """
        del args
        if self._slide_manager_parent.parent is not None:
            canvas_parent_index = self._slide_manager_parent.parent.canvas.indexof(self._slide_manager_parent.canvas)
            if canvas_parent_index > -1:
                self._slide_manager_parent.parent.canvas.remove(self._slide_manager_parent.canvas)

        fbo = Fbo(size=self._slide_manager_parent.size, with_stencilbuffer=True)

        with fbo:
            ClearColor(0, 0, 0, 1)
            ClearBuffers()
            Scale(1, -1, 1)
            Translate(-self._slide_manager_parent.x, -self._slide_manager_parent.y - self._slide_manager_parent.height, 0)

        fbo.add(self._slide_manager_parent.canvas)
        fbo.draw()
        data = fbo.texture.pixels
        fbo.remove(self._slide_manager_parent.canvas)

        if self._slide_manager_parent.parent is not None and canvas_parent_index > -1:
            self._slide_manager_parent.parent.canvas.insert(canvas_parent_index, self._slide_manager_parent.canvas)

        return data
Пример #25
0
    def __init__(self, pos, tick):
        super(Trail, self).__init__()
        self.pos = pos
        self.tick = tick
        self.x = NOW_X + DRAW_CALIBRATION + tick * PIXELS_PER_TICK
        self.y = 360 - 240 + 480 * (pos)
        self.is_hit = False

        self.color = Color(rgb=[0.9, 0.9, 1.0], a=0.9)

        self.width = 40 * PIXELS_PER_TICK
        self.height = 20

        self.flare_color = Color(rgb=[0.5, 0.5, 0.6])
        self.flare_color.a = 0
        self.hit_flare = Rectangle(pos=(self.x, self.y - 40), size=(20, 80))
        self.add(self.flare_color)
        self.add(self.hit_flare)

        self.add(self.color)
        self.shape = Rectangle(pos=(-10, -10), size=(20, 20))

        self.add(PushMatrix())
        self.add(Translate(self.x, self.y))
        self.add(Rotate(angle=45))
        self.add(self.shape)
        self.add(PopMatrix())
Пример #26
0
    def __init__(self, **kwargs):
        # Make sure opengl context exists
        EventLoop.ensure_window()

        self.canvas = RenderContext(use_parent_projection=True,
                                    use_parent_modelview=True)

        with self.canvas:
            self.fbo = Fbo(size=self.size)

        with self.fbo.before:
            PushMatrix()
            self.fbo_translation = Translate(-self.x, -self.y, 0)
        with self.fbo:
            ClearColor(1, 1, 1, 1)
            Color(*self.background_color)
            ClearBuffers()
            self.fbo_rectangle = Rectangle(size=self.size)
        with self.fbo.after:
            PopMatrix()

        super(EffectWidget, self).__init__(**kwargs)

        Clock.schedule_interval(self._update_glsl, 0)

        self.bind(pos=self._update_translation,
                  size=self.refresh_fbo_setup,
                  effects=self.refresh_fbo_setup)

        self.refresh_fbo_setup()
Пример #27
0
    def export_as_image(self, *args, **kwargs):
        '''Return an core :class:`~kivy.core.image.Image` of the actual
        widget.

        .. versionadded:: 1.11.0
        '''
        from kivy.core.image import Image
        scale = kwargs.get('scale', 1)

        if self.parent is not None:
            canvas_parent_index = self.parent.canvas.indexof(self.canvas)
            if canvas_parent_index > -1:
                self.parent.canvas.remove(self.canvas)

        fbo = Fbo(size=(self.width * scale, self.height * scale),
                  with_stencilbuffer=True)

        with fbo:
            ClearColor(0, 0, 0, 0)
            ClearBuffers()
            Scale(1, -1, 1)
            Scale(scale, scale, 1)
            Translate(-self.x, -self.y - self.height, 0)

        fbo.add(self.canvas)
        fbo.draw()
        img = Image(fbo.texture)
        fbo.remove(self.canvas)

        if self.parent is not None and canvas_parent_index > -1:
            self.parent.canvas.insert(canvas_parent_index, self.canvas)

        return img
Пример #28
0
    def __init__(self):
        super(SongMenu, self).__init__()

        self.current_song_index = 0
        self.num_songs = 3

        self.trans = Translate()
        self.add(self.trans)

        self.img_locations = [
            center, (center[0] + 400, center[1]), (center[0] + 800, center[1])
        ]
        self.label_locations = [(center[0], center[1] - 170),
                                (center[0] + 400, center[1] - 170),
                                (center[0] + 800, center[1] - 170)]

        self.list_imgs = []
        self.list_labels = []
        self.anim_group = AnimGroup()

        for i in range(3):
            image_path = index_to_img[i]
            label_path = index_to_img_label[i]
            image = Image(250, 250, self.img_locations[i], image_path)
            label = Image(250, 45, self.label_locations[i], label_path)

            self.add(image)
            self.add(label)
            self.list_imgs.append(image)
            self.list_labels.append(label)

        for im in self.list_imgs:
            self.anim_group.add(im)
        for label in self.list_labels:
            self.anim_group.add(label)
Пример #29
0
    def draw_object(self, obj_id):
        m = self._scene.objects[obj_id]
        self.obj_rot_z = Rotate(self.obj_rotation[2], 0, 0, 1)
        self.obj_rot_y = Rotate(self.obj_rotation[1], 0, 1, 0)
        self.obj_rot_x = Rotate(self.obj_rotation[0], 1, 0, 0)
        self.obj_translate = Translate(xyz=self.obj_translation)

        if len(m.indices) > 2**16:
            print '%s too big! %s indices' % (obj_id, len(m.indices))

        if m.texture:
            print "loading texture %s " % m.texture
            img = Image(
                source=resource_find(join(dirname(self.scene), m.texture)))
            texture = img.texture
            if texture:
                texture.wrap = 'repeat'
        else:
            texture = None

        vertex_lenght = sum(x[1] for x in m.vertex_format)
        if len(m.vertices) % vertex_lenght:
            print(('warning: vertices lenght (%s)'
                   'is not a multiple of vertex_format lenght(%s)') %
                  (len(m.vertices), vertex_lenght))
        Mesh(vertices=m.vertices,
             indices=m.indices,
             fmt=m.vertex_format,
             texture=texture,
             mode=self.mode)
Пример #30
0
    def draw_annulars(self):
        # draw annulars that are in the annulars list:
        # requires properties annular_thickness, and a list of dicts {color: , start: , stop: }, ...,
        # where start and stop are the values of the scale to start and stop the annular

        if len(self.annulars) == 0:
            return

        awidth = self.annular_thickness
        self.annular_canvas = InstructionGroup()

        if self.semi_circle:
            self.annular_canvas.add(PushMatrix())
            self.annular_canvas.add(
                Translate(0, -self.dial_diameter / 2 + self.hub_radius))

        for a in self.annulars:
            self.annular_canvas.add(Color(*a.get('color', [0, 1, 0, 1])))
            st = self.value_to_angle(a.get('start', self.scale_min))
            en = self.value_to_angle(a.get('stop', self.scale_max))
            self.annular_canvas.add(
                Line(ellipse=(self.pos[0] + awidth, self.pos[1] + awidth,
                              self.dial_diameter - awidth * 2,
                              self.dial_diameter - awidth * 2,
                              st + awidth / 2.0 - self.tic_width,
                              en + awidth / 2.0),
                     width=awidth,
                     cap='none',
                     joint='round'))

        if self.semi_circle:
            self.annular_canvas.add(PopMatrix())

        self.canvas.before.add(self.annular_canvas)
Пример #31
0
    def draw(self):
        Game.engine['gfx'].draw_rectangle(
            (self.x, self.y), (self.width, self.height), self.current_colour)

        # Kivy is special so we make sure that our attached widget is the right colour and size
        # to get the overlay to appear
        if Game.engine_def['gfx'] == "kivy":
            from kivy.graphics import Color, PushMatrix, PopMatrix, Translate, Quad
            if not self in Game.engine['gfx'].entity_draws:
                Game.engine['gfx'].entity_draws[self] = dict()
                with Game.engine['gfx'].widget.canvas:
                    Game.engine['gfx'].entity_draws[self]['color'] = Color()
                    Game.engine['gfx'].entity_draws[self][
                        'color'].rgba = self.current_colour
                    PushMatrix()
                    Game.engine['gfx'].entity_draws[self][
                        'translate'] = Translate()

                    Game.engine['gfx'].entity_draws[self]['rect'] = Quad(
                        points=(0.0, 0.0, self.width, 0.0, self.width,
                                self.height, 0.0, self.height))
                    Game.engine['gfx'].entity_draws[self]['translate'].xy = (
                        self.x, self.y)
                    PopMatrix()
            # Otherwise just update values
            else:
                Game.engine['gfx'].entity_draws[self]['translate'].xy = (
                    self.x, self.y)
                Game.engine['gfx'].entity_draws[self][
                    'color'].rgba = self.current_colour
                Game.engine['gfx'].entity_draws[self]['rect'].points = (
                    0.0, 0.0, self.width, 0.0, self.width, self.height, 0.0,
                    self.height)