コード例 #1
0
ファイル: MainWindow.xaml.cs プロジェクト: bajdcc/Danmuku
        private void s_Completed(object sender, EventArgs e)
        {
            ClockGroup clockGroup = sender as ClockGroup;

            if (clockGroup != null)
            {
                FullScreenDanmaku fullScreenDanmaku = Storyboard.GetTarget(clockGroup.Children[0].Timeline) as FullScreenDanmaku;
                if (fullScreenDanmaku != null)
                {
                    this.fulloverlay.LayoutRoot.Children.Remove(fullScreenDanmaku);
                }
            }
        }
コード例 #2
0
ファイル: MainWindow.xaml.cs プロジェクト: bajdcc/Danmuku
 public void AddDMText(string user, string text, bool warn)
 {
     if (user == null || text == null)
     {
         return;
     }
     if (Dispatcher.CheckAccess())
     {
         while (infos.Count >= 50)
         {
             infos.Dequeue();
         }
         if (warn)
         {
             infos.Enqueue($"! {text}\n");
         }
         else
         {
             if (string.IsNullOrEmpty(user))
             {
                 infos.Enqueue($"{text}\n");
             }
             else
             {
                 infos.Enqueue($"{user}: {text}\n");
             }
         }
         this.textBox.Text = string.Join("\n", infos);
         this.textBox.Focus();
         this.textBox.CaretIndex      = this.textBox.Text.Length;
         this.textBox.SelectionStart  = this.textBox.Text.Length;
         this.textBox.SelectionLength = 0;
         this.textBox.ScrollToEnd();
         if (true)
         {
             DanmakuTextControl danmakuTextControl = new DanmakuTextControl();
             danmakuTextControl.UserName.Text = user;
             if (warn)
             {
                 danmakuTextControl.UserName.Foreground = Brushes.Red;
                 danmakuTextControl.Text.Foreground     = Brushes.LightBlue;
             }
             text = text.Trim("\r\n ".ToCharArray());
             danmakuTextControl.Text.Text = text;
             danmakuTextControl.ChangeHeight();
             Storyboard storyboard = (Storyboard)danmakuTextControl.Resources["Storyboard1"];
             storyboard.Completed += new EventHandler(this.sb_Completed);
             this.overlay.LayoutRoot.Children.Add(danmakuTextControl);
         }
         if (!warn && showdanmu)
         {
             lock (this.fulloverlay.LayoutRoot.Children)
             {
                 FullScreenDanmaku fullScreenDanmaku = new FullScreenDanmaku();
                 fullScreenDanmaku.Text.Text = text;
                 fullScreenDanmaku.ChangeHeight();
                 double width = fullScreenDanmaku.Text.DesiredSize.Width;
                 Dictionary <double, bool> dictionary = new Dictionary <double, bool>();
                 dictionary.Add(0.0, true);
                 foreach (object current in this.fulloverlay.LayoutRoot.Children)
                 {
                     if (current is FullScreenDanmaku)
                     {
                         FullScreenDanmaku fullScreenDanmaku2 = current as FullScreenDanmaku;
                         if (!dictionary.ContainsKey((double)Convert.ToInt32(fullScreenDanmaku2.Margin.Top)))
                         {
                             dictionary.Add((double)Convert.ToInt32(fullScreenDanmaku2.Margin.Top), true);
                         }
                         if (fullScreenDanmaku2.Margin.Left > SystemParameters.PrimaryScreenWidth - width - 50.0)
                         {
                             dictionary[(double)Convert.ToInt32(fullScreenDanmaku2.Margin.Top)] = false;
                         }
                     }
                 }
                 double top;
                 if (dictionary.All(p => !p.Value))
                 {
                     top = dictionary.Max(p => p.Key) + fullScreenDanmaku.Text.DesiredSize.Height;
                 }
                 else
                 {
                     top = (from p in dictionary
                            where p.Value
                            select p).Min(p => p.Key);
                 }
                 Storyboard         storyboard2        = new Storyboard();
                 Duration           duration           = new Duration(TimeSpan.FromTicks(Convert.ToInt64((SystemParameters.PrimaryScreenWidth + width) / Store.FullOverlayEffect1 * 10000000.0)));
                 ThicknessAnimation thicknessAnimation = new ThicknessAnimation(new Thickness(SystemParameters.PrimaryScreenWidth, top, 0.0, 0.0), new Thickness(-width, top, 0.0, 0.0), duration);
                 storyboard2.Children.Add(thicknessAnimation);
                 storyboard2.Duration = duration;
                 Storyboard.SetTarget(thicknessAnimation, fullScreenDanmaku);
                 Storyboard.SetTargetProperty(thicknessAnimation, new PropertyPath("(FrameworkElement.Margin)", new object[0]));
                 this.fulloverlay.LayoutRoot.Children.Add(fullScreenDanmaku);
                 storyboard2.Completed += new EventHandler(this.s_Completed);
                 storyboard2.Begin();
             }
         }
     }
     else
     {
         this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(delegate
         {
             this.AddDMText(user, text, warn);
         }));
     }
 }