Is there way to check mouse movement on edge of screen?

Find quick help here to get you started with Hollywood
Post Reply
Bugala
Posts: 1181
Joined: Sun Feb 14, 2010 7:11 pm

Is there way to check mouse movement on edge of screen?

Post by Bugala »

I was just about to add functionality to my editor to scroll around by pushing the mouse to the edge of the screen and then moving the screen the amount you are moving your mouse over the edge.

But, is there any such command in Hollywood?

I can use MouseX and MouseY to get the movement on the screen, but what if the mouse is already on the right edge of the screen. How do I then determine how much I moved the mouse toward the right, as the mouse pointer isn't moving anymore?
plouf
Posts: 473
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: Is there way to check mouse movement on edge of screen?

Post by plouf »

just an idea, for "workaround" !

i have see a few similar "editors", where they use a combined use of Arrows AND mouse, mostly for accuracy,
But in your case maybe its a working workaround for movement "over the edge"
i.e. user while hold rightmouse button moves your square, when goes to the edge, and while still holding RMB, use arrows and continue to move..

a nice "touch" in these case is the report of the actual position in your "map" in statusbar of window, so user knows hoe far it has get
Christos
Bugala
Posts: 1181
Joined: Sun Feb 14, 2010 7:11 pm

Re: Is there way to check mouse movement on edge of screen?

Post by Bugala »

Thanks to your suggestion, I figured out another way to get around the problem. Not perfect, but as long as refresh rate is very high, it works, although not perfectly:

Code: Select all

