Esempio n. 1
0
        /// <summary>
        /// メインフォーム
        /// </summary>
        public DrawingForm()
        {
            InitializeComponent();
            this.DoubleBuffered = true;

            var drawingManager = new DrawingManager(new RectanglePen(Color.Blue));

            drawingManager.Start(this, MouseButtons.Left);

            var gesture = new MouseGesture();

            gesture.DirectionCaptured += (o, e) => this.Text = e.Gesture;
            gesture.Add("→←→",
                        () =>
            {
                drawingManager.Clear();
                this.Text = "クリア";
                this.Refresh();
            });
            gesture.Add("↑↓",
                        () =>
            {
                drawingManager.DefaultItem = new EllipsePen(Color.Red);
                this.Text = "楕円";
                this.Refresh();
            });
            gesture.Add("↑→↓←",
                        () =>
            {
                drawingManager.DefaultItem = new RectanglePen(Color.Blue);
                this.Text = "四角形";
                this.Refresh();
            });
            gesture.Add("↓→↑",
                        () =>
            {
                drawingManager.DefaultItem = DrawingManager.Selector;
                this.Text = "選択";
                this.Refresh();
            });
            gesture.Start(this, MouseButtons.Right, 30);


            this.Paint += (o, e) => drawingManager.Draw(e.Graphics);
        }
