internal static void Initialize() { NVG.InitOpenGL(); Engine.NVGCtx = NVG.CreateGL3(NVG.NVG_DEBUG | NVG.NVG_ANTIALIAS); string[] Fonts = ContentManager.GetAllFonts(); List <string> LoadedFonts = new List <string>(); foreach (var Font in Fonts) { string FontName = Files.GetFileName(Font); NVG.CreateFont(Engine.NVGCtx, FontName, Font); LoadedFonts.Add(FontName); } // Every font is the fallback for every other font. TODO: Is this even a good idea? for (int i = 0; i < LoadedFonts.Count; i++) { for (int j = 0; j < LoadedFonts.Count; j++) { if (i == j) { continue; } NVG.AddFallbackFont(Engine.NVGCtx, LoadedFonts[i], LoadedFonts[j]); } } NVG.ImagePattern(Engine.NVGCtx, 0, 0, 100, 100, 0, 0, 0); }
static unsafe void DrawThumbnails(NanoVGContext vg, float x, float y, float w, float h, int[] images, int nimages, float t) { float cornerRadius = 3.0f; NVGPaint shadowPaint, imgPaint, fadePaint; float ix, iy, iw, ih; float thumb = 60.0f; float arry = 30.5f; int imgw, imgh; float stackh = (nimages / 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; NVG.Save(vg); // nvgClearState(vg); // Drop shadow shadowPaint = NVG.BoxGradient(vg, x, y + 4, w, h, cornerRadius * 2, 20, NVG.RGBA(0, 0, 0, 128), NVG.RGBA(0, 0, 0, 0)); NVG.BeginPath(vg); NVG.Rect(vg, x - 10, y - 10, w + 20, h + 30); NVG.RoundedRect(vg, x, y, w, h, cornerRadius); NVG.PathWinding(vg, NVGSolidity.NVG_HOLE); NVG.FillPaint(vg, shadowPaint); NVG.Fill(vg); // Window NVG.BeginPath(vg); NVG.RoundedRect(vg, x, y, w, h, cornerRadius); NVG.MoveTo(vg, x - 10, y + arry); NVG.LineTo(vg, x + 1, y + arry - 11); NVG.LineTo(vg, x + 1, y + arry + 11); NVG.FillColor(vg, NVG.RGBA(200, 200, 200, 255)); NVG.Fill(vg); NVG.Save(vg); NVG.Scissor(vg, x, y, w, h); NVG.Translate(vg, 0, -(stackh - h) * u); dv = 1.0f / (float)(nimages - 1); for (i = 0; i < nimages; i++) { float tx, ty, v, a; tx = x + 10; ty = y + 10; tx += (i % 2) * (thumb + 10); ty += (i / 2) * (thumb + 10); NVG.ImageSize(vg, images[i], &imgw, &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 = Math.Clamp((u2 - v) / dv, 0, 1); if (a < 1.0f) { DrawSpinner(vg, tx + thumb / 2, ty + thumb / 2, thumb * 0.25f, t); } imgPaint = NVG.ImagePattern(vg, tx + ix, ty + iy, iw, ih, 0.0f / 180.0f * NVG_PI, images[i], a); NVG.BeginPath(vg); NVG.RoundedRect(vg, tx, ty, thumb, thumb, 5); NVG.FillPaint(vg, imgPaint); NVG.Fill(vg); shadowPaint = NVG.BoxGradient(vg, tx - 1, ty, thumb + 2, thumb + 2, 5, 3, NVG.RGBA(0, 0, 0, 128), NVG.RGBA(0, 0, 0, 0)); NVG.BeginPath(vg); NVG.Rect(vg, tx - 5, ty - 5, thumb + 10, thumb + 10); NVG.RoundedRect(vg, tx, ty, thumb, thumb, 6); NVG.PathWinding(vg, NVGSolidity.NVG_HOLE); NVG.FillPaint(vg, shadowPaint); NVG.Fill(vg); NVG.BeginPath(vg); NVG.RoundedRect(vg, tx + 0.5f, ty + 0.5f, thumb - 1, thumb - 1, 4 - 0.5f); NVG.StrokeWidth(vg, 1.0f); NVG.StrokeColor(vg, NVG.RGBA(255, 255, 255, 192)); NVG.Stroke(vg); } NVG.Restore(vg); // Hide fades fadePaint = NVG.LinearGradient(vg, x, y, x, y + 6, NVG.RGBA(200, 200, 200, 255), NVG.RGBA(200, 200, 200, 0)); NVG.BeginPath(vg); NVG.Rect(vg, x + 4, y, w - 8, 6); NVG.FillPaint(vg, fadePaint); NVG.Fill(vg); fadePaint = NVG.LinearGradient(vg, x, y + h, x, y + h - 6, NVG.RGBA(200, 200, 200, 255), NVG.RGBA(200, 200, 200, 0)); NVG.BeginPath(vg); NVG.Rect(vg, x + 4, y + h - 6, w - 8, 6); NVG.FillPaint(vg, fadePaint); NVG.Fill(vg); // Scroll bar shadowPaint = NVG.BoxGradient(vg, x + w - 12 + 1, y + 4 + 1, 8, h - 8, 3, 4, NVG.RGBA(0, 0, 0, 32), NVG.RGBA(0, 0, 0, 92)); NVG.BeginPath(vg); NVG.RoundedRect(vg, x + w - 12, y + 4, 8, h - 8, 3); NVG.FillPaint(vg, shadowPaint); // NVG.FillColor(vg, NVG.RGBA(255,0,0,128)); NVG.Fill(vg); scrollh = (h / stackh) * (h - 8); shadowPaint = NVG.BoxGradient(vg, x + w - 12 - 1, y + 4 + (h - 8 - scrollh) * u - 1, 8, scrollh, 3, 4, NVG.RGBA(220, 220, 220, 255), NVG.RGBA(128, 128, 128, 255)); NVG.BeginPath(vg); NVG.RoundedRect(vg, x + w - 12 + 1, y + 4 + 1 + (h - 8 - scrollh) * u, 8 - 2, scrollh - 2, 2); NVG.FillPaint(vg, shadowPaint); // NVG.FillColor(vg, NVG.RGBA(0,0,0,128)); NVG.Fill(vg); NVG.Restore(vg); }
public static NVGpaint ImagePattern(int OriginX, int OriginY, int Width, int Height, float Angle, int Image, float Alpha = 1.0f) { return(NVG.ImagePattern(Engine.NVGCtx, OriginX, OriginY, Width, Height, Angle, Image, Alpha)); }