Exemple #1
0
    def render_get_clip_region(self, cr, device_bbox):

        # Get the area which needs to be updated, in device coordinates, and
        # determine whether the render is "sparse", [TODO: define what this
        # means]
        x, y, w, h = device_bbox
        cx, cy = x+w/2, y+h/2
        if pygtkcompat.USE_GTK3:
            # As of 2012-07-08, Ubuntu Precise (LTS, unfortunately) and Debian
            # unstable(!) use python-cairo 1.8.8, which is too old to support
            # the cairo.Region return from Gdk.Window.get_clip_region() we
            # really need. They'll be important to support for a while, so we
            # have to use an inefficient workaround using the complete clip
            # rectangle for the update.
            #
            # http://stackoverflow.com/questions/6133622/
            # http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=653588
            # http://packages.ubuntu.com/python-cairo
            # http://packages.debian.org/python-cairo

            clip_exists, rect = gdk.cairo_get_clip_rectangle(cr)
            if clip_exists:
                # It's a wrapped cairo_rectangle_int_t, CairoRectangleInt
                area = (rect.x, rect.y, rect.width, rect.height)
                clip_region = area
                sparse = (cx < rect.x or cx > rect.x+rect.width
                          or cy < rect.y or cy > rect.y+rect.height)
            else:
                clip_region = None
                sparse = False

            # clip_region = self.get_window().get_clip_region()
            # sparse = not clip_region.contains_point(cx, cy)
        else:
            clip_region = self.window.get_clip_region()
            sparse = not clip_region.point_in(cx, cy)

        return clip_region, sparse
Exemple #2
0
    def render_get_clip_region(self, cr, device_bbox):
        # Could this be an alternative?
        #x0, y0, x1, y1 = cr.clip_extents()
        #sparse = True
        #clip_region = (x0, y0, x1-x0, y1-y0)
        #return clip_region, sparse

        # Get the area which needs to be updated, in device coordinates, and
        # determine whether the render is "sparse", [TODO: define what this
        # means]
        x, y, w, h = device_bbox
        cx, cy = x+w/2, y+h/2

        # As of 2012-07-08, Ubuntu Precise (LTS, unfortunately) and Debian
        # unstable(!) use python-cairo 1.8.8, which is too old to support
        # the cairo.Region return from Gdk.Window.get_clip_region() we
        # really need. They'll be important to support for a while, so we
        # have to use an inefficient workaround using the complete clip
        # rectangle for the update.
        #
        # http://stackoverflow.com/questions/6133622/
        # http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=653588
        # http://packages.ubuntu.com/python-cairo
        # http://packages.debian.org/python-cairo

        clip_exists, rect = gdk.cairo_get_clip_rectangle(cr)
        if clip_exists:
            # It's a wrapped cairo_rectangle_int_t, CairoRectangleInt
            area = (rect.x, rect.y, rect.width, rect.height)
            clip_region = area
            sparse = (cx < rect.x or cx > rect.x+rect.width
                      or cy < rect.y or cy > rect.y+rect.height)
        else:
            clip_region = None
            sparse = False

        return clip_region, sparse
