animation_bezier_editor.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*************************************************************************/
  2. /* animation_bezier_editor.h */
  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. #ifndef ANIMATION_BEZIER_EDITOR_H
  31. #define ANIMATION_BEZIER_EDITOR_H
  32. #include "animation_track_editor.h"
  33. class ViewPanner;
  34. class AnimationBezierTrackEdit : public Control {
  35. GDCLASS(AnimationBezierTrackEdit, Control);
  36. enum {
  37. MENU_KEY_INSERT,
  38. MENU_KEY_DUPLICATE,
  39. MENU_KEY_DELETE,
  40. MENU_KEY_SET_HANDLE_FREE,
  41. MENU_KEY_SET_HANDLE_BALANCED,
  42. };
  43. AnimationTimelineEdit *timeline = nullptr;
  44. UndoRedo *undo_redo = nullptr;
  45. Node *root = nullptr;
  46. Control *play_position = nullptr; //separate control used to draw so updates for only position changed are much faster
  47. float play_position_pos = 0;
  48. Ref<Animation> animation;
  49. int selected_track = 0;
  50. Vector<Rect2> view_rects;
  51. Ref<Texture2D> bezier_icon;
  52. Ref<Texture2D> bezier_handle_icon;
  53. Ref<Texture2D> selected_icon;
  54. RBMap<int, Rect2> subtracks;
  55. enum {
  56. REMOVE_ICON,
  57. LOCK_ICON,
  58. SOLO_ICON,
  59. VISIBILITY_ICON
  60. };
  61. RBMap<int, RBMap<int, Rect2>> subtrack_icons;
  62. RBSet<int> locked_tracks;
  63. RBSet<int> hidden_tracks;
  64. int solo_track = -1;
  65. bool is_filtered = false;
  66. float v_scroll = 0;
  67. float v_zoom = 1;
  68. PopupMenu *menu = nullptr;
  69. void _zoom_changed();
  70. void _update_locked_tracks_after(int p_track);
  71. void _update_hidden_tracks_after(int p_track);
  72. virtual void gui_input(const Ref<InputEvent> &p_event) override;
  73. void _menu_selected(int p_index);
  74. void _play_position_draw();
  75. Vector2 insert_at_pos;
  76. typedef Pair<int, int> IntPair;
  77. bool moving_selection_attempt = false;
  78. IntPair select_single_attempt;
  79. bool moving_selection = false;
  80. int moving_selection_from_key = 0;
  81. int moving_selection_from_track = 0;
  82. Vector2 moving_selection_offset;
  83. bool box_selecting_attempt = false;
  84. bool box_selecting = false;
  85. bool box_selecting_add = false;
  86. Vector2 box_selection_from;
  87. Vector2 box_selection_to;
  88. int moving_handle = 0; //0 no move -1 or +1 out
  89. int moving_handle_key = 0;
  90. int moving_handle_track = 0;
  91. Vector2 moving_handle_left;
  92. Vector2 moving_handle_right;
  93. int moving_handle_mode = 0; // value from Animation::HandleMode
  94. void _clear_selection();
  95. void _clear_selection_for_anim(const Ref<Animation> &p_anim);
  96. void _select_at_anim(const Ref<Animation> &p_anim, int p_track, float p_pos);
  97. void _change_selected_keys_handle_mode(Animation::HandleMode p_mode);
  98. Vector2 menu_insert_key;
  99. struct AnimMoveRestore {
  100. int track = 0;
  101. float time = 0;
  102. Variant key;
  103. float transition = 0;
  104. };
  105. AnimationTrackEditor *editor = nullptr;
  106. struct EditPoint {
  107. Rect2 point_rect;
  108. Rect2 in_rect;
  109. Rect2 out_rect;
  110. int track = 0;
  111. int key = 0;
  112. };
  113. Vector<EditPoint> edit_points;
  114. struct SelectionCompare {
  115. bool operator()(const IntPair &lh, const IntPair &rh) {
  116. if (lh.first == rh.first) {
  117. return lh.second < rh.second;
  118. } else {
  119. return lh.first < rh.first;
  120. }
  121. }
  122. };
  123. typedef RBSet<IntPair, SelectionCompare> SelectionSet;
  124. SelectionSet selection;
  125. Ref<ViewPanner> panner;
  126. void _scroll_callback(Vector2 p_scroll_vec, bool p_alt);
  127. void _pan_callback(Vector2 p_scroll_vec);
  128. void _zoom_callback(Vector2 p_scroll_vec, Vector2 p_origin, bool p_alt);
  129. void _draw_line_clipped(const Vector2 &p_from, const Vector2 &p_to, const Color &p_color, int p_clip_left, int p_clip_right);
  130. void _draw_track(int p_track, const Color &p_color);
  131. float _bezier_h_to_pixel(float p_h);
  132. protected:
  133. static void _bind_methods();
  134. void _notification(int p_what);
  135. public:
  136. virtual String get_tooltip(const Point2 &p_pos) const override;
  137. Ref<Animation> get_animation() const;
  138. void set_animation_and_track(const Ref<Animation> &p_animation, int p_track);
  139. virtual Size2 get_minimum_size() const override;
  140. void set_undo_redo(UndoRedo *p_undo_redo);
  141. void set_timeline(AnimationTimelineEdit *p_timeline);
  142. void set_editor(AnimationTrackEditor *p_editor);
  143. void set_root(Node *p_root);
  144. void set_filtered(bool p_filtered);
  145. void set_play_position(float p_pos);
  146. void update_play_position();
  147. void duplicate_selection();
  148. void delete_selection();
  149. AnimationBezierTrackEdit();
  150. };
  151. #endif // ANIMATION_BEZIER_EDITOR_H