#transform #confusion-matrix
Вопрос:
Я могу перемещать или изменять размер объектов, и будут найдены прямоугольники с маркерами перетаскивания. После поворота объекта с помощью преобразования матрицы ручки захвата перемещаются, но фактическое положение ручек остается прежним. Как обновить расположение прямоугольников ручки захвата после поворота? Вот код, который рисует прямоугольники ручки перетаскивания
Public Sub DrawSelectedObject(ByVal g As Graphics, ByVal selectedObject As GraphicObjects, ByVal Scale As Single)
If selectedObject Is Nothing Then
Exit Sub
End If
Dim gCon1, gCon2 As Drawing2D.GraphicsContainer
gCon1 = g.BeginContainer
g.ScaleTransform(Scale, Scale,
Drawing.Drawing2D.MatrixOrder.Append)
gCon2 = g.BeginContainer
g.PageUnit = GraphicsUnit.Pixel
If Not selectedObject Is Nothing Then
Dim selectionPen As New Pen(Color.FromKnownColor(KnownColor.Black))
selectionPen.DashStyle = Drawing2D.DashStyle.Solid
selectionPen.Width = 1
Dim GrabHandleBrush As Brush = New SolidBrush(Color.Black)
Dim HandlePen As New Pen(Color.FromKnownColor(KnownColor.Black))
If selectedObject.Rotation <> 0 Then
Dim myMatrix As Drawing2D.Matrix
myMatrix = g.Transform()
myMatrix.RotateAt(selectedObject.Rotation, New PointF(selectedObject.X, selectedObject.Y), Drawing.Drawing2D.MatrixOrder.Append)
g.Transform = myMatrix
'RotatedBitmap = RotateImage(selectedObject.Image, selectedObject.Rotation)
End If
DragRectangleF = New RectangleF(selectedObject.X, selectedObject.Y, selectedObject.Width, selectedObject.Height)
Dim RectHeight As Integer = 8
If selectedObject.Height < 50 Then
RectHeight = 4
ElseIf selectedObject.Height < 25 Then
RectHeight = 2
End If
Drag_Handles(0) = New RectangleF(DragRectangleF.X - RectHeight / 2, DragRectangleF.Y - RectHeight / 2, RectHeight, RectHeight)
Drag_Handles(1) = New RectangleF(DragRectangleF.X DragRectangleF.Width / 2 - RectHeight / 2, DragRectangleF.Y - RectHeight / 2, RectHeight, RectHeight)
Drag_Handles(2) = New RectangleF(DragRectangleF.X DragRectangleF.Width - RectHeight / 2, DragRectangleF.Y - RectHeight / 2, RectHeight, RectHeight)
Drag_Handles(3) = New RectangleF(DragRectangleF.X DragRectangleF.Width - RectHeight / 2, DragRectangleF.Y DragRectangleF.Height / 2 - RectHeight / 2, RectHeight, RectHeight)
Drag_Handles(4) = New RectangleF(DragRectangleF.X DragRectangleF.Width - RectHeight / 2, DragRectangleF.Y DragRectangleF.Height - RectHeight / 2, RectHeight, RectHeight)
Drag_Handles(5) = New RectangleF(DragRectangleF.X DragRectangleF.Width / 2 - RectHeight / 2, DragRectangleF.Y DragRectangleF.Height - RectHeight / 2, RectHeight, RectHeight)
Drag_Handles(6) = New RectangleF(DragRectangleF.X - RectHeight / 2, DragRectangleF.Y DragRectangleF.Height - RectHeight / 2, RectHeight, RectHeight)
Drag_Handles(7) = New RectangleF(DragRectangleF.X - RectHeight / 2, DragRectangleF.Y DragRectangleF.Height / 2 - RectHeight / 2, RectHeight, RectHeight)
'last 2 drag handles are for rotating object
Drag_Handles(8) = New RectangleF(DragRectangleF.X DragRectangleF.Width - RectHeight / 2, DragRectangleF.Y 10, RectHeight, RectHeight)
Drag_Handles(9) = New RectangleF(DragRectangleF.X DragRectangleF.Width - RectHeight / 2, DragRectangleF.Y DragRectangleF.Height - 20, RectHeight, RectHeight)
g.DrawRectangle(New Pen(Color.Gray), DragRectangleF.X, DragRectangleF.Y, DragRectangleF.Width, DragRectangleF.Height)
g.FillRectangles(Brushes.Gray, Drag_Handles)
g.DrawRectangles(Pens.Black, Drag_Handles)
Dim RotationDragHandle As New RectangleF()
RotationDragHandle = Drag_Handles(8)
g.FillRectangle(Brushes.YellowGreen, RotationDragHandle)
Dim RotationDragHandle1 As New RectangleF()
RotationDragHandle1 = Drag_Handles(9)
g.FillRectangle(Brushes.YellowGreen, RotationDragHandle1)
End If
g.EndContainer(gCon2)
g.EndContainer(gCon1)
End Sub
Вот код, который ищет прямоугольники ручки захвата, расположенные в подпроцедуре Перемещения мыши
Dim tmprect As RectangleF
Dim i As Integer = 0
Dim R As New RectangleF
gobjc.LoadDrag_Handles()
Dim OffSetX As Single = 0
Dim OffSetY As Single = 0
For Each tmprect In gobjc.Drag_Handles
If tmprect.Contains(e.X / Zoom, e.Y / Zoom) Then
MouseInRect = True
ActiveDrag = i
SetDragCursor()
Invalidate()
Return
End If
i = 1
Next
If gobjc.DragRectangleF.Contains(e.X / Zoom, e.Y / Zoom) Then
MouseInRect = True
Cursor = Cursors.Hand
Invalidate()
Return
End If
Комментарии:
1. Я работаю с Microsoft над этим, я добавил картинку по их просьбе. Также они хотели знать тип spp его фреймворк Windows Form 4.6.1. Я опубликую результаты, когда вернусь от них.