Path: blob/master/editor/scene/2d/sprite_2d_editor_plugin.h
9903 views
/**************************************************************************/1/* sprite_2d_editor_plugin.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */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/**************************************************************************/2930#pragma once3132#include "editor/plugins/editor_plugin.h"33#include "scene/2d/sprite_2d.h"34#include "scene/gui/spin_box.h"3536class AcceptDialog;37class Button;38class ConfirmationDialog;39class EditorZoomWidget;40class HBoxContainer;41class MenuButton;42class Panel;43class ViewPanner;4445class Sprite2DEditor : public Control {46GDCLASS(Sprite2DEditor, Control);4748enum Menu {49MENU_OPTION_CONVERT_TO_MESH_2D,50MENU_OPTION_CONVERT_TO_POLYGON_2D,51MENU_OPTION_CREATE_COLLISION_POLY_2D,52MENU_OPTION_CREATE_LIGHT_OCCLUDER_2D53};5455HBoxContainer *top_hb = nullptr;5657Menu selected_menu_item;5859Sprite2D *node = nullptr;6061MenuButton *options = nullptr;62Button *resize_region_rect = nullptr;6364ConfirmationDialog *outline_dialog = nullptr;6566AcceptDialog *err_dialog = nullptr;6768ConfirmationDialog *debug_uv_dialog = nullptr;69Panel *debug_uv = nullptr;70Vector<Vector2> uv_lines;71Vector<Vector<Vector2>> outline_lines;72Vector<Vector<Vector2>> computed_outline_lines;73Vector<Vector2> computed_vertices;74Vector<Vector2> computed_uv;75Vector<int> computed_indices;7677HScrollBar *h_scroll = nullptr;78VScrollBar *v_scroll = nullptr;79EditorZoomWidget *zoom_widget = nullptr;80Ref<ViewPanner> panner;81Vector2 draw_offset;82real_t draw_zoom = 1.0;8384SpinBox *simplification = nullptr;85SpinBox *grow_pixels = nullptr;86SpinBox *shrink_pixels = nullptr;87Button *update_preview = nullptr;8889void _menu_option(int p_option);9091//void _create_uv_lines();92friend class Sprite2DEditorPlugin;9394void _debug_uv_input(const Ref<InputEvent> &p_input);95void _debug_uv_draw();96void _popup_debug_uv_dialog();97void _center_view();98void _pan_callback(Vector2 p_scroll_vec, Ref<InputEvent> p_event);99void _zoom_callback(float p_zoom_factor, Vector2 p_origin, Ref<InputEvent> p_event);100void _update_zoom_and_pan(bool p_zoom_at_center);101void _update_mesh_data();102103void _create_node();104void _convert_to_mesh_2d_node();105void _convert_to_polygon_2d_node();106void _create_collision_polygon_2d_node();107void _create_light_occluder_2d_node();108109void _add_as_sibling_or_child(Node *p_own_node, Node *p_new_node);110111void _sync_sprite_resize_mode();112void _update_sprite_resize_mode_button();113114protected:115void _node_removed(Node *p_node);116void _notification(int p_what);117static void _bind_methods();118119public:120void edit(Sprite2D *p_sprite);121Sprite2DEditor();122};123124class Sprite2DEditorPlugin : public EditorPlugin {125GDCLASS(Sprite2DEditorPlugin, EditorPlugin);126127Sprite2DEditor *sprite_editor = nullptr;128129Label *dragging_mode_hint = nullptr;130131public:132virtual String get_plugin_name() const override { return "Sprite2D"; }133bool has_main_screen() const override { return false; }134virtual void edit(Object *p_object) override;135virtual bool handles(Object *p_object) const override;136virtual void make_visible(bool p_visible) override;137138Sprite2DEditorPlugin();139};140141142