Ejemplo n.º 1
0
		private void CanvasAnimatedControl_OnDraw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args)
	    {
		    using (var ds = _blobRenderTarget.CreateDrawingSession())
		    {
				ds.Clear(sender.ClearColor);
				ds.Blend = CanvasBlend.Add;
				foreach (var blob in _blobs)
				{
					_blobBrush.Transform = Matrix3x2.CreateTranslation(blob.Position);
					ds.FillCircle(blob.Position, BlobSize, _blobBrush);
				}
			}
			_mask.Image = _un;
			using (args.DrawingSession.CreateLayer(_mask))
			{
				args.DrawingSession.DrawImage(_gbe);
			}

			foreach (var blob in _blobs)
		    {
			    blob.Position = Vector2.Add(blob.Position, blob.Velocity);
			    var xc = blob.Position.X < 0.0f || blob.Position.X > sender.Size.Width ? -1.0f : 1.0f;
			    var yc = blob.Position.Y < 0.0f || blob.Position.Y > sender.Size.Height ? -1.0f : 1.0f;
				blob.Velocity = new Vector2(blob.Velocity.X * xc, blob.Velocity.Y * yc);
			}
	    }
Ejemplo n.º 2
0
		private void CanvasAnimatedControl_OnDraw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args)
		{
			for (int i = 0; i <= _ringCount; i++)
			{
				var currentOffset = StartOffset + i*(RingPadding + RingStrokeWidth);
				using (var c = new CanvasPathBuilder(sender))
				{
					c.BeginFigure(currentOffset, 0.0f);
					c.AddArc(new Vector2(0.0f, 0.0f), currentOffset, currentOffset, 0.0f, (float)(Math.PI * 2));
					c.EndFigure(CanvasFigureLoop.Open);
					using (var g = CanvasGeometry.CreatePath(c))
					{
						var m = _pattern[_animationCounter + (_ringCount - i)];
						_brush.Transform = Matrix3x2.CreateRotation((float)(Math.PI * 2 * m), _center);
						using (args.DrawingSession.CreateLayer(_brush))
						{
							args.DrawingSession.DrawGeometry(g, _center, Color.FromArgb(255,
								m < 0.5 ? Convert.ToByte(Math.Floor(m * 2 * 255)) : Convert.ToByte(Math.Floor((1.5 - m) * 255)),
								m < 0.5 ? (byte)128 : Convert.ToByte(Math.Floor(m * 255)),
								255), RingStrokeWidth);
						}
					}
				}
			}
			_animationCounter++;
			if (_animationCounter > _pattern.Count - _ringCount - 1) _animationCounter = 0;
		}
Ejemplo n.º 3
0
        static Matrix3x2 GetDisplayTransform(ICanvasAnimatedControl canvas)
        {
            var outputSize = canvas.Size.ToVector2();
            var sourceSize = new Vector2(canvas.ConvertPixelsToDips(simulationW), canvas.ConvertPixelsToDips(simulationH));

            return(Utils.GetDisplayTransform(outputSize, sourceSize));
        }
 private void canvasMain_Draw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args)
 {
     foreach(Room room in Rooms)
     {
         room.Draw(args);
     }
 }
        private void Canvas_Draw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args)
        {
            var fontFormat = new Microsoft.Graphics.Canvas.Text.CanvasTextFormat
            {
                FontSize = 28,
            };

            args.DrawingSession.DrawRectangle(gameBoardConfig.GameBoard, Colors.Red);
            drawGameBoard(args, gameBoardConfig);

            scoreTextBox.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
                                             () => { scoreTextBox.Text = $"Score: {score}"; });
            bombsTextBox.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
                                             () => { bombsTextBox.Text = $"Bombs: {bombCount} bombs"; });
            flagsTextBox.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
                                             () => { flagsTextBox.Text = $"Flags: {flagCount} flags"; });
            timeTextBox.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
                                            () => { timeTextBox.Text = $"Time: {num} seconds"; });



            if (lastPoint.HasValue)
            {
                Point point = lastPoint.Value;

                double x = point.X;
                double y = point.Y;
                System.Numerics.Vector2 vec = new System.Numerics.Vector2(Convert.ToSingle(x), Convert.ToSingle(y));
                args.DrawingSession.DrawEllipse(vec, 10, 10, Colors.Red);
            }
        }
 private void Canvas_Update(ICanvasAnimatedControl sender, CanvasAnimatedUpdateEventArgs args)
 {
     num       = game.Duration;
     bombCount = game.Definition.numOfBomb;
     flagCount = game.GetFlagCount();
     score     = game.numberOfRevealedSpots;
 }
        private void canvas_Draw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args)
        {
            _fpsCounter++;

            if (ViewModel.DrawMode == DrawModes.DrawEllipse)
            {
                for (int i = 0; i < ViewModel.SpriteCount; i++)
                {
                    args.DrawingSession.FillCircle(_position[i].X, _position[i].Y, 5, _drawColour);
                }
            }
            else
            {
                using (var sb = args.DrawingSession.CreateSpriteBatch(CanvasSpriteSortMode.None, CanvasImageInterpolation.Linear, CanvasSpriteOptions.None))
                {
                    for (int i = 0; i < ViewModel.SpriteCount; i++)
                    {
                        sb.DrawFromSpriteSheet(_spriteBitmap, new Vector2(_position[i].X, _position[i].Y), _spriteRect, Vector4.One, _spriteOrigin, 0, Vector2.One, CanvasSpriteFlip.None);
                    }
                }
            }

            if (ViewModel.ShowDebug)
            {
                args.DrawingSession.DrawText(GetDebugText(), _canvasRect, _debugTextColour, _debugTextFormat);
            }
        }
Ejemplo n.º 8
0
 void Update(ICanvasAnimatedControl sender, CanvasAnimatedUpdateEventArgs args)
 {
     foreach (var ball in bouncingBalls)
     {
         ball.Update(sender.Size);
     }
 }
