animation_bezier_editor.cpp 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201
  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-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 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.lerp(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.lerp(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.lerp(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_theme_icon("KeyBezierPoint", "EditorIcons");
  167. bezier_handle_icon = get_theme_icon("KeyBezierHandle", "EditorIcons");
  168. selected_icon = get_theme_icon("KeyBezierSelected", "EditorIcons");
  169. if (handle_mode_option->get_item_count() == 0) {
  170. handle_mode_option->add_icon_item(get_theme_icon("BezierHandlesFree", "EditorIcons"), TTR("Free"), HANDLE_MODE_FREE);
  171. handle_mode_option->add_icon_item(get_theme_icon("BezierHandlesBalanced", "EditorIcons"), TTR("Balanced"), HANDLE_MODE_BALANCED);
  172. handle_mode_option->add_icon_item(get_theme_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_theme_constant("hseparation", "ItemList");
  178. int vsep = get_theme_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_theme_color("accent_color", "Editor");
  188. accent.a *= 0.7;
  189. draw_rect(Rect2(Point2(), get_size()), accent, false);
  190. }
  191. Ref<Font> font = get_theme_font("font", "Label");
  192. Color color = get_theme_color("font_color", "Label");
  193. int hsep = get_theme_constant("hseparation", "ItemList");
  194. int vsep = get_theme_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<Texture2D> close_icon = get_theme_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. NodePath path = animation->track_get_path(track);
  214. Node *node = nullptr;
  215. if (root && root->has_node(path)) {
  216. node = root->get_node(path);
  217. }
  218. String text;
  219. int h = font->get_height();
  220. if (node) {
  221. int ofs = 0;
  222. Ref<Texture2D> 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_theme_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_theme_color("accent_color", "Editor");
  269. { //guides
  270. float min_left_scale = font->get_height() + vsep;
  271. float scale = (min_left_scale * 2) * v_zoom;
  272. float step = Math::pow(10.0, Math::round(Math::log(scale / 5.0) / Math::log(10.0))) * 5.0;
  273. scale = Math::stepify(scale, step);
  274. while (scale / v_zoom < min_left_scale * 2) {
  275. scale += step;
  276. }
  277. bool first = true;
  278. int prev_iv = 0;
  279. for (int i = font->get_height(); i < get_size().height; i++) {
  280. float ofs = get_size().height / 2 - i;
  281. ofs *= v_zoom;
  282. ofs += v_scroll;
  283. int iv = int(ofs / scale);
  284. if (ofs < 0)
  285. iv -= 1;
  286. if (!first && iv != prev_iv) {
  287. Color lc = linecolor;
  288. lc.a *= 0.5;
  289. draw_line(Point2(limit, i), Point2(right_limit, i), lc);
  290. Color c = color;
  291. c.a *= 0.5;
  292. draw_string(font, Point2(limit + 8, i - 2), rtos(Math::stepify((iv + 1) * scale, step)), c);
  293. }
  294. first = false;
  295. prev_iv = iv;
  296. }
  297. }
  298. { //draw OTHER curves
  299. float scale = timeline->get_zoom_scale();
  300. Ref<Texture2D> point = get_theme_icon("KeyValue", "EditorIcons");
  301. for (Map<int, Color>::Element *E = subtrack_colors.front(); E; E = E->next()) {
  302. _draw_track(E->key(), E->get());
  303. for (int i = 0; i < animation->track_get_key_count(E->key()); i++) {
  304. float offset = animation->track_get_key_time(E->key(), i);
  305. float value = animation->bezier_track_get_key_value(E->key(), i);
  306. Vector2 pos((offset - timeline->get_value()) * scale + limit, _bezier_h_to_pixel(value));
  307. if (pos.x >= limit && pos.x <= right_limit) {
  308. draw_texture(point, pos - point->get_size() / 2, E->get());
  309. }
  310. }
  311. }
  312. //draw edited curve
  313. const Color highlight = get_theme_color("highlight_color", "Editor");
  314. _draw_track(track, highlight);
  315. }
  316. //draw editor handles
  317. {
  318. float scale = timeline->get_zoom_scale();
  319. edit_points.clear();
  320. for (int i = 0; i < animation->track_get_key_count(track); i++) {
  321. float offset = animation->track_get_key_time(track, i);
  322. float value = animation->bezier_track_get_key_value(track, i);
  323. if (moving_selection && selection.has(i)) {
  324. offset += moving_selection_offset.x;
  325. value += moving_selection_offset.y;
  326. }
  327. Vector2 pos((offset - timeline->get_value()) * scale + limit, _bezier_h_to_pixel(value));
  328. Vector2 in_vec = animation->bezier_track_get_key_in_handle(track, i);
  329. if (moving_handle != 0 && moving_handle_key == i) {
  330. in_vec = moving_handle_left;
  331. }
  332. Vector2 pos_in = Vector2(((offset + in_vec.x) - timeline->get_value()) * scale + limit, _bezier_h_to_pixel(value + in_vec.y));
  333. Vector2 out_vec = animation->bezier_track_get_key_out_handle(track, i);
  334. if (moving_handle != 0 && moving_handle_key == i) {
  335. out_vec = moving_handle_right;
  336. }
  337. Vector2 pos_out = Vector2(((offset + out_vec.x) - timeline->get_value()) * scale + limit, _bezier_h_to_pixel(value + out_vec.y));
  338. _draw_line_clipped(pos, pos_in, accent, limit, right_limit);
  339. _draw_line_clipped(pos, pos_out, accent, limit, right_limit);
  340. EditPoint ep;
  341. if (pos.x >= limit && pos.x <= right_limit) {
  342. ep.point_rect.position = (pos - bezier_icon->get_size() / 2).floor();
  343. ep.point_rect.size = bezier_icon->get_size();
  344. if (selection.has(i)) {
  345. draw_texture(selected_icon, ep.point_rect.position);
  346. draw_string(font, ep.point_rect.position + Vector2(8, -font->get_height() - 4), TTR("Time:") + " " + rtos(Math::stepify(offset, 0.001)), accent);
  347. draw_string(font, ep.point_rect.position + Vector2(8, -8), TTR("Value:") + " " + rtos(Math::stepify(value, 0.001)), accent);
  348. } else {
  349. draw_texture(bezier_icon, ep.point_rect.position);
  350. }
  351. ep.point_rect = ep.point_rect.grow(ep.point_rect.size.width * 0.5);
  352. }
  353. if (pos_in.x >= limit && pos_in.x <= right_limit) {
  354. ep.in_rect.position = (pos_in - bezier_handle_icon->get_size() / 2).floor();
  355. ep.in_rect.size = bezier_handle_icon->get_size();
  356. draw_texture(bezier_handle_icon, ep.in_rect.position);
  357. ep.in_rect = ep.in_rect.grow(ep.in_rect.size.width * 0.5);
  358. }
  359. if (pos_out.x >= limit && pos_out.x <= right_limit) {
  360. ep.out_rect.position = (pos_out - bezier_handle_icon->get_size() / 2).floor();
  361. ep.out_rect.size = bezier_handle_icon->get_size();
  362. draw_texture(bezier_handle_icon, ep.out_rect.position);
  363. ep.out_rect = ep.out_rect.grow(ep.out_rect.size.width * 0.5);
  364. }
  365. edit_points.push_back(ep);
  366. }
  367. }
  368. if (box_selecting) {
  369. Color bs = accent;
  370. bs.a *= 0.5;
  371. Vector2 bs_from = box_selection_from;
  372. Vector2 bs_to = box_selection_to;
  373. if (bs_from.x > bs_to.x) {
  374. SWAP(bs_from.x, bs_to.x);
  375. }
  376. if (bs_from.y > bs_to.y) {
  377. SWAP(bs_from.y, bs_to.y);
  378. }
  379. draw_rect(Rect2(bs_from, bs_to - bs_from), bs);
  380. }
  381. }
  382. }
  383. Ref<Animation> AnimationBezierTrackEdit::get_animation() const {
  384. return animation;
  385. }
  386. void AnimationBezierTrackEdit::set_animation_and_track(const Ref<Animation> &p_animation, int p_track) {
  387. animation = p_animation;
  388. track = p_track;
  389. if (is_connected_compat("select_key", editor, "_key_selected"))
  390. disconnect_compat("select_key", editor, "_key_selected");
  391. if (is_connected_compat("deselect_key", editor, "_key_deselected"))
  392. disconnect_compat("deselect_key", editor, "_key_deselected");
  393. connect_compat("select_key", editor, "_key_selected", varray(p_track), CONNECT_DEFERRED);
  394. connect_compat("deselect_key", editor, "_key_deselected", varray(p_track), CONNECT_DEFERRED);
  395. update();
  396. }
  397. Size2 AnimationBezierTrackEdit::get_minimum_size() const {
  398. return Vector2(1, 1);
  399. }
  400. void AnimationBezierTrackEdit::set_undo_redo(UndoRedo *p_undo_redo) {
  401. undo_redo = p_undo_redo;
  402. }
  403. void AnimationBezierTrackEdit::set_timeline(AnimationTimelineEdit *p_timeline) {
  404. timeline = p_timeline;
  405. timeline->connect("zoom_changed", callable_mp(this, &AnimationBezierTrackEdit::_zoom_changed));
  406. }
  407. void AnimationBezierTrackEdit::set_editor(AnimationTrackEditor *p_editor) {
  408. editor = p_editor;
  409. connect_compat("clear_selection", editor, "_clear_selection", varray(false));
  410. }
  411. void AnimationBezierTrackEdit::_play_position_draw() {
  412. if (!animation.is_valid() || play_position_pos < 0)
  413. return;
  414. float scale = timeline->get_zoom_scale();
  415. int h = get_size().height;
  416. int px = (-timeline->get_value() + play_position_pos) * scale + timeline->get_name_limit();
  417. if (px >= timeline->get_name_limit() && px < (get_size().width - timeline->get_buttons_width())) {
  418. Color color = get_theme_color("accent_color", "Editor");
  419. play_position->draw_line(Point2(px, 0), Point2(px, h), color);
  420. }
  421. }
  422. void AnimationBezierTrackEdit::set_play_position(float p_pos) {
  423. play_position_pos = p_pos;
  424. play_position->update();
  425. }
  426. void AnimationBezierTrackEdit::update_play_position() {
  427. play_position->update();
  428. }
  429. void AnimationBezierTrackEdit::set_root(Node *p_root) {
  430. root = p_root;
  431. }
  432. void AnimationBezierTrackEdit::_zoom_changed() {
  433. update();
  434. }
  435. String AnimationBezierTrackEdit::get_tooltip(const Point2 &p_pos) const {
  436. return Control::get_tooltip(p_pos);
  437. }
  438. void AnimationBezierTrackEdit::_clear_selection() {
  439. selection.clear();
  440. emit_signal("clear_selection");
  441. update();
  442. }
  443. void AnimationBezierTrackEdit::_clear_selection_for_anim(const Ref<Animation> &p_anim) {
  444. if (!(animation == p_anim))
  445. return;
  446. //selection.clear();
  447. _clear_selection();
  448. }
  449. void AnimationBezierTrackEdit::_select_at_anim(const Ref<Animation> &p_anim, int p_track, float p_pos) {
  450. if (!(animation == p_anim))
  451. return;
  452. int idx = animation->track_find_key(p_track, p_pos, true);
  453. ERR_FAIL_COND(idx < 0);
  454. selection.insert(idx);
  455. emit_signal("select_key", idx, true);
  456. update();
  457. }
  458. void AnimationBezierTrackEdit::_gui_input(const Ref<InputEvent> &p_event) {
  459. if (p_event->is_pressed()) {
  460. if (ED_GET_SHORTCUT("animation_editor/duplicate_selection")->is_shortcut(p_event)) {
  461. duplicate_selection();
  462. accept_event();
  463. }
  464. if (ED_GET_SHORTCUT("animation_editor/delete_selection")->is_shortcut(p_event)) {
  465. delete_selection();
  466. accept_event();
  467. }
  468. }
  469. Ref<InputEventMouseButton> mb = p_event;
  470. if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_WHEEL_DOWN) {
  471. float v_zoom_orig = v_zoom;
  472. if (mb->get_command()) {
  473. timeline->get_zoom()->set_value(timeline->get_zoom()->get_value() * 1.05);
  474. } else {
  475. if (v_zoom < 100000) {
  476. v_zoom *= 1.2;
  477. }
  478. }
  479. v_scroll = v_scroll + (mb->get_position().y - get_size().y / 2) * (v_zoom - v_zoom_orig);
  480. update();
  481. }
  482. if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_WHEEL_UP) {
  483. float v_zoom_orig = v_zoom;
  484. if (mb->get_command()) {
  485. timeline->get_zoom()->set_value(timeline->get_zoom()->get_value() / 1.05);
  486. } else {
  487. if (v_zoom > 0.000001) {
  488. v_zoom /= 1.2;
  489. }
  490. }
  491. v_scroll = v_scroll + (mb->get_position().y - get_size().y / 2) * (v_zoom - v_zoom_orig);
  492. update();
  493. }
  494. if (mb.is_valid() && mb->get_button_index() == BUTTON_MIDDLE) {
  495. if (mb->is_pressed()) {
  496. int x = mb->get_position().x - timeline->get_name_limit();
  497. panning_timeline_from = x / timeline->get_zoom_scale();
  498. panning_timeline = true;
  499. panning_timeline_at = timeline->get_value();
  500. } else {
  501. panning_timeline = false;
  502. }
  503. }
  504. if (mb.is_valid() && mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed()) {
  505. menu_insert_key = mb->get_position();
  506. if (menu_insert_key.x >= timeline->get_name_limit() && menu_insert_key.x <= get_size().width - timeline->get_buttons_width()) {
  507. Vector2 popup_pos = get_global_transform().xform(mb->get_position());
  508. menu->clear();
  509. menu->add_icon_item(bezier_icon, TTR("Insert Key Here"), MENU_KEY_INSERT);
  510. if (selection.size()) {
  511. menu->add_separator();
  512. menu->add_icon_item(get_theme_icon("Duplicate", "EditorIcons"), TTR("Duplicate Selected Key(s)"), MENU_KEY_DUPLICATE);
  513. menu->add_separator();
  514. menu->add_icon_item(get_theme_icon("Remove", "EditorIcons"), TTR("Delete Selected Key(s)"), MENU_KEY_DELETE);
  515. }
  516. menu->set_as_minsize();
  517. menu->set_position(popup_pos);
  518. menu->popup();
  519. }
  520. }
  521. if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
  522. if (close_icon_rect.has_point(mb->get_position())) {
  523. emit_signal("close_request");
  524. return;
  525. }
  526. for (Map<int, Rect2>::Element *E = subtracks.front(); E; E = E->next()) {
  527. if (E->get().has_point(mb->get_position())) {
  528. set_animation_and_track(animation, E->key());
  529. _clear_selection();
  530. return;
  531. }
  532. }
  533. for (int i = 0; i < edit_points.size(); i++) {
  534. //first check point
  535. //command makes it ignore the main point, so control point editors can be force-edited
  536. //path 2D editing in the 3D and 2D editors works the same way
  537. if (!mb->get_command()) {
  538. if (edit_points[i].point_rect.has_point(mb->get_position())) {
  539. if (mb->get_shift()) {
  540. //add to selection
  541. if (selection.has(i)) {
  542. selection.erase(i);
  543. } else {
  544. selection.insert(i);
  545. }
  546. update();
  547. select_single_attempt = -1;
  548. } else if (selection.has(i)) {
  549. moving_selection_attempt = true;
  550. moving_selection = false;
  551. moving_selection_from_key = i;
  552. moving_selection_offset = Vector2();
  553. select_single_attempt = i;
  554. update();
  555. } else {
  556. moving_selection_attempt = true;
  557. moving_selection = true;
  558. moving_selection_from_key = i;
  559. moving_selection_offset = Vector2();
  560. selection.clear();
  561. selection.insert(i);
  562. update();
  563. }
  564. return;
  565. }
  566. }
  567. if (edit_points[i].in_rect.has_point(mb->get_position())) {
  568. moving_handle = -1;
  569. moving_handle_key = i;
  570. moving_handle_left = animation->bezier_track_get_key_in_handle(track, i);
  571. moving_handle_right = animation->bezier_track_get_key_out_handle(track, i);
  572. update();
  573. return;
  574. }
  575. if (edit_points[i].out_rect.has_point(mb->get_position())) {
  576. moving_handle = 1;
  577. moving_handle_key = i;
  578. moving_handle_left = animation->bezier_track_get_key_in_handle(track, i);
  579. moving_handle_right = animation->bezier_track_get_key_out_handle(track, i);
  580. update();
  581. return;
  582. ;
  583. }
  584. }
  585. //insert new point
  586. if (mb->get_command() && mb->get_position().x >= timeline->get_name_limit() && mb->get_position().x < get_size().width - timeline->get_buttons_width()) {
  587. Array new_point;
  588. new_point.resize(5);
  589. float h = (get_size().height / 2 - mb->get_position().y) * v_zoom + v_scroll;
  590. new_point[0] = h;
  591. new_point[1] = -0.25;
  592. new_point[2] = 0;
  593. new_point[3] = 0.25;
  594. new_point[4] = 0;
  595. float time = ((mb->get_position().x - timeline->get_name_limit()) / timeline->get_zoom_scale()) + timeline->get_value();
  596. while (animation->track_find_key(track, time, true) != -1) {
  597. time += 0.001;
  598. }
  599. undo_redo->create_action(TTR("Add Bezier Point"));
  600. undo_redo->add_do_method(animation.ptr(), "track_insert_key", track, time, new_point);
  601. undo_redo->add_undo_method(animation.ptr(), "track_remove_key_at_position", track, time);
  602. undo_redo->commit_action();
  603. //then attempt to move
  604. int index = animation->track_find_key(track, time, true);
  605. ERR_FAIL_COND(index == -1);
  606. _clear_selection();
  607. selection.insert(index);
  608. moving_selection_attempt = true;
  609. moving_selection = false;
  610. moving_selection_from_key = index;
  611. moving_selection_offset = Vector2();
  612. select_single_attempt = -1;
  613. update();
  614. return;
  615. }
  616. //box select
  617. if (mb->get_position().x >= timeline->get_name_limit() && mb->get_position().x < get_size().width - timeline->get_buttons_width()) {
  618. box_selecting_attempt = true;
  619. box_selecting = false;
  620. box_selecting_add = false;
  621. box_selection_from = mb->get_position();
  622. return;
  623. }
  624. }
  625. if (box_selecting_attempt && mb.is_valid() && !mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
  626. if (box_selecting) {
  627. //do actual select
  628. if (!box_selecting_add) {
  629. _clear_selection();
  630. }
  631. Vector2 bs_from = box_selection_from;
  632. Vector2 bs_to = box_selection_to;
  633. if (bs_from.x > bs_to.x) {
  634. SWAP(bs_from.x, bs_to.x);
  635. }
  636. if (bs_from.y > bs_to.y) {
  637. SWAP(bs_from.y, bs_to.y);
  638. }
  639. Rect2 selection_rect(bs_from, bs_to - bs_from);
  640. for (int i = 0; i < edit_points.size(); i++) {
  641. if (edit_points[i].point_rect.intersects(selection_rect)) {
  642. selection.insert(i);
  643. }
  644. }
  645. } else {
  646. _clear_selection(); //clicked and nothing happened, so clear the selection
  647. }
  648. box_selecting_attempt = false;
  649. box_selecting = false;
  650. update();
  651. }
  652. if (moving_handle != 0 && mb.is_valid() && !mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
  653. undo_redo->create_action(TTR("Move Bezier Points"));
  654. undo_redo->add_do_method(animation.ptr(), "bezier_track_set_key_in_handle", track, moving_handle_key, moving_handle_left);
  655. undo_redo->add_do_method(animation.ptr(), "bezier_track_set_key_out_handle", track, moving_handle_key, moving_handle_right);
  656. 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));
  657. 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));
  658. undo_redo->commit_action();
  659. moving_handle = 0;
  660. update();
  661. }
  662. if (moving_selection_attempt && mb.is_valid() && !mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
  663. if (moving_selection) {
  664. //combit it
  665. undo_redo->create_action(TTR("Move Bezier Points"));
  666. List<AnimMoveRestore> to_restore;
  667. // 1-remove the keys
  668. for (Set<int>::Element *E = selection.back(); E; E = E->prev()) {
  669. undo_redo->add_do_method(animation.ptr(), "track_remove_key", track, E->get());
  670. }
  671. // 2- remove overlapped keys
  672. for (Set<int>::Element *E = selection.back(); E; E = E->prev()) {
  673. float newtime = editor->snap_time(animation->track_get_key_time(track, E->get()) + moving_selection_offset.x);
  674. int idx = animation->track_find_key(track, newtime, true);
  675. if (idx == -1)
  676. continue;
  677. if (selection.has(idx))
  678. continue; //already in selection, don't save
  679. undo_redo->add_do_method(animation.ptr(), "track_remove_key_at_position", track, newtime);
  680. AnimMoveRestore amr;
  681. amr.key = animation->track_get_key_value(track, idx);
  682. amr.track = track;
  683. amr.time = newtime;
  684. to_restore.push_back(amr);
  685. }
  686. // 3-move the keys (re insert them)
  687. for (Set<int>::Element *E = selection.back(); E; E = E->prev()) {
  688. float newpos = editor->snap_time(animation->track_get_key_time(track, E->get()) + moving_selection_offset.x);
  689. /*
  690. if (newpos<0)
  691. continue; //no add at the beginning
  692. */
  693. Array key = animation->track_get_key_value(track, E->get());
  694. float h = key[0];
  695. h += moving_selection_offset.y;
  696. key[0] = h;
  697. undo_redo->add_do_method(animation.ptr(), "track_insert_key", track, newpos, key, 1);
  698. }
  699. // 4-(undo) remove inserted keys
  700. for (Set<int>::Element *E = selection.back(); E; E = E->prev()) {
  701. float newpos = editor->snap_time(animation->track_get_key_time(track, E->get()) + moving_selection_offset.x);
  702. /*
  703. if (newpos<0)
  704. continue; //no remove what no inserted
  705. */
  706. undo_redo->add_undo_method(animation.ptr(), "track_remove_key_at_position", track, newpos);
  707. }
  708. // 5-(undo) reinsert keys
  709. for (Set<int>::Element *E = selection.back(); E; E = E->prev()) {
  710. float oldpos = animation->track_get_key_time(track, E->get());
  711. undo_redo->add_undo_method(animation.ptr(), "track_insert_key", track, oldpos, animation->track_get_key_value(track, E->get()), 1);
  712. }
  713. // 6-(undo) reinsert overlapped keys
  714. for (List<AnimMoveRestore>::Element *E = to_restore.front(); E; E = E->next()) {
  715. AnimMoveRestore &amr = E->get();
  716. undo_redo->add_undo_method(animation.ptr(), "track_insert_key", amr.track, amr.time, amr.key, 1);
  717. }
  718. undo_redo->add_do_method(this, "_clear_selection_for_anim", animation);
  719. undo_redo->add_undo_method(this, "_clear_selection_for_anim", animation);
  720. // 7-reselect
  721. for (Set<int>::Element *E = selection.back(); E; E = E->prev()) {
  722. float oldpos = animation->track_get_key_time(track, E->get());
  723. float newpos = editor->snap_time(oldpos + moving_selection_offset.x);
  724. undo_redo->add_do_method(this, "_select_at_anim", animation, track, newpos);
  725. undo_redo->add_undo_method(this, "_select_at_anim", animation, track, oldpos);
  726. }
  727. undo_redo->commit_action();
  728. moving_selection = false;
  729. } else if (select_single_attempt != -1) {
  730. selection.clear();
  731. selection.insert(select_single_attempt);
  732. }
  733. moving_selection_attempt = false;
  734. update();
  735. }
  736. Ref<InputEventMouseMotion> mm = p_event;
  737. if (mm.is_valid() && mm->get_button_mask() & BUTTON_MASK_MIDDLE) {
  738. v_scroll += mm->get_relative().y * v_zoom;
  739. if (v_scroll > 100000)
  740. v_scroll = 100000;
  741. if (v_scroll < -100000)
  742. v_scroll = -100000;
  743. int x = mm->get_position().x - timeline->get_name_limit();
  744. float ofs = x / timeline->get_zoom_scale();
  745. float diff = ofs - panning_timeline_from;
  746. timeline->set_value(panning_timeline_at - diff);
  747. update();
  748. }
  749. if (moving_selection_attempt && mm.is_valid()) {
  750. if (!moving_selection) {
  751. moving_selection = true;
  752. select_single_attempt = -1;
  753. }
  754. float y = (get_size().height / 2 - mm->get_position().y) * v_zoom + v_scroll;
  755. float x = editor->snap_time(((mm->get_position().x - timeline->get_name_limit()) / timeline->get_zoom_scale()) + timeline->get_value());
  756. 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));
  757. update();
  758. }
  759. if (box_selecting_attempt && mm.is_valid()) {
  760. if (!box_selecting) {
  761. box_selecting = true;
  762. box_selecting_add = mm->get_shift();
  763. }
  764. box_selection_to = mm->get_position();
  765. if (get_local_mouse_position().y < 0) {
  766. //avoid cursor from going too above, so it does not lose focus with viewport
  767. warp_mouse(Vector2(get_local_mouse_position().x, 0));
  768. }
  769. update();
  770. }
  771. if (moving_handle != 0 && mm.is_valid()) {
  772. float y = (get_size().height / 2 - mm->get_position().y) * v_zoom + v_scroll;
  773. float x = ((mm->get_position().x - timeline->get_name_limit()) / timeline->get_zoom_scale()) + timeline->get_value();
  774. Vector2 key_pos = Vector2(animation->track_get_key_time(track, moving_handle_key), animation->bezier_track_get_key_value(track, moving_handle_key));
  775. Vector2 moving_handle_value = Vector2(x, y) - key_pos;
  776. moving_handle_left = animation->bezier_track_get_key_in_handle(track, moving_handle_key);
  777. moving_handle_right = animation->bezier_track_get_key_out_handle(track, moving_handle_key);
  778. if (moving_handle == -1) {
  779. moving_handle_left = moving_handle_value;
  780. if (moving_handle_left.x > 0) {
  781. moving_handle_left.x = 0;
  782. }
  783. if (handle_mode_option->get_selected() == HANDLE_MODE_BALANCED) {
  784. Vector2 scale = Vector2(timeline->get_zoom_scale(), v_zoom);
  785. moving_handle_right = (-(moving_handle_left * scale).normalized() * (moving_handle_right * scale).length()) / scale;
  786. } else if (handle_mode_option->get_selected() == HANDLE_MODE_MIRROR) {
  787. moving_handle_right = -moving_handle_left;
  788. }
  789. }
  790. if (moving_handle == 1) {
  791. moving_handle_right = moving_handle_value;
  792. if (moving_handle_right.x < 0) {
  793. moving_handle_right.x = 0;
  794. }
  795. if (handle_mode_option->get_selected() == HANDLE_MODE_BALANCED) {
  796. Vector2 scale = Vector2(timeline->get_zoom_scale(), v_zoom);
  797. moving_handle_left = (-(moving_handle_right * scale).normalized() * (moving_handle_left * scale).length()) / scale;
  798. } else if (handle_mode_option->get_selected() == HANDLE_MODE_MIRROR) {
  799. moving_handle_left = -moving_handle_right;
  800. }
  801. }
  802. update();
  803. }
  804. }
  805. void AnimationBezierTrackEdit::_menu_selected(int p_index) {
  806. switch (p_index) {
  807. case MENU_KEY_INSERT: {
  808. Array new_point;
  809. new_point.resize(5);
  810. float h = (get_size().height / 2 - menu_insert_key.y) * v_zoom + v_scroll;
  811. new_point[0] = h;
  812. new_point[1] = -0.25;
  813. new_point[2] = 0;
  814. new_point[3] = 0.25;
  815. new_point[4] = 0;
  816. float time = ((menu_insert_key.x - timeline->get_name_limit()) / timeline->get_zoom_scale()) + timeline->get_value();
  817. while (animation->track_find_key(track, time, true) != -1) {
  818. time += 0.001;
  819. }
  820. undo_redo->create_action(TTR("Add Bezier Point"));
  821. undo_redo->add_do_method(animation.ptr(), "track_insert_key", track, time, new_point);
  822. undo_redo->add_undo_method(animation.ptr(), "track_remove_key_at_position", track, time);
  823. undo_redo->commit_action();
  824. } break;
  825. case MENU_KEY_DUPLICATE: {
  826. duplicate_selection();
  827. } break;
  828. case MENU_KEY_DELETE: {
  829. delete_selection();
  830. } break;
  831. }
  832. }
  833. void AnimationBezierTrackEdit::duplicate_selection() {
  834. if (selection.size() == 0)
  835. return;
  836. float top_time = 1e10;
  837. for (Set<int>::Element *E = selection.back(); E; E = E->prev()) {
  838. float t = animation->track_get_key_time(track, E->get());
  839. if (t < top_time)
  840. top_time = t;
  841. }
  842. undo_redo->create_action(TTR("Anim Duplicate Keys"));
  843. List<Pair<int, float>> new_selection_values;
  844. for (Set<int>::Element *E = selection.back(); E; E = E->prev()) {
  845. float t = animation->track_get_key_time(track, E->get());
  846. float dst_time = t + (timeline->get_play_position() - top_time);
  847. int existing_idx = animation->track_find_key(track, dst_time, true);
  848. 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()));
  849. undo_redo->add_undo_method(animation.ptr(), "track_remove_key_at_position", track, dst_time);
  850. Pair<int, float> p;
  851. p.first = track;
  852. p.second = dst_time;
  853. new_selection_values.push_back(p);
  854. if (existing_idx != -1) {
  855. 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));
  856. }
  857. }
  858. undo_redo->commit_action();
  859. //reselect duplicated
  860. selection.clear();
  861. for (List<Pair<int, float>>::Element *E = new_selection_values.front(); E; E = E->next()) {
  862. int track = E->get().first;
  863. float time = E->get().second;
  864. int existing_idx = animation->track_find_key(track, time, true);
  865. if (existing_idx == -1)
  866. continue;
  867. selection.insert(existing_idx);
  868. }
  869. update();
  870. }
  871. void AnimationBezierTrackEdit::delete_selection() {
  872. if (selection.size()) {
  873. undo_redo->create_action(TTR("Anim Delete Keys"));
  874. for (Set<int>::Element *E = selection.back(); E; E = E->prev()) {
  875. undo_redo->add_do_method(animation.ptr(), "track_remove_key", track, E->get());
  876. 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);
  877. }
  878. undo_redo->add_do_method(this, "_clear_selection_for_anim", animation);
  879. undo_redo->add_undo_method(this, "_clear_selection_for_anim", animation);
  880. undo_redo->commit_action();
  881. //selection.clear();
  882. }
  883. }
  884. void AnimationBezierTrackEdit::set_block_animation_update_ptr(bool *p_block_ptr) {
  885. block_animation_update_ptr = p_block_ptr;
  886. }
  887. void AnimationBezierTrackEdit::_bind_methods() {
  888. ClassDB::bind_method("_gui_input", &AnimationBezierTrackEdit::_gui_input);
  889. ClassDB::bind_method("_clear_selection", &AnimationBezierTrackEdit::_clear_selection);
  890. ClassDB::bind_method("_clear_selection_for_anim", &AnimationBezierTrackEdit::_clear_selection_for_anim);
  891. ClassDB::bind_method("_select_at_anim", &AnimationBezierTrackEdit::_select_at_anim);
  892. ADD_SIGNAL(MethodInfo("timeline_changed", PropertyInfo(Variant::FLOAT, "position"), PropertyInfo(Variant::BOOL, "drag")));
  893. ADD_SIGNAL(MethodInfo("remove_request", PropertyInfo(Variant::INT, "track")));
  894. ADD_SIGNAL(MethodInfo("insert_key", PropertyInfo(Variant::FLOAT, "ofs")));
  895. ADD_SIGNAL(MethodInfo("select_key", PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::BOOL, "single")));
  896. ADD_SIGNAL(MethodInfo("deselect_key", PropertyInfo(Variant::INT, "index")));
  897. ADD_SIGNAL(MethodInfo("clear_selection"));
  898. ADD_SIGNAL(MethodInfo("close_request"));
  899. ADD_SIGNAL(MethodInfo("move_selection_begin"));
  900. ADD_SIGNAL(MethodInfo("move_selection", PropertyInfo(Variant::FLOAT, "ofs")));
  901. ADD_SIGNAL(MethodInfo("move_selection_commit"));
  902. ADD_SIGNAL(MethodInfo("move_selection_cancel"));
  903. }
  904. AnimationBezierTrackEdit::AnimationBezierTrackEdit() {
  905. undo_redo = nullptr;
  906. timeline = nullptr;
  907. root = nullptr;
  908. menu = nullptr;
  909. block_animation_update_ptr = nullptr;
  910. moving_selection_attempt = false;
  911. moving_selection = false;
  912. select_single_attempt = -1;
  913. box_selecting = false;
  914. box_selecting_attempt = false;
  915. moving_handle = 0;
  916. play_position_pos = 0;
  917. play_position = memnew(Control);
  918. play_position->set_mouse_filter(MOUSE_FILTER_PASS);
  919. add_child(play_position);
  920. play_position->set_anchors_and_margins_preset(PRESET_WIDE);
  921. play_position->connect("draw", callable_mp(this, &AnimationBezierTrackEdit::_play_position_draw));
  922. set_focus_mode(FOCUS_CLICK);
  923. v_scroll = 0;
  924. v_zoom = 1;
  925. panning_timeline = false;
  926. set_clip_contents(true);
  927. handle_mode = HANDLE_MODE_FREE;
  928. handle_mode_option = memnew(OptionButton);
  929. add_child(handle_mode_option);
  930. menu = memnew(PopupMenu);
  931. add_child(menu);
  932. menu->connect("id_pressed", callable_mp(this, &AnimationBezierTrackEdit::_menu_selected));
  933. //set_mouse_filter(MOUSE_FILTER_PASS); //scroll has to work too for selection
  934. }