Esempio n. 2
0
		//-------------------------------------------------------------
		// イベントの初期化
		//-------------------------------------------------------------
		private void InitEvent()
		{
			// スレッドビューワを開く
			openViewerToolStripButton.Click += (sender, e) => shortcut.ExecCommand(Commands.OpenPeerstViewer);
			// 最小化ボタン
			minToolStripButton.Click += (sender, e) => shortcut.RaiseEvent(ShortcutEvents.MinButtonClick);
			// 最大化ボタン
			maxToolStripButton.Click += (sender, e) => shortcut.RaiseEvent(ShortcutEvents.MaxButtonClick);
			// 閉じるボタン
			closeToolStripButton.Click += (sender, e) => shortcut.RaiseEvent(ShortcutEvents.CloseButtonClick);
			// 音量クリック
			statusBar.VolumeClick += (sender, e) => shortcut.RaiseEvent(ShortcutEvents.Mute);
			// ダブルクリック
			pecaPlayer.DoubleClickEvent += (sender, e) => shortcut.RaiseEvent(ShortcutEvents.DoubleClick);
			// マウスホイール
			MouseWheel += (sender, e) =>
			{
				if ((Control.MouseButtons & MouseButtons.Right) == MouseButtons.Right)
				{
					// 右クリックマウスホイール
					if (e.Delta > 0)
					{
						shortcut.RaiseEvent(ShortcutEvents.RightClickWheelUp);
					}
					else if (e.Delta < 0)
					{
						shortcut.RaiseEvent(ShortcutEvents.RightClickWheelDown);
					}
				}
				else
				{
					// マウスホイール
					if (e.Delta > 0)
					{
						shortcut.RaiseEvent(ShortcutEvents.WheelUp);
					}
					else if (e.Delta < 0)
					{
						shortcut.RaiseEvent(ShortcutEvents.WheelDown);
					}
				}
			};

			// チャンネル情報更新
			bool isFirst = true;
			pecaPlayer.ChannelInfoChange += (sender, e) =>
			{
				ChannelInfo info = pecaPlayer.ChannelInfo;
				// TODO 文字が空の場合は、スペースを空けない
				UpdateChannelDetail(info);

				// タイトル設定
				string chName = getChannelName(info);
				Win32API.SetWindowText(Handle, String.Format("{0} - PeerstPlayer", chName));

				// 初回のみの設定
				if (isFirst)
				{
					// コンタクトURL設定
					// TODO コンタクトURLが変更されたら、通知後にURL変更
					// コンタクトURLが空の場合、引数からコンタクトURLを取得する
					if (string.IsNullOrEmpty(info.Url))
					{
						var commandLine = Environment.GetCommandLineArgs();
						if (Environment.GetCommandLineArgs().Length > 4)
						{
							var url = commandLine[4];
							statusBar.SelectThreadUrl = url;
						}
						else
						{
							// コンタクトURLが空の場合
							statusBar.SelectThreadUrl = String.Empty;
						}
					}
					else
					{
						statusBar.SelectThreadUrl = info.Url;
					}
					isFirst = false;
				}
			};

			// ステータスバーのサイズ変更
			statusBar.HeightChanged += (sender, e) =>
			{
				// 最大化時はサイズ変更しない
				if (WindowState == FormWindowState.Maximized)
				{
					return;
				}

				// Formサイズ変更
				if (FrameInvisible)
				{
					Size = new Size(pecaPlayer.Width, pecaPlayer.Height + statusBar.Height);
				}
				else
				{
					ClientSize = new Size(ClientSize.Width, (pecaPlayer.Height + statusBar.Height));
				}
			};

			// ステータスバーのクリックイベント
			statusBar.ChannelDetailClick += (sender, e) =>
			{
				if (e.Button == MouseButtons.Left)
				{
					shortcut.RaiseEvent(ShortcutEvents.StatusbarLeftClick);
				}
				else if (e.Button == MouseButtons.Right)
				{
					shortcut.RaiseEvent(ShortcutEvents.StatusbarRightClick);
				}
			};

			// サイズ変更
			SizeChanged += (sender, e) =>
			{
				if ((ClientSize.Width) == 0 || (ClientSize.Height == 0))
				{
					return;
				}

				// 幅
				pecaPlayer.Width = ClientSize.Width;
				statusBar.Width = ClientSize.Width;

				// 高さ
				pecaPlayer.Height = ClientSize.Height - statusBar.Height;
				statusBar.Top = pecaPlayer.Bottom;
			};

			// 動画サイズ変更
			pecaPlayer.MovieSizeChange += (sender, e) =>
			{
				// Formサイズ変更
				if (FrameInvisible)
				{
					Size = new Size(pecaPlayer.Width, pecaPlayer.Height + statusBar.Height);
				}
				else
				{
					ClientSize = new Size(pecaPlayer.Width, pecaPlayer.Height + statusBar.Height);
				}

				// 幅
				statusBar.Width = pecaPlayer.Width;

				// 高さ
				statusBar.Top = pecaPlayer.Bottom;
			};

			// 音量変更イベント
			pecaPlayer.VolumeChange += (sender, e) => statusBar.Volume = (pecaPlayer.Mute ? "-" : pecaPlayer.Volume.ToString());

			// スレッドタイトル右クリックイベント
			statusBar.ThreadTitleRightClick += (sender, e) => shortcut.RaiseEvent(ShortcutEvents.ThreadTitleRightClick);

			// マウスジェスチャー
			MouseGesture mouseGesture = new MouseGesture();
			mouseGesture.Interval = PlayerSettings.MouseGestureInterval;
			bool isGesturing = false;

			// タイマーイベント
			Timer timer = new Timer();
			timer.Interval = MovieStatusUpdateInterval;
			timer.Tick += (sender, e) =>
			{
				// 自動表示ボタンの表示切り替え
				if (toolStrip.Visible && !IsVisibleToolStrip(PointToClient(MousePosition)))
				{
					toolStrip.Visible = false;
				}

				// 画面外に出たらマウスジェスチャー解除
				if (!RectangleToScreen(ClientRectangle).Contains(MousePosition))
				{
					isGesturing = false;
				}

				// 動画ステータスを表示
				if (pecaPlayer.Duration.Length == 0)
				{
					switch (pecaPlayer.PlayState)
					{
						case WMPPlayState.wmppsUndefined: statusBar.MovieStatus		= "";			break;
						case WMPPlayState.wmppsStopped: statusBar.MovieStatus		= "停止";		break;
						case WMPPlayState.wmppsPaused: statusBar.MovieStatus		= "一時停止";	break;
						case WMPPlayState.wmppsPlaying: statusBar.MovieStatus		= "再生中";		break;
						case WMPPlayState.wmppsScanForward: statusBar.MovieStatus	= "早送り";		break;
						case WMPPlayState.wmppsScanReverse: statusBar.MovieStatus	= "巻き戻し";	break;
						case WMPPlayState.wmppsWaiting: statusBar.MovieStatus		= "接続待機";	break;
						case WMPPlayState.wmppsMediaEnded: statusBar.MovieStatus	= "再生完了";	break;
						case WMPPlayState.wmppsTransitioning: statusBar.MovieStatus = "準備中";		break;
						case WMPPlayState.wmppsReady: statusBar.MovieStatus			= "準備完了";	break;
						case WMPPlayState.wmppsReconnecting: statusBar.MovieStatus	= "再接続";		break;
						case WMPPlayState.wmppsBuffering: statusBar.MovieStatus		= string.Format("バッファ{0}%", pecaPlayer.BufferingProgress); break;
					}
				}
				// 再生時間を表示
				else
				{
					statusBar.MovieStatus = pecaPlayer.Duration;
				}

				// 動画情報を更新
				ChannelInfo info = pecaPlayer.ChannelInfo ?? new ChannelInfo();
				statusBar.UpdateMovieInfo(
					new MovieInfo()
					{
						NowFps = pecaPlayer.NowFrameRate,
						Fps = pecaPlayer.FrameRate,
						NowBitrate = pecaPlayer.NowBitrate,
						Bitrate = pecaPlayer.Bitrate,
						ListenerNumber = info.Listeners,
						RelayNumber = info.Relays,
						Status = info.Status,
						StreamType = info.Type,
					});
			};
			timer.Start();

			// マウスダウンイベント
			pecaPlayer.MouseDownEvent += (sender, e) =>
			{
				if (e.nButton == (short)Keys.LButton)
				{
					// マウスドラッグ
					FormUtility.WindowDragStart(this.Handle);
				}
				else if (e.nButton == (short)Keys.RButton)
				{
					// マウスジェスチャー開始
					mouseGesture.Start();
					isGesturing = true;
				}
				else if (e.nButton == (short)Keys.MButton)
				{
					// 中クリック
					shortcut.RaiseEvent(ShortcutEvents.MiddleClick);
				}
			};

			// マウスアップイベント
			pecaPlayer.MouseUpEvent += (sender, e) =>
			{
				if (e.nButton == (short)Keys.RButton)
				{
					// チャンネル詳細を再描画
					ChannelInfo info = pecaPlayer.ChannelInfo;
					if (info != null)
					{
						UpdateChannelDetail(info);
					}

					// マウスジェスチャーが実行されていなければ
					string gesture = mouseGesture.ToString();
					if (string.IsNullOrEmpty(gesture))
					{
						// コンテキストメニュー表示
						contextMenuStrip.Show(MousePosition);
					}
					else if (isGesturing)
					{
						// マウスジェスチャー実行
						shortcut.ExecGesture(gesture);
					}

					isGesturing = false;
				}
			};

			// マウス移動イベント
			pecaPlayer.MouseMoveEvent += (sender, e) =>
			{
				// 自動表示ボタンの表示切り替え
				if (toolStrip.Visible != IsVisibleToolStrip(new Point(e.fX, e.fY)))
				{
					toolStrip.Visible = !toolStrip.Visible;
				}

				if (isGesturing)
				{
					// ジェスチャー表示
					mouseGesture.Moving(new Point(e.fX, e.fY));

					string gesture = mouseGesture.ToString();
					string detail = shortcut.GetGestureDetail(gesture);
					if (!String.IsNullOrEmpty(gesture))
					{
						string message = string.Format("ジェスチャ: {0} {1}", gesture, (String.IsNullOrEmpty(detail) ? "" : "(" + detail + ")"));
						ToastMessage.Show(message);
					}
				}
			};

			// キー押下イベント
			pecaPlayer.KeyDownEvent += (sender, e) => shortcut.RaiseKeyEvent(e);

			// ステータスバー マウスホバーイベント
			statusBar.MouseHoverEvent += (sender, e) => shortcut.RaiseEvent(ShortcutEvents.StatusbarHover);

			// 終了処理
			FormClosed += (sender, e) =>
			{
				Logger.Instance.Debug("FormClosed");
				pecaPlayer.Close();
				statusBar.Close();
			};

			// グローウィンドウの弊害で消えなくなっていたので自分で消えるようにする
			Deactivate += (sender, e) =>
			{
				contextMenuStrip.Hide();
			};

			// 動画再生イベント
			pecaPlayer.MovieStart += (sender, e) =>
			{
				pecaPlayer.UpdateChannelInfo();
				shortcut.ExecCommand(PlayerSettings.MovieStartCommand);
			};

			// コマンド実行内容の表示
			shortcut.CommandExecuted += (sender, e) =>
			{
				CommnadExecutedEventArgs args = (CommnadExecutedEventArgs)e;

				// ステータスバー表示切り替えはメッセージを出さない
				if (args.Command != Commands.VisibleStatusBar)
				{
					ToastMessage.Show(string.Format("コマンド: {0}", args.Detail));
				}
			};

			//-----------------------------------------------------
			// コンテキストメニュー
			//-----------------------------------------------------

			// 拡大率
			scale25PerToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.WindowScale25Per);
			scale50PerToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.WindowScale50Per);
			scale75PerToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.WindowScale75Per);
			scale100PerToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.WindowScale100Per);
			scale150PerToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.WindowScale150Per);
			scale200PerToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.WindowScale200Per);

			// サイズ変更
			size160x120ToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.WindowSize160x120);
			size320x240ToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.WindowSize320x240);
			size480x360ToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.WindowSize480x360);
			size640x480ToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.WindowSize640x480);
			size800x600ToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.WindowSize800x600);
			fitMovieSizeToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.FitMovieSize);

			// 画面分割
			screenSplitWidthx5ToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.ScreenSplitWidthx5);
			screenSplitWidthx4ToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.ScreenSplitWidthx4);
			screenSplitWidthx3ToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.ScreenSplitWidthx3);
			screenSplitWidthx2ToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.ScreenSplitWidthx2);
			screenSplitHeightx5ToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.ScreenSplitHeightx5);
			screenSplitHeightx4ToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.ScreenSplitHeightx4);
			screenSplitHeightx3ToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.ScreenSplitHeightx3);
			screenSplitHeightx2ToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.ScreenSplitHeightx2);

			// 機能
			topMostToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.TopMost);
			updateChannelInfoToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.UpdateChannelInfo);
			bumpToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.Bump);
			functionToolStripMenuItem.DropDownOpening += (sender, e) => topMostToolStripMenuItem.Checked = TopMost;
			screenshotToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.Screenshot);
			openScreenshotFolderToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.OpenScreenshotFolder);
			retryPlayerToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.RetryPlayer);
			// ファイルから開く
			openFromFileToolStripMenuItem.Click += (sender, e) =>
			{
				var dialog = new OpenFileDialog();
				if (dialog.ShowDialog() == DialogResult.OK)
				{
					// TODO スレッド選択を解除
					// TODO ステータスバーを変更
					Open(dialog.FileName);
				}
			};
			// URLから開く
			openFromUrlToolStripTextBox.KeyDown += (sender, e) =>
			{
				if (e.KeyCode == Keys.Return)
				{
					// TODO FLV or WMVの判定をして、PecaPlayerコントロールを再初期化する
					// TODO スレッド選択を解除 + 新しいスレッドへ移動
					// TODO ステータスバーを変更
					Open(((ToolStripTextBox)sender).Text);
					contextMenuStrip.Close();
				}
			};
			// クリップボードから開く
			openFromClipboardToolStripMenuItem.Click += (sender, e) =>
			{
				try
				{
					if (Clipboard.ContainsText())
					{
						// TODO FLV or WMVの判定をして、PecaPlayerコントロールを再初期化する
						// TODO スレッド選択を解除 + 新しいスレッドへ移動
						// TODO ステータスバーを変更
						Open(Clipboard.GetText());
					}
				}
				catch (System.Runtime.InteropServices.ExternalException)
				{
					MessageBox.Show("クリップボードのオープンに失敗しました");
				}
			};

			// 音量
			volumeUpToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.VolumeUp);
			volumeDownToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.VolumeDown);
			muteToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.Mute);
			volumeBalanceLeftToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.VolumeBalanceLeft);
			volumeBalanceMiddleToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.VolumeBalanceMiddle);
			volumeBalanceRightToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.VolumeBalanceRight);
			volumeToolStripMenuItem.DropDownOpening += (sender, e) => muteToolStripMenuItem.Checked = pecaPlayer.Mute;
			volumeToolStripMenuItem.DropDownOpening += (sender, e) => volumeBalanceLeftToolStripMenuItem.Checked = (pecaPlayer.VolumeBalance == VolumeBalanceCommandArgs.BalanceLeft);
			volumeToolStripMenuItem.DropDownOpening += (sender, e) => volumeBalanceMiddleToolStripMenuItem.Checked = (pecaPlayer.VolumeBalance == VolumeBalanceCommandArgs.BalanceMiddle);
			volumeToolStripMenuItem.DropDownOpening += (sender, e) => volumeBalanceRightToolStripMenuItem.Checked = (pecaPlayer.VolumeBalance == VolumeBalanceCommandArgs.BalanceRight);

			// 設定メニュー押下
			settingToolStripMenuItem.Click += (sender, e) =>
			{
				PlayerSettingView view = new PlayerSettingView(shortcut);
				view.TopMost = TopMost;
				view.ShowDialog();
			};

			// WMPメニュー押下
			wmpMenuToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.WmpMenu);
			// 動画情報表示押下
			showDebugToolStripMenuItem.Click += (sender, e) => pecaPlayer.ShowDebug();
		}
