This commit is contained in:
2019-09-30 16:18:53 +02:00
parent 7d884d7cba
commit 53f2a0666b
70 changed files with 2984 additions and 197 deletions

View File

@@ -143,20 +143,18 @@ Public Class DefaultDrawMethodes
Public Shared Sub DrawTriangle(e As PaintingObjectPaintEventArgs)
Dim obj As PaintingObject = e.PaintingObject
Dim p1 As New Point(obj.Size.Width / 2 + e.X, e.Y)
Dim p2 As New Point(e.X, e.Y + obj.Size.Height)
Dim p3 As New Point(e.X + obj.Size.Width, e.Y + obj.Size.Height)
If obj.EnableFill Then
Dim b As New SolidBrush(obj.FillColor)
Dim p1 As New Point(obj.Size.Width / 2 + e.X, e.Y)
Dim p2 As New Point(e.X, e.Y + obj.Size.Height)
Dim p3 As New Point(e.X + obj.Size.Width, e.Y + obj.Size.Height)
e.Graphics.FillPolygon(b, {p1, p2, p3})
End If
If obj.EnableOutline Then
Dim lw As Single = obj.OutlineThicknes
Dim p As New Pen(obj.OutlineColor, obj.OutlineThicknes) With {.DashStyle = obj.OutlineDashStyle, .Alignment = PenAlignment.Inset}
Dim p1 As New Point(obj.Size.Width / 2 + e.X, e.Y)
Dim p2 As New Point(e.X, e.Y + obj.Size.Height)
Dim p3 As New Point(e.X + obj.Size.Width, e.Y + obj.Size.Height)
e.Graphics.DrawPolygon(p, {p1, p2, p3})
End If
End Sub
@@ -225,10 +223,10 @@ Public Class DefaultDrawMethodes
End Sub
Public Shared Sub DrawAreaSelection(e As PaintEventArgs, pc As PaintingControl, startMousePos As PointF, lastMousePos As PointF)
Dim p As New Pen(pc.AreaSelectionColor)
p.DashStyle = DashStyle.DashDot
p.Width = 3
Dim rectToDraw As RectangleF = HelpfulDrawingFunctions.GetRectangle(startMousePos, lastMousePos)
Dim p As New Pen(pc.AreaSelectionColor)
p.DashStyle = If(startMousePos.X >= lastMousePos.X, DashStyle.DashDot, DashStyle.Solid)
p.Width = 3
e.Graphics.DrawRectangle(p, rectToDraw.X, rectToDraw.Y, rectToDraw.Width, rectToDraw.Height)
End Sub

View File

