sprite_frames_editor_plugin.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /**************************************************************************/
  2. /* sprite_frames_editor_plugin.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 SPRITE_FRAMES_EDITOR_PLUGIN_H
  31. #define SPRITE_FRAMES_EDITOR_PLUGIN_H
  32. #include "editor/editor_node.h"
  33. #include "editor/editor_plugin.h"
  34. #include "scene/2d/animated_sprite.h"
  35. #include "scene/gui/dialogs.h"
  36. #include "scene/gui/file_dialog.h"
  37. #include "scene/gui/line_edit.h"
  38. #include "scene/gui/split_container.h"
  39. #include "scene/gui/texture_rect.h"
  40. #include "scene/gui/tree.h"
  41. class SpriteFramesEditor : public HSplitContainer {
  42. GDCLASS(SpriteFramesEditor, HSplitContainer);
  43. enum {
  44. PARAM_USE_CURRENT, // Used in callbacks to indicate `dominant_param` should be not updated.
  45. PARAM_FRAME_COUNT, // Keep "Horizontal" & "Vertical" values.
  46. PARAM_SIZE, // Keep "Size" values.
  47. };
  48. int dominant_param = PARAM_FRAME_COUNT;
  49. ToolButton *load;
  50. ToolButton *load_sheet;
  51. ToolButton *_delete;
  52. ToolButton *copy;
  53. ToolButton *paste;
  54. ToolButton *empty;
  55. ToolButton *empty2;
  56. ToolButton *move_up;
  57. ToolButton *move_down;
  58. ToolButton *zoom_out;
  59. ToolButton *zoom_reset;
  60. ToolButton *zoom_in;
  61. ItemList *tree;
  62. bool loading_scene;
  63. int sel;
  64. ToolButton *new_anim;
  65. ToolButton *remove_anim;
  66. LineEdit *anim_search_box;
  67. Tree *animations;
  68. SpinBox *anim_speed;
  69. CheckButton *anim_loop;
  70. EditorFileDialog *file;
  71. AcceptDialog *dialog;
  72. SpriteFrames *frames;
  73. StringName edited_anim;
  74. ConfirmationDialog *delete_dialog;
  75. ConfirmationDialog *split_sheet_dialog;
  76. ScrollContainer *split_sheet_scroll;
  77. TextureRect *split_sheet_preview;
  78. SpinBox *split_sheet_h;
  79. SpinBox *split_sheet_v;
  80. SpinBox *split_sheet_size_x;
  81. SpinBox *split_sheet_size_y;
  82. SpinBox *split_sheet_sep_x;
  83. SpinBox *split_sheet_sep_y;
  84. SpinBox *split_sheet_offset_x;
  85. SpinBox *split_sheet_offset_y;
  86. ToolButton *split_sheet_zoom_out;
  87. ToolButton *split_sheet_zoom_reset;
  88. ToolButton *split_sheet_zoom_in;
  89. EditorFileDialog *file_split_sheet;
  90. Set<int> frames_selected;
  91. Set<int> frames_toggled_by_mouse_hover;
  92. int last_frame_selected;
  93. float scale_ratio;
  94. int thumbnail_default_size;
  95. float thumbnail_zoom;
  96. float max_thumbnail_zoom;
  97. float min_thumbnail_zoom;
  98. float sheet_zoom;
  99. float max_sheet_zoom;
  100. float min_sheet_zoom;
  101. Size2i _get_frame_count() const;
  102. Size2i _get_frame_size() const;
  103. Size2i _get_offset() const;
  104. Size2i _get_separation() const;
  105. void _load_pressed();
  106. void _file_load_request(const PoolVector<String> &p_path, int p_at_pos = -1);
  107. void _copy_pressed();
  108. void _paste_pressed();
  109. void _empty_pressed();
  110. void _empty2_pressed();
  111. void _delete_pressed();
  112. void _up_pressed();
  113. void _down_pressed();
  114. void _update_library(bool p_skip_selector = false);
  115. void _animation_select();
  116. void _animation_name_edited();
  117. void _animation_add();
  118. void _animation_remove();
  119. void _animation_remove_confirmed();
  120. void _animation_search_text_changed(const String &p_text);
  121. void _animation_loop_changed();
  122. void _animation_fps_changed(double p_value);
  123. void _tree_input(const Ref<InputEvent> &p_event);
  124. void _zoom_in();
  125. void _zoom_out();
  126. void _zoom_reset();
  127. bool updating;
  128. bool updating_split_settings = false; // Skip SpinBox/Range callback when setting value by code.
  129. UndoRedo *undo_redo;
  130. Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
  131. bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
  132. void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
  133. void _open_sprite_sheet();
  134. void _prepare_sprite_sheet(const String &p_file);
  135. int _sheet_preview_position_to_frame_index(const Vector2 &p_position);
  136. void _sheet_preview_draw();
  137. void _sheet_spin_changed(double p_value, int p_dominant_param);
  138. void _sheet_preview_input(const Ref<InputEvent> &p_event);
  139. void _sheet_scroll_input(const Ref<InputEvent> &p_event);
  140. void _sheet_add_frames();
  141. void _sheet_zoom_on_position(float p_zoom, const Vector2 &p_position);
  142. void _sheet_zoom_in();
  143. void _sheet_zoom_out();
  144. void _sheet_zoom_reset();
  145. void _sheet_select_clear_all_frames();
  146. protected:
  147. void _notification(int p_what);
  148. void _gui_input(Ref<InputEvent> p_event);
  149. static void _bind_methods();
  150. public:
  151. void set_undo_redo(UndoRedo *p_undo_redo) { undo_redo = p_undo_redo; }
  152. void edit(SpriteFrames *p_frames);
  153. SpriteFramesEditor();
  154. };
  155. class SpriteFramesEditorPlugin : public EditorPlugin {
  156. GDCLASS(SpriteFramesEditorPlugin, EditorPlugin);
  157. SpriteFramesEditor *frames_editor;
  158. EditorNode *editor;
  159. Button *button;
  160. public:
  161. virtual String get_name() const { return "SpriteFrames"; }
  162. bool has_main_screen() const { return false; }
  163. virtual void edit(Object *p_object);
  164. virtual bool handles(Object *p_object) const;
  165. virtual void make_visible(bool p_visible);
  166. SpriteFramesEditorPlugin(EditorNode *p_node);
  167. ~SpriteFramesEditorPlugin();
  168. };
  169. #endif // SPRITE_FRAMES_EDITOR_PLUGIN_H