texture_region_editor_plugin.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*************************************************************************/
  2. /* texture_region_editor_plugin.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 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 TEXTURE_REGION_EDITOR_PLUGIN_H
  31. #define TEXTURE_REGION_EDITOR_PLUGIN_H
  32. #include "canvas_item_editor_plugin.h"
  33. #include "editor/editor_node.h"
  34. #include "editor/editor_plugin.h"
  35. #include "scene/2d/sprite.h"
  36. #include "scene/gui/patch_9_frame.h"
  37. #include "scene/resources/style_box.h"
  38. #include "scene/resources/texture.h"
  39. class TextureRegionEditor : public Control {
  40. OBJ_TYPE(TextureRegionEditor, Control);
  41. enum SnapMode {
  42. SNAP_NONE,
  43. SNAP_PIXEL,
  44. SNAP_GRID,
  45. SNAP_AUTOSLICE
  46. };
  47. friend class TextureRegionEditorPlugin;
  48. MenuButton *snap_mode_button;
  49. TextureFrame *icon_zoom;
  50. ToolButton *zoom_in;
  51. ToolButton *zoom_reset;
  52. ToolButton *zoom_out;
  53. HBoxContainer *hb_grid; //For showing/hiding the grid controls when changing the SnapMode
  54. SpinBox *sb_step_y;
  55. SpinBox *sb_step_x;
  56. SpinBox *sb_off_y;
  57. SpinBox *sb_off_x;
  58. SpinBox *sb_sep_y;
  59. SpinBox *sb_sep_x;
  60. Control *edit_draw;
  61. VScrollBar *vscroll;
  62. HScrollBar *hscroll;
  63. EditorNode *editor;
  64. UndoRedo *undo_redo;
  65. Vector2 draw_ofs;
  66. float draw_zoom;
  67. bool updating_scroll;
  68. int snap_mode;
  69. Vector2 snap_offset;
  70. Vector2 snap_step;
  71. Vector2 snap_separation;
  72. Patch9Frame *node_patch9;
  73. Sprite *node_sprite;
  74. Ref<StyleBoxTexture> obj_styleBox;
  75. Ref<AtlasTexture> atlas_tex;
  76. Rect2 rect;
  77. Rect2 rect_prev;
  78. float prev_margin;
  79. int edited_margin;
  80. List<Rect2> autoslice_cache;
  81. bool drag;
  82. bool creating;
  83. Vector2 drag_from;
  84. int drag_index;
  85. void _set_snap_mode(int p_mode);
  86. void _set_snap_off_x(float p_val);
  87. void _set_snap_off_y(float p_val);
  88. void _set_snap_step_x(float p_val);
  89. void _set_snap_step_y(float p_val);
  90. void _set_snap_sep_x(float p_val);
  91. void _set_snap_sep_y(float p_val);
  92. void _zoom_in();
  93. void _zoom_reset();
  94. void _zoom_out();
  95. void apply_rect(const Rect2 &rect);
  96. protected:
  97. void _notification(int p_what);
  98. void _node_removed(Object *p_obj);
  99. static void _bind_methods();
  100. Vector2 snap_point(Vector2 p_target) const;
  101. virtual void _changed_callback(Object *p_changed, const char *p_prop);
  102. public:
  103. void _edit_region();
  104. void _region_draw();
  105. void _region_input(const InputEvent &p_input);
  106. void _scroll_changed(float);
  107. void edit(Object *p_obj);
  108. TextureRegionEditor(EditorNode *p_editor);
  109. };
  110. class TextureRegionEditorPlugin : public EditorPlugin {
  111. OBJ_TYPE(TextureRegionEditorPlugin, EditorPlugin);
  112. Button *region_button;
  113. TextureRegionEditor *region_editor;
  114. EditorNode *editor;
  115. public:
  116. virtual String get_name() const { return "TextureRegion"; }
  117. bool has_main_screen() const { return false; }
  118. virtual void edit(Object *p_node);
  119. virtual bool handles(Object *p_node) const;
  120. virtual void make_visible(bool p_visible);
  121. void set_state(const Dictionary &p_state);
  122. Dictionary get_state() const;
  123. TextureRegionEditorPlugin(EditorNode *p_node);
  124. };
  125. #endif // TEXTURE_REGION_EDITOR_PLUGIN_H