├── scr ├── BezierControlDemo │ ├── Properties │ │ ├── Settings.settings │ │ ├── Settings.Designer.cs │ │ ├── AssemblyInfo.cs │ │ ├── Resources.Designer.cs │ │ └── Resources.resx │ ├── Program.cs │ ├── Form1.cs │ ├── BezierControlDemo.csproj │ ├── Form1.resx │ └── Form1.Designer.cs ├── BezierControl │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── BezierControl.csproj │ └── BezierClass.cs └── BezierControl.sln ├── README.md ├── .gitignore └── LICENSE /scr/BezierControlDemo/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /scr/BezierControlDemo/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Windows.Forms; 5 | 6 | namespace BezierControlDemo 7 | { 8 | static class Program 9 | { 10 | /// 11 | /// Главная точка входа для приложения. 12 | /// 13 | [STAThread] 14 | static void Main() 15 | { 16 | Application.EnableVisualStyles(); 17 | Application.SetCompatibleTextRenderingDefault(false); 18 | Application.Run(new Form1()); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | BezierControl 2 | ============= 3 | 4 | Class for drawing cubic bezier curve with mouse, for use in WinForms. 5 | 6 | Класс для рисования кубической кривой Безье при помощи мыши. 7 | Отрисовка кривой реализована встроенными средствами System.Drawing.Drawing2D, метод [GraphicsPath.AddBeziers](http://msdn.microsoft.com/en-us/library/wdba9had(v=vs.110).aspx). 8 | 9 | ### Управление 10 | * Якоря (красные точки), контролы (зеленые точки) и сегменты кривой можно таскать, зажав левую кнопку мыши. 11 | * Нажать правую кнопку мыши в свободном месте холста или на сегменте кривой, чтобы добавить новый якорь в позицию курсора мыши. 12 | * Нажать колесо мыши для удаления якоря или сегмента кривой в позиции курсора мыши. 13 | 14 | 15 | 16 | ### Точки кривой 17 | ``` 18 | //Список точек кривой попиксельно 19 | List pixels = bezier.ToPixels; 20 | //Список точек полилинии, сформированной из кривой методом GraphicsPath.Flatten. 21 | List polyline = bezier.ToPolyline(); 22 | ``` 23 | 24 | ![Demo Screenshot](http://images.illuzor.com/uploads/bez-new.png) 25 | -------------------------------------------------------------------------------- /scr/BezierControlDemo/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.233 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace BezierControlDemo.Properties 12 | { 13 | 14 | 15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")] 17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase 18 | { 19 | 20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 21 | 22 | public static Settings Default 23 | { 24 | get 25 | { 26 | return defaultInstance; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /scr/BezierControlDemo/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // Управление общими сведениями о сборке осуществляется с помощью 6 | // набора атрибутов. Измените значения этих атрибутов, чтобы изменить сведения, 7 | // связанные со сборкой. 8 | [assembly: AssemblyTitle("BezierControlDemo")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("NVTelecom")] 12 | [assembly: AssemblyProduct("BezierControlDemo")] 13 | [assembly: AssemblyCopyright("Copyright © NVTelecom 2014")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Параметр ComVisible со значением FALSE делает типы в сборке невидимыми 18 | // для COM-компонентов. Если требуется обратиться к типу в этой сборке через 19 | // COM, задайте атрибуту ComVisible значение TRUE для этого типа. 20 | [assembly: ComVisible(false)] 21 | 22 | // Следующий GUID служит для идентификации библиотеки типов, если этот проект будет видимым для COM 23 | [assembly: Guid("103b15e8-561c-45b4-b3e1-8e27b88707c0")] 24 | 25 | // Сведения о версии сборки состоят из следующих четырех значений: 26 | // 27 | // Основной номер версии 28 | // Дополнительный номер версии 29 | // Номер построения 30 | // Редакция 31 | // 32 | // Можно задать все значения или принять номер построения и номер редакции по умолчанию, 33 | // используя "*", как показано ниже: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /scr/BezierControl/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // Управление общими сведениями о сборке осуществляется с помощью 6 | // набора атрибутов. Измените значения этих атрибутов, чтобы изменить сведения, 7 | // связанные со сборкой. 8 | [assembly: AssemblyTitle("BezierControl")] 9 | [assembly: AssemblyDescription("Class for drawing cubic bezier curve with mouse, for use in WinForms")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Maxx53")] 12 | [assembly: AssemblyProduct("BezierControl")] 13 | [assembly: AssemblyCopyright("Copyright © Maxx53, 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Параметр ComVisible со значением FALSE делает типы в сборке невидимыми 18 | // для COM-компонентов. Если требуется обратиться к типу в этой сборке через 19 | // COM, задайте атрибуту ComVisible значение TRUE для этого типа. 20 | [assembly: ComVisible(false)] 21 | 22 | // Следующий GUID служит для идентификации библиотеки типов, если этот проект будет видимым для COM 23 | [assembly: Guid("d20a981b-cb20-4d8d-8270-788285b3ee28")] 24 | 25 | // Сведения о версии сборки состоят из следующих четырех значений: 26 | // 27 | // Основной номер версии 28 | // Дополнительный номер версии 29 | // Номер построения 30 | // Редакция 31 | // 32 | // Можно задать все значения или принять номер построения и номер редакции по умолчанию, 33 | // используя "*", как показано ниже: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /scr/BezierControl/BezierControl.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {DFEB0BF8-4F16-4326-A04B-B34BB40E6634} 9 | Library 10 | Properties 11 | BezierControl 12 | BezierControl 13 | v4.0 14 | 512 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 51 | -------------------------------------------------------------------------------- /scr/BezierControl.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BezierControlDemo", "BezierControlDemo\BezierControlDemo.csproj", "{10B9DB1F-DA10-49CA-A9C4-40C4B3E17E7D}" 5 | EndProject 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BezierControl", "BezierControl\BezierControl.csproj", "{DFEB0BF8-4F16-4326-A04B-B34BB40E6634}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Debug|Mixed Platforms = Debug|Mixed Platforms 12 | Debug|x86 = Debug|x86 13 | Release|Any CPU = Release|Any CPU 14 | Release|Mixed Platforms = Release|Mixed Platforms 15 | Release|x86 = Release|x86 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {10B9DB1F-DA10-49CA-A9C4-40C4B3E17E7D}.Debug|Any CPU.ActiveCfg = Debug|x86 19 | {10B9DB1F-DA10-49CA-A9C4-40C4B3E17E7D}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 20 | {10B9DB1F-DA10-49CA-A9C4-40C4B3E17E7D}.Debug|Mixed Platforms.Build.0 = Debug|x86 21 | {10B9DB1F-DA10-49CA-A9C4-40C4B3E17E7D}.Debug|x86.ActiveCfg = Debug|x86 22 | {10B9DB1F-DA10-49CA-A9C4-40C4B3E17E7D}.Debug|x86.Build.0 = Debug|x86 23 | {10B9DB1F-DA10-49CA-A9C4-40C4B3E17E7D}.Release|Any CPU.ActiveCfg = Release|x86 24 | {10B9DB1F-DA10-49CA-A9C4-40C4B3E17E7D}.Release|Mixed Platforms.ActiveCfg = Release|x86 25 | {10B9DB1F-DA10-49CA-A9C4-40C4B3E17E7D}.Release|Mixed Platforms.Build.0 = Release|x86 26 | {10B9DB1F-DA10-49CA-A9C4-40C4B3E17E7D}.Release|x86.ActiveCfg = Release|x86 27 | {10B9DB1F-DA10-49CA-A9C4-40C4B3E17E7D}.Release|x86.Build.0 = Release|x86 28 | {DFEB0BF8-4F16-4326-A04B-B34BB40E6634}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {DFEB0BF8-4F16-4326-A04B-B34BB40E6634}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {DFEB0BF8-4F16-4326-A04B-B34BB40E6634}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU 31 | {DFEB0BF8-4F16-4326-A04B-B34BB40E6634}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU 32 | {DFEB0BF8-4F16-4326-A04B-B34BB40E6634}.Debug|x86.ActiveCfg = Debug|Any CPU 33 | {DFEB0BF8-4F16-4326-A04B-B34BB40E6634}.Release|Any CPU.ActiveCfg = Release|Any CPU 34 | {DFEB0BF8-4F16-4326-A04B-B34BB40E6634}.Release|Any CPU.Build.0 = Release|Any CPU 35 | {DFEB0BF8-4F16-4326-A04B-B34BB40E6634}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU 36 | {DFEB0BF8-4F16-4326-A04B-B34BB40E6634}.Release|Mixed Platforms.Build.0 = Release|Any CPU 37 | {DFEB0BF8-4F16-4326-A04B-B34BB40E6634}.Release|x86.ActiveCfg = Release|Any CPU 38 | EndGlobalSection 39 | GlobalSection(SolutionProperties) = preSolution 40 | HideSolutionNode = FALSE 41 | EndGlobalSection 42 | EndGlobal 43 | -------------------------------------------------------------------------------- /scr/BezierControlDemo/Form1.cs: -------------------------------------------------------------------------------- 1 | using System.Windows.Forms; 2 | using System.Drawing; 3 | using BezierControl; 4 | 5 | 6 | 7 | /// Using: 8 | /// private BezierLine bezier = new BezierLine(); 9 | /// 10 | /// bezier.Draw(e); to Control_Paint() event 11 | /// bezier.MouseDown(e); to Control_MouseDown() event 12 | /// bezier.MouseMove(e); to Control_MouseMove() event 13 | /// bezier.MouseUp(e); to Control_MouseUp() event 14 | /// 15 | 16 | 17 | /// Getting output: 18 | /// 19 | /// List pixels = bezier.ToPixels; 20 | /// List polyline = bezier.ToPolyline(); 21 | /// 22 | 23 | 24 | namespace BezierControlDemo 25 | { 26 | public partial class Form1 : Form 27 | { 28 | private BezierLine bezier; 29 | 30 | public Form1() 31 | { 32 | InitializeComponent(); 33 | } 34 | 35 | private void Form1_Load(object sender, System.EventArgs e) 36 | { 37 | bezier = new BezierLine(pictureBox1); 38 | 39 | //If you need snapping to grid! 40 | //bezier.isSnap = true; 41 | //bezier.snapRes = 20; 42 | 43 | //If you need to change colors 44 | //bezier.pathPenColor = Color.Black; 45 | //bezier.anchorBrushColor = Color.Gold; 46 | //bezier.ctrlBrushColor = Color.Blue; 47 | //bezier.ctrlPenColor = Color.Green; 48 | 49 | //If you need to change sizes 50 | //bezier.AnchorSize = 20; 51 | //bezier.ControlSize = 10; 52 | //bezier.pathPenWidth = 20; 53 | //bezier.ctrlPen.Width = 10; 54 | 55 | //Wanna get fast draw? 56 | //bezier.Smoothing = false; 57 | 58 | bezier.Spawn(40, 40); 59 | } 60 | 61 | private void pictureBox1_Paint(object sender, PaintEventArgs e) 62 | { 63 | bezier.Draw(e); 64 | } 65 | 66 | private void pictureBox1_MouseDown(object sender, MouseEventArgs e) 67 | { 68 | bezier.MouseDown(e); 69 | } 70 | 71 | private void pictureBox1_MouseMove(object sender, MouseEventArgs e) 72 | { 73 | bezier.MouseMove(e); 74 | } 75 | 76 | private void checkBox1_CheckedChanged(object sender, System.EventArgs e) 77 | { 78 | bezier.ShowAnchors = checkBox1.Checked; 79 | } 80 | 81 | private void checkBox2_CheckedChanged(object sender, System.EventArgs e) 82 | { 83 | bezier.ShowControls = checkBox2.Checked; 84 | } 85 | 86 | private void pictureBox1_MouseUp(object sender, MouseEventArgs e) 87 | { 88 | bezier.MouseUp(e); 89 | } 90 | 91 | 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /scr/BezierControlDemo/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // Этот код создан программным средством. 4 | // Версия среды выполнения: 4.0.30319.233 5 | // 6 | // Изменения в этом файле могут привести к неправильному поведению и будут утрачены, если 7 | // код создан повторно. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace BezierControlDemo.Properties 12 | { 13 | 14 | 15 | /// 16 | /// Класс ресурсов со строгим типом для поиска локализованных строк и пр. 17 | /// 18 | // Этот класс был автоматически создан при помощи StronglyTypedResourceBuilder 19 | // класс с помощью таких средств, как ResGen или Visual Studio. 20 | // Для добавления или удаления члена измените файл .ResX, а затем перезапустите ResGen 21 | // с параметром /str или заново постройте свой VS-проект. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources 26 | { 27 | 28 | private static global::System.Resources.ResourceManager resourceMan; 29 | 30 | private static global::System.Globalization.CultureInfo resourceCulture; 31 | 32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 33 | internal Resources() 34 | { 35 | } 36 | 37 | /// 38 | /// Возврат кэшированного экземпляра ResourceManager, используемого этим классом. 39 | /// 40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 41 | internal static global::System.Resources.ResourceManager ResourceManager 42 | { 43 | get 44 | { 45 | if ((resourceMan == null)) 46 | { 47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("BezierControlDemo.Properties.Resources", typeof(Resources).Assembly); 48 | resourceMan = temp; 49 | } 50 | return resourceMan; 51 | } 52 | } 53 | 54 | /// 55 | /// Переопределяет свойство CurrentUICulture текущего потока для всех 56 | /// подстановки ресурсов с помощью этого класса ресурсов со строгим типом. 57 | /// 58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 59 | internal static global::System.Globalization.CultureInfo Culture 60 | { 61 | get 62 | { 63 | return resourceCulture; 64 | } 65 | set 66 | { 67 | resourceCulture = value; 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | local.properties 15 | .classpath 16 | .settings/ 17 | .loadpath 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # CDT-specific 26 | .cproject 27 | 28 | # PDT-specific 29 | .buildpath 30 | 31 | 32 | ################# 33 | ## Visual Studio 34 | ################# 35 | 36 | ## Ignore Visual Studio temporary files, build results, and 37 | ## files generated by popular Visual Studio add-ons. 38 | 39 | # User-specific files 40 | *.suo 41 | *.user 42 | *.sln.docstates 43 | 44 | # Build results 45 | 46 | [Dd]ebug/ 47 | [Rr]elease/ 48 | x64/ 49 | build/ 50 | [Bb]in/ 51 | [Oo]bj/ 52 | 53 | # MSTest test Results 54 | [Tt]est[Rr]esult*/ 55 | [Bb]uild[Ll]og.* 56 | 57 | *_i.c 58 | *_p.c 59 | *.ilk 60 | *.meta 61 | *.obj 62 | *.pch 63 | *.pdb 64 | *.pgc 65 | *.pgd 66 | *.rsp 67 | *.sbr 68 | *.tlb 69 | *.tli 70 | *.tlh 71 | *.tmp 72 | *.tmp_proj 73 | *.log 74 | *.vspscc 75 | *.vssscc 76 | .builds 77 | *.pidb 78 | *.log 79 | *.scc 80 | 81 | # Visual C++ cache files 82 | ipch/ 83 | *.aps 84 | *.ncb 85 | *.opensdf 86 | *.sdf 87 | *.cachefile 88 | 89 | # Visual Studio profiler 90 | *.psess 91 | *.vsp 92 | *.vspx 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | 101 | # TeamCity is a build add-in 102 | _TeamCity* 103 | 104 | # DotCover is a Code Coverage Tool 105 | *.dotCover 106 | 107 | # NCrunch 108 | *.ncrunch* 109 | .*crunch*.local.xml 110 | 111 | # Installshield output folder 112 | [Ee]xpress/ 113 | 114 | # DocProject is a documentation generator add-in 115 | DocProject/buildhelp/ 116 | DocProject/Help/*.HxT 117 | DocProject/Help/*.HxC 118 | DocProject/Help/*.hhc 119 | DocProject/Help/*.hhk 120 | DocProject/Help/*.hhp 121 | DocProject/Help/Html2 122 | DocProject/Help/html 123 | 124 | # Click-Once directory 125 | publish/ 126 | 127 | # Publish Web Output 128 | *.Publish.xml 129 | *.pubxml 130 | 131 | # NuGet Packages Directory 132 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 133 | #packages/ 134 | 135 | # Windows Azure Build Output 136 | csx 137 | *.build.csdef 138 | 139 | # Windows Store app package directory 140 | AppPackages/ 141 | 142 | # Others 143 | sql/ 144 | *.Cache 145 | ClientBin/ 146 | [Ss]tyle[Cc]op.* 147 | ~$* 148 | *~ 149 | *.dbmdl 150 | *.[Pp]ublish.xml 151 | *.pfx 152 | *.publishsettings 153 | 154 | # RIA/Silverlight projects 155 | Generated_Code/ 156 | 157 | # Backup & report files from converting an old project file to a newer 158 | # Visual Studio version. Backup files are not needed, because we have git ;-) 159 | _UpgradeReport_Files/ 160 | Backup*/ 161 | UpgradeLog*.XML 162 | UpgradeLog*.htm 163 | 164 | # SQL Server files 165 | App_Data/*.mdf 166 | App_Data/*.ldf 167 | 168 | ############# 169 | ## Windows detritus 170 | ############# 171 | 172 | # Windows image file caches 173 | Thumbs.db 174 | ehthumbs.db 175 | 176 | # Folder config file 177 | Desktop.ini 178 | 179 | # Recycle Bin used on file shares 180 | $RECYCLE.BIN/ 181 | 182 | # Mac crap 183 | .DS_Store 184 | 185 | 186 | ############# 187 | ## Python 188 | ############# 189 | 190 | *.py[co] 191 | 192 | # Packages 193 | *.egg 194 | *.egg-info 195 | dist/ 196 | build/ 197 | eggs/ 198 | parts/ 199 | var/ 200 | sdist/ 201 | develop-eggs/ 202 | .installed.cfg 203 | 204 | # Installer logs 205 | pip-log.txt 206 | 207 | # Unit test / coverage reports 208 | .coverage 209 | .tox 210 | 211 | #Translations 212 | *.mo 213 | 214 | #Mr Developer 215 | .mr.developer.cfg 216 | -------------------------------------------------------------------------------- /scr/BezierControlDemo/BezierControlDemo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | x86 6 | 8.0.30703 7 | 2.0 8 | {10B9DB1F-DA10-49CA-A9C4-40C4B3E17E7D} 9 | WinExe 10 | Properties 11 | BezierControlDemo 12 | BezierControlDemo 13 | v4.0 14 | Client 15 | 512 16 | 17 | 18 | x86 19 | true 20 | full 21 | false 22 | bin\Debug\ 23 | DEBUG;TRACE 24 | prompt 25 | 4 26 | 27 | 28 | x86 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE 33 | prompt 34 | 4 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | Form 46 | 47 | 48 | Form1.cs 49 | 50 | 51 | 52 | 53 | Form1.cs 54 | 55 | 56 | ResXFileCodeGenerator 57 | Resources.Designer.cs 58 | Designer 59 | 60 | 61 | True 62 | Resources.resx 63 | 64 | 65 | SettingsSingleFileGenerator 66 | Settings.Designer.cs 67 | 68 | 69 | True 70 | Settings.settings 71 | True 72 | 73 | 74 | 75 | 76 | {DFEB0BF8-4F16-4326-A04B-B34BB40E6634} 77 | BezierControl 78 | True 79 | False 80 | 81 | 82 | 83 | 90 | -------------------------------------------------------------------------------- /scr/BezierControlDemo/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /scr/BezierControlDemo/Form1.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 1) You can drag anchor points (red), control points (green) and line segments. 122 | 2) Right mouse click to spawn new anchor point in mouse porition at bezier line or at the end of the line. 123 | 3) Mouse wheel click to remove anchor point or line segment at mouse position. 124 | 125 | -------------------------------------------------------------------------------- /scr/BezierControlDemo/Form1.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace BezierControlDemo 2 | { 3 | partial class Form1 4 | { 5 | /// 6 | /// Требуется переменная конструктора. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Освободить все используемые ресурсы. 12 | /// 13 | /// истинно, если управляемый ресурс должен быть удален; иначе ложно. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Код, автоматически созданный конструктором форм Windows 24 | 25 | /// 26 | /// Обязательный метод для поддержки конструктора - не изменяйте 27 | /// содержимое данного метода при помощи редактора кода. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); 32 | this.pictureBox1 = new System.Windows.Forms.PictureBox(); 33 | this.checkBox1 = new System.Windows.Forms.CheckBox(); 34 | this.checkBox2 = new System.Windows.Forms.CheckBox(); 35 | this.groupBox1 = new System.Windows.Forms.GroupBox(); 36 | this.label4 = new System.Windows.Forms.Label(); 37 | ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); 38 | this.groupBox1.SuspendLayout(); 39 | this.SuspendLayout(); 40 | // 41 | // pictureBox1 42 | // 43 | this.pictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 44 | | System.Windows.Forms.AnchorStyles.Left) 45 | | System.Windows.Forms.AnchorStyles.Right))); 46 | this.pictureBox1.BackColor = System.Drawing.SystemColors.Window; 47 | this.pictureBox1.Location = new System.Drawing.Point(12, 12); 48 | this.pictureBox1.Name = "pictureBox1"; 49 | this.pictureBox1.Size = new System.Drawing.Size(615, 381); 50 | this.pictureBox1.TabIndex = 0; 51 | this.pictureBox1.TabStop = false; 52 | this.pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint); 53 | this.pictureBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseDown); 54 | this.pictureBox1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseMove); 55 | this.pictureBox1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseUp); 56 | // 57 | // checkBox1 58 | // 59 | this.checkBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); 60 | this.checkBox1.AutoSize = true; 61 | this.checkBox1.Checked = true; 62 | this.checkBox1.CheckState = System.Windows.Forms.CheckState.Checked; 63 | this.checkBox1.Location = new System.Drawing.Point(12, 399); 64 | this.checkBox1.Name = "checkBox1"; 65 | this.checkBox1.Size = new System.Drawing.Size(95, 17); 66 | this.checkBox1.TabIndex = 1; 67 | this.checkBox1.Text = "Show Anchors"; 68 | this.checkBox1.UseVisualStyleBackColor = true; 69 | this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged); 70 | // 71 | // checkBox2 72 | // 73 | this.checkBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); 74 | this.checkBox2.AutoSize = true; 75 | this.checkBox2.Checked = true; 76 | this.checkBox2.CheckState = System.Windows.Forms.CheckState.Checked; 77 | this.checkBox2.Location = new System.Drawing.Point(12, 422); 78 | this.checkBox2.Name = "checkBox2"; 79 | this.checkBox2.Size = new System.Drawing.Size(94, 17); 80 | this.checkBox2.TabIndex = 1; 81 | this.checkBox2.Text = "Show Controls"; 82 | this.checkBox2.UseVisualStyleBackColor = true; 83 | this.checkBox2.CheckedChanged += new System.EventHandler(this.checkBox2_CheckedChanged); 84 | // 85 | // groupBox1 86 | // 87 | this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 88 | | System.Windows.Forms.AnchorStyles.Right))); 89 | this.groupBox1.Controls.Add(this.label4); 90 | this.groupBox1.Location = new System.Drawing.Point(111, 399); 91 | this.groupBox1.Name = "groupBox1"; 92 | this.groupBox1.Size = new System.Drawing.Size(516, 63); 93 | this.groupBox1.TabIndex = 2; 94 | this.groupBox1.TabStop = false; 95 | this.groupBox1.Text = "Tips"; 96 | // 97 | // label4 98 | // 99 | this.label4.AutoSize = true; 100 | this.label4.Location = new System.Drawing.Point(6, 17); 101 | this.label4.Name = "label4"; 102 | this.label4.Size = new System.Drawing.Size(493, 39); 103 | this.label4.TabIndex = 0; 104 | this.label4.Text = resources.GetString("label4.Text"); 105 | // 106 | // Form1 107 | // 108 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 109 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 110 | this.ClientSize = new System.Drawing.Size(639, 470); 111 | this.Controls.Add(this.groupBox1); 112 | this.Controls.Add(this.checkBox2); 113 | this.Controls.Add(this.checkBox1); 114 | this.Controls.Add(this.pictureBox1); 115 | this.Name = "Form1"; 116 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; 117 | this.Text = "BezierControl Demo"; 118 | this.Load += new System.EventHandler(this.Form1_Load); 119 | ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); 120 | this.groupBox1.ResumeLayout(false); 121 | this.groupBox1.PerformLayout(); 122 | this.ResumeLayout(false); 123 | this.PerformLayout(); 124 | 125 | } 126 | 127 | #endregion 128 | 129 | private System.Windows.Forms.PictureBox pictureBox1; 130 | private System.Windows.Forms.CheckBox checkBox1; 131 | private System.Windows.Forms.CheckBox checkBox2; 132 | private System.Windows.Forms.GroupBox groupBox1; 133 | private System.Windows.Forms.Label label4; 134 | 135 | 136 | 137 | } 138 | } 139 | 140 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /scr/BezierControl/BezierClass.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2015 All Rights Reserved 3 | // 4 | // Maxx53 5 | // 26/03/2015 6 | // Class for drawing cubic bezier curve with mouse, for use in WinForms. 7 | 8 | using System; 9 | using System.Collections.Generic; 10 | using System.Drawing; 11 | using System.Drawing.Drawing2D; 12 | using System.Windows.Forms; 13 | 14 | 15 | namespace BezierControl 16 | { 17 | [Flags] 18 | public enum PointID : byte 19 | { 20 | Anchor = 0, 21 | Control1 = 1, 22 | Control2 = 2, 23 | } 24 | 25 | public class BezierLine : List 26 | { 27 | #region Variables 28 | 29 | private int toMove = -1; 30 | private int highLited = -1; 31 | private int polyNum = -1; 32 | 33 | private double radius1; 34 | private Point center1; 35 | private BezierPoint second1; 36 | private bool skip1 = false; 37 | 38 | private double radius2; 39 | private Point center2; 40 | private BezierPoint second2; 41 | private bool skip2 = false; 42 | 43 | private Point oldMousePoint; 44 | private GraphicsPath gp = new GraphicsPath(); 45 | private Control canvas; 46 | 47 | private bool showControls = true; 48 | private bool showAnchors = true; 49 | 50 | private Pen pathPenLight = new Pen(Color.Aqua, 2); 51 | private Pen ctrlPenLight = new Pen(Color.CadetBlue, 2); 52 | 53 | private SolidBrush anchorBrush = new SolidBrush(Color.Red); 54 | private SolidBrush ctrlBrush = new SolidBrush(Color.Green); 55 | private SolidBrush anchorLight = new SolidBrush(Color.Pink); 56 | private SolidBrush ctrlLight = new SolidBrush(Color.LawnGreen); 57 | 58 | public bool Smoothing = true; 59 | public bool isStart = false; 60 | public bool polyMoving = false; 61 | 62 | public bool isSnap = false; 63 | public int snapRes = 20; 64 | 65 | public Pen pathPen = new Pen(Color.Gray, 2); 66 | public Pen ctrlPen = new Pen(Color.Blue, 0); 67 | 68 | public static int anchorSize = 12; 69 | public static int controlSize = 8; 70 | 71 | #endregion 72 | 73 | #region Properties 74 | 75 | public BezierLine(Control p) 76 | { 77 | canvas = p; 78 | } 79 | 80 | public Color pathPenColor 81 | { 82 | get 83 | { 84 | return pathPen.Color; 85 | } 86 | set 87 | { 88 | pathPen.Color = value; 89 | pathPenLight.Color = Utils.HighlightColor(value); 90 | } 91 | } 92 | 93 | public float pathPenWidth 94 | { 95 | get 96 | { 97 | return pathPen.Width; 98 | } 99 | set 100 | { 101 | pathPen.Width = value; 102 | pathPenLight.Width = pathPen.Width + 1; 103 | } 104 | } 105 | 106 | public Color ctrlPenColor 107 | { 108 | get 109 | { 110 | return ctrlPen.Color; 111 | } 112 | set 113 | { 114 | ctrlPen.Color = value; 115 | ctrlPenLight.Color = Utils.HighlightColor(value); 116 | } 117 | } 118 | 119 | public Color anchorBrushColor 120 | { 121 | get 122 | { 123 | return anchorBrush.Color; 124 | } 125 | set 126 | { 127 | anchorBrush.Color = value; 128 | anchorLight.Color = Utils.HighlightColor(value); 129 | } 130 | } 131 | 132 | public Color ctrlBrushColor 133 | { 134 | get 135 | { 136 | return ctrlBrush.Color; 137 | } 138 | set 139 | { 140 | ctrlBrush.Color = value; 141 | ctrlLight.Color = Utils.HighlightColor(value); 142 | } 143 | } 144 | 145 | public bool ShowControls 146 | { 147 | get 148 | { 149 | return showControls; 150 | } 151 | set 152 | { 153 | showControls = value; 154 | canvas.Refresh(); 155 | } 156 | } 157 | 158 | public bool ShowAnchors 159 | { 160 | get 161 | { 162 | return showAnchors; 163 | } 164 | set 165 | { 166 | showAnchors = value; 167 | canvas.Refresh(); 168 | } 169 | } 170 | 171 | public int AnchorSize 172 | { 173 | get 174 | { 175 | return anchorSize; 176 | } 177 | set 178 | { 179 | anchorSize = value; 180 | } 181 | } 182 | 183 | public int ControlSize 184 | { 185 | get 186 | { 187 | return controlSize; 188 | } 189 | set 190 | { 191 | controlSize = value; 192 | } 193 | } 194 | 195 | #endregion 196 | 197 | #region Editing line 198 | 199 | public void AddPoint(int x, int y, PointID id) 200 | { 201 | this.Add(new BezierPoint(new Point(x, y), id)); 202 | } 203 | 204 | public void AddPoint(Point point, PointID id) 205 | { 206 | this.Add(new BezierPoint(point, id)); 207 | } 208 | 209 | public void AddNode(int x, int y) 210 | { 211 | if (this.Count != 0) 212 | { 213 | this.AddPoint(this[this.Count - 1].Coord, PointID.Control1); 214 | this.AddPoint(x, y, PointID.Control2); 215 | this.AddPoint(x, y, PointID.Anchor); 216 | } 217 | } 218 | 219 | public void RemoveNode(int idx) 220 | { 221 | if (this.Count > 4) 222 | { 223 | if (idx == 0) 224 | { 225 | this.RemoveAt(idx); 226 | this.RemoveAt(idx); 227 | this.RemoveAt(idx); 228 | } 229 | else 230 | if (idx == this.Count - 1) 231 | { 232 | this.RemoveAt(idx - 2); 233 | this.RemoveAt(idx - 2); 234 | this.RemoveAt(idx - 2); 235 | } 236 | else 237 | { 238 | this.RemoveAt(idx); 239 | this.RemoveAt(idx); 240 | this.RemoveAt(idx - 1); 241 | } 242 | } 243 | } 244 | 245 | public void Spawn(int x, int y) 246 | { 247 | if (this.Count == 0) 248 | { 249 | 250 | this.AddPoint(x, y, PointID.Anchor); 251 | this.AddNode(x, y + 40); 252 | canvas.Refresh(); 253 | } 254 | } 255 | 256 | public void ImportPoints(List list) 257 | { 258 | byte x = 0; 259 | for (int i = 0; i < list.Count; i++) 260 | { 261 | if (i == 0) 262 | { 263 | this.AddPoint(list[i], PointID.Anchor); 264 | x++; 265 | continue; 266 | } 267 | 268 | switch (x) 269 | { 270 | case 0: 271 | this.AddPoint(list[i], PointID.Anchor); 272 | break; 273 | case 1: 274 | this.AddPoint(list[i], PointID.Control1); 275 | break; 276 | case 2: 277 | this.AddPoint(list[i], PointID.Control2); 278 | x = 0; 279 | continue; 280 | } 281 | 282 | x++; 283 | } 284 | } 285 | 286 | public void ClearLine() 287 | { 288 | this.Clear(); 289 | this.AddPoint(10, 100, PointID.Anchor); 290 | this.AddNode(160, 100); 291 | canvas.Refresh(); 292 | } 293 | 294 | private void InsertAtPos(int pos, Point point) 295 | { 296 | this.Insert(pos, new BezierPoint(point, PointID.Control1)); 297 | this.Insert(pos, new BezierPoint(point, PointID.Anchor)); 298 | this.Insert(pos, new BezierPoint(point, PointID.Control2)); 299 | 300 | } 301 | 302 | private void InsertAtPoly(int PolyNum, Point loc) 303 | { 304 | this.InsertAtPos((PolyNum + 1) * 3 - 1, loc); 305 | canvas.Refresh(); 306 | } 307 | 308 | public void UpdateSizes() 309 | { 310 | for (int i = 0; i < this.Count; i++) 311 | { 312 | this[i].ForceUpdateRect(); 313 | } 314 | canvas.Invalidate(); 315 | } 316 | 317 | #endregion 318 | 319 | #region Setting Positions 320 | 321 | private void SetAnchorPos(Point point) 322 | { 323 | 324 | var deltaX = this[toMove].Coord.X - point.X; 325 | var deltaY = this[toMove].Coord.Y - point.Y; 326 | 327 | this[toMove].Coord = point; 328 | 329 | if (toMove == 0) 330 | { 331 | this[toMove + 1].Coord = new Point(this[toMove + 1].Coord.X - deltaX, this[toMove + 1].Coord.Y - deltaY); 332 | } 333 | else if (toMove == this.Count - 1) 334 | { 335 | this[toMove - 1].Coord = new Point(this[toMove - 1].Coord.X - deltaX, this[toMove - 1].Coord.Y - deltaY); 336 | } 337 | else 338 | { 339 | this[toMove - 1].Coord = new Point(this[toMove - 1].Coord.X - deltaX, this[toMove - 1].Coord.Y - deltaY); 340 | this[toMove + 1].Coord = new Point(this[toMove + 1].Coord.X - deltaX, this[toMove + 1].Coord.Y - deltaY); 341 | } 342 | 343 | } 344 | 345 | private void SetControlsPos(Point point) 346 | { 347 | this[toMove].Coord = point; 348 | 349 | if (!skip1) 350 | { 351 | second1.Coord = Utils.setRotation(radius1, second1.Coord, center1, Math.PI + Utils.getAngleRad(point, center1)); 352 | } 353 | } 354 | 355 | private void SetPolyPos(Point point) 356 | { 357 | var CtrlNum1 = (polyNum) * 3 + 1; 358 | var CtrlNum2 = (polyNum) * 3 + 2; 359 | 360 | var deltaX = oldMousePoint.X - point.X; 361 | var deltaY = oldMousePoint.Y - point.Y; 362 | 363 | this[CtrlNum1].Coord = new Point(this[CtrlNum1].Coord.X - deltaX, this[CtrlNum1].Coord.Y - deltaY); 364 | this[CtrlNum2].Coord = new Point(this[CtrlNum2].Coord.X - deltaX, this[CtrlNum2].Coord.Y - deltaY); 365 | 366 | 367 | if (!skip1) 368 | { 369 | var firstSync = this[CtrlNum1]; 370 | second1.Coord = Utils.setRotation(radius1, second1.Coord, center1, Math.PI + Utils.getAngleRad(firstSync.Coord, center1)); 371 | } 372 | 373 | if (!skip2) 374 | { 375 | var secondSync = this[CtrlNum2]; 376 | second2.Coord = Utils.setRotation(radius2, second2.Coord, center2, Math.PI + Utils.getAngleRad(secondSync.Coord, center2)); 377 | } 378 | 379 | oldMousePoint = point; 380 | 381 | } 382 | 383 | #endregion 384 | 385 | #region Control Events 386 | 387 | public void Draw(PaintEventArgs e) 388 | { 389 | if (canvas == null) return; 390 | 391 | if (this.Count > 1) 392 | { 393 | if (Smoothing) 394 | { 395 | e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; 396 | //e.Graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; 397 | } 398 | 399 | gp.Reset(); 400 | 401 | gp.AddBeziers(ToPointArray()); 402 | 403 | 404 | //Draw Real this 405 | 406 | e.Graphics.DrawPath(pathPen, gp); 407 | 408 | //Drawing highligt bezier 409 | int nu = (polyNum) * 3; 410 | if ((polyNum != -1) && (nu + 3 < this.Count)) 411 | { 412 | 413 | e.Graphics.DrawBezier(pathPenLight, this[nu].Coord, this[nu + 1].Coord, this[nu + 2].Coord, this[nu + 3].Coord); 414 | } 415 | 416 | //Draw Controls Lines 417 | if (ShowControls) 418 | { 419 | for (int i = 0; i < this.Count; i++) 420 | { 421 | 422 | if (i != 0) 423 | { 424 | if (this[i - 1].Id != PointID.Control1) 425 | { 426 | e.Graphics.DrawLine(ctrlPen, this[i - 1].Coord, this[i].Coord); 427 | } 428 | } 429 | } 430 | } 431 | 432 | //Draw anchors 433 | if (ShowAnchors) 434 | { 435 | for (int i = 0; i < this.Count; i++) 436 | { 437 | if (this[i].Id == PointID.Anchor) 438 | { 439 | if ((highLited != -1) && (i == highLited)) 440 | { 441 | e.Graphics.FillEllipse(anchorLight, this[i].Rect); 442 | } 443 | else 444 | e.Graphics.FillEllipse(anchorBrush, this[i].Rect); 445 | //e.Graphics.DrawEllipse(Pens.Red, this[i].Rect); 446 | } 447 | } 448 | } 449 | 450 | //Draw Controls Points 451 | //Backward loop 452 | if (ShowControls) 453 | { 454 | for (int i = this.Count-1; i > -1; i--) 455 | { 456 | if ((this[i].Id == PointID.Control1) | (this[i].Id == PointID.Control2)) 457 | { 458 | if ((highLited != -1) && (i == highLited)) 459 | { 460 | e.Graphics.FillEllipse(ctrlLight, this[i].Rect); 461 | } 462 | else 463 | e.Graphics.FillEllipse(ctrlBrush, this[i].Rect); 464 | //e.Graphics.DrawEllipse(Pens.Green, this[i].Rect); 465 | } 466 | } 467 | } 468 | 469 | } 470 | } 471 | 472 | public void MouseDown(MouseEventArgs e) 473 | { 474 | MouseDown(e.Location, e.Button); 475 | } 476 | 477 | public void MouseDown(Point location, MouseButtons mb ) 478 | { 479 | if (this.Count == 0) return; 480 | 481 | isStart = false; 482 | toMove = -1; 483 | // polyNum = -1; 484 | polyMoving = false; 485 | 486 | if (mb == MouseButtons.Left) 487 | { 488 | //Checking controls 489 | for (int i = 0; i < this.Count; i++) 490 | { 491 | if (this[i].Rect.Contains(location) && (this[i].Id != PointID.Anchor)) 492 | { 493 | skip1 = false; 494 | toMove = i; 495 | 496 | if ((i != 1) & (i != this.Count - 2)) 497 | { 498 | //Prepare for moving 499 | 500 | if (this[i].Id == PointID.Control1) 501 | { 502 | center1 = this[i - 1].Coord; 503 | second1 = this[i - 2]; 504 | } 505 | else 506 | { 507 | center1 = this[i + 1].Coord; 508 | second1 = this[i + 2]; 509 | 510 | } 511 | 512 | radius1 = Utils.getRadius(second1.Coord, center1); 513 | 514 | } 515 | else skip1 = true; 516 | 517 | return; 518 | } 519 | 520 | } 521 | 522 | //Checking anchors 523 | //Separate cycle because elements overlap each other 524 | for (int i = 0; i < this.Count; i++) 525 | { 526 | if (this[i].Rect.Contains(location) && (this[i].Id == PointID.Anchor)) 527 | { 528 | toMove = i; 529 | isStart = (i == 0); 530 | return; 531 | } 532 | 533 | } 534 | 535 | 536 | //Checking segment 537 | if (GetSegmentNumber(location)) 538 | { 539 | skip1 = false; 540 | skip2 = false; 541 | int polyPos = polyNum * 3; 542 | 543 | if (polyPos != 0) 544 | { 545 | center1 = this[polyPos].Coord; 546 | second1 = this[polyPos - 1]; 547 | radius1 = Utils.getRadius(second1.Coord, center1); 548 | } 549 | else 550 | skip1 = true; 551 | 552 | if (polyPos != this.Count - 4) 553 | { 554 | center2 = this[polyPos + 3].Coord; 555 | second2 = this[polyPos + 4]; 556 | radius2 = Utils.getRadius(second2.Coord, center2); 557 | } 558 | else 559 | skip2 = true; 560 | 561 | 562 | } 563 | 564 | } 565 | else 566 | if (mb == System.Windows.Forms.MouseButtons.Right) 567 | { 568 | if (polyNum == -1) 569 | { 570 | var snupping = Utils.GetSnappingPoint(location, snapRes); 571 | 572 | this.AddNode(snupping.X, snupping.Y); 573 | canvas.Refresh(); 574 | } 575 | } 576 | else if (mb == System.Windows.Forms.MouseButtons.Middle) 577 | { 578 | if (polyNum == -1) 579 | { 580 | 581 | for (int i = 0; i < this.Count; i++) 582 | { 583 | if (this[i].Rect.Contains(location) && (this[i].Id == PointID.Anchor)) 584 | { 585 | this.toMove = i; 586 | 587 | this.RemoveNode(toMove); 588 | canvas.Refresh(); 589 | 590 | return; 591 | } 592 | 593 | } 594 | } 595 | else 596 | { 597 | int pos = polyNum * 3; 598 | this.RemoveNode(pos); 599 | this.RemoveNode(pos); 600 | polyNum = -1; 601 | canvas.Refresh(); 602 | 603 | return; 604 | } 605 | 606 | } 607 | } 608 | 609 | public void MouseUp(MouseEventArgs e) 610 | { 611 | MouseUp(e.Location, e.Button); 612 | } 613 | 614 | public void MouseUp(Point location, MouseButtons mb) 615 | { 616 | 617 | if ((polyNum != -1) && (!polyMoving)) 618 | { 619 | InsertAtPoly(polyNum, location); 620 | 621 | polyNum = -1; 622 | } 623 | 624 | } 625 | 626 | public void MouseMove(MouseEventArgs e) 627 | { 628 | MouseMove(e.Location, e.Button); 629 | } 630 | 631 | public void MouseMove(Point location, MouseButtons mb) 632 | { 633 | if (mb == MouseButtons.Left) 634 | { 635 | if (polyNum != -1) 636 | { 637 | SetPolyPos(location); 638 | polyMoving = true; 639 | } 640 | else 641 | if (toMove != -1) 642 | { 643 | var ourPoint = this[toMove]; 644 | 645 | switch (ourPoint.Id) 646 | { 647 | case PointID.Anchor: 648 | 649 | Point locPoint = location; 650 | 651 | if (isSnap) 652 | { 653 | locPoint = Utils.GetSnappingPoint(location, snapRes); 654 | } 655 | 656 | SetAnchorPos(locPoint); 657 | break; 658 | 659 | 660 | case PointID.Control1: 661 | 662 | SetControlsPos(location); 663 | 664 | break; 665 | case PointID.Control2: 666 | 667 | SetControlsPos(location); 668 | 669 | break; 670 | default: 671 | break; 672 | } 673 | 674 | } 675 | 676 | } 677 | else 678 | { 679 | //If not Left Mouse Button 680 | //Finding element to highlight 681 | 682 | highLited = -1; 683 | polyNum = -1; 684 | 685 | //Finding Control 686 | for (int i = 0; i < this.Count; i++) 687 | { 688 | if (this[i].Rect.Contains(location) && (this[i].Id != PointID.Anchor)) 689 | { 690 | highLited = i; 691 | break; 692 | } 693 | } 694 | 695 | 696 | //Finding Anchor 697 | if (highLited == -1) 698 | { 699 | for (int i = 0; i < this.Count; i++) 700 | { 701 | if (this[i].Rect.Contains(location) && (this[i].Id == PointID.Anchor)) 702 | { 703 | highLited = i; 704 | break; 705 | } 706 | } 707 | } 708 | 709 | //Finding Line 710 | if (highLited == -1) 711 | GetSegmentNumber(location); 712 | } 713 | 714 | canvas.Invalidate(); 715 | } 716 | 717 | private bool GetSegmentNumber(Point location) 718 | { 719 | if (this.gp.IsOutlineVisible(location, pathPen)) 720 | { 721 | int polys = this.Count / 3; 722 | int inc = 0; 723 | 724 | for (int k = 0; k < polys; k++) 725 | { 726 | Point[] rrr = new Point[4]; 727 | 728 | for (int i = 0; i < 4; i++) 729 | { 730 | rrr[i] = this[inc + i].Coord; 731 | } 732 | 733 | inc += 3; 734 | 735 | var segmentPath = new GraphicsPath(); 736 | 737 | //Oh, it's a line! 738 | if ((rrr[0] == rrr[1]) && (rrr[2] == rrr[3])) 739 | { 740 | segmentPath.AddLine(rrr[0], rrr[2]); 741 | } 742 | else 743 | { 744 | segmentPath.AddBezier(rrr[0], rrr[1], rrr[2], rrr[3]); 745 | } 746 | 747 | if (segmentPath.IsOutlineVisible(location, pathPen)) 748 | { 749 | polyNum = k; 750 | oldMousePoint = location; 751 | break; 752 | } 753 | 754 | segmentPath.Dispose(); 755 | } 756 | } 757 | 758 | return (polyNum != -1); 759 | } 760 | 761 | #endregion 762 | 763 | #region Export points 764 | 765 | private Point[] ToPointArray() 766 | { 767 | var resArr = new Point[this.Count]; 768 | 769 | for (int i = 0; i < this.Count; i++) 770 | { 771 | resArr[i] = this[i].Coord; 772 | } 773 | return resArr; 774 | } 775 | 776 | public List ToPixels() 777 | { 778 | var temp = new List(); 779 | 780 | GraphicsPath gp = new GraphicsPath(); 781 | 782 | gp.AddBeziers(ToPointArray()); 783 | gp.Flatten(null, 0.1f); 784 | 785 | for (int i = 0; i < gp.PointCount - 1; i++) 786 | { 787 | var xsss = Utils.GetPointsOnLine((int)gp.PathPoints[i].X, (int)gp.PathPoints[i].Y, (int)gp.PathPoints[i + 1].X, (int)gp.PathPoints[i + 1].Y); 788 | temp.AddRange(xsss); 789 | 790 | if (i != gp.PointCount - 1) 791 | temp.RemoveAt(temp.Count - 1); 792 | } 793 | return temp; 794 | } 795 | 796 | internal List ToPoints() 797 | { 798 | var temp = new List(); 799 | // gp.Flatten(null, 0.1f); 800 | 801 | for (int i = 0; i < this.Count; i++) 802 | { 803 | temp.Add(this[i].Coord); 804 | } 805 | 806 | return temp; 807 | } 808 | 809 | public List ToPolyline() 810 | { 811 | var temp = new List(); 812 | gp.Flatten(null, 0.1f); 813 | 814 | for (int i = 0; i < this.Count; i++) 815 | { 816 | temp.Add(this[i].Coord); 817 | } 818 | 819 | return temp; 820 | } 821 | 822 | public List ToPolylineF() 823 | { 824 | var temp = new List(); 825 | gp.Flatten(null, 0.1f); 826 | 827 | for (int i = 0; i < gp.PathPoints.Length; i++) 828 | { 829 | temp.Add(gp.PathPoints[i]); 830 | } 831 | 832 | return temp; 833 | } 834 | 835 | #endregion 836 | } 837 | 838 | #region Helper classes 839 | 840 | public class BezierPoint 841 | { 842 | public BezierPoint(Point _coord, PointID id) 843 | { 844 | this.Coord = _coord; 845 | this.Id = id; 846 | UpdateRect(); 847 | } 848 | 849 | private void UpdateRect() 850 | { 851 | int Size; 852 | 853 | if (Id == PointID.Anchor) 854 | Size = BezierLine.anchorSize; 855 | else 856 | Size = BezierLine.controlSize; 857 | 858 | int Rad = Size / 2; 859 | 860 | Rect = new Rectangle(Coord.X - Rad, Coord.Y - Rad, Size, Size); 861 | } 862 | 863 | 864 | 865 | internal void ForceUpdateRect() 866 | { 867 | UpdateRect(); 868 | } 869 | 870 | 871 | 872 | //Properties----------------- 873 | 874 | private Point coord; 875 | public Point Coord 876 | { 877 | get 878 | { 879 | return coord; 880 | } 881 | set 882 | { 883 | coord = value; 884 | UpdateRect(); 885 | } 886 | } 887 | 888 | public PointID Id { set; get; } 889 | public Rectangle Rect { set; get; } 890 | 891 | } 892 | 893 | public class Utils 894 | { 895 | public static Color HighlightColor(Color input) 896 | { 897 | if (input.GetBrightness() < 0.7f) 898 | return ControlPaint.Light(input); 899 | else 900 | return ControlPaint.Dark(input); 901 | } 902 | 903 | public static List GetPointsOnLine(int x0, int y0, int x1, int y1) 904 | { 905 | bool steep = Math.Abs(y1 - y0) > Math.Abs(x1 - x0); 906 | bool isreverse = false; 907 | List temp = new List(); 908 | 909 | if (steep) 910 | { 911 | int t; 912 | t = x0; // swap x0 and y0 913 | x0 = y0; 914 | y0 = t; 915 | t = x1; // swap x1 and y1 916 | x1 = y1; 917 | y1 = t; 918 | } 919 | 920 | if (x0 > x1) 921 | { 922 | isreverse = true; 923 | int t; 924 | t = x0; // swap x0 and x1 925 | x0 = x1; 926 | x1 = t; 927 | t = y0; // swap y0 and y1 928 | y0 = y1; 929 | y1 = t; 930 | } 931 | int dx = x1 - x0; 932 | int dy = Math.Abs(y1 - y0); 933 | int error = dx / 2; 934 | int ystep = (y0 < y1) ? 1 : -1; 935 | int y = y0; 936 | for (int x = x0; x <= x1; x++) 937 | { 938 | temp.Add(new Point((steep ? y : x), (steep ? x : y))); 939 | error = error - dy; 940 | if (error < 0) 941 | { 942 | y += ystep; 943 | error += dx; 944 | } 945 | } 946 | 947 | if (isreverse) 948 | { 949 | temp.Reverse(); 950 | } 951 | return temp; 952 | } 953 | 954 | 955 | public static Point setRotation(double radius, Point point, Point centerPoint, double angle) 956 | { 957 | return new Point((int)(Math.Cos(angle) * radius + centerPoint.X), (int)(Math.Sin(angle) * radius + centerPoint.Y)); 958 | } 959 | 960 | 961 | public static double getAngleRad(Point origin, Point target) 962 | { 963 | return Math.Atan2(origin.Y - target.Y, origin.X - target.X); 964 | } 965 | 966 | 967 | public static double getRadius(Point pointA, Point pointB) 968 | { 969 | double width; 970 | double height; 971 | 972 | if (pointA.X > pointB.Y) 973 | { 974 | width = pointA.X - pointB.X; 975 | } 976 | else 977 | { 978 | width = pointB.X - pointA.X; 979 | } 980 | 981 | if (pointA.Y > pointB.Y) 982 | { 983 | height = pointA.Y - pointB.Y; 984 | } 985 | else 986 | { 987 | height = pointB.Y - pointA.Y; 988 | } 989 | 990 | return Math.Sqrt(Math.Pow(width, 2) + Math.Pow(height, 2)); 991 | } 992 | 993 | public static Point GetSnappingPoint(Point mouse, int cellSize) 994 | { 995 | //Get x interval based on cell width 996 | var xInterval = GetInterval(mouse.X, cellSize); 997 | 998 | //Get y interal based in cell height 999 | var yInterval = GetInterval(mouse.Y, cellSize); 1000 | 1001 | // return the point on cell grid closest to the mouseposition 1002 | return new Point() 1003 | { 1004 | X = Math.Abs(xInterval.Lower - mouse.X) > Math.Abs(xInterval.Upper - mouse.X) ? xInterval.Upper : xInterval.Lower, 1005 | Y = Math.Abs(yInterval.Lower - mouse.Y) > Math.Abs(yInterval.Upper - mouse.Y) ? yInterval.Upper : yInterval.Lower, 1006 | }; 1007 | } 1008 | 1009 | private static Interval GetInterval(int mousePos, int size) 1010 | { 1011 | return new Interval() 1012 | { 1013 | Lower = ((mousePos / size)) * size, 1014 | Upper = ((mousePos / size)) * size + size 1015 | }; 1016 | } 1017 | 1018 | class Interval 1019 | { 1020 | public int Lower { get; set; } 1021 | public int Upper { get; set; } 1022 | } 1023 | } 1024 | 1025 | #endregion 1026 | 1027 | } 1028 | --------------------------------------------------------------------------------