Ejemplo n.º 9
0
        private void OnDraw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args)
        {
            int updateCount = (int)(args.Timing.UpdateCount);

            var ds = args.DrawingSession;

            //
            // Pick layout
            //
            var size = sender.Size;

            Matrix3x2 counterTransform;
            Matrix3x2 graphTransform;
            CalculateLayout(size, width, height, out counterTransform, out graphTransform);

            //
            // Draw
            //
            ds.Transform = counterTransform;
            sweepRenderer.Draw(sender, args.Timing, ds);

            if (!ThumbnailGenerator.IsDrawingThumbnail)
            {
                ds.Transform = Matrix3x2.CreateTranslation(graphTransform.Translation);
                updatesPerDrawRenderer.Draw(args, ds, width * graphTransform.M11, height * graphTransform.M22);

                ds.Transform = Matrix3x2.Identity;
                touchPointsRenderer.Draw(ds);
            }
        }
Ejemplo n.º 10
0
        void canvas_Draw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args)
        {
            // Update the scrolling text rendertarget.
            DrawScrollingText(args.Timing);

            if (BloomEnabled && !ThumbnailGenerator.IsDrawingThumbnail)
            {
                // If the bloom filter is turned on, draw the teapot into a rendertarget.
                DemandCreateBloomRenderTarget(sender);

                using (var drawingSession = bloomRenderTarget.CreateDrawingSession())
                {
                    drawingSession.Clear(Colors.Black);

                    DrawTeapot(sender, drawingSession);
                }

                // Apply the bloom filter, which uses the rendertarget containing the teapot as input,
                // adds a glow effect, and draws the combined result to our CanvasAnimatedControl.
                ApplyBloomFilter(args.DrawingSession);
            }
            else
            {
                // If not blooming, draw the teapot directly to the CanvasAnimatedControl swapchain.
                DrawTeapot(sender, args.DrawingSession);
            }
        }
Ejemplo n.º 11
0
        void DemandCreateBloomRenderTarget(ICanvasAnimatedControl sender)
        {
            // Early-out if we already have a rendertarget of the correct size.
            // This compares against a stored copy of sender.Size, rather than reading back bloomRenderTarget.Size,
            // because the actual rendertarget size will be rounded to an integer number of pixels,
            // thus may not be identical to the size that was passed in when constructing the rendertarget.
            var senderSize = sender.Size;

            if (bloomRenderTarget != null &&
                bloomRenderTargetSize == senderSize &&
                bloomRenderTarget.Dpi == sender.Dpi)
            {
                return;
            }

            // Destroy the old rendertarget.
            if (bloomRenderTarget != null)
            {
                bloomRenderTarget.Dispose();
            }

            // Create the new rendertarget.
            bloomRenderTarget     = new CanvasRenderTarget(sender, senderSize);
            bloomRenderTargetSize = senderSize;

            // Configure the bloom effect to use this new rendertarget.
            extractBrightAreas.Source = bloomRenderTarget;
            bloomResult.Background    = bloomRenderTarget;
        }
        //Perform debug drawing
        protected void DebugDraw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args, DrawInfo info)
        {
            //If the collider is a box collider
            if (collider is BoxCollider)
            {
                //Cast the collider to a box collider
                BoxCollider boxCollider = (BoxCollider)collider;

                //Copy the collider into a debug collider
                DrawableBoxCollider debugCollider = new DrawableBoxCollider(boxCollider.Position, boxCollider.Size);

                //Draw the collider
                debugCollider.Draw(sender, args, info);
            }
            else

            //If the collider is a circle collider
            if (collider is CircleCollider)
            {
                //Cast the collider to a circle collider
                CircleCollider circleCollider = (CircleCollider)collider;

                //Copy the collider into a debug collider
                DrawableCircleCollider debugCollider = new DrawableCircleCollider(circleCollider.Position, circleCollider.Radius);

                //Draw the collider
                debugCollider.Draw(sender, args, info);
            }
        }
Ejemplo n.º 13
0
 private void Canvas_OnUpdate(ICanvasAnimatedControl sender, CanvasAnimatedUpdateEventArgs args)
 {
     foreach (var temp in FireflyParticle)
     {
         temp.Time(args.Timing.ElapsedTime);
     }
 }
Ejemplo n.º 14
0
 private void Canvas_Update(ICanvasAnimatedControl sender, CanvasAnimatedUpdateEventArgs args)
 {
     if (resourceRealizationSize != sender.Size)
     {
         needsResourceRecreation = true;
     }
 }
        protected ICanvasBrush GetBackgroundBrush(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args, CanvasImageBrush item, TimeSpan ellapsed)
        {
            var b = Bounds; //TransformBounds(Bounds);


            var ib = item.SourceRectangle ?? item.Image.GetBounds(sender);

            var scale = b.Width / ib.Width;

            if (ib.Height * scale < b.Height)
            {
                scale = b.Height / ib.Height;
            }

            ib.Height *= scale;
            ib.Width  *= scale;

            var offset = new Vector2((float)(b.Width - ib.Width), (float)(b.Height - ib.Height)) / 2f;


            var transform = Matrix3x2.CreateScale((float)scale);  // * Matrix3x2.CreateScale((float) (1f/scale));

            transform.Translation = new Vector2((float)b.X + offset.X, (float)b.Y + offset.Y);
            item.Transform        = transform;
            return(item);
        }
