Add background image alignment
background_image_align_horiz: left, center, right background_image_align_vert: top, middle, bottom
This commit is contained in:
parent
21529cec6c
commit
df8890199c
|
@ -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',
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue