private void CreateTrianglePrototype() { Path myPath = new Path(); string type = "Triangle"; myPath.Tag = type; NTriangle triangle = new NTriangle(myPath); prototypedFigures.Add(type, triangle); }
private static NGraphicsPath CreateTriangle(double w, double h) { NTriangle triangle = new NTriangle(); triangle.A = new NPoint(0.5 * w, 0.1 * h); triangle.B = new NPoint(0.9 * w, 0.9 * h); triangle.C = new NPoint(0.1 * w, 0.8 * h); NGraphicsPath path = new NGraphicsPath(); path.AddTriangle(triangle); return(path); }
public override void MouseMove(Point point) { if (Figure != null) { // gdy przesuwamy prostokat lub kwadrat if (Figure.GetType() == typeof(NRectangle) || Figure.GetType() == typeof(NSquare)) { if (lengthShift == 0 && widthShift == 0) //kod do utrzymywania myszki w tym samym miejscu w figurze podczas rysowania { lengthShift = point.Y - ((NRectangle)Figure).GetTopLeft().Y; widthShift = point.X - ((NRectangle)Figure).GetTopLeft().X; } point.Y -= lengthShift; point.X -= widthShift; } // gdy przesuwamy elipse lub kolo else if (Figure.GetType() == typeof(NEllipse) || Figure.GetType() == typeof(NCircle)) { dynamic f_tmp = Figure; if (lengthShift == 0 && widthShift == 0) //kod do utrzymywania myszki w tym samym miejscu w figurze podczas rysowania { Point center = f_tmp.GetCenterPoint(); lengthShift = point.Y - center.Y; //stała odległość myszki od środka figury widthShift = point.X - center.X; } point.Y -= lengthShift; point.X -= widthShift; } // gdy przesywamy trojkat else if (Figure.GetType() == typeof(NTriangle)) { NTriangle tmp_Triangle = Figure as NTriangle; if (lengthShift == 0 && widthShift == 0) //kod do utrzymywania myszki w tym samym miejscu w figurze podczas rysowania { Point positionOfTriangle = ((NTriangle)Figure).GetTopCorner(); lengthShift = point.Y - positionOfTriangle.Y; widthShift = point.X - positionOfTriangle.X; } point.Y -= lengthShift; point.X -= widthShift; } // gdy przesywamy dowolny wielokat else if (Figure.GetType() == typeof(NPolygon)) { if (lengthShift == 0 && widthShift == 0) { Point startPointOfPolygon = Figure.GetPointCollection().Last(); lengthShift = point.Y - startPointOfPolygon.Y; widthShift = point.X - startPointOfPolygon.X; } point.Y -= lengthShift; point.X -= widthShift; if (Figure.GetPointCollection().Any(e => e.Y - (Figure.GetPointCollection().Last().Y - point.Y) < 0)) { point.Y++; } } Figure.MoveBy(point); } }