Skip to content

Commit baa071f

Browse files
committed
v1.1
1 parent c0c0d3e commit baa071f

File tree

3 files changed

+74
-29
lines changed

3 files changed

+74
-29
lines changed

Google Translate Canvas/Canvas.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,43 @@ public void clearCanvas()
7777
{
7878
canvasGraphics.Clear(Color.FromArgb(222, 222, 222));
7979
}
80+
81+
public void undoLastLine()
82+
{
83+
try
84+
{
85+
Form1.lines.RemoveAt(Form1.lines.Count - 1);
86+
}
87+
catch { return; }
88+
89+
canvasGraphics.Clear(Color.FromArgb(222, 222, 222));
90+
91+
foreach (Form1.line stroke in Form1.lines)
92+
{
93+
drawLine(stroke.xCoords, stroke.yCoords);
94+
}
95+
if (Form1.lines.Count != 0)
96+
{
97+
Program.form1.googleRequest();
98+
}
99+
}
100+
101+
public void drawLine(List<int> Xs, List<int> Ys)
102+
{
103+
int currentX, currentY;
104+
for (int i = 0; i < Xs.Count - 1; i += 1)
105+
{
106+
previousX = Xs[i]; previousY = Ys[i];
107+
currentX = Xs[i + 1]; currentY = Ys[i + 1];
108+
109+
if (currentX > previousX) { previousX += -1; }
110+
else if (currentX < previousX) { previousX += 1; }
111+
if (currentY > previousY) { previousY += -1; }
112+
else if (currentY < previousY) { previousY += 1; }
113+
114+
canvasGraphics.DrawLine(canvasPen, previousX, previousY, currentX, currentY);
115+
}
116+
}
80117
private void Canvas_Resize(object sender, EventArgs e)
81118
{
82119
canvasGraphics = CreateGraphics();

Google Translate Canvas/Form1.Designer.cs

Lines changed: 31 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Google Translate Canvas/Form1.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class line
2323
public List<int> xCoords = new List<int>();
2424
public List<int> yCoords = new List<int>();
2525
}
26-
public List<line> lines = new List<line>();
26+
public static List<line> lines = new List<line>();
2727

2828
public void addLine()
2929
{
@@ -46,7 +46,6 @@ public void addYCoordinate(int Y)
4646

4747
private void btnClear_Click(object sender, EventArgs e)
4848
{
49-
lines.Clear();
5049
canvas1.clearCanvas();
5150
}
5251

@@ -87,8 +86,6 @@ public void googleRequest()
8786

8887
var content = response.Content.ReadAsStringAsync();
8988

90-
flpSuggestions.Invoke(new MethodInvoker(delegate { lblOutput.Text = content.Result; }));
91-
9289
string[] suggestions = getSuggestionsList(content.Result);
9390
if (suggestions == null) { flpSuggestions.Invoke(new MethodInvoker(delegate { tbxInput.Text += " "; return; })); }
9491

@@ -182,5 +179,10 @@ string createCoordinateString()
182179
}
183180

184181
}
182+
183+
private void button1_Click(object sender, EventArgs e)
184+
{
185+
canvas1.undoLastLine();
186+
}
185187
}
186188
}

0 commit comments

Comments
 (0)