예제 #1
0
        private async void OnCreateResources(CanvasControl sender, object args)
        {
            if (Image == null)
            {
                return;
            }

            _imageLoaded = false;
            _scaleEffect = new ScaleEffect();
            _blurEffect  = new GaussianBlurEffect();

            var file = Image as StorageFile;

            if (file != null)
            {
                using (var thumbnail = await file.GetThumbnailAsync(ThumbnailMode.VideosView))
                {
                    _image = await CanvasBitmap.LoadAsync(sender.Device, thumbnail);
                }

                _imageLoaded = true;
                sender.Invalidate();
            }

            var url = Image as string;

            if (!string.IsNullOrEmpty(url))
            {
                _image = await CanvasBitmap.LoadAsync(sender.Device, new Uri(url));

                _imageLoaded = true;
                sender.Invalidate();
            }
        }
        private void OnUndo()
        {
            if (_strokes == null || !_strokes.Any())
            {
                return;
            }

            _strokes.Pop();
            _canvasControl.Invalidate();
        }
예제 #3
0
 private void EllipseShadowControl_SizeChanged(object sender, SizeChangedEventArgs e)
 {
     if (CanvasControl != null)
     {
         CanvasControl.Invalidate();
     }
 }
예제 #4
0
 public virtual void Invalidate()
 {
     if (_canvas != null)
     {
         _canvas.Invalidate();
     }
 }
예제 #5
0
        void gameCanvas_Draw(CanvasControl sender, CanvasDrawEventArgs args)
        {
            gameRender.updateGameData(gameLoop.getData());
            gameRender.Draw(args.DrawingSession);

            sender.Invalidate();
        }
예제 #6
0
        private void applyPage()
        {
            if (pager == null)
            {
                return;
            }
            var fontWidth  = FontSize + LetterSpacing;
            var fontHeight = FontSize + LineSpacing;
            var line       = Math.Floor(CanvasControl.ActualWidth / fontWidth);
            var count      = Math.Floor(CanvasControl.ActualHeight / fontHeight);
            var lines      = pager.GetPage(Page, (int)line, (int)count);

            renderTarget = new CanvasRenderTarget(CanvasControl, (float)CanvasControl.ActualWidth,
                                                  (float)CanvasControl.ActualHeight, 96);
            var font = new CanvasTextFormat();

            font.FontFamily = FontFamily.ToString();
            font.FontSize   = (float)FontSize;
            using (var ds = renderTarget.CreateDrawingSession())
            {
                ds.Clear(ColorHelper.FromArgb(255, 255, 255, 255));
                var lineIndex = -1;
                foreach (var item in lines)
                {
                    lineIndex++;
                    for (int i = 0; i < item.Lnegth; i++)
                    {
                        ds.DrawText(Text[item.Start + i].ToString(), new Vector2((float)((i + (item.IsNew ? 2 : 0)) * fontWidth),
                                                                                 (float)(lineIndex * fontHeight)), ColorHelper.FromArgb(255, 0, 0, 0), font);
                    }
                }
            }
            CanvasControl.Invalidate();
        }
예제 #7
0
        private void CanvasControl_PointerPressed(object sender, PointerRoutedEventArgs e)
        {
            PointerPoint ptrPoint = e.GetCurrentPoint(CanvasControl);

            _pointerPoints.Add(ptrPoint.Position.ToVector2());
            CanvasControl.Invalidate();
        }
예제 #8
0
        private async Task CreateResourcesAsync(CanvasControl sender)
        {
            m_BackgroundImage = await CanvasBitmap.LoadAsync(sender.Device, new Uri("ms-appx:///Assets/setup_bg.jpg"));

            //m_BackgroundImageInitialAlpha = await CanvasBitmap.LoadAsync(sender.Device, new Uri("ms-appx:///Assets/nuki_initial.png"));
            var blured = new GaussianBlurEffect()
            {
                Source     = m_BackgroundImage,
                BlurAmount = 10.0f,
            };

            m_BluredBackground = new BlendEffect()
            {
                Background = blured,
                Foreground = new ColorSourceEffect()
                {
                    Color = Windows.UI.Color.FromArgb(25, 0, 0, 0)
                },
                Mode = BlendEffectMode.Darken
            };

            m_BlendedBackground = new BlendEffect()
            {
                Background = blured,
                Foreground = new ColorSourceEffect()
                {
                    Color = Windows.UI.Color.FromArgb(100, 0, 0, 0)
                },
                Mode = BlendEffectMode.Darken
            };
            m_ImageStatus = ImageLoadStatus.Fading;
            sender.Invalidate();
        }