Esempio n. 3
0
        public PlayerSettingView(ShortcutManager shortcut)
        {
            this.shortcut = shortcut;

            InitializeComponent();

            // 親ウィンドウの中心に表示
            StartPosition = FormStartPosition.CenterParent;

            // 初期化
            Shown += (sender, e) =>
            {
                // チェックボックスの表示
                disconnectRealyOnCloseCheckBox.Checked = PlayerSettings.DisconnectRealyOnClose;
                returnPositionOnStartCheckBox.Checked  = PlayerSettings.ReturnPositionOnStart;
                returnSizeOnStartCheckBox.Checked      = PlayerSettings.ReturnSizeOnStart;
                windowSnapEnableCheckBox.Checked       = PlayerSettings.WindowSnapEnable;
                aspectRateFixCheckBox.Checked          = PlayerSettings.AspectRateFix;
                frameInvisibleCheckBox.Checked         = PlayerSettings.FrameInvisible;
                topMostCheckBox.Checked            = PlayerSettings.TopMost;
                writeFieldVisibleCheckBox.Checked  = PlayerSettings.WriteFieldVisible;
                initVolumeTextBox.Text             = PlayerSettings.InitVolume.ToString();
                saveReturnPositionCheckBox.Checked = PlayerSettings.SaveReturnPositionOnClose;
                saveReturnSizeCheckBox.Checked     = PlayerSettings.SaveReturnSizeOnClose;
                exitedViewerCloseCheckBox.Checked  = PlayerSettings.ExitedViewerClose;

                // チェックボックスの設定(ステータスバー)
                displayFpsCheckBox.Checked     = PlayerSettings.DisplayFps;
                displayBitrateCheckBox.Checked = PlayerSettings.DisplayBitrate;
                listenerNumberCheckBox.Checked = PlayerSettings.DisplayListenerNumber;

                // 音量変化
                volumeChangeNoneTextBox.Text  = PlayerSettings.VolumeChangeNone.ToString();
                volumeChangeCtrlTextBox.Text  = PlayerSettings.VolumeChangeCtrl.ToString();
                volumeChangeShiftTextBox.Text = PlayerSettings.VolumeChangeShift.ToString();

                // スクリーンショット
                screenshotFolderTextBox.Text = PlayerSettings.ScreenshotFolder;
                foreach (var item in screenshotExtensionComboBox.Items)
                {
                    if (item.ToString() == PlayerSettings.ScreenshotExtension)
                    {
                        screenshotExtensionComboBox.SelectedItem = item;
                    }
                }
                // 拡張子が選択されていなければpngを選ばせる
                if (screenshotExtensionComboBox.SelectedItem == null)
                {
                    screenshotExtensionComboBox.SelectedIndex = screenshotExtensionComboBox.FindString("png");
                }
                // 書式
                screenshotFormatTextBox.Text = PlayerSettings.ScreenshotFormat;
                screenshotSampleTextBox.Text = Shortcut.Command.ScreenshotCommand.Format(screenshotFormatTextBox.Text, null);

                // スレッド
                autoReadThreadCheckBox.Checked = PlayerSettings.AutoReadThread;

                // FLV
                flvGpuCheckBox.Checked    = PlayerSettings.Gpu;
                useRtmpCheckBox.Checked   = PlayerSettings.Rtmp;
                bufferTimeTextBox.Text    = PlayerSettings.BufferTime.ToString();
                bufferTimeMaxTextBox.Text = PlayerSettings.BufferTimeMax.ToString();

                // 動画再生開始時のコマンド
                movieStartComboBox.Items.Clear();
                foreach (Commands command in movieStartCommandList)
                {
                    string detail = shortcut.CommandMap[command].Detail;
                    movieStartComboBox.Items.Add(detail);

                    if (PlayerSettings.MovieStartCommand == command)
                    {
                        movieStartComboBox.SelectedIndex = (movieStartComboBox.Items.Count - 1);
                    }
                }

                // ショートカット・ジェスチャー表示
                shortcutListView.Items.Clear();
                foreach (KeyValuePair <Commands, ShortcutCommand> commandPair in shortcut.CommandMap)
                {
                    // ショートカットのアイテム追加
                    ListViewItem keyItem = CreateKeyItem(shortcut, commandPair);
                    shortcutListView.Items.Add(keyItem);
                }
            };

            // スクリーンショットを保存するフォルダを選ぶダイアログを表示するボタン
            browseScreenshotFolderButton.Click += (sender, args) =>
            {
                folderBrowserDialog.RootFolder   = Environment.SpecialFolder.Desktop;
                folderBrowserDialog.SelectedPath = PlayerSettings.ScreenshotFolder;
                if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
                {
                    screenshotFolderTextBox.Text = folderBrowserDialog.SelectedPath;
                }
            };

            // スクリーンショットファイル名の書式
            screenshotFormatTextBox.TextChanged += (sender, args) =>
            {
                screenshotSampleTextBox.Text = Shortcut.Command.ScreenshotCommand.Format(screenshotFormatTextBox.Text, null);
            };
            // 書式の補助メニュー
            screenshotFormatButton.Click += (sender, args) => screenshotContextMenuStrip.Show(screenshotFormatButton, 0, 0);
            Action <string> formatHelper = (x) =>
            {
                // 選択されているテキストの位置を取得しておく
                var selectionStart = screenshotFormatTextBox.SelectionStart;
                screenshotFormatTextBox.Text = screenshotFormatTextBox.Text.Insert(screenshotFormatTextBox.SelectionStart, x);
                // 追加した文字列の後ろにカーソルを移動
                screenshotFormatTextBox.SelectionStart = selectionStart + x.Length;
                screenshotFormatTextBox.Focus();
            };

            year2ToolStripMenuItem.Click       += (sender, args) => formatHelper("yy");
            year4ToolStripMenuItem.Click       += (sender, args) => formatHelper("yyyy");
            monthToolStripMenuItem.Click       += (sender, args) => formatHelper("MM");
            dayToolStripMenuItem.Click         += (sender, args) => formatHelper("dd");
            hourToolStripMenuItem.Click        += (sender, args) => formatHelper("hh");
            minuteToolStripMenuItem.Click      += (sender, args) => formatHelper("mm");
            secondToolStripMenuItem.Click      += (sender, args) => formatHelper("ss");
            channelNameToolStripMenuItem.Click += (sender, args) => formatHelper("$0");

            // Tab遷移しないようにする
            shortcutListView.PreviewKeyDown += (sender, e) => e.IsInputKey = true;

            // ショートカット設定時にエラー音がならないようにする
            shortcutListView.KeyPress += (sender, e) => e.Handled = true;

            // ショートカット入力
            shortcutListView.KeyDown += (sender, e) =>
            {
                if (shortcutListView.SelectedIndices.Count <= 0)
                {
                    return;
                }
                if (e.KeyData == Keys.ProcessKey)
                {
                    return;
                }

                // 同じキー入力を削除
                foreach (ListViewItem item in shortcutListView.Items)
                {
                    object tag = item.SubItems[1].Tag;                          // KeyInput

                    if ((tag == null))
                    {
                        continue;
                    }

                    KeyInput keyInput = (KeyInput)tag;

                    if ((keyInput.Key == e.KeyCode) && (keyInput.Modifiers == e.Modifiers))
                    {
                        item.SubItems[1].Text = "-";
                        item.SubItems[1].Tag  = null;
                    }
                }

                // ショートカット登録
                KeyInput input = new KeyInput(e.Modifiers, e.KeyCode);
                int      index = shortcutListView.SelectedIndices[0];
                shortcutListView.Items[index].SubItems[1].Text = ConvertKeyInputToString(input);
                shortcutListView.Items[index].SubItems[1].Tag  = input;

                // キー入力を無視
                e.Handled = true;
            };

            // ダブルクリックでコマンド削除
            shortcutListView.MouseDoubleClick += (sender, e) =>
            {
                if (shortcutListView.SelectedIndices.Count <= 0)
                {
                    return;
                }

                if (e.Button == MouseButtons.Left)
                {
                    int index = shortcutListView.SelectedIndices[0];
                    shortcutListView.Items[index].SubItems[1].Text = "-";
                    shortcutListView.Items[index].SubItems[1].Tag  = null;
                }
                else if (e.Button == System.Windows.Forms.MouseButtons.Right)
                {
                    int index = shortcutListView.SelectedIndices[0];
                    shortcutListView.Items[index].SubItems[2].Text = "-";
                    shortcutListView.Items[index].SubItems[2].Tag  = null;
                }
            };

            // マウスジェスチャ
            MouseGesture mouseGesture = new MouseGesture();

            mouseGesture.Interval = PlayerSettings.MouseGestureInterval;
            bool gestureing = false;

            shortcutListView.MouseDown += (sender, e) =>
            {
                if (e.Button == MouseButtons.Right)
                {
                    mouseGesture.Start();
                    gestureing = true;
                }
            };
            shortcutListView.MouseMove += (sender, e) =>
            {
                if (shortcutListView.SelectedIndices.Count <= 0)
                {
                    return;
                }
                if (gestureing == false)
                {
                    return;
                }

                mouseGesture.Moving(e.Location);
                string gesture = mouseGesture.ToString();

                int index = shortcutListView.SelectedIndices[0];
                if (string.IsNullOrEmpty(gesture))
                {
                    return;
                }
                if (shortcutListView.Items[index].SubItems[2].Text == mouseGesture.ToString())
                {
                    return;
                }

                // ジェスチャを登録
                shortcutListView.Items[index].SubItems[2].Text = gesture;
                shortcutListView.Items[index].SubItems[2].Tag  = null;
            };
            shortcutListView.MouseUp += (sender, e) =>
            {
                if (shortcutListView.SelectedIndices.Count <= 0)
                {
                    return;
                }
                if (gestureing == false)
                {
                    return;
                }

                mouseGesture.Moving(e.Location);
                string gesture = mouseGesture.ToString();

                int index = shortcutListView.SelectedIndices[0];
                if (string.IsNullOrEmpty(gesture))
                {
                    return;
                }

                // 同じジェスチャを削除
                foreach (ListViewItem item in shortcutListView.Items)
                {
                    string text = item.SubItems[2].Text;
                    if (gesture == text)
                    {
                        item.SubItems[2].Text = "-";
                        item.SubItems[2].Tag  = null;
                    }
                }

                // ジェスチャを登録
                shortcutListView.Items[index].SubItems[2].Text = gesture;
                shortcutListView.Items[index].SubItems[2].Tag  = null;
            };
            shortcutListView.MouseUp += (sender, e) => gestureing = false;
        }
