开始

如果一个ui不是单调的显示,而是有一些动画(渐显渐隐,卷帘下拉……)就好了。

下面的脚本就是解决这个问题的,它简单,功能略疲乏,但满足一些小需求。

代码


#Include G:\AHK\gitee_ahk2\common\Extend.ahk

/** @example
 * g := Gui('+AlwaysOnTop +ToolWindow -Caption')
 * g.AddText('w200 h200')
 * 
 * Animation.FadeIn(g)
 * Sleep 1000
 * Animation.FadeOut(g, true)
 * 
 * Animation.RollDown(g)
 * Sleep 1000
 * Animation.RollUp(g)
 */
class Animation {
  static FadeOut(target, hide := false, wait := 10) {
    loop 25 {
      Sleep wait
      WinSetTransparent(255 - A_Index * 10, target)
    }
    hide ? target.Hide() : target.Destroy()
  }

  static FadeIn(target, doAfterShow := Noop, wait := 10) {
    target.Show('Minimize NA'), WinSetTransparent(0, target), target.Restore()
    target.getPos(, , &w, &h), _getPos(&x, &y), target.Move(x, y), doAfterShow()
    loop 25 {
      Sleep wait
      WinSetTransparent(A_Index * 10, target)
    }
    WinSetTransparent(255, target)

    _getPos(&x, &y) {
      MouseGetPos(&mx, &my)
      x := mx, y := my
      if mx + w > A_ScreenWidth
        x := mx - w
      if my + h > A_ScreenHeight
        y := my - h
    }
  }

  static RollDown(target, doAfterShow := Noop) {
    target.Show('Minimize NA'), WinSetTransparent(0, target), target.Restore()
    target.getPos(, , &w, &h), _getPos(&x, &y), doAfterShow()
      , target.Move(, , , 0)
      , WinSetTransparent(255, target)
      , target.Show('x' x ' y' y ' NA')
    loop h
      target.Move(, , , A_Index)

    _getPos(&x, &y) {
      MouseGetPos(&mx, &my)
      x := mx, y := my
      if mx + w > A_ScreenWidth
        x := mx - w
      if my + h > A_ScreenHeight
        y := my - h
    }
  }

说明

所有的都是静态方法,只需要像这样般使用:

g := Gui('+AlwaysOnTop +ToolWindow -Caption')
g.AddText('w200 h200')

Animation.FadeIn(g)
Sleep 1000
Animation.FadeOut(g, true)

Animation.RollDown(g)
Sleep 1000
Animation.RollUp(g)
posted on 2024-03-25 13:22  落寞的雪  阅读(62)  评论(0编辑  收藏  举报