[315] | 1 | package org.apollo.gui;
|
---|
| 2 |
|
---|
| 3 | import java.awt.Color;
|
---|
| 4 | import java.awt.FontMetrics;
|
---|
| 5 | import java.awt.Graphics;
|
---|
| 6 | import java.awt.Graphics2D;
|
---|
| 7 | import java.awt.Rectangle;
|
---|
[355] | 8 | import java.awt.Stroke;
|
---|
[315] | 9 | import java.awt.geom.Area;
|
---|
| 10 | import java.awt.geom.Rectangle2D;
|
---|
| 11 | import java.util.LinkedList;
|
---|
| 12 |
|
---|
[344] | 13 | import org.apollo.AudioFrameKeyboardActions;
|
---|
[355] | 14 | import org.apollo.AudioFrameMouseActions;
|
---|
[315] | 15 | import org.apollo.audio.util.Timeline;
|
---|
| 16 | import org.apollo.items.FramePlaybackLauncher;
|
---|
[333] | 17 | import org.apollo.items.RecordOverdubLauncher;
|
---|
[355] | 18 | import org.apollo.util.Mutable;
|
---|
[315] | 19 | import org.apollo.widgets.LinkedTrack;
|
---|
[318] | 20 | import org.apollo.widgets.SampledTrack;
|
---|
[315] | 21 | import org.expeditee.gui.Browser;
|
---|
| 22 | import org.expeditee.gui.FrameGraphics;
|
---|
| 23 | import org.expeditee.gui.FrameMouseActions;
|
---|
| 24 | import org.expeditee.gui.FreeItems;
|
---|
| 25 | import org.expeditee.gui.FrameGraphics.FrameRenderPass;
|
---|
| 26 | import org.expeditee.items.Item;
|
---|
| 27 | import org.expeditee.items.widgets.InteractiveWidget;
|
---|
| 28 | import org.expeditee.items.widgets.WidgetCorner;
|
---|
| 29 | import org.expeditee.items.widgets.WidgetEdge;
|
---|
| 30 |
|
---|
| 31 | /**
|
---|
| 32 | * All final effects rendered here - to give extra feedback to the user and simply to make
|
---|
| 33 | * it more apealing.
|
---|
| 34 | * @author Brook Novak
|
---|
| 35 | *
|
---|
| 36 | */
|
---|
| 37 | public class FrameRenderPasses implements FrameRenderPass {
|
---|
| 38 |
|
---|
| 39 | private static final Color SHADED_EXPANDED_BACKING_COLOR = new Color(80, 80, 80, 140);
|
---|
[355] | 40 | private static final Color Y_HELPER_LINES_COLOR = Color.DARK_GRAY;
|
---|
| 41 | private static final Stroke Y_HELPER_LINES_STROKE = OverdubbedFrameTimeAxis.TRACK_TIMELINE_STROKE;
|
---|
| 42 |
|
---|
[315] | 43 | private static FrameRenderPasses instance = new FrameRenderPasses();
|
---|
| 44 |
|
---|
[355] | 45 | private LinkedList<Integer> timeHelperLinesToPaint = null;
|
---|
| 46 | private Mutable.Integer yAxisTimelineHelperToPaint = null;
|
---|
| 47 |
|
---|
[315] | 48 | private boolean shouldDrawFullscreenHelpers = false;
|
---|
| 49 |
|
---|
| 50 | private FrameRenderPasses() {
|
---|
| 51 | FrameGraphics.addFrameRenderPass(this);
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | public static FrameRenderPasses getInstance() {
|
---|
| 55 | return instance;
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | public void paintFinalPass(Graphics g) {
|
---|
| 59 | if (Browser._theBrowser == null) return;
|
---|
| 60 | int frameHeight = Browser._theBrowser.getContentPane().getHeight();
|
---|
| 61 | if (ExpandedTrackManager.getInstance().isAnyExpandedTrackVisible()
|
---|
| 62 | && !FreeItems.getInstance().isEmpty()) {
|
---|
| 63 |
|
---|
| 64 | // Conceivable could have multiple
|
---|
[318] | 65 | LinkedList<SampledTrack> toPaint = null;
|
---|
[315] | 66 |
|
---|
| 67 | for (Item i : FreeItems.getInstance()) {
|
---|
| 68 | if (i instanceof WidgetCorner) {
|
---|
| 69 | InteractiveWidget iw = ((WidgetCorner)i).getWidgetSource();
|
---|
| 70 |
|
---|
[318] | 71 | if (iw != null && iw instanceof SampledTrack) {
|
---|
[315] | 72 |
|
---|
| 73 | if (toPaint == null) {
|
---|
[318] | 74 | toPaint = new LinkedList<SampledTrack>();
|
---|
[315] | 75 | } else if (toPaint.contains(iw)) {
|
---|
| 76 | continue;
|
---|
| 77 | }
|
---|
| 78 |
|
---|
[318] | 79 | toPaint.add((SampledTrack)iw);
|
---|
[315] | 80 | }
|
---|
| 81 | }
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | if (toPaint != null) {
|
---|
[318] | 85 | for (SampledTrack trackWidget : toPaint) {
|
---|
[315] | 86 | if (g.getClip() == null
|
---|
| 87 | || g.getClip().intersects(trackWidget.getComponant().getBounds()))
|
---|
| 88 | trackWidget.paintInFreeSpace(g, true);
|
---|
| 89 |
|
---|
| 90 | }
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | OverdubbedFrameTimeAxis.getInstance().paint(g);
|
---|
| 96 |
|
---|
| 97 | TimeAxis timeAxis = OverdubbedFrameTimeAxis.getInstance().getTimeAxis();
|
---|
| 98 | Timeline lastTimeline = OverdubbedFrameTimeAxis.getInstance().getLastTimeline();
|
---|
| 99 |
|
---|
| 100 | FramePlaybackBarRenderer.getInstance().paint((Graphics2D)g);
|
---|
| 101 |
|
---|
[355] | 102 | if (timeHelperLinesToPaint != null && timeAxis != null && lastTimeline != null) {
|
---|
[315] | 103 |
|
---|
| 104 | Rectangle r = OverdubbedFrameTimeAxis.getInstance().getCurrentTimelineArea();
|
---|
| 105 |
|
---|
| 106 | // Draw helper bar and text
|
---|
[355] | 107 | for (Integer x : timeHelperLinesToPaint) {
|
---|
[315] | 108 |
|
---|
[355] | 109 | ((Graphics2D)g).setStroke(OverdubbedFrameTimeAxis.TRACK_TIMELINE_STROKE);
|
---|
| 110 | g.setColor(Color.RED);
|
---|
| 111 |
|
---|
| 112 | if (shouldDrawFullscreenHelpers)
|
---|
[315] | 113 | g.drawLine(x, 0, x, frameHeight);
|
---|
[355] | 114 | else
|
---|
[315] | 115 | g.drawLine(x, r.y, x, r.y + r.height);
|
---|
[355] | 116 |
|
---|
[315] | 117 | long ms = lastTimeline.getMSTimeAtX(x) - lastTimeline.getFirstInitiationTime();
|
---|
| 118 |
|
---|
| 119 | String label = timeAxis.createSpecificTimeLabel(Math.abs(ms), 500.0);
|
---|
| 120 | if (ms < 0) label = "-" + label;
|
---|
| 121 |
|
---|
| 122 | FontMetrics fm = g.getFontMetrics(SampledTrackGraphViewPort.TIME_HELPER_FONT);
|
---|
| 123 | Rectangle2D rect = fm.getStringBounds(label, g);
|
---|
| 124 | int labelWidth = (int)(rect.getWidth());
|
---|
| 125 | int labelHeight = (int)(rect.getHeight());
|
---|
| 126 |
|
---|
| 127 | int y = r.y + (r.height / 2) - ((labelHeight + 4) / 2);
|
---|
| 128 |
|
---|
| 129 |
|
---|
| 130 | g.setColor(SampledTrackGraphViewPort.TIME_HELPER_COLOR);
|
---|
| 131 | g.fillRect(x + 2, y, labelWidth + 3, labelHeight + 4);
|
---|
| 132 |
|
---|
| 133 | g.setColor(SampledTrackGraphViewPort.TIME_HELPER_BORDERCOLOR);
|
---|
| 134 | ((Graphics2D)g).setStroke(SampledTrackGraphViewPort.ZOOM_BACKING_BORDER_STROKE);
|
---|
| 135 | g.fillRect(x + 2, y, labelWidth + 3, labelHeight + 4);
|
---|
| 136 |
|
---|
| 137 | g.setFont(SampledTrackGraphViewPort.TIME_HELPER_FONT);
|
---|
| 138 | g.setColor(Color.BLACK);
|
---|
| 139 | g.drawString(label, x + 4, y + labelHeight);
|
---|
| 140 |
|
---|
| 141 |
|
---|
| 142 | }
|
---|
[355] | 143 |
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 | // Draw Y helper
|
---|
| 147 | if (yAxisTimelineHelperToPaint != null) {
|
---|
| 148 |
|
---|
| 149 | ((Graphics2D)g).setStroke(Y_HELPER_LINES_STROKE);
|
---|
| 150 | g.setColor(Y_HELPER_LINES_COLOR);
|
---|
| 151 |
|
---|
| 152 | g.drawLine(
|
---|
| 153 | 0,
|
---|
| 154 | yAxisTimelineHelperToPaint.value,
|
---|
| 155 | Browser._theBrowser.getContentPane().getWidth(),
|
---|
| 156 | yAxisTimelineHelperToPaint.value);
|
---|
[315] | 157 |
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 |
|
---|
| 161 | }
|
---|
| 162 |
|
---|
| 163 | public void paintPreLayeredPanePass(Graphics g) {
|
---|
| 164 | if (Browser._theBrowser == null) return;
|
---|
| 165 |
|
---|
| 166 | if (ExpandedTrackManager.getInstance().isAnyExpandedTrackVisible()) {
|
---|
| 167 |
|
---|
| 168 | g.setColor(SHADED_EXPANDED_BACKING_COLOR);
|
---|
| 169 | g.fillRect(0, 0,
|
---|
| 170 | Browser._theBrowser.getContentPane().getWidth(),
|
---|
| 171 | Browser._theBrowser.getContentPane().getHeight());
|
---|
| 172 | }
|
---|
| 173 |
|
---|
| 174 | }
|
---|
| 175 |
|
---|
| 176 | public Area paintStarted(Area currentClip) {
|
---|
| 177 | if (Browser._theBrowser == null) return currentClip;
|
---|
| 178 |
|
---|
| 179 | LinkedList<InteractiveWidget> seen = null;
|
---|
| 180 |
|
---|
| 181 | //boolean idDirty = false;
|
---|
| 182 | //if (helperLinesToPaint != null) {
|
---|
| 183 | // idDirty = true;
|
---|
| 184 |
|
---|
| 185 | //}
|
---|
| 186 |
|
---|
| 187 | invalidateHelperLines(currentClip);
|
---|
| 188 |
|
---|
[355] | 189 | timeHelperLinesToPaint = null;
|
---|
| 190 | yAxisTimelineHelperToPaint = null;
|
---|
[344] | 191 | shouldDrawFullscreenHelpers = AudioFrameKeyboardActions.isControlDown() ||
|
---|
| 192 | (AudioFrameKeyboardActions.isShiftDown() && !FreeItems.getInstance().isEmpty());
|
---|
[315] | 193 |
|
---|
| 194 | // Get free tracks and paint line helpers
|
---|
| 195 | if (!FreeItems.getInstance().isEmpty() || FrameMouseActions.getlastHighlightedItem() != null) {
|
---|
| 196 |
|
---|
| 197 | LinkedList<Item> possibles = new LinkedList<Item>(FreeItems.getInstance());
|
---|
| 198 | if (FreeItems.getInstance().isEmpty() &&
|
---|
| 199 | FrameMouseActions.getlastHighlightedItem() != null)
|
---|
| 200 | possibles.add(FrameMouseActions.getlastHighlightedItem());
|
---|
| 201 |
|
---|
| 202 | for (Item i : possibles) {
|
---|
| 203 |
|
---|
| 204 | InteractiveWidget iw = null;
|
---|
| 205 |
|
---|
| 206 | if (i instanceof WidgetCorner) {
|
---|
| 207 | iw = ((WidgetCorner)i).getWidgetSource();
|
---|
| 208 | } else if (i instanceof WidgetEdge) {
|
---|
| 209 | iw = ((WidgetEdge)i).getWidgetSource();
|
---|
| 210 | }
|
---|
| 211 |
|
---|
| 212 | if (iw != null) {
|
---|
| 213 |
|
---|
[318] | 214 | if (iw != null && (iw instanceof SampledTrack ||
|
---|
[352] | 215 | iw instanceof LinkedTrack)) {
|
---|
[315] | 216 |
|
---|
| 217 | if (seen == null) {
|
---|
| 218 | seen = new LinkedList<InteractiveWidget>();
|
---|
| 219 | } else if (seen.contains(iw)) {
|
---|
| 220 | continue;
|
---|
| 221 | }
|
---|
| 222 |
|
---|
[355] | 223 | if (timeHelperLinesToPaint == null)
|
---|
| 224 | timeHelperLinesToPaint = new LinkedList<Integer>();
|
---|
[315] | 225 |
|
---|
[355] | 226 | timeHelperLinesToPaint.add(iw.getX());
|
---|
[315] | 227 | }
|
---|
[333] | 228 | } else if (i instanceof FramePlaybackLauncher || i instanceof RecordOverdubLauncher) {
|
---|
[355] | 229 | if (timeHelperLinesToPaint == null)
|
---|
| 230 | timeHelperLinesToPaint = new LinkedList<Integer>();
|
---|
| 231 | timeHelperLinesToPaint.add(i.getX());
|
---|
[315] | 232 | }
|
---|
| 233 | }
|
---|
| 234 |
|
---|
| 235 | }
|
---|
[355] | 236 |
|
---|
| 237 | if ((AudioFrameMouseActions.isYAxisRestictionOn() || AudioFrameMouseActions.isSnapOn())
|
---|
| 238 | && !FreeItems.getInstance().isEmpty()) {
|
---|
| 239 |
|
---|
| 240 | int smallestY = FreeItems.getInstance().get(0).getY();
|
---|
| 241 | for (Item i : FreeItems.getInstance()) {
|
---|
| 242 | if (i.getY() < smallestY) smallestY = i.getY();
|
---|
| 243 | }
|
---|
[315] | 244 |
|
---|
[355] | 245 | if (smallestY > 0) {
|
---|
| 246 | yAxisTimelineHelperToPaint = Mutable.createMutableInteger(smallestY);
|
---|
| 247 | }
|
---|
| 248 | }
|
---|
| 249 |
|
---|
[315] | 250 | // Invalidate on the fly
|
---|
| 251 | invalidateHelperLines(currentClip);
|
---|
| 252 |
|
---|
| 253 | return currentClip;
|
---|
| 254 |
|
---|
| 255 | }
|
---|
| 256 |
|
---|
| 257 | private void invalidateHelperLines(Area currentClip) {
|
---|
[355] | 258 | if (currentClip != null) {
|
---|
| 259 |
|
---|
| 260 | if (timeHelperLinesToPaint != null && !timeHelperLinesToPaint.isEmpty()) {
|
---|
| 261 | currentClip.add(new Area(OverdubbedFrameTimeAxis.getInstance().getCurrentTimelineArea()));
|
---|
| 262 | if (shouldDrawFullscreenHelpers) {
|
---|
| 263 | int fsHeight = Browser._theBrowser.getContentPane().getHeight();
|
---|
| 264 | for (Integer n : timeHelperLinesToPaint) {
|
---|
| 265 | currentClip.add(new Area(new Rectangle(n - 1, 0, 3, fsHeight)));
|
---|
| 266 | }
|
---|
[315] | 267 | }
|
---|
| 268 | }
|
---|
[355] | 269 |
|
---|
| 270 | if (yAxisTimelineHelperToPaint != null && shouldDrawFullscreenHelpers) {
|
---|
[315] | 271 |
|
---|
[355] | 272 | currentClip.add(new Area(new Rectangle(
|
---|
| 273 | 0,
|
---|
| 274 | yAxisTimelineHelperToPaint.value - 1,
|
---|
| 275 | Browser._theBrowser.getContentPane().getWidth(),
|
---|
| 276 | 3)));
|
---|
| 277 |
|
---|
| 278 | }
|
---|
[315] | 279 | }
|
---|
| 280 | }
|
---|
| 281 |
|
---|
| 282 |
|
---|
| 283 |
|
---|
| 284 |
|
---|
| 285 | }
|
---|