Пример #1
0
 public Recorder()
 {
     storyboard = new Storyboard();
     storyboard.BeginTime = TimeSpan.Zero;
     storyboard.Duration = TimeSpan.Zero;
     storyboard.SetValue(Storyboard.ChildrenProperty, new TimelineCollection());
 }
Пример #2
0
 public GameLoop(FrameworkElement parent, double storyBoardMilliseconds)
 {
     gameLoop = new Storyboard();
     gameLoop.Duration = TimeSpan.FromMilliseconds(storyBoardMilliseconds);
     gameLoop.SetValue(FrameworkElement.NameProperty, "gameloop");
     parent.Resources.Add("gameloop", gameLoop);
     gameLoop.Completed += new EventHandler(gameLoop_Completed);
 }
Пример #3
0
 public void Attach(Canvas canvas)
 {
     _storyboard = new Storyboard();
     _storyboard.SetValue(FrameworkElement.NameProperty, "gameloop");
     canvas.Resources.Add("gameloop", _storyboard);
     _lastUpdateTime = DateTime.Now;
     _storyboard.Completed += storyboard_Completed;
     _storyboard.Begin();
 }
Пример #4
0
 public void Attach(Canvas canvas, string name, TickDelegate tickEvent, TimeSpan interval)
 {
     if (this.canvas != null) return;
     this.canvas = canvas;
     this.tickEvent = tickEvent;
     storyboard = new Storyboard();
     storyboard.SetValue<string>(Storyboard.NameProperty, name);
     canvas.Resources.Add(storyboard);
     lastUpdateTime = DateTime.Now;
     storyboard.Duration = new Duration(interval);
     storyboard.Completed += new EventHandler(Tick);
 }
Пример #5
0
        private void RenderWaiting_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
            {
                return;
            }

            storyboard = Resources["storyboard"] as Storyboard;
            if (storyboard != null)
            {
                storyboard.SetValue(Storyboard.TargetNameProperty, "animationTarget");
                storyboard.Begin(animationTarget);
            }
        }
Пример #6
0
 private void MoveWithAnimation(Popup popup, double newVertical)
 {
     var storyBoard = new Storyboard();
     storyBoard.SetValue(Storyboard.TargetProperty, popup);
     storyBoard.SetValue(Storyboard.TargetPropertyProperty, new PropertyPath("VerticalOffset"));
     storyBoard.Children.Add(new DoubleAnimation(popup.VerticalOffset, newVertical, TimeSpan.FromSeconds(0.25)));
     storyBoard.Completed += OnStoryBoardCompleted;
     storyBoard.Begin();
 }
Пример #7
0
 void _SetupYTranslationStoryboard(TranslateTransform transform, string sbName, double translation)
 {
     if (Resources.Contains(sbName))
     {
         Storyboard sb = Resources[sbName] as Storyboard;
         DoubleAnimationUsingKeyFrames anim = sb.Children[0] as DoubleAnimationUsingKeyFrames;
         SplineDoubleKeyFrame keyFrame = anim.KeyFrames[0] as SplineDoubleKeyFrame;
         keyFrame.Value = translation;
     }
     else
     {
         Storyboard sb = new Storyboard();
         sb.SetValue(FrameworkElement.NameProperty, sbName);
         DoubleAnimationUsingKeyFrames anim = new DoubleAnimationUsingKeyFrames();
         sb.Children.Add(anim);
         Storyboard.SetTarget(anim, transform);
         Storyboard.SetTargetProperty(anim, new PropertyPath("Y"));
         anim.BeginTime = new TimeSpan(0, 0, 0);
         SplineDoubleKeyFrame keyFrame = new SplineDoubleKeyFrame();
         KeySpline spline = new KeySpline();
         spline.ControlPoint1 = new Point(0, 1);
         spline.ControlPoint2 = new Point(1, 1);
         keyFrame.KeySpline = spline;
         keyFrame.KeyTime = new TimeSpan(0, 0, 1);
         keyFrame.Value = translation;
         anim.KeyFrames.Add(keyFrame);
         Resources.Add(sbName, sb);
     }
 }
