Пример #1
0
        private async Task <Grid> CreateNewDanmuControl(DanmakuModel m)
        {
            switch (DanmakuStyle)
            {
            case DanmakuBorderStyle.WithoutStroke:
                return(DanmakuItemControl.CreateControlNoBorder((float)DanmakuSizeZoom, DanmakuBold, DanmakuFontFamily, m));

            case DanmakuBorderStyle.Stroke:
                return(await DanmakuItemControl.CreateControlBorder((float)DanmakuSizeZoom, DanmakuBold, DanmakuFontFamily, m));

            default:
                return(DanmakuItemControl.CreateControlOverlap((float)DanmakuSizeZoom, DanmakuBold, DanmakuFontFamily, m));
            }
        }
Пример #2
0
        /// <summary>
        ///  添加底部弹幕
        /// </summary>
        /// <param name="m">参数</param>
        /// <param name="own">是否自己发送的</param>
        public async void AddBottomDanmu(DanmakuModel m, bool own)
        {
            Grid grid = null;

            switch (borderStyle)
            {
            case DanmakuBorderStyle.Default:
                grid = DanmakuItemControl.CreateControlOverlap((float)sizeZoom, bold, font, m);
                break;

            case DanmakuBorderStyle.NoBorder:
                grid = DanmakuItemControl.CreateControlNoBorder((float)sizeZoom, bold, font, m);
                break;

            case DanmakuBorderStyle.Shadow:
                grid = DanmakuItemControl.CreateControlShadow((float)sizeZoom, bold, font, m);
                break;

            case DanmakuBorderStyle.BorderV2:
                grid = await DanmakuItemControl.CreateControlBorder((float)sizeZoom, bold, font, m);

                break;

            default:
                break;
            }
            if (own)
            {
                grid.BorderBrush     = new SolidColorBrush(m.color);
                grid.BorderThickness = new Thickness(1);
            }
            grid.HorizontalAlignment = HorizontalAlignment.Center;
            grid.VerticalAlignment   = VerticalAlignment.Top;
            Grid.SetRow(grid, ComputeBottomRow());
            grid_Bottom.Children.Add(grid);


            //创建空转换动画
            TranslateTransform moveTransform = new TranslateTransform();
            //创建动画
            Duration        duration           = new Duration(TimeSpan.FromSeconds(5));
            DoubleAnimation myDoubleAnimationX = new DoubleAnimation();

            myDoubleAnimationX.Duration = duration;
            //创建故事版
            Storyboard moveStoryboard = new Storyboard();

            moveStoryboard.Duration = duration;
            moveStoryboard.Children.Add(myDoubleAnimationX);
            Storyboard.SetTarget(myDoubleAnimationX, moveTransform);
            //故事版加入动画
            Storyboard.SetTargetProperty(myDoubleAnimationX, "X");
            topBottomStoryList.Add(moveStoryboard);

            moveStoryboard.Completed += new EventHandler <object>((senders, obj) =>
            {
                grid_Bottom.Children.Remove(grid);
                grid.Children.Clear();
                grid = null;
                topBottomStoryList.Remove(moveStoryboard);
                moveStoryboard.Stop();
                moveStoryboard = null;
            });
            moveStoryboard.Begin();
        }
