Exemplo n.º 1
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
Exemplo n.º 2
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)
Exemplo n.º 3
0
    def export_as_image(self, *args, **kwargs):

        # overwrite the function, because ClearColor is set to black per default
        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(1, 1, 1, 1)
            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
Exemplo n.º 4
0
    def export_to_png(self, filename, *args, **kwargs):
        '''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`.

        .. note::

            The image includes only this widget and its children. If you want
            to include widgets elsewhere in the tree, you must call
            :meth:`~Widget.export_to_png` from their common parent, or use
            :meth:`~kivy.core.window.WindowBase.screenshot` to capture the
            whole window.

        .. note::

            The image will be saved in png format, you should include the
            extension in your filename.

        .. versionadded:: 1.9.0

        :Parameters:
            `filename`: str
                The filename with which to save the png.
            `scale`: float
                The amount by which to scale the saved image, defaults to 1.

                .. versionadded:: 1.11.0
        '''

        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()
        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
Exemplo n.º 5
0
    def add_graphics(self, canvas, black_back=False):
        '''Adds all the graphics required to visualize the shapes to the
        canvas.
        '''
        _get_app().stage_factory.remove_shapes_gl_color_instructions(
            canvas, self.canvas_name)
        self.shape_views = []
        w, h = self.screen_width, self.screen_height

        with canvas:
            PushMatrix()
            s = Scale()
            if self.flip_projector:
                s.x = -1
            s.origin = w / 2., h / 2.

        if black_back:
            with canvas:
                Color(0, 0, 0, 1, group=self.canvas_name)
                Rectangle(size=(w, h), group=self.canvas_name)

        if self.do_quad_mode:
            half_w = w // 2
            half_h = h // 2

            for (x, y) in ((0, 1), (1, 1), (0, 0), (1, 0)):
                with canvas:
                    PushMatrix(group=self.canvas_name)
                    Translate(x * half_w, y * half_h, group=self.canvas_name)
                    s = Scale(group=self.canvas_name)
                    s.x = s.y = 0.5
                    s.origin = 0, 0
                instructs = _get_app(
                    ).stage_factory.get_shapes_gl_color_instructions(
                        canvas, self.canvas_name)
                with canvas:
                    PopMatrix(group=self.canvas_name)
                self.shape_views.append(instructs)
        else:
            self.shape_views = [
                _get_app().stage_factory.get_shapes_gl_color_instructions(
                    canvas, self.canvas_name)]

        with canvas:
            PopMatrix()

        if self.output_count and not self.serializer_tex:
            with canvas:
                Color(1, 1, 1, 1, group=self.canvas_name)
                tex = self.serializer_tex = Texture.create(size=(1, 1))
                tex.mag_filter = 'nearest'
                tex.min_filter = 'nearest'
                Rectangle(texture=tex, pos=(0, h - 1), size=(1, 1),
                          group=self.canvas_name)
Exemplo n.º 6
0
    def capture_image(self, filename):
        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
Exemplo n.º 7
0
    def __init__(self, **kwargs):
        super(SvgWidget, self).__init__(**kwargs)
        with self.canvas:
            self.scale = Scale(1, 1, 1)
            self.svg = Svg(kwargs['filename'])

        self.bind(size=self._do_scale)
Exemplo n.º 8
0
    def __init__(self, parent, **kwargs):
        super(Ball, self).__init__(**kwargs)
        self.touch_uid = None
        self.target_pos = self.pos

        self.animation = None

        radius = self.radius = parent.cell_size * 0.3
        self.handle_radius = parent.cell_size * BALL_TOUCH_RADIUS
        self.zoc_radius = self.radius
        with self.canvas:
            Color(0, 0, 1, 0.5)
            Ellipse(pos=(-radius, -radius), size=(radius * 2, radius * 2))
            Color(0, 0, 0, 1)
            HollowCircle((0, 0), radius, 18)
            Color(0.5, 0.5, 0.5, 0.4)
            FilledCircle((0, 0), self.handle_radius)
            HollowCircle((0, 0), self.handle_radius, 18)
            self.scale_instruction = Scale(self.zoc_radius)
            Color(1, 1, 1, 0.2)
            FilledCircle((0, 0), 1)
            Color(0.5, 0.5, 0.5, 0.4)
            HollowCircle((0, 0), 1, 32)
        with self.canvas.before:
            PushMatrix()
            self.translation_instruction = Translate(0, 0, 0)
        with self.canvas.after:
            PopMatrix()
