Browse Source

Implemented basic deletion feature, bugs remain

Martin Edlund 5 years ago
parent
commit
b2e8e5d11d

+ 20 - 7
SketchAssistant/SketchAssistant/Form1.Designer.cs

@@ -40,10 +40,11 @@ namespace SketchAssistant
             this.toolStrip1 = new System.Windows.Forms.ToolStrip();
             this.canvasButton = new System.Windows.Forms.ToolStripButton();
             this.drawButton = new System.Windows.Forms.ToolStripButton();
+            this.deleteButton = new System.Windows.Forms.ToolStripButton();
             this.statusStrip1 = new System.Windows.Forms.StatusStrip();
             this.toolStripLoadStatus = new System.Windows.Forms.ToolStripStatusLabel();
             this.backgroundWorker2 = new System.ComponentModel.BackgroundWorker();
-            this.drawTimer = new System.Windows.Forms.Timer(this.components);
+            this.mouseTimer = new System.Windows.Forms.Timer(this.components);
             this.tableLayoutPanel1.SuspendLayout();
             ((System.ComponentModel.ISupportInitialize)(this.pictureBoxRight)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.pictureBoxLeft)).BeginInit();
@@ -119,7 +120,7 @@ namespace SketchAssistant
             // loadToolStripMenuItem
             // 
             this.loadToolStripMenuItem.Name = "loadToolStripMenuItem";
-            this.loadToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
+            this.loadToolStripMenuItem.Size = new System.Drawing.Size(109, 22);
             this.loadToolStripMenuItem.Text = "Load...";
             this.loadToolStripMenuItem.Click += new System.EventHandler(this.loadToolStripMenuItem_Click);
             // 
@@ -127,7 +128,8 @@ namespace SketchAssistant
             // 
             this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
             this.canvasButton,
-            this.drawButton});
+            this.drawButton,
+            this.deleteButton});
             this.toolStrip1.Location = new System.Drawing.Point(0, 24);
             this.toolStrip1.Name = "toolStrip1";
             this.toolStrip1.Size = new System.Drawing.Size(696, 25);
@@ -154,6 +156,16 @@ namespace SketchAssistant
             this.drawButton.Text = "Draw";
             this.drawButton.Click += new System.EventHandler(this.drawButton_Click);
             // 
+            // deleteButton
+            // 
+            this.deleteButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
+            this.deleteButton.Image = ((System.Drawing.Image)(resources.GetObject("deleteButton.Image")));
+            this.deleteButton.ImageTransparentColor = System.Drawing.Color.Magenta;
+            this.deleteButton.Name = "deleteButton";
+            this.deleteButton.Size = new System.Drawing.Size(44, 22);
+            this.deleteButton.Text = "Delete";
+            this.deleteButton.Click += new System.EventHandler(this.deleteButton_Click);
+            // 
             // statusStrip1
             // 
             this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
@@ -170,10 +182,10 @@ namespace SketchAssistant
             this.toolStripLoadStatus.Size = new System.Drawing.Size(40, 17);
             this.toolStripLoadStatus.Text = "no file";
             // 
-            // drawTimer
+            // mouseTimer
             // 
-            this.drawTimer.Interval = 2;
-            this.drawTimer.Tick += new System.EventHandler(this.drawTimer_Tick);
+            this.mouseTimer.Interval = 2;
+            this.mouseTimer.Tick += new System.EventHandler(this.mouseTimer_Tick);
             // 
             // Form1
             // 
@@ -219,9 +231,10 @@ namespace SketchAssistant
         private System.ComponentModel.BackgroundWorker backgroundWorker2;
         private System.Windows.Forms.PictureBox pictureBoxRight;
         private System.Windows.Forms.PictureBox pictureBoxLeft;
-        private System.Windows.Forms.Timer drawTimer;
+        private System.Windows.Forms.Timer mouseTimer;
         private System.Windows.Forms.ToolStripButton canvasButton;
         private System.Windows.Forms.ToolStripButton drawButton;
+        private System.Windows.Forms.ToolStripButton deleteButton;
     }
 }
 

+ 78 - 7
SketchAssistant/SketchAssistant/Form1.cs

@@ -29,7 +29,8 @@ namespace SketchAssistant
         public enum ProgramState
         {
             Idle,
-            Draw
+            Draw,
+            Delete
         }
         //Current Program State
         private ProgramState currentState;
@@ -49,6 +50,11 @@ namespace SketchAssistant
         Point currentCursorPosition;
         //The graphic representation of the right image
         Graphics graph = null;
+        //Deletion Matrixes for checking postions of lines in the image
+        bool[,] isFilledMatrix;
+        List<int>[,] linesMatrix;
+        //Size of deletion area
+        int deletionSize = 10;
 
         /******************************************/
         /*** FORM SPECIFIC FUNCTIONS START HERE ***/
@@ -80,7 +86,7 @@ namespace SketchAssistant
             }
         }
 
-        //Changes The State of the Program to drawing
+        //Changes the state of the program to drawing
         private void drawButton_Click(object sender, EventArgs e)
         {
             if(rightImage != null)
@@ -96,6 +102,22 @@ namespace SketchAssistant
             }
         }
 
