예제 #1
0
파일: Projection.cs 프로젝트: Remmery/Pong
 /// <summary>
 /// Event that occurs when the mouse button is released (end of selection)
 /// </summary>
 /// <param name="sender">Object that fired the event</param>
 /// <param name="e">Extra information on the event</param>
 private void pictureBox_MouseUp(object sender, MouseEventArgs e)
 {
     this.pictureBox1.Invalidate();
     if (this.select)
     {
         if (selection.X + selection.Width > pictureBox1.Width)
         {
             selection.Width = pictureBox1.Width - selection.X;
         }
         if (selection.Y + selection.Height > pictureBox1.Height)
         {
             selection.Height = pictureBox1.Height - selection.Y;
         }
         DialogResult result = MessageBox.Show("Do you want to use the selected area?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
         if (result == DialogResult.Yes)
         {
             //add to unscaled list
             rectanglesUnscaled.Add(selection);
             //scale selection to original size
             Bitmap bmp    = camera.LastFrame;
             double scaleX = (double)bmp.Width / pictureBox1.Width;
             double scaleY = (double)bmp.Height / pictureBox1.Height;
             selection.X      = (int)(selection.X * scaleX);
             selection.Y      = (int)(selection.Y * scaleY);
             selection.Width  = (int)(selection.Width * scaleX);
             selection.Height = (int)(selection.Height * scaleY);
             //add to scaled list
             rectangles.Add(selection);
             if (rectangles.Count == setup.NumberOfPlayers)
             {
                 finished = true;
                 this.pictureBox1.MouseDown -= new MouseEventHandler(this.pictureBox_MouseDown);
                 this.pictureBox1.MouseMove -= new MouseEventHandler(this.pictureBox_MouseMove);
                 this.pictureBox1.MouseUp   -= new MouseEventHandler(this.pictureBox_MouseUp);
                 setup.Rectangles            = rectangles;
                 camera.End();
                 this.Close();
             }
         }
         else
         {
             this.selection = new Rectangle();
         }
     }
     this.select = false;
 }
예제 #2
0
 private void Window_Closed(object sender, EventArgs e)
 {
     //http://stackoverflow.com/questions/2927939/application-current-shutdown-vs-application-current-dispatcher-begininvokeshu
     camera.End();
     Dispatcher.InvokeShutdown();
 }