GUICurveDrawing.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using System;
  4. using System.Collections.Generic;
  5. using BansheeEngine;
  6. namespace BansheeEditor
  7. {
  8. /** @addtogroup AnimationEditor
  9. * @{
  10. */
  11. /// <summary>
  12. /// Draws one or multiple curves over the specified physical area. User can specify horizontal and vertical range to
  13. /// display, as well as physical size of the GUI area.
  14. /// </summary>
  15. internal class GUICurveDrawing : GUITimelineBase
  16. {
  17. private const int LINE_SPLIT_WIDTH = 2;
  18. private const int TANGENT_LINE_DISTANCE = 30;
  19. private static readonly Color COLOR_MID_GRAY = new Color(90.0f / 255.0f, 90.0f / 255.0f, 90.0f / 255.0f, 1.0f);
  20. private static readonly Color COLOR_DARK_GRAY = new Color(40.0f / 255.0f, 40.0f / 255.0f, 40.0f / 255.0f, 1.0f);
  21. private EdAnimationCurve[] curves;
  22. private bool[][] selectedKeyframes;
  23. private float yRange = 20.0f;
  24. private float yOffset;
  25. private GUIGraphTicks tickHandler;
  26. /// <summary>
  27. /// Creates a new curve drawing GUI element.
  28. /// </summary>
  29. /// <param name="layout">Layout into which to add the GUI element.</param>
  30. /// <param name="width">Width of the element in pixels.</param>
  31. /// <param name="height">Height of the element in pixels.</param>
  32. /// <param name="curves">Initial set of curves to display. </param>
  33. public GUICurveDrawing(GUILayout layout, int width, int height, EdAnimationCurve[] curves)
  34. :base(layout, width, height)
  35. {
  36. tickHandler = new GUIGraphTicks(GUITickStepType.Time);
  37. this.curves = curves;
  38. ClearSelectedKeyframes(); // Makes sure the array is initialized
  39. }
  40. /// <summary>
  41. /// Change the set of curves to display.
  42. /// </summary>
  43. /// <param name="curves">New set of curves to draw on the GUI element.</param>
  44. public void SetCurves(EdAnimationCurve[] curves)
  45. {
  46. this.curves = curves;
  47. }
  48. /// <summary>
  49. /// Changes the visible range that the GUI element displays.
  50. /// </summary>
  51. /// <param name="xRange">Range of the horizontal area. Displayed area will range from [0, xRange].</param>
  52. /// <param name="yRange">Range of the vertical area. Displayed area will range from
  53. /// [-yRange * 0.5, yRange * 0.5]</param>
  54. public void SetRange(float xRange, float yRange)
  55. {
  56. SetRange(xRange);
  57. this.yRange = yRange;
  58. }
  59. /// <summary>
  60. /// Returns the offset at which the displayed timeline values start at.
  61. /// </summary>
  62. /// <param name="offset">Value to start the timeline values at.</param>
  63. public void SetOffset(Vector2 offset)
  64. {
  65. SetOffset(offset.x);
  66. yOffset = offset.y;
  67. }
  68. /// <summary>
  69. /// Marks the specified key-frame as selected, changing the way it is displayed.
  70. /// </summary>
  71. /// <param name="keyframeRef">Keyframe reference containing the curve and keyframe index.</param>
  72. /// <param name="selected">True to select it, false to deselect it.</param>
  73. public void SelectKeyframe(KeyframeRef keyframeRef, bool selected)
  74. {
  75. if (selectedKeyframes == null)
  76. return;
  77. if (keyframeRef.curveIdx < 0 || keyframeRef.curveIdx >= selectedKeyframes.Length)
  78. return;
  79. if (keyframeRef.keyIdx < 0 || keyframeRef.keyIdx >= selectedKeyframes[keyframeRef.curveIdx].Length)
  80. return;
  81. selectedKeyframes[keyframeRef.curveIdx][keyframeRef.keyIdx] = selected;
  82. }
  83. /// <summary>
  84. /// Clears any key-frames that were marked as selected.
  85. /// </summary>
  86. public void ClearSelectedKeyframes()
  87. {
  88. selectedKeyframes = new bool[curves.Length][];
  89. for (int i = 0; i < curves.Length; i++)
  90. {
  91. KeyFrame[] keyframes = curves[i].KeyFrames;
  92. selectedKeyframes[i] = new bool[keyframes.Length];
  93. }
  94. }
  95. /// <summary>
  96. /// Attempts to find a keyframe under the provided coordinates.
  97. /// </summary>
  98. /// <param name="pixelCoords">Coordinates relative to this GUI element in pixels.</param>
  99. /// <param name="keyframe">Output object containing keyframe index and index of the curve it belongs to. Only valid
  100. /// if method returns true.</param>
  101. /// <returns>True if there is a keyframe under the coordinates, false otherwise.</returns>
  102. public bool FindKeyFrame(Vector2I pixelCoords, out KeyframeRef keyframe)
  103. {
  104. keyframe = new KeyframeRef();
  105. float nearestDistance = float.MaxValue;
  106. for (int i = 0; i < curves.Length; i++)
  107. {
  108. EdAnimationCurve curve = curves[i];
  109. KeyFrame[] keyframes = curve.KeyFrames;
  110. for (int j = 0; j < keyframes.Length; j++)
  111. {
  112. Vector2 keyframeCurveCoords = new Vector2(keyframes[j].time, keyframes[j].value);
  113. Vector2I keyframeCoords = CurveToPixelSpace(keyframeCurveCoords);
  114. float distanceToKey = Vector2I.Distance(pixelCoords, keyframeCoords);
  115. if (distanceToKey < nearestDistance)
  116. {
  117. nearestDistance = distanceToKey;
  118. keyframe.keyIdx = j;
  119. keyframe.curveIdx = i;
  120. }
  121. }
  122. }
  123. // We're not near any keyframe
  124. if (nearestDistance > 5.0f)
  125. return false;
  126. return true;
  127. }
  128. /// <summary>
  129. /// Attempts to find a a tangent handle under the provided coordinates.
  130. /// </summary>
  131. /// <param name="pixelCoords">Coordinates relative to this GUI element in pixels.</param>
  132. /// <param name="tangent">Output object containing keyframe information and tangent type. Only valid if method
  133. /// returns true.</param>
  134. /// <returns>True if there is a tangent handle under the coordinates, false otherwise.</returns>
  135. public bool FindTangent(Vector2I pixelCoords, out TangentRef tangent)
  136. {
  137. tangent = new TangentRef();
  138. float nearestDistance = float.MaxValue;
  139. for (int i = 0; i < curves.Length; i++)
  140. {
  141. EdAnimationCurve curve = curves[i];
  142. KeyFrame[] keyframes = curve.KeyFrames;
  143. for (int j = 0; j < keyframes.Length; j++)
  144. {
  145. if (!IsSelected(i, j))
  146. continue;
  147. TangentMode tangentMode = curve.TangentModes[j];
  148. if (IsTangentDisplayed(tangentMode, TangentType.In))
  149. {
  150. Vector2I tangentCoords = GetTangentPosition(keyframes[j], TangentType.In);
  151. float distanceToHandle = Vector2I.Distance(pixelCoords, tangentCoords);
  152. if (distanceToHandle < nearestDistance)
  153. {
  154. nearestDistance = distanceToHandle;
  155. tangent.keyframeRef.keyIdx = j;
  156. tangent.keyframeRef.curveIdx = i;
  157. tangent.type = TangentType.In;
  158. }
  159. ; }
  160. if (IsTangentDisplayed(tangentMode, TangentType.Out))
  161. {
  162. Vector2I tangentCoords = GetTangentPosition(keyframes[j], TangentType.Out);
  163. float distanceToHandle = Vector2I.Distance(pixelCoords, tangentCoords);
  164. if (distanceToHandle < nearestDistance)
  165. {
  166. nearestDistance = distanceToHandle;
  167. tangent.keyframeRef.keyIdx = j;
  168. tangent.keyframeRef.curveIdx = i;
  169. tangent.type = TangentType.Out;
  170. }
  171. }
  172. }
  173. }
  174. // We're not near any keyframe
  175. if (nearestDistance > 5.0f)
  176. return false;
  177. return true;
  178. }
  179. /// <summary>
  180. /// Converts pixel coordinates into coordinates in curve space.
  181. /// </summary>
  182. /// <param name="pixelCoords">Coordinates relative to this GUI element, in pixels.</param>
  183. /// <param name="curveCoords">Curve coordinates within the range as specified by <see cref="SetRange"/>. Only
  184. /// valid when function returns true.</param>
  185. /// <returns>True if the coordinates are within the curve area, false otherwise.</returns>
  186. public bool PixelToCurveSpace(Vector2I pixelCoords, out Vector2 curveCoords)
  187. {
  188. Rect2I bounds = canvas.Bounds;
  189. // Check if outside of curve drawing bounds
  190. if (pixelCoords.x < (bounds.x + PADDING) || pixelCoords.x >= (bounds.x + bounds.width - PADDING) ||
  191. pixelCoords.y < bounds.y || pixelCoords.y >= (bounds.y + bounds.height))
  192. {
  193. curveCoords = new Vector2();
  194. return false;
  195. }
  196. // Find time and value of the place under the coordinates
  197. Vector2I relativeCoords = pixelCoords - new Vector2I(bounds.x + PADDING, bounds.y);
  198. float lengthPerPixel = GetRange() / drawableWidth;
  199. float heightPerPixel = yRange / height;
  200. float centerOffset = yRange / 2.0f;
  201. float t = rangeOffset + relativeCoords.x * lengthPerPixel;
  202. float value = yOffset + centerOffset - relativeCoords.y * heightPerPixel;
  203. curveCoords = new Vector2();
  204. curveCoords.x = t;
  205. curveCoords.y = value;
  206. return true;
  207. }
  208. /// <summary>
  209. /// Converts coordinate in curve space (time, value) into pixel coordinates relative to this element's origin.
  210. /// </summary>
  211. /// <param name="curveCoords">Time and value of the location to convert.</param>
  212. /// <returns>Coordinates relative to this element's origin, in pixels.</returns>
  213. public Vector2I CurveToPixelSpace(Vector2 curveCoords)
  214. {
  215. int heightOffset = height / 2; // So that y = 0 is at center of canvas
  216. Vector2 relativeCurveCoords = curveCoords - new Vector2(rangeOffset, yOffset);
  217. Vector2I pixelCoords = new Vector2I();
  218. pixelCoords.x = (int)((relativeCurveCoords.x / GetRange()) * drawableWidth) + PADDING;
  219. pixelCoords.y = heightOffset - (int)((relativeCurveCoords.y / yRange) * height);
  220. return pixelCoords;
  221. }
  222. /// <summary>
  223. /// Draws a vertical frame marker on the curve area.
  224. /// </summary>
  225. /// <param name="t">Time at which to draw the marker.</param>
  226. /// <param name="color">Color with which to draw the marker.</param>
  227. /// <param name="onTop">Determines should the marker be drawn above or below the curve.</param>
  228. private void DrawFrameMarker(float t, Color color, bool onTop)
  229. {
  230. int xPos = (int)(((t - rangeOffset) / GetRange()) * drawableWidth) + PADDING;
  231. Vector2I start = new Vector2I(xPos, 0);
  232. Vector2I end = new Vector2I(xPos, height);
  233. byte depth;
  234. if (onTop)
  235. depth = 110;
  236. else
  237. depth = 128;
  238. canvas.DrawLine(start, end, color, depth);
  239. }
  240. /// <summary>
  241. /// Draws a horizontal line representing the line at y = 0.
  242. /// </summary>
  243. private void DrawCenterLine()
  244. {
  245. Vector2I center = CurveToPixelSpace(new Vector2(0.0f, 0.0f));
  246. Vector2I start = new Vector2I(0, center.y);
  247. Vector2I end = new Vector2I(width, center.y);
  248. canvas.DrawLine(start, end, COLOR_DARK_GRAY);
  249. }
  250. /// <summary>
  251. /// Draws a diamond shape of the specified size at the coordinates.
  252. /// </summary>
  253. /// <param name="center">Position at which to place the diamond's center, in pixel coordinates.</param>
  254. /// <param name="size">Determines number of pixels to extend the diamond in each direction.</param>
  255. /// <param name="innerColor">Color of the diamond's background.</param>
  256. /// <param name="outerColor">Color of the diamond's outline.</param>
  257. private void DrawDiamond(Vector2I center, int size, Color innerColor, Color outerColor)
  258. {
  259. Vector2I a = new Vector2I(center.x - size, center.y);
  260. Vector2I b = new Vector2I(center.x, center.y - size);
  261. Vector2I c = new Vector2I(center.x + size, center.y);
  262. Vector2I d = new Vector2I(center.x, center.y + size);
  263. // Draw diamond shape
  264. Vector2I[] linePoints = new Vector2I[] { a, b, c, d, a };
  265. Vector2I[] trianglePoints = new Vector2I[] { b, c, a, d };
  266. canvas.DrawTriangleStrip(trianglePoints, innerColor, 101);
  267. canvas.DrawPolyLine(linePoints, outerColor, 100);
  268. }
  269. /// <summary>
  270. /// Draws a keyframe a the specified time and value.
  271. /// </summary>
  272. /// <param name="t">Time to draw the keyframe at.</param>
  273. /// <param name="y">Y value to draw the keyframe at.</param>
  274. /// <param name="selected">Determines should the keyframe be drawing using the selected color scheme, or normally.
  275. /// </param>
  276. private void DrawKeyframe(float t, float y, bool selected)
  277. {
  278. Vector2I pixelCoords = CurveToPixelSpace(new Vector2(t, y));
  279. if (selected)
  280. DrawDiamond(pixelCoords, 3, Color.White, Color.BansheeOrange);
  281. else
  282. DrawDiamond(pixelCoords, 3, Color.White, Color.Black);
  283. }
  284. /// <summary>
  285. /// Draws zero, one or two tangents for the specified keyframe. Whether tangents are drawn depends on the provided
  286. /// mode.
  287. /// </summary>
  288. /// <param name="keyFrame">Keyframe to draw the tangents for.</param>
  289. /// <param name="tangentMode">Type of tangents in the keyframe.</param>
  290. private void DrawTangents(KeyFrame keyFrame, TangentMode tangentMode)
  291. {
  292. Vector2I keyframeCoords = CurveToPixelSpace(new Vector2(keyFrame.time, keyFrame.value));
  293. if (IsTangentDisplayed(tangentMode, TangentType.In))
  294. {
  295. Vector2I tangentCoords = GetTangentPosition(keyFrame, TangentType.In);
  296. canvas.DrawLine(keyframeCoords, tangentCoords, Color.LightGray);
  297. DrawDiamond(tangentCoords, 2, Color.Green, Color.Black);
  298. }
  299. if (IsTangentDisplayed(tangentMode, TangentType.Out))
  300. {
  301. Vector2I tangentCoords = GetTangentPosition(keyFrame, TangentType.Out);
  302. canvas.DrawLine(keyframeCoords, tangentCoords, Color.LightGray);
  303. DrawDiamond(tangentCoords, 2, Color.Green, Color.Black);
  304. }
  305. }
  306. /// <summary>
  307. /// Returns the position of the tangent, in element's pixel space.
  308. /// </summary>
  309. /// <param name="keyFrame">Keyframe that the tangent belongs to.</param>
  310. /// <param name="type">Which tangent to retrieve the position for.</param>
  311. /// <returns>Position of the tangent, relative to the this GUI element's origin, in pixels.</returns>
  312. private Vector2I GetTangentPosition(KeyFrame keyFrame, TangentType type)
  313. {
  314. Vector2I position = CurveToPixelSpace(new Vector2(keyFrame.time, keyFrame.value));
  315. Vector2 normal;
  316. if (type == TangentType.In)
  317. normal = -EdAnimationCurve.TangentToNormal(keyFrame.inTangent);
  318. else
  319. normal = EdAnimationCurve.TangentToNormal(keyFrame.outTangent);
  320. // X/Y ranges aren't scaled 1:1, adjust normal accordingly
  321. normal.x /= GetRange();
  322. normal.y /= yRange;
  323. normal = Vector2.Normalize(normal);
  324. // Convert normal (in percentage) to pixel values
  325. Vector2I offset = new Vector2I((int)(normal.x * TANGENT_LINE_DISTANCE),
  326. (int)(-normal.y * TANGENT_LINE_DISTANCE));
  327. return position + offset;
  328. }
  329. /// <summary>
  330. /// Checks if the tangent should be displayed, depending on the active tangent mode.
  331. /// </summary>
  332. /// <param name="mode">Tangent mode for the keyframe.</param>
  333. /// <param name="type">Which tangent to check for.</param>
  334. /// <returns>True if the tangent should be displayed.</returns>
  335. private bool IsTangentDisplayed(TangentMode mode, TangentType type)
  336. {
  337. if (mode == TangentMode.Auto)
  338. return false;
  339. else if (mode == TangentMode.Free)
  340. return true;
  341. if (type == TangentType.In)
  342. return mode.HasFlag(TangentMode.InFree);
  343. else
  344. return mode.HasFlag(TangentMode.OutFree);
  345. }
  346. /// <summary>
  347. /// Rebuilds the internal GUI elements. Should be called whenever timeline properties change.
  348. /// </summary>
  349. public override void Rebuild()
  350. {
  351. canvas.Clear();
  352. if (curves == null)
  353. return;
  354. tickHandler.SetRange(rangeOffset, rangeOffset + GetRange(true), drawableWidth + GUIGraphTime.PADDING);
  355. // Draw vertical frame markers
  356. int numTickLevels = tickHandler.NumLevels;
  357. for (int i = numTickLevels - 1; i >= 0; i--)
  358. {
  359. float[] ticks = tickHandler.GetTicks(i);
  360. float strength = tickHandler.GetLevelStrength(i);
  361. for (int j = 0; j < ticks.Length; j++)
  362. {
  363. Color color = COLOR_DARK_GRAY;
  364. color.a *= strength;
  365. DrawFrameMarker(ticks[j], color, false);
  366. }
  367. }
  368. // Draw center line
  369. DrawCenterLine();
  370. // Draw curves
  371. int curveIdx = 0;
  372. foreach (var curve in curves)
  373. {
  374. Color color = GetUniqueColor(curveIdx);
  375. DrawCurve(curve, color);
  376. // Draw keyframes
  377. KeyFrame[] keyframes = curve.KeyFrames;
  378. for (int i = 0; i < keyframes.Length; i++)
  379. {
  380. bool isSelected = IsSelected(curveIdx, i);
  381. DrawKeyframe(keyframes[i].time, keyframes[i].value, isSelected);
  382. if (isSelected)
  383. DrawTangents(keyframes[i], curve.TangentModes[i]);
  384. }
  385. curveIdx++;
  386. }
  387. // Draw selected frame marker
  388. if (markedFrameIdx != -1)
  389. DrawFrameMarker(GetTimeForFrame(markedFrameIdx), Color.BansheeOrange, true);
  390. }
  391. /// <summary>
  392. /// Generates a unique color based on the provided index.
  393. /// </summary>
  394. /// <param name="idx">Index to use for generating a color. Should be less than 30 in order to guarantee reasonably
  395. /// different colors.</param>
  396. /// <returns>Unique color.</returns>
  397. private Color GetUniqueColor(int idx)
  398. {
  399. const int COLOR_SPACING = 359 / 15;
  400. float hue = ((idx * COLOR_SPACING) % 359) / 359.0f;
  401. return Color.HSV2RGB(new Color(hue, 175.0f / 255.0f, 175.0f / 255.0f));
  402. }
  403. /// <summary>
  404. /// Checks is the provided key-frame currently marked as selected.
  405. /// </summary>
  406. /// <param name="curveIdx">Index of the curve the keyframe is on.</param>
  407. /// <param name="keyIdx">Index of the keyframe.</param>
  408. /// <returns>True if selected, false otherwise.</returns>
  409. private bool IsSelected(int curveIdx, int keyIdx)
  410. {
  411. if (selectedKeyframes == null)
  412. return false;
  413. if (curveIdx < 0 || curveIdx >= selectedKeyframes.Length)
  414. return false;
  415. if (keyIdx < 0 || keyIdx >= selectedKeyframes[curveIdx].Length)
  416. return false;
  417. return selectedKeyframes[curveIdx][keyIdx];
  418. }
  419. /// <summary>
  420. /// Draws the curve using the provided color.
  421. /// </summary>
  422. /// <param name="curve">Curve to draw within the currently set range. </param>
  423. /// <param name="color">Color to draw the curve with.</param>
  424. private void DrawCurve(EdAnimationCurve curve, Color color)
  425. {
  426. float range = GetRange();
  427. float lengthPerPixel = range / drawableWidth;
  428. KeyFrame[] keyframes = curve.KeyFrames;
  429. if (keyframes.Length <= 0)
  430. return;
  431. // Draw start line
  432. {
  433. float curveStart = MathEx.Clamp(keyframes[0].time, 0.0f, range);
  434. float curveValue = curve.Evaluate(0.0f, false);
  435. Vector2I start = CurveToPixelSpace(new Vector2(0.0f, curveValue));
  436. start.x -= GUIGraphTime.PADDING;
  437. Vector2I end = CurveToPixelSpace(new Vector2(curveStart, curveValue));
  438. canvas.DrawLine(start, end, COLOR_MID_GRAY);
  439. }
  440. List<Vector2I> linePoints = new List<Vector2I>();
  441. // Draw in between keyframes
  442. for (int i = 0; i < keyframes.Length - 1; i++)
  443. {
  444. float start = MathEx.Clamp(keyframes[i].time, 0.0f, range);
  445. float end = MathEx.Clamp(keyframes[i + 1].time, 0.0f, range);
  446. bool isStep = keyframes[i].outTangent == float.PositiveInfinity ||
  447. keyframes[i + 1].inTangent == float.PositiveInfinity;
  448. // If step tangent, draw the required lines without sampling, as the sampling will miss the step
  449. if (isStep)
  450. {
  451. float startValue = curve.Evaluate(start, false);
  452. float endValue = curve.Evaluate(end, false);
  453. linePoints.Add(CurveToPixelSpace(new Vector2(start, startValue)));
  454. linePoints.Add(CurveToPixelSpace(new Vector2(end, startValue)));
  455. linePoints.Add(CurveToPixelSpace(new Vector2(end, endValue)));
  456. }
  457. else // Draw normally
  458. {
  459. float timeIncrement = LINE_SPLIT_WIDTH*lengthPerPixel;
  460. int startPixel = (int)(start / lengthPerPixel);
  461. int endPixel = (int)(end / lengthPerPixel);
  462. int numSplits;
  463. if (startPixel != endPixel)
  464. {
  465. float fNumSplits = (end - start) / timeIncrement;
  466. numSplits = MathEx.FloorToInt(fNumSplits);
  467. float remainder = fNumSplits - numSplits;
  468. float lengthRounded = (end - start)*(numSplits/fNumSplits);
  469. timeIncrement = lengthRounded/numSplits;
  470. numSplits += MathEx.CeilToInt(remainder) + 1;
  471. }
  472. else
  473. {
  474. numSplits = 1;
  475. timeIncrement = 0.0f;
  476. }
  477. for (int j = 0; j < numSplits; j++)
  478. {
  479. float t = Math.Min(start + j * timeIncrement, end);
  480. float value = curve.Evaluate(t, false);
  481. linePoints.Add(CurveToPixelSpace(new Vector2(t, value)));
  482. }
  483. }
  484. }
  485. canvas.DrawPolyLine(linePoints.ToArray(), color);
  486. // Draw end line
  487. {
  488. float curveEnd = MathEx.Clamp(keyframes[keyframes.Length - 1].time, 0.0f, range);
  489. float curveValue = curve.Evaluate(range, false);
  490. Vector2I start = CurveToPixelSpace(new Vector2(curveEnd, curveValue));
  491. Vector2I end = new Vector2I(width, start.y);
  492. canvas.DrawLine(start, end, COLOR_MID_GRAY);
  493. }
  494. }
  495. }
  496. /** }@ */
  497. }