public override void Draw(CanvasRenderingContext2D canv) { if (!Visible) return; string txt = Text; if (canv.Font != Font) canv.Font = Font; //var w = canv.MeasureText(txt).Width; //var h = int.Parse(canv.Font.Split("pt")[0]); // canv.fillStyle = "rgba(255,255,255,0.78)"; // var pad = 3; // canv.fillRect(this.parent.x + this.x - pad, this.parent.y + this.y - h - pad, w + (pad * 2), h + (pad * 2)); canv.FillStyle = Color; canv.FillText(txt, TotalX, TotalY); }
private static void start() { canvas = (CanvasElement)Document.GetElementById("canvas"); context = (CanvasRenderingContext2D)canvas.GetContext(CanvasContextId.Render2D); Offset = new Vector2(0, 0); Vector2 draggingPos = null; canvas.OnMousedown = @event => { int mouseX = ((dynamic)@event).pageX; int mouseY = ((dynamic)@event).pageY; draggingPos = new Vector2(mouseX, mouseY); }; canvas.OnMouseup = @event => { /* if (draggingPos == null) return; int mouseX = ((dynamic)@event).pageX; int mouseY = ((dynamic)@event).pageY; draggingPos = new Vector2(draggingPos.X - mouseX, draggingPos.Y - mouseY); Offset = new Vector2(Offset.X + draggingPos.X, Offset.Y + draggingPos.Y); draw(); */ draggingPos = null; }; Document.OnMousemove = @event => { if (draggingPos == null) return; int mouseX = ((dynamic)@event).pageX; int mouseY = ((dynamic)@event).pageY; Offset = new Vector2(Offset.X + (draggingPos.X - mouseX) * 6, Offset.Y + (draggingPos.Y - mouseY) * 6); draggingPos = new Vector2(mouseX, mouseY); Draw(); }; canvas.Width = Document.Body.ClientWidth - 100; canvas.Height = Document.Body.ClientHeight - 100; context.Save(); context.Font = "50px Arial"; context.FillText("Loading...", canvas.Width / 2, canvas.Height / 2); context.Restore(); Window.OnKeydown = @event => { if (((dynamic)@event).keyCode == 17) { drawLines = !drawLines; } Draw(); }; Window.SetTimeout(() => { Console.WriteLine("Started"); Console.Profile(); Stopwatch sw = new Stopwatch(); sw.Start(); tree = new RTree<Player>(); players = new List<Player>(); for (int j = 0; j < numberOfPlayers; j++) { var player = new Player(nextId()); player.X = rand.Next(0, gameSize); player.Y = rand.Next(0, gameSize); players.Add(player); tree.Add(new Rectangle(player.X, player.Y), player); } buildClusters(viewRadius); sw.Stop(); Console.ProfileEnd(); Console.WriteLine(string.Format("Time {0}", sw.ElapsedMilliseconds)); Console.WriteLine("Done"); Draw(); }); }
private bool drawHaltMode(CanvasRenderingContext2D canvas) { canvas.FillStyle = "white"; canvas.Font = "21pt arial bold"; canvas.FillText("HALT MODE\r\n Press: P to step\r\n O to resume", 10, 120); if (waitingForDrawContinue) return true; else waitingForDrawContinue = true; return false; }
private static void drawLoading(CanvasRenderingContext2D canvas) { canvas.FillStyle = "white"; canvas.FillText("Loading... " /*+ (this.inds.tc + this.inds.tp + this.inds.t) + " / " + (this.inds.total)*/, 95, 95); canvas.Restore(); return; }
public void Draw(CanvasRenderingContext2D canvas) { dragger.Tick(); canvas.Save(); foreach (var are in canvasDepths) { are.Draw(canvas); } if (true /*DEBUGs*/) { for (var i = 0; i < messages.Count; i++) { canvas.FillText(messages[i], 10, 25 + i * 30); } } canvas.Restore(); }
public void DrawAnimationDebug(CanvasRenderingContext2D canvas, Point position, ChunkLayer layer, TileChunkDebugDrawOptions debugDrawOptions ) { if (debugDrawOptions == null) return; canvas.Save(); canvas.FillStyle = "White"; canvas.TextBaseline = TextBaseline.Top; { int yOffset = layer == ChunkLayer.Low ? 0 : 64; if (debugDrawOptions.ShowBaseData) { canvas.FillText("Base", position.X + 0, position.Y + yOffset); } if (debugDrawOptions.ShowPaletteAnimationData) { if (HasPixelAnimations()) { var paletteAnimationCanvases = PaletteAnimationCanvasesCache[layer]; foreach (var paletteAnimationIndex in GetAllPaletteAnimationIndexes()) { var paletteAnimationCanvasFrames = paletteAnimationCanvases[paletteAnimationIndex]; if (paletteAnimationCanvasFrames == null) continue; var currentFrame = SonicManager.Instance.TilePaletteAnimationManager.GetCurrentFrame(paletteAnimationIndex); canvas.FillText("Palette " + paletteAnimationIndex + "-" + currentFrame.FrameIndex, position.X + 25, position.Y + yOffset + (paletteAnimationIndex*13)); } } } if (debugDrawOptions.ShowTileAnimationData) { if (HasTileAnimations()) { var tileAnimationCanvases = TileAnimationCanvasesCache[layer]; foreach (var tileAnimationIndex in GetAllTileAnimationIndexes()) { var tileAnimationCanvasFrames = tileAnimationCanvases[tileAnimationIndex]; if (tileAnimationCanvasFrames == null) continue; var currentFrame = SonicManager.Instance.TileAnimationManager.GetCurrentFrame(tileAnimationIndex); canvas.FillText("Tile " + tileAnimationIndex + "-" + currentFrame.FrameIndex, position.X + 75, position.Y + yOffset + (tileAnimationIndex*13)); } } } } if (debugDrawOptions.OutlineChunk) { canvas.StrokeStyle = "black"; canvas.StrokeRect(position.X, position.Y, 128, 128); } if (debugDrawOptions.OutlineTiles) { canvas.StrokeStyle = "green"; for (int x = 0; x < TileSideLength; x++) { for (int y = 0; y < TileSideLength; y++) { canvas.StrokeRect(position.X + (x * TileSquareSize), position.Y + (y * TileSquareSize), TileSquareSize, TileSquareSize); } } } if (debugDrawOptions.OutlineTilePieces) { canvas.StrokeStyle = "purple"; for (int x = 0; x < TilePieceSideLength; x++) { for (int y = 0; y < TilePieceSideLength; y++) { canvas.StrokeRect(position.X + (x * TilePiecesSquareSize), position.Y + (y * TilePiecesSquareSize), TilePiecesSquareSize, TilePiecesSquareSize); } } } if (debugDrawOptions.OutlineTile != null) { /* canvas.StrokeStyle = "yellow"; for (int x = 0; x < TileSideLength; x++) { for (int y = 0; y < TileSideLength; y++) { var tilePieceInfo = this.GetTilePiece(x, y); if (tilePieceInfo == null) continue; var tilePiece = tilePieceInfo.GetTilePiece(); if (tilePiece == null) continue; if (tilePiece == debugDrawOptions.OutlineTilePiece) { canvas.StrokeRect(position.X + (x * TileSquareSize), position.Y + (y * TileSquareSize), TileSquareSize, TileSquareSize); } } } */ } if (debugDrawOptions.OutlineTilePiece != null) { canvas.StrokeStyle = "yellow"; for (int x = 0; x < TilePieceSideLength; x++) { for (int y = 0; y < TilePieceSideLength; y++) { var tilePieceInfo = this.GetTilePieceInfo(x, y,false); if (tilePieceInfo == null) continue; var tilePiece = tilePieceInfo.GetTilePiece(); if (tilePiece == null) continue; if (tilePiece.Index == debugDrawOptions.OutlineTilePiece.Block) { canvas.StrokeRect(position.X + (x * TilePiecesSquareSize), position.Y + (y * TilePiecesSquareSize), TilePiecesSquareSize, TilePiecesSquareSize); } } } } canvas.Restore(); }
public override void Draw(CanvasRenderingContext2D canv) { if (!Visible) return; canv.Save(); if (!Focused) { CursorPosition = -1; DragPosition = -1; } DrawTicks++; can = canv; canv.StrokeStyle = ButtonBorderGrad; canv.FillStyle = Clicking ? Button1Grad : Button2Grad; canv.LineWidth = 2; Help.RoundRect(canv, TotalX, TotalY, Width, Height, 2, true, true); if (canv.Font != Font) canv.Font = Font; if (DragPosition != -1) { canv.FillStyle = "#598AFF"; var w1 = canv.MeasureText(Text.Substring(0, Math.Min(DragPosition, CursorPosition))).Width; var w2 = canv.MeasureText(Text.Substring(0, Math.Max(DragPosition, CursorPosition))).Width; canv.FillRect(TotalX + 8 + w1, TotalY + 3, w2 - w1, ( Height - 7 )); } canv.FillStyle = "#000000"; int hc; if (canv.Font.IndexOf("pt") != -1) hc = int.Parse(canv.Font.Substr(0, canv.Font.IndexOf("pt"))); else hc = int.Parse(canv.Font.Substr(0, canv.Font.IndexOf("px"))); canv.FillText(Text, TotalX + 8, TotalY + ( ( Height - hc ) / 2 ) + Height / 2); if (Focused && ( ( blinkTick++ % 35 ) == 0 )) blinked = !blinked; if (Focused && blinked) { canv.StrokeStyle = "#000000"; var w = canv.MeasureText(Text.Substring(0, CursorPosition)).Width; canv.BeginPath(); canv.MoveTo(TotalX + 8 + w, TotalY + 3); canv.LineTo(TotalX + 8 + w, TotalY + ( Height - 7 )); canv.LineWidth = 2; canv.Stroke(); } canv.Restore(); base.Draw(canv); }
public void DrawUI(CanvasRenderingContext2D canvas, Point pos) { canvas.Save(); { if (canvas.Font != "13pt Arial bold") canvas.Font = "13pt Arial bold"; canvas.FillStyle = "White"; canvas.FillText("Rings: " + Rings, pos.X + 90, pos.Y + 45); canvas.FillText("Angle: " + Angle.ToString(16), pos.X + 90, pos.Y + 75); canvas.FillText("Position: " + ( X ) + ", " + ( Y ), pos.X + 90, pos.Y + 105); canvas.FillText("Speed: g: " + Gsp.ToFixed(3) + " x:" + Xsp.ToFixed(3) + " y:" + Ysp.ToFixed(3), pos.X + 90, pos.Y + 135); canvas.FillText("Mode: " + Mode.ToString(), pos.X + 90, pos.Y + 165); canvas.FillText("Multiplier: " + Watcher.mult, pos.X + 90, pos.Y + 195); // canvas.FillText("RealScale: " + SonicManager.Instance.RealScale.String(), pos.X + 90, pos.Y + 225); if (InAir) canvas.FillText("Air ", pos.X + 220, pos.Y + 45); if (HLock > 0) canvas.FillText("HLock: " + HLock, pos.X + 90, pos.Y + 195); } canvas.Restore(); }