1 | package org.apollo;
|
---|
2 |
|
---|
3 | import java.awt.event.MouseEvent;
|
---|
4 | import java.awt.event.MouseMotionListener;
|
---|
5 | import java.util.List;
|
---|
6 |
|
---|
7 | import org.apollo.widgets.LinkedTrack;
|
---|
8 | import org.apollo.widgets.SampledTrack;
|
---|
9 | import org.expeditee.gui.DisplayIO;
|
---|
10 | import org.expeditee.gui.Frame;
|
---|
11 | import org.expeditee.gui.FrameGraphics;
|
---|
12 | import org.expeditee.gui.FrameMouseActions;
|
---|
13 | import org.expeditee.gui.FreeItems;
|
---|
14 | import org.expeditee.items.Item;
|
---|
15 | import org.expeditee.items.widgets.InteractiveWidget;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * Apollos mouse actions extensions. Overrides expeditees frame mouse actions and
|
---|
19 | * forwards them onto expeditee (filtering out certain non-conflicting key-sequences).
|
---|
20 | *
|
---|
21 | * @author Brook Novak
|
---|
22 | *
|
---|
23 | */
|
---|
24 | public class AudioFrameMouseActions implements MouseMotionListener {
|
---|
25 |
|
---|
26 | private static final int COARSE_PLACEMENT_TOLERANCE = 100; // The minium distance from a track widet to auto-align free space items to
|
---|
27 |
|
---|
28 | public void mouseDragged(MouseEvent e) {
|
---|
29 | FrameMouseActions.getInstance().mouseDragged(e);
|
---|
30 | }
|
---|
31 |
|
---|
32 | public void mouseMoved(MouseEvent e) {
|
---|
33 |
|
---|
34 | boolean forwareToExpeditee = true;
|
---|
35 |
|
---|
36 | if (AudioFrameKeyboardActions.isControlDown != e.isControlDown()) {
|
---|
37 | AudioFrameKeyboardActions.isControlDown = e.isControlDown();
|
---|
38 | FrameGraphics.refresh(false); // For special post effects
|
---|
39 | }
|
---|
40 |
|
---|
41 | AudioFrameKeyboardActions.isShiftDown = e.isShiftDown();
|
---|
42 |
|
---|
43 | if (isYAxisRestictionOn() && !FreeItems.getInstance().isEmpty()) {
|
---|
44 |
|
---|
45 | // Restrict movement of free items to Y-Axis only
|
---|
46 | forwareToExpeditee = false;
|
---|
47 |
|
---|
48 | int smallestY = FreeItems.getInstance().get(0).getY();
|
---|
49 |
|
---|
50 | for (Item i : FreeItems.getInstance()) {
|
---|
51 | if (i.getY() < smallestY) smallestY = i.getY();
|
---|
52 | }
|
---|
53 |
|
---|
54 | for (Item i : FreeItems.getInstance()) {
|
---|
55 | i.setY(e.getY() + (i.getY() - smallestY));
|
---|
56 | }
|
---|
57 |
|
---|
58 | // Avoids no-op suppression in expeditee once anchored free items
|
---|
59 | FrameMouseActions.MouseX = e.getX();
|
---|
60 | FrameMouseActions.MouseY = e.getY();
|
---|
61 |
|
---|
62 | } else if (e.isShiftDown() &&
|
---|
63 | !FreeItems.getInstance().isEmpty()) {
|
---|
64 |
|
---|
65 | // Couse movement of free items: Restraining left-most pixel in items
|
---|
66 | // to the closest anchored track widgets x position.
|
---|
67 |
|
---|
68 | Frame currentFrame = DisplayIO.getCurrentFrame();
|
---|
69 | if (currentFrame != null) {
|
---|
70 |
|
---|
71 | // Search all anchored track x positions for the current frame
|
---|
72 | List<InteractiveWidget> widgets = currentFrame.getInteractiveWidgets();
|
---|
73 |
|
---|
74 | int closestXPosition = -1;
|
---|
75 | int closestDistance = -1;
|
---|
76 |
|
---|
77 | for (InteractiveWidget iw : widgets) {
|
---|
78 | if (iw instanceof SampledTrack || iw instanceof LinkedTrack) {
|
---|
79 | int distance = Math.abs(e.getX() - iw.getX());
|
---|
80 | if (closestDistance < 0 || distance < closestDistance) {
|
---|
81 | closestDistance = distance;
|
---|
82 | closestXPosition = iw.getX();
|
---|
83 | }
|
---|
84 |
|
---|
85 | distance = Math.abs(e.getX() - (iw.getX() + iw.getWidth()));
|
---|
86 | if (closestDistance < 0 || distance < closestDistance) {
|
---|
87 | closestDistance = distance;
|
---|
88 | closestXPosition = iw.getX() + iw.getWidth();
|
---|
89 | }
|
---|
90 |
|
---|
91 | }
|
---|
92 | }
|
---|
93 |
|
---|
94 | int smallestX = FreeItems.getInstance().get(0).getX();
|
---|
95 | int smallestY = FreeItems.getInstance().get(0).getY();
|
---|
96 |
|
---|
97 | for (Item i : FreeItems.getInstance()) {
|
---|
98 | if (i.getX() < smallestX) smallestX = i.getX();
|
---|
99 | if (i.getY() < smallestY) smallestY = i.getY();
|
---|
100 | }
|
---|
101 |
|
---|
102 | // Should auto-adjust free items?
|
---|
103 | if (closestDistance > 0 &&
|
---|
104 | closestDistance < COARSE_PLACEMENT_TOLERANCE) { // NB: 0 = do nothing since already there
|
---|
105 |
|
---|
106 | for (Item i : FreeItems.getInstance()) {
|
---|
107 | i.setPosition(
|
---|
108 | closestXPosition + (i.getX() - smallestX),
|
---|
109 | e.getY() + (i.getY() - smallestY));
|
---|
110 |
|
---|
111 | }
|
---|
112 |
|
---|
113 | } else if (closestDistance > 0) { // keep things set to cursor
|
---|
114 |
|
---|
115 | for (Item i : FreeItems.getInstance()) {
|
---|
116 | i.setPosition(
|
---|
117 | e.getX() + (i.getX() - smallestX),
|
---|
118 | e.getY() + (i.getY() - smallestY));
|
---|
119 | }
|
---|
120 |
|
---|
121 | }
|
---|
122 |
|
---|
123 | forwareToExpeditee = false;
|
---|
124 |
|
---|
125 | }
|
---|
126 |
|
---|
127 | }
|
---|
128 |
|
---|
129 | // Expeditees frame mouse actions uses an offset and fights over free-item
|
---|
130 | // movement if it listens to the mouse event router... therefore add an extra
|
---|
131 | // layer to avoid this... otherwise auto-aligned items jitter like crazy while
|
---|
132 | // moving the cursus
|
---|
133 | if (forwareToExpeditee) {
|
---|
134 | FrameMouseActions.getInstance().mouseMoved(e);
|
---|
135 | } else {
|
---|
136 | FrameGraphics.refresh(true);
|
---|
137 | }
|
---|
138 | }
|
---|
139 |
|
---|
140 | /**
|
---|
141 | * @return
|
---|
142 | * True if the user is restricting movement on the y-axis only
|
---|
143 | */
|
---|
144 | public static boolean isYAxisRestictionOn() {
|
---|
145 | return AudioFrameKeyboardActions.isControlDown && AudioFrameKeyboardActions.isShiftDown;
|
---|
146 | }
|
---|
147 |
|
---|
148 |
|
---|
149 | }
|
---|