예제 #9
0
        private void Canvas_Draw(CanvasControl sender, CanvasDrawEventArgs args)
        {
            var size = sender.Size;
            var ds   = args.DrawingSession;

            // Animate and then display the current image effect.
            animationFunction((float)timer.Elapsed.TotalSeconds);

            ds.DrawImage(effect, (size.ToVector2() - currentEffectSize) / 2);

            // Draw text showing which effects are in use, but only if the screen is large enough to fit it.
            const float minSizeToShowText = 500;

            if ((size.Width + size.Height) / 2 > minSizeToShowText && !ThumbnailGenerator.IsDrawingThumbnail)
            {
                string text = activeEffectNames;

                if (textLabel != null)
                {
                    text += "\n\n" + textLabel;
                }

                ds.DrawText(text, 0, 80, Colors.White, textFormat);
            }

            sender.Invalidate();
        }
예제 #10
0
        public async Task SetCanvas(double width, double height, IRandomAccessStream randomAccessStream)
        {
            CanvasVisibility = Visibility.Visible;

            canvasControl.Height = height;
            canvasControl.Width  = width;

            canvasBitmap = await CanvasBitmap.LoadAsync(canvasControl, randomAccessStream);

            //CanvasDevice device = CanvasDevice.GetSharedDevice();
            //CanvasRenderTarget offscreen = new CanvasRenderTarget(device, (float)width/2,(float)height/2,96);
            if (PictureCompression.UsePictureCompression)
            {
                ScaleEffect effect = new ScaleEffect()
                {
                    Source = canvasBitmap,
                    Scale  = new Vector2((float)(160 / width))
                };
                CanvasDevice       device    = CanvasDevice.GetSharedDevice();
                CanvasRenderTarget offscreen = new CanvasRenderTarget(device, (float)160, (float)(height * 160 / width), 96);
                using (CanvasDrawingSession ds = offscreen.CreateDrawingSession())
                {
                    ds.Clear(Colors.Black);
                    ds.DrawImage(effect);
                }
                canvasControl.Height = offscreen.Size.Height;
                canvasControl.Width  = offscreen.Size.Width;
                canvasBitmap         = offscreen;
            }
            canvasControl.Invalidate();
            ASCIIText   = string.Empty;
            BitmapImage = new BitmapImage();
        }
예제 #11
0
 private void Shadow_SizeChanged(object sender, SizeChangedEventArgs e)
 {
     if (_shadowCanvas != null && e.NewSize != e.PreviousSize)
     {
         _shadowCanvas.Invalidate();
     }
 }
예제 #12
0
        void EnsureResources(CanvasControl sender, CanvasDrawEventArgs args)
        {
            if (!_needsResourceRecreation)
            {
                return;
            }

            if ((0 == sender.Size.Width) || (0 == sender.Size.Height))
            {
                this.OuterCircleRadius = 0;
            }
            else
            {
                this.OuterCircleRadius = Math.Min((float)sender.Size.Height / 2f - 2 * outerCircleThickness,
                                                  (float)sender.Size.Width / 2f - 2 * outerCircleThickness);
            }

            this.MiddleCircleRadius = OuterCircleRadius - MiddleCircleDelta;
            this.InnerCircleRadius  = MiddleCircleRadius - InnerCircleDelta;

            this.PointerStrokeStyle = new CanvasStrokeStyle()
            {
                StartCap  = CanvasCapStyle.Flat,
                EndCap    = CanvasCapStyle.Triangle,
                DashStyle = CanvasDashStyle.Solid
            };

            CreateInnerCircleBrush(sender);

            sender.Invalidate();

            _needsResourceRecreation = false;
        }
