public RenderState(RenderState other) { this.parent = other.parent; this.vertTextIndex = other.vertTextIndex.Clone() as int[]; this.vertIconIndex = other.vertIconIndex; this.offset = other.offset; this.elemIndex = other.elemIndex; this.lineIndex = other.lineIndex; this.fontIndex = other.fontIndex; this.font = other.font; this.color = other.color; this.lineBeginX = other.lineBeginX; this.lineWidth = other.lineWidth; this.lineAvailWidth = other.lineAvailWidth; this.lineHeight = other.lineHeight; this.lineBaseLine = other.lineBaseLine; this.lineAlign = other.lineAlign; this.curElemOffset = other.curElemOffset; this.curElemVertTextIndex = other.curElemVertTextIndex; this.curElemVertIconIndex = other.curElemVertIconIndex; this.curElemWrapIndex = other.curElemWrapIndex; this.curElemText = other.curElemText; }
public RenderState(FormattedText parent) { this.parent = parent; this.vertTextIndex = new int[this.parent.fonts != null ? this.parent.fonts.Length : 0]; this.font = (this.parent.fonts != null && this.parent.fonts.Length > 0) ? this.parent.fonts[0].Res : null; this.color = ColorRgba.White; this.lineAlign = parent.lineAlign; this.PeekLineStats(); this.offset.X = this.lineBeginX; }
void ICmpRenderer.Draw(IDrawDevice device) { Profile.BeginMeasure(@"ProfileRenderer"); Canvas canvas = new Canvas(device); canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, ColorRgba.White, null)); bool anyTextReport = this.textReportPerf || this.textReportStat; bool anyGraph = this.drawGraphs && this.counterGraphs.Count > 0; // Determine geometry int areaWidth = (int)device.TargetSize.X - 20; if (anyGraph && anyTextReport) areaWidth = (areaWidth - 10) / 2; Rect textReportRect = new Rect( 10, 10, anyTextReport ? areaWidth : 0, (int)device.TargetSize.Y - 20); Rect graphRect = new Rect( anyTextReport ? (textReportRect.RightX + 10) : 10, 10, anyGraph ? areaWidth : 0, (int)device.TargetSize.Y - 20); // Text Reports if (anyTextReport) { // Update Report IEnumerable<ProfileCounter> counters = Profile.GetUsedCounters(); if (!this.textReportPerf) counters = counters.Where(c => !(c is TimeCounter)); if (!this.textReportStat) counters = counters.Where(c => !(c is StatCounter)); if (this.textReport == null || (Time.MainTimer - this.textReportLast).TotalMilliseconds > this.updateInterval) { string report = Profile.GetTextReport(counters, this.textReportOptions | ProfileReportOptions.FormattedText); if (this.textReport == null) { this.textReport = new FormattedText(); this.textReport.Fonts = new[] { Font.GenericMonospace8 }; } this.textReport.MaxWidth = (int)textReportRect.W; this.textReport.SourceText = report; this.textReportLast = Time.MainTimer; } // Draw Report canvas.DrawText(textReport, ref textReportTextVert, ref textReportIconVert, textReportRect.X, textReportRect.Y, drawBackground: true); } // Counter Graphs if (anyGraph) { // Mark graph cache as unused foreach (GraphCacheEntry entry in this.graphCache.Values) { entry.WasUsed = false; } int space = 5; int graphY = (int)graphRect.Y; int graphH = MathF.Min((int)(graphRect.H / this.counterGraphs.Count) - space, (int)graphRect.W / 2); foreach (string counterName in this.counterGraphs) { ProfileCounter counter = Profile.GetCounter<ProfileCounter>(counterName); if (counter == null) return; // Create or retrieve graph cache entry GraphCacheEntry cache = null; if (!this.graphCache.TryGetValue(counterName, out cache)) { cache = new GraphCacheEntry(); cache.GraphValues = new float[ProfileCounter.ValueHistoryLen]; cache.GraphColors = new ColorRgba[ProfileCounter.ValueHistoryLen]; this.graphCache[counterName] = cache; } cache.WasUsed = true; float cursorRatio = 0.0f; if (counter is TimeCounter) { TimeCounter timeCounter = counter as TimeCounter; for (int i = 0; i < ProfileCounter.ValueHistoryLen; i++) { float factor = timeCounter.ValueGraph[i] / Time.MsPFMult; cache.GraphValues[i] = factor * 0.75f; cache.GraphColors[i] = ColorRgba.Lerp(ColorRgba.White, ColorRgba.Red, factor); } canvas.State.ColorTint = ColorRgba.Black.WithAlpha(0.5f); canvas.FillRect(graphRect.X, graphY, graphRect.W, graphH); canvas.State.ColorTint = ColorRgba.White; this.DrawHorizontalGraph(canvas, cache.GraphValues, cache.GraphColors, ref cache.VertGraph, graphRect.X, graphY, graphRect.W, graphH); cursorRatio = (float)timeCounter.ValueGraphCursor / (float)ProfileCounter.ValueHistoryLen; } else if (counter is StatCounter) { StatCounter statCounter = counter as StatCounter; for (int i = 0; i < ProfileCounter.ValueHistoryLen; i++) { cache.GraphValues[i] = (float)(statCounter.ValueGraph[i] - statCounter.MinValue) / statCounter.MaxValue; cache.GraphColors[i] = ColorRgba.White; } canvas.State.ColorTint = ColorRgba.Black.WithAlpha(0.5f); canvas.FillRect(graphRect.X, graphY, graphRect.W, graphH); canvas.State.ColorTint = ColorRgba.White; this.DrawHorizontalGraph(canvas, cache.GraphValues, cache.GraphColors, ref cache.VertGraph, graphRect.X, graphY, graphRect.W, graphH); cursorRatio = (float)statCounter.ValueGraphCursor / (float)ProfileCounter.ValueHistoryLen; } canvas.DrawText(new string[] { counter.FullName }, ref cache.VertText, graphRect.X, graphY); canvas.DrawLine(graphRect.X + graphRect.W * cursorRatio, graphY, graphRect.X + graphRect.W * cursorRatio, graphY + graphH); graphY += graphH + space; } // Remove unused graph cache entries foreach (var pair in this.graphCache.ToArray()) { if (!pair.Value.WasUsed) { pair.Value.GraphColors = null; pair.Value.GraphValues = null; pair.Value.VertGraph = null; pair.Value.VertText = null; this.graphCache.Remove(pair.Key); } } } Profile.EndMeasure(@"ProfileRenderer"); }
public FormattedText(FormattedText other) { other.DeepCopyTo(this); }
public FormattedText(FormattedText other) { this.sourceText = other.sourceText; this.icons = other.icons != null ? (Icon[])other.icons.Clone() : null; this.flowAreas = other.flowAreas != null ? (FlowArea[])other.flowAreas.Clone() : null; this.fonts = other.fonts != null ? (ContentRef<Font>[])other.fonts.Clone() : null; this.maxWidth = other.maxWidth; this.maxHeight = other.maxHeight; this.wrapMode = other.wrapMode; this.lineAlign = other.lineAlign; this.ApplySource(this.sourceText); }