private Shape.Shape GetShapeForChanging() { Point[] helpPoint = new Point[allShapes[selectedShapesNumber].list[0].point.Length]; for (int i = 0; i < helpPoint.Length; i++) { helpPoint[i].X = allShapes[selectedShapesNumber].list[0].point[i].X; helpPoint[i].Y = allShapes[selectedShapesNumber].list[0].point[i].Y; } if (allShapes[selectedShapesNumber].list.Count != allShapes[selectedShapesNumber].count + 1) { shape = CreateNewShape(allShapes[selectedShapesNumber].list[0].GetType().Name, helpPoint, allShapes[selectedShapesNumber].list[0].pen); if (selectedShapesNumber != allShapes.Count - 1) { ChangeIsCurrentInVersionStract(false, selectedShapesNumber); versionOfShape newVersionOfShape = new versionOfShape(); newVersionOfShape.count = 1; newVersionOfShape.prevVersionIndex = selectedShapesNumber; newVersionOfShape.isCurrentVersion = true; newVersionOfShape.list = new List <Shape.Shape>(); allShapes.Add(newVersionOfShape); selectedShapesNumber = allShapes.Count - 1; ChangeCountInVersionStract(allShapes[selectedShapesNumber].count - 1, selectedShapesNumber); } allShapes[selectedShapesNumber].list.Insert(0, shape); } return(shape); }
private IResizable GetObject(String libraryName) { IResizable shape = null; String AboutLibName = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), libraryName); if (File.Exists(AboutLibName)) { ///Загружаем сборку Assembly AboutAssembly = Assembly.LoadFrom(AboutLibName); ///в цикле проходим по всем public-типам сборки foreach (Type t in AboutAssembly.GetExportedTypes()) { ///если это класс,который реализует интерфейс IAboutInt, ///то это то,что нам нужно Smile if (t.IsClass && typeof(IResizable).IsAssignableFrom(t)) { ///создаем объект полученного класса shape = (IResizable)Activator.CreateInstance(t); ///вызываем его метод GetAboutText break; } } } return(shape); }
private void DrawShape(string shapeName, Point[] pointLocal, Color color, float brushWidth) { shape = ChangeShapeProperties(shapeName, pointLocal, color, brushWidth); if (shape != null && pointLocal.Length > 1) { shape.Draw(bitmapSecondary, pointLocal, false); } }
public override void MoveVertical(Shape.Shape shape, int offset) { shape.center.Y = 0; for (int i = 0; i < shape.point.Length; i++) { shape.point[i].Y -= offset; // centre.X += point[i].X / point.Length; shape.center.Y += shape.point[i].Y / shape.point.Length; } }
private void numericUpDown1_ValueChanged(object sender, EventArgs e) { pen.Width = (int)numericUpDown.Value; if (selectedShapesNumber > -1 && allShapes[selectedShapesNumber].list[0].GetType().GetInterface("IResizable") != null) { shape = GetShapeForChanging(); shape.ChangePenWidth((float)numericUpDown.Value); Redraw(); Selection(); } }
public override void MoveHorizontal(Shape.Shape shape, int offset) { shape.center.X = 0; for (int i = 0; i < shape.point.Length; i++) { shape.point[i].X -= offset; shape.center.X += shape.point[i].X / shape.point.Length; // centre.Y += point[i].Y / point.Length; } // return shape; }
public static void AddNewShapeToList(Shape.Shape shape) { versionOfShape subListAllShapes; subListAllShapes.list = new List <Shape.Shape>(); subListAllShapes.count = 1; subListAllShapes.list.Add(shape); subListAllShapes.prevVersionIndex = -1; subListAllShapes.isCurrentVersion = true; allShapes.Add(subListAllShapes); }
static void Main(string[] args) { Shape[] Array = new Shape[100]; Array[0] = new Triangle(1, 1, Math.Sqrt(2)); Array[1] = new Rectangle(5, 6.5); Array[2] = new Circle(8); for (int i = 0; Array[i] != null; i++) Console.WriteLine(Array[i].calcArea()); Console.ReadLine(); }
static void Main() { Shape[] container = new Shape[3]; container[0] = new Triangle(2, 5); container[1] = new Rectangle(15, 2); container[2] = new Circle(15, 2); foreach (var shape in container) { shape.CalculateSurface(); } }
static void Main() { Shape[] shapes = new Shape[]{ new Circle(10), new Triangle(5,10), new Rectangle(5,10) }; foreach (var shape in shapes) { Console.WriteLine(shape.CalculateSurface()); } }
static void Main(string[] args) { Shape[] arr = new Shape[100]; Round shape1 = new Round(10); Triangle shape2 = new Triangle(8, 6, 4); Rectangle shape3 = new Rectangle(3, 5); arr[0] = shape1; arr[1] = shape2; arr[2] = shape3; for (int i = 0; arr[i] != null; i++) Console.WriteLine(arr[i].Area()); Console.ReadLine(); }
public static Shape.Shape CreateNewShape(string shapeName, Point[] pointLocal, Pen pen) { shape = null; IResizable myObject; myObject = GetObjectFromLibrary(shapeName); if (myObject != null) { shape = myObject.Initialization(pointLocal, pen); } return(shape); }
public static Shape GetRotatedSize(Shape shape, double angleOfTheShapeThatWillBeRotated) { double cosinusTimesWidth = Math.Abs(Math.Cos(angleOfTheShapeThatWillBeRotated)) * shape.Width; double sinusTimesWidth = Math.Abs(Math.Sin(angleOfTheShapeThatWillBeRotated)) * shape.Width; double sinusTimesHeight = Math.Abs(Math.Sin(angleOfTheShapeThatWillBeRotated)) * shape.Height; double cosinusTimesHeight = Math.Abs(Math.Cos(angleOfTheShapeThatWillBeRotated)) * shape.Height; double rotatedWidth = cosinusTimesWidth * sinusTimesHeight; double rotatedHeight = sinusTimesWidth * cosinusTimesHeight; Shape rotatedShape = new Shape(rotatedWidth, rotatedHeight); return rotatedShape; }
private void btnColor_Click(object sender, EventArgs e) { if (colorDialog.ShowDialog() == DialogResult.OK) { pen.Color = colorDialog.Color; if (selectedShapesNumber > -1 && allShapes[selectedShapesNumber].list[0].GetType().GetInterface("IResizable") != null) { shape = GetShapeForChanging(); shape.ChangeColor(colorDialog.Color); Redraw(); Selection(); } } }
public override void ResizableHorizontal(Shape.Shape shape, int newX) { if (newX > Math.Max(shape.point[0].X, Math.Max(shape.point[1].X, shape.point[2].X)) - 15) { shape.point[getIndexMaxPoint(shape.point[0].X, shape.point[1].X, shape.point[2].X)].X = newX; } else { shape.point[getIndexMinPoint(shape.point[0].X, shape.point[1].X, shape.point[2].X)].X = newX; } shape.center.X = 0; for (int i = 0; i < 3; i++) { shape.center.X += shape.point[i].X / shape.point.Length; } }
public override void ResizableVertical(Shape.Shape shape, int newY) { if (newY > Math.Max(shape.point[0].Y, Math.Max(shape.point[1].Y, shape.point[2].Y)) - 15) { shape.point[getIndexMaxPoint(shape.point[0].Y, shape.point[1].Y, shape.point[2].Y)].Y = newY; } else { shape.point[getIndexMinPoint(shape.point[0].Y, shape.point[1].Y, shape.point[2].Y)].Y = newY; } shape.center.Y = 0; for (int i = 0; i < 3; i++) { shape.center.Y += shape.point[i].Y / shape.point.Length; } }
private void btnOpen_Click(object sender, EventArgs e) { MyTxtFileStream txtFileStream = MyTxtFileStream.getInstance(); if (txtFileStream.Open()) { Redraw(); } else { List <versionOfShape> allShapes = new List <versionOfShape>(); point = new Point[0]; pen = new Pen(Color.Black); shape = null; } }
static void Main(string[] args) { Shape[] ArrayObject = new Shape[3]; Shape triangle = new Triangle(12, 12, 12); Shape circle = new Circle(12); Shape rectangle = new Rectangle(12, 12); ArrayObject[0] = triangle; ArrayObject[1] = circle; ArrayObject[2] = rectangle; for (int count = 0; count <= 2; count++) { Console.WriteLine(ArrayObject[count].Area()); } Console.ReadLine(); }
private void drawField_MouseClick(object sender, MouseEventArgs e) { currentMouseDown.X = e.X; currentMouseDown.Y = e.Y; Array.Resize(ref point, point.Length + 1); point[point.Length - 1].X = e.X; point[point.Length - 1].Y = e.Y; bitmapMain = bitmapSecondary; if (shapeComboBox.Text != "Mouse") { shape = CreateNewShape(shapeComboBox.Text, point, pen); if (shape != null && ((shape.GetType().Name == "MyTriangle" && point.Length == 3) || (shape.GetType().Name != "MyTriangle" && point.Length == 2))) { AddNewShapeToList(shape); } } else { { FindShapeByClick(e.X, e.Y); if (selectedShapesNumber != -1) { Selection(); } Redraw(); } Array.Resize(ref point, 0); } if (shape != null && shapeComboBox.Text != "Mouse" && point.Length > 1) { shape.Draw(bitmapMain, point, true); if (shapeComboBox.Text == "MyTriangle" && point.Length != 2 || shapeComboBox.Text != "MyTriangle") { Array.Resize(ref point, 0); } } }
public override void ResizableHorizontal(Shape.Shape shape, int newX) { base.ResizableHorizontal(shape, newX); }
public override void ResizableVertical(Shape.Shape shape, int newY) { base.ResizableVertical(shape, newY); }
/* public override void MoveHorizontal(ref Point[] point, int offset, ref Point centre) * { * * base.MoveHorizontal(ref point, offset, ref centre); * }*/ public override void MoveHorizontal(Shape.Shape shape, int offset) { base.MoveHorizontal(shape, offset); // return shape; }
public override void MoveVertical(Shape.Shape shape, int offset) { base.MoveVertical(shape, offset); }
private void drawField_MouseMove(object sender, MouseEventArgs e) { if (e.Button != MouseButtons.Left) { if (selectedShapesNumber > -1) { if ((e.X < selectRectangle[0].X + 10 && e.X > selectRectangle[0].X - 10 && e.Y <selectRectangle[1].Y && e.Y> selectRectangle[0].Y) || (e.X <selectRectangle[1].X + 10 && e.X> selectRectangle[1].X - 10 && e.Y <selectRectangle[1].Y && e.Y> selectRectangle[0].Y)) { this.Cursor = Cursors.SizeWE; } else { if ((e.Y < selectRectangle[0].Y + 10 && e.Y > selectRectangle[0].Y - 10 && e.X <selectRectangle[1].X && e.X> selectRectangle[0].X) || (e.Y <selectRectangle[1].Y + 10 && e.Y> selectRectangle[1].Y - 10 && e.X <selectRectangle[1].X && e.X> selectRectangle[0].X)) { this.Cursor = Cursors.SizeNS; } else { this.Cursor = Cursors.Arrow; } } } else { this.Cursor = Cursors.Arrow; } } if (shapeComboBox.Text != "Mouse") { if (point.Length > 0 && shape != null) { Array.Resize(ref point, point.Length + 1); point[point.Length - 1].X = e.X; point[point.Length - 1].Y = e.Y; bitmapSecondary = new Bitmap(bitmapMain); DrawShape(shapeComboBox.Text, point, pen.Color, pen.Width); drawField.Image = bitmapSecondary; if (point.Length > 1) { Array.Resize(ref point, point.Length - 1); } } } else { if (e.Button == MouseButtons.Left && selectedShapesNumber > -1) { if (allShapes[selectedShapesNumber].list[0].GetType().GetInterface("IResizable") != null) { shape = GetShapeForChanging(); if (this.Cursor == Cursors.Arrow) { if (e.X < selectRectangle[1].X && e.X > selectRectangle[0].X && e.Y <selectRectangle[1].Y && e.Y> selectRectangle[0].Y) { shape.MoveHorizontal(shape, currentMouseDown.X - e.X); currentMouseDown.X = e.X; shape.MoveVertical(shape, currentMouseDown.Y - e.Y); currentMouseDown.Y = e.Y; Redraw(); isChanged = true; } } else { if (this.Cursor == Cursors.SizeWE) { shape.ResizableHorizontal(shape, e.X); } if (this.Cursor == Cursors.SizeNS) { shape.ResizableVertical(shape, e.Y); } Redraw(); isChanged = true; // Selection(); } // Selection(); } } } Selection(); }
private int FindDistance(Shape.Shape shape, int x, int y) { int tempDistance = (int)(Math.Pow(Math.Pow(Math.Abs(shape.center.X - x), 2) + Math.Pow(Math.Abs(shape.center.Y - y), 2), 0.5)); return(tempDistance); }