|
@@ -30,8 +30,13 @@ namespace SketchAssistant
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
bool inDrawingMode;
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
bool mousePressed;
|
|
|
|
|
|
|
|
@@ -100,14 +105,15 @@ namespace SketchAssistant
|
|
|
public MVP_Model(MVP_Presenter presenter)
|
|
|
{
|
|
|
programPresenter = presenter;
|
|
|
- historyOfActions = new ActionHistory(null);
|
|
|
+ historyOfActions = new ActionHistory();
|
|
|
redrawAss = new RedrawAssistant();
|
|
|
+ rightLineList = new List<Tuple<bool, Line>>();
|
|
|
+ overlayItems = new List<Tuple<bool, HashSet<Point>>>();
|
|
|
}
|
|
|
-
|
|
|
- public void Undo()
|
|
|
- {
|
|
|
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -133,21 +139,6 @@ namespace SketchAssistant
|
|
|
return image;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- private void DrawEmptyCanvasRight()
|
|
|
- {
|
|
|
- if (leftImage == null)
|
|
|
- {
|
|
|
- rightImageWithoutOverlay = GetEmptyCanvas(leftImageBoxWidth, leftImageBoxHeight);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- rightImageWithoutOverlay = GetEmptyCanvas(leftImage.Width, leftImage.Height);
|
|
|
- }
|
|
|
- RefreshRightImage();
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
|
@@ -164,29 +155,11 @@ namespace SketchAssistant
|
|
|
{
|
|
|
leftImage = GetEmptyCanvas(width, height);
|
|
|
}
|
|
|
- RefreshLeftImage();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- private void RefreshRightImage()
|
|
|
- {
|
|
|
- programPresenter.UpdateRightImage(rightImageWithOverlay);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- private void RefreshLeftImage()
|
|
|
- {
|
|
|
programPresenter.UpdateLeftImage(leftImage);
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
private void RedrawRightImage()
|
|
|
{
|
|
@@ -207,9 +180,15 @@ namespace SketchAssistant
|
|
|
currLine.DrawLine(workingGraph);
|
|
|
}
|
|
|
rightImageWithoutOverlay = workingCanvas;
|
|
|
-
|
|
|
- RedrawRightOverlay();
|
|
|
- RefreshRightImage();
|
|
|
+
|
|
|
+ if (leftImage != null)
|
|
|
+ {
|
|
|
+ RedrawRightOverlay();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ programPresenter.UpdateRightImage(rightImageWithoutOverlay);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
@@ -230,17 +209,7 @@ namespace SketchAssistant
|
|
|
}
|
|
|
}
|
|
|
rightImageWithOverlay = workingCanvas;
|
|
|
- RefreshRightImage();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- public void ChangeState(bool nowDrawing)
|
|
|
- {
|
|
|
- inDrawingMode = nowDrawing;
|
|
|
- UpdateUI();
|
|
|
+ programPresenter.UpdateRightImage(rightImageWithOverlay);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -280,7 +249,7 @@ namespace SketchAssistant
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -294,7 +263,7 @@ namespace SketchAssistant
|
|
|
|
|
|
foreach (Point pnt in GeometryCalculator.FilledCircleAlgorithm(p, (int)range))
|
|
|
{
|
|
|
- if (pnt.X >= 0 && pnt.Y >= 0 && pnt.X < rightImage.Width && pnt.Y < rightImage.Height)
|
|
|
+ if (pnt.X >= 0 && pnt.Y >= 0 && pnt.X < rightImageWithoutOverlay.Width && pnt.Y < rightImageWithoutOverlay.Height)
|
|
|
{
|
|
|
if (isFilledMatrix[pnt.X, pnt.Y])
|
|
|
{
|
|
@@ -305,6 +274,7 @@ namespace SketchAssistant
|
|
|
return returnSet;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -332,44 +302,148 @@ namespace SketchAssistant
|
|
|
return currentLineEndings;
|
|
|
}
|
|
|
*/
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
- public void UpdateSizes()
|
|
|
+ private void UpdateUI()
|
|
|
{
|
|
|
- if (rightImageWithoutOverlay != null)
|
|
|
+ programPresenter.UpdateUIState(inDrawingMode, historyOfActions.CanUndo(), historyOfActions.CanRedo(), (rightImageWithoutOverlay != null));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private bool CheckSavedStatus()
|
|
|
+ {
|
|
|
+ if (!historyOfActions.IsEmpty())
|
|
|
{
|
|
|
- int widthImage = rightImageWithoutOverlay.Width;
|
|
|
- int heightImage = rightImageWithoutOverlay.Height;
|
|
|
- int widthBox = rightImageBoxWidth;
|
|
|
- int heightBox = rightImageBoxHeight;
|
|
|
+ return (MessageBox.Show("You have unsaved changes, do you wish to continue?",
|
|
|
+ "Attention", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ */
|
|
|
|
|
|
- float imageRatio = (float)widthImage / (float)heightImage;
|
|
|
- float containerRatio = (float)widthBox / (float)heightBox;
|
|
|
- float zoomFactor = 0;
|
|
|
- if (imageRatio >= containerRatio)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public void DrawEmptyCanvasRight()
|
|
|
+ {
|
|
|
+ if (leftImage == null)
|
|
|
+ {
|
|
|
+ rightImageWithoutOverlay = GetEmptyCanvas(leftImageBoxWidth, leftImageBoxHeight);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ rightImageWithoutOverlay = GetEmptyCanvas(leftImage.Width, leftImage.Height);
|
|
|
+ }
|
|
|
+ RepopulateDeletionMatrixes();
|
|
|
+ rightImageWithOverlay = rightImageWithoutOverlay;
|
|
|
+ programPresenter.UpdateRightImage(rightImageWithOverlay);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public void SetLeftLineList(int width, int height, List<Line> listOfLines)
|
|
|
+ {
|
|
|
+ var workingCanvas = GetEmptyCanvas(width,height);
|
|
|
+ var workingGraph = Graphics.FromImage(workingCanvas);
|
|
|
+ leftLineList = listOfLines;
|
|
|
+
|
|
|
+ foreach (Line line in leftLineList)
|
|
|
+ {
|
|
|
+ line.DrawLine(workingGraph);
|
|
|
+ }
|
|
|
+ leftImage = workingCanvas;
|
|
|
+ programPresenter.UpdateLeftImage(leftImage);
|
|
|
+
|
|
|
+ DrawEmptyCanvasRight();
|
|
|
+ rightLineList = new List<Tuple<bool, Line>>();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void Undo()
|
|
|
+ {
|
|
|
+ if (historyOfActions.CanUndo())
|
|
|
+ {
|
|
|
+ HashSet<int> affectedLines = historyOfActions.GetCurrentAction().GetLineIDs();
|
|
|
+ SketchAction.ActionType undoAction = historyOfActions.GetCurrentAction().GetActionType();
|
|
|
+ switch (undoAction)
|
|
|
{
|
|
|
-
|
|
|
- zoomFactor = (float)widthImage / (float)widthBox;
|
|
|
+ case SketchAction.ActionType.Delete:
|
|
|
+
|
|
|
+ ChangeLines(affectedLines, true);
|
|
|
+ break;
|
|
|
+ case SketchAction.ActionType.Draw:
|
|
|
+
|
|
|
+ ChangeLines(affectedLines, false);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
}
|
|
|
- else
|
|
|
+ if(leftImage != null)
|
|
|
{
|
|
|
-
|
|
|
- zoomFactor = (float)heightImage / (float)heightBox;
|
|
|
+
|
|
|
}
|
|
|
- markerRadius = (int)(10 * zoomFactor);
|
|
|
- redrawAss.SetMarkerRadius(markerRadius);
|
|
|
- deletionRadius = (int)(5 * zoomFactor);
|
|
|
+ RedrawRightImage();
|
|
|
}
|
|
|
+ RepopulateDeletionMatrixes();
|
|
|
+ programPresenter.PassLastActionTaken(historyOfActions.MoveAction(true));
|
|
|
+ UpdateUI();
|
|
|
}
|
|
|
|
|
|
+ public void Redo()
|
|
|
+ {
|
|
|
+ if (historyOfActions.CanRedo())
|
|
|
+ {
|
|
|
+ programPresenter.PassLastActionTaken(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;
|
|
|
+ }
|
|
|
+ if (leftImage != null)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ RedrawRightImage();
|
|
|
+ RepopulateDeletionMatrixes();
|
|
|
+ }
|
|
|
+ UpdateUI();
|
|
|
+ }
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
- private void UpdateUI()
|
|
|
+
|
|
|
+ public void ChangeState(bool nowDrawing)
|
|
|
{
|
|
|
- programPresenter.UpdateUIState(inDrawingMode, historyOfActions.CanUndo(), historyOfActions.CanRedo(), (rightImageWithoutOverlay != null));
|
|
|
+ inDrawingMode = nowDrawing;
|
|
|
+ UpdateUI();
|
|
|
}
|
|
|
|
|
|
|
|
@@ -378,7 +452,7 @@ namespace SketchAssistant
|
|
|
|
|
|
public Tuple<int, int> GetRightImageDimensions()
|
|
|
{
|
|
|
- if(rightImageWithoutOverlay != null)
|
|
|
+ if (rightImageWithoutOverlay != null)
|
|
|
{
|
|
|
return new Tuple<int, int>(rightImageWithoutOverlay.Width, rightImageWithoutOverlay.Height);
|
|
|
}
|
|
@@ -390,23 +464,115 @@ namespace SketchAssistant
|
|
|
|
|
|
public void SetCurrentCursorPosition(Point p)
|
|
|
{
|
|
|
+ currentCursorPosition = p;
|
|
|
+ }
|
|
|
|
|
|
+ public void MouseDown()
|
|
|
+ {
|
|
|
+ mousePressed = true;
|
|
|
+ if (inDrawingMode)
|
|
|
+ {
|
|
|
+ currentLine = new List<Point>();
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ public void MouseUp()
|
|
|
+ {
|
|
|
+ mousePressed = false;
|
|
|
+ if (inDrawingMode && currentLine.Count > 0)
|
|
|
+ {
|
|
|
+ Line newLine = new Line(currentLine, rightLineList.Count);
|
|
|
+ rightLineList.Add(new Tuple<bool, Line>(true, newLine));
|
|
|
+ newLine.PopulateMatrixes(isFilledMatrix, linesMatrix);
|
|
|
+ programPresenter.PassLastActionTaken(historyOfActions.AddNewAction(new SketchAction(SketchAction.ActionType.Draw, newLine.GetID())));
|
|
|
+ if(leftImage != null)
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ RedrawRightImage();
|
|
|
+ }
|
|
|
+ UpdateUI();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void Tick()
|
|
|
+ {
|
|
|
+ if (cursorPositions.Count > 0) { previousCursorPosition = cursorPositions.Dequeue(); }
|
|
|
+ else { previousCursorPosition = currentCursorPosition; }
|
|
|
+ cursorPositions.Enqueue(currentCursorPosition);
|
|
|
+
|
|
|
+ if (inDrawingMode && mousePressed)
|
|
|
+ {
|
|
|
+ var rightGraph = Graphics.FromImage(rightImageWithoutOverlay);
|
|
|
+ currentLine.Add(currentCursorPosition);
|
|
|
+ Line drawline = new Line(currentLine);
|
|
|
+ drawline.DrawLine(rightGraph);
|
|
|
+ RedrawRightOverlay();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!inDrawingMode && mousePressed)
|
|
|
+ {
|
|
|
+ List<Point> uncheckedPoints = GeometryCalculator.BresenhamLineAlgorithm(previousCursorPosition, currentCursorPosition);
|
|
|
+ foreach (Point currPoint in uncheckedPoints)
|
|
|
+ {
|
|
|
+ HashSet<int> linesToDelete = CheckDeletionMatrixesAroundPoint(currPoint, deletionRadius);
|
|
|
+ if (linesToDelete.Count > 0)
|
|
|
+ {
|
|
|
+ programPresenter.PassLastActionTaken(historyOfActions.AddNewAction(new SketchAction(SketchAction.ActionType.Delete, linesToDelete)));
|
|
|
+ foreach (int lineID in linesToDelete)
|
|
|
+ {
|
|
|
+ rightLineList[lineID] = new Tuple<bool, Line>(false, rightLineList[lineID].Item2);
|
|
|
+ }
|
|
|
+ RepopulateDeletionMatrixes();
|
|
|
+ if(leftImage != null)
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ RedrawRightImage();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- private bool CheckSavedStatus()
|
|
|
+ public void UpdateSizes()
|
|
|
{
|
|
|
- if (!historyOfActions.IsEmpty())
|
|
|
+ if (rightImageWithoutOverlay != null)
|
|
|
{
|
|
|
- return (MessageBox.Show("You have unsaved changes, do you wish to continue?",
|
|
|
- "Attention", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes);
|
|
|
+ int widthImage = rightImageWithoutOverlay.Width;
|
|
|
+ int heightImage = rightImageWithoutOverlay.Height;
|
|
|
+ int widthBox = rightImageBoxWidth;
|
|
|
+ int heightBox = rightImageBoxHeight;
|
|
|
+
|
|
|
+ float imageRatio = (float)widthImage / (float)heightImage;
|
|
|
+ float containerRatio = (float)widthBox / (float)heightBox;
|
|
|
+ float zoomFactor = 0;
|
|
|
+ if (imageRatio >= containerRatio)
|
|
|
+ {
|
|
|
+
|
|
|
+ zoomFactor = (float)widthImage / (float)widthBox;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ zoomFactor = (float)heightImage / (float)heightBox;
|
|
|
+ }
|
|
|
+ markerRadius = (int)(10 * zoomFactor);
|
|
|
+ redrawAss.SetMarkerRadius(markerRadius);
|
|
|
+ deletionRadius = (int)(5 * zoomFactor);
|
|
|
}
|
|
|
- return true;
|
|
|
}
|
|
|
- */
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public bool HasUnsavedProgress()
|
|
|
+ {
|
|
|
+ return !historyOfActions.IsEmpty();
|
|
|
+ }
|
|
|
}
|
|
|
}
|