[Solved] How to detect when an icon is dragging (not dropped) over a window ?

22 posts / 0 new
Last post
zzd10h
zzd10h's picture
Offline
Last seen: 2 years 8 months ago
Joined: 2012-08-24 20:56
[Solved] How to detect when an icon is dragging (not dropped) over a window ?
Hi, Is somebody could give me advices about the following question ? I don't have problem to detect a dropped icon on my window with WINDOW_AppMsgHook but I would like to detect when a icon is dragging over my window (without to be dropped). Is it possible ? I tried to use a DropZone but as soon that I add a WBDZA_Hook, OS freezes when a icon is dragged in my window. DropZone is well created but certainly that I misuse it... Is a DropZone with WBDZA_Hook could help me ? Thank you for your help (I will post too on Hyperion forum) Sample based on SDK:Examples/GUI/Window/AppWindow.c http://www.indiego.rocks/file/download/d605baa46913966e9519a21c0ad04cc6
  1. if ( (appDropZoneHook = AllocSysObjectTags(ASOT_HOOK,
  2. ASOHOOK_Entry, appDropZone_hook,
  3. ASOHOOK_Data, NULL,
  4. TAG_END)) )
  5. {
  6.  
  7. GetAttr(WINDOW_AppWindowPtr,objects[OID_MAIN],(uint32 *)&windowZone) ;
  8.  
  9. if ( (dropZone = AddAppWindowDropZone((struct AppWindow *)windowZone,1,0,
  10. WBDZA_Left,0,
  11. WBDZA_Top, 0,
  12. WBDZA_Width, windows->Width,
  13. WBDZA_Height, windows->Height,
  14. WBDZA_Hook, appDropZone_hook,
  15. TAG_END)) )
  16. {
  17. printf("dropZone OK \n");
  18. }
  19. else
  20. printf("dropZone KO \n");
  21.  
  22. } //end if appMessageDropZoneHook
  23.  
  24. LONG appDropZone_hook(struct Hook *hook, APTR reserved, struct AppWindowDropZoneMsg *adzm)
  25. {
  26. printf("windows->MouseX (%d) windows->MouseY (%d) \n",windows->MouseX,windows->MouseY) ;
  27.  
  28. return 0 ;
  29. }
