Ejemplo n.º 1
0
        // Просто проверка. Здесь фактически методы расширения не используются как методы расширения,
        // поэтому этот метод можно просто рассматривать как проверку всех методов из класса с методами
        // расширений через делегаты :)
        static void FastCheckWithDelegates(string[] wordList)
        {
            CheckStyle[] checks = new CheckStyle[] {
                MyExtensions.IsRussian, MyExtensions.IsEnglish, MyExtensions.IsNumber, MyExtensions.IsMixed
            };

            //for (int i = 0; i < wordList.Length; i++)
            //{
            //    Console.WriteLine($"Word is = {wordList[i]}");
            //    for (int j = 0; j < checks.Length; j++)
            //    {
            //        Console.WriteLine(
            //            $"   Check is = {checks[j].Method.Name,10} == {checks[j].Invoke(wordList[i])}");
            //        //Console.WriteLine($"   Result is = {checks[j].Invoke(wordList[i])}");
            //    }
            //    Console.WriteLine("===========================================");
            //    Console.WriteLine();
            //}

            // Refactored
            foreach (var word in wordList)
            {
                Console.WriteLine($"Word is = {word}");
                foreach (var check in checks)
                {
                    Console.WriteLine($"   Check is = {check.Method.Name,10} == {check.Invoke(word)}");
                }
                Console.WriteLine("===========================================");
                Console.WriteLine();
            }
        }
Ejemplo n.º 2
0
 /// <summary>Initializes a new instance of the <see cref="ToggleCheckmarkBase" /> class.</summary>
 protected ToggleCheckmarkBase()
 {
     _boxSpacing = 2;
     _box        = new Rectangle(0, 0, 14, 14);
     _animation  = Settings.DefaultValue.Animation;
     _checkStyle = new CheckStyle(ClientRectangle);
     _border     = new Border();
     _colorState = new ControlColorState();
     ConfigureAnimation(new[] { 0.05, 0.10, 0.08 }, new[] { EffectType.EaseInOut, EffectType.Linear });
 }
Ejemplo n.º 3
0
        /// <summary>Draws a check box control in the specified state and location.</summary>
        /// <param name="graphics">The graphics to draw on.</param>
        /// <param name="border">The border type.</param>
        /// <param name="checkStyle">The check mark type.</param>
        /// <param name="rectangle">The rectangle that represents the dimensions of the check box.</param>
        /// <param name="checkState">The check State.</param>
        /// <param name="enabled">The state to draw the check mark in.</param>
        /// <param name="color">The background color.</param>
        /// <param name="backgroundImage">The background Image.</param>
        /// <param name="mouseStates">The mouse States.</param>
        public static void DrawCheckBox(Graphics graphics, Border border, CheckStyle checkStyle, Rectangle rectangle, bool checkState, bool enabled, Color color, Image backgroundImage, MouseStates mouseStates)
        {
            GraphicsPath _boxGraphicsPath = VisualBorderRenderer.CreateBorderTypePath(rectangle, border);

            graphics.SetClip(_boxGraphicsPath);
            VisualBackgroundRenderer.DrawBackground(graphics, color, backgroundImage, mouseStates, rectangle, border);

            if (checkState)
            {
                DrawCheckMark(graphics, checkStyle, rectangle, enabled);
            }

            VisualBorderRenderer.DrawBorderStyle(graphics, border, _boxGraphicsPath, mouseStates);
            graphics.ResetClip();
        }
Ejemplo n.º 4
0
        /// <summary>Initializes a new instance of the <see cref="VisualCheckBox" /> class.</summary>
        public VisualCheckBox()
        {
            Size = new Size(125, 23);

            Border = new Border {
                Rounding = DefaultConstants.Rounding.BoxRounding
            };

            CheckStyle = new CheckStyle(ClientRectangle)
            {
                Style = CheckStyle.CheckType.Checkmark
            };

            UpdateTheme(ThemeManager.Theme);
        }
Ejemplo n.º 5
0
        /// <summary>Initializes a new instance of the <see cref="VisualRadioButton" /> class.</summary>
        public VisualRadioButton()
        {
            Cursor = Cursors.Hand;
            Size   = new Size(125, 23);

            Border = new Border {
                Rounding = Settings.DefaultValue.Rounding.RoundedRectangle
            };

            CheckStyle = new CheckStyle(ClientRectangle)
            {
                Style = CheckStyle.CheckType.Shape, ShapeRounding = Settings.DefaultValue.Rounding.Default, Bounds = new Rectangle(new Point(), new Size(8, 8))
            };

            UpdateTheme(ThemeManager.Theme);
        }
