diff --git a/terminatorlib/config.py b/terminatorlib/config.py index 80c29cbd..ae156329 100644 --- a/terminatorlib/config.py +++ b/terminatorlib/config.py @@ -216,6 +216,9 @@ DEFAULTS = { 'background_darkness' : 0.5, '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/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) diff --git a/terminatorlib/terminal.py b/terminatorlib/terminal.py index 9f633a66..964b5c40 100644 --- a/terminatorlib/terminal.py +++ b/terminatorlib/terminal.py @@ -1135,17 +1135,52 @@ class Terminal(Gtk.VBox): # save cairo context cr.save() + # 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': + # keep stretched ratios + xratio = xratio + yratio = yratio + elif image_mode == 'scale_and_fit': + ratio = min(xratio, yratio) + xratio = yratio = ratio + elif image_mode == 'scale_and_crop': + ratio = max(xratio, yratio) + xratio = yratio = ratio + else: + xratio = yratio = 1 cr.scale(xratio, yratio) - cr.set_source_surface(self.background_image) + + 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() + + 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) + cr.paint() + # draw transparent monochrome layer Gdk.cairo_set_source_rgba(cr, self.bgcolor) cr.paint() + # restore cairo context cr.restore()