Exemplo n.º 9
0
    def show_lines(self):
        indices = []
        grid = self.grid
        cols = grid.cols
        rows = grid.rows
        for col in range(grid.cols + 1):
            indices.extend((
                col * (rows + 1),
                col * (rows + 1) + rows,
            ))
        for row in range(grid.rows + 1):
            indices.extend((
                row,
                row + (cols * (rows + 1)),
            ))

        with self.canvas:
            self.g_canvas = Canvas()

        with self.g_canvas:
            Color(1, 0, 0, 0.5)
            PushMatrix()
            Scale(self.width, self.height, 1.)
            self.g_mesh = Mesh(vertices=self.grid.line_vertices,
                               indices=self.grid.line_indices,
                               mode="lines",
                               source="projectionmapping/data/white.png")
            PopMatrix()

        self.rebuild_informations()
Exemplo n.º 10
0
    def __init__(self, pos, texture, size_x=1.0, size_y=1.0, intensity=1.0, Tr=1.0):
        super(BillboardDisplay, self).__init__()
        
        self.intensity = intensity
        self.Tr = Tr

        self.translate = Translate()
        self.rotate_azi = Rotate(origin=(0,0,0), axis=(0,1,0))
        self.rotate_ele = Rotate(origin=(0,0,0), axis=(1,0,0))
        self.scale = Scale()
        self.color_instruction = InstructionGroup()
        self.mesh = Mesh(
            texture=texture,
            vertices=rectangle_nurb.vertices,
            indices=rectangle_nurb.indices,
            fmt=rectangle_nurb.vertex_format,
            mode='triangles'
        )

        self.add(PushMatrix())
        self.add(self.translate)
        self.add(self.rotate_azi)
        self.add(self.rotate_ele)
        self.add(self.scale)
        self.add(self.color_instruction)
        self.add(self.mesh)
        self.add(PopMatrix())

        self.set_color(intensity=intensity, Tr=Tr)
        self.set_size(size_x, size_y)
        self.set_pos(pos)
        self.set_texture(texture)
Exemplo n.º 11
0
    def add_image(self, widget):
        filename = f"tmp_{self.img_counter}.png"
        output_size = (self.meta_data["width"], self.meta_data["height"])

        if self.meta_data["WH_ratio"] != widget.width // widget.height:
            raise Exception("W/H ratio does not match")

        img_scale = self.meta_data["width"] / widget.width

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

        fbo = Fbo(size=output_size, with_stencilbuffer=True)

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

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

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

        self.img_counter += 1
Exemplo n.º 12
0
    def __init__(self,
                 nurb,
                 pos,
                 size=1.0,
                 color=(0.0, 1.0, 0.0),
                 tr=1.0,
                 intensity=1.0):
        super(NurbDisplay, self).__init__()

        self.color = color
        self.tr = tr
        self.intensity = intensity

        self.translate = Translate()
        self.scale = Scale()
        self.color_instruction = InstructionGroup()

        self.add(PushMatrix())
        self.add(self.translate)
        self.add(self.scale)
        self.add(self.color_instruction)
        self.add(self.make_mesh(nurb))
        self.add(PopMatrix())

        self.set_color()
        self.set_size(size)
        self.set_pos(pos)
Exemplo n.º 13
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
Exemplo n.º 14
0
Arquivo: main.py Projeto: matham/ceed
    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
Exemplo n.º 15
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))
Exemplo n.º 16
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
Exemplo n.º 17
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
Exemplo n.º 18
0
 def test_animated_instruction(self):
     instruction = Scale(3)
     self.a.start(instruction)
     self.assertEqual(self.a.animated_properties['x'], 100)
     self.assertAlmostEqual(instruction.x, 3)
     self.sleep(1.5)
     self.assertAlmostEqual(instruction.x, 100)
Exemplo n.º 19
0
    def draw(self, *_):
        self.canvas.clear()

        with self.canvas:
            ScissorPush(x=self.pos[0], y=self.pos[1], width=self.size[0], height=self.size[1])
            Color(*self.colors['bg'])
            Translate(self.pos[0], self.pos[1] + self.size[1])
            Scale(1 / self.zoom, -1 / self.zoom, 1)
            Rectangle(pos=(0, 0), size=self.size)
            Translate(self.camx, self.camy)
            self.inner_draw()
            Translate(-self.camx, -self.camy)
            Scale(self.zoom, self.zoom, 1)
            Color(0, 0, 0)
            Scale(1, -1, 1)
            Translate(-self.pos[0], -self.pos[1] - self.size[1])

            ScissorPop()
