private void draw_Click(object sender, EventArgs e) { if (IsInt(tb_x1.Text, tb_y1.Text, tb_x2.Text, tb_y2.Text) && (cb_figures.SelectedIndex > -1) && ((Convert.ToInt32(tb_x1.Text, 10) < picture.Width) && (Convert.ToInt32(tb_y1.Text, 10) < picture.Height) && (Convert.ToInt32(tb_x2.Text, 10) < picture.Width) && (Convert.ToInt32(tb_y2.Text, 10) < picture.Height))) { Point topLeft = new Point(Convert.ToInt32(tb_x1.Text, 10), Convert.ToInt32(tb_y1.Text)); Point bottomRight = new Point(Convert.ToInt32(tb_x2.Text, 10), Convert.ToInt32(tb_y2.Text)); figure = maker.FactoryMethod(fatness, color, topLeft, bottomRight); figureList.Add(figure); //figuresExs.Add(figure); figure.Draw(graphics); jsonList.Add(new InfoForJSON() { fatness = fatness, color = color, topLeft = topLeft, bottomRight = bottomRight, figureName = maker.ToString() }); currentFabrics.Add(maker); picture.Image = bmap; } else { //tb_x1.Text = tb_x2.Text = tb_y1.Text = tb_y2.Text = ""; MessageBox.Show(message, title_mess, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static List <MainFigure> DrawCustomFigure(int index, Graphics g, Point possition) { MainFigure biggestFigure = GetBiggestFigure(savedFigures[index]); Point oldCenter = GetCenterOfFigure(biggestFigure); List <MainFigure> temps = new List <MainFigure>(); int offsetX = 0; int offsetY = 0; MainFigure tempFigure; foreach (var figure in savedFigures[index]) { Point centerFigure = GetCenterOfFigure(figure); offsetX = GetOffsetX(oldCenter, centerFigure); offsetY = GetOffsetY(oldCenter, centerFigure); Point newCenter = GetNewCenter(possition, offsetX, offsetY); tempFigure = GetFigure(newCenter, figure); tempFigure.Draw(g); temps.Add(tempFigure); } return(temps); }
public MainFigure PickFigure(List <MainFigure> figures, Point location) { foreach (var figure in figures) { if ((figure.topLeft.X <= location.X && figure.bottomRight.X >= location.X) && (figure.topLeft.Y <= location.Y && figure.bottomRight.Y >= location.Y)) { if (croch != null && (croch.topLeft.X < figure.topLeft.X)) { croch = (MainFigure)Activator.CreateInstance(figure.GetType(), 4, Color.CornflowerBlue, new Point(figure.topLeft.X - 4, figure.topLeft.Y - 4), new Point(figure.bottomRight.X + 4, figure.bottomRight.Y + 4)); } } } return(null); }
private static MainFigure GetFigure(Point center, MainFigure figure) { int newTopLeftX, newTopLeftY; int newBottomRightX, newBottomRightY; newTopLeftX = center.X - ((figure.bottomRight.X - figure.topLeft.X) / 2); newTopLeftY = center.Y - ((figure.bottomRight.Y - figure.topLeft.Y) / 2); newBottomRightX = center.X + ((figure.bottomRight.X - figure.topLeft.X) / 2); newBottomRightY = center.Y + ((figure.bottomRight.Y - figure.topLeft.Y) / 2); return (MainFigure)Activator.CreateInstance(figure.GetType(), 3, Color.Aqua, new Point(newTopLeftX, newTopLeftY), new Point(newBottomRightX, newBottomRightY)); }
private void openToolStripMenuItem_Click_1(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.InitialDirectory = "/files"; openFileDialog.RestoreDirectory = true; openFileDialog.FileName = "figures"; openFileDialog.DefaultExt = ".json"; if (openFileDialog.ShowDialog() == DialogResult.OK) { StreamReader stream = new StreamReader(openFileDialog.OpenFile()); string data = stream.ReadToEnd(); { string[] dataArray = data.Split('\n'); foreach (string dataBlock in dataArray) { try { InfoForJSON jSON = JsonConvert.DeserializeObject <InfoForJSON>(dataBlock); foreach (Fabric fab in allFabrics) { if (jSON.figureName == fab.ToString()) { jsonList.Add(jSON); Fabric factory = fab; figure = factory.FactoryMethod(jSON.fatness, jSON.color, jSON.topLeft, jSON.bottomRight); figure.Draw(graphics); picture.Image = bmap; break; } } } catch (Exception ex) { MessageBox.Show(message, title_mess, MessageBoxButtons.OK, MessageBoxIcon.Warning); continue; } } } stream.Close(); } }
private void picture_MouseDown(object sender, MouseEventArgs e) { if (cmb_custom_figures.SelectedIndex >= 0) { int index = cmb_custom_figures.SelectedIndex; CustomFigure.DrawCustomFigure(index, graphics, e.Location); picture.Invalidate(); picture.Image = bmap; } else { if (cb_figures.SelectedIndex >= 0) { isDrawing = true; start = new Point(e.X, e.Y); figure = maker.FactoryMethod(fatness, color, start, start); currentFabrics.Add(maker); } } }
private static MainFigure GetBiggestFigure(List<MainFigure> figures) { MainFigure biggestFigrue = null; foreach(var figure in figures) { if(biggestFigrue == null) { biggestFigrue = figure; } else { if(((biggestFigrue.bottomRight.X - biggestFigrue.topLeft.X) + (biggestFigrue.bottomRight.Y - biggestFigrue.topLeft.Y)) < ((figure.bottomRight.X - figure.topLeft.X) + (figure.bottomRight.Y - figure.topLeft.Y))) { biggestFigrue = figure; } } } return biggestFigrue; }
private void picture_MouseDown(object sender, MouseEventArgs e) { if (isEdit) { } else { if (cmb_custom_figures.SelectedIndex >= 0) { int index = cmb_custom_figures.SelectedIndex; figuresExs = new List <MainFigure>(CustomFigure.DrawCustomFigure(index, graphics, e.Location)); int i = 0; foreach (var figure in figuresExs) { jsonList.Add(new InfoForJSON() { fatness = figure.fatness, color = figure.color, topLeft = figure.topLeft, bottomRight = figure.bottomRight, figureName = CustomFigure.fabrics[index][i].ToString() }); i++; } picture.Invalidate(); picture.Image = bmap; } else { if (cb_figures.SelectedIndex >= 0) { isDrawing = true; start = new Point(e.X, e.Y); figure = maker.FactoryMethod(fatness, color, start, start); currentFabrics.Add(maker); } } } }
private static Point GetCenterOfFigure(MainFigure figure) { return new Point(figure.topLeft.X + ((figure.bottomRight.X - figure.topLeft.X) / 2), figure.topLeft.Y + ((figure.bottomRight.Y - figure.topLeft.Y) / 2)); }
public void Crochet(MainFigure figure, Graphics g) { figure.Draw(g); }