+        //Changes the state of the program to deletion
+        private void deleteButton_Click(object sender, EventArgs e)
+        {
+            if (rightImage != null)
+            {
+                if (currentState.Equals(ProgramState.Delete))
+                {
+                    ChangeState(ProgramState.Idle);
+                }
+                else
+                {
+                    ChangeState(ProgramState.Delete);
+                }
+            }
+        }
+
         //get current Mouse positon within the right picture box
         private void pictureBoxRight_MouseMove(object sender, MouseEventArgs e)
         {
@@ -112,13 +134,15 @@ namespace SketchAssistant
             }
         }
 
-        //Lift left mouse button to stop drawing.
+        //Lift left mouse button to stop drawing and add a new Line.
         private void pictureBoxRight_MouseUp(object sender, MouseEventArgs e)
         {
             mousePressed = false;
             if (currentState.Equals(ProgramState.Draw))
             {
-                lineList.Add(new Tuple<bool, Line>(true, new Line(currentLine)));
+                Line newLine = new Line(currentLine, lineList.Count);
+                lineList.Add(new Tuple<bool, Line>(true, newLine));
+                newLine.PopulateMatrixes(isFilledMatrix, linesMatrix);
             }
         }
 
@@ -131,7 +155,7 @@ namespace SketchAssistant
         }
 
         //add a Point on every tick to the Drawpath
-        private void drawTimer_Tick(object sender, EventArgs e)
+        private void mouseTimer_Tick(object sender, EventArgs e)
         {
             if (currentState.Equals(ProgramState.Draw) && mousePressed)
             {
@@ -140,6 +164,23 @@ namespace SketchAssistant
                 drawline.DrawLine(graph);
                 pictureBoxRight.Image = rightImage;
             }
+            if (currentState.Equals(ProgramState.Delete) && mousePressed)
+            {
+                if (currentCursorPosition.X < rightImage.Width - 1 && currentCursorPosition.Y < rightImage.Height- 1
+                    && currentCursorPosition.X >= 0 && currentCursorPosition.Y >= 0)
+                {
+
+                    if (isFilledMatrix[currentCursorPosition.X, currentCursorPosition.Y])
+                    {
+                        foreach (int lineid in linesMatrix[currentCursorPosition.X, currentCursorPosition.Y])
+                        {
+                            lineList[lineid] = new Tuple<bool, Line>(false, lineList[lineid].Item2);
+                        }
+                        RepopulateDeletionMatrixes();
+                        RedrawRightImage();
+                    }
+                }
+            }
         }
 
         /***********************************/
@@ -165,6 +206,8 @@ namespace SketchAssistant
                 graph.FillRectangle(Brushes.White, 0, 0, leftImage.Width + 10, leftImage.Height + 10);
                 pictureBoxRight.Image = rightImage;
             }
+            isFilledMatrix = new bool[rightImage.Width, rightImage.Height];
+            linesMatrix = new List<int>[rightImage.Width, rightImage.Height];
             this.Refresh();
             pictureBoxRight.Refresh();
         }
@@ -182,6 +225,7 @@ namespace SketchAssistant
                     lineBoolTuple.Item2.DrawLine(graph);
                 }
             }
+            pictureBoxRight.Refresh();
         }
 
         /// <summary>
@@ -195,7 +239,11 @@ namespace SketchAssistant
             {
                 case ProgramState.Draw:
                     drawButton.CheckState = CheckState.Unchecked;
-                    drawTimer.Enabled = false;
+                    mouseTimer.Enabled = false;
+                    break;
+                case ProgramState.Delete:
+                    deleteButton.CheckState = CheckState.Unchecked;
+                    mouseTimer.Enabled = false;
                     break;
                 default:
                     break;
@@ -204,7 +252,11 @@ namespace SketchAssistant
             {
                 case ProgramState.Draw:
                     drawButton.CheckState = CheckState.Checked;
-                    drawTimer.Enabled = true;
+                    mouseTimer.Enabled = true;
+                    break;
+                case ProgramState.Delete:
+                    deleteButton.CheckState = CheckState.Checked;
+                    mouseTimer.Enabled = true;
                     break;
                 default:
                     break;
@@ -254,5 +306,24 @@ namespace SketchAssistant
             }
             return realCoordinates;
         }
+
+        /// <summary>
+        /// A function that populates the matrixes needed for deletion detection with line data.
+        /// </summary>
+        private void RepopulateDeletionMatrixes()
+        {
+            if(rightImage != null)
+            {
+                isFilledMatrix = new bool[rightImage.Width,rightImage.Height];
+                linesMatrix = new List<int>[rightImage.Width, rightImage.Height];
+                foreach(Tuple<bool,Line> lineTuple in lineList)
+                {
+                    if (lineTuple.Item1)
+                    {
+                        lineTuple.Item2.PopulateMatrixes(isFilledMatrix, linesMatrix);
+                    }
+                }
+            }
+        }
     }
 }

+ 16 - 1
SketchAssistant/SketchAssistant/Form1.resx

