Esempio n. 1
0
        // Hover effect
        private void Glow(HolderImage icon, bool hover)
        {
            System.Windows.Media.Effects.DropShadowEffect dse = new System.Windows.Media.Effects.DropShadowEffect();
            dse.Color       = hover ? Colors.White : Colors.Black;
            dse.ShadowDepth = 0;
            dse.BlurRadius  = 5;

            icon.Effect = dse;
        }
Esempio n. 2
0
        // Create "Random" button outside of WrapPanel
        private void MakeRandomIcon()
        {
            double      iconSize         = Double.Parse(io.GetSetting("Main", "icon_size"));
            HolderImage randomIcon       = new HolderImage();
            BitmapImage randomIconSource = new BitmapImage();

            randomIconSource.BeginInit();
            randomIconSource.UriSource   = new Uri("dice.png", UriKind.Relative);
            randomIconSource.CacheOption = BitmapCacheOption.OnLoad;
            randomIconSource.EndInit();
            randomIcon.Source = randomIconSource;

            // Create the events handlers
            randomIcon.MouseEnter          += (sender, eventArgs) => { Glow(randomIcon, true); };
            randomIcon.MouseLeave          += (sender, eventArgs) => { Glow(randomIcon, false); };
            randomIcon.MouseLeftButtonDown += (sender, eventArgs) => { ButtonEffectDown(randomIcon); };
            Random random = new Random();

            if (!(io.gamesList.Count == 0))
            {
                randomIcon.MouseLeftButtonUp += (sender, eventArgs) => { LaunchGame(io.gamesList[random.Next(0, io.gamesList.Count - 1)]); };
            }
            randomIcon.VerticalAlignment   = VerticalAlignment.Center;
            randomIcon.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            randomIcon.Height  = iconSize / 2;
            randomIcon.Width   = iconSize / 2;
            bottomPanel.Height = iconSize;

            // Create a label and stack panel
            TextBlock lbl = new TextBlock();

            lbl.Text = "Random";
            lbl.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
            lbl.TextAlignment       = TextAlignment.Center;
            lbl.TextTrimming        = TextTrimming.CharacterEllipsis;
            lbl.Height     = Double.NaN; // auto
            lbl.Width      = Double.NaN; // auto
            lbl.FontFamily = MainWindow.lblTemplate.FontFamily;
            lbl.FontSize   = MainWindow.lblTemplate.FontSize;
            lbl.FontStyle  = MainWindow.lblTemplate.FontStyle;
            lbl.FontWeight = MainWindow.lblTemplate.FontWeight;
            lbl.Padding    = new Thickness(0, MainWindow.labelPaddingTop, 0, 0);
            lbl.Foreground = MainWindow.lblTemplate.Foreground;
            lbl.Effect     = new System.Windows.Media.Effects.DropShadowEffect();
            StackPanel sp = new StackPanel();

            sp.Width  = Double.NaN;
            sp.Height = Double.NaN;
            sp.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
            sp.Children.Add(randomIcon);
            sp.Children.Add(lbl);
            bottomPanel.Children.Add(sp);
        }
Esempio n. 3
0
        // Creates the button pressed down effect.
        private void ButtonEffectDown(HolderImage icon)
        {
            TranslateTransform trans = new TranslateTransform();

            icon.RenderTransform = trans;
            Double          currentLeft = icon.Margin.Left;
            Double          currentTop  = icon.Margin.Top;
            DoubleAnimation anim1       = new DoubleAnimation(icon.Margin.Left + 3, currentLeft, TimeSpan.FromSeconds(0.2));
            DoubleAnimation anim2       = new DoubleAnimation(icon.Margin.Top + 3, currentTop, TimeSpan.FromSeconds(0.2));

            trans.BeginAnimation(TranslateTransform.XProperty, anim1);
            trans.BeginAnimation(TranslateTransform.YProperty, anim2);
        }
Esempio n. 4
0
 // Remove icon visually, add to hiddenlist
 private void HideIcon(HolderImage icon)
 {
     try
     {
         StackPanel panel = (StackPanel)icon.Parent;
         io.hiddenList.Add(icon.game.ID.ToString());
         panel.Children.RemoveRange(0, panel.Children.Count);
         WrapPanel mainPanel = (WrapPanel)panel.Parent;
         mainPanel.Children.Remove(panel);
         UpdateLayout();
         io.WriteSetting("Main", "Hide", string.Join(",", io.hiddenList));
     }
     catch (Exception e)
     {
         System.Windows.MessageBox.Show("Could not hide icon. \n " + e.Message);
         io.LogToFile(e.ToString());
     }
 }
