Path: blob/master/editor/scene/gradient_editor_plugin.h
9896 views
/**************************************************************************/1/* gradient_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"3435class EditorSpinSlider;36class ColorPicker;37class PopupPanel;38class GradientTexture1D;3940class GradientEdit : public Control {41GDCLASS(GradientEdit, Control);4243Ref<Gradient> gradient;44Ref<GradientTexture1D> preview_texture;4546PopupPanel *popup = nullptr;47ColorPicker *picker = nullptr;4849bool snap_enabled = false;50int snap_count = 10;5152enum GrabMode {53GRAB_NONE,54GRAB_ADD,55GRAB_MOVE56};5758GrabMode grabbing = GRAB_NONE;59float pre_grab_offset = 0.5;60int pre_grab_index = -1;61int selected_index = -1;62int hovered_index = -1;6364// Make sure to use the scaled values below.65const int BASE_SPACING = 4;66const int BASE_HANDLE_WIDTH = 8;6768int draw_spacing = BASE_SPACING;69int handle_width = BASE_HANDLE_WIDTH;7071int _get_gradient_rect_width() const;7273void _color_changed(const Color &p_color);74void _redraw();7576int _get_point_at(int p_xpos) const;77int _predict_insertion_index(float p_offset);78void _show_color_picker();7980protected:81virtual void gui_input(const Ref<InputEvent> &p_event) override;82void _notification(int p_what);83static void _bind_methods();8485public:86void set_gradient(const Ref<Gradient> &p_gradient);87const Ref<Gradient> &get_gradient() const;8889ColorPicker *get_picker() const;90PopupPanel *get_popup() const;9192void set_selected_index(int p_index);9394void add_point(float p_offset, const Color &p_color);95void remove_point(int p_index);96void set_offset(int p_index, float p_offset);97void set_color(int p_index, const Color &p_color);98void reverse_gradient();99100void set_snap_enabled(bool p_enabled);101void set_snap_count(int p_count);102103GradientEdit();104};105106class GradientEditor : public VBoxContainer {107GDCLASS(GradientEditor, VBoxContainer);108109Button *reverse_button = nullptr;110Button *snap_button = nullptr;111EditorSpinSlider *snap_count_edit = nullptr;112GradientEdit *gradient_editor_rect = nullptr;113114void _set_snap_enabled(bool p_enabled);115void _set_snap_count(int p_count);116117protected:118void _notification(int p_what);119120public:121static const int DEFAULT_SNAP;122void set_gradient(const Ref<Gradient> &p_gradient);123124GradientEditor();125};126127class EditorInspectorPluginGradient : public EditorInspectorPlugin {128GDCLASS(EditorInspectorPluginGradient, EditorInspectorPlugin);129130public:131virtual bool can_handle(Object *p_object) override;132virtual void parse_begin(Object *p_object) override;133};134135class GradientEditorPlugin : public EditorPlugin {136GDCLASS(GradientEditorPlugin, EditorPlugin);137138public:139virtual String get_plugin_name() const override { return "Gradient"; }140141GradientEditorPlugin();142};143144145