Exemplo n.º 1
0
        private Brush GetCairoBackgroundBrush_Image(string wallpaper, CairoWallpaperStyle wallpaperStyle)
        {
            ImageBrush backgroundImageBrush = null;

            if (!string.IsNullOrWhiteSpace(wallpaper) && Shell.Exists(wallpaper))
            {
                TryAndEat(() =>
                {
                    Uri backgroundImageUri            = new Uri(wallpaper, UriKind.Absolute);
                    BitmapImage backgroundBitmapImage = new BitmapImage(backgroundImageUri);
                    backgroundBitmapImage.Freeze();
                    backgroundImageBrush = new ImageBrush(backgroundBitmapImage);

                    switch (wallpaperStyle)
                    {
                    case CairoWallpaperStyle.Tile:
                        backgroundImageBrush.AlignmentX    = AlignmentX.Left;
                        backgroundImageBrush.AlignmentY    = AlignmentY.Top;
                        backgroundImageBrush.TileMode      = TileMode.Tile;
                        backgroundImageBrush.Stretch       = Stretch.Fill; // stretch to fill viewport, which is pixel size of image, as WPF is DPI-aware
                        backgroundImageBrush.Viewport      = new Rect(0, 0, (backgroundImageBrush.ImageSource as BitmapSource).PixelWidth, (backgroundImageBrush.ImageSource as BitmapSource).PixelHeight);
                        backgroundImageBrush.ViewportUnits = BrushMappingMode.Absolute;
                        break;

                    case CairoWallpaperStyle.Center:
                        // need to find a way to ignore image DPI for this case
                        backgroundImageBrush.AlignmentX = AlignmentX.Center;
                        backgroundImageBrush.AlignmentY = AlignmentY.Center;
                        backgroundImageBrush.TileMode   = TileMode.None;
                        backgroundImageBrush.Stretch    = Stretch.None;
                        break;

                    case CairoWallpaperStyle.Fit:
                        backgroundImageBrush.AlignmentX = AlignmentX.Center;
                        backgroundImageBrush.AlignmentY = AlignmentY.Center;
                        backgroundImageBrush.TileMode   = TileMode.None;
                        backgroundImageBrush.Stretch    = Stretch.Uniform;
                        break;

                    case CairoWallpaperStyle.Fill:
                    case CairoWallpaperStyle.Span:     // TODO: Impliment multiple monitor backgrounds
                        backgroundImageBrush.AlignmentX = AlignmentX.Center;
                        backgroundImageBrush.AlignmentY = AlignmentY.Center;
                        backgroundImageBrush.TileMode   = TileMode.None;
                        backgroundImageBrush.Stretch    = Stretch.UniformToFill;
                        break;

                    case CairoWallpaperStyle.Stretch:
                    default:
                        backgroundImageBrush.AlignmentX = AlignmentX.Center;
                        backgroundImageBrush.AlignmentY = AlignmentY.Center;
                        backgroundImageBrush.TileMode   = TileMode.None;
                        backgroundImageBrush.Stretch    = Stretch.Fill;
                        break;
                    }
                });
                backgroundImageBrush.Freeze();
            }
            return(backgroundImageBrush);
        }
Exemplo n.º 2
0
        private System.Windows.Media.Brush GetCairoBackgroundBrush_Image()
        {
            string wallpaper = Registry.GetValue(@"HKEY_CURRENT_USER\Control Panel\Desktop", "Wallpaper", "") as string;
            CairoWallpaperStyle wallpaperStyle = CairoWallpaperStyle.Stretch;

            return(GetCairoBackgroundBrush_Image(wallpaper, wallpaperStyle));
        }
Exemplo n.º 3
0
        private Brush GetCairoBackgroundBrush_Image()
        {
            string wallpaper = Settings.Instance.CairoBackgroundImagePath;

            CairoWallpaperStyle wallpaperStyle = CairoWallpaperStyle.Stretch;

            if (Enum.IsDefined(typeof(CairoWallpaperStyle), Settings.Instance.CairoBackgroundImageStyle))
            {
                wallpaperStyle = (CairoWallpaperStyle)Settings.Instance.CairoBackgroundImageStyle;
            }

            return(GetCairoBackgroundBrush_Image(wallpaper, wallpaperStyle) ?? GetCairoBackgroundBrush_Windows());
        }
