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); } }
public static void Draw(CanvasAnimatedDrawEventArgs args) { DrawBackground(args); DrawTitle(args); DrawItemsBorder(args); DrawItems(args); }
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; }
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 } }
private void canvasMain_Draw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args) { foreach(Room room in Rooms) { room.Draw(args); } }
public void DrawTitleLayout(CanvasAnimatedDrawEventArgs args, Vector2 position, Color color) { if (TitleLayout != null) { args.DrawingSession.DrawTextLayout(TitleLayout, position, color); } }
public void Draw(CanvasAnimatedDrawEventArgs args) { DrawBackground(args); DrawBorder(args); DrawFeedItemData(args); if (State == DISPLAYTILESTATE.ACTIVE || State == DISPLAYTILESTATE.FADING_IN) { DrawTimerBar(args); } }
public void Draw(CanvasAnimatedDrawEventArgs args) { if (Position != null) { args.DrawingSession.DrawTextLayout(TextLayout, Position, Colors.White); } }
public void Draw(Vector2 MapPosition, CanvasAnimatedDrawEventArgs args) { foreach(Region region in Regions) { region.Draw(MapPosition, args); } }
public void DrawSelected(CanvasAnimatedDrawEventArgs args) { if (Position != null) { args.DrawingSession.DrawTextLayout(TextLayout, Position, Colors.Yellow); } }
public void Draw(CanvasAnimatedDrawEventArgs args) { if (State == CURSOR_STATE.ON) { args.DrawingSession.DrawTextLayout(CursorCharacter, Position, Color); } }
private void Tick(CanvasAnimatedDrawEventArgs args) { //swipe var leftN = new Vector2(_leftCenter.X + (float) Math.Sin(ToRad(_loopCounter))*_swiperLength, _leftCenter.Y + (float) Math.Cos(ToRad(_loopCounter))*_swiperLength); var rightN = new Vector2(_rightCenter.X + (float) Math.Sin(ToRad(-1*_loopCounter + 180))*_swiperLength, _rightCenter.Y + (float) Math.Cos(ToRad(-1*_loopCounter + 180))*_swiperLength); args.DrawingSession.DrawLine(_leftCenter, leftN, Colors.Black, 1.0f); args.DrawingSession.DrawLine(_rightCenter, rightN, Colors.Black, 1.0f); //cleanup for (var i = _lines.Count - 1; i >= 0; i--) { if (_lines[i].Timeout == 0) _lines.Remove(_lines[i]); } //draw foreach (var fadingLine in _lines) { args.DrawingSession.DrawLine(fadingLine.Start, fadingLine.End, Color.FromArgb((byte) (80*((float) fadingLine.Timeout/FadeStart)), 0, 0, 0)); fadingLine.Timeout -= 1; } //add new _lines.Add(new FadingLine {End = rightN, Start = leftN, Timeout = FadeStart}); _lines.Add(new FadingLine {End = rightN, Start = _rightCenter, Timeout = FadeStart}); _lines.Add(new FadingLine {End = leftN, Start = _leftCenter, Timeout = FadeStart}); //loop _loopCounter += 0.5f; if (_loopCounter > 360.0) _loopCounter = 0.5f; }
public void Draw(CanvasAnimatedDrawEventArgs args, Vector2 position, CanvasTextFormat font) { if (LastFont == null || LastFont.FontFamily != font.FontFamily || LastFont.FontSize != font.FontSize) { Widths.Clear(); // recalculate widths for(int i = 0; i < Parts.Count; i++) { CanvasTextLayout layoutTemp = new CanvasTextLayout(args.DrawingSession, Parts[i].String.Replace(' ', '.'), font, 0, 0); Widths.Add((float)layoutTemp.LayoutBounds.Width); } LastFont = font; } float fOffsetX = 0.0f; for (int i = 0; i < Parts.Count; i++) { // draw string part args.DrawingSession.DrawText(Parts[i].String, new Vector2(position.X + fOffsetX, position.Y), Parts[i].Color, font); // add to offset fOffsetX += Widths[i]; } }
// Draws a clock with given ray in the middle of a canvas private void drawClock(CanvasAnimatedDrawEventArgs canvas, Vector2 middle, float ray) { canvas.DrawingSession.DrawCircle(midScreen, ray, Colors.White); canvas.DrawingSession.DrawText("12", midScreen.X - 5, midScreen.Y - ray, Colors.White, font); canvas.DrawingSession.DrawText("3", midScreen.X + ray - 10, midScreen.Y - 5, Colors.White, font); canvas.DrawingSession.DrawText("6", midScreen.X - 2.5f, midScreen.Y + ray - 12, Colors.White, font); canvas.DrawingSession.DrawText("9", midScreen.X - ray + 5, midScreen.Y - 5, Colors.White, font); }
private void Canvas_Draw( ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args) { this.renderer.SetDrawingSession(args.DrawingSession); this.world.Draw(this.renderer); this.renderer.ClearDrawingSession(); }
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); }
public static void Draw(CanvasAnimatedDrawEventArgs args) { foreach (win2d_Control control in Controls) { control.Draw(args); } // START DEBUG DrawDebug(args); // END DEBUG }
public static void Draw(CanvasAnimatedDrawEventArgs args) { args.DrawingSession.FillRectangle(MapCreationScreenBackgroundRect, Colors.CornflowerBlue); if (ProgressPhaseTextLayout != null) { args.DrawingSession.DrawTextLayout(ProgressPhaseTextLayout, ProgressPhaseTextLayoutPosition, Colors.White); args.DrawingSession.FillRectangle(ProgressPercentageRect, Colors.White); args.DrawingSession.DrawRectangle(ProgressPercentageBorderRect, Colors.White); } }
public override void Draw(CanvasAnimatedDrawEventArgs args) { args.DrawingSession.FillRectangle(Rect, Color); foreach (win2d_Control control in Controls) { control.Draw(args); } // border args.DrawingSession.DrawRectangle(Rect, Colors.White); }
// 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); }
//public int Opacity //{ // get // { // return PixelFormat.TRANSLUCENT; // } //} private void CanvasControlOnDraw(ICanvasAnimatedControl canvasControl, CanvasAnimatedDrawEventArgs args) { lock (this) { using (_bitmapCanvas.CreateSession(canvasControl.Device, canvasControl.Size.Width, canvasControl.Size.Height, args.DrawingSession)) { _bitmapCanvas.Clear(Colors.Transparent); LottieLog.BeginSection("Drawable.Draw"); if (_compositionLayer == null) { return; } var scale = _scale; float extraScale = 1f; var hasExtraScale = false; float maxScale = GetMaxScale(_bitmapCanvas); if (_compositionLayer.HasMatte() || _compositionLayer.HasMasks()) { // Since we can only scale up the animation so much before masks and mattes get clipped, we // may have to scale the canvas to fake the rest. This isn't a problem for software rendering // but hardware accelerated scaling is rasterized so it will appear pixelated. extraScale = scale / maxScale; scale = Math.Min(scale, maxScale); // This check fixes some floating point rounding issues. hasExtraScale = extraScale > 1.001f; } if (hasExtraScale) { _bitmapCanvas.Save(); // This is extraScale ^2 because what happens is when the scale increases, the intrinsic size // of the view increases. That causes the drawable to keep growing even though we are only // rendering to the size of the view in the top left quarter, leaving the rest blank. // The first scale by extraScale scales up the canvas so that we are back at the original // size. The second extraScale is what actually has the scaling effect. float extraScaleSquared = extraScale * extraScale; int px = (int)(_composition.Bounds.Width * scale / 2f); int py = (int)(_composition.Bounds.Height * scale / 2f); _bitmapCanvas.Scale(extraScaleSquared, extraScaleSquared, px, py); } _matrix.Reset(); _matrix = MatrixExt.PreScale(_matrix, scale, scale); _compositionLayer.Draw(_bitmapCanvas, _matrix, _alpha); if (hasExtraScale) { _bitmapCanvas.Restore(); } LottieLog.EndSection("Drawable.Draw"); } } }
public void Draw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args) { if (currentImg?.ScaleEffect != null) { args.DrawingSession.DrawImage(currentImg.ScaleEffect, new System.Numerics.Vector2(), new Rect() { Height = MetroSlideshow.WindowHeight, Width = MetroSlideshow.WindowWidth }, currentImg.Opacity); } threshold++; if (threshold == 1) { threshold = 0; if (fastChange) { frame += 4; } else { frame++; } } if (frame < EndFrameThreshold) { return; } // Resetting variables var artistCount = Locator.MediaLibrary.ArtistCount(); if (ImgIndex < artistCount - 1) { ImgIndex++; } else { ImgIndex = 0; } if (fastChange) { fastChange = false; } if (clearSlideshow) { sender.Paused = true; } frame = 0; blurAmount = MaximumBlur; }
//---------------------------- Draw Elements ----------------------------- private static void DrawInstructionsTitle(CanvasAnimatedDrawEventArgs args) { using (CanvasTextFormat format = new CanvasTextFormat { HorizontalAlignment = CanvasHorizontalAlignment.Center, VerticalAlignment = CanvasVerticalAlignment.Center, WordWrapping = CanvasWordWrapping.NoWrap, FontSize = 50.0f }) { args.DrawingSession.DrawText("Instructions", 250, 120, Colors.DeepPink, format); } }
private static void DrawReturnButton(CanvasAnimatedDrawEventArgs args) { using (CanvasTextFormat format = new CanvasTextFormat { HorizontalAlignment = CanvasHorizontalAlignment.Center, VerticalAlignment = CanvasVerticalAlignment.Center, WordWrapping = CanvasWordWrapping.NoWrap, FontSize = 20.0f }) { args.DrawingSession.DrawText("Return", 400, 660, Colors.DeepSkyBlue, format); } }
private void canvasMain_Draw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args) { lock(TileLock) { for (int x = 0; x < nTilesX; x++) { for (int y = 0; y < nTilesY; y++) { Tiles[x, y].Draw(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); }
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) { } }
private void DrawStatisticsUI(CanvasAnimatedDrawEventArgs args, float gridWidthInDips, Rect statisticsArea) { int y = (int)statisticsArea.Y; PieceType[] types = new PieceType[] { PieceType.T, PieceType.R, PieceType.Z, PieceType.O, PieceType.S, PieceType.L, PieceType.I }; foreach (var type in types) { int statistic = grid.GetStatistic((int)type); string formatString = String.Format("{0:000}", statistic); args.DrawingSession.DrawText(formatString, (float)statisticsArea.X + 120, (float)y + 65, Colors.Red, headingTextFormat); y += 65; } }
public virtual void DrawMirrored(CanvasAnimatedDrawEventArgs args) { for (int i = 0; i < Lines.Count; i++) { if (i % 2 == 1) { Lines[i].DrawMirrored(args); } else { Lines[i].Draw(args); } } }
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, }); }
//---------------------------- Draw Elements ----------------------------- private static void DrawCheckButton(CanvasAnimatedDrawEventArgs args) { using (CanvasTextFormat format = new CanvasTextFormat { HorizontalAlignment = CanvasHorizontalAlignment.Center, VerticalAlignment = CanvasVerticalAlignment.Center, WordWrapping = CanvasWordWrapping.NoWrap, FontSize = 30.0f }) { args.DrawingSession.DrawText("Check", 400, 600, Colors.DeepSkyBlue, format); args.DrawingSession.DrawRectangle(300, 575, 200, 55, Colors.DeepPink); } }
void AnimatedCanvas_Draw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args) { animatedDeviceResources.InitMessage(); DrawToOutput(animatedDeviceResources, args.DrawingSession); // Update the info text. var message = animatedDeviceResources.GetFinalMessage(); var task = textBlock.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { textBlock.Text = message; }); }
private void DrawFrame(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args) { var blur = new GaussianBlurEffect(); blur.Source = _helloWorld; blur.BlurAmount = 10.0f; args.DrawingSession.DrawImage(blur); //args.DrawingSession.DrawCircle(_circle.Position.X, _circle.Position.Y, 10, Colors.Green); foreach (var drawMe in _objects) { drawMe.DrawMe(args.DrawingSession, new MG.Vector2(600, 800), _pixelsPerMeter); } }
private void DrawWinString(CanvasAnimatedDrawEventArgs args) { // initialize (need drawing args for text width) if (strWinnerString == string.Empty) { // initialize win environment strWinnerString = "Congratulations, " + Regions[0].Name + "!"; CanvasTextLayout winningTextLayout = new CanvasTextLayout(args.DrawingSession, strWinnerString, Statics.FontExtraLarge, 0.0f, 0.0f); double dWinningStringWidth = winningTextLayout.DrawBounds.Width; fWinnerStringPositionX = (float)(WidthInPixels - dWinningStringWidth) / 2 + Position.X + Statics.LeftColumnPadding; fWinnerStringPositionY = 40.0f + Position.Y + Statics.LeftColumnPadding; } args.DrawingSession.DrawText(strWinnerString.Substring(0, nWinningStringFrame / 5), new Vector2(fWinnerStringPositionX, fWinnerStringPositionY), Colors.White, Statics.FontExtraLarge); }
private async void AnimatedCanvasCtrl_OnDraw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args) { if (_animatedCompositionMask == 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(200, 200)), CanvasGeometryCombine.Exclude); // Update the geometry in the Composition Mask await _animatedCompositionMask.RedrawAsync(updatedGeometry); }
public void DrawHeightMap(Vector2 MapPosition, CanvasAnimatedDrawEventArgs args, bool bDrawPaths) { foreach (Room room in Rooms) { room.DrawHeight(MapPosition, args); } if(bDrawPaths) { foreach(Room room in Rooms) { room.DrawRoomConnections(MapPosition, args); } } }
private void CanvasAnimatedControl_Draw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args) { using (var ds = args.DrawingSession) { _interopDrawing.Session = ds; try { _game.Draw((GameTime)args.Timing.ElapsedTime); // ds.DrawText("123456", new System.Numerics.Vector2(100,100), Color.); } finally { _interopDrawing.Session = null; } } }
private void Canvas_Draw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args) { if (!pong.gameOver) { pong.DrawPong(args.DrawingSession); } else { var fontFormat = new Microsoft.Graphics.Canvas.Text.CanvasTextFormat { FontSize = 48 }; args.DrawingSession.DrawText("Game over! Do you want to play again? ( Y/N )", 400, 400, Colors.Azure, fontFormat); } }
private static void DrawCredits(CanvasAnimatedDrawEventArgs args) { using (CanvasTextFormat format = new CanvasTextFormat { HorizontalAlignment = CanvasHorizontalAlignment.Justified, VerticalAlignment = CanvasVerticalAlignment.Center, WordWrapping = CanvasWordWrapping.WholeWord, FontSize = 15.0f }) { args.DrawingSession.DrawText("Music: Sath Button/ Gaming Sound Fx", 80, 200, Colors.DeepSkyBlue, format); args.DrawingSession.DrawText("Assets: Google Images", 80, 250, Colors.DeepSkyBlue, format); args.DrawingSession.DrawText("Class: CIS 297", 80, 315, Colors.DeepSkyBlue, format); args.DrawingSession.DrawText("Team 12. Muaz, Zak, John", 80, 380, Colors.DeepSkyBlue, format); } }
public static void Draw(CanvasAnimatedDrawEventArgs args) { lock (Chunk.CacheLock) { for (int x = Camera.ChunkPositionX; x < Camera.ChunkPositionX + Chunk.MaxChunksVisibleX; x++) { for (int y = Camera.ChunkPositionY; y < Camera.ChunkPositionY + Chunk.MaxChunksVisibleY; y++) { Chunk c; if (ChunkCache.TryGetValue(new PointInt(x, y), out c)) { c.Draw(args); } } } } }
private void Canvas_OnDraw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args) { // st.Restart(); canvas.IsFixedTimeStep = false; int width = Constants.ChartWidth; if (Acceleration.Count > width) { Acceleration.RemoveRange(0, Acceleration.Count - width); } _chartRenderer.RenderData(canvas, args, Colors.Black, DataStrokeThickness, Acceleration); _chartRenderer.RenderAxes(canvas, args); // st.Stop(); // Debug.WriteLine(st.ElapsedTicks + "!"); }
private void canvasMain_Draw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args) { args.DrawingSession.Antialiasing = Microsoft.Graphics.Canvas.CanvasAntialiasing.Aliased; if (fullLoopTimer != null) { fullLoopTimer.Stop(); Debug.LastFullLoopTime = fullLoopTimer.ElapsedMilliseconds; if (Debug.LastFullLoopTime > Debug.MaxFullLoopTime) { Debug.MaxFullLoopTime = Debug.LastFullLoopTime; } if (fullLoopTimer.ElapsedMilliseconds > canvasMain.TargetElapsedTime.TotalMilliseconds + 1) { Debug.SlowFrames++; } } fullLoopTimer = Stopwatch.StartNew(); Stopwatch s = Stopwatch.StartNew(); Stopwatch sMap = Stopwatch.StartNew(); Map.Draw(args); sMap.Stop(); Stopwatch sDebug = Stopwatch.StartNew(); Debug.Draw(args); sDebug.Stop(); Stopwatch sMouse = Stopwatch.StartNew(); Mouse.Draw(args); sMouse.Stop(); s.Stop(); Debug.LastDrawTime = s.ElapsedMilliseconds; Debug.LastDrawMouseTime = sMouse.ElapsedMilliseconds; Debug.LastDrawDebugTime = sDebug.ElapsedMilliseconds; Debug.LastDrawMapTime = sMap.ElapsedMilliseconds; foreach (Sprite sprite in Sprites) { sprite.Draw(args); } }
/// <summary> /// Stage OnDraw 事件. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void StageOnDraw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args) { if (!this._isResourceReady || !this._isStageInited) { return; } var drawFrame = this._drawNextFrame > -1 ? this._drawNextFrame : this.CurrentFrame; var stageResource = this._stageResource; var sprites = stageResource.Sprites; using (var session = args.DrawingSession) { // 遍历 Sprites 进行绘制. foreach (var sprite in sprites) { this.DrawSingleSprite(drawFrame, session, sprite); } } this.CurrentFrame = drawFrame; this._drawNextFrame = -1; if (this.IsInPlay) { var nextFrame = drawFrame + 1; var isLoopFinished = nextFrame > this.TotalFrame - 1; if (isLoopFinished) { nextFrame = 0; this._playedCount++; } this.CurrentFrame = nextFrame; } // 判断是否继续播放. // 此条件需要写在结尾, 否则当前帧会被清空而显示空白. if (this.LoopCount > 0 && this._playedCount >= this.LoopCount) { this.Pause(); this.NotifyLoopFinish(); } this.OnLoop?.Invoke(); }
private void CanvasAnimatedDraw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args) { DrawEventCount(); // Add one live cell per draw, just to keep it alive forever // _current[_random.Next(_width), _random.Next(_height)] = true; _nIteration++; _nPixel = 0; const float usedDpi = 96.0f; for (int x = 0, bufferIndex = 0; x < _width; x++) { for (int y = 0; y < _height; y++, bufferIndex += 4) { if (_next[x, y] = NextLiveValue(_current, x, y)) { _nPixel++; _buffer[bufferIndex + 3] = 0xff; } else { _buffer[bufferIndex + 3] = 0; } } } if (_nPixel < _minimum) { _minimum = _nPixel; } using (var bitmap = CanvasBitmap.CreateFromBytes(sender, _buffer, _width, _height, DirectXPixelFormat.B8G8R8A8UIntNormalized, usedDpi)) { args.DrawingSession.DrawImage(bitmap, new Rect(0, 0, _width, _height), new Rect(0, 0, _width, _height), 1, CanvasImageInterpolation.NearestNeighbor); } args.DrawingSession.DrawText($"FPS {FramesPerSecond:F2}", new Vector2(10, 10), Colors.Black); args.DrawingSession.DrawText("Step " + _nIteration, new Vector2(10, 30), Colors.Black); args.DrawingSession.DrawText("Pixel " + _nPixel, new Vector2(10, 50), Colors.Black); args.DrawingSession.DrawText("Minimum " + _minimum, new Vector2(10, 70), Colors.Black); var tmp = _next; _next = _current; _current = tmp; }
/// <summary> /// To debug tile references /// </summary> public static void DrawGameTilesDebugLines(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args, GameTile[] gameTiles) { if (gameTiles != null) { foreach (var item in gameTiles) { if (item.nextTile != null) { args.DrawingSession.DrawLine(item.drawable.ActualCenter, item.nextTile.drawable.ActualCenter, new CanvasSolidColorBrush(sender, Colors.Cyan)); } if (item.nextHomeTile != null) { args.DrawingSession.DrawLine(item.drawable.ActualCenter, item.nextHomeTile.drawable.ActualCenter, new CanvasSolidColorBrush(sender, Colors.Magenta)); } } } }
private void OnDraw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args) { var ds = args.DrawingSession; using (var spriteBatch = ds.CreateSpriteBatch()) { // Draw gameObjects foreach (Layer layer in EntityManager.Layers) { foreach (IGameObjectModel gameObject in layer.GameObjects) { gameObject.UpdateMovement(); gameObject.DrawSelf(spriteBatch); } } } }
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); }
/// <summary> /// draws the sprites for the level /// </summary> public void drawLevel(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args) { var frames_sprite = (int)(this.frames / 15) + 1; // Frame sprite for the animations off water and torches // Loop through all the tiles in the level for (int x = 0; x < levels.gekozenLevel.GetLength(0); x += 1) { for (int y = 0; y < levels.gekozenLevel.GetLength(1); y += 1) { string tileType = levels.gekozenLevel[x, y].ToString(); // Get the current tile type string tmp = tileType + "_" + frames_sprite; // Tile type for the choosen animation frame // makes the sprite move if (Levels.Levels.tiles.ContainsKey(tmp)) // if the animated frame exists { Tile tile = Levels.Levels.tiles[tileType + "_" + frames_sprite]; args.DrawingSession.DrawImage( tile.Effect, y * 32, x * 32 ); // Draw the tile to generate the level } else // Show the default tile sprite { Tile tile = Levels.Levels.tiles[tileType]; args.DrawingSession.DrawImage( tile.Effect, y * 32, x * 32 ); // Draw the tile to generate the level } } } if (this.frames > 60) { this.frames = 0; // Set the amount off frames back to 0, needed for the animation } }
public override void Draw(CanvasAnimatedDrawEventArgs args) { base.Draw(args); // draw leaders int i = 0; for (i = 0; i < Leaders.Count; i++) { RichString str = Leaders[i].ToRichString(); //CanvasTextLayout layout = new CanvasTextLayout(args.DrawingSession, str.String, LeadersFont, 0, 0); float x = Padding + Position.X;// + (Width - str.Width) / 2; str.Draw(args, new Vector2(x, LeadersPosition.Y + i * (float)LeadersTextLayout.LayoutBounds.Height), LeadersFont); } // draw first column of strings float fCurrentY = StringsPosition.Y; i = 0; while ((fCurrentY + (float)StringsTextLayout.LayoutBounds.Height) < MaxY && i < Strings.Count) { RichString str = Strings[i].ToRichString(); str.Draw(args, new Vector2(StringsPosition.X, fCurrentY), StringsFont); fCurrentY += (float)StringsTextLayout.LayoutBounds.Height; i++; } // set second column x position float fCurrentX = Position.X + Width / 2 + Padding; fCurrentY = StringsPosition.Y; // draw second column of strings while ((fCurrentY + (float)StringsTextLayout.LayoutBounds.Height) < MaxY && i < Strings.Count) { RichString str = Strings[i].ToRichString(); str.Draw(args, new Vector2(fCurrentX, fCurrentY), StringsFont); fCurrentY += (float)StringsTextLayout.LayoutBounds.Height; i++; } }
public void RenderAxes(CanvasAnimatedControl canvas, CanvasAnimatedDrawEventArgs args) { var width = Constants.ChartWidth; var height = Constants.ChartHeight; var midWidth = (float)(width * .5); var midHeight = (float)(height * .5); using (var cpb = new CanvasPathBuilder(args.DrawingSession)) { // Horizontal line cpb.BeginFigure(new Vector2(0, midHeight)); cpb.AddLine(new Vector2(width, midHeight)); cpb.EndFigure(CanvasFigureLoop.Open); // Horizontal line arrow cpb.BeginFigure(new Vector2(width - 10, midHeight - 3)); cpb.AddLine(new Vector2(width, midHeight)); cpb.AddLine(new Vector2(width - 10, midHeight + 3)); cpb.EndFigure(CanvasFigureLoop.Open); args.DrawingSession.DrawGeometry(CanvasGeometry.CreatePath(cpb), Colors.Gray, 1); } args.DrawingSession.DrawText("0", 5, midHeight - 30, Colors.Gray); args.DrawingSession.DrawText(width.ToString(), width - 50, midHeight - 30, Colors.Gray); using (var cpb = new CanvasPathBuilder(args.DrawingSession)) { // Vertical line cpb.BeginFigure(new Vector2(midWidth, 0)); cpb.AddLine(new Vector2(midWidth, height)); cpb.EndFigure(CanvasFigureLoop.Open); // Vertical line arrow cpb.BeginFigure(new Vector2(midWidth - 3, 10)); cpb.AddLine(new Vector2(midWidth, 0)); cpb.AddLine(new Vector2(midWidth + 3, 10)); cpb.EndFigure(CanvasFigureLoop.Open); args.DrawingSession.DrawGeometry(CanvasGeometry.CreatePath(cpb), Colors.Gray, 1); } args.DrawingSession.DrawText("0", midWidth + 5, height - 30, Colors.Gray); args.DrawingSession.DrawText("1", midWidth + 5, 5, Colors.Gray); }
//Draw map levels private void DrawLevels(CanvasAnimatedDrawEventArgs args) { for (int j = 0; j < worldMap.GetSize().Y; j++) { //Two cycles for proper order for (int i = 1; i < worldMap.GetSize().X; i += 2) { var item = worldMap[i, j]; args.DrawingSession.FillGeometry(hex, new System.Numerics.Vector2(item.DrawPoint.X, item.DrawPoint.Y), brushes[item.WorldLevel]); } for (int i = 0; i < worldMap.GetSize().X; i += 2) { var item = worldMap[i, j]; args.DrawingSession.FillGeometry(hex, new System.Numerics.Vector2(item.DrawPoint.X, item.DrawPoint.Y), brushes[item.WorldLevel]); } } }
private void AnimatedCanvasCtrl_OnDraw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args) { if (_animatedMaskSurface == null) { return; } _angle = (float)((_angle + 1) % 360); var angle = _angle * Scalar.DegreesToRadians; // Calculate the new geometry based on the angle var combinedGeometry = _ellipse1.CombineWith(_ellipse2, Matrix3x2.CreateRotation(angle, _center), CanvasGeometryCombine.Union); var updatedGeometry = _outerGeometry.CombineWith(combinedGeometry, Matrix3x2.CreateRotation(angle / 2, _center), CanvasGeometryCombine.Xor); // Update the geometry in the Composition Mask _animatedMaskSurface.Redraw(updatedGeometry); }
internal void Draw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args) { if (CanvasControl == null) { CanvasControl = sender as CanvasAnimatedControl; } var ds = args.DrawingSession; if (!ChessBoard.Updating) { foreach (var item in ChessBoard.Squares) { ds.FillRectangle(item.Rect, item.Color); ds.DrawRectangle(item.Rect, Colors.Aquamarine); //ds.DrawText(item.ToString(), new Vector2((float)item.Rect.X + item.Size/4, (float)item.Rect.Y + item.Size/4), Colors.Black); } } }
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); }
public void Draw(CanvasAnimatedDrawEventArgs args) { int x = (int)_position.X; for (int i = 0; i < Characters.Count; i++) { int y = (int)(_position.Y + 200 * Math.Sin(i * .20 + loopCount * 0.01)); if (_drawStyle == DRAW_STYLE.NORMAL) { Characters[i].Draw(args, new Vector2(x, y)); } else { Characters[i].DrawMirrored(args, new Vector2(x, y)); } x += Characters[i].Width; } }
public override void Draw(CanvasAnimatedDrawEventArgs args) { base.Draw(args); // draw leaders int i = 0; for(i = 0; i < Leaders.Count; i++) { RichString str = Leaders[i].ToRichString(); //CanvasTextLayout layout = new CanvasTextLayout(args.DrawingSession, str.String, LeadersFont, 0, 0); float x = Padding + Position.X;// + (Width - str.Width) / 2; str.Draw(args, new Vector2(x, LeadersPosition.Y + i * (float)LeadersTextLayout.LayoutBounds.Height), LeadersFont); } // draw first column of strings float fCurrentY = StringsPosition.Y; i = 0; while ((fCurrentY + (float)StringsTextLayout.LayoutBounds.Height) < MaxY && i < Strings.Count) { RichString str = Strings[i].ToRichString(); str.Draw(args, new Vector2(StringsPosition.X, fCurrentY), StringsFont); fCurrentY += (float)StringsTextLayout.LayoutBounds.Height; i++; } // set second column x position float fCurrentX = Position.X + Width / 2 + Padding; fCurrentY = StringsPosition.Y; // draw second column of strings while ((fCurrentY + (float)StringsTextLayout.LayoutBounds.Height) < MaxY && i < Strings.Count) { RichString str = Strings[i].ToRichString(); str.Draw(args, new Vector2(fCurrentX, fCurrentY), StringsFont); fCurrentY += (float)StringsTextLayout.LayoutBounds.Height; i++; } }
public static void Draw(CanvasAnimatedDrawEventArgs args) { args.DrawingSession.DrawRectangle(new Rect(980, 50, 850, 50), Colors.White); args.DrawingSession.DrawRectangle(new Rect(980, 100, 850, 220), Colors.White); args.DrawingSession.DrawRectangle(new Rect(980, 320, 850, 50), Colors.White); // args.DrawingSession.DrawText("Recent Contentions", new Vector2(Position.X, 53), Colors.White, Statics.FontLarge); //float fCurrentY = Position.Y; //int i = 0; //for (i = 0; i < Strings.Count - 1; i++) //{ // args.DrawingSession.DrawText(Strings[i].String, new Vector2(Position.X, fCurrentY), Strings[i].Color, Statics.FontSmall); // fCurrentY += 20; //} //if (Strings.Count > 0) //{ // args.DrawingSession.DrawText(Strings[i].String, new Vector2(Position.X, Position.Y + 205), Strings[i].Color, Statics.FontLarge); //} }
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); } }
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); } }
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, }); }