Ejemplo n.º 16
0
        // draw stuff onto the other pivot page here! @60FPS!
        private void drawingBoard_Draw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args)
        {
            var ds = args.DrawingSession;
            var t  = args.Timing;

            // frame count of (this) second.
            var fraCount   = t.UpdateCount % 60L;
            var timingInfo =
                $"<Elapsed time: {t.ElapsedTime}, Total time: {t.TotalTime}, " +
                $"\nFrame cout. of current second: {fraCount}>";

            if (t.UpdateCount % 10L == 0)
            {
                WriteLine(timingInfo);
            }

            var r = 70.0f * (float)Abs(Sin((t.UpdateCount % 240L) / 240.0 * 2 * PI));
            var o = new Vector2(250, 250);

            ds.DrawCircle(o, r, Colors.DarkViolet, 7);

            var lauren_rect = new Rect(100, 250, 100, 100);

            ds.FillRectangle(lauren_rect, lauren_brush);
            ds.DrawRectangle(lauren_rect, Colors.DarkGray); //draw a border around it
        }
        protected ICanvasBrush GetBackgroundBrush(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args, string item, TimeSpan ellapsed)
        {
            var commands = new CanvasCommandList(sender);
            var b        = TransformBounds(Bounds);

            using (var session = commands.CreateDrawingSession())
            {
                session.Clear(Color.FromArgb(255, 255, 255, 255));
                session.DrawLine((float)b.X, (float)b.Y, (float)b.X + (float)b.Width, (float)b.Y + (float)b.Height, Colors.Black);
                session.DrawLine((float)b.X, (float)b.Y + (float)b.Height, (float)b.X + (float)b.Width, (float)b.Y, Colors.Black);
                session.DrawText(item, TransformBounds(Bounds), Color.FromArgb(155, 63, 63, 63), new CanvasTextFormat()
                {
                    HorizontalAlignment = CanvasHorizontalAlignment.Center,
                    VerticalAlignment   = CanvasVerticalAlignment.Center,
                    FontSize            = 30f
                });
            }

            var brush = new CanvasImageBrush(sender, commands);

            brush.SourceRectangle = b;
            brush.Transform       = Matrix3x2.CreateTranslation((float)b.X, (float)b.Y);


            return(brush);
        }
Ejemplo n.º 18
0
            async Task CaptureThumbnailFromAnimatedControl(ICanvasAnimatedControl animatedControl, MethodInfo drawMethod)
            {
                // Wait for the control to be ready.
                while (!animatedControl.ReadyToDraw)
                {
                    await Task.Delay(1);
                }

                // Wait a while for any animations to settle into a good looking state.
                await Task.Delay(TimeSpan.FromSeconds(animationDelay));

                // We will mess with the control device from somewhere other than its game loop thread,
                // so must first pause the control to stop the game loop. There's no good way to
                // synchronize this, so we just wait a moment to give the game loop a chance to exit.
                animatedControl.Paused = true;
                // TODO #3317: once we can RunAsync on the update/render thread, use that instead of this
                await Task.Delay(TimeSpan.FromSeconds(0.1f));

                // Capture a thumbnail from the control.
                var timing = new CanvasTimingInformation
                {
                    TotalTime   = TimeSpan.FromSeconds(animationDelay),
                    UpdateCount = (int)(animationDelay * 60),
                };

                await CaptureThumbnailFromControl(animatedControl, animatedControl.Size, drawMethod, ds => new CanvasAnimatedDrawEventArgs(ds, timing));
            }
Ejemplo n.º 19
0
        private void canvas_AnimatedDraw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args)
        {
            float radius = (float)(1 + Math.Sin(args.Timing.TotalTime.TotalSeconds)) * 10f;

            blur.BlurAmount = radius;
            args.DrawingSession.DrawImage(blur);
        }
Ejemplo n.º 20
0
	    private void CanvasAnimatedControl_OnDraw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args)
	    {
			foreach (var waveParticle in _particles)
			{
				args.DrawingSession.DrawLine(waveParticle.DrawPosition, waveParticle.DrawVelocity, Colors.IndianRed, 3.0f);
				args.DrawingSession.FillCircle(waveParticle.DrawPosition, 3.0f, Colors.Aqua);
			}

		    foreach (var waveParticle in _particles) waveParticle.Tick();

			//?
		    var diff = new float[_particles.Count];
		    diff[0] = _particles[1].Position.Y - _particles[0].Position.Y;
		    for (int index = 1; index < _particles.Count - 1; index++)
		    {
			    var l = _particles[index - 1].Position.Y - _particles[index].Position.Y;
			    var r = _particles[index].Position.Y - _particles[index + 1].Position.Y;
			    diff[index] = (l - r)/2.0f;
		    }
		    diff[_particles.Count - 1] = _particles[_particles.Count - 1].Position.Y - _particles[_particles.Count - 2].Position.Y;

		    for (int index = 0; index < _particles.Count; index++)
		    {
			    //todo
		    }
	    }
Ejemplo n.º 21
0
        private void canvasWin2d_Update(ICanvasAnimatedControl sender, CanvasAnimatedUpdateEventArgs args)
        {
            // Loop over all the particles.
            for (int i = 0; i < maxParticles; i++)
            {
                // Update the horizontal position.
                particles[i].newLeft += particles[i].hDir;

                // If outside the bounds, then invert the direction of motion.
                if (particles[i].newLeft - radius <= 0)
                {
                    particles[i].hDir = 1;
                }
                else if (particles[i].newLeft >= wComponent)
                {
                    particles[i].hDir = -1;
                }

                // Update the vertical position.
                particles[i].newTop += particles[i].vDir;

                // If outside the bounds, then invert the direction of motion.
                if (particles[i].newTop - radius <= 0)
                {
                    particles[i].vDir = 1;
                }
                else if (particles[i].newTop >= hComponent)
                {
                    particles[i].vDir = -1;
                }
            }
        }
