animation_bezier_editor.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /**************************************************************************/
  2. /* animation_bezier_editor.h */
  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. #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. AnimationTimelineEdit *timeline;
  48. UndoRedo *undo_redo;
  49. Node *root;
  50. Control *play_position; //separate control used to draw so updates for only position changed are much faster
  51. float play_position_pos;
  52. Ref<Animation> animation;
  53. int track;
  54. Vector<Rect2> view_rects;
  55. Ref<Texture> bezier_icon;
  56. Ref<Texture> bezier_handle_icon;
  57. Ref<Texture> selected_icon;
  58. Rect2 close_icon_rect;
  59. Map<int, Rect2> subtracks;
  60. float v_scroll;
  61. float v_zoom;
  62. PopupMenu *menu;
  63. void _zoom_changed();
  64. void _gui_input(const Ref<InputEvent> &p_event);
  65. void _menu_selected(int p_index);
  66. bool *block_animation_update_ptr; //used to block all tracks re-gen (speed up)
  67. void _play_position_draw();
  68. Vector2 insert_at_pos;
  69. bool moving_selection_attempt;
  70. int select_single_attempt;
  71. bool moving_selection;
  72. int moving_selection_from_key;
  73. Vector2 moving_selection_offset;
  74. bool box_selecting_attempt;
  75. bool box_selecting;
  76. bool box_selecting_add;
  77. Vector2 box_selection_from;
  78. Vector2 box_selection_to;
  79. int moving_handle; //0 no move -1 or +1 out
  80. int moving_handle_key;
  81. Vector2 moving_handle_left;
  82. Vector2 moving_handle_right;
  83. void _clear_selection();
  84. void _clear_selection_for_anim(const Ref<Animation> &p_anim);
  85. void _select_at_anim(const Ref<Animation> &p_anim, int p_track, float p_pos);
  86. Vector2 menu_insert_key;
  87. struct AnimMoveRestore {
  88. int track;
  89. float time;
  90. Variant key;
  91. float transition;
  92. };
  93. AnimationTrackEditor *editor;
  94. struct EditPoint {
  95. Rect2 point_rect;
  96. Rect2 in_rect;
  97. Rect2 out_rect;
  98. };
  99. Vector<EditPoint> edit_points;
  100. Set<int> selection;
  101. bool panning_timeline;
  102. float panning_timeline_from;
  103. float panning_timeline_at;
  104. void _draw_line_clipped(const Vector2 &p_from, const Vector2 &p_to, const Color &p_color, int p_clip_left, int p_clip_right);
  105. void _draw_track(int p_track, const Color &p_color);
  106. float _bezier_h_to_pixel(float p_h);
  107. protected:
  108. static void _bind_methods();
  109. void _notification(int p_what);
  110. public:
  111. virtual String get_tooltip(const Point2 &p_pos) const;
  112. Ref<Animation> get_animation() const;
  113. void set_animation_and_track(const Ref<Animation> &p_animation, int p_track);
  114. virtual Size2 get_minimum_size() const;
  115. void set_undo_redo(UndoRedo *p_undo_redo);
  116. void set_timeline(AnimationTimelineEdit *p_timeline);
  117. void set_editor(AnimationTrackEditor *p_editor);
  118. void set_root(Node *p_root);
  119. void set_block_animation_update_ptr(bool *p_block_ptr);
  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