diff options
Diffstat (limited to 'src/background.vala')
-rw-r--r-- | src/background.vala | 69 |
1 files changed, 61 insertions, 8 deletions
diff --git a/src/background.vala b/src/background.vala index 65a3365..07dce7e 100644 --- a/src/background.vala +++ b/src/background.vala @@ -2,6 +2,7 @@ * * Copyright (C) 2011,2012 Canonical Ltd * Copyright (C) 2015-2017 Mike Gabriel <mike.gabriel@das-netzwerkteam.de> + * Copyright (C) 2025 Robert Tari * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 as @@ -18,6 +19,7 @@ * Authors: Robert Ancell <robert.ancell@canonical.com> * Michael Terry <michael.terry@canonical.com> * Mike Gabriel <mike.gabriel@das-netzwerkteam.de> + * Robert Tari <robert@tari.in> */ class BackgroundLoader : Object @@ -171,17 +173,43 @@ class BackgroundLoader : Object var target_aspect = (double) width / height; var aspect = (double) image.width / image.height; double scale, offset_x = 0, offset_y = 0; + string sPosition = AGSettings.get_string (AGSettings.KEY_BACKGROUND_POSITION); + if (aspect > target_aspect) { /* Fit height and trim sides */ scale = (double) height / image.height; - offset_x = (image.width * scale - width) / 2; + + if (sPosition == "center") + { + offset_x = (image.width * scale - width) / 2; + } + else if (sPosition == "top-left" || sPosition == "bottom-left") + { + offset_x = 0; + } + else if (sPosition == "top-right" || sPosition == "bottom-right") + { + offset_x = (image.width * scale - width); + } } else { /* Fit width and trim top and bottom */ scale = (double) width / image.width; - offset_y = (image.height * scale - height) / 2; + + if (sPosition == "center") + { + offset_y = (image.height * scale - height) / 2; + } + else if (sPosition == "top-left" || sPosition == "top-right") + { + offset_y = 0; + } + else if (sPosition == "bottom-left" || sPosition == "bottom-right") + { + offset_y = (image.height * scale - height); + } } var scaled_image = new Gdk.Pixbuf (image.colorspace, image.has_alpha, image.bits_per_sample, width, height); @@ -194,6 +222,7 @@ class BackgroundLoader : Object { var grid_x_offset = get_grid_offset (image.width); var grid_y_offset = get_grid_offset (image.height); + var greeter = new ArcticaGreeter(); /* Create background */ var surface = new Cairo.Surface.similar (target_surface, Cairo.Content.COLOR, image.width, image.height); @@ -206,8 +235,31 @@ class BackgroundLoader : Object if (logo != null) { bc.save (); - var x = (int) (grid_x_offset + 1.1 * grid_size); - var y = (int) (image.height - 1.1 * grid_size - logo_height + grid_y_offset); + string sPosition = AGSettings.get_string (AGSettings.KEY_LOGO_POSITION); + int x = AGSettings.get_integer (AGSettings.KEY_LOGO_OFFSET_HORIZONTAL); + int y = AGSettings.get_integer (AGSettings.KEY_LOGO_OFFSET_VERTICAL); + + if (sPosition == "top-left") + { + x = (int) (grid_x_offset + (x * greeter.grid_size)); + y = (int) (grid_y_offset + ((y + 1) * greeter.grid_size)); + } + else if (sPosition == "top-right") + { + x = (int) (image.width - (x * greeter.grid_size) - logo_width + grid_x_offset); + y = (int) (grid_y_offset + ((y + 1) * greeter.grid_size)); + } + else if (sPosition == "bottom-left") + { + x = (int) (grid_x_offset + (x * greeter.grid_size)); + y = (int) (image.height - (y * greeter.grid_size) - logo_height + grid_y_offset); + } + else if (sPosition == "bottom-right") + { + x = (int) (image.width - (x * greeter.grid_size) - logo_width + grid_x_offset); + y = (int) (image.height - (y * greeter.grid_size) - logo_height + grid_y_offset); + } + bc.translate (x, y); bc.set_source_surface (logo, 0, 0); bc.paint_with_alpha (AGSettings.get_double (AGSettings.KEY_LOGO_ALPHA)); @@ -835,14 +887,15 @@ public class Background : Gtk.Fixed var height = get_allocated_height (); var grid_x_offset = get_grid_offset (width); var grid_y_offset = get_grid_offset (height); + var greeter = new ArcticaGreeter(); /* Overlay grid */ - var overlay_surface = new Cairo.Surface.similar (target_surface, Cairo.Content.COLOR_ALPHA, grid_size, grid_size); + var overlay_surface = new Cairo.Surface.similar (target_surface, Cairo.Content.COLOR_ALPHA, greeter.grid_size, greeter.grid_size); var oc = new Cairo.Context (overlay_surface); oc.rectangle (0, 0, 1, 1); - oc.rectangle (grid_size - 1, 0, 1, 1); - oc.rectangle (0, grid_size - 1, 1, 1); - oc.rectangle (grid_size - 1, grid_size - 1, 1, 1); + oc.rectangle (greeter.grid_size - 1, 0, 1, 1); + oc.rectangle (0, greeter.grid_size - 1, 1, 1); + oc.rectangle (greeter.grid_size - 1, greeter.grid_size - 1, 1, 1); oc.set_source_rgba (1.0, 1.0, 1.0, 0.25); oc.fill (); var overlay = new Cairo.Pattern.for_surface (overlay_surface); |