Esempio n. 4
0
        //-------------------------------------------------------------
        // イベントの初期化
        //-------------------------------------------------------------
        private void InitEvent()
        {
            // スレッドビューワを開く
            openViewerToolStripButton.Click += (sender, e) => shortcut.ExecCommand(Commands.OpenPeerstViewer);
            // 最小化ボタン
            minToolStripButton.Click += (sender, e) => shortcut.RaiseEvent(ShortcutEvents.MinButtonClick);
            // 最大化ボタン
            maxToolStripButton.Click += (sender, e) => shortcut.RaiseEvent(ShortcutEvents.MaxButtonClick);
            // 閉じるボタン
            closeToolStripButton.Click += (sender, e) => shortcut.RaiseEvent(ShortcutEvents.CloseButtonClick);
            // 音量クリック
            statusBar.VolumeClick += (sender, e) => shortcut.RaiseEvent(ShortcutEvents.Mute);
            // ダブルクリック
            pecaPlayer.DoubleClickEvent += (sender, e) => shortcut.RaiseEvent(ShortcutEvents.DoubleClick);
            // マウスホイール
            MouseWheel += (sender, e) =>
            {
                if ((Control.MouseButtons & MouseButtons.Right) == MouseButtons.Right)
                {
                    // 右クリックマウスホイール
                    if (e.Delta > 0)
                    {
                        shortcut.RaiseEvent(ShortcutEvents.RightClickWheelUp);
                    }
                    else if (e.Delta < 0)
                    {
                        shortcut.RaiseEvent(ShortcutEvents.RightClickWheelDown);
                    }
                }
                else
                {
                    // マウスホイール
                    if (e.Delta > 0)
                    {
                        shortcut.RaiseEvent(ShortcutEvents.WheelUp);
                    }
                    else if (e.Delta < 0)
                    {
                        shortcut.RaiseEvent(ShortcutEvents.WheelDown);
                    }
                }
            };

            // チャンネル情報更新
            bool isFirst = true;

            pecaPlayer.ChannelInfoChange += (sender, e) =>
            {
                ChannelInfo info = pecaPlayer.ChannelInfo;
                // TODO 文字が空の場合は、スペースを空けない
                UpdateChannelDetail(info);

                // タイトル設定
                string chName = getChannelName(info);
                Win32API.SetWindowText(Handle, String.Format("{0} - PeerstPlayer", chName));

                // 初回のみの設定
                if (isFirst)
                {
                    // コンタクトURL設定
                    // TODO コンタクトURLが変更されたら、通知後にURL変更
                    // コンタクトURLが空の場合、引数からコンタクトURLを取得する
                    if (string.IsNullOrEmpty(info.Url))
                    {
                        var commandLine = Environment.GetCommandLineArgs();
                        if (Environment.GetCommandLineArgs().Length > 4)
                        {
                            var url = commandLine[4];
                            statusBar.SelectThreadUrl = url;
                        }
                        else
                        {
                            // コンタクトURLが空の場合
                            statusBar.SelectThreadUrl = String.Empty;
                        }
                    }
                    else
                    {
                        statusBar.SelectThreadUrl = info.Url;
                    }
                    isFirst = false;
                }
            };

            // ステータスバーのサイズ変更
            statusBar.HeightChanged += (sender, e) =>
            {
                // 最大化時はサイズ変更しない
                if (WindowState == FormWindowState.Maximized)
                {
                    return;
                }

                // Formサイズ変更
                if (FrameInvisible)
                {
                    Size = new Size(pecaPlayer.Width, pecaPlayer.Height + statusBar.Height);
                }
                else
                {
                    ClientSize = new Size(ClientSize.Width, (pecaPlayer.Height + statusBar.Height));
                }
            };

            // ステータスバーのクリックイベント
            statusBar.ChannelDetailClick += (sender, e) =>
            {
                if (e.Button == MouseButtons.Left)
                {
                    shortcut.RaiseEvent(ShortcutEvents.StatusbarLeftClick);
                }
                else if (e.Button == MouseButtons.Right)
                {
                    shortcut.RaiseEvent(ShortcutEvents.StatusbarRightClick);
                }
            };

            // サイズ変更
            SizeChanged += (sender, e) =>
            {
                if ((ClientSize.Width) == 0 || (ClientSize.Height == 0))
                {
                    return;
                }

                // 幅
                pecaPlayer.Width = ClientSize.Width;
                statusBar.Width  = ClientSize.Width;

                // 高さ
                pecaPlayer.Height = ClientSize.Height - statusBar.Height;
                statusBar.Top     = pecaPlayer.Bottom;
            };

            // 動画サイズ変更
            pecaPlayer.MovieSizeChange += (sender, e) =>
            {
                // Formサイズ変更
                if (FrameInvisible)
                {
                    Size = new Size(pecaPlayer.Width, pecaPlayer.Height + statusBar.Height);
                }
                else
                {
                    ClientSize = new Size(pecaPlayer.Width, pecaPlayer.Height + statusBar.Height);
                }

                // 幅
                statusBar.Width = pecaPlayer.Width;

                // 高さ
                statusBar.Top = pecaPlayer.Bottom;
            };

            // 音量変更イベント
            pecaPlayer.VolumeChange += (sender, e) => statusBar.Volume = (pecaPlayer.Mute ? "-" : pecaPlayer.Volume.ToString());

            // スレッドタイトル右クリックイベント
            statusBar.ThreadTitleRightClick += (sender, e) => shortcut.RaiseEvent(ShortcutEvents.ThreadTitleRightClick);

            // マウスジェスチャー
            MouseGesture mouseGesture = new MouseGesture();

            mouseGesture.Interval = PlayerSettings.MouseGestureInterval;
            bool isGesturing = false;

            // タイマーイベント
            Timer timer = new Timer();

            timer.Interval = MovieStatusUpdateInterval;
            timer.Tick    += (sender, e) =>
            {
                // 自動表示ボタンの表示切り替え
                if (toolStrip.Visible && !IsVisibleToolStrip(PointToClient(MousePosition)))
                {
                    toolStrip.Visible = false;
                }

                // 画面外に出たらマウスジェスチャー解除
                if (!RectangleToScreen(ClientRectangle).Contains(MousePosition))
                {
                    isGesturing = false;
                }

                // 動画ステータスを表示
                if (pecaPlayer.Duration.Length == 0)
                {
                    switch (pecaPlayer.PlayState)
                    {
                    case WMPPlayState.wmppsUndefined: statusBar.MovieStatus = "";                   break;

                    case WMPPlayState.wmppsStopped: statusBar.MovieStatus = "停止";         break;

                    case WMPPlayState.wmppsPaused: statusBar.MovieStatus = "一時停止";       break;

                    case WMPPlayState.wmppsPlaying: statusBar.MovieStatus = "再生中";                break;

                    case WMPPlayState.wmppsScanForward: statusBar.MovieStatus = "早送り";                break;

                    case WMPPlayState.wmppsScanReverse: statusBar.MovieStatus = "巻き戻し";       break;

                    case WMPPlayState.wmppsWaiting: statusBar.MovieStatus = "接続待機";       break;

                    case WMPPlayState.wmppsMediaEnded: statusBar.MovieStatus = "再生完了";       break;

                    case WMPPlayState.wmppsTransitioning: statusBar.MovieStatus = "準備中";            break;

                    case WMPPlayState.wmppsReady: statusBar.MovieStatus = "準備完了";       break;

                    case WMPPlayState.wmppsReconnecting: statusBar.MovieStatus = "再接続";                break;

                    case WMPPlayState.wmppsBuffering: statusBar.MovieStatus = string.Format("バッファ{0}%", pecaPlayer.BufferingProgress); break;
                    }
                }
                // 再生時間を表示
                else
                {
                    statusBar.MovieStatus = pecaPlayer.Duration;
                }

                // 動画情報を更新
                ChannelInfo info = pecaPlayer.ChannelInfo ?? new ChannelInfo();
                statusBar.UpdateMovieInfo(
                    new MovieInfo()
                {
                    NowFps         = pecaPlayer.NowFrameRate,
                    Fps            = pecaPlayer.FrameRate,
                    NowBitrate     = pecaPlayer.NowBitrate,
                    Bitrate        = pecaPlayer.Bitrate,
                    ListenerNumber = info.Listeners,
                    RelayNumber    = info.Relays,
                    Status         = info.Status,
                    StreamType     = info.Type,
                });
            };
            timer.Start();

            // マウスダウンイベント
            pecaPlayer.MouseDownEvent += (sender, e) =>
            {
                if (e.nButton == (short)Keys.LButton)
                {
                    // マウスドラッグ
                    FormUtility.WindowDragStart(this.Handle);
                }
                else if (e.nButton == (short)Keys.RButton)
                {
                    // マウスジェスチャー開始
                    mouseGesture.Start();
                    isGesturing = true;
                }
                else if (e.nButton == (short)Keys.MButton)
                {
                    // 中クリック
                    shortcut.RaiseEvent(ShortcutEvents.MiddleClick);
                }
            };

            // マウスアップイベント
            pecaPlayer.MouseUpEvent += (sender, e) =>
            {
                if (e.nButton == (short)Keys.RButton)
                {
                    // チャンネル詳細を再描画
                    ChannelInfo info = pecaPlayer.ChannelInfo;
                    if (info != null)
                    {
                        UpdateChannelDetail(info);
                    }

                    // マウスジェスチャーが実行されていなければ
                    string gesture = mouseGesture.ToString();
                    if (string.IsNullOrEmpty(gesture))
                    {
                        // コンテキストメニュー表示
                        contextMenuStrip.Show(MousePosition);
                    }
                    else if (isGesturing)
                    {
                        // マウスジェスチャー実行
                        shortcut.ExecGesture(gesture);
                    }

                    isGesturing = false;
                }
            };

            // マウス移動イベント
            pecaPlayer.MouseMoveEvent += (sender, e) =>
            {
                // 自動表示ボタンの表示切り替え
                if (toolStrip.Visible != IsVisibleToolStrip(new Point(e.fX, e.fY)))
                {
                    toolStrip.Visible = !toolStrip.Visible;
                }

                if (isGesturing)
                {
                    // ジェスチャー表示
                    mouseGesture.Moving(new Point(e.fX, e.fY));

                    string gesture = mouseGesture.ToString();
                    string detail  = shortcut.GetGestureDetail(gesture);
                    if (!String.IsNullOrEmpty(gesture))
                    {
                        string message = string.Format("ジェスチャ: {0} {1}", gesture, (String.IsNullOrEmpty(detail) ? "" : "(" + detail + ")"));
                        ToastMessage.Show(message);
                    }
                }
            };

            // キー押下イベント
            pecaPlayer.KeyDownEvent += (sender, e) => shortcut.RaiseKeyEvent(e);

            // ステータスバー マウスホバーイベント
            statusBar.MouseHoverEvent += (sender, e) => shortcut.RaiseEvent(ShortcutEvents.StatusbarHover);

            // 終了処理
            FormClosed += (sender, e) =>
            {
                Logger.Instance.Debug("FormClosed");
                pecaPlayer.Close();
                statusBar.Close();
            };

            // グローウィンドウの弊害で消えなくなっていたので自分で消えるようにする
            Deactivate += (sender, e) =>
            {
                contextMenuStrip.Hide();
            };

            // 動画再生イベント
            pecaPlayer.MovieStart += (sender, e) =>
            {
                pecaPlayer.UpdateChannelInfo();
                shortcut.ExecCommand(PlayerSettings.MovieStartCommand);
            };

            // コマンド実行内容の表示
            shortcut.CommandExecuted += (sender, e) =>
            {
                CommnadExecutedEventArgs args = (CommnadExecutedEventArgs)e;

                // ステータスバー表示切り替えはメッセージを出さない
                if (args.Command != Commands.VisibleStatusBar)
                {
                    ToastMessage.Show(string.Format("コマンド: {0}", args.Detail));
                }
            };

            //-----------------------------------------------------
            // コンテキストメニュー
            //-----------------------------------------------------

            // 拡大率
            scale25PerToolStripMenuItem.Click  += (sender, e) => shortcut.ExecCommand(Commands.WindowScale25Per);
            scale50PerToolStripMenuItem.Click  += (sender, e) => shortcut.ExecCommand(Commands.WindowScale50Per);
            scale75PerToolStripMenuItem.Click  += (sender, e) => shortcut.ExecCommand(Commands.WindowScale75Per);
            scale100PerToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.WindowScale100Per);
            scale150PerToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.WindowScale150Per);
            scale200PerToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.WindowScale200Per);

            // サイズ変更
            size160x120ToolStripMenuItem.Click  += (sender, e) => shortcut.ExecCommand(Commands.WindowSize160x120);
            size320x240ToolStripMenuItem.Click  += (sender, e) => shortcut.ExecCommand(Commands.WindowSize320x240);
            size480x360ToolStripMenuItem.Click  += (sender, e) => shortcut.ExecCommand(Commands.WindowSize480x360);
            size640x480ToolStripMenuItem.Click  += (sender, e) => shortcut.ExecCommand(Commands.WindowSize640x480);
            size800x600ToolStripMenuItem.Click  += (sender, e) => shortcut.ExecCommand(Commands.WindowSize800x600);
            fitMovieSizeToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.FitMovieSize);

            // 画面分割
            screenSplitWidthx5ToolStripMenuItem.Click  += (sender, e) => shortcut.ExecCommand(Commands.ScreenSplitWidthx5);
            screenSplitWidthx4ToolStripMenuItem.Click  += (sender, e) => shortcut.ExecCommand(Commands.ScreenSplitWidthx4);
            screenSplitWidthx3ToolStripMenuItem.Click  += (sender, e) => shortcut.ExecCommand(Commands.ScreenSplitWidthx3);
            screenSplitWidthx2ToolStripMenuItem.Click  += (sender, e) => shortcut.ExecCommand(Commands.ScreenSplitWidthx2);
            screenSplitHeightx5ToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.ScreenSplitHeightx5);
            screenSplitHeightx4ToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.ScreenSplitHeightx4);
            screenSplitHeightx3ToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.ScreenSplitHeightx3);
            screenSplitHeightx2ToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.ScreenSplitHeightx2);

            // 機能
            topMostToolStripMenuItem.Click           += (sender, e) => shortcut.ExecCommand(Commands.TopMost);
            updateChannelInfoToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.UpdateChannelInfo);
            bumpToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.Bump);
            functionToolStripMenuItem.DropDownOpening   += (sender, e) => topMostToolStripMenuItem.Checked = TopMost;
            screenshotToolStripMenuItem.Click           += (sender, e) => shortcut.ExecCommand(Commands.Screenshot);
            openScreenshotFolderToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.OpenScreenshotFolder);
            retryPlayerToolStripMenuItem.Click          += (sender, e) => shortcut.ExecCommand(Commands.RetryPlayer);
            // ファイルから開く
            openFromFileToolStripMenuItem.Click += (sender, e) =>
            {
                var dialog = new OpenFileDialog();
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    // TODO スレッド選択を解除
                    // TODO ステータスバーを変更
                    Open(dialog.FileName);
                }
            };
            // URLから開く
            openFromUrlToolStripTextBox.KeyDown += (sender, e) =>
            {
                if (e.KeyCode == Keys.Return)
                {
                    // TODO FLV or WMVの判定をして、PecaPlayerコントロールを再初期化する
                    // TODO スレッド選択を解除 + 新しいスレッドへ移動
                    // TODO ステータスバーを変更
                    Open(((ToolStripTextBox)sender).Text);
                    contextMenuStrip.Close();
                }
            };
            // クリップボードから開く
            openFromClipboardToolStripMenuItem.Click += (sender, e) =>
            {
                try
                {
                    if (Clipboard.ContainsText())
                    {
                        // TODO FLV or WMVの判定をして、PecaPlayerコントロールを再初期化する
                        // TODO スレッド選択を解除 + 新しいスレッドへ移動
                        // TODO ステータスバーを変更
                        Open(Clipboard.GetText());
                    }
                }
                catch (System.Runtime.InteropServices.ExternalException)
                {
                    MessageBox.Show("クリップボードのオープンに失敗しました");
                }
            };

            // 音量
            volumeUpToolStripMenuItem.Click            += (sender, e) => shortcut.ExecCommand(Commands.VolumeUp);
            volumeDownToolStripMenuItem.Click          += (sender, e) => shortcut.ExecCommand(Commands.VolumeDown);
            muteToolStripMenuItem.Click                += (sender, e) => shortcut.ExecCommand(Commands.Mute);
            volumeBalanceLeftToolStripMenuItem.Click   += (sender, e) => shortcut.ExecCommand(Commands.VolumeBalanceLeft);
            volumeBalanceMiddleToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.VolumeBalanceMiddle);
            volumeBalanceRightToolStripMenuItem.Click  += (sender, e) => shortcut.ExecCommand(Commands.VolumeBalanceRight);
            volumeToolStripMenuItem.DropDownOpening    += (sender, e) => muteToolStripMenuItem.Checked = pecaPlayer.Mute;
            volumeToolStripMenuItem.DropDownOpening    += (sender, e) => volumeBalanceLeftToolStripMenuItem.Checked = (pecaPlayer.VolumeBalance == VolumeBalanceCommandArgs.BalanceLeft);
            volumeToolStripMenuItem.DropDownOpening    += (sender, e) => volumeBalanceMiddleToolStripMenuItem.Checked = (pecaPlayer.VolumeBalance == VolumeBalanceCommandArgs.BalanceMiddle);
            volumeToolStripMenuItem.DropDownOpening    += (sender, e) => volumeBalanceRightToolStripMenuItem.Checked = (pecaPlayer.VolumeBalance == VolumeBalanceCommandArgs.BalanceRight);

            // 設定メニュー押下
            settingToolStripMenuItem.Click += (sender, e) =>
            {
                PlayerSettingView view = new PlayerSettingView(shortcut);
                view.TopMost = TopMost;
                view.ShowDialog();
            };

            // WMPメニュー押下
            wmpMenuToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.WmpMenu);
            // 動画情報表示押下
            showDebugToolStripMenuItem.Click += (sender, e) => pecaPlayer.ShowDebug();
        }
