def render_execute(self, cr, transformation, surface, sparse, mipmap_level, clip_region): translation_only = self.is_translation_only() model_bbox = surface.x, surface.y, surface.w, surface.h # not sure if it is a good idea to clip so tightly # has no effect right now because device_bbox is always smaller cr.rectangle(*model_bbox) cr.clip() if self.visualize_rendering: surface.pixbuf.fill((int(random.random()*0xff)<<16)+0x00000000) # Composite tiles = [] for tx, ty in surface.get_tiles(): if self.tile_is_visible( tx, ty, transformation, clip_region, sparse, translation_only ): tiles.append((tx, ty)) self.doc._layers.render_into(surface, tiles, mipmap_level, overlay=self.overlay_layer) gdk.cairo_set_source_pixbuf( cr, surface.pixbuf, round(surface.x), round(surface.y) ) # Pixelize at high zoom-in levels if self.scale > self.pixelize_threshold: pattern = cr.get_source() pattern.set_filter(cairo.FILTER_NEAREST) cr.paint() if self.visualize_rendering: # visualize painted bboxes (blue) cr.set_source_rgba(0, 0, random.random(), 0.4) cr.paint()
def _render_execute(self, cr, transformation, surface, sparse, mipmap_level, clip_region): """Renders tiles into a prepared pixbufsurface, then blits it. """ translation_only = self.is_translation_only() model_bbox = surface.x, surface.y, surface.w, surface.h # not sure if it is a good idea to clip so tightly # has no effect right now because device_bbox is always smaller cr.rectangle(*model_bbox) cr.clip() if self.visualize_rendering: surface.pixbuf.fill((int(random.random() * 0xff) << 16) + 0x00000000) fake_alpha_check_tile = None if not self._draw_real_alpha_checks: fake_alpha_check_tile = self._fake_alpha_check_tile # Determine which tiles to render. tiles = list(surface.get_tiles()) if sparse: tiles = [(tx, ty) for (tx, ty) in tiles if self._tile_is_visible( tx, ty, transformation, clip_region, translation_only, )] # Composite each stack of tiles in the exposed area # into the pixbufsurface. self.doc._layers.render_into( surface, tiles, mipmap_level, overlay=self.overlay_layer, opaque_base_tile=fake_alpha_check_tile, filter=self.display_filter, ) # Set the surface's underlying pixbuf as the source, then paint # it with Cairo. We don't care if it's pixelized at high zoom-in # levels: in fact, it'll look sharper and better. gdk.cairo_set_source_pixbuf(cr, surface.pixbuf, round(surface.x), round(surface.y)) if self.scale > self.pixelize_threshold: pattern = cr.get_source() pattern.set_filter(cairo.FILTER_NEAREST) cr.paint() # Using different random blues helps make one rendered bbox # distinct from the next when the user is painting. if self.visualize_rendering: cr.set_source_rgba(0, 0, random.random(), 0.4) cr.paint()
def _surface_from_file(file_location, ctx): pixbuf = GdkPixbuf.Pixbuf.new_from_file(file_location) surface = ctx.get_target().create_similar(cairo.CONTENT_COLOR_ALPHA, pixbuf.get_width(), pixbuf.get_height()) ctx_surface = cairo.Context(surface) Gdk.cairo_set_source_pixbuf(ctx_surface, pixbuf, 0, 0) ctx_surface.paint() return surface
def draw_cb(self, widget, cr): # Paint the base color, and the list's pixbuf. state_flags = widget.get_state_flags() style_context = widget.get_style_context() bg_color_gdk = style_context.get_background_color(state_flags) bg_color = uicolor.from_gdk_rgba(bg_color_gdk) cr.set_source_rgb(*bg_color.get_rgb()) cr.paint() gdk.cairo_set_source_pixbuf(cr, self.pixbuf, 0, 0) cr.paint() # border colors gdkrgba = style_context.get_background_color(state_flags | gtk.StateFlags.SELECTED) selected_color = uicolor.from_gdk_rgba(gdkrgba) gdkrgba = style_context.get_background_color(state_flags | gtk.StateFlags.NORMAL) insertion_color = uicolor.from_gdk_rgba(gdkrgba) # Draw borders last_i = len(self.itemlist) - 1 for i, b in enumerate(self.itemlist): rect_color = None if b is self.selected: rect_color = selected_color elif i == self.drag_insertion_index \ or (i == last_i and self.drag_insertion_index > i): rect_color = insertion_color if rect_color is None: continue x = (i % self.tiles_w) * self.total_w y = (i / self.tiles_w) * self.total_h w = self.total_w h = self.total_h def shrink(pixels, x, y, w, h): x += pixels y += pixels w -= 2 * pixels h -= 2 * pixels return (x, y, w, h) x, y, w, h = shrink(self.spacing_outside, x, y, w, h) for j in range(self.border_visible_outside_cell): x, y, w, h = shrink(-1, x, y, w, h) for j in xrange(self.border_visible + self.border_visible_outside_cell): cr.set_source_rgb(*rect_color.get_rgb()) cr.rectangle(x, y, w - 1, h - 1) # FIXME: check pixel alignment cr.stroke() x, y, w, h = shrink(1, x, y, w, h) return True
def _render_execute(self, cr, transformation, surface, sparse, mipmap_level, clip_rect, filter=None): """Renders tiles into a prepared pixbufsurface, then blits it. """ translation_only = self.is_translation_only() if self.visualize_rendering: surface.pixbuf.fill((int(random.random()*0xff) << 16)+0x00000000) fake_alpha_check_tile = None if not self._draw_real_alpha_checks: fake_alpha_check_tile = self._fake_alpha_check_tile # Determine which tiles to render. tiles = list(surface.get_tiles()) if sparse: tiles = [ (tx, ty) for (tx, ty) in tiles if self._tile_is_visible( tx, ty, transformation, clip_rect, translation_only, ) ] # Composite each stack of tiles in the exposed area # into the pixbufsurface. self.doc._layers.render_into( surface, tiles, mipmap_level, overlay = self.overlay_layer, opaque_base_tile = fake_alpha_check_tile, filter = filter, ) # Set the surface's underlying pixbuf as the source, then paint # it with Cairo. We don't care if it's pixelized at high zoom-in # levels: in fact, it'll look sharper and better. gdk.cairo_set_source_pixbuf( cr, surface.pixbuf, round(surface.x), round(surface.y) ) if self.scale > self.pixelize_threshold: pattern = cr.get_source() pattern.set_filter(cairo.FILTER_NEAREST) cr.paint()
def draw_cb(self, widget, cr): # Paint the base color, and the list's pixbuf. state_flags = widget.get_state_flags() style_context = widget.get_style_context() bg_color_gdk = style_context.get_background_color(state_flags) bg_color = RGBColor.new_from_gdk_rgba(bg_color_gdk) cr.set_source_rgb(*bg_color.get_rgb()) cr.paint() gdk.cairo_set_source_pixbuf(cr, self.pixbuf, 0, 0) cr.paint() # border colors gdkrgba = style_context.get_background_color( state_flags | gtk.StateFlags.SELECTED) selected_color = RGBColor.new_from_gdk_rgba(gdkrgba) gdkrgba = style_context.get_background_color( state_flags | gtk.StateFlags.NORMAL) insertion_color = RGBColor.new_from_gdk_rgba(gdkrgba) # Draw borders last_i = len(self.itemlist) - 1 for i, b in enumerate(self.itemlist): rect_color = None if b is self.selected: rect_color = selected_color elif i == self.drag_insertion_index \ or (i == last_i and self.drag_insertion_index > i): rect_color = insertion_color if rect_color is None: continue x = (i % self.tiles_w) * self.total_w y = (i / self.tiles_w) * self.total_h w = self.total_w h = self.total_h def shrink(pixels, x, y, w, h): x += pixels y += pixels w -= 2*pixels h -= 2*pixels return (x, y, w, h) x, y, w, h = shrink(self.spacing_outside, x, y, w, h) for j in range(self.border_visible_outside_cell): x, y, w, h = shrink(-1, x, y, w, h) for j in xrange(self.border_visible + self.border_visible_outside_cell): cr.set_source_rgb(*rect_color.get_rgb()) cr.rectangle(x, y, w-1, h-1) # FIXME: check pixel alignment cr.stroke() x, y, w, h = shrink(1, x, y, w, h) return True
def render_execute(self, cr, transformation, surface, sparse, mipmap_level, clip_region): translation_only = self.is_translation_only() model_bbox = surface.x, surface.y, surface.w, surface.h # not sure if it is a good idea to clip so tightly # has no effect right now because device_bbox is always smaller cr.rectangle(*model_bbox) cr.clip() if self.visualize_rendering: surface.pixbuf.fill((int(random.random() * 0xff) << 16) + 0x00000000) # Composite fake_alpha_check_tile = None if not self._draw_real_alpha_checks: fake_alpha_check_tile = self._fake_alpha_check_tile tiles = [] for tx, ty in surface.get_tiles(): if self.tile_is_visible(tx, ty, transformation, clip_region, sparse, translation_only): tiles.append((tx, ty)) self.doc._layers.render_into( surface, tiles, mipmap_level, overlay=self.overlay_layer, opaque_base_tile=fake_alpha_check_tile, filter=self.display_filter, ) gdk.cairo_set_source_pixbuf(cr, surface.pixbuf, round(surface.x), round(surface.y)) # Pixelize at high zoom-in levels if self.scale > self.pixelize_threshold: pattern = cr.get_source() pattern.set_filter(cairo.FILTER_NEAREST) cr.paint() if self.visualize_rendering: # visualize painted bboxes (blue) cr.set_source_rgba(0, 0, random.random(), 0.4) cr.paint()
def _render_execute(self, cr, transformation, surface, sparse, mipmap_level, clip_region): """Renders tiles into a prepared pixbufsurface, then blits it. """ translation_only = self.is_translation_only() model_bbox = surface.x, surface.y, surface.w, surface.h # not sure if it is a good idea to clip so tightly # has no effect right now because device_bbox is always smaller cr.rectangle(*model_bbox) cr.clip() if self.visualize_rendering: surface.pixbuf.fill((int(random.random()*0xff) << 16)+0x00000000) fake_alpha_check_tile = None if not self._draw_real_alpha_checks: fake_alpha_check_tile = self._fake_alpha_check_tile # Determine which tiles to render. tiles = list(surface.get_tiles()) if sparse: tiles = [ (tx, ty) for (tx, ty) in tiles if self._tile_is_visible( tx, ty, transformation, clip_region, translation_only, ) ] # Composite each stack of tiles in the exposed area # into the pixbufsurface. self.doc._layers.render_into( surface, tiles, mipmap_level, overlay = self.overlay_layer, opaque_base_tile = fake_alpha_check_tile, filter = self.display_filter, ) # Set the surface's underlying pixbuf as the source, then paint # it with Cairo. We don't care if it's pixelized at high zoom-in # levels: in fact, it'll look sharper and better. gdk.cairo_set_source_pixbuf( cr, surface.pixbuf, round(surface.x), round(surface.y) ) if self.scale > self.pixelize_threshold: pattern = cr.get_source() pattern.set_filter(cairo.FILTER_NEAREST) cr.paint() # Using different random blues helps make one rendered bbox # distinct from the next when the user is painting. if self.visualize_rendering: cr.set_source_rgba(0, 0, random.random(), 0.4) cr.paint()
def render_execute(self, cr, surface, sparse, mipmap_level, clip_region): translation_only = self.is_translation_only() model_bbox = surface.x, surface.y, surface.w, surface.h #print 'model bbox', model_bbox # not sure if it is a good idea to clip so tightly # has no effect right now because device_bbox is always smaller cr.rectangle(*model_bbox) cr.clip() layers = self.get_visible_layers() if self.visualize_rendering: surface.pixbuf.fill((int(random.random()*0xff)<<16)+0x00000000) background = None if self.current_layer_solo: background = self.neutral_background_pixbuf layers = [self.doc.layer] # this is for hiding instead #layers.pop(self.doc.layer_idx) if self.overlay_layer: idx = layers.index(self.doc.layer) layers.insert(idx+1, self.overlay_layer) # Composite tiles = [(tx, ty) for tx, ty in surface.get_tiles() if tile_is_visible(cr, tx, ty, clip_region, sparse, translation_only)] self.doc.render_into(surface, tiles, mipmap_level, layers, background) if translation_only and not pygtkcompat.USE_GTK3: # not sure why, but using gdk directly is notably faster than the same via cairo x, y = cr.user_to_device(surface.x, surface.y) self.window.draw_pixbuf(None, surface.pixbuf, 0, 0, int(x), int(y), dither=gdk.RGB_DITHER_MAX) else: #print 'Position (screen coordinates):', cr.user_to_device(surface.x, surface.y) if pygtkcompat.USE_GTK3: gdk.cairo_set_source_pixbuf(cr, surface.pixbuf, round(surface.x), round(surface.y)) else: cr.set_source_pixbuf(surface.pixbuf, round(surface.x), round(surface.y)) pattern = cr.get_source() # We could set interpolation mode here (eg nearest neighbour) #pattern.set_filter(cairo.FILTER_NEAREST) # 1.6s #pattern.set_filter(cairo.FILTER_FAST) # 2.0s #pattern.set_filter(cairo.FILTER_GOOD) # 3.1s #pattern.set_filter(cairo.FILTER_BEST) # 3.1s #pattern.set_filter(cairo.FILTER_BILINEAR) # 3.1s if self.scale > 2.8: # pixelize at high zoom-in levels pattern.set_filter(cairo.FILTER_NEAREST) cr.paint() if self.doc.frame_enabled: # Draw a overlay for all the area outside the "document area" cr.save() frame_rgba = self.app.preferences["frame.color_rgba"] frame_rgba = [helpers.clamp(c, 0, 1) for c in frame_rgba] cr.set_source_rgba(*frame_rgba) cr.set_operator(cairo.OPERATOR_OVER) mipmap_factor = 2**mipmap_level frame = self.doc.get_frame() cr.rectangle(frame[0]/mipmap_factor, frame[1]/mipmap_factor, frame[2]/mipmap_factor, frame[3]/mipmap_factor) cr.rectangle(*model_bbox) cr.set_fill_rule(cairo.FILL_RULE_EVEN_ODD) cr.fill() cr.restore() if self.visualize_rendering: # visualize painted bboxes (blue) cr.set_source_rgba(0, 0, random.random(), 0.4) cr.paint()
def render_execute(self, cr, transformation, surface, sparse, mipmap_level, clip_region): translation_only = self.is_translation_only() model_bbox = surface.x, surface.y, surface.w, surface.h #logger.debug('model bbox: %r', model_bbox) # not sure if it is a good idea to clip so tightly # has no effect right now because device_bbox is always smaller cr.rectangle(*model_bbox) cr.clip() layers = self.get_visible_layers() if self.visualize_rendering: surface.pixbuf.fill((int(random.random()*0xff)<<16)+0x00000000) background = None if self.current_layer_solo: background = self.neutral_background_pixbuf layers = [self.doc.layer] # this is for hiding instead #layers.pop(self.doc.layer_idx) if self.overlay_layer: idx = layers.index(self.doc.layer) layers.insert(idx+1, self.overlay_layer) # Composite tiles = [] for tx, ty in surface.get_tiles(): if self.tile_is_visible(tx, ty, transformation, clip_region, sparse, translation_only): tiles.append((tx, ty)) self.doc.render_into(surface, tiles, mipmap_level, layers, background) # The speedup below worked for GTK2, is there is an equivalent for GTK3? #if translation_only: # # not sure why, but using gdk directly is notably faster than the same via cairo # x, y = self.model_to_display(surface.x, surface.y) # self.window.draw_pixbuf(None, surface.pixbuf, 0, 0, int(x), int(y), # dither=gdk.RGB_DITHER_MAX) #logger.debug('Position (screen coordinates): %r', cr.model_to_display(surface.x, surface.y)) gdk.cairo_set_source_pixbuf(cr, surface.pixbuf, round(surface.x), round(surface.y)) pattern = cr.get_source() # We could set interpolation mode here (eg nearest neighbour) #pattern.set_filter(cairo.FILTER_NEAREST) # 1.6s #pattern.set_filter(cairo.FILTER_FAST) # 2.0s #pattern.set_filter(cairo.FILTER_GOOD) # 3.1s #pattern.set_filter(cairo.FILTER_BEST) # 3.1s #pattern.set_filter(cairo.FILTER_BILINEAR) # 3.1s # Pixelize at high zoom-in levels if self.scale > self.pixelize_threshold: pattern.set_filter(cairo.FILTER_NEAREST) cr.paint() if self.visualize_rendering: # visualize painted bboxes (blue) cr.set_source_rgba(0, 0, random.random(), 0.4) cr.paint()
def render_execute(self, cr, transformation, surface, sparse, mipmap_level, clip_region): translation_only = self.is_translation_only() model_bbox = surface.x, surface.y, surface.w, surface.h #logger.debug('model bbox: %r', model_bbox) # not sure if it is a good idea to clip so tightly # has no effect right now because device_bbox is always smaller cr.rectangle(*model_bbox) cr.clip() layers = self.get_visible_layers() if self.visualize_rendering: surface.pixbuf.fill((int(random.random() * 0xff) << 16) + 0x00000000) background = None if self.current_layer_solo: background = self.neutral_background_pixbuf layers = [self.doc.layer] # this is for hiding instead #layers.pop(self.doc.layer_idx) if self.overlay_layer: idx = layers.index(self.doc.layer) layers.insert(idx + 1, self.overlay_layer) # Composite tiles = [] for tx, ty in surface.get_tiles(): if self.tile_is_visible(tx, ty, transformation, clip_region, sparse, translation_only): tiles.append((tx, ty)) self.doc.render_into(surface, tiles, mipmap_level, layers, background) # The speedup below worked for GTK2, is there is an equivalent for GTK3? #if translation_only: # # not sure why, but using gdk directly is notably faster than the same via cairo # x, y = self.model_to_display(surface.x, surface.y) # self.window.draw_pixbuf(None, surface.pixbuf, 0, 0, int(x), int(y), # dither=gdk.RGB_DITHER_MAX) #logger.debug('Position (screen coordinates): %r', cr.model_to_display(surface.x, surface.y)) gdk.cairo_set_source_pixbuf(cr, surface.pixbuf, round(surface.x), round(surface.y)) pattern = cr.get_source() # We could set interpolation mode here (eg nearest neighbour) #pattern.set_filter(cairo.FILTER_NEAREST) # 1.6s #pattern.set_filter(cairo.FILTER_FAST) # 2.0s #pattern.set_filter(cairo.FILTER_GOOD) # 3.1s #pattern.set_filter(cairo.FILTER_BEST) # 3.1s #pattern.set_filter(cairo.FILTER_BILINEAR) # 3.1s # Pixelize at high zoom-in levels if self.scale > self.pixelize_threshold: pattern.set_filter(cairo.FILTER_NEAREST) cr.paint() if self.visualize_rendering: # visualize painted bboxes (blue) cr.set_source_rgba(0, 0, random.random(), 0.4) cr.paint()