You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
131 lines
5.0 KiB
131 lines
5.0 KiB
package com.fine.theme.utils; |
|
|
|
import com.formdev.flatlaf.util.Animator.Interpolator; |
|
import com.formdev.flatlaf.util.CubicBezierEasing; |
|
|
|
import java.awt.Component; |
|
import java.awt.Graphics; |
|
import java.awt.Graphics2D; |
|
|
|
/** |
|
* Painter 可在组件值更改时自动对绘画进行动画处理。 |
|
* getValues(Component) 返回组件的值。如果值已更改,则 paintAnimated(Component, Graphics2D, int, int, int, int, float[]) |
|
* 使用动画值(从旧值到新值)多次调用。如果 getValues(Component) 返回多个值,则每个值都有自己独立的动画。 |
|
* 仅当传递给 paintWithAnimation(Component, Graphics, int, int, int, int) 的组件是 的 JComponent实例时,动画才有效。 |
|
* 在组件上设置客户端属性以存储动画状态。 |
|
* |
|
* @author vito |
|
* @since 11.0 |
|
* Created on 2024/1/29 |
|
*/ |
|
public interface AnimatedPainter { |
|
/** |
|
* 开始绘画。调用 paintAnimated(Component, Graphics2D, int, int, int, int, float[]) 一次来绘制当前值 |
|
* 或者如果值与上次绘制相比发生了变化,则它会启动动画并使用动画值(从旧值到新值)多次调用 |
|
* paintAnimated(Component, Graphics2D, int, int, int, int, float[]) 。 |
|
* |
|
* @param c 动画所属组件 |
|
* @param g 绘制上下文 |
|
* @param x x |
|
* @param y y |
|
* @param width 区域宽度 |
|
* @param height 区域高度 |
|
*/ |
|
default void paintWithAnimation(Component c, Graphics g, int x, int y, int width, int height) { |
|
AnimatedPainterSupport.paint(this, c, g, x, y, width, height); |
|
} |
|
|
|
/** |
|
* 绘制给定的(动画)值。 |
|
* 从 paintWithAnimation(Component, Graphics, int, int, int, int)调用。 |
|
* |
|
* @param c 动画所属组件 |
|
* @param g 绘制上下文 |
|
* @param x x |
|
* @param y y |
|
* @param width 区域宽度 |
|
* @param height 区域高度 |
|
* @param animatedValues 动画值,介于先前的值 getValues(Component) 和返回的最新值 getValues(Component) 之间 |
|
*/ |
|
void paintAnimated(Component c, Graphics2D g, int x, int y, int width, int height, float[] animatedValues); |
|
|
|
/** |
|
* 从 animator 调用以重新绘制区域。 |
|
* 用于限制重绘区域。例如,如果希望只有底部边框有动画。如果对多个边框进行动画处理(例如底部和右侧),那么单独的重绘是没有意义的, |
|
* 因为 Swing 重绘管理器会合并区域并重绘整个组件。默认实现会重新绘制整个给定区域。 |
|
*/ |
|
default void repaintDuringAnimation(Component c, int x, int y, int width, int height) { |
|
c.repaint(x, y, width, height); |
|
} |
|
|
|
/** |
|
* 获取组件的值。 |
|
* 如果值发生更改,则此类将从旧值动画到新值。如果返回多个值,则每个值都有自己独立的动画。 |
|
* 对于切换按钮,0 表示关闭和 1 表示打开 |
|
*/ |
|
float[] getValues(Component c); |
|
|
|
/** |
|
* 动画是否启用 |
|
*/ |
|
default boolean isAnimationEnabled() { |
|
return true; |
|
} |
|
|
|
/** |
|
* 返回动画的持续时间(以毫秒为单位)(默认值为 150)。 |
|
*/ |
|
default int getAnimationDuration() { |
|
return 150; |
|
} |
|
|
|
/** |
|
* 返回动画的分辨率(以毫秒为单位)(默认值为 10)。分辨率是计时事件之间的时间量。 |
|
*/ |
|
default int getAnimationResolution() { |
|
return 10; |
|
} |
|
|
|
/** |
|
* 返回动画的插值器。默认值为 {@link CubicBezierEasing#STANDARD_EASING}. |
|
*/ |
|
default Interpolator getAnimationInterpolator() { |
|
return CubicBezierEasing.STANDARD_EASING; |
|
} |
|
|
|
/** |
|
* 返回给定值索引和值的动画持续时间(以毫秒为单位)(默认值为 150)。 |
|
*/ |
|
default int getAnimationDuration(int valueIndex, float value) { |
|
return getAnimationDuration(); |
|
} |
|
|
|
/** |
|
* 返回给定值索引和值的动画分辨率(以毫秒为单位)(默认值为 10)。分辨率是计时事件之间的时间量 |
|
*/ |
|
default int getAnimationResolution(int valueIndex, float value) { |
|
return getAnimationResolution(); |
|
} |
|
|
|
/** |
|
* 返回给定值索引和值的动画插值器。默认值为 {@link CubicBezierEasing#STANDARD_EASING}. |
|
*/ |
|
default Interpolator getAnimationInterpolator(int valueIndex, float value) { |
|
return getAnimationInterpolator(); |
|
} |
|
|
|
/** |
|
* 返回用于存储动画支持的客户端属性键。 |
|
*/ |
|
default Object getClientPropertyKey() { |
|
return getClass(); |
|
} |
|
|
|
/** |
|
* 保存位置,提供给 repaintDuringAnimation(Component, int, int, int, int)使用重新绘制动画区域。 |
|
* 仅当传递到的 paintWithAnimation(Component, Graphics, int, int, int, int) 图形上下文使用转换的位置时才需要。 |
|
*/ |
|
static void saveRepaintLocation(AnimatedPainter painter, Component c, int x, int y) { |
|
AnimatedPainterSupport.saveRepaintLocation(painter, c, x, y); |
|
} |
|
}
|
|
|