Пример #8
0
        private void _AddStoryboard(UIElement panel, double value)
        {
            TransformGroup tGroup = new TransformGroup();
            TranslateTransform translate = new TranslateTransform();
            translate.Y = 0;
            tGroup.Children.Add(translate);
            panel.RenderTransform = tGroup;

            string sbName = (panel as FrameworkElement).Name + "Animation";

            if (Resources.Contains(sbName))
            {
                Storyboard sb = Resources[sbName] as Storyboard;
                DoubleAnimationUsingKeyFrames anim = sb.Children[0] as DoubleAnimationUsingKeyFrames;
                SplineDoubleKeyFrame keyFrame = anim.KeyFrames[0] as SplineDoubleKeyFrame;
                keyFrame.Value = -(value);
            }
            else
            {
                Storyboard sb = new Storyboard();
                sb.SetValue(NameProperty, sbName);
                DoubleAnimationUsingKeyFrames anim = new DoubleAnimationUsingKeyFrames();
                sb.Children.Add(anim);
                Storyboard.SetTargetName(anim, (panel as FrameworkElement).Name);
                Storyboard.SetTargetProperty(anim, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.Y)"));
                anim.BeginTime = new TimeSpan(0, 0, 0);
                SplineDoubleKeyFrame keyFrame = new SplineDoubleKeyFrame();
                KeySpline spline = new KeySpline();
                spline.ControlPoint1 = new Point(0, 1);
                spline.ControlPoint2 = new Point(1, 1);
                keyFrame.KeySpline = spline;
                keyFrame.KeyTime = new TimeSpan(0, 0, 1);
                keyFrame.Value = -(value);
                anim.KeyFrames.Add(keyFrame);
                Resources.Add(sbName, sb);
            }
        }
Пример #9
0
        private static Storyboard createDoubleAnimation(DependencyObject p, bool expanded)
        {
            DoubleAnimation a = new DoubleAnimation();
            a.Duration = new TimeSpan(0, 0, 0, 0, 200);
            Storyboard.SetTargetProperty(a, new PropertyPath(HeightProperty));

            CircleEase b = new CircleEase();
            b.EasingMode = EasingMode.EaseOut;
            a.EasingFunction = b;

            if (expanded)
            {
                a.From = (double)p.GetValue(CRMAppBar.ClosedHeightProperty);
                a.To = (double)p.GetValue(CRMAppBar.PanelHeightProperty);                
            }
            else
            {
                a.From = (double)p.GetValue(CRMAppBar.PanelHeightProperty);
                a.To = (double)p.GetValue(CRMAppBar.ClosedHeightProperty);
            }

            Storyboard sb = new Storyboard();
            sb.SetValue(Storyboard.TargetProperty, p);
            sb.Children.Add(a);
            return sb;
        }
Пример #10
0
        void OnCompositionTargetRendering(object sender, EventArgs args)
        {
            DateTime dateTime = DateTime.Now;

#if !USE_CANVAS_WITH_ANIMATION_FADEOUT

            // Determine the amount to decrease the intensity of each pixel
            accumulatedDecrease += 256 * (dateTime - lastDateTime).TotalSeconds / Persistence;
            int decrease = (int)accumulatedDecrease;

            // If integral decrease, sweep through the pixels
            if (decrease > 0)
            {
                accumulatedDecrease -= decrease;

            #if USE_WRITEABLEBITMAP

                for (int index = 0; index < writeableBitmap.Pixels.Length; index++)
                {
                    int pixel = writeableBitmap.Pixels[index];

                    if (pixel != 0)
                    {
                        int a = pixel >> 24 & 0xFF;
                        int r = pixel >> 16 & 0xFF;
                        int g = pixel >> 8 & 0xFF;
                        int b = pixel & 0xFF;

                        a = Math.Max(0, a - decrease);
                        r = Math.Max(0, r - decrease);
                        g = Math.Max(0, g - decrease);
                        b = Math.Max(0, b - decrease);

                        writeableBitmap.Pixels[index] = a << 24 | r << 16 | g << 8 | b;
                    }
                }

            #elif USE_CANVAS_WITH_MANUAL_FADEOUT

                // Decrease the color of each element
                foreach (UIElement child in screenCanvas.Children)
                {
                    SolidColorBrush brush = (child as Shape).Stroke as SolidColorBrush;
                    Color clr = brush.Color;
                    brush.Color = Color.FromArgb((byte)Math.Max(0, clr.A - decrease), clr.R, clr.G, clr.B);

                    if (brush.Color.A == 0)
                        removableElements.Add(child);
                }

                foreach (UIElement child in removableElements)
                    screenCanvas.Children.Remove(child);
            #endif 
            }
#endif
            if (XProvider != null && YProvider != null)
            {

#if USE_WRITEABLEBITMAP_WITH_OUTLINE_FILL

                points.Clear();
                
#else
                Polyline polyline = new Polyline
                {
                    StrokeThickness = this.Brightness,
                    Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0, 0xFF, 0)),
                    StrokeStartLineCap = PenLineCap.Round,
                    StrokeEndLineCap = PenLineCap.Round,
                    StrokeLineJoin = PenLineJoin.Round
                };

                PointCollection points = polyline.Points;
