Drag.DragPicture

Hi all, having some real trouble sussing out how to draw a picture to represent the selected rows being dragged from a listbox. I’m iterating through the selected rows in the listbox and creating a picture that when inspected using breaks, is being created correctly. I’m using drag.additem to add items to the drag and then using drag.dragPicture = p

Sadly, I keep getting the last selected entry in the listbox repeated for each row - what am I missing!?!?

I seem to remember that there was a bug with for multiple drag items. This one? <https://xojo.com/issue/63255>

Hi Beatrix, yes, absolutely. Got around it by passing a joined string as the drag item and then splitting it in the dropItem event, therefore only having to generate one picture. Workaround, but sort of gets me around the issue. But definitely a bug.

Do you know Beatrix, if there’s a way to make the dragPicture HiDPI? Can’t seem to suss that either! Always seems lo-resolution 72dpi.

Many thanks,
Dave.

Never got a HiDPI drag item working.

Also the Xojo IDE itself doesn’t. @Greg_O_Lone
<https://xojo.com/issue/58092>

Better stop driving myself nuts by trying then! Thank you both.

Although, just ran this and it appears to work…

#Pragma unused row

var sF As Integer = me.TrueWindow.ScaleFactor

var backC As Color = getSystemHighlightColour

var backgroundBrightness As Integer = Sqrt(backC.Red^20.299 + backC.Green^20.587 + backC.Blue^2*0.114)

var textColour As Color

if backgroundBrightness < 155 Then
textColour = RGB(255,255,255)
Else
textColour = RGB(0,0,0)
End

var p As New Picture((me.ColumnAt(0).WidthActual + me.ColumnAt(1).WidthActual)sf, (me.RowHeightsf))

p.Graphics.AntiAliased = True
p.Graphics.AntiAliasMode = Graphics.AntiAliasModes.HighQuality
p.VerticalResolution = 72sf
p.HorizontalResolution = 72
sf
p.Graphics.DrawingColor = backC
p.Graphics.FillRectangle(0,0,p.Width,p.Height)

p.Graphics.DrawingColor = textColour

p.Graphics.Bold = me.Bold
p.Graphics.FontName = me.FontName
p.Graphics.FontSize = me.FontSize*sf

var yy As Integer = p.Graphics.textascent + (p.Height-p.Graphics.textheight)\2

if me.SelectedRowCount > 1 Then
p.Graphics.DrawText Format(me.SelectedRowCount, “####”) + " items.", 3sf, yy
Else
p.Graphics.DrawText “1 item.”, 3
sf, yy
End

var selectedRowsArray(-1) As String

For i As Integer = 0 To me.RowCount-1
if me.Selected(i) = True Then
selectedRowsArray.Append me.CellValueAt(i,0)
End
Next

drag.Text = Join(selectedRowsArray, EndOfLine)

Drag.DragPicture = p

Return True

Also, apologies, I haven’t quite sussed out how to copy and paste text so it’s coloured like in the IDE…

You haven’t tried our InstallDragImageMBS function?
It allows you to pass an image with SetNextDragImageMBS function to be used for next drag & drop.
This way you can pass the real picture to the plugin and have it pass it to the OS bypassing the one you pass via Xojo.

Highlight (i.e., select) the text you want to show as code. Then click the </> button.

Oh! That sounds interesting, I’ll take a look - thanks Christian.

Ah I see! Thanks Tim!

I never got that to work. There is no difference I can see on a Retina screen:

Code:

Dim DragPicture As New Picture(email_envelope.Width, email_envelope.Height)
DragPicture.Graphics.DrawPicture(email_envelope, 0, 0)

if self.ScaleFactor > 1 then
  dim ni as new NSImageMBS(DragPicture)
  ni.setSize(email_envelope.Width, email_envelope.Height)
  SetNextDragImageMBS(ni)
end if

Dim theDragItem As New DragItem(Self.TrueWindow, MouseX, MouseY, DragPicture.Width, DragPicture.Height)
theDragItem.rawData("MAXX") = DragRecIDs
theDragItem.DragPicture = DragPicture
theDragItem.Drag

Ah, that broke, when Xojo moved to newer Drag & Drop API.

But I could adapt the plugin.

Yes, please.

Okay. Will come with next pre-release.

1 Like

Great, going to test ASAP.