├── .gitignore ├── DanmakuChi.sln ├── DanmakuChi ├── App.xaml ├── App.xaml.cs ├── Danmaku.cs ├── DanmakuChi.csproj ├── DanmakuCurtain.xaml ├── DanmakuCurtain.xaml.cs ├── MainWindow.xaml ├── MainWindow.xaml.cs ├── OutlinedTextBlock.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ ├── Settings.settings │ └── app.manifest ├── QRCode.xaml ├── QRCode.xaml.cs ├── app.config └── packages.config ├── LICENSE └── README.md /.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 | -------------------------------------------------------------------------------- /DanmakuChi.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}") = "DanmakuChi", "DanmakuChi\DanmakuChi.csproj", "{F385529D-6598-49F9-8167-0ADA89637E4F}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | MyRelease|Any CPU = MyRelease|Any CPU 12 | Release|Any CPU = Release|Any CPU 13 | EndGlobalSection 14 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 15 | {F385529D-6598-49F9-8167-0ADA89637E4F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 16 | {F385529D-6598-49F9-8167-0ADA89637E4F}.Debug|Any CPU.Build.0 = Debug|Any CPU 17 | {F385529D-6598-49F9-8167-0ADA89637E4F}.MyRelease|Any CPU.ActiveCfg = MyRelease|Any CPU 18 | {F385529D-6598-49F9-8167-0ADA89637E4F}.MyRelease|Any CPU.Build.0 = MyRelease|Any CPU 19 | {F385529D-6598-49F9-8167-0ADA89637E4F}.Release|Any CPU.ActiveCfg = Release|Any CPU 20 | {F385529D-6598-49F9-8167-0ADA89637E4F}.Release|Any CPU.Build.0 = Release|Any CPU 21 | EndGlobalSection 22 | GlobalSection(SolutionProperties) = preSolution 23 | HideSolutionNode = FALSE 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /DanmakuChi/App.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /DanmakuChi/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.Data; 5 | using System.Linq; 6 | using System.Windows; 7 | 8 | namespace DanmakuChi { 9 | /// 10 | /// App.xaml 的交互逻辑 11 | /// 12 | public partial class App : Application { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /DanmakuChi/Danmaku.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading; 6 | using System.Windows; 7 | using System.Windows.Controls; 8 | using System.Windows.Data; 9 | using System.Windows.Documents; 10 | using System.Windows.Input; 11 | using System.Windows.Media; 12 | using System.Windows.Media.Animation; 13 | using System.Windows.Media.Effects; 14 | using System.Windows.Media.Imaging; 15 | using System.Windows.Navigation; 16 | using System.Windows.Shapes; 17 | using System.Windows.Threading; 18 | 19 | namespace DanmakuChi { 20 | /// 21 | /// Interactive logic of Danmaku Canvas 22 | /// 23 | public class OutlinedDanmaku : OutlinedTextBlock { 24 | public OutlinedDanmaku(string text) { 25 | FontSize = 36; 26 | Text = text; 27 | Fill = Brushes.White; 28 | Stroke = Brushes.Black; 29 | 30 | Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); 31 | Arrange(new Rect(0, 0, DesiredSize.Width, DesiredSize.Height)); 32 | } 33 | } 34 | 35 | public class ShadowDanmaku : TextBlock { 36 | //TODO: Optimizing the performance of danmaku animation with shadow. 37 | public ShadowDanmaku(string text) { 38 | FontSize = 36; 39 | Text = text; 40 | Foreground = Brushes.White; 41 | 42 | Effect = new DropShadowEffect { 43 | Color = Colors.Black, 44 | BlurRadius = 2, 45 | ShadowDepth = 1, 46 | Opacity = 1, 47 | RenderingBias = RenderingBias.Performance 48 | }; 49 | 50 | Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); 51 | Arrange(new Rect(0, 0, DesiredSize.Width, DesiredSize.Height)); 52 | } 53 | } 54 | 55 | 56 | public class DanmakuManager { 57 | private Grid container; 58 | 59 | private int lineHeight = 48; 60 | private int paddingTop = 8; 61 | 62 | private Boolean[] isOccupy; 63 | private Boolean enableShadowEffect; 64 | private int lines; 65 | 66 | public int usableLine() { 67 | for (int line = 0; line < lines; line += 1) { 68 | if (!isOccupy[line]) { 69 | isOccupy[line] = true; 70 | return line; 71 | } 72 | } 73 | return -1; 74 | } 75 | 76 | public void clearLine() { 77 | for (int line = 0; line < lines; line += 1) { 78 | isOccupy[line] = false; 79 | } 80 | } 81 | 82 | public int lineLocationY(int line) { 83 | return (line * lineHeight) + paddingTop; 84 | } 85 | 86 | public DanmakuManager(Grid grid, bool enableShadow) { 87 | container = grid; 88 | 89 | lines = (int)(container.RenderSize.Height / lineHeight) - 1; 90 | isOccupy = new Boolean[lines]; 91 | 92 | enableShadowEffect = enableShadow; 93 | } 94 | 95 | public void Shoot(string text) { 96 | var line = usableLine(); 97 | 98 | if (line == -1) { 99 | clearLine(); 100 | line = usableLine(); 101 | } 102 | 103 | FrameworkElement danmaku = new OutlinedDanmaku(text); 104 | // Danmaku initilization and display 105 | if (enableShadowEffect) { 106 | danmaku = new ShadowDanmaku(text); 107 | } 108 | 109 | danmaku.Margin = new Thickness(0, lineLocationY(line), 0, 0); 110 | container.Children.Add(danmaku); 111 | 112 | // Initilizing animation 113 | var anim = new DoubleAnimation(); 114 | anim.From = this.container.RenderSize.Width; 115 | anim.To = -danmaku.DesiredSize.Width - 1600; 116 | anim.SpeedRatio = danmaku.DesiredSize.Width > 80 ? 117 | (.05 * (danmaku.DesiredSize.Width / 1500 + 1)) : 118 | (.1 * ((100 - danmaku.DesiredSize.Width) / 100 + 1)); 119 | TranslateTransform trans = new TranslateTransform(); 120 | danmaku.RenderTransform = trans; 121 | 122 | // Handling the end of danmaku 123 | anim.Completed += new EventHandler(delegate (Object o, EventArgs a) { 124 | container.Children.Remove(danmaku); 125 | }); 126 | 127 | // Managing the danmaku lines 128 | var timer = new DispatcherTimer(); 129 | timer.Interval = TimeSpan.FromMilliseconds(300); 130 | timer.Tick += new EventHandler(delegate (Object o, EventArgs a) { 131 | Point relativePoint = danmaku.TransformToAncestor(container) 132 | .Transform(new Point(0, 0)); 133 | if (relativePoint.X < container.ActualWidth - danmaku.DesiredSize.Width - 50) { 134 | timer.Stop(); 135 | isOccupy[line] = false; 136 | } 137 | }); 138 | timer.Start(); 139 | 140 | // Play animation 141 | trans.BeginAnimation(TranslateTransform.XProperty, anim); 142 | } 143 | } 144 | } -------------------------------------------------------------------------------- /DanmakuChi/DanmakuChi.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {F385529D-6598-49F9-8167-0ADA89637E4F} 8 | WinExe 9 | Properties 10 | DanmakuChi 11 | DanmakuChi 12 | v4.0 13 | 512 14 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 15 | 4 16 | false 17 | 18 | publish\ 19 | true 20 | Disk 21 | false 22 | Foreground 23 | 7 24 | Days 25 | false 26 | false 27 | false 28 | true 29 | 0 30 | 1.2.0.0 31 | false 32 | true 33 | true 34 | 35 | 36 | x64 37 | true 38 | full 39 | false 40 | bin\Debug\ 41 | DEBUG;TRACE 42 | prompt 43 | 4 44 | false 45 | 46 | 47 | AnyCPU 48 | pdbonly 49 | true 50 | bin\Release\ 51 | TRACE 52 | prompt 53 | 4 54 | false 55 | 56 | 57 | A1630F66B2DBBAF3EE0A3C98B5AD2DB6A05FD469 58 | 59 | 60 | DanmakuChi_TemporaryKey.pfx 61 | 62 | 63 | true 64 | 65 | 66 | LocalIntranet 67 | 68 | 69 | Properties\app.manifest 70 | 71 | 72 | true 73 | 74 | 75 | bin\MyRelease\ 76 | TRACE 77 | true 78 | pdbonly 79 | AnyCPU 80 | prompt 81 | MinimumRecommendedRules.ruleset 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 4.0 97 | 98 | 99 | ..\packages\ThoughtWorks.QRCode.1.1.0\lib\ThoughtWorks.QRCode.dll 100 | True 101 | 102 | 103 | ..\packages\WebSocketSharp.1.0.3-rc9\lib\websocket-sharp.dll 104 | True 105 | 106 | 107 | 108 | 109 | 110 | ..\packages\YamlDotNet.3.7.0\lib\net35\YamlDotNet.dll 111 | True 112 | 113 | 114 | 115 | 116 | MSBuild:Compile 117 | Designer 118 | 119 | 120 | QRCode.xaml 121 | 122 | 123 | Designer 124 | MSBuild:Compile 125 | 126 | 127 | MSBuild:Compile 128 | Designer 129 | 130 | 131 | App.xaml 132 | Code 133 | 134 | 135 | 136 | DanmakuCurtain.xaml 137 | 138 | 139 | MainWindow.xaml 140 | 141 | 142 | Designer 143 | MSBuild:Compile 144 | 145 | 146 | 147 | 148 | 149 | Code 150 | 151 | 152 | True 153 | True 154 | Resources.resx 155 | 156 | 157 | True 158 | Settings.settings 159 | True 160 | 161 | 162 | ResXFileCodeGenerator 163 | Resources.Designer.cs 164 | 165 | 166 | 167 | 168 | 169 | 170 | SettingsSingleFileGenerator 171 | Settings.Designer.cs 172 | 173 | 174 | 175 | 176 | 177 | False 178 | Microsoft .NET Framework 4 %28x86 和 x64%29 179 | true 180 | 181 | 182 | False 183 | .NET Framework 3.5 SP1 184 | false 185 | 186 | 187 | False 188 | Windows Installer 4.5 189 | true 190 | 191 | 192 | 193 | 200 | -------------------------------------------------------------------------------- /DanmakuChi/DanmakuCurtain.xaml: -------------------------------------------------------------------------------- 1 |  13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /DanmakuChi/DanmakuCurtain.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Windows; 6 | using System.Windows.Controls; 7 | using System.Windows.Data; 8 | using System.Windows.Documents; 9 | using System.Windows.Input; 10 | using System.Windows.Media; 11 | using System.Windows.Media.Animation; 12 | using System.Windows.Media.Imaging; 13 | using System.Windows.Shapes; 14 | using System.Windows.Interop; 15 | using System.Runtime.InteropServices; 16 | 17 | namespace DanmakuChi { 18 | /// 19 | /// Window penetration 20 | /// 21 | public static class WindowsServices { 22 | const int WS_EX_TRANSPARENT = 0x00000020; 23 | const int GWL_EXSTYLE = (-20); 24 | 25 | [DllImport("user32.dll")] 26 | static extern int GetWindowLong(IntPtr hwnd, int index); 27 | 28 | [DllImport("user32.dll")] 29 | static extern int SetWindowLong(IntPtr hwnd, int index, int newStyle); 30 | 31 | public static void SetWindowExTransparent(IntPtr hwnd) { 32 | var extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE); 33 | SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_TRANSPARENT); 34 | } 35 | } 36 | /// 37 | /// Interactive logic of Danmaku.xaml 38 | /// 39 | public partial class DanmakuCurtain : Window { 40 | /// 41 | /// Window penetration 42 | /// 43 | #region Code of window penetration 44 | protected override void OnSourceInitialized(EventArgs e) { 45 | base.OnSourceInitialized(e); 46 | var hwnd = new WindowInteropHelper(this).Handle; 47 | WindowsServices.SetWindowExTransparent(hwnd); 48 | } 49 | #endregion 50 | public double screenHeight = SystemParameters.PrimaryScreenHeight; 51 | public double screenWidth = SystemParameters.PrimaryScreenWidth; 52 | 53 | private bool enableShadowEffect = false; 54 | 55 | private DanmakuManager dm = null; 56 | 57 | private void Window_Loaded(object sender, RoutedEventArgs e) { 58 | 59 | } 60 | 61 | 62 | public DanmakuCurtain(bool enableShadow) { 63 | InitializeComponent(); 64 | 65 | Top = 0; 66 | Left = 0; 67 | Width = screenWidth; 68 | Height = screenHeight; 69 | 70 | enableShadowEffect = enableShadow; 71 | } 72 | 73 | public void Shoot(string text) { 74 | if (dm == null) { 75 | dm = new DanmakuManager(curtain, enableShadowEffect); 76 | } 77 | dm.Shoot(text); 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /DanmakuChi/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  10 | 11 | 12 | 13 | 14 | 15 | 16 | 18 | 19 | 20 |