|
@@ -9,25 +9,29 @@ using System.Threading.Tasks;
|
|
|
using System.Windows.Forms;
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
|
namespace SketchAssistant
|
|
|
{
|
|
|
- public partial class Form1 : Form
|
|
|
+ public partial class Form1 : Form, MVP_View
|
|
|
{
|
|
|
public Form1()
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
- fileImporter = new FileImporter();
|
|
|
+ ProgramPresenter = new MVP_Presenter(this);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
+ public enum ButtonState
|
|
|
+ {
|
|
|
+ Enabled,
|
|
|
+ Disabled,
|
|
|
+ Active
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
@@ -38,72 +42,23 @@ namespace SketchAssistant
|
|
|
Draw,
|
|
|
Delete
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- private ProgramState currentState;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- private FileImporter fileImporter;
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
OpenFileDialog openFileDialog = new OpenFileDialog();
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- private Image leftImage = null;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- private List<Line> leftLineList;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- Image rightImage = null;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- List<Point> currentLine;
|
|
|
-
|
|
|
|
|
|
|
|
|
- List<Tuple<bool,Line>> rightLineList = new List<Tuple<bool, Line>>();
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- bool mousePressed = false;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- Point currentCursorPosition;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- Point previousCursorPosition;
|
|
|
+ List<Tuple<bool, Line>> rightLineList = new List<Tuple<bool, Line>>();
|
|
|
|
|
|
|
|
|
|
|
|
Queue<Point> cursorPositions = new Queue<Point>();
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- Graphics rightGraph = null;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- bool[,] isFilledMatrix;
|
|
|
- HashSet<int>[,] linesMatrix;
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
|
|
|
- uint deletionSize = 2;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- ActionHistory historyOfActions;
|
|
|
+ MVP_Presenter ProgramPresenter;
|
|
|
|
|
|
|
|
|
|
|
@@ -111,54 +66,25 @@ namespace SketchAssistant
|
|
|
|
|
|
private void Form1_Load(object sender, EventArgs e)
|
|
|
{
|
|
|
- currentState = ProgramState.Idle;
|
|
|
this.DoubleBuffered = true;
|
|
|
- historyOfActions = new ActionHistory(null);
|
|
|
- UpdateButtonStatus();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
private void Form1_Resize(object sender, System.EventArgs e)
|
|
|
{
|
|
|
+ ProgramPresenter.Resize(new Tuple<int, int>(pictureBoxLeft.Width, pictureBoxLeft.Height),
|
|
|
+ new Tuple<int, int>(pictureBoxRight.Width, pictureBoxRight.Height));
|
|
|
this.Refresh();
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- private void loadToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
- {
|
|
|
- openFileDialog.Filter = "Image|*.jpg;*.png;*.jpeg";
|
|
|
- if(openFileDialog.ShowDialog() == DialogResult.OK)
|
|
|
- {
|
|
|
- toolStripLoadStatus.Text = openFileDialog.SafeFileName;
|
|
|
- leftImage = Image.FromFile(openFileDialog.FileName);
|
|
|
- pictureBoxLeft.Image = leftImage;
|
|
|
-
|
|
|
- this.Refresh();
|
|
|
- }
|
|
|
- UpdateButtonStatus();
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void examplePictureToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
- openFileDialog.Filter = "Interactive Sketch-Assistant Drawing|*.isad";
|
|
|
- if (openFileDialog.ShowDialog() == DialogResult.OK)
|
|
|
- {
|
|
|
- toolStripLoadStatus.Text = openFileDialog.SafeFileName;
|
|
|
- try
|
|
|
- {
|
|
|
- (int, int, List<Line>) values = fileImporter.ParseISADInputFile(openFileDialog.FileName);
|
|
|
- DrawEmptyCanvasLeft(values.Item1, values.Item2);
|
|
|
- BindAndDrawLeftImage(values.Item3);
|
|
|
- this.Refresh();
|
|
|
- }
|
|
|
- catch(FileImporterException ex)
|
|
|
- {
|
|
|
- ShowInfoMessage(ex.ToString());
|
|
|
- }
|
|
|
- }
|
|
|
+ ProgramPresenter.ExamplePictureToolStripMenuItemClick();
|
|
|
}
|
|
|
|
|
|
|
|
@@ -166,486 +92,239 @@ namespace SketchAssistant
|
|
|
|
|
|
private void SVGDrawingToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
- openFileDialog.Filter = "Scalable Vector Graphics|*.svg";
|
|
|
- if (openFileDialog.ShowDialog() == DialogResult.OK)
|
|
|
- {
|
|
|
- toolStripLoadStatus.Text = openFileDialog.SafeFileName;
|
|
|
- try
|
|
|
- {
|
|
|
- (int, int, List<Line>) drawing = fileImporter.ParseSVGInputFile(openFileDialog.FileName, pictureBoxLeft.Width, pictureBoxLeft.Height);
|
|
|
- DrawEmptyCanvasLeft(drawing.Item1, drawing.Item2);
|
|
|
- BindAndDrawLeftImage(drawing.Item3);
|
|
|
- this.Refresh();
|
|
|
- }
|
|
|
- catch (FileImporterException ex)
|
|
|
- {
|
|
|
- ShowInfoMessage(ex.ToString());
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- ShowInfoMessage("exception occured while trying to parse svg file:\n\n" + ex.ToString() + "\n\n" + ex.StackTrace);
|
|
|
- }
|
|
|
- }
|
|
|
+ ProgramPresenter.SVGToolStripMenuItemClick();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
private void drawButton_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
- if(rightImage != null)
|
|
|
- {
|
|
|
- if (currentState.Equals(ProgramState.Draw))
|
|
|
- {
|
|
|
- ChangeState(ProgramState.Idle);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- ChangeState(ProgramState.Draw);
|
|
|
- }
|
|
|
- }
|
|
|
- UpdateButtonStatus();
|
|
|
+ ProgramPresenter.ChangeState(true);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
private void deleteButton_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
- if (rightImage != null)
|
|
|
- {
|
|
|
- if (currentState.Equals(ProgramState.Delete))
|
|
|
- {
|
|
|
- ChangeState(ProgramState.Idle);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- ChangeState(ProgramState.Delete);
|
|
|
- }
|
|
|
- }
|
|
|
- UpdateButtonStatus();
|
|
|
+ ProgramPresenter.ChangeState(false);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
private void undoButton_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
- if (historyOfActions.CanUndo())
|
|
|
- {
|
|
|
- HashSet<int> affectedLines = historyOfActions.GetCurrentAction().GetLineIDs();
|
|
|
- SketchAction.ActionType undoAction = historyOfActions.GetCurrentAction().GetActionType();
|
|
|
- switch (undoAction)
|
|
|
- {
|
|
|
- case SketchAction.ActionType.Delete:
|
|
|
-
|
|
|
- ChangeLines(affectedLines, true);
|
|
|
- break;
|
|
|
- case SketchAction.ActionType.Draw:
|
|
|
-
|
|
|
- ChangeLines(affectedLines, false);
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- historyOfActions.MoveAction(true);
|
|
|
- UpdateButtonStatus();
|
|
|
+ ProgramPresenter.Undo();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
private void redoButton_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
- if (historyOfActions.CanRedo())
|
|
|
- {
|
|
|
- historyOfActions.MoveAction(false);
|
|
|
- HashSet<int> affectedLines = historyOfActions.GetCurrentAction().GetLineIDs();
|
|
|
- SketchAction.ActionType redoAction = historyOfActions.GetCurrentAction().GetActionType();
|
|
|
- switch (redoAction)
|
|
|
- {
|
|
|
- case SketchAction.ActionType.Delete:
|
|
|
-
|
|
|
- ChangeLines(affectedLines, false);
|
|
|
- break;
|
|
|
- case SketchAction.ActionType.Draw:
|
|
|
-
|
|
|
- ChangeLines(affectedLines, true);
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- UpdateButtonStatus();
|
|
|
+ ProgramPresenter.Redo();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
private void Form1_KeyDown(object sender, KeyEventArgs e)
|
|
|
{
|
|
|
if (e.Modifiers == Keys.Control && e.KeyCode == Keys.Z)
|
|
|
{
|
|
|
- undoButton_Click(sender, e);
|
|
|
+ ProgramPresenter.Undo();
|
|
|
}
|
|
|
if (e.Modifiers == Keys.Control && e.KeyCode == Keys.Y)
|
|
|
{
|
|
|
- redoButton_Click(sender, e);
|
|
|
+ ProgramPresenter.Redo();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- private void pictureBoxRight_MouseMove(object sender, MouseEventArgs e)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private void pictureBoxRight_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
- currentCursorPosition = ConvertCoordinates(new Point(e.X, e.Y));
|
|
|
+ ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Click);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private void pictureBoxRight_MouseMove(object sender, MouseEventArgs e)
|
|
|
+ {
|
|
|
+ ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Move, e);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
private void pictureBoxRight_MouseDown(object sender, MouseEventArgs e)
|
|
|
{
|
|
|
- mousePressed = true;
|
|
|
- if (currentState.Equals(ProgramState.Draw))
|
|
|
- {
|
|
|
- currentLine = new List<Point>();
|
|
|
- }
|
|
|
+ ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Down);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
private void pictureBoxRight_MouseUp(object sender, MouseEventArgs e)
|
|
|
{
|
|
|
- mousePressed = false;
|
|
|
- if (currentState.Equals(ProgramState.Draw) && currentLine.Count > 0)
|
|
|
- {
|
|
|
- Line newLine = new Line(currentLine, rightLineList.Count);
|
|
|
- rightLineList.Add(new Tuple<bool, Line>(true, newLine));
|
|
|
- newLine.PopulateMatrixes(isFilledMatrix, linesMatrix);
|
|
|
- historyOfActions.AddNewAction(new SketchAction(SketchAction.ActionType.Draw, newLine.GetID()));
|
|
|
- }
|
|
|
- UpdateButtonStatus();
|
|
|
+ ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Up);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
private void canvasButton_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
- if (!historyOfActions.IsEmpty())
|
|
|
- {
|
|
|
- if (MessageBox.Show("You have unsaved changes, creating a new canvas will discard these.",
|
|
|
- "Attention", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
|
|
|
- {
|
|
|
- historyOfActions = new ActionHistory(lastActionTakenLabel);
|
|
|
- DrawEmptyCanvasRight();
|
|
|
-
|
|
|
- isFilledMatrix = new bool[rightImage.Width, rightImage.Height];
|
|
|
- linesMatrix = new HashSet<int>[rightImage.Width, rightImage.Height];
|
|
|
- rightLineList = new List<Tuple<bool, Line>>();
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- historyOfActions = new ActionHistory(lastActionTakenLabel);
|
|
|
- DrawEmptyCanvasRight();
|
|
|
-
|
|
|
- isFilledMatrix = new bool[rightImage.Width, rightImage.Height];
|
|
|
- linesMatrix = new HashSet<int>[rightImage.Width, rightImage.Height];
|
|
|
- rightLineList = new List<Tuple<bool, Line>>();
|
|
|
- }
|
|
|
- UpdateButtonStatus();
|
|
|
+ ProgramPresenter.NewCanvas();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
private void mouseTimer_Tick(object sender, EventArgs e)
|
|
|
{
|
|
|
- cursorPositions.Enqueue(currentCursorPosition);
|
|
|
- previousCursorPosition = cursorPositions.Dequeue();
|
|
|
- if (currentState.Equals(ProgramState.Draw) && mousePressed)
|
|
|
- {
|
|
|
- currentLine.Add(currentCursorPosition);
|
|
|
- Line drawline = new Line(currentLine);
|
|
|
- drawline.DrawLine(rightGraph);
|
|
|
- pictureBoxRight.Image = rightImage;
|
|
|
- }
|
|
|
- if (currentState.Equals(ProgramState.Delete) && mousePressed)
|
|
|
- {
|
|
|
- List<Point> uncheckedPoints = Line.BresenhamLineAlgorithm(previousCursorPosition, currentCursorPosition);
|
|
|
- foreach (Point currPoint in uncheckedPoints)
|
|
|
- {
|
|
|
- HashSet<int> linesToDelete = CheckDeletionMatrixesAroundPoint(currPoint, deletionSize);
|
|
|
- if (linesToDelete.Count > 0)
|
|
|
- {
|
|
|
- historyOfActions.AddNewAction(new SketchAction(SketchAction.ActionType.Delete, linesToDelete));
|
|
|
- foreach (int lineID in linesToDelete)
|
|
|
- {
|
|
|
- rightLineList[lineID] = new Tuple<bool, Line>(false, rightLineList[lineID].Item2);
|
|
|
- }
|
|
|
- RepopulateDeletionMatrixes();
|
|
|
- RedrawRightImage();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ ProgramPresenter.Tick();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
- private void DrawEmptyCanvasRight()
|
|
|
+ public void EnableTimer()
|
|
|
{
|
|
|
- if (leftImage == null)
|
|
|
- {
|
|
|
- rightImage = new Bitmap(pictureBoxRight.Width, pictureBoxRight.Height);
|
|
|
- rightGraph = Graphics.FromImage(rightImage);
|
|
|
- rightGraph.FillRectangle(Brushes.White, 0, 0, pictureBoxRight.Width + 10, pictureBoxRight.Height + 10);
|
|
|
- pictureBoxRight.Image = rightImage;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- rightImage = new Bitmap(leftImage.Width, leftImage.Height);
|
|
|
- rightGraph = Graphics.FromImage(rightImage);
|
|
|
- rightGraph.FillRectangle(Brushes.White, 0, 0, leftImage.Width + 10, leftImage.Height + 10);
|
|
|
- pictureBoxRight.Image = rightImage;
|
|
|
- }
|
|
|
- this.Refresh();
|
|
|
- pictureBoxRight.Refresh();
|
|
|
+ mouseTimer.Enabled = true;
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- private void DrawEmptyCanvasLeft(int width, int height)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public Tuple<String, String> openNewDialog(String Filter)
|
|
|
{
|
|
|
- if (width == 0)
|
|
|
+ openFileDialog.Filter = Filter;
|
|
|
+ if (openFileDialog.ShowDialog() == DialogResult.OK)
|
|
|
{
|
|
|
- leftImage = new Bitmap(pictureBoxLeft.Width, pictureBoxLeft.Height);
|
|
|
+ return new Tuple<string, string>(openFileDialog.FileName, openFileDialog.SafeFileName);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- leftImage = new Bitmap(width, height);
|
|
|
+ return new Tuple<string, string>("", "");
|
|
|
}
|
|
|
- Graphics.FromImage(leftImage).FillRectangle(Brushes.White, 0, 0, pictureBoxLeft.Width + 10, pictureBoxLeft.Height + 10);
|
|
|
- pictureBoxLeft.Image = leftImage;
|
|
|
-
|
|
|
- this.Refresh();
|
|
|
- pictureBoxLeft.Refresh();
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
- private void RedrawRightImage()
|
|
|
+
|
|
|
+ public void SetToolStripLoadStatus(String message)
|
|
|
{
|
|
|
- DrawEmptyCanvasRight();
|
|
|
- foreach (Tuple<bool, Line> lineBoolTuple in rightLineList)
|
|
|
- {
|
|
|
- if (lineBoolTuple.Item1)
|
|
|
- {
|
|
|
- lineBoolTuple.Item2.DrawLine(rightGraph);
|
|
|
- }
|
|
|
- }
|
|
|
- pictureBoxRight.Refresh();
|
|
|
+ toolStripLoadStatus.Text = message;
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- private void ChangeLines(HashSet<int> lines, bool shown)
|
|
|
+
|
|
|
+ public void SetLastActionTakenText(String message)
|
|
|
{
|
|
|
- foreach (int lineId in lines)
|
|
|
- {
|
|
|
- if (lineId <= rightLineList.Count - 1 && lineId >= 0)
|
|
|
- {
|
|
|
- rightLineList[lineId] = new Tuple<bool, Line>(shown, rightLineList[lineId].Item2);
|
|
|
- }
|
|
|
- }
|
|
|
- RedrawRightImage();
|
|
|
+ lastActionTakenLabel.Text = message;
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
- private void UpdateButtonStatus()
|
|
|
+
|
|
|
+
|
|
|
+ public void SetToolStripButtonStatus(String buttonName, ButtonState state)
|
|
|
{
|
|
|
- undoButton.Enabled = historyOfActions.CanUndo();
|
|
|
- redoButton.Enabled = historyOfActions.CanRedo();
|
|
|
- drawButton.Enabled = (rightImage != null);
|
|
|
- deleteButton.Enabled = (rightImage != null);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- private void ChangeState(ProgramState newState)
|
|
|
- {
|
|
|
- switch (currentState)
|
|
|
+ ToolStripButton buttonToChange;
|
|
|
+ switch (buttonName)
|
|
|
{
|
|
|
- case ProgramState.Draw:
|
|
|
- drawButton.CheckState = CheckState.Unchecked;
|
|
|
- mouseTimer.Enabled = false;
|
|
|
+ case "canvasButton":
|
|
|
+ buttonToChange = canvasButton;
|
|
|
break;
|
|
|
- case ProgramState.Delete:
|
|
|
- deleteButton.CheckState = CheckState.Unchecked;
|
|
|
- mouseTimer.Enabled = false;
|
|
|
+ case "drawButton":
|
|
|
+ buttonToChange = drawButton;
|
|
|
break;
|
|
|
- default:
|
|
|
+ case "deleteButton":
|
|
|
+ buttonToChange = deleteButton;
|
|
|
break;
|
|
|
- }
|
|
|
- switch (newState)
|
|
|
- {
|
|
|
- case ProgramState.Draw:
|
|
|
- drawButton.CheckState = CheckState.Checked;
|
|
|
- mouseTimer.Enabled = true;
|
|
|
+ case "undoButton":
|
|
|
+ buttonToChange = undoButton;
|
|
|
break;
|
|
|
- case ProgramState.Delete:
|
|
|
- deleteButton.CheckState = CheckState.Checked;
|
|
|
- mouseTimer.Enabled = true;
|
|
|
+ case "redoButton":
|
|
|
+ buttonToChange = redoButton;
|
|
|
break;
|
|
|
default:
|
|
|
- break;
|
|
|
+ Console.WriteLine("Invalid Button was given to SetToolStripButton. \nMaybe you forgot to add a case?");
|
|
|
+ return;
|
|
|
}
|
|
|
- currentState = newState;
|
|
|
- pictureBoxRight.Refresh();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- private Point ConvertCoordinates(Point cursorPosition)
|
|
|
- {
|
|
|
- Point realCoordinates = new Point(5,3);
|
|
|
- if(pictureBoxRight.Image == null)
|
|
|
- {
|
|
|
- return cursorPosition;
|
|
|
- }
|
|
|
-
|
|
|
- int widthImage = pictureBoxRight.Image.Width;
|
|
|
- int heightImage = pictureBoxRight.Image.Height;
|
|
|
- int widthBox = pictureBoxRight.Width;
|
|
|
- int heightBox = pictureBoxRight.Height;
|
|
|
-
|
|
|
- float imageRatio = (float)widthImage / (float)heightImage;
|
|
|
- float containerRatio = (float)widthBox / (float)heightBox;
|
|
|
-
|
|
|
- if (imageRatio >= containerRatio)
|
|
|
+ switch (state)
|
|
|
{
|
|
|
-
|
|
|
- float zoomFactor = (float)widthImage / (float)widthBox;
|
|
|
- float scaledHeight = heightImage / zoomFactor;
|
|
|
- float filler = (heightBox - scaledHeight) / 2;
|
|
|
- realCoordinates.X = (int)(cursorPosition.X * zoomFactor);
|
|
|
- realCoordinates.Y = (int)((cursorPosition.Y - filler) * zoomFactor);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
-
|
|
|
- float zoomFactor = (float)heightImage / (float)heightBox;
|
|
|
- float scaledWidth = widthImage / zoomFactor;
|
|
|
- float filler = (widthBox - scaledWidth) / 2;
|
|
|
- realCoordinates.X = (int)((cursorPosition.X - filler) * zoomFactor);
|
|
|
- realCoordinates.Y = (int)(cursorPosition.Y * zoomFactor);
|
|
|
- }
|
|
|
- return realCoordinates;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- private void RepopulateDeletionMatrixes()
|
|
|
- {
|
|
|
- if(rightImage != null)
|
|
|
- {
|
|
|
- isFilledMatrix = new bool[rightImage.Width,rightImage.Height];
|
|
|
- linesMatrix = new HashSet<int>[rightImage.Width, rightImage.Height];
|
|
|
- foreach(Tuple<bool,Line> lineTuple in rightLineList)
|
|
|
- {
|
|
|
- if (lineTuple.Item1)
|
|
|
- {
|
|
|
- lineTuple.Item2.PopulateMatrixes(isFilledMatrix, linesMatrix);
|
|
|
- }
|
|
|
- }
|
|
|
+ case ButtonState.Active:
|
|
|
+ buttonToChange.Checked = true;
|
|
|
+ break;
|
|
|
+ case ButtonState.Disabled:
|
|
|
+ buttonToChange.Checked = false;
|
|
|
+ buttonToChange.Enabled = false;
|
|
|
+ break;
|
|
|
+ case ButtonState.Enabled:
|
|
|
+ buttonToChange.Checked = false;
|
|
|
+ buttonToChange.Enabled = true;
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- private HashSet<int> CheckDeletionMatrixesAroundPoint(Point p, uint range)
|
|
|
+
|
|
|
+ public void DisplayInLeftPictureBox(Image img)
|
|
|
{
|
|
|
- HashSet<int> returnSet = new HashSet<int>();
|
|
|
-
|
|
|
- if (p.X >= 0 && p.Y >= 0 && p.X < rightImage.Width && p.Y < rightImage.Height)
|
|
|
- {
|
|
|
- if (isFilledMatrix[p.X, p.Y])
|
|
|
- {
|
|
|
- returnSet.UnionWith(linesMatrix[p.X, p.Y]);
|
|
|
- }
|
|
|
- }
|
|
|
- for (int x_mod = (int)range*(-1); x_mod < range; x_mod++)
|
|
|
- {
|
|
|
- for (int y_mod = (int)range * (-1); y_mod < range; y_mod++)
|
|
|
- {
|
|
|
- if (p.X + x_mod >= 0 && p.Y + y_mod >= 0 && p.X + x_mod < rightImage.Width && p.Y + y_mod < rightImage.Height)
|
|
|
- {
|
|
|
- if (isFilledMatrix[p.X + x_mod, p.Y + y_mod])
|
|
|
- {
|
|
|
- returnSet.UnionWith(linesMatrix[p.X + x_mod, p.Y + y_mod]);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return returnSet;
|
|
|
+ pictureBoxLeft.Image = img;
|
|
|
+ pictureBoxLeft.Refresh();
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- private void BindAndDrawLeftImage(List<Line> newTemplatePicture)
|
|
|
+
|
|
|
+ public void DisplayInRightPictureBox(Image img)
|
|
|
{
|
|
|
- leftLineList = newTemplatePicture;
|
|
|
- foreach(Line l in leftLineList)
|
|
|
- {
|
|
|
- l.DrawLine(Graphics.FromImage(leftImage));
|
|
|
- }
|
|
|
+ pictureBoxRight.Image = img;
|
|
|
+ pictureBoxRight.Refresh();
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- private void ShowInfoMessage(String message)
|
|
|
+ public void ShowInfoMessage(String message)
|
|
|
{
|
|
|
MessageBox.Show(message);
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
-
|
|
|
- public Object[] GetAllVariables()
|
|
|
+
|
|
|
+
|
|
|
+ public bool ShowWarning(String message)
|
|
|
{
|
|
|
- return new Object[] { currentState, fileImporter, openFileDialog, leftImage, leftLineList, rightImage, currentLine, rightLineList, mousePressed, currentCursorPosition, previousCursorPosition, cursorPositions, rightGraph, isFilledMatrix, linesMatrix, deletionSize, historyOfActions };
|
|
|
+ return (MessageBox.Show(message, "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- public void CreateCanvasAndSetPictureForTesting(int width, int height, List<Line> newImage)
|
|
|
- {
|
|
|
- DrawEmptyCanvasLeft(width, height);
|
|
|
- BindAndDrawLeftImage(newImage);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
}
|