private void EditCircle(Shape existingShape, int x, int y) { int cx = ((Circle)existingShape).CX, cy = ((Circle)existingShape).CY; if (buffer.Count == 0) { Info.Text = "Click on the circle to change the radius,\n click on the center to move the circle"; DeleteBtn.IsEnabled = true; ApplyColorBtn.IsEnabled = true; HandleVertex(cx, cy, 2); buffer.Add(cx); buffer.Add(cy); } else if (buffer.Count == 2) { DeleteBtn.IsEnabled = false; ApplyColorBtn.IsEnabled = false; //if clicked on the center -> move the circle if (x <= cx + 5 && x >= cx - 5 && y <= cy + 5 && y >= cy - 5) { Info.Text = "Click somewhere to change the position of the circle"; HandleVertex(cx, cy, 0); int r = ((Circle)existingShape).R; existingShape.EditMode = true; buffer.Add(r); } //if clicked elsewhere -> change the radius else { existingShape.Edit(new List <int> { buffer[0], buffer[1], x, y }, null, null); Redraw(); buffer.Clear(); Info.Text = ""; } } //new center else if (buffer.Count == 3) { existingShape.Edit(new List <int> { x, y, x, y + buffer[2] }, null, null); Redraw(); buffer.Clear(); Info.Text = ""; } }
private void EditLine(Shape existingShape, int x, int y) { //finish editing DeleteBtn.IsEnabled = false; ApplyColorBtn.IsEnabled = false; if (buffer.Count == 2) { existingShape.Edit(new List <int> { buffer[0], buffer[1], x, y }, null, null); Redraw(); buffer.Clear(); Info.Text = ""; } //start editing else if (buffer.Count == 0) { Info.Text = "Click somewhere to change the position of the vertex"; DeleteBtn.IsEnabled = true; ApplyColorBtn.IsEnabled = true; HandleVertex(x, y, 2); if (x <= existingShape.Points[0] + V_SIZE && x >= existingShape.Points[0] - V_SIZE) { buffer.Add(existingShape.Points[2]); buffer.Add(existingShape.Points[3]); } else { buffer.Add(existingShape.Points[0]); buffer.Add(existingShape.Points[1]); } } }
private void ThickSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e) { Shape edited = CheckEditMode(); int value = (int)((Slider)sender).Value; if (edited != null) { edited.EditMode = false; buffer.Clear(); Info.Text = ""; edited.Edit(null, value, null); Redraw(); } }
private void ApplyColorBtn_Click(object sender, RoutedEventArgs e) { Shape edited = CheckEditMode(); List <int> color = GetColor(); DeleteBtn.IsEnabled = false; ApplyColorBtn.IsEnabled = false; if (edited != null) { edited.EditMode = false; buffer.Clear(); Info.Text = ""; edited.Edit(null, null, color); Redraw(); } }
private void EditPolygon(Shape existingShape, int x, int y) { if (buffer.Count == 0) { Info.Text = "Choose one vertex to change the vertex' position,\n choose two neighboring vertices to change the edge's position,\n choose three neighboring vertices to change the position of the polygon"; DeleteBtn.IsEnabled = true; ApplyColorBtn.IsEnabled = true; HandleVertex(x, y, 2); buffer.Add(x); buffer.Add(y); } else if (buffer.Count == 2) { DeleteBtn.IsEnabled = false; ApplyColorBtn.IsEnabled = false; List <int> nb = (existingShape as Polygon).CheckNeighborClick(buffer[0], buffer[1], x, y); //move vertex if (nb.Count == 2) { (existingShape as Polygon).PrepareNewVertices(nb[0], nb[1], x, y); existingShape.Edit(existingShape.Points, null, null); Redraw(); buffer.Clear(); Info.Text = ""; } //move edge else if (nb.Count == 4) { Info.Text = "Choose the place to change the position of the edge,\n click on a neighboring vertex to move the polygon"; HandleVertex(x, y, 0); HandleVertex(buffer[0], buffer[1], 0); existingShape.EditMode = true; buffer.Add(nb[0]); buffer.Add(nb[1]); buffer.Add(nb[2]); buffer.Add(nb[3]); } } else if (buffer.Count == 6) { List <int> nb1 = (existingShape as Polygon).CheckNeighborClick(buffer[2], buffer[3], x, y); List <int> nb2 = (existingShape as Polygon).CheckNeighborClick(buffer[4], buffer[5], x, y); //move edge if (nb1.Count == 2 && nb2.Count == 2) { int dx = buffer[4] + (buffer[2] - buffer[4]) / 2; int dy = buffer[5] + (buffer[3] - buffer[5]) / 2; dx = x - dx; dy = y - dy; (existingShape as Polygon).PrepareNewVertices(buffer[2], buffer[3], buffer[2] + dx, buffer[3] + dy); (existingShape as Polygon).PrepareNewVertices(buffer[4], buffer[5], buffer[4] + dx, buffer[5] + dy); existingShape.Edit(existingShape.Points, null, null); Redraw(); buffer.Clear(); Info.Text = ""; } //move entire polygon else { Info.Text = "Click somewhere to change the position of the polygon"; HandleVertex(x, y, 0); int x1 = Math.Max(Math.Max(x, buffer[2]), buffer[4]); int x2 = Math.Min(Math.Min(x, buffer[2]), buffer[4]); int y1 = Math.Max(Math.Max(y, buffer[3]), buffer[5]); int y2 = Math.Min(Math.Min(y, buffer[3]), buffer[5]); int dx = (x1 - x2) / 2 + x2; int dy = (y1 - y2) / 2 + y2; buffer.Add(dx); buffer.Add(dy); HandleVertex(dx, dy, 2); existingShape.EditMode = true; } } else { int dx = x - buffer[6]; int dy = y - buffer[7]; for (int i = 0; i < existingShape.Points.Count - 1; i += 2) { (existingShape as Polygon).PrepareNewVertices(existingShape.Points[i], existingShape.Points[i + 1], existingShape.Points[i] + dx, existingShape.Points[i + 1] + dy); } existingShape.Edit(existingShape.Points, null, null); Redraw(); buffer.Clear(); Info.Text = ""; } }