protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (DesignMode) { return; } int fieldSize = GetFieldSize(); PointFloat offset = GetOffset(); if (_hoverPoint != GUIHelper.NULLPOINT) { e.Graphics.DrawRectangle(new Pen(Color.WhiteSmoke, 2f), offset.X + _hoverPoint.X * fieldSize * Zoom, offset.Y + _hoverPoint.Y * fieldSize * Zoom, fieldSize * Zoom, fieldSize * Zoom); } }
private Point CalcPointHit(Point mouseLocation) { int fieldSize = GetFieldSize(); PointFloat offset = GetOffset(); if (fieldSize == 0) { return(GUIHelper.NULLPOINT); } int x = (int)Math.Floor((mouseLocation.X - offset.X) / (fieldSize * Zoom)); int y = (int)Math.Floor((mouseLocation.Y - offset.Y) / (fieldSize * Zoom)); Point point = new Point(x, y); if (IsInsideBoard(point)) { return(point); } return(GUIHelper.NULLPOINT); }
protected override void OnPaintBackground(PaintEventArgs e) { base.OnPaintBackground(e); if (Board == null) { return; } if (IMAGES == null) { LoadImages(Application.StartupPath + @"/Images/new"); } int fieldSize = GetFieldSize(); PointFloat offset = GetOffset(); for (int y = 1; y < Board.Size.Height - 1; y++) { float yPos = offset.Y + (y - 1) * fieldSize * Zoom; if (yPos > e.ClipRectangle.Height) { break; } for (int x = 1; x < Board.Size.Width - 1; x++) { float xPos = offset.X + (x - 1) * fieldSize * Zoom; if (xPos > e.ClipRectangle.Width) { break; } Image image = IMAGES[Board.Fields[x, y].EncodedField]; e.Graphics.DrawImage(image, xPos, yPos, fieldSize * Zoom, fieldSize * Zoom); } } }
public void DrawRobo(PaintEventArgs e, RoboPosition position, String name) { if (position == null) { return; } if (!IsInsideBoard(new Point(position.X, position.Y))) { return; } int fieldSize = GetFieldSize(); PointFloat offset = GetOffset(); Image roboImage = IMAGES['B']; if (position.IsDead) { roboImage = IMAGES['X']; e.Graphics.DrawImage(roboImage, offset.X + position.X * fieldSize * Zoom, offset.Y + position.Y * fieldSize * Zoom, fieldSize, fieldSize); } else { switch (position.Direction) { case Direction.Left: roboImage.RotateFlip(RotateFlipType.Rotate180FlipNone); e.Graphics.DrawImage(roboImage, offset.X + position.X * fieldSize * Zoom, offset.Y + position.Y * fieldSize * Zoom, fieldSize, fieldSize); roboImage.RotateFlip(RotateFlipType.Rotate180FlipNone); break; case Direction.Up: roboImage.RotateFlip(RotateFlipType.Rotate270FlipNone); e.Graphics.DrawImage(roboImage, offset.X + position.X * fieldSize * Zoom, offset.Y + position.Y * fieldSize * Zoom, fieldSize, fieldSize); roboImage.RotateFlip(RotateFlipType.Rotate90FlipNone); break; case Direction.Down: roboImage.RotateFlip(RotateFlipType.Rotate90FlipNone); e.Graphics.DrawImage(roboImage, offset.X + position.X * fieldSize * Zoom, offset.Y + position.Y * fieldSize * Zoom, fieldSize, fieldSize); roboImage.RotateFlip(RotateFlipType.Rotate270FlipNone); break; default: e.Graphics.DrawImage(roboImage, offset.X + position.X * fieldSize * Zoom, offset.Y + position.Y * fieldSize * Zoom, fieldSize, fieldSize); break; } } e.Graphics.DrawString(name, new Font("Arial", 10), new SolidBrush(Color.FloralWhite), offset.X + position.X * fieldSize * Zoom, offset.Y + position.Y * fieldSize * Zoom); }