Ignore:
Timestamp:
05/10/18 16:04:51 (6 years ago)
Author:
davidb
Message:

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:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/apollo/gui/FrameRenderPasses.java

    r355 r1102  
    11package org.apollo.gui;
    22
    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.Stroke;
    9 import java.awt.geom.Area;
    10 import java.awt.geom.Rectangle2D;
    113import java.util.LinkedList;
    124
    13 import org.apollo.AudioFrameKeyboardActions;
    14 import org.apollo.AudioFrameMouseActions;
     5import org.apollo.ApolloGestureActions;
    156import org.apollo.audio.util.Timeline;
    167import org.apollo.items.FramePlaybackLauncher;
     
    1910import org.apollo.widgets.LinkedTrack;
    2011import org.apollo.widgets.SampledTrack;
     12import org.expeditee.core.Clip;
     13import org.expeditee.core.Colour;
     14import org.expeditee.core.Dimension;
     15import org.expeditee.core.Fill;
     16import org.expeditee.core.Point;
     17import org.expeditee.core.Stroke;
     18import org.expeditee.core.TextLayout;
     19import org.expeditee.core.bounds.AxisAlignedBoxBounds;
     20import org.expeditee.gio.EcosystemManager;
     21import org.expeditee.gio.GraphicsManager;
     22import org.expeditee.gio.gesture.StandardGestureActions;
     23import org.expeditee.gio.input.KBMInputEvent.Key;
     24import org.expeditee.gio.input.StandardInputEventListeners;
    2125import org.expeditee.gui.Browser;
    2226import org.expeditee.gui.FrameGraphics;
    23 import org.expeditee.gui.FrameMouseActions;
    2427import org.expeditee.gui.FreeItems;
    2528import org.expeditee.gui.FrameGraphics.FrameRenderPass;
    2629import org.expeditee.items.Item;
    27 import org.expeditee.items.widgets.InteractiveWidget;
     30import org.expeditee.items.widgets.Widget;
    2831import org.expeditee.items.widgets.WidgetCorner;
    2932import org.expeditee.items.widgets.WidgetEdge;
     
    3134/**
    3235 * All final effects rendered here - to give extra feedback to the user and simply to make
    33  * it more apealing.
     36 * it more appealing.
    3437 * @author Brook Novak
    3538 *
     
    3740public class FrameRenderPasses implements FrameRenderPass {
    3841       
    39         private static final Color SHADED_EXPANDED_BACKING_COLOR = new Color(80, 80, 80, 140);
    40         private static final Color Y_HELPER_LINES_COLOR = Color.DARK_GRAY;
     42        private static final Colour SHADED_EXPANDED_BACKING_COLOR = Colour.FromRGBA255(80, 80, 80, 140);
     43        private static final Colour Y_HELPER_LINES_COLOR = Colour.DARK_GREY;
    4144        private static final Stroke Y_HELPER_LINES_STROKE = OverdubbedFrameTimeAxis.TRACK_TIMELINE_STROKE;
    4245       
     
    4851        private boolean shouldDrawFullscreenHelpers = false;
    4952       
    50         private FrameRenderPasses() {
     53        private FrameRenderPasses()
     54        {
    5155                FrameGraphics.addFrameRenderPass(this);
    5256        }
    5357       
    54         public static FrameRenderPasses getInstance() {
     58        public static FrameRenderPasses getInstance()
     59        {
    5560                return instance;
    5661        }
    5762
    58         public void paintFinalPass(Graphics g) {
     63        public void paintFinalPass()
     64        {
    5965                if (Browser._theBrowser == null) return;
    60                 int frameHeight = Browser._theBrowser.getContentPane().getHeight();
     66               
     67                GraphicsManager gm = EcosystemManager.getGraphicsManager();
     68               
     69                int frameHeight = EcosystemManager.getGraphicsManager().getWindowSize().getHeight();
    6170                if (ExpandedTrackManager.getInstance().isAnyExpandedTrackVisible()
    6271                                && !FreeItems.getInstance().isEmpty()) {
     
    6776                        for (Item i : FreeItems.getInstance()) {
    6877                                if (i instanceof WidgetCorner) {
    69                                         InteractiveWidget iw = ((WidgetCorner)i).getWidgetSource();
     78                                        Widget iw = ((WidgetCorner)i).getWidgetSource();
    7079                                       
    7180                                        if (iw != null && iw instanceof SampledTrack) {
     
    8493                        if (toPaint != null) {
    8594                                for (SampledTrack trackWidget : toPaint) {
    86                                         if (g.getClip() == null
    87                                                         || g.getClip().intersects(trackWidget.getComponant().getBounds()))
    88                                         trackWidget.paintInFreeSpace(g, true);
    89                                        
     95                                        if (gm.peekClip() == null || gm.peekClip().isNotClipped() || (!gm.peekClip().isFullyClipped() && gm.peekClip().getBounds().intersects(trackWidget.getBounds()))) {
     96                                                trackWidget.paintInFreeSpace(true);
     97                                        }
    9098                                }
    9199                        }
     
    93101                }
    94102               
    95                 OverdubbedFrameTimeAxis.getInstance().paint(g);
     103                OverdubbedFrameTimeAxis.getInstance().paint();
    96104               
    97105                TimeAxis timeAxis = OverdubbedFrameTimeAxis.getInstance().getTimeAxis();       
    98106                Timeline lastTimeline = OverdubbedFrameTimeAxis.getInstance().getLastTimeline();
    99107               
    100                 FramePlaybackBarRenderer.getInstance().paint((Graphics2D)g);
     108                FramePlaybackBarRenderer.getInstance().paint();
    101109
    102110                if (timeHelperLinesToPaint != null && timeAxis != null && lastTimeline != null) {
    103111
    104                         Rectangle r = OverdubbedFrameTimeAxis.getInstance().getCurrentTimelineArea();
     112                        AxisAlignedBoxBounds r = OverdubbedFrameTimeAxis.getInstance().getCurrentTimelineArea();
    105113                       
    106114                        // Draw helper bar and text
    107115                        for (Integer x : timeHelperLinesToPaint) {
    108116                               
    109                                 ((Graphics2D)g).setStroke(OverdubbedFrameTimeAxis.TRACK_TIMELINE_STROKE);
    110                                 g.setColor(Color.RED);
    111                                
    112                                 if (shouldDrawFullscreenHelpers)
    113                                         g.drawLine(x, 0, x, frameHeight);
    114                                 else
    115                                         g.drawLine(x, r.y, x, r.y + r.height);
    116                                                                        
     117                                if (shouldDrawFullscreenHelpers) {
     118                                        gm.drawLine(new Point(x, 0), new Point(x, frameHeight), Colour.RED, OverdubbedFrameTimeAxis.TRACK_TIMELINE_STROKE);
     119                                } else {
     120                                        gm.drawLine(new Point(x, r.getMinY()), new Point(x, r.getMinY() + r.getHeight()), Colour.RED, OverdubbedFrameTimeAxis.TRACK_TIMELINE_STROKE);
     121                                }
     122                               
    117123                                long ms = lastTimeline.getMSTimeAtX(x) - lastTimeline.getFirstInitiationTime();
    118124
     
    120126                                if (ms < 0) label = "-" + label;
    121127                               
    122                                 FontMetrics fm   = g.getFontMetrics(SampledTrackGraphViewPort.TIME_HELPER_FONT);
    123                                 Rectangle2D rect = fm.getStringBounds(label, g);
     128                                //FontMetrics fm   = g.getFontMetrics(SampledTrackGraphViewPort.TIME_HELPER_FONT);
     129                                //Rectangle2D rect = fm.getStringBounds(label, g);
     130                                TextLayout layout = EcosystemManager.getTextLayoutManager().layoutStringSimple(label, SampledTrackGraphViewPort.TIME_HELPER_FONT);
     131                                AxisAlignedBoxBounds rect = layout.getPixelBounds(0, 0);
    124132                                int labelWidth  = (int)(rect.getWidth());
    125133                                int labelHeight  = (int)(rect.getHeight());
    126134                               
    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                                
     135                                int y = r.getMinY() + (r.getHeight() / 2) - ((labelHeight + 4) / 2);
     136                               
     137                                gm.drawRectangle(new Point(x + 2,  y), new Dimension(labelWidth + 3, labelHeight + 4), 0.0, new Fill(SampledTrackGraphViewPort.TIME_HELPER_COLOR), SampledTrackGraphViewPort.TIME_HELPER_BORDERCOLOR, SampledTrackGraphViewPort.ZOOM_BACKING_BORDER_STROKE, null);
     138
     139                                gm.drawTextLayout(layout, new Point(x + 4, y + labelHeight), Colour.BLACK);
    142140                        }
    143141               
     
    146144//               Draw Y helper
    147145                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);
    157                        
    158                 }
    159                
    160        
    161         }
    162 
    163         public void paintPreLayeredPanePass(Graphics g) {
     146                        gm.drawLine(0, yAxisTimelineHelperToPaint.value, EcosystemManager.getGraphicsManager().getWindowSize().getWidth(), yAxisTimelineHelperToPaint.value, Y_HELPER_LINES_COLOR, Y_HELPER_LINES_STROKE);
     147                }
     148               
     149       
     150        }
     151
     152        public void paintPreLayeredPanePass()
     153        {
    164154                if (Browser._theBrowser == null) return;
    165155               
    166156                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) {
     157                        Dimension windowSize = EcosystemManager.getGraphicsManager().getWindowSize();
     158                        EcosystemManager.getGraphicsManager().drawRectangle(Point.ORIGIN, windowSize, 0.0, new Fill(SHADED_EXPANDED_BACKING_COLOR), null, null, null);
     159                }
     160               
     161        }
     162
     163        public Clip paintStarted(Clip currentClip)
     164        {
    177165                if (Browser._theBrowser == null) return currentClip;
    178166
    179                 LinkedList<InteractiveWidget> seen = null;
     167                LinkedList<Widget> seen = null;
    180168               
    181169                //boolean idDirty = false;
     
    189177                timeHelperLinesToPaint = null;
    190178                yAxisTimelineHelperToPaint = null;
    191                 shouldDrawFullscreenHelpers = AudioFrameKeyboardActions.isControlDown() ||
    192                         (AudioFrameKeyboardActions.isShiftDown() && !FreeItems.getInstance().isEmpty());
     179                shouldDrawFullscreenHelpers = StandardInputEventListeners.kbmStateListener.isKeyDown(Key.CTRL) ||
     180                        (StandardInputEventListeners.kbmStateListener.isKeyDown(Key.SHIFT) && !FreeItems.getInstance().isEmpty());
    193181
    194182                // Get free tracks and paint line helpers
    195                 if (!FreeItems.getInstance().isEmpty() || FrameMouseActions.getlastHighlightedItem() != null) {
     183                if (!FreeItems.getInstance().isEmpty() || StandardGestureActions.getlastHighlightedItem() != null) {
    196184
    197185                        LinkedList<Item> possibles = new LinkedList<Item>(FreeItems.getInstance());
    198                         if (FreeItems.getInstance().isEmpty() &&
    199                                         FrameMouseActions.getlastHighlightedItem() != null)
    200                                 possibles.add(FrameMouseActions.getlastHighlightedItem());
     186                        if (FreeItems.getInstance().isEmpty() && StandardGestureActions.getlastHighlightedItem() != null) {
     187                                possibles.add(StandardGestureActions.getlastHighlightedItem());
     188                        }
    201189                       
    202190                        for (Item i : possibles) {
    203191                               
    204                                 InteractiveWidget iw = null;
     192                                Widget iw = null;
    205193                               
    206194                                if (i instanceof WidgetCorner) {
     
    216204                                               
    217205                                                if (seen == null) {
    218                                                         seen = new LinkedList<InteractiveWidget>();
     206                                                        seen = new LinkedList<Widget>();
    219207                                                } else if (seen.contains(iw)) {
    220208                                                        continue;
     
    235223                }
    236224               
    237                 if ((AudioFrameMouseActions.isYAxisRestictionOn() || AudioFrameMouseActions.isSnapOn())
     225                if ((ApolloGestureActions.isYAxisRestictionOn() || ApolloGestureActions.isSnapOn())
    238226                        && !FreeItems.getInstance().isEmpty()) {
    239227                       
     
    255243        }
    256244       
    257         private void invalidateHelperLines(Area currentClip) {
    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                                         }
    267                                 }
    268                         }
    269                        
    270                         if (yAxisTimelineHelperToPaint != null && shouldDrawFullscreenHelpers) {
    271 
    272                                 currentClip.add(new Area(new Rectangle(
    273                                                 0,
    274                                                 yAxisTimelineHelperToPaint.value - 1,
    275                                                 Browser._theBrowser.getContentPane().getWidth(),
    276                                                 3)));
    277                        
    278                         }
    279                 }
    280         }
    281        
    282        
    283        
    284 
     245        private void invalidateHelperLines(Clip currentClip)
     246        {
     247                if (currentClip == null) return;
     248               
     249                if (timeHelperLinesToPaint != null && !timeHelperLinesToPaint.isEmpty()) {
     250                        currentClip.includeBounds(OverdubbedFrameTimeAxis.getInstance().getCurrentTimelineArea().clone());
     251                        if (shouldDrawFullscreenHelpers) {
     252                                int fsHeight = EcosystemManager.getGraphicsManager().getWindowSize().getHeight();
     253                                for (Integer n : timeHelperLinesToPaint) {
     254                                        currentClip.includeBounds(new AxisAlignedBoxBounds(n - 1, 0, 3, fsHeight));
     255                                }
     256                        }
     257                }
     258               
     259                if (yAxisTimelineHelperToPaint != null && shouldDrawFullscreenHelpers) {
     260
     261                        currentClip.includeBounds(new AxisAlignedBoxBounds(
     262                                        0,
     263                                        yAxisTimelineHelperToPaint.value - 1,
     264                                        EcosystemManager.getGraphicsManager().getWindowSize().getWidth(),
     265                                        3));
     266               
     267                }
     268        }
    285269}
Note: See TracChangeset for help on using the changeset viewer.