mouse click event not available

Just starting out? Need help? Post your questions and find answers here.
User avatar
menschmarkus
User
User
Posts: 18
Joined: Fri Dec 28, 2012 11:23 pm
Location: Center Germany

mouse click event not available

Post by menschmarkus »

Hi,

I try to play a video in a window, stop it and draw something on the image with 2DDraw functions like LineXY(). Everything is running fine but after stopping video, opening Draw mode I move my cursor over the window and still-video-image area and press left mouse button. Problem is, during the mouse moves above the still-video-image it is impossible to catch mouse click event. (#PB_Event_LeftClick with WaitWindowEvent() or WindowEvent() handler). As soon I leave the still-video-image area everything is working fine.

Code: Select all

EnableExplicit

If Not InitMovie()
    MessageRequester("ERROR","Couldn't open video library",#MB_ICONERROR)
    End
EndIf


Enumeration
    #moviewin
    #moviectrl
    #startstop01
    #speedup
    #tracbar
    #movie
    #drawimage
    #drawme
    #BasicImage
EndEnumeration

Global FileName.s
Global width.i, height.i, movielen.i, SlowmoThread.i, RunMovThread.i, position.q, speedpos.q
Global event.i, EventWin.i, ClickStatus.i=0

OpenWindow(#moviectrl,10,10,640,90,"Movie Control")
ButtonGadget(#startstop01,3,3,150,30,"start/stop",#PB_Button_Toggle)
ButtonGadget(#speedup,160,3,150,30,"Slowmo",#PB_Button_Toggle)
ButtonGadget(#drawme,320,3,150,30,"Draw Me")
TrackBarGadget(#tracbar,3,70,300,20,1,100)


Procedure tracbar(speedpos)
    SetGadgetState(#tracbar,speedpos)                           
EndProcedure

Procedure   playmov(value.i)
    If value = 0 ;start Movie
        PlayMovie(#movie,WindowID(#moviectrl))
    ElseIf value = 1 ;Pause movie
        PauseMovie(#movie)
    ElseIf value = 2 ;restart movie
        ResumeMovie(#movie)
    EndIf
EndProcedure

Procedure speedup(speedpos.i)
    Repeat
        speedpos + 1
        MovieSeek(#movie,speedpos)
        playmov(2)
        playmov(1)
        Delay(200)
        tracbar(speedpos)
        PostEvent(#tracbar,#moviectrl,#tracbar)
        SetWindowTitle(#moviectrl,"Movie Position: " + Str(speedpos))
    ForEver   
EndProcedure

Procedure Drawline()
    Protected mxposs.i, myposs.i, mxpose.i, mypose.i, ClickStatus.i = 0, ievent.i
    Repeat
        ievent = WaitWindowEvent()
        Debug ievent
        Select ievent
            Case #PB_Event_LeftClick
                Debug "WindowEvent(): " + Str(ievent)
                If ClickStatus = 0
                    Debug "Clickstatus: 0"
                    mxposs = WindowMouseX(#moviectrl)
                    myposs = WindowMouseY(#moviectrl)
                    ClickStatus + 1
                ElseIf ClickStatus = 1
                    Debug "click status: 1"
                    mxpose = WindowMouseX(#moviectrl)
                    mypose = WindowMouseY(#moviectrl)
                    ClickStatus + 1
                Else
                    Circle( 175,  175, 50, RGBA(255,   0,   0, 128))
                    LineXY(mxposs,myposs,mxpose,mypose,RGBA(255,0,0,128))
                EndIf
                Debug "Clickstatus: 2"
        EndSelect
        SetWindowTitle(#moviectrl,"mousex: " + Str(WindowMouseX(#moviectrl)) + "  /  mousey: " + Str(WindowMouseY(#moviectrl)))
       
    Until ClickStatus > 1
    LineXY(mxposs,myposs,mxpose,mypose,RGBA(255,0,0,128))
EndProcedure


FileName = OpenFileRequester("Movie","","Video files|*.avi;*.mpg;*.mkv|All Files|*.*",0)
If FileName <> ""
    If LoadMovie(#movie,FileName) = 0
        MessageRequester("ERROR","Couldn't open video file",#MB_ICONERROR)
        End
    Else
        width = MovieWidth(#movie)
        height = MovieHeight(#movie)
        movielen = MovieLength(#movie)
        SetGadgetAttribute(#tracbar,#PB_TrackBar_Maximum,movielen)
        ResizeWindow(#moviectrl,#PB_Ignore,#PB_Ignore,width,height+105)
        ResizeMovie(#movie,0,100,width,height)
        playmov(0)
        Repeat
            Delay(10)
            event = WindowEvent()
            EventWin = EventWindow()
            If EventWin = #moviectrl
                Select event
                    Case #PB_Event_Gadget
                        Select EventGadget()
                            Case #startstop01
                                If GetGadgetState(#startstop01) = 1
                                    position = MovieStatus(#movie)
                                    playmov(1)
                                    SetWindowTitle(#moviectrl,"Movie " + Str(position))
                                    DisableGadget(#speedup,1)
                                Else
                                    SetWindowTitle(#moviectrl,"Movie ")
                                    playmov(2)
                                    DisableGadget(#speedup,0)
                                EndIf
                            Case #speedup
                                If GetGadgetState(#speedup) = 1
                                    speedpos = MovieStatus(#movie)
                                    playmov(1)
                                    SlowmoThread = CreateThread(@speedup(),speedpos)
                                    If IsThread(SlowmoThread)
                                        DisableGadget(#startstop01,1)
                                    EndIf
                                Else
                                    If IsThread(SlowmoThread)
                                        KillThread(SlowmoThread)
                                        DisableGadget(#startstop01,0)
                                    EndIf
                                    playmov(2)
                                EndIf
                            Case #tracbar
                                If GetGadgetState(#startstop01) = 1
                                    speedpos = GetGadgetState(#tracbar)
                                    MovieSeek(#movie,speedpos)
                                    playmov(2)
                                    playmov(1)
                                    SetGadgetState(#tracbar,speedpos)
                                EndIf
                            Case #drawme
                                If  CreateImage(#drawme,width,height,32) And StartDrawing(ImageOutput(#drawme))
                                    DrawingMode(#PB_2DDrawing_AlphaChannel)
                                    Box(0, 0, width, height, $00000000)
                                    DrawingMode(#PB_2DDrawing_AlphaBlend)
                                    Circle( 75,  75, 50, RGBA(255,   0,   0, 128))
                                    Circle(125,  75, 50, RGBA(  0, 255,   0, 128))
                                    Circle(100, 125, 50, RGBA(  0,   0, 255, 128))
                                    Drawline()
                                    DrawImage(ImageID(#drawme),0,0)
                                    StopDrawing()
                                    ImageGadget(#BasicImage,0,100,0,0,ImageID(#drawme))
                                EndIf
                        EndSelect
                    Case #PB_Event_CloseWindow
                        Break
                    Default
                        speedpos = MovieStatus(#movie)
                        If speedpos > 0
                            SetGadgetState(#tracbar,speedpos)
                        EndIf
                EndSelect
            Else
                Select event
                    Case #PB_Event_Gadget
                        Select EventGadget()
                            Case 0
                               
                            Default
                                Debug EventGadget()
                        EndSelect
                EndSelect
            EndIf
        ForEver
        StopMovie(#movie)
        FreeMovie(#movie)
    EndIf
EndIf
End 
Any ideas how to fix the problem?

Thanks for helpful comments.
As soon you do it right, it works !
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: mouse click event not available

Post by netmaestro »

What OS?
BERESHEIT
User avatar
menschmarkus
User
User
Posts: 18
Joined: Fri Dec 28, 2012 11:23 pm
Location: Center Germany

Re: mouse click event not available

Post by menschmarkus »

WIN 7/64
WIN 8.1/32

compiled in 32 bit

same effect in both systems.
As soon you do it right, it works !
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: mouse click event not available

Post by netmaestro »

Change your code as shown and you should be able to respond to mouse clicks on the movie screen:

Code: Select all

Procedure hookproc(nCode, wparam, lparam)
  If wparam = #WM_LBUTTONDOWN
    *llhs.MOUSEHOOKSTRUCT = lparam
    SetRect_(mr.RECT,0,100,width,height)
    If PtInRect_(mr, PeekQ(@*llhs\pt))
      Debug "Left mouse button down - do what you like here"
    EndIf
  EndIf
  ProcedureReturn CallNextHookEx_(0, nCode, wparam, lparam)
EndProcedure

OpenWindow(#moviectrl,10,10,640,90,"Movie Control")
hook = SetWindowsHookEx_(#WH_MOUSE_LL, @hookproc(), 0,0)
BERESHEIT
Post Reply