@@ -155,6 +155,21 @@
         mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+
         kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D
         TgDQASA1MVpwzwAAAABJRU5ErkJggg==
+</value>
+  </data>
+  <data name="deleteButton.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+    <value>
+        iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
+        YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG
+        YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9
+        0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw
+        bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc
+        VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9
+        c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32
+        Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo
+        mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+
+        kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D
+        TgDQASA1MVpwzwAAAABJRU5ErkJggg==
 </value>
   </data>
   <metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
@@ -163,7 +178,7 @@
   <metadata name="backgroundWorker2.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
     <value>622, 17</value>
   </metadata>
-  <metadata name="drawTimer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+  <metadata name="mouseTimer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
     <value>786, 17</value>
   </metadata>
   <metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">

+ 60 - 1
SketchAssistant/SketchAssistant/Line.cs

@@ -10,12 +10,20 @@ namespace SketchAssistant
     class Line
     {
         private List<Point> linePoints;
+        private int identifier;
 
         public Line(List<Point> points)
         {
             linePoints = new List<Point>(points);
         }
 
+        public Line(List<Point> points, int id)
+        {
+            linePoints = new List<Point>(points);
+            identifier = id;
+            CleanPoints();
+        }
+
         public Point GetStartPoint()
         {
             return linePoints.First();
@@ -39,8 +47,59 @@ namespace SketchAssistant
             {
                 canvas.DrawLine(thePen, linePoints[i], linePoints[i + 1]);
             }
-            //canvas.DrawLine(thePen, linePoints[linePoints.Count-1], linePoints[linePoints.Count]);
             return canvas;
         }
+
+        /// <summary>
+        /// A function that will take to matrixes and populate the with the line data of this line object
+        /// Exceptions:
+        ///     Will throw IndexOutOfRangeException if any of the points of this line are 
+        ///     outside of the given matrixes.
+        /// </summary>
+        /// <param name="boolMatrix">The Matrix of booleans, in which is saved wether there is a line at this position.</param>
+        /// <param name="listMatrix">The Matrix of Lists of integers, in which is saved which lines are at this position</param>
+        public void PopulateMatrixes(bool[,] boolMatrix, List<int>[,] listMatrix)
+        {
+            foreach(Point currPoint in linePoints)
+            {
+                try
+                {
+                    boolMatrix[currPoint.X, currPoint.Y] = true;
+                    if (listMatrix[currPoint.X, currPoint.Y] == null)
+                    {
+                        listMatrix[currPoint.X, currPoint.Y] = new List<int>();
+                    }
+                    listMatrix[currPoint.X, currPoint.Y].Add(identifier);
+                }
+                catch(IndexOutOfRangeException e)
+                {
+
+                }
+            }
+        }
+
+        /// <summary>
+        /// Removes duplicate points from the line object
+        /// </summary>
+        private void CleanPoints()
+        {
+            List<Point> newList = new List<Point>();
+            Point nullPoint = new Point(-1, -1);
+            for (int i = 1; i < linePoints.Count; i++)
+            {
+                if ((linePoints[i].X == linePoints[i - 1].X) && (linePoints[i].Y == linePoints[i - 1].Y))
+                {
+                    linePoints[i - 1] = nullPoint;
+                }
+            }
+            foreach(Point linepoint in linePoints)
+            {
+                if (!(linepoint.X == -1))
+                {
+                    newList.Add(linepoint);
+                }
+            }
+            linePoints = newList;
+        }
     }
 }

+ 13 - 0
userstory6.md

@@ -0,0 +1,13 @@
+# Userstory 6
+
+|**ID**|6|
+|-|-|
+|**Name**|Löschfunktionalität|
+|**Beschreibung**|Man kann einen Knopf in der UI drücken um in den Löschmodus zu kommen, und um wieder aus dem Löschmodus rauszukommen. Wenn man im Löschmodus ist, kann man auf einer Leinwand im rechten Bereich gezeichnete Elemente löschen indem man auf sie klickt.|
+|**Akzeptanzkriterium**|Der Knopf für den Löschmodus kann nur gedrückt werden, wenn im rechten Bereich eine Zeichennleinwand vorhanden ist. Wenn man den Knopf drückt ohne im Löschmodus zu sein, verändert sich der Knopf erkennbar und man kommt in den Löschmodus. Drückt man den Knopf, während man im Löschmodus ist, wird der Löschmodus beendet und der Knopf bekommt wieder sein urspüngliches Aussehen. Während man im Löschmodus ist, kann man auf der Leinwand im rechten Bereich Elemente löschen, wenn der Mauszeiger sie berührt während man die Maustaste gedrückt hält. Die Elemente die man löscht verschwinden. Drückt man den Löschknopf während man in einem anderen Modus ist (z.B. Zeichenmodus) wird der andere Modus beendet und man ist im Löschmodus.|
+|Geschätzter Aufwand (Story Points)|16|
+|Entwickler|Martin|
+|Umgesetzt in Iteration|keine|
+|Tatsächlicher Aufwand (Std.)|keine|
+|Velocity (Std./Story Point)|keine|
+|Bemerkungen|Keine|