Path: blob/master/editor/scene/gui/control_editor_plugin.h
9903 views
/**************************************************************************/1/* control_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/box_container.h"35#include "scene/gui/button.h"36#include "scene/gui/margin_container.h"3738class CheckBox;39class CheckButton;40class EditorSelection;41class GridContainer;42class Label;43class OptionButton;44class PanelContainer;45class PopupPanel;46class Separator;47class TextureRect;4849// Inspector controls.50class ControlPositioningWarning : public MarginContainer {51GDCLASS(ControlPositioningWarning, MarginContainer);5253Control *control_node = nullptr;5455PanelContainer *bg_panel = nullptr;56GridContainer *grid = nullptr;57TextureRect *title_icon = nullptr;58TextureRect *hint_icon = nullptr;59Label *title_label = nullptr;60Label *hint_label = nullptr;61Control *hint_filler_left = nullptr;62Control *hint_filler_right = nullptr;6364void _update_warning();65void _update_toggler();66virtual void gui_input(const Ref<InputEvent> &p_event) override;6768protected:69void _notification(int p_notification);7071public:72void set_control(Control *p_node);7374ControlPositioningWarning();75};7677class EditorPropertyAnchorsPreset : public EditorProperty {78GDCLASS(EditorPropertyAnchorsPreset, EditorProperty);79OptionButton *options = nullptr;8081void _option_selected(int p_which);8283protected:84virtual void _set_read_only(bool p_read_only) override;85void _notification(int p_what);8687public:88void setup(const Vector<String> &p_options);89virtual void update_property() override;90EditorPropertyAnchorsPreset();91};9293class EditorPropertySizeFlags : public EditorProperty {94GDCLASS(EditorPropertySizeFlags, EditorProperty);9596enum FlagPreset {97SIZE_FLAGS_PRESET_FILL,98SIZE_FLAGS_PRESET_SHRINK_BEGIN,99SIZE_FLAGS_PRESET_SHRINK_CENTER,100SIZE_FLAGS_PRESET_SHRINK_END,101SIZE_FLAGS_PRESET_CUSTOM,102};103104OptionButton *flag_presets = nullptr;105CheckBox *flag_expand = nullptr;106VBoxContainer *flag_options = nullptr;107Vector<CheckBox *> flag_checks;108109bool vertical = false;110111bool keep_selected_preset = false;112113void _preset_selected(int p_which);114void _expand_toggled();115void _flag_toggled();116117protected:118virtual void _set_read_only(bool p_read_only) override;119120public:121void setup(const Vector<String> &p_options, bool p_vertical);122virtual void update_property() override;123EditorPropertySizeFlags();124};125126class EditorInspectorPluginControl : public EditorInspectorPlugin {127GDCLASS(EditorInspectorPluginControl, EditorInspectorPlugin);128129bool inside_control_category = false;130131public:132virtual bool can_handle(Object *p_object) override;133virtual void parse_category(Object *p_object, const String &p_category) override;134virtual void parse_group(Object *p_object, const String &p_group) override;135virtual 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 = false) override;136};137138// Toolbar controls.139class ControlEditorPopupButton : public Button {140GDCLASS(ControlEditorPopupButton, Button);141142Ref<Texture2D> arrow_icon;143144PopupPanel *popup_panel = nullptr;145VBoxContainer *popup_vbox = nullptr;146147void _popup_visibility_changed(bool p_visible);148149protected:150void _notification(int p_what);151152public:153virtual Size2 get_minimum_size() const override;154virtual void toggled(bool p_pressed) override;155156VBoxContainer *get_popup_hbox() const { return popup_vbox; }157158ControlEditorPopupButton();159};160161class ControlEditorPresetPicker : public MarginContainer {162GDCLASS(ControlEditorPresetPicker, MarginContainer);163164virtual void _preset_button_pressed(const int p_preset) {}165166protected:167static constexpr int grid_separation = 0;168HashMap<int, Button *> preset_buttons;169170void _add_row_button(HBoxContainer *p_row, const int p_preset, const String &p_name);171void _add_separator(BoxContainer *p_box, Separator *p_separator);172};173174class AnchorPresetPicker : public ControlEditorPresetPicker {175GDCLASS(AnchorPresetPicker, ControlEditorPresetPicker);176177virtual void _preset_button_pressed(const int p_preset) override;178179protected:180void _notification(int p_notification);181static void _bind_methods();182183public:184AnchorPresetPicker();185};186187class SizeFlagPresetPicker : public ControlEditorPresetPicker {188GDCLASS(SizeFlagPresetPicker, ControlEditorPresetPicker);189190CheckButton *expand_button = nullptr;191192bool vertical = false;193194virtual void _preset_button_pressed(const int p_preset) override;195void _expand_button_pressed();196197protected:198void _notification(int p_notification);199static void _bind_methods();200201public:202void set_allowed_flags(Vector<SizeFlags> &p_flags);203void set_expand_flag(bool p_expand);204205SizeFlagPresetPicker(bool p_vertical);206};207208class ControlEditorToolbar : public HBoxContainer {209GDCLASS(ControlEditorToolbar, HBoxContainer);210211EditorSelection *editor_selection = nullptr;212213ControlEditorPopupButton *anchors_button = nullptr;214ControlEditorPopupButton *containers_button = nullptr;215Button *anchor_mode_button = nullptr;216217SizeFlagPresetPicker *container_h_picker = nullptr;218SizeFlagPresetPicker *container_v_picker = nullptr;219220bool anchors_mode = false;221222void _anchors_preset_selected(int p_preset);223void _anchors_to_current_ratio();224void _anchor_mode_toggled(bool p_status);225void _container_flags_selected(int p_flags, bool p_vertical);226void _expand_flag_toggled(bool p_expand, bool p_vertical);227228Vector2 _position_to_anchor(const Control *p_control, Vector2 position);229bool _is_node_locked(const Node *p_node);230List<Control *> _get_edited_controls();231void _selection_changed();232233protected:234void _notification(int p_notification);235236static ControlEditorToolbar *singleton;237238public:239bool is_anchors_mode_enabled() { return anchors_mode; }240241static ControlEditorToolbar *get_singleton() { return singleton; }242243ControlEditorToolbar();244};245246// Editor plugin.247class ControlEditorPlugin : public EditorPlugin {248GDCLASS(ControlEditorPlugin, EditorPlugin);249250ControlEditorToolbar *toolbar = nullptr;251252public:253virtual String get_plugin_name() const override { return "Control"; }254255ControlEditorPlugin();256};257258259