Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/scene/texture/texture_layered_editor_plugin.h
21318 views
1
/**************************************************************************/
2
/* texture_layered_editor_plugin.h */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#pragma once
32
33
#include "editor/inspector/editor_inspector.h"
34
#include "editor/plugins/editor_plugin.h"
35
#include "scene/gui/spin_box.h"
36
#include "scene/resources/material.h"
37
#include "scene/resources/shader.h"
38
#include "scene/resources/texture.h"
39
40
class ColorChannelSelector;
41
42
class TextureLayeredEditor : public Control {
43
GDCLASS(TextureLayeredEditor, Control);
44
45
struct ThemeCache {
46
Color outline_color;
47
} theme_cache;
48
49
SpinBox *layer = nullptr;
50
Label *info = nullptr;
51
Ref<TextureLayered> texture;
52
53
static inline Ref<Shader> shaders[3];
54
Ref<ShaderMaterial> materials[3];
55
56
float x_rot = 0;
57
float y_rot = 0;
58
Control *texture_rect = nullptr;
59
60
bool setting = false;
61
Vector2 original_mouse_pos;
62
bool use_rotation = false;
63
64
ColorChannelSelector *channel_selector = nullptr;
65
66
void _draw_outline();
67
68
void _make_materials();
69
void _update_material(bool p_texture_changed);
70
71
void _layer_changed(double) {
72
if (!setting) {
73
_update_material(false);
74
}
75
}
76
77
void _texture_changed();
78
79
void _texture_rect_update_area();
80
void _texture_rect_draw();
81
82
void _update_gui();
83
84
void on_selected_channels_changed();
85
86
protected:
87
void _notification(int p_what);
88
virtual void gui_input(const Ref<InputEvent> &p_event) override;
89
90
public:
91
static void init_shaders();
92
static void finish_shaders();
93
94
void edit(Ref<TextureLayered> p_texture);
95
96
TextureLayeredEditor();
97
};
98
99
class EditorInspectorPluginLayeredTexture : public EditorInspectorPlugin {
100
GDCLASS(EditorInspectorPluginLayeredTexture, EditorInspectorPlugin);
101
102
public:
103
virtual bool can_handle(Object *p_object) override;
104
virtual void parse_begin(Object *p_object) override;
105
};
106
107
class TextureLayeredEditorPlugin : public EditorPlugin {
108
GDCLASS(TextureLayeredEditorPlugin, EditorPlugin);
109
110
public:
111
virtual String get_plugin_name() const override { return "TextureLayered"; }
112
113
TextureLayeredEditorPlugin();
114
};
115
116