source: trunk/src/org/apollo/gui/OverdubbedFrameTimeAxis.java@ 1102

Last change on this file since 1102 was 1102, checked in by davidb, 6 years ago

Reworking of the code-base to separate logic from graphics. This version of Expeditee now supports a JFX graphics as an alternative to SWING

File size: 5.0 KB
Line 
1package org.apollo.gui;
2
3import org.apollo.audio.util.Timeline;
4import org.apollo.mvc.Observer;
5import org.apollo.mvc.Subject;
6import org.apollo.mvc.SubjectChangedEvent;
7import org.expeditee.core.Colour;
8import org.expeditee.core.Dimension;
9import org.expeditee.core.Fill;
10import org.expeditee.core.Point;
11import org.expeditee.core.Stroke;
12import org.expeditee.core.bounds.AxisAlignedBoxBounds;
13import org.expeditee.gio.EcosystemManager;
14import org.expeditee.gio.GraphicsManager;
15import org.expeditee.gio.InputManager.WindowEventListener;
16import org.expeditee.gio.InputManager.WindowEventType;
17import org.expeditee.gui.Browser;
18import org.expeditee.gui.DisplayController;
19
20/**
21 * The global timeline on the current overdubbed frame
22 *
23 * @author Brook Novak
24 *
25 */
26public class OverdubbedFrameTimeAxis implements Observer { //, DisplayIOObserver {
27
28 private TimeAxis timeAxis = null;
29 private AxisAlignedBoxBounds lastInvalidated;
30 private Timeline lastTimeline = null;
31
32 private static OverdubbedFrameTimeAxis instance = new OverdubbedFrameTimeAxis();
33
34 private static final int GLOBAL_TIMELINE_HEIGHT = 30;
35 private static final Colour GLOBAL_TIMELINE_BACKCOLOR = Colour.FromRGBA255(220, 220, 220, 100);
36 private static final Colour GLOBAL_EMPTY_TIMELINE_BACKCOLOR = Colour.FromRGBA255(240, 240, 240, 100);
37
38 public static final Stroke TRACK_TIMELINE_STROKE = new Stroke(1.0f, Stroke.CAP.SQUARE, Stroke.JOIN.BEVEL, new float[] { 5.0f, 5.0f }, 0.0f);
39
40 private static final Stroke TIMELINE_BORDER_STROKE = new Stroke(1.0f);
41
42 /**
43 * Singleton constructor,
44 */
45 private OverdubbedFrameTimeAxis() {
46
47 FrameLayoutDaemon.getInstance().addObserver(this);
48
49 //DisplayIO.addDisplayIOObserver(this);
50
51 // Listen for resize events
52 EcosystemManager.getInputManager().addWindowEventListener(new WindowEventListener()
53 {
54 @Override
55 public void onWindowEvent(WindowEventType type)
56 {
57 if (type == WindowEventType.WINDOW_RESIZED) updateAxis();
58 }
59 });
60 }
61
62
63 /**
64 *
65 * @return
66 * The singleton instance.
67 */
68 public static OverdubbedFrameTimeAxis getInstance() {
69 return instance;
70 }
71
72 public void setObservedSubject(Subject parent) {
73 }
74
75 public Subject getObservedSubject() {
76 return FrameLayoutDaemon.getInstance();
77 }
78
79 public void modelChanged(Subject source, SubjectChangedEvent event) {
80 updateAxis();
81 }
82
83 /*public void frameChanged() {
84 updateAxis();
85 }*/
86
87 private void updateAxis() {
88
89 if (Browser._theBrowser == null)
90 return;
91
92 lastTimeline = FrameLayoutDaemon.getInstance().getLastComputedTimeline();
93 if (lastTimeline == null ||
94 FrameLayoutDaemon.getInstance().getTimelineOwner() != DisplayController.getCurrentFrame()) {
95
96 // The frame layout daemon only lays out frames once - unless the user rearranges tracks
97 // on a frame then the daemon we re-calc the timeline... thus a timeline must be infferred
98
99 lastTimeline = FrameLayoutDaemon.inferTimeline(DisplayController.getCurrentFrame());
100
101 if (lastTimeline == null) { // no widgets
102 if (timeAxis != null && lastInvalidated != null) {
103 DisplayController.invalidateArea(lastInvalidated); // old position
104 }
105
106 timeAxis = null;
107 return;
108 }
109
110 }
111
112 timeAxis = new TimeAxis();
113
114 timeAxis.setAxis(
115 0,
116 lastTimeline.getRunningTime(),
117 -1,
118 lastTimeline.getRunningTime(),
119 lastTimeline.getPixelWidth());
120
121
122 AxisAlignedBoxBounds newBounds = getCurrentTimelineArea();
123 if (lastInvalidated != null && !lastInvalidated.equals(newBounds)) {
124 DisplayController.invalidateArea(lastInvalidated); // old position
125 }
126
127 DisplayController.invalidateArea(newBounds);
128
129 lastInvalidated = newBounds;
130
131 DisplayController.requestRefresh(true);
132
133 }
134
135 public AxisAlignedBoxBounds getCurrentTimelineArea()
136 {
137 assert(Browser._theBrowser != null);
138 int y = EcosystemManager.getGraphicsManager().getWindowSize().getHeight() - GLOBAL_TIMELINE_HEIGHT;
139 if (!DisplayController.isAudienceMode()) {
140 y -= DisplayController.getMessageBayPaintArea().getHeight();
141 }
142
143 if (y < 0) y = 0;
144
145 return new AxisAlignedBoxBounds(0, y, EcosystemManager.getGraphicsManager().getWindowSize().getWidth(), GLOBAL_TIMELINE_HEIGHT);
146 }
147
148
149 public void paint()
150 {
151 if (Browser._theBrowser == null) return;
152
153 if (timeAxis != null && lastTimeline != null) {
154
155 GraphicsManager gm = EcosystemManager.getGraphicsManager();
156
157 AxisAlignedBoxBounds r = getCurrentTimelineArea();
158 gm.drawRectangle(new Point(0, r.getMinY()), new Dimension(EcosystemManager.getGraphicsManager().getWindowSize().getWidth(), r.getHeight()), 0.0, new Fill(GLOBAL_EMPTY_TIMELINE_BACKCOLOR), null, null, null);
159
160 timeAxis.paint(
161 lastTimeline.getInitiationXPixel(),
162 r.getMinY(),
163 r.getHeight(),
164 GLOBAL_TIMELINE_BACKCOLOR);
165
166 gm.drawLine(new Point(0, r.getMinY()), new Point(EcosystemManager.getGraphicsManager().getWindowSize().getWidth(), r.getMinY()), Colour.DARK_GREY, TIMELINE_BORDER_STROKE);
167
168 }
169
170
171 }
172
173
174 public Timeline getLastTimeline() {
175 return lastTimeline;
176 }
177
178
179 public TimeAxis getTimeAxis() {
180 return timeAxis;
181 }
182
183
184
185}
Note: See TracBrowser for help on using the repository browser.