/// <summary> /// アニメーション処理 /// </summary> private async void GHFormAnimation(CancellationToken token) { await Task.Run(() => { int loopMax = 0; int slideDistance = 0; long totalTime = 0; bool slide = false; bool fade = false; bool reverse = GHManager.Settings.Launcher.Pos >= 2; bool visible = (bool)Invoke(new DelegateGetVisible(GetVisible)); int srcPos = (int)Invoke(new DelegateGetSrcPosition(GetGetSrcPosition)); int destPos = (int)Invoke(new DelegateGetDestPosition(GetGetDestPosition)); long animateTime = (long)Invoke(new DelegateGetAnimateTime(GetAnimateTime)); IntPtr handle = (IntPtr)Invoke(new DelegateGetHandle(GetFormHandle)); DelegateAnimationInitial animationInitial = AnimationInitial; DelegateAnimationFinal animationFinal = AnimationFinal; DelegateSetLeftOrTop setLeftOrTop = SetLeftOrTop; DelegateGetLeftOrTop getLeftOrTop = GetLeftOrTop; DelegateGetAlpha getAlpha = GetAlpha; DelegateSetAlpha setAlpha = SetAlpha; DelegateGetTotalTime getTotalTime = GetTotalTime; // スライド・フェードのフラグを取得 slide = (bool)Invoke(new DelegateGetSlideFlag(GetSlideFlag)); fade = (bool)Invoke(new DelegateGetFadeFlag(GetFadeFlag)); bool slideEnd = slide; bool fadeEnd = fade; // ループ回数 loopMax = (int)(animateInfo._AnimateTime / AnimationSleepMili); if (!slideEnd && !fadeEnd) { loopMax = 0; } for (int i = 0; i < loopMax; ++i) { if (token.IsCancellationRequested) { return; } Invoke(animationInitial); totalTime = (long)Invoke(getTotalTime); slideEnd = slide ? GHFormSlider(visible, srcPos, destPos, loopMax, i, animateTime, totalTime, ref handle, ref slideDistance, ref getLeftOrTop, ref setLeftOrTop) : false; fadeEnd = fade ? GHFormFader(visible, srcPos, destPos, loopMax, i, animateTime, totalTime, ref getAlpha, ref setAlpha) : false; Invoke(animationFinal, new object[] { slideEnd, fadeEnd }); // 指定時間待つ Thread.Sleep(AnimationSleepMili); } // 正確な位置に修正 if (slide) { if (!visible) { Invoke(setLeftOrTop, srcPos); } if (visible) { Invoke(setLeftOrTop, destPos); } } else { if (!visible) { Invoke(setLeftOrTop, destPos); } if (visible) { Invoke(setLeftOrTop, destPos); } } Invoke(new DelegateEndAnimation(EndAnimation)); }, token); }
/// <summary> /// ウィンドウをフェードさせる /// </summary> /// <param name="loopMax">ループ最大</param> /// <param name="loopCount">現在のループ数</param> /// <returns></returns> private bool GHFormFader(bool visible, int srcPos, int destPos, int loopMax, int loopCount, long animateTime, long totalTime, ref DelegateGetAlpha getAlpha, ref DelegateSetAlpha setAlpha) { int alpha = (byte)Invoke(getAlpha); // アルファ値の間隔 int interval = (int)Math.Floor((decimal)(255 / loopMax)); alpha += (interval * (visible ? 1 : -1)); if (alpha > 255) { alpha = 255; } if (alpha < 0) { alpha = 0; } Invoke(setAlpha, (byte)alpha); // 経過時間がアニメーション時間を超えたら終了 if (totalTime < animateTime) { return(true); } else { if (!visible) { Invoke(setAlpha, (byte)0); } if (visible) { Invoke(setAlpha, (byte)255); } return(false); } }