예제 #13
0
        /// <summary>
        /// Get the bytes for next frame, update the imagebuffer and invalidate the canvas to trigger a redraw with the new imagebuffer. Finally we set trigger a change frame which we're observing.
        /// </summary>
        private async Task ChangeCurrentFrameAsync()
        {
            try
            {
                var time  = Stopwatch.StartNew();
                var frame = await _decoder.GetFrameAsync((uint)_currentFrameIndex);

                var pixelData = await frame.GetPixelDataAsync(
                    BitmapPixelFormat.Bgra8,
                    BitmapAlphaMode.Straight,
                    new BitmapTransform(),
                    ExifOrientationMode.IgnoreExifOrientation,
                    ColorManagementMode.DoNotColorManage
                    );

                CreateActualPixels(pixelData.DetachPixelData());

                var newDelay = _currentGifFrame.DelayMilliseconds - time.ElapsedMilliseconds;
                if (newDelay > 0 && time.ElapsedMilliseconds < 300)
                {
                    await Task.Delay((int)newDelay);
                }

                time.Stop();

                _canvasControl?.Invalidate();

                SetNextFrame();
            }
            catch (Exception)
            {
                // We could potentially crash by leaving the viewport in the middle of a sequence
                StopByCatch();
            }
        }
예제 #14
0
        private void Canvas_Draw(CanvasControl sender, CanvasDrawEventArgs args)
        {
            var ds = args.DrawingSession;

            float w = (float)sender.ActualWidth;
            float h = (float)sender.ActualHeight;

            // Animate and then display the current image effect.
            animationFunction((float)timer.Elapsed.TotalSeconds);

            ds.DrawImage(effect, (new Vector2(w, h) - currentEffectSize) / 2);

            // Draw text showing which effects are in use, but only if the screen is large enough to fit it.
            const float minSizeToShowText = 550;

            if (w > minSizeToShowText && h > minSizeToShowText)
            {
                string text = GetActiveEffectNames();

                if (textLabel != null)
                {
                    text += "\n\n" + textLabel;
                }

                ds.DrawText(text, 0, 80, Colors.White);
            }

            sender.Invalidate();
        }
예제 #15
0
 private void Render()
 {
     if (App.Model.SecondSourceRenderTarget != null)
     {
         CanvasControl.Invalidate();//刷新直方图
         修图.BarPage.AdjustBarPage.Render();
     }
 }
예제 #16
0
 private void OnRendering(object sender, object e)
 {
     if (DateTime.UtcNow.Subtract(this.previousUpdateTime) > this.frameDuration)
     {
         this.previousUpdateTime = DateTime.UtcNow;
         canvas.Invalidate();
     }
 }
예제 #17
0
        private static void OnGraphicalPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            CanvasControl canvas = ((HistogramControl)d)._histogramCanvas;

            if (canvas != null)
            {
                canvas.Invalidate();
            }
        }
예제 #18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="appCtx"></param>
        /// <param name="canvas"></param>
        /// <param name="drawableEdges"></param>
        /// <param name="drawableVertices"></param>
        public static void LayoutDGraphRandom(
            AppContext appCtx,
            CanvasControl canvas,
            Dictionary <Guid, DrawableEdge> drawableEdges,
            Dictionary <Guid, DrawableVertex> drawableVertices)
        {
            drawableEdges.Clear();
            drawableVertices.Clear();
            foreach (KeyValuePair <Guid, UVertex> kvp in appCtx.CurrentGraph.Vertices)
            {
                Int32 min_x = Defines.VERTEX_SIZE;
                Int32 min_y = Defines.VERTEX_SIZE;
                Int32 max_x = 0;
                Int32 max_y = 0;
                if (appCtx.FitGraphToView == true)
                {
                    max_x = (Int32)canvas.ActualWidth - Defines.VERTEX_SIZE;
                    max_y = (Int32)canvas.ActualHeight - Defines.VERTEX_SIZE;
                }
                else
                {
                    max_x = Defines.VERTEX_SIZE * (appCtx.CurrentGraph.Vertices.Count + Defines.MAX_VERTEX_SPACE);
                    max_y = Defines.VERTEX_SIZE * (appCtx.CurrentGraph.Vertices.Count + Defines.MAX_VERTEX_SPACE);
                }

                Vector2        circlePos = new Vector2(appCtx.RandomSource.Next(min_x, max_x), appCtx.RandomSource.Next(min_y, max_y));
                DrawableVertex dn        = new DrawableVertex
                {
                    Position = circlePos,
                    VertexId = kvp.Value.VertexId,
                    Circle   = CanvasGeometry.CreateCircle(canvas, circlePos, Defines.VERTEX_SIZE)
                };
                drawableVertices[dn.VertexId] = dn;
            }

            foreach (KeyValuePair <Guid, UEdge> kvp in appCtx.CurrentGraph.Edges)
            {
                CanvasPathBuilder pathBuilder = new CanvasPathBuilder(canvas);

                DrawableEdge de = new DrawableEdge
                {
                    EdgeId       = kvp.Value.EdgeId,
                    HeadVertexId = kvp.Value.HeadVertexId,
                    TailVertexId = kvp.Value.TailVertexId,
                };
                de.HeadPosition = drawableVertices[de.HeadVertexId].Position;
                de.TailPosition = drawableVertices[de.TailVertexId].Position;
                pathBuilder.BeginFigure(de.HeadPosition);
                pathBuilder.AddLine(de.TailPosition);
                pathBuilder.EndFigure(CanvasFigureLoop.Open);
                de.Line = CanvasGeometry.CreatePath(pathBuilder);
                drawableEdges[de.EdgeId] = de;
            }

            canvas.Invalidate();
        }