Exemplo n.º 4
0
        private Brush GetCairoBackgroundBrush_Windows()
        {
            string wallpaper          = string.Empty;
            CairoWallpaperStyle style = CairoWallpaperStyle.Stretch;

            try
            {
                wallpaper = Registry.GetValue(@"HKEY_CURRENT_USER\Control Panel\Desktop", "Wallpaper", "") as string;
                string regWallpaperStyle = Registry.GetValue(@"HKEY_CURRENT_USER\Control Panel\Desktop", "WallpaperStyle", "") as string;
                string regTileWallpaper  = Registry.GetValue(@"HKEY_CURRENT_USER\Control Panel\Desktop", "TileWallpaper", "") as string;

                // https://docs.microsoft.com/en-us/windows/desktop/Controls/themesfileformat-overview
                switch ($"{regWallpaperStyle}{regTileWallpaper}")
                {
                case "01":     // Tiled { WallpaperStyle = 0; TileWallpaper = 1 }
                    style = CairoWallpaperStyle.Tile;
                    break;

                case "00":     // Centered { WallpaperStyle = 0; TileWallpaper = 0 }
                    style = CairoWallpaperStyle.Center;
                    break;

                case "60":     // Fit { WallpaperStyle = 6; TileWallpaper = 0 }
                    style = CairoWallpaperStyle.Fit;
                    break;

                case "100":     // Fill { WallpaperStyle = 10; TileWallpaper = 0 }
                    style = CairoWallpaperStyle.Fill;
                    break;

                case "220":     // Span { WallpaperStyle = 22; TileWallpaper = 0 }
                    style = CairoWallpaperStyle.Span;
                    break;

                case "20":     // Stretched { WallpaperStyle = 2; TileWallpaper = 0 }
                default:
                    style = CairoWallpaperStyle.Stretch;
                    break;
                }
            }
            catch (Exception ex)
            {
                CairoLogger.Instance.Debug("Problem loading Windows background", ex);
            }

            return(GetCairoBackgroundBrush_Image(wallpaper, style) ?? GetCairoBackgroundBrush_Color());
        }
Exemplo n.º 5
0
        private System.Windows.Media.Brush GetCairoBackgroundBrush_Windows()
        {
            // draw wallpaper
            string regWallpaper      = Registry.GetValue(@"HKEY_CURRENT_USER\Control Panel\Desktop", "Wallpaper", "") as string;
            string regWallpaperStyle = Registry.GetValue(@"HKEY_CURRENT_USER\Control Panel\Desktop", "WallpaperStyle", "") as string;
            string regTileWallpaper  = Registry.GetValue(@"HKEY_CURRENT_USER\Control Panel\Desktop", "TileWallpaper", "") as string;

            CairoWallpaperStyle style = CairoWallpaperStyle.Stretch;

            // https://docs.microsoft.com/en-us/windows/desktop/Controls/themesfileformat-overview
            switch ($"{regWallpaperStyle}{regTileWallpaper}")
            {
            case "01":     // Tiled { WallpaperStyle = 0; TileWallpaper = 1 }
                style = CairoWallpaperStyle.Tile;
                break;

            case "00":     // Centered { WallpaperStyle = 1; TileWallpaper = 0 }
                style = CairoWallpaperStyle.Center;
                break;

            case "60":     // Fit { WallpaperStyle = 6; TileWallpaper = 0 }
                style = CairoWallpaperStyle.Fit;
                break;

            case "100":     // Fill { WallpaperStyle = 10; TileWallpaper = 0 }
                style = CairoWallpaperStyle.Fill;
                break;

            case "220":     // Span { WallpaperStyle = 10; TileWallpaper = 0 }
                style = CairoWallpaperStyle.Span;
                break;

            case "20":     // Stretched { WallpaperStyle = 2; TileWallpaper = 0 }
            default:
                style = CairoWallpaperStyle.Stretch;
                break;
            }

            return(GetCairoBackgroundBrush_Image(regWallpaper, style));
        }