Esempio n. 5
0
        //bool mgstart = false;
        private UserControl1 createView(string path)
        {
            UserControl1 us = new UserControl1();

            us.listView.BackColor = Color.LightGray;
            us.Enter += (s, e) => {
                if (activeUs != null)
                {
                    activeUs.listView.BackColor = Color.LightGray;
                    if (mg != null)
                    {
                        mg.End();
                    }
                    mglog = string.Empty;
                    //mgstart = false;
                }
                activeUs = us;
                activeUs.listView.BackColor = Color.White;
            };

            //us.listView.DoubleClick += (sender, e) => {
            //    if (us.listView.SelectedIndices.Count == 1) {
            //        var items = us.ItemList;
            //        var index = us.listView.SelectedIndices[0];
            //        //var fp = System.IO.Path.Combine(us.Path, items[index].Name);
            //        var fp = getFullPath(us.Dir, items[index].Name);
            //        //if (items[index].IsFile) {
            //        if (File.Exists(fp)) {
            //            HistoryListView.Items.Insert(0, fp);
            //            Process.Start(fp);
            //        }
            //        else if(Directory.Exists(fp)){
            //            us.Dir = fp;
            //        }
            //    }
            //};
            us.listView.DoubleClickEx += (sender, e) => {
                if (us.listView.SelectedIndices.Count == 1)
                {
                    var items = us.ItemList;
                    var index = us.listView.SelectedIndices[0];
                    //var fp = System.IO.Path.Combine(us.Path, items[index].Name);
                    var fp = getFullPath(us.Dir, items[index].Name);
                    //if (items[index].IsFile) {
                    if (File.Exists(fp))
                    {
                        HistoryListView.Items.Insert(0, fp);
                        Process.Start(fp);
                    }
                    else if (Directory.Exists(fp))
                    {
                        us.Dir = fp;
                    }
                }
                else if (us.listView.SelectedIndices.Count == 0)
                {
                    us.UpDir();
                }
            };

            us.listView.MouseDown += (s, e) => {
                if (e.Button == MouseButtons.Right)
                {
                    mglog = string.Empty;
                    //if (mg == null) mg = new MouseGesture();

                    //mg.Start(us.listView, e.Location);
                    mg.Start(us.listView, us.listView.PointToScreen(new Point(e.X, e.Y)));
                    activeUs.listView.MultiSelect = false;
                }

                if (popupForm != null && popupForm.Visible)
                {
                    popupForm.Visible = false;
                }
            };

            us.listView.MouseMove += (s, e) => {
                if (e.Button == MouseButtons.Right)
                {
                    //Arrow arrow = mg.Test(new Point(e.X, e.Y));
                    Arrow arrow = mg.Test(us.listView.PointToScreen(new Point(e.X, e.Y)));
                    if (arrow != Arrow.none)
                    {
                        switch (arrow)
                        {
                        case Arrow.up:
                            //label1.Text += "↑";
                            mglog += "U";
                            break;

                        case Arrow.right:
                            //label1.Text += "→";
                            mglog += "R";
                            break;

                        case Arrow.down:
                            //label1.Text += "↓";
                            mglog += "D";
                            break;

                        case Arrow.left:
                            mglog += "L";
                            //label1.Text += "←";
                            break;
                        }
                    }
                }
            };
            us.listView.MouseUpEx += (s, e) => {
                if (e.Button == MouseButtons.Right)
                {
                    //Console.WriteLine("mglog=" + mglog);
                    if (MouseGestureMap.ContainsKey(mglog))
                    {
                        MouseGestureMap[mglog](this);
                    }
                    else if (mglog == string.Empty)
                    {
                        //UserControl1 u = s as UserControl1;
                        var ctm      = new ShellContextMenu();
                        var selfiles = us.SelectedItemList;
                        if (selfiles.Count == 0)
                        {
                            //ctm.CreateFolderMenu(us.listView.PointToScreen(new Point(e.X, e.Y)), us.Dir);
                            DirectoryInfo[] dir = new DirectoryInfo[1];
                            dir[0] = new DirectoryInfo(us.Dir);
                            ctm.ShowContextMenu(dir, us.listView.PointToScreen(new Point(e.X, e.Y)));
                        }
                        else
                        {
                            List <FileInfo> arrFI = new List <FileInfo>();
                            selfiles.ForEach(x => {
                                arrFI.Add(new FileInfo(System.IO.Path.Combine(us.Dir, x.Name)));
                            });
                            ctm.ShowContextMenu(arrFI.ToArray(), us.listView.PointToScreen(new Point(e.X, e.Y)));
                        }
                    }
                    if (mg != null)
                    {
                        mg.End();
                    }
                    mglog = string.Empty;
                    activeUs.listView.MultiSelect = true;
                }
            };
            us.listView.MouseUp += (s, e) => {
                if (e.Button == MouseButtons.Middle)
                {
                    if (us.listView.SelectedIndices.Count > 0)
                    {
                        var item = us.ItemList[us.listView.SelectedIndices[0]];
                        if (!item.IsFile)
                        {
                            var p = Path.Combine(us.Dir, item.Name);
                            createView(p);
                        }
                    }
                }
                else if (e.Button == MouseButtons.Right && !activeUs.listView.MultiSelect)
                {
                    var ctm      = new ShellContextMenu();
                    var selfiles = us.SelectedItemList;
                    //if (selfiles.Count == 0) {
                    //    DirectoryInfo[] dir = new DirectoryInfo[1];
                    //    dir[0] = new DirectoryInfo(us.Dir);
                    //    ctm.ShowContextMenu(dir, us.listView.PointToScreen(new Point(e.X, e.Y)));
                    //}
                    //else
                    if (selfiles.Count > 0)
                    {
                        List <FileInfo> arrFI = new List <FileInfo>();
                        selfiles.ForEach(x => {
                            arrFI.Add(new FileInfo(System.IO.Path.Combine(us.Dir, x.Name)));
                        });
                        ctm.ShowContextMenu(arrFI.ToArray(), us.listView.PointToScreen(new Point(e.X, e.Y)));
                    }
                    activeUs.listView.MultiSelect = true;
                }
            };
            us.listView.ItemMouseHover += (s, e) => {
                //e.Item.
                //var kk=0;
            };
            us.ChangePath += (s, e) => {
                HistoryListView.Items.Insert(0, e.path);
            };

            flowLayoutPanel1.Controls.Add(us);
            us.Dir = path;

            ResizeWindow();

            return(us);
        }