Exemplo n.º 20
0
    def start(self, evt):
        with self.canvas.before:
            self.gradients = [[1, 0, 0, 1], [0, 0, 1, 1]]
            self.color = Color(1, 0, 0, 1)
            self.scale = Scale(1, 1, 1)
            self.svg = Svg(self.source)

        self.bind(size=self._do_scale)
        self.size = self.svg.width, self.svg.height
Exemplo n.º 21
0
 def init_fbo(self):
     with self.canvas:
         Color(1, 1, 1)
         self.g_fbo = Fbo(size=self.size)
         self.g_fbo_texture = self.g_fbo.texture
         Color(1, 1, 1, 1)
         PushMatrix()
         self.g_scale = Scale(self.width / 2, self.height / 2, 1.)
         self.build_grid()
         PopMatrix()
Exemplo n.º 22
0
    def on_touch_down(self, touch, force=False):
        if force:
            self.touch_uid = touch.uid
        if self.touch_uid == touch.uid:
            #touch.grab(self)
            with self.canvas.before:
                PushMatrix()
            with self.canvas.after:
                PopMatrix()
            with self.canvas:
                # Create the ring of “satellite” points
                self.color_instruction = Color(1, 1, 0, 0)
                self.points = Point(points=self.pos,
                                    pointsize=5,
                                    source='particle.png')
                Translate(self.pos[0], self.pos[1], 0)
                self.scale_instruction = Scale(self.parent.cell_size * 10)
                self.rotate_instruction = Rotate(0, 0, 0, 1)
                self.rscale_instruction = Scale(1)
                num_satellites = 9
                satellites = []
                for i in range(num_satellites):
                    angle = i / num_satellites * 2 * math.pi
                    satellites.extend([
                        math.cos(angle) * 1.3,
                        math.sin(angle) * 1.3,
                    ])
                Point(points=satellites, pointsize=0.2, source='particle2.png')

            # A scale-in animation
            animation = Animation(scale=self.parent.cell_size / 3 * 2,
                                  t='out_cubic',
                                  duration=0.2)
            animation.start(self.scale_instruction)

            # A fade-in animation
            animation = Animation(a=0.8, t='out_cubic', duration=0.2)
            animation.start(self.color_instruction)

            # A practically infinite spinning animation
            animation = Animation(angle=200000 * self.spin, duration=1000)
            animation.start(self.rotate_instruction)
            return True
Exemplo n.º 23
0
    def add_graphics(self, canvas, black_back=False):
        '''Adds all the graphics required to visualize the shapes to the
        canvas.
        '''
        _get_app().stage_factory.remove_shapes_gl_color_instructions(
            canvas, self.canvas_name)
        self.shape_views = []
        w, h = self.screen_width, self.screen_height

        with canvas:
            PushMatrix()
            s = Scale()
            if self.flip_projector:
                s.x = -1
            s.origin = w / 2., h / 2.

        if black_back:
            with canvas:
                Color(0, 0, 0, 1, group=self.canvas_name)
                Rectangle(size=(w, h), group=self.canvas_name)

        if self.do_quad_mode:
            half_w = w // 2
            half_h = h // 2

            for (x, y) in ((0, 1), (1, 1), (0, 0), (1, 0)):
                with canvas:
                    PushMatrix(group=self.canvas_name)
                    Translate(x * half_w, y * half_h, group=self.canvas_name)
                    s = Scale(group=self.canvas_name)
                    s.x = s.y = 0.5
                    s.origin = 0, 0
                instructs = _get_app().\
                    stage_factory.get_shapes_gl_color_instructions(
                    canvas, self.canvas_name)
                with canvas:
                    PopMatrix(group=self.canvas_name)
                self.shape_views.append(instructs)
        else:
            self.shape_views = [
                _get_app().stage_factory.get_shapes_gl_color_instructions(
                    canvas, self.canvas_name)
            ]

        with canvas:
            PopMatrix()

        if self.output_count and not self.serializer_tex:
            with canvas:
                Color(1, 1, 1, 1, group=self.canvas_name)
                tex = self.serializer_tex = Texture.create(size=(1, 1))
                tex.mag_filter = 'nearest'
                tex.min_filter = 'nearest'
                Rectangle(texture=tex,
                          pos=(0, h - 1),
                          size=(1, 1),
                          group=self.canvas_name)
Exemplo n.º 24
0
 def test_animated_instruction(self):
     from kivy.graphics import Scale
     from kivy.animation import Animation
     a = Animation(x=100, d=1)
     instruction = Scale(3)
     a.start(instruction)
     assert a.animated_properties == {'x': 100, }
     assert instruction.x == pytest.approx(3)
     sleep(1.5)
     assert instruction.x == pytest.approx(100)
     assert no_animations_being_played()
