protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
if(this.ActiveBlueprint == null) return;
PointF mouseLoc = this.PointToClient(Cursor.Position);
PointF mouseOffset = new PointF(mouseLoc.X-this._center.X, mouseLoc.Y-this._center.Y);
int? idState = ((int?)this.HoveredRoom?.GetID() ?? -1) + ((int?)this.HoveredCorner?.GetID() ?? -1) + ((int?)this.HoveredWall?.GetID() ?? -1) ;
int nullState = (this.HoveredRoom != null ? 1 : 0) + (this.HoveredCorner != null ? 2 : 0) + (this.HoveredWall != null ? 4 : 0);
int state = nullState + ((int)idState << 3);
this.HoveredCorner = (this._editMode ? this.ActiveBlueprint.GetCornerAtPoint(mouseOffset, this.Renderer.CornerSizeEdit) : null);
this.HoveredWall = (this._editMode && this.HoveredCorner == null ? this.ActiveBlueprint.GetWallAtPoint(mouseOffset, this.WallDistance) : null);
this.HoveredRoom = (this.HoveredWall == null && this.HoveredCorner == null ? this.ActiveBlueprint.GetRoomAtPoint(mouseOffset) : null);
idState = ((int?)this.HoveredRoom?.GetID() ?? -1) + ((int?)this.HoveredCorner?.GetID() ?? -1) + ((int?)this.HoveredWall?.GetID() ?? -1);
nullState = (this.HoveredRoom != null ? 1 : 0) + (this.HoveredCorner != null ? 2 : 0) + (this.HoveredWall != null ? 4 : 0);
int newState = nullState + ((int)idState << 3);
//Panning
if(this._panOrigin != PointF.Empty) {
this._center = new PointF(this._center.X-(this._panOrigin.X-e.Location.X), this._center.Y-(this._panOrigin.Y-e.Location.Y));
this._panOrigin = e.Location;
this.Invalidate();
}
//Snapping
if(this.SelectedCorner != null && this._movingCorner) {
this._snapCorners.Clear();
float snapX, snapY, closestX, closestY;
snapX = snapY = closestX = closestY = float.MaxValue;
foreach(Room room in this.ActiveBlueprint.Rooms) {
foreach(Corner corner in room.GetCorners()) {
if(corner.Equals(this.SelectedCorner)) continue;
float distX = Math.Abs(corner.GetPoint().X-mouseOffset.X);
float distY = Math.Abs(corner.GetPoint().Y-mouseOffset.Y);
if(distX <= closestX && distX < this.CornerSnapDistance) {
snapX = corner.GetPoint().X;
closestX = distX;
this._snapCorners.Add(corner);
}
if(distY <= closestY && distY < this.CornerSnapDistance) {
snapY = corner.GetPoint().Y;
closestY = distY;
this._snapCorners.Add(corner);
}
this._snapCorners.RemoveAll((c) => (!snapX.Equals(c.GetPoint().X) && !snapY.Equals(c.GetPoint().Y)));
}
}
this.SelectedCorner.SetPoint(new PointF((!snapX.Equals(float.MaxValue) ? snapX : mouseOffset.X), (!snapY.Equals(float.MaxValue) ? snapY : mouseOffset.Y)));
this.Invalidate();
}
if(state != newState) this.Invalidate();
}