animation_editor.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. /*************************************************************************/
  2. /* animation_editor.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #ifndef ANIMATION_EDITOR_H
  30. #define ANIMATION_EDITOR_H
  31. #include "scene/gui/control.h"
  32. #include "scene/gui/slider.h"
  33. #include "scene/gui/menu_button.h"
  34. #include "scene/gui/spin_box.h"
  35. #include "scene/gui/texture_frame.h"
  36. #include "scene/gui/scroll_bar.h"
  37. #include "scene/gui/tool_button.h"
  38. #include "scene/gui/file_dialog.h"
  39. #include "scene/gui/empty_control.h"
  40. #include "scene/resources/animation.h"
  41. #include "scene/animation/animation_cache.h"
  42. #include "scene_tree_editor.h"
  43. #include "editor_data.h"
  44. #include "property_editor.h"
  45. class AnimationKeyEdit;
  46. class AnimationKeyEditor : public VBoxContainer {
  47. OBJ_TYPE( AnimationKeyEditor, VBoxContainer );
  48. /*
  49. enum {
  50. MENU_NEW_ANIMATION,
  51. MENU_OPEN_ANIMATION,
  52. MENU_EDIT_ANIMATION,
  53. MENU_CLOSE_ANIMATION,
  54. MENU_KEYING_ACTIVE,
  55. MENU_SET_ROOT_NODE,
  56. MENU_SYNC_TO_PLAYER,
  57. MENU_ANIM_BASE=100,
  58. };
  59. */
  60. enum {
  61. TRACK_MENU_ADD_VALUE_TRACK,
  62. TRACK_MENU_ADD_TRANSFORM_TRACK,
  63. TRACK_MENU_ADD_CALL_TRACK,
  64. TRACK_MENU_SCALE,
  65. TRACK_MENU_SCALE_PIVOT,
  66. TRACK_MENU_MOVE_UP,
  67. TRACK_MENU_MOVE_DOWN,
  68. TRACK_MENU_REMOVE,
  69. TRACK_MENU_DUPLICATE,
  70. TRACK_MENU_DUPLICATE_TRANSPOSE,
  71. TRACK_MENU_SET_ALL_TRANS_LINEAR,
  72. TRACK_MENU_SET_ALL_TRANS_CONSTANT,
  73. TRACK_MENU_SET_ALL_TRANS_OUT,
  74. TRACK_MENU_SET_ALL_TRANS_IN,
  75. TRACK_MENU_SET_ALL_TRANS_INOUT,
  76. TRACK_MENU_SET_ALL_TRANS_OUTIN,
  77. TRACK_MENU_NEXT_STEP,
  78. TRACK_MENU_PREV_STEP,
  79. TRACK_MENU_OPTIMIZE
  80. };
  81. struct MouseOver {
  82. enum Over {
  83. OVER_NONE,
  84. OVER_NAME,
  85. OVER_KEY,
  86. OVER_VALUE,
  87. OVER_INTERP,
  88. OVER_UP,
  89. OVER_DOWN,
  90. OVER_REMOVE,
  91. OVER_ADD_KEY,
  92. };
  93. Over over;
  94. int track;
  95. int over_key;
  96. } mouse_over;
  97. struct SelectedKey {
  98. int track;
  99. int key;
  100. bool operator<(const SelectedKey& p_key) const { return track==p_key.track ? key < p_key.key : track < p_key.track; };
  101. };
  102. struct KeyInfo {
  103. float pos;
  104. };
  105. Map<SelectedKey,KeyInfo> selection;
  106. struct ClickOver {
  107. enum Click {
  108. CLICK_NONE,
  109. CLICK_RESIZE_NAMES,
  110. CLICK_DRAG_TIMELINE,
  111. CLICK_MOVE_KEYS,
  112. CLICK_SELECT_KEYS
  113. };
  114. SelectedKey selk;
  115. bool shift;
  116. Click click;
  117. Point2 at;
  118. Point2 to;
  119. } click;
  120. float timeline_pos;
  121. float name_column_ratio;
  122. int track_name_editing;
  123. int interp_editing;
  124. int cont_editing;
  125. int selected_track;
  126. int last_menu_track_opt;
  127. LineEdit *track_name;
  128. PopupMenu *track_menu;
  129. PopupMenu *type_menu;
  130. EmptyControl *ec;
  131. TextureFrame *zoomicon;
  132. HSlider *zoom;
  133. //MenuButton *menu;
  134. SpinBox *length;
  135. Button *loop;
  136. bool keying;
  137. ToolButton *edit_button;
  138. ToolButton *move_up_button;
  139. ToolButton *move_down_button;
  140. ToolButton *remove_button;
  141. SpinBox *step;
  142. MenuButton *menu_track;
  143. HScrollBar *h_scroll;
  144. VScrollBar *v_scroll;
  145. Control *track_editor;
  146. Control *track_pos;
  147. ConfirmationDialog *scale_dialog;
  148. SpinBox *scale;
  149. PopupDialog *key_edit_dialog;
  150. PropertyEditor *key_editor;
  151. Ref<Animation> animation;
  152. void _update_paths();
  153. int last_idx;
  154. Node *root;
  155. UndoRedo *undo_redo;
  156. EditorHistory* history;
  157. ConfirmationDialog *insert_confirm;
  158. AnimationKeyEdit *key_edit;
  159. bool inserting;
  160. bool updating;
  161. bool te_drawing;
  162. void _animation_len_changed(float p_len);
  163. void _animation_loop_changed();
  164. void _step_changed(float p_len);
  165. struct InsertData {
  166. Animation::TrackType type;
  167. NodePath path;
  168. int track_idx;
  169. Variant value;
  170. String query;
  171. };/* insert_data;*/
  172. bool insert_query;
  173. List<InsertData> insert_data;
  174. uint64_t insert_frame;
  175. int cvi_track;
  176. float cvi_pos;
  177. int right_data_size_cache;
  178. EditorSelection *editor_selection;
  179. AnimationKeyEditor();
  180. float _get_zoom_scale() const;
  181. void _track_editor_draw();
  182. void _track_editor_input_event(const InputEvent& p_input);
  183. void _track_pos_draw();
  184. void _track_name_changed(const String& p_name);
  185. void _track_menu_selected(int p_idx);
  186. void _confirm_insert_list();
  187. int _confirm_insert(InsertData p_id,int p_at_track=-1);
  188. void _query_insert(const InsertData& p_id);
  189. void _update_menu();
  190. bool insert_queue;
  191. void _insert_delay();
  192. void _scale();
  193. //void _browse_path();
  194. StringName alc;
  195. void _animation_changed();
  196. void _scroll_changed(double);
  197. void _menu_track(int p_type);
  198. void _clear_selection_for_anim(const Ref<Animation>& p_anim);
  199. void _select_at_anim(const Ref<Animation>& p_anim,int p_track,float p_pos);
  200. PropertyInfo _find_hint_for_track(int p_idx);
  201. void _create_value_item(int p_type);
  202. void _pane_drag(const Point2& p_delta);
  203. void _animation_len_update();
  204. void _root_removed();
  205. protected:
  206. void _notification(int p_what);
  207. static void _bind_methods();
  208. public:
  209. void set_animation(const Ref<Animation>& p_anim);
  210. Ref<Animation> get_current_animation() const;
  211. void set_root(Node *p_root);
  212. Node *get_root() const;
  213. void set_keying(bool p_enabled);
  214. bool has_keying() const;
  215. void cleanup();
  216. void set_anim_pos(float p_pos);
  217. void insert_node_value_key(Node* p_node, const String& p_property,const Variant& p_value,bool p_only_if_exists=false);
  218. void insert_value_key(const String& p_property,const Variant& p_value);
  219. void insert_transform_key(Spatial *p_node,const String& p_sub,const Transform& p_xform);
  220. AnimationKeyEditor(UndoRedo *p_undo_redo, EditorHistory *p_history, EditorSelection *p_selection);
  221. ~AnimationKeyEditor();
  222. };
  223. #endif // ANIMATION_EDITOR_H