sprite_region_editor_plugin.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*************************************************************************/
  2. /* sprite_region_editor_plugin.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Author: Mariano Suligoy */
  11. /* */
  12. /* Permission is hereby granted, free of charge, to any person obtaining */
  13. /* a copy of this software and associated documentation files (the */
  14. /* "Software"), to deal in the Software without restriction, including */
  15. /* without limitation the rights to use, copy, modify, merge, publish, */
  16. /* distribute, sublicense, and/or sell copies of the Software, and to */
  17. /* permit persons to whom the Software is furnished to do so, subject to */
  18. /* the following conditions: */
  19. /* */
  20. /* The above copyright notice and this permission notice shall be */
  21. /* included in all copies or substantial portions of the Software. */
  22. /* */
  23. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  24. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  25. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  26. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  27. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  28. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  29. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  30. /*************************************************************************/
  31. #ifndef SPRITE_REGION_EDITOR_PLUGIN_H
  32. #define SPRITE_REGION_EDITOR_PLUGIN_H
  33. #include "canvas_item_editor_plugin.h"
  34. #include "tools/editor/editor_plugin.h"
  35. #include "tools/editor/editor_node.h"
  36. #include "scene/2d/sprite.h"
  37. class SpriteRegionEditor : public HBoxContainer {
  38. OBJ_TYPE(SpriteRegionEditor, HBoxContainer );
  39. ToolButton *edit_node;
  40. // Button *use_region;
  41. ToolButton *b_snap_enable;
  42. ToolButton *b_snap_grid;
  43. TextureFrame *icon_zoom;
  44. HSlider *zoom;
  45. SpinBox *zoom_value;
  46. Control *edit_draw;
  47. VScrollBar *vscroll;
  48. HScrollBar *hscroll;
  49. Sprite *node;
  50. EditorNode *editor;
  51. AcceptDialog *dlg_editor;
  52. UndoRedo* undo_redo;
  53. Vector2 draw_ofs;
  54. float draw_zoom;
  55. bool updating_scroll;
  56. bool use_snap;
  57. bool snap_show_grid;
  58. Vector2 snap_offset;
  59. Vector2 snap_step;
  60. Rect2 rect;
  61. Rect2 rect_prev;
  62. bool drag;
  63. bool creating;
  64. Vector2 drag_from;
  65. int drag_index;
  66. AcceptDialog *error;
  67. void _set_use_snap(bool p_use);
  68. void _set_show_grid(bool p_show);
  69. void _set_snap_off_x(float p_val);
  70. void _set_snap_off_y(float p_val);
  71. void _set_snap_step_x(float p_val);
  72. void _set_snap_step_y(float p_val);
  73. protected:
  74. void _notification(int p_what);
  75. void _node_removed(Node *p_node);
  76. static void _bind_methods();
  77. Vector2 snap_point(Vector2 p_target) const;
  78. public:
  79. void edit();
  80. void _edit_node();
  81. void _region_draw();
  82. void _region_input(const InputEvent &p_input);
  83. void _scroll_changed(float);
  84. void edit(Node *p_sprite);
  85. SpriteRegionEditor(EditorNode* p_editor);
  86. };
  87. class SpriteRegionEditorPlugin : public EditorPlugin
  88. {
  89. OBJ_TYPE( SpriteRegionEditorPlugin, EditorPlugin );
  90. SpriteRegionEditor *region_editor;
  91. EditorNode *editor;
  92. public:
  93. virtual String get_name() const { return "Sprite"; }
  94. bool has_main_screen() const { return false; }
  95. virtual void edit(Object *p_node);
  96. virtual bool handles(Object *p_node) const;
  97. virtual void make_visible(bool p_visible);
  98. SpriteRegionEditorPlugin(EditorNode *p_node);
  99. };
  100. #endif // SPRITE_REGION_EDITOR_PLUGIN_H