Exemplo n.º 6
0
        private Brush GetCairoBackgroundBrush_Picsum()
        {
            ImageBrush backgroundImageBrush = null;

            try
            {
                PicSumWallpaperClient client = new PicSumWallpaperClient(1920, 1080, true, 8);

                BitmapImage backgroundBitmapImage = client.Wallpaper as BitmapImage;
                backgroundBitmapImage.Freeze();
                backgroundImageBrush = new ImageBrush(backgroundBitmapImage);

                CairoWallpaperStyle wallpaperStyle = CairoWallpaperStyle.Stretch;
                if (Enum.IsDefined(typeof(CairoWallpaperStyle), Settings.Instance.BingWallpaperStyle))
                {
                    wallpaperStyle = (CairoWallpaperStyle)Settings.Instance.BingWallpaperStyle;
                }

                switch (wallpaperStyle)
                {
                case CairoWallpaperStyle.Tile:
                    backgroundImageBrush.AlignmentX    = AlignmentX.Left;
                    backgroundImageBrush.AlignmentY    = AlignmentY.Top;
                    backgroundImageBrush.TileMode      = TileMode.Tile;
                    backgroundImageBrush.Stretch       = Stretch.Fill; // stretch to fill viewport, which is pixel size of image, as WPF is DPI-aware
                    backgroundImageBrush.Viewport      = new Rect(0, 0, (backgroundImageBrush.ImageSource as BitmapSource).PixelWidth, (backgroundImageBrush.ImageSource as BitmapSource).PixelHeight);
                    backgroundImageBrush.ViewportUnits = BrushMappingMode.Absolute;
                    break;

                case CairoWallpaperStyle.Center:
                    // need to find a way to ignore image DPI for this case
                    backgroundImageBrush.AlignmentX = AlignmentX.Center;
                    backgroundImageBrush.AlignmentY = AlignmentY.Center;
                    backgroundImageBrush.TileMode   = TileMode.None;
                    backgroundImageBrush.Stretch    = Stretch.None;
                    break;

                case CairoWallpaperStyle.Fit:
                    backgroundImageBrush.AlignmentX = AlignmentX.Center;
                    backgroundImageBrush.AlignmentY = AlignmentY.Center;
                    backgroundImageBrush.TileMode   = TileMode.None;
                    backgroundImageBrush.Stretch    = Stretch.Uniform;
                    break;

                case CairoWallpaperStyle.Fill:
                case CairoWallpaperStyle.Span:     // TODO: Impliment multiple monitor backgrounds
                    backgroundImageBrush.AlignmentX = AlignmentX.Center;
                    backgroundImageBrush.AlignmentY = AlignmentY.Center;
                    backgroundImageBrush.TileMode   = TileMode.None;
                    backgroundImageBrush.Stretch    = Stretch.UniformToFill;
                    break;

                case CairoWallpaperStyle.Stretch:
                default:
                    backgroundImageBrush.AlignmentX = AlignmentX.Center;
                    backgroundImageBrush.AlignmentY = AlignmentY.Center;
                    backgroundImageBrush.TileMode   = TileMode.None;
                    backgroundImageBrush.Stretch    = Stretch.Fill;
                    break;
                }

                backgroundImageBrush.Freeze();
            }
            catch
            {
                return(GetCairoBackgroundBrush_Windows());
            }

            return(backgroundImageBrush);
        }
Exemplo n.º 7
0
        private Brush GetCairoBackgroundBrush_BingImageOfTheDay()
        {
            ImageBrush backgroundImageBrush = null;

            TryAndEat(() =>
            {
                SupportingClasses.BingPhotoOfDayClient.BingWallPaperClient client = new SupportingClasses.BingPhotoOfDayClient.BingWallPaperClient();
                client.DownLoad();

                BitmapImage backgroundBitmapImage = client.WPFPhotoOfTheDay as BitmapImage;
                backgroundBitmapImage.Freeze();
                backgroundImageBrush = new ImageBrush(backgroundBitmapImage);

                CairoWallpaperStyle wallpaperStyle = CairoWallpaperStyle.Stretch;
                if (Enum.IsDefined(typeof(CairoWallpaperStyle), Settings.Instance.BingWallpaperStyle))
                {
                    wallpaperStyle = (CairoWallpaperStyle)Settings.Instance.BingWallpaperStyle;
                }

                switch (wallpaperStyle)
                {
                case CairoWallpaperStyle.Tile:
                    backgroundImageBrush.AlignmentX    = AlignmentX.Left;
                    backgroundImageBrush.AlignmentY    = AlignmentY.Top;
                    backgroundImageBrush.TileMode      = TileMode.Tile;
                    backgroundImageBrush.Stretch       = Stretch.Fill; // stretch to fill viewport, which is pixel size of image, as WPF is DPI-aware
                    backgroundImageBrush.Viewport      = new Rect(0, 0, (backgroundImageBrush.ImageSource as BitmapSource).PixelWidth, (backgroundImageBrush.ImageSource as BitmapSource).PixelHeight);
                    backgroundImageBrush.ViewportUnits = BrushMappingMode.Absolute;
                    break;

                case CairoWallpaperStyle.Center:
                    // need to find a way to ignore image DPI for this case
                    backgroundImageBrush.AlignmentX = AlignmentX.Center;
                    backgroundImageBrush.AlignmentY = AlignmentY.Center;
                    backgroundImageBrush.TileMode   = TileMode.None;
                    backgroundImageBrush.Stretch    = Stretch.None;
                    break;

                case CairoWallpaperStyle.Fit:
                    backgroundImageBrush.AlignmentX = AlignmentX.Center;
                    backgroundImageBrush.AlignmentY = AlignmentY.Center;
                    backgroundImageBrush.TileMode   = TileMode.None;
                    backgroundImageBrush.Stretch    = Stretch.Uniform;
                    break;

                case CairoWallpaperStyle.Fill:
                case CairoWallpaperStyle.Span:     // TODO: Impliment multiple monitor backgrounds
                    backgroundImageBrush.AlignmentX = AlignmentX.Center;
                    backgroundImageBrush.AlignmentY = AlignmentY.Center;
                    backgroundImageBrush.TileMode   = TileMode.None;
                    backgroundImageBrush.Stretch    = Stretch.UniformToFill;
                    break;

                case CairoWallpaperStyle.Stretch:
                default:
                    backgroundImageBrush.AlignmentX = AlignmentX.Center;
                    backgroundImageBrush.AlignmentY = AlignmentY.Center;
                    backgroundImageBrush.TileMode   = TileMode.None;
                    backgroundImageBrush.Stretch    = Stretch.Fill;
                    break;
                }
            });

            backgroundImageBrush.Freeze();

            return(backgroundImageBrush);
        }