Esempio n. 5
0
        // Generates icons image and places them on the stack panel
        private void GenerateIcons()
        {
            // Get all icons from the icons directory
            io.iconsList = Directory.GetFiles(ICONS_DIR, "*.png", SearchOption.TopDirectoryOnly).ToList <string>();
            io.gamesList.Sort();

            foreach (Game game in io.gamesList)
            {
                io.LogToFile("Processing " + game.Name);
                // Skip hidden games.
                if (!game.Visible)
                {
                    continue;
                }
                // Try to get the icon
                string foundIcon = FindIcon(game);
                // Create the image to hold the icon
                HolderImage icon       = new HolderImage();
                BitmapImage iconSource = new BitmapImage();
                iconSource.BeginInit();
                if (string.IsNullOrEmpty(foundIcon) || !File.Exists(ICONS_DIR + foundIcon + ".png"))
                {
                    iconSource.UriSource = new Uri("default.png", UriKind.Relative);
                    io.LogToFile("Using default icon.");
                }
                else
                {
                    iconSource.UriSource = new Uri(ICONS_DIR + foundIcon + ".png", UriKind.Relative);
                    io.LogToFile("Using " + iconSource.UriSource.ToString());
                }

                iconSource.CacheOption = BitmapCacheOption.OnLoad;
                try
                {
                    iconSource.EndInit();
                }
                catch (InvalidOperationException ex)
                {
                    io.LogToFile("Error processing " + game.Name + ". " + ex.ToString());
                    continue;
                }
                icon.Source = iconSource;

                // Create the events handlers
                icon.MouseLeftButtonDown += (sender, eventArgs) => { ButtonEffectDown(icon); };
                icon.MouseLeftButtonUp   += (sender, eventArgs) => { LaunchGame(game); };
                icon.MouseEnter          += (sender, eventArgs) => { Glow(icon, true); };
                icon.MouseLeave          += (sender, eventArgs) => { Glow(icon, false); };
                // Add context menu
                System.Windows.Controls.ContextMenu menu  = new System.Windows.Controls.ContextMenu();
                System.Windows.Controls.MenuItem    mItem = new System.Windows.Controls.MenuItem();
                mItem.Header = "Hide";
                mItem.Click += (s, eventArgs) => { HideIcon(icon); };
                menu.Items.Add(mItem);
                icon.ContextMenu = menu;

                // Set the icons size based on config file
                icon.Width  = double.Parse(MainWindow.iconSize);
                icon.Height = double.Parse(MainWindow.iconSize);
                icon.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                icon.VerticalAlignment   = VerticalAlignment.Center;
                icon.Effect = new System.Windows.Media.Effects.DropShadowEffect();

                // Create a label and stack panel
                TextBlock lbl = new TextBlock();
                lbl.Text = game.Name;
                lbl.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                lbl.TextAlignment       = TextAlignment.Center;
                lbl.TextTrimming        = TextTrimming.CharacterEllipsis;
                lbl.Height     = Double.NaN; // auto
                lbl.Width      = Double.NaN; // auto
                lbl.FontFamily = MainWindow.lblTemplate.FontFamily;
                lbl.FontSize   = MainWindow.lblTemplate.FontSize;
                lbl.FontStyle  = MainWindow.lblTemplate.FontStyle;
                lbl.FontWeight = MainWindow.lblTemplate.FontWeight;
                lbl.Padding    = new Thickness(0, MainWindow.labelPaddingTop, 0, 0);
                lbl.Foreground = MainWindow.lblTemplate.Foreground;
                lbl.Effect     = new System.Windows.Media.Effects.DropShadowEffect();
                StackPanel sp = new StackPanel();
                sp.Width  = icon.Width + icon.Margin.Left + icon.Margin.Right;
                sp.Height = icon.Height + lbl.Height + icon.Margin.Top + icon.Margin.Bottom;
                sp.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                sp.Margin = new Thickness(MainWindow.iconSpacing[0], MainWindow.iconSpacing[1], MainWindow.iconSpacing[2], MainWindow.iconSpacing[3]);

                // Store the game object
                icon.game = game;

                // Add the icon to the stack panel created, then add that stack panel on the main panel.
                sp.Children.Add(icon);
                sp.Children.Add(lbl);
                spMain.Children.Add(sp);
            }
            if (!MainWindow.hideRandomIcon)
            {
                MakeRandomIcon();
            }
        }