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

Commit

Permalink
Attempt to get pixel coords on click
Browse files Browse the repository at this point in the history
  • Loading branch information
Virenbar committed Oct 29, 2019
1 parent 4d72afe commit 27b4b1a
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 1 deletion.
19 changes: 18 additions & 1 deletion MCPixelArtCrafter/Controls/PictureBoxPAZ.vb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Public Class PictureBoxPAZ
BorderStyle = BorderStyle.Fixed3D
PanableAndZoomable = True
End Sub

#Region "Properties"
''' <summary>
''' Get or Set the property to enable(disable) Pan and Zoom
''' </summary>
Expand Down Expand Up @@ -80,6 +80,18 @@ Public Class PictureBoxPAZ
''' Grid spacing (0-No grid)
''' </summary>
Public Property GridSpacing As Integer = 0

Public ReadOnly Property MousePos As Point
Get
Dim CP = PointToClient(MousePosition)
Dim X = (tX * _zoomScale - CP.X) / _zoomScale
Dim Y = (tX * _zoomScale - CP.Y) / _zoomScale
Return New Point(X, Y)
'Dim IP = New Point(tX, tY).Multiply(_zoomScale)
'Return CP.Substract(IP).Divide(_zoomScale)
End Get
End Property
#End Region
Protected Overrides Sub OnPaint(ByVal pe As PaintEventArgs)
If IsDisposed Then Return

Expand Down Expand Up @@ -232,3 +244,8 @@ Public Class PictureBoxPAZ
_zoomScale = Math.Max(_zoomScale, _zoomMin)
End Sub
End Class
'TODO: Fix grid
'Try alternative pixel render
'https://stackoverflow.com/questions/40498312/c-sharp-create-grid-for-painting-pixels-and-rendering-text
'Or make new bitmap with max zoom and grid

15 changes: 15 additions & 0 deletions MCPixelArtCrafter/Extensions.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Imports System.Runtime.CompilerServices
Module Extensions
<Extension>
Public Function Divide(p As Point, n As Double) As PointF
Return New PointF(p.X / n, p.Y / n)
End Function
<Extension>
Public Function Multiply(p As Point, n As Double) As PointF
Return New PointF(p.X * n, p.Y * n)
End Function
<Extension>
Public Function Substract(p1 As Point, p2 As Point) As Point
Return New Point(p1.X - p2.X, p1.Y - p2.X)
End Function
End Module
1 change: 1 addition & 0 deletions MCPixelArtCrafter/Forms/MapPreview.Designer.vb

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

4 changes: 4 additions & 0 deletions MCPixelArtCrafter/Forms/MapPreview.vb
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ Public Class MapPreview
Private Sub MapPreview_Closing(sender As Object, e As CancelEventArgs) Handles Me.Closing
MapResult = Nothing
End Sub

Private Sub PB_Click(sender As Object, e As EventArgs) Handles PB.Click
Console.WriteLine(PB.MousePos.ToString)
End Sub
End Class
1 change: 1 addition & 0 deletions MCPixelArtCrafter/MCPixelArtCrafter.vbproj
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@
<Compile Include="DataClasses\MapColor.vb" />
<Compile Include="DataClasses\MapColorsCollection.vb" />
<Compile Include="DataClasses\MapResult.vb" />
<Compile Include="Extensions.vb" />
<Compile Include="My Project\AssemblyInfo.vb" />
<Compile Include="My Project\Application.Designer.vb">
<AutoGen>True</AutoGen>
Expand Down

0 comments on commit 27b4b1a

Please sign in to comment.