Path: blob/master/editor/scene/texture/texture_region_editor_plugin.h
9903 views
/**************************************************************************/1/* texture_region_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/inspector/editor_inspector.h"33#include "editor/plugins/editor_plugin.h"34#include "scene/gui/dialogs.h"3536class AtlasTexture;37class NinePatchRect;38class OptionButton;39class PanelContainer;40class Sprite2D;41class Sprite3D;42class StyleBoxTexture;43class ViewPanner;4445class TextureRegionEditor : public AcceptDialog {46GDCLASS(TextureRegionEditor, AcceptDialog);4748enum SnapMode {49SNAP_NONE,50SNAP_PIXEL,51SNAP_GRID,52SNAP_AUTOSLICE53};5455friend class TextureRegionEditorPlugin;56OptionButton *snap_mode_button = nullptr;57Button *zoom_in = nullptr;58Button *zoom_reset = nullptr;59Button *zoom_out = nullptr;60HBoxContainer *hb_grid = nullptr; //For showing/hiding the grid controls when changing the SnapMode61SpinBox *sb_step_y = nullptr;62SpinBox *sb_step_x = nullptr;63SpinBox *sb_off_y = nullptr;64SpinBox *sb_off_x = nullptr;65SpinBox *sb_sep_y = nullptr;66SpinBox *sb_sep_x = nullptr;6768PanelContainer *texture_preview = nullptr;69Panel *texture_overlay = nullptr;7071VScrollBar *vscroll = nullptr;72HScrollBar *hscroll = nullptr;7374Vector2 draw_ofs;75float draw_zoom = 1.0;76float min_draw_zoom = 1.0;77float max_draw_zoom = 1.0;78bool updating_scroll = false;7980SnapMode snap_mode = SNAP_NONE;81Vector2 snap_offset;82Vector2 snap_step;83Vector2 snap_separation;8485Sprite2D *node_sprite_2d = nullptr;86Sprite3D *node_sprite_3d = nullptr;87NinePatchRect *node_ninepatch = nullptr;88Ref<StyleBoxTexture> res_stylebox;89Ref<AtlasTexture> res_atlas_texture;9091Rect2 rect;92Rect2 rect_prev;93float prev_margin = 0.0f;94int edited_margin = -1;95HashMap<RID, List<Rect2>> cache_map;96List<Rect2> autoslice_cache;97bool autoslice_is_dirty = true;9899bool drag = false;100bool creating = false;101Vector2 drag_from;102int drag_index = -1;103bool request_center = false;104105Ref<ViewPanner> panner;106void _pan_callback(Vector2 p_scroll_vec, Ref<InputEvent> p_event);107void _zoom_callback(float p_zoom_factor, Vector2 p_origin, Ref<InputEvent> p_event);108void _scroll_changed(float);109Transform2D _get_offset_transform() const;110111void _set_snap_mode(int p_mode);112void _set_snap_off_x(float p_val);113void _set_snap_off_y(float p_val);114void _set_snap_step_x(float p_val);115void _set_snap_step_y(float p_val);116void _set_snap_sep_x(float p_val);117void _set_snap_sep_y(float p_val);118119void _zoom_on_position(float p_zoom, Point2 p_position = Point2());120void _zoom_in();121void _zoom_reset();122void _zoom_out();123124void _apply_rect(const Rect2 &p_rect);125void _update_rect();126void _update_autoslice();127128Ref<Texture2D> _get_edited_object_texture() const;129Rect2 _get_edited_object_region() const;130void _texture_changed();131void _node_removed(Node *p_node);132133void _edit_region();134void _clear_edited_object();135136void _draw_margin_line(Vector2 p_from, Vector2 p_to);137138void _set_grid_parameters_clamping(bool p_enabled);139140protected:141void _notification(int p_what);142virtual void shortcut_input(const Ref<InputEvent> &p_event) override;143static void _bind_methods();144145void _texture_preview_draw();146void _texture_overlay_draw();147void _texture_overlay_input(const Ref<InputEvent> &p_input);148149Vector2 snap_point(Vector2 p_target) const;150151public:152void edit(Object *p_obj);153154TextureRegionEditor();155};156157//158159class EditorInspectorPluginTextureRegion : public EditorInspectorPlugin {160GDCLASS(EditorInspectorPluginTextureRegion, EditorInspectorPlugin);161162TextureRegionEditor *texture_region_editor = nullptr;163164void _region_edit(Object *p_object);165166public:167virtual bool can_handle(Object *p_object) override;168virtual bool parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const BitField<PropertyUsageFlags> p_usage, const bool p_wide) override;169170EditorInspectorPluginTextureRegion();171};172173class TextureRegionEditorPlugin : public EditorPlugin {174GDCLASS(TextureRegionEditorPlugin, EditorPlugin);175176public:177virtual String get_plugin_name() const override { return "TextureRegion"; }178179TextureRegionEditorPlugin();180};181182183