예제 #19
0
 void canvasControl_Draw(
     CanvasControl sender,
     CanvasDrawEventArgs args)
 {
     using (CanvasDrawingSession drawSession = args.DrawingSession)
     {
         this.Update(drawSession.Device);
         this.Render(drawSession, (int)sender.ActualWidth, (int)sender.ActualHeight);
     }
     sender.Invalidate();
 }
        void EnsureResources(CanvasControl sender, CanvasDrawEventArgs args)
        {
            if (!_needsResourceRecreation)
            {
                return;
            }

            sender.Invalidate();

            _needsResourceRecreation = false;
        }
예제 #21
0
        private void DataChanged(DependencyPropertyChangedEventArgs e)
        {
            INotifyCollectionChanged oldCollection = e.OldValue as INotifyCollectionChanged;

            if (oldCollection != null)
            {
                oldCollection.CollectionChanged -= DataOnCollectionChanged;
            }

            INotifyCollectionChanged newCollection = e.NewValue as INotifyCollectionChanged;

            if (newCollection != null)
            {
                newCollection.CollectionChanged += DataOnCollectionChanged;
                if (_canvas != null)
                {
                    _canvas.Invalidate();
                }
            }
        }
예제 #22
0
        private void BinsSourceChanged(DependencyPropertyChangedEventArgs e)
        {
            INotifyCollectionChanged oldCollection = e.OldValue as INotifyCollectionChanged;

            if (oldCollection != null)
            {
                oldCollection.CollectionChanged -= BinSourceOnCollectionChanged;
            }

            INotifyCollectionChanged newCollection = e.NewValue as INotifyCollectionChanged;

            if (newCollection != null)
            {
                newCollection.CollectionChanged += BinSourceOnCollectionChanged;
                if (_histogramCanvas != null)
                {
                    _histogramCanvas.Invalidate();
                }
            }
        }
예제 #23
0
        private void RefreshTimer_Tick(object sender, object e)
        {
            System.Diagnostics.Debug.WriteLine("Ilość w kolejce=" + block.list.Count + " CZAS OD POCZĄTKU= " + watch.ElapsedMilliseconds);
            float temp = (float)block.list.Count / (float)5000;

            temp *= 100;
            System.Diagnostics.Debug.WriteLine("Ilość w kolejce=" + temp);
            progress.Value = temp;
            status.Text    = block.list.Count.ToString();
            if (controlOfCanvas != null && temp > 1)
            {
                controlOfCanvas.Invalidate();
            }
        }
예제 #24
0
        private void SetCreateMoveScrollArgsAndTriggerEvent(double newViewWidth,
                                                            double newViewHeight, double newMiddleOfViewX, double newMiddleOfViewY)
        {
            CurrentViewDimensions = new ViewDimensions(newViewWidth,
                                                       newViewHeight, newMiddleOfViewX, newMiddleOfViewY);
            MoveScrollArgs args = GetMoveScrollArgs(CurrentViewDimensions);

            if (!AreViewDimensionsPossible(CurrentViewDimensions))
            {
                return;
            }

            MoveScrollView(this, args);
            canvas.Invalidate();
        }
