Exemplo n.º 1
0
        private void LoadThemes(List <ThemeConfig> themes, string activeTheme = null)
        {
            Size         thumbnailSize = ThemeThumbLoader.GetThumbnailSize(this);
            ListViewItem focusedItem   = null;

            foreach (ThemeConfig theme in themes.ToList())
            {
                try
                {
                    using (Image thumbnailImage = ThemeThumbLoader.GetThumbnailImage(theme, thumbnailSize, true))
                    {
                        this.Invoke(new Action(() =>
                        {
                            listView1.LargeImageList.Images.Add(thumbnailImage);
                            string itemText = ThemeManager.GetThemeName(theme);
                            if (JsonConfig.settings.favoriteThemes != null &&
                                JsonConfig.settings.favoriteThemes.Contains(theme.themeId))
                            {
                                itemText = "★ " + itemText;
                            }
                            ListViewItem newItem = listView1.Items.Add(itemText, listView1.LargeImageList.Images.Count - 1);
                            newItem.Tag          = theme.themeId;

                            if (activeTheme == null || activeTheme == theme.themeId)
                            {
                                focusedItem = newItem;
                            }
                        }));
                    }
                }
                catch (OutOfMemoryException)
                {
                    ThemeLoader.HandleError(new FailedToCreateThumbnail(theme.themeId));
                }
            }

            this.Invoke(new Action(() =>
            {
                listView1.Sort();

                if (focusedItem == null)
                {
                    focusedItem = listView1.Items[0];
                }

                focusedItem.Selected = true;
                listView1.EnsureVisible(focusedItem.Index);

                ThemeThumbLoader.CacheThumbnails(listView1);
            }));
        }
Exemplo n.º 2
0
        public static string GeneratePreviewHtml(ThemeConfig theme)
        {
            string htmlText = Properties.Resources.preview_html;
            Dictionary <string, string> replacers = new Dictionary <string, string>();

            replacers.Add("basePath", new Uri(Environment.CurrentDirectory).AbsoluteUri);

            if (theme != null)
            {
                replacers.Add("themeName", ThemeManager.GetThemeName(theme));
                replacers.Add("themeAuthor", ThemeManager.GetThemeAuthor(theme));
                replacers.Add("previewMessage", string.Format(_("Previewing {0}"), "<span id=\"previewText\"></span>"));

                SolarData      solarData = SunriseSunsetService.GetSolarData(DateTime.Today);
                SchedulerState wpState   = AppContext.wpEngine.GetImageData(solarData, theme);

                if (ThemeManager.IsThemeDownloaded(theme))
                {
                    // TODO Why are images flickering?
                    ThemeImageData imageData   = GetThemeImageData(theme);
                    int            activeImage = imageData.FindIndex(entry => entry.Item2 == wpState.daySegment4) +
                                                 wpState.imageNumber;

                    replacers.Add("downloadMessage", "");
                    replacers.Add("carouselIndicators", GetCarouselIndicators(imageData.Count, activeImage));
                    replacers.Add("carouselItems", GetCarouselItems(imageData, activeImage, theme));
                }
                else
                {
                    replacers.Add("downloadMessage", string.Format("<div id=\"bottomCenterPanel\">{0}</div>",
                                                                   _("Theme is not downloaded. Click Download button to enable full preview.")));
                    replacers.Add("carouselIndicators", "");
                    replacers.Add("carouselItems", GetCarouselItems(wpState, theme));
                }
            }
            else
            {
                replacers.Add("themeAuthor", "Microsoft");

                int    startCarouselIndex = htmlText.IndexOf("<!--");
                int    endCarouselIndex   = htmlText.LastIndexOf("-->") + 3;
                string imageTag           = string.Format("<img src=\"{0}\">",
                                                          (new Uri(ThemeThumbLoader.GetWindowsWallpaper())).AbsoluteUri);

                htmlText = htmlText.Substring(0, startCarouselIndex) + imageTag +
                           htmlText.Substring(endCarouselIndex + 1);
            }

            return(RenderTemplate(htmlText, replacers));
        }
Exemplo n.º 3
0
        public ThemeDialog()
        {
            InitializeComponent();
            Localization.TranslateForm(this);

            this.Font         = SystemFonts.MessageBoxFont;
            this.FormClosing += OnFormClosing;

            int bestWidth = (ThemeThumbLoader.GetThumbnailSize(this).Width + 30) * 2 +
                            SystemInformation.VerticalScrollBarWidth;
            int oldWidth = this.imageListView1.Size.Width;

            this.imageListView1.Size = new Size(bestWidth, this.imageListView1.Height);
            this.Size = new Size(this.Width + bestWidth - oldWidth, this.Height);
            this.CenterToScreen();
        }
