Page 1 of 1

help with returning image events

Posted: Mon Nov 24, 2003 3:31 pm
by localmotion34
ok i have a program i am writing as a database for my PHD dissertation research. i have a window with 10 tabs, 6 image gadgets each. i want to be able to paste an image from Clampfit(its software that traces electrophysiological readings). the traces are able to be copied from clampfit and pasted into anything else. what i want to be able to do is when the mouse hovers over an image gadget, i want to be able to right click, have a popup menu appear, click on "paste" and have the image be pasted into the image the mouse is over. then move to the next or any other 59 images and do the same. ive worked with the ismouseovergadget and got the popup to appear, but i cant seem to figure out how to return the actual image gadget i am over to paste the image into.

Procedure IsMouseOverGadget(Gadget)
target1=Gadget
GetWindowRect_(GadgetID(Gadget),GadgetRect.RECT)
GetCursorPos_(mouse.POINT)
If mouse\x>=GadgetRect\Left And mouse\x<=GadgetRect\right And mouse\y>=GadgetRect\Top And mouse\y<=GadgetRect\bottom
ProcedureReturn #True and target1
Else
ProcedureReturn #False
EndIf
EndProcedure

;inside loop
EventID = WaitWindowEvent()
Select EventID
Case #WM_rButtonDown
target=IsMouseOverGadget(#Image_9)
If target=#True
DisplayPopupMenu(1,WindowID())
EndIf

;how i paste
Procedure pasteimage()
If CreateImage(17, 270,210)
foo.l = GetClipboardData(#PB_Clipboard_Image)
If foo
If StartDrawing(ImageOutput())
DrawImage(foo,0,0,270,210)
StopDrawing()
EndIf
EndIf
EndIf
SetGadgetState(target1,UseImage(17))
EndProcedure

Case #MENU_9
pasteimage()

Posted: Mon Nov 24, 2003 7:01 pm
by fsw
You could add this to your ImageGadget:

setwindowlong_(hGadget,#GWL_STYLE,getwindowlong_(hGadget,#GWL_STYLE)|256)

But it only fires LeftClickEvents...

So if you have the ImageGadget area you could swap the mouse buttons inside this area with SwapMouseButton_(#TRUE) and SwapMouseButton_(#FALSE) outside this area.

Just a thought...

Posted: Tue Nov 25, 2003 9:57 pm
by Hi-Toro
I *think* this sort of thing should work, but I can't test it as PB is giving me an error on ChildWindowFromPoint, which may possibly be a problem with my PB installation...

Code: Select all

window = OpenWindow (0, 320, 200, 320, 200, #PB_Window_SystemMenu, "Test window")

CreateGadgetList (WindowID ())

gadget1 = ButtonGadget (0, 0, 0, WindowWidth () / 2, WindowHeight (), "Gadget 1")
gadget2 = ButtonGadget (0, WindowWidth () / 2, 0, WindowWidth () / 2, WindowHeight (), "Gadget 1")

Repeat

    ; Get cursor screen position...
    
    GetCursorPos_ (@p.POINT)
    
    ; Convert to window co-ordinates...
    
    ScreenToClient_ (window, @p)
    
    ; Find child window it's over...
    
    Select ChildWindowFromPoint_ (window, p)
        Case window
            SetWindowText_ (window, "Over main window")
        Case gadget1
            SetWindowText_ (window, "Over Gadget 1")
        Case gadget2
            SetWindowText_ (window, "Over Gadget 2")
    EndSelect

Until WaitWindowEvent () = #PB_Event_CloseWindow
[EDIT]

Well, this works (below), but it's a PB bug I think, as the ChildWindowFromPoint syntax should be as above!

Code: Select all


window = OpenWindow (0, 320, 200, 320, 200, #PB_Window_SystemMenu, "")
CreateGadgetList (WindowID ())

gad1 = ButtonGadget (0, 0, 0, WindowWidth () / 2, WindowHeight (), "Gadget 1")
gad2 = ButtonGadget (1, WindowWidth () / 2, 0, WindowWidth () / 2, WindowHeight (), "Gadget 2")

Repeat

    GetCursorPos_ (@p.POINT)
    ScreenToClient_ (window, @p)
    
    Select ChildWindowFromPoint_ (window, p\x, p\y)
        Case gad1
            SetWindowText_ (window, "Over gadget 1")
        Case gad2
            SetWindowText_ (window, "Over gadget 2")
    EndSelect
    
Until WaitWindowEvent () = #PB_Event_CloseWindow


Posted: Wed Sep 15, 2004 5:53 am
by Shannara
Anybody figured out a way to do this in Linux?