Skip to content

Commit

Permalink
#2 - Added zoom in/out shortcut and menu item
Browse files Browse the repository at this point in the history
  • Loading branch information
lkosson committed Sep 18, 2023
1 parent 3a1d538 commit 66fd392
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 16 deletions.
16 changes: 12 additions & 4 deletions Canvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -432,11 +432,19 @@ private Vector2 Snap(Vector2 point, params Vector2[] hints)
protected override void OnMouseWheel(MouseEventArgs e)
{
base.OnMouseWheel(e);
Zoom(e.Delta > 0 ? 1.1f : 1 / 1.1f, e.X, e.Y);
}

viewMatrix.Translate(-e.X, -e.Y, MatrixOrder.Append);
if (e.Delta > 0) viewMatrix.Scale(1.1f, 1.1f, MatrixOrder.Append);
else viewMatrix.Scale(1 / 1.1f, 1 / 1.1f, MatrixOrder.Append);
viewMatrix.Translate(e.X, e.Y, MatrixOrder.Append);
public void Zoom(float scale)
{
Zoom(scale, Width / 2, Height / 2);
}

public void Zoom(float scale, int x, int y)
{
viewMatrix.Translate(-x, -y, MatrixOrder.Append);
viewMatrix.Scale(scale, scale, MatrixOrder.Append);
viewMatrix.Translate(x, y, MatrixOrder.Append);

matrixUpdated = true;

Expand Down
44 changes: 32 additions & 12 deletions MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,8 @@ protected override void OnKeyDown(KeyEventArgs e)
else if (e.KeyCode == Keys.OemSemicolon && e.Modifiers == Keys.None) AddComment(false);
else if (e.KeyCode == Keys.OemSemicolon && e.Modifiers == Keys.Shift) AddComment(true);
else if (e.KeyCode == Keys.OemQuestion && e.Modifiers == Keys.None) ToggleComment();
else if (e.KeyCode == Keys.Oemplus && e.Modifiers == Keys.None) canvas.Zoom(1.1f);
else if (e.KeyCode == Keys.OemMinus && e.Modifiers == Keys.None) canvas.Zoom(1 / 1.1f);
else { e.Handled = false; }

if (e.Handled && e.Alt) { e.SuppressKeyPress = true; }
Expand Down Expand Up @@ -382,5 +384,7 @@ protected override void OnKeyDown(KeyEventArgs e)
private void convertToOutlineToolStripMenuItem_Click(object sender, EventArgs e) => ConvertToOutline();
private void rotateToolStripMenuItem_Click(object sender, EventArgs e) => canvas.StartMouseRotate();
private void commentUncommentLinesToolStripMenuItem_Click(object sender, EventArgs e) => ToggleComment();
private void zoomInToolStripMenuItem_Click(object sender, EventArgs e) => canvas.Zoom(1.5f);
private void zoomOutToolStripMenuItem_Click(object sender, EventArgs e) => canvas.Zoom(1 / 1.5f);
}
}

0 comments on commit 66fd392

Please sign in to comment.