Spider 3.00 WindowMouseX(window) and WindowMouseY(window) not ok

Just starting out? Need help? Post your questions and find answers here.
Stefan
Posts: 248
Joined: Mon Feb 05, 2018 9:44 pm

Spider 3.00 WindowMouseX(window) and WindowMouseY(window) not ok

Post by Stefan »

Unfortunately, there is no way to find out in Spider whether the mouse is over an image.
I also couldn't find anything in JavaScript that I, as a layman, could implement.
So I wrote an emergency procedure that checks every 50 ms with WindowMouseX(window) and WindowMouseY(window) whether the mouse pointer is over an image.
Everything worked fine up to Spider version 2.51.
It worked up to Spider3 b3 too.
But with the finished version Spider 3.0, the mouse coordinates no longer match.
What has changed?
I just can't reproduce the error.
Fred
Site Admin
Posts: 1820
Joined: Mon Feb 24, 2014 10:51 am

Re: Spider 3.00 WindowMouseX(window) and WindowMouseY(window) not ok

Post by Fred »

Unfortunately, we will need a small snippet to see the issue or we can't investigate. We changed the way to move the window but it shouldn't impact the WindowMouseX() function (at least I can't see a link in the code).
Stefan
Posts: 248
Joined: Mon Feb 05, 2018 9:44 pm

Re: Spider 3.00 WindowMouseX(window) and WindowMouseY(window) not ok

Post by Stefan »

Code: Select all

xres.i=DesktopWidth(0)  
yres.i=DesktopHeight(0)  

Debug Str(xres)+" x "+Str(yres) ;1601 x 781

This is WRONG! The real solution is 1921 x 937

BUT with this resolution the code works in Spider 3.0


With this code I can find our the real solution: 1921 x 937

Code: Select all

!document.body.style.zoom = 1 / window.devicePixelRatio * 100 + "%"
!v_width=document.body.clientWidth;
!v_height=document.body.clientHeight;

xres=width
yres=height

Debug Str(xres)+" x "+Str(yres)

But with this resolution, my code doesn't work well in Spider 3.00

In Spider 2.51 my code works well in this resolution.
Fred
Site Admin
Posts: 1820
Joined: Mon Feb 24, 2014 10:51 am

Re: Spider 3.00 WindowMouseX(window) and WindowMouseY(window) not ok

Post by Fred »

There is a new 'DPI' option to get the real desktop resolution, may be you can try this. We also need a working snippet to show the issue.
User avatar
Peter
Posts: 1197
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: Spider 3.00 WindowMouseX(window) and WindowMouseY(window) not ok

Post by Peter »

Stefan wrote: Fri Jun 28, 2024 6:11 amSo I wrote an emergency procedure that checks every 50 ms with WindowMouseX(window) and WindowMouseY(window) whether the mouse pointer is over an image.
It would probably be easier to process the MouseEnter and MouseLeave events of the images. I have written a small example code for this: viewtopic.php?t=2588
Stefan
Posts: 248
Joined: Mon Feb 05, 2018 9:44 pm

Re: Spider 3.00 WindowMouseX(window) and WindowMouseY(window) not ok

Post by Stefan »

With this code you can test it.
With check_screen(2) it works, with check_screen(1) it doesn't work

Code: Select all




EnableExplicit

Declare TimerProcedure()
Declare check_Screen(flg)
Declare Desktop_Zoomen()



Enumeration
  #win
  #tgadget
  #tgadget1
  #timer
  
EndEnumeration

Global xres,yres,pic1,pic,picgadget1,picgadget2,pcflg,ScreenXres,Screenyres

Global PcFlg, zugross, testzoom ;Tablet oder Handy
testzoom=1



pcflg=1


check_Screen(2)

OpenWindow(#win,0,0,xres,yres,"Window "+Str(xres)+" "+Str(yres))


TextGadget(#tgadget,10,10,200,30,"")
TextGadget(#tgadget1,320,10,200,30,"")

pic=CreateImage(#PB_Any,60,60,32,RGB(200,0,0))
pic1=CreateImage(#PB_Any,60,60,32,RGB(0,200,0))

picgadget1=ImageGadget(#PB_Any,50,yres-ImageHeight(pic)-50,ImageWidth(pic),ImageHeight(pic),ImageID(pic))
picgadget2=ImageGadget(#PB_Any,650,yres-ImageHeight(pic1)-50,ImageWidth(pic1),ImageHeight(pic1),ImageID(pic1))


AddWindowTimer(#win,#timer,50)
BindEvent(#PB_Event_Timer,@TimerProcedure())

Procedure TimerProcedure()
  Protected  i,mx,my,gx,gy,gw,gh
  If EventTimer()=#timer
    SetGadgetText(#tgadget1,"")
    mx=WindowMouseX(#win)
    my=WindowMouseY(#win)
    
    
    SetGadgetText(#tgadget,"x="+Str(mx)+" y= "+Str(my))
    
    gx=GadgetX(picgadget1)
    gy=GadgetY(picgadget1)
    gw=GadgetWidth(picgadget1)
    gh=GadgetHeight(picgadget1)
    
    If mx>gx And mx<gx+gw
      If my>gy And gy<gy+gh
        SetGadgetText(#tgadget1,"Mouse in red box")
        
      EndIf
    EndIf
    
    gx=GadgetX(picgadget2)
    gy=GadgetY(picgadget2)
    gw=GadgetWidth(picgadget2)
    gh=GadgetHeight(picgadget2)
    
    If mx>gx And mx<gx+gw
      If my>gy And gy<gy+gh
        SetGadgetText(#tgadget1,"Mouse in green box")
        
      EndIf
    EndIf
    
    
    
    
    
  EndIf
  
EndProcedure


Procedure check_Screen(flg)
  
  
  
  Protected  width,height
  
  
  If flg=1
    
    !document.body.style.zoom = 1 / window.devicePixelRatio * 100 + "%"
    !v_width=document.body.clientWidth;
    !v_height=document.body.clientHeight;
    
    !v_r=window.devicePixelRatio
    
  Else
    
    
    xres=DesktopWidth(0)
    yres=DesktopHeight(0)
    ProcedureReturn
    
  EndIf
  
  
  
  
  xres=width
  yres=height
  
  Debug xres
  Debug yres
  
  
EndProcedure




Fred
Site Admin
Posts: 1820
Joined: Mon Feb 24, 2014 10:51 am

Re: Spider 3.00 WindowMouseX(window) and WindowMouseY(window) not ok

Post by Fred »

If you manually modify the zoom factor using CSS, you will need to adjust the WindowMouseX/Y() return to match the new ratio. As you can see, using CSS zoom isn't the same the using the browser zoom (using mousewheel up/down) as it doesn't change the ratio. When using the mousewheel it change the ratio and all work as expected.
Post Reply