private void PrepareSLBitmap()
        {
            if (slBitmap != null)
            {
                slBitmap.Dispose();
            }

            int width = Math.Min(ClientSize.Width, ClientSize.Height) / 2;

            if (width < 10)
            {
                slBitmap = null;
                return;
            }

            // Prepare Bitmap
            slBitmap = new Bitmap(width, width);

            BitmapData bmData;

            byte[] bytes;
            BitmapReadBytes(slBitmap, out bytes, out bmData);
            for (int y = 0; y < width; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    Color c = ColorMath.HslToRgb(new HslColor(hue, (byte)(x * 255 / width), (byte)(y * 255 / width)));
                    BitmapSetPixel(bytes, bmData, x, y, c);
                }
            }
            BitmapWriteBytes(slBitmap, bytes, bmData);
        }
Beispiel #2
0
        private void Color_Changed(object sender, EventArgs e)
        {
            Properties.Settings.Default.CustomColor = ColorMath.HslToRgb(new HslColor(colorWheel1.Hue, colorWheel1.Saturation, colorWheel1.Lightness));
            Color  c   = Properties.Settings.Default.CustomColor;
            string RGB = "#" + c.R.ToString("X2") + c.G.ToString("X2") + c.B.ToString("X2");

            app.Invoke((MethodInvoker) delegate
            {
                app.GPMBrowser.EvaluateScriptAsync("(function() {window.CustomColor = '" + RGB + "'; window.ReDrawTheme();})();");
            });
        }
Beispiel #3
0
        private void Color_Changed(object sender, EventArgs e)
        {
            Properties.Settings.Default.CustomColor = ColorMath.HslToRgb(new HslColor(colorWheel1.Hue, colorWheel1.Saturation, colorWheel1.Lightness));
            downloadProgress.BackColor = Properties.Settings.Default.CustomColor;
            Color  c   = Properties.Settings.Default.CustomColor;
            string RGB = "#" + c.R.ToString("X2") + c.G.ToString("X2") + c.B.ToString("X2");

            app.Invoke((MethodInvoker) delegate
            {
                app.GPMBrowser.EvaluateScriptAsync("window.theme.updateTheme({foreSecondary: '" + RGB + "'});");
            });
        }
