Page 1 of 1
Canvasgadget + drag n drop
Posted: Wed Jul 24, 2013 12:11 pm
by captain_skank
Is it possible to drag and drop a canvas gadget ??
I don't think it is but am more than happy to be proved wrong
Cheers
Re: Canvasgadget + drag n drop
Posted: Wed Jul 24, 2013 4:19 pm
by davido
I use drag/drop on canvas gadgets a lot:
A little demo to show dragging text to a canvas gadget.
I hope I have read your request correctly.
Code: Select all
If OpenWindow(0, 100, 200, 195, 260, "PureBasic Window", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
CanvasGadget(0,10,10,100,100)
EnableGadgetDrop(0,#PB_Drop_Text,#PB_Drag_Copy)
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_GadgetDrop
Select EventGadget()
Case 0
Debug EventDropText()
EndSelect
EndIf
If Event = #PB_Event_CloseWindow ; If the user has pressed on the close button
Quit = 1
EndIf
Until Quit = 1
EndIf
End
Re: Canvasgadget + drag n drop
Posted: Wed Jul 24, 2013 4:21 pm
by TI-994A
captain_skank wrote:Is it possible to drag and drop a canvas gadget ??
Hello captain_skank. I'm not absolutely sure what you mean by
drag & drop a canvas gadget, but this example simulates a drag&drop functionality for a CanvasGadget():
Code: Select all
EnableExplicit
InitNetwork()
Enumeration
#MainWindow
#Canvas
#Image
EndEnumeration
Define wFlags, appQuit, dragOn, canvasMouseXOffset, canvasMouseYOffset
If ReceiveHTTPFile("https://dl.dropboxusercontent.com/u/38177172/CS.bmp",
GetTemporaryDirectory() + "CS.bmp")
LoadImage(#Image, GetTemporaryDirectory() + "CS.bmp")
wFlags = #PB_Window_SystemMenu |#PB_Window_ScreenCentered
OpenWindow(#MainWindow, #PB_Any, #PB_Any, 640, 480, "Drag&Drop CanvasGadget", wFlags)
CanvasGadget(#Canvas, 10, 10, 200, 205, #PB_Canvas_Border)
SetGadgetAttribute(#Canvas, #PB_Canvas_Image, ImageID(#Image))
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
appQuit = 1
Case #PB_Event_Gadget
Select EventGadget()
Case #Canvas
Select EventType()
Case #PB_EventType_LeftButtonDown
dragOn = 1
canvasMouseXOffset = GetGadgetAttribute(#Canvas, #PB_Canvas_MouseX)
canvasMouseYOffset = GetGadgetAttribute(#Canvas, #PB_Canvas_MouseY)
Case #PB_EventType_LeftButtonUp
dragOn = 0
Case #PB_EventType_MouseMove
If dragOn
ResizeGadget(#Canvas, WindowMouseX(#MainWindow) - canvasMouseXOffset,
WindowMouseY(#MainWindow) - canvasMouseYOffset, #PB_Ignore, #PB_Ignore)
EndIf
EndSelect
EndSelect
EndSelect
Until appQuit = 1
EndIf
Hope you like the image.

Re: Canvasgadget + drag n drop
Posted: Wed Jul 24, 2013 4:35 pm
by davido
Hi TI-994A,
I thought my reply was a little naïve.
I think that your's is better.
A very nice demo by the way.
Also see:
http://www.purebasic.fr/english/viewtop ... 13&t=54098
Re: Canvasgadget + drag n drop
Posted: Wed Jul 24, 2013 5:07 pm
by TI-994A
Hi davido, and thank you. A working example to someone who's not familiar with the functionality is never naive. I've always known it's there, but I've never had a chance to use PureBasic's Drag&Drop functions; very interesting. Thanks for the example, and the link too.
Re: Canvasgadget + drag n drop
Posted: Thu Jul 25, 2013 6:30 am
by coder14
Nice TI. Clever choice of image.

Re: Canvasgadget + drag n drop
Posted: Thu Jul 25, 2013 8:47 am
by captain_skank
Thanks guys - some nice code there.
It's not quite what I was after but has given me an idea how to acheive my end result - so thanks again.
cheers
Re: Canvasgadget + drag n drop
Posted: Sat Jul 27, 2013 10:50 pm
by netmaestro
Based on the assumption that what you want to do is drag the
image from the canvas to somewhere else, could you see if this might serve:
Code: Select all
; drag the red box from the canvas to the imagegadget
CreateImage(0, 64,64,24, #Black)
CreateImage(1, 64,64,24, #Red)
OpenWindow(1, 0, 0, 300, 100, "Drag & Drop", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
CanvasGadget(0, 20,10,64,64)
SetGadgetAttribute(0, #PB_Canvas_Image, ImageID(1))
ImageGadget(1, 200, 10, 64, 64, ImageID(0))
EnableGadgetDrop(1, #PB_Drop_Image, #PB_Drag_Copy|#PB_Drag_Move)
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget And EventGadget() = 0 And EventType() = #PB_EventType_LeftButtonDown
DragImage(ImageID(1))
EndIf
If Event = #PB_Event_GadgetDrop And EventGadget() = 1
SetGadgetState(EventGadget(), EventDropImage(2))
EndIf
Until Event = #PB_Event_CloseWindow