Page 1 of 1

clientmousex() clientmousey()

Posted: Sat Jun 12, 2004 12:15 pm
by blueznl
it's rather silly that one has to resort to winapi to retrieve a mousepointer location

to keep old code functioning i would like to suggest to add these two commands that return the coordinates of the mouse in the client area

see also viewtopic.php?t=11233

Re: clientmousex() clientmousey()

Posted: Sat Jun 12, 2004 4:03 pm
by GPI
At the moment the WindowX() and WindowY() functions are total useless, because they start outside the client-area (the gadget has a diffrent zero-point). And the problem: there is no PB-only way to find out, how big the "title-bar" of a window is, so nobody can translate the points.

It would be nice to change the WindowX() and WindowY() to client-Koordinates.

Code: Select all

  Id=GadgetID(gadget)
  GetCursorPos_(mouse.POINT)
  MapWindowPoints_(0,Id,mouse,1)

Posted: Sat Jun 12, 2004 4:34 pm
by blueznl
euh, gpi, you are refering to windowmousex() and windowmousey()? correct? :-)

Posted: Sat Jun 12, 2004 7:10 pm
by GPI
blueznl wrote:euh, gpi, you are refering to windowmousex() and windowmousey()? correct? :-)
Yes...

Posted: Sat Jun 12, 2004 7:13 pm
by blueznl
then you stand corrected :-)

Posted: Sat Jun 12, 2004 8:10 pm
by thefool
blueznl wrote:then you stand corrected :-)
:lol:

Posted: Mon Jun 14, 2004 12:10 am
by Danilo

Code: Select all

; 
; by Danilo, 30.04.2003 - german forum
;
;   modified 11.12.2003
; 
Procedure WindowClientMouseX(win)             ; added param, 11.12.03
  ; Returns X-Position of MouseCursor 
  ; in the current window's client area 
  ; or -1 if mouse cursor isnt in this area. 
  GetCursorPos_(mouse.POINT) 
  ScreenToClient_(WindowID(win),mouse) 
  GetClientRect_(WindowID(win),rect.RECT) 
  If mouse\x < 0 Or mouse\x > rect\right 
    ProcedureReturn -1 
  ElseIf mouse\y < 0 Or mouse\y > rect\bottom ; added 11.12.03
    ProcedureReturn - 1
  Else 
    ProcedureReturn mouse\x 
  EndIf 
EndProcedure 

Procedure WindowClientMouseY(win)             ; added param, 11.12.03
  ; Returns Y-Position of MouseCursor 
  ; in the current window's client area 
  ; or -1 if mouse cursor isnt in this area. 
  GetCursorPos_(mouse.POINT) 
  ScreenToClient_(WindowID(win),mouse) 
  GetClientRect_(WindowID(win),rect.RECT) 
  If mouse\y < 0 Or mouse\y > rect\bottom 
    ProcedureReturn -1 
  ElseIf mouse\x < 0 Or mouse\x > rect\right  ; added 11.12.03
    ProcedureReturn - 1
  Else 
    ProcedureReturn mouse\y 
  EndIf 
EndProcedure 

OpenWindow(1,200,200,300,300,#PB_Window_SystemMenu,"MousePos") 

Repeat 
  Select WaitWindowEvent() 
    Case #PB_Event_CloseWindow 
      End 
    Default 
      StartDrawing(WindowOutput()) 
        Box(0,0,300,300,0) 
        DrawingMode(1):FrontColor($FF,$FF,$00) 
        Locate(30,100) 
        DrawText("MouseX: "+Str( WindowClientMouseX(1) )) 
        Locate(30,120) 
        DrawText("MouseY: "+Str( WindowClientMouseY(1) )) 
      StopDrawing()  
  EndSelect 
ForEver
Fred wanted to change WindowMouseX/Y to this code internally,
but looks like he forgot it...

Posted: Sun Jun 20, 2004 7:22 pm
by Fred
This is done now, for v3.91. As GPI said the current commands aren't really useful.