├── document └── demo.gif ├── ParticleOnTextCursor ├── App.config ├── Properties │ ├── Settings.settings │ ├── Settings.Designer.cs │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ └── Resources.resx ├── Program.cs ├── ParticleForm.Designer.cs ├── ParticleOnTextCursor.csproj ├── Particle.cs ├── ParticleForm.resx └── ParticleForm.cs ├── README.md ├── ParticleOnTextCursor.sln └── .gitignore /document/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/if1live/ParticleOnTextCursor/HEAD/document/demo.gif -------------------------------------------------------------------------------- /ParticleOnTextCursor/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /ParticleOnTextCursor/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ParticleOnTextCursor 2 | 3 | ## Overview 4 | Implement Particle effect on text cursor. 5 | 6 | ![Demo](https://raw.githubusercontent.com/if1live/ParticleOnTextCursor/master/document/demo.gif) 7 | 8 | Similar with https://github.com/codeinthedark/editor/pull/1 9 | 10 | ## TODO 11 | * Quit Program (Not implemented yet. Use Ctrl-Alt-Delete) 12 | * Select Particle Color from text's pixel color 13 | 14 | ## Special Thanks 15 | * Getting Caret Position Inside Any Application 16 | * http://www.codeproject.com/Articles/34520/Getting-Position-Inside-Any-Appli 17 | -------------------------------------------------------------------------------- /ParticleOnTextCursor/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using System.Windows.Forms; 6 | 7 | namespace ParticleOnTextCursor 8 | { 9 | static class Program 10 | { 11 | /// 12 | /// The main entry point for the application. 13 | /// 14 | [STAThread] 15 | static void Main() 16 | { 17 | Application.EnableVisualStyles(); 18 | Application.SetCompatibleTextRenderingDefault(false); 19 | Application.Run(new ParticleForm()); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /ParticleOnTextCursor.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.23107.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ParticleOnTextCursor", "ParticleOnTextCursor\ParticleOnTextCursor.csproj", "{DCAE25CD-6AEB-4438-85F6-939704247FE6}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {DCAE25CD-6AEB-4438-85F6-939704247FE6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {DCAE25CD-6AEB-4438-85F6-939704247FE6}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {DCAE25CD-6AEB-4438-85F6-939704247FE6}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {DCAE25CD-6AEB-4438-85F6-939704247FE6}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /ParticleOnTextCursor/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 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 ParticleOnTextCursor.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /ParticleOnTextCursor/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("ParticleOnTextCursor")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("ParticleOnTextCursor")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("dcae25cd-6aeb-4438-85f6-939704247fe6")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /ParticleOnTextCursor/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 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 ParticleOnTextCursor.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 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 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// Returns the cached ResourceManager instance used by this class. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ParticleOnTextCursor.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /ParticleOnTextCursor/ParticleForm.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace ParticleOnTextCursor 2 | { 3 | partial class ParticleForm 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 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 Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.components = new System.ComponentModel.Container(); 32 | this.txtCaretX = new System.Windows.Forms.TextBox(); 33 | this.txtCaretY = new System.Windows.Forms.TextBox(); 34 | this.lblCurrentApp = new System.Windows.Forms.TextBox(); 35 | this.timer1 = new System.Windows.Forms.Timer(this.components); 36 | this.particleTimer = new System.Windows.Forms.Timer(this.components); 37 | this.SuspendLayout(); 38 | // 39 | // txtCaretX 40 | // 41 | this.txtCaretX.Location = new System.Drawing.Point(13, 13); 42 | this.txtCaretX.Name = "txtCaretX"; 43 | this.txtCaretX.Size = new System.Drawing.Size(157, 21); 44 | this.txtCaretX.TabIndex = 0; 45 | // 46 | // txtCaretY 47 | // 48 | this.txtCaretY.Location = new System.Drawing.Point(13, 41); 49 | this.txtCaretY.Name = "txtCaretY"; 50 | this.txtCaretY.Size = new System.Drawing.Size(157, 21); 51 | this.txtCaretY.TabIndex = 1; 52 | // 53 | // lblCurrentApp 54 | // 55 | this.lblCurrentApp.Location = new System.Drawing.Point(13, 69); 56 | this.lblCurrentApp.Name = "lblCurrentApp"; 57 | this.lblCurrentApp.Size = new System.Drawing.Size(157, 21); 58 | this.lblCurrentApp.TabIndex = 2; 59 | // 60 | // timer1 61 | // 62 | this.timer1.Tick += new System.EventHandler(this.timer1_Tick); 63 | // 64 | // particleTimer 65 | // 66 | this.particleTimer.Interval = 20; 67 | this.particleTimer.Tick += new System.EventHandler(this.particleTimer_Tick); 68 | // 69 | // ParticleForm 70 | // 71 | this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F); 72 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 73 | this.ClientSize = new System.Drawing.Size(182, 125); 74 | this.Controls.Add(this.lblCurrentApp); 75 | this.Controls.Add(this.txtCaretY); 76 | this.Controls.Add(this.txtCaretX); 77 | this.Name = "ParticleForm"; 78 | this.Text = "Form1"; 79 | this.Load += new System.EventHandler(this.Form1_Load); 80 | this.ResumeLayout(false); 81 | this.PerformLayout(); 82 | 83 | } 84 | 85 | #endregion 86 | 87 | private System.Windows.Forms.TextBox txtCaretX; 88 | private System.Windows.Forms.TextBox txtCaretY; 89 | private System.Windows.Forms.TextBox lblCurrentApp; 90 | private System.Windows.Forms.Timer timer1; 91 | private System.Windows.Forms.Timer particleTimer; 92 | } 93 | } 94 | 95 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | build/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | 25 | # Visual Studo 2015 cache/options directory 26 | .vs/ 27 | 28 | # MSTest test Results 29 | [Tt]est[Rr]esult*/ 30 | [Bb]uild[Ll]og.* 31 | 32 | # NUNIT 33 | *.VisualState.xml 34 | TestResult.xml 35 | 36 | # Build Results of an ATL Project 37 | [Dd]ebugPS/ 38 | [Rr]eleasePS/ 39 | dlldata.c 40 | 41 | *_i.c 42 | *_p.c 43 | *_i.h 44 | *.ilk 45 | *.meta 46 | *.obj 47 | *.pch 48 | *.pdb 49 | *.pgc 50 | *.pgd 51 | *.rsp 52 | *.sbr 53 | *.tlb 54 | *.tli 55 | *.tlh 56 | *.tmp 57 | *.tmp_proj 58 | *.log 59 | *.vspscc 60 | *.vssscc 61 | .builds 62 | *.pidb 63 | *.svclog 64 | *.scc 65 | 66 | # Chutzpah Test files 67 | _Chutzpah* 68 | 69 | # Visual C++ cache files 70 | ipch/ 71 | *.aps 72 | *.ncb 73 | *.opensdf 74 | *.sdf 75 | *.cachefile 76 | 77 | # Visual Studio profiler 78 | *.psess 79 | *.vsp 80 | *.vspx 81 | 82 | # TFS 2012 Local Workspace 83 | $tf/ 84 | 85 | # Guidance Automation Toolkit 86 | *.gpState 87 | 88 | # ReSharper is a .NET coding add-in 89 | _ReSharper*/ 90 | *.[Rr]e[Ss]harper 91 | *.DotSettings.user 92 | 93 | # JustCode is a .NET coding addin-in 94 | .JustCode 95 | 96 | # TeamCity is a build add-in 97 | _TeamCity* 98 | 99 | # DotCover is a Code Coverage Tool 100 | *.dotCover 101 | 102 | # NCrunch 103 | _NCrunch_* 104 | .*crunch*.local.xml 105 | 106 | # MightyMoose 107 | *.mm.* 108 | AutoTest.Net/ 109 | 110 | # Web workbench (sass) 111 | .sass-cache/ 112 | 113 | # Installshield output folder 114 | [Ee]xpress/ 115 | 116 | # DocProject is a documentation generator add-in 117 | DocProject/buildhelp/ 118 | DocProject/Help/*.HxT 119 | DocProject/Help/*.HxC 120 | DocProject/Help/*.hhc 121 | DocProject/Help/*.hhk 122 | DocProject/Help/*.hhp 123 | DocProject/Help/Html2 124 | DocProject/Help/html 125 | 126 | # Click-Once directory 127 | publish/ 128 | 129 | # Publish Web Output 130 | *.[Pp]ublish.xml 131 | *.azurePubxml 132 | # TODO: Comment the next line if you want to checkin your web deploy settings 133 | # but database connection strings (with potential passwords) will be unencrypted 134 | *.pubxml 135 | *.publishproj 136 | 137 | # NuGet Packages 138 | *.nupkg 139 | # The packages folder can be ignored because of Package Restore 140 | **/packages/* 141 | # except build/, which is used as an MSBuild target. 142 | !**/packages/build/ 143 | # Uncomment if necessary however generally it will be regenerated when needed 144 | #!**/packages/repositories.config 145 | 146 | # Windows Azure Build Output 147 | csx/ 148 | *.build.csdef 149 | 150 | # Windows Store app package directory 151 | AppPackages/ 152 | 153 | # Others 154 | *.[Cc]ache 155 | ClientBin/ 156 | [Ss]tyle[Cc]op.* 157 | ~$* 158 | *~ 159 | *.dbmdl 160 | *.dbproj.schemaview 161 | *.pfx 162 | *.publishsettings 163 | node_modules/ 164 | bower_components/ 165 | 166 | # RIA/Silverlight projects 167 | Generated_Code/ 168 | 169 | # Backup & report files from converting an old project file 170 | # to a newer Visual Studio version. Backup files are not needed, 171 | # because we have git ;-) 172 | _UpgradeReport_Files/ 173 | Backup*/ 174 | UpgradeLog*.XML 175 | UpgradeLog*.htm 176 | 177 | # SQL Server files 178 | *.mdf 179 | *.ldf 180 | 181 | # Business Intelligence projects 182 | *.rdl.data 183 | *.bim.layout 184 | *.bim_*.settings 185 | 186 | # Microsoft Fakes 187 | FakesAssemblies/ 188 | 189 | # Node.js Tools for Visual Studio 190 | .ntvs_analysis.dat 191 | 192 | # Visual Studio 6 build log 193 | *.plg 194 | 195 | # Visual Studio 6 workspace options file 196 | *.opt 197 | -------------------------------------------------------------------------------- /ParticleOnTextCursor/ParticleOnTextCursor.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {DCAE25CD-6AEB-4438-85F6-939704247FE6} 8 | WinExe 9 | Properties 10 | ParticleOnTextCursor 11 | ParticleOnTextCursor 12 | v4.5.2 13 | 512 14 | true 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | Form 52 | 53 | 54 | ParticleForm.cs 55 | 56 | 57 | 58 | 59 | ParticleForm.cs 60 | 61 | 62 | ResXFileCodeGenerator 63 | Resources.Designer.cs 64 | Designer 65 | 66 | 67 | True 68 | Resources.resx 69 | 70 | 71 | SettingsSingleFileGenerator 72 | Settings.Designer.cs 73 | 74 | 75 | True 76 | Settings.settings 77 | True 78 | 79 | 80 | 81 | 82 | 83 | 84 | 91 | -------------------------------------------------------------------------------- /ParticleOnTextCursor/Particle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Drawing; 4 | using System.Reflection; 5 | 6 | namespace ParticleOnTextCursor 7 | { 8 | class Particle 9 | { 10 | public int x; 11 | public int y; 12 | public float vx; 13 | public float vy; 14 | public Color color; 15 | public int life; 16 | 17 | public Particle(int x, int y, float vx, float vy, Color color, int life) 18 | { 19 | this.x = x; 20 | this.y = y; 21 | this.vx = vx; 22 | this.vy = vy; 23 | this.color = color; 24 | this.life = life; 25 | } 26 | } 27 | 28 | class ParticleEmitter 29 | { 30 | public List AvailableColors 31 | { 32 | get 33 | { 34 | return availableColors; 35 | } 36 | } 37 | private List availableColors; 38 | private Random random = new Random(); 39 | 40 | public List Particles 41 | { 42 | get 43 | { 44 | return particles; 45 | } 46 | } 47 | private List particles = new List(); 48 | 49 | private List GetAllColors() 50 | { 51 | List allColors = new List(); 52 | 53 | foreach (PropertyInfo property in typeof(Color).GetProperties()) 54 | { 55 | if (property.PropertyType == typeof(Color)) 56 | { 57 | allColors.Add((Color)property.GetValue(null)); 58 | } 59 | } 60 | return allColors; 61 | } 62 | 63 | private List GetParticleColors() 64 | { 65 | // http://www.flounder.com/csharp_color_table.htm 66 | List colors = new List 67 | { 68 | Color.Blue, 69 | Color.CornflowerBlue, 70 | Color.Cyan, 71 | Color.Crimson, 72 | Color.DeepPink, 73 | Color.DeepSkyBlue, 74 | Color.MediumSpringGreen, 75 | 76 | }; 77 | return colors; 78 | } 79 | 80 | 81 | public ParticleEmitter() 82 | { 83 | //availableColors = GetAllColors(); 84 | availableColors = GetParticleColors(); 85 | } 86 | 87 | public Color SelectColor() 88 | { 89 | int idx = random.Next(availableColors.Count); 90 | return availableColors[idx]; 91 | } 92 | 93 | public int SelectLifeInterval() 94 | { 95 | int minLife = 80; 96 | int maxLife = 130; 97 | return random.Next(minLife, maxLife); 98 | } 99 | 100 | public Point SelectVelocity() 101 | { 102 | float minVelocity = 500; 103 | float maxVelocity = 890; 104 | float velocity = random.Next((int)minVelocity, (int)maxVelocity); 105 | 106 | int minAngle = 0; 107 | int maxAngle = 30; 108 | int angle = random.Next(minAngle, maxAngle); 109 | 110 | double vy = - Math.Cos((Math.PI / 180) * angle) * velocity; 111 | double vx = Math.Sin((Math.PI / 180) * angle) * velocity; 112 | 113 | int sign = random.Next(100) > 50 ? 1 : -1; 114 | vx = vx * sign; 115 | return new Point((int)vx, (int)vy); 116 | } 117 | 118 | public void Emit(int x, int y) 119 | { 120 | Color color = SelectColor(); 121 | for(int i = 0; i < 5; ++i) 122 | { 123 | EmitSingleParticle(x, y, color); 124 | } 125 | } 126 | 127 | public void EmitSingleParticle(int x, int y, Color color) 128 | { 129 | Point velocity = SelectVelocity(); 130 | float vx = velocity.X; 131 | float vy = velocity.Y; 132 | int life = SelectLifeInterval(); 133 | Particle p = new Particle(x, y, vx, vy, color, life); 134 | particles.Add(p); 135 | } 136 | 137 | public void Update(int ms) 138 | { 139 | float gravity = 10.0f; 140 | for(int i = 0; i < particles.Count; ++i) 141 | { 142 | Particle p = particles[i]; 143 | p.life -= ms; 144 | 145 | p.x += (int)(p.vx * ms / 1000.0f); 146 | p.y += (int)(p.vy * ms / 1000.0f); 147 | 148 | p.vy += gravity * ms; 149 | } 150 | particles.RemoveAll(p => p.life <= 0); 151 | } 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /ParticleOnTextCursor/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 | -------------------------------------------------------------------------------- /ParticleOnTextCursor/ParticleForm.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 | 17, 17 122 | 123 | 124 | 104, 17 125 | 126 | -------------------------------------------------------------------------------- /ParticleOnTextCursor/ParticleForm.cs: -------------------------------------------------------------------------------- 1 | // http://www.codeproject.com/Articles/34520/Getting-Position-Inside-Any-Appli 2 | ////////////////////////////////////////////////////////////////////////// 3 | // // 4 | // Anybody can Use, Modify, Redistribute this code freely. If this // 5 | // module has been helpful to you then just leave a comment on Website // 6 | // // 7 | ////////////////////////////////////////////////////////////////////////// 8 | 9 | using System; 10 | using System.Diagnostics; 11 | using System.Drawing; 12 | using System.Runtime.InteropServices; 13 | using System.Text; 14 | using System.Threading; 15 | using System.Windows.Forms; 16 | using System.Collections.Generic; 17 | 18 | namespace ParticleOnTextCursor 19 | { 20 | public partial class ParticleForm : Form 21 | { 22 | public ParticleForm() 23 | { 24 | InitializeComponent(); 25 | // http://stackoverflow.com/questions/4387680/transparent-background-on-winforms 26 | // Transparent background on winforms? 27 | this.BackColor = Color.LimeGreen; 28 | this.TransparencyKey = Color.LimeGreen; 29 | 30 | // http://stackoverflow.com/questions/7482922/remove-the-title-bar-in-windows-forms 31 | // Remove the title bar in Windows Forms 32 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; 33 | 34 | // http://stackoverflow.com/questions/505167/how-do-i-make-a-winforms-app-go-full-screen 35 | // How do I make a WinForms app go Full Screen 36 | this.WindowState = FormWindowState.Maximized; 37 | 38 | 39 | // Processing events from Hooks involves message queue complexities. 40 | // Timer has been used just to avoid that Mouse and Keyboard hooking 41 | // and to keep things simple. 42 | timer1.Start(); 43 | particleTimer.Start(); 44 | 45 | #if (!DEBUG) 46 | txtCaretX.Hide(); 47 | txtCaretY.Hide(); 48 | lblCurrentApp.Hide(); 49 | #endif 50 | } 51 | 52 | #region Data Members & Structures 53 | 54 | [StructLayout(LayoutKind.Sequential)] // Required by user32.dll 55 | public struct RECT 56 | { 57 | public uint Left; 58 | public uint Top; 59 | public uint Right; 60 | public uint Bottom; 61 | }; 62 | 63 | [StructLayout(LayoutKind.Sequential)] // Required by user32.dll 64 | public struct GUITHREADINFO 65 | { 66 | public uint cbSize; 67 | public uint flags; 68 | public IntPtr hwndActive; 69 | public IntPtr hwndFocus; 70 | public IntPtr hwndCapture; 71 | public IntPtr hwndMenuOwner; 72 | public IntPtr hwndMoveSize; 73 | public IntPtr hwndCaret; 74 | public RECT rcCaret; 75 | 76 | }; 77 | GUITHREADINFO guiInfo; // To store GUI Thread Information 78 | Point caretPosition; // To store Caret Position 79 | String prevActiveProcess = ""; 80 | 81 | #endregion 82 | 83 | #region winform always on top 84 | 85 | // http://www.c-sharpcorner.com/UploadFile/kirtan007/make-form-stay-always-on-top-of-every-window/ 86 | static readonly IntPtr HWND_TOPMOST = new IntPtr(-1); 87 | static readonly IntPtr HWND_NOTOPMOST = new IntPtr(-2); 88 | static readonly IntPtr HWND_TOP = new IntPtr(0); 89 | static readonly IntPtr HWND_BOTTOM = new IntPtr(1); 90 | const UInt32 SWP_NOSIZE = 0x0001; 91 | const UInt32 SWP_NOMOVE = 0x0002; 92 | const UInt32 TOPMOST_FLAGS = SWP_NOMOVE | SWP_NOSIZE; 93 | 94 | [DllImport("user32.dll")] 95 | [return: MarshalAs(UnmanagedType.Bool)] 96 | public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags); 97 | 98 | private void Form1_Load(object sender, EventArgs e) 99 | { 100 | SetWindowPos(this.Handle, HWND_TOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS); 101 | } 102 | #endregion 103 | 104 | 105 | #region DllImports 106 | 107 | 108 | /*- Retrieves Title Information of the specified window -*/ 109 | [DllImport("user32.dll")] 110 | static extern int GetWindowText(int hWnd, StringBuilder text, int count); 111 | 112 | /*- Retrieves Id of the thread that created the specified window -*/ 113 | [DllImport("user32.dll", SetLastError = true)] 114 | static extern uint GetWindowThreadProcessId(int hWnd, out uint lpdwProcessId); 115 | 116 | /*- Retrieves information about active window or any specific GUI thread -*/ 117 | [DllImport("user32.dll", EntryPoint = "GetGUIThreadInfo")] 118 | public static extern bool GetGUIThreadInfo(uint tId, out GUITHREADINFO threadInfo); 119 | 120 | /*- Retrieves Handle to the ForeGroundWindow -*/ 121 | [DllImport("user32.dll")] 122 | public static extern IntPtr GetForegroundWindow(); 123 | 124 | /*- Converts window specific point to screen specific -*/ 125 | [DllImport("user32.dll")] 126 | public static extern bool ClientToScreen(IntPtr hWnd, out Point position); 127 | 128 | 129 | #endregion 130 | 131 | #region Particle 132 | private ParticleEmitter emitter = new ParticleEmitter(); 133 | 134 | private int tickCount = 0; 135 | private void RenderParticle(Graphics g) 136 | { 137 | int size = 4; 138 | List colors = emitter.AvailableColors; 139 | foreach(Color c in colors) 140 | { 141 | var allParticles = emitter.Particles; 142 | var particles = allParticles.FindAll(p => p.color == c); 143 | 144 | Brush brush = new SolidBrush(c); 145 | foreach(Particle p in particles) 146 | { 147 | g.FillRectangle(brush, p.x, p.y, size, size); 148 | } 149 | } 150 | 151 | #if DEBUG 152 | // for tick debuggging 153 | tickCount = (tickCount + 1) % 100; 154 | Pen myPen = new Pen(Color.DeepSkyBlue); 155 | myPen.Width = 5; 156 | g.DrawLine(myPen, 1, 1, tickCount, 1); 157 | #endif 158 | } 159 | 160 | #endregion 161 | 162 | 163 | #region Event Handlers 164 | protected override void OnPaint(PaintEventArgs e) 165 | { 166 | Graphics g = e.Graphics; 167 | RenderParticle(g); 168 | } 169 | 170 | private void particleTimer_Tick(object sender, EventArgs e) 171 | { 172 | emitter.Update(particleTimer.Interval); 173 | Invalidate(); 174 | } 175 | 176 | private void timer1_Tick(object sender, EventArgs e) 177 | { 178 | // If Tooltip window is active window (Suppose user clicks on the Tooltip Window) 179 | if (GetForegroundWindow() == this.Handle) 180 | { 181 | // then do no processing 182 | return; 183 | } 184 | 185 | // Get Current active Process 186 | string activeProcess = GetActiveProcess(); 187 | 188 | // If window explorer is active window (eg. user has opened any drive) 189 | // Or for any failure when activeProcess is nothing 190 | if ((activeProcess.ToLower().Contains("explorer") | (activeProcess == string.Empty))) 191 | { 192 | // Dissappear Tooltip 193 | this.Visible = false; 194 | } 195 | else 196 | { 197 | Point prevCaretPosition = new Point(caretPosition.X, caretPosition.Y); 198 | 199 | // Otherwise Calculate Caret position 200 | EvaluateCaretPosition(); 201 | 202 | bool isParticleRequired = IsParticleRequired(prevActiveProcess, activeProcess, prevCaretPosition, caretPosition); 203 | if (isParticleRequired) 204 | { 205 | // Adjust ToolTip according to the Caret 206 | // 커서 위치에 맞춰서 창을 이동시킬 필요는 없을듯 207 | //AdjustUI(); 208 | emitter.Emit(caretPosition.X - 25, caretPosition.Y - 35); 209 | } 210 | 211 | // Display current active Process on Tooltip 212 | lblCurrentApp.Text = activeProcess; 213 | this.Visible = true; 214 | } 215 | 216 | // 기존에 활성화되어있던 프로세스 이름 저장해두기 217 | // 창이 바뀌는 경우는 파티클 효과 무시하려고 218 | prevActiveProcess = activeProcess; 219 | } 220 | #endregion 221 | 222 | #region Methods 223 | 224 | private bool IsParticleRequired(String prevActiveProcess, String currActiveProcess, Point prevCaretPosition, Point currCaretPosition) 225 | { 226 | if ((currActiveProcess.ToLower().Contains("explorer") | (currActiveProcess == string.Empty))) 227 | { 228 | return false; 229 | } 230 | #if DEBUG 231 | if (currActiveProcess == "devenv") 232 | { 233 | // skip visual studio 234 | return false; 235 | } 236 | #endif 237 | if (prevActiveProcess != currActiveProcess) 238 | { 239 | return false; 240 | } 241 | if (prevCaretPosition == currCaretPosition) 242 | { 243 | return false; 244 | } 245 | return true; 246 | } 247 | 248 | /// 249 | /// This function will adjust Tooltip position and 250 | /// will keep it always inside the screen area. 251 | /// 252 | private void AdjustUI() 253 | { 254 | // Get Current Screen Resolution 255 | Rectangle workingArea = SystemInformation.WorkingArea; 256 | 257 | // If current caret position throws Tooltip outside of screen area 258 | // then do some UI adjustment. 259 | if (caretPosition.X + this.Width > workingArea.Width) 260 | { 261 | caretPosition.X = caretPosition.X - this.Width - 50; 262 | } 263 | 264 | if (caretPosition.Y + this.Height > workingArea.Height) 265 | { 266 | caretPosition.Y = caretPosition.Y - this.Height - 50; 267 | } 268 | 269 | this.Left = caretPosition.X; 270 | this.Top = caretPosition.Y; 271 | } 272 | 273 | /// 274 | /// Evaluates Cursor Position with respect to client screen. 275 | /// 276 | private void EvaluateCaretPosition() 277 | { 278 | caretPosition = new Point(); 279 | 280 | // Fetch GUITHREADINFO 281 | GetCaretPosition(); 282 | 283 | caretPosition.X = (int)guiInfo.rcCaret.Left + 25; 284 | caretPosition.Y = (int)guiInfo.rcCaret.Bottom + 25; 285 | 286 | ClientToScreen(guiInfo.hwndCaret, out caretPosition); 287 | 288 | txtCaretX.Text = (caretPosition.X).ToString(); 289 | txtCaretY.Text = caretPosition.Y.ToString(); 290 | 291 | } 292 | 293 | /// 294 | /// Get the caret position 295 | /// 296 | public void GetCaretPosition() 297 | { 298 | guiInfo = new GUITHREADINFO(); 299 | guiInfo.cbSize = (uint)Marshal.SizeOf(guiInfo); 300 | 301 | // Get GuiThreadInfo into guiInfo 302 | GetGUIThreadInfo(0, out guiInfo); 303 | } 304 | 305 | /// 306 | /// Retrieves name of active Process. 307 | /// 308 | /// Active Process Name 309 | private string GetActiveProcess() 310 | { 311 | const int nChars = 256; 312 | int handle = 0; 313 | StringBuilder Buff = new StringBuilder(nChars); 314 | handle = (int)GetForegroundWindow(); 315 | 316 | // If Active window has some title info 317 | if (GetWindowText(handle, Buff, nChars) > 0) 318 | { 319 | uint lpdwProcessId; 320 | uint dwCaretID = GetWindowThreadProcessId(handle, out lpdwProcessId); 321 | uint dwCurrentID = (uint)Thread.CurrentThread.ManagedThreadId; 322 | return Process.GetProcessById((int)lpdwProcessId).ProcessName; 323 | } 324 | // Otherwise either error or non client region 325 | return String.Empty; 326 | } 327 | 328 | #endregion 329 | } 330 | } 331 | --------------------------------------------------------------------------------