Page 1 of 1
Hide cursor when inside window (api)
Posted: Wed Feb 08, 2006 9:22 pm
by Joakim Christiansen
Code updated For 5.20+
Just a simple example that hides the mouse cursor when it's inside a window
Code: Select all
OpenWindow(0,0,0,320,240,"Test",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
Repeat
If WindowMouseX(0)=-1 Or WindowMouseY(0)=-1
If ShowMouse = -1
ShowMouse = ShowCursor_(#True)
EndIf
Else
If ShowMouse = 0
ShowMouse = ShowCursor_(#False)
EndIf
EndIf
StartDrawing(WindowOutput(0))
Circle(WindowMouseX(0),WindowMouseY(0),5,#Red)
StopDrawing()
Until WindowEvent() = #PB_Event_CloseWindow
Posted: Wed Feb 08, 2006 11:19 pm
by ABBKlaus
and even better with a little delay
Code: Select all
OpenWindow(0,0,0,320,240,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"Test")
Repeat
If WindowMouseX(0)=-1 Or WindowMouseY(0)=-1
If ShowMouse = -1
ShowMouse = ShowCursor_(#True)
EndIf
Else
If ShowMouse = 0
ShowMouse = ShowCursor_(#False)
EndIf
EndIf
StartDrawing(WindowOutput(0))
Circle(WindowMouseX(0),WindowMouseY(0),5,#Red)
StopDrawing()
Until WaitWindowEvent(1) = #PB_Event_CloseWindow
Posted: Sat Jun 24, 2006 1:34 pm
by Dräc
Because previous codes assume that the state of the internal cursor count is 0 when starting the loop, here a little enhancement:
ShowCursor(Flag): Flag=#False --> Hide cursor, Flag=#True --> Show cursor
Works what ever the number of time that ShowCursor_ was called before.
But I haven’t find another way then calling several time ShowCursor_ to adapt the internal cursor count.
PLEASE, before trying, suppress the ‘_’ in the third line
Made it unless the code does appared correctly (someone knows how to disable the '<' character under BBcode?)
Code: Select all
Procedure ShowCursor(Flag); Flag=#True/#False, show/hide cursor
Static CursorState
If Flag <_> CursorState
CursorState = ShowCursor_(Flag)
If (CursorState >=0 And Flag = 0) Or (CursorState <0 And Flag)
Repeat
Until ShowCursor_(Flag) =Flag-1
EndIf
CursorState =Flag
EndIf
EndProcedure
OpenWindow(0,0,0,320,240,"Test",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
For i=0 To 10000
ShowCursor_(#True)
Next
Repeat
If WindowMouseX(0)=-1 Or WindowMouseY(0)=-1
ShowCursor(#True)
Else
ShowCursor(#False)
EndIf
StartDrawing(WindowOutput(0))
Circle(WindowMouseX(0),WindowMouseY(0),5,#Red)
StopDrawing()
Until WaitWindowEvent(1) = #PB_Event_CloseWindow
Posted: Sat Jun 24, 2006 2:42 pm
by Trond
Dräc, disable html in your profile.
Here's yet another way (using a transparent 1x1 pixel cursor):
Code: Select all
OpenWindow(0,0,0,320,240,"Test")
Mask.w = %0000000010000000
hCur = CreateCursor_(GetModuleHandle_(0), 0, 0, 1, 1, @Mask, @Mask+1)
SetClassLong_(WindowID(0), #GCL_HCURSOR, hCur)
Repeat
StartDrawing(WindowOutput(0))
Circle(WindowMouseX(0),WindowMouseY(0),5,#Red)
StopDrawing()
Until WaitWindowEvent(1) = #PB_Event_CloseWindow
DestroyCursor_(hCur)
Posted: Sat Jun 24, 2006 3:14 pm
by Dräc
Trond wrote:Dräc, disable html in your profile.
Right, thanks