Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

background image - respect ratio #644

Closed
ynikitenko opened this issue Sep 14, 2022 · 3 comments · Fixed by #713
Closed

background image - respect ratio #644

ynikitenko opened this issue Sep 14, 2022 · 3 comments · Fixed by #713
Assignees
Labels
enhancement New feature or request

Comments

@ynikitenko
Copy link

Is your feature request related to a problem? Please describe.
My background image ratio is wrong for my terminal (when it is not maximized).

Describe the solution you'd like
Would be great to add standard options for background images: repeat / tile, scale and crop, center, scale, scale and keep proportions.

Describe alternatives you've considered
Have no idea. I want the same background image to work when the window is small and when it is large. Maybe will have to use transparent background (and move the terminal to an empty desktop).

Additional context
Version 2.1.1-3, Arch Linux.

@Vulcalien Vulcalien added the enhancement New feature or request label Oct 19, 2022
@Vulcalien
Copy link
Member

This is the code of interest:

# file: terminatorlib/terminal.py
def background_draw(self, widget, cr):
    if self.background_image is None:
        return False

    # save cairo context
    cr.save()
    # draw background image
    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)
    cr.set_source_surface(self.background_image)
    cr.get_source().set_filter(cairo.Filter.FAST)
    cr.paint()
    # draw transparent monochrome layer
    Gdk.cairo_set_source_rgba(cr, self.bgcolor)
    cr.paint()
    # restore cairo context
    cr.restore()

And in particular, how xratio and yratio are calculated.
This way of calculating is is basically a "stretch and fill the terminal".

Scale and keep ratio, scale and crop, center (and don't scale I presume?) are pretty straight-forward.
Tiling could be a little harder and require more changes.

@Vulcalien Vulcalien self-assigned this Oct 19, 2022
@Vulcalien
Copy link
Member

Working on this, and I'm basically done with the code. Now only the GUI has to be implemented.

I have added these drawing modes: stretch_and_fill, scale_and_fit, scale_and_crop and tiling. There is also one
The new config options are: background_image_mode, background_image_align_horiz and background_image_align_vert.

I've added a few drawing modes and three config options:

  1. background_image_mode, with values:
    • stretch_and_fill
    • scale_and_fit
    • scale_and_crop
    • tiling
    • (this draws a single image, without scaling it; maybe call it single_image?)
  2. background_image_align_horiz, with values:
    • left (or anything)
    • center
    • right
  3. background_image_align_vert, with values:
    • top (or anything)
    • middle
    • bottom

The defaults are stretch_and_fill, center and center. This is the behavior that terminator has right now with images.
I'm writing this to check if everyone likes the option/value names.

@mattrose
Copy link
Member

mattrose commented Nov 2, 2022

The names all sound good. Good luck with the GUI stuff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants