From 21529cec6c3de7a6d2fe2a58ef1d72f79c8d304d Mon Sep 17 00:00:00 2001 From: Vulcalien Date: Tue, 1 Nov 2022 10:30:38 +0100 Subject: [PATCH 1/3] 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() From df8890199cf3f26952816506fb3da7f30b2f7f75 Mon Sep 17 00:00:00 2001 From: Vulcalien Date: Tue, 1 Nov 2022 23:27:17 +0100 Subject: [PATCH 2/3] Add background image alignment background_image_align_horiz: left, center, right background_image_align_vert: top, middle, bottom --- terminatorlib/config.py | 2 ++ terminatorlib/terminal.py | 27 ++++++++++++++++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/terminatorlib/config.py b/terminatorlib/config.py index cdf96846..ae156329 100644 --- a/terminatorlib/config.py +++ b/terminatorlib/config.py @@ -217,6 +217,8 @@ DEFAULTS = { 'background_type' : 'solid', 'background_image' : '', 'background_image_mode' : 'stretch_and_fill', + 'background_image_align_horiz': 'center', + 'background_image_align_vert' : 'middle', 'backspace_binding' : 'ascii-del', 'delete_binding' : 'escape-sequence', 'color_scheme' : 'grey_on_black', diff --git a/terminatorlib/terminal.py b/terminatorlib/terminal.py index a5b2efda..964b5c40 100644 --- a/terminatorlib/terminal.py +++ b/terminatorlib/terminal.py @@ -1138,22 +1138,39 @@ class Terminal(Gtk.VBox): # draw background image image_mode = self.config['background_image_mode'] + image_align_horiz = self.config['background_image_align_horiz'] + image_align_vert = self.config['background_image_align_vert'] 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()) if image_mode == 'stretch_and_fill': - cr.scale(xratio, yratio) + # keep stretched ratios + xratio = xratio + yratio = yratio elif image_mode == 'scale_and_fit': ratio = min(xratio, yratio) - cr.scale(ratio, ratio) + xratio = yratio = ratio elif image_mode == 'scale_and_crop': ratio = max(xratio, yratio) - cr.scale(ratio, ratio) + xratio = yratio = ratio + else: + xratio = yratio = 1 + cr.scale(xratio, yratio) - # TODO add image alignment + xoffset = 0 + yoffset = 0 + if image_align_horiz == 'center': + xoffset = (rect.width / xratio - self.background_image.get_width()) / 2 + elif image_align_horiz == 'right': + xoffset = rect.width / xratio - self.background_image.get_width() - cr.set_source_surface(self.background_image) + if image_align_vert == 'middle': + yoffset = (rect.height / yratio - self.background_image.get_height()) / 2 + elif image_align_vert == 'bottom': + yoffset = rect.height / yratio - self.background_image.get_height() + + cr.set_source_surface(self.background_image, xoffset, yoffset) cr.get_source().set_filter(cairo.Filter.FAST) if image_mode == 'tiling': cr.get_source().set_extend(cairo.Extend.REPEAT) From 6cc3052ba70f3552ad966b5e3c0dbaf8c363bb94 Mon Sep 17 00:00:00 2001 From: Vulcalien Date: Tue, 14 Feb 2023 16:59:59 +0100 Subject: [PATCH 3/3] Add background image's drawing mode and alignment to preferences GUI --- terminatorlib/preferences.glade | 382 +++++++++++++++++++++++++------- terminatorlib/prefseditor.py | 80 ++++++- 2 files changed, 378 insertions(+), 84 deletions(-) diff --git a/terminatorlib/preferences.glade b/terminatorlib/preferences.glade index 57dc3620..b8ca1749 100644 --- a/terminatorlib/preferences.glade +++ b/terminatorlib/preferences.glade @@ -1,5 +1,5 @@ - + @@ -154,6 +154,60 @@ + + + + + + + + Left + + + Center + + + Right + + + + + + + + + + + Top + + + Middle + + + Bottom + + + + + + + + + + + Stretch and Fill + + + Scale and Fit + + + Scale and Crop + + + Tiling + + + @@ -2660,41 +2714,208 @@ - + True False + 12 - + True False - Background Image File: + vertical + + + True + False + + + True + False + Image File: + + + False + True + 5 + 0 + + + + + True + False + Choose file + + + + False + True + end + 1 + + + + + False + True + 0 + + + + + True + False + + + True + False + Drawing mode: + + + False + True + 5 + 0 + + + + + True + False + ImageDrawingModeListStore + 0 + + + + + 0 + + + + + False + True + end + 1 + + + + + False + True + 1 + + + + + True + False + 12 + True + + + True + False + + + True + False + Horizontal alignment: + + + False + True + 5 + 0 + + + + + True + False + ImageAlignHorizListStore + 1 + + + + + 0 + + + + + False + True + end + 1 + + + + + False + True + 0 + + + + + True + False + + + True + False + Vertical alignment: + + + False + True + 5 + 0 + + + + + True + False + ImageAlignVertListStore + 1 + + + + + 0 + + + + + False + True + end + 1 + + + + + False + True + 1 + + + + + False + True + 2 + + - - False - True - 5 - 0 - - - - - True - False - Choose file - - - - False - True - end - 1 - False True - 4 + 3 @@ -2783,7 +3004,7 @@ False True - 4 + 6 @@ -3721,12 +3942,12 @@ - + False + True True - False - filter keybindings + filter keybindings False @@ -3734,68 +3955,73 @@ 0 - - - True - True - adjustment4 - never - in - + True True - True - KeybindingsListStore - False - 0 - - - + adjustment4 + never + in - - Name - - - - 0 - + + True + True + True + KeybindingsListStore + False + 0 + + - - - - - Action - - - 1 - - - - - - - Keybinding - - - True - other - - + + Name + + + + 0 + + + + + + + Action + + + + 1 + + + + + + + Keybinding + + + True + other + + + + + 2 + 3 + + - - 2 - 3 - + + True + True + 1 + - - 3 diff --git a/terminatorlib/prefseditor.py b/terminatorlib/prefseditor.py index a333069f..2fc668d3 100755 --- a/terminatorlib/prefseditor.py +++ b/terminatorlib/prefseditor.py @@ -694,11 +694,42 @@ class PrefsEditor: elif self.config['background_type'] == 'image': guiget('image_radiobutton').set_active(True) self.update_background_tab() + # Background image + widget = guiget('background_image_file') + widget.set_filename(self.config['background_image']) + + widget = guiget('background_image_mode_combobox') + if self.config['background_image_mode'] == 'scale_and_fit': + widget.set_active(1) + elif self.config['background_image_mode'] == 'scale_and_crop': + widget.set_active(2) + elif self.config['background_image_mode'] == 'tiling': + widget.set_active(3) + else: + # default to stretch_and_fill + widget.set_active(0) + + widget = guiget('background_image_align_horiz_combobox') + if self.config['background_image_align_horiz'] == 'center': + widget.set_active(1) + elif self.config['background_image_align_horiz'] == 'right': + widget.set_active(2) + else: + # default to left + widget.set_active(0) + + widget = guiget('background_image_align_vert_combobox') + if self.config['background_image_align_vert'] == 'middle': + widget.set_active(1) + elif self.config['background_image_align_vert'] == 'bottom': + widget.set_active(2) + else: + # default to top + widget.set_active(0) + # Background shading widget = guiget('background_darkness_scale') widget.set_value(float(self.config['background_darkness'])) - widget = guiget('background_image_file') - widget.set_filename(self.config['background_image']) ## Scrolling tab # Scrollbar position @@ -999,6 +1030,41 @@ class PrefsEditor: self.config['background_image'] = widget.get_filename() self.config.save() + def on_background_image_mode_changed(self, widget): + selected = widget.get_active() + if selected == 1: + value = 'scale_and_fit' + elif selected == 2: + value = 'scale_and_crop' + elif selected == 3: + value = 'tiling' + else: + value = 'stretch_and_fill' + self.config['background_image_mode'] = value + self.config.save() + + def on_background_image_align_horiz_changed(self, widget): + selected = widget.get_active() + if selected == 1: + value = 'center' + elif selected == 2: + value = 'right' + else: + value = 'left' + self.config['background_image_align_horiz'] = value + self.config.save() + + def on_background_image_align_vert_changed(self, widget): + selected = widget.get_active() + if selected == 1: + value = 'middle' + elif selected == 2: + value = 'bottom' + else: + value = 'top' + self.config['background_image_align_vert'] = value + self.config.save() + def on_darken_background_scale_value_changed(self, widget): """Background darkness setting changed""" value = widget.get_value() # This one is rounded according to the UI. @@ -1603,10 +1669,12 @@ class PrefsEditor: self.config['background_type'] = backtype self.config.save() - if backtype == 'image': - guiget('background_image_file').set_sensitive(True) - else: - guiget('background_image_file').set_sensitive(False) + # toggle sensitivity of widgets related to background image + for element in ('background_image_file', + 'background_image_align_horiz_combobox', + 'background_image_align_vert_combobox', + 'background_image_mode_combobox'): + guiget(element).set_sensitive(backtype == 'image') if backtype in ('transparent', 'image'): guiget('darken_background_scale').set_sensitive(True)