public static void SetPersonMask(string name, ColorInstance color) { Person value; if (PeopleTable.TryGetValue(name, out value)) { value.Mask = color.GetColor(); } }
public void TransformBlitMask(ObjectInstance ul, ObjectInstance ur, ObjectInstance lr, ObjectInstance ll, ColorInstance color) { float w = (float)_image.Size.X, h = (float)_image.Size.Y; Vertex[] array = new Vertex[4]; Color c = color.GetColor(); array[0] = new Vertex(GlobalPrimitives.GetVector(ul), c, new Vector2f(0, 0)); array[1] = new Vertex(GlobalPrimitives.GetVector(ur), c, new Vector2f(w, 0)); array[2] = new Vertex(GlobalPrimitives.GetVector(lr), c, new Vector2f(w, h)); array[3] = new Vertex(GlobalPrimitives.GetVector(ll), c, new Vector2f(0, h)); Program.Batch.Add(_image, array); }
public void ZoomBlitMask(double x, double y, double z, ColorInstance color) { if (!Visible(x, y)) return; float wz = (float)(_source.Width * z); float hz = (float)(_source.Height * z); Program.Batch.Add(_image, _source, new FloatRect((float)x, (float)y, wz, hz), color.GetColor()); }
public void OutlinedCircle(int ox, int oy, int r, ColorInstance color, [DefaultParameterValue(false)] bool antialias = false) { if (r < 0 || color == null || ox < 0 || oy < 0) throw new ArgumentException("Invalid parameters."); else if (r == 0) return; fixed (byte* buf = _pixels) { var w = r * 2; var h = w; var c = color.GetColor(); if (antialias) { var pio2 = Math.PI / 2; for (var y = 0; y < r; ++y) { for (var x = 0; x < r; ++x) { var dist = Math.Sqrt(x * x + y * y); if (dist > r - 2 && dist < r) { c.A = (byte)(c.A * Math.Sin(Math.Sin((1 - Math.Abs(dist - r + 1)) * pio2) * pio2)); SetPixel(buf, ox + x + r, oy + y + r, ref c); SetPixel(buf, ox + r - x, oy + y + r, ref c); SetPixel(buf, ox + r - x, oy + r - y, ref c); SetPixel(buf, ox + x + r, oy + r - y, ref c); } } } } else { var pi2 = Math.PI * 2; var step = pi2 / (Math.Min(360, pi2 * r)); int ci = color.GetInt(); for (double pt = 0.0, pt2 = step; pt < pi2; pt += step, pt2 += step) { int x1 = (int)(r + r * Math.Sin(pt)); int y1 = (int)(r + r * Math.Cos(pt)); int x2 = (int)(r + r * Math.Sin(pt2)); int y2 = (int)(r + r * Math.Cos(pt2)); Line(buf, ox + x1, oy + y1, ox + x2, oy + y2, ci); } } } _changed = true; }
public void ReplaceColor(ColorInstance colorA, ColorInstance colorB) { Color a = colorA.GetColor(); Color b = colorB.GetColor(); for (var i = 0; i < _pixels.Length; i += 4) { if (_pixels[i] == a.R && _pixels[i + 1] == a.G && _pixels[i + 2] == a.B && _pixels[i + 3] == a.A) { _pixels[i + 0] = b.R; _pixels[i + 1] = b.G; _pixels[i + 2] = b.B; _pixels[i + 3] = b.A; } } _changed = true; }
public void PointSeries(ArrayInstance array, ColorInstance color) { Color c = color.GetColor(); Vertex[] verts = new Vertex[array.Length]; for (var i = 0; i < array.Length; ++i) { Vector2f vect = GlobalPrimitives.GetVector(array[i] as ObjectInstance); verts[i] = new Vertex(vect, c); } _batch.AddVerts(verts, verts.Length, PrimitiveType.Points); _changed = true; }
public static void SetColorMask(ColorInstance color, int frames) { Color c = color.GetColor(); if (c.Equals(Color.White)) _mask = null; else { _mask = color; _target_alpha = c.A; _mask_frames = frames; } }
public static void GradientLine(double x1, double y1, double x2, double y2, ColorInstance color1, ColorInstance color2) { _verts[0] = new Vertex(new Vector2f((float)x1, (float)y1), color1.GetColor()); _verts[1] = new Vertex(new Vector2f((float)x2, (float)y2), color2.GetColor()); Program.Batch.AddVerts(_verts, 2, PrimitiveType.Lines); }
public static void GradientTriangle(ObjectInstance A, ObjectInstance B, ObjectInstance C, ColorInstance color1, ColorInstance color2, ColorInstance color3) { _verts[0] = new Vertex(GetVector(A), color1.GetColor()); _verts[1] = new Vertex(GetVector(B), color2.GetColor()); _verts[2] = new Vertex(GetVector(C), color3.GetColor()); Program.Batch.AddVerts(_verts, 3, PrimitiveType.Triangles); }
public static void PointSeries(ArrayInstance points, ColorInstance color) { Program.Batch.Flush(); if (points == null || color == null) throw new NullReferenceException(); Color sfml_col = color.GetColor(); Vertex[] v = new Vertex[points.Length]; for (var i = 0; i < points.Length; ++i) { ObjectInstance obj = points[i] as ObjectInstance; if (obj != null) v[i] = new Vertex(GetVector(obj), sfml_col); else throw new NullReferenceException(); } Program.Batch.AddVerts(v, v.Length, PrimitiveType.Points); }
public static void Polygon(ArrayInstance points, ColorInstance color, [DefaultParameterValue(false)] bool inverse = false) { if (points == null || color == null) throw new NullReferenceException(); Color c = color.GetColor(); Vertex[] v = new Vertex[points.Length]; for (var i = 0; i < points.Length; ++i) { ObjectInstance obj = points[i] as ObjectInstance; v[i] = new Vertex(GetVector(obj), c); } Program.Batch.AddVerts(v, v.Length, PrimitiveType.TrianglesFan); }
public static void Point(double x, double y, ColorInstance color) { _verts[0] = new Vertex(new Vector2f((float)x, (float)y), color.GetColor()); Program.Batch.AddVerts(_verts, 1, PrimitiveType.Points); }
// is this even being used? public static void OutlinedRectangles(ArrayInstance items, ColorInstance color) { uint size = items.Length * 4; Color c = color.GetColor(); Vertex[] verts = new Vertex[size]; for (var i = 0; i < size; i += 4) { ObjectInstance rect = items[i / 4] as ObjectInstance; int x1 = (int)rect["x"]; int y1 = (int)rect["y"]; int x2 = x1 + (int)rect["w"]; int y2 = y1 + (int)rect["h"]; verts[i + 0] = new Vertex(new Vector2f(x1, y1), c); verts[i + 1] = new Vertex(new Vector2f(x2, y1), c); verts[i + 2] = new Vertex(new Vector2f(x2, y2), c); verts[i + 3] = new Vertex(new Vector2f(x1, y2), c); } Program.Batch.AddVerts(verts, verts.Length, PrimitiveType.LinesStrip); }
public static void LineSeries(ArrayInstance points, ColorInstance color) { if (points == null || color == null) throw new NullReferenceException(); Color sfml_col = color.GetColor(); Vertex[] v = new Vertex[points.Length]; for (var i = 0; i < points.Length; ++i) { ObjectInstance obj = points[i] as ObjectInstance; if (obj != null) v[i] = new Vertex(GetVector(obj), sfml_col); else throw new Jurassic.JavaScriptException(Program._engine, "Invalid object", "Not a JS object in array."); } Program.Batch.AddVerts(v, v.Length, PrimitiveType.Lines); }
public void GradientLine(int x1, int y1, int x2, int y2, ColorInstance col1, ColorInstance col2) { Vertex[] _verts = new Vertex[2]; _verts[0] = new Vertex(new Vector2f(x1, y1), col1.GetColor()); _verts[1] = new Vertex(new Vector2f(x2, y2), col2.GetColor()); _batch.AddVerts(_verts, 2, PrimitiveType.Lines); _changed = true; }
public void BlitMaskSurface(SurfaceInstance surf, int ox, int oy, ColorInstance mask) { Color mask_c = mask.GetColor(), final = new Color(); fixed (byte* buf = _pixels) { for (int y = 0; y < surf._height; ++y) { for (int x = 0; x < surf._width; ++x) { Color dest = surf.GetColorAt(x, y); ColorBlend(ref dest, ref mask_c, ref final); // todo SetPixel(buf, ox + x, oy + y, ref final); } } } _changed = true; }
public void Line(int x1, int y1, int x2, int y2, ColorInstance color) { Color col = color.GetColor(); Vertex[] _verts = new Vertex[2]; _verts[0] = new Vertex(new Vector2f(x1, y1), col); _verts[1] = new Vertex(new Vector2f(x2, y2), col); _batch.AddVerts(_verts, 2, PrimitiveType.Lines); _changed = true; }
public void FilledCircle(int ox, int oy, int r, ColorInstance color, [DefaultParameterValue(false)] bool antialias = false) { if (ox < 0 || oy < 0 || r < 0 || color == null) throw new ArgumentException("Invalid parameters."); if (r == 0) return; fixed (byte* buf = _pixels) { var pi2 = Math.PI / 2; var w = r * 2; var h = w; Color c = color.GetColor(); ox -= r; oy -= r; if (antialias) { for (var y = 0; y < r; ++y) { for (var x = 0; x < r; ++x) { var dist = Math.Sqrt(x * x + y * y); if (dist < r) { if (dist > r - 1) c.A = (byte)(c.A * Math.Sin(Math.Sin((r - dist) * pi2) * pi2)); SetPixel(buf, ox + x + r, oy + y + r, ref c); SetPixel(buf, ox + r - x, oy + y + r, ref c); SetPixel(buf, ox + r - x, oy + r - y, ref c); SetPixel(buf, ox + x + r, oy + r - y, ref c); } } } } else { int ci = color.GetInt(); for (var y = 0; y < r; ++y) { int lw = (int)(r * Math.Cos(Math.Asin(1 - (float)y / r))); Line(buf, ox + r - lw, oy + y, ox + r + lw, oy + y, ci); Line(buf, ox + r - lw, oy + h - y - 1, ox + r + lw, oy + h - y - 1, ci); } } } _changed = true; }
public void SetPixel(int x, int y, ColorInstance color) { Vertex[] verts = new Vertex[1] { new Vertex(new Vector2f(x, y), color.GetColor()) }; _batch.AddVerts(verts, 1, PrimitiveType.Points); _changed = true; }
public void SetColorMask(ColorInstance color) { this["color"] = color; _color = color.GetColor(); foreach (Sprite s in _sprites) s.Color = _color; }