Пример #1
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            _graphics = new SilverlightGraphics (LayoutRoot);

            var timer = new DispatcherTimer {
                Interval = TimeSpan.FromSeconds (1),
            };
            timer.Tick += delegate {
                Draw ();
            };
            timer.Start ();
        }
Пример #2
0
        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            //
            // Initialize the graphics context
            //
            _graphics = new SilverlightGraphics (LayoutRoot);

            //
            // Create a timer to refresh the clock
            //
            var timer = new DispatcherTimer {
                Interval = TimeSpan.FromSeconds (1),
            };
            timer.Tick += delegate {
                Draw ();
            };
            timer.Start ();
        }
        double Draw()
        {
            var del = Content;
            if (del == null) return 0;

            if (_graphics == null) {
                _graphics = new SilverlightGraphics (this);
            }

            var startT = DateTime.Now;

            _graphics.BeginDrawing ();
            _graphics.BeginEntity (del);

            //
            // Draw
            //
            var fr = new RectangleF (0, 0, (float)ActualWidth, (float)ActualHeight);
            if (_ppi != NativePointsPerInch) {
                fr.Width /= _ppi / (float)NativePointsPerInch;
                fr.Height /= _ppi / (float)NativePointsPerInch;
            }
            del.Frame = fr;
            try {
                del.Draw (_graphics);
            }
            catch (Exception) {
            }

            _graphics.EndDrawing ();

            var endT = DateTime.Now;
            return (endT - startT).TotalSeconds;
        }
 public void ResetGraphics()
 {
     _graphics = null;
 }
        void DrawTick(object sender, DispatcherTimerTickEventArgs e)
        {
            if (Paused) {
                _drawCount = 0;
                _drawTime = 0;
                return;
            }

            var del = Delegate;
            if (del == null) return;

            if (_graphics == null) {
                _graphics = new SilverlightGraphics(this);
            }

            var good = ActualWidth > 0 && ActualHeight > 0;
            if (!good) return;

            //
            // Start drawing
            //
            var startT = DateTime.Now;
            _graphics.BeginDrawing();

            //
            // Draw
            //
            var fr = new RectangleF(0, 0, (float)ActualWidth, (float)ActualHeight);
            if (_ppi != NativePointsPerInch) {
                fr.Width /= _ppi/(float) NativePointsPerInch;
                fr.Height /= _ppi / (float)NativePointsPerInch;
            }
            del.Frame = fr;
            try {
                del.Draw (_graphics);
            }
            catch (Exception) {
            }

            //
            // End drawing
            //
            _graphics.EndDrawing();

            var endT = DateTime.Now;

            _drawTime += (endT - startT).TotalSeconds;
            _drawCount++;

            //
            // Throttle
            //
            if (_drawCount > 2 && (DateTime.Now - _lastThrottleTime) >= ThrottleInterval) {

                _lastThrottleTime = DateTime.Now;

                var maxfps = 1.0 / (_drawTime / _drawCount);
                _drawTime = 0;
                _drawCount = 0;

                var fps = ClampUpdateFreq((int)(maxfps * CpuUtilization));

                if (Math.Abs(fps - _fps) > 1) {
                    _fps = fps;
                    Start();
                }
            }

            //
            // Notify
            //
            var df = DrewFrame;
            if (df != null) {
                df(this, EventArgs.Empty);
            }
        }