animation_bezier_editor.cpp 39 KB

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