void LoadContentScale() { _txlogScale = new TexXyz[NUMS]; for (int i = 0; i < NUMS; ++i) { _txlogScale[i] = new TexXyz(); _txlogScale[i].LoadContent_CAS_SizeM_UnsignedX(_mgr.GraphicsDevice, _sb, _mgr.Content); } }
void CalculateAndDrawLines() { float[] xs = new float[_NotesXValues.Count]; // list of x values Dictionary <float, String> ids = new Dictionary <float, String>(); // map x to id Vector2 vLastLeft = new Vector2(-100, 0); Vector2 vLastRight = vLastLeft; _posYears.Clear(); _years.Clear(); _txlistNotes.Clear(); _posListNotes.Clear(); // build: xs to hold x values // dIds to hold x->id int m = 0; foreach (var n in _NotesXValues) { float x = (float)Math.Round(n.Value, ROUND); xs[m++] = x; // note x values if (ids.ContainsKey(x) == false) { ids.Add(x, n.Key); // note id foreach x value } } Array.Sort(xs); // now we've the x values and we know which x value is which note... for (int j = 0; j < xs.Length - 1; ++j) // draw from left to right - xs is sorted { float left, right; left = xs[j]; right = xs[j + 1]; float width = right - left; float h = posLnZero.Y - 25; if (width > 22) #region draw parametric line { // draw parametric line // Ranges for line float half = left + width / 2; float[] ixs = { left, half, right }; float[] iys = { posLnZero.Y, h, posLnZero.Y }; float[] xout, yout; int nOutputPoints = (int)Math.Max(10, Math.Round(width / 4, 0)); CubicSpline.FitParametric(ixs, iys, nOutputPoints, out xout, out yout); for (int k = 0; k < xout.Length - 1; ++k) { Vector2 pt1 = new Vector2(xout[k], yout[k]); Vector2 pt2 = new Vector2(xout[k + 1], yout[k + 1]); DrawLine(pt1, pt2, _clrGlobal); } // draw years Vector2 pt = new Vector2(left + width / 2, posLnZero.Y - 25 - 14); //todo magic _posYears.Add(pt); // The current left, right x-values float a = left; float b = right; if (ids.ContainsKey(a) && ids.ContainsKey(b)) { //String[] id = { ids[a], ids[b] }; // note ids TimeSpan ts; DateTime[] dts = { _Notes[ids[a]].dtUnified, _Notes[ids[b]].dtUnified }; if (dts[0] > dts[1]) { ts = dts[0] - dts[1]; } else { ts = dts[1] - dts[0]; } DateTime dt = DateTime.MinValue + ts; _years.Add(Math.Max(1, dt.Year - 1)); DateTime dtLeft = dts[0]; DateTime dtRight = dts[1]; if (dtLeft.Year != yearprev) { TexXyz texLeft = new TexXyz(); texLeft.LoadContent_CAS_SizeM_UnsignedX(_mgr.GraphicsDevice, _sb, _mgr.Content); texLeft.Update(dtLeft.Year); _txlistNotes.Add(texLeft); _posListNotes.Add(new Vector2(left, posNotes.Y)); } TexXyz texRight = new TexXyz(); texRight.LoadContent_CAS_SizeM_UnsignedX(_mgr.GraphicsDevice, _sb, _mgr.Content); texRight.Update(dtRight.Year); _txlistNotes.Add(texRight); _posListNotes.Add(new Vector2(right, posNotes.Y)); yearprev = dtRight.Year; } #if DEBUG else { Debug.WriteLine("Internal error CwaNoteStatsImage CalculateDrawLines missing key"); } #endif } // if draw #endregion else { // curve is too small, so just draw a small line DrawLine(new Vector2(left, posLnZero.Y), new Vector2(right, posLnZero.Y), _clrGlobal); } } for (int i = 1; i < _posListNotes.Count; ++i) { float w = _posListNotes[i].X - _posListNotes[i - 1].X; if (w < 30) { Vector2 left = _posListNotes[i]; left.X += 7; _posListNotes[i] = left; Vector2 right = _posListNotes[i - 1]; right.X -= 7; _posListNotes[i - 1] = right; } } // calculate the years difference textures _txYearsDif = new TexXyz[_years.Count]; for (int w = 0; w < _years.Count; ++w) { if (_years[w] > 0) { _txYearsDif[w] = new TexXyz(); _txYearsDif[w].LoadContent_CAS_SizeM_UnsignedX(_mgr.GraphicsDevice, _sb, _mgr.Content); _txYearsDif[w].Update(_years[w]); bool updated = _txYearsDif[w].UpdateConsume; } } }