private void libInit(initCompleteHandler initCompleted) { //FormattedText ft = new FormattedText("OhMyDanmaku", CultureInfo.GetCultureInfo("zh-cn"), FlowDirection.LeftToRight, new Typeface("Microsoft YaHei"), danmaku_FontSize, Brushes.Black); // Create a test danmaku to calculate row OutlinedTextBlock _testDanmaku = new OutlinedTextBlock(); _testDanmaku.Text = "OhMyDanmaku"; _testDanmaku.FontFamily = (FontFamily) new FontFamilyConverter().ConvertFromString("Microsoft YaHei"); _testDanmaku.Name = "uni_testheight"; _testDanmaku.FontSize = danmaku_FontSize; _testDanmaku.FontWeight = FontWeights.Bold; _testDanmaku.Loaded += delegate(object o, RoutedEventArgs e) { calcRow(system_RenderCanvas.Height, _testDanmaku.Name, _testDanmaku.ActualHeight); if (system_enableAPCS) { preventCoverInit(initCompleted); } else { initCompleted(); } }; system_RenderCanvas.Children.Add(_testDanmaku); system_RenderCanvas.RegisterName(_testDanmaku.Name, _testDanmaku); }
private void calcRow(double _renderHeight, string _testTargetName, double _fontHeight) { //Remove the test danmaku OutlinedTextBlock _testtargetDanmaku = system_RenderCanvas.FindName(_testTargetName) as OutlinedTextBlock; system_RenderCanvas.Children.Remove(_testtargetDanmaku); system_RenderCanvas.UnregisterName(_testTargetName); //total Row slots _maxRow = (int)(_renderHeight / _fontHeight); //Row Height manual_danmaku_rowHeight = (int)_fontHeight; }
private void doAnimation(string _targetUniqueName, int _duration, int _row) { OutlinedTextBlock _targetDanmaku = system_RenderCanvas.FindName(_targetUniqueName) as OutlinedTextBlock; double _danmakuWidth = _targetDanmaku.ActualWidth; DoubleAnimation _doubleAnimation = new DoubleAnimation(system_RenderCanvas.Width, -_danmakuWidth, new Duration(TimeSpan.FromMilliseconds(_duration)), FillBehavior.Stop); Storyboard _sb = new Storyboard(); Storyboard.SetTarget(_doubleAnimation, _targetDanmaku); Storyboard.SetTargetProperty(_doubleAnimation, new PropertyPath("(Canvas.Left)")); _sb.Completed += delegate(object o, EventArgs e) { removeOutdateDanmaku(_targetDanmaku.Name, _row); }; //remove danmaku after animation end _sb.Children.Add(_doubleAnimation); _sb.Begin(); }
/// <summary> /// Create a danmaku manually, instead of using default construct method params. /// </summary> /// <param name="_content">Danmaku Content</param> /// <param name="_targetRow">Target row slot, check "getRowNumbers" method</param> /// <param name="_rowHeight">Row slot height, check "getNormalRowHeight" method</param> /// <param name="_fontSize">Danmaku font size</param> /// <param name="_duration">Danmaku stay duration cross the render area</param> /// <param name="_R">Danmaku color red</param> /// <param name="_G">Danmaku color green</param> /// <param name="_B">Danmaku color blue</param> /// <param name="_enableShadow">Danmaku shadow</param> public void createDanmaku(string _content, int _targetRow, int _rowHeight, int _fontSize, int _duration, byte _R, byte _G, byte _B, bool _enableShadow) //_targetRow counting from zero { OutlinedTextBlock _singleDanmaku = new OutlinedTextBlock(); _singleDanmaku.Text = _content; _singleDanmaku.FontFamily = (FontFamily) new FontFamilyConverter().ConvertFromString("Microsoft YaHei"); _singleDanmaku.Name = "uni_" + getRandomString(ra.Next(5, 8)); _singleDanmaku.FontSize = _fontSize; _singleDanmaku.SetValue(Canvas.TopProperty, (double)_targetRow * _rowHeight); _singleDanmaku.Fill = new SolidColorBrush(Color.FromRgb(_R, _G, _B)); _singleDanmaku.CacheMode = new BitmapCache(); _singleDanmaku.FontWeight = FontWeights.Bold; if (_enableShadow == true) { DropShadowEffect _ef = new DropShadowEffect(); _ef.RenderingBias = RenderingBias.Performance; _ef.Opacity = (double)100; _ef.ShadowDepth = (double)0; _ef.BlurRadius = (double)11; if (_R == 0 && _G == 0 && _B == 0) { _ef.Color = Color.FromRgb(255, 255, 255); } else { _ef.Color = Color.FromRgb(0, 0, 0); } _singleDanmaku.Effect = _ef; } _singleDanmaku.Loaded += delegate(object o, RoutedEventArgs e) { doAnimation(_singleDanmaku.Name, _duration, _targetRow); }; //add animation system_RenderCanvas.Children.Add(_singleDanmaku); system_RenderCanvas.RegisterName(_singleDanmaku.Name, _singleDanmaku); if (system_enableAPCS) { lockRow(_targetRow); } }
private void removeOutdateDanmaku(string _targetUniqueName, int _row) { OutlinedTextBlock ready2remove = system_RenderCanvas.FindName(_targetUniqueName) as OutlinedTextBlock; if (ready2remove != null) { system_RenderCanvas.Children.Remove(ready2remove); system_RenderCanvas.UnregisterName(_targetUniqueName); ready2remove = null; if (system_enableAPCS) { unlockRow(_row); } } else { Console.WriteLine("Remove Danmaku Error."); } }
private void libInit(initCompleteHandler initCompleted) { //FormattedText ft = new FormattedText("OhMyDanmaku", CultureInfo.GetCultureInfo("zh-cn"), FlowDirection.LeftToRight, new Typeface("Microsoft YaHei"), danmaku_FontSize, Brushes.Black); // Create a test danmaku to calculate row OutlinedTextBlock _testDanmaku = new OutlinedTextBlock(); _testDanmaku.Text = "OhMyDanmaku"; _testDanmaku.FontFamily = (FontFamily)new FontFamilyConverter().ConvertFromString("Microsoft YaHei"); _testDanmaku.Name = "uni_testheight"; _testDanmaku.FontSize = danmaku_FontSize; _testDanmaku.FontWeight = FontWeights.Bold; _testDanmaku.Loaded += delegate(object o, RoutedEventArgs e) { calcRow(system_RenderCanvas.Height, _testDanmaku.Name, _testDanmaku.ActualHeight); if (system_enableAPCS) { preventCoverInit(initCompleted); } else { initCompleted(); } }; system_RenderCanvas.Children.Add(_testDanmaku); system_RenderCanvas.RegisterName(_testDanmaku.Name, _testDanmaku); }
//_targetRow counting from zero /// <summary> /// Create a danmaku manually, instead of using default construct method params. /// </summary> /// <param name="_content">Danmaku Content</param> /// <param name="_targetRow">Target row slot, check "getRowNumbers" method</param> /// <param name="_rowHeight">Row slot height, check "getNormalRowHeight" method</param> /// <param name="_fontSize">Danmaku font size</param> /// <param name="_duration">Danmaku stay duration cross the render area</param> /// <param name="_R">Danmaku color red</param> /// <param name="_G">Danmaku color green</param> /// <param name="_B">Danmaku color blue</param> /// <param name="_enableShadow">Danmaku shadow</param> public void createDanmaku(string _content, int _targetRow, int _rowHeight, int _fontSize, int _duration, byte _R, byte _G, byte _B, bool _enableShadow) { OutlinedTextBlock _singleDanmaku = new OutlinedTextBlock(); _singleDanmaku.Text = _content; _singleDanmaku.FontFamily = (FontFamily)new FontFamilyConverter().ConvertFromString("Microsoft YaHei"); _singleDanmaku.Name = "uni_" + getRandomString(ra.Next(5, 8)); _singleDanmaku.FontSize = _fontSize; _singleDanmaku.SetValue(Canvas.TopProperty, (double)_targetRow * _rowHeight); _singleDanmaku.Fill = new SolidColorBrush(Color.FromRgb(_R, _G, _B)); _singleDanmaku.CacheMode = new BitmapCache(); _singleDanmaku.FontWeight = FontWeights.Bold; if (_enableShadow == true) { DropShadowEffect _ef = new DropShadowEffect(); _ef.RenderingBias = RenderingBias.Performance; _ef.Opacity = (double)100; _ef.ShadowDepth = (double)0; _ef.BlurRadius = (double)11; if (_R == 0 && _G == 0 && _B == 0) { _ef.Color = Color.FromRgb(255, 255, 255); } else { _ef.Color = Color.FromRgb(0, 0, 0); } _singleDanmaku.Effect = _ef; } _singleDanmaku.Loaded += delegate(object o, RoutedEventArgs e) { doAnimation(_singleDanmaku.Name, _duration, _targetRow); }; //add animation system_RenderCanvas.Children.Add(_singleDanmaku); system_RenderCanvas.RegisterName(_singleDanmaku.Name, _singleDanmaku); if (system_enableAPCS) { lockRow(_targetRow); } }