Ejemplo n.º 6
0
        /// <summary>Initializes a new instance of the <see cref="VisualCheckBox" /> class.</summary>
        public VisualCheckBox()
        {
            Cursor = Cursors.Hand;
            Size   = new Size(125, 23);

            Border = new Border {
                Rounding = Settings.DefaultValue.Rounding.BoxRounding
            };

            CheckStyle = new CheckStyle(ClientRectangle)
            {
                Style = CheckStyle.CheckType.Character
            };

            UpdateTheme(Settings.DefaultValue.DefaultStyle);
        }
Ejemplo n.º 7
0
        private void m_CheckStyleCombo_SelectedIndexChanged(object sender, EventArgs e)
        {
            object o = m_CheckStyleCombo.SelectedItem;

            if (!(o is CheckStyle))
            {
                return;
            }

            CheckStyle style = (CheckStyle)o;
            int        count = Controls.Count;
            NListBox   list;

            for (int i = 0; i < count; i++)
            {
                list = Controls[i] as NListBox;
                if (list == null)
                {
                    continue;
                }

                list.CheckStyle = style;
            }
        }
Ejemplo n.º 8
0
 /// <summary>Draws a check box control in the specified state and with the specified text.</summary>
 /// <param name="graphics">The graphics to draw on.</param>
 /// <param name="border">The border type.</param>
 /// <param name="checkStyle">The check mark type.</param>
 /// <param name="rectangle">The rectangle that represents the dimensions of the check box.</param>
 /// <param name="state">The toggle state of the check mark.</param>
 /// <param name="enabled">The state to draw the check mark in.</param>
 /// <param name="color">The brush used to fill the background.</param>
 /// <param name="backgroundImage">The background Image.</param>
 /// <param name="mouseState">The state of the mouse on the control.</param>
 /// <param name="text">The text.</param>
 /// <param name="font">The font.</param>
 /// <param name="foreColor">The fore Color.</param>
 /// <param name="textPoint">The text Point.</param>
 public static void DrawCheckBox(Graphics graphics, Border border, CheckStyle checkStyle, Rectangle rectangle, bool state, bool enabled, Color color, Image backgroundImage, MouseStates mouseState, string text, Font font, Color foreColor, Point textPoint)
 {
     DrawCheckBox(graphics, border, checkStyle, rectangle, state, enabled, color, backgroundImage, mouseState);
     graphics.DrawString(text, font, new SolidBrush(foreColor), textPoint);
 }
Ejemplo n.º 9
0
        /// <summary>
        ///     Draws a check mark control in the specified state, on the specified graphics surface, and within the specified
        ///     bounds.
        /// </summary>
        /// <param name="graphics">The graphics to draw on.</param>
        /// <param name="checkStyle">The check mark type.</param>
        /// <param name="rectangle">The rectangle that represents the dimensions of the check box.</param>
        /// <param name="enabled">The state to draw the check mark in.</param>
        public static void DrawCheckMark(Graphics graphics, CheckStyle checkStyle, Rectangle rectangle, bool enabled)
        {
            Size _characterSize = StringUtil.MeasureText(checkStyle.Character.ToString(), checkStyle.Font, graphics);

            int _styleCount       = checkStyle.Style.Count();
            var _defaultLocations = new Point[_styleCount];

            _defaultLocations[0] = new Point((rectangle.X + (rectangle.Width / 2)) - (_characterSize.Width / 2), (rectangle.Y + (rectangle.Height / 2)) - (_characterSize.Height / 2));
            _defaultLocations[1] = new Point((rectangle.X + (rectangle.Width / 2)) - (checkStyle.Bounds.Width / 2), (rectangle.Y + (rectangle.Height / 2)) - (checkStyle.Bounds.Height / 2));
            _defaultLocations[2] = new Point((rectangle.X + (rectangle.Width / 2)) - (checkStyle.Bounds.Width / 2), (rectangle.Y + (rectangle.Height / 2)) - (checkStyle.Bounds.Height / 2));
            _defaultLocations[3] = new Point((rectangle.X + (rectangle.Width / 2)) - (checkStyle.Bounds.Width / 2), (rectangle.Y + (rectangle.Height / 2)) - (checkStyle.Bounds.Height / 2));

            Point _tempLocation;

            if (checkStyle.AutoSize)
            {
                int styleIndex;

                switch (checkStyle.Style)
                {
                case CheckStyle.CheckType.Character:
                {
                    styleIndex = 0;
                    break;
                }

                case CheckStyle.CheckType.Image:
                {
                    styleIndex = 1;
                    break;
                }

                case CheckStyle.CheckType.Shape:
                {
                    styleIndex = 2;
                    break;
                }

                case CheckStyle.CheckType.Checkmark:
                {
                    styleIndex = 3;
                    break;
                }

                default:
                {
                    throw new ArgumentOutOfRangeException();
                }
                }

                _tempLocation = _defaultLocations[styleIndex];
            }
            else
            {
                _tempLocation = checkStyle.Bounds.Location;
            }

            switch (checkStyle.Style)
            {
            case CheckStyle.CheckType.Character:
            {
                graphics.DrawString(checkStyle.Character.ToString(), checkStyle.Font, new SolidBrush(checkStyle.CheckColor), _tempLocation);
                break;
            }

            case CheckStyle.CheckType.Image:
            {
                Rectangle _imageRectangle = new Rectangle(_tempLocation, checkStyle.Bounds.Size);
                graphics.DrawImage(checkStyle.Image, _imageRectangle);
                break;
            }

            case CheckStyle.CheckType.Shape:
            {
                Rectangle    shapeRectangle = new Rectangle(_tempLocation, checkStyle.Bounds.Size);
                GraphicsPath shapePath      = VisualBorderRenderer.CreateBorderTypePath(shapeRectangle, checkStyle.ShapeRounding, checkStyle.ShapeRounding, checkStyle.ShapeType);
                graphics.FillPath(new SolidBrush(checkStyle.CheckColor), shapePath);
                break;
            }

            case CheckStyle.CheckType.Checkmark:
            {
                DrawCheckmark(graphics, checkStyle.CheckColor, rectangle, checkStyle.Thickness);
            }

            break;

            default:
            {
                throw new ArgumentOutOfRangeException();
            }
            }
        }
