//========= CONSTRUCTORS ========= #region Constructors /** <summary> Constructs the default control. </summary> */ public MazeEditor() : base() { this.InitializeComponent(); this.blocks = new MazeBlock[1, 1]; this.blocks[0, 0] = new MazeBlock(); this.pathWidth = 16; this.wallWidth = 3; this.wallStyle = 1; this.drawGrid = true; this.hoverType = MazeWallTypes.None; this.hoverPoint = Point.Empty; }
/** <summary> Called when the mouse is hovering. </summary> */ protected override void OnMouseMove(MouseEventArgs e) { Point mousePos = new Point(e.X - this.wallWidth, e.Y - this.wallWidth); this.hoverPoint = new Point(mousePos.X / (this.pathWidth + this.wallWidth * 2), mousePos.Y / (this.pathWidth + this.wallWidth * 2)); Point offset = new Point(mousePos.X % (this.pathWidth + this.wallWidth * 2), mousePos.Y % (this.pathWidth + this.wallWidth * 2)); if (offset.X < this.pathWidth) { if (offset.Y < this.pathWidth) { this.hoverType = MazeWallTypes.Quadrant; } else { this.hoverType = MazeWallTypes.WallX; } } else { if (offset.Y < this.pathWidth) { this.hoverType = MazeWallTypes.WallY; } else { this.hoverType = MazeWallTypes.None; } } if (!IsNormalBlock(new Point(this.hoverPoint.X / 2, this.hoverPoint.Y / 2)) || ((this.hoverType == MazeWallTypes.WallX && !IsNormalBlock(new Point(this.hoverPoint.X / 2, (this.hoverPoint.Y + 1) / 2))) || (this.hoverType == MazeWallTypes.WallY && !IsNormalBlock(new Point((this.hoverPoint.X + 1) / 2, this.hoverPoint.Y / 2))))) { this.hoverType = MazeWallTypes.None; } if (e.Button == MouseButtons.Left || e.Button == MouseButtons.Right) { OnMouseDown(e); } this.Invalidate(); base.OnMouseMove(e); }