Ejemplo n.º 22
0
        private void Canvas_Draw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args)
        {
            EnsureResources(sender, sender.Size);

            textLayout.SetBrush(0, testString.Length, null);
            if (hasSelection)
            {
                int firstIndex = Math.Min(selectionStartIndex, selectionEndIndex);
                int length     = Math.Abs(selectionEndIndex - selectionStartIndex) + 1;
                CanvasTextLayoutRegion[] descriptions = textLayout.GetCharacterRegions(firstIndex, length);
                foreach (CanvasTextLayoutRegion description in descriptions)
                {
                    args.DrawingSession.FillRectangle(InflateRect(description.LayoutBounds), Colors.White);
                }
                textLayout.SetBrush(firstIndex, length, selectionTextBrush);
            }

            args.DrawingSession.DrawTextLayout(textLayout, 0, 0, textBrush);

            if (showPerCharacterLayoutBounds)
            {
                for (int i = 0; i < testString.Length; i++)
                {
                    CanvasTextLayoutRegion textLayoutRegion;
                    textLayout.GetCaretPosition(i, false, out textLayoutRegion);

                    args.DrawingSession.DrawRectangle(textLayoutRegion.LayoutBounds, Colors.Blue, 2);
                }
            }

            if (showDrawBounds)
            {
                args.DrawingSession.DrawRectangle(textLayout.DrawBounds, Colors.Green, 2);
            }
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Update du SlateView
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>

        private void OnSlateViewUpdate(ICanvasAnimatedControl sender, CanvasAnimatedUpdateEventArgs args)
        {
            if (machine.IsStarted)
            {
                var xboxGamepads = xboxGamepadManager.GetGamepads();

                // fusion entre les Gamepads XBOX et le keyboard

                int value1 = 0;
                int value2 = 0;

                if (xboxGamepads[0] != null)
                {
                    value1 = xboxGamepads[0].GetValue();
                }

                if (xboxGamepads[1] != null)
                {
                    value2 = xboxGamepads[1].GetValue();
                }

                value1 = value1 | value2;

                value2 = keyboardGamepad.GetValue();

                value1 = value1 | value2;

                machine.GamepadGlobal.SetValue(value1);
            }
        }
Ejemplo n.º 24
0
        //Displays this collider (for debugging)
        public void Draw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args, DrawInfo info)
        {
            //Draw box outline
            Vector2 lowerBound = (Position + info.offset) - (Size / 2);

            args.DrawingSession.DrawRectangle(new Rect(lowerBound.x, lowerBound.y, Size.x, Size.y), drawingColor);
        }
Ejemplo n.º 25
0
 private void Canvas_Update(ICanvasAnimatedControl sender, CanvasAnimatedUpdateEventArgs args)
 {
     if (!PAUSED)
     {
         covidGame.Update();
     }
 }
Ejemplo n.º 26
0
        void CanvasControl_Draw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args)
        {
            //args.DrawingSession.DrawText("Hello, world!", 100, 100, Colors.Yellow);
            if (!Character.swordCollected)
            {
                //args.DrawingSession.DrawRectangle(weapon.X_Location + 5f, weapon.Y_Location - 23f, 10, 46, Colors.Plum, 10);
                args.DrawingSession.DrawRectangle(Character.X_Location - 15f, Character.Y_Location - 12.5f, 25, 25, Colors.Black, 25);
            }
            if (Character.swordCollected)
            {
                args.DrawingSession.DrawRectangle(Character.X_Location - 15f, Character.Y_Location - 12.5f, 25, 25, Colors.Plum, 25);
            }
            foreach (Enemy x in enemies)
            {
                args.DrawingSession.DrawEllipse(x.X_Location, x.Y_Location, 10, 10, Colors.Green, 20);
                x.MoveToPlayer(Character.X_Location, Character.Y_Location);
            }
            foreach (Curtis_sRect x in walls)
            {
                args.DrawingSession.DrawRectangle(x.x, x.y, x.width, x.height, Colors.Black, x.brushSize);
            }

            if (!WinningCollectable.Collected)
            {
                args.DrawingSession.DrawRectangle(WinningCollectable.X_Location, WinningCollectable.Y_Location, 15, 15, Colors.Gold, 15);
            }
        }
Ejemplo n.º 27
0
        void DemandCreateBloomRenderTarget(ICanvasAnimatedControl sender)
        {
            float w = (float)sender.Size.Width;
            float h = (float)sender.Size.Height;

            // Early-out if we already have a rendertarget of the correct size.
            // Compare sizes as pixels rather than dips to avoid rounding artifacts.
            if (bloomRenderTarget != null &&
                bloomRenderTarget.SizeInPixels.Width == sender.ConvertDipsToPixels(w) &&
                bloomRenderTarget.SizeInPixels.Height == sender.ConvertDipsToPixels(h))
            {
                return;
            }

            // Destroy the old rendertarget.
            if (bloomRenderTarget != null)
            {
                bloomRenderTarget.Dispose();
            }

            // Create the new rendertarget.
            bloomRenderTarget = new CanvasRenderTarget(sender, w, h);

            // Configure the bloom effect to use this new rendertarget.
            extractBrightAreas.Source = bloomRenderTarget;
            bloomResult.Background    = bloomRenderTarget;
        }
Ejemplo n.º 28
0
        private void animatedControl_Draw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args)
        {
            args.DrawingSession.Clear(Colors.White);

            args.DrawingSession.DrawImage(bitmap, new System.Numerics.Vector2(200));
            animatedControl.Invalidate();
        }
Ejemplo n.º 29
0
 void Update(ICanvasAnimatedControl sender, CanvasAnimatedUpdateEventArgs args)
 {
     foreach (var ball in bouncingBalls)
     {
         ball.Update(sender.Size);
     }
 }
