Пример #1
0
    def redraw(self, x, y, width, height, propagate=True, timing=False):
        """Redraw an outdated area in the displayed image.
        @x: The x coordinate of upper-left corner of rectangle.
        @y: The y coordinate of upper-left corner of rectangle.
        @width: The width of rectangle.
        @height: The height of rectangle.
        @propagate: Boolean to redraw or not the related sandbox area.
        @timing: Boolean to use or not the redraw timing system."""

        # Use the timing system.
        if timing:

            # Update obscure limits.
            obs = self.obscured
            if not obs[0] or x < obs[0]: obs[0] = x
            if not obs[1] or y < obs[1]: obs[1] = y
            if not obs[2] or x+width > obs[2]: obs[2] = x+width
            if not obs[3] or y+height > obs[3]: obs[3] = y+height
            if not self.obscured_time: self.obscured_time = time.time()

            # Abort redraw if there are more redraws in the stack and
            # the last redraw is too close.
            if gtk.events_pending():
                if time.time() - self.obscured_time < 0.04:
                    return

            # Overwrite redraw area with obscure limits.
            x = self.obscured[0]
            y = self.obscured[1]
            width = self.obscured[2] - self.obscured[0]
            height = self.obscured[3] - self.obscured[1]

        # Clear area with black and transparent pixels.
        core.clear(
            self.document.pointer,
            self.document.width,
            self.document.height,
            x,
            y,
            width,
            height)

        # Draw prelower layer.
        prelower = self.document.layers.prelower
        prelower.composite(1, self.document, 0, 0, x, y, width, height)

        # Avoid if there is no active layer.
        if self.document.layers.active:

            # Draw active (middle) layer.
            self.document.layers.active.composite(
                1,
                self.document,
                self.document.layers.active.xpos,
                self.document.layers.active.ypos,
                x,
                y,
                width,
                height)

            # Draw preupper layer.
            preupper = self.document.layers.preupper
            preupper.composite(1, self.document, 0, 0, x, y, width, height)

        # Progagate redraw to sandbox.
        if propagate:
            if hasattr(self.sandbox, 'pixbuf'):
                self.sandbox.redraw(x, y, width, height)

        # Reset redraw timing limits.
        if timing:
            self.obscured = [0] * 4
            self.obscured_time = None
Пример #2
0
    def clear(self, x, y, width, height):
        """Clear (fill) the given area with black and opaque pixels."""

        core.clear(self.pointer, self.width, self.height, x, y, width, height)