Ejemplo n.º 10
0
        private void OnGUI()
        {
            //Unable to use a named GUIStyle without a current skin.
            //Most likely you need to move your GUIStyle initialization code to OnGUI
            //GUI风格元素需要在OnGUI方法里初始化,否则会报以上错误,界面也会发生显示错误
            if (checkStyle == null)
            {
                checkStyle = new CheckStyle();
            }

            GUILayout.BeginHorizontal(checkStyle.ToolBar, new GUILayoutOption[] { GUILayout.Width(this.position.width) });
            {
                EditorGUI.BeginChangeCheck();

                checkTypeMix = (CheckEnumType)EditorGUILayout.EnumMaskPopup(new GUIContent(titleStr), checkTypeMix, checkStyle.TE_ToolBarBtn, new GUILayoutOption[] { GUILayout.Width(600) });

                if (EditorGUI.EndChangeCheck())
                {
                    //检查类型分类
                    OnCheckTypeSelect(checkTypeMix);
                }

                EditorGUI.BeginChangeCheck();

                if (GUILayout.Button(string.Format("当前目录{0}", filePath), checkStyle.TE_ToolBarBtn))
                {
                    filePath = EditorUtility.OpenFolderPanel("选择筛选目录{0}", Application.dataPath, string.Empty);

                    var currentDir = BuildUtils.GetUnityPath(Path.GetFullPath(Directory.GetCurrentDirectory()));

                    filePath = filePath.Replace(string.Format("{0}/", currentDir), "");
                }
                if (EditorGUI.EndChangeCheck())
                {
                    checkManager.SetFilePath(filePath);

                    Debug.Log(string.Format("当前选择目录:{0}", filePath));
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            {
                if (GUILayout.Button("Check"))
                {
                    //检查
                    if (checkManager.GetPathListByFilePath())
                    {
                        checkManager.OnCheck();
                    }
                }

                if (GUILayout.Button("Format"))
                {
                    //处理
                    checkManager.OnFormat();
                }
            }
            GUILayout.EndHorizontal();

            #region 表格GUI绘制
            //表格 GUI 绘制
            Rect viewRect = new Rect(border * 2 + this.position.width * percet, offset * 2, this.position.width * (1 - percet) - border * 3, this.position.height - offset * 2 - border);

            if (table != null)
            {
                table.Draw(viewRect);
            }
            #endregion

            #region 检查项GUI绘制

            //检查项 itemlist 绘制
            Rect itemViewRect = new Rect(border, offset * 2, this.position.width * percet, this.position.height - offset * 2 - border);

            GUILayout.BeginArea(itemViewRect, checkStyle.WindowBackground);

            scrollview = GUILayout.BeginScrollView(scrollview, GUIStyle.none, GUI.skin.verticalScrollbar);

            DrawItemWind(itemViewRect);

            GUILayout.EndScrollView();

            GUILayout.EndArea();

            #endregion
        }