Ejemplo n.º 30
0
        private void OnGameLoopStarting(ICanvasAnimatedControl sender, object args)
        {
            //
            // The GestureRecognizer needs to be created and accessed from the 
            // same thread -- in this case the game loop thread, so we use the GameLoopStarting event 
            // for this.
            //

            gestureRecognizer = new GestureRecognizer();
            gestureRecognizer.GestureSettings = GestureSettings.ManipulationTranslateInertia | GestureSettings.ManipulationTranslateY;
                
            gestureRecognizer.ManipulationStarted += gestureRecognizer_ManipulationStarted;
            gestureRecognizer.ManipulationUpdated += gestureRecognizer_ManipulationUpdated;
            gestureRecognizer.ManipulationCompleted += gestureRecognizer_ManipulationCompleted;

            gestureRecognizer.InertiaTranslationDeceleration = -0.05f;

            //
            // When the GestureRecognizer goes into intertia mode (ie after the pointer is released)
            // we want it to generate ManipulationUpdated events in sync with the game loop's Update.
            // We do this by disabling AutoProcessIntertia and explicitly calling ProcessInertia() 
            // from the Update.
            //
            gestureRecognizer.AutoProcessInertia = false;

            inputSource = animatedControl.CreateCoreIndependentInputSource(CoreInputDeviceTypes.Mouse | CoreInputDeviceTypes.Pen | CoreInputDeviceTypes.Touch);

            inputSource.PointerPressed += Input_PointerPressed;
            inputSource.PointerMoved += Input_PointerMoved;
            inputSource.PointerReleased += Input_PointerReleased;
        }
Ejemplo n.º 31
0
        private void OnUpdate(ICanvasAnimatedControl sender, CanvasAnimatedUpdateEventArgs args)
        {
            float height      = (float)sender.Size.Height;
            float totalHeight = characters.Length * lineHeight + height;

            if (inManipulation)
            {
                if (gestureRecognizer != null)
                {
                    gestureRecognizer.ProcessInertia();
                }
            }
            else
            {
                velocity = velocity * 0.90f + targetVelocity * 0.10f;

                offset = offset + velocity;
            }

            offset = offset % totalHeight;
            while (offset < 0)
            {
                offset += totalHeight;
            }

            float top = height - offset;

            firstLine = Math.Max(0, (int)(-top / lineHeight));
            lastLine  = Math.Min(characters.Length, (int)((height + lineHeight - top) / lineHeight));
        }
Ejemplo n.º 32
0
        private void AnimaControl_Draw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args)
        {
            float t = ( float )args.Timing.TotalTime.TotalMilliseconds;

            if (Restarted)
            {
                Restarted = false;
                pt        = t;
            }

            t -= pt;

            // Center in the control.
            Vector2 position = (sender.Size.ToVector2() - grumpySize) / 2;

            position.Y -= grumpySize.Y * 0.5f;

            rippleEffect.Properties["t1"] = EaseOutCubic(t, 1500);
            rippleEffect.Properties["t2"] = EaseOutCubic(t, 1900);

            // Draw the custom effect.
            dissolveEffect.Source1 = bmpImage;
            dissolveEffect.Source2 = rippleEffect;

            args.DrawingSession.DrawImage(dissolveEffect, position);

            if (2000 < t)
            {
                sender.Paused = true;
            }
        }
Ejemplo n.º 33
0
        private void OnGameLoopStarting(ICanvasAnimatedControl sender, object args)
        {
            //
            // The GestureRecognizer needs to be created and accessed from the
            // same thread -- in this case the game loop thread, so we use the GameLoopStarting event
            // for this.
            //

            gestureRecognizer = new GestureRecognizer();
            gestureRecognizer.GestureSettings = GestureSettings.ManipulationTranslateInertia | GestureSettings.ManipulationTranslateY;

            gestureRecognizer.ManipulationStarted   += gestureRecognizer_ManipulationStarted;
            gestureRecognizer.ManipulationUpdated   += gestureRecognizer_ManipulationUpdated;
            gestureRecognizer.ManipulationCompleted += gestureRecognizer_ManipulationCompleted;

            gestureRecognizer.InertiaTranslationDeceleration = -0.05f;

            //
            // When the GestureRecognizer goes into intertia mode (ie after the pointer is released)
            // we want it to generate ManipulationUpdated events in sync with the game loop's Update.
            // We do this by disabling AutoProcessIntertia and explicitly calling ProcessInertia()
            // from the Update.
            //
            gestureRecognizer.AutoProcessInertia = false;

            inputSource = animatedControl.CreateCoreIndependentInputSource(CoreInputDeviceTypes.Mouse | CoreInputDeviceTypes.Pen | CoreInputDeviceTypes.Touch);

            inputSource.PointerPressed  += Input_PointerPressed;
            inputSource.PointerMoved    += Input_PointerMoved;
            inputSource.PointerReleased += Input_PointerReleased;
        }
Ejemplo n.º 34
0
        private void OnGameLoopStarting(ICanvasAnimatedControl sender, object args)
        {
            _gestureRecognizer = new GestureRecognizer();
            _gestureRecognizer.GestureSettings = GestureSettings.ManipulationTranslateX |
                                                 GestureSettings.ManipulationTranslateY |
                                                 GestureSettings.ManipulationScale;

            _gestureRecognizer.ManipulationStarted   += gestureRecognizer_ManipulationStarted;
            _gestureRecognizer.ManipulationUpdated   += gestureRecognizer_ManipulationUpdated;
            _gestureRecognizer.ManipulationCompleted += gestureRecognizer_ManipulationCompleted;

            //
            // When the GestureRecognizer goes into intertia mode (ie after the pointer is released)
            // we want it to generate ManipulationUpdated events in sync with the game loop's Update.
            // We do this by disabling AutoProcessIntertia and explicitly calling ProcessInertia()
            // from the Update.
            //
            _gestureRecognizer.InertiaTranslationDeceleration = -5.0f;
            _gestureRecognizer.AutoProcessInertia             = false;

            _inputDevice = Cvs.CreateCoreIndependentInputSource(
                CoreInputDeviceTypes.Mouse
                | CoreInputDeviceTypes.Touch
                | CoreInputDeviceTypes.Pen);

            _inputDevice.PointerPressed      += OnPointerPressed;
            _inputDevice.PointerReleased     += OnPointerReleased;
            _inputDevice.PointerWheelChanged += OnPointerWheelChanged;
            _inputDevice.PointerMoved        += OnPointerMoved;
        }