Exemplo n.º 8
0
        private System.Windows.Media.Brush GetCairoBackgroundBrush_Image(string wallpaper, CairoWallpaperStyle wallpaperStyle)
        {
            ImageBrush backgroundImageBrush = null;

            if (!string.IsNullOrWhiteSpace(wallpaper) && Shell.Exists(wallpaper))
            {
                TryAndEat(() =>
                {
                    Uri backgroundImageUri            = new Uri(wallpaper, UriKind.Absolute);
                    BitmapImage backgroundBitmapImage = new BitmapImage(backgroundImageUri);
                    backgroundImageBrush = new ImageBrush(backgroundBitmapImage);

                    switch (wallpaperStyle)
                    {
                    case CairoWallpaperStyle.Tile:
                        backgroundImageBrush.AlignmentX    = AlignmentX.Left;
                        backgroundImageBrush.AlignmentY    = AlignmentY.Top;
                        backgroundImageBrush.TileMode      = TileMode.Tile;
                        backgroundImageBrush.Stretch       = Stretch.None;
                        backgroundImageBrush.Viewport      = new Rect(0, 0, backgroundImageBrush.ImageSource.Width, backgroundImageBrush.ImageSource.Height);
                        backgroundImageBrush.ViewportUnits = BrushMappingMode.Absolute;
                        break;

                    case CairoWallpaperStyle.Center:
                        backgroundImageBrush.AlignmentX = AlignmentX.Center;
                        backgroundImageBrush.AlignmentY = AlignmentY.Center;
                        backgroundImageBrush.TileMode   = TileMode.None;
                        backgroundImageBrush.Stretch    = Stretch.None;
                        break;

                    case CairoWallpaperStyle.Fit:
                        backgroundImageBrush.AlignmentX = AlignmentX.Center;
                        backgroundImageBrush.AlignmentY = AlignmentY.Center;
                        backgroundImageBrush.TileMode   = TileMode.None;
                        backgroundImageBrush.Stretch    = Stretch.Uniform;
                        break;

                    case CairoWallpaperStyle.Fill:
                    case CairoWallpaperStyle.Span:     // TODO: Impliment multiple monitor backgrounds
                        backgroundImageBrush.AlignmentX = AlignmentX.Center;
                        backgroundImageBrush.AlignmentY = AlignmentY.Center;
                        backgroundImageBrush.TileMode   = TileMode.None;
                        backgroundImageBrush.Stretch    = Stretch.UniformToFill;
                        break;

                    case CairoWallpaperStyle.Stretch:
                    default:
                        backgroundImageBrush.AlignmentX = AlignmentX.Center;
                        backgroundImageBrush.AlignmentY = AlignmentY.Center;
                        backgroundImageBrush.TileMode   = TileMode.None;
                        backgroundImageBrush.Stretch    = Stretch.Fill;
                        break;
                    }
                });
            }
            return(backgroundImageBrush);
        }