diff --git a/Deroute/FormAbout.Designer.cs b/Deroute/FormAbout.Designer.cs index 66ddccc..0cf21af 100644 --- a/Deroute/FormAbout.Designer.cs +++ b/Deroute/FormAbout.Designer.cs @@ -61,7 +61,7 @@ private void InitializeComponent() this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(172, 48); this.label1.TabIndex = 1; - this.label1.Text = "Deroute Tool 2.5\r\n© 2023, emu-russia"; + this.label1.Text = "Deroute Tool 2.6\r\n© 2023, emu-russia"; // // label2 // @@ -149,6 +149,7 @@ private void InitializeComponent() this.entityBox1.CellTextAlignment = TextAlignment.TopLeft; this.entityBox1.ForeColor = System.Drawing.Color.Snow; this.entityBox1.Grayscale = false; + this.entityBox1.GridSize = 0F; this.entityBox1.HideCells = false; this.entityBox1.HideGrid = true; this.entityBox1.HideImage = false; @@ -172,6 +173,7 @@ private void InitializeComponent() this.entityBox1.SelectionBoxColor = System.Drawing.Color.Red; this.entityBox1.SelectionColor = System.Drawing.Color.LimeGreen; this.entityBox1.Size = new System.Drawing.Size(744, 243); + this.entityBox1.SnapToGrid = false; this.entityBox1.TabIndex = 8; this.entityBox1.Text = "entityBox1"; this.entityBox1.UnitCustomColor = System.Drawing.Color.Snow; diff --git a/EntityBox/MouseInput.cs b/EntityBox/MouseInput.cs index 0faa1e3..fdee8c8 100644 --- a/EntityBox/MouseInput.cs +++ b/EntityBox/MouseInput.cs @@ -19,6 +19,24 @@ public float GetDragDistance() return draggingDist; } + private Point SnapMousePosToGrid (int MouseX, int MouseY) + { + Point p = new Point(); + + p.X = MouseX; + p.Y = MouseY; + + if (snapToGrid) + { + var lp = ScreenToLambda(p.X, p.Y); + lp.X = (float)Math.Round(lp.X / gridSize) * gridSize; + lp.Y = (float)Math.Round(lp.Y / gridSize) * gridSize; + p = LambdaToScreen(lp.X, lp.Y); + } + + return p; + } + // // Mouse hit test // @@ -72,10 +90,12 @@ private Entity EntityHitTest(int MouseX, int MouseY) Math.Pow(ortho.Y, 2)); len = Math.Max(1.0F, len); + var WireSize = entity.WidthOverride != 0 ? entity.WidthOverride : WireBaseSize; + PointF rot = RotatePoint(ortho, -90); PointF normalized = new PointF(rot.X / len, rot.Y / len); - PointF baseVect = new PointF(normalized.X * ((WireBaseSize * zf) / 2), - normalized.Y * ((WireBaseSize * zf) / 2)); + PointF baseVect = new PointF(normalized.X * ((WireSize * zf) / 2), + normalized.Y * ((WireSize * zf) / 2)); rect[0].X = baseVect.X + start.X; rect[0].Y = baseVect.Y + start.Y; @@ -84,8 +104,8 @@ private Entity EntityHitTest(int MouseX, int MouseY) rot = RotatePoint(ortho, +90); normalized = new PointF(rot.X / len, rot.Y / len); - baseVect = new PointF(normalized.X * ((WireBaseSize * zf) / 2), - normalized.Y * ((WireBaseSize * zf) / 2)); + baseVect = new PointF(normalized.X * ((WireSize * zf) / 2), + normalized.Y * ((WireSize * zf) / 2)); rect[1].X = baseVect.X + start.X; rect[1].Y = baseVect.Y + start.Y; @@ -122,21 +142,23 @@ private Entity EntityHitTest(int MouseX, int MouseY) } else if (entity.IsVias() && HideVias == false) { + var ViasSize = entity.WidthOverride != 0 ? entity.WidthOverride : ViasBaseSize; + rect[0] = LambdaToScreen(entity.LambdaX, entity.LambdaY); - rect[0].X -= ((float)ViasBaseSize * zf); - rect[0].Y -= ((float)ViasBaseSize * zf); + rect[0].X -= ((float)ViasSize * zf); + rect[0].Y -= ((float)ViasSize * zf); rect[1] = LambdaToScreen(entity.LambdaX, entity.LambdaY); - rect[1].X += ((float)ViasBaseSize * zf); - rect[1].Y -= ((float)ViasBaseSize * zf); + rect[1].X += ((float)ViasSize * zf); + rect[1].Y -= ((float)ViasSize * zf); rect[2] = LambdaToScreen(entity.LambdaX, entity.LambdaY); - rect[2].X += ((float)ViasBaseSize * zf); - rect[2].Y += ((float)ViasBaseSize * zf); + rect[2].X += ((float)ViasSize * zf); + rect[2].Y += ((float)ViasSize * zf); rect[3] = LambdaToScreen(entity.LambdaX, entity.LambdaY); - rect[3].X -= ((float)ViasBaseSize * zf); - rect[3].Y += ((float)ViasBaseSize * zf); + rect[3].X -= ((float)ViasSize * zf); + rect[3].Y += ((float)ViasSize * zf); if (PointInPoly(rect, point) == true) return entity; @@ -204,8 +226,9 @@ protected override void OnMouseDown(MouseEventArgs e) if (Okay == true) { - SavedMouseX = e.X; - SavedMouseY = e.Y; + var p = SnapMousePosToGrid(e.X, e.Y); + SavedMouseX = p.X; + SavedMouseY = p.Y; SavedScrollX = _ScrollX; SavedScrollY = _ScrollY; DrawingBegin = true; @@ -469,7 +492,8 @@ protected override void OnMouseUp(MouseEventArgs e) if (e.Button == MouseButtons.Left && (Mode == EntityMode.WireGround || Mode == EntityMode.WireInterconnect || Mode == EntityMode.WirePower) && DrawingBegin) { - AddWire((EntityType)Mode, SavedMouseX, SavedMouseY, e.X, e.Y); + var p = SnapMousePosToGrid(e.X, e.Y); + AddWire((EntityType)Mode, SavedMouseX, SavedMouseY, p.X, p.Y); DrawingBegin = false; } @@ -491,7 +515,8 @@ protected override void OnMouseUp(MouseEventArgs e) Mode == EntityMode.UnitCustom ) && DrawingBegin) { - AddCell((EntityType)Mode, SavedMouseX, SavedMouseY, e.X, e.Y); + var p = SnapMousePosToGrid(e.X, e.Y); + AddCell((EntityType)Mode, SavedMouseX, SavedMouseY, p.X, p.Y); DrawingBegin = false; } @@ -572,8 +597,9 @@ protected override void OnMouseMove(MouseEventArgs e) if (DrawingBegin && (Mode == EntityMode.WireGround || Mode == EntityMode.WireInterconnect || Mode == EntityMode.WirePower)) { - LastMouseX = e.X; - LastMouseY = e.Y; + var p = SnapMousePosToGrid(e.X, e.Y); + LastMouseX = p.X; + LastMouseY = p.Y; Invalidate(); } @@ -593,8 +619,9 @@ protected override void OnMouseMove(MouseEventArgs e) Mode == EntityMode.UnitMemory || Mode == EntityMode.UnitCustom)) { - LastMouseX = e.X; - LastMouseY = e.Y; + var p = SnapMousePosToGrid(e.X, e.Y); + LastMouseX = p.X; + LastMouseY = p.Y; Invalidate(); }