From 8e875ad5e40a393c895fb468640a2de2eaa3983d Mon Sep 17 00:00:00 2001 From: ogamespec Date: Mon, 10 Jul 2023 10:37:23 +0300 Subject: [PATCH 1/3] Update MouseInput.cs --- EntityBox/MouseInput.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/EntityBox/MouseInput.cs b/EntityBox/MouseInput.cs index 0faa1e3..4b0f585 100644 --- a/EntityBox/MouseInput.cs +++ b/EntityBox/MouseInput.cs @@ -72,10 +72,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 +86,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; From 16d28b34a2ead3e41f5b9d3491cf930c69ddc638 Mon Sep 17 00:00:00 2001 From: ogamespec Date: Mon, 10 Jul 2023 10:47:30 +0300 Subject: [PATCH 2/3] Update MouseInput.cs --- EntityBox/MouseInput.cs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/EntityBox/MouseInput.cs b/EntityBox/MouseInput.cs index 4b0f585..46f0b85 100644 --- a/EntityBox/MouseInput.cs +++ b/EntityBox/MouseInput.cs @@ -124,21 +124,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; From 6c5947ee9af48f3b8064315b178018d0ff861a41 Mon Sep 17 00:00:00 2001 From: ogamespec Date: Mon, 10 Jul 2023 11:15:29 +0300 Subject: [PATCH 3/3] Snap To Grid feature --- Deroute/FormAbout.Designer.cs | 4 +++- EntityBox/MouseInput.cs | 39 ++++++++++++++++++++++++++++------- 2 files changed, 34 insertions(+), 9 deletions(-) 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 46f0b85..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 // @@ -208,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; @@ -473,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; } @@ -495,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; } @@ -576,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(); } @@ -597,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(); }