Ejemplo n.º 35
0
        private void canvas_Update(ICanvasAnimatedControl sender, CanvasAnimatedUpdateEventArgs args)
        {
            //Update game objects
            gameObjects.Update(MILLISECONDS_PER_FRAME);

            //Check for collision events
            collisions.CollisionTest();

            //Count down spawn timer
            spawnTime -= MILLISECONDS_PER_FRAME;

            //If timer ended
            if (spawnTime <= 0.0)
            {
                //Spawn an enemy
                SpawnEnemy();

                //Reset the timer
                ResetEnemySpawnTimer();
            }

            //If all players dead
            if (players.IsEmpty())
            {
                //Jump to main menu TODO (crashing due to a thread error)
                //this.Frame.Navigate(typeof(MainMenuPage));
            }
        }
Ejemplo n.º 36
0
        private void OnDraw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args)
        {
            var textDisplay = GenerateTextDisplay(sender, (float)sender.Size.Width, (float)sender.Size.Height);

            var blurEffect = new GaussianBlurEffect()
            {
                Source     = textDisplay,
                BlurAmount = 10
            };

            textOpacityBrush.StartPoint = blurOpacityBrush.StartPoint = new Vector2(0, 0);
            textOpacityBrush.EndPoint   = blurOpacityBrush.EndPoint = new Vector2(0, (float)sender.Size.Height);

            var ds = args.DrawingSession;

            using (ds.CreateLayer(blurOpacityBrush))
            {
                ds.DrawImage(blurEffect);
            }

            using (ds.CreateLayer(textOpacityBrush))
            {
                ds.DrawImage(textDisplay);
            }
        }
Ejemplo n.º 37
0
		private void Canvas_Draw(
			ICanvasAnimatedControl sender,
			CanvasAnimatedDrawEventArgs args)
		{
			this.renderer.SetDrawingSession(args.DrawingSession);

			this.world.Draw(this.renderer);

			this.renderer.ClearDrawingSession();
		}
Ejemplo n.º 38
0
        private void canvasMain_Draw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args)
        {
            map.Draw(args);
            rlbProminent.Draw(args);
            rlbLeaderboard.Draw(args);

            // args.DrawingSession.DrawLine(Statics.ColumnDividerTop, Statics.ColumnDividerBottom, Colors.White);
            // Leaderboard.Draw(args);

            //DrawDebug(args);
        }
Ejemplo n.º 39
0
        // Updates the Win2D canvas for each Draw operation, those are usually many times per second
        private void CanvasControl_Draw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args) {
            // Calculates the angles using using the time spent for each measure of time.    
            float secAngle = (float)(DateTime.Now.Second * 6.28) / 60 - polarFix;
            float minAngle = (float)(DateTime.Now.Minute * 6.28 + secAngle) / 60 - polarFix;
            float houAngle = (float)(DateTime.Now.Hour * 6.28 / 12) + (minAngle / 60) - polarFix;

            drawClock(args, midScreen, ray);

            drawClockPointer(args, midScreen, ray, secAngle, Colors.Red);
            drawClockPointer(args, midScreen, ray, minAngle, Colors.Blue);
            drawClockPointer(args, midScreen, ray, houAngle, Colors.Green);
        }
Ejemplo n.º 40
0
 private void canvasMain_Update(ICanvasAnimatedControl sender, CanvasAnimatedUpdateEventArgs args)
 {
     lock(TileLock)
     {
         for (int x = 0; x < nTilesX; x++)
         {
             for (int y = 0; y < nTilesY; y++)
             {
                 Tiles[x, y].Update(args);
             }
         }
     }
 }
        private void AnimatedCanvasCtrl_OnDraw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args)
        {
            if (_animatedMaskSurface == null)
                return;

            _angle = (float)((_angle + 1) % 360);
            var radians = (float)((_angle * Math.PI) / 180);
            // Calculate the new geometry based on the angle
            var updatedGeometry = _outerGeometry.CombineWith(_combinedGeometry,
                                                             Matrix3x2.CreateRotation(radians, new Vector2(_width / 2, _height / 2)),
                                                             CanvasGeometryCombine.Exclude);
            // Update the geometry in the Composition Mask
            _animatedMaskSurface.Redraw(updatedGeometry);
        }
Ejemplo n.º 42
0
		private void CanvasAnimatedControl_OnDraw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args)
		{
			lock (_staticPoints)
			{
				foreach (var staticPoint in _staticPoints)
				{
					args.DrawingSession.FillCircle(staticPoint.Position, staticPoint.IsInteractive ? 5.0f : 2.0f, Colors.White);
				}
			}
			lock (_movingPoints)
			{

			}
		}
Ejemplo n.º 43
0
        void Canvas_CreateResources(ICanvasAnimatedControl sender, CanvasCreateResourcesEventArgs args)
        {
            if (args.Reason == CanvasCreateResourcesReason.DpiChanged)
            {
                // These resources are all DPI independent, so no need to recreate them
                // if only the DPI has changed.
                return;
            }

            CreateFlameEffect();

            text = null;
            newText = textInput.Text;
        }
Ejemplo n.º 44
0
        private void Canvas_Draw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args)
        {
            var ds = args.DrawingSession;

            // If the text or font size has changed then recreate the text command list.
            var newFontSize = GetFontSize(sender.Size);
            if (newText != text || newFontSize != fontSize)
            {
                text = newText;
                fontSize = newFontSize;
                SetupText(sender);
            };

            ConfigureEffect(args.Timing);

            ds.DrawImage(composite, sender.Size.ToVector2() / 2);
        }
Ejemplo n.º 45
0
        void Update(ICanvasAnimatedControl sender, CanvasAnimatedUpdateEventArgs args)
        {
            var elapsedTime = (float)args.Timing.ElapsedTime.TotalSeconds;

            switch (CurrentMode)
            {
                case ParticleMode.Explosions:
                    CreateExplosions(elapsedTime);
                    break;

                case ParticleMode.SmokePlume:
                    CreateSmokePlume(elapsedTime);
                    break;
            }

            smokePlume.Update(elapsedTime);
            smoke.Update(elapsedTime);
            explosion.Update(elapsedTime);
        }
 private void canvasMain_Update(ICanvasAnimatedControl sender, CanvasAnimatedUpdateEventArgs args)
 {
     switch(State)
     {
         case GAMESTATE.ADDING_ROOMS:
             if (Rooms.Count < nMaxRooms)
             {
                 Rooms.Add(Room.CreateRandomRoom());
             }
             else
             {
                 State = GAMESTATE.SEPARATING_ROOMS;
             }
             break;
         case GAMESTATE.SEPARATING_ROOMS:
             break;
         case GAMESTATE.DONE:
             break;
     }
 }
