in ExampleGallery/AnimatedControlExample.xaml.cs [444:520]
public void Draw(CanvasAnimatedDrawEventArgs args, CanvasDrawingSession ds, float width, float height)
{
drawCount++;
const int maxEntries = 120;
updatesPerDraw.Enqueue(updatesThisDraw);
while (updatesPerDraw.Count > maxEntries)
updatesPerDraw.Dequeue();
ds.Antialiasing = CanvasAntialiasing.Aliased;
var barWidth = width / (float)maxEntries;
const float heightPerUpdate = 10.0f;
float barBottom = height * 0.25f;
int maxUpdates = 0;
int maxIndex = -1;
int index = 0;
foreach (int update in updatesPerDraw)
{
float barHeight = update * heightPerUpdate;
Windows.UI.Color color = Colors.Gray;
if ((Math.Max(0, drawCount - maxEntries) + index) % 60 == 0)
color = Colors.White;
ds.FillRectangle(barWidth * index, height - barHeight - barBottom, barWidth, barHeight + barBottom, color);
if (update > maxUpdates)
{
maxIndex = index;
maxUpdates = update;
}
index++;
}
if (maxUpdates > 0)
{
var y = height - maxUpdates * heightPerUpdate - barBottom;
ds.DrawLine(0, y, width, y, Colors.White, 1, maxStroke);
ds.DrawText(
maxUpdates.ToString(),
0,
height - maxUpdates * heightPerUpdate - barBottom,
Colors.White,
new CanvasTextFormat()
{
FontSize = heightPerUpdate * 2,
HorizontalAlignment = CanvasHorizontalAlignment.Left,
VerticalAlignment = CanvasVerticalAlignment.Bottom
});
}
using (var textFormat = new CanvasTextFormat()
{
FontSize = width * 0.05f,
HorizontalAlignment = CanvasHorizontalAlignment.Left,
VerticalAlignment = CanvasVerticalAlignment.Top
})
{
float y = 1;
ds.DrawText("Updates per Draw", 1, y, Colors.White, textFormat);
y += textFormat.FontSize * 2;
textFormat.FontSize *= 0.6f;
ds.DrawText(string.Format("{0} total updates", args.Timing.UpdateCount), 1, y, Colors.Red, textFormat);
y += textFormat.FontSize * 1.2f;
ds.DrawText(string.Format("{0} total draws", drawCount), 1, y, Colors.Green, textFormat);
}
updatesThisDraw = 0;
}