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

Method BoxPair

src/main/java/fieldbox/boxes/plugins/BoxPair.java:39–124  ·  view source on GitHub ↗
(Box root)

Source from the content-addressed store, hash-verified

37 }
38
39 public BoxPair(Box root)
40 {
41 this.root = root;
42
43 this.properties.putToMap(Commands.command, "Create Box Pair", (x) -> {
44 this.newBoxPair();
45 return null;
46 });
47 this.properties.putToMap(Commands.commandDoc, "Create Box Pair",
48 "Create a pair of boxes that are linked together. This is useful for representing a selection of a interval of time from a longer interval. In the parlance of video editing, for example, there's a _selection_ from some _footage_. In Field these are both represented by boxes.");
49
50
51 Cached<Object, Long, Object> work = FrameChangedHash.getCached(this, (a, last) -> {
52 checkPairs();
53 return null;
54 }, () -> salt);
55
56 this.properties.putToMap(Boxes.insideRunLoop, "main.__checkPairs__", () -> {
57 work.apply(null);
58 return true;
59 });
60
61 this.properties.putToMap(Callbacks.onFrameChanged, "__checkPairFrames__", (box, rect) -> {
62
63 if (!box.properties.isTrue(isPaired, false)) return rect;
64 boolean isMain = box.properties.get(Box.name).trim().length()>0;
65 Rect now = box.properties.get(Box.frame);
66 Rect next = rect;
67 FieldBoxWindow window = find(Boxes.window, both()).findFirst().get();
68 if (!window.getCurrentMouseState().keyboardState.isShiftDown()) {
69
70
71
72 double dx1 = now.x - next.x;
73 double dx2 = (now.x + now.w) - (next.x + next.w);
74 double dy1 = now.y - next.y;
75 double dy2 = (now.y + now.h) - (next.y + next.h);
76
77
78 if (isMain && eq(dx1, dx2) && eq(dy1, dy2)) {
79 // pure translation
80 Rect ff = box.properties.get(f).properties.get(Box.frame);
81 ff.x -= dx1;
82 ff.y -= dy1;
83 } else if (isMain && eq(now.x + now.w, next.x + next.w) && !eq(now.x, next.x)) {
84 // scale around end point;
85 double l1 = next.w / now.w;
86
87 Rect ff = box.properties.get(f).properties.get(Box.frame);
88 double newStart = (float) ((ff.x - (now.x + now.w)) * l1 + (now.x + now.w));
89 double newEnd = (float) (((ff.x + ff.w) - (now.x + now.w)) * l1 + (now.x + now.w));
90
91 ff.x = (float) newStart;
92 ff.w = (float) (newEnd - newStart);
93 } else if (isMain && eq(now.x, next.x) && !eq(now.x + now.w, next.x + next.w)) {
94 // scale around start point;
95 double l1 = next.w / now.w;
96

Callers

nothing calls this directly

Calls 13

newBoxPairMethod · 0.95
getCachedMethod · 0.95
checkPairsMethod · 0.95
eqMethod · 0.95
putToMapMethod · 0.80
isTrueMethod · 0.80
isShiftDownMethod · 0.80
getCurrentMouseStateMethod · 0.80
applyMethod · 0.65
getMethod · 0.65
lengthMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected