From 21529cec6c3de7a6d2fe2a58ef1d72f79c8d304d Mon Sep 17 00:00:00 2001 From: Vulcalien Date: Tue, 1 Nov 2022 10:30:38 +0100 Subject: [PATCH] Add different background image modes stretch_and_fill, scale_and_fit, scale_and_crop, tiling --- terminatorlib/config.py | 1 + terminatorlib/terminal.py | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/terminatorlib/config.py b/terminatorlib/config.py index 80c29cbd..cdf96846 100644 --- a/terminatorlib/config.py +++ b/terminatorlib/config.py @@ -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', diff --git a/terminatorlib/terminal.py b/terminatorlib/terminal.py index 9f633a66..a5b2efda 100644 --- a/terminatorlib/terminal.py +++ b/terminatorlib/terminal.py @@ -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()