texture_region_editor_plugin.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Author: Mariano Suligoy */
  12. /* */
  13. /* Permission is hereby granted, free of charge, to any person obtaining */
  14. /* a copy of this software and associated documentation files (the */
  15. /* "Software"), to deal in the Software without restriction, including */
  16. /* without limitation the rights to use, copy, modify, merge, publish, */
  17. /* distribute, sublicense, and/or sell copies of the Software, and to */
  18. /* permit persons to whom the Software is furnished to do so, subject to */
  19. /* the following conditions: */
  20. /* */
  21. /* The above copyright notice and this permission notice shall be */
  22. /* included in all copies or substantial portions of the Software. */
  23. /* */
  24. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  25. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  26. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  27. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  28. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  29. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  30. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  31. /*************************************************************************/
  32. #ifndef TEXTURE_REGION_EDITOR_PLUGIN_H
  33. #define TEXTURE_REGION_EDITOR_PLUGIN_H
  34. #include "canvas_item_editor_plugin.h"
  35. #include "editor/editor_node.h"
  36. #include "editor/editor_plugin.h"
  37. #include "scene/2d/sprite.h"
  38. #include "scene/gui/nine_patch_rect.h"
  39. #include "scene/resources/style_box.h"
  40. #include "scene/resources/texture.h"
  41. class TextureRegionEditor : public Control {
  42. GDCLASS(TextureRegionEditor, Control);
  43. enum SnapMode {
  44. SNAP_NONE,
  45. SNAP_PIXEL,
  46. SNAP_GRID,
  47. SNAP_AUTOSLICE
  48. };
  49. friend class TextureRegionEditorPlugin;
  50. MenuButton *snap_mode_button;
  51. TextureRect *icon_zoom;
  52. ToolButton *zoom_in;
  53. ToolButton *zoom_reset;
  54. ToolButton *zoom_out;
  55. HBoxContainer *hb_grid; //For showing/hiding the grid controls when changing the SnapMode
  56. SpinBox *sb_step_y;
  57. SpinBox *sb_step_x;
  58. SpinBox *sb_off_y;
  59. SpinBox *sb_off_x;
  60. SpinBox *sb_sep_y;
  61. SpinBox *sb_sep_x;
  62. Control *edit_draw;
  63. VScrollBar *vscroll;
  64. HScrollBar *hscroll;
  65. EditorNode *editor;
  66. UndoRedo *undo_redo;
  67. Vector2 draw_ofs;
  68. float draw_zoom;
  69. bool updating_scroll;
  70. int snap_mode;
  71. Vector2 snap_offset;
  72. Vector2 snap_step;
  73. Vector2 snap_separation;
  74. NinePatchRect *node_ninepatch;
  75. Sprite *node_sprite;
  76. Ref<StyleBoxTexture> obj_styleBox;
  77. Ref<AtlasTexture> atlas_tex;
  78. Rect2 rect;
  79. Rect2 rect_prev;
  80. float prev_margin;
  81. int edited_margin;
  82. List<Rect2> autoslice_cache;
  83. bool drag;
  84. bool creating;
  85. Vector2 drag_from;
  86. int drag_index;
  87. void _set_snap_mode(int p_mode);
  88. void _set_snap_off_x(float p_val);
  89. void _set_snap_off_y(float p_val);
  90. void _set_snap_step_x(float p_val);
  91. void _set_snap_step_y(float p_val);
  92. void _set_snap_sep_x(float p_val);
  93. void _set_snap_sep_y(float p_val);
  94. void _zoom_in();
  95. void _zoom_reset();
  96. void _zoom_out();
  97. void apply_rect(const Rect2 &rect);
  98. protected:
  99. void _notification(int p_what);
  100. void _node_removed(Object *p_obj);
  101. static void _bind_methods();
  102. Vector2 snap_point(Vector2 p_target) const;
  103. virtual void _changed_callback(Object *p_changed, const char *p_prop);
  104. public:
  105. void _edit_region();
  106. void _region_draw();
  107. void _region_input(const Ref<InputEvent> &p_input);
  108. void _scroll_changed(float);
  109. void edit(Object *p_obj);
  110. TextureRegionEditor(EditorNode *p_editor);
  111. };
  112. class TextureRegionEditorPlugin : public EditorPlugin {
  113. GDCLASS(TextureRegionEditorPlugin, EditorPlugin);
  114. Button *region_button;
  115. TextureRegionEditor *region_editor;
  116. EditorNode *editor;
  117. public:
  118. virtual String get_name() const { return "TextureRegion"; }
  119. bool has_main_screen() const { return false; }
  120. virtual void edit(Object *p_object);
  121. virtual bool handles(Object *p_object) const;
  122. virtual void make_visible(bool p_visible);
  123. void set_state(const Dictionary &p_state);
  124. Dictionary get_state() const;
  125. TextureRegionEditorPlugin(EditorNode *p_node);
  126. };
  127. #endif // TEXTURE_REGION_EDITOR_PLUGIN_H