public static void drawLines(NvgContext vg, float x, float y, float w, float h, float t) { int i, j; float pad = 5.0f, s = w / 9.0f - pad * 2; float[] pts = new float[4 * 2]; float fx, fy; LineCap[] joins = new LineCap[] { LineCap.Miter, LineCap.Round, LineCap.Bevel }; LineCap[] caps = new LineCap[] { LineCap.Butt, LineCap.Round, LineCap.Square }; vg.Save(); pts[0] = -s * 0.25f + (float)Math.Cos(t * 0.3f) * s * 0.5f; pts[1] = (float)Math.Sin(t * 0.3f) * s * 0.5f; pts[2] = -s * 0.25f; pts[3] = 0; pts[4] = s * 0.25f; pts[5] = 0; pts[6] = s * 0.25f + (float)Math.Cos(-t * 0.3f) * s * 0.5f; pts[7] = (float)Math.Sin(-t * 0.3f) * s * 0.5f; for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) { fx = x + s * 0.5f + (i * 3 + j) / 9.0f * w + pad; fy = y - s * 0.5f + pad; vg.LineCap(caps[i]); vg.LineJoin(joins[j]); vg.StrokeWidth(s * 0.3f); vg.StrokeColor(new Color(0, 0, 0, 160)); vg.BeginPath(); vg.MoveTo(fx + pts[0], fy + pts[1]); vg.LineTo(fx + pts[2], fy + pts[3]); vg.LineTo(fx + pts[4], fy + pts[5]); vg.LineTo(fx + pts[6], fy + pts[7]); vg.Stroke(); vg.LineCap(LineCap.Butt); vg.LineJoin(LineCap.Bevel); vg.StrokeWidth(1.0f); vg.StrokeColor(new Color(0, 192, 255, 255)); vg.BeginPath(); vg.MoveTo(fx + pts[0], fy + pts[1]); vg.LineTo(fx + pts[2], fy + pts[3]); vg.LineTo(fx + pts[4], fy + pts[5]); vg.LineTo(fx + pts[6], fy + pts[7]); vg.Stroke(); } } vg.Restore(); }
public static void drawCaps(NvgContext vg, float x, float y, float width) { int i; LineCap[] caps = new[] { LineCap.Butt, LineCap.Round, LineCap.Square }; float lineWidth = 8.0f; vg.Save(); vg.BeginPath(); vg.Rect(x - lineWidth / 2, y, width + lineWidth, 40); vg.FillColor(new Color(255, 255, 255, 32)); vg.Fill(); vg.BeginPath(); vg.Rect(x, y, width, 40); vg.FillColor(new Color(255, 255, 255, 32)); vg.Fill(); vg.StrokeWidth(lineWidth); for (i = 0; i < 3; i++) { vg.LineCap(caps[i]); vg.StrokeColor(new Color(0, 0, 0, 255)); vg.BeginPath(); vg.MoveTo(x, y + i * 10 + 5); vg.LineTo(x + width, y + i * 10 + 5); vg.Stroke(); } vg.Restore(); }
public static void drawWidths(NvgContext vg, float x, float y, float width) { int i; vg.Save(); vg.StrokeColor(new Color(0, 0, 0, 255)); for (i = 0; i < 20; i++) { float w = (i + 0.5f) * 0.1f; vg.StrokeWidth(w); vg.BeginPath(); vg.MoveTo(x, y); vg.LineTo(x + width, y + width * 0.3f); vg.Stroke(); y += 10; } vg.Restore(); }
public static void drawColorwheel(NvgContext vg, float x, float y, float w, float h, float t) { int i; float r0, r1, ax, ay, bx, by, cx, cy, aeps, r; float hue = (float)Math.Sin(t * 0.12f); Paint paint; vg.Save(); /* vg.BeginPath(); * vg.Rect(x,y,w,h); * vg.FillColor(new Color(255,0,0,128)); * vg.Fill();*/ cx = x + w * 0.5f; cy = y + h * 0.5f; r1 = (w < h ? w : h) * 0.5f - 5.0f; r0 = r1 - 20.0f; aeps = 0.5f / r1; // half a pixel arc length in radians (2pi cancels out). for (i = 0; i < 6; i++) { float a0 = (float)i / 6.0f * (float)Math.PI * 2.0f - aeps; float a1 = (float)(i + 1.0f) / 6.0f * (float)Math.PI * 2.0f + aeps; vg.BeginPath(); vg.Arc(cx, cy, r0, a0, a1, Winding.ClockWise); vg.Arc(cx, cy, r1, a1, a0, Winding.CounterClockWise); vg.ClosePath(); ax = cx + (float)Math.Cos(a0) * (r0 + r1) * 0.5f; ay = cy + (float)Math.Sin(a0) * (r0 + r1) * 0.5f; bx = cx + (float)Math.Cos(a1) * (r0 + r1) * 0.5f; by = cy + (float)Math.Sin(a1) * (r0 + r1) * 0.5f; paint = vg.LinearGradient(ax, ay, bx, by, NvgUtility.HSLA(a0 / ((float)Math.PI * 2), 1.0f, 0.55f, 255), NvgUtility.HSLA(a1 / ((float)Math.PI * 2), 1.0f, 0.55f, 255)); vg.FillPaint(paint); vg.Fill(); } vg.BeginPath(); vg.Circle(cx, cy, r0 - 0.5f); vg.Circle(cx, cy, r1 + 0.5f); vg.StrokeColor(new Color(0, 0, 0, 64)); vg.StrokeWidth(1.0f); vg.Stroke(); // Selector vg.Save(); vg.Translate(cx, cy); vg.Rotate(hue * (float)Math.PI * 2); // Marker on vg.StrokeWidth(2.0f); vg.BeginPath(); vg.Rect(r0 - 1, -3, r1 - r0 + 2, 6); vg.StrokeColor(new Color(255, 255, 255, 192)); vg.Stroke(); paint = vg.BoxGradient(r0 - 3, -5, r1 - r0 + 6, 10, 2, 4, new Color(0, 0, 0, 128), new Color(0, 0, 0, 0)); vg.BeginPath(); vg.Rect(r0 - 2 - 10, -4 - 10, r1 - r0 + 4 + 20, 8 + 20); vg.Rect(r0 - 2, -4, r1 - r0 + 4, 8); vg.PathWinding(Solidity.Hole); vg.FillPaint(paint); vg.Fill(); // Center triangle r = r0 - 6; ax = (float)Math.Cos(120.0f / 180.0f * (float)Math.PI) * r; ay = (float)Math.Sin(120.0f / 180.0f * (float)Math.PI) * r; bx = (float)Math.Cos(-120.0f / 180.0f * (float)Math.PI) * r; by = (float)Math.Sin(-120.0f / 180.0f * (float)Math.PI) * r; vg.BeginPath(); vg.MoveTo(r, 0); vg.LineTo(ax, ay); vg.LineTo(bx, by); vg.ClosePath(); paint = vg.LinearGradient(r, 0, ax, ay, NvgUtility.HSLA(hue, 1.0f, 0.5f, 255), new Color(255, 255, 255, 255)); vg.FillPaint(paint); vg.Fill(); paint = vg.LinearGradient((r + ax) * 0.5f, (0 + ay) * 0.5f, bx, by, new Color(0, 0, 0, 0), new Color(0, 0, 0, 255)); vg.FillPaint(paint); vg.Fill(); vg.StrokeColor(new Color(0, 0, 0, 64)); vg.Stroke(); // Select circle on triangle ax = (float)Math.Cos(120.0f / 180.0f * (float)Math.PI) * r * 0.3f; ay = (float)Math.Sin(120.0f / 180.0f * (float)Math.PI) * r * 0.4f; vg.StrokeWidth(2.0f); vg.BeginPath(); vg.Circle(ax, ay, 5); vg.StrokeColor(new Color(255, 255, 255, 192)); vg.Stroke(); paint = vg.RadialGradient(ax, ay, 7, 9, new Color(0, 0, 0, 64), new Color(0, 0, 0, 0)); vg.BeginPath(); vg.Rect(ax - 20, ay - 20, 40, 40); vg.Circle(ax, ay, 7); vg.PathWinding(Solidity.Hole); vg.FillPaint(paint); vg.Fill(); vg.Restore(); vg.Restore(); }
public static void drawThumbnails(NvgContext vg, float x, float y, float w, float h, int[] images, float t) { float cornerRadius = 3.0f; Paint shadowPaint, imgPaint, fadePaint; float ix, iy, iw, ih; float thumb = 60.0f; float arry = 30.5f; int imgw, imgh; float stackh = (images.Length / 2) * (thumb + 10) + 10; int i; float u = (1 + (float)Math.Cos(t * 0.5f)) * 0.5f; float u2 = (1 - (float)Math.Cos(t * 0.2f)) * 0.5f; float scrollh, dv; vg.Save(); // ClearState(vg); // Drop shadow shadowPaint = vg.BoxGradient(x, y + 4, w, h, cornerRadius * 2, 20, new Color(0, 0, 0, 128), new Color(0, 0, 0, 0)); vg.BeginPath(); vg.Rect(x - 10, y - 10, w + 20, h + 30); vg.RoundedRect(x, y, w, h, cornerRadius); vg.PathWinding(Solidity.Hole); vg.FillPaint(shadowPaint); vg.Fill(); // Window vg.BeginPath(); vg.RoundedRect(x, y, w, h, cornerRadius); vg.MoveTo(x - 10, y + arry); vg.LineTo(x + 1, y + arry - 11); vg.LineTo(x + 1, y + arry + 11); vg.FillColor(new Color(200, 200, 200, 255)); vg.Fill(); vg.Save(); vg.Scissor(x, y, w, h); vg.Translate(0, -(stackh - h) * u); dv = 1.0f / (float)(images.Length - 1); for (i = 0; i < images.Length; i++) { float tx, ty, v, a; tx = x + 10; ty = y + 10; tx += (i % 2) * (thumb + 10); ty += (i / 2) * (thumb + 10); vg.ImageSize(images[i], out imgw, out imgh); if (imgw < imgh) { iw = thumb; ih = iw * (float)imgh / (float)imgw; ix = 0; iy = -(ih - thumb) * 0.5f; } else { ih = thumb; iw = ih * (float)imgw / (float)imgh; ix = -(iw - thumb) * 0.5f; iy = 0; } v = i * dv; a = clampf((u2 - v) / dv, 0, 1); if (a < 1.0f) { drawSpinner(vg, tx + thumb / 2, ty + thumb / 2, thumb * 0.25f, t); } imgPaint = vg.ImagePattern(tx + ix, ty + iy, iw, ih, 0.0f / 180.0f * (float)Math.PI, images[i], a); vg.BeginPath(); vg.RoundedRect(tx, ty, thumb, thumb, 5); vg.FillPaint(imgPaint); vg.Fill(); shadowPaint = vg.BoxGradient(tx - 1, ty, thumb + 2, thumb + 2, 5, 3, new Color(0, 0, 0, 128), new Color(0, 0, 0, 0)); vg.BeginPath(); vg.Rect(tx - 5, ty - 5, thumb + 10, thumb + 10); vg.RoundedRect(tx, ty, thumb, thumb, 6); vg.PathWinding(Solidity.Hole); vg.FillPaint(shadowPaint); vg.Fill(); vg.BeginPath(); vg.RoundedRect(tx + 0.5f, ty + 0.5f, thumb - 1, thumb - 1, 4 - 0.5f); vg.StrokeWidth(1.0f); vg.StrokeColor(new Color(255, 255, 255, 192)); vg.Stroke(); } vg.Restore(); // Hide fades fadePaint = vg.LinearGradient(x, y, x, y + 6, new Color(200, 200, 200, 255), new Color(200, 200, 200, 0)); vg.BeginPath(); vg.Rect(x + 4, y, w - 8, 6); vg.FillPaint(fadePaint); vg.Fill(); fadePaint = vg.LinearGradient(x, y + h, x, y + h - 6, new Color(200, 200, 200, 255), new Color(200, 200, 200, 0)); vg.BeginPath(); vg.Rect(x + 4, y + h - 6, w - 8, 6); vg.FillPaint(fadePaint); vg.Fill(); // Scroll bar shadowPaint = vg.BoxGradient(x + w - 12 + 1, y + 4 + 1, 8, h - 8, 3, 4, new Color(0, 0, 0, 32), new Color(0, 0, 0, 92)); vg.BeginPath(); vg.RoundedRect(x + w - 12, y + 4, 8, h - 8, 3); vg.FillPaint(shadowPaint); // vg.FillColor(new Color(255,0,0,128)); vg.Fill(); scrollh = (h / stackh) * (h - 8); shadowPaint = vg.BoxGradient(x + w - 12 - 1, y + 4 + (h - 8 - scrollh) * u - 1, 8, scrollh, 3, 4, new Color(220, 220, 220, 255), new Color(128, 128, 128, 255)); vg.BeginPath(); vg.RoundedRect(x + w - 12 + 1, y + 4 + 1 + (h - 8 - scrollh) * u, 8 - 2, scrollh - 2, 2); vg.FillPaint(shadowPaint); // vg.FillColor(new Color(0,0,0,128)); vg.Fill(); vg.Restore(); }
public static void drawGraph(NvgContext vg, float x, float y, float w, float h, float t) { Paint bg; float[] samples = new float[6]; float[] sx = new float[6], sy = new float[6]; float dx = w / 5.0f; int i; samples[0] = (1 + (float)Math.Sin(t * 1.2345f + (float)Math.Cos(t * 0.33457f) * 0.44f)) * 0.5f; samples[1] = (1 + (float)Math.Sin(t * 0.68363f + (float)Math.Cos(t * 1.3f) * 1.55f)) * 0.5f; samples[2] = (1 + (float)Math.Sin(t * 1.1642f + (float)Math.Cos(t * 0.33457) * 1.24f)) * 0.5f; samples[3] = (1 + (float)Math.Sin(t * 0.56345f + (float)Math.Cos(t * 1.63f) * 0.14f)) * 0.5f; samples[4] = (1 + (float)Math.Sin(t * 1.6245f + (float)Math.Cos(t * 0.254f) * 0.3f)) * 0.5f; samples[5] = (1 + (float)Math.Sin(t * 0.345f + (float)Math.Cos(t * 0.03f) * 0.6f)) * 0.5f; for (i = 0; i < 6; i++) { sx[i] = x + i * dx; sy[i] = y + h * samples[i] * 0.8f; } // Graph background bg = vg.LinearGradient(x, y, x, y + h, new Color(0, 160, 192, 0), new Color(0, 160, 192, 64)); vg.BeginPath(); vg.MoveTo(sx[0], sy[0]); for (i = 1; i < 6; i++) { vg.BezierTo(sx[i - 1] + dx * 0.5f, sy[i - 1], sx[i] - dx * 0.5f, sy[i], sx[i], sy[i]); } vg.LineTo(x + w, y + h); vg.LineTo(x, y + h); vg.FillPaint(bg); vg.Fill(); // Graph line vg.BeginPath(); vg.MoveTo(sx[0], sy[0] + 2); for (i = 1; i < 6; i++) { vg.BezierTo(sx[i - 1] + dx * 0.5f, sy[i - 1] + 2, sx[i] - dx * 0.5f, sy[i] + 2, sx[i], sy[i] + 2); } vg.StrokeColor(new Color(0, 0, 0, 32)); vg.StrokeWidth(3.0f); vg.Stroke(); vg.BeginPath(); vg.MoveTo(sx[0], sy[0]); for (i = 1; i < 6; i++) { vg.BezierTo(sx[i - 1] + dx * 0.5f, sy[i - 1], sx[i] - dx * 0.5f, sy[i], sx[i], sy[i]); } vg.StrokeColor(new Color(0, 160, 192, 255)); vg.StrokeWidth(3.0f); vg.Stroke(); // Graph sample pos for (i = 0; i < 6; i++) { bg = vg.RadialGradient(sx[i], sy[i] + 2, 3.0f, 8.0f, new Color(0, 0, 0, 32), new Color(0, 0, 0, 0)); vg.BeginPath(); vg.Rect(sx[i] - 10, sy[i] - 10 + 2, 20, 20); vg.FillPaint(bg); vg.Fill(); } vg.BeginPath(); for (i = 0; i < 6; i++) { vg.Circle(sx[i], sy[i], 4.0f); } vg.FillColor(new Color(0, 160, 192, 255)); vg.Fill(); vg.BeginPath(); for (i = 0; i < 6; i++) { vg.Circle(sx[i], sy[i], 2.0f); } vg.FillColor(new Color(220, 220, 220, 255)); vg.Fill(); vg.StrokeWidth(1.0f); }