Exemple #3
0
    def _render_get_clip_region(self, cr, device_bbox):
        """Get the area that needs to be updated, in device coords.

        Called when handling "draw" events.  This uses Cairo's clip
        region, which ultimately derives from the areas sent by
        lib.document.Document.canvas_area_modified().  These can be
        small or large if the update comes form the user drawing
        something. When panning or zooming the canvas, it's a full
        redraw, and the area corresponds to the entire display.

        :param cairo.Context cr: as passed to the "draw" event handler.
        :param tuple device_bbox: (x,y,w,h) widget extents
        :returns: (clipregion, sparse)
        :rtype: tuple

        The clip region return value is a tuple (x, y, w, h) containing
        the area to redraw in display coordinates, or None.

        This also determines whether the redraw is "sparse", meaning
        that the clip region returned does not contain the centre of the
        device bbox.

        """

        # Could this be an alternative?
        #x0, y0, x1, y1 = cr.clip_extents()
        #sparse = True
        #clip_region = (x0, y0, x1-x0, y1-y0)
        #return clip_region, sparse

        # Get the area which needs to be updated, in device coordinates, and
        # determine whether the render is "sparse", [TODO: define what this
        # means]
        x, y, w, h = device_bbox
        cx, cy = x+w/2, y+h/2

        # As of 2012-07-08, Ubuntu Precise (LTS, unfortunately) and Debian
        # unstable(!) use python-cairo 1.8.8, which does not support
        # the cairo.Region return from Gdk.Window.get_clip_region() we
        # really need. They'll be important to support for a while, so we
        # have to use an inefficient workaround using the complete clip
        # rectangle for the update.
        #
        # http://stackoverflow.com/questions/6133622/
        # http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=653588
        # http://packages.ubuntu.com/python-cairo
        # http://packages.debian.org/python-cairo
        #
        # Update 2015-08-14: actually, on Debian-derived systems you
        # need gir1.2-freedesktop 1.44.0, which contains a wrapping for
        # some cairoish return values from GTK/GDK, including
        # CairoRegion: cairo-1.0.typelib. On MSYS2, ensure you have
        # mingw-w64-i686-gobject-introspection-runtime or its x86_64
        # equivalent installed, also at version 1.44.

        clip_exists, rect = gdk.cairo_get_clip_rectangle(cr)
        if clip_exists:
            # It's a wrapped cairo_rectangle_int_t, CairoRectangleInt
            area = (rect.x, rect.y, rect.width, rect.height)
            clip_region = area
            sparse = (cx < rect.x or cx > rect.x+rect.width
                      or cy < rect.y or cy > rect.y+rect.height)
        else:
            clip_region = None
            sparse = False

        return clip_region, sparse
Exemple #4
0
    def _render_get_clip_region(self, cr, device_bbox):
        """Get the area that needs to be updated, in device coords.

        Called when handling "draw" events.  This uses Cairo's clip
        region, which ultimately derives from the areas sent by
        lib.document.Document.canvas_area_modified().  These can be
        small or large if the update comes form the user drawing
        something. When panning or zooming the canvas, it's a full
        redraw, and the area corresponds to the entire display.

        :param cairo.Context cr: as passed to the "draw" event handler.
        :param tuple device_bbox: (x,y,w,h) widget extents
        :returns: (clipregion, sparse)
        :rtype: tuple

        The clip region return value is a lib.helpers.Rect containing
        the area to redraw in display coordinates, or None.

        This also determines whether the redraw is "sparse", meaning
        that the clip region returned does not contain the centre of the
        device bbox.

        """

        # Could this be an alternative?
        #x0, y0, x1, y1 = cr.clip_extents()
        #sparse = True
        #clip_region = (x0, y0, x1-x0, y1-y0)
        #return clip_region, sparse

        # Get the area which needs to be updated, in device coordinates, and
        # determine whether the render is "sparse", [TODO: define what this
        # means]
        x, y, w, h = device_bbox
        cx, cy = x+w/2, y+h/2

        # As of 2012-07-08, Ubuntu Precise (LTS, unfortunately) and Debian
        # unstable(!) use python-cairo 1.8.8, which does not support
        # the cairo.Region return from Gdk.Window.get_clip_region() we
        # really need. They'll be important to support for a while, so we
        # have to use an inefficient workaround using the complete clip
        # rectangle for the update.
        #
        # http://stackoverflow.com/questions/6133622/
        # http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=653588
        # http://packages.ubuntu.com/python-cairo
        # http://packages.debian.org/python-cairo
        #
        # Update 2015-08-14: actually, on Debian-derived systems you
        # need gir1.2-freedesktop 1.44.0, which contains a wrapping for
        # some cairoish return values from GTK/GDK, including
        # CairoRegion: cairo-1.0.typelib. On MSYS2, ensure you have
        # mingw-w64-i686-gobject-introspection-runtime or its x86_64
        # equivalent installed, also at version 1.44.

        clip_exists, rect = gdk.cairo_get_clip_rectangle(cr)
        if clip_exists:
            # It's a wrapped cairo_rectangle_int_t, CairoRectangleInt
            # Convert to a better representation for our purposes,
            # noting https://github.com/mypaint/mypaint/issues/433
            rect = helpers.Rect(rect.x, rect.y, rect.width, rect.height)
            sparse = (
                cx < rect.x
                or cx > (rect.x + rect.w)
                or cy < rect.y
                or cy > (rect.y + rect.h)
            )
        else:
            rect = None
            sparse = False

        return rect, sparse