Add different background image modes

stretch_and_fill, scale_and_fit, scale_and_crop, tiling
This commit is contained in:
Vulcalien 2022-11-01 10:30:38 +01:00
parent 403bf540d0
commit 21529cec6c
2 changed files with 20 additions and 1 deletions

View File

@ -216,6 +216,7 @@ DEFAULTS = {
'background_darkness' : 0.5,
'background_type' : 'solid',
'background_image' : '',
'background_image_mode' : 'stretch_and_fill',
'backspace_binding' : 'ascii-del',
'delete_binding' : 'escape-sequence',
'color_scheme' : 'grey_on_black',

View File

@ -1135,17 +1135,35 @@ class Terminal(Gtk.VBox):
# save cairo context
cr.save()
# draw background image
image_mode = self.config['background_image_mode']
rect = self.vte.get_allocation()
xratio = float(rect.width) / float(self.background_image.get_width())
yratio = float(rect.height) / float(self.background_image.get_height())
cr.scale(xratio, yratio)
if image_mode == 'stretch_and_fill':
cr.scale(xratio, yratio)
elif image_mode == 'scale_and_fit':
ratio = min(xratio, yratio)
cr.scale(ratio, ratio)
elif image_mode == 'scale_and_crop':
ratio = max(xratio, yratio)
cr.scale(ratio, ratio)
# TODO add image alignment
cr.set_source_surface(self.background_image)
cr.get_source().set_filter(cairo.Filter.FAST)
if image_mode == 'tiling':
cr.get_source().set_extend(cairo.Extend.REPEAT)
cr.paint()
# draw transparent monochrome layer
Gdk.cairo_set_source_rgba(cr, self.bgcolor)
cr.paint()
# restore cairo context
cr.restore()