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
if ( (appDropZoneHook = AllocSysObjectTags(ASOT_HOOK, ASOHOOK_Entry, appDropZone_hook, ASOHOOK_Data, NULL, TAG_END)) ) { GetAttr(WINDOW_AppWindowPtr,objects[OID_MAIN],(uint32 *)&windowZone) ; if ( (dropZone = AddAppWindowDropZone((struct AppWindow *)windowZone,1,0, WBDZA_Left,0, WBDZA_Top, 0, WBDZA_Width, windows->Width, WBDZA_Height, windows->Height, WBDZA_Hook, appDropZone_hook, TAG_END)) ) { printf("dropZone OK \n"); } else printf("dropZone KO \n"); } //end if appMessageDropZoneHook LONG appDropZone_hook(struct Hook *hook, APTR reserved, struct AppWindowDropZoneMsg *adzm) { printf("windows->MouseX (%d) windows->MouseY (%d) \n",windows->MouseX,windows->MouseY) ; return 0 ; }
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
"or use the rastport to draw something into your window."
Many thanks Thomas (again) for your help and your sample. It works great !
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 ?
I tried to use GA_Selected inside the hook but as the AutoDocs stated, complex drawing freeze the system.
Thank you
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
Thank you Javier but if the state of the picture is changed inside the hool, it will crashs too I guess.
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.
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)
"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...
You could make a seperate drop zone for each icon.
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.
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.
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.
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.
"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
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.
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.
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.
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...
with ICONDRAWA_EraseBackground, FALSE,
with ICONDRAWA_EraseBackground, TRUE,
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.
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.
Finally solved simply by updating my BackFill before the second DrawIconState(IDS_NORMAL) !