Path: blob/master/editor/scene/gradient_editor_plugin.h
20952 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"34#include "scene/resources/gradient.h"3536class EditorSpinSlider;37class ColorPicker;38class PopupPanel;39class GradientTexture1D;4041class GradientEdit : public Control {42GDCLASS(GradientEdit, Control);4344Ref<Gradient> gradient;45Ref<GradientTexture1D> preview_texture;4647PopupPanel *popup = nullptr;48ColorPicker *picker = nullptr;4950bool snap_enabled = false;51int snap_count = 10;5253enum GrabMode {54GRAB_NONE,55GRAB_ADD,56GRAB_MOVE57};5859GrabMode grabbing = GRAB_NONE;60float pre_grab_offset = 0.5;61int pre_grab_index = -1;62int selected_index = -1;63int hovered_index = -1;6465// Make sure to use the scaled values below.66const int BASE_SPACING = 4;67const int BASE_HANDLE_WIDTH = 8;6869int draw_spacing = BASE_SPACING;70int handle_width = BASE_HANDLE_WIDTH;7172int _get_gradient_rect_width() const;7374void _color_changed(const Color &p_color);75void _redraw();7677int _get_point_at(int p_xpos) const;78int _predict_insertion_index(float p_offset);79void _show_color_picker();8081protected:82virtual void gui_input(const Ref<InputEvent> &p_event) override;83void _notification(int p_what);84static void _bind_methods();8586public:87void set_gradient(const Ref<Gradient> &p_gradient);88const Ref<Gradient> &get_gradient() const;8990ColorPicker *get_picker() const;91PopupPanel *get_popup() const;9293void set_selected_index(int p_index);9495void add_point(float p_offset, const Color &p_color);96void remove_point(int p_index);97void set_offset(int p_index, float p_offset);98void set_color(int p_index, const Color &p_color);99void reverse_gradient();100101void set_snap_enabled(bool p_enabled);102void set_snap_count(int p_count);103104GradientEdit();105};106107class GradientEditor : public VBoxContainer {108GDCLASS(GradientEditor, VBoxContainer);109110Button *reverse_button = nullptr;111Button *snap_button = nullptr;112EditorSpinSlider *snap_count_edit = nullptr;113GradientEdit *gradient_editor_rect = nullptr;114115void _set_snap_enabled(bool p_enabled);116void _set_snap_count(int p_count);117118protected:119void _notification(int p_what);120121public:122static const int DEFAULT_SNAP;123void set_gradient(const Ref<Gradient> &p_gradient);124125GradientEditor();126};127128class EditorInspectorPluginGradient : public EditorInspectorPlugin {129GDCLASS(EditorInspectorPluginGradient, EditorInspectorPlugin);130131public:132virtual bool can_handle(Object *p_object) override;133virtual void parse_begin(Object *p_object) override;134};135136class GradientEditorPlugin : public EditorPlugin {137GDCLASS(GradientEditorPlugin, EditorPlugin);138139public:140virtual String get_plugin_name() const override { return "Gradient"; }141142GradientEditorPlugin();143};144145146