def render(self, width, height, st, at):

        width = max(self.style.xminimum, width)
        height = max(self.style.yminimum, height)

        color = self.color or self.style.color

        rv = Render(width, height)

        if color is None or width <= 0 or height <= 0:
            return rv

        SIZE = 10

        if width < SIZE or height < SIZE:
            tex = renpy.display.draw.solid_texture(width, height, color)
        else:
            tex = renpy.display.draw.solid_texture(SIZE, SIZE, color)
            rv.forward = Matrix2D(1.0 * SIZE / width, 0, 0,
                                  1.0 * SIZE / height)
            rv.reverse = Matrix2D(1.0 * width / SIZE, 0, 0,
                                  1.0 * height / SIZE)

        rv.blit(tex, (0, 0))

        return rv
Exemple #2
0
        def draw(x0, x1, y0, y1):

            # Compute the coordinates of the left, right, top, and
            # bottom sides of the region, for both the source and
            # destination surfaces.

            # left side.
            if x0 >= 0:
                dx0 = x0
                sx0 = x0
            else:
                dx0 = dw + x0
                sx0 = sw + x0

            # right side.
            if x1 > 0:
                dx1 = x1
                sx1 = x1
            else:
                dx1 = dw + x1
                sx1 = sw + x1

            # top side.
            if y0 >= 0:
                dy0 = y0
                sy0 = y0
            else:
                dy0 = dh + y0
                sy0 = sh + y0

            # bottom side
            if y1 > 0:
                dy1 = y1
                sy1 = y1
            else:
                dy1 = dh + y1
                sy1 = sh + y1

            # Quick exit.
            if sx0 == sx1 or sy0 == sy1:
                return

            # Compute sizes.
            csw = sx1 - sx0
            csh = sy1 - sy0
            cdw = dx1 - dx0
            cdh = dy1 - dy0

            if csw <= 0 or csh <= 0 or cdh <= 0 or cdw <= 0:
                return

            # Get a subsurface.
            cr = crend.subsurface((sx0, sy0, csw, csh))

            # Scale or tile if we have to.
            if csw != cdw or csh != cdh:

                if self.tile:
                    ctw, cth = cdw, cdh

                    xtiles = max(1, cdw // csw + (1 if cdw % csw else 0))
                    ytiles = max(1, cdh // csh + (1 if cdh % csh else 0))

                    if cdw % csw or cdh % csh:
                        # Area is not an exact integer number of tiles

                        if self.tile == "integer":
                            if cdw % csw / float(csw) < self.tile_ratio:
                                xtiles = max(1, xtiles - 1)
                            if cdh % csh / float(csh) < self.tile_ratio:
                                ytiles = max(1, ytiles - 1)

                            # Set size of the used tiles (ready to scale)
                            ctw, cth = csw * xtiles, csh * ytiles

                    newcr = Render(ctw, cth)
                    newcr.xclipping = True
                    newcr.yclipping = True

                    for x in range(0, xtiles):
                        for y in range(0, ytiles):
                            newcr.blit(cr, (x * csw, y * csh))

                    csw, csh = ctw, cth
                    cr = newcr

                if csw != cdw or csh != cdh:
                    # Subsurface needs scaling
                    newcr = Render(cdw, cdh)
                    newcr.forward = Matrix2D(1.0 * csw / cdw, 0, 0,
                                             1.0 * csh / cdh)
                    newcr.reverse = Matrix2D(1.0 * cdw / csw, 0, 0,
                                             1.0 * cdh / csh)
                    newcr.blit(cr, (0, 0))

                    cr = newcr

            # Blit.
            rv.blit(cr, (dx0, dy0))
            return
        def draw(x0, x1, y0, y1):

            # Compute the coordinates of the left, right, top, and
            # bottom sides of the region, for both the source and
            # destination surfaces.

            # left side.
            if x0 >= 0:
                dx0 = x0
                sx0 = x0
            else:
                dx0 = dw + x0
                sx0 = sw + x0

            # right side.
            if x1 > 0:
                dx1 = x1
                sx1 = x1
            else:
                dx1 = dw + x1
                sx1 = sw + x1

            # top side.
            if y0 >= 0:
                dy0 = y0
                sy0 = y0
            else:
                dy0 = dh + y0
                sy0 = sh + y0

            # bottom side
            if y1 > 0:
                dy1 = y1
                sy1 = y1
            else:
                dy1 = dh + y1
                sy1 = sh + y1

            # Quick exit.
            if sx0 == sx1 or sy0 == sy1:
                return

            # Compute sizes.
            csw = sx1 - sx0
            csh = sy1 - sy0
            cdw = dx1 - dx0
            cdh = dy1 - dy0

            if csw <= 0 or csh <= 0 or cdh <= 0 or cdw <= 0:
                return

            # Get a subsurface.
            cr = crend.subsurface((sx0, sy0, csw, csh))

            # Scale or tile if we have to.
            if csw != cdw or csh != cdh:

                if self.tile:
                    newcr = Render(cdw, cdh)
                    newcr.xclipping = True
                    newcr.yclipping = True

                    for x in xrange(0, cdw, csw):
                        for y in xrange(0, cdh, csh):
                            newcr.blit(cr, (x, y))

                    cr = newcr

                else:

                    newcr = Render(cdw, cdh)
                    newcr.forward = Matrix2D(1.0 * csw / cdw, 0, 0,
                                             1.0 * csh / cdh)
                    newcr.reverse = Matrix2D(1.0 * cdw / csw, 0, 0,
                                             1.0 * cdh / csh)
                    newcr.blit(cr, (0, 0))

                    cr = newcr

            # Blit.
            rv.blit(cr, (dx0, dy0))
            return
Exemple #4
0
    def render(self, width, height, st, at):

        # Should we perform clipping?
        clipping = False

        # Preserve the illusion of linear time.
        if st == 0:
            self.st_offset = self.st
        if at == 0:
            self.at_offset = self.at

        self.st = st = st + self.st_offset
        self.at = at = at + self.at_offset

        # If we have to, call the function that updates this transform.
        if self.function is not None:

            fr = self.function(self, st, at)

            if fr is not None:
                renpy.display.render.redraw(self, fr)

        self.active = True

        if self.state.size:
            width, height = self.state.size

        if self.child is None:
            raise Exception("Transform does not have a child.")

        cr = render(self.child, width, height, st - self.child_st_base, at)
        width, height = cr.get_size()

        forward = IDENTITY
        reverse = IDENTITY
        xo = yo = 0

        # Cropping.
        crop = self.state.crop
        if crop is None and self.state.corner1 and self.state.corner2:
            x1, y1 = self.state.corner1
            x2, y2 = self.state.corner2

            minx = min(x1, x2)
            maxx = max(x1, x2)
            miny = min(y1, y2)
            maxy = max(y1, y2)

            crop = (minx, miny, maxx - minx, maxy - miny)

        if crop:

            negative_xo, negative_yo, width, height = crop
            xo = -negative_xo
            yo = -negative_yo

            clipping = True

            if self.state.rotate:
                clipcr = renpy.display.render.Render(width, height)
                clipcr.subpixel_blit(cr, (xo, yo))
                clipcr.clipping = clipping
                xo = yo = 0
                cr = clipcr
                clipping = False

        # Size.
        if self.state.size and self.state.size != (width, height):
            nw, nh = self.state.size
            xzoom = 1.0 * nw / width
            yzoom = 1.0 * nh / height
            forward = forward * Matrix2D(1.0 / xzoom, 0, 0, 1.0 / yzoom)
            reverse = Matrix2D(xzoom, 0, 0, yzoom) * reverse

            xo = xo * xzoom
            yo = yo * yzoom

            width, height = self.state.size

        # Rotation.
        if self.state.rotate is not None:

            cw = width
            ch = height

            width = height = math.hypot(cw, ch)
            angle = -self.state.rotate * math.pi / 180

            xdx = math.cos(angle)
            xdy = -math.sin(angle)
            ydx = -xdy
            ydy = xdx

            forward = forward * Matrix2D(xdx, xdy, ydx, ydy)

            xdx = math.cos(-angle)
            xdy = -math.sin(-angle)
            ydx = -xdy
            ydy = xdx

            reverse = Matrix2D(xdx, xdy, ydx, ydy) * reverse

            xo, yo = reverse.transform(-cw / 2.0, -ch / 2.0)
            xo += width / 2.0
            yo += height / 2.0

        xzoom = self.state.zoom * self.state.xzoom
        yzoom = self.state.zoom * self.state.yzoom

        if xzoom != 1 or yzoom != 1:

            forward = forward * Matrix2D(1.0 / xzoom, 0, 0, 1.0 / yzoom)
            reverse = Matrix2D(xzoom, 0, 0, yzoom) * reverse

            width *= xzoom
            height *= yzoom
            xo *= xzoom
            yo *= yzoom

        rv = renpy.display.render.Render(width, height)

        if forward is not IDENTITY:
            rv.forward = forward
            rv.reverse = reverse

        self.forward = forward

        rv.alpha = self.state.alpha

        rv.clipping = clipping

        if self.state.subpixel:
            rv.subpixel_blit(cr, (xo, yo), main=True)
        else:
            rv.blit(cr, (xo, yo), main=True)

        self.offsets = [(xo, yo)]

        return rv