thomas
thomas's picture
Offline
Last seen: 1 day 7 hours ago
Joined: 2011-05-16 14:23
Re: How to detect when an icon is dragging (not dropped) over...
I am quite sure that printf is the culprit. The hook function is run by Workbench but printf depends on the runtime environment of your program. Hooks in most cases are called by system tasks and cannot use your program's runtime routines. And of course they cannot depend on data which is only valid in your process, like current dir, stdin, stdout and so on. You should use kprintf instead to get serial debug output or use the rastport to draw something into your window. Here is a working example (it does not use ReAction, though): http://thomas-rapp.homepage.t-online.de/examples/dropzone.c
zzd10h
zzd10h's picture
Offline
Last seen: 2 years 8 months ago
Joined: 2012-08-24 20:56
Re: How to detect when an icon is dragging (not dropped) over...
"or use the rastport to draw something into your window." Many thanks Thomas (again) for your help and your sample. It works great !
zzd10h
zzd10h's picture
Offline
Last seen: 2 years 8 months ago
Joined: 2012-08-24 20:56
Re: How to detect when an icon is dragging (not dropped) over...
It took me some reboots to find that "AllocSysObjectTags(ASOT_HOOK" make crashs this hook. Taking your "appDropZoneHook.h_Entry = (HOOKFUNC)appDropZone_hook;" solves this problem. Finally all work fine but do you have an idea how to highlight an icon when a workbench object is dragging over it ? IMAGE(http://zzd10h.amiga-ng.org/Divers/FastView_Capture_T151206_192346.jpg) I tried to use GA_Selected inside the hook but as the AutoDocs stated, complex drawing freeze the system.
  1. ULONG appDropZone_hook(struct Hook *hook,APTR reserved,struct AppWindowDropZoneMsg *adzm)
  2. {
  3. draw_area (adzm->adzm_RastPort,&adzm->adzm_DropZoneBox,adzm->adzm_Action == ADZMACTION_Enter);
  4.  
  5.  
  6. /* if (adzm->adzm_Action == ADZMACTION_Enter)
  7. SetGadgetAttrs((struct Gadget *)(button[adzm->adzm_ID]),window, NULL,GA_Selected, TRUE,TAG_END);
  8.   else
  9. SetGadgetAttrs((struct Gadget *)(button[adzm->adzm_ID]),window, NULL,GA_Selected, FALSE,TAG_END);
  10. */
  11. return (0);
  12. }
Thank you
jabirulo
jabirulo's picture
Offline
Last seen: 1 month 1 week ago
Joined: 2013-05-30 00:53
Re: How to detect when an icon is dragging (not dropped) over...
Hi, don't know if it will crash/not-work too, but what about change the whole icon/image with a previously faded/opaqueness one (that you stored in memory/array)? So you can use the Selected image for the user to know it dropped an icon and the faded/opaqueness to notice the user's pointer is over it.
AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P
zzd10h
zzd10h's picture
Offline
Last seen: 2 years 8 months ago
Joined: 2012-08-24 20:56
Re: How to detect when an icon is dragging (not dropped) over...
Thank you Javier but if the state of the picture is changed inside the hool, it will crashs too I guess.
tboeckel
tboeckel's picture
Offline
Last seen: 4 weeks 1 day ago
Joined: 2011-09-13 12:32
Re: How to detect when an icon is dragging (not dropped) over...
Let your hook send a signal or a message to your main application to do the actual render work. This might defer the actual rendering for a few milliseconds, but it takes the complex rendering operation outside the hook's context.
zzd10h
zzd10h's picture
Offline
Last seen: 2 years 8 months ago
Joined: 2012-08-24 20:56
Re: How to detect when an icon is dragging (not dropped) over...
Thank you Thore for your advice, I just tried to send an ApplicationMessage to my program inside the hook but it is processed only when left mouse button is released. I will try to send a signal or a message this evening (but without hope to much)
zzd10h
zzd10h's picture
Offline
Last seen: 2 years 8 months ago
Joined: 2012-08-24 20:56
Re: How to detect when an icon is dragging (not dropped) over...
"I will try to send a signal or a message this evening (but without hope to much)" Unfortunately, Signal() is processed too only when LMB is released. I wonder how AmiDock do that when an icon is dragged over a button...
thomas
thomas's picture
Offline
Last seen: 1 day 7 hours ago
Joined: 2011-05-16 14:23
Re: How to detect when an icon is dragging (not dropped) over...
You could make a seperate drop zone for each icon.
zzd10h
zzd10h's picture
Offline
Last seen: 2 years 8 months ago
Joined: 2012-08-24 20:56
Re: How to detect when an icon is dragging (not dropped) over...
Yes Thomas, I still have a different drop zone for each icon, each adzm_ID is different when i drop a file on a icon. The problem is that this adzm_ID is trapped by my main event loop when the LMB is released.
thomas
thomas's picture
Offline
Last seen: 1 day 7 hours ago
Joined: 2011-05-16 14:23
Re: How to detect when an icon is dragging (not dropped) over...
Your example does not check for AMTYPE_APPWINDOWZONE messages. The documentation of AddAppWindowDropZone says that once you have a drop zone, you'll no longer receive AMTYPE_APPWINDOW messages but only AMTYPE_APPWINDOWZONE messages.
zzd10h
zzd10h's picture
Offline
Last seen: 2 years 8 months ago
Joined: 2012-08-24 20:56
Re: How to detect when an icon is dragging (not dropped) over...
Yes, thank you, i tried that too but the main problem is that the program (main event loop) doesn't receive any messages/signals until LMB is released.
thomas
thomas's picture
Offline
Last seen: 1 day 7 hours ago
Joined: 2011-05-16 14:23
Re: How to detect when an icon is dragging (not dropped) over...
Why should it and where do you believe should this message come from? The drop zone hook is called whenever the mouse pointer enters or leaves a drop zone. The app port gets a message when an icon is dropped. There are no other messages/signals while the window is inactive.
zzd10h
zzd10h's picture
Offline
Last seen: 2 years 8 months ago
Joined: 2012-08-24 20:56
Re: How to detect when an icon is dragging (not dropped) over...
"Your example does not check for AMTYPE_APPWINDOWZONE messages." I thought that you spotted that my problem of picture refresh could come from the lack of message checking
thomas
thomas's picture
Offline
Last seen: 1 day 7 hours ago
Joined: 2011-05-16 14:23
Re: How to detect when an icon is dragging (not dropped) over...
Perhaps you should once again describe your problem precisely. I really don't see what it is. BTW, this was the first time you used the word "refresh" in this thread.
zzd10h
zzd10h's picture
Offline
Last seen: 2 years 8 months ago
Joined: 2012-08-24 20:56
Re: How to detect when an icon is dragging (not dropped) over...
By "refresh" I meant change the button (a .info icon picture) selected state. My problem is that I have a sort of Dock with buttons. If I drag a workbench icon (RAM: volume icon for example) over the button of the Dock without releasing left mouse button, I would like to change the selected state of the button where my mouse is. The hook sample that you made works great but when I use SetGadgetAttrs((struct Gadget *)(button[adzm->adzm_ID]),window, NULL,GA_Selected, FALSE,TAG_END); to change the selected representation of the button it crashs (as stated in the AutoDocs). As it fails, I tried to send Signal/Messages to my main program but there are not processed until LMB is released. Sorry if I was not enough clear before.
thomas
thomas's picture
Offline
Last seen: 1 day 7 hours ago
Joined: 2011-05-16 14:23
Re: How to detect when an icon is dragging (not dropped) over...
It shouldn't crash, it should deadlock. SetGadgetAttrs holds an internal lock. If it is an icon you could use DrawIconState. If it needs to be an icon, you could use SetAttrs instead of SetGadgetAttrs and then do the GM_RENDER method manually (DoMethod (object,GM_RENDER,NULL,RastPort,GREDRAW_TOGGLE); see struct gpRender). Hopefully it does not need a GadgetInfo.
zzd10h
zzd10h's picture
Offline
Last seen: 2 years 8 months ago
Joined: 2012-08-24 20:56
Re: How to detect when an icon is dragging (not dropped) over...
You are right, it's a freeze not a simple crash. Following your advice, it's far better, no more freeze and overall the icons are selected when I drag objects over them, many thanks again :) Now, my problem is that my background alphamap is not refreshed when an icon change from Selected to Normal, the yellow bordering halo is kept drawed. If I use ICONDRAWA_EraseBackground, TRUE, the yellow halo is erased but my Alpha background is no more transparent...
  1. struct DiskObject *iconProgramme;
  2.  
  3. iconProgramme = GetIconTags(tab_program[index],
  4. ICONGETA_FailIfUnavailable, FALSE,
  5. ICONGETA_UseFriendBitMap, TRUE,
  6. ICONGETA_GetPaletteMappedIcon, TRUE,
  7. ICONGETA_Width,ICON_SIZE,
  8. ICONGETA_Height,ICON_SIZE,
  9. ICONGETA_ForceScaling, icon_scaling,
  10. ICONGETA_AllowUpscaling, icon_scaling,
  11. TAG_END ) ;
  12.  
  13. GetAttrs((struct Gadget *)(button[index]),GA_Left, &left);
  14. GetAttrs((struct Gadget *)(button[index]),GA_Top, &top);
  15.  
  16. if (adzm->adzm_Action == ADZMACTION_Enter)
  17. {
  18.  
  19. DrawIconState(adzm->adzm_RastPort, iconProgramme, NULL, left,top, IDS_SELECTED,
  20. ICONDRAWA_EraseBackground, FALSE,
  21. ICONDRAWA_Frameless, TRUE,
  22. ICONDRAWA_Borderless, TRUE,
  23. TAG_DONE);
  24. }
  25. else
  26. {
  27. DrawIconState(adzm->adzm_RastPort, iconProgramme, NULL, left,top , IDS_NORMAL,
  28. ICONDRAWA_EraseBackground, FALSE,
  29. ICONDRAWA_Frameless, TRUE,
  30. ICONDRAWA_Borderless, TRUE,
  31. TAG_DONE);
  32.  
  33. }
  34.  
  35. if (iconProgramme)
  36. FreeDiskObject(iconProgramme) ;
