Page 1 of 1

mouse x y canvas update loop

Posted: Sun Nov 27, 2011 1:23 am
by ehowington
trying to figure out how to update a text gadget to display the x y when entering the canvas of the mouse postion within the canvas as a thread perhaps???

any ideas suggestions?

Re: mouse x y canvas update loop

Posted: Sun Nov 27, 2011 1:56 am
by IdeasVacuum
Like This?

Code: Select all

Enumeration
  #GADGET_Canvas
  #GADGET_Text
EndEnumeration


If OpenWindow(0, 0, 0, 500, 400, "Canvas XY", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

  CanvasGadget(#GADGET_Canvas, 10, 10, 380, 380, #PB_Canvas_ClipMouse)
    TextGadget(#GADGET_Text, 400, 10, 80, 20,"")


  SetGadgetAttribute(#GADGET_Canvas, #PB_Canvas_Cursor, #PB_Cursor_Cross)

  Repeat
       Event = WaitWindowEvent()
    If Event = #PB_Event_Gadget

            Select EventGadget()

                   Case #GADGET_Canvas

                                X = GetGadgetAttribute(#GADGET_Canvas, #PB_Canvas_MouseX)
                                Y = GetGadgetAttribute(#GADGET_Canvas, #PB_Canvas_MouseY)
                                         SetGadgetText(#GADGET_Text,"X" + Str(X) + " Y" + Str(Y))
            EndSelect

    EndIf

  Until Event = #PB_Event_CloseWindow

EndIf

End

Re: mouse x y canvas update loop

Posted: Sun Nov 27, 2011 2:14 am
by ehowington
ty ty ;)