/// <summary> /// キャプチャフォームが閉じられた /// </summary> /// <param name="sender">イベント発生源</param> /// <param name="e">イベント情報</param> private void CaptureForm_FormClosed(object sender, FormClosedEventArgs e) { CaptureForm f = sender as CaptureForm; if (f == null) { return; } if (f.IsCaptureEnd) { // キャプチャ範囲が選択された場合 config.CaptureRect = f.CaptureRects.CaptureRect; config.Save(); captureRects = f.CaptureRects; BeginCapturing(); } else if (config.CaptureRect.Top > 0 && config.CaptureRect.Left > 0 && config.CaptureRect.Width > 0 && config.CaptureRect.Height > 0) { // キャプチャ範囲が選択されなかった場合でも、以前の選択範囲があるならキャプチャを開始 BeginCapturing(); } captureBtn.Text = "キャプチャ範囲選択"; captureForm = new CaptureForm(); }
/// <summary> /// マウス移動イベント /// </summary> /// <param name="sender">イベント発生源</param> /// <param name="e">イベント情報</param> private void screenImg_MouseMove(object sender, MouseEventArgs e) { if (!IsSelecting) { return; } endPoint = new Point(e.X, e.Y); int captureWidth = Math.Abs(endPoint.X - startPoint.X); int captureHeight = Math.Abs(endPoint.Y - startPoint.Y); xUnit = captureWidth / (X_BLOCK_NUM); yUnit = captureHeight / Y_BLOCK_NUM; CaptureRects.CalculateRects(startPoint, endPoint); Refresh(); }
/// <summary> /// コンストラクタ /// </summary> public MainForm() { InitializeComponent(); playerNameTxts = new TextBox[] { playerNameTxt1, playerNameTxt2 }; tagsTxts = new TextBox[] { tagsTxt1, tagsTxt2 }; stepRecordTxts = new TextBox[] { stepRecordTxt1, stepRecordTxt2 }; statusLabel.Text = ""; fpsLbl.Text = ""; // 設定情報を読み込み初期化 config = new PuyofuConfiguration(); config.Init(); detector.SimilarityThreshold = config.SimilarityThreshold; similarityValueBar.Value = config.SimilarityThreshold; similarityValueLbl.Text = similarityValueBar.Value.ToString(); recordIdTxt.Text = config.RecordId.ToString(); recordDate.Text = config.RecordDate; playerNameTxt1.Text = config.PlayerName1; playerNameTxt2.Text = config.PlayerName2; CheckFieldRadio(config.TargetField); if (config.CaptureRect.Top > 0 && config.CaptureRect.Left > 0 && config.CaptureRect.Width > 0 && config.CaptureRect.Height > 0) { captureRects = new CaptureRects(); captureRects.CalculateRects(config.CaptureRect); BeginCapturing(); } // サンプリング画像初期設定 updateSamples(); // ペンの初期化 pens[PuyoType.AKA] = new Pen(Color.Red, 2); pens[PuyoType.MIDORI] = new Pen(Color.Green, 2); pens[PuyoType.AO] = new Pen(Color.LightBlue, 2); pens[PuyoType.KI] = new Pen(Color.Yellow, 2); pens[PuyoType.MURASAKI] = new Pen(Color.Purple, 2); }
/// <summary> /// マウスダウンイベント /// </summary> /// <param name="sender">イベント発生源</param> /// <param name="e">イベント情報</param> private void screenImg_MouseDown(object sender, MouseEventArgs e) { if (!IsSelecting && e.Button != MouseButtons.Left) { return; } if (!IsSelecting) { // キャプチャ範囲指定開始 startPoint = new Point(e.X, e.Y); endPoint = new Point(e.X, e.Y); xUnit = 0f; yUnit = 0f; IsSelecting = true; CaptureRects = new CaptureRects(); Refresh(); } else if (e.Button == MouseButtons.Right) { // キャンセル IsSelecting = false; Refresh(); } else if (e.Button == MouseButtons.Left) { // キャプチャ範囲指定終了 endPoint = new Point(e.X, e.Y); int captureWidth = Math.Abs(endPoint.X - startPoint.X); int captureHeight = Math.Abs(endPoint.Y - startPoint.Y); xUnit = captureWidth / (X_BLOCK_NUM); yUnit = captureHeight / Y_BLOCK_NUM; IsCaptureEnd = true; this.Close(); } }
/// <summary> /// 画面を再描画 /// </summary> /// <param name="sender">イベント発生源</param> /// <param name="e">イベント情報</param> private void screenPict_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; using (Bitmap bm = new Bitmap(rawScreenImage)) { // オリジナルのスクリーン画像を描画 g.DrawImage(rawScreenImage, new Point(0, 0)); if (!IsSelecting) { return; } // 選択範囲を描画 using (Pen pen = new Pen(System.Drawing.Color.Red, 2)) { g.DrawRectangle(pen, CaptureRects.GetFieldRect(0)); g.DrawRectangle(pen, CaptureRects.GetFieldRect(1)); g.DrawRectangle(pen, CaptureRects.GetNextRect(0)); g.DrawRectangle(pen, CaptureRects.GetNextRect(1)); } } }