Ejemplo n.º 1
0
    void Search(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.Enter)
        {
            var term = SearchBox.Text.Trim();
            if (term.Length == 0)
            {
                return;
            }

            if (IsUrl(term))
            {
                Status("Downloading...");

                // https://youtu.be/0fYL_qiDYf0
                if (IsYoutubeVideo(term))
                {
                    var url = GetFullScreenYoutubeUrl(term);
                    Browse(url);
                }
                else
                {
                    var image = Wallhaven.Download(term);

                    if (image != null)
                    {
                        SetWallpaper(image);
                    }
                    else
                    {
                        Browse(term);
                    }
                }

                Status();
            }
            else if (term.Contains("\\"))
            {
                Status("Opening...");
                SetWallpaper(Image.FromFile(term));
                Status();
            }
            else if (!Searcher.IsBusy)
            {
                Searcher.RunWorkerAsync(term);
            }
        }
    }
Ejemplo n.º 2
0
 public void RandomWallpaper(object sender, EventArgs e)
 {
     SetWallpaper(Wallhaven.Random().FirstOrDefault());
 }
Ejemplo n.º 3
0
    public SearchOverlay(FullScreenForm owner) : base(owner)
    {
        // Bounds?
        int ScreenWidth  = Screen.WorkingArea.Width - Width;
        int ScreenHeight = Screen.WorkingArea.Height - Height;

        var SearchPanel = new Panel
        {
            Height    = 71,
            BackColor = Color.Gray,
            Width     = (ScreenWidth / 5) * 2,
            Location  = new Point(ScreenWidth / 3, ScreenHeight / 3),
        };

        SearchLabel = new Label
        {
            Height    = 40,
            Text      = SearchLabelText,
            Font      = SearchFont,
            Dock      = DockStyle.Top,
            BackColor = Color.Black,
            ForeColor = Color.WhiteSmoke,
        };

        SearchBox = new TextBox
        {
            Height      = 40,
            Font        = SearchFont,
            Dock        = DockStyle.Top,
            BackColor   = Color.Black,
            Margin      = new Padding(10),
            ForeColor   = Color.WhiteSmoke,
            BorderStyle = BorderStyle.None,
        };

        SearchPanel.Controls.AddRange(new Control[]
        {
            SearchBox,
            SearchLabel
        });

        Grid = new Panel()
        {
            AutoScroll = false,
            Dock       = DockStyle.Bottom,
            Height     = 100,
            Padding    = new Padding(0, 0, 0, 40),
            BackColor  = Color.Black,
        };

        Grid.VerticalScroll.Enabled   = true;
        Grid.VerticalScroll.Visible   = false;
        Grid.HorizontalScroll.Enabled = true;
        Grid.HorizontalScroll.Visible = false;

        CloseButton = new Label
        {
            Text      = "×",
            Width     = 50,
            Height    = 50,
            Font      = new Font(SearchFont.Name, 20),        // 30
            ForeColor = Color.White,
            BackColor = Color.Black,
            TabStop   = false,
            Location  = new Point(Screen.WorkingArea.Width - 30, 0)            // 50
        };

        var Logo = new Label
        {
            AutoSize  = true,
            Font      = SearchFont,
            ForeColor = Color.White,
            Dock      = DockStyle.Left,
            Text      = $"Desktop2 ({GetResolution()})"
        };

        CloseButton.Click += (s, e) => (Owner as Form).Close();

        Controls.AddRange(new Control[]
        {
            Logo,
            CloseButton,
            Grid,
            SearchPanel
        });

        Searcher.DoWork += (s, e) =>
        {
            Status("Searching...");
            var term = (string)e.Argument;
            e.Result = term != null?Wallhaven.Search(term) : Wallhaven.Random();
        };

        Searcher.RunWorkerCompleted += (s, e) =>
        {
            LoadImages((IEnumerable <Image>)e.Result);
            Status();
        };

        SearchBox.KeyUp += Search;
        Searcher.RunWorkerAsync();
        SearchBox.Focus();
    }