protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { this._context = await this._canvasReference.CreateCanvas2DAsync(); int maxFrames = 4; int currentFrame = 1; int y = 0; while (true) { await Task.Delay(100); await this._context.SetFillStyleAsync("cornflowerblue"); await this._context.FillRectAsync(0, 0, 1024, 768); await this._context.DrawImageAsync(ashRef, (currentFrame - 1) * 64, 0, 64, 64, 0, y, 64, 64); currentFrame++; y++; if (currentFrame > maxFrames) { currentFrame = 1; } } } }
public async Task <string> ClampText(Canvas2DContext context, string text, int maxWidth) { var metrics = await context.MeasureTextAsync(text); if (metrics.Width <= maxWidth) { return(text); } const string suffix = "..."; var suffixMetrics = await context.MeasureTextAsync(suffix); maxWidth = (int)Math.Floor(maxWidth - suffixMetrics.Width); var str = string.Empty; var previousStr = string.Empty; foreach (var letter in text) { str += letter; var width = await context.MeasureTextAsync(str); if (width.Width > maxWidth) { return(previousStr); } previousStr = str; } throw new FormatterException(text); }
protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { this._context = await this._canvasReference.CreateCanvas2DAsync(); await this._context.SetFillStyleAsync("cornflowerblue"); await this._context.FillRectAsync(0, 0, xBound, yBound); await this._context.DrawImageAsync(ashRef, 0, 0, 64, 64, 0, 0, 64, 64); } else { await Task.Delay(17); await this._context.SetFillStyleAsync("cornflowerblue"); await this._context.FillRectAsync(0, 0, xBound, yBound); await this._context.DrawImageAsync(ashRef, (currentFrame - 1) * 64, yCor, 64, 64, AD, WS, 64, 64); if (currentFrame > maxFrames) { currentFrame = 1; } } }
public BlazorCanvas(Canvas2DContext surface, long width, long height) { Surface = surface; Width = (int)width; Height = (int)height; Colors = new Dictionary <int, string>(); }
public static async Task DrawImageFor(this IDisplayable element, Canvas2DContext context, ElementReference imageRef) { await context.DrawImageAsync(imageRef, element.Position.X - element.Size / 2, element.Position.Y - element.Size / 2, element.Size, element.Size); }
public async ValueTask Render(GameContext game, Canvas2DContext context) { if (null == Animation) { return; } if (game.GameTime.TotalTime - _lastUpdate > 1000f / Animation.Fps) { if (_currFrameIndex >= Animation.FramesCount) { _currFrameIndex = 0; } _lastUpdate = game.GameTime.TotalTime; _currFramePosX = _currFrameIndex * Animation.FrameSize.Width; ++_currFrameIndex; } await context.SaveAsync(); await context.TranslateAsync(_transform.Position.X + (MirrorVertically ? Animation.FrameSize.Width : 0f), _transform.Position.Y); await context.ScaleAsync(MirrorVertically? -1f : 1f, 1f); await context.DrawImageAsync(Animation.ImageRef, _currFramePosX, 0, Animation.FrameSize.Width, Animation.FrameSize.Height, 0, 0, Animation.FrameSize.Width, Animation.FrameSize.Height); await context.RestoreAsync(); }
public async ValueTask Render(GameContext game, Canvas2DContext context) { var fps = 1000f / game.GameTime.ElapsedMilliseconds; await context.SetFillStyleAsync("green"); await context.FillRectAsync(10, 50, 300, _height); await context.SetFillStyleAsync("#fff"); await context.SetFontAsync("18px verdana"); y = startY; await WriteLine($"Total game time (s): {game.GameTime.TotalMilliseconds / 1000}", context); await WriteLine($"Frame time (ms): {game.GameTime.ElapsedMilliseconds}", context); await WriteLine($"FPS: {fps:###}", context); if (AsteroidsSpawner is not null) { await WriteLine($"Asteroids alive: {AsteroidsSpawner.Alive:###}", context); } if (BulletSpawner is not null) { await WriteLine($"Bullets spawned: {BulletSpawner.Alive:###}", context); } }
protected override async Task OnAfterRenderAsync(bool firstRender) { int j = 0; foreach (RealTime item in this._dashboardData) { this._context = await this._canvasReferenceList[j].CreateCanvas2DAsync(); this._contextList.Add(this._context); //Clear canvas await this._context.ClearRectAsync(0, 0, _canvasReferenceList[j].Width, _canvasReferenceList[j].Height); await this.DrawAvailabilityCardAsync(item); j++; } //else //{ // int j = 0; // foreach (RealTime item in this._dashboardData) // { // this._context = this._contextList[j]; //Clear canvas //await this._context.ClearRectAsync(0, 0, _canvasReferenceList[j].Width, _canvasReferenceList[j].Height); //await this.DrawAvailabilityCardAsync(item); //j++; //} //} }
protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { this._context = await this._canvasReference.CreateCanvas2DAsync(); await Task.Delay(100); await this._context.SetFillStyleAsync("cornflowerblue"); await this._context.FillRectAsync(0, 0, mapBorderMaxX, mapBorderMaxY); await this._context.DrawImageAsync(ashRef, (currentFrame - 1) *spriteX, spriteY, 64, 64, x, y, 64, 64); if (currentFrame > maxFrames) { currentFrame = 1; } } else { await Task.Delay(100); await this._context.SetFillStyleAsync("cornflowerblue"); await this._context.FillRectAsync(0, 0, mapBorderMaxX, mapBorderMaxY); await this._context.DrawImageAsync(ashRef, (currentFrame - 1) *spriteX, spriteY, 64, 64, x, y, 64, 64); if (currentFrame > maxFrames) { currentFrame = 1; } } }
public async Task Draw(int width, int height, Canvas2DContext canvas) { var index = 0; for (var y = 0; y < _data.Height; ++y) { for (var x = 0; x < _data.Width; ++x, ++index) { var val = _data.Density[index]; if (val == 0) { continue; } //todo: highlight the visible rectangle. bool inside = true; var clr = ChooseColor(val); if (!inside) { DarkenColor(clr); } await canvas.SetFillStyleAsync(ColorToString(clr)); await canvas.RectAsync(x, y, 1, 1); } } }
public async ValueTask Render(GameContext game, Canvas2DContext context) { if (null == Animation) { return; } if (game.GameTime.TotalTime - _lastUpdate > 1000f / Animation.Fps) { if (_currFrameIndex >= Animation.FramesCount) { _completed = true; _currFrameIndex = 0; } _lastUpdate = game.GameTime.TotalTime; _currFramePosX = _currFrameIndex * Animation.FrameSize.Width; ++_currFrameIndex; } var dx = -(_transform.Direction.X - 1f) * Animation.FrameSize.Width / 2f; await context.SetTransformAsync(_transform.Direction.X, 0, 0, 1, dx, 0); await context.DrawImageAsync(Animation.ImageRef, _currFramePosX, 0, Animation.FrameSize.Width, Animation.FrameSize.Height, _transform.Position.X, _transform.Position.Y, Animation.FrameSize.Width, Animation.FrameSize.Height); }
public async void DrawCurveControlLines(Canvas2DContext ctx, BezierCurve curve) { await ctx.BeginPathAsync(); await ctx.MoveToAsync(curve.ControlPoint1.X, curve.ControlPoint1.Y); await ctx.LineToAsync(curve.StartPoint.X, curve.StartPoint.Y); //await ctx.SetStrokeStyleAsync("red"); await ctx.StrokeAsync(); await ctx.BeginPathAsync(); //await ctx.SetFillStyleAsync("yellow"); await ctx.ArcAsync(curve.ControlPoint1.X, curve.ControlPoint1.Y, 5, 0, Math.PI * 2); await ctx.FillAsync(); await ctx.BeginPathAsync(); await ctx.MoveToAsync(curve.ControlPoint2.X, curve.ControlPoint2.Y); await ctx.LineToAsync(curve.EndPoint.X, curve.EndPoint.Y); //await ctx.SetStrokeStyleAsync("red"); await ctx.StrokeAsync(); await ctx.BeginPathAsync(); // await ctx.SetFillStyleAsync("yellow"); await ctx.ArcAsync(curve.ControlPoint2.X, curve.ControlPoint2.Y, 5, 0, Math.PI * 2); await ctx.FillAsync(); }
public PreviewService(Canvas2DContext context, Pres argPres, BECanvasComponent Canvas, int skala) { _outputCanvasContext = context; SetPresentationToPlay(argPres); _canvasReference = Canvas; this.skala = skala; }
public void ResetCanvas(Canvas2DContext ctx) { if (spriteService.IsRotated) { ctx.SetTransformAsync(1, 0, 0, 1, 0, 0); } ctx.ClearRectAsync(0, 0, Constants.CanvasSize.Width, Constants.CanvasSize.Height); }
private async ValueTask RenderHearts(GameContext game, Canvas2DContext context) { var text = $"{_playerStatsComponent.Health}/{_playerStatsComponent.MaxHealth}"; await RenderSprite(context, _heartSprite); await RenderText(context, text, _heartSprite.Bounds.Width); }
public override async void Draw(Canvas2DContext batch) { await batch.SetFillStyleAsync("green"); await batch.ArcAsync(95, 50, 40, 0, 2 *Math.PI); await batch.StrokeAsync(); }
public async Task Init() { canvas = await component.CreateCanvas2DAsync(); Tick.Interval = 1000; Tick.AutoReset = true; Tick.Elapsed += (s, e) => { TestState.Counter++; }; }
private static async Task RenderSprite(Canvas2DContext context, SpriteBase sprite) { await context.DrawImageAsync(sprite.ElementRef, sprite.Bounds.X, sprite.Bounds.Y, sprite.Bounds.Width, sprite.Bounds.Height, sprite.Origin.X, sprite.Origin.Y, -sprite.Bounds.Width, -sprite.Bounds.Height); }
protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { _canvas2DContext = await CanvasReference.CreateCanvas2DAsync(); _canvasBoundingClientRect = await JsRuntime.InvokeAsync <BoundingClientRect>("TodoIncJsInteropHelper.getBoundingClientRect", _canvasWrapperElement); } }
protected override async Task OnAfterRenderAsync(bool firstRender) { this._context = await this._canvasReference.CreateCanvas2DAsync(); Timer timer = new Timer(delegate { NoteStoppedTyping(); }, null, 0, 1000); }
protected override void OnAfterRender() { this._context = this.canvasReference.CreateCanvas2D(); this._context.FillStyle = "green"; this._context.FillRect(10, 100, 100, 100); this._context.Font = "48px serif"; this._context.StrokeText("Hello Blazor!!!", 10, 100); }
private static async Task RenderText(Canvas2DContext context, string text, int x) { await context.SetFillStyleAsync("#fff"); await context.SetFontAsync("18px verdana"); await context.SetTextBaselineAsync(TextBaseline.Middle); await context.FillTextAsync(text, x, 0); }
public override async Task Draw(Canvas2DContext context) { await context.BeginPathAsync(); await context.ArcAsync(Position.X, Position.Y, Size / 2, 0, 2 *Math.PI); await context.SetFillStyleAsync("blue"); await context.FillAsync(); }
public static void Clear(this Canvas2DContext context, string style = "transparent") { context.Save(); context.SetGlobalCompositeOperation("copy"); context.SetStrokeStyle(style); context.BeginPath(); context.LineTo(0, 0); context.Stroke(); context.Restore(); }
public async Task PlaceImage(IImageController imageController) { Height = imageController.Height; Width = imageController.Width; imageController.SetImageFormat(ImageFormat.Png); ImageSource = imageController.GetBase64Image(); StateHasChanged(); await Canvas2DContext.DrawImageAsync(ImageToBeLoaded, 0, 0, Width, Height); StateHasChanged(); }
public async Task Draw(Canvas2DContext context) { await Body[currentIndex].Draw(context); await Head[currentIndex].Draw(context); await context.BeginPathAsync(); await context.StrokeRectAsync(Head[currentIndex].Position.X - Head[currentIndex].ScaledWidth / 2, Head[currentIndex].Position.Y - Head[currentIndex].ScaledHeight / 2, Head[currentIndex].ScaledWidth, Head[currentIndex].ScaledHeight + Body[currentIndex].SourceRectangle.Height *scale.Y); await context.ClosePathAsync(); }
public static async Task DrawOn(this IDisplayable element, Canvas2DContext context) { await context.BeginPathAsync(); await context.ArcAsync(element.Position.X, element.Position.Y, element.Size / 2, 0, Math.PI * 2); await context.SetFillStyleAsync(element.Color); await context.FillAsync(); await context.ClosePathAsync(); }
public async ValueTask Init(BECanvasComponent canvas, ElementReference spriteSheet) { _context = await canvas.CreateCanvas2DAsync(); _spriteSheet = spriteSheet; var result = await _client.GetAsync($"{_apiUrl}/gethighscore"); var highScore = JsonSerializer.Deserialize <HighScore>(await result.Content.ReadAsStringAsync().ConfigureAwait(false)); HighScore = highScore.Score; HighScoreName = highScore.Name; }
protected override async Task OnAfterRenderAsync() { this._context = await this._canvasReference.CreateCanvas2DAsync(); await this._context.SetFillStyleAsync("green"); await this._context.FillRectAsync(10, 100, 100, 100); await this._context.SetFontAsync("48px serif"); await this._context.StrokeTextAsync("Hello Blazor!!!", 10, 100); }
public async ValueTask Render(GameContext game, Canvas2DContext context) { await context.SaveAsync(); await context.TranslateAsync(_transform.World.Position.X, _transform.World.Position.Y); await context.RotateAsync(_transform.World.Rotation); await context.DrawImageAsync(Sprite.Source, -Sprite.Origin.X, -Sprite.Origin.Y, Sprite.Size.Width, Sprite.Size.Height); await context.RestoreAsync(); }