#endif

                // Interpolate from lastDateTime to current dateTime
                int milliseconds = (int)(dateTime - lastDateTime).TotalMilliseconds;

                for (int msec = 0; msec <= milliseconds; msec++)
                {
                    DateTime dt = lastDateTime + TimeSpan.FromMilliseconds(msec);

                    Point point = new Point(0.5 * LayoutRoot.ActualWidth * (1 + XProvider.GetAxisValue(dt)),
                                            0.5 * LayoutRoot.ActualHeight * (1 + YProvider.GetAxisValue(dt)));
                    points.Add(point);
                }

                lastDateTime = dateTime;         

#if USE_CANVAS_WITH_ANIMATION_FADEOUT

                ColorAnimation anima = new ColorAnimation
                {
                    To = Color.FromArgb(0, 0, 0xFF, 0),
                    Duration = TimeSpan.FromSeconds(this.Persistence)
                };

                Storyboard.SetTarget(anima, polyline.Stroke as SolidColorBrush);
                Storyboard.SetTargetProperty(anima, new PropertyPath(SolidColorBrush.ColorProperty));

                Storyboard storyboard = new Storyboard();
                storyboard.SetValue(Oscilloscope.AnimatedObjectProperty, polyline);
                storyboard.Children.Add(anima);
                storyboard.Completed += new EventHandler(storyboard_Completed);
                storyboard.Begin();
#endif

#if USE_CANVAS

                screenCanvas.Children.Add(polyline);

#elif USE_WRITEABLEBITMAP_WITH_POLYLINE

                writeableBitmap.Render(polyline, null);

#else // USE_WRITEABLEBITMAP_WITH_OUTLINE_FILL

                lineList.Clear();

                for (int i = 0; i < points.Count - 1; i++)
                {
                    RoundCappedLine line = new RoundCappedLine(points[i], points[i + 1], this.Brightness / 2);
                    lineList.Add(line);
                }

                for (int y = 0; y < writeableBitmap.PixelHeight; y++)
                {
                    xCollection.Clear();

                    foreach (RoundCappedLine line in lineList)
                        line.GetAllX(y, xCollection);

                    if (xCollection.Count > 0)
                    {
                        int rowIndex = y * writeableBitmap.PixelWidth;
                                
                        for (int pair = 0; pair < xCollection.Count; pair += 2)
                        {
                            int x1 = (int)xCollection[pair];
                            int x2 = (int)xCollection[pair + 1];

                            if (x1 != x2)
                            {
                                int xMin = Math.Max(0, Math.Min(writeableBitmap.PixelWidth - 1, Math.Min(x1, x2)));
                                int xMax = Math.Max(0, Math.Min(writeableBitmap.PixelWidth - 1, Math.Max(x1, x2)));

                                for (int x = xMin; x < xMax; x++)
                                {
                                    writeableBitmap.Pixels[rowIndex + x] = beamPixel;
                                }
                            }
                        }
                    }
                }
#endif
            }

#if USE_WRITEABLEBITMAP

            writeableBitmap.Invalidate();
#endif
            
        }