예제 #25
0
        private void CanvasControl_Draw(CanvasControl sender, CanvasDrawEventArgs args)
        {
            if (_drawable == null)
            {
                _drawable ??= new FragmentContextViewWavesDrawable(args.DrawingSession);
                _drawable.addParent(sender);
            }

            if (_service?.Manager != null)
            {
                _drawable.setState(_service.Manager.IsMuted ? 1 : 0);
                _drawable.draw(0, 48, (float)sender.Size.Width, 48 + 40, args.DrawingSession, sender, 1);
            }

            sender.Invalidate();
        }
예제 #26
0
        public void ZoomReal()
        {
            CanvasControl canvas = this.GetCanvas();

            if (canvas != null)
            {
                canvas.Width              = this.imageInfo.Width * this.initialZoom;
                canvas.Height             = this.imageInfo.Height * this.initialZoom;
                imageInfo.CurrentZoom     = this.initialZoom;
                this.translateTransform.X = 0;
                this.translateTransform.Y = 0;
                (canvas.Tag as CanvasImageBrush).Transform = Matrix3x2.CreateScale(this.imageInfo.CurrentZoom);
                canvas.Invalidate();
                this.UpdateManipulationMode();
            }
        }
        public void Draw(CanvasControl sender, CanvasDrawEventArgs args)
        {
            var size = sender.Size;
            using (var ds = args.DrawingSession)
            {
                ds.DrawImage(effect, (size.ToVector2() - currentEffectSize) / 2);
                var brush = new CanvasImageBrush(sender, this.effect)
                {
                    ExtendX = CanvasEdgeBehavior.Wrap,
                    ExtendY = CanvasEdgeBehavior.Wrap,
                    SourceRectangle = new Rect(0, bitmap.SizeInPixels.Height - 96, 96, 96)
                };

                ds.FillRectangle(0, 0, (float)this.ActualWidth, (float)this.ActualHeight, brush);
            }
            sender.Invalidate();
        }
예제 #28
0
        void OnDraw(CanvasControl sender, CanvasDrawEventArgs args)
        {
            this.Initialise();

            using (CanvasDrawingSession drawSession = args.DrawingSession)
            {
                foreach (var renderer in this.renderList)
                {
                    renderer.Update(sender.Device);
                    renderer.Render(
                        drawSession,
                        this.faceControl,
                        (int)sender.ActualWidth, (int)sender.ActualHeight);
                }
            }
            sender.Invalidate();
        }
예제 #29
0
        public void Zoom(Single scale)
        {
            CanvasControl canvas = this.GetCanvas();

            if (this.imageInfo != null)
            {
                if (scale * this.imageInfo.CurrentZoom < this.initialZoom)
                {
                    this.ZoomReal();
                }
                else if (IsZoomable(scale))
                {
                    canvas.Width  *= scale;
                    canvas.Height *= scale;
                    Double xp = this.translateTransform.X / ((canvas.ActualWidth - this.ActualWidth) / this.imageInfo.CurrentZoom);
                    Double yp = this.translateTransform.Y / ((canvas.ActualHeight - this.ActualHeight) / this.imageInfo.CurrentZoom);
                    this.imageInfo.CurrentZoom *= scale;
                    if (scale < this.initialZoom)
                    {
                        this.translateTransform.X = xp * ((canvas.Width - this.ActualWidth) / this.imageInfo.CurrentZoom);
                        this.translateTransform.Y = yp * ((canvas.Height - this.ActualHeight) / this.imageInfo.CurrentZoom);
                    }
                    if (this.translateTransform.X > 0)
                    {
                        this.translateTransform.X = 0;
                    }
                    if (this.translateTransform.Y > 0)
                    {
                        this.translateTransform.Y = 0;
                    }
                    (canvas.Tag as CanvasImageBrush).Transform =
                        Matrix3x2.CreateTranslation
                        (
                            new Vector2
                            (
                                (Single)this.translateTransform.X,
                                (Single)this.translateTransform.Y
                            )
                        ) *
                        Matrix3x2.CreateScale(this.imageInfo.CurrentZoom);
                    canvas.Invalidate();
                    this.UpdateManipulationMode();
                }
            }
        }
        public void Draw(CanvasControl sender, CanvasDrawEventArgs args)
        {
            var size = sender.Size;

            using (var ds = args.DrawingSession)
            {
                ds.DrawImage(effect, (size.ToVector2() - currentEffectSize) / 2);
                var brush = new CanvasImageBrush(sender, this.effect)
                {
                    ExtendX         = CanvasEdgeBehavior.Wrap,
                    ExtendY         = CanvasEdgeBehavior.Wrap,
                    SourceRectangle = new Rect(0, bitmap.SizeInPixels.Height - 96, 96, 96)
                };

                ds.FillRectangle(0, 0, (float)this.ActualWidth, (float)this.ActualHeight, brush);
            }
            sender.Invalidate();
        }
