public static void drawScissor(NvgContext vg, float x, float y, float t) { vg.Save(); // Draw first rect and set scissor to it's area. vg.Translate(x, y); vg.Rotate(NvgUtility.DegToRad(5)); vg.BeginPath(); vg.Rect(-20, -20, 60, 40); vg.FillColor(new Color(255, 0, 0, 255)); vg.Fill(); vg.Scissor(-20, -20, 60, 40); // Draw second rectangle with offset and rotation. vg.Translate(40, 0); vg.Rotate(t); // Draw the intended second rectangle without any scissoring. vg.Save(); vg.ResetScissor(); vg.BeginPath(); vg.Rect(-20, -10, 60, 30); vg.FillColor(new Color(255, 128, 0, 64)); vg.Fill(); vg.Restore(); // Draw second rectangle with combined scissoring. vg.IntersectScissor(-20, -10, 60, 30); vg.BeginPath(); vg.Rect(-20, -10, 60, 30); vg.FillColor(new Color(255, 128, 0, 255)); vg.Fill(); 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 void renderDemo(NvgContext vg, float mx, float my, float width, float height, float t, bool blowup) { float x, y, popy; drawEyes(vg, width - 250, 50, 150, 100, mx, my, t); drawParagraph(vg, width - 450, 50, 150, 100, mx, my); drawGraph(vg, 0, height / 2, width, height / 2, t); drawColorwheel(vg, width - 300, height - 300, 250.0f, 250.0f, t); // Line joints drawLines(vg, 120, height - 50, 600, 50, t); // Line caps drawWidths(vg, 10, 50, 30); // Line caps drawCaps(vg, 10, 300, 30); drawScissor(vg, 50, height - 80, t); vg.Save(); if (blowup) { vg.Rotate((float)Math.Sin(t * 0.3f) * 5.0f / 180.0f * (float)Math.PI); vg.Scale(2.0f, 2.0f); } // Widgets drawWindow(vg, "Widgets `n Stuff", 50, 50, 300, 400); x = 60; y = 95; drawSearchBox(vg, "Search", x, y, 280, 25); y += 40; drawDropDown(vg, "Effects", x, y, 280, 28); popy = y + 14; y += 45; // Form drawLabel(vg, "Login", x, y, 280, 20); y += 25; drawEditBox(vg, "Email", x, y, 280, 28); y += 35; drawEditBox(vg, "Password", x, y, 280, 28); y += 38; drawCheckBox(vg, "Remember me", x, y, 140, 28); drawButton(vg, ICON_LOGIN, "Sign in", x + 138, y, 140, 28, new Color(0, 96, 128, 255)); y += 45; // Slider drawLabel(vg, "Diameter", x, y, 280, 20); y += 25; drawEditBoxNum(vg, "123.00", "px", x + 180, y, 100, 28); drawSlider(vg, 0.4f, x, y, 170, 28); y += 55; drawButton(vg, ICON_TRASH, "Delete", x, y, 160, 28, new Color(128, 16, 8, 255)); drawButton(vg, null, "Cancel", x + 170, y, 110, 28, new Color(0, 0, 0, 0)); // Thumbnails box drawThumbnails(vg, 365, popy - 30, 160, 300, images, t); vg.Restore(); }