Mouse ripple animation is going behind window? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
autohotkey_avatar
Posts: 27
Joined: 04 Aug 2022, 02:51

Mouse ripple animation is going behind window?

Post by autohotkey_avatar » 13 Aug 2022, 03:07

This script will display a ripple animation at the mouse when LControl is released.

It works when the mouse is over most windows. However, some windows in one app I have try hard to "stay on top". For such windows, the ripple animation is going behind the window.

Is there a way I can force the animation to be always on top?

Code: Select all

#NoEnv
CoordMode Mouse, Screen
Setup()

~LControl Up::
	ShowRipple(LeftClickRippleColor)
return

Setup()
{
    Global
    RippleWinSize := 300
    RippleStep := 10
    RippleMinSize := 10
    RippleMaxSize := RippleWinSize - 20
    RippleAlphaMax := 0x60
    RippleAlphaStep := RippleAlphaMax // ((RippleMaxSize - RippleMinSize) / RippleStep)
    RippleVisible := False
    LeftClickRippleColor := 0xff0000
    RightClickRippleColor := 0x0000ff
    MouseIdleRippleColor := 0x000000
    
    DllCall("LoadLibrary", Str, "gdiplus.dll")
    VarSetCapacity(buf, 16, 0)
    NumPut(1, buf)
    DllCall("gdiplus\GdiplusStartup", UIntP, pToken, UInt, &buf, UInt, 0)
    
    Gui Ripple: -Caption +LastFound +AlwaysOnTop +ToolWindow +Owner +E0x80000
    Gui Ripple: Show, NA, RippleWin
    hRippleWin := WinExist("RippleWin")
    hRippleDC := DllCall("GetDC", UInt, 0)
    VarSetCapacity(buf, 40, 0)
    NumPut(40, buf, 0)
    NumPut(RippleWinSize, buf, 4)
    NumPut(RippleWinSize, buf, 8)
    NumPut(1, buf, 12, "ushort")
    NumPut(32, buf, 14, "ushort")
    NumPut(0, buf, 16)
    hRippleBmp := DllCall("CreateDIBSection", UInt, hRippleDC, UInt, &buf, UInt, 0, UIntP, ppvBits, UInt, 0, UInt, 0)
    DllCall("ReleaseDC", UInt, 0, UInt, hRippleDC)
    hRippleDC := DllCall("CreateCompatibleDC", UInt, 0)
    DllCall("SelectObject", UInt, hRippleDC, UInt, hRippleBmp)
    DllCall("gdiplus\GdipCreateFromHDC", UInt, hRippleDC, UIntP, pRippleGraphics)
    DllCall("gdiplus\GdipSetSmoothingMode", UInt, pRippleGraphics, Int, 4)
    
    MouseGetPos _lastX, _lastY
    Return

}

ShowRipple(_color, _interval:=10)
{
    Global
    if (RippleVisible)
    	Return
    RippleColor := _color
    RippleDiameter := RippleMinSize
    RippleAlpha := RippleAlphaMax
    RippleVisible := True

    MouseGetPos _pointerX, _pointerY
    SetTimer RippleTimer, % _interval
    Return

RippleTimer:
    DllCall("gdiplus\GdipGraphicsClear", UInt, pRippleGraphics, Int, 0)
    if ((RippleDiameter += RippleStep) < RippleMaxSize) {
        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\GdipDrawEllipse", UInt, pRippleGraphics, UInt, pRipplePen, float, 1, float, 1, float, (RippleDiameter - 1), float, (RippleDiameter - 1))
        DllCall("gdiplus\GdipDeletePen", UInt, pRipplePen)
    }
    else {
        RippleVisible := False
        SetTimer RippleTimer, Off
    }

    VarSetCapacity(buf, 8)
    NumPut(_pointerX - RippleDiameter // 2, buf, 0)
    NumPut(_pointerY - RippleDiameter // 2, buf, 4)
    DllCall("UpdateLayeredWindow", UInt, hRippleWin, UInt, 0, UInt, &buf, Int64p, (RippleDiameter + 5) | (RippleDiameter + 5) << 32, UInt, hRippleDC, Int64p, 0, UInt, 0, UIntP, 0x1FF0000, UInt, 2)
    Return
}

Rohwedder
Posts: 7670
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Mouse ripple animation is going behind window?  Topic is solved

Post by Rohwedder » 13 Aug 2022, 04:42

Hallo,
replace:

Code: Select all

~LControl Up::
	ShowRipple(LeftClickRippleColor)
return
by:

Code: Select all

~LControl Up::
	Loop, 2
		WinSet, AlwaysOnTop ,% ["Off","On"][A_Index], ahk_id %hRippleWin%
	ShowRipple(LeftClickRippleColor)
return
(Off, On is safer than 2 x Toggle)

Post Reply

Return to “Ask for Help (v1)”