Esempio n. 6
0
        public PlayerSettingView(ShortcutManager shortcut)
        {
            this.shortcut = shortcut;

            InitializeComponent();

            // 親ウィンドウの中心に表示
            StartPosition = FormStartPosition.CenterParent;

            // 初期化
            Shown += (sender, e) =>
            {
                // チェックボックスの表示
                disconnectRealyOnCloseCheckBox.Checked = PlayerSettings.DisconnectRealyOnClose;
                returnPositionOnStartCheckBox.Checked = PlayerSettings.ReturnPositionOnStart;
                returnSizeOnStartCheckBox.Checked = PlayerSettings.ReturnSizeOnStart;
                windowSnapEnableCheckBox.Checked = PlayerSettings.WindowSnapEnable;
                aspectRateFixCheckBox.Checked = PlayerSettings.AspectRateFix;
                frameInvisibleCheckBox.Checked = PlayerSettings.FrameInvisible;
                topMostCheckBox.Checked = PlayerSettings.TopMost;
                writeFieldVisibleCheckBox.Checked = PlayerSettings.WriteFieldVisible;
                initVolumeTextBox.Text = PlayerSettings.InitVolume.ToString();
                saveReturnPositionCheckBox.Checked = PlayerSettings.SaveReturnPositionOnClose;
                saveReturnSizeCheckBox.Checked = PlayerSettings.SaveReturnSizeOnClose;

                // チェックボックスの設定(ステータスバー)
                displayFpsCheckBox.Checked = PlayerSettings.DisplayFps;
                displayBitrateCheckBox.Checked = PlayerSettings.DisplayBitrate;
                listenerNumberCheckBox.Checked = PlayerSettings.DisplayListenerNumber;

                // 音量変化
                volumeChangeNoneTextBox.Text = PlayerSettings.VolumeChangeNone.ToString();
                volumeChangeCtrlTextBox.Text = PlayerSettings.VolumeChangeCtrl.ToString();
                volumeChangeShiftTextBox.Text = PlayerSettings.VolumeChangeShift.ToString();

                // 動画再生開始時のコマンド
                movieStartComboBox.Items.Clear();
                foreach (Commands command in movieStartCommandList)
                {
                    string detail = shortcut.CommandMap[command].Detail;
                    movieStartComboBox.Items.Add(detail);

                    if (PlayerSettings.MovieStartCommand == command)
                    {
                        movieStartComboBox.SelectedIndex = (movieStartComboBox.Items.Count - 1);
                    }
                }

                // ショートカット・ジェスチャー表示
                shortcutListView.Items.Clear();
                foreach (KeyValuePair<Commands, ShortcutCommand> commandPair in shortcut.CommandMap)
                {
                    // ショートカットのアイテム追加
                    ListViewItem keyItem = CreateKeyItem(shortcut, commandPair);
                    shortcutListView.Items.Add(keyItem);
                }
            };

            // Tab遷移しないようにする
            shortcutListView.PreviewKeyDown += (sender, e) => e.IsInputKey = true;

            // ショートカット設定時にエラー音がならないようにする
            shortcutListView.KeyPress += (sender, e) => e.Handled = true;

            // ショートカット入力
            shortcutListView.KeyDown += (sender, e) =>
            {
                if (shortcutListView.SelectedIndices.Count <= 0) return;
                if (e.KeyData == Keys.ProcessKey) return;

                // 同じキー入力を削除
                foreach (ListViewItem item in shortcutListView.Items)
                {
                    object tag = item.SubItems[1].Tag;	// KeyInput

                    if ((tag == null))
                    {
                        continue;
                    }

                    KeyInput keyInput = (KeyInput)tag;

                    if ((keyInput.Key == e.KeyCode) && (keyInput.Modifiers == e.Modifiers))
                    {
                        item.SubItems[1].Text = "-";
                        item.SubItems[1].Tag = null;
                    }
                }

                // ショートカット登録
                KeyInput input = new KeyInput(e.Modifiers, e.KeyCode);
                int index = shortcutListView.SelectedIndices[0];
                shortcutListView.Items[index].SubItems[1].Text = ConvertKeyInputToString(input);
                shortcutListView.Items[index].SubItems[1].Tag = input;

                // キー入力を無視
                e.Handled = true;
            };

            // ダブルクリックでコマンド削除
            shortcutListView.MouseDoubleClick += (sender, e) =>
            {
                if (shortcutListView.SelectedIndices.Count <= 0) return;

                if (e.Button == MouseButtons.Left)
                {
                    int index = shortcutListView.SelectedIndices[0];
                    shortcutListView.Items[index].SubItems[1].Text = "-";
                    shortcutListView.Items[index].SubItems[1].Tag = null;
                }
                else if (e.Button == System.Windows.Forms.MouseButtons.Right)
                {
                    int index = shortcutListView.SelectedIndices[0];
                    shortcutListView.Items[index].SubItems[2].Text = "-";
                    shortcutListView.Items[index].SubItems[2].Tag = null;
                }
            };

            // マウスジェスチャ
            MouseGesture mouseGesture = new MouseGesture();
            mouseGesture.Interval = PlayerSettings.MouseGestureInterval;
            bool gestureing = false;
            shortcutListView.MouseDown += (sender, e) =>
            {
                if (e.Button == MouseButtons.Right)
                {
                    mouseGesture.Start();
                    gestureing = true;
                }
            };
            shortcutListView.MouseMove += (sender, e) =>
            {
                if (shortcutListView.SelectedIndices.Count <= 0) return;
                if (gestureing == false) return;

                mouseGesture.Moving(e.Location);

                int index = shortcutListView.SelectedIndices[0];

                string gesture = mouseGesture.ToString();
                if (string.IsNullOrEmpty(gesture)) return;
                if (shortcutListView.Items[index].SubItems[2].Text == mouseGesture.ToString()) return;

                // 同じジェスチャを削除
                foreach (ListViewItem item in shortcutListView.Items)
                {
                    string text = item.SubItems[2].Text;
                    if (gesture == text)
                    {
                        item.SubItems[2].Text = "-";
                        item.SubItems[2].Tag = null;
                    }
                }

                // ジェスチャを登録
                shortcutListView.Items[index].SubItems[2].Text = gesture;
                shortcutListView.Items[index].SubItems[2].Tag = null;
            };
            shortcutListView.MouseUp += (sender, e) => gestureing = false;
        }
