Skip to content

Commit b0626fe

Browse files
committed
TextureEditorPlugin: Add borders to 3D and Layered editors
1 parent 215acd5 commit b0626fe

File tree

6 files changed

+38
-12
lines changed

6 files changed

+38
-12
lines changed

editor/plugins/texture_3d_editor_plugin.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,16 @@ void Texture3DEditor::_notification(int p_what) {
8383

8484
case NOTIFICATION_DRAW: {
8585
Ref<Texture2D> checkerboard = get_editor_theme_icon(SNAME("Checkerboard"));
86-
Size2 size = get_size();
87-
88-
draw_texture_rect(checkerboard, Rect2(Point2(), size), true);
86+
draw_texture_rect(checkerboard, texture_rect->get_rect(), true);
87+
_draw_outline();
8988
} break;
9089

9190
case NOTIFICATION_THEME_CHANGED: {
9291
if (info) {
9392
Ref<Font> metadata_label_font = get_theme_font(SNAME("expression"), EditorStringName(EditorFonts));
9493
info->add_theme_font_override(SceneStringName(font), metadata_label_font);
9594
}
95+
theme_cache.outline_color = get_theme_color(SNAME("extra_border_color_1"), EditorStringName(Editor));
9696
} break;
9797
}
9898
}
@@ -120,6 +120,12 @@ void Texture3DEditor::_update_material(bool p_texture_changed) {
120120
material->set_shader_parameter("u_channel_factors", channel_selector->get_selected_channel_factors());
121121
}
122122

