⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 estylebase.cs

📁 破解的飞信源代码
💻 CS
字号:
namespace Imps.Client.Pc
{
    using Imps.Client.Pc.Theme;
    using Imps.Client.Utils;
    using System;
    using System.Drawing;
    using System.Runtime.CompilerServices;
    using System.Windows.Forms;
    using System.Xml;

    public abstract class EStyleBase
    {
        public event EventHandler StyleChanged;

        protected EStyleBase()
        {
        }

        public static EAlignment AlignmentStringToValue(string s, EAlignment def)
        {
            switch (s)
            {
                case "left":
                    return EAlignment.left;

                case "top":
                    return EAlignment.top;

                case "right":
                    return EAlignment.right;

                case "bottom":
                    return EAlignment.bottom;

                case "center":
                    return EAlignment.center;

                case "stretch":
                    return EAlignment.stretch;
            }
            return def;
        }

        public virtual void ChangeColor(int hue, double sat, double lum)
        {
            if (this.StyleChanged != null)
            {
                this.StyleChanged(null, EventArgs.Empty);
            }
        }

        public virtual void Clone(EStyleBase style)
        {
        }

        public virtual void Dispose()
        {
            this.StyleChanged = null;
        }

        public static Rectangle GetAlignmentRectangle(Size imageSize, Rectangle drawingTo, EAlignment horAlign, EAlignment verAlign)
        {
            System.Drawing.Point location = new System.Drawing.Point(drawingTo.Left, drawingTo.Top);
            Size size = new Size(imageSize.Width, imageSize.Height);
            if (horAlign == EAlignment.left)
            {
                location.X = drawingTo.Left;
            }
            else if (horAlign == EAlignment.right)
            {
                location.X += drawingTo.Width - imageSize.Width;
            }
            else if (horAlign == EAlignment.center)
            {
                location.X += (drawingTo.Width - imageSize.Width) / 2;
            }
            if (verAlign == EAlignment.top)
            {
                location.Y = drawingTo.Top;
            }
            else if (verAlign == EAlignment.bottom)
            {
                location.Y += drawingTo.Height - imageSize.Height;
            }
            else if (verAlign == EAlignment.center)
            {
                location.Y += (drawingTo.Height - imageSize.Height) / 2;
            }
            return new Rectangle(location, size);
        }

        protected Color GetColorAttribute(XmlElement elem, string attrName)
        {
            Color empty = Color.Empty;
            if (elem.HasAttribute(attrName))
            {
                int argb = Convert.ToInt32(elem.GetAttribute(attrName), 0x10);
                empty = Color.FromArgb(0xff, Color.FromArgb(argb));
            }
            return empty;
        }

        protected Bitmap GetImageAttribute(XmlElement elem, string attrName)
        {
            Bitmap bitmap = null;
            if (elem.HasAttribute(attrName))
            {
                try
                {
                    bitmap = new Bitmap(ThemeManager.GetImagePath(elem.GetAttribute(attrName)));
                }
                catch (Exception exception)
                {
                    throw new Exception(exception.Message + ":" + attrName);
                }
            }
            return bitmap;
        }

        protected int GetIntegerAttribute(XmlElement elem, string attrName)
        {
            int num = 0;
            if (elem.HasAttribute(attrName))
            {
                int.TryParse(elem.GetAttribute(attrName), ref num);
                return num;
            }
            return 0;
        }

        protected RGB GetRGBAttribute(XmlElement elem, string attrName)
        {
            RGB rgb = null;
            if (elem.HasAttribute(attrName))
            {
                int argb = Convert.ToInt32(elem.GetAttribute(attrName), 0x10);
                rgb = new RGB(Color.FromArgb(0xff, Color.FromArgb(argb)));
            }
            return rgb;
        }

        public static Rectangle GetStretchRectangle(Size src, Rectangle dst, EStretch flag)
        {
            int width = src.Width;
            int height = src.Height;
            if (flag == EStretch.horizontal)
            {
                width = dst.Width;
            }
            else if (flag == EStretch.vertical)
            {
                height = dst.Height;
            }
            else if (flag == EStretch.fill)
            {
                width = dst.Width;
                height = dst.Height;
            }
            else if (((flag == EStretch.scale) && (width != 0)) && (height != 0))
            {
                double num3 = ((double) dst.Width) / ((double) width);
                double num4 = ((double) dst.Height) / ((double) height);
                if (num3 > num4)
                {
                    height = (int) Math.Floor(src.Height * num4);
                    width = (int) Math.Floor(src.Width * num4);
                }
                else
                {
                    height = (int) Math.Floor(src.Height * num3);
                    width = (int) Math.Floor(src.Width * num3);
                }
            }
            return new Rectangle(dst.Left, dst.Top, width, height);
        }