with ICONDRAWA_EraseBackground, FALSE, IMAGE(http://www.indiego.rocks/file/download/40462a97719b2af3352954a33734db66) with ICONDRAWA_EraseBackground, TRUE, IMAGE(http://www.indiego.rocks/file/download/56df2269b03d1701f5583a6e1c0cc4e4)
thomas
thomas's picture
Offline
Last seen: 1 day 7 hours ago
Joined: 2011-05-16 14:23
Re: How to detect when an icon is dragging (not dropped) over...
Please define alphamap. Do you mean your window is transparent? Then you have to copy the new alpha data into the bitmap used by WA_AlphaClips and call ChangeLayerAlpha.
zzd10h
zzd10h's picture
Offline
Last seen: 2 years 8 months ago
Joined: 2012-08-24 20:56
Re: How to detect when an icon is dragging (not dropped) over...
Yes, my window is transparent but even when no transparent (only colored by a WA_BackFill hook or with an pattern with a WINDOW_BackFillName), the icon background is the same. But thank you for all your advices, it's very complex for me but instructive.
zzd10h
zzd10h's picture
Offline
Last seen: 2 years 8 months ago
Joined: 2012-08-24 20:56
Re: [Solved] How to detect when an icon is dragging (not...
Finally solved simply by updating my BackFill before the second DrawIconState(IDS_NORMAL) !
Log in or register to post comments