Page 1 of 1

Problem with mouse in window screen

Posted: Mon Apr 07, 2025 2:22 pm
by Psychophanta
I have this code to check it.
There can be changed form mode "Canvas gadget" to "graphical screen" and viceversa (using key 'C' in the keyboard)
The issue is that when change to screen from the canvas to the graphical for the first time, all is correct, but the second time doing it, then the mouse moving is ignored, and also the mouse buttons :shock: why?
The keyboard is not ignored.

Code: Select all

Global RX.u=900,RY.u=500
OpenWindow(0,0,0,RX,RY,Titulo$,#PB_Window_BorderLess|#PB_Window_ScreenCentered)

Procedure lienzo()
  Protected Event.i,mx.f=RX/2,my.f=RY/2,rmb.a,teclamodifiers.a,teclasoltada.a,figura.b=0
  CanvasGadget(10,0,0,RX,RY,#PB_Canvas_Keyboard|#PB_Canvas_DrawFocus|#PB_Canvas_ClipMouse)
  Repeat
    Repeat
      Event.i=WindowEvent()
      Select EventType()
      Case #PB_EventType_MouseMove
        mx.f=GetGadgetAttribute(10,#PB_Canvas_MouseX)
        my.f=GetGadgetAttribute(10,#PB_Canvas_MouseY)
      Case #PB_EventType_RightButtonDown:rmb.a=1
      Case #PB_EventType_RightButtonUp:rmb.a=0
      Case #PB_EventType_KeyUp
        teclamodifiers.a=GetGadgetAttribute(10,#PB_Canvas_Modifiers)
        teclasoltada.a=GetGadgetAttribute (10,#PB_Canvas_Key)
      EndSelect
    Until Event=#PB_Event_None
    figura.b=0
    If rmb:figura.b=1
    ElseIf teclasoltada.a=#PB_Shortcut_C:FreeGadget(#PB_All):ProcedureReturn
    EndIf
    StartDrawing(CanvasOutput(10)):Box(0,0,RX,RY,0)
    If figura.b:Box(mx-40,my-40,80,80,$DDDDEE)
    Else:Circle(mx,my,40,$DDDDEE)
    EndIf
    StopDrawing()
  Until teclasoltada.a=#PB_Shortcut_Escape
  FreeGadget(#PB_All):End
EndProcedure
Procedure pantallagrafica()
  Protected mx.f=RX/2,my.f=RY/2,figura.b=0
  InitMouse():InitSprite():InitKeyboard()
  OpenWindowedScreen(WindowID(0),0,0,RX,RY,1,0,0,#PB_Screen_WaitSynchronization)
  MouseLocate(mx, my)
  Repeat:While WindowEvent()<>#PB_Event_None:Wend
    ExamineKeyboard():ExamineMouse():mx=MouseX():my=MouseY()
    ClearScreen(0)
    figura.b=0
    If MouseButton(#PB_MouseButton_Right):figura.b=1
    ElseIf KeyboardReleased(#PB_Key_C):CloseScreen():ProcedureReturn
    EndIf
    StartDrawing(ScreenOutput())
    If figura.b:Box(mx-40,my-40,80,80,$DDDDEE)
    Else:Circle(mx,my,40,$DDDDEE)
    EndIf
    StopDrawing()
    FlipBuffers():Delay(12)
  Until KeyboardPushed(#PB_Key_Escape)
  CloseScreen():End
EndProcedure

Repeat
  lienzo()
  pantallagrafica()
Forever
NOTICE: in PB6.04x86 it works as it should do

Re: Problem with mouse in window screen

Posted: Mon Apr 14, 2025 7:39 pm
by Psychophanta
This one is still not fixed in the PB6.21 beta 5