Exemplo n.º 4
0
        private void LoadPreviewImage(Image image)
        {
            int       width  = pictureBox1.Size.Width;
            int       height = pictureBox1.Size.Height;
            Rectangle screen = Screen.FromControl(this).Bounds;

            if ((screen.Y / (double)screen.X) <= (height / (double)width))
            {
                height = width * 9 / 16;
            }
            else
            {
                width = height * 16 / 9;
            }

            pictureBox1.Image = ThemeThumbLoader.ScaleImage(image, new Size(width, height));
        }
        public ThemeDialog()
        {
            InitializeComponent();
            Localization.TranslateForm(this);

            this.Font         = SystemFonts.MessageBoxFont;
            this.FormClosing += OnFormClosing;

            Size thumbnailSize = ThemeThumbLoader.GetThumbnailSize(this);
            int  newWidth      = (thumbnailSize.Width + 35) * 3 + SystemInformation.VerticalScrollBarWidth;
            int  newHeight     = (thumbnailSize.Height + this.Font.Height + 40) * 2;
            int  oldWidth      = this.imageListView1.Size.Width;
            int  oldHeight     = this.imageListView1.Size.Height;

            this.Size = new Size(this.Width + newWidth - this.imageListView1.Size.Width,
                                 this.Height + newHeight - this.imageListView1.Size.Height);
            this.CenterToScreen();
        }
Exemplo n.º 6
0
        private void LoadImportedThemes(List <ThemeConfig> themes, ImportDialog importDialog)
        {
            themes.Sort((t1, t2) => t1.themeId.CompareTo(t2.themeId));
            Size thumbnailSize        = ThemeThumbLoader.GetThumbnailSize(this);
            ImageListViewItem newItem = null;

            Task.Run(() =>
            {
                for (int i = 0; i < themes.Count; i++)
                {
                    this.Invoke(new Action(() => EnsureThemeNotDuplicated(themes[i].themeId)));

                    string themeName = ThemeManager.GetThemeName(themes[i]);
                    themeNames.Add(themeName);
                    themeNames.Sort();
                    int itemIndex = themeNames.IndexOf(themeName) + 1;

                    using (Image thumbnailImage = ThemeThumbLoader.GetThumbnailImage(themes[i], thumbnailSize, false))
                    {
                        this.Invoke(new Action(() =>
                        {
                            imageListView1.Items.Insert(itemIndex, ThemeManager.GetThemeName(themes[i]),
                                                        thumbnailImage);
                            newItem     = imageListView1.Items[itemIndex];
                            newItem.Tag = themes[i].themeId;
                        }));
                    }
                }

                if (newItem != null)
                {
                    this.Invoke(new Action(() =>
                    {
                        imageListView1.ClearSelection();
                        newItem.Selected = true;
                        imageListView1.EnsureVisible(newItem.Index);
                    }));
                }

                ThemeThumbLoader.CacheThumbnails(imageListView1.Items);
                importDialog.thumbnailsLoaded = true;
                this.Invoke(new Action(() => importDialog.Close()));
            });
        }
Exemplo n.º 7
0
        private void ThemeDialog_Load(object sender, EventArgs e)
        {
            previewer           = new WPF.ThemePreviewer();
            previewerHost.Child = previewer;

            listView1.ContextMenuStrip   = contextMenuStrip1;
            listView1.ListViewItemSorter = new CompareByItemText();
            SetWindowTheme(listView1.Handle, "Explorer", null);

            ImageList imageList = new ImageList();

            imageList.ColorDepth = ColorDepth.Depth32Bit;
            Size thumbnailSize = ThemeThumbLoader.GetThumbnailSize(this);

            imageList.ImageSize      = thumbnailSize;
            listView1.LargeImageList = imageList;

            imageList.Images.Add(ThemeThumbLoader.ScaleImage(windowsWallpaper, thumbnailSize));
            listView1.Items.Add(_("None"), 0);

            string[] displayNames = DisplayDevices.GetAllMonitorsFriendlyNames().ToArray();
            for (int i = 0; i < displayNames.Length; i++)
            {
                displayComboBox.Items.Add(string.Format(_("Display {0} - {1}"), i + 1, displayNames[i]));
            }
            displayComboBox.Enabled       = UwpDesktop.IsMultiDisplaySupported();
            displayComboBox.SelectedIndex = 0;

            string activeTheme = ThemeManager.currentTheme?.themeId;

            if (!JsonConfig.IsNullOrEmpty(JsonConfig.settings.multiDisplayThemes))
            {
                displayComboBox.SelectedIndex = 1;
                activeTheme = JsonConfig.settings.multiDisplayThemes[0];
            }
            else if (activeTheme == null && (JsonConfig.firstRun || JsonConfig.settings.themeName != null))
            {
                activeTheme = "Mojave_Desert";
            }

            Task.Run(new Action(() =>
                                LoadThemes(ThemeManager.themeSettings, (activeTheme != null) ? activeTheme : "")));
        }
