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