You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-08 12:40:44 +00:00
TextureEditorPlugin: Add borders to 3D and Layered editors
This commit is contained in:
@@ -83,9 +83,8 @@ void Texture3DEditor::_notification(int p_what) {
|
|||||||
|
|
||||||
case NOTIFICATION_DRAW: {
|
case NOTIFICATION_DRAW: {
|
||||||
Ref<Texture2D> checkerboard = get_editor_theme_icon(SNAME("Checkerboard"));
|
Ref<Texture2D> checkerboard = get_editor_theme_icon(SNAME("Checkerboard"));
|
||||||
Size2 size = get_size();
|
draw_texture_rect(checkerboard, texture_rect->get_rect(), true);
|
||||||
|
_draw_outline();
|
||||||
draw_texture_rect(checkerboard, Rect2(Point2(), size), true);
|
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case NOTIFICATION_THEME_CHANGED: {
|
case NOTIFICATION_THEME_CHANGED: {
|
||||||
@@ -93,6 +92,7 @@ void Texture3DEditor::_notification(int p_what) {
|
|||||||
Ref<Font> metadata_label_font = get_theme_font(SNAME("expression"), EditorStringName(EditorFonts));
|
Ref<Font> metadata_label_font = get_theme_font(SNAME("expression"), EditorStringName(EditorFonts));
|
||||||
info->add_theme_font_override(SceneStringName(font), metadata_label_font);
|
info->add_theme_font_override(SceneStringName(font), metadata_label_font);
|
||||||
}
|
}
|
||||||
|
theme_cache.outline_color = get_theme_color(SNAME("extra_border_color_1"), EditorStringName(Editor));
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -120,6 +120,12 @@ void Texture3DEditor::_update_material(bool p_texture_changed) {
|
|||||||
material->set_shader_parameter("u_channel_factors", channel_selector->get_selected_channel_factors());
|
material->set_shader_parameter("u_channel_factors", channel_selector->get_selected_channel_factors());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Texture3DEditor::_draw_outline() {
|
||||||
|
const float outline_width = Math::round(EDSCALE);
|
||||||
|
const Rect2 outline_rect = texture_rect->get_rect().grow(outline_width * 0.5);
|
||||||
|
draw_rect(outline_rect, theme_cache.outline_color, false, outline_width);
|
||||||
|
}
|
||||||
|
|
||||||
void Texture3DEditor::_make_shaders() {
|
void Texture3DEditor::_make_shaders() {
|
||||||
shader.instantiate();
|
shader.instantiate();
|
||||||
shader->set_code(texture_3d_shader);
|
shader->set_code(texture_3d_shader);
|
||||||
@@ -149,7 +155,7 @@ void Texture3DEditor::_texture_rect_update_area() {
|
|||||||
int ofs_x = (size.width - tex_width) / 2;
|
int ofs_x = (size.width - tex_width) / 2;
|
||||||
int ofs_y = (size.height - tex_height) / 2;
|
int ofs_y = (size.height - tex_height) / 2;
|
||||||
|
|
||||||
texture_rect->set_position(Vector2(ofs_x, ofs_y));
|
texture_rect->set_position(Vector2(ofs_x, ofs_y - Math::round(EDSCALE)));
|
||||||
texture_rect->set_size(Vector2(tex_width, tex_height));
|
texture_rect->set_size(Vector2(tex_width, tex_height));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,10 @@ class ColorChannelSelector;
|
|||||||
class Texture3DEditor : public Control {
|
class Texture3DEditor : public Control {
|
||||||
GDCLASS(Texture3DEditor, Control);
|
GDCLASS(Texture3DEditor, Control);
|
||||||
|
|
||||||
|
struct ThemeCache {
|
||||||
|
Color outline_color;
|
||||||
|
} theme_cache;
|
||||||
|
|
||||||
SpinBox *layer = nullptr;
|
SpinBox *layer = nullptr;
|
||||||
Label *info = nullptr;
|
Label *info = nullptr;
|
||||||
Ref<Texture3D> texture;
|
Ref<Texture3D> texture;
|
||||||
@@ -54,6 +58,8 @@ class Texture3DEditor : public Control {
|
|||||||
|
|
||||||
bool setting = false;
|
bool setting = false;
|
||||||
|
|
||||||
|
void _draw_outline();
|
||||||
|
|
||||||
void _make_shaders();
|
void _make_shaders();
|
||||||
|
|
||||||
void _layer_changed(double) {
|
void _layer_changed(double) {
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ void TexturePreview::_notification(int p_what) {
|
|||||||
|
|
||||||
bg_rect->set_color(get_theme_color(SNAME("dark_color_2"), EditorStringName(Editor)));
|
bg_rect->set_color(get_theme_color(SNAME("dark_color_2"), EditorStringName(Editor)));
|
||||||
checkerboard->set_texture(get_editor_theme_icon(SNAME("Checkerboard")));
|
checkerboard->set_texture(get_editor_theme_icon(SNAME("Checkerboard")));
|
||||||
cached_outline_color = get_theme_color(SNAME("extra_border_color_1"), EditorStringName(Editor));
|
theme_cache.outline_color = get_theme_color(SNAME("extra_border_color_1"), EditorStringName(Editor));
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -104,7 +104,7 @@ void TexturePreview::_notification(int p_what) {
|
|||||||
void TexturePreview::_draw_outline() {
|
void TexturePreview::_draw_outline() {
|
||||||
const float outline_width = Math::round(EDSCALE);
|
const float outline_width = Math::round(EDSCALE);
|
||||||
const Rect2 outline_rect = Rect2(Vector2(), outline_overlay->get_size()).grow(outline_width * 0.5);
|
const Rect2 outline_rect = Rect2(Vector2(), outline_overlay->get_size()).grow(outline_width * 0.5);
|
||||||
outline_overlay->draw_rect(outline_rect, cached_outline_color, false, outline_width);
|
outline_overlay->draw_rect(outline_rect, theme_cache.outline_color, false, outline_width);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TexturePreview::_update_texture_display_ratio() {
|
void TexturePreview::_update_texture_display_ratio() {
|
||||||
|
|||||||
@@ -45,6 +45,10 @@ class TexturePreview : public MarginContainer {
|
|||||||
GDCLASS(TexturePreview, MarginContainer);
|
GDCLASS(TexturePreview, MarginContainer);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
struct ThemeCache {
|
||||||
|
Color outline_color;
|
||||||
|
} theme_cache;
|
||||||
|
|
||||||
TextureRect *texture_display = nullptr;
|
TextureRect *texture_display = nullptr;
|
||||||
|
|
||||||
MarginContainer *margin_container = nullptr;
|
MarginContainer *margin_container = nullptr;
|
||||||
@@ -57,8 +61,6 @@ private:
|
|||||||
|
|
||||||
ColorChannelSelector *channel_selector = nullptr;
|
ColorChannelSelector *channel_selector = nullptr;
|
||||||
|
|
||||||
Color cached_outline_color;
|
|
||||||
|
|
||||||
void _draw_outline();
|
void _draw_outline();
|
||||||
void _update_metadata_label_text();
|
void _update_metadata_label_text();
|
||||||
|
|
||||||
|
|||||||
@@ -239,9 +239,8 @@ void TextureLayeredEditor::_notification(int p_what) {
|
|||||||
|
|
||||||
case NOTIFICATION_DRAW: {
|
case NOTIFICATION_DRAW: {
|
||||||
Ref<Texture2D> checkerboard = get_editor_theme_icon(SNAME("Checkerboard"));
|
Ref<Texture2D> checkerboard = get_editor_theme_icon(SNAME("Checkerboard"));
|
||||||
Size2 size = get_size();
|
draw_texture_rect(checkerboard, texture_rect->get_rect(), true);
|
||||||
|
_draw_outline();
|
||||||
draw_texture_rect(checkerboard, Rect2(Point2(), size), true);
|
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case NOTIFICATION_THEME_CHANGED: {
|
case NOTIFICATION_THEME_CHANGED: {
|
||||||
@@ -249,6 +248,7 @@ void TextureLayeredEditor::_notification(int p_what) {
|
|||||||
Ref<Font> metadata_label_font = get_theme_font(SNAME("expression"), EditorStringName(EditorFonts));
|
Ref<Font> metadata_label_font = get_theme_font(SNAME("expression"), EditorStringName(EditorFonts));
|
||||||
info->add_theme_font_override(SceneStringName(font), metadata_label_font);
|
info->add_theme_font_override(SceneStringName(font), metadata_label_font);
|
||||||
}
|
}
|
||||||
|
theme_cache.outline_color = get_theme_color(SNAME("extra_border_color_1"), EditorStringName(Editor));
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -296,6 +296,12 @@ void TextureLayeredEditor::on_selected_channels_changed() {
|
|||||||
_update_material(false);
|
_update_material(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextureLayeredEditor::_draw_outline() {
|
||||||
|
const float outline_width = Math::round(EDSCALE);
|
||||||
|
const Rect2 outline_rect = texture_rect->get_rect().grow(outline_width * 0.5);
|
||||||
|
draw_rect(outline_rect, theme_cache.outline_color, false, outline_width);
|
||||||
|
}
|
||||||
|
|
||||||
void TextureLayeredEditor::_make_shaders() {
|
void TextureLayeredEditor::_make_shaders() {
|
||||||
shaders[0].instantiate();
|
shaders[0].instantiate();
|
||||||
shaders[0]->set_code(array_2d_shader);
|
shaders[0]->set_code(array_2d_shader);
|
||||||
@@ -333,7 +339,7 @@ void TextureLayeredEditor::_texture_rect_update_area() {
|
|||||||
int ofs_x = (size.width - tex_width) / 2;
|
int ofs_x = (size.width - tex_width) / 2;
|
||||||
int ofs_y = (size.height - tex_height) / 2;
|
int ofs_y = (size.height - tex_height) / 2;
|
||||||
|
|
||||||
texture_rect->set_position(Vector2(ofs_x, ofs_y));
|
texture_rect->set_position(Vector2(ofs_x, ofs_y - Math::round(EDSCALE)));
|
||||||
texture_rect->set_size(Vector2(tex_width, tex_height));
|
texture_rect->set_size(Vector2(tex_width, tex_height));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,10 @@ class ColorChannelSelector;
|
|||||||
class TextureLayeredEditor : public Control {
|
class TextureLayeredEditor : public Control {
|
||||||
GDCLASS(TextureLayeredEditor, Control);
|
GDCLASS(TextureLayeredEditor, Control);
|
||||||
|
|
||||||
|
struct ThemeCache {
|
||||||
|
Color outline_color;
|
||||||
|
} theme_cache;
|
||||||
|
|
||||||
SpinBox *layer = nullptr;
|
SpinBox *layer = nullptr;
|
||||||
Label *info = nullptr;
|
Label *info = nullptr;
|
||||||
Ref<TextureLayered> texture;
|
Ref<TextureLayered> texture;
|
||||||
@@ -56,6 +60,8 @@ class TextureLayeredEditor : public Control {
|
|||||||
|
|
||||||
ColorChannelSelector *channel_selector = nullptr;
|
ColorChannelSelector *channel_selector = nullptr;
|
||||||
|
|
||||||
|
void _draw_outline();
|
||||||
|
|
||||||
void _make_shaders();
|
void _make_shaders();
|
||||||
void _update_material(bool p_texture_changed);
|
void _update_material(bool p_texture_changed);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user