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 drawSpinner(NvgContext vg, float cx, float cy, float r, float t) { float a0 = 0.0f + t * 6; float a1 = (float)Math.PI + t * 6; float r0 = r; float r1 = r * 0.75f; float ax, ay, bx, by; Paint paint; vg.Save(); 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, new Color(0, 0, 0, 0), new Color(0, 0, 0, 128)); vg.FillPaint(paint); vg.Fill(); 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 virtual void Render(FrameEventArgs frameEventArgs) { FramebufferScene.Use(); GL.PushMatrix(); GL.ClearColor(Color.Black); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit); // RenderOriginAxes(); // Set up uniforms ShaderDefault.Uniforms.SetValue("lightPos", LightPosition); ShaderDefault.Uniforms.SetValue("cameraPos", Camera.Position); ShaderDefault.Uniforms.SetValue("v", Camera.GetTransformation()); ShaderDefault.Uniforms.SetValue("p", ProjectionMatrix); GL.ActiveTexture(TextureUnit.Texture1); GL.BindTexture(TextureTarget.Texture2D, TextureRandom.Id); foreach (var actor in Scene.Actors) { if (!actor.RenderOutsideFrustum && !Camera.FrustumContains(actor.BoundingBox)) { continue; } var e = new ActorEventArgs(actor); ActorPreRender?.Invoke(this, e); actor.Render(this, Camera); ActorPostRender?.Invoke(this, e); } GL.PopMatrix(); FramebufferScene.Release(); FramebufferInterface.Use(); GL.ClearColor(0, 0, 0, 0); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit); Nvg.BeginFrame(Window.Width, Window.Height, 1); Nvg.Save(); UserInterface.Render(this, Nvg, frameEventArgs); Nvg.Restore(); Nvg.EndFrame(); FramebufferInterface.Release(); ShaderScreen.Use(); DrawFullscreenQuad(FramebufferScene.Texture, FramebufferInterface.Texture); ShaderScreen.Release(); }
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 drawWindow(NvgContext vg, string title, float x, float y, float w, float h) { float cornerRadius = 3.0f; Paint shadowPaint; Paint headerPaint; vg.Save(); // ClearState(vg); // Window vg.BeginPath(); vg.RoundedRect(x, y, w, h, cornerRadius); vg.FillColor(new Color(28, 30, 34, 192)); // vg.FillColor(new Color(0,0,0,128)); vg.Fill(); // Drop shadow shadowPaint = vg.BoxGradient(x, y + 2, w, h, cornerRadius * 2, 10, 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(); // Header headerPaint = vg.LinearGradient(x, y, x, y + 15, new Color(255, 255, 255, 8), new Color(0, 0, 0, 16)); vg.BeginPath(); vg.RoundedRect(x + 1, y + 1, w - 2, 30, cornerRadius - 1); vg.FillPaint(headerPaint); vg.Fill(); vg.BeginPath(); vg.MoveTo(x + 0.5f, y + 0.5f + 30); vg.LineTo(x + 0.5f + w - 1, y + 0.5f + 30); vg.StrokeColor(new Color(0, 0, 0, 32)); vg.Stroke(); vg.FontSize(18.0f); vg.FontFace("sans-bold"); vg.TextAlign(Alignment.Center | Alignment.Middle); vg.FontBlur(2); vg.FillColor(new Color(0, 0, 0, 128)); vg.Text(x + w / 2, y + 16 + 1, title); vg.FontBlur(0); vg.FillColor(new Color(220, 220, 220, 160)); vg.Text(x + w / 2, y + 16, title); vg.Restore(); }
public static void drawSlider(NvgContext vg, float pos, float x, float y, float w, float h) { Paint bg, knob; float cy = y + (int)(h * 0.5f); float kr = (int)(h * 0.25f); vg.Save(); // ClearState(vg); // Slot bg = vg.BoxGradient(x, cy - 2 + 1, w, 4, 2, 2, new Color(0, 0, 0, 32), new Color(0, 0, 0, 128)); vg.BeginPath(); vg.RoundedRect(x, cy - 2, w, 4, 2); vg.FillPaint(bg); vg.Fill(); // Knob Shadow bg = vg.RadialGradient(x + (int)(pos * w), cy + 1, kr - 3, kr + 3, new Color(0, 0, 0, 64), new Color(0, 0, 0, 0)); vg.BeginPath(); vg.Rect(x + (int)(pos * w) - kr - 5, cy - kr - 5, kr * 2 + 5 + 5, kr * 2 + 5 + 5 + 3); vg.Circle(x + (int)(pos * w), cy, kr); vg.PathWinding(Solidity.Hole); vg.FillPaint(bg); vg.Fill(); // Knob knob = vg.LinearGradient(x, cy - kr, x, cy + kr, new Color(255, 255, 255, 16), new Color(0, 0, 0, 16)); vg.BeginPath(); vg.Circle(x + (int)(pos * w), cy, kr - 1); vg.FillColor(new Color(40, 43, 48, 255)); vg.Fill(); vg.FillPaint(knob); vg.Fill(); vg.BeginPath(); vg.Circle(x + (int)(pos * w), cy, kr - 0.5f); vg.StrokeColor(new Color(0, 0, 0, 92)); 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 void Render(Matrix4 model, Matrix4 view, Matrix4 projection) { _framebuffer.Use(); GL.PushMatrix(); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit); GL.Color3(Color.White); // Set up uniforms _uTint.Value = TintColor; _uLightPos.Value = LightPosition; _uMatModel.Value = model; _uMatView.Value = view; _uMatProjection.Value = projection; _uSamples.Value = _framebuffer.Samples; _uTexRandom.Value = 1; GL.ActiveTexture(TextureUnit.Texture1); GL.BindTexture(TextureTarget.Texture2D, _texRandom); // Engage shader, render, disengage _shaderModel.Use(_uTint, _uLightPos, _uMatModel, _uMatView, _uMatProjection, _uSamples, _uTexRandom); foreach (var chunk in Chunks) { chunk?.Draw(); } _shaderScreen.Release(); // Render the ocean GL.Color3(Color.MediumBlue); var waterLevel = _generator.GetWaterLevel(); GL.MatrixMode(MatrixMode.Projection); GL.LoadMatrix(ref projection); GL.MatrixMode(MatrixMode.Modelview); var mat = view * model; GL.LoadMatrix(ref mat); GL.Begin(PrimitiveType.Quads); GL.Normal3(Vector3.UnitY); GL.Vertex3(-1, waterLevel - 0.4, -1); GL.Vertex3(SideLength * 16 - 1, waterLevel - 0.4, -1); GL.Vertex3(SideLength * 16 - 1, waterLevel - 0.4, SideLength * 16 - 1); GL.Vertex3(-1, waterLevel - 0.4, SideLength * 16 - 1); GL.End(); GL.PopMatrix(); _framebuffer.Release(); _framebufferUi.Use(); GL.ClearColor(0, 0, 0, 0); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit); _nvg.BeginFrame(_window.Width, _window.Height, 1); _nvg.Save(); _nvg.FillColor(NanoVg.Rgba(255, 255, 255, 255)); _nvg.FontFace("sans"); _nvg.FontSize(18); _nvg.TextAlign(NvgAlign.Top | NvgAlign.Left); _perfGraphFps.RenderGraph(_nvg, 4, 4); _nvg.Restore(); _ui.Render(this, _nvg); _nvg.EndFrame(); _framebufferUi.Release(); _uWidth.Value = _window.Width; _uHeight.Value = _window.Height; _uTexColor.Value = 0; _uTexUi.Value = 1; _uSamples.Value = _framebuffer.Samples; _uSamplesUi.Value = _framebufferUi.Samples; _shaderScreen.Use(_uWidth, _uHeight, _uTexColor, _uTexUi, _uSamples, _uSamplesUi); DrawFullscreenQuad(_framebuffer.TextureId, _framebufferUi.TextureId); _shaderScreen.Release(); }
public static void drawParagraph(NvgContext vg, float x, float y, float width, float height, float mx, float my) { TextRow[] rows = new TextRow[3]; GlyphPosition[] glyphs = new GlyphPosition[100]; string text = "This is longer chunk of text.\n \n Would have used lorem ipsum but she was busy jumping over the lazy dog with the fox and all the men who came to the aid of the party."; StringSegment start; int nrows, i, nglyphs, j, lnum = 0; float lineh; float caretx, px; Bounds bounds = new Bounds(); float a; float gx = 0, gy = 0; int gutter = 0; for (i = 0; i < rows.Length; ++i) { rows[i] = new TextRow(); } vg.Save(); vg.FontSize(18.0f); vg.FontFace("sans"); vg.TextAlign(Alignment.Left | Alignment.Top); float ascender, descender; vg.TextMetrics(out ascender, out descender, out lineh); // The text break API can be used to fill a large buffer of rows, // or to iterate over the text just few lines (or just one) at a time. // The "next" variable of the last returned item tells where to continue. start = text; while (true) { nrows = vg.TextBreakLines(start, width, rows, out start); if (nrows <= 0) { break; } for (i = 0; i < nrows; i++) { TextRow row = rows[i]; var hit = mx > x && mx < (x + width) && my >= y && my < (y + lineh); vg.BeginPath(); vg.FillColor(new Color(255, 255, 255, hit ? 64 : 16)); vg.Rect(x, y, row.Width, lineh); vg.Fill(); vg.FillColor(new Color(255, 255, 255, 255)); vg.Text(x, y, row.Str); if (hit) { caretx = (mx < x + row.Width / 2) ? x : x + row.Width; px = x; nglyphs = vg.TextGlyphPositions(x, y, row.Str, glyphs); for (j = 0; j < nglyphs; j++) { float x0 = glyphs[j].X; float x1 = (j + 1 < nglyphs) ? glyphs[j + 1].X : x + row.Width; float gx2 = x0 * 0.3f + x1 * 0.7f; if (mx >= px && mx < gx2) { caretx = glyphs[j].X; } px = gx2; } vg.BeginPath(); vg.FillColor(new Color(255, 192, 0, 255)); vg.Rect(caretx, y, 1, lineh); vg.Fill(); gutter = lnum + 1; gx = x - 10; gy = y + lineh / 2; } lnum++; y += lineh; } } if (gutter > 0) { string txt = gutter.ToString(); vg.FontSize(13.0f); vg.TextAlign(Alignment.Right | Alignment.Middle); vg.TextBounds(gx, gy, txt, ref bounds); vg.BeginPath(); vg.FillColor(new Color(255, 192, 0, 255)); vg.RoundedRect((int)bounds.b1 - 4, (int)bounds.b2 - 2, (int)(bounds.b3 - bounds.b1) + 8, (int)(bounds.b4 - bounds.b2) + 4, ((int)(bounds.b4 - bounds.b2) + 4) / 2 - 1); vg.Fill(); vg.FillColor(new Color(32, 32, 32, 255)); vg.Text(gx, gy, txt); } y += 20.0f; vg.FontSize(13.0f); vg.TextAlign(Alignment.Left | Alignment.Top); vg.TextLineHeight(1.2f); vg.TextBoxBounds(x, y, 150, "Hover your mouse over the text to see calculated caret position.", ref bounds); // Fade the tooltip out when close to it. gx = (float)Math.Abs((mx - (bounds.b1 + bounds.b3) * 0.5f) / (bounds.b1 - bounds.b3)); gy = (float)Math.Abs((my - (bounds.b2 + bounds.b4) * 0.5f) / (bounds.b2 - bounds.b4)); a = maxf(gx, gy) - 0.5f; a = clampf(a, 0, 1); vg.GlobalAlpha(a); vg.BeginPath(); vg.FillColor(new Color(220, 220, 220, 255)); vg.RoundedRect(bounds.b1 - 2, bounds.b2 - 2, (int)(bounds.b3 - bounds.b1) + 4, (int)(bounds.b4 - bounds.b2) + 4, 3); px = (int)((bounds.b3 + bounds.b1) / 2); vg.MoveTo(px, bounds.b2 - 10); vg.LineTo(px + 7, bounds.b2 + 1); vg.LineTo(px - 7, bounds.b2 + 1); vg.Fill(); vg.FillColor(new Color(0, 0, 0, 220)); vg.TextBox(x, y, 150, "Hover your mouse over the text to see calculated caret position."); 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 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(); }
public void Render(NvgContext vg, int x, int y, float w, float h, float gameTime) { vg.Save(); vg.Translate(x, y); vg.bndSplitterWidgets(0, 0, w, h); x = 10; y = 10; vg.bndToolButton(x, y, 120, Blendish.BND_WIDGET_HEIGHT, BNDcornerFlags.BND_CORNER_NONE, BNDwidgetState.BND_DEFAULT, BNDicon.BND_ICON_GHOST, "Default"); y += 25; vg.bndToolButton(x, y, 120, Blendish.BND_WIDGET_HEIGHT, BNDcornerFlags.BND_CORNER_NONE, BNDwidgetState.BND_HOVER, BNDicon.BND_ICON_GHOST, "Hovered"); y += 25; vg.bndToolButton(x, y, 120, Blendish.BND_WIDGET_HEIGHT, BNDcornerFlags.BND_CORNER_NONE, BNDwidgetState.BND_ACTIVE, BNDicon.BND_ICON_GHOST, "Active"); y += 40; vg.bndRadioButton(x, y, 80, Blendish.BND_WIDGET_HEIGHT, BNDcornerFlags.BND_CORNER_NONE, BNDwidgetState.BND_DEFAULT, null, "Default"); y += 25; vg.bndRadioButton(x, y, 80, Blendish.BND_WIDGET_HEIGHT, BNDcornerFlags.BND_CORNER_NONE, BNDwidgetState.BND_HOVER, null, "Hovered"); y += 25; vg.bndRadioButton(x, y, 80, Blendish.BND_WIDGET_HEIGHT, BNDcornerFlags.BND_CORNER_NONE, BNDwidgetState.BND_ACTIVE, null, "Active"); y += 25; vg.bndLabel(x, y, 120, Blendish.BND_WIDGET_HEIGHT, null, "Label:"); y += Blendish.BND_WIDGET_HEIGHT; vg.bndChoiceButton(x, y, 80, Blendish.BND_WIDGET_HEIGHT, BNDcornerFlags.BND_CORNER_NONE, BNDwidgetState.BND_DEFAULT, null, "Default"); y += 25; vg.bndChoiceButton(x, y, 80, Blendish.BND_WIDGET_HEIGHT, BNDcornerFlags.BND_CORNER_NONE, BNDwidgetState.BND_HOVER, null, "Hovered"); y += 25; vg.bndChoiceButton(x, y, 80, Blendish.BND_WIDGET_HEIGHT, BNDcornerFlags.BND_CORNER_NONE, BNDwidgetState.BND_ACTIVE, null, "Active"); y += 25; int ry = y; int rx = x; y = 10; x += 130; vg.bndOptionButton(x, y, 120, Blendish.BND_WIDGET_HEIGHT, BNDwidgetState.BND_DEFAULT, "Default"); y += 25; vg.bndOptionButton(x, y, 120, Blendish.BND_WIDGET_HEIGHT, BNDwidgetState.BND_HOVER, "Hovered"); y += 25; vg.bndOptionButton(x, y, 120, Blendish.BND_WIDGET_HEIGHT, BNDwidgetState.BND_ACTIVE, "Active"); y += 40; vg.bndNumberField(x, y, 120, Blendish.BND_WIDGET_HEIGHT, BNDcornerFlags.BND_CORNER_DOWN, BNDwidgetState.BND_DEFAULT, "Top", "100"); y += Blendish.BND_WIDGET_HEIGHT - 2; vg.bndNumberField(x, y, 120, Blendish.BND_WIDGET_HEIGHT, BNDcornerFlags.BND_CORNER_ALL, BNDwidgetState.BND_DEFAULT, "Center", "100"); y += Blendish.BND_WIDGET_HEIGHT - 2; vg.bndNumberField(x, y, 120, Blendish.BND_WIDGET_HEIGHT, BNDcornerFlags.BND_CORNER_TOP, BNDwidgetState.BND_DEFAULT, "Bottom", "100"); int mx = x - 30; int my = y - 12; int mw = 120; vg.bndMenuBackground(mx, my, mw, 120, BNDcornerFlags.BND_CORNER_TOP); vg.bndMenuLabel(mx, my, mw, Blendish.BND_WIDGET_HEIGHT, null, "Menu Title"); my += Blendish.BND_WIDGET_HEIGHT - 2; vg.bndMenuItem(mx, my, mw, Blendish.BND_WIDGET_HEIGHT, BNDwidgetState.BND_DEFAULT, BNDicon.BND_ICON_FILE_FOLDER, "Default"); my += Blendish.BND_WIDGET_HEIGHT - 2; vg.bndMenuItem(mx, my, mw, Blendish.BND_WIDGET_HEIGHT, BNDwidgetState.BND_HOVER, BNDicon.BND_ICON_FILE_BLANK, "Hovered"); my += Blendish.BND_WIDGET_HEIGHT - 2; vg.bndMenuItem(mx, my, mw, Blendish.BND_WIDGET_HEIGHT, BNDwidgetState.BND_ACTIVE, BNDicon.BND_ICON_FILE_BLEND, "Active"); y = 10; x += 130; int ox = x; vg.bndNumberField(x, y, 120, Blendish.BND_WIDGET_HEIGHT, BNDcornerFlags.BND_CORNER_NONE, BNDwidgetState.BND_DEFAULT, "Default", "100"); y += 25; vg.bndNumberField(x, y, 120, Blendish.BND_WIDGET_HEIGHT, BNDcornerFlags.BND_CORNER_NONE, BNDwidgetState.BND_HOVER, "Hovered", "100"); y += 25; vg.bndNumberField(x, y, 120, Blendish.BND_WIDGET_HEIGHT, BNDcornerFlags.BND_CORNER_NONE, BNDwidgetState.BND_ACTIVE, "Active", "100"); y += 40; vg.bndRadioButton(x, y, 60, Blendish.BND_WIDGET_HEIGHT, BNDcornerFlags.BND_CORNER_RIGHT, BNDwidgetState.BND_DEFAULT, null, "One"); x += 60 - 1; vg.bndRadioButton(x, y, 60, Blendish.BND_WIDGET_HEIGHT, BNDcornerFlags.BND_CORNER_ALL, BNDwidgetState.BND_DEFAULT, null, "Two"); x += 60 - 1; vg.bndRadioButton(x, y, 60, Blendish.BND_WIDGET_HEIGHT, BNDcornerFlags.BND_CORNER_ALL, BNDwidgetState.BND_DEFAULT, null, "Three"); x += 60 - 1; vg.bndRadioButton(x, y, 60, Blendish.BND_WIDGET_HEIGHT, BNDcornerFlags.BND_CORNER_LEFT, BNDwidgetState.BND_ACTIVE, null, "Butts"); x = ox; y += 40; float progress_value = fmodf(gameTime / 10.0f, 1.0f); string progress_label; progress_label = string.Format("{0:0.00}", progress_value * 100 + 0.5f); vg.bndSlider(x, y, 240, Blendish.BND_WIDGET_HEIGHT, BNDcornerFlags.BND_CORNER_NONE, BNDwidgetState.BND_DEFAULT, progress_value, "Default", progress_label); y += 25; vg.bndSlider(x, y, 240, Blendish.BND_WIDGET_HEIGHT, BNDcornerFlags.BND_CORNER_NONE, BNDwidgetState.BND_HOVER, progress_value, "Hovered", progress_label); y += 25; vg.bndSlider(x, y, 240, Blendish.BND_WIDGET_HEIGHT, BNDcornerFlags.BND_CORNER_NONE, BNDwidgetState.BND_ACTIVE, progress_value, "Active", progress_label); int rw = x + 240 - rx; float s_offset = (float)Math.Sin(gameTime / 2.0f) * 0.5f + 0.5f; float s_size = (float)Math.Cos(gameTime / 3.11f) * 0.5f + 0.5f; vg.bndScrollBar(rx, ry, rw, Blendish.BND_SCROLLBAR_HEIGHT, BNDwidgetState.BND_DEFAULT, s_offset, s_size); ry += 20; vg.bndScrollBar(rx, ry, rw, Blendish.BND_SCROLLBAR_HEIGHT, BNDwidgetState.BND_HOVER, s_offset, s_size); ry += 20; vg.bndScrollBar(rx, ry, rw, Blendish.BND_SCROLLBAR_HEIGHT, BNDwidgetState.BND_ACTIVE, s_offset, s_size); string edit_text = "The quick brown fox"; int t = (int)(gameTime * 2); int idx1 = (t / edit_text.Length) % edit_text.Length; int idx2 = idx1 + (t % (edit_text.Length - idx1)); ry += 25; vg.bndTextField(rx, ry, 240, Blendish.BND_WIDGET_HEIGHT, BNDcornerFlags.BND_CORNER_NONE, BNDwidgetState.BND_DEFAULT, null, edit_text, idx1, idx2); ry += 25; vg.bndTextField(rx, ry, 240, Blendish.BND_WIDGET_HEIGHT, BNDcornerFlags.BND_CORNER_NONE, BNDwidgetState.BND_HOVER, null, edit_text, idx1, idx2); ry += 25; vg.bndTextField(rx, ry, 240, Blendish.BND_WIDGET_HEIGHT, BNDcornerFlags.BND_CORNER_NONE, BNDwidgetState.BND_ACTIVE, null, edit_text, idx1, idx2); draw_noodles(vg, 20, ry + 50); rx += rw + 20; ry = 10; vg.bndScrollBar(rx, ry, Blendish.BND_SCROLLBAR_WIDTH, 240, BNDwidgetState.BND_DEFAULT, s_offset, s_size); rx += 20; vg.bndScrollBar(rx, ry, Blendish.BND_SCROLLBAR_WIDTH, 240, BNDwidgetState.BND_HOVER, s_offset, s_size); rx += 20; vg.bndScrollBar(rx, ry, Blendish.BND_SCROLLBAR_WIDTH, 240, BNDwidgetState.BND_ACTIVE, s_offset, s_size); x = ox; y += 40; vg.bndToolButton(x, y, Blendish.BND_TOOL_WIDTH, Blendish.BND_WIDGET_HEIGHT, BNDcornerFlags.BND_CORNER_RIGHT, BNDwidgetState.BND_DEFAULT, BNDicon.BND_ICON_REC, null); x += Blendish.BND_TOOL_WIDTH - 1; vg.bndToolButton(x, y, Blendish.BND_TOOL_WIDTH, Blendish.BND_WIDGET_HEIGHT, BNDcornerFlags.BND_CORNER_ALL, BNDwidgetState.BND_DEFAULT, BNDicon.BND_ICON_PLAY, null); x += Blendish.BND_TOOL_WIDTH - 1; vg.bndToolButton(x, y, Blendish.BND_TOOL_WIDTH, Blendish.BND_WIDGET_HEIGHT, BNDcornerFlags.BND_CORNER_ALL, BNDwidgetState.BND_DEFAULT, BNDicon.BND_ICON_FF, null); x += Blendish.BND_TOOL_WIDTH - 1; vg.bndToolButton(x, y, Blendish.BND_TOOL_WIDTH, Blendish.BND_WIDGET_HEIGHT, BNDcornerFlags.BND_CORNER_ALL, BNDwidgetState.BND_DEFAULT, BNDicon.BND_ICON_REW, null); x += Blendish.BND_TOOL_WIDTH - 1; vg.bndToolButton(x, y, Blendish.BND_TOOL_WIDTH, Blendish.BND_WIDGET_HEIGHT, BNDcornerFlags.BND_CORNER_ALL, BNDwidgetState.BND_DEFAULT, BNDicon.BND_ICON_PAUSE, null); x += Blendish.BND_TOOL_WIDTH - 1; vg.bndToolButton(x, y, Blendish.BND_TOOL_WIDTH, Blendish.BND_WIDGET_HEIGHT, BNDcornerFlags.BND_CORNER_LEFT, BNDwidgetState.BND_DEFAULT, BNDicon.BND_ICON_PREV_KEYFRAME, null); x += Blendish.BND_TOOL_WIDTH - 1; x += 5; vg.bndRadioButton(x, y, Blendish.BND_TOOL_WIDTH, Blendish.BND_WIDGET_HEIGHT, BNDcornerFlags.BND_CORNER_RIGHT, BNDwidgetState.BND_DEFAULT, BNDicon.BND_ICON_MOD_CLOTH, null); x += Blendish.BND_TOOL_WIDTH - 1; vg.bndRadioButton(x, y, Blendish.BND_TOOL_WIDTH, Blendish.BND_WIDGET_HEIGHT, BNDcornerFlags.BND_CORNER_ALL, BNDwidgetState.BND_DEFAULT, BNDicon.BND_ICON_MOD_EXPLODE, null); x += Blendish.BND_TOOL_WIDTH - 1; vg.bndRadioButton(x, y, Blendish.BND_TOOL_WIDTH, Blendish.BND_WIDGET_HEIGHT, BNDcornerFlags.BND_CORNER_ALL, BNDwidgetState.BND_DEFAULT, BNDicon.BND_ICON_MOD_FLUIDSIM, null); x += Blendish.BND_TOOL_WIDTH - 1; vg.bndRadioButton(x, y, Blendish.BND_TOOL_WIDTH, Blendish.BND_WIDGET_HEIGHT, BNDcornerFlags.BND_CORNER_ALL, BNDwidgetState.BND_DEFAULT, BNDicon.BND_ICON_MOD_MULTIRES, null); x += Blendish.BND_TOOL_WIDTH - 1; vg.bndRadioButton(x, y, Blendish.BND_TOOL_WIDTH, Blendish.BND_WIDGET_HEIGHT, BNDcornerFlags.BND_CORNER_ALL, BNDwidgetState.BND_ACTIVE, BNDicon.BND_ICON_MOD_SMOKE, null); x += Blendish.BND_TOOL_WIDTH - 1; vg.bndRadioButton(x, y, Blendish.BND_TOOL_WIDTH, Blendish.BND_WIDGET_HEIGHT, BNDcornerFlags.BND_CORNER_LEFT, BNDwidgetState.BND_DEFAULT, BNDicon.BND_ICON_MOD_SOLIDIFY, null); vg.Restore(); }