Path: blob/master/editor/scene/2d/path_2d_editor_plugin.h
9903 views
/**************************************************************************/1/* path_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/path_2d.h"34#include "scene/gui/box_container.h"3536class CanvasItemEditor;37class ConfirmationDialog;38class MenuButton;3940class Path2DEditor : public HBoxContainer {41GDCLASS(Path2DEditor, HBoxContainer);4243friend class Path2DEditorPlugin;4445CanvasItemEditor *canvas_item_editor = nullptr;46Panel *panel = nullptr;47Path2D *node = nullptr;4849enum Mode {50MODE_CREATE,51MODE_EDIT,52MODE_EDIT_CURVE,53MODE_DELETE,54MODE_CLOSE,55MODE_CLEAR_POINTS,56};5758Mode mode = MODE_EDIT;59HBoxContainer *toolbar = nullptr;60Button *curve_clear_points = nullptr;61Button *curve_close = nullptr;62Button *curve_create = nullptr;63Button *curve_del = nullptr;64Button *curve_edit = nullptr;65Button *curve_edit_curve = nullptr;66MenuButton *handle_menu = nullptr;6768Button *create_curve_button = nullptr;69ConfirmationDialog *clear_points_dialog = nullptr;7071bool mirror_handle_angle = true;72bool mirror_handle_length = true;73bool on_edge = false;7475enum HandleOption {76HANDLE_OPTION_ANGLE,77HANDLE_OPTION_LENGTH,78};7980enum Action {81ACTION_NONE,82ACTION_MOVING_POINT,83ACTION_MOVING_NEW_POINT,84ACTION_MOVING_NEW_POINT_FROM_SPLIT,85ACTION_MOVING_IN,86ACTION_MOVING_OUT,87};8889Action action = ACTION_NONE;90int action_point = 0;91Point2 moving_from;92Point2 moving_screen_from;93float orig_in_length = 0.0f;94float orig_out_length = 0.0f;95Vector2 edge_point;96Vector2 original_mouse_pos;9798// Number of control points in range of the last click.99// 0, 1, or 2.100int control_points_in_range = 0;101102void _mode_selected(int p_mode);103void _handle_option_pressed(int p_option);104void _cancel_current_action();105106void _node_visibility_changed();107void _update_toolbar();108109void _create_curve();110void _confirm_clear_points();111void _clear_curve_points(Path2D *p_path2d);112void _restore_curve_points(Path2D *p_path2d, const PackedVector2Array &p_points);113114RID debug_mesh_rid;115RID debug_handle_mesh_rid;116RID debug_handle_multimesh_rid;117118RID debug_handle_curve_multimesh_rid;119RID debug_handle_sharp_multimesh_rid;120RID debug_handle_smooth_multimesh_rid;121122LocalVector<Vector2> debug_handle_lines;123LocalVector<Transform2D> debug_handle_curve_transforms;124LocalVector<Transform2D> debug_handle_sharp_transforms;125LocalVector<Transform2D> debug_handle_smooth_transforms;126127protected:128void _notification(int p_what);129void _node_removed(Node *p_node);130static void _bind_methods();131132public:133bool forward_gui_input(const Ref<InputEvent> &p_event);134void forward_canvas_draw_over_viewport(Control *p_overlay);135void edit(Node *p_path2d);136Path2DEditor();137~Path2DEditor();138};139140class Path2DEditorPlugin : public EditorPlugin {141GDCLASS(Path2DEditorPlugin, EditorPlugin);142143Path2DEditor *path2d_editor = nullptr;144145public:146virtual bool forward_canvas_gui_input(const Ref<InputEvent> &p_event) override { return path2d_editor->forward_gui_input(p_event); }147virtual void forward_canvas_draw_over_viewport(Control *p_overlay) override { path2d_editor->forward_canvas_draw_over_viewport(p_overlay); }148149virtual String get_plugin_name() const override { return "Path2D"; }150bool has_main_screen() const override { return false; }151virtual void edit(Object *p_object) override;152virtual bool handles(Object *p_object) const override;153virtual void make_visible(bool p_visible) override;154155Path2DEditorPlugin();156};157158159