Ejemplo n.º 47
0
        public void Draw(ICanvasAnimatedControl sender, CanvasDrawingSession drawingSession)
        {
            if (currentThunder == null)
            {
                return;
            }
            // 保护原先画布的混合模式
            var previousBlend = drawingSession.Blend;
            drawingSession.Blend = blendState;
            var builder = new CanvasPathBuilder(sender);
            builder.BeginFigure(0, 0);
            for (int i = 0; i < currentThunder.LifeLong; i++)
            {
                builder.AddLine(currentThunder.Path[i].X, currentThunder.Path[i].Y);
            }
            builder.EndFigure(CanvasFigureLoop.Open);
            builder.SetSegmentOptions(CanvasFigureSegmentOptions.ForceRoundLineJoin);

            // Draw the particle.
            var path = CanvasGeometry.CreatePath(builder);
            var NormalizeLifeTime = currentThunder.TimeSinceStart / currentThunder.Duration;
            byte opacity = (byte)((NormalizeLifeTime - 1) * (NormalizeLifeTime - 1) * 255);
            CanvasCommandList cl = new CanvasCommandList(sender);
            using (CanvasDrawingSession clds = cl.CreateDrawingSession())
            {
                clds.DrawGeometry(path, currentThunder.Position, Color.FromArgb((byte)(0.75f * opacity), 255, 255, 255), 6 * currentThunder.Luminace);
            }
            var lightAmount = 20.6f * currentThunder.Luminace * (NormalizeLifeTime - 1) * (NormalizeLifeTime - 1);
            blur.Source = cl;
            blur.BlurAmount = lightAmount;
            drawingSession.DrawImage(blur);
            drawingSession.DrawGeometry(path, currentThunder.Position, Color.FromArgb(opacity, 255, 240, 180), 2 * currentThunder.Luminace);
            drawingSession.Blend = previousBlend;
            if (NormalizeLifeTime > 1)
            {
                currentThunder = null;
            }
        }
Ejemplo n.º 48
0
        private void CanvasControl_OnDraw(ICanvasAnimatedControl canvasAnimatedControl, CanvasAnimatedDrawEventArgs args)
        {

            //if (startPointSet && endPointSet)
            //{
            //    args.DrawingSession.DrawLine(startPoint.ToVector2(), endPoint.ToVector2(), Colors.Red);

            //}
            //args.DrawingSession.DrawImage(translationEffect);
            foreach (var tank in Tanks)
            {
                args.DrawingSession.DrawImage(tank.translationEffect);
                if (tank.selected)
                {
                    args.DrawingSession.DrawCircle(tank.CurrentPosition, tank.size + 5.0f, Colors.Crimson);

                    //debug info
                    args.DrawingSession.DrawText(tank.CurrentPosition.ToString(), 100, 100, Colors.Red);

                    args.DrawingSession.DrawText("TargetPos:" + tank.TargetPosition.ToString(), 100, 150, Colors.Red);
                    args.DrawingSession.DrawText("FiringTarget:" + tank.FiringTarget.ToString(), 100, 200, Colors.Red);

                    args.DrawingSession.DrawText(tank.desiredRot.ToString(), 100, 250, Colors.Red);
                    args.DrawingSession.DrawText(tank.currentRot.ToString(), 100, 300, Colors.Red);
                    args.DrawingSession.DrawText((tank.currentRot - tank.desiredRot).ToString(), 100, 350, Colors.Red);

                }
            }

            foreach (var projectile in Projectiles)
            {
                args.DrawingSession.DrawCircle(projectile.pos.X, projectile.pos.Y, 5.0f, new CanvasSolidColorBrush(canvasAnimatedControl, Colors.Yellow));
                args.DrawingSession.DrawCircle(projectile.Target, 15.0f, Colors.Crimson, 5.0f);
            }


        }
Ejemplo n.º 49
0
 void canvas_Draw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args)
 {
     args.DrawingSession.DrawText(
         "This example is temporarily disabled for UAP.\n\n" +
         "We'll turn it on as soon as a UAP NuGet package\n" +
         "for the DirectX Tool Kit is available.",
         sender.Size.ToVector2() / 2,
         Colors.Red,
         new CanvasTextFormat
         {
             HorizontalAlignment = CanvasHorizontalAlignment.Center,
             VerticalAlignment = CanvasVerticalAlignment.Center,
         });
 }
Ejemplo n.º 50
0
        void DrawTeapot(ICanvasAnimatedControl sender, CanvasDrawingSession drawingSession)
        {
            Vector2 size = sender.Size.ToVector2();

            // Draw some text (using Win2D) to make sure this appears behind the teapot.
            if (!ThumbnailGenerator.IsDrawingThumbnail)
            {
                drawingSession.DrawText("Text drawn before the teapot", size * new Vector2(0.5f, 0.1f), Colors.Gray);
            }

            // Draw the teapot (using Direct3D).
            teapot.SetWorld(Matrix4x4.CreateFromYawPitchRoll(-spinTheTeapot, spinTheTeapot / 23, spinTheTeapot / 42));
            teapot.SetView(Matrix4x4.CreateLookAt(new Vector3(1.5f, 1, 0), Vector3.Zero, Vector3.UnitY));
            teapot.SetProjection(Matrix4x4.CreatePerspectiveFieldOfView(1, size.X / size.Y, 0.1f, 10f));

            teapot.Draw(drawingSession);

            // Draw more text (using Win2D) to make sure this appears above the teapot.
            if (!ThumbnailGenerator.IsDrawingThumbnail)
            {
                drawingSession.DrawText("\nText drawn after the teapot", size * new Vector2(0.5f, 0.1f), Colors.Gray);
            }
        }