예제 #31
0
        private void canvasControl_Draw(CanvasControl sender, CanvasDrawEventArgs args)
        {
            if (DesignMode.DesignModeEnabled)
            {
                return;
            }

            if (modeInstance == null)
            {
                frameCounter = 0;
                modeInstance = CurrentMode.Create(this, sender);
            }

            modeInstance.Draw(args.DrawingSession, frameCounter, (float)sender.ActualWidth, (float)sender.ActualHeight);

            frameCounter++;
            sender.Invalidate();
        }
예제 #32
0
 private void canvas_Draw(CanvasControl sender, CanvasDrawEventArgs args)
 {
     //only draw if image is loaded
     if (bitmapImg != null)
     {
         args.DrawingSession.DrawImage(bitmapImg, bitmapRect);
         sender.Invalidate();
     }
 }
예제 #33
0
        private void UpdateJoystick(CanvasControl control, double posX, double posY, bool isFirstTime=false)
        {
            joystickDirection.X = (float)(posX - joystickCanvasSize.Width/2);
            joystickDirection.Y = (float)(posY - joystickCanvasSize.Height/2);

            float overRatio = joystickDirection.Length() / (float)JOYSTICK_HALF_SIZE;
            if (overRatio > 1.0f)
            {
                joystickDirection.X /= overRatio;
                joystickDirection.Y /= overRatio;
            }

            joystickDrawRect.X = joystickCanvasSize.Width / 2 + joystickDirection.X - JOYSTICK_HALF_SIZE;
            joystickDrawRect.Y = joystickCanvasSize.Height / 2 + joystickDirection.Y - JOYSTICK_HALF_SIZE;

            if (!isFirstTime)
            {
                control.Invalidate();
            }
        }
예제 #34
0
        private void Canvas_Draw(CanvasControl sender, CanvasDrawEventArgs args)
        {
            var size = sender.Size;
            var ds = args.DrawingSession;

            // Animate and then display the current image effect.
            animationFunction((float)timer.Elapsed.TotalSeconds);

            ds.DrawImage(effect, (size.ToVector2() - currentEffectSize) / 2);

            // Draw text showing which effects are in use, but only if the screen is large enough to fit it.
            const float minSizeToShowText = 500;

            if ((size.Width + size.Height) / 2 > minSizeToShowText && !ThumbnailGenerator.IsDrawingThumbnail)
            {
                string text = activeEffectNames;

                if (textLabel != null)
                {
                    text += "\n\n" + textLabel;
                }

                ds.DrawText(text, 0, 80, Colors.White, textFormat);
            }

            sender.Invalidate();
        }
