Example #1
0
        public void Next()
        {
            Children.Remove(fFormerPanel);
            fFormerPanel.BeginAnimation(Panel.OpacityProperty, null); // Remove animation (not required but this assists the garbage collector)
            fFormerPanel.Done();                                      // Notify former panel that it is no longer in use.

            // Memory leak checking

            /*
             * GC.Collect();
             * GC.WaitForPendingFinalizers();
             * GC.Collect(5, GCCollectionMode.Forced);
             */

            // Rotate the panels down
            fFormerPanel = fActivePanel;
            fActivePanel = fNextPanel;
            fNextPanel   = null;

            // Stop the former panel
            fFormerPanel.Stop();

            // Animate the next panel in and play it
            if (fFadeTime >= cMinFadeTime)
            {
                DoubleAnimation animation = new DoubleAnimation(0.0, 1.0, fFadeTime);
                fActivePanel.BeginAnimation(Panel.OpacityProperty, animation, HandoffBehavior.SnapshotAndReplace);
            }
            else
            {
                fActivePanel.Opacity = 1.0;
            }
            fActivePanel.IsMuted = fMuted;
            fActivePanel.Play();

            if (!fDirectionIsForward)
            {
                fEnumerator.MoveNext();
                fEnumerator.MoveNext();
                fDirectionIsForward = true;
            }

            // Prep the next panel
            fEnumerator.MoveNext(AdvanceFlags.Wrap);
            string filename = fEnumerator.Current;

            if (string.IsNullOrEmpty(filename))
            {
                fNextPanel = new TextPanel(cNoImagesFound);
            }
            else
            {
                fNextPanel = SlidePanel.Load(new Uri(filename));
                fNextPanel.ShowMetadata = fShowMetadata;
            }
            fNextPanel.Opacity = 0.0;
            Children.Add(fNextPanel);
        }
Example #2
0
        public void Prev()
        {
            if (fFormerPanel == null || fFormerPanel is TextPanel)
            {
                Message("At beginning.");
                return;
            }

            // Make sure we're ready for a reversal
            if (fFormerPanel.PanelState == PanelState.Init)
            {
                Message("Waiting for previous media to load...");
                return;
            }

            // Remove the prepped next panel
            Children.Remove(fNextPanel);
            fNextPanel.Done();    // Notify next panel that it is no longer in use.

            // Reverse-rotate the panels
            fNextPanel   = fActivePanel;
            fActivePanel = fFormerPanel;
            fFormerPanel = null;

            // Stop the formerly active panel
            fNextPanel.Stop();

            // Make it transparent again (remove existing animation)
            fNextPanel.BeginAnimation(Panel.OpacityProperty, null, HandoffBehavior.SnapshotAndReplace);
            fNextPanel.Opacity = 0.0;
            Debug.Assert(fActivePanel.Opacity == 1.0); // Ensure that the new active panel is visible
            Debug.WriteLine("New Active Panel: " + fActivePanel.Uri);

            // Play the new active panel
            fActivePanel.IsMuted = fMuted;
            fActivePanel.Play();

            if (fDirectionIsForward)
            {
                fEnumerator.MovePrev();
                fEnumerator.MovePrev();
                fDirectionIsForward = false;
            }

            // Load up a replacement former panel
            if (!fEnumerator.MovePrev() || string.IsNullOrEmpty(fEnumerator.Current))
            {
                fFormerPanel = new TextPanel("At Beginning");
            }
            else
            {
                fFormerPanel = SlidePanel.Load(new Uri(fEnumerator.Current));
                fFormerPanel.ShowMetadata = fShowMetadata;
            }
            Debug.Assert(fFormerPanel.Opacity == 1.0);
            Children.Insert(0, fFormerPanel);
        }
Example #3
0
        private void Tick()
        {
            fInTick = true;
            unchecked
            {
                // Hide the mouse cursor if it's been idle for a while
                if (fCursorDisplayedAt != 0 && fTimeOfLastTick - fCursorDisplayedAt > cHideCursorAfter)
                {
                    Cursor             = Cursors.None;
                    fCursorDisplayedAt = 0;
                }

                if (fAutoAdvanceAt != 0)
                {
                    int timeSinceAutoAdvance = fTimeOfLastTick - fAutoAdvanceAt;
                    // Subtract and compare to zero rather than just compare because of wrapping issues
                    if (timeSinceAutoAdvance > 0)
                    {
                        if (fNextPanel.PanelState != PanelState.Init || timeSinceAutoAdvance > cMaxWaitForLoad)
                        {
                            fAutoAdvanceAt = 0;
                            if (fActivePanel.PanelState == PanelState.Paused)
                            {
                                Debug.WriteLine("AutoPlay");
                                fActivePanel.Play();
                            }
                            else
                            {
                                Debug.WriteLine("AutoAdvance");
                                Next();
                            }
                        }
                        else
                        {
                            Message("Waiting for media to load...");
                            Debug.WriteLine(string.Format("Waiting for next image to load: name={0}, tick={1}", fNextPanel.Uri, fTimeOfLastTick - fAutoAdvanceAt));
                        }
                    }
                }

                if (fMessage != null && fTimeOfLastTick - fClearMessageAt > 0)
                {
                    Message(null);
                }
            }
            fInTick = false;
        }