@DISPLAY {Width=1920, Height=1080, Title = "MouseEdgeScroller", ScaleMode = #SCALEMODE_AUTO, FitScale = True, Sizeable=True, borderless=True, smoothscale=True}
EscapeQuit(True)

LeftEdge=20

CurrentX = 0
CurrentY = 0


If MouseX() > 1960
EndIf

SetInterval(1, Function() Cls(#BLACK)
			Line(500 -  CurrentX, 500 - CurrentY, 500 - CurrentX, 600 - CurrentY, #WHITE) EndFunction, 1)
SetInterval(2, Function()
	If MouseX() > 1870 
		moveamount = MouseX() - 1870
		CurrentX = CurrentX - moveamount
		MovePointer(1870, MouseY() )
	ElseIf MouseX() < 50
		moveamount = 50 - MouseX()
		CurrentX = CurrentX + MoveAmount
		MovePointer(50, MouseY())
	EndIf	
	If MouseY() > 1030 
		moveamount = MouseY() - 1030
		CurrentY = CurrentY - moveamount
		MovePointer(MouseX(), 1030 )
	ElseIf MouseY() < 50
		moveamount = 50 - MouseY()
		CurrentY = CurrentY + MoveAmount
		MovePointer(MouseX(), 50)
	EndIf	

		EndFunction, 1)

Repeat
	WaitEvent()
Forever
User avatar
jPV
Posts: 604
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: Is there way to check mouse movement on edge of screen?

Post by jPV »

Bugala wrote: Tue Feb 20, 2024 9:28 pm Thanks to your suggestion, I figured out another way to get around the problem. Not perfect, but as long as refresh rate is very high, it works, although not perfectly
It gets ultra heavy to call the functions that frequently, and especially to refresh the display 1000 frames per second. There's no need to draw stuff on screen as frequently as you check the mouse movement. So, change the Interval 1 from 1ms to 40ms or something like that if you keep your original code.

I would suggest that don't use Intervals at all, but only do something if the mouse has actually moved. And if it has been moved in the middle with no change to the scroll position, don't update graphics then either (but of course if you do something else that needs fullscreen update, then this can be left out).

And if you do those moveamount calculations separately and not calculate directly on the CurrentX/Y assignments, better use Local variables for those temp values you don't need anywhere else. They'll be faster and don't mess things if you happen to use same variable names elsewhere in the code.

Here's an example that doesn't make (mid-range) computers to choke, especially when idling ;)

Code: Select all

@DISPLAY {Width=1920, Height=1080, Title = "MouseEdgeScroller", ScaleMode = #SCALEMODE_AUTO, FitScale = True, Sizeable=True, borderless=True, smoothscale=True}
EscapeQuit(True)

LeftEdge=20

CurrentX = 0
CurrentY = 0


Function p_Redraw()
	Cls(#BLACK)
	Line(500 -  CurrentX, 500 - CurrentY, 500 - CurrentX, 600 - CurrentY, #WHITE)
EndFunction

Function p_MouseMove()
	Local OldX, OldY = CurrentX, CurrentY
	If MouseX() > 1870 
		Local moveamount = MouseX() - 1870
		CurrentX = CurrentX - moveamount
		MovePointer(1870, MouseY() )
	ElseIf MouseX() < 50
		Local moveamount = 50 - MouseX()
		CurrentX = CurrentX + MoveAmount
		MovePointer(50, MouseY())
	EndIf	
	If MouseY() > 1030 
		Local moveamount = MouseY() - 1030
		CurrentY = CurrentY - moveamount
		MovePointer(MouseX(), 1030 )
	ElseIf MouseY() < 50
		Local moveamount = 50 - MouseY()
		CurrentY = CurrentY + MoveAmount
		MovePointer(MouseX(), 50)
	EndIf	
	If OldX <> CurrentX Or OldY <> CurrentY Then p_Redraw()
EndFunction

p_Redraw()

InstallEventHandler({OnMouseMove=p_MouseMove})

Repeat
	WaitEvent()
Forever
Bugala
Posts: 1181
Joined: Sun Feb 14, 2010 7:11 pm

Re: Is there way to check mouse movement on edge of screen?

Post by Bugala »

Thanks for that OnMouseMove Event, I didn't even realize there is one like that, will use it.
User avatar
jPV
Posts: 604
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: Is there way to check mouse movement on edge of screen?

Post by jPV »

Bugala wrote: Wed Feb 21, 2024 10:08 am Thanks for that OnMouseMove Event, I didn't even realize there is one like that, will use it.
Yeah, there are maaany nice events to avoid constant polling of things :)

And BTW. OnMouseMove event provides X and Y positions of the mouse pointer in the function call, so you can make it even more efficient/clean by removing all useless MouseX() and MouseY() calls.

Code: Select all

@DISPLAY {Width=1920, Height=1080, Title = "MouseEdgeScroller", ScaleMode = #SCALEMODE_AUTO, FitScale = True, Sizeable=True, borderless=True, smoothscale=True}
EscapeQuit(True)

LeftEdge=20

CurrentX = 0
CurrentY = 0


Function p_Redraw()
	Cls(#BLACK)
	Line(500 -  CurrentX, 500 - CurrentY, 500 - CurrentX, 600 - CurrentY, #WHITE)
EndFunction

Function p_MouseMove(msg)
	Local OldX, OldY = CurrentX, CurrentY
	If msg.x > 1870 
		Local moveamount = msg.x - 1870
		CurrentX = CurrentX - moveamount
		MovePointer(1870, msg.y)
	ElseIf msg.x < 50
		Local moveamount = 50 - msg.x
		CurrentX = CurrentX + MoveAmount
		MovePointer(50, msg.y)
	EndIf	
	If msg.y > 1030 
		Local moveamount = msg.y - 1030
		CurrentY = CurrentY - moveamount
		MovePointer(msg.x, 1030 )
	ElseIf msg.y < 50
		Local moveamount = 50 - msg.y
		CurrentY = CurrentY + MoveAmount
		MovePointer(msg.x, 50)
	EndIf	
	If OldX <> CurrentX Or OldY <> CurrentY Then p_Redraw()
EndFunction

p_Redraw()

InstallEventHandler({OnMouseMove=p_MouseMove})

Repeat
	WaitEvent()
Forever
Post Reply