GUICurveEditor.cs 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276
  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. /// Displays a set of animation curves and events. Allows manipulation of both by adding, removing and modifying
  13. /// curve keyframes, and animation events.
  14. /// </summary>
  15. internal class GUICurveEditor
  16. {
  17. /// <summary>
  18. /// Information about currently selected set of keyframes for a specific curve.
  19. /// </summary>
  20. class SelectedKeyframes
  21. {
  22. public int curveIdx;
  23. public List<int> keyIndices = new List<int>();
  24. }
  25. /// <summary>
  26. /// Information about a keyframe that is currently being dragged.
  27. /// </summary>
  28. struct DraggedKeyframe
  29. {
  30. public DraggedKeyframe(int index, KeyFrame original)
  31. {
  32. this.index = index;
  33. this.original = original;
  34. }
  35. public int index;
  36. public KeyFrame original;
  37. }
  38. /// <summary>
  39. /// Information about all keyframes of a specific curve that are currently being dragged.
  40. /// </summary>
  41. class DraggedKeyframes
  42. {
  43. public int curveIdx;
  44. public List<DraggedKeyframe> keys = new List<DraggedKeyframe>();
  45. }
  46. /// <summary>
  47. /// Data about an animation event.
  48. /// </summary>
  49. class EventInfo
  50. {
  51. public AnimationEvent animEvent;
  52. public bool selected;
  53. }
  54. private const int TIMELINE_HEIGHT = 20;
  55. private const int VERT_PADDING = 2;
  56. private const int EVENTS_HEIGHT = 15;
  57. private const int SIDEBAR_WIDTH = 30;
  58. private const int DRAG_START_DISTANCE = 3;
  59. private AnimationWindow window;
  60. private GUILayout gui;
  61. private GUIPanel drawingPanel;
  62. private GUIPanel eventsPanel;
  63. private GUIGraphTime guiTimeline;
  64. private GUIAnimEvents guiEvents;
  65. private GUICurveDrawing guiCurveDrawing;
  66. private GUIGraphValues guiSidebar;
  67. private ContextMenu blankContextMenu;
  68. private ContextMenu keyframeContextMenu;
  69. private ContextMenu blankEventContextMenu;
  70. private ContextMenu eventContextMenu;
  71. private Vector2I contextClickPosition;
  72. private CurveDrawInfo[] curveInfos = new CurveDrawInfo[0];
  73. private bool disableCurveEdit = false;
  74. private float xRange = 60.0f;
  75. private float yRange = 10.0f;
  76. private Vector2 offset;
  77. private int width;
  78. private int height;
  79. private int markedFrameIdx;
  80. private List<SelectedKeyframes> selectedKeyframes = new List<SelectedKeyframes>();
  81. private List<EventInfo> events = new List<EventInfo>();
  82. private bool isPointerHeld;
  83. private bool isMousePressedOverKey;
  84. private bool isMousePressedOverTangent;
  85. private bool isDragInProgress;
  86. private bool isModifiedDuringDrag;
  87. private List<DraggedKeyframes> draggedKeyframes = new List<DraggedKeyframes>();
  88. private TangentRef draggedTangent;
  89. private Vector2I dragStart;
  90. /// <summary>
  91. /// Triggers whenever user selects a new frame. Reports the index of the selected frame.
  92. /// </summary>
  93. public Action<int> OnFrameSelected;
  94. /// <summary>
  95. /// Triggered whenever a new animation event is added.
  96. /// </summary>
  97. public Action OnEventAdded;
  98. /// <summary>
  99. /// Triggered whenever values in an animation event change.
  100. /// </summary>
  101. public Action OnEventModified;
  102. /// <summary>
  103. /// Triggered whenever an animation event is deleted.
  104. /// </summary>
  105. public Action OnEventDeleted;
  106. /// <summary>
  107. /// Triggered whenever keyframe in a curve is modified (added, removed or edited).
  108. /// </summary>
  109. public Action OnCurveModified;
  110. /// <summary>
  111. /// Triggered when the user clicks anywhere on the curve editor area.
  112. /// </summary>
  113. public Action OnClicked;
  114. /// <summary>
  115. /// The displayed range of the curve, where:
  116. /// .x - Range of the horizontal area. Displayed area ranges from [0, x].
  117. /// .y - Range of the vertical area. Displayed area ranges from [-y, y].
  118. /// </summary>
  119. public Vector2 Range
  120. {
  121. get { return new Vector2(xRange, yRange); }
  122. set
  123. {
  124. xRange = value.x;
  125. yRange = value.y;
  126. guiTimeline.SetRange(xRange);
  127. guiEvents.SetRange(xRange);
  128. guiCurveDrawing.SetRange(xRange, yRange * 2.0f);
  129. guiSidebar.SetRange(offset.y - yRange, offset.y + yRange);
  130. Redraw();
  131. }
  132. }
  133. /// <summary>
  134. /// Determines how much to offset the displayed curve values.
  135. /// </summary>
  136. public Vector2 Offset
  137. {
  138. get { return offset; }
  139. set
  140. {
  141. offset = value;
  142. guiTimeline.SetOffset(offset.x);
  143. guiEvents.SetOffset(offset.x);
  144. guiCurveDrawing.SetOffset(offset);
  145. guiSidebar.SetRange(offset.y - yRange, offset.y + yRange);
  146. Redraw();
  147. }
  148. }
  149. /// <summary>
  150. /// Returns the width of the curve editor, in pixels.
  151. /// </summary>
  152. public int Width
  153. {
  154. get { return width; }
  155. }
  156. /// <summary>
  157. /// Returns the height of the curve editor, in pixels.
  158. /// </summary>
  159. public int Height
  160. {
  161. get { return height; }
  162. }
  163. /// <summary>
  164. /// Set to true if curves are not allowed to be edited.
  165. /// </summary>
  166. public bool DisableCurveEdit
  167. {
  168. set { disableCurveEdit = value; }
  169. }
  170. /// <summary>
  171. /// Animation events displayed on the curve editor.
  172. /// </summary>
  173. public AnimationEvent[] Events
  174. {
  175. get
  176. {
  177. AnimationEvent[] animEvents = new AnimationEvent[events.Count];
  178. // Note: Hidden dependency. Returned events must point to the same event class this object is using, so
  179. // that any modifications made in this class will be visible in the returned values.
  180. for (int i = 0; i < events.Count; i++)
  181. animEvents[i] = events[i].animEvent;
  182. return animEvents;
  183. }
  184. set
  185. {
  186. events.Clear();
  187. for (int i = 0; i < value.Length; i++)
  188. {
  189. EventInfo eventInfo = new EventInfo();
  190. eventInfo.animEvent = value[i];
  191. events.Add(eventInfo);
  192. }
  193. UpdateEventsGUI();
  194. }
  195. }
  196. /// <summary>
  197. /// Creates a new curve editor GUI elements.
  198. /// </summary>
  199. /// <param name="window">Parent window of the GUI element.</param>
  200. /// <param name="gui">GUI layout into which to place the GUI element.</param>
  201. /// <param name="width">Width in pixels.</param>
  202. /// <param name="height">Height in pixels.</param>
  203. public GUICurveEditor(AnimationWindow window, GUILayout gui, int width, int height)
  204. {
  205. this.window = window;
  206. this.gui = gui;
  207. this.width = width;
  208. this.height = height;
  209. blankContextMenu = new ContextMenu();
  210. blankContextMenu.AddItem("Add keyframe", AddKeyframeAtPosition);
  211. blankEventContextMenu = new ContextMenu();
  212. blankEventContextMenu.AddItem("Add event", AddEventAtPosition);
  213. keyframeContextMenu = new ContextMenu();
  214. keyframeContextMenu.AddItem("Delete", DeleteSelectedKeyframes);
  215. keyframeContextMenu.AddItem("Edit", EditSelectedKeyframe);
  216. keyframeContextMenu.AddItem("Tangents/Auto", () => { ChangeSelectionTangentMode(TangentMode.Auto); });
  217. keyframeContextMenu.AddItem("Tangents/Free", () => { ChangeSelectionTangentMode(TangentMode.Free); });
  218. keyframeContextMenu.AddItem("Tangents/In/Auto", () => { ChangeSelectionTangentMode(TangentMode.InAuto); });
  219. keyframeContextMenu.AddItem("Tangents/In/Free", () => { ChangeSelectionTangentMode(TangentMode.InFree); });
  220. keyframeContextMenu.AddItem("Tangents/In/Linear", () => { ChangeSelectionTangentMode(TangentMode.InLinear); });
  221. keyframeContextMenu.AddItem("Tangents/In/Step", () => { ChangeSelectionTangentMode(TangentMode.InStep); });
  222. keyframeContextMenu.AddItem("Tangents/Out/Auto", () => { ChangeSelectionTangentMode(TangentMode.OutAuto); });
  223. keyframeContextMenu.AddItem("Tangents/Out/Free", () => { ChangeSelectionTangentMode(TangentMode.OutFree); });
  224. keyframeContextMenu.AddItem("Tangents/Out/Linear", () => { ChangeSelectionTangentMode(TangentMode.OutLinear); });
  225. keyframeContextMenu.AddItem("Tangents/Out/Step", () => { ChangeSelectionTangentMode(TangentMode.OutStep); });
  226. eventContextMenu = new ContextMenu();
  227. eventContextMenu.AddItem("Delete", DeleteSelectedEvents);
  228. eventContextMenu.AddItem("Edit", EditSelectedEvent);
  229. GUIPanel timelinePanel = gui.AddPanel();
  230. guiTimeline = new GUIGraphTime(timelinePanel, width, TIMELINE_HEIGHT);
  231. GUIPanel timelineBgPanel = gui.AddPanel(1);
  232. GUITexture timelineBackground = new GUITexture(null, EditorStyles.Header);
  233. timelineBackground.Bounds = new Rect2I(0, 0, width, TIMELINE_HEIGHT + VERT_PADDING);
  234. timelineBgPanel.AddElement(timelineBackground);
  235. eventsPanel = gui.AddPanel();
  236. eventsPanel.SetPosition(0, TIMELINE_HEIGHT + VERT_PADDING);
  237. guiEvents = new GUIAnimEvents(eventsPanel, width, EVENTS_HEIGHT);
  238. GUIPanel eventsBgPanel = eventsPanel.AddPanel(1);
  239. GUITexture eventsBackground = new GUITexture(null, EditorStyles.Header);
  240. eventsBackground.Bounds = new Rect2I(0, 0, width, EVENTS_HEIGHT + VERT_PADDING);
  241. eventsBgPanel.AddElement(eventsBackground);
  242. drawingPanel = gui.AddPanel();
  243. drawingPanel.SetPosition(0, TIMELINE_HEIGHT + EVENTS_HEIGHT + VERT_PADDING);
  244. guiCurveDrawing = new GUICurveDrawing(drawingPanel, width, height - TIMELINE_HEIGHT - EVENTS_HEIGHT - VERT_PADDING * 2, curveInfos);
  245. guiCurveDrawing.SetRange(60.0f, 20.0f);
  246. GUIPanel sidebarPanel = gui.AddPanel(-10);
  247. sidebarPanel.SetPosition(0, TIMELINE_HEIGHT + EVENTS_HEIGHT + VERT_PADDING);
  248. guiSidebar = new GUIGraphValues(sidebarPanel, SIDEBAR_WIDTH, height - TIMELINE_HEIGHT - EVENTS_HEIGHT - VERT_PADDING * 2);
  249. guiSidebar.SetRange(-10.0f, 10.0f);
  250. }
  251. /// <summary>
  252. /// Converts coordinate in curve space (time, value) into pixel coordinates relative to the curve drawing area
  253. /// origin.
  254. /// </summary>
  255. /// <param name="curveCoords">Time and value of the location to convert.</param>
  256. /// <returns>Coordinates relative to curve drawing area's origin, in pixels.</returns>
  257. public Vector2I CurveToPixelSpace(Vector2 curveCoords)
  258. {
  259. return guiCurveDrawing.CurveToPixelSpace(curveCoords);
  260. }
  261. /// <summary>
  262. /// Converts coordinates in window space (relative to the parent window origin) into coordinates in curve space.
  263. /// </summary>
  264. /// <param name="windowPos">Coordinates relative to parent editor window, in pixels.</param>
  265. /// <param name="curveCoord">Curve coordinates within the range as specified by <see cref="Range"/>. Only
  266. /// valid when function returns true.</param>
  267. /// <returns>True if the coordinates are within the curve area, false otherwise.</returns>
  268. public bool WindowToCurveSpace(Vector2I windowPos, out Vector2 curveCoord)
  269. {
  270. Rect2I elementBounds = GUIUtility.CalculateBounds(gui, window.GUI);
  271. Vector2I pointerPos = windowPos - new Vector2I(elementBounds.x, elementBounds.y);
  272. Rect2I drawingBounds = drawingPanel.Bounds;
  273. Vector2I drawingPos = pointerPos - new Vector2I(drawingBounds.x, drawingBounds.y);
  274. return guiCurveDrawing.PixelToCurveSpace(drawingPos, out curveCoord);
  275. }
  276. /// <summary>
  277. /// Handles input. Should be called by the owning window whenever a pointer is pressed.
  278. /// </summary>
  279. /// <param name="ev">Object containing pointer press event information.</param>
  280. internal void OnPointerPressed(PointerEvent ev)
  281. {
  282. if (ev.IsUsed)
  283. return;
  284. Vector2I windowPos = window.ScreenToWindowPos(ev.ScreenPos);
  285. Rect2I elementBounds = GUIUtility.CalculateBounds(gui, window.GUI);
  286. Vector2I pointerPos = windowPos - new Vector2I(elementBounds.x, elementBounds.y);
  287. bool isOverEditor = pointerPos.x >= 0 && pointerPos.x < width && pointerPos.y >= 0 && pointerPos.y < height;
  288. if (!isOverEditor)
  289. return;
  290. else
  291. OnClicked?.Invoke();
  292. Rect2I drawingBounds = drawingPanel.Bounds;
  293. Vector2I drawingPos = pointerPos - new Vector2I(drawingBounds.x, drawingBounds.y);
  294. Rect2I eventBounds = eventsPanel.Bounds;
  295. Vector2I eventPos = pointerPos - new Vector2I(eventBounds.x, eventBounds.y);
  296. if (ev.Button == PointerButton.Left)
  297. {
  298. Vector2 curveCoord;
  299. if (guiCurveDrawing.PixelToCurveSpace(drawingPos, out curveCoord, true))
  300. {
  301. KeyframeRef keyframeRef;
  302. if (!guiCurveDrawing.FindKeyFrame(drawingPos, out keyframeRef))
  303. {
  304. TangentRef tangentRef;
  305. if (guiCurveDrawing.FindTangent(drawingPos, out tangentRef))
  306. {
  307. isMousePressedOverTangent = true;
  308. dragStart = drawingPos;
  309. draggedTangent = tangentRef;
  310. }
  311. else
  312. ClearSelection();
  313. }
  314. else
  315. {
  316. if (!IsSelected(keyframeRef))
  317. {
  318. if (!Input.IsButtonHeld(ButtonCode.LeftShift) && !Input.IsButtonHeld(ButtonCode.RightShift))
  319. ClearSelection();
  320. SelectKeyframe(keyframeRef);
  321. }
  322. isMousePressedOverKey = true;
  323. dragStart = drawingPos;
  324. }
  325. guiCurveDrawing.Rebuild();
  326. UpdateEventsGUI();
  327. }
  328. else
  329. {
  330. int frameIdx = guiTimeline.GetFrame(pointerPos);
  331. if (frameIdx != -1)
  332. SetMarkedFrame(frameIdx);
  333. else
  334. {
  335. int eventIdx;
  336. if (guiEvents.FindEvent(eventPos, out eventIdx))
  337. {
  338. if (!Input.IsButtonHeld(ButtonCode.LeftShift) && !Input.IsButtonHeld(ButtonCode.RightShift))
  339. ClearSelection();
  340. events[eventIdx].selected = true;
  341. UpdateEventsGUI();
  342. }
  343. else
  344. {
  345. ClearSelection();
  346. guiCurveDrawing.Rebuild();
  347. UpdateEventsGUI();
  348. }
  349. }
  350. OnFrameSelected?.Invoke(frameIdx);
  351. }
  352. isPointerHeld = true;
  353. }
  354. else if (ev.Button == PointerButton.Right)
  355. {
  356. Vector2 curveCoord;
  357. if (guiCurveDrawing.PixelToCurveSpace(drawingPos, out curveCoord, true))
  358. {
  359. contextClickPosition = drawingPos;
  360. KeyframeRef keyframeRef;
  361. if (!guiCurveDrawing.FindKeyFrame(drawingPos, out keyframeRef))
  362. {
  363. ClearSelection();
  364. blankContextMenu.Open(pointerPos, gui);
  365. guiCurveDrawing.Rebuild();
  366. UpdateEventsGUI();
  367. }
  368. else
  369. {
  370. // If clicked outside of current selection, just select the one keyframe
  371. if (!IsSelected(keyframeRef))
  372. {
  373. ClearSelection();
  374. SelectKeyframe(keyframeRef);
  375. guiCurveDrawing.Rebuild();
  376. UpdateEventsGUI();
  377. }
  378. keyframeContextMenu.Open(pointerPos, gui);
  379. }
  380. }
  381. else if (guiEvents.GetFrame(eventPos) != -1) // Clicked over events bar
  382. {
  383. contextClickPosition = eventPos;
  384. int eventIdx;
  385. if (!guiEvents.FindEvent(eventPos, out eventIdx))
  386. {
  387. ClearSelection();
  388. blankEventContextMenu.Open(pointerPos, gui);
  389. guiCurveDrawing.Rebuild();
  390. UpdateEventsGUI();
  391. }
  392. else
  393. {
  394. // If clicked outside of current selection, just select the one event
  395. if (!events[eventIdx].selected)
  396. {
  397. ClearSelection();
  398. events[eventIdx].selected = true;
  399. guiCurveDrawing.Rebuild();
  400. UpdateEventsGUI();
  401. }
  402. eventContextMenu.Open(pointerPos, gui);
  403. }
  404. }
  405. }
  406. }
  407. /// <summary>
  408. /// Handles input. Should be called by the owning window whenever a pointer is moved.
  409. /// </summary>
  410. /// <param name="ev">Object containing pointer move event information.</param>
  411. internal void OnPointerMoved(PointerEvent ev)
  412. {
  413. if (ev.Button != PointerButton.Left)
  414. return;
  415. if (isPointerHeld)
  416. {
  417. Vector2I windowPos = window.ScreenToWindowPos(ev.ScreenPos);
  418. Rect2I elementBounds = GUIUtility.CalculateBounds(gui, window.GUI);
  419. Vector2I pointerPos = windowPos - new Vector2I(elementBounds.x, elementBounds.y);
  420. if (isMousePressedOverKey || isMousePressedOverTangent)
  421. {
  422. Rect2I drawingBounds = drawingPanel.Bounds;
  423. Vector2I drawingPos = pointerPos - new Vector2I(drawingBounds.x, drawingBounds.y);
  424. if (!isDragInProgress)
  425. {
  426. int distance = Vector2I.Distance(drawingPos, dragStart);
  427. if (distance >= DRAG_START_DISTANCE)
  428. {
  429. if (isMousePressedOverKey && !disableCurveEdit)
  430. {
  431. draggedKeyframes.Clear();
  432. foreach (var selectedEntry in selectedKeyframes)
  433. {
  434. EdAnimationCurve curve = curveInfos[selectedEntry.curveIdx].curve;
  435. KeyFrame[] keyFrames = curve.KeyFrames;
  436. DraggedKeyframes newEntry = new DraggedKeyframes();
  437. newEntry.curveIdx = selectedEntry.curveIdx;
  438. draggedKeyframes.Add(newEntry);
  439. foreach (var keyframeIdx in selectedEntry.keyIndices)
  440. newEntry.keys.Add(new DraggedKeyframe(keyframeIdx, keyFrames[keyframeIdx]));
  441. }
  442. }
  443. // TODO - UNDOREDO record keyframe or tangent
  444. isDragInProgress = true;
  445. }
  446. }
  447. if (isDragInProgress)
  448. {
  449. if (isMousePressedOverKey && !disableCurveEdit)
  450. {
  451. Vector2 diff = Vector2.Zero;
  452. Vector2 dragStartCurve;
  453. if (guiCurveDrawing.PixelToCurveSpace(dragStart, out dragStartCurve, true))
  454. {
  455. Vector2 currentPosCurve;
  456. if (guiCurveDrawing.PixelToCurveSpace(drawingPos, out currentPosCurve, true))
  457. diff = currentPosCurve - dragStartCurve;
  458. }
  459. foreach (var draggedEntry in draggedKeyframes)
  460. {
  461. EdAnimationCurve curve = curveInfos[draggedEntry.curveIdx].curve;
  462. for (int i = 0; i < draggedEntry.keys.Count; i++)
  463. {
  464. DraggedKeyframe draggedKey = draggedEntry.keys[i];
  465. float newTime = Math.Max(0.0f, draggedKey.original.time + diff.x);
  466. float newValue = draggedKey.original.value + diff.y;
  467. int newIndex = curve.UpdateKeyframe(draggedKey.index, newTime, newValue);
  468. // It's possible key changed position due to time change, but since we're moving all
  469. // keys at once they cannot change position relative to one another, otherwise we would
  470. // need to update indices for other keys as well.
  471. draggedKey.index = newIndex;
  472. draggedEntry.keys[i] = draggedKey;
  473. }
  474. curve.Apply();
  475. }
  476. // Rebuild selected keys from dragged keys (after potential sorting)
  477. ClearSelection();
  478. foreach (var draggedEntry in draggedKeyframes)
  479. {
  480. foreach (var keyframe in draggedEntry.keys)
  481. SelectKeyframe(new KeyframeRef(draggedEntry.curveIdx, keyframe.index));
  482. }
  483. isModifiedDuringDrag = true;
  484. guiCurveDrawing.Rebuild();
  485. UpdateEventsGUI();
  486. }
  487. else if (isMousePressedOverTangent && !disableCurveEdit)
  488. {
  489. EdAnimationCurve curve = curveInfos[draggedTangent.keyframeRef.curveIdx].curve;
  490. KeyFrame keyframe = curve.KeyFrames[draggedTangent.keyframeRef.keyIdx];
  491. Vector2 keyframeCurveCoords = new Vector2(keyframe.time, keyframe.value);
  492. Vector2 currentPosCurve;
  493. if (guiCurveDrawing.PixelToCurveSpace(drawingPos, out currentPosCurve, true))
  494. {
  495. Vector2 normal = currentPosCurve - keyframeCurveCoords;
  496. normal = normal.Normalized;
  497. float tangent = EdAnimationCurve.NormalToTangent(normal);
  498. if (draggedTangent.type == TangentType.In)
  499. {
  500. if (normal.x > 0.0f)
  501. tangent = float.PositiveInfinity;
  502. keyframe.inTangent = -tangent;
  503. if(curve.TangentModes[draggedTangent.keyframeRef.keyIdx] == TangentMode.Free)
  504. keyframe.outTangent = -tangent;
  505. }
  506. else
  507. {
  508. if (normal.x < 0.0f)
  509. tangent = float.PositiveInfinity;
  510. keyframe.outTangent = tangent;
  511. if (curve.TangentModes[draggedTangent.keyframeRef.keyIdx] == TangentMode.Free)
  512. keyframe.inTangent = tangent;
  513. }
  514. curve.KeyFrames[draggedTangent.keyframeRef.keyIdx] = keyframe;
  515. curve.Apply();
  516. isModifiedDuringDrag = true;
  517. guiCurveDrawing.Rebuild();
  518. }
  519. }
  520. }
  521. }
  522. else // Move frame marker
  523. {
  524. int frameIdx = guiTimeline.GetFrame(pointerPos);
  525. if (frameIdx != -1)
  526. SetMarkedFrame(frameIdx);
  527. OnFrameSelected?.Invoke(frameIdx);
  528. }
  529. }
  530. }
  531. /// <summary>
  532. /// Handles input. Should be called by the owning window whenever a pointer is released.
  533. /// </summary>
  534. /// <param name="ev">Object containing pointer release event information.</param>
  535. internal void OnPointerReleased(PointerEvent ev)
  536. {
  537. if (isModifiedDuringDrag)
  538. OnCurveModified?.Invoke();
  539. isPointerHeld = false;
  540. isDragInProgress = false;
  541. isMousePressedOverKey = false;
  542. isMousePressedOverTangent = false;
  543. isModifiedDuringDrag = false;
  544. }
  545. /// <summary>
  546. /// Handles input. Should be called by the owning window whenever a button is released.
  547. /// </summary>
  548. /// <param name="ev">Object containing button release event information.</param>
  549. internal void OnButtonUp(ButtonEvent ev)
  550. {
  551. if(ev.Button == ButtonCode.Delete)
  552. DeleteSelectedKeyframes();
  553. }
  554. /// <summary>
  555. /// Change the set of curves to display.
  556. /// </summary>
  557. /// <param name="curveInfos">New set of curves to draw on the GUI element.</param>
  558. public void SetCurves(CurveDrawInfo[] curveInfos)
  559. {
  560. this.curveInfos = curveInfos;
  561. guiCurveDrawing.SetCurves(curveInfos);
  562. Redraw();
  563. }
  564. /// <summary>
  565. /// Change the physical size of the GUI element.
  566. /// </summary>
  567. /// <param name="width">Width of the element in pixels.</param>
  568. /// <param name="height">Height of the element in pixels.</param>
  569. public void SetSize(int width, int height)
  570. {
  571. this.width = width;
  572. this.height = height;
  573. guiTimeline.SetSize(width, TIMELINE_HEIGHT);
  574. guiEvents.SetSize(height, EVENTS_HEIGHT);
  575. guiCurveDrawing.SetSize(width, height - TIMELINE_HEIGHT - EVENTS_HEIGHT);
  576. guiSidebar.SetSize(SIDEBAR_WIDTH, height - TIMELINE_HEIGHT - EVENTS_HEIGHT);
  577. Redraw();
  578. }
  579. /// <summary>
  580. /// Number of frames per second, used for frame selection and marking.
  581. /// </summary>
  582. /// <param name="fps">Number of prames per second.</param>
  583. public void SetFPS(int fps)
  584. {
  585. guiTimeline.SetFPS(fps);
  586. guiEvents.SetFPS(fps);
  587. guiCurveDrawing.SetFPS(fps);
  588. Redraw();
  589. }
  590. /// <summary>
  591. /// Returns time for a frame with the specified index. Depends on set range and FPS.
  592. /// </summary>
  593. /// <param name="frameIdx">Index of the frame (not a key-frame) to get the time for.</param>
  594. /// <returns>Time of the frame with the provided index. </returns>
  595. public float GetTimeForFrame(int frameIdx)
  596. {
  597. return guiCurveDrawing.GetTimeForFrame(frameIdx);
  598. }
  599. /// <summary>
  600. /// Sets the frame at which to display the frame marker.
  601. /// </summary>
  602. /// <param name="frameIdx">Index of the frame to display the marker on, or -1 to clear the marker.</param>
  603. public void SetMarkedFrame(int frameIdx)
  604. {
  605. markedFrameIdx = frameIdx;
  606. guiTimeline.SetMarkedFrame(frameIdx);
  607. guiEvents.SetMarkedFrame(frameIdx);
  608. guiCurveDrawing.SetMarkedFrame(frameIdx);
  609. Redraw();
  610. }
  611. /// <summary>
  612. /// Adds a new keyframe at the currently selected frame.
  613. /// </summary>
  614. public void AddKeyFrameAtMarker()
  615. {
  616. ClearSelection();
  617. if (!disableCurveEdit)
  618. {
  619. foreach (var curveInfo in curveInfos)
  620. {
  621. float t = guiCurveDrawing.GetTimeForFrame(markedFrameIdx);
  622. float value = curveInfo.curve.Evaluate(t);
  623. curveInfo.curve.AddKeyframe(t, value);
  624. curveInfo.curve.Apply();
  625. }
  626. }
  627. else
  628. ShowReadOnlyMessage();
  629. // TODO - UNDOREDO
  630. OnCurveModified?.Invoke();
  631. guiCurveDrawing.Rebuild();
  632. UpdateEventsGUI();
  633. }
  634. /// <summary>
  635. /// Adds a new event at the currently selected event.
  636. /// </summary>
  637. public void AddEventAtMarker()
  638. {
  639. ClearSelection();
  640. float eventTime = guiEvents.GetTimeForFrame(markedFrameIdx);
  641. EventInfo eventInfo = new EventInfo();
  642. eventInfo.animEvent = new AnimationEvent("", eventTime);
  643. events.Add(eventInfo); // TODO - UNDOREDO
  644. OnEventAdded?.Invoke();
  645. UpdateEventsGUI();
  646. guiCurveDrawing.Rebuild();
  647. StartEventEdit(events.Count - 1);
  648. }
  649. /// <summary>
  650. /// Rebuilds GUI displaying the animation events list.
  651. /// </summary>
  652. private void UpdateEventsGUI()
  653. {
  654. AnimationEvent[] animEvents = new AnimationEvent[events.Count];
  655. bool[] selected = new bool[events.Count];
  656. for (int i = 0; i < events.Count; i++)
  657. {
  658. animEvents[i] = events[i].animEvent;
  659. selected[i] = events[i].selected;
  660. }
  661. guiEvents.SetEvents(animEvents, selected);
  662. guiEvents.Rebuild();
  663. }
  664. /// <summary>
  665. /// Rebuilds the entire curve editor GUI.
  666. /// </summary>
  667. public void Redraw()
  668. {
  669. guiCurveDrawing.Rebuild();
  670. guiTimeline.Rebuild();
  671. guiEvents.Rebuild();
  672. guiSidebar.Rebuild();
  673. }
  674. /// <summary>
  675. /// Changes the tangent mode for all currently selected keyframes.
  676. /// </summary>
  677. /// <param name="mode">Tangent mode to set. If only in or out tangent mode is provided, the mode for the opposite
  678. /// tangent will be kept as is.</param>
  679. private void ChangeSelectionTangentMode(TangentMode mode)
  680. {
  681. if (disableCurveEdit)
  682. {
  683. ShowReadOnlyMessage();
  684. return;
  685. }
  686. foreach (var selectedEntry in selectedKeyframes)
  687. {
  688. EdAnimationCurve curve = curveInfos[selectedEntry.curveIdx].curve;
  689. foreach (var keyframeIdx in selectedEntry.keyIndices)
  690. {
  691. if (mode == TangentMode.Auto || mode == TangentMode.Free)
  692. curve.SetTangentMode(keyframeIdx, mode);
  693. else
  694. {
  695. TangentMode newMode = curve.TangentModes[keyframeIdx];
  696. if (mode.HasFlag((TangentMode) TangentType.In))
  697. {
  698. // Replace only the in tangent mode, keeping the out tangent as is
  699. TangentMode inFlags = (TangentMode.InAuto | TangentMode.InFree | TangentMode.InLinear |
  700. TangentMode.InStep);
  701. newMode &= ~inFlags;
  702. newMode |= (mode & inFlags);
  703. }
  704. else
  705. {
  706. // Replace only the out tangent mode, keeping the in tangent as is
  707. TangentMode outFlags = (TangentMode.OutAuto | TangentMode.OutFree | TangentMode.OutLinear |
  708. TangentMode.OutStep);
  709. newMode &= ~outFlags;
  710. newMode |= (mode & outFlags);
  711. }
  712. curve.SetTangentMode(keyframeIdx, newMode);
  713. }
  714. }
  715. curve.Apply();
  716. }
  717. // TODO - UNDOREDO
  718. OnCurveModified?.Invoke();
  719. guiCurveDrawing.Rebuild();
  720. }
  721. /// <summary>
  722. /// Adds a new keyframe at the position the context menu was opened at.
  723. /// </summary>
  724. private void AddKeyframeAtPosition()
  725. {
  726. Vector2 curveCoord;
  727. if (guiCurveDrawing.PixelToCurveSpace(contextClickPosition, out curveCoord))
  728. {
  729. ClearSelection();
  730. if (!disableCurveEdit)
  731. {
  732. foreach (var curveInfo in curveInfos)
  733. {
  734. float t = curveCoord.x;
  735. float value = curveCoord.y;
  736. curveInfo.curve.AddKeyframe(t, value);
  737. curveInfo.curve.Apply();
  738. }
  739. }
  740. else
  741. ShowReadOnlyMessage();
  742. // TODO - UNDOREDO
  743. OnCurveModified?.Invoke();
  744. guiCurveDrawing.Rebuild();
  745. UpdateEventsGUI();
  746. }
  747. }
  748. /// <summary>
  749. /// Adds a new event at the position the context menu was opened at.
  750. /// </summary>
  751. private void AddEventAtPosition()
  752. {
  753. int frame = guiEvents.GetFrame(contextClickPosition);
  754. if (frame != -1)
  755. {
  756. ClearSelection();
  757. float time = guiEvents.GetTime(contextClickPosition.x);
  758. EventInfo eventInfo = new EventInfo();
  759. eventInfo.animEvent = new AnimationEvent("", time);
  760. events.Add(eventInfo); // TODO - UNDOREDO
  761. OnEventAdded?.Invoke();
  762. UpdateEventsGUI();
  763. guiCurveDrawing.Rebuild();
  764. StartEventEdit(events.Count - 1);
  765. }
  766. }
  767. /// <summary>
  768. /// Removes all currently selected keyframes from the curves.
  769. /// </summary>
  770. private void DeleteSelectedKeyframes()
  771. {
  772. if (!disableCurveEdit)
  773. {
  774. foreach (var selectedEntry in selectedKeyframes)
  775. {
  776. EdAnimationCurve curve = curveInfos[selectedEntry.curveIdx].curve;
  777. // Sort keys from highest to lowest so the indices don't change
  778. selectedEntry.keyIndices.Sort((x, y) =>
  779. {
  780. return y.CompareTo(x);
  781. });
  782. foreach (var keyframeIdx in selectedEntry.keyIndices)
  783. curve.RemoveKeyframe(keyframeIdx);
  784. curve.Apply();
  785. }
  786. }
  787. else
  788. ShowReadOnlyMessage();
  789. // TODO - UNDOREDO
  790. ClearSelection();
  791. OnCurveModified?.Invoke();
  792. guiCurveDrawing.Rebuild();
  793. UpdateEventsGUI();
  794. }
  795. /// <summary>
  796. /// Deletes all currently selected events.
  797. /// </summary>
  798. private void DeleteSelectedEvents()
  799. {
  800. List<EventInfo> newEvents = new List<EventInfo>();
  801. foreach (var entry in events)
  802. {
  803. if(!entry.selected)
  804. newEvents.Add(entry);
  805. }
  806. events = newEvents; // TODO - UNDOREDO
  807. OnEventDeleted?.Invoke();
  808. ClearSelection();
  809. guiCurveDrawing.Rebuild();
  810. UpdateEventsGUI();
  811. }
  812. /// <summary>
  813. /// Unselects any selected keyframes and events.
  814. /// </summary>
  815. private void ClearSelection()
  816. {
  817. guiCurveDrawing.ClearSelectedKeyframes();
  818. selectedKeyframes.Clear();
  819. foreach (var entry in events)
  820. entry.selected = false;
  821. }
  822. /// <summary>
  823. /// Adds the provided keyframe to the selection list (doesn't clear existing ones).
  824. /// </summary>
  825. /// <param name="keyframeRef">Keyframe to select.</param>
  826. private void SelectKeyframe(KeyframeRef keyframeRef)
  827. {
  828. guiCurveDrawing.SelectKeyframe(keyframeRef, true);
  829. if (!IsSelected(keyframeRef))
  830. {
  831. int curveIdx = selectedKeyframes.FindIndex(x =>
  832. {
  833. return x.curveIdx == keyframeRef.curveIdx;
  834. });
  835. if (curveIdx == -1)
  836. {
  837. curveIdx = selectedKeyframes.Count;
  838. SelectedKeyframes newKeyframes = new SelectedKeyframes();
  839. newKeyframes.curveIdx = keyframeRef.curveIdx;
  840. selectedKeyframes.Add(newKeyframes);
  841. }
  842. selectedKeyframes[curveIdx].keyIndices.Add(keyframeRef.keyIdx);
  843. }
  844. }
  845. /// <summary>
  846. /// Checks is the provided keyframe currently selected.
  847. /// </summary>
  848. /// <param name="keyframeRef">Keyframe to check.</param>
  849. /// <returns>True if selected, false otherwise.</returns>
  850. private bool IsSelected(KeyframeRef keyframeRef)
  851. {
  852. int curveIdx = selectedKeyframes.FindIndex(x =>
  853. {
  854. return x.curveIdx == keyframeRef.curveIdx;
  855. });
  856. if (curveIdx == -1)
  857. return false;
  858. int keyIdx = selectedKeyframes[curveIdx].keyIndices.FindIndex(x =>
  859. {
  860. return x == keyframeRef.keyIdx;
  861. });
  862. return keyIdx != -1;
  863. }
  864. /// <summary>
  865. /// Opens the edit window for the currently selected keyframe.
  866. /// </summary>
  867. private void EditSelectedKeyframe()
  868. {
  869. if (disableCurveEdit)
  870. {
  871. ShowReadOnlyMessage();
  872. return;
  873. }
  874. if (selectedKeyframes.Count == 0)
  875. return;
  876. EdAnimationCurve curve = curveInfos[selectedKeyframes[0].curveIdx].curve;
  877. KeyFrame[] keyFrames = curve.KeyFrames;
  878. int keyIndex = selectedKeyframes[0].keyIndices[0];
  879. KeyFrame keyFrame = keyFrames[keyIndex];
  880. Vector2I position = guiCurveDrawing.CurveToPixelSpace(new Vector2(keyFrame.time, keyFrame.value));
  881. Rect2I drawingBounds = GUIUtility.CalculateBounds(drawingPanel, window.GUI);
  882. position.x = MathEx.Clamp(position.x, 0, drawingBounds.width);
  883. position.y = MathEx.Clamp(position.y, 0, drawingBounds.height);
  884. Vector2I windowPos = position + new Vector2I(drawingBounds.x, drawingBounds.y);
  885. KeyframeEditWindow editWindow = DropDownWindow.Open<KeyframeEditWindow>(window, windowPos);
  886. editWindow.Initialize(keyFrame, x =>
  887. {
  888. curve.UpdateKeyframe(keyIndex, x.time, x.value);
  889. curve.Apply();
  890. // TODO UNDOREDO
  891. guiCurveDrawing.Rebuild();
  892. OnCurveModified?.Invoke();
  893. });
  894. }
  895. /// <summary>
  896. /// Opens the edit window for the currently selected event.
  897. /// </summary>
  898. private void EditSelectedEvent()
  899. {
  900. for (int i = 0; i < events.Count; i++)
  901. {
  902. if (events[i].selected)
  903. {
  904. StartEventEdit(i);
  905. break;
  906. }
  907. }
  908. }
  909. /// <summary>
  910. /// Opens the event edit window for the specified event.
  911. /// </summary>
  912. /// <param name="eventIdx">Event index to open the edit window for.</param>
  913. private void StartEventEdit(int eventIdx)
  914. {
  915. AnimationEvent animEvent = events[eventIdx].animEvent;
  916. Vector2I position = new Vector2I();
  917. position.x = guiEvents.GetOffset(animEvent.Time);
  918. position.y = EVENTS_HEIGHT/2;
  919. Rect2I eventBounds = GUIUtility.CalculateBounds(eventsPanel, window.GUI);
  920. Vector2I windowPos = position + new Vector2I(eventBounds.x, eventBounds.y);
  921. SceneObject so = window.SelectedSO;
  922. Component[] components = so.GetComponents();
  923. string[] componentNames = new string[components.Length];
  924. for (int i = 0; i < components.Length; i++)
  925. componentNames[i] = components[i].GetType().Name;
  926. EventEditWindow editWindow = DropDownWindow.Open<EventEditWindow>(window, windowPos);
  927. editWindow.Initialize(animEvent, componentNames, () =>
  928. {
  929. UpdateEventsGUI();
  930. OnEventModified?.Invoke();
  931. });
  932. }
  933. /// <summary>
  934. /// Shows a dialog box that notifies the user that the animation clip is read only.
  935. /// </summary>
  936. private void ShowReadOnlyMessage()
  937. {
  938. LocEdString title = new LocEdString("Warning");
  939. LocEdString message =
  940. new LocEdString("You cannot edit keyframes on animation clips that" +
  941. " are imported from an external file.");
  942. DialogBox.Open(title, message, DialogBox.Type.OK);
  943. }
  944. }
  945. /// <summary>
  946. /// Drop down window that displays input boxes used for editing a keyframe.
  947. /// </summary>
  948. [DefaultSize(120, 80)]
  949. internal class KeyframeEditWindow : DropDownWindow
  950. {
  951. /// <summary>
  952. /// Initializes the drop down window by creating the necessary GUI. Must be called after construction and before
  953. /// use.
  954. /// </summary>
  955. /// <param name="keyFrame">Keyframe whose properties to edit.</param>
  956. /// <param name="updateCallback">Callback triggered when event values change.</param>
  957. internal void Initialize(KeyFrame keyFrame, Action<KeyFrame> updateCallback)
  958. {
  959. GUIFloatField timeField = new GUIFloatField(new LocEdString("Time"), 40, "");
  960. timeField.Value = keyFrame.time;
  961. timeField.OnChanged += x => { keyFrame.time = x; updateCallback(keyFrame); };
  962. GUIFloatField valueField = new GUIFloatField(new LocEdString("Value"), 40, "");
  963. valueField.Value = keyFrame.value;
  964. valueField.OnChanged += x => { keyFrame.value = x; updateCallback(keyFrame); };
  965. GUILayoutY vertLayout = GUI.AddLayoutY();
  966. vertLayout.AddFlexibleSpace();
  967. GUILayoutX horzLayout = vertLayout.AddLayoutX();
  968. horzLayout.AddFlexibleSpace();
  969. GUILayout contentLayout = horzLayout.AddLayoutY();
  970. GUILayout timeLayout = contentLayout.AddLayoutX();
  971. timeLayout.AddSpace(5);
  972. timeLayout.AddElement(timeField);
  973. timeLayout.AddFlexibleSpace();
  974. GUILayout componentLayout = contentLayout.AddLayoutX();
  975. componentLayout.AddSpace(5);
  976. componentLayout.AddElement(valueField);
  977. componentLayout.AddFlexibleSpace();
  978. horzLayout.AddFlexibleSpace();
  979. vertLayout.AddFlexibleSpace();
  980. }
  981. }
  982. /// <summary>
  983. /// Drop down window that displays input boxes used for editing an event.
  984. /// </summary>
  985. [DefaultSize(200, 80)]
  986. internal class EventEditWindow : DropDownWindow
  987. {
  988. /// <summary>
  989. /// Initializes the drop down window by creating the necessary GUI. Must be called after construction and before
  990. /// use.
  991. /// </summary>
  992. /// <param name="animEvent">Event whose properties to edit.</param>
  993. /// <param name="componentNames">List of component names that the user can select from.</param>
  994. /// <param name="updateCallback">Callback triggered when event values change.</param>
  995. internal void Initialize(AnimationEvent animEvent, string[] componentNames, Action updateCallback)
  996. {
  997. int selectedIndex = -1;
  998. string methodName = "";
  999. if (!string.IsNullOrEmpty(animEvent.Name))
  1000. {
  1001. string[] nameEntries = animEvent.Name.Split('/');
  1002. if (nameEntries.Length > 1)
  1003. {
  1004. string typeName = nameEntries[0];
  1005. for (int i = 0; i < componentNames.Length; i++)
  1006. {
  1007. if (componentNames[i] == typeName)
  1008. {
  1009. selectedIndex = i;
  1010. break;
  1011. }
  1012. }
  1013. methodName = nameEntries[nameEntries.Length - 1];
  1014. }
  1015. }
  1016. GUIFloatField timeField = new GUIFloatField(new LocEdString("Time"), 40, "");
  1017. timeField.Value = animEvent.Time;
  1018. timeField.OnChanged += x => { animEvent.Time = x; updateCallback(); }; // TODO UNDOREDO
  1019. GUIListBoxField componentField = new GUIListBoxField(componentNames, new LocEdString("Component"), 40);
  1020. if (selectedIndex != -1)
  1021. componentField.Index = selectedIndex;
  1022. componentField.OnSelectionChanged += x =>
  1023. {
  1024. string compName = "";
  1025. if (x != -1)
  1026. compName = componentNames[x] + "/";
  1027. animEvent.Name = compName + x;
  1028. updateCallback();
  1029. };// TODO UNDOREDO
  1030. GUITextField methodField = new GUITextField(new LocEdString("Method"), 40, false, "", GUIOption.FixedWidth(190));
  1031. methodField.Value = methodName;
  1032. methodField.OnChanged += x =>
  1033. {
  1034. string compName = "";
  1035. if(componentField.Index != -1)
  1036. compName = componentNames[componentField.Index] + "/";
  1037. animEvent.Name = compName + x;
  1038. updateCallback();
  1039. }; // TODO UNDOREDO
  1040. GUILayoutY vertLayout = GUI.AddLayoutY();
  1041. vertLayout.AddFlexibleSpace();
  1042. GUILayoutX horzLayout = vertLayout.AddLayoutX();
  1043. horzLayout.AddFlexibleSpace();
  1044. GUILayout contentLayout = horzLayout.AddLayoutY();
  1045. GUILayout timeLayout = contentLayout.AddLayoutX();
  1046. timeLayout.AddSpace(5);
  1047. timeLayout.AddElement(timeField);
  1048. timeLayout.AddFlexibleSpace();
  1049. GUILayout componentLayout = contentLayout.AddLayoutX();
  1050. componentLayout.AddSpace(5);
  1051. componentLayout.AddElement(componentField);
  1052. componentLayout.AddFlexibleSpace();
  1053. GUILayout methodLayout = contentLayout.AddLayoutX();
  1054. methodLayout.AddSpace(5);
  1055. methodLayout.AddElement(methodField);
  1056. methodLayout.AddFlexibleSpace();
  1057. horzLayout.AddFlexibleSpace();
  1058. vertLayout.AddFlexibleSpace();
  1059. }
  1060. }
  1061. /** @} */
  1062. }