Exemplo n.º 25
0
    def start(self, manager):
        for screen in self.screen_in, self.screen_out:
            with screen.canvas.before:
                PushMatrix(group='swaptransition_scale')
                scale = Scale(group='swaptransition_scale')
            with screen.canvas.after:
                PopMatrix(group='swaptransition_scale')

            screen.bind(center=self.update_scale)
            self.scales[screen] = scale
        super(SwapTransition, self).start(manager)
Exemplo n.º 26
0
 def __init__(self, graphics):
     super(Transform, self).__init__()
     self.position = Translate()
     self.rotation = Rotate()
     self.scale = Scale()
     self.add(PushMatrix())
     self.add(self.position)
     self.add(self.rotation)
     self.add(self.scale)
     self.add(graphics)
     self.add(PopMatrix())
Exemplo n.º 27
0
    def Create(self,
               elastin=0.8,
               collision=False,
               size=[100, 100],
               source=None,
               texture=None,
               loop=1,
               fade=0.0,
               sequence=[1, 1],
               playspeed=1.0,
               **kargs):
        self.collision = collision
        self.elastin = max(min(elastin, 1.0), 0.0)
        self.size = size
        self.loop = loop
        self.fade = fade
        self.sequence = sequence
        self.playspeed = playspeed

        if texture == None:
            if source != None:
                self.texture = Image(source=source).texture
        else:
            self.texture = texture

        if self.sequence[0] == 1 and self.sequence[1] == 1:
            self.playspeed = 0

        for key in kargs:
            if not hasattr(self, key):
                raise AttributeError(self.__class__.__name__ +
                                     " has not attribue " + key)
            self.variables[key] = kargs[key]

        if self.texture:
            self.cellcount = self.sequence[0] * self.sequence[1]
            self.cellsize = div(self.texture.size, self.sequence)
            curtexture = self.texture.get_region(0.0, 0.0, *self.cellsize)
            with self.canvas:
                Color(1, 1, 1, 1)
                self.box = Rectangle(texture=curtexture,
                                     pos=(0, 0),
                                     size=self.size)
            with self.canvas.before:
                PushMatrix()
                self.boxPos = Translate(0, 0)
                self.boxRot = Rotate(angle=0,
                                     axis=(0, 0, 1),
                                     origin=mul(mul(self.size, 0.5),
                                                self.scaling))
                self.boxScale = Scale(1, 1, 1)
            with self.canvas.after:
                PopMatrix()
Exemplo n.º 28
0
 def update(self):
     with self.canvas.before:
         LoadIdentity()
         self.g_translate = Translate(*self._translation_diff)
         self._translation = [
             self._translation[x] + self._translation_diff[x]
             for x in [0, 1]
         ]
         self._translation_diff = [0, 0]
         self.g_scale = Scale(self._scale_ratio)
         self._total_scale = self._total_scale * self._scale_ratio
         self._scale_ratio = 1.0
Exemplo n.º 29
0
    def _draw_widget(self, *args):
        """Draws the image (draws a rectangle using the image texture)"""
        del args

        anchor = (self.x - self.anchor_offset_pos[0], self.y - self.anchor_offset_pos[1])
        self.canvas.clear()

        with self.canvas:
            Color(*self.color)
            Rotate(angle=self.rotation, origin=anchor)
            Scale(self.scale).origin = anchor
            Rectangle(pos=self.pos, size=self.size, texture=self.texture)
Exemplo n.º 30
0
 def __init__(self, **kwargs):
     super(Inspector, self).__init__(**kwargs)
     self.avoid_bring_to_top = False
     self.win = kwargs.get('win')
     with self.canvas.before:
         self.gcolor = Color(1, 0, 0, .25)
         PushMatrix()
         self.gtranslate = Translate(0, 0, 0)
         self.grotate = Rotate(0, 0, 0, 1)
         self.gscale = Scale(1.)
         self.grect = Rectangle(size=(0, 0))
         PopMatrix()
     Clock.schedule_interval(self.update_widget_graphics, 0)
Exemplo n.º 31
0
 def __init__(self, **kwargs):
     super(GeoJsonMapLayer, self).__init__(**kwargs)
     with self.canvas:
         self.canvas_polygon = Canvas()
         self.canvas_line = Canvas()
     with self.canvas_polygon.before:
         PushMatrix()
         self.g_matrix = MatrixInstruction()
         self.g_scale = Scale()
         self.g_translate = Translate()
     with self.canvas_polygon:
         self.g_canvas_polygon = Canvas()
     with self.canvas_polygon.after:
         PopMatrix()