@@ -23,6 +23,8 @@ 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
Public Property AutoMultiselection As Boolean = True
@@ -90,9 +92,10 @@ Public Class PaintingControl
End Get
Set(value As Color)
bgColor = value
If value <> Color.Transparent Then
MyBase.BackColor = value
End If
MyBase.BackColor = value
'If value <> Color.Transparent Then
' MyBase.BackColor = value
'End If
End Set
End Property
Public ReadOnly Property IsAreaSelecting As Boolean
@@ -114,6 +117,7 @@ Public Class PaintingControl
End Property
Public Sub New()
'SetStyle(ControlStyles.Opaque, True) 'For real transparency
DoubleBuffered = True
End Sub
@@ -150,7 +154,7 @@ Public Class PaintingControl
curObjMouseDown = GetObjects(lastMousePos).Where(Function(n) Not n.MouseTransparency).LastOrDefault
curObjMouseDown?.RaiseMouseDown(GetMouseEventArgs(e, curObjMouseDown))
If Not GetSelectedObjects.Contains(curObjMouseDown) Then
If curObjMouseDown Is Nothing OrElse Not curObjMouseDown.Selected OrElse pressedControl Then
Dim hasMovedObjects As Boolean = False
If _IsMovingObjects Then
For Each obj As PaintingObject In GetSelectedObjects()
@@ -164,7 +168,7 @@ Public Class PaintingControl
If (Not hasMovedObjects) AndAlso (Not _IsAreaSelecting) Then
Dim selChanged As New List(Of PaintingObject)
If AutoRemoveSelection AndAlso Not pressedShift Then
If AutoRemoveSelection AndAlso Not pressedControl Then
For Each obj As PaintingObject In PaintingObjects
If obj.Selected Then
obj.SelectedDirect = False
@@ -175,9 +179,9 @@ Public Class PaintingControl
Next
End If
If AutoSingleSelection Then
If AutoSingleSelection AndAlso curObjMouseDown IsNot Nothing Then
Dim objtosel As PaintingObject = curObjMouseDown
If objtosel?.EnableSelection Then
If objtosel.EnableSelection Then
objtosel.SelectedDirect = Not objtosel.Selected
If Not selChanged.Contains(objtosel) Then
selChanged.Add(objtosel)
@@ -418,7 +422,7 @@ Public Class PaintingControl
Get
Dim cp = MyBase.CreateParams
'If EnableFullTransparentBackground Then
'If EnableRealTransparency Then
' cp.ExStyle = cp.ExStyle Or &H20 'WS_EX_TRANSPARENT
'End If
@@ -431,16 +435,14 @@ Public Class PaintingControl
''' </summary>
''' <param name="m"></param>
Protected Overrides Sub WndProc(ByRef m As Message)
Dim WM_NCHITTEST As Integer = &H84
Dim HTTRANSPARENT As Integer = -1
Const WM_NCHITTEST As Integer = &H84
Const HTTRANSPARENT As Integer = -1
'If m.Msg = WM_NCHITTEST Then
' m.Result = CType(HTTRANSPARENT, IntPtr)
'Else
' MyBase.WndProc(m)
'End If
MyBase.WndProc(m)
If Not VisibleForMouseEvents AndAlso m.Msg = WM_NCHITTEST Then
m.Result = CType(HTTRANSPARENT, IntPtr)
Else
MyBase.WndProc(m)
End If
End Sub
Protected Overrides Sub OnPaintBackground(e As PaintEventArgs)
@@ -448,13 +450,13 @@ Public Class PaintingControl
Me.SuspendLayout()
'Draw Background
'If Not EnableRealTransparency Then
MyBase.OnPaintBackground(e)
'End If
End Sub
Protected Overrides Sub OnPaint(e As PaintEventArgs)
'Do default Drawing Methode
MyBase.OnPaint(e)
'Draw PaintingObjects stuff
If StopDrawing Then
e.Graphics.DrawImage(bufferedImg, Point.Empty)
Else
@@ -482,6 +484,9 @@ Public Class PaintingControl
End If
End If
'Do default Drawing Methode
MyBase.OnPaint(e)
'Start Drawing directly to the Form
ResumeLayout(False)
End Sub
@@ -501,53 +506,76 @@ Public Class PaintingControl
Private Function CalcTextSize(obj As PaintingObject) As SizeF
Return CalcTextSize(obj, Parent.CreateGraphics)
End Function
Private Function CalcTextSize(obj As PaintingObject, g As Graphics) As SizeF
Return g.MeasureString(obj.Text, obj.TextFont, obj.Width)
End Function
Private Sub SelectControlsInArea()
Dim rect As RectangleF = HelpfulDrawingFunctions.GetRectangle(startMousePos, lastMousePos)
Dim rect As RectangleF = GetRectangle(startMousePos, lastMousePos)
For Each obj As PaintingObject In PaintingObjects
obj.Selected = HelpfulDrawingFunctions.OverlapsTwoRectangles(obj.Rectangle, rect)
obj.Selected = If(startMousePos.X >= lastMousePos.X,
OverlapsTwoRectangles(obj.Rectangle, rect),
RectangleContainsRectangle(rect, obj.Rectangle))
Next
End Sub
Public Sub ArrangeToGrid(obj As PaintingObject)
Dim zoomedGridChunkSize As New SizeF(GridChunkSize.Width * ZoomFactor.Width, Me.GridChunkSize.Height * ZoomFactor.Height)
Public Sub ArrangeToGrid(obj As PaintingObject, snapPinnedObjects As Boolean)
If snapPinnedObjects OrElse Not IsPinnedObject(obj) Then
Dim zoomedGridChunkSize As New SizeF(GridChunkSize.Width * ZoomFactor.Width, Me.GridChunkSize.Height * ZoomFactor.Height)
Dim modTop As Integer = obj.Y Mod zoomedGridChunkSize.Height
Dim modLeft As Integer = obj.X Mod zoomedGridChunkSize.Width
Dim modTop As Integer = obj.Y Mod zoomedGridChunkSize.Height
Dim modLeft As Integer = obj.X Mod zoomedGridChunkSize.Width
Dim halfHeight As Integer = zoomedGridChunkSize.Height / 2
Dim halfWidth As Integer = zoomedGridChunkSize.Width / 2
Dim halfHeight As Integer = zoomedGridChunkSize.Height / 2
Dim halfWidth As Integer = zoomedGridChunkSize.Width / 2
If modTop > halfHeight Then
obj.Y += (zoomedGridChunkSize.Height - modTop)
Else
obj.Y -= modTop
End If
Dim zoomLocation =
Sub(obj2 As PaintingObject)
If modTop > halfHeight Then
obj2.Y += (zoomedGridChunkSize.Height - modTop)
Else
obj2.Y -= modTop
End If
If modLeft > halfWidth Then
obj.X += (zoomedGridChunkSize.Width - modLeft)
Else
obj.X -= modLeft
End If
If modLeft > halfWidth Then
obj2.X += (zoomedGridChunkSize.Width - modLeft)
Else
obj2.X -= modLeft
End If
End Sub
zoomLocation(obj)
For Each pinned As PaintingObject In obj.PinnedObjects
zoomLocation(pinned)
Next
If obj.EnableResize AndAlso Not obj.HardcodedSize Then
Dim modH As Integer = obj.Height Mod zoomedGridChunkSize.Height
Dim modW As Integer = obj.Width Mod zoomedGridChunkSize.Width
If modH > halfHeight Then
obj.Height += (zoomedGridChunkSize.Height - modH)
Else
obj.Height -= modH
End If
Dim zoomSize =
Sub(obj2 As PaintingObject)
If obj2.EnableResize AndAlso Not obj2.HardcodedSize Then
If modH > halfHeight Then
obj2.Height += (zoomedGridChunkSize.Height - modH)
Else
obj2.Height -= modH
End If
If modW > halfWidth Then
obj.Width += (zoomedGridChunkSize.Width - modW)
Else
obj.Width -= modW
End If
If modW > halfWidth Then
obj2.Width += (zoomedGridChunkSize.Width - modW)
Else
obj2.Width -= modW
End If
End If
End Sub
zoomSize(obj)
For Each pinned As PaintingObject In obj.PinnedObjects
zoomSize(pinned)
Next
End If
End Sub
@@ -564,7 +592,7 @@ Public Class PaintingControl
If GridEnabled Then
For Each obj As PaintingObject In GetSelectedObjects()
If obj.AutoAlignToGrid Then
ArrangeToGrid(obj)
ArrangeToGrid(obj, False)
End If
Next
If Not StopDrawing Then Refresh()

