void IDanmakuWindow.AddDanmaku(DanmakuType type, string comment, uint color)
        {
            if ((this as Window).CheckAccess())
            {
                //<Storyboard x:Key="Storyboard1">
                //			<ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="fullScreenDanmaku">
                //				<EasingThicknessKeyFrame KeyTime="0" Value="3,0,0,0"/>
                //				<EasingThicknessKeyFrame KeyTime="0:0:1.9" Value="220,0,0,0"/>
                //			</ThicknessAnimationUsingKeyFrames>
                //		</Storyboard>
                lock (LayoutRoot.Children)
                {
                    var v = new FullScreenDanmaku();
                    v.Text.Text = comment;
                    v.ChangeHeight();
                    var wd = v.Text.DesiredSize.Width;

                    Dictionary<double, bool> dd = new Dictionary<double, bool>();
                    dd.Add(0, true);
                    foreach (var child in LayoutRoot.Children)
                    {
                        if (child is FullScreenDanmaku)
                        {
                            var c = child as FullScreenDanmaku;
                            if (!dd.ContainsKey(Convert.ToInt32(c.Margin.Top)))
                            {
                                dd.Add(Convert.ToInt32(c.Margin.Top), true);
                            }
                            if (c.Margin.Left > (SystemParameters.PrimaryScreenWidth - wd - 50))
                            {
                                dd[Convert.ToInt32(c.Margin.Top)] = false;
                            }
                        }
                    }
                    double top;
                    if (dd.All(p => p.Value == false))
                    {
                        top = dd.Max(p => p.Key) + v.Text.DesiredSize.Height;
                    }
                    else
                    {
                        top = dd.Where(p => p.Value).Min(p => p.Key);
                    }
                    // v.Height = v.Text.DesiredSize.Height;
                    // v.Width = v.Text.DesiredSize.Width;
                    Storyboard s = new Storyboard();
                    Duration duration =
                        new Duration(
                            TimeSpan.FromTicks(Convert.ToInt64((SystemParameters.PrimaryScreenWidth + wd) /
                                                               Store.FullOverlayEffect1 * TimeSpan.TicksPerSecond)));
                    ThicknessAnimation f =
                        new ThicknessAnimation(new Thickness(SystemParameters.PrimaryScreenWidth, top, 0, 0),
                            new Thickness(-wd, top, 0, 0), duration);
                    s.Children.Add(f);
                    s.Duration = duration;
                    Storyboard.SetTarget(f, v);
                    Storyboard.SetTargetProperty(f, new PropertyPath("(FrameworkElement.Margin)"));
                    LayoutRoot.Children.Add(v);
                    s.Completed += s_Completed;
                    s.Begin();
                }
            }
            else
            {
                this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(
                    () => (this as IDanmakuWindow).AddDanmaku(type, comment, color))
                );
            }
        }
Пример #2
0
        void IDanmakuWindow.AddDanmaku(DanmakuType type, string comment, uint color)
        {
            if ((this as Window).CheckAccess())
            {
                //<Storyboard x:Key="Storyboard1">
                //			<ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="fullScreenDanmaku">
                //				<EasingThicknessKeyFrame KeyTime="0" Value="3,0,0,0"/>
                //				<EasingThicknessKeyFrame KeyTime="0:0:1.9" Value="220,0,0,0"/>
                //			</ThicknessAnimationUsingKeyFrames>
                //		</Storyboard>
                lock (LayoutRoot.Children)
                {
                    var v = new FullScreenDanmaku();
                    v.Text.Text = comment;
                    v.ChangeHeight();
                    var wd = v.Text.DesiredSize.Width;

                    Dictionary <double, bool> dd = new Dictionary <double, bool>();
                    dd.Add(0, true);
                    foreach (var child in LayoutRoot.Children)
                    {
                        if (child is FullScreenDanmaku)
                        {
                            var c = child as FullScreenDanmaku;
                            if (!dd.ContainsKey(Convert.ToInt32(c.Margin.Top)))
                            {
                                dd.Add(Convert.ToInt32(c.Margin.Top), true);
                            }
                            if (c.Margin.Left > (SystemParameters.PrimaryScreenWidth - wd - 50))
                            {
                                dd[Convert.ToInt32(c.Margin.Top)] = false;
                            }
                        }
                    }
                    double top;
                    if (dd.All(p => p.Value == false))
                    {
                        top = dd.Max(p => p.Key) + v.Text.DesiredSize.Height;
                    }
                    else
                    {
                        top = dd.Where(p => p.Value).Min(p => p.Key);
                    }
                    // v.Height = v.Text.DesiredSize.Height;
                    // v.Width = v.Text.DesiredSize.Width;
                    Storyboard s        = new Storyboard();
                    Duration   duration =
                        new Duration(
                            TimeSpan.FromTicks(Convert.ToInt64((SystemParameters.PrimaryScreenWidth + wd) /
                                                               Store.FullOverlayEffect1 * TimeSpan.TicksPerSecond)));
                    ThicknessAnimation f =
                        new ThicknessAnimation(new Thickness(SystemParameters.PrimaryScreenWidth, top, 0, 0),
                                               new Thickness(-wd, top, 0, 0), duration);
                    s.Children.Add(f);
                    s.Duration = duration;
                    Storyboard.SetTarget(f, v);
                    Storyboard.SetTargetProperty(f, new PropertyPath("(FrameworkElement.Margin)"));
                    LayoutRoot.Children.Add(v);
                    s.Completed += s_Completed;
                    s.Begin();
                }
            }
            else
            {
                this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(
                                                () => (this as IDanmakuWindow).AddDanmaku(type, comment, color))
                                            );
            }
        }