public override void Draw(NVGcontext ctx) { base.Draw(ctx); if (0 > m_FontId) { return; } int prefFontSize = GetPreferredFontSize(); NanoVG.nvgFontFace(ctx, m_FontId); NanoVG.nvgFontSize(ctx, prefFontSize); NanoVG.nvgFillColor(ctx, this.color); int fixedWidth = (int)this.fixedSize.X; Vector2 pos = this.localPosition; if (0 < fixedWidth) { NanoVG.nvgTextAlign(ctx, (int)(NVGalign.NVG_ALIGN_LEFT | NVGalign.NVG_ALIGN_TOP)); NanoVG.nvgTextBox(ctx, pos.X, pos.Y, fixedWidth, caption); } else { NanoVG.nvgTextAlign(ctx, (int)(NVGalign.NVG_ALIGN_LEFT | NVGalign.NVG_ALIGN_MIDDLE)); NanoVG.nvgText(ctx, pos.X, pos.Y + this.size.Y * 0.5f, caption); } // DEBUG: BOUNDS //NanoVG.nvgStrokeWidth (ctx, 1.0f); //NanoVG.nvgBeginPath (ctx); //NanoVG.nvgRect (ctx, pos.X, pos.Y, this.size.X, this.size.Y); //NanoVG.nvgStrokeColor (ctx, this.color); //NanoVG.nvgStroke(ctx); }
public override Vector2 GetPreferredSize(NVGcontext ctx) { if (string.IsNullOrEmpty(caption)) { return(Vector2.Zero); } Vector2 ret = Vector2.Zero; int prefFontSize = GetPreferredFontSize(); NanoVG.nvgFontFace(ctx, font); NanoVG.nvgFontSize(ctx, prefFontSize); int fixedWidth = (int)this.fixedSize.X; if (0 < fixedWidth) { Vector2 pos = this.localPosition; NanoVG.nvgTextAlign(ctx, (int)(NVGalign.NVG_ALIGN_LEFT | NVGalign.NVG_ALIGN_TOP)); NanoVG.nvgTextBoxBounds(ctx, pos.X, pos.Y, fixedWidth, caption, m_Bounds); ret.X = fixedWidth; ret.Y = (m_Bounds[3] - m_Bounds[1]); } else { NanoVG.nvgTextAlign(ctx, (int)(NVGalign.NVG_ALIGN_LEFT | NVGalign.NVG_ALIGN_MIDDLE)); ret.X = NanoVG.nvgTextBounds(ctx, 0, 0, caption, m_Bounds); ret.Y = prefFontSize; } return(ret); }
public static void Load(NVGcontext ctx, string fontName, string fileName) { string filePath = RESOURCES_PATH + fileName; int fontHandle = NanoVG.nvgCreateFont(ctx, fontName, filePath); s_FontMap[fontName] = fontHandle; }
public override Vector2 GetPreferredSize(NVGcontext ctx) { Vector2 ret = base.GetPreferredSize(ctx); ret.X += 15f; return(ret); }
public override void Draw(NVGcontext ctx) { if (!this.enabled && this.pushed) { this.pushed = false; } if (m_Popup) { m_Popup.isVisible = this.pushed; } base.Draw(ctx); if (0 != this.chevronIcon) { Theme style = this.theme; byte[] icon = Fonts.GetIconUTF8(this.chevronIcon); NVGcolor currTextColor = GetCurrTextColor(); int currFontSize = (0 <= this.fontSize) ? this.fontSize : style.buttonFontSize; int fontFace = Fonts.Get(style.fontIcons); NanoVG.nvgFontSize(ctx, currFontSize * 1.5f); NanoVG.nvgFontFace(ctx, fontFace); NanoVG.nvgFillColor(ctx, currTextColor); NanoVG.nvgTextAlign(ctx, (int)(NVGalign.NVG_ALIGN_LEFT | NVGalign.NVG_ALIGN_MIDDLE)); float iw = NanoVG.nvgTextBounds(ctx, 0f, 0f, icon, null); Vector2 iconPos = this.localPosition; iconPos.X += this.size.X - iw - 8; iconPos.Y += this.size.Y * 0.5f - 1; NanoVG.nvgText(ctx, iconPos.X, iconPos.Y, icon); } }
public virtual Vector2 GetPreferredSize(NVGcontext ctx) { if (this.layout) { return(this.layout.GetPreferredSize(ctx, this)); } return(this.size); }
public override void Draw(NVGcontext ctx) { if ((X == X1 && Y == Y1) || Radius == 0) { return; } NanoVG.nvgArcTo(ctx, X, Y, X1, Y1, Radius); }
public override void Draw(NVGcontext ctx) { if (RadiusX == 0 || RadiusY == 0) { return; } NanoVG.nvgEllipse(ctx, X, Y, RadiusX, RadiusY); }
public override void Draw(NVGcontext ctx) { if (Width == 0 || Height == 0) { return; } NanoVG.nvgRoundedRect(ctx, X, Y, Width, Height, Radius); }
public Vector2 GetTargetSize(NVGcontext ctx, Vector2 preferredSize) { Vector2 fixedSize = this.fixedSize; Vector2 targetSize; targetSize.X = 0f < fixedSize.X? fixedSize.X : preferredSize.X; targetSize.Y = 0f < fixedSize.Y? fixedSize.Y : preferredSize.Y; return(targetSize); }
public override void Draw(NVGcontext ctx) { if (Width == 0 || Height == 0) { return; } NanoVG.nvgBeginPath(ctx); NanoVG.nvgRect(ctx, X, Y, Width, Height); NanoVG.nvgStroke(ctx); }
public override void Draw(NVGcontext ctx) { if (A0 == A1 || Radius == 0) { return; } NanoVG.nvgBeginPath(ctx); NanoVG.nvgArc(ctx, X, Y, Radius, A0, A1, Dir); NanoVG.nvgStroke(ctx); }
public override void Draw(NVGcontext ctx) { if (Radius == 0) { return; } NanoVG.nvgBeginPath(ctx); NanoVG.nvgCircle(ctx, X, Y, Radius); NanoVG.nvgStroke(ctx); }
public void Render(NVGcontext nvg) { lock (_commands) { NanoVG.nvgSave(nvg); foreach (var simBody in _commands) { simBody.Execute(nvg); } NanoVG.nvgRestore(nvg); } }
public override void Draw(NVGcontext ctx) { if (X == X1 && Y == Y1) { return; } NanoVG.nvgBeginPath(ctx); NanoVG.nvgMoveTo(ctx, X, Y); NanoVG.nvgLineTo(ctx, X1, Y1); NanoVG.nvgStroke(ctx); }
public void Execute(NVGcontext ctx) { NanoVG.nvgBeginPath(ctx); Draw(ctx); if (Fill) { NanoVG.nvgFill(ctx); } else { NanoVG.nvgStroke(ctx); } }
public override void Draw(NVGcontext ctx) { base.Draw(ctx); Theme style = this.theme; Vector2 pos = this.localPosition; Vector2 size = this.size; if (!string.IsNullOrEmpty(this.caption)) { int currFontSize = GetPreferredFontSize(); if (0 < currFontSize) { int currFontFace = Fonts.Get(this.theme.fontNormal); NVGcolor currTextColor = this.enabled ? style.textColor : style.disabledTextColor; NanoVG.nvgFontSize(ctx, currFontSize); NanoVG.nvgFontFace(ctx, currFontFace); NanoVG.nvgFillColor(ctx, currTextColor); NanoVG.nvgTextAlign(ctx, (int)(NVGalign.NVG_ALIGN_LEFT | NVGalign.NVG_ALIGN_MIDDLE)); NanoVG.nvgText(ctx, pos.X + size.Y * 1.2f + 5, pos.Y + this.size.Y * 0.5f, this.caption); } } Color4f col = Color4f.Black; Color4f icol = this.pushed ? col.WithAlpha(100) : col.WithAlpha(32); Color4f ocol = col.WithAlpha(180); NVGpaint bg = NanoVG.nvgBoxGradient(ctx, pos.X + 1.5f, pos.Y + 1.5f , size.X - 2f, size.Y - 2f, 3f, 3f , icol.ToNVGColor() , ocol.ToNVGColor()); NanoVG.nvgBeginPath(ctx); NanoVG.nvgRoundedRect(ctx, pos.X + 1f, pos.Y + 1f, size.Y - 2f, size.Y - 2f, 3f); NanoVG.nvgFillPaint(ctx, bg); NanoVG.nvgFill(ctx); if (this.check) { int fontIcons = Fonts.Get(style.fontIcons); NVGcolor iconColor = this.enabled ? style.iconColor : style.disabledTextColor; NanoVG.nvgFontSize(ctx, 1.8f * size.Y); NanoVG.nvgFontFace(ctx, fontIcons); NanoVG.nvgFillColor(ctx, iconColor); NanoVG.nvgTextAlign(ctx, (int)(NVGalign.NVG_ALIGN_CENTER | NVGalign.NVG_ALIGN_MIDDLE)); byte[] icon = Fonts.GetIconUTF8((int)Font.Entypo.ICON_CHECK); NanoVG.nvgText(ctx, pos.X + size.Y * 0.5f + 1f, pos.Y + size.Y * 0.5f, icon); } }
public override void PerformLayout(NVGcontext ctx) { if (this.layout || 1 != this.childCount) { base.PerformLayout(ctx); } else { Widget child = GetChild(0); child.localPosition = Vector2.Zero; child.size = this.size; child.PerformLayout(ctx); } }
public override void PerformLayout(NVGcontext ctx) { base.PerformLayout(ctx); if (null == m_Popup || null == m_ParentWindow) { return; } Vector2 anchor; anchor.X = m_ParentWindow.width + 15f; anchor.Y = this.GetScreenPosition().Y - m_ParentWindow.localPosition.Y + this.size.Y * 0.5f; m_Popup.anchorPos = anchor; }
public virtual void PerformLayout(NVGcontext ctx) { if (this.layout) { this.layout.PerformLayout(ctx, this); return; } int childCount = this.childCount; for (int i = 0; childCount > i; ++i) { Widget child = this.GetChild(i); child.ApplyTargetSize(ctx); child.PerformLayout(ctx); } }
public override void Draw(NVGcontext ctx) { RefreshRelativePlacement(); if (!this.isVisible) { return; } Vector2 pos = this.localPosition; Vector2 size = this.size; Theme style = this.theme; int ds = style.windowDropShadowSize; int cr = style.windowCornerRadius; int ds2 = 2 * ds; int cr2 = 2 * cr; int ah = this.anchorHeight; // draw drop shadow. NVGpaint shadowPaint = NanoVG.nvgBoxGradient(ctx, pos.X, pos.Y, size.X, size.Y, cr2, ds2 , style.dropShadowColor , style.transparentColor); NanoVG.nvgBeginPath(ctx); NanoVG.nvgRect(ctx, pos.X - ds, pos.Y - ds, size.X + ds2, size.Y + ds2); NanoVG.nvgRoundedRect(ctx, pos.X, pos.Y, size.X, size.Y, cr); NanoVG.nvgPathWinding(ctx, (int)NVGsolidity.NVG_HOLE); NanoVG.nvgFillPaint(ctx, shadowPaint); NanoVG.nvgFill(ctx); // draw window. NanoVG.nvgBeginPath(ctx); NanoVG.nvgRoundedRect(ctx, pos.X, pos.Y, size.X, size.Y, cr); // draw anchor triangle. NanoVG.nvgMoveTo(ctx, pos.X - 15, pos.Y + ah); NanoVG.nvgLineTo(ctx, pos.X + 1, pos.Y + ah - 15); NanoVG.nvgLineTo(ctx, pos.X + 1, pos.Y + ah + 15); NanoVG.nvgFillColor(ctx, style.windowPopupColor); NanoVG.nvgFill(ctx); // draw contents. DrawChildren(ctx); }
public override Vector2 GetPreferredSize(NVGcontext ctx) { if (!Vector2.Zero.Equals(this.fixedSize)) { return(this.fixedSize); } int currFontSize = GetPreferredFontSize(); int currFontFace = Fonts.Get(this.theme.fontNormal); NanoVG.nvgFontSize(ctx, currFontSize); NanoVG.nvgFontFace(ctx, currFontFace); float tw = NanoVG.nvgTextBounds(ctx, 0f, 0f, this.caption, null); Vector2 ret; ret.X = tw + 1.7f * currFontSize; ret.Y = 1.3f * currFontSize; return(ret); }
protected void DrawChildren(NVGcontext ctx) { int childCount = m_Children.Count; if (0 == childCount) { return; } Vector2 pos = this.localPosition; NanoVG.nvgTranslate(ctx, pos.X, pos.Y); for (int i = 0; childCount > i; ++i) { Widget child = m_Children[i]; if (child.isVisible) { child.Draw(ctx); } } NanoVG.nvgTranslate(ctx, -pos.X, -pos.Y); }
public override Vector2 GetPreferredSize(NVGcontext ctx) { Vector2 ret; int prefFontSize = GetPreferredFontSize(); NanoVG.nvgFontSize(ctx, prefFontSize); NanoVG.nvgFontFace(ctx, this.theme.fontBold); float tw = NanoVG.nvgTextBounds(ctx, 0f, 0f, this.caption, null); float iw = 0f; float ih = prefFontSize; int btnIcon = this.icon; if (0 < btnIcon) { if (NanoVG.nvgIsFontIcon(btnIcon)) { byte[] icon = Fonts.GetIconUTF8(btnIcon); ih *= 1.5f; NanoVG.nvgFontFace(ctx, this.theme.fontIcons); NanoVG.nvgFontSize(ctx, ih); iw = NanoVG.nvgTextBounds(ctx, 0f, 0f, icon, null) + this.size.Y * 0.15f; } else { int w, h; w = h = 1; ih *= 0.9f; NanoVG.nvgImageSize(ctx, btnIcon, ref w, ref h); iw = w * ih / h; } } ret.X = (int)(tw + iw) + 20; ret.Y = prefFontSize + 10; return(ret); }
public void ApplyTargetSize(NVGcontext ctx) { this.size = GetTargetSize(ctx); }
public static void RenderGraph(NVGcontext vg, float x, float y) { int i; float avg, w, h; string str; avg = GetGraphAverage(); w = 200; h = 35; NanoVG.nvgBeginPath(vg); NanoVG.nvgRect(vg, x, y, w, h); NanoVG.nvgFillColor(vg, NanoVG.nvgRGBA(0, 0, 0, 128)); NanoVG.nvgFill(vg); NanoVG.nvgBeginPath(vg); NanoVG.nvgMoveTo(vg, x, y + h); if (style == (int)GraphrenderStyle.GRAPH_RENDER_FPS) { for (i = 0; i < GRAPH_HISTORY_COUNT; i++) { float v = 1.0f / (0.00001f + values[(head + i) % GRAPH_HISTORY_COUNT]); float vx, vy; if (v > 80.0f) { v = 80.0f; } vx = x + ((float)i / (GRAPH_HISTORY_COUNT - 1)) * w; vy = y + h - ((v / 80.0f) * h); NanoVG.nvgLineTo(vg, vx, vy); } } else if (style == (int)GraphrenderStyle.GRAPH_RENDER_PERCENT) { for (i = 0; i < GRAPH_HISTORY_COUNT; i++) { float v = values[(head + i) % GRAPH_HISTORY_COUNT] * 1.0f; float vx, vy; if (v > 100.0f) { v = 100.0f; } vx = x + ((float)i / (GRAPH_HISTORY_COUNT - 1)) * w; vy = y + h - ((v / 100.0f) * h); NanoVG.nvgLineTo(vg, vx, vy); } } else { for (i = 0; i < GRAPH_HISTORY_COUNT; i++) { float v = values[(head + i) % GRAPH_HISTORY_COUNT] * 1000.0f; float vx, vy; if (v > 20.0f) { v = 20.0f; } vx = x + ((float)i / (GRAPH_HISTORY_COUNT - 1)) * w; vy = y + h - ((v / 20.0f) * h); NanoVG.nvgLineTo(vg, vx, vy); } } NanoVG.nvgLineTo(vg, x + w, y + h); NanoVG.nvgFillColor(vg, NanoVG.nvgRGBA(255, 192, 0, 128)); NanoVG.nvgFill(vg); NanoVG.nvgFontFace(vg, "sans"); if (name[0] != '\0') { NanoVG.nvgFontSize(vg, 14.0f); NanoVG.nvgTextAlign(vg, (int)(NVGalign.NVG_ALIGN_LEFT | NVGalign.NVG_ALIGN_TOP)); NanoVG.nvgFillColor(vg, NanoVG.nvgRGBA(240, 240, 240, 192)); NanoVG.nvgText(vg, x + 3, y + 1, name); } if (style == (int)GraphrenderStyle.GRAPH_RENDER_FPS) { NanoVG.nvgFontSize(vg, 18.0f); NanoVG.nvgTextAlign(vg, (int)(NVGalign.NVG_ALIGN_RIGHT | NVGalign.NVG_ALIGN_TOP)); NanoVG.nvgFillColor(vg, NanoVG.nvgRGBA(240, 240, 240, 255)); str = String.Format("{0:0.00} FPS", 1.0f / avg); NanoVG.nvgText(vg, x + w - 3, y + 1, str); NanoVG.nvgFontSize(vg, 15.0f); NanoVG.nvgTextAlign(vg, (int)(NVGalign.NVG_ALIGN_RIGHT | NVGalign.NVG_ALIGN_BOTTOM)); NanoVG.nvgFillColor(vg, NanoVG.nvgRGBA(240, 240, 240, 160)); str = String.Format("{0:0.00} ms", avg * 1000.0f); NanoVG.nvgText(vg, x + w - 3, y + h - 1, str); } else if (style == (int)GraphrenderStyle.GRAPH_RENDER_PERCENT) { NanoVG.nvgFontSize(vg, 18.0f); NanoVG.nvgTextAlign(vg, (int)(NVGalign.NVG_ALIGN_RIGHT | NVGalign.NVG_ALIGN_TOP)); NanoVG.nvgFillColor(vg, NanoVG.nvgRGBA(240, 240, 240, 255)); str = String.Format("{0:0.0} %", avg * 1.0f); NanoVG.nvgText(vg, x + w - 3, y + 1, str); } else { NanoVG.nvgFontSize(vg, 18.0f); NanoVG.nvgTextAlign(vg, (int)(NVGalign.NVG_ALIGN_RIGHT | NVGalign.NVG_ALIGN_TOP)); NanoVG.nvgFillColor(vg, NanoVG.nvgRGBA(240, 240, 240, 255)); str = String.Format("{0:0.00} ms", avg * 1000.0f); NanoVG.nvgText(vg, x + w - 3, y + 1, str); } }
public abstract void Draw(NVGcontext ctx);
public override void Draw(NVGcontext ctx) { NanoVG.nvgSave(ctx); }
public abstract void Execute(NVGcontext ctx);
public virtual void Draw(NVGcontext ctx) { // TODO: draw debug bounds. DrawChildren(ctx); }