//override public override void Draw(System.Drawing.Graphics e) { Update(); Pencil.Color = PenColor; for (int i = 0; i < CurrentShape.GetLength(0); i++) { for (int j = 0; j < CurrentShape.GetLength(1); j++) { if (CurrentShape[i, j] == 1) { if (ShadowY + i >= BackgroundY) { //shadow Painter.Color = ShadowColor; e.FillRectangle(Painter, GetRect(X + j, ShadowY + i)); e.DrawRectangle(Pencil, GetRect(X + j, ShadowY + i)); } if (Y + i >= BackgroundY) { //shape Painter.Color = CurrentColor; e.FillRectangle(Painter, GetRect(X + j, Y + i)); e.DrawRectangle(Pencil, GetRect(X + j, Y + i)); } } } } }
private void BtnCurve_Click(object sender, EventArgs e) { shapes.ForEach(shape => shape.IsSelected = false); psfMain.Invalidate(); for (int i = 0; i < clbShape.Items.Count; i++) { clbShape.SetItemChecked(i, false); } if (btnCurve.BackColor == Color.Silver) { UncheckAll(); currentShape = CurrentShape.NoDrawing; psfMain.Cursor = Cursors.Default; btnSelect.BackColor = Color.Silver; } else { UncheckAll(); psfMain.Cursor = Cursors.Cross; currentShape = CurrentShape.Curve; btnCurve.BackColor = Color.Silver; } }
private void btnSelect_Click(object sender, EventArgs e) { shapes.ForEach(shape => shape.IsSelected = false); KhungVe.Invalidate(); currentShape = CurrentShape.NoDrawing; UncheckAll(); btnSelect.BackColor = Color.Silver; KhungVe.Cursor = Cursors.Default; }
public void TryRotate() { if (CanRotationBeMade()) { ClearPreviousCurrentShapePosition(); CurrentShape.Rotate(); PlaceCurrentShape(); GameUpdated?.Invoke(this, EventArgs.Empty); } }
private bool CanMovementCanBeMade(Movement movement) { //first we need to see if this can be moved //we get a copy of the item Shape localCopy = CurrentShape.Clone(); //we get a reference to all its left,right or bottom pieces Piece[] pieces = localCopy.ToArray(); switch (movement) { case Movement.Left: for (int i = 0; i < pieces.Count(); i++) { pieces[i].Column--; } break; case Movement.Bottom: //we increase their row property by one for (int i = 0; i < pieces.Count(); i++) { pieces[i].Row++; } break; case Movement.Right: for (int i = 0; i < pieces.Count(); i++) { pieces[i].Column++; } break; default: break; } //if any column is greater than 7, row less than 0 or greater than 7 //or there exists another item in the new positions if (pieces.Any(x => x.Row >= Constants.Rows) || pieces.Any(x => x.Column >= Constants.Columns) || pieces.Any(x => x.Column < 0) || //we get the new position of each piece //we check if a piece in this position in the array already exists //and this position is *not* in the current shape :) (pieces.Any(x => GameArray[x.Row, x.Column] != null && CurrentShape.Where(y => y.Row == x.Row && y.Column == x.Column).Count() == 0))) { //movement cannot be done return(false); } else { //movement OK return(true); } }
public void Rotate(Vector2Int?coordinate = null) { var shapes = ShapeContainer.Shapes; IncrementRotationIndex(); if (coordinate != null) { while (CheckCanNotToRotate(coordinate.Value, _rotationIndex)) { IncrementRotationIndex(); } } void IncrementRotationIndex() { _rotationIndex++; if (_rotationIndex >= shapes.Length) { _rotationIndex = 0; } } CurrentShape = shapes[_rotationIndex]; var shapeSize = CurrentShape.Size; BlockGrid = new GameObject[shapeSize.x, shapeSize.y]; var blockIndex = 0; for (var x = 0; x < shapeSize.x; x++) { for (var y = 0; y < shapeSize.y; y++) { var bit = CurrentShape.GetBlock(new Vector2Int(x, y)); if (!bit) { continue; } var blockCoordinate = _grid.GetBlockCoordinate(new Vector2Int(x, y) + CurrentShape.Offset); var position = transform.position; var block = _initialBlocks[blockIndex]; BlockGrid[x, y] = block; block.transform.position = new Vector3( blockCoordinate.x + position.x, blockCoordinate.y + position.y, position.z); blockIndex++; } } }
//Event select shapes private void btnSelect_Click(object sender, EventArgs e) { foreach (Shape s in shapes) { s.isSelect = false; } pnlPaint.Invalidate(); currentShape = CurrentShape.NoDrawing; UncheckButton(); btnSelect.BackColor = Color.SkyBlue; pnlPaint.Cursor = Cursors.Default; }
private void form_MouseDoubleClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { if (IsCurrentShapeTypeRegion) { form.Close(RegionResult.Region); } else if (CurrentShape != null && !IsCreating) { CurrentShape.OnShapeDoubleClicked(); } } }
private void form_MouseDoubleClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { if (IsCurrentShapeTypeRegion && ValidRegions.Length > 0) { Form.UpdateRegionPath(); Form.Close(RegionResult.Region); } else if (CurrentShape != null && !IsCreating) { CurrentShape.OnDoubleClicked(); } } }
private void newToolStripMenuItem_Click(object sender, EventArgs e) { pnlPaint.BackgroundImage = null; pnlPaint.BackColor = Color.White; shapes.Clear(); selectedShape = null; resizeShape = null; cbbDashStyle.SelectedIndex = 0; nmrSize.Value = 1; zoom = 1f; currentShape = CurrentShape.NoDrawing; mode = ShapeMode.NoFill; isCtrPress = isDrawBezier = isDrawPolygon = isMouseDown = isMouseSelect = isMovingShape = false; UncheckButton(); pnlPaint.Invalidate(); }
public void CloneDraw(Graphics e, Background b) { for (int i = 0; i < CurrentShape.GetLength(0); i++) { for (int j = 0; j < CurrentShape.GetLength(1); j++) { if (CurrentShape[i, j] == 1) { //clone Pencil.Color = PenColor; Painter.Color = CurrentColor; e.FillRectangle(Painter, GetRect(X + j + b.MaxX, Y + i + BackgroundY)); e.DrawRectangle(Pencil, GetRect(X + j + b.MaxX, Y + i + BackgroundY)); } } } }
private void btnLine_Click(object sender, EventArgs e) { lstObject.ForEach(shape => shape.IsSelected = false); PanelPaint.Invalidate(); if (btnLine.BackColor == Color.Silver) { UncheckAll(); currentShape = CurrentShape.NoDrawing; PanelPaint.Cursor = Cursors.Default; btnSelect.BackColor = Color.Silver; } else { UncheckAll(); PanelPaint.Cursor = Cursors.Cross; currentShape = CurrentShape.Line; btnLine.BackColor = Color.Silver; } }
private void btnCircle_Click(object sender, EventArgs e) { shapes.ForEach(shape => shape.IsSelected = false); KhungVe.Invalidate(); if (btnCircle.BackColor == Color.Silver) { UncheckAll(); currentShape = CurrentShape.NoDrawing; KhungVe.Cursor = Cursors.Default; btnSelect.BackColor = Color.Silver; } else { UncheckAll(); KhungVe.Cursor = Cursors.Cross; currentShape = CurrentShape.Circle; btnCircle.BackColor = Color.Silver; } }
private void ClbShape_SelectedIndexChanged(object sender, EventArgs e) { UncheckAll(); EnableButtons(); btnSelect.BackColor = Color.Silver; psfMain.Cursor = Cursors.Default; currentShape = CurrentShape.NoDrawing; trkLineWidth.Enabled = true; int index = clbShape.SelectedIndex; if (index < 0) { return; } for (int i = 0; i < clbShape.Items.Count; i++) { shapes[i].IsSelected = clbShape.GetItemChecked(i); } psfMain.Invalidate(); }
private bool CanRotationBeMade() { //we need to see if this can be rotated //get a local copy Shape localCopy = CurrentShape.Clone(); localCopy.Rotate(); Piece[] pieces = localCopy.ToArray(); if (pieces.Any(x => x.Row >= Constants.Rows) || pieces.Any(x => x.Column >= Constants.Columns) || pieces.Any(x => x.Column < 0) || //we get the new position of each piece //we check if a piece in this position in the array already exists //and this position is *not* in the current shape :) (pieces.Any(x => GameArray[x.Row, x.Column] != null && CurrentShape.Where(y => y.Row == x.Row && y.Column == x.Column).Count() == 0))) { return(false); } else { return(true); } }
//Event click of button choose shape private void btnShapes_Click(object sender, EventArgs e) { shapes.ForEach(shape => shape.isSelect = false); pnlPaint.Invalidate(); Button btn = sender as Button; if (btn.BackColor == Color.SkyBlue) { UncheckButton(); currentShape = CurrentShape.NoDrawing; pnlPaint.Cursor = Cursors.Default; btnSelect.BackColor = Color.SkyBlue; } else { UncheckButton(); pnlPaint.Cursor = Cursors.Cross; btn.BackColor = Color.SkyBlue; switch (int.Parse(btn.Tag.ToString())) { case 0: currentShape = CurrentShape.Line; break; case 1: currentShape = CurrentShape.Rectangle; break; case 2: currentShape = CurrentShape.Ellipse; break; case 3: currentShape = CurrentShape.Bezier; break; case 4: currentShape = CurrentShape.Polygon; break; default: currentShape = CurrentShape.NoDrawing; MessageBox.Show("Can't Choose This Shape!"); break; } } }
//Change draw mode (draw or fill) private void ckbFill_CheckedChanged(object sender, EventArgs e) { bool fill = false; UncheckButton(); currentShape = CurrentShape.NoDrawing; if (!ckbFill.Checked) { mode = ShapeMode.NoFill; EnableButtons(); cbbDashStyle.Enabled = true; nmrSize.Enabled = true; fill = false; } else { mode = ShapeMode.Fill; nmrSize.Enabled = false; btnLine.Enabled = btnBezier.Enabled = false; cbbDashStyle.Enabled = false; fill = true; } shapes.FindAll(shape => shape.isSelect).ForEach(shape => { if (shape is ShapeSet group) { group.FillAll(fill); } else { shape.isFilled = fill; } }); pnlPaint.Invalidate(); }
public void Rotate() { CurrentShape.Rotate(this); }
public void ShiftShapeDown() { CurrentShape.ShiftShapeDown(this); }
public void ShiftRight() { CurrentShape.ShiftRight(this); }
public void RefreshGrid() { CurrentShape.UnDraw(this); CurrentShape.Draw(this); }
public void ShiftLeft() { CurrentShape.ShiftLeft(this); }