public static void DrawImage(this IGsGraphics graphics, ImageParams data, GsColor color, GsRectangle source) { var size = data.ImageSize.ToVector() * data.Scale; var dest = new GsRectangle(data.Position, size.ToSize()); graphics.DrawImage(data.Image, dest, source, data.Origin, 0f, GsImageFlip.None, color); }
public void DrawString(GsFont font, string text, float x, float y, GsColor color) { var f = GetFont(font); TextureData d; if (!stringTextures.TryGetValue(text, out d)) { var s = MeasureString(font, text); var bmp = new Bitmap((int)Math.Ceiling(s.Width) + 2, (int)Math.Ceiling(s.Height) + 2); using (var gra = Graphics.FromImage(bmp)) { using (var b = new SolidBrush(Color.FromArgb(color.A, color.R, color.G, color.B))) { gra.SmoothingMode = SmoothingMode.AntiAlias; gra.TextRenderingHint = TextRenderingHint.AntiAliasGridFit; gra.Clear(Color.Transparent); gra.DrawString(text, f, b, new RectangleF(0, 0, bmp.Width, bmp.Height), centerCenter); } } d = new TextureData { Bitmap = bmp, ID = Texture.BindImage(bmp), }; stringTextures[text] = d; } DrawImage(d, x, y, d.Bitmap.Width, d.Bitmap.Height, color); }
protected virtual void DrawBackground(DrawParams dparams, GsRectangle bounds, GsRectangle inside) { GsColor bgColor = (Level == MaxLevel ? GsMath.SmoothStep(GsColor.Beige, GsColor.SkyBlue, .5f) : GsColor.Beige); GsColor color = Selected ? GsColor.DarkGreen : bgColor; dparams.Graphics.FillRectangle(color, bounds); }
public static void DrawImage(this IGsGraphics graphics, ImageParams data, GsColor color, GsVector offset, float rotation, GsImageFlip flip) { var size = data.ImageSize.ToVector() * data.Scale; var dest = new GsRectangle(data.Position + offset, size.ToSize()); graphics.DrawImage(data.Image, dest, null, data.Origin, rotation, flip, color); }
public void DrawRectangle(GsColor color, float x, float y, float width, float height) { var pts = new[] { new Vector2(x, y), new Vector2(x + width, y), new Vector2(x + width, y + height), new Vector2(x, y + height), }; using (AlphaBlend(color)) { GL.Begin(PrimitiveType.Lines); GL.Color4(color.R, color.G, color.B, color.A); int i = 0; while (i < rectangleIndices.Length) { GL.Vertex2(pts[rectangleIndices[i++]]); GL.Vertex2(pts[rectangleIndices[i++]]); } GL.End(); } }
protected virtual void DrawWeaponTower(DrawParams dparams, GsVector offset) { ImageParams data = GetTextureDrawData(offset); GsColor color = GsColor.Gray; var graphics = dparams.Graphics; graphics.DrawImage(data, color, Orientation); }
public void FillPolygon(GsColor color, GsVector[] pts) { SwitchMode(Mode.Primitives); var indices = Ratcliff.Triangulate(pts).Select(i => (short)i).ToArray(); primitiveBatch.DrawIndexed(PrimitiveType.TriangleList, indices, pts.Select(p => CreateVertex(color, p)).ToArray()); }
public void FillRectangle(GsColor color, float x, float y, float width, float height) { SwitchMode(Mode.Primitives); primitiveBatch.DrawQuad( CreateVertex(color, x, y), CreateVertex(color, x + width - 1, y), CreateVertex(color, x + width - 1, y + height - 1), CreateVertex(color, x, y + height - 1)); }
protected virtual void DrawWeaponBase(DrawParams dparams, GsRectangle bounds, GsRectangle inside) { var wbase = ImageProvider.GetFramedImage("towerBase").Image; var wbaseSize = ImageProvider.GetSize(wbase); var scale = Calculator.ComputeScale(wbaseSize, bounds.Size); var color = new GsColor(GsColor.Gray, 128); var graphics = dparams.Graphics; graphics.DrawImage(wbase, color, bounds.Location, scale); }
public AlphaBlendSettings(GsColor color) { if (color.A < 255) { enabled = true; GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); } }
public void DrawPolygon(GsColor color, GsVector[] pts) { SwitchMode(Mode.Primitives); for (int i = 1; i < pts.Length; ++i) { var p1 = pts[i - 1]; var p2 = pts[i]; primitiveBatch.DrawLine(CreateVertex(color, p1), CreateVertex(color, p2)); } }
public void DrawLine(GsColor color, float x0, float y0, float x1, float y1) { using (AlphaBlend(color)) { GL.Begin(PrimitiveType.Lines); GL.Color4(color.R, color.G, color.B, color.A); GL.Vertex2(x0, y0); GL.Vertex2(x1, y1); GL.End(); } }
protected override void DrawWeaponBase(DrawParams dparams, GsRectangle bounds, GsRectangle inside) { // draw a speed bump! var speedbump = GetImage(); var speedbumpSize = ImageProvider.GetSize(speedbump); var scale = Calculator.ComputeScale(speedbumpSize, bounds.Size); GsColor color = GsColor.White; var graphics = dparams.Graphics; graphics.DrawImage(speedbump, color, bounds.Location, scale); }
public void FillRectangle(GsColor color, float x, float y, float width, float height) { using (AlphaBlend(color)) { GL.Begin(PrimitiveType.Quads); GL.Color4(color.R, color.G, color.B, color.A); GL.Vertex2(x, y); GL.Vertex2(x + width, y); GL.Vertex2(x + width, y + height); GL.Vertex2(x, y + height); GL.End(); } }
public void DrawPolygon(GsColor color, GsVector[] pts) { using (AlphaBlend(color)) { GL.Begin(PrimitiveType.Lines); GL.Color4(color.R, color.G, color.B, color.A); for (int i = 1; i < pts.Length; ++i) { var p1 = pts[i - 1]; var p2 = pts[i]; GL.Vertex2(p1.X, p1.Y); GL.Vertex2(p2.X, p2.Y); } GL.End(); } }
protected void DrawProgressState(DrawParams dparams, GsRectangle bounds, GsRectangle inside) { float width = inside.Width; float height = (float)Math.Round(inside.Height / 3f); float x = inside.X + ((inside.Width / 2f) - (width / 2f)); float y = inside.Y + ((inside.Height / 2f) - (height / 2f)); float progressWidth = width * Calculator.CalculatePercent(ProgressValue, 0, MaxProgress); float factor = ProgressValue / (MaxProgress); GsColor barFill = GsMath.Lerp(GsColor.Red, GsColor.DarkGreen, factor); GsColor barBder = GsColor.Black; dparams.Graphics.FillRectangle(barFill, x, y, progressWidth, height); dparams.Graphics.DrawRectangle(barBder, x, y, width, height); }
public void DrawRectangle(GsColor color, float x, float y, float width, float height) { SwitchMode(Mode.Primitives); var verts = new[] { CreateVertex(color, x - 1, y), CreateVertex(color, x + width, y), CreateVertex(color, x + width, y + height), CreateVertex(color, x, y + height) }; primitiveBatch.DrawIndexed(PrimitiveType.LineList, new short[] { 0, 1, 1, 2, 2, 3, 3, 0 }, verts); }
private void DrawGrid(DrawParams dparams) { GsVector offset = dparams.Offset; for (int c = 0; c < NumCols; ++c) { for (int r = 0; r < NumRows; ++r) { GridCell cell = Grid[c, r]; GsRectangle bounds = new GsRectangle(cell.X + offset.X, cell.Y + offset.Y, cell.Width, cell.Height); if (cellsToFlash.ContainsKey(cell)) { // draw the flashing cells int index = ((int)((SecondsToFlashCell - cellsToFlash[cell]) * FlashesPerSecond)) % MaxFlashes; float mu = ((float)index) / ((float)MaxFlashes); GsColor color = GsMath.SmoothStep(FlashStart, FlashEnd, mu); color = new GsColor(color, 200); dparams.Graphics.FillRectangle(color, bounds); } if (cell.IsOuter && !cell.IsThroughway) { switch (dparams.FillMode) { case GridFillMode.Solid: { dparams.Graphics.FillRectangle(GsColor.White, bounds); break; } case GridFillMode.Polygons: { dparams.Graphics.DrawRectangle(GsColor.White, bounds); break; } } } } } }
public void FillPolygon(GsColor color, GsVector[] pts) { using (AlphaBlend(color)) { var indices = Ratcliff.Triangulate(pts); GL.Begin(PrimitiveType.Triangles); GL.Color4(color.R, color.G, color.B, color.A); int i = 0; while (i < indices.Length) { var p1 = pts[indices[i++]]; var p2 = pts[indices[i++]]; var p3 = pts[indices[i++]]; GL.Vertex2(p1.X, p1.Y); GL.Vertex2(p2.X, p2.Y); GL.Vertex2(p3.X, p3.Y); } GL.End(); } }
public void Draw(DrawParams dparams) { if (Chunk != null) { GsColor color = Chunk.Valid ? GsColor.Green : GsColor.Red; GsRectangle bounds = new GsRectangle(Chunk.Location + dparams.Offset, Chunk.Size); dparams.Graphics.FillRectangle(new GsColor(color, 100), bounds); dparams.Graphics.DrawRectangle(color, bounds); // draw the chunks being edited foreach (GridCellChunk item in chunksBeingEdited.Keys) { GsColor itemClr = item.Valid ? GsColor.Green : GsColor.Red; GsRectangle itemBounds = new GsRectangle(item.Location + dparams.Offset, item.Size); dparams.Graphics.FillRectangle(new GsColor(itemClr, 100), itemBounds); dparams.Graphics.DrawRectangle(itemClr, itemBounds); } } }
public TeslaCoilPiece() { // setup the description StringBuilder sb = new StringBuilder(); sb.AppendLine("Fires a charged burst of electricity. The burst is very effective against ground units."); // set the properties needed Attack = 9000; Price = 2500; Radius = 250; UpgradePercent = 45; LevelVisibility = 75; Description = sb.ToString(); ProjectileLifeInSeconds = 6.7f; CanFireProjectiles = false; Name = TeslaCoilName; UltimateName = UltimateTeslaCoilName; Grouping = PieceGrouping.Three; ImageKey = "teslaCoil"; Element = Element.Electricity; Specialty = PieceSpecialty.Both; // set the properties of the piece mIndex = 0; mAggregateTimeSinceUpdate = 0; mTeslaState = TeslaState.Idle; Color = GsColor.White; // get the image var image = GetImage(); var imageSize = ImageProvider.GetSize(image); FrameSize = new GsSize(imageSize.Width / (NumberIndexFrames + 1), imageSize.Height); LightningColor = GsMath.Lerp(GsColor.Purple, GsColor.DarkBlue, .5f); LightningColor = GsMath.Lerp(LightningColor, GsColor.Red, .75f); }
public static Color ToColor(this GsColor color) { return(new Color(color.R, color.G, color.B, color.A)); }
private void DrawImage(TextureData data, float x, float y, float width, float height, GsColor color) { using (data.Bind()) { GL.Begin(PrimitiveType.Quads); GL.Color4(color.R, color.G, color.B, color.A); GL.TexCoord2(0f, 0f); GL.Vertex2(x, y); GL.TexCoord2(1f, 0f); GL.Vertex2(x + width, y); GL.TexCoord2(1f, 1f); GL.Vertex2(x + width, y + height); GL.TexCoord2(0f, 1f); GL.Vertex2(x, y + height); GL.End(); } }
public void DrawImage(GsImage image, GsRectangle dest, GsRectangle?source, GsVector origin, float angle, GsImageFlip flip, GsColor tint) { DrawSprite(image.Data as TextureData, dest, source, origin, angle, flip, tint); }
private IDisposable AlphaBlend(GsColor color) { return(new AlphaBlendSettings(color)); }
public void DrawImage(GsImage image, float x, float y, float width, float height, GsColor tint) { DrawImage(image.Data as TextureData, x, y, width, height, tint); }
public void DrawImage(GsImage image, GsRectangle dest, GsRectangle?source, GsVector origin, float angle, GsImageFlip flip, GsColor tint) { SwitchMode(Mode.Sprites); Rectangle?src = null; if (source.HasValue) { var s = source.Value; src = new Rectangle((int)s.X, (int)s.Y, (int)s.Width, (int)s.Height); } var dst = new RectangleF(dest.X, dest.Y, dest.Width, dest.Height); spriteBatch.Draw(image.Data as Texture2D, dst, src, tint.ToColor(), angle, new Vector2(origin.X, origin.Y), flip.ToSpriteEffects(), 0f); }
public static PixelData ToPixelData(this GsColor color) { return(new PixelData { A = color.A, B = color.B, G = color.G, R = color.R }); }
private void DrawSprite(TextureData data, GsRectangle dst, GsRectangle?source, GsVector origin, float rotation, GsImageFlip flip, GsColor color) { if (color.A <= 0) { return; } GsSize texSize = new GsSize(data.Bitmap.Width, data.Bitmap.Height); GsRectangle src = source.GetValueOrDefault( new GsRectangle(GsVector.Zero, texSize)); using (data.Bind()) { GL.Color4(color.R, color.G, color.B, color.A); // Setup the matrix GL.PushMatrix(); if ((dst.X != 0) || (dst.Y != 0)) { GL.Translate(dst.X, dst.Y, 0f); } if (rotation != 0) { GL.Rotate(MathHelper.RadiansToDegrees(rotation), 0, 0, 1); } if ((dst.Width != 0 && origin.X != 0) || (dst.Height != 0 && origin.Y != 0)) { GL.Translate( -origin.X * (float)dst.Width / (float)src.Width, -origin.Y * (float)dst.Height / (float)src.Height, 0f); } // Calculate the points on the texture float x = src.X / texSize.Width; float y = src.Y / texSize.Height; float twidth = src.Width / texSize.Width; float theight = src.Height / texSize.Height; Vector2[] tx = new Vector2[] { new Vector2(x, y + theight), new Vector2(x + twidth, y + theight), new Vector2(x + twidth, y), new Vector2(x, y), }; var tcs = texCoords[flip]; int t = 0; GL.Begin(PrimitiveType.Quads); GL.TexCoord2(tx[tcs[t++]]); GL.Vertex2(0f, dst.Height); GL.TexCoord2(tx[tcs[t++]]); GL.Vertex2(dst.Width, dst.Height); GL.TexCoord2(tx[tcs[t++]]); GL.Vertex2(dst.Width, 0f); GL.TexCoord2(tx[tcs[t++]]); GL.Vertex2(0f, 0f); GL.End(); GL.PopMatrix(); } }
public void FillEllipse(GsColor color, float x, float y, float width, float height) { var pts = Geometry.CreateEllipse(x, y, width, height); FillPolygon(color, pts); }