MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / TimeHelper

Class TimeHelper

src/main/java/fieldbox/boxes/plugins/TimeHelper.java:17–96  ·  view source on GitHub ↗

utilities for helping with moving the time slider around with the mouse

Source from the content-addressed store, hash-verified

15/**
16 * utilities for helping with moving the time slider around with the mouse
17 */
18public class TimeHelper extends Box implements Mouse.OnMouseDown {
19
20 private final Box root;
21
22 public TimeHelper(Box root) {
23 this.root = root;
24 this.properties.put(Planes.plane, "__always__");
25 this.properties.putToMap(Mouse.onMouseDown, "__timeHelper__", this);
26
27 }
28
29 @Override
30 public Mouse.Dragger onMouseDown(Window.Event<Window.MouseState> e, int button) {
31 if (button == 0) return button0(e);
32 return null;
33 }
34
35 protected Mouse.Dragger button0(Window.Event<Window.MouseState> e) {
36 if (!e.after.keyboardState.keysDown.contains(GLFW_KEY_S)) return null;
37 e.properties.put(Window.consumed, true);
38
39 Optional<Drawing> drawing = this.find(Drawing.drawing, both())
40 .findFirst();
41
42 Drawing.dirty(this);
43
44 Vec2 point = new Vec2(e.after.mx, e.after.my);
45
46 Box startAt = startAt(e.after, root);
47 if (startAt == root) {
48 // start anywhere
49
50 if (e.after.keyboardState.isShiftDown()) {
51 set((float) point.x);
52 return null;
53 } else {
54 final float start = (float) point.x;
55 final float startAtT = get();
56 return (e1, termination) -> {
57 Vec2 point1 = new Vec2(e1.after.mx, e1.after.my);
58 double d = point1.x-start;
59 set((float) (startAtT+d/5));
60 Drawing.dirty(this);
61 // TODO: actual feedback
62 return !termination;
63 };
64 }
65 } else {
66 if (Math.abs(point.x - startAt.properties.get(frame).x) < Math.abs(
67 point.x - startAt.properties.get(frame).x - startAt.properties.get(frame).w)) {
68 set(startAt.properties.get(frame).x);
69 return null;
70 } else {
71 set(startAt.properties.get(frame).x + startAt.properties.get(frame).w);
72 return null;
73 }
74 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected