Skip to content

Commit

Permalink
Fix Can't cancel the "load a calibration screenshot" window #41
Browse files Browse the repository at this point in the history
  • Loading branch information
stringandstickytape committed Jan 16, 2015
1 parent ba29bb5 commit 99e39c3
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions RegulatedNoise/Ocr/Calibration/OcrCalibratorTab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private void FillRawData()
tb_rawdata.Text = string.Join(Environment.NewLine, Form1.OcrCalibrator.CalibrationBoxes.Select(p => p.Position.X + ";" + p.Position.Y));
}

private Bitmap getReferenceScreenshot(bool necessarily)
private Bitmap getReferenceScreenshot()
{
var openFile = new OpenFileDialog
{
Expand All @@ -86,10 +86,7 @@ private Bitmap getReferenceScreenshot(bool necessarily)
InitialDirectory =
Environment.GetFolderPath((Environment.SpecialFolder.MyPictures)) +
@"\Frontier Developments\Elite Dangerous",
Title =
necessarily
? "Open a screenshot for calibration verification? (not essential)"
: "Open a screenshot for calibration"
Title = "Open a screenshot for calibration"
};

if (openFile.ShowDialog() == DialogResult.OK)
Expand All @@ -101,7 +98,7 @@ private Bitmap getReferenceScreenshot(bool necessarily)
var wrongres = MessageBox.Show("The selected image has a different resolution from your current game settings. Do you want to pick another image?", "Ooops...", MessageBoxButtons.YesNo);
if (wrongres == DialogResult.Yes)
{
return getReferenceScreenshot(necessarily);
return getReferenceScreenshot();
}

// Force resolution from input bmp
Expand All @@ -113,7 +110,7 @@ private Bitmap getReferenceScreenshot(bool necessarily)

return bmp;
}
return getReferenceScreenshot(necessarily);
return null;
}

private Bitmap _refbmp;
Expand All @@ -126,12 +123,15 @@ private void btn_calibrate_Click(object sender, EventArgs e)
if (_refbmp != null)
_refbmp.Dispose();

_refbmp = getReferenceScreenshot(true);
_refbmp = getReferenceScreenshot();

btn_calibration_reset.Enabled = true;
if (_refbmp == null)
{
return;
}

if (_refbmp != null)
pb_calibratorBox.Image = _refbmp;
btn_calibration_reset.Enabled = true;
pb_calibratorBox.Image = _refbmp;

if (Form1.OcrCalibrator.CalibrationBoxes == null)
{
Expand All @@ -142,10 +142,7 @@ private void btn_calibrate_Click(object sender, EventArgs e)
else
{
FillRawData();
if (_refbmp != null)
{
_drawPoints = true;
}
_drawPoints = true;
Form1.OcrCalibrator.SaveCalibration();
}

Expand Down Expand Up @@ -273,7 +270,7 @@ private void Pb_calibratorBox_MouseMove(object sender, MouseEventArgs e)
if (pb_calibratorMagnifier.Image != null)
pb_calibratorMagnifier.Image.Dispose();

if (pb_calibratorBox.Image != null)
if (pb_calibratorBox.Image != null && _refbmp != null)
pb_calibratorMagnifier.Image = Crop(_refbmp, new Rectangle(e.X - 25, e.Y - 17, 50, 31));
}

Expand Down

0 comments on commit 99e39c3

Please sign in to comment.