public virtual void DrawLine(string color, float lineWidth, PointF ScreenFrom, PointF ScreenTo) { #if DOTNET // try to call the draw primitive DrawPrimitives?.DrawLine(color, lineWidth, ScreenFrom, ScreenTo); // normal GDI Pen p = new Pen(Brushes.Blue, lineWidth); oGraphics?.DrawLine(p, ScreenFrom, ScreenTo); #else this.context.save(); this.context.lineWidth = lineWidth; this.context.beginPath(); this.context.strokeStyle = color; this.context.moveTo(ScreenFrom.X, ScreenFrom.Y); this.context.lineTo(ScreenTo.X, ScreenTo.Y); this.context.closePath(); this.context.stroke(); this.context.restore(); #endif }
private void DrawGrid(GameTime gameTime, SpriteBatch spriteBatch) { Vector2 pos = new Vector2(0, 0); Rectangle rec; for (int j = 0; j < cellArray.GetLength(1); j++) { for (int i = 0; i < cellArray.GetLength(0); i++) { pos.X += cellWidth; if (cellArray[i, j].type != 0) { rec = new Rectangle((int)pos.X, (int)pos.Y, cellWidth, cellWidth); DrawPrimitives.DrawRectangle(rec, WhitePixel, getColor(cellArray[i, j].type), spriteBatch, true, 1); DrawPrimitives.DrawRectangle(rec, WhitePixel, Color.Black, spriteBatch, false, 1); spriteBatch.DrawString(font1, cellArray[i, j].count.ToString(), new Vector2(pos.X + 5, pos.Y + 5), Color.Red); DrawConnector(pos, spriteBatch, 0, cellArray[i, j].north); DrawConnector(pos, spriteBatch, 1, cellArray[i, j].south); DrawConnector(pos, spriteBatch, 2, cellArray[i, j].east); DrawConnector(pos, spriteBatch, 3, cellArray[i, j].west); } } pos.X = 0; pos.Y += cellWidth; } }
private void OnRenderControlPaint(object sender, PaintEventArgs e) { if (!_semaphore.WaitOne(0, false)) { return; } try { lock (_semaphore) { RenderContainer.DepthBuffer.Clear(); RenderContainer.BackBuffer.Clear(); Rectangle clipRectangle = new Rectangle(e.ClipRectangle.X, e.ClipRectangle.Y, e.ClipRectangle.Width, e.ClipRectangle.Height); DrawSprites?.Invoke(RenderContainer.Device11.Device, RenderContainer.SpriteBatch, clipRectangle); DrawPrimitives?.Invoke(RenderContainer.Device11.Device, RenderContainer.BackBuffer.Target2D, clipRectangle); RenderContainer.Device11.SwapChain.Present(1, PresentFlags.None); } } catch (Exception ex) { Log.Error(ex); } finally { _semaphore.Release(); } }
public override void Draw(SpriteBatch spriteBatch) { Constants.g.Clear(Color.White); DrawPrimitives.DrawRect(spriteBatch, new Rectangle(100, 100, 100, 100), Color.Black); a.changePos(a.Start + new Vector2(1, 0), a.End + new Vector2(1, 0)); base.Draw(spriteBatch); }
//Currently now showing stats. public static void DrawHealthBar(SpriteBatch spriteBatch, Texture2D whitePixel, Rectangle rec, Color col, bool showStats, bool border, int val, int totalVal) { //Draw the Health Bar float ratio = (float)val / (float)totalVal; int healthWidth = (int)Math.Round(rec.Width * ratio); Rectangle drawRec = rec; drawRec.Width = healthWidth; if (border) { Rectangle borderRec = new Rectangle(rec.X - 1, rec.Y - 1, rec.Width + 2, rec.Height + 2); DrawPrimitives.DrawRectangle(borderRec, whitePixel, Color.White, spriteBatch, false, 2); } DrawPrimitives.DrawRectangle(drawRec, whitePixel, col, spriteBatch, true, 2); }
protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp, null, null, null, null); //player.Draw(gameTime); int pointsCount = 0; foreach (Point p in points) { pointsCount++; DrawPrimitives.DrawPoint(p, 2, Color.White); } DrawPrimitives.DrawPoint(line.P1, 2, Color.Red); DrawPrimitives.DrawPoint(line.P2, 2, Color.Blue); DrawPrimitives.DrawPoint(check, 5, Color.Green); DrawPrimitives.DrawLine(line, 2); spriteBatch.DrawString(console, pointsCount.ToString(), Vector2.Zero, Color.Black); spriteBatch.DrawString(console, pointsCount.ToString(), Vector2.Zero, Color.Black); spriteBatch.End(); base.Draw(gameTime); }
public void DrawCircle(string color, float Radius, float CenterX, float CenterY) { #if DOTNET Pen p = GetColor(color, 1); RectangleF rf = new RectangleF(CenterX - Radius, CenterY - Radius, Radius, Radius); oGraphics?.DrawEllipse(p, rf); DrawPrimitives?.DrawEllipse(color, CenterX, CenterY, Radius); #else this.context.save(); this.context.lineWidth = 1; this.context.beginPath(); this.context.strokeStyle = color; this.context.arc(CenterX, CenterY, Radius, 0, 2 * Math.PI); this.context.closePath(); this.context.stroke(); this.context.restore(); #endif }
public void DrawRectangle(string color, float width, float height, float CenterX, float CenterY) { #if DOTNET Pen p = new Pen(Brushes.Black, 1); float upperleftX = CenterX - width / 2; float upperleftY = CenterY - height / 2; oGraphics?.DrawRectangle(p, upperleftX, upperleftY, width, height); DrawPrimitives?.DrawRectangle(color, width, height, CenterX, CenterY); #else this.context.save(); this.context.lineWidth = 1; this.context.beginPath(); this.context.strokeStyle = color; this.context.strokeRect(CenterX - width / 2, CenterY - height / 2, width, height); this.context.closePath(); this.context.stroke(); this.context.restore(); #endif }
//draw the connectors of 10 x 10 cells private void DrawConnector(Vector2 pos, SpriteBatch spriteBatch, int dir, bool isConn) { Color c = Color.Black; if (isConn) { c = Color.White; } Rectangle rec; switch (dir) { case 0: //north rec = new Rectangle((int)pos.X + (cellWidth / 2), (int)pos.Y, 2, 4); break; case 1: //south rec = new Rectangle((int)pos.X + (cellWidth / 2), (int)pos.Y + (cellWidth - 4), 2, 4); break; case 2: //east rec = new Rectangle((int)pos.X + (cellWidth - 4), (int)pos.Y + (cellWidth / 2), 4, 2); break; case 3: //west rec = new Rectangle((int)pos.X, (int)pos.Y + (cellWidth / 2), 4, 2); break; default: rec = new Rectangle((int)pos.X, (int)pos.Y, 0, 0); break; } DrawPrimitives.DrawRectangle(rec, WhitePixel, c, spriteBatch, true, 1); }