1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package my3d;
import java.util.ArrayList;
import javafx.animation.AnimationTimer;
import javafx.scene.control.CheckMenuItem;
import javafx.scene.control.MenuItem;
import my3d._slider_dialog.*;
public abstract class _viewer3d3 extends _viewer3d2 {
	@Override
	public void init_menu() {
		super.init_menu();
		if (!animation_enable) return;
		anim_dlg = new _slider_dialog(stage, "アニメーション",
			(values) -> {
			anim_cycle = Math.pow(10, values[0]);
			if (!b_anim) {
				anim_pos = values[1];
				repaint();
			}
		},
			new _slider_data("周期", 0, 1, Math.log10(anim_cycle)),
			new _slider_data("位置", 0, 1, anim_pos)
		);
		add_param_menu((index) -> {
			if (!anim_dlg.isShowing())
				anim_dlg.showAndWait();
		},
			"アニメーション"
		);
		ArrayList<MenuItem> items = add_setting_menu((index) -> {
			if (b_anim) timer.stop();
			else timer.start();
			b_anim = !b_anim;
		},
			"cアニメーション"
		);
		setting_anim_menu = (CheckMenuItem)items.get(0);
		timer = new AnimationTimer() {
			private long prev_t;
			@Override
			public void handle(long t) {
				if (t - prev_t < 1.0e+9) {
					anim_pos += (t - prev_t) / (anim_cycle * 1.0e+9);
					anim_pos -= (int)anim_pos;
					anim_dlg.init_value_at(1, anim_pos);
					repaint();
				}
				prev_t = t;
			}
		};
	}
	private boolean animation_enable;
	protected void set_animation_enable(boolean b) {
		animation_enable = b;
	}
	private double anim_cycle = 2, anim_pos = 0;
	private _slider_dialog anim_dlg;
	private boolean b_anim;
	private AnimationTimer timer;
	private CheckMenuItem setting_anim_menu;
	protected double get_anim_pos() { return anim_pos; }
	protected void set_anim_pos(double pos) {
		if (b_anim) {
			timer.stop();
			b_anim = false;
			setting_anim_menu.setSelected(false);
		}
		anim_pos = pos;
		anim_dlg.init_value_at(1, pos);
		repaint();
	}
}