Exemplo n.º 8
0
        private void LoadThemes(List <ThemeConfig> themes, string activeTheme = null)
        {
            Size         thumbnailSize = ThemeThumbLoader.GetThumbnailSize(this);
            ListViewItem focusedItem   = null;

            foreach (ThemeConfig theme in themes)
            {
                using (Image thumbnailImage = ThemeThumbLoader.GetThumbnailImage(theme, thumbnailSize, true))
                {
                    this.Invoke(new Action(() =>
                    {
                        listView1.LargeImageList.Images.Add(thumbnailImage);
                        ListViewItem newItem = listView1.Items.Add(ThemeManager.GetThemeName(theme),
                                                                   listView1.LargeImageList.Images.Count - 1);
                        newItem.Tag = theme.themeId;

                        if (activeTheme == null || activeTheme == theme.themeId)
                        {
                            focusedItem = newItem;
                        }
                    }));
                }
            }

            this.Invoke(new Action(() =>
            {
                listView1.Sort();

                if (focusedItem == null)
                {
                    focusedItem = listView1.Items[0];
                }

                focusedItem.Selected = true;
                listView1.EnsureVisible(focusedItem.Index);

                ThemeThumbLoader.CacheThumbnails(listView1);
            }));
        }
Exemplo n.º 9
0
        public ThemeDialog()
        {
            InitializeComponent();
            int oldButtonWidth = this.importButton.Width;

            Localization.TranslateForm(this);
            this.themeLinkLabel.Left += (this.importButton.Width - oldButtonWidth);

            this.Font         = SystemFonts.MessageBoxFont;
            this.FormClosing += OnFormClosing;
            this.FormClosed  += OnFormClosed;

            Rectangle bounds        = Screen.FromControl(this).Bounds;
            Size      thumbnailSize = ThemeThumbLoader.GetThumbnailSize(this);
            int       newWidth      = thumbnailSize.Width + SystemInformation.VerticalScrollBarWidth;
            int       oldWidth      = this.listView1.Size.Width;

            using (Graphics g = this.CreateGraphics())
            {
                newWidth += (int)Math.Ceiling(46 * g.DpiX / 96);
            }

            this.previewerHost.Anchor &= ~AnchorStyles.Left;
            this.displayComboBox.Width = newWidth;
            this.listView1.Width       = newWidth;
            this.downloadButton.Left  += (newWidth - oldWidth) / 2;
            this.applyButton.Left     += (newWidth - oldWidth) / 2;
            this.closeButton.Left     += (newWidth - oldWidth) / 2;
            this.Width += (newWidth - oldWidth);
            this.previewerHost.Anchor |= AnchorStyles.Left;

            int heightDiff = this.Height - this.previewerHost.Height;
            int widthDiff  = this.Width - this.previewerHost.Width;
            int bestHeight = bounds.Height * 5 / 8;
            int bestWidth  = (bestHeight - heightDiff) * bounds.Width / bounds.Height + widthDiff;

            this.Size = new Size(bestWidth, bestHeight);
            this.CenterToScreen();
        }
Exemplo n.º 10
0
        public ThemeDialog()
        {
            InitializeComponent();
            Localization.TranslateForm(this);

            this.Font         = SystemFonts.MessageBoxFont;
            this.FormClosing += OnFormClosing;
            this.FormClosed  += OnFormClosed;

            Rectangle bounds        = Screen.FromControl(this).Bounds;
            Size      thumbnailSize = ThemeThumbLoader.GetThumbnailSize(this);
            int       newWidth      = thumbnailSize.Width + SystemInformation.VerticalScrollBarWidth + 46;
            int       oldWidth      = this.listView1.Size.Width;

            this.previewerHost.Anchor &= ~AnchorStyles.Left;
            this.listView1.Width       = newWidth;
            this.downloadButton.Left  += (newWidth - oldWidth) / 2;
            this.applyButton.Left     += (newWidth - oldWidth) / 2;
            this.closeButton.Left     += (newWidth - oldWidth) / 2;
            this.Width += (newWidth - oldWidth);
            this.previewerHost.Anchor |= AnchorStyles.Left;
            this.Size = new Size(bounds.Width * 5 / 8, bounds.Height * 5 / 8);
            this.CenterToScreen();
        }