/// <summary>
        /// Create a WPFDanmakuEngine instance
        /// </summary>
        /// <param name="TargetCanvas">Danmaku container</param>
        /// <param name="DefaultStyle">Default danmaku style</param>
        public WPFDanmakuEngine(Canvas TargetCanvas, BaseDanmaku DefaultStyle, DrawMode Mode)
        {
            mRandomObj = new Random();
            if (Mode == DrawMode.Performance) {
                throw new NotImplementedException("Still working on this");
            } else {
                CurrentDrawMode = DrawMode.Compatibility;

                if (TargetCanvas.IsLoaded) {
                    this.mBindingCanvas = TargetCanvas;
                } else {
                    throw new InvalidOperationException("Canvas is not ready.");
                }

                this.mDefaultStyle = DefaultStyle;
                GenerateWPFCache();
            }
        }
Beispiel #2
0
        /// <summary>
        /// Create a WPFDanmakuEngine instance
        /// </summary>
        /// <param name="TargetCanvas">Danmaku container</param>
        /// <param name="DefaultStyle">Default danmaku style</param>
        public WPFDanmakuEngine(Canvas TargetCanvas, BaseDanmaku DefaultStyle, DrawMode Mode)
        {
            mRandomObj = new Random();
            if (Mode == DrawMode.Performance)
            {
                throw new NotImplementedException("Still working on this");
            }
            else
            {
                CurrentDrawMode = DrawMode.Compatibility;

                if (TargetCanvas.IsLoaded)
                {
                    this.mBindingCanvas = TargetCanvas;
                }
                else
                {
                    throw new InvalidOperationException("Canvas is not ready.");
                }

                this.mDefaultStyle = DefaultStyle;
                GenerateWPFCache();
            }
        }
Beispiel #3
0
        /// <summary>
        /// Draw a right to left danmaku on binding canvas
        /// </summary>
        /// <param name="Content">Danmaku content</param>
        /// <param name="Style">Override default danmaku style if needed</param>
        /// <returns></returns>
        public string DrawDanmaku_R2L(string Content, BaseDanmaku Style = null)
        {
            SolidColorBrush  _FillBrush;
            Duration         _duration;
            DropShadowEffect _ShadowEffect;

            if (Style == null || Style == mDefaultStyle)
            {
                Style         = mDefaultStyle;
                _FillBrush    = mCache_SolidColorBrush;
                _ShadowEffect = mCache_ShadowEffect;
                _duration     = mCache_Duration;
            }
            else
            {
                if (Style.Duration != mDefaultStyle.Duration)
                {
                    _duration = new Duration(TimeSpan.FromMilliseconds(Style.Duration));
                }
                else
                {
                    _duration = mCache_Duration;
                }

                if (Style.ColorR != mDefaultStyle.ColorR || Style.ColorG != mDefaultStyle.ColorG || Style.ColorB != mDefaultStyle.ColorB)
                {
                    _FillBrush    = new SolidColorBrush(Color.FromRgb(Style.ColorR, Style.ColorG, Style.ColorB));
                    _ShadowEffect = mCache_ShadowEffect;
                    if ((Style.ColorR + Style.ColorG + Style.ColorB + 1) / 3 >= 255 / 2)
                    {
                        _ShadowEffect.Color = Color.FromRgb(0, 0, 0);
                    }
                    else
                    {
                        _ShadowEffect.Color = Color.FromRgb(255, 255, 255);
                    }
                }
                else
                {
                    _ShadowEffect = mCache_ShadowEffect;
                    _FillBrush    = mCache_SolidColorBrush;
                }
            }

            OutlinedTextBlock _thisDanmaku = new OutlinedTextBlock();

            _thisDanmaku.Name = "uni_" + Utils.GetRandomString(5);

            // Style
            _thisDanmaku.Text       = Content;
            _thisDanmaku.FontFamily = Style.FontFamily;
            _thisDanmaku.FontSize   = Style.FontSize;
            _thisDanmaku.Fill       = _FillBrush;
            _thisDanmaku.SetValue(Canvas.TopProperty, Style.PositionX);
            _thisDanmaku.SetValue(Canvas.LeftProperty, Style.PositionY);
            _thisDanmaku.FontWeight = FontWeights.Bold;

            if (Style.Shadow)
            {
                _thisDanmaku.Effect = _ShadowEffect;
            }

            // Animation
            _thisDanmaku.Loaded += delegate(object o, RoutedEventArgs e) { AddR2LAnimation(_thisDanmaku.Name, _duration); };

            // Add to canvas
            BindingCanvas.Children.Add(_thisDanmaku);
            BindingCanvas.RegisterName(_thisDanmaku.Name, _thisDanmaku);

            return(_thisDanmaku.Name);
        }
        /// <summary>
        /// Draw a right to left danmaku on binding canvas
        /// </summary>
        /// <param name="Content">Danmaku content</param>
        /// <param name="Style">Override default danmaku style if needed</param>
        /// <returns></returns>
        public string DrawDanmaku_R2L(string Content, BaseDanmaku Style = null)
        {
            SolidColorBrush _FillBrush;
            Duration _duration;
            DropShadowEffect _ShadowEffect;
            if (Style == null || Style == mDefaultStyle) {
                Style = mDefaultStyle;
                _FillBrush = mCache_SolidColorBrush;
                _ShadowEffect = mCache_ShadowEffect;
                _duration = mCache_Duration;
            } else {
                if (Style.Duration != mDefaultStyle.Duration) {
                    _duration = new Duration(TimeSpan.FromMilliseconds(Style.Duration));
                } else {
                    _duration = mCache_Duration;
                }

                if (Style.ColorR != mDefaultStyle.ColorR || Style.ColorG != mDefaultStyle.ColorG || Style.ColorB != mDefaultStyle.ColorB) {
                    _FillBrush = new SolidColorBrush(Color.FromRgb(Style.ColorR, Style.ColorG, Style.ColorB));
                    _ShadowEffect = mCache_ShadowEffect;
                    if ((Style.ColorR + Style.ColorG + Style.ColorB + 1) / 3 >= 255 / 2) {
                        _ShadowEffect.Color = Color.FromRgb(0, 0, 0);
                    } else {
                        _ShadowEffect.Color = Color.FromRgb(255, 255, 255);
                    }
                } else {
                    _ShadowEffect = mCache_ShadowEffect;
                    _FillBrush = mCache_SolidColorBrush;
                }
            }

            OutlinedTextBlock _thisDanmaku = new OutlinedTextBlock();
            _thisDanmaku.Name = "uni_" + Utils.GetRandomString(5);

            // Style
            _thisDanmaku.Text = Content;
            _thisDanmaku.FontFamily = Style.FontFamily;
            _thisDanmaku.FontSize = Style.FontSize;
            _thisDanmaku.Fill = _FillBrush;
            _thisDanmaku.SetValue(Canvas.TopProperty, Style.PositionX);
            _thisDanmaku.SetValue(Canvas.LeftProperty, Style.PositionY);
            _thisDanmaku.FontWeight = FontWeights.Bold;

            if (Style.Shadow) {
                _thisDanmaku.Effect = _ShadowEffect;
            }

            // Animation
            _thisDanmaku.Loaded += delegate (object o, RoutedEventArgs e) { AddR2LAnimation(_thisDanmaku.Name, _duration); };

            // Add to canvas
            BindingCanvas.Children.Add(_thisDanmaku);
            BindingCanvas.RegisterName(_thisDanmaku.Name, _thisDanmaku);

            return _thisDanmaku.Name;
        }
 public MainWindow()
 {
     InitializeComponent();
     ra = new Random();
     bd = new BaseDanmaku();
 }