animation_bezier_editor.cpp 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225
  1. /*************************************************************************/
  2. /* animation_bezier_editor.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "animation_bezier_editor.h"
  31. #include "editor/editor_node.h"
  32. float AnimationBezierTrackEdit::_bezier_h_to_pixel(float p_h) {
  33. float h = p_h;
  34. h = (h - v_scroll) / v_zoom;
  35. h = (get_size().height / 2) - h;
  36. return h;
  37. }
  38. static _FORCE_INLINE_ Vector2 _bezier_interp(real_t t, const Vector2 &start, const Vector2 &control_1, const Vector2 &control_2, const Vector2 &end) {
  39. /* Formula from Wikipedia article on Bezier curves. */
  40. real_t omt = (1.0 - t);
  41. real_t omt2 = omt * omt;
  42. real_t omt3 = omt2 * omt;
  43. real_t t2 = t * t;
  44. real_t t3 = t2 * t;
  45. return start * omt3 + control_1 * omt2 * t * 3.0 + control_2 * omt * t2 * 3.0 + end * t3;
  46. }
  47. void AnimationBezierTrackEdit::_draw_track(int p_track, const Color &p_color) {
  48. float scale = timeline->get_zoom_scale();
  49. int limit = timeline->get_name_limit();
  50. int right_limit = get_size().width - timeline->get_buttons_width();
  51. //selection may have altered the order of keys
  52. Map<float, int> key_order;
  53. for (int i = 0; i < animation->track_get_key_count(p_track); i++) {
  54. float ofs = animation->track_get_key_time(p_track, i);
  55. if (moving_selection && track == p_track && selection.has(i)) {
  56. ofs += moving_selection_offset.x;
  57. }
  58. key_order[ofs] = i;
  59. }
  60. for (Map<float, int>::Element *E = key_order.front(); E; E = E->next()) {
  61. int i = E->get();
  62. if (!E->next())
  63. break;
  64. int i_n = E->next()->get();
  65. float offset = animation->track_get_key_time(p_track, i);
  66. float height = animation->bezier_track_get_key_value(p_track, i);
  67. Vector2 out_handle = animation->bezier_track_get_key_out_handle(p_track, i);
  68. if (track == p_track && moving_handle != 0 && moving_handle_key == i) {
  69. out_handle = moving_handle_right;
  70. }
  71. if (moving_selection && track == p_track && selection.has(i)) {
  72. offset += moving_selection_offset.x;
  73. height += moving_selection_offset.y;
  74. }
  75. out_handle += Vector2(offset, height);
  76. float offset_n = animation->track_get_key_time(p_track, i_n);
  77. float height_n = animation->bezier_track_get_key_value(p_track, i_n);
  78. Vector2 in_handle = animation->bezier_track_get_key_in_handle(p_track, i_n);
  79. if (track == p_track && moving_handle != 0 && moving_handle_key == i_n) {
  80. in_handle = moving_handle_left;
  81. }
  82. if (moving_selection && track == p_track && selection.has(i_n)) {
  83. offset_n += moving_selection_offset.x;
  84. height_n += moving_selection_offset.y;
  85. }
  86. in_handle += Vector2(offset_n, height_n);
  87. Vector2 start(offset, height);
  88. Vector2 end(offset_n, height_n);
  89. int from_x = (offset - timeline->get_value()) * scale + limit;
  90. int point_start = from_x;
  91. int to_x = (offset_n - timeline->get_value()) * scale + limit;
  92. int point_end = to_x;
  93. if (from_x > right_limit) //not visible
  94. continue;
  95. if (to_x < limit) //not visible
  96. continue;
  97. from_x = MAX(from_x, limit);
  98. to_x = MIN(to_x, right_limit);
  99. Vector<Vector2> lines;
  100. Vector2 prev_pos;
  101. for (int j = from_x; j <= to_x; j++) {
  102. float t = (j - limit) / scale + timeline->get_value();
  103. float h;
  104. if (j == point_end) {
  105. h = end.y; //make sure it always connects
  106. } else if (j == point_start) {
  107. h = start.y; //make sure it always connects
  108. } else { //custom interpolation, used because it needs to show paths affected by moving the selection or handles
  109. int iterations = 10;
  110. float low = 0;
  111. float high = 1;
  112. float middle;
  113. //narrow high and low as much as possible
  114. for (int k = 0; k < iterations; k++) {
  115. middle = (low + high) / 2;
  116. Vector2 interp = _bezier_interp(middle, start, out_handle, in_handle, end);
  117. if (interp.x < t) {
  118. low = middle;
  119. } else {
  120. high = middle;
  121. }
  122. }
  123. //interpolate the result:
  124. Vector2 low_pos = _bezier_interp(low, start, out_handle, in_handle, end);
  125. Vector2 high_pos = _bezier_interp(high, start, out_handle, in_handle, end);
  126. float c = (t - low_pos.x) / (high_pos.x - low_pos.x);
  127. h = low_pos.linear_interpolate(high_pos, c).y;
  128. }
  129. h = _bezier_h_to_pixel(h);
  130. Vector2 pos(j, h);
  131. if (j > from_x) {
  132. lines.push_back(prev_pos);
  133. lines.push_back(pos);
  134. }
  135. prev_pos = pos;
  136. }
  137. if (lines.size() >= 2) {
  138. draw_multiline(lines, p_color);
  139. }
  140. }
  141. }
  142. void AnimationBezierTrackEdit::_draw_line_clipped(const Vector2 &p_from, const Vector2 &p_to, const Color &p_color, int p_clip_left, int p_clip_right) {
  143. Vector2 from = p_from;
  144. Vector2 to = p_to;
  145. if (from.x == to.x)
  146. return;
  147. if (to.x < from.x) {
  148. SWAP(to, from);
  149. }
  150. if (to.x < p_clip_left)
  151. return;
  152. if (from.x > p_clip_right)
  153. return;
  154. if (to.x > p_clip_right) {
  155. float c = (p_clip_right - from.x) / (to.x - from.x);
  156. to = from.linear_interpolate(to, c);
  157. }
  158. if (from.x < p_clip_left) {
  159. float c = (p_clip_left - from.x) / (to.x - from.x);
  160. from = from.linear_interpolate(to, c);
  161. }
  162. draw_line(from, to, p_color);
  163. }
  164. void AnimationBezierTrackEdit::_notification(int p_what) {
  165. if (p_what == NOTIFICATION_THEME_CHANGED || p_what == NOTIFICATION_ENTER_TREE) {
  166. bezier_icon = get_icon("KeyBezierPoint", "EditorIcons");
  167. bezier_handle_icon = get_icon("KeyBezierHandle", "EditorIcons");
  168. selected_icon = get_icon("KeyBezierSelected", "EditorIcons");
  169. if (handle_mode_option->get_item_count() == 0) {
  170. handle_mode_option->add_icon_item(get_icon("BezierHandlesFree", "EditorIcons"), TTR("Free"), HANDLE_MODE_FREE);
  171. handle_mode_option->add_icon_item(get_icon("BezierHandlesBalanced", "EditorIcons"), TTR("Balanced"), HANDLE_MODE_BALANCED);
  172. handle_mode_option->add_icon_item(get_icon("BezierHandlesMirror", "EditorIcons"), TTR("Mirror"), HANDLE_MODE_MIRROR);
  173. }
  174. }
  175. if (p_what == NOTIFICATION_RESIZED) {
  176. int right_limit = get_size().width - timeline->get_buttons_width();
  177. int hsep = get_constant("hseparation", "ItemList");
  178. int vsep = get_constant("vseparation", "ItemList");
  179. handle_mode_option->set_position(Vector2(right_limit + hsep, get_size().height - handle_mode_option->get_combined_minimum_size().height - vsep));
  180. handle_mode_option->set_size(Vector2(timeline->get_buttons_width() - hsep * 2, handle_mode_option->get_combined_minimum_size().height));
  181. }
  182. if (p_what == NOTIFICATION_DRAW) {
  183. if (animation.is_null())
  184. return;
  185. int limit = timeline->get_name_limit();
  186. if (has_focus()) {
  187. Color accent = get_color("accent_color", "Editor");
  188. accent.a *= 0.7;
  189. draw_rect(Rect2(Point2(), get_size()), accent, false);
  190. }
  191. Ref<Font> font = get_font("font", "Label");
  192. Color color = get_color("font_color", "Label");
  193. int hsep = get_constant("hseparation", "ItemList");
  194. int vsep = get_constant("vseparation", "ItemList");
  195. Color linecolor = color;
  196. linecolor.a = 0.2;
  197. draw_line(Point2(limit, 0), Point2(limit, get_size().height), linecolor);
  198. int right_limit = get_size().width - timeline->get_buttons_width();
  199. draw_line(Point2(right_limit, 0), Point2(right_limit, get_size().height), linecolor);
  200. Ref<Texture> close_icon = get_icon("Close", "EditorIcons");
  201. close_icon_rect.position = Vector2(get_size().width - close_icon->get_width() - hsep, hsep);
  202. close_icon_rect.size = close_icon->get_size();
  203. draw_texture(close_icon, close_icon_rect.position);
  204. String base_path = animation->track_get_path(track);
  205. int end = base_path.find(":");
  206. if (end != -1) {
  207. base_path = base_path.substr(0, end + 1);
  208. }
  209. // NAMES AND ICON
  210. int vofs = vsep;
  211. int margin = 0;
  212. {
  213. int ofs = 0;
  214. NodePath path = animation->track_get_path(track);
  215. Node *node = NULL;
  216. if (root && root->has_node(path)) {
  217. node = root->get_node(path);
  218. }
  219. String text;
  220. int h = font->get_height();
  221. if (node) {
  222. Ref<Texture> icon = EditorNode::get_singleton()->get_object_icon(node, "Node");
  223. h = MAX(h, icon->get_height());
  224. draw_texture(icon, Point2(ofs, vofs + int(h - icon->get_height()) / 2));
  225. margin = icon->get_width();
  226. text = node->get_name();
  227. ofs += hsep;
  228. ofs += icon->get_width();
  229. Vector2 string_pos = Point2(ofs, vofs + (h - font->get_height()) / 2 + font->get_ascent());
  230. string_pos = string_pos.floor();
  231. draw_string(font, string_pos, text, color, limit - ofs - hsep);
  232. vofs += h + vsep;
  233. }
  234. }
  235. // RELATED TRACKS TITLES
  236. Map<int, Color> subtrack_colors;
  237. subtracks.clear();
  238. for (int i = 0; i < animation->get_track_count(); i++) {
  239. if (animation->track_get_type(i) != Animation::TYPE_BEZIER)
  240. continue;
  241. String path = animation->track_get_path(i);
  242. if (!path.begins_with(base_path))
  243. continue; //another node
  244. path = path.replace_first(base_path, "");
  245. Color cc = color;
  246. Rect2 rect = Rect2(margin, vofs, limit - margin - hsep, font->get_height() + vsep);
  247. if (i != track) {
  248. cc.a *= 0.7;
  249. uint32_t hash = path.hash();
  250. hash = ((hash >> 16) ^ hash) * 0x45d9f3b;
  251. hash = ((hash >> 16) ^ hash) * 0x45d9f3b;
  252. hash = (hash >> 16) ^ hash;
  253. float h = (hash % 65535) / 65536.0;
  254. Color subcolor;
  255. subcolor.set_hsv(h, 0.2, 0.8);
  256. subcolor.a = 0.5;
  257. draw_rect(Rect2(0, vofs + font->get_height() * 0.1, margin - hsep, font->get_height() * 0.8), subcolor);
  258. subtrack_colors[i] = subcolor;
  259. subtracks[i] = rect;
  260. } else {
  261. Color ac = get_color("accent_color", "Editor");
  262. ac.a = 0.5;
  263. draw_rect(rect, ac);
  264. }
  265. draw_string(font, Point2(margin, vofs + font->get_ascent()), path, cc, limit - margin - hsep);
  266. vofs += font->get_height() + vsep;
  267. }
  268. Color accent = get_color("accent_color", "Editor");
  269. { //guides
  270. float min_left_scale = font->get_height() + vsep;
  271. float scale = 1;
  272. while (scale / v_zoom < min_left_scale * 2) {
  273. scale *= 5;
  274. }
  275. bool first = true;
  276. int prev_iv = 0;
  277. for (int i = font->get_height(); i < get_size().height; i++) {
  278. float ofs = get_size().height / 2 - i;
  279. ofs *= v_zoom;
  280. ofs += v_scroll;
  281. int iv = int(ofs / scale);
  282. if (ofs < 0)
  283. iv -= 1;
  284. if (!first && iv != prev_iv) {
  285. Color lc = linecolor;
  286. lc.a *= 0.5;
  287. draw_line(Point2(limit, i), Point2(right_limit, i), lc);
  288. Color c = color;
  289. c.a *= 0.5;
  290. draw_string(font, Point2(limit + 8, i - 2), itos((iv + 1) * scale), c);
  291. }
  292. first = false;
  293. prev_iv = iv;
  294. }
  295. }
  296. { //draw OTHER curves
  297. float scale = timeline->get_zoom_scale();
  298. Ref<Texture> point = get_icon("KeyValue", "EditorIcons");
  299. for (Map<int, Color>::Element *E = subtrack_colors.front(); E; E = E->next()) {
  300. _draw_track(E->key(), E->get());
  301. for (int i = 0; i < animation->track_get_key_count(E->key()); i++) {
  302. float offset = animation->track_get_key_time(E->key(), i);
  303. float value = animation->bezier_track_get_key_value(E->key(), i);
  304. Vector2 pos((offset - timeline->get_value()) * scale + limit, _bezier_h_to_pixel(value));
  305. if (pos.x >= limit && pos.x <= right_limit) {
  306. draw_texture(point, pos - point->get_size() / 2, E->get());
  307. }
  308. }
  309. }
  310. //draw edited curve
  311. const Color highlight = get_color("highlight_color", "Editor");
  312. _draw_track(track, highlight);
  313. }
  314. //draw editor handles
  315. {
  316. float scale = timeline->get_zoom_scale();
  317. edit_points.clear();
  318. for (int i = 0; i < animation->track_get_key_count(track); i++) {
  319. float offset = animation->track_get_key_time(track, i);
  320. float value = animation->bezier_track_get_key_value(track, i);
  321. if (moving_selection && selection.has(i)) {
  322. offset += moving_selection_offset.x;
  323. value += moving_selection_offset.y;
  324. }
  325. Vector2 pos((offset - timeline->get_value()) * scale + limit, _bezier_h_to_pixel(value));
  326. Vector2 in_vec = animation->bezier_track_get_key_in_handle(track, i);
  327. if (moving_handle != 0 && moving_handle_key == i) {
  328. in_vec = moving_handle_left;
  329. }
  330. Vector2 pos_in = Vector2(((offset + in_vec.x) - timeline->get_value()) * scale + limit, _bezier_h_to_pixel(value + in_vec.y));
  331. Vector2 out_vec = animation->bezier_track_get_key_out_handle(track, i);
  332. if (moving_handle != 0 && moving_handle_key == i) {
  333. out_vec = moving_handle_right;
  334. }
  335. Vector2 pos_out = Vector2(((offset + out_vec.x) - timeline->get_value()) * scale + limit, _bezier_h_to_pixel(value + out_vec.y));
  336. _draw_line_clipped(pos, pos_in, accent, limit, right_limit);
  337. _draw_line_clipped(pos, pos_out, accent, limit, right_limit);
  338. EditPoint ep;
  339. if (pos.x >= limit && pos.x <= right_limit) {
  340. ep.point_rect.position = (pos - bezier_icon->get_size() / 2).floor();
  341. ep.point_rect.size = bezier_icon->get_size();
  342. if (selection.has(i)) {
  343. draw_texture(selected_icon, ep.point_rect.position);
  344. draw_string(font, ep.point_rect.position + Vector2(8, -font->get_height() - 4), TTR("Time:") + " " + rtos(Math::stepify(offset, 0.001)), accent);
  345. draw_string(font, ep.point_rect.position + Vector2(8, -8), TTR("Value:") + " " + rtos(Math::stepify(value, 0.001)), accent);
  346. } else {
  347. draw_texture(bezier_icon, ep.point_rect.position);
  348. }
  349. ep.point_rect = ep.point_rect.grow(ep.point_rect.size.width * 0.5);
  350. }
  351. if (pos_in.x >= limit && pos_in.x <= right_limit) {
  352. ep.in_rect.position = (pos_in - bezier_handle_icon->get_size() / 2).floor();
  353. ep.in_rect.size = bezier_handle_icon->get_size();
  354. draw_texture(bezier_handle_icon, ep.in_rect.position);
  355. ep.in_rect = ep.in_rect.grow(ep.in_rect.size.width * 0.5);
  356. }
  357. if (pos_out.x >= limit && pos_out.x <= right_limit) {
  358. ep.out_rect.position = (pos_out - bezier_handle_icon->get_size() / 2).floor();
  359. ep.out_rect.size = bezier_handle_icon->get_size();
  360. draw_texture(bezier_handle_icon, ep.out_rect.position);
  361. ep.out_rect = ep.out_rect.grow(ep.out_rect.size.width * 0.5);
  362. }
  363. edit_points.push_back(ep);
  364. }
  365. }
  366. if (box_selecting) {
  367. Color bs = accent;
  368. bs.a *= 0.5;
  369. Vector2 bs_from = box_selection_from;
  370. Vector2 bs_to = box_selection_to;
  371. if (bs_from.x > bs_to.x) {
  372. SWAP(bs_from.x, bs_to.x);
  373. }
  374. if (bs_from.y > bs_to.y) {
  375. SWAP(bs_from.y, bs_to.y);
  376. }
  377. draw_rect(Rect2(bs_from, bs_to - bs_from), bs);
  378. }
  379. #if 0
  380. // KEYFAMES //
  381. {
  382. float scale = timeline->get_zoom_scale();
  383. int limit_end = get_size().width - timeline->get_buttons_width();
  384. for (int i = 0; i < animation->track_get_key_count(track); i++) {
  385. float offset = animation->track_get_key_time(track, i) - timeline->get_value();
  386. if (editor->is_key_selected(track, i) && editor->is_moving_selection()) {
  387. offset += editor->get_moving_selection_offset();
  388. }
  389. offset = offset * scale + limit;
  390. draw_key(i, scale, int(offset), editor->is_key_selected(track, i), limit, limit_end);
  391. }
  392. }
  393. #endif
  394. }
  395. }
  396. Ref<Animation> AnimationBezierTrackEdit::get_animation() const {
  397. return animation;
  398. }
  399. void AnimationBezierTrackEdit::set_animation_and_track(const Ref<Animation> &p_animation, int p_track) {
  400. animation = p_animation;
  401. track = p_track;
  402. if (is_connected("select_key", editor, "_key_selected"))
  403. disconnect("select_key", editor, "_key_selected");
  404. if (is_connected("deselect_key", editor, "_key_deselected"))
  405. disconnect("deselect_key", editor, "_key_deselected");
  406. connect("select_key", editor, "_key_selected", varray(p_track), CONNECT_DEFERRED);
  407. connect("deselect_key", editor, "_key_deselected", varray(p_track), CONNECT_DEFERRED);
  408. update();
  409. }
  410. Size2 AnimationBezierTrackEdit::get_minimum_size() const {
  411. return Vector2(1, 1);
  412. }
  413. void AnimationBezierTrackEdit::set_undo_redo(UndoRedo *p_undo_redo) {
  414. undo_redo = p_undo_redo;
  415. }
  416. void AnimationBezierTrackEdit::set_timeline(AnimationTimelineEdit *p_timeline) {
  417. timeline = p_timeline;
  418. timeline->connect("zoom_changed", this, "_zoom_changed");
  419. }
  420. void AnimationBezierTrackEdit::set_editor(AnimationTrackEditor *p_editor) {
  421. editor = p_editor;
  422. connect("clear_selection", editor, "_clear_selection");
  423. }
  424. void AnimationBezierTrackEdit::_play_position_draw() {
  425. if (!animation.is_valid() || play_position_pos < 0)
  426. return;
  427. float scale = timeline->get_zoom_scale();
  428. int h = get_size().height;
  429. int px = (-timeline->get_value() + play_position_pos) * scale + timeline->get_name_limit();
  430. if (px >= timeline->get_name_limit() && px < (get_size().width - timeline->get_buttons_width())) {
  431. Color color = get_color("accent_color", "Editor");
  432. play_position->draw_line(Point2(px, 0), Point2(px, h), color);
  433. }
  434. }
  435. void AnimationBezierTrackEdit::set_play_position(float p_pos) {
  436. play_position_pos = p_pos;
  437. play_position->update();
  438. }
  439. void AnimationBezierTrackEdit::update_play_position() {
  440. play_position->update();
  441. }
  442. void AnimationBezierTrackEdit::set_root(Node *p_root) {
  443. root = p_root;
  444. }
  445. void AnimationBezierTrackEdit::_zoom_changed() {
  446. update();
  447. }
  448. String AnimationBezierTrackEdit::get_tooltip(const Point2 &p_pos) const {
  449. return Control::get_tooltip(p_pos);
  450. }
  451. void AnimationBezierTrackEdit::_clear_selection() {
  452. selection.clear();
  453. emit_signal("clear_selection");
  454. update();
  455. }
  456. void AnimationBezierTrackEdit::_clear_selection_for_anim(const Ref<Animation> &p_anim) {
  457. if (!(animation == p_anim))
  458. return;
  459. //selection.clear();
  460. _clear_selection();
  461. }
  462. void AnimationBezierTrackEdit::_select_at_anim(const Ref<Animation> &p_anim, int p_track, float p_pos) {
  463. if (!(animation == p_anim))
  464. return;
  465. int idx = animation->track_find_key(p_track, p_pos, true);
  466. ERR_FAIL_COND(idx < 0);
  467. selection.insert(idx);
  468. emit_signal("select_key", idx, true);
  469. update();
  470. }
  471. void AnimationBezierTrackEdit::_gui_input(const Ref<InputEvent> &p_event) {
  472. if (p_event->is_pressed()) {
  473. if (ED_GET_SHORTCUT("animation_editor/duplicate_selection")->is_shortcut(p_event)) {
  474. duplicate_selection();
  475. accept_event();
  476. }
  477. if (ED_GET_SHORTCUT("animation_editor/delete_selection")->is_shortcut(p_event)) {
  478. delete_selection();
  479. accept_event();
  480. }
  481. }
  482. Ref<InputEventMouseButton> mb = p_event;
  483. if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_WHEEL_DOWN) {
  484. if (mb->get_command()) {
  485. timeline->get_zoom()->set_value(timeline->get_zoom()->get_value() * 1.05);
  486. } else {
  487. if (v_zoom < 1000) {
  488. v_zoom *= 1.2;
  489. }
  490. }
  491. update();
  492. }
  493. if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_WHEEL_UP) {
  494. if (mb->get_command()) {
  495. timeline->get_zoom()->set_value(timeline->get_zoom()->get_value() / 1.05);
  496. } else {
  497. if (v_zoom > 0.01) {
  498. v_zoom /= 1.2;
  499. }
  500. }
  501. update();
  502. }
  503. if (mb.is_valid() && mb->get_button_index() == BUTTON_MIDDLE) {
  504. if (mb->is_pressed()) {
  505. int x = mb->get_position().x - timeline->get_name_limit();
  506. panning_timeline_from = x / timeline->get_zoom_scale();
  507. panning_timeline = true;
  508. panning_timeline_at = timeline->get_value();
  509. } else {
  510. panning_timeline = false;
  511. }
  512. }
  513. if (mb.is_valid() && mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed()) {
  514. menu_insert_key = mb->get_position();
  515. if (menu_insert_key.x >= timeline->get_name_limit() && menu_insert_key.x <= get_size().width - timeline->get_buttons_width()) {
  516. Vector2 popup_pos = get_global_transform().xform(mb->get_position());
  517. menu->clear();
  518. menu->add_icon_item(bezier_icon, TTR("Insert Key Here"), MENU_KEY_INSERT);
  519. if (selection.size()) {
  520. menu->add_separator();
  521. menu->add_icon_item(get_icon("Duplicate", "EditorIcons"), TTR("Duplicate Selected Key(s)"), MENU_KEY_DUPLICATE);
  522. menu->add_separator();
  523. menu->add_icon_item(get_icon("Remove", "EditorIcons"), TTR("Delete Selected Key(s)"), MENU_KEY_DELETE);
  524. }
  525. menu->set_as_minsize();
  526. menu->set_position(popup_pos);
  527. menu->popup();
  528. }
  529. }
  530. if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
  531. if (close_icon_rect.has_point(mb->get_position())) {
  532. emit_signal("close_request");
  533. return;
  534. }
  535. for (Map<int, Rect2>::Element *E = subtracks.front(); E; E = E->next()) {
  536. if (E->get().has_point(mb->get_position())) {
  537. set_animation_and_track(animation, E->key());
  538. _clear_selection();
  539. return;
  540. }
  541. }
  542. for (int i = 0; i < edit_points.size(); i++) {
  543. //first check point
  544. //command makes it ignore the main point, so control point editors can be force-edited
  545. //path 2D editing in the 3D and 2D editors works the same way
  546. if (!mb->get_command()) {
  547. if (edit_points[i].point_rect.has_point(mb->get_position())) {
  548. if (mb->get_shift()) {
  549. //add to selection
  550. if (selection.has(i)) {
  551. selection.erase(i);
  552. } else {
  553. selection.insert(i);
  554. }
  555. update();
  556. select_single_attempt = -1;
  557. } else if (selection.has(i)) {
  558. moving_selection_attempt = true;
  559. moving_selection = false;
  560. moving_selection_from_key = i;
  561. moving_selection_offset = Vector2();
  562. select_single_attempt = i;
  563. update();
  564. } else {
  565. moving_selection_attempt = true;
  566. moving_selection = true;
  567. moving_selection_from_key = i;
  568. moving_selection_offset = Vector2();
  569. selection.clear();
  570. selection.insert(i);
  571. update();
  572. }
  573. return;
  574. }
  575. }
  576. if (edit_points[i].in_rect.has_point(mb->get_position())) {
  577. moving_handle = -1;
  578. moving_handle_key = i;
  579. moving_handle_left = animation->bezier_track_get_key_in_handle(track, i);
  580. moving_handle_right = animation->bezier_track_get_key_out_handle(track, i);
  581. update();
  582. return;
  583. }
  584. if (edit_points[i].out_rect.has_point(mb->get_position())) {
  585. moving_handle = 1;
  586. moving_handle_key = i;
  587. moving_handle_left = animation->bezier_track_get_key_in_handle(track, i);
  588. moving_handle_right = animation->bezier_track_get_key_out_handle(track, i);
  589. update();
  590. return;
  591. ;
  592. }
  593. }
  594. //insert new point
  595. if (mb->get_command() && mb->get_position().x >= timeline->get_name_limit() && mb->get_position().x < get_size().width - timeline->get_buttons_width()) {
  596. Array new_point;
  597. new_point.resize(5);
  598. float h = (get_size().height / 2 - mb->get_position().y) * v_zoom + v_scroll;
  599. new_point[0] = h;
  600. new_point[1] = -0.25;
  601. new_point[2] = 0;
  602. new_point[3] = 0.25;
  603. new_point[4] = 0;
  604. float time = ((mb->get_position().x - timeline->get_name_limit()) / timeline->get_zoom_scale()) + timeline->get_value();
  605. while (animation->track_find_key(track, time, true) != -1) {
  606. time += 0.001;
  607. }
  608. undo_redo->create_action(TTR("Add Bezier Point"));
  609. undo_redo->add_do_method(animation.ptr(), "track_insert_key", track, time, new_point);
  610. undo_redo->add_undo_method(animation.ptr(), "track_remove_key_at_position", track, time);
  611. undo_redo->commit_action();
  612. //then attempt to move
  613. int index = animation->track_find_key(track, time, true);
  614. ERR_FAIL_COND(index == -1);
  615. _clear_selection();
  616. selection.insert(index);
  617. moving_selection_attempt = true;
  618. moving_selection = false;
  619. moving_selection_from_key = index;
  620. moving_selection_offset = Vector2();
  621. select_single_attempt = -1;
  622. update();
  623. return;
  624. }
  625. //box select
  626. if (mb->get_position().x >= timeline->get_name_limit() && mb->get_position().x < get_size().width - timeline->get_buttons_width()) {
  627. box_selecting_attempt = true;
  628. box_selecting = false;
  629. box_selecting_add = false;
  630. box_selection_from = mb->get_position();
  631. return;
  632. }
  633. }
  634. if (box_selecting_attempt && mb.is_valid() && !mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
  635. if (box_selecting) {
  636. //do actual select
  637. if (!box_selecting_add) {
  638. _clear_selection();
  639. }
  640. Vector2 bs_from = box_selection_from;
  641. Vector2 bs_to = box_selection_to;
  642. if (bs_from.x > bs_to.x) {
  643. SWAP(bs_from.x, bs_to.x);
  644. }
  645. if (bs_from.y > bs_to.y) {
  646. SWAP(bs_from.y, bs_to.y);
  647. }
  648. Rect2 selection_rect(bs_from, bs_to - bs_from);
  649. for (int i = 0; i < edit_points.size(); i++) {
  650. if (edit_points[i].point_rect.intersects(selection_rect)) {
  651. selection.insert(i);
  652. }
  653. }
  654. } else {
  655. _clear_selection(); //clicked and nothing happened, so clear the selection
  656. }
  657. box_selecting_attempt = false;
  658. box_selecting = false;
  659. update();
  660. }
  661. if (moving_handle != 0 && mb.is_valid() && !mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
  662. undo_redo->create_action(TTR("Move Bezier Points"));
  663. undo_redo->add_do_method(animation.ptr(), "bezier_track_set_key_in_handle", track, moving_handle_key, moving_handle_left);
  664. undo_redo->add_do_method(animation.ptr(), "bezier_track_set_key_out_handle", track, moving_handle_key, moving_handle_right);
  665. undo_redo->add_undo_method(animation.ptr(), "bezier_track_set_key_in_handle", track, moving_handle_key, animation->bezier_track_get_key_in_handle(track, moving_handle_key));
  666. undo_redo->add_undo_method(animation.ptr(), "bezier_track_set_key_out_handle", track, moving_handle_key, animation->bezier_track_get_key_out_handle(track, moving_handle_key));
  667. undo_redo->commit_action();
  668. moving_handle = 0;
  669. update();
  670. }
  671. if (moving_selection_attempt && mb.is_valid() && !mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
  672. if (moving_selection) {
  673. //combit it
  674. undo_redo->create_action(TTR("Move Bezier Points"));
  675. List<AnimMoveRestore> to_restore;
  676. // 1-remove the keys
  677. for (Set<int>::Element *E = selection.back(); E; E = E->prev()) {
  678. undo_redo->add_do_method(animation.ptr(), "track_remove_key", track, E->get());
  679. }
  680. // 2- remove overlapped keys
  681. for (Set<int>::Element *E = selection.back(); E; E = E->prev()) {
  682. float newtime = editor->snap_time(animation->track_get_key_time(track, E->get()) + moving_selection_offset.x);
  683. int idx = animation->track_find_key(track, newtime, true);
  684. if (idx == -1)
  685. continue;
  686. if (selection.has(idx))
  687. continue; //already in selection, don't save
  688. undo_redo->add_do_method(animation.ptr(), "track_remove_key_at_position", track, newtime);
  689. AnimMoveRestore amr;
  690. amr.key = animation->track_get_key_value(track, idx);
  691. amr.track = track;
  692. amr.time = newtime;
  693. to_restore.push_back(amr);
  694. }
  695. // 3-move the keys (re insert them)
  696. for (Set<int>::Element *E = selection.back(); E; E = E->prev()) {
  697. float newpos = editor->snap_time(animation->track_get_key_time(track, E->get()) + moving_selection_offset.x);
  698. /*
  699. if (newpos<0)
  700. continue; //no add at the beginning
  701. */
  702. Array key = animation->track_get_key_value(track, E->get());
  703. float h = key[0];
  704. h += moving_selection_offset.y;
  705. key[0] = h;
  706. undo_redo->add_do_method(animation.ptr(), "track_insert_key", track, newpos, key, 1);
  707. }
  708. // 4-(undo) remove inserted keys
  709. for (Set<int>::Element *E = selection.back(); E; E = E->prev()) {
  710. float newpos = editor->snap_time(animation->track_get_key_time(track, E->get()) + moving_selection_offset.x);
  711. /*
  712. if (newpos<0)
  713. continue; //no remove what no inserted
  714. */
  715. undo_redo->add_undo_method(animation.ptr(), "track_remove_key_at_position", track, newpos);
  716. }
  717. // 5-(undo) reinsert keys
  718. for (Set<int>::Element *E = selection.back(); E; E = E->prev()) {
  719. float oldpos = animation->track_get_key_time(track, E->get());
  720. undo_redo->add_undo_method(animation.ptr(), "track_insert_key", track, oldpos, animation->track_get_key_value(track, E->get()), 1);
  721. }
  722. // 6-(undo) reinsert overlapped keys
  723. for (List<AnimMoveRestore>::Element *E = to_restore.front(); E; E = E->next()) {
  724. AnimMoveRestore &amr = E->get();
  725. undo_redo->add_undo_method(animation.ptr(), "track_insert_key", amr.track, amr.time, amr.key, 1);
  726. }
  727. // 6-(undo) reinsert overlapped keys
  728. for (List<AnimMoveRestore>::Element *E = to_restore.front(); E; E = E->next()) {
  729. AnimMoveRestore &amr = E->get();
  730. undo_redo->add_undo_method(animation.ptr(), "track_insert_key", amr.track, amr.time, amr.key, 1);
  731. }
  732. undo_redo->add_do_method(this, "_clear_selection_for_anim", animation);
  733. undo_redo->add_undo_method(this, "_clear_selection_for_anim", animation);
  734. // 7-reselect
  735. for (Set<int>::Element *E = selection.back(); E; E = E->prev()) {
  736. float oldpos = animation->track_get_key_time(track, E->get());
  737. float newpos = editor->snap_time(oldpos + moving_selection_offset.x);
  738. undo_redo->add_do_method(this, "_select_at_anim", animation, track, newpos);
  739. undo_redo->add_undo_method(this, "_select_at_anim", animation, track, oldpos);
  740. }
  741. undo_redo->commit_action();
  742. moving_selection = false;
  743. } else if (select_single_attempt != -1) {
  744. selection.clear();
  745. selection.insert(select_single_attempt);
  746. }
  747. moving_selection_attempt = false;
  748. update();
  749. }
  750. Ref<InputEventMouseMotion> mm = p_event;
  751. if (mm.is_valid() && mm->get_button_mask() & BUTTON_MASK_MIDDLE) {
  752. v_scroll += mm->get_relative().y * v_zoom;
  753. if (v_scroll > 100000)
  754. v_scroll = 100000;
  755. if (v_scroll < -100000)
  756. v_scroll = -100000;
  757. int x = mm->get_position().x - timeline->get_name_limit();
  758. float ofs = x / timeline->get_zoom_scale();
  759. float diff = ofs - panning_timeline_from;
  760. timeline->set_value(panning_timeline_at - diff);
  761. update();
  762. }
  763. if (moving_selection_attempt && mm.is_valid()) {
  764. if (!moving_selection) {
  765. moving_selection = true;
  766. select_single_attempt = -1;
  767. }
  768. float y = (get_size().height / 2 - mm->get_position().y) * v_zoom + v_scroll;
  769. float x = editor->snap_time(((mm->get_position().x - timeline->get_name_limit()) / timeline->get_zoom_scale()) + timeline->get_value());
  770. moving_selection_offset = Vector2(x - animation->track_get_key_time(track, moving_selection_from_key), y - animation->bezier_track_get_key_value(track, moving_selection_from_key));
  771. update();
  772. }
  773. if (box_selecting_attempt && mm.is_valid()) {
  774. if (!box_selecting) {
  775. box_selecting = true;
  776. box_selecting_add = mm->get_shift();
  777. }
  778. box_selection_to = mm->get_position();
  779. if (get_local_mouse_position().y < 0) {
  780. //avoid cursor from going too above, so it does not lose focus with viewport
  781. warp_mouse(Vector2(get_local_mouse_position().x, 0));
  782. }
  783. update();
  784. }
  785. if (moving_handle != 0 && mm.is_valid()) {
  786. float y = (get_size().height / 2 - mm->get_position().y) * v_zoom + v_scroll;
  787. float x = ((mm->get_position().x - timeline->get_name_limit()) / timeline->get_zoom_scale()) + timeline->get_value();
  788. Vector2 key_pos = Vector2(animation->track_get_key_time(track, moving_handle_key), animation->bezier_track_get_key_value(track, moving_handle_key));
  789. Vector2 moving_handle_value = Vector2(x, y) - key_pos;
  790. moving_handle_left = animation->bezier_track_get_key_in_handle(track, moving_handle_key);
  791. moving_handle_right = animation->bezier_track_get_key_out_handle(track, moving_handle_key);
  792. if (moving_handle == -1) {
  793. moving_handle_left = moving_handle_value;
  794. if (moving_handle_left.x > 0) {
  795. moving_handle_left.x = 0;
  796. }
  797. if (handle_mode_option->get_selected() == HANDLE_MODE_BALANCED) {
  798. Vector2 scale = Vector2(timeline->get_zoom_scale(), v_zoom);
  799. moving_handle_right = (-(moving_handle_left * scale).normalized() * (moving_handle_right * scale).length()) / scale;
  800. } else if (handle_mode_option->get_selected() == HANDLE_MODE_MIRROR) {
  801. moving_handle_right = -moving_handle_left;
  802. }
  803. }
  804. if (moving_handle == 1) {
  805. moving_handle_right = moving_handle_value;
  806. if (moving_handle_right.x < 0) {
  807. moving_handle_right.x = 0;
  808. }
  809. if (handle_mode_option->get_selected() == HANDLE_MODE_BALANCED) {
  810. Vector2 scale = Vector2(timeline->get_zoom_scale(), v_zoom);
  811. moving_handle_left = (-(moving_handle_right * scale).normalized() * (moving_handle_left * scale).length()) / scale;
  812. } else if (handle_mode_option->get_selected() == HANDLE_MODE_MIRROR) {
  813. moving_handle_left = -moving_handle_right;
  814. }
  815. }
  816. update();
  817. }
  818. }
  819. void AnimationBezierTrackEdit::_menu_selected(int p_index) {
  820. switch (p_index) {
  821. case MENU_KEY_INSERT: {
  822. Array new_point;
  823. new_point.resize(5);
  824. float h = (get_size().height / 2 - menu_insert_key.y) * v_zoom + v_scroll;
  825. new_point[0] = h;
  826. new_point[1] = -0.25;
  827. new_point[2] = 0;
  828. new_point[3] = 0.25;
  829. new_point[4] = 0;
  830. float time = ((menu_insert_key.x - timeline->get_name_limit()) / timeline->get_zoom_scale()) + timeline->get_value();
  831. while (animation->track_find_key(track, time, true) != -1) {
  832. time += 0.001;
  833. }
  834. undo_redo->create_action(TTR("Add Bezier Point"));
  835. undo_redo->add_do_method(animation.ptr(), "track_insert_key", track, time, new_point);
  836. undo_redo->add_undo_method(animation.ptr(), "track_remove_key_at_position", track, time);
  837. undo_redo->commit_action();
  838. } break;
  839. case MENU_KEY_DUPLICATE: {
  840. duplicate_selection();
  841. } break;
  842. case MENU_KEY_DELETE: {
  843. delete_selection();
  844. } break;
  845. }
  846. }
  847. void AnimationBezierTrackEdit::duplicate_selection() {
  848. if (selection.size() == 0)
  849. return;
  850. float top_time = 1e10;
  851. for (Set<int>::Element *E = selection.back(); E; E = E->prev()) {
  852. float t = animation->track_get_key_time(track, E->get());
  853. if (t < top_time)
  854. top_time = t;
  855. }
  856. undo_redo->create_action(TTR("Anim Duplicate Keys"));
  857. List<Pair<int, float> > new_selection_values;
  858. for (Set<int>::Element *E = selection.back(); E; E = E->prev()) {
  859. float t = animation->track_get_key_time(track, E->get());
  860. float dst_time = t + (timeline->get_play_position() - top_time);
  861. int existing_idx = animation->track_find_key(track, dst_time, true);
  862. undo_redo->add_do_method(animation.ptr(), "track_insert_key", track, dst_time, animation->track_get_key_value(track, E->get()), animation->track_get_key_transition(track, E->get()));
  863. undo_redo->add_undo_method(animation.ptr(), "track_remove_key_at_position", track, dst_time);
  864. Pair<int, float> p;
  865. p.first = track;
  866. p.second = dst_time;
  867. new_selection_values.push_back(p);
  868. if (existing_idx != -1) {
  869. undo_redo->add_undo_method(animation.ptr(), "track_insert_key", track, dst_time, animation->track_get_key_value(track, existing_idx), animation->track_get_key_transition(track, existing_idx));
  870. }
  871. }
  872. undo_redo->commit_action();
  873. //reselect duplicated
  874. selection.clear();
  875. for (List<Pair<int, float> >::Element *E = new_selection_values.front(); E; E = E->next()) {
  876. int track = E->get().first;
  877. float time = E->get().second;
  878. int existing_idx = animation->track_find_key(track, time, true);
  879. if (existing_idx == -1)
  880. continue;
  881. selection.insert(existing_idx);
  882. }
  883. update();
  884. }
  885. void AnimationBezierTrackEdit::delete_selection() {
  886. if (selection.size()) {
  887. undo_redo->create_action(TTR("Anim Delete Keys"));
  888. for (Set<int>::Element *E = selection.back(); E; E = E->prev()) {
  889. undo_redo->add_do_method(animation.ptr(), "track_remove_key", track, E->get());
  890. undo_redo->add_undo_method(animation.ptr(), "track_insert_key", track, animation->track_get_key_time(track, E->get()), animation->track_get_key_value(track, E->get()), 1);
  891. }
  892. undo_redo->add_do_method(this, "_clear_selection_for_anim", animation);
  893. undo_redo->add_undo_method(this, "_clear_selection_for_anim", animation);
  894. undo_redo->commit_action();
  895. //selection.clear();
  896. }
  897. }
  898. void AnimationBezierTrackEdit::set_block_animation_update_ptr(bool *p_block_ptr) {
  899. block_animation_update_ptr = p_block_ptr;
  900. }
  901. void AnimationBezierTrackEdit::_bind_methods() {
  902. ClassDB::bind_method("_zoom_changed", &AnimationBezierTrackEdit::_zoom_changed);
  903. ClassDB::bind_method("_menu_selected", &AnimationBezierTrackEdit::_menu_selected);
  904. ClassDB::bind_method("_gui_input", &AnimationBezierTrackEdit::_gui_input);
  905. ClassDB::bind_method("_play_position_draw", &AnimationBezierTrackEdit::_play_position_draw);
  906. ClassDB::bind_method("_clear_selection", &AnimationBezierTrackEdit::_clear_selection);
  907. ClassDB::bind_method("_clear_selection_for_anim", &AnimationBezierTrackEdit::_clear_selection_for_anim);
  908. ClassDB::bind_method("_select_at_anim", &AnimationBezierTrackEdit::_select_at_anim);
  909. ADD_SIGNAL(MethodInfo("timeline_changed", PropertyInfo(Variant::REAL, "position"), PropertyInfo(Variant::BOOL, "drag")));
  910. ADD_SIGNAL(MethodInfo("remove_request", PropertyInfo(Variant::INT, "track")));
  911. ADD_SIGNAL(MethodInfo("insert_key", PropertyInfo(Variant::REAL, "ofs")));
  912. ADD_SIGNAL(MethodInfo("select_key", PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::BOOL, "single")));
  913. ADD_SIGNAL(MethodInfo("deselect_key", PropertyInfo(Variant::INT, "index")));
  914. ADD_SIGNAL(MethodInfo("clear_selection"));
  915. ADD_SIGNAL(MethodInfo("close_request"));
  916. ADD_SIGNAL(MethodInfo("move_selection_begin"));
  917. ADD_SIGNAL(MethodInfo("move_selection", PropertyInfo(Variant::REAL, "ofs")));
  918. ADD_SIGNAL(MethodInfo("move_selection_commit"));
  919. ADD_SIGNAL(MethodInfo("move_selection_cancel"));
  920. }
  921. AnimationBezierTrackEdit::AnimationBezierTrackEdit() {
  922. undo_redo = NULL;
  923. timeline = NULL;
  924. root = NULL;
  925. menu = NULL;
  926. block_animation_update_ptr = NULL;
  927. moving_selection_attempt = false;
  928. moving_selection = false;
  929. select_single_attempt = -1;
  930. box_selecting = false;
  931. box_selecting_attempt = false;
  932. moving_handle = 0;
  933. play_position_pos = 0;
  934. play_position = memnew(Control);
  935. play_position->set_mouse_filter(MOUSE_FILTER_PASS);
  936. add_child(play_position);
  937. play_position->set_anchors_and_margins_preset(PRESET_WIDE);
  938. play_position->connect("draw", this, "_play_position_draw");
  939. set_focus_mode(FOCUS_CLICK);
  940. v_scroll = 0;
  941. v_zoom = 1;
  942. panning_timeline = false;
  943. set_clip_contents(true);
  944. handle_mode = HANDLE_MODE_FREE;
  945. handle_mode_option = memnew(OptionButton);
  946. add_child(handle_mode_option);
  947. menu = memnew(PopupMenu);
  948. add_child(menu);
  949. menu->connect("id_pressed", this, "_menu_selected");
  950. //set_mouse_filter(MOUSE_FILTER_PASS); //scroll has to work too for selection
  951. }