public override void Draw(GameTime gameTime)
{
if (_history == null) {
InitializeHistory();
return;
}
SpriteFont font = debugManager.DebugFont;
SpriteBatch spriteBatch = debugManager.SpriteBatch;
Texture2D whiteTexture = debugManager.WhiteTexture;
//Effect solidEffect = debugManager.SolidColorEffect;
// Compute command window size and draw.
float w = GraphicsDevice.Viewport.Width;
float h = GraphicsDevice.Viewport.Height;
float topMargin = h * 0.1f;
float leftMargin = w * 0.1f;
Rectangle rect = new Rectangle();
rect.X = (int)leftMargin;
rect.Y = (int)topMargin;
rect.Width = (int)(w * 0.8f);
rect.Height = (int)(20 * font.LineSpacing);
float sampleStride = rect.Width / (float)_historyCount;
Matrix mtx = Matrix.CreateTranslation(
new Vector3(0, -rect.Height * (1.0f - 1.0f), 0));
spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, mtx);
spriteBatch.Draw(whiteTexture, rect, new Color(0, 0, 0, 200));
spriteBatch.Draw(whiteTexture, new Rectangle(rect.X + (int)(_graphIndex * sampleStride), rect.Top, 1, rect.Height), Color.White);
spriteBatch.End();
Viewport viewport = spriteBatch.GraphicsDevice.Viewport;
float nw = (viewport.Width > 0)
? 1f / viewport.Width : 0;
float nh = (viewport.Height > 0)
? -1f / viewport.Height : 0;
Matrix mat = new Matrix
{
M11 = nw * 2f,
M22 = nh * 2f,
M33 = 1f,
M44 = 1f,
M41 = -1f - nh,
M42 = 1f - nw,
};
//solidEffect.Parameters["MatrixTransform"].SetValue(mtx * mat);
//debugManager.BasicEffect.TextureEnabled = false;
debugManager.BasicEffect.VertexColorEnabled = true;
debugManager.BasicEffect.World = mtx * mat;
const float frameSpan = 1.0f / 60.0f * 1000f;
float scaleY = rect.Height * 1f / frameSpan;
int bars = _ruler.Frame.Bars.Length;
for (int i = 0; i < bars; i++) {
for (int j = 0; j < _ruler.Frame.Bars[i].MarkCount; j++) {
float time = _ruler.Frame.Bars[i].Markers[j].EndTime - _ruler.Frame.Bars[i].Markers[j].BeginTime;
Color c = _ruler.Frame.Bars[i].Markers[j].Color;
if (_history[i][j] == null)
_history[i][j] = InitializeHistory(new Vector2(rect.Left, rect.Bottom), sampleStride, c);
_history[i][j][_graphIndex] = new VertexPositionColor(new Vector3(rect.X + _graphIndex * sampleStride, rect.Bottom - time * scaleY, 0), c);
//solidEffect.Parameters["solidColor"].SetValue(new Vector4(c.R, c.G, c.B, 1));
//solidEffect.CurrentTechnique.Passes[0].Apply();
debugManager.BasicEffect.CurrentTechnique.Passes[0].Apply();
spriteBatch.GraphicsDevice.DrawUserPrimitives(PrimitiveType.LineStrip, _history[i][j], 0, _historyCount - 1);
//_drawBatch.DrawPrimitivePath(_history2[i][j], Pens.White);
/*for (int seg = 1; seg < _historyCount; seg++) {
Vector3 pos1 = _history[i][j][seg - 1].Position;
Vector3 pos2 = _history[i][j][seg].Position;
_drawBatch.DrawPrimitiveLine(new Point((int)pos1.X, (int)pos1.Y), new Point((int)pos2.X, (int)pos2.Y), Pens.White);
}*/
}
}
//solidEffect.Parameters["solidColor"].SetValue(new Vector4(1, 1, 1, .33f));
//solidEffect.CurrentTechnique.Passes[0].Apply();
spriteBatch.GraphicsDevice.DrawUserPrimitives(PrimitiveType.LineStrip, _total, 0, _historyCount - 1);
}