Path: blob/master/editor/scene/2d/polygon_2d_editor_plugin.h
9903 views
/**************************************************************************/1/* polygon_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/scene/2d/abstract_polygon_2d_editor.h"33#include "scene/2d/polygon_2d.h"3435class AcceptDialog;36class ButtonGroup;37class EditorZoomWidget;38class HScrollBar;39class HSlider;40class Label;41class MenuButton;42class Panel;43class ScrollContainer;44class SpinBox;45class TextureRect;46class ViewPanner;47class VScrollBar;4849class Polygon2DEditor : public AbstractPolygon2DEditor {50GDCLASS(Polygon2DEditor, AbstractPolygon2DEditor);5152enum {53MENU_POLYGON_TO_UV,54MENU_UV_TO_POLYGON,55MENU_UV_CLEAR,56MENU_GRID_SETTINGS,57};5859enum Mode {60MODE_POINTS,61MODE_POLYGONS,62MODE_UV,63MODE_BONES,64MODE_MAX65};6667enum Action {68ACTION_CREATE,69ACTION_CREATE_INTERNAL,70ACTION_REMOVE_INTERNAL,71ACTION_EDIT_POINT,72ACTION_MOVE,73ACTION_ROTATE,74ACTION_SCALE,75ACTION_ADD_POLYGON,76ACTION_REMOVE_POLYGON,77ACTION_PAINT_WEIGHT,78ACTION_CLEAR_WEIGHT,79ACTION_MAX80};8182Polygon2D *node = nullptr;83Polygon2D *previous_node = nullptr;8485Button *dock_button = nullptr;86VBoxContainer *polygon_edit = nullptr;87Mode current_mode = MODE_MAX; // Uninitialized.88Button *mode_buttons[MODE_MAX];89Action selected_action = ACTION_CREATE;90Button *action_buttons[ACTION_MAX];91Button *b_snap_enable = nullptr;92Button *b_snap_grid = nullptr;93MenuButton *edit_menu = nullptr;9495Control *canvas = nullptr;96Panel *canvas_background = nullptr;97Polygon2D *preview_polygon = nullptr;98EditorZoomWidget *zoom_widget = nullptr;99HScrollBar *hscroll = nullptr;100VScrollBar *vscroll = nullptr;101bool center_view_on_draw = false;102103Ref<ViewPanner> panner;104void _pan_callback(Vector2 p_scroll_vec, Ref<InputEvent> p_event);105void _zoom_callback(float p_zoom_factor, Vector2 p_origin, Ref<InputEvent> p_event);106Vector2 draw_offset;107real_t draw_zoom = 1.0;108109VBoxContainer *bone_scroll_main_vb = nullptr;110ScrollContainer *bone_scroll = nullptr;111VBoxContainer *bone_scroll_vb = nullptr;112Button *sync_bones = nullptr;113HSlider *bone_paint_strength = nullptr;114SpinBox *bone_paint_radius = nullptr;115Label *bone_paint_radius_label = nullptr;116bool bone_painting = false;117int bone_painting_bone = 0;118Vector<float> prev_weights;119Vector2 bone_paint_pos;120AcceptDialog *grid_settings = nullptr;121122void _sync_bones();123void _update_bone_list();124125Vector<Vector2> editing_points;126Vector<Vector2> previous_uv;127Vector<Vector2> previous_polygon;128Vector<Color> previous_colors;129int previous_internal_vertices = 0;130Array previous_bones;131Array previous_polygons;132133Vector2 create_to;134int point_drag_index = -1;135bool is_dragging = false;136bool is_creating = false;137Vector<int> polygon_create;138Action current_action = ACTION_CREATE;139Vector2 drag_from;140141AcceptDialog *error = nullptr;142143bool use_snap = false;144bool snap_show_grid = false;145Vector2 snap_offset;146Vector2 snap_step;147148void _edit_menu_option(int p_option);149150void _cancel_editing();151void _update_polygon_editing_state();152void _update_available_modes();153154void _center_view();155void _update_zoom_and_pan(bool p_zoom_at_center);156void _canvas_input(const Ref<InputEvent> &p_input);157void _center_view_on_draw(bool p_enabled = true);158void _canvas_draw();159void _set_action(int p_mode);160161void _set_use_snap(bool p_use);162void _set_show_grid(bool p_show);163void _set_snap_off_x(real_t p_val);164void _set_snap_off_y(real_t p_val);165void _set_snap_step_x(real_t p_val);166void _set_snap_step_y(real_t p_val);167168void _select_mode(int p_mode);169void _bone_paint_selected(int p_index);170171int _get_polygon_count() const override;172173protected:174virtual Node2D *_get_node() const override;175virtual void _set_node(Node *p_polygon) override;176177virtual Vector2 _get_offset(int p_idx) const override;178179virtual bool _has_uv() const override { return true; }180virtual void _commit_action() override;181182void _notification(int p_what);183static void _bind_methods();184185Vector2 snap_point(Vector2 p_target) const;186187public:188Polygon2DEditor();189};190191class Polygon2DEditorPlugin : public AbstractPolygon2DEditorPlugin {192GDCLASS(Polygon2DEditorPlugin, AbstractPolygon2DEditorPlugin);193194public:195Polygon2DEditorPlugin();196};197198199