private void setToGrid(Element el) { if (el is Convoyeur) { Convoyeur l = (Convoyeur)el; l.yGrid2 = (l.Y2) * _grille.nbCellule / (_grille.nbCellule * _grille.tailleCellule); l.xGrid2 = (l.X2) * _grille.nbCellule / (_grille.nbCellule * _grille.tailleCellule); } el.yGrid = (el.Y1) * _grille.nbCellule / (_grille.nbCellule * _grille.tailleCellule); el.xGrid = (el.X1) * _grille.nbCellule / (_grille.nbCellule * _grille.tailleCellule); }
public bool add(Element el) { if (el is Convoyeur) { Convoyeur l = (Convoyeur)el; bool flag1 = false; bool flag2 = false; Element prov1 = null; Element prov2 = null; foreach (Element li in LesElements) { if (li is Convoyeur && el.xGrid == li.xGrid && el.yGrid == li.yGrid) { return(false); } } foreach (Element element in LesElements) { if (el.xGrid == element.xGrid && el.yGrid == element.yGrid) { flag1 = true; prov1 = element; } if (l.xGrid2 == element.xGrid && l.yGrid2 == element.yGrid) { flag2 = true; prov2 = element; } } if (!flag1 || !flag2) { return(false); } else { prov1.Sorties.Add(el); el.Sorties.Add(prov2); } } else if (el is Machine) { foreach (Element element in LesElements) { if (el.xGrid == element.xGrid && el.yGrid == element.yGrid) { return(false); } } } _LesElements.Add(el); return(true); }
/// <summary> /// Dessin de la fenetre /// </summary> private void pictureBox1_Paint(object sender, PaintEventArgs e) { paintGrid(e); foreach (Element el in _grille.LesElements) { Pen LinePen = null; //SolidBrush Brush = null; TextureBrush brush = null; /*if (el.isSelected) * { * LinePen = new Pen(Color.Blue, 3); * Brush = new SolidBrush(Color.Blue); * } * else * {*/ Bitmap bmp = new Bitmap(el.ImgPath); Bitmap result = ResizeBitmap(bmp, _grille.tailleCellule, _grille.tailleCellule); brush = new TextureBrush(result); //} if (el is Convoyeur) { LinePen = new Pen(Color.Red, 3); Convoyeur l = (Convoyeur)el; e.Graphics.DrawLine(LinePen, el.xGrid * _grille.tailleCellule + _grille.tailleCellule / 2, el.yGrid * _grille.tailleCellule + _grille.tailleCellule / 2, l.xGrid2 * _grille.tailleCellule + _grille.tailleCellule / 2, l.yGrid2 * _grille.tailleCellule + _grille.tailleCellule / 2); } else { e.Graphics.FillRectangle(brush, (el.xGrid * _grille.tailleCellule + _grille.tailleCellule / 2) - (_grille.tailleCellule - 4) / 2, (el.yGrid * _grille.tailleCellule + _grille.tailleCellule / 2) - (_grille.tailleCellule - 4) / 2, _grille.tailleCellule - 2, _grille.tailleCellule - 2); } } if (IsMouseDown) { switch (CaseDraw) { case "Convoyeur": { e.Graphics.DrawLine(new Pen(Color.Blue, 1), _StartX, _StartY, _CurX, _CurY); break; } default: { break; } } } else { UpdateList(_grille.LesElements, listBox1.SelectedIndex); } }
private void pictureBox1_MouseUp(object sender, MouseEventArgs e) { IsMouseDown = false; if (e.Button == MouseButtons.Left) { switch (CaseDraw) { case "Convoyeur": { Convoyeur C = new Convoyeur(_StartX, _StartY, _CurX, _CurY); setToGrid(C); _grille.add(C); break; } default: { break; } } } pictureBox1.Invalidate(); }