Ejemplo n.º 51
0
 int DipsToPixelSize(ICanvasAnimatedControl sender, float dips)
 {
     System.Diagnostics.Debug.Assert(dips > 0);
     return Math.Max(sender.ConvertDipsToPixels(dips, CanvasDpiRounding.Round), 1);
 }
Ejemplo n.º 52
0
        void DemandCreateBloomRenderTarget(ICanvasAnimatedControl sender)
        {
            // Early-out if we already have a rendertarget of the correct size.
            // Compare sizes as pixels rather than DIPs to avoid rounding artifacts.
            if (bloomRenderTarget != null &&
                bloomRenderTarget.SizeInPixels.Width == DipsToPixelSize(sender, (float)sender.Size.Width) &&
                bloomRenderTarget.SizeInPixels.Height == DipsToPixelSize(sender, (float)sender.Size.Height))
            {
                return;
            }

            // Destroy the old rendertarget.
            if (bloomRenderTarget != null)
            {
                bloomRenderTarget.Dispose();
            }

            // Create the new rendertarget.
            bloomRenderTarget = new CanvasRenderTarget(sender, sender.Size);

            // Configure the bloom effect to use this new rendertarget.
            extractBrightAreas.Source = bloomRenderTarget;
            bloomResult.Background = bloomRenderTarget;
        }
Ejemplo n.º 53
0
 void canvas_Update(ICanvasAnimatedControl sender, CanvasAnimatedUpdateEventArgs args)
 {
     if (ThumbnailGenerator.IsDrawingThumbnail)
     {
         spinTheTeapot = 5.7f;
     }
     else if (SpinEnabled)
     {
         spinTheTeapot += (float)args.Timing.ElapsedTime.TotalSeconds;
     }
 }
Ejemplo n.º 54
0
        private void OnGameLoopStopped(ICanvasAnimatedControl sender, object args)
        {
            // Unregister the various input / gesture events.  Since these have strong thread affinity
            // this needs to be done on the game loop thread.

            inputSource.PointerPressed -= Input_PointerPressed;
            inputSource.PointerMoved -= Input_PointerMoved;
            inputSource.PointerReleased -= Input_PointerReleased;

            gestureRecognizer.ManipulationStarted -= gestureRecognizer_ManipulationStarted;
            gestureRecognizer.ManipulationUpdated -= gestureRecognizer_ManipulationUpdated;
            gestureRecognizer.ManipulationCompleted -= gestureRecognizer_ManipulationCompleted;
        }
Ejemplo n.º 55
0
 private void Canvas_Draw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args)
 {
     slideshow.Draw(args);
 }
Ejemplo n.º 56
0
 void canvas_Update(ICanvasAnimatedControl sender, CanvasAnimatedUpdateEventArgs args)
 {
 }
Ejemplo n.º 57
0
        private void OnDraw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args)
        {
            var textDisplay = GenerateTextDisplay(sender, (float)sender.Size.Width, (float)sender.Size.Height);

            var blurEffect = new GaussianBlurEffect()
            {
                Source = textDisplay,
                BlurAmount = 10
            };

            textOpacityBrush.StartPoint = blurOpacityBrush.StartPoint = new Vector2(0,0);
            textOpacityBrush.EndPoint = blurOpacityBrush.EndPoint = new Vector2(0, (float)sender.Size.Height);

            var ds = args.DrawingSession;

            using (ds.CreateLayer(blurOpacityBrush))
            {
                ds.DrawImage(blurEffect);
            }

            using (ds.CreateLayer(textOpacityBrush))
            {
                ds.DrawImage(textDisplay);
            }
        }
Ejemplo n.º 58
0
        void canvas_Draw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args)
        {
            // Update the scrolling text rendertarget.
            DrawScrollingText(args.Timing);

            if (BloomEnabled && !ThumbnailGenerator.IsDrawingThumbnail)
            {
                // If the bloom filter is turned on, draw the teapot into a rendertarget.
                DemandCreateBloomRenderTarget(sender);

                using (var drawingSession = bloomRenderTarget.CreateDrawingSession())
                {
                    drawingSession.Clear(Colors.Black);

                    DrawTeapot(sender, drawingSession);
                }

                // Apply the bloom filter, which uses the rendertarget containing the teapot as input,
                // adds a glow effect, and draws the combined result to our CanvasAnimatedControl.
                ApplyBloomFilter(args.DrawingSession);
            }
            else
            {
                // If not blooming, draw the teapot directly to the CanvasAnimatedControl swapchain.
                DrawTeapot(sender, args.DrawingSession);
            }
        }
Ejemplo n.º 59
0
        private void OnUpdate(ICanvasAnimatedControl sender, CanvasAnimatedUpdateEventArgs args)
        {
            float height = (float)sender.Size.Height;
            float totalHeight = characters.Length * lineHeight + height;

            if (inManipulation)
            {
                if (gestureRecognizer != null)
                    gestureRecognizer.ProcessInertia();
            }
            else
            {
                velocity = velocity * 0.90f + targetVelocity * 0.10f;

                offset = offset + velocity;
            }

            offset = offset % totalHeight;
            while (offset < 0)
                offset += totalHeight;

            float top = height - offset;
            firstLine = Math.Max(0, (int)(-top / lineHeight));
            lastLine = Math.Min(characters.Length, (int)((height + lineHeight - top) / lineHeight));
        }
Ejemplo n.º 60
0
        void Draw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args)
        {
            var ds = args.DrawingSession;

            smokePlume.Draw(ds, UseSpriteBatch);
            smoke.Draw(ds, UseSpriteBatch);
            explosion.Draw(ds, UseSpriteBatch);
        }