From 27b4b1a1b2bb4fab7e8b99e2c43e02ea73d221f3 Mon Sep 17 00:00:00 2001 From: Virenbar Date: Tue, 29 Oct 2019 17:59:30 +0500 Subject: [PATCH] Attempt to get pixel coords on click --- MCPixelArtCrafter/Controls/PictureBoxPAZ.vb | 19 ++++++++++++++++++- MCPixelArtCrafter/Extensions.vb | 15 +++++++++++++++ .../Forms/MapPreview.Designer.vb | 1 + MCPixelArtCrafter/Forms/MapPreview.vb | 4 ++++ MCPixelArtCrafter/MCPixelArtCrafter.vbproj | 1 + 5 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 MCPixelArtCrafter/Extensions.vb diff --git a/MCPixelArtCrafter/Controls/PictureBoxPAZ.vb b/MCPixelArtCrafter/Controls/PictureBoxPAZ.vb index 52b1090..b9219c5 100644 --- a/MCPixelArtCrafter/Controls/PictureBoxPAZ.vb +++ b/MCPixelArtCrafter/Controls/PictureBoxPAZ.vb @@ -31,7 +31,7 @@ Public Class PictureBoxPAZ BorderStyle = BorderStyle.Fixed3D PanableAndZoomable = True End Sub - +#Region "Properties" ''' ''' Get or Set the property to enable(disable) Pan and Zoom ''' @@ -80,6 +80,18 @@ Public Class PictureBoxPAZ ''' Grid spacing (0-No grid) ''' 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 @@ -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 + diff --git a/MCPixelArtCrafter/Extensions.vb b/MCPixelArtCrafter/Extensions.vb new file mode 100644 index 0000000..21e0ade --- /dev/null +++ b/MCPixelArtCrafter/Extensions.vb @@ -0,0 +1,15 @@ +Imports System.Runtime.CompilerServices +Module Extensions + + Public Function Divide(p As Point, n As Double) As PointF + Return New PointF(p.X / n, p.Y / n) + End Function + + Public Function Multiply(p As Point, n As Double) As PointF + Return New PointF(p.X * n, p.Y * n) + End Function + + 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 diff --git a/MCPixelArtCrafter/Forms/MapPreview.Designer.vb b/MCPixelArtCrafter/Forms/MapPreview.Designer.vb index 8fe83d9..38a0517 100644 --- a/MCPixelArtCrafter/Forms/MapPreview.Designer.vb +++ b/MCPixelArtCrafter/Forms/MapPreview.Designer.vb @@ -79,6 +79,7 @@ Partial Class MapPreview Me.PB.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor Me.PB.Location = New System.Drawing.Point(0, 0) Me.PB.Name = "PB" + Me.PB.ShowGrid = False Me.PB.Size = New System.Drawing.Size(846, 351) Me.PB.TabIndex = 0 Me.PB.TabStop = False diff --git a/MCPixelArtCrafter/Forms/MapPreview.vb b/MCPixelArtCrafter/Forms/MapPreview.vb index d2e9eaf..a29fe73 100644 --- a/MCPixelArtCrafter/Forms/MapPreview.vb +++ b/MCPixelArtCrafter/Forms/MapPreview.vb @@ -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 \ No newline at end of file diff --git a/MCPixelArtCrafter/MCPixelArtCrafter.vbproj b/MCPixelArtCrafter/MCPixelArtCrafter.vbproj index d970a59..c6c434f 100644 --- a/MCPixelArtCrafter/MCPixelArtCrafter.vbproj +++ b/MCPixelArtCrafter/MCPixelArtCrafter.vbproj @@ -166,6 +166,7 @@ + True