help with returning image events

Everything else that doesn't fall into one of the other PB categories.
localmotion34
Enthusiast
Enthusiast
Posts: 665
Joined: Fri Sep 12, 2003 10:40 pm
Location: Tallahassee, Florida

help with returning image events

Post 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()
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Post 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...
Hi-Toro
Enthusiast
Enthusiast
Posts: 270
Joined: Sat Apr 26, 2003 3:23 pm

Post 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

James Boyd
http://www.hi-toro.com/
Death to the Pixies!
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post by Shannara »

Anybody figured out a way to do this in Linux?
Post Reply