Cleaned logic

This commit is contained in:
Robinson 2023-02-03 00:29:30 +01:00
parent 6c5493944e
commit f20c4e73a0
No known key found for this signature in database
GPG Key ID: 8E7DB78588BD6F5C
2 changed files with 25 additions and 28 deletions

View File

@ -15,10 +15,10 @@
*/ */
package dorkbox.notify package dorkbox.notify
import dorkbox.notify.LAFUtil.tweenEngine
import dorkbox.tweenEngine.Tween import dorkbox.tweenEngine.Tween
import dorkbox.tweenEngine.TweenEquations import dorkbox.tweenEngine.TweenEquations
import dorkbox.tweenEngine.TweenEvents import dorkbox.tweenEngine.TweenEvents
import dorkbox.util.SwingUtil
import java.awt.Canvas import java.awt.Canvas
import java.awt.Dimension import java.awt.Dimension
import java.awt.Graphics import java.awt.Graphics
@ -148,7 +148,6 @@ internal class AppNotify(override val notification: Notify): Canvas(), NotifyTyp
throw RuntimeException("Not able to add the notification to the window glassPane") throw RuntimeException("Not able to add the notification to the window glassPane")
} }
// now we setup the rendering of the image // now we setup the rendering of the image
refresh() refresh()
} }
@ -226,15 +225,16 @@ internal class AppNotify(override val notification: Notify): Canvas(), NotifyTyp
override fun setupHide() { override fun setupHide() {
if (hideTween == null && notification.hideAfterDurationInMillis > 0) { if (hideTween == null && notification.hideAfterDurationInMillis > 0) {
// begin a timeline to get rid of the popup (default is 5 seconds) // begin a timeline to get rid of the popup (default is 5 seconds)
hideTween = LAFUtil.tweenEngine.to(this, AppAccessor.PROGRESS, tweenAccessor, notification.hideAfterDurationInMillis / 1000.0f) val tween = tweenEngine
.to(this, AppAccessor.PROGRESS, tweenAccessor, notification.hideAfterDurationInMillis / 1000.0f)
.value(Notify.WIDTH.toFloat()) .value(Notify.WIDTH.toFloat())
.ease(TweenEquations.Linear) .ease(TweenEquations.Linear)
.addCallback(TweenEvents.COMPLETE) { .addCallback(TweenEvents.COMPLETE) {
SwingUtil.invokeLater { notification.onClose()
notification.onClose()
}
} }
.start()
hideTween = tween
tween.start()
} }
} }
@ -242,7 +242,7 @@ internal class AppNotify(override val notification: Notify): Canvas(), NotifyTyp
if (moveTween != null) { if (moveTween != null) {
moveTween!!.value(y) moveTween!!.value(y)
} else { } else {
val tween = LAFUtil.tweenEngine val tween = tweenEngine
.to(this, AppAccessor.Y_POS, tweenAccessor, Notify.MOVE_DURATION) .to(this, AppAccessor.Y_POS, tweenAccessor, Notify.MOVE_DURATION)
.value(y) .value(y)
.ease(TweenEquations.Linear) .ease(TweenEquations.Linear)
@ -261,7 +261,7 @@ internal class AppNotify(override val notification: Notify): Canvas(), NotifyTyp
shakeTween!!.valueRelative(targetX, targetY) shakeTween!!.valueRelative(targetX, targetY)
.repeatAutoReverse(count, 0f) .repeatAutoReverse(count, 0f)
} else { } else {
val tween = LAFUtil.tweenEngine val tween = tweenEngine
.to(this, AppAccessor.X_Y_POS, tweenAccessor, 0.05f) .to(this, AppAccessor.X_Y_POS, tweenAccessor, 0.05f)
.valueRelative(targetX, targetY) .valueRelative(targetX, targetY)
.repeatAutoReverse(count, 0f) .repeatAutoReverse(count, 0f)
@ -273,20 +273,17 @@ internal class AppNotify(override val notification: Notify): Canvas(), NotifyTyp
} }
fun onClick(x: Int, y: Int) { fun onClick(x: Int, y: Int) {
// this must happen in the Swing EDT. This is usually called by the active renderer // Check - we were over the 'X' (and thus no notify), or was it in the general area?
SwingUtil.invokeLater {
// Check - we were over the 'X' (and thus no notify), or was it in the general area?
val isClickOnCloseButton = !notification.hideCloseButton && x >= 280 && y <= 20 val isClickOnCloseButton = !notification.hideCloseButton && x >= 280 && y <= 20
// reasonable position for detecting mouse over // reasonable position for detecting mouse over
if (!isClickOnCloseButton) { if (isClickOnCloseButton) {
// only call the general click handler IF we click in the general area! // we always close the notification popup
notification.onClickAction() notification.onClose()
} else { } else {
// we always close the notification popup // only call the general click handler IF we click in the general area!
notification.onClose() notification.onClickAction()
}
} }
} }

View File

@ -21,7 +21,6 @@ import dorkbox.tweenEngine.Tween
import dorkbox.tweenEngine.TweenEquations import dorkbox.tweenEngine.TweenEquations
import dorkbox.tweenEngine.TweenEvents import dorkbox.tweenEngine.TweenEvents
import dorkbox.util.ScreenUtil import dorkbox.util.ScreenUtil
import dorkbox.util.SwingUtil
import java.awt.Dimension import java.awt.Dimension
import java.awt.Graphics import java.awt.Graphics
import java.awt.MouseInfo import java.awt.MouseInfo
@ -142,15 +141,16 @@ internal class DesktopNotify(override val notification: Notify) : JWindow(), Not
override fun setupHide() { override fun setupHide() {
if (hideTween == null && notification.hideAfterDurationInMillis > 0) { if (hideTween == null && notification.hideAfterDurationInMillis > 0) {
// begin a timeline to get rid of the popup (default is 5 seconds) // begin a timeline to get rid of the popup (default is 5 seconds)
hideTween = tweenEngine.to(this, DesktopAccessor.PROGRESS, tweenAccessor, notification.hideAfterDurationInMillis / 1000.0f) val tween = tweenEngine
.to(this, DesktopAccessor.PROGRESS, tweenAccessor, notification.hideAfterDurationInMillis / 1000.0f)
.value(Notify.WIDTH.toFloat()) .value(Notify.WIDTH.toFloat())
.ease(TweenEquations.Linear) .ease(TweenEquations.Linear)
.addCallback(TweenEvents.COMPLETE) { .addCallback(TweenEvents.COMPLETE) {
SwingUtil.invokeLater { notification.onClose()
notification.onClose()
}
} }
.start()
hideTween = tween
tween.start()
} }
} }
@ -175,7 +175,7 @@ internal class DesktopNotify(override val notification: Notify) : JWindow(), Not
override fun doShake(count: Int, targetX: Float, targetY: Float) { override fun doShake(count: Int, targetX: Float, targetY: Float) {
if (shakeTween != null) { if (shakeTween != null) {
shakeTween!!.valueRelative(targetX, targetY) shakeTween!!.valueRelative(targetX, targetY)
.repeatAutoReverse(count, 0f) .repeatAutoReverse(count, 0f)
} else { } else {
val tween = tweenEngine val tween = tweenEngine
.to(this, DesktopAccessor.X_Y_POS, tweenAccessor, 0.05f) .to(this, DesktopAccessor.X_Y_POS, tweenAccessor, 0.05f)