/// <summary> /// 透明化の為にウインドウの再作成 /// ※ WindowStyleの変更はShowをする前にしか変更できないため /// </summary> private void RenewWindow() { AppModel model = DataContext as AppModel; if (model != null) { // 現在の状態と透明化フラグの状態に差異があるか確認 if ( (model.Stealth == true && WindowStyle == WindowStyle.None) || (model.Stealth == false && WindowStyle == WindowStyle.SingleBorderWindow) ) { // 差異が無い場合は、何もしない } else { // 透明化の状態と現在のWindowの状態が異なる時 // 新しいWindowを作成して、自身のModelを渡す。 FlyingCommentsWindow newWind = new FlyingCommentsWindow(DataContext as AppModel); // 位置とサイズをコピー newWind.Top = Top; newWind.Left = Left; newWind.Width = Width; newWind.Height = Height; newWind.WindowState = WindowState; //newWind.DataContext = DataContext; //newWind.Owner = Owner; // 旧ウィンドウを閉じる ManualColse(); // 旧ウィンドウとモデルを切断 DataContext = null; // 新ウィンドウを表示する newWind.Show(); } } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { try { AppModel model = DataContext as AppModel; // モデルが設定されている場合 if (model != null) { // 位置情報の保存 model.CommentWndRect = new Rect(Left, Top, Width, Height); model.CommentWndStste = WindowState; } } catch (Exception ex) { _logger.Error($"例外 { ex.Message}"); } }
/// <summary> /// コンストラクタ /// </summary> /// <param name="model"></param> public FlyingCommentsWindow(AppModel model) { InitializeComponent(); /// Model設定 DataContext = model; /// コメントリストの変更通知を受け取るためにバインディングを設定 Binding TextListCountBinding = new Binding("TextListCount"); TextListCountBinding.Mode = BindingMode.OneWay; this.SetBinding(TextListCount, TextListCountBinding); /// 透明化の変更通知を受け取るためにバインディングを設定 Binding StealthBinding = new Binding("Stealth"); StealthBinding.Mode = BindingMode.OneWay; this.SetBinding(Stealth, StealthBinding); // ウインドウの位置とサイズを設定 Left = model.CommentWndRect.Left; Top = model.CommentWndRect.Top; Width = model.CommentWndRect.Width; Height = model.CommentWndRect.Height; WindowState = model.CommentWndStste; /// 透明化の初期状態を設定 if (model.Stealth == true) { WindowStyle = WindowStyle.None; AllowsTransparency = true; Background = new SolidColorBrush(Colors.Transparent); // 透明を設定 } else { WindowStyle = WindowStyle.SingleBorderWindow; AllowsTransparency = false; } }
/// <summary> /// コンストラクタ /// </summary> public MainWindow() { InitializeComponent(); App ap = Application.Current as App; DataContext = ap.Model; AppModel model = DataContext as AppModel; // ウインドウの位置とサイズを指定 Left = model.SettingWndRect.Left; Top = model.SettingWndRect.Top; Width = model.SettingWndRect.Width; Height = model.SettingWndRect.Height; //コメントウインドウを作成 FlyingCommentsWindow newWnd = new FlyingCommentsWindow(DataContext as AppModel); newWnd.Show(); // フォント選択コンボBoxにシステムのフォント一覧を設定 m_FontName.ItemsSource = Fonts.SystemFontFamilies; }
/// <summary> /// コメント表示 /// </summary> private void FlyingComment() { AppModel model = DataContext as AppModel; if (model != null) { string flytext = model.PopText(); if (string.IsNullOrEmpty(flytext) == false) { // コメントのテキストコントロール OutlineTextControl CommentBlock = new OutlineTextControl(); // 表示文字設定 CommentBlock.Text = flytext; // フォント設定 CommentBlock.Font = new FontFamily(model.FontName);; // ボールド設定 CommentBlock.Bold = model.FontBald; // イタリック設定 CommentBlock.Italic = model.FontItalic; // フォントサイズ設定 try { FontSizeConverter myFontSizeConverter = new FontSizeConverter(); CommentBlock.FontSize = (Double)myFontSizeConverter.ConvertFromString(model.FontSize); } catch (Exception ex) { _logger.Error($"フォントサイズ変換に失敗{ ex.Message}"); } // 文字色設定 ColorConverter ColorConv = new ColorConverter(); try { Color col = (Color)ColorConv.ConvertFrom(model.FontColor); CommentBlock.Fill = new SolidColorBrush(col); } catch (Exception ex) { _logger.Error($"文字色変換に失敗{ ex.Message}"); } // テキストの枠線の色 try { Color col = (Color)ColorConv.ConvertFrom(model.FontThicknessColor); CommentBlock.Stroke = new SolidColorBrush(col); } catch (Exception ex) { _logger.Error($"文字の縁色変換に失敗{ ex.Message}"); } // テキストの枠の太さ try { ushort thic = 0; ushort.TryParse(model.FontThickness, out thic); CommentBlock.StrokeThickness = thic; } catch (Exception ex) { _logger.Error($"文字の縁の太さ変換に失敗{ ex.Message}"); } try { // 位置設定Y軸 // 全体のサイズ/コメントの縦幅で、画面の行数を計算 long linecount = (long)(m_Canvas.ActualHeight / CommentBlock.FormattedTextHeight); long pos = 0; if (linecount >= 2) { // 前回の行数と異なる場所になるようにする。 pos = _LastLine; while (_LastLine == pos) { pos = _rnd.Next(0, (int)linecount); } _LastLine = pos; } double ypos = pos * CommentBlock.FormattedTextHeight; //CommentBlock.SetValue(Canvas.LeftProperty, 200.0); CommentBlock.SetValue(Canvas.TopProperty, ypos); // アニメーション設定 DoubleAnimation myDoubleAnimation = new DoubleAnimation(); // キャンバスの右端から myDoubleAnimation.From = m_Canvas.ActualWidth; // キャンバスの左端-コメントの長さ=コメントが全て見きれる位置 myDoubleAnimation.To = 0 - CommentBlock.FormattedTextWidth; // コメント滞在時間 try { long time = 0; long.TryParse(model.CommentTime, out time); myDoubleAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(time)); } catch (Exception ex) { _logger.Error($"コメント滞在時間の変換に失敗{ ex.Message}"); throw; } // 繰り返しを無しに設定 myDoubleAnimation.AutoReverse = false; // アニメーションの終了イベントを設定 myDoubleAnimation.Completed += (s, _) => CommentScrollCompleted(CommentBlock); // アニメーションを開始 CommentBlock.BeginAnimation(Canvas.LeftProperty, myDoubleAnimation); m_Canvas.Children.Add(CommentBlock); } catch (Exception ex) { _logger.Error($"コメントコントロールの作成に失敗{ ex.Message}"); } } } }
/// <summary> /// テストコメントを送信 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void m_TestSendButton_Click(object sender, RoutedEventArgs e) { AppModel model = DataContext as AppModel; model.PushText(m_TestComment.Text); }
/// <summary> /// YouTubeを監視を実行 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void RunYouTbbe_Click(object sender, RoutedEventArgs e) { AppModel model = DataContext as AppModel; model?.RunYouTube(); }