From 984cc4622421e66b0639993c8627356957c757aa Mon Sep 17 00:00:00 2001 From: Pilzinsel64 Date: Fri, 27 Oct 2023 08:51:05 +0200 Subject: [PATCH] prevent resizing on moving painting object --- Pilz.UI/PaintingControl/PaintingControl.vb | 29 ++++++++++++------- .../PaintingControl/PaintingObjectResizing.vb | 21 ++++++++++++-- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/Pilz.UI/PaintingControl/PaintingControl.vb b/Pilz.UI/PaintingControl/PaintingControl.vb index e1a7890..83086a6 100644 --- a/Pilz.UI/PaintingControl/PaintingControl.vb +++ b/Pilz.UI/PaintingControl/PaintingControl.vb @@ -24,7 +24,6 @@ Public Class PaintingControl Public Property Offset As PointF = PointF.Empty Public ReadOnly Property PaintingObjects As New PaintingObjectList(Me) - 'Public Property EnableRealTransparency As Boolean = False Public Property VisibleForMouseEvents As Boolean = True Public Property AutoAreaSelection As Boolean = True Public Property AutoSingleSelection As Boolean = True @@ -50,9 +49,6 @@ Public Class PaintingControl Private pressedControl As Boolean = False Private pressedAlt As Boolean = False - 'Friend WithEvents HScrollBarAdv1 As DevComponents.DotNetBar.ScrollBar.HScrollBarAdv - 'Friend WithEvents VScrollBarAdv1 As DevComponents.DotNetBar.VScrollBarAdv - Private savedPos As New Dictionary(Of PaintingObject, PointF) Public Event SelectionChanged(sender As Object, e As PaintingObjectEventArgs) @@ -118,10 +114,21 @@ Public Class PaintingControl End Property Public Sub New() - 'SetStyle(ControlStyles.Opaque, True) 'For real transparency + AddHandler PaintingObjectResizing.CheckEnabled, AddressOf PaintingObjectResizing_CheckEnabled DoubleBuffered = True End Sub + Protected Overrides Sub Finalize() + RemoveHandler PaintingObjectResizing.CheckEnabled, AddressOf PaintingObjectResizing_CheckEnabled + MyBase.Finalize() + End Sub + + Private Sub PaintingObjectResizing_CheckEnabled(sender As PaintingObjectResizing, ByRef enabled As Boolean) + If PaintingObjects.Contains(sender.PaintingObject) AndAlso pressedAlt Then + enabled = False + End If + End Sub + Private Sub ResetAllBufferedImages() For Each ob As PaintingObject In PaintingObjects ob.ResetImageBuffer() @@ -129,7 +136,7 @@ Public Class PaintingControl Refresh() End Sub - Private Sub CheckKeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown, Me.KeyUp + Protected Sub CheckKeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown, Me.KeyUp pressedShift = e.Shift pressedControl = e.Control pressedAlt = e.Alt @@ -141,7 +148,7 @@ Public Class PaintingControl End Get End Property - Private Sub CheckMouseClick(sender As Object, e As MouseEventArgs) Handles Me.MouseClick + Protected Sub CheckMouseClick(sender As Object, e As MouseEventArgs) Handles Me.MouseClick For Each obj As PaintingObject In GetObjects(New Point(e.X + Offset.X, e.Y + Offset.Y)) If Not obj.MouseTransparency Then obj.RaiseMouseClick(GetMouseEventArgs(e, obj)) @@ -149,7 +156,7 @@ Public Class PaintingControl Next End Sub - Private Sub CheckMouseDown(sender As Object, e As MouseEventArgs) Handles Me.MouseDown + Protected Sub CheckMouseDown(sender As Object, e As MouseEventArgs) Handles Me.MouseDown lastMousePos = New Point(e.X + Offset.X, e.Y + Offset.Y) curObjMouseDown = GetObjects(lastMousePos).Where(Function(n) Not n.MouseTransparency).LastOrDefault @@ -225,7 +232,7 @@ Public Class PaintingControl Public Sub RaiseSelectionChanged() RaiseEvent SelectionChanged(Me, New PaintingObjectEventArgs(SelectedObjects)) End Sub - Private Sub CheckMouseUp(sender As Object, e As MouseEventArgs) Handles Me.MouseUp + Protected Sub CheckMouseUp(sender As Object, e As MouseEventArgs) Handles Me.MouseUp If _IsAreaSelecting Then _IsAreaSelecting = False End If @@ -252,7 +259,7 @@ Public Class PaintingControl RaiseEvent AfterScrollingDone(Me, New EventArgs) End If End Sub - Private Sub CheckMouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove + Protected Sub CheckMouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove If _IsAreaSelecting OrElse _IsMovingObjects Then lastMousePos = New Point(e.X + Offset.X, e.Y + Offset.Y) End If @@ -648,6 +655,8 @@ Public Class PaintingControl Dim val As Single = e.Delta / 120 / 10 ZoomFactor = New SizeF(Math.Max(ZoomFactor.Width + val, 0.25), Math.Max(ZoomFactor.Height + val, 0.25)) Refresh() + Else + '... End If End Sub diff --git a/Pilz.UI/PaintingControl/PaintingObjectResizing.vb b/Pilz.UI/PaintingControl/PaintingObjectResizing.vb index 9edbea5..bd9a5e9 100644 --- a/Pilz.UI/PaintingControl/PaintingObjectResizing.vb +++ b/Pilz.UI/PaintingControl/PaintingObjectResizing.vb @@ -1,10 +1,15 @@ Imports System.Drawing +Imports System.Runtime.CompilerServices Imports System.Windows.Forms + Imports Newtonsoft.Json + Imports Pilz.Drawing Friend Class PaintingObjectResizing + Public Shared Event CheckEnabled(sender As PaintingObjectResizing, ByRef enabled As Boolean) + Private WithEvents mObj As PaintingObject Private WithEvents mObjParent As Control = Nothing Private WithEvents mObjControl As Control = Nothing @@ -35,13 +40,23 @@ Imports Pilz.Drawing End Get End Property + Public ReadOnly Property PaintingObject As PaintingObject + Get + Return mObj + End Get + End Property + Public Sub New(obj As PaintingObject) mObj = obj mObjControl = mObj.Parent End Sub - Shared Function ApplyToControl(obj As PaintingObject) As PaintingObjectResizing - Return New PaintingObjectResizing(obj) + Private Function IsEnabled() As Boolean + Dim enabled = Me.Enabled + + RaiseEvent CheckEnabled(Me, enabled) + + Return enabled End Function Private Sub mControl_MouseDown(sender As Object, e As MouseEventArgs) Handles mObj.MouseDown @@ -115,7 +130,7 @@ Imports Pilz.Drawing Dim setToNone As Boolean = False Dim isOnTop As Boolean = mObj.Parent.GetObject(New PointF(realX, realY), True) Is mObj - If Enabled AndAlso isOnTop Then + If IsEnabled() AndAlso isOnTop Then Select Case True Case HelpfulDrawingFunctions.IsPointInRectangle(eLocation, New Rectangle(newRect.X, newRect.Y, newRect.Width, newRect.Height)) mObj.Cursor = Cursors.SizeNWSE