Esempio n. 7
0
		public PlayerSettingView(ShortcutManager shortcut)
		{
			this.shortcut = shortcut;

			InitializeComponent();

			// 親ウィンドウの中心に表示
			StartPosition = FormStartPosition.CenterParent;

			// 初期化
			Shown += (sender, e) =>
			{
				// チェックボックスの表示
				disconnectRealyOnCloseCheckBox.Checked = PlayerSettings.DisconnectRealyOnClose;
				returnPositionOnStartCheckBox.Checked = PlayerSettings.ReturnPositionOnStart;
				returnSizeOnStartCheckBox.Checked = PlayerSettings.ReturnSizeOnStart;
				windowSnapEnableCheckBox.Checked = PlayerSettings.WindowSnapEnable;
				aspectRateFixCheckBox.Checked = PlayerSettings.AspectRateFix;
				frameInvisibleCheckBox.Checked = PlayerSettings.FrameInvisible;
				topMostCheckBox.Checked = PlayerSettings.TopMost;
				writeFieldVisibleCheckBox.Checked = PlayerSettings.WriteFieldVisible;
				initVolumeTextBox.Text = PlayerSettings.InitVolume.ToString();
				saveReturnPositionCheckBox.Checked = PlayerSettings.SaveReturnPositionOnClose;
				saveReturnSizeCheckBox.Checked = PlayerSettings.SaveReturnSizeOnClose;
				exitedViewerCloseCheckBox.Checked = PlayerSettings.ExitedViewerClose;

				// チェックボックスの設定(ステータスバー)
				displayFpsCheckBox.Checked = PlayerSettings.DisplayFps;
				displayBitrateCheckBox.Checked = PlayerSettings.DisplayBitrate;
				listenerNumberCheckBox.Checked = PlayerSettings.DisplayListenerNumber;

				// 音量変化
				volumeChangeNoneTextBox.Text = PlayerSettings.VolumeChangeNone.ToString();
				volumeChangeCtrlTextBox.Text = PlayerSettings.VolumeChangeCtrl.ToString();
				volumeChangeShiftTextBox.Text = PlayerSettings.VolumeChangeShift.ToString();

				// スクリーンショット
				screenshotFolderTextBox.Text = PlayerSettings.ScreenshotFolder;
				foreach (var item in screenshotExtensionComboBox.Items)
				{
					if (item.ToString() == PlayerSettings.ScreenshotExtension)
					{
						screenshotExtensionComboBox.SelectedItem = item;
					}
				}
				// 拡張子が選択されていなければpngを選ばせる
				if (screenshotExtensionComboBox.SelectedItem == null)
				{
					screenshotExtensionComboBox.SelectedIndex = screenshotExtensionComboBox.FindString("png");
				}
				// 書式
				screenshotFormatTextBox.Text = PlayerSettings.ScreenshotFormat;
				screenshotSampleTextBox.Text = Shortcut.Command.ScreenshotCommand.Format(screenshotFormatTextBox.Text, null);

				// スレッド
				autoReadThreadCheckBox.Checked = PlayerSettings.AutoReadThread;

				// FLV
				flvGpuCheckBox.Checked = PlayerSettings.Gpu;
				useRtmpCheckBox.Checked = PlayerSettings.Rtmp;
				bufferTimeTextBox.Text = PlayerSettings.BufferTime.ToString();
				bufferTimeMaxTextBox.Text = PlayerSettings.BufferTimeMax.ToString();

				// 動画再生開始時のコマンド
				movieStartComboBox.Items.Clear();
				foreach (Commands command in movieStartCommandList)
				{
					string detail = shortcut.CommandMap[command].Detail;
					movieStartComboBox.Items.Add(detail);

					if (PlayerSettings.MovieStartCommand == command)
					{
						movieStartComboBox.SelectedIndex = (movieStartComboBox.Items.Count - 1);
					}
				}

				// ショートカット・ジェスチャー表示
				shortcutListView.Items.Clear();
				foreach (KeyValuePair<Commands, ShortcutCommand> commandPair in shortcut.CommandMap)
				{
					// ショートカットのアイテム追加
					ListViewItem keyItem = CreateKeyItem(shortcut, commandPair);
					shortcutListView.Items.Add(keyItem);
				}
			};

			// スクリーンショットを保存するフォルダを選ぶダイアログを表示するボタン
			browseScreenshotFolderButton.Click += (sender, args) =>
			{
				folderBrowserDialog.RootFolder = Environment.SpecialFolder.Desktop;
				folderBrowserDialog.SelectedPath = PlayerSettings.ScreenshotFolder;
				if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
				{
					screenshotFolderTextBox.Text = folderBrowserDialog.SelectedPath;
				}
			};

			// スクリーンショットファイル名の書式
			screenshotFormatTextBox.TextChanged += (sender, args) =>
			{
				screenshotSampleTextBox.Text = Shortcut.Command.ScreenshotCommand.Format(screenshotFormatTextBox.Text, null);
			};
			// 書式の補助メニュー
			screenshotFormatButton.Click += (sender, args) => screenshotContextMenuStrip.Show(screenshotFormatButton, 0, 0);
			Action<string> formatHelper = (x) =>
			{
				// 選択されているテキストの位置を取得しておく
				var selectionStart = screenshotFormatTextBox.SelectionStart;
				screenshotFormatTextBox.Text = screenshotFormatTextBox.Text.Insert(screenshotFormatTextBox.SelectionStart, x);
				// 追加した文字列の後ろにカーソルを移動
				screenshotFormatTextBox.SelectionStart = selectionStart + x.Length;
				screenshotFormatTextBox.Focus();
			};
			year2ToolStripMenuItem.Click += (sender, args) => formatHelper("yy");
			year4ToolStripMenuItem.Click += (sender, args) => formatHelper("yyyy");
			monthToolStripMenuItem.Click += (sender, args) => formatHelper("MM");
			dayToolStripMenuItem.Click += (sender, args) => formatHelper("dd");
			hourToolStripMenuItem.Click += (sender, args) => formatHelper("hh");
			minuteToolStripMenuItem.Click += (sender, args) => formatHelper("mm");
			secondToolStripMenuItem.Click += (sender, args) => formatHelper("ss");
			channelNameToolStripMenuItem.Click += (sender, args) => formatHelper("$0");

			// Tab遷移しないようにする
			shortcutListView.PreviewKeyDown += (sender, e) => e.IsInputKey = true;

			// ショートカット設定時にエラー音がならないようにする
			shortcutListView.KeyPress += (sender, e) => e.Handled = true;

			// ショートカット入力
			shortcutListView.KeyDown += (sender, e) =>
			{
				if (shortcutListView.SelectedIndices.Count <= 0) return;
				if (e.KeyData == Keys.ProcessKey) return;

				// 同じキー入力を削除
				foreach (ListViewItem item in shortcutListView.Items)
				{
					object tag = item.SubItems[1].Tag;	// KeyInput

					if ((tag == null))
					{
						continue;
					}

					KeyInput keyInput = (KeyInput)tag;

					if ((keyInput.Key == e.KeyCode) && (keyInput.Modifiers == e.Modifiers))
					{
						item.SubItems[1].Text = "-";
						item.SubItems[1].Tag = null;
					}
				}

				// ショートカット登録
				KeyInput input = new KeyInput(e.Modifiers, e.KeyCode);
				int index = shortcutListView.SelectedIndices[0];
				shortcutListView.Items[index].SubItems[1].Text = ConvertKeyInputToString(input);
				shortcutListView.Items[index].SubItems[1].Tag = input;

				// キー入力を無視
				e.Handled = true;
			};

			// ダブルクリックでコマンド削除
			shortcutListView.MouseDoubleClick += (sender, e) =>
			{
				if (shortcutListView.SelectedIndices.Count <= 0) return;

				if (e.Button == MouseButtons.Left)
				{
					int index = shortcutListView.SelectedIndices[0];
					shortcutListView.Items[index].SubItems[1].Text = "-";
					shortcutListView.Items[index].SubItems[1].Tag = null;
				}
				else if (e.Button == System.Windows.Forms.MouseButtons.Right)
				{
					int index = shortcutListView.SelectedIndices[0];
					shortcutListView.Items[index].SubItems[2].Text = "-";
					shortcutListView.Items[index].SubItems[2].Tag = null;
				}
			};

			// マウスジェスチャ
			MouseGesture mouseGesture = new MouseGesture();
			mouseGesture.Interval = PlayerSettings.MouseGestureInterval;
			bool gestureing = false;
			shortcutListView.MouseDown += (sender, e) =>
			{
				if (e.Button == MouseButtons.Right)
				{
					mouseGesture.Start();
					gestureing = true;
				}
			};
			shortcutListView.MouseMove += (sender, e) =>
			{
				if (shortcutListView.SelectedIndices.Count <= 0) return;
				if (gestureing == false) return;

				mouseGesture.Moving(e.Location);
                string gesture = mouseGesture.ToString();

				int index = shortcutListView.SelectedIndices[0];
				if (string.IsNullOrEmpty(gesture)) return;
				if (shortcutListView.Items[index].SubItems[2].Text == mouseGesture.ToString()) return;

				// ジェスチャを登録
				shortcutListView.Items[index].SubItems[2].Text = gesture;
				shortcutListView.Items[index].SubItems[2].Tag = null;
			};
            shortcutListView.MouseUp += (sender, e) =>
            {
                if (shortcutListView.SelectedIndices.Count <= 0) return;
                if (gestureing == false) return;

                mouseGesture.Moving(e.Location);
                string gesture = mouseGesture.ToString();

                int index = shortcutListView.SelectedIndices[0];
                if (string.IsNullOrEmpty(gesture)) return;

                // 同じジェスチャを削除
                foreach (ListViewItem item in shortcutListView.Items)
                {
                    string text = item.SubItems[2].Text;
                    if (gesture == text)
                    {
                        item.SubItems[2].Text = "-";
                        item.SubItems[2].Tag = null;
                    }
                }

                // ジェスチャを登録
                shortcutListView.Items[index].SubItems[2].Text = gesture;
                shortcutListView.Items[index].SubItems[2].Tag = null;
            };
			shortcutListView.MouseUp += (sender, e) => gestureing = false;
		}