예제 #35
0
        private void OnIOGraphDraw(CanvasControl sender, CanvasDrawEventArgs args)
        {
            var ds = args.DrawingSession;

            var mostRecentBytesRead = imageStream == null ? 0 : imageStream.GetBytesRead();

            bytesRead.Add(mostRecentBytesRead);

            // Flash the control red when there's some IO
            if (mostRecentBytesRead != 0)
                flash = 1;
            else
                flash *= 0.95f;

            ds.Clear(new Vector4(flash, 0, 0, 1));

            ds.DrawText("Bytes read", new Rect(0, 0, sender.ActualWidth, sender.ActualHeight), Colors.DarkRed,
                new CanvasTextFormat()
                {
                    VerticalAlignment = CanvasVerticalAlignment.Center,
                    HorizontalAlignment = CanvasHorizontalAlignment.Left,
                    FontSize = 12
                });


            int maxBytesRead = bytesRead.Max();
            maxBytesRead = Math.Max(1, maxBytesRead);

            int displayCount = 120;

            // Draw a moving vertical tick to allow us to see that the graph is
            // updating even if nothing is being read.
            drawCount = (drawCount + 1) % displayCount;
            var vx = (1.0f - (float)drawCount / (float)displayCount) * (float)sender.ActualWidth;
            ds.DrawLine(vx, (float)sender.ActualHeight - 5, vx, (float)sender.ActualHeight, Colors.Gray);


            // Draw the graph
            if (bytesRead.Count > 2)
            {
                var p = new CanvasPathBuilder(sender);
                for (int i = 0; i < Math.Min(displayCount, bytesRead.Count); ++i)
                {
                    var x = ((float)i / (float)displayCount) * (float)sender.ActualWidth;
                    var y = (float)sender.ActualHeight - ((float)bytesRead[i] / (float)maxBytesRead) * (float)sender.ActualHeight;

                    if (i == 0)
                        p.BeginFigure(x, y);
                    else
                        p.AddLine(x, y);
                }
                p.EndFigure(CanvasFigureLoop.Open);

                using (var g = CanvasGeometry.CreatePath(p))
                {
                    ds.DrawGeometry(g, Colors.White, 3, new CanvasStrokeStyle()
                    {
                        LineJoin = CanvasLineJoin.Round
                    });
                }

                int toRemove = bytesRead.Count - displayCount;
                if (toRemove > 0)
                    bytesRead.RemoveRange(0, toRemove);
            }

            sender.Invalidate();
        }
예제 #36
0
        void MainCanvas_Draw(CanvasControl sender, CanvasDrawEventArgs args)
        {
            var ds = args.DrawingSession;
            ds.Clear(Colors.Black);

            float dt = m_stopwatch.ElapsedMilliseconds / 1000.0f;
            m_stopwatch.Restart();

            // We are abusing the Draw call as our "game loop" = create new fireworks here
            // independent of the timing of input events.
            //if (m_wasPointerPressed == true) // Disable check so we always are rendering.
            {
                for (int i = 0; i < Constants.NumPerFrame; i++)
                {
                    var firework = new Firework(
                        (float)m_pointerPos.X + RndFloat(-Constants.PosRndMax, Constants.PosRndMax),
                        (float)m_pointerPos.Y + RndFloat(-Constants.PosRndMax, Constants.PosRndMax),
                        (float)(m_pointerPos.X - m_pointerPrevPos.X) / dt * Constants.PointerVelCoeff + RndFloat(-Constants.VelRndMax, Constants.VelRndMax),
                        (float)(m_pointerPos.Y - m_pointerPrevPos.Y) / dt * Constants.PointerVelCoeff + RndFloat(-Constants.VelRndMax, Constants.VelRndMax),
                        RndFloat(Constants.RadiusMin, Constants.RadiusMax),
                        Color.FromArgb(
                            255,
                            RndByte(0, 255),
                            RndByte(0, 255),
                            RndByte(0, 255)
                        ));

                    m_controller.AddFirework(firework);
                }
            }

            m_controller.UpdateFireworks(dt);
            m_controller.RenderFireworks(ds);

            // We snap the pointer position with each Draw call, independent of the frequency of input events.
            m_pointerPrevPos = m_pointerPos;

            // Render loop.
            sender.Invalidate();
        }
예제 #37
0
        private void canvasControl_Draw(CanvasControl sender, CanvasDrawEventArgs args)
        {
            if (DesignMode.DesignModeEnabled)
                return;

            if (modeInstance == null)
            {
                frameCounter = 0;
                modeInstance = CurrentMode.Create(this, sender);
            }

            modeInstance.Draw(args.DrawingSession, frameCounter, (float)sender.ActualWidth, (float)sender.ActualHeight);

            frameCounter++;
            sender.Invalidate();
        }