Page 1 of 1

Flicker in example code from help file

Posted: Tue Sep 29, 2015 8:43 pm
by firace
This example in the help file is flickering heavily for me.... (Windows 8.1, x86)

Code: Select all

 If OpenWindow(0, 0, 0, 300, 30, "Window mouse monitor", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    TextGadget(0, 10, 6, 200, 20, "")
    
    Repeat
      Event = WaitWindowEvent(20) ; return at least every 20ms for an update
      
      SetGadgetText(0, "Window mouse position: " + Str(WindowMouseX(0)) + "," + Str(WindowMouseY(0)))       
    Until Event = #PB_Event_CloseWindow
  EndIf
Are there good / simple ways to fix that?

Re: Flicker in example code from help file

Posted: Tue Sep 29, 2015 8:54 pm
by GPI
I would sepearte this in a fixed text and a variable one:

Code: Select all

If OpenWindow(0, 0, 0, 300, 30, "Window mouse monitor", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    TextGadget(0, 10, 6, 150, 20, "Window mouse position: ")
    TextGadget(1,160,6,100,20,"")
    Repeat
      Event = WaitWindowEvent(20) ; return at least every 20ms for an update
     
      SetGadgetText(1,  Str(WindowMouseX(0)) + "," + Str(WindowMouseY(0)))       
    Until Event = #PB_Event_CloseWindow
  EndIf
or you use a read-ony borderless string-gadget

Code: Select all

If OpenWindow(0, 0, 0, 300, 30, "Window mouse monitor", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    StringGadget(0, 10, 6, 200, 20, "",#PB_String_BorderLess|#PB_String_ReadOnly)
   
    Repeat
      Event = WaitWindowEvent(20) ; return at least every 20ms for an update
     
      SetGadgetText(0, "Window mouse position: " + Str(WindowMouseX(0)) + "," + Str(WindowMouseY(0)))       
    Until Event = #PB_Event_CloseWindow
  EndIf
edit: or the best methode:

Code: Select all

 If OpenWindow(0, 0, 0, 300, 30, "Window mouse monitor", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    TextGadget(0, 10, 6, 200, 20, "")
    
    Define oldx,oldy,x,y
    Repeat
      Event = WaitWindowEvent(20) ; return at least every 20ms for an update
      x=WindowMouseX(0)
      y=WindowMouseY(0)
      If x<>oldx Or y<>oldy
        SetGadgetText(0, "Window mouse position: " + Str(x) + "," + Str(y))       
        oldx=x
        oldy=y
      EndIf
      
    Until Event = #PB_Event_CloseWindow
  EndIf
only change the text, when the coordinates have changed.

Re: Flicker in example code from help file

Posted: Tue Sep 29, 2015 9:24 pm
by ts-soft

Code: Select all

EnableExplicit

Define X, Y, oldX, oldY

If OpenWindow(0, 0, 0, 300, 30, "Window mouse monitor", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  TextGadget(0, 10, 6, 200, 20, "")
  
  AddWindowTimer(0, 1, 100)
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        Break
      Case #PB_Event_Timer
        If EventTimer() = 1
          X = WindowMouseX(0)
          Y = WindowMouseY(0)
          If X <> oldX Or Y <> oldY
            SetGadgetText(0, "Window mouse position: " + Str(X) + "," + Str(Y))
            oldX = X
            oldY = Y
          EndIf
        EndIf
    EndSelect
  ForEver
EndIf
No code outside a event in eventloop and no flickering at all :wink:

Re: Flicker in example code from help file

Posted: Wed Sep 30, 2015 9:17 am
by firace
Many thanks for the various approaches provided!

Re: Flicker in example code from help file

Posted: Wed Sep 30, 2015 3:38 pm
by Mesa
@firace: This is not the help example ! ! !
The help example is

Code: Select all

  If OpenWindow(0, 0, 0, 300, 30, "Position of the mouse on the desktop", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    TextGadget(0, 10, 6, 200, 20, "")
    
    Repeat
      Event = WaitWindowEvent(20)
      
      If Event = 0 ; No more events in the queue, so let's display the mouse coordinates
        SetGadgetText(0, "Coordinates: " + Str(DesktopMouseX()) + "," + Str(DesktopMouseY()))  
      EndIf
       
    Until Event = #PB_Event_CloseWindow
  EndIf
The line

Code: Select all

 If Event = 0  ; No more events in the queue, so let's display the mouse coordinates
is very very important.

The example has no sense without that line (i'm the creator of this example in the french help team)

You should not have flickering with this line (i hope :wink: ).

M.

Re: Flicker in example code from help file

Posted: Sun Oct 04, 2015 8:23 pm
by firace
@Mesa: yes it is taken straight from the help file (from WindowMouseX, not DesktopMouseX)

And unfortunately even your example flickers for me :(

GPI's second snippet does eliminate the flicker, though.

Re: Flicker in example code from help file

Posted: Mon Oct 05, 2015 6:45 am
by Vera
Mesa wrote:(i'm the creator of this example in the french help team)
Both examples exist since 2004 and there is no specific french help team.