private void drawingPanel_Click(object sender, EventArgs e) { MouseEventArgs mos = e as MouseEventArgs; switch (mode) { case Mode.ConstructCurve: case Mode.PathCreate: if (mos.Button == MouseButtons.Left) { construct.Add(mos.Location); (sender as Panel).Invalidate(); construct.exit = false; } else if (mos.Button == MouseButtons.Right) { if (mode == Mode.PathCreate) { if (construct.exit) { WorkingMode = Mode.Normal; Cursor = Cursors.Default; } else if (construct.CanBeDrawed() && construct.currentSet == null) // first curve { Complex last = new Complex(construct.bezier.points[construct.bezier.points.Count - 1]); construct.currentSet = new BezierSet(construct.bezier); beziers.Add(construct.currentSet); construct.bezier = new Bezier(); construct.pt = new List<Complex>(); construct.Add(new Point((int)last.Re, (int)last.Im)); } else if (construct != null && construct.currentSet != null && construct.bezier != null) { var last = construct.currentSet.set.Last(); construct.currentSet.set.Add(construct.bezier); last.ConnectRight(construct.bezier, false); // polacz z pierwszym Complex l = construct.bezier.points[construct.bezier.Degree - 1]; construct.pt = new List<Complex>(); construct.Add(new Point((int)l.Re, (int)l.Im)); } construct.exit = true; } else { if (construct != null && construct.bezier != null && construct.bezier.points.Count > 1) { beziers.Add(new BezierSet(construct.bezier)); } WorkingMode = Mode.Normal; Cursor = Cursors.Default; } (sender as Panel).Invalidate(); } break; case Mode.AddingNewCurve: if (mos.Button == MouseButtons.Left) { addnew.Add(mos.Location); (sender as Panel).Invalidate(); if (addnew.Ready()) { Cursor = Cursors.Arrow; FormAddCurve ask = new FormAddCurve(); ask.ShowDialog(this); // construct curve with enough control points Bezier b = new Bezier(addnew.pt, ask.Degree - 2); beziers.Add(new BezierSet(b)); // exit adding curve WorkingMode = Mode.Normal; drawingPanel.Invalidate(); } } break; case Mode.Merging: if (mos.Button == MouseButtons.Right) WorkingMode = Mode.Normal; else if (mos.Button == MouseButtons.Left) { var p = FindNearestPoint(mos); if (p != null) { if (normalMode.ptr.i == 0) // jesli zaznaczony byl po lewej { if (normalMode.ptr.bez.ConnectLeft(p.bez, p.i != 0)) // to dopnij z prawej strony z odpowiednim koncem { if (p.bset != normalMode.ptr.bset) { normalMode.ptr.bset.Add(p.bset); beziers.Remove(p.bset); } drawingPanel.Invalidate(); WorkingMode = Mode.Normal; } } else if (normalMode.ptr.i == normalMode.ptr.bez.Degree - 1) { if (normalMode.ptr.bez.ConnectRight(p.bez, p.i != 0)) { if (p.bset != normalMode.ptr.bset) { normalMode.ptr.bset.Add(p.bset); beziers.Remove(p.bset); } drawingPanel.Invalidate(); WorkingMode = Mode.Normal; } } } } break; } }
private void podniesStopienToolStripMenuItem_Click(object sender, EventArgs e) { if (normalMode.ptr != null) { int degree = normalMode.ptr.bez.points.Count; FormAddCurve form = new FormAddCurve(degree); form.ShowDialog(this); int diff = form.Degree - degree; if (diff > 0) normalMode.ptr.bez.DegreeElevate(diff); else if (diff < 0) normalMode.ptr.bez.DegreeReduction(-diff); else return; drawingPanel.Invalidate(); } }