animation_bezier_editor.cpp 39 KB

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