prevent resizing on moving painting object
This commit is contained in:
@@ -24,7 +24,6 @@ Public Class PaintingControl
|
|||||||
|
|
||||||
Public Property Offset As PointF = PointF.Empty
|
Public Property Offset As PointF = PointF.Empty
|
||||||
Public ReadOnly Property PaintingObjects As New PaintingObjectList(Me)
|
Public ReadOnly Property PaintingObjects As New PaintingObjectList(Me)
|
||||||
'Public Property EnableRealTransparency As Boolean = False
|
|
||||||
Public Property VisibleForMouseEvents As Boolean = True
|
Public Property VisibleForMouseEvents As Boolean = True
|
||||||
Public Property AutoAreaSelection As Boolean = True
|
Public Property AutoAreaSelection As Boolean = True
|
||||||
Public Property AutoSingleSelection As Boolean = True
|
Public Property AutoSingleSelection As Boolean = True
|
||||||
@@ -50,9 +49,6 @@ Public Class PaintingControl
|
|||||||
Private pressedControl As Boolean = False
|
Private pressedControl As Boolean = False
|
||||||
Private pressedAlt 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)
|
Private savedPos As New Dictionary(Of PaintingObject, PointF)
|
||||||
|
|
||||||
Public Event SelectionChanged(sender As Object, e As PaintingObjectEventArgs)
|
Public Event SelectionChanged(sender As Object, e As PaintingObjectEventArgs)
|
||||||
@@ -118,10 +114,21 @@ Public Class PaintingControl
|
|||||||
End Property
|
End Property
|
||||||
|
|
||||||
Public Sub New()
|
Public Sub New()
|
||||||
'SetStyle(ControlStyles.Opaque, True) 'For real transparency
|
AddHandler PaintingObjectResizing.CheckEnabled, AddressOf PaintingObjectResizing_CheckEnabled
|
||||||
DoubleBuffered = True
|
DoubleBuffered = True
|
||||||
End Sub
|
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()
|
Private Sub ResetAllBufferedImages()
|
||||||
For Each ob As PaintingObject In PaintingObjects
|
For Each ob As PaintingObject In PaintingObjects
|
||||||
ob.ResetImageBuffer()
|
ob.ResetImageBuffer()
|
||||||
@@ -129,7 +136,7 @@ Public Class PaintingControl
|
|||||||
Refresh()
|
Refresh()
|
||||||
End Sub
|
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
|
pressedShift = e.Shift
|
||||||
pressedControl = e.Control
|
pressedControl = e.Control
|
||||||
pressedAlt = e.Alt
|
pressedAlt = e.Alt
|
||||||
@@ -141,7 +148,7 @@ Public Class PaintingControl
|
|||||||
End Get
|
End Get
|
||||||
End Property
|
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))
|
For Each obj As PaintingObject In GetObjects(New Point(e.X + Offset.X, e.Y + Offset.Y))
|
||||||
If Not obj.MouseTransparency Then
|
If Not obj.MouseTransparency Then
|
||||||
obj.RaiseMouseClick(GetMouseEventArgs(e, obj))
|
obj.RaiseMouseClick(GetMouseEventArgs(e, obj))
|
||||||
@@ -149,7 +156,7 @@ Public Class PaintingControl
|
|||||||
Next
|
Next
|
||||||
End Sub
|
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)
|
lastMousePos = New Point(e.X + Offset.X, e.Y + Offset.Y)
|
||||||
|
|
||||||
curObjMouseDown = GetObjects(lastMousePos).Where(Function(n) Not n.MouseTransparency).LastOrDefault
|
curObjMouseDown = GetObjects(lastMousePos).Where(Function(n) Not n.MouseTransparency).LastOrDefault
|
||||||
@@ -225,7 +232,7 @@ Public Class PaintingControl
|
|||||||
Public Sub RaiseSelectionChanged()
|
Public Sub RaiseSelectionChanged()
|
||||||
RaiseEvent SelectionChanged(Me, New PaintingObjectEventArgs(SelectedObjects))
|
RaiseEvent SelectionChanged(Me, New PaintingObjectEventArgs(SelectedObjects))
|
||||||
End Sub
|
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
|
If _IsAreaSelecting Then
|
||||||
_IsAreaSelecting = False
|
_IsAreaSelecting = False
|
||||||
End If
|
End If
|
||||||
@@ -252,7 +259,7 @@ Public Class PaintingControl
|
|||||||
RaiseEvent AfterScrollingDone(Me, New EventArgs)
|
RaiseEvent AfterScrollingDone(Me, New EventArgs)
|
||||||
End If
|
End If
|
||||||
End Sub
|
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
|
If _IsAreaSelecting OrElse _IsMovingObjects Then
|
||||||
lastMousePos = New Point(e.X + Offset.X, e.Y + Offset.Y)
|
lastMousePos = New Point(e.X + Offset.X, e.Y + Offset.Y)
|
||||||
End If
|
End If
|
||||||
@@ -648,6 +655,8 @@ Public Class PaintingControl
|
|||||||
Dim val As Single = e.Delta / 120 / 10
|
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))
|
ZoomFactor = New SizeF(Math.Max(ZoomFactor.Width + val, 0.25), Math.Max(ZoomFactor.Height + val, 0.25))
|
||||||
Refresh()
|
Refresh()
|
||||||
|
Else
|
||||||
|
'...
|
||||||
End If
|
End If
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,15 @@
|
|||||||
Imports System.Drawing
|
Imports System.Drawing
|
||||||
|
Imports System.Runtime.CompilerServices
|
||||||
Imports System.Windows.Forms
|
Imports System.Windows.Forms
|
||||||
|
|
||||||
Imports Newtonsoft.Json
|
Imports Newtonsoft.Json
|
||||||
|
|
||||||
Imports Pilz.Drawing
|
Imports Pilz.Drawing
|
||||||
|
|
||||||
<Serializable> Friend Class PaintingObjectResizing
|
<Serializable> Friend Class PaintingObjectResizing
|
||||||
|
|
||||||
|
Public Shared Event CheckEnabled(sender As PaintingObjectResizing, ByRef enabled As Boolean)
|
||||||
|
|
||||||
Private WithEvents mObj As PaintingObject
|
Private WithEvents mObj As PaintingObject
|
||||||
Private WithEvents mObjParent As Control = Nothing
|
Private WithEvents mObjParent As Control = Nothing
|
||||||
Private WithEvents mObjControl As Control = Nothing
|
Private WithEvents mObjControl As Control = Nothing
|
||||||
@@ -35,13 +40,23 @@ Imports Pilz.Drawing
|
|||||||
End Get
|
End Get
|
||||||
End Property
|
End Property
|
||||||
|
|
||||||
|
Public ReadOnly Property PaintingObject As PaintingObject
|
||||||
|
Get
|
||||||
|
Return mObj
|
||||||
|
End Get
|
||||||
|
End Property
|
||||||
|
|
||||||
Public Sub New(obj As PaintingObject)
|
Public Sub New(obj As PaintingObject)
|
||||||
mObj = obj
|
mObj = obj
|
||||||
mObjControl = mObj.Parent
|
mObjControl = mObj.Parent
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
Shared Function ApplyToControl(obj As PaintingObject) As PaintingObjectResizing
|
Private Function IsEnabled() As Boolean
|
||||||
Return New PaintingObjectResizing(obj)
|
Dim enabled = Me.Enabled
|
||||||
|
|
||||||
|
RaiseEvent CheckEnabled(Me, enabled)
|
||||||
|
|
||||||
|
Return enabled
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
Private Sub mControl_MouseDown(sender As Object, e As MouseEventArgs) Handles mObj.MouseDown
|
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 setToNone As Boolean = False
|
||||||
Dim isOnTop As Boolean = mObj.Parent.GetObject(New PointF(realX, realY), True) Is mObj
|
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
|
Select Case True
|
||||||
Case HelpfulDrawingFunctions.IsPointInRectangle(eLocation, New Rectangle(newRect.X, newRect.Y, newRect.Width, newRect.Height))
|
Case HelpfulDrawingFunctions.IsPointInRectangle(eLocation, New Rectangle(newRect.X, newRect.Y, newRect.Width, newRect.Height))
|
||||||
mObj.Cursor = Cursors.SizeNWSE
|
mObj.Cursor = Cursors.SizeNWSE
|
||||||
|
|||||||
Reference in New Issue
Block a user