        protected string GetStringAttribute(XmlElement elem, string attrName)
        {
            string attribute = string.Empty;
            if (elem.HasAttribute(attrName))
            {
                attribute = elem.GetAttribute(attrName);
            }
            return attribute;
        }

        protected virtual void LoadStyle(XmlElement elem)
        {
        }

        public static Cursor NameToCursor(string name)
        {
            switch (name)
            {
                case "AppStarting":
                    return Cursors.AppStarting;

                case "Arrow":
                    return Cursors.Arrow;

                case "Cross":
                    return Cursors.Cross;

                case "Default":
                    return Cursors.Default;

                case "Hand":
                    return Cursors.Hand;

                case "Help":
                    return Cursors.Help;

                case "HSplit":
                    return Cursors.HSplit;

                case "IBeam":
                    return Cursors.IBeam;

                case "No":
                    return Cursors.No;

                case "NoMove2D":
                    return Cursors.NoMove2D;

                case "NoMoveHoriz":
                    return Cursors.NoMoveHoriz;

                case "NoMoveVert":
                    return Cursors.NoMoveVert;

                case "PanEast":
                    return Cursors.PanEast;

                case "PanNE":
                    return Cursors.PanNE;

                case "PanNorth":
                    return Cursors.PanNorth;

                case "PanNW":
                    return Cursors.PanNW;

                case "PanSE":
                    return Cursors.PanSE;

                case "PanSouth":
                    return Cursors.PanSouth;

                case "PanSW":
                    return Cursors.PanSW;

                case "PanWest":
                    return Cursors.PanWest;

                case "SizeAll":
                    return Cursors.SizeAll;

                case "SizeNESW":
                    return Cursors.SizeNESW;

                case "SizeNS":
                    return Cursors.SizeNS;

                case "SizeNWSE":
                    return Cursors.SizeNWSE;

                case "SizeWE":
                    return Cursors.SizeWE;

                case "UpArrow":
                    return Cursors.UpArrow;

                case "VSplit":
                    return Cursors.VSplit;

                case "WaitCursor":
                    return Cursors.WaitCursor;
            }
            return Cursors.Default;
        }

        public virtual void SetStyle(XmlElement elem)
        {
            this.LoadStyle(elem);
            if (this.StyleChanged != null)
            {
                this.StyleChanged(null, EventArgs.Empty);
            }
        }

        public static EStretch StretchStringToValue(string s, EStretch def)
        {
            switch (s)
            {
                case "horizontal":
                    return EStretch.horizontal;

                case "vertical":
                    return EStretch.vertical;

                case "none":
                    return EStretch.none;

                case "fill":
                    return EStretch.fill;

                case "scale":
                    return EStretch.scale;
            }
            return def;
        }

        public static System.Drawing.Point StyleLocationToWindowLocation(System.Drawing.Point location, EAlignment alignX, EAlignment alignY, Size windowSize)
        {
            System.Drawing.Point point = new System.Drawing.Point(location.X, location.Y);
            if (alignX == EAlignment.left)
            {
                point.X = location.X;
            }
            else if (alignX == EAlignment.right)
            {
                point.X = windowSize.Width - location.X;
            }
            if (alignY == EAlignment.top)
            {
                point.Y = location.Y;
                return point;
            }
            if (alignY == EAlignment.bottom)
            {
                point.Y = windowSize.Height - location.Y;
            }
            return point;
        }

        public static Rectangle StyleRectToWindowRect(Rectangle rect, EAlignment alignX, EAlignment alignY, EAlignment alignHor, EAlignment alignVer, Size windowSize)
        {
            System.Drawing.Point location = new System.Drawing.Point(rect.X, rect.Y);
            Size size = new Size(rect.Width, rect.Height);
            if (alignX == EAlignment.left)
            {
                location.X = location.X;
            }
            else if (alignX == EAlignment.right)
            {
                location.X = windowSize.Width - location.X;
            }
            if (alignY == EAlignment.top)
            {
                location.Y = location.Y;
            }
            else if (alignY == EAlignment.bottom)
            {
                location.Y = windowSize.Height - location.Y;
            }
            if (alignHor == EAlignment.center)
            {
                location.X = (windowSize.Width - size.Width) / 2;
            }
            else if (alignHor == EAlignment.stretch)
            {
                size.Width = (windowSize.Width - location.X) - size.Width;
            }
            if (alignVer == EAlignment.center)
            {
                location.Y = (windowSize.Height - rect.Height) / 2;
            }
            else if (alignVer == EAlignment.stretch)
            {
                size.Height = (windowSize.Height - location.Y) - size.Height;
            }
            return new Rectangle(location, size);
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -