Skip to content
This repository has been archived by the owner on Aug 24, 2022. It is now read-only.

Commit

Permalink
Fixed zoom fixpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Virenbar committed Nov 5, 2019
1 parent 3d3560a commit d8ceed0
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 12 deletions.
16 changes: 10 additions & 6 deletions MCPixelArtCrafter/Controls/PictureBoxPAZ.vb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Public Class PictureBoxPAZ
End Set
End Property

Protected ReadOnly Property ImageSize() As Size
Protected ReadOnly Property ImageSize As Size
Get
Return New Size(CInt(Math.Round(Image.Size.Width * _zoomScale)), CInt(Math.Round(Image.Size.Height * _zoomScale)))
End Get
Expand All @@ -80,7 +80,11 @@ Public Class PictureBoxPAZ
''' Grid spacing (0-No grid)
''' </summary>
Public Property GridSpacing As Integer = 0

Public ReadOnly Property OriginPos As Point
Get
Return New Point(tX, tY)
End Get
End Property
Public ReadOnly Property MousePos As Point
Get
Dim CP = PointToClient(MousePosition)
Expand Down Expand Up @@ -217,11 +221,11 @@ Public Class PictureBoxPAZ
If Image IsNot Nothing AndAlso _zoomScale <> newZoom Then
'fixPoint.X = Math.Min(fixPoint.X, CInt((Me.Image.Size.Width * _zoomScale)))
'fixPoint.Y = Math.Min(fixPoint.Y, CInt((Me.Image.Size.Height * _zoomScale)))
Dim shiftX As Integer = (fixPoint.X * (newZoom - _zoomScale) / newZoom / _zoomScale)
Dim shiftY As Integer = (fixPoint.Y * (newZoom - _zoomScale) / newZoom / _zoomScale)
Dim shiftX As Integer = -((fixPoint.X - tX) / _zoomScale * (newZoom - _zoomScale))
Dim shiftY As Integer = -((fixPoint.Y - tY) / _zoomScale * (newZoom - _zoomScale))
_zoomScale = newZoom
tX += -shiftX
tY += -shiftY
tX += shiftX
tY += shiftY
CheckT()
Invalidate()
End If
Expand Down
35 changes: 29 additions & 6 deletions MCPixelArtCrafter/Forms/MapPreview.Designer.vb

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

3 changes: 3 additions & 0 deletions MCPixelArtCrafter/Forms/MapPreview.resx
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,7 @@
<metadata name="SFD.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>116, 17</value>
</metadata>
<metadata name="StatusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>189, 17</value>
</metadata>
</root>
4 changes: 4 additions & 0 deletions MCPixelArtCrafter/Forms/MapPreview.vb
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@ Public Class MapPreview
Private Sub PB_Click(sender As Object, e As EventArgs) Handles PB.Click
Console.WriteLine(PB.MousePos.ToString)
End Sub

Private Sub PB_MouseMove(sender As Object, e As MouseEventArgs) Handles PB.MouseMove
TS_MousePos.Text = String.Format("X:{0}|Y:{1}", PB.MousePos.X, PB.MousePos.Y)
End Sub
End Class

0 comments on commit d8ceed0

Please sign in to comment.