123+
void Texture3DEditor::_draw_outline() {
124+
const float outline_width = Math::round(EDSCALE);
125+
const Rect2 outline_rect = texture_rect->get_rect().grow(outline_width * 0.5);
126+
draw_rect(outline_rect, theme_cache.outline_color, false, outline_width);
127+
}
128+
123129
void Texture3DEditor::_make_shaders() {
124130
shader.instantiate();
125131
shader->set_code(texture_3d_shader);
@@ -149,7 +155,7 @@ void Texture3DEditor::_texture_rect_update_area() {
149155
int ofs_x = (size.width - tex_width) / 2;
150156
int ofs_y = (size.height - tex_height) / 2;
151157

152-
texture_rect->set_position(Vector2(ofs_x, ofs_y));
158+
texture_rect->set_position(Vector2(ofs_x, ofs_y - Math::round(EDSCALE)));
153159
texture_rect->set_size(Vector2(tex_width, tex_height));
154160
}
155161

editor/plugins/texture_3d_editor_plugin.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ class ColorChannelSelector;
4141
class Texture3DEditor : public Control {
4242
GDCLASS(Texture3DEditor, Control);
4343

44+
struct ThemeCache {
45+
Color outline_color;
46+
} theme_cache;
47+
4448
SpinBox *layer = nullptr;
4549
Label *info = nullptr;
4650
Ref<Texture3D> texture;
@@ -54,6 +58,8 @@ class Texture3DEditor : public Control {
5458

5559
bool setting = false;
5660

61+
void _draw_outline();
62+
5763
void _make_shaders();
5864

5965
void _layer_changed(double) {

editor/plugins/texture_editor_plugin.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,15 @@ void TexturePreview::_notification(int p_what) {
9696

9797
bg_rect->set_color(get_theme_color(SNAME("dark_color_2"), EditorStringName(Editor)));
9898
checkerboard->set_texture(get_editor_theme_icon(SNAME("Checkerboard")));
99-
cached_outline_color = get_theme_color(SNAME("extra_border_color_1"), EditorStringName(Editor));
99+
theme_cache.outline_color = get_theme_color(SNAME("extra_border_color_1"), EditorStringName(Editor));
100100
} break;
101101
}
102102
}
103103

104104
void TexturePreview::_draw_outline() {
105105
const float outline_width = Math::round(EDSCALE);
106106
const Rect2 outline_rect = Rect2(Vector2(), outline_overlay->get_size()).grow(outline_width * 0.5);
107-
outline_overlay->draw_rect(outline_rect, cached_outline_color, false, outline_width);
107+
outline_overlay->draw_rect(outline_rect, theme_cache.outline_color, false, outline_width);
108108
}
109109

110110
void TexturePreview::_update_texture_display_ratio() {

editor/plugins/texture_editor_plugin.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ class TexturePreview : public MarginContainer {
4545
GDCLASS(TexturePreview, MarginContainer);
4646

4747
private:
48+
struct ThemeCache {
49+
Color outline_color;
50+
} theme_cache;
51+
4852
TextureRect *texture_display = nullptr;
4953

5054
MarginContainer *margin_container = nullptr;
@@ -57,8 +61,6 @@ class TexturePreview : public MarginContainer {
5761

5862
ColorChannelSelector *channel_selector = nullptr;
5963

60-
Color cached_outline_color;
61-
6264
void _draw_outline();
6365
void _update_metadata_label_text();
6466

editor/plugins/texture_layered_editor_plugin.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,16 +239,16 @@ void TextureLayeredEditor::_notification(int p_what) {
239239

240240
case NOTIFICATION_DRAW: {
241241
Ref<Texture2D> checkerboard = get_editor_theme_icon(SNAME("Checkerboard"));
242-
Size2 size = get_size();
243-
244-
draw_texture_rect(checkerboard, Rect2(Point2(), size), true);
242+
draw_texture_rect(checkerboard, texture_rect->get_rect(), true);
243+
_draw_outline();
245244
} break;
246245

247246
case NOTIFICATION_THEME_CHANGED: {
248247
if (info) {
249248
Ref<Font> metadata_label_font = get_theme_font(SNAME("expression"), EditorStringName(EditorFonts));
250249
info->add_theme_font_override(SceneStringName(font), metadata_label_font);
251250
}
251+
theme_cache.outline_color = get_theme_color(SNAME("extra_border_color_1"), EditorStringName(Editor));
252252
} break;
253253
}
254254
}
@@ -296,6 +296,12 @@ void TextureLayeredEditor::on_selected_channels_changed() {
296296
_update_material(false);
297297
}
298298

299+
void TextureLayeredEditor::_draw_outline() {
300+
const float outline_width = Math::round(EDSCALE);
301+
const Rect2 outline_rect = texture_rect->get_rect().grow(outline_width * 0.5);
302+
draw_rect(outline_rect, theme_cache.outline_color, false, outline_width);
303+
}
304+
299305
void TextureLayeredEditor::_make_shaders() {
300306
shaders[0].instantiate();
301307
shaders[0]->set_code(array_2d_shader);
@@ -333,7 +339,7 @@ void TextureLayeredEditor::_texture_rect_update_area() {
333339
int ofs_x = (size.width - tex_width) / 2;
334340
int ofs_y = (size.height - tex_height) / 2;
335341

336-
texture_rect->set_position(Vector2(ofs_x, ofs_y));
342+
texture_rect->set_position(Vector2(ofs_x, ofs_y - Math::round(EDSCALE)));
337343
texture_rect->set_size(Vector2(tex_width, tex_height));
338344
}
339345

editor/plugins/texture_layered_editor_plugin.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ class ColorChannelSelector;
4141
class TextureLayeredEditor : public Control {
4242
GDCLASS(TextureLayeredEditor, Control);
4343

44+
struct ThemeCache {
45+
Color outline_color;
46+
} theme_cache;
47+
4448
SpinBox *layer = nullptr;
4549
Label *info = nullptr;
4650
Ref<TextureLayered> texture;
@@ -56,6 +60,8 @@ class TextureLayeredEditor : public Control {
5660

5761
ColorChannelSelector *channel_selector = nullptr;
5862

63+
void _draw_outline();
64+
5965
void _make_shaders();
6066
void _update_material(bool p_texture_changed);
6167

0 commit comments

Comments
 (0)