public static Color HslToRgb(HslColor hsl)
 {
     // Translated from JavaScript, part of coati
     double h = (double)hsl.H / 256;
     double s = (double)hsl.S / 255;
     double l = (double)hsl.L / 255;
     double q;
     if (l < 0.5)
         q = l * (1 + s);
     else
         q = l + s - l * s;
     double p = 2 * l - q;
     double[] t = new double[] { h + 1.0 / 3, h, h - 1.0 / 3 };
     byte[] rgb = new byte[3];
     for (int i = 0; i < 3; i++)
     {
         if (t[i] < 0) t[i]++;
         if (t[i] > 1) t[i]--;
         if (t[i] < 1.0 / 6)
             rgb[i] = (byte)Math.Round((p + ((q - p) * 6 * t[i])) * 255);
         else if (t[i] < 1.0 / 2)
             rgb[i] = (byte)Math.Round(q * 255);
         else if (t[i] < 2.0 / 3)
             rgb[i] = (byte)Math.Round((p + ((q - p) * 6 * (2.0 / 3 - t[i]))) * 255);
         else
             rgb[i] = (byte)Math.Round(p * 255);
     }
     return Color.FromArgb(rgb[0], rgb[1], rgb[2]);
 }
Ejemplo n.º 2
0
        public SettingsDialog(CoreMusicApp main)
        {
            app     = main;
            updater = Updater.Instance(app);
            InitializeComponent();
            Resize_Enabled = false;

            var skin = MaterialSkinManager.Instance;

            skin.AddFormToManage(this);

            colorWheel1.MouseUp += Color_Changed;
            HslColor set = ColorMath.RgbToHsl(Properties.Settings.Default.CustomColor);

            colorWheel1.Hue        = set.H;
            colorWheel1.Saturation = set.S;
            colorWheel1.Lightness  = set.L;

            materialCheckBox1.Checked            = Properties.Settings.Default.CustomTheme;
            materialCheckBox1.CheckStateChanged += (res, send) =>
            {
                string command;
                if (materialCheckBox1.Checked)
                {
                    command = "window.theme.enable()";
                    app.Invoke((MethodInvoker) delegate
                    {
                        app.darkTheme();
                    });
                }
                else
                {
                    command = "window.theme.disable()";
                    app.Invoke((MethodInvoker) delegate
                    {
                        app.lightTheme();
                    });
                }
                app.Invoke((MethodInvoker) delegate
                {
                    app.GPMBrowser.EvaluateScriptAsync("(function() {" + command + ";})();");
                });
            };

            materialCheckBox2.Checked            = Properties.Settings.Default.DesktopNotifications;
            materialCheckBox2.CheckStateChanged += (res, send) =>
            {
                if (materialCheckBox2.Checked)
                {
                    Properties.Settings.Default.DesktopNotifications = true;
                }
                else
                {
                    Properties.Settings.Default.DesktopNotifications = false;
                }
                Properties.Settings.Default.Save();
            };

            materialCheckBox3.Checked            = !Properties.Settings.Default.HoverControls;
            materialCheckBox3.CheckStateChanged += (res, send) =>
            {
                Properties.Settings.Default.HoverControls = !materialCheckBox3.Checked;
                app.Invoke((MethodInvoker) delegate
                {
                    if (Properties.Settings.Default.HoverControls)
                    {
                        app.GPMBrowser.EvaluateScriptAsync("window.GPM.mini.showControlsWhen('hover');");
                    }
                    else
                    {
                        app.GPMBrowser.EvaluateScriptAsync("window.GPM.mini.showControlsWhen('always');");
                    }
                });
            };

            materialCheckBox4.Checked            = Properties.Settings.Default.MiniAlwaysOnTop;
            materialCheckBox4.CheckStateChanged += (res, send) =>
            {
                Properties.Settings.Default.MiniAlwaysOnTop = materialCheckBox4.Checked;
            };

            lastFMUsername.Text      = Properties.Settings.Default.LastFMUsername;
            lastFMUsername.GotFocus += (res, send) =>
            {
                focusDefaultInputField(lastFMUsername, "Username", true);
            };
            lastFMUsername.LostFocus += async(res, send) =>
            {
                focusDefaultInputField(lastFMUsername, "Username", false);
                Properties.Settings.Default.LastFMUsername = lastFMUsername.Text;
                lastFMAuth(-1);
                await new LastFM().init();
                lastFMAuth((LastFM.user_key != null ? 1 : 0));
            };
            lastFMUsername.KeyPress += (send, e) =>
            {
                if (e.KeyChar == (char)13)
                {
                    lastFMPassword.Focus();
                }
            };

            lastFMPassword.Text      = Properties.Settings.Default.LastFMPassword;
            lastFMPassword.GotFocus += (res, send) =>
            {
                focusDefaultInputField(lastFMPassword, "1234567", true);
            };
            lastFMPassword.LostFocus += async(res, send) =>
            {
                focusDefaultInputField(lastFMPassword, "1234567", false);
                Properties.Settings.Default.LastFMPassword = lastFMPassword.Text;
                lastFMAuth(-1);
                await new LastFM().init();
                lastFMAuth((LastFM.user_key != null ? 1 : 0));
            };
            lastFMPassword.KeyPress += (send, e) =>
            {
                if (e.KeyChar == (char)13)
                {
                    lastFMUsername.Focus();
                }
            };

            installUpdateButton.Hide();
            installUpdateButton.Click += (sender, e) =>
            {
                Close();
                // For some reason we need to delay the closing of the main form by just enough for this one to close first....
                // #windowsPlz
                System.Threading.Timer timer = null;
                timer = new System.Threading.Timer((obj) =>
                {
                    timer.Dispose();
                    Dispose();
                    updater.Install();
                },
                                                   null, 100, System.Threading.Timeout.Infinite);
            };
            updater.OnStateChange += UpdateStateChange;
            UpdateStateChange(null, new UpdateStatusEventArgs(Updater.state, Updater.DownloadProgress));

            downloadProgress.BackColor = Properties.Settings.Default.CustomColor;
        }