Beispiel #4
0
        public SettingsDialog(CoreMusicApp main)
        {
            app = main;
            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.turnOnCustom()";
                    app.Invoke((MethodInvoker) delegate
                    {
                        app.darkTheme();
                    });
                }
                else
                {
                    command = "window.turnOffCustom()";
                    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
                {
                    app.GPMBrowser.EvaluateScriptAsync("(function() {window.hoverControls = " + (!materialCheckBox3.Checked).ToString().ToLower() + "})();");
                });
            };

            materialRaisedButton1.Click += (res, send) =>
            {
                Properties.Settings.Default.Reset();
                Properties.Settings.Default.Save();
                DialogResult = DialogResult.Abort;
                Close();
            };

            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();
                }
            };
        }
        private void PrepareWheelBitmap()
        {
            if (wheelBitmap != null)
            {
                wheelBitmap.Dispose();
            }

            int   width  = Math.Min(ClientSize.Width, ClientSize.Height);
            Point center = new Point(width / 2, width / 2);

            if (width < 10)
            {
                wheelBitmap = null;
                return;
            }

            // Prepare Bitmap
            wheelBitmap = new Bitmap(width, width);

            // Fill background
            Graphics g = Graphics.FromImage(wheelBitmap);

            using (Brush b = new SolidBrush(Color.Transparent))
            {
                g.FillRectangle(b, 0, 0, width, width);
            }

            // Paint outer color wheel
            double minDist = width / 2 * 0.78;
            double maxDist = width / 2 - 1;
            double factor  = 128.0 / Math.PI;  // map -pi...pi to 0...255 => map 0...pi to 0...128

            BitmapData bmData;

            byte[] bytes;
            BitmapReadBytes(wheelBitmap, out bytes, out bmData);
            for (int y = 0; y < width; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    double dist = GetDistance(new Point(x, y), center);
                    byte   alpha;
                    if (dist < minDist - 0.5)
                    {
                        alpha = 0;
                    }
                    else if (dist < minDist + 0.5)
                    {
                        alpha = (byte)((0.5 - minDist + dist) * 255);
                    }
                    else if (dist < maxDist - 0.5)
                    {
                        alpha = 255;
                    }
                    else if (dist < maxDist + 0.5)
                    {
                        alpha = (byte)((0.5 + maxDist - dist) * 255);
                    }
                    else
                    {
                        alpha = 0;
                    }

                    if (alpha > 0)
                    {
                        double radAngle = Math.Atan2(y - center.Y, x - center.X);
                        // -pi   -> -180° -> 192
                        // -pi/2 ->  -90° -> 128
                        // 0     ->    0° ->  64
                        // pi/2  ->   90° ->   0
                        // pi    ->  180° -> 192
                        //
                        // y = a * x + t;
                        // a = -1
                        // t = 192
                        byte  hue = (byte)Mod((int)(-factor * radAngle + 192), 256);
                        Color c   = Color.FromArgb(alpha, ColorMath.HslToRgb(new HslColor(hue, 255, 128)));
                        BitmapSetPixel(bytes, bmData, x, y, c);
                    }
                }
            }
            BitmapWriteBytes(wheelBitmap, bytes, bmData);
        }
        //protected override void OnPaintBackground(PaintEventArgs pevent)
        //{
        //    if (VisualStyleRenderer.IsSupported)
        //    {
        //        // The VisualStyleElement does not matter, we're only drawing the parent's background
        //        VisualStyleRenderer r = new VisualStyleRenderer(VisualStyleElement.Window.Dialog.Normal);
        //        r.DrawParentBackground(pevent.Graphics, ClientRectangle, this);
        //    }
        //    else
        //    {
        //        base.OnPaintBackground(pevent);
        //    }
        //}
        // NOTE: Other solution: http://dotnetrix.co.uk/custom.htm#tip3

        protected override void OnPaint(PaintEventArgs pe)
        {
            // Draw outer color wheel bitmap
            if (wheelBitmap != null)
            {
                pe.Graphics.DrawImage(wheelBitmap, new Point());
            }

            // Draw inner color bitmap
            if (slBitmap != null)
            {
                pe.Graphics.DrawImage(slBitmap, new Point(slBitmap.Width / 2, slBitmap.Width / 2));
            }

            pe.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            // Draw hue marker
            double radAngle = (double)hue / 128 * Math.PI + Math.PI / 2;
            // sin(angle) = y / d
            // cos(angle) = x / d
            double d = 0.89 * wheelBitmap.Width / 2;
            int    x = (int)Math.Round(d * Math.Cos(radAngle));
            int    y = (int)-Math.Round(d * Math.Sin(radAngle));

            // Map center-relative coordinates to window coordinates
            x += wheelBitmap.Width / 2;
            y += wheelBitmap.Width / 2;
            Color c = ColorMath.ToGray(ColorMath.HslToRgb(new HslColor(hue, 255, 128))) > 128 ? Color.Black : Color.White;

            using (Pen p = new Pen(c))
            {
                pe.Graphics.DrawEllipse(p, x - 3, y - 3, 6, 6);
            }

            // Draw secondary hue markers
            if (secondaryHues != null)
            {
                foreach (byte sHue in secondaryHues)
                {
                    radAngle = (double)sHue / 128 * Math.PI + Math.PI / 2;
                    // sin(angle) = y / d
                    // cos(angle) = x / d
                    d = 0.89 * wheelBitmap.Width / 2;
                    x = (int)Math.Round(d * Math.Cos(radAngle));
                    y = (int)-Math.Round(d * Math.Sin(radAngle));
                    // Map center-relative coordinates to window coordinates
                    x += wheelBitmap.Width / 2;
                    y += wheelBitmap.Width / 2;
                    c  = ColorMath.ToGray(ColorMath.HslToRgb(new HslColor(sHue, 255, 128))) > 128 ? Color.Black : Color.White;
                    //using (Pen p = new Pen(Color.FromArgb(128, c)))
                    //{
                    //    pe.Graphics.DrawRectangle(p, x - 2, y - 2, 4, 4);
                    //}
                    using (Brush b = new SolidBrush(Color.FromArgb(128, c)))
                    {
                        pe.Graphics.FillRectangle(b, x - 2, y - 2, 4, 4);
                    }
                }
            }

            // Draw inner color marker
            x = slBitmap.Width / 2 + saturation * (slBitmap.Width - 1) / 255;
            y = slBitmap.Width / 2 + lightness * (slBitmap.Width - 1) / 255;
            c = ColorMath.ToGray(ColorMath.HslToRgb(new HslColor(hue, saturation, lightness))) > 128 ? Color.Black : Color.White;
            using (Pen p = new Pen(c))
            {
                pe.Graphics.DrawEllipse(p, x - 3, y - 3, 6, 6);
            }
        }
Beispiel #7
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;
        }