public void DrawUI(CanvasRenderingContext2D _canvas, Point pos, bool showOutline, bool showCollideMap, bool showHurtMap, bool showOffset, bool xflip, bool yflip) { var fd = GetCache(showOutline, showCollideMap, showHurtMap); _canvas.Save(); _canvas.Translate(pos.X, pos.Y); if (xflip) { if (yflip) { _canvas.Translate(fd.Canvas.Width / 2d, fd.Canvas.Height / 2d); _canvas.Rotate(-90 * Math.PI / 180); _canvas.Translate(-fd.Canvas.Width / 2d, -fd.Canvas.Height / 2d); _canvas.Translate(0, Height); _canvas.Scale(1, -1); } else { _canvas.Translate(fd.Canvas.Width / 2d, fd.Canvas.Height / 2d); _canvas.Rotate(-90 * Math.PI / 180); _canvas.Translate(-fd.Canvas.Width / 2d, -fd.Canvas.Height / 2d); } } else { if (yflip) { _canvas.Translate(0, Height); _canvas.Scale(1, -1); } else { } } _canvas.DrawImage(fd.Canvas, 0, 0); if (showOffset) { _canvas.BeginPath(); _canvas.MoveTo(OffsetX, 0); _canvas.LineTo(OffsetX, Height); _canvas.LineWidth = 1; _canvas.StrokeStyle = "#000000"; _canvas.Stroke(); _canvas.BeginPath(); _canvas.MoveTo(0, OffsetY); _canvas.LineTo(Width, OffsetY); _canvas.LineWidth = 1; _canvas.StrokeStyle = "#000000"; _canvas.Stroke(); } _canvas.Restore(); }
public void Draw(CanvasRenderingContext2D canvas, Sonic character, SensorM sensorResult) { var x = Help.Floor(character.X) - SonicManager.Instance.WindowLocation.X; var y = Help.Floor(character.Y) - SonicManager.Instance.WindowLocation.Y; canvas.BeginPath(); if (sensorResult.Truthy() && sensorResult.Chosen) { canvas.StrokeStyle = "#FFF76D"; canvas.LineWidth = 4; } else { canvas.StrokeStyle = Color; canvas.LineWidth = 2; } switch (character.Mode) { case RotationMode.Floor: canvas.MoveTo(( x + X1 ), ( y + Y1 )); canvas.LineTo(( x + X2 ), ( y + Y2 )); break; case RotationMode.LeftWall: canvas.MoveTo(( x - Y1 ), ( y + X1 )); canvas.LineTo(( x - Y2 ), ( y + X2 )); break; case RotationMode.Ceiling: canvas.MoveTo(( x - X1 ), ( y - Y1 )); canvas.LineTo(( x - X2 ), ( y - Y2 )); break; case RotationMode.RightWall: canvas.MoveTo(( x + Y1 ), ( y - X1 )); canvas.LineTo(( x + Y2 ), ( y - X2 )); break; } canvas.ClosePath(); canvas.Stroke(); }
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, bool showImages, int selectedPieceIndex, LevelObject levelObject) { canvas.Save(); if (!showImages) { canvas.StrokeStyle = "#000000"; canvas.LineWidth = 2; canvas.BeginPath(); canvas.MoveTo(-1000, 0); canvas.LineTo(1000, 0); canvas.ClosePath(); canvas.Stroke(); canvas.BeginPath(); canvas.MoveTo(0, -1000); canvas.LineTo(0, 1000); canvas.ClosePath(); canvas.Stroke(); for (var i = 1; i < Pieces.Count; i++) { var j = Pieces[i]; canvas.BeginPath(); canvas.MoveTo(j.X, j.Y); canvas.LineTo(Pieces[i - 1].X, Pieces[i - 1].Y); canvas.Stroke(); } } foreach (var levelObjectPieceLayoutPiece in Pieces) { if (showImages) { LevelObjectPiece piece = levelObject.Pieces[levelObjectPieceLayoutPiece.PieceIndex]; var asset = levelObject.Assets[piece.AssetIndex]; if (asset.Frames.Count > 0) { var frm = asset.Frames[0]; frm.DrawUI(canvas, new Point(levelObjectPieceLayoutPiece.X - frm.OffsetX, levelObjectPieceLayoutPiece.Y - frm.OffsetY), false, false, false, false, piece.Xflip, piece.Yflip); } } else { CanvasGradient drawRadial; drawRadial = SonicManager.Instance.mainCanvas.Context.CreateRadialGradient(0, 0, 0, 10, 10, 50); drawRadial.AddColorStop(0, "white"); if (selectedPieceIndex == levelObjectPieceLayoutPiece.PieceIndex) drawRadial.AddColorStop(1, "yellow"); else drawRadial.AddColorStop(1, "red"); canvas.FillStyle = drawRadial; canvas.BeginPath(); canvas.Arc(levelObjectPieceLayoutPiece.X, levelObjectPieceLayoutPiece.Y, 10, 0, Math.PI * 2, true); canvas.ClosePath(); canvas.Fill(); } } canvas.Restore(); }
public void Draw(CanvasRenderingContext2D canvas) { var fx = ( X ); var fy = ( Y ); if (Invulnerable()) return; var cur = SonicManager.Instance.SpriteCache.SonicSprites[SpriteState]; if (cur == null) {} if (cur.Loaded()) { canvas.Save(); var offset = GetOffsetFromImage(); canvas.Translate(( fx - SonicManager.Instance.WindowLocation.X + offset.X ), ( ( fy - SonicManager.Instance.WindowLocation.Y + offset.Y ) )); if (SonicManager.Instance.ShowHeightMap) { canvas.Save(); var mul = 6; var xj = Xsp * mul; var yj = Ysp * mul; canvas.BeginPath(); canvas.MoveTo(0, 0); canvas.LineTo(xj, yj); canvas.FillStyle = "rgba(163,241,255,0.8)"; canvas.Arc(xj, yj, 5, 0, 2 * Math.PI, true); canvas.ClosePath(); canvas.LineWidth = 6; canvas.StrokeStyle = "white"; //6C6CFC canvas.Stroke(); canvas.LineWidth = 3; canvas.StrokeStyle = "#2448D8"; //6C6CFC canvas.Fill(); canvas.Stroke(); canvas.Restore(); } if (!Facing) { //canvas.translate(cur.width, 0); canvas.Scale(-1, 1); if (!CurrentlyBall && !SpinDash) canvas.Rotate(-Help.FixAngle(Angle)); canvas.DrawImage(cur, -cur.Width / 2, -cur.Height / 2); if (SpinDash) { canvas.DrawImage( SonicManager.Instance.SpriteCache.SonicSprites[ ( "spinsmoke" + ( SonicManager.Instance.DrawTickCount % 14 ) / 2 )], ( -cur.Width / 2 ) - 25, -cur.Height / 2 + ( offset.Y ) - 14, cur.Width, cur.Height); } } else { if (!CurrentlyBall && !SpinDash) canvas.Rotate(Help.FixAngle(Angle)); canvas.DrawImage(cur, -cur.Width / 2, -cur.Height / 2); if (SpinDash) { canvas.DrawImage( SonicManager.Instance.SpriteCache.SonicSprites[ ( "spinsmoke" + ( SonicManager.Instance.DrawTickCount % 14 ) / 2 )], ( -cur.Width / 2 ) - 25, -cur.Height / 2 + ( offset.Y ) - 14, cur.Width, cur.Height); } } /* canvas.moveTo(-10 * scale.x, 4 * scale.y); canvas.lineTo(10 * scale.x, 4 * scale.y); canvas.lineWidth = 3; canvas.strokeStyle = "#FFF"; canvas.stroke(); canvas.moveTo(-9 * scale.x, 0 * scale.y); canvas.lineTo(-9 * scale.x, 20 * scale.y); canvas.lineWidth = 3; canvas.strokeStyle = "#FFF"; canvas.stroke(); canvas.moveTo(9 * scale.x, 0 * scale.y); canvas.lineTo(9 * scale.x, 20 * scale.y); canvas.lineWidth = 3; canvas.strokeStyle = "#FFF"; canvas.stroke();*/ /* canvas.strokeStyle = "#FFF"; canvas.lineWidth = 4; canvas.strokeRect(-cur.width / 2, -cur.height / 2, cur.width, cur.height); */ canvas.Restore(); if (SonicManager.Instance.ShowHeightMap) SensorManager.Draw(canvas, this); for (var i = 0; i < HaltSmoke.Count; i++) { var lo = HaltSmoke[i]; canvas.DrawImage( SonicManager.Instance.SpriteCache.SonicSprites[ ( "haltsmoke" + ( SonicManager.Instance.DrawTickCount % ( 4 * 6 ) ) / 6 )], ( ( lo.X - SonicManager.Instance.WindowLocation.X - 25 ) ), ( ( lo.Y + 12 - SonicManager.Instance.WindowLocation.Y + offset.Y ) )); if (( ( SonicManager.Instance.DrawTickCount + 6 ) % ( 4 * 6 ) ) / 6 == 0) HaltSmoke = HaltSmoke.Extract(i, 1); } } }