Пример #3
0
        public async void AddPositionDanmu(DanmakuModel m)
        {
            var data = Newtonsoft.Json.JsonConvert.DeserializeObject <object[]>(m.text);

            m.text = data[4].ToString().Replace("/n", "\r\n");
            Grid grid       = null;
            var  fontFamily = data[data.Length - 2].ToString();

            switch (borderStyle)
            {
            case DanmakuBorderStyle.Default:
                grid = DanmakuItemControl.CreateControlOverlap((float)sizeZoom, bold, fontFamily, m);
                break;

            case DanmakuBorderStyle.NoBorder:
                grid = DanmakuItemControl.CreateControlNoBorder((float)sizeZoom, bold, fontFamily, m);
                break;

            case DanmakuBorderStyle.Shadow:
                grid = DanmakuItemControl.CreateControlShadow((float)sizeZoom, bold, fontFamily, m);
                break;

            case DanmakuBorderStyle.BorderV2:
                grid = await DanmakuItemControl.CreateControlBorder((float)sizeZoom, bold, fontFamily, m);

                break;

            default:
                break;
            }

            grid.Tag = m;
            grid.HorizontalAlignment = HorizontalAlignment.Left;
            grid.VerticalAlignment   = VerticalAlignment.Center;

            double toX = 0;
            double toY = 0;

            double X = 0, Y = 0;
            double dur = 0;

            if (data.Length > 7)
            {
                X = data[0].ToDouble();
                Y = data[1].ToDouble();

                toX = data[7].ToDouble();
                toY = data[8].ToDouble();

                dur = data[10].ToDouble();
            }
            else
            {
                toX = data[0].ToDouble();
                toY = data[1].ToDouble();
            }
            if (toX < 1 && toY < 1)
            {
                toX = this.ActualWidth * toX;
                toY = this.ActualHeight * toY;
            }
            if (X < 1 && Y < 1)
            {
                X = this.ActualWidth * X;
                Y = this.ActualHeight * Y;
            }

            if (data.Length >= 7)
            {
                var             rotateZ    = data[5].ToDouble();
                var             rotateY    = data[6].ToDouble();
                PlaneProjection projection = new PlaneProjection();
                projection.RotationZ = -rotateZ;
                projection.RotationY = rotateY;
                grid.Projection      = projection;
            }

            //Canvas.SetLeft(grid, toX);
            //Canvas.SetTop(grid, toY);

            canvas.Children.Add(grid);


            double dmDuration  = data[3].ToDouble();
            var    opacitys    = data[2].ToString().Split('-');
            double opacityFrom = opacitys[0].ToDouble();
            double opacityTo   = opacitys[1].ToDouble();

            //创建故事版
            Storyboard moveStoryboard = new Storyboard();


            //if (X != toX || Y != toY)
            //{
            Duration duration = new Duration(TimeSpan.FromMilliseconds(dur));
            {
                DoubleAnimation myDoubleAnimationY = new DoubleAnimation();
                myDoubleAnimationY.Duration = duration;
                myDoubleAnimationY.From     = Y;
                myDoubleAnimationY.To       = toY;


                Storyboard.SetTarget(myDoubleAnimationY, grid);
                Storyboard.SetTargetProperty(myDoubleAnimationY, "(Canvas.Top)");
                moveStoryboard.Children.Add(myDoubleAnimationY);
            }
            {
                DoubleAnimation myDoubleAnimationX = new DoubleAnimation();
                myDoubleAnimationX.Duration = duration;
                myDoubleAnimationX.From     = X;
                myDoubleAnimationX.To       = toX;
                Storyboard.SetTarget(myDoubleAnimationX, grid);
                Storyboard.SetTargetProperty(myDoubleAnimationX, "(Canvas.Left)");
                moveStoryboard.Children.Add(myDoubleAnimationX);
            }
            //}
            //else
            //{
            //    Canvas.SetTop(grid,toY);
            //    Canvas.SetLeft(grid,toX);
            //}

            //透明度动画
            DoubleAnimation opacityAnimation = new DoubleAnimation()
            {
                Duration = new Duration(TimeSpan.FromSeconds(dmDuration)),
                From     = opacityFrom,
                To       = opacityTo
            };

            Storyboard.SetTarget(opacityAnimation, grid);
            Storyboard.SetTargetProperty(opacityAnimation, "Opacity");
            moveStoryboard.Children.Add(opacityAnimation);



            positionStoryList.Add(moveStoryboard);

            moveStoryboard.Completed += new EventHandler <object>((senders, obj) =>
            {
                canvas.Children.Remove(grid);
                positionStoryList.Remove(moveStoryboard);
            });
            moveStoryboard.Begin();
        }
Пример #4
0
        /// <summary>
        /// 添加直播滚动弹幕
        /// </summary>
        /// <param name="text">参数</param>
        /// <param name="own">是否自己发送的</param>
        /// <param name="color">颜色</param>
        public async void AddLiveDanmu(string text, bool own, Color?color)
        {
            if (color == null)
            {
                color = Colors.White;
            }
            var m = new DanmakuModel()
            {
                text     = text,
                color    = color.Value,
                location = DanmakuLocation.Roll,
                size     = 25
            };
            Grid grid = null;

            switch (borderStyle)
            {
            case DanmakuBorderStyle.Default:
                grid = DanmakuItemControl.CreateControlOverlap((float)sizeZoom, bold, font, m);
                break;

            case DanmakuBorderStyle.NoBorder:
                grid = DanmakuItemControl.CreateControlNoBorder((float)sizeZoom, bold, font, m);
                break;

            case DanmakuBorderStyle.Shadow:
                grid = DanmakuItemControl.CreateControlShadow((float)sizeZoom, bold, font, m);
                break;

            case DanmakuBorderStyle.BorderV2:
                grid = await DanmakuItemControl.CreateControlBorder((float)sizeZoom, bold, font, m);

                break;

            default:
                break;
            }
            if (own)
            {
                grid.BorderBrush     = new SolidColorBrush(color.Value);
                grid.BorderThickness = new Thickness(1);
            }
            var r = ComputeRollRow(grid);

            if (r == -1)
            {
                return;
            }
            Grid.SetRow(grid, r);
            grid.HorizontalAlignment = HorizontalAlignment.Left;
            grid.VerticalAlignment   = VerticalAlignment.Center;
            grid_Roll.Children.Add(grid);
            grid_Roll.UpdateLayout();

            TranslateTransform moveTransform = new TranslateTransform();

            moveTransform.X      = gv.ActualWidth;
            grid.RenderTransform = moveTransform;

            //创建动画
            Duration        duration           = new Duration(TimeSpan.FromSeconds(speed));
            DoubleAnimation myDoubleAnimationX = new DoubleAnimation();

            myDoubleAnimationX.Duration = duration;
            //创建故事版
            Storyboard moveStoryboard = new Storyboard();

            moveStoryboard.Duration = duration;
            myDoubleAnimationX.To   = -(grid.ActualWidth);//到达
            moveStoryboard.Children.Add(myDoubleAnimationX);
            Storyboard.SetTarget(myDoubleAnimationX, moveTransform);
            //故事版加入动画
            Storyboard.SetTargetProperty(myDoubleAnimationX, "X");
            rollStoryList.Add(moveStoryboard);

            moveStoryboard.Completed += new EventHandler <object>((senders, obj) =>
            {
                grid_Roll.Children.Remove(grid);
                grid.Children.Clear();
                grid = null;
                rollStoryList.Remove(moveStoryboard);
                moveStoryboard.Stop();
                moveStoryboard = null;
            });
            moveStoryboard.Begin();
        }