View File

@@ -432,7 +432,7 @@ Imports Newtonsoft.Json
Public Sub ArrangeToGrid()
If Parent IsNot Nothing Then
Parent.ArrangeToGrid(Me)
Parent.ArrangeToGrid(Me, True)
If Not Parent.StopDrawing Then Parent.Refresh()
End If
End Sub

View File

@@ -66,7 +66,6 @@ Imports Pilz.Drawing
End Sub
Private Sub mControl_MouseMove(sender As Object, e As MouseEventArgs) Handles mObjControl.MouseMove
If mMouseDown AndAlso mEdge <> EdgeEnum.None Then
Dim eX As Integer = e.X + mObj.Parent.Offset.X
@@ -97,6 +96,8 @@ Imports Pilz.Drawing
Dim eXo As Integer = e.X
Dim eYo As Integer = e.Y
Dim realX As Integer = eXo + mObj.Parent.Offset.X
Dim realY As Integer = eYo + mObj.Parent.Offset.Y
Dim eXwo As Integer = eXo - mObj.X
Dim eYwo As Integer = eYo - mObj.Y
Dim eX As Integer = eXwo + mObj.Parent.Offset.X
@@ -112,7 +113,7 @@ Imports Pilz.Drawing
newRect.Height = (extRect.Height - oldRect.Height) / 2
Dim setToNone As Boolean = False
Dim isOnTop As Boolean = mObj.Parent.GetObject(New PointF(eXo, eYo), True) Is mObj
Dim isOnTop As Boolean = mObj.Parent.GetObject(New PointF(realX, realY), True) Is mObj
If Enabled AndAlso isOnTop Then
Select Case True

View File

@@ -68,7 +68,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<HintPath>..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="12.0.1" targetFramework="net45" />
<package id="Newtonsoft.Json" version="12.0.2" targetFramework="net45" />
</packages>