Display ripple effect when mouse click

Post your working scripts, libraries and tools for AHK v1.1 and older
asenx
Posts: 3
Joined: 13 Sep 2021, 16:11

Re: Display ripple effect when mouse click

14 Sep 2021, 14:34

Drugwash wrote:
14 Sep 2021, 03:21
My apologies, it's been a long time since last working on this. I believe a better version has been implemented in @robodesign's Keypress OSD.

On a related note, in Linux under Wine after latest updates this script behaves much worse than before - not that it ever worked correctly anyway - so it would be quite hard if not impossible for me to try and fix this script now. :(

As @sofista mentioned above there is an idle timer that kicks in. If you don't want that you can simply comment out this line:
SetTimer MouseIdleTimer, %MouseIdleTimer%
Keypress OSD is very difficult for me to understand at the moment. I only want to interrupt the animation and start it again in case of a double click. Any idea how to do this?
User avatar
kunkel321
Posts: 957
Joined: 30 Nov 2015, 21:19

Re: Display ripple effect when mouse click

18 Sep 2021, 13:03

Pretty cool -- Thanks for sharing. It seems to be working correctly on my multi-monitor setup.

I see that you can assign what color to use for the circles... Is it possible to use burn(darken) or dodge(lighten) rather than a particular color? A burn followed immediately by a dodge would give the effect of shadows and reflections -- thus giving a visual appearance more similar to looking through the ripples in water.
ste(phen|ve) kunkel
User avatar
Hellbent
Posts: 2102
Joined: 23 Sep 2017, 13:34

Re: Display ripple effect when mouse click

18 Sep 2021, 14:39

kunkel321 wrote:
18 Sep 2021, 13:03
Pretty cool -- Thanks for sharing. It seems to be working correctly on my multi-monitor setup.

I see that you can assign what color to use for the circles... Is it possible to use burn(darken) or dodge(lighten) rather than a particular color? A burn followed immediately by a dodge would give the effect of shadows and reflections -- thus giving a visual appearance more similar to looking through the ripples in water.
You could probably get an effect like that by using this gdip brush type.

Code: Select all

Brush := Gdip_CreateLineBrush( X1 , Y1 , X2 , Y2 , Color1 , Color2 , 1 )
Changing the positions of two points back and forth.


On a slightly related note to this topic.
I have this prototype I was playing around with awhile ago that can perhaps be useful to some people that are looking for cursor highlighting.

It currently only works on your main monitor.
You can change the colors of things and their transparencies.
You can reduce or increase the number of circles.
You can change the speed and range of speeds the circles travel.
Temp (1).gif
Temp (1).gif (120.67 KiB) Viewed 2219 times

Requires GDIP and this Layered Window Class to run.

Code:

.

Code: Select all

;***************************************************************************************************
#Include <My Altered Gdip Lib>  ;<------       Replace with your copy of GDIP
;***************************************************************************************************
#Include <LayeredWindow Class>  ;Layered window class
;***************************************************************************************************
#SingleInstance, Force
SetBatchLines, -1
CoordMode, Mouse, Screen
OnExit, GuiClose
MainWindow := New LayeredWindow(x := -1 , y := -1 , w := A_ScreenWidth+1 , h := A_ScreenHeight+1 , window := 1 , title := "Cursor Tracker" , smoothing := 2 , options := "+AlwaysOnTop -DPIScale +E0x20" , autoShow := 1 , GdipStart := 1)
;~ Brush := Gdip_BrushCreateSolid("0x2200FF00")
Brush := Gdip_BrushCreateSolid("0x3300FF00")
Brush2 := Gdip_BrushCreateSolid("0x77ffff00")
MouseGetPos, x, y
Circles := []
Loop, 50
	Circles[A_Index] := New Circle(x,y,MainWindow.G,Brush)
SetTimer, Always, 300
SetTimer, WatchCursor, 30
return
GuiClose:
	MainWindow.DeleteWindow( TurnOffGdip := 1 )
	ExitApp
Always:
	Gui,1:Show,NA
	return
WatchCursor:
	MouseGetPos,tx,ty
	MainWindow.ClearWindow()
	Gdip_FillEllipse(MainWindow.G, Brush2 , tx-20, ty-20 , 40, 40)
	Loop, % Circles.Length()	{
		(Circles[A_Index].Move(tx,ty))?((Circles[A_Index].Active)?(Circles[A_Index].Draw()))
	}
	MainWindow.UpdateWindow()
	return
class Circle	{
	__New(x,y,pGraphics,Brush){
		This.D := This._Random(3,15)
		This.Position := New HB_Vector(x - This.D / 2, y - This.D / 2)
		;~ This.Speed := This._Random(10.00,20.00)
		This.Speed := This._Random(20.00,40.00)
		;~ This.Speed := This._Random(5.00,20.00)
		This.Acc := New HB_Vector()
		This.Target := New HB_Vector()
		This.Graphics := pGraphics
		This.Brush := Brush
		This.Distance := 0
		This._SetTarget( x, y)
	}
	Draw(){
		Gdip_FillEllipse(This.Graphics, This.Brush, This.Position.X, This.Position.Y, This.D, This.D)
	}
	_SetTarget(tx,ty){
		local dist 
		This.Target := ""
		if(This.LastTX=tx&&This.LastTY=ty){
			This.Position.X := tx - (This.D/2) 
			This.Position.Y := ty - (This.D/2)
			This.Active := 0
			return
		}
		This.Active := 1
		This.LastTX := tx
		This.LastTY := ty
		This.Target := New HB_Vector(tx-(This.D / 2),ty-( This.D /2))
		dist := This.Position.dist(This.Target)
		This.Distance := dist / This.Speed
	}
	Move(tx,ty){
		if(--This.Distance>0){
			This.Acc.X := This.Target.X 
			This.Acc.Y := This.Target.Y
			This.Acc.Sub(This.Position)
			This.Acc.SetMag(This.Speed)
			This.Position.Add(This.Acc)
		}else{
			This._SetTarget(tx,ty)
		}
		return 1
	}
	_Random(Min,Max){
		local Out
		Random,Out,Min,Max
		return Out
	}
}
Class HB_Vector	{
	__New(x:=0,y:=0){
		This.X:=x
		This.Y:=y
	}
	Add(Other_HB_Vector){
		This.X+=Other_HB_Vector.X
		This.Y+=Other_HB_Vector.Y
	}
	Sub(Other_HB_Vector){
		This.X-=Other_HB_Vector.X
		This.Y-=Other_HB_Vector.Y
	}
	mag(){
		return Sqrt(This.X*This.X + This.Y*This.Y)
	}
	magsq(){
		return This.Mag()**2
	}	
	setMag(in1){
		m:=This.Mag()
		This.X := This.X * in1/m
		This.Y := This.Y * in1/m
		return This
	}
	mult(in1,in2:="",in3:="",in4:="",in5:=""){
		if(IsObject(in1)&&in2=""){
			This.X*=In1.X 
			This.Y*=In1.Y 
		}else if(!IsObject(In1)&&In2=""){
			This.X*=In1
			This.Y*=In1
		}else if(!IsObject(In1)&&IsObject(In2)){
			This.X*=In1*In2.X
			This.Y*=In1*In2.Y
		}else if(IsObject(In1)&&IsObject(In2)){
			This.X*=In1.X*In2.X
			This.Y*=In1.Y*In2.Y
		}	
	}
	div(in1,in2:="",in3:="",in4:="",in5:=""){
		if(IsObject(in1)&&in2=""){
			This.X/=In1.X 
			This.Y/=In1.Y 
		}else if(!IsObject(In1)&&In2=""){
			This.X/=In1
			This.Y/=In1
		}else if(!IsObject(In1)&&IsObject(In2)){
			This.X/=In1/In2.X
			This.Y/=In1/In2.Y
		}else if(IsObject(In1)&&IsObject(In2)){
			This.X/=In1.X/In2.X
			This.Y/=In1.Y/In2.Y
		}	
	}
	dist(in1){
		return Sqrt(((This.X-In1.X)**2) + ((This.Y-In1.Y)**2))
	}
	dot(in1){
		return (This.X*in1.X)+(This.Y*In1.Y)
	}
	cross(in1){
		return This.X*In1.Y-This.Y*In1.X
	}
	Norm(){
		m:=This.Mag()
		This.X/=m
		This.Y/=m
	}
}
User avatar
kunkel321
Posts: 957
Joined: 30 Nov 2015, 21:19

Re: Display ripple effect when mouse click

19 Sep 2021, 11:05

Hellbent wrote:
18 Sep 2021, 14:39
You could probably get an effect like that by using this gdip brush type.

Code: Select all

Brush := Gdip_CreateLineBrush( X1 , Y1 , X2 , Y2 , Color1 , Color2 , 1 )
Changing the positions of two points back and forth.
Thanks for the idea HellBent. The line of code would go inside of Mright's Setup() function, yes?

Here's just the top of the function:

Code: Select all

Setup()
{
    Global
    RippleWinSize := 200
    RippleStep := 10
    RippleMinSize := 10
    RippleMaxSize := RippleWinSize - 20
    RippleAlphaMax := 0x60
    RippleAlphaStep := RippleAlphaMax // ((RippleMaxSize - RippleMinSize) / RippleStep)
    RippleVisible := False
    ;RippleVisible := True
    Brush := Gdip_CreateLineBrush( X1 , Y1 , X2 , Y2 , Color1 , Color2 , 1 )
    LeftClickRippleColor := Brush
    RightClickRippleColor := 0x0000ff
    MouseIdleRippleColor := 0x008000
Where would color1 and color2 get assigned though?

Side note: I got your cursor gizmo to work -- Pretty cool. The green stuff reminds me of germs trying to infect your cursor LOL.
I like the new avatar by the way. Cheers. :thumbup:
ste(phen|ve) kunkel
User avatar
Hellbent
Posts: 2102
Joined: 23 Sep 2017, 13:34

Re: Display ripple effect when mouse click

19 Sep 2021, 12:05

Thanks.
kunkel321 wrote:
19 Sep 2021, 11:05

Thanks for the idea HellBent. The line of code would go inside of Mright's Setup() function, yes?

Here's just the top of the function:

Where would color1 and color2 get assigned though?
I'm not too familiar with his code but I had noticed his drawing routine creates a pen and then draws a ellipse with it.

Code: Select all

DllCall("gdiplus\GdipCreatePen1", Int, ((RippleAlpha -= RippleAlphaStep) << 24) | RippleColor, float, 3, Int, 2, UIntP, pRipplePen)
DllCall("gdiplus\GdipDrawEllipse", UInt, pRippleGraphics, UInt, pRipplePen, float, 1, float, 1, float, RippleDiameter - 1, float, RippleDiameter - 1)
DllCall("gdiplus\GdipDeletePen", UInt, pRipplePen)
if I was writing that using the gdip lib it would look like this.

Code: Select all

Pen := Gdip_CreatePen( "0xFF3399FF" , 1 ) 
, Gdip_DrawEllipse( G , Pen , 0 , 0 , 50 , 50 ) 
, Gdip_DeletePen( Pen )
And the above can easily have the pen swapped with this one

Code: Select all

Brush := Gdip_CreateLineBrush( 0 , 0 , 100 , 100 , "0xFF3399FF" , "0xFF000000" , 1 ) 
, Pen := Gdip_CreatePenFromBrush( Brush , 1 ) 
, Gdip_DeleteBrush( Brush ) 
, Gdip_DrawEllipse( G , Pen , 0 , 0 , 50 , 50 ) 
, Gdip_DeletePen( Pen )

Then it is just a matter of using two different sets of positions for the brush and swap between them.

Here is an example of two different positions used.
20210919130319.png
20210919130319.png (25.25 KiB) Viewed 2156 times
EntropicBlackhole
Posts: 40
Joined: 12 Jun 2021, 15:28

Re: Display ripple effect when mouse click

24 Sep 2021, 11:45

This has great potential
by adjusting the colors, to the red and blue Portal uses, and by using a hotkey you have to hold while clicking, you could right click inside a folder or on your desktop, and it would create this little portal, you left click somewhere else, creating another portal, and when dragging a file into one portal, it places it into the folder where the other portal is, to reset portals you could use the middle click button, it's a very nice idea in my opinion
User avatar
Hellbent
Posts: 2102
Joined: 23 Sep 2017, 13:34

Re: Display ripple effect when mouse click

24 Sep 2021, 17:41

EntropicBlackhole wrote:
24 Sep 2021, 11:45
This has great potential
by adjusting the colors, to the red and blue Portal uses, and by using a hotkey you have to hold while clicking, you could right click inside a folder or on your desktop, and it would create this little portal, you left click somewhere else, creating another portal, and when dragging a file into one portal, it places it into the folder where the other portal is, to reset portals you could use the middle click button, it's a very nice idea in my opinion
You can create the windows (the graphics) pretty easily and then use GuiDropFiles to setup your file transfer.

This example isn't quite the same, but it shows a similar effect.

Image

viewtopic.php?f=76&t=72575#p314196
User avatar
kunkel321
Posts: 957
Joined: 30 Nov 2015, 21:19

Re: Display ripple effect when mouse click

25 Sep 2021, 12:04

Thanks for the cool tips HellBent.

It's all a bit over my head. But that's okay, I'm off to other projects anyway. :- }
ste(phen|ve) kunkel
User avatar
Drugwash
Posts: 850
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

Re: Display ripple effect when mouse click

28 Sep 2021, 08:44

asenx wrote:
14 Sep 2021, 14:34
Keypress OSD is very difficult for me to understand at the moment. I only want to interrupt the animation and start it again in case of a double click. Any idea how to do this?
Here's a slightly modified version of the file used in Keypress OSD as I have it on my computer. It may not be the latest. Hopefully it's OK to post it here.
It attempts to solve the single-click/double-click animation restart. It also includes cues for wheel rotation.
keypress-mouse-ripples-functions MOD.ahk
(11.35 KiB) Downloaded 102 times
Part of my AHK work can be found here.
Pacifista
Posts: 46
Joined: 17 Jan 2022, 16:17

Re: Display ripple effect when mouse click

02 Mar 2022, 05:52

Drugwash wrote:
28 Sep 2021, 08:44
asenx wrote:
14 Sep 2021, 14:34
Keypress OSD is very difficult for me to understand at the moment. I only want to interrupt the animation and start it again in case of a double click. Any idea how to do this?
Here's a slightly modified version of the file used in Keypress OSD as I have it on my computer. It may not be the latest. Hopefully it's OK to post it here.
It attempts to solve the single-click/double-click animation restart. It also includes cues for wheel rotation.

keypress-mouse-ripples-functions MOD.ahk
this one is lagging as hell mister.
User avatar
Drugwash
Posts: 850
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

Re: Display ripple effect when mouse click

02 Mar 2022, 06:35

Pacifista wrote:
02 Mar 2022, 05:52
this one is lagging as hell mister.
As compared to... what, exactly? Can you provide a comparison?
There may be a very slight delay due to waiting for a double-click to time out, but that shouldn't be too visible.
Maybe there's something else on your system holding back the script.
Anybody else experiencing such issue?
Part of my AHK work can be found here.
Pacifista
Posts: 46
Joined: 17 Jan 2022, 16:17

Re: Display ripple effect when mouse click

02 Mar 2022, 07:49

The one above is working like a charm. This one's calibration and delay is not good enough.
User avatar
Drugwash
Posts: 850
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

Re: Display ripple effect when mouse click

02 Mar 2022, 08:15

Tried my best but it's hard to get to a good compromise, more so when I'm using Linux which is not very friendly to these scripts at least in my old version of Wine.
Do you have any improvements of your own to the script?
Part of my AHK work can be found here.
User avatar
Drugwash
Posts: 850
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

Re: Display ripple effect when mouse click

02 Mar 2022, 14:43

Took another look at the code. As a workaround one can set the DCT variable (Double-Click Time) to zero. For convenience I have added a toggle variable: NoDblClk; when true it will set DCT to zero making all ripples fire instantly. The downside is the double-click will not be detected anymore so the specific appearance (thicker line) will never be displayed for any of the clicks (left/middle/right).

While at it I added the idle ripples feature that was in the original version of the code. For convenience it can be enabled/disabled through a toggle variable: ShowIdleRipples.
There are also a few variables that control the appearance of idle ripples:

Code: Select all

- MouseIdleTimer		:= 5000		; [ms]
- MouseIdleMinSize		:= 30		; [px]
- MouseIdleMaxSize		:= 80		; [px]
- MouseIdleFrequency	:= 40		; [ms]
- MouseIdleRippleColor	:= "808080"	; [RGB]
- MouseIdleShape		:= 1		; [1-2] 1=Circle, 2=Square

Haven't tested but this idle feature may interfere with full screen exclusive applications such as videoplayers or presentations. Not sure if detection of such windows can be performed in a reliable manner so you may wanna keep that in mind and disable the script when using such applications.


keypress-mouse-ripples-functions MOD.ahk
new version 2022.03.02
(12.55 KiB) Downloaded 109 times
Part of my AHK work can be found here.

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: furqan and 74 guests