| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338 | using System.Drawing;namespace Optimizer{    internal class ToggleSwitchRenderer : ToggleSwitchRendererBase    {        public Color BackColor { get; set; }        public Color LeftSideColor { get; set; }        public Color LeftSideColorHovered { get; set; }        public Color LeftSideColorPressed { get; set; }        public Color RightSideColor { get; set; }        public Color RightSideColorHovered { get; set; }        public Color RightSideColorPressed { get; set; }        public Color BorderColor { get; set; }        public Color ButtonColor { get; set; }        public Color ButtonColorHovered { get; set; }        public Color ButtonColorPressed { get; set; }        public ToggleSwitchRenderer()        {            switch (Options.CurrentOptions.Color)            {                case Theme.Caramel:                    LeftSideColor = Color.DarkOrange;                    LeftSideColorHovered = Color.DarkOrange;                    LeftSideColorPressed = Color.DarkOrange;                    break;                case Theme.Ocean:                    LeftSideColor = Color.DodgerBlue;                    LeftSideColorHovered = Color.DodgerBlue;                    LeftSideColorPressed = Color.DodgerBlue;                    break;                case Theme.Lime:                    LeftSideColor = Color.LimeGreen;                    LeftSideColorHovered = Color.LimeGreen;                    LeftSideColorPressed = Color.LimeGreen;                    break;                case Theme.Magma:                    LeftSideColor = Color.Tomato;                    LeftSideColorHovered = Color.Tomato;                    LeftSideColorPressed = Color.Tomato;                    break;                case Theme.Minimal:                    LeftSideColor = Color.Gray;                    LeftSideColorHovered = Color.Gray;                    LeftSideColorPressed = Color.Gray;                    break;                case Theme.Zerg:                    LeftSideColor = Color.MediumOrchid;                    LeftSideColorHovered = Color.MediumOrchid;                    LeftSideColorPressed = Color.MediumOrchid;                    break;            }            BorderColor = Color.FromArgb(20, 20, 20);            BackColor = Color.White;            RightSideColor = Color.FromArgb(40, 40, 40);            RightSideColorHovered = Color.FromArgb(40, 40, 40);            RightSideColorPressed = Color.FromArgb(40, 40, 40);            ButtonColor = Color.White;            ButtonColorHovered = Color.WhiteSmoke;            ButtonColorPressed = Color.WhiteSmoke;        }        public override void RenderBorder(Graphics g, Rectangle borderRectangle)        {            Color borderColor = !ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled ? BorderColor.ToGrayScale() : BorderColor;            g.SetClip(borderRectangle);            using (Pen borderPen = new Pen(borderColor))            {                g.DrawRectangle(borderPen, borderRectangle.X, borderRectangle.Y, borderRectangle.Width - 1, borderRectangle.Height - 1);            }            g.ResetClip();        }        public override void RenderLeftToggleField(Graphics g, Rectangle leftRectangle, int totalToggleFieldWidth)        {            Rectangle adjustedLeftRect = new Rectangle(leftRectangle.X + 2, 2, leftRectangle.Width - 2, leftRectangle.Height - 4);            if (adjustedLeftRect.Width > 0)            {                Color leftColor = LeftSideColor;                if (ToggleSwitch.IsLeftSidePressed)                    leftColor = LeftSideColorPressed;                else if (ToggleSwitch.IsLeftSideHovered)                    leftColor = LeftSideColorHovered;                if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)                    leftColor = leftColor.ToGrayScale();                g.SetClip(adjustedLeftRect);                using (Brush leftBrush = new SolidBrush(leftColor))                {                    g.FillRectangle(leftBrush, adjustedLeftRect);                }                if (ToggleSwitch.OnSideImage != null || !string.IsNullOrEmpty(ToggleSwitch.OnText))                {                    RectangleF fullRectangle = new RectangleF(leftRectangle.X + 2 - (totalToggleFieldWidth - leftRectangle.Width), 2, totalToggleFieldWidth - 2, ToggleSwitch.Height - 4);                    g.IntersectClip(fullRectangle);                    if (ToggleSwitch.OnSideImage != null)                    {                        Size imageSize = ToggleSwitch.OnSideImage.Size;                        Rectangle imageRectangle;                        int imageXPos = (int)fullRectangle.X;                        if (ToggleSwitch.OnSideScaleImageToFit)                        {                            Size canvasSize = new Size((int)fullRectangle.Width, (int)fullRectangle.Height);                            Size resizedImageSize = ImageHelper.RescaleImageToFit(imageSize, canvasSize);                            if (ToggleSwitch.OnSideAlignment == ToggleSwitchAlignment.Center)                            {                                imageXPos = (int)((float)fullRectangle.X + (((float)fullRectangle.Width - (float)resizedImageSize.Width) / 2));                            }                            else if (ToggleSwitch.OnSideAlignment == ToggleSwitchAlignment.Near)                            {                                imageXPos = (int)((float)fullRectangle.X + (float)fullRectangle.Width - (float)resizedImageSize.Width);                            }                            imageRectangle = new Rectangle(imageXPos, (int)((float)fullRectangle.Y + (((float)fullRectangle.Height - (float)resizedImageSize.Height) / 2)), resizedImageSize.Width, resizedImageSize.Height);                            if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)                                g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle, 0, 0, ToggleSwitch.OnSideImage.Width, ToggleSwitch.OnSideImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());                            else                                g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle);                        }                        else                        {                            if (ToggleSwitch.OnSideAlignment == ToggleSwitchAlignment.Center)                            {                                imageXPos = (int)((float)fullRectangle.X + (((float)fullRectangle.Width - (float)imageSize.Width) / 2));                            }                            else if (ToggleSwitch.OnSideAlignment == ToggleSwitchAlignment.Near)                            {                                imageXPos = (int)((float)fullRectangle.X + (float)fullRectangle.Width - (float)imageSize.Width);                            }                            imageRectangle = new Rectangle(imageXPos, (int)((float)fullRectangle.Y + (((float)fullRectangle.Height - (float)imageSize.Height) / 2)), imageSize.Width, imageSize.Height);                            if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)                                g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle, 0, 0, ToggleSwitch.OnSideImage.Width, ToggleSwitch.OnSideImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());                            else                                g.DrawImageUnscaled(ToggleSwitch.OnSideImage, imageRectangle);                        }                    }                    else if (!string.IsNullOrEmpty(ToggleSwitch.OnText))                    {                        SizeF textSize = g.MeasureString(ToggleSwitch.OnText, ToggleSwitch.OnFont);                        float textXPos = fullRectangle.X;                        if (ToggleSwitch.OnSideAlignment == ToggleSwitchAlignment.Center)                        {                            textXPos = (float)fullRectangle.X + (((float)fullRectangle.Width - (float)textSize.Width) / 2);                        }                        else if (ToggleSwitch.OnSideAlignment == ToggleSwitchAlignment.Near)                        {                            textXPos = (float)fullRectangle.X + (float)fullRectangle.Width - (float)textSize.Width;                        }                        RectangleF textRectangle = new RectangleF(textXPos, (float)fullRectangle.Y + (((float)fullRectangle.Height - (float)textSize.Height) / 2), textSize.Width, textSize.Height);                        Color textForeColor = ToggleSwitch.OnForeColor;                        if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)                            textForeColor = textForeColor.ToGrayScale();                        using (Brush textBrush = new SolidBrush(textForeColor))                        {                            g.DrawString(ToggleSwitch.OnText, ToggleSwitch.OnFont, textBrush, textRectangle);                        }                    }                }                g.ResetClip();            }        }        public override void RenderRightToggleField(Graphics g, Rectangle rightRectangle, int totalToggleFieldWidth)        {            Rectangle adjustedRightRect = new Rectangle(rightRectangle.X, 2, rightRectangle.Width - 2, rightRectangle.Height - 4);            if (adjustedRightRect.Width > 0)            {                Color rightColor = RightSideColor;                if (ToggleSwitch.IsRightSidePressed)                    rightColor = RightSideColorPressed;                else if (ToggleSwitch.IsRightSideHovered)                    rightColor = RightSideColorHovered;                if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)                    rightColor = rightColor.ToGrayScale();                g.SetClip(adjustedRightRect);                using (Brush rightBrush = new SolidBrush(rightColor))                {                    g.FillRectangle(rightBrush, adjustedRightRect);                }                if (ToggleSwitch.OffSideImage != null || !string.IsNullOrEmpty(ToggleSwitch.OnText))                {                    RectangleF fullRectangle = new RectangleF(rightRectangle.X, 2, totalToggleFieldWidth - 2, ToggleSwitch.Height - 4);                    g.IntersectClip(fullRectangle);                    if (ToggleSwitch.OffSideImage != null)                    {                        Size imageSize = ToggleSwitch.OffSideImage.Size;                        Rectangle imageRectangle;                        int imageXPos = (int)fullRectangle.X;                        if (ToggleSwitch.OffSideScaleImageToFit)                        {                            Size canvasSize = new Size((int)fullRectangle.Width, (int)fullRectangle.Height);                            Size resizedImageSize = ImageHelper.RescaleImageToFit(imageSize, canvasSize);                            if (ToggleSwitch.OffSideAlignment == ToggleSwitchAlignment.Center)                            {                                imageXPos = (int)((float)fullRectangle.X + (((float)fullRectangle.Width - (float)resizedImageSize.Width) / 2));                            }                            else if (ToggleSwitch.OffSideAlignment == ToggleSwitchAlignment.Far)                            {                                imageXPos = (int)((float)fullRectangle.X + (float)fullRectangle.Width - (float)resizedImageSize.Width);                            }                            imageRectangle = new Rectangle(imageXPos, (int)((float)fullRectangle.Y + (((float)fullRectangle.Height - (float)resizedImageSize.Height) / 2)), resizedImageSize.Width, resizedImageSize.Height);                            if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)                                g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle, 0, 0, ToggleSwitch.OnSideImage.Width, ToggleSwitch.OnSideImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());                            else                                g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle);                        }                        else                        {                            if (ToggleSwitch.OffSideAlignment == ToggleSwitchAlignment.Center)                            {                                imageXPos = (int)((float)fullRectangle.X + (((float)fullRectangle.Width - (float)imageSize.Width) / 2));                            }                            else if (ToggleSwitch.OffSideAlignment == ToggleSwitchAlignment.Far)                            {                                imageXPos = (int)((float)fullRectangle.X + (float)fullRectangle.Width - (float)imageSize.Width);                            }                            imageRectangle = new Rectangle(imageXPos, (int)((float)fullRectangle.Y + (((float)fullRectangle.Height - (float)imageSize.Height) / 2)), imageSize.Width, imageSize.Height);                            if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)                                g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle, 0, 0, ToggleSwitch.OnSideImage.Width, ToggleSwitch.OnSideImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());                            else                                g.DrawImageUnscaled(ToggleSwitch.OffSideImage, imageRectangle);                        }                    }                    else if (!string.IsNullOrEmpty(ToggleSwitch.OnText))                    {                        SizeF textSize = g.MeasureString(ToggleSwitch.OnText, ToggleSwitch.OffFont);                        float textXPos = fullRectangle.X;                        if (ToggleSwitch.OffSideAlignment == ToggleSwitchAlignment.Center)                        {                            textXPos = (float)fullRectangle.X + (((float)fullRectangle.Width - (float)textSize.Width) / 2);                        }                        else if (ToggleSwitch.OffSideAlignment == ToggleSwitchAlignment.Far)                        {                            textXPos = (float)fullRectangle.X + (float)fullRectangle.Width - (float)textSize.Width;                        }                        RectangleF textRectangle = new RectangleF(textXPos, (float)fullRectangle.Y + (((float)fullRectangle.Height - (float)textSize.Height) / 2), textSize.Width, textSize.Height);                        Color textForeColor = ToggleSwitch.OffForeColor;                        if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)                            textForeColor = textForeColor.ToGrayScale();                        using (Brush textBrush = new SolidBrush(textForeColor))                        {                            g.DrawString(ToggleSwitch.OnText, ToggleSwitch.OffFont, textBrush, textRectangle);                        }                    }                }            }        }        public override void RenderButton(Graphics g, Rectangle buttonRectangle)        {            Color buttonColor = ButtonColor;            if (ToggleSwitch.IsButtonPressed)            {                buttonColor = ButtonColorPressed;            }            else if (ToggleSwitch.IsButtonHovered)            {                buttonColor = ButtonColorHovered;            }            if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)                buttonColor = buttonColor.ToGrayScale();            g.SetClip(buttonRectangle);            using (Brush backBrush = new SolidBrush(buttonColor))            {                g.FillRectangle(backBrush, buttonRectangle);            }            g.ResetClip();        }        public override int GetButtonWidth()        {            return (int)((double)ToggleSwitch.Height / 3 * 2);        }        public override Rectangle GetButtonRectangle()        {            int buttonWidth = GetButtonWidth();            return GetButtonRectangle(buttonWidth);        }        public override Rectangle GetButtonRectangle(int buttonWidth)        {            Rectangle buttonRect = new Rectangle(ToggleSwitch.ButtonValue, 0, buttonWidth, ToggleSwitch.Height);            return buttonRect;        }    }}
 |