animation_bezier_editor.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 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 AnimationBezierTrackEdit : public Control {
  34. GDCLASS(AnimationBezierTrackEdit, Control);
  35. enum HandleMode {
  36. HANDLE_MODE_FREE,
  37. HANDLE_MODE_BALANCED,
  38. HANDLE_MODE_MIRROR
  39. };
  40. enum {
  41. MENU_KEY_INSERT,
  42. MENU_KEY_DUPLICATE,
  43. MENU_KEY_DELETE
  44. };
  45. HandleMode handle_mode;
  46. OptionButton *handle_mode_option;
  47. VBoxContainer *right_column;
  48. Button *close_button;
  49. AnimationTimelineEdit *timeline = nullptr;
  50. UndoRedo *undo_redo = nullptr;
  51. Node *root = nullptr;
  52. Control *play_position; //separate control used to draw so updates for only position changed are much faster
  53. float play_position_pos = 0;
  54. Ref<Animation> animation;
  55. int track;
  56. Vector<Rect2> view_rects;
  57. Ref<Texture2D> bezier_icon;
  58. Ref<Texture2D> bezier_handle_icon;
  59. Ref<Texture2D> selected_icon;
  60. Rect2 close_icon_rect;
  61. Map<int, Rect2> subtracks;
  62. float v_scroll = 0;
  63. float v_zoom = 1;
  64. PopupMenu *menu = nullptr;
  65. void _zoom_changed();
  66. virtual void gui_input(const Ref<InputEvent> &p_event) override;
  67. void _menu_selected(int p_index);
  68. void _play_position_draw();
  69. Vector2 insert_at_pos;
  70. bool moving_selection_attempt = false;
  71. int select_single_attempt = -1;
  72. bool moving_selection = false;
  73. int moving_selection_from_key;
  74. Vector2 moving_selection_offset;
  75. bool box_selecting_attempt = false;
  76. bool box_selecting = false;
  77. bool box_selecting_add = false;
  78. Vector2 box_selection_from;
  79. Vector2 box_selection_to;
  80. int moving_handle = 0; //0 no move -1 or +1 out
  81. int moving_handle_key = 0;
  82. Vector2 moving_handle_left;
  83. Vector2 moving_handle_right;
  84. void _clear_selection();
  85. void _clear_selection_for_anim(const Ref<Animation> &p_anim);
  86. void _select_at_anim(const Ref<Animation> &p_anim, int p_track, float p_pos);
  87. Vector2 menu_insert_key;
  88. struct AnimMoveRestore {
  89. int track = 0;
  90. float time = 0;
  91. Variant key;
  92. float transition = 0;
  93. };
  94. AnimationTrackEditor *editor;
  95. struct EditPoint {
  96. Rect2 point_rect;
  97. Rect2 in_rect;
  98. Rect2 out_rect;
  99. };
  100. Vector<EditPoint> edit_points;
  101. Set<int> selection;
  102. bool panning_timeline = false;
  103. float panning_timeline_from;
  104. float panning_timeline_at;
  105. void _draw_line_clipped(const Vector2 &p_from, const Vector2 &p_to, const Color &p_color, int p_clip_left, int p_clip_right);
  106. void _draw_track(int p_track, const Color &p_color);
  107. float _bezier_h_to_pixel(float p_h);
  108. protected:
  109. static void _bind_methods();
  110. void _notification(int p_what);
  111. public:
  112. virtual String get_tooltip(const Point2 &p_pos) const override;
  113. Ref<Animation> get_animation() const;
  114. void set_animation_and_track(const Ref<Animation> &p_animation, int p_track);
  115. virtual Size2 get_minimum_size() const override;
  116. void set_undo_redo(UndoRedo *p_undo_redo);
  117. void set_timeline(AnimationTimelineEdit *p_timeline);
  118. void set_editor(AnimationTrackEditor *p_editor);
  119. void set_root(Node *p_root);
  120. void set_play_position(float p_pos);
  121. void update_play_position();
  122. void duplicate_selection();
  123. void delete_selection();
  124. AnimationBezierTrackEdit();
  125. };
  126. #endif // ANIMATION_BEZIER_EDITOR_H