def cairo_paint_pointer_overlay(context, cursor_data, px, py, start_time): if not cursor_data: return elapsed = max(0, monotonic_time() - start_time) if elapsed > 6: return cw = cursor_data[3] ch = cursor_data[4] xhot = cursor_data[5] yhot = cursor_data[6] pixels = cursor_data[8] x = px - xhot y = py - yhot alpha = max(0, (5.0 - elapsed) / 5.0) log("cairo_paint_pointer_overlay%s drawing pointer with cairo, alpha=%s", (context, x, y, start_time), alpha) context.translate(x, y) context.rectangle(0, 0, cw, ch) argb = unpremultiply_argb(pixels) img_data = memoryview_to_bytes(argb) pixbuf = pixbuf_new_from_data(img_data, COLORSPACE_RGB, True, 8, cw, ch, cw * 4) context.set_operator(cairo.OPERATOR_OVER) cairo_set_source_pixbuf(context, pixbuf, 0, 0) context.paint()
def cairo_paint_pixbuf(self, pixbuf, x, y): """ must be called from UI thread """ log("cairo_paint_pixbuf(%s, %s, %s) backing=%s", pixbuf, x, y, self._backing) #now use it to paint: gc = gdk_cairo_context(cairo.Context(self._backing)) gc.set_operator(cairo.OPERATOR_SOURCE) cairo_set_source_pixbuf(gc, pixbuf, x, y) gc.paint()
def cairo_paint_pixbuf(self, pixbuf, x, y): """ must be called from UI thread """ log("cairo_paint_pixbuf(%s, %s, %s) backing=%s", pixbuf, x, y, self._backing) #now use it to paint: gc = gdk_cairo_context(cairo.Context(self._backing)) cairo_set_source_pixbuf(gc, pixbuf, x, y) gc.paint() return True