Przeglądaj źródła

Merge pull request #78858 from MewPurPur/tweak-mesh-preview

Improve material and mesh preview buttons
Rémi Verschelde 2 lat temu
rodzic
commit
02709d57ee

+ 31 - 6
editor/editor_themes.cpp

@@ -176,12 +176,6 @@ void EditorColorMap::create() {
 	add_conversion_exception("Sky");
 	add_conversion_exception("EditorControlAnchor");
 	add_conversion_exception("DefaultProjectIcon");
-	add_conversion_exception("GuiChecked");
-	add_conversion_exception("GuiRadioChecked");
-	add_conversion_exception("GuiIndeterminate");
-	add_conversion_exception("GuiCloseCustomizable");
-	add_conversion_exception("GuiGraphNodePort");
-	add_conversion_exception("GuiResizer");
 	add_conversion_exception("ZoomMore");
 	add_conversion_exception("ZoomLess");
 	add_conversion_exception("ZoomReset");
@@ -191,6 +185,18 @@ void EditorColorMap::create() {
 	add_conversion_exception("StatusSuccess");
 	add_conversion_exception("StatusWarning");
 	add_conversion_exception("OverbrightIndicator");
+	add_conversion_exception("MaterialPreviewCube");
+	add_conversion_exception("MaterialPreviewSphere");
+	add_conversion_exception("MaterialPreviewLight1");
+	add_conversion_exception("MaterialPreviewLight2");
+
+	// GUI
+	add_conversion_exception("GuiChecked");
+	add_conversion_exception("GuiRadioChecked");
+	add_conversion_exception("GuiIndeterminate");
+	add_conversion_exception("GuiCloseCustomizable");
+	add_conversion_exception("GuiGraphNodePort");
+	add_conversion_exception("GuiResizer");
 	add_conversion_exception("GuiMiniCheckerboard");
 
 	/// Code Editor.
@@ -944,6 +950,25 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
 	editor_log_button_pressed->set_border_color(accent_color);
 	theme->set_stylebox("pressed", "EditorLogFilterButton", editor_log_button_pressed);
 
+	// Buttons in material previews
+	const Color dim_light_color = icon_normal_color.darkened(0.24);
+	const Color dim_light_highlighted_color = icon_normal_color.darkened(0.18);
+	Ref<StyleBox> sb_empty_borderless = make_empty_stylebox();
+
+	theme->set_type_variation("PreviewLightButton", "Button");
+	// When pressed, don't use the accent color tint. When unpressed, dim the icon.
+	theme->set_color("icon_normal_color", "PreviewLightButton", dim_light_color);
+	theme->set_color("icon_focus_color", "PreviewLightButton", dim_light_color);
+	theme->set_color("icon_pressed_color", "PreviewLightButton", icon_normal_color);
+	theme->set_color("icon_hover_pressed_color", "PreviewLightButton", icon_normal_color);
+	// Unpressed icon is dim, so use a dim highlight.
+	theme->set_color("icon_hover_color", "PreviewLightButton", dim_light_highlighted_color);
+
+	theme->set_stylebox("normal", "PreviewLightButton", sb_empty_borderless);
+	theme->set_stylebox("hover", "PreviewLightButton", sb_empty_borderless);
+	theme->set_stylebox("focus", "PreviewLightButton", sb_empty_borderless);
+	theme->set_stylebox("pressed", "PreviewLightButton", sb_empty_borderless);
+
 	// ProjectTag
 	{
 		theme->set_type_variation("ProjectTag", "Button");

+ 1 - 1
editor/icons/MaterialPreviewCube.svg

@@ -1 +1 @@
-<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="M8 1 1 4v8l7 3 7-3V4z" fill="#d6d6d6"/><path d="m1 4 7 3 7-3-7-3z" fill="#fff"/><path d="m8 15-7-3V4l7 3z" fill="#e0e0e0"/><path d="m8 15 7-3V4L8 7z" fill="#d6d6d6"/></svg>
+<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="m8 1 7 3v8l-7 3-7-3V4z" fill="none" stroke="#000" stroke-opacity=".8" stroke-width="2" stroke-linejoin="round"/><path d="M8 1 1 4v8l7 3 7-3V4z" fill="#d6d6d6"/><path d="m1 4 7 3 7-3-7-3z" fill="#f9f9f9"/><path d="m8 15-7-3V4l7 3z" fill="#e0e0e0"/></svg>

+ 0 - 1
editor/icons/MaterialPreviewCubeOff.svg

@@ -1 +0,0 @@
-<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="M8 1 1 4v8l7 3 7-3V4z" fill="#d6d6d6"/><path d="m1 4 7 3 7-3-7-3z" fill="#fff"/><path d="m8 15-7-3V4l7 3z" fill="#e0e0e0"/><path d="m8 15 7-3V4L8 7z" fill="#d6d6d6"/><path d="M8 1 1 4v8l7 3 7-3V4z" fill-opacity=".235"/></svg>

+ 1 - 1
editor/icons/MaterialPreviewLight1.svg

@@ -1 +1 @@
-<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="M7 1v2h2V1zM3.758 2.344 2.344 3.758l1.414 1.414 1.414-1.414zm8.484 0-1.414 1.414 1.414 1.414 1.414-1.414zM8 4a4 4 0 0 0 0 8 4 4 0 0 0 0-8zM7 5h2v6H8V6H7zM1 7v2h2V7zm12 0v2h2V7zm-9.242 3.828-1.414 1.414 1.414 1.414 1.414-1.414zm8.484 0-1.414 1.414 1.414 1.414 1.414-1.414zM7 13v2h2v-2z" fill="#e0e0e0"/></svg>
+<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><g fill="none" stroke="#000" stroke-width="2" stroke-opacity=".8" stroke-linejoin="round"><path d="M7 1v2h2V1zM3.758 2.344 2.344 3.758l1.414 1.414 1.414-1.414zm8.484 0-1.414 1.414 1.414 1.414 1.414-1.414zM8 4a4 4 0 0 0 0 8 4 4 0 0 0 0-8zM1 7v2h2V7zm12 0v2h2V7zm-9.242 3.828-1.414 1.414 1.414 1.414 1.414-1.414zm8.484 0-1.414 1.414 1.414 1.414 1.414-1.414zM7 13v2h2v-2z"/><circle cx="8" cy="8" r="3.5" fill="#000"/></g><path d="M7 1v2h2V1zM3.758 2.344 2.344 3.758l1.414 1.414 1.414-1.414zm8.484 0-1.414 1.414 1.414 1.414 1.414-1.414zM8 4a4 4 0 0 0 0 8 4 4 0 0 0 0-8zM1 7v2h2V7zm12 0v2h2V7zm-9.242 3.828-1.414 1.414 1.414 1.414 1.414-1.414zm8.484 0-1.414 1.414 1.414 1.414 1.414-1.414zM7 13v2h2v-2zm1-7.875a.75.75 0 0 1 1.145.625V11h-1.5V7.152l-1 .667-.75-1.2z" fill="#f9f9f9"/></svg>

+ 0 - 1
editor/icons/MaterialPreviewLight1Off.svg

@@ -1 +0,0 @@
-<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="M7 1v2h2V1zM3.758 2.344 2.344 3.758l1.414 1.414 1.414-1.414zm8.484 0-1.414 1.414 1.414 1.414 1.414-1.414zM8 4a4 4 0 0 0 0 8 4 4 0 0 0 0-8zM7 5h2v6H8V6H7zM1 7v2h2V7zm12 0v2h2V7zm-9.242 3.828-1.414 1.414 1.414 1.414 1.414-1.414zm8.484 0-1.414 1.414 1.414 1.414 1.414-1.414zM7 13v2h2v-2z" fill="#e0e0e0" fill-opacity=".69"/></svg>

+ 1 - 1
editor/icons/MaterialPreviewLight2.svg

@@ -1 +1 @@
-<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="M7 1v2h2V1zM3.758 2.344 2.344 3.758l1.414 1.414 1.414-1.414zm8.484 0-1.414 1.414 1.414 1.414 1.414-1.414zM8 4a4 4 0 0 0 0 8 4 4 0 0 0 0-8zM7 5h2v3H7v1h2v1H6V7h2V6H7zM1 7v2h2V7zm12 0v2h2V7zm-9.242 3.828-1.414 1.414 1.414 1.414 1.414-1.414zm8.484 0-1.414 1.414 1.414 1.414 1.414-1.414zM7 13v2h2v-2z" fill="#e0e0e0"/></svg>
+<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><g fill="none" stroke="#000" stroke-width="2" stroke-opacity=".8" stroke-linejoin="round"><path d="M7 1v2h2V1zM3.758 2.344 2.344 3.758l1.414 1.414 1.414-1.414zm8.484 0-1.414 1.414 1.414 1.414 1.414-1.414zM8 4a4 4 0 0 0 0 8 4 4 0 0 0 0-8zM1 7v2h2V7zm12 0v2h2V7zm-9.242 3.828-1.414 1.414 1.414 1.414 1.414-1.414zm8.484 0-1.414 1.414 1.414 1.414 1.414-1.414zM7 13v2h2v-2z"/><circle cx="8" cy="8" r="3.5" fill="#000"/></g><path d="M7 1v2h2V1zM3.758 2.344 2.344 3.758l1.414 1.414 1.414-1.414zm8.484 0-1.414 1.414 1.414 1.414 1.414-1.414zM8 4a4 4 0 0 0 0 8 4 4 0 0 0 0-8zM1 7v2h2V7zm12 0v2h2V7zm-9.242 3.828-1.414 1.414 1.414 1.414 1.414-1.414zm8.484 0-1.414 1.414 1.414 1.414 1.414-1.414zM7 13v2h2v-2zM5.9 6.45a1.98 1.98 0 1 1 3.4 1.8L8.05 9.5h2V11H6.8a.9.9 0 0 1-.75-1.5L8.3 7.25a.62.62 0 1 0-1.1-.45z" fill="#f9f9f9"/></svg>

+ 0 - 1
editor/icons/MaterialPreviewLight2Off.svg

@@ -1 +0,0 @@
-<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="M7 1v2h2V1zM3.758 2.344 2.344 3.758l1.414 1.414 1.414-1.414zm8.484 0-1.414 1.414 1.414 1.414 1.414-1.414zM8 4a4 4 0 0 0 0 8 4 4 0 0 0 0-8zM7 5h2v3H7v1h2v1H6V7h2V6H7zM1 7v2h2V7zm12 0v2h2V7zm-9.242 3.828-1.414 1.414 1.414 1.414 1.414-1.414zm8.484 0-1.414 1.414 1.414 1.414 1.414-1.414zM7 13v2h2v-2z" fill="#e0e0e0" fill-opacity=".69"/></svg>

+ 1 - 1
editor/icons/MaterialPreviewSphere.svg

@@ -1 +1 @@
-<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="M8 1a7 7 0 0 0 0 14A7 7 0 0 0 8 1zM6 3a2 2 0 0 1 0 4 2 2 0 0 1 0-4z" fill="#e0e0e0"/></svg>
+<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><circle cx="8" cy="8" r="8" fill="#000" fill-opacity=".8"/><path d="M8 1a7 7 0 0 0 0 14A7 7 0 0 0 8 1zM6 7a2 2 0 0 1 0-4 2 2 0 0 1 0 4" fill="#e0e0e0"/></svg>

+ 0 - 1
editor/icons/MaterialPreviewSphereOff.svg

@@ -1 +0,0 @@
-<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="M8 1a7 7 0 0 0 0 14A7 7 0 0 0 8 1zM6 3a2 2 0 0 1 0 4 2 2 0 0 1 0-4z" fill="#e0e0e0"/><path d="M8 1a7 7 0 0 0 0 14A7 7 0 0 0 8 1zM6 3a2 2 0 0 1 0 4 2 2 0 0 1 0-4z" fill-opacity=".23529"/></svg>

+ 45 - 49
editor/plugins/material_editor_plugin.cpp

@@ -39,9 +39,9 @@
 #include "scene/3d/light_3d.h"
 #include "scene/3d/mesh_instance_3d.h"
 #include "scene/gui/box_container.h"
+#include "scene/gui/button.h"
 #include "scene/gui/color_rect.h"
 #include "scene/gui/subviewport_container.h"
-#include "scene/gui/texture_button.h"
 #include "scene/main/viewport.h"
 #include "scene/resources/fog_material.h"
 #include "scene/resources/particle_process_material.h"
@@ -63,15 +63,11 @@ void MaterialEditor::gui_input(const Ref<InputEvent> &p_event) {
 void MaterialEditor::_update_theme_item_cache() {
 	Control::_update_theme_item_cache();
 
-	theme_cache.light_1_on = get_theme_icon(SNAME("MaterialPreviewLight1"), SNAME("EditorIcons"));
-	theme_cache.light_1_off = get_theme_icon(SNAME("MaterialPreviewLight1Off"), SNAME("EditorIcons"));
-	theme_cache.light_2_on = get_theme_icon(SNAME("MaterialPreviewLight2"), SNAME("EditorIcons"));
-	theme_cache.light_2_off = get_theme_icon(SNAME("MaterialPreviewLight2Off"), SNAME("EditorIcons"));
+	theme_cache.light_1_icon = get_theme_icon(SNAME("MaterialPreviewLight1"), SNAME("EditorIcons"));
+	theme_cache.light_2_icon = get_theme_icon(SNAME("MaterialPreviewLight2"), SNAME("EditorIcons"));
 
-	theme_cache.sphere_on = get_theme_icon(SNAME("MaterialPreviewSphere"), SNAME("EditorIcons"));
-	theme_cache.sphere_off = get_theme_icon(SNAME("MaterialPreviewSphereOff"), SNAME("EditorIcons"));
-	theme_cache.box_on = get_theme_icon(SNAME("MaterialPreviewCube"), SNAME("EditorIcons"));
-	theme_cache.box_off = get_theme_icon(SNAME("MaterialPreviewCubeOff"), SNAME("EditorIcons"));
+	theme_cache.sphere_icon = get_theme_icon(SNAME("MaterialPreviewSphere"), SNAME("EditorIcons"));
+	theme_cache.box_icon = get_theme_icon(SNAME("MaterialPreviewCube"), SNAME("EditorIcons"));
 
 	theme_cache.checkerboard = get_theme_icon(SNAME("Checkerboard"), SNAME("EditorIcons"));
 }
@@ -79,15 +75,11 @@ void MaterialEditor::_update_theme_item_cache() {
 void MaterialEditor::_notification(int p_what) {
 	switch (p_what) {
 		case NOTIFICATION_THEME_CHANGED: {
-			light_1_switch->set_texture_normal(theme_cache.light_1_on);
-			light_1_switch->set_texture_pressed(theme_cache.light_1_off);
-			light_2_switch->set_texture_normal(theme_cache.light_2_on);
-			light_2_switch->set_texture_pressed(theme_cache.light_2_off);
-
-			sphere_switch->set_texture_normal(theme_cache.sphere_off);
-			sphere_switch->set_texture_pressed(theme_cache.sphere_on);
-			box_switch->set_texture_normal(theme_cache.box_off);
-			box_switch->set_texture_pressed(theme_cache.box_on);
+			light_1_switch->set_icon(theme_cache.light_1_icon);
+			light_2_switch->set_icon(theme_cache.light_2_icon);
+
+			sphere_switch->set_icon(theme_cache.sphere_icon);
+			box_switch->set_icon(theme_cache.box_icon);
 		} break;
 
 		case NOTIFICATION_DRAW: {
@@ -135,34 +127,32 @@ void MaterialEditor::edit(Ref<Material> p_material, const Ref<Environment> &p_en
 	_update_rotation();
 }
 
-void MaterialEditor::_button_pressed(Node *p_button) {
-	if (p_button == light_1_switch) {
-		light1->set_visible(!light_1_switch->is_pressed());
-	}
+void MaterialEditor::_on_light_1_switch_pressed() {
+	light1->set_visible(light_1_switch->is_pressed());
+}
 
-	if (p_button == light_2_switch) {
-		light2->set_visible(!light_2_switch->is_pressed());
-	}
+void MaterialEditor::_on_light_2_switch_pressed() {
+	light2->set_visible(light_2_switch->is_pressed());
+}
 
-	if (p_button == box_switch) {
-		box_instance->show();
-		sphere_instance->hide();
-		box_switch->set_pressed(true);
-		sphere_switch->set_pressed(false);
-		EditorSettings::get_singleton()->set_project_metadata("inspector_options", "material_preview_on_sphere", false);
-	}
+void MaterialEditor::_on_sphere_switch_pressed() {
+	box_instance->hide();
+	sphere_instance->show();
+	box_switch->set_pressed(false);
+	sphere_switch->set_pressed(true);
+	EditorSettings::get_singleton()->set_project_metadata("inspector_options", "material_preview_on_sphere", true);
+}
 
-	if (p_button == sphere_switch) {
-		box_instance->hide();
-		sphere_instance->show();
-		box_switch->set_pressed(false);
-		sphere_switch->set_pressed(true);
-		EditorSettings::get_singleton()->set_project_metadata("inspector_options", "material_preview_on_sphere", true);
-	}
+void MaterialEditor::_on_box_switch_pressed() {
+	box_instance->show();
+	sphere_instance->hide();
+	box_switch->set_pressed(true);
+	sphere_switch->set_pressed(false);
+	EditorSettings::get_singleton()->set_project_metadata("inspector_options", "material_preview_on_sphere", false);
 }
 
 MaterialEditor::MaterialEditor() {
-	// canvas item
+	// Canvas item
 
 	vc_2d = memnew(SubViewportContainer);
 	vc_2d->set_stretch(true);
@@ -185,7 +175,7 @@ MaterialEditor::MaterialEditor() {
 
 	layout_2d->set_visible(false);
 
-	// spatial
+	// Spatial
 
 	vc = memnew(SubViewportContainer);
 	vc->set_stretch(true);
@@ -247,32 +237,38 @@ MaterialEditor::MaterialEditor() {
 	VBoxContainer *vb_shape = memnew(VBoxContainer);
 	layout_3d->add_child(vb_shape);
 
-	sphere_switch = memnew(TextureButton);
+	sphere_switch = memnew(Button);
+	sphere_switch->set_theme_type_variation("PreviewLightButton");
 	sphere_switch->set_toggle_mode(true);
 	sphere_switch->set_pressed(true);
 	vb_shape->add_child(sphere_switch);
-	sphere_switch->connect("pressed", callable_mp(this, &MaterialEditor::_button_pressed).bind(sphere_switch));
+	sphere_switch->connect("pressed", callable_mp(this, &MaterialEditor::_on_sphere_switch_pressed));
 
-	box_switch = memnew(TextureButton);
+	box_switch = memnew(Button);
+	box_switch->set_theme_type_variation("PreviewLightButton");
 	box_switch->set_toggle_mode(true);
 	box_switch->set_pressed(false);
 	vb_shape->add_child(box_switch);
-	box_switch->connect("pressed", callable_mp(this, &MaterialEditor::_button_pressed).bind(box_switch));
+	box_switch->connect("pressed", callable_mp(this, &MaterialEditor::_on_box_switch_pressed));
 
 	layout_3d->add_spacer();
 
 	VBoxContainer *vb_light = memnew(VBoxContainer);
 	layout_3d->add_child(vb_light);
 
-	light_1_switch = memnew(TextureButton);
+	light_1_switch = memnew(Button);
+	light_1_switch->set_theme_type_variation("PreviewLightButton");
 	light_1_switch->set_toggle_mode(true);
+	light_1_switch->set_pressed(true);
 	vb_light->add_child(light_1_switch);
-	light_1_switch->connect("pressed", callable_mp(this, &MaterialEditor::_button_pressed).bind(light_1_switch));
+	light_1_switch->connect("pressed", callable_mp(this, &MaterialEditor::_on_light_1_switch_pressed));
 
-	light_2_switch = memnew(TextureButton);
+	light_2_switch = memnew(Button);
+	light_2_switch->set_theme_type_variation("PreviewLightButton");
 	light_2_switch->set_toggle_mode(true);
+	light_2_switch->set_pressed(true);
 	vb_light->add_child(light_2_switch);
-	light_2_switch->connect("pressed", callable_mp(this, &MaterialEditor::_button_pressed).bind(light_2_switch));
+	light_2_switch->connect("pressed", callable_mp(this, &MaterialEditor::_on_light_2_switch_pressed));
 
 	if (EditorSettings::get_singleton()->get_project_metadata("inspector_options", "material_preview_on_sphere", true)) {
 		box_instance->hide();

+ 14 - 16
editor/plugins/material_editor_plugin.h

@@ -44,7 +44,7 @@ class HBoxContainer;
 class MeshInstance3D;
 class SubViewport;
 class SubViewportContainer;
-class TextureButton;
+class Button;
 
 class MaterialEditor : public Control {
 	GDCLASS(MaterialEditor, Control);
@@ -71,27 +71,25 @@ class MaterialEditor : public Control {
 
 	HBoxContainer *layout_3d = nullptr;
 
-	TextureButton *sphere_switch = nullptr;
-	TextureButton *box_switch = nullptr;
-
-	TextureButton *light_1_switch = nullptr;
-	TextureButton *light_2_switch = nullptr;
-
 	Ref<Material> material;
 
+	Button *sphere_switch = nullptr;
+	Button *box_switch = nullptr;
+	Button *light_1_switch = nullptr;
+	Button *light_2_switch = nullptr;
+
 	struct ThemeCache {
-		Ref<Texture2D> light_1_on;
-		Ref<Texture2D> light_1_off;
-		Ref<Texture2D> light_2_on;
-		Ref<Texture2D> light_2_off;
-		Ref<Texture2D> sphere_on;
-		Ref<Texture2D> sphere_off;
-		Ref<Texture2D> box_on;
-		Ref<Texture2D> box_off;
+		Ref<Texture2D> light_1_icon;
+		Ref<Texture2D> light_2_icon;
+		Ref<Texture2D> sphere_icon;
+		Ref<Texture2D> box_icon;
 		Ref<Texture2D> checkerboard;
 	} theme_cache;
 
-	void _button_pressed(Node *p_button);
+	void _on_light_1_switch_pressed();
+	void _on_light_2_switch_pressed();
+	void _on_sphere_switch_pressed();
+	void _on_box_switch_pressed();
 
 protected:
 	virtual void _update_theme_item_cache() override;

+ 21 - 26
editor/plugins/mesh_editor_plugin.cpp

@@ -32,7 +32,7 @@
 
 #include "core/config/project_settings.h"
 #include "editor/editor_scale.h"
-#include "scene/gui/texture_button.h"
+#include "scene/gui/button.h"
 #include "scene/main/viewport.h"
 
 void MeshEditor::gui_input(const Ref<InputEvent> &p_event) {
@@ -42,11 +42,8 @@ void MeshEditor::gui_input(const Ref<InputEvent> &p_event) {
 	if (mm.is_valid() && (mm->get_button_mask().has_flag(MouseButtonMask::LEFT))) {
 		rot_x -= mm->get_relative().y * 0.01;
 		rot_y -= mm->get_relative().x * 0.01;
-		if (rot_x < -Math_PI / 2) {
-			rot_x = -Math_PI / 2;
-		} else if (rot_x > Math_PI / 2) {
-			rot_x = Math_PI / 2;
-		}
+
+		rot_x = CLAMP(rot_x, -Math_PI / 2, Math_PI / 2);
 		_update_rotation();
 	}
 }
@@ -54,19 +51,15 @@ void MeshEditor::gui_input(const Ref<InputEvent> &p_event) {
 void MeshEditor::_update_theme_item_cache() {
 	SubViewportContainer::_update_theme_item_cache();
 
-	theme_cache.light_1_on = get_theme_icon(SNAME("MaterialPreviewLight1"), SNAME("EditorIcons"));
-	theme_cache.light_1_off = get_theme_icon(SNAME("MaterialPreviewLight1Off"), SNAME("EditorIcons"));
-	theme_cache.light_2_on = get_theme_icon(SNAME("MaterialPreviewLight2"), SNAME("EditorIcons"));
-	theme_cache.light_2_off = get_theme_icon(SNAME("MaterialPreviewLight2Off"), SNAME("EditorIcons"));
+	theme_cache.light_1_icon = get_theme_icon(SNAME("MaterialPreviewLight1"), SNAME("EditorIcons"));
+	theme_cache.light_2_icon = get_theme_icon(SNAME("MaterialPreviewLight2"), SNAME("EditorIcons"));
 }
 
 void MeshEditor::_notification(int p_what) {
 	switch (p_what) {
 		case NOTIFICATION_THEME_CHANGED: {
-			light_1_switch->set_texture_normal(theme_cache.light_1_on);
-			light_1_switch->set_texture_pressed(theme_cache.light_1_off);
-			light_2_switch->set_texture_normal(theme_cache.light_2_on);
-			light_2_switch->set_texture_pressed(theme_cache.light_2_off);
+			light_1_switch->set_icon(theme_cache.light_1_icon);
+			light_2_switch->set_icon(theme_cache.light_2_icon);
 		} break;
 	}
 }
@@ -100,21 +93,19 @@ void MeshEditor::edit(Ref<Mesh> p_mesh) {
 	}
 }
 
-void MeshEditor::_button_pressed(Node *p_button) {
-	if (p_button == light_1_switch) {
-		light1->set_visible(!light_1_switch->is_pressed());
-	}
+void MeshEditor::_on_light_1_switch_pressed() {
+	light1->set_visible(light_1_switch->is_pressed());
+}
 
-	if (p_button == light_2_switch) {
-		light2->set_visible(!light_2_switch->is_pressed());
-	}
+void MeshEditor::_on_light_2_switch_pressed() {
+	light2->set_visible(light_2_switch->is_pressed());
 }
 
 MeshEditor::MeshEditor() {
 	viewport = memnew(SubViewport);
 	Ref<World3D> world_3d;
 	world_3d.instantiate();
-	viewport->set_world_3d(world_3d); //use own world
+	viewport->set_world_3d(world_3d); // Use own world.
 	add_child(viewport);
 	viewport->set_disable_input(true);
 	viewport->set_msaa_3d(Viewport::MSAA_4X);
@@ -154,15 +145,19 @@ MeshEditor::MeshEditor() {
 	VBoxContainer *vb_light = memnew(VBoxContainer);
 	hb->add_child(vb_light);
 
-	light_1_switch = memnew(TextureButton);
+	light_1_switch = memnew(Button);
+	light_1_switch->set_theme_type_variation("PreviewLightButton");
 	light_1_switch->set_toggle_mode(true);
+	light_1_switch->set_pressed(true);
 	vb_light->add_child(light_1_switch);
-	light_1_switch->connect("pressed", callable_mp(this, &MeshEditor::_button_pressed).bind(light_1_switch));
+	light_1_switch->connect("pressed", callable_mp(this, &MeshEditor::_on_light_1_switch_pressed));
 
-	light_2_switch = memnew(TextureButton);
+	light_2_switch = memnew(Button);
+	light_2_switch->set_theme_type_variation("PreviewLightButton");
 	light_2_switch->set_toggle_mode(true);
+	light_2_switch->set_pressed(true);
 	vb_light->add_child(light_2_switch);
-	light_2_switch->connect("pressed", callable_mp(this, &MeshEditor::_button_pressed).bind(light_2_switch));
+	light_2_switch->connect("pressed", callable_mp(this, &MeshEditor::_on_light_2_switch_pressed));
 
 	rot_x = 0;
 	rot_y = 0;

+ 7 - 8
editor/plugins/mesh_editor_plugin.h

@@ -41,7 +41,7 @@
 #include "scene/resources/material.h"
 
 class SubViewport;
-class TextureButton;
+class Button;
 
 class MeshEditor : public SubViewportContainer {
 	GDCLASS(MeshEditor, SubViewportContainer);
@@ -59,17 +59,16 @@ class MeshEditor : public SubViewportContainer {
 
 	Ref<Mesh> mesh;
 
-	TextureButton *light_1_switch = nullptr;
-	TextureButton *light_2_switch = nullptr;
+	Button *light_1_switch = nullptr;
+	Button *light_2_switch = nullptr;
 
 	struct ThemeCache {
-		Ref<Texture2D> light_1_on;
-		Ref<Texture2D> light_1_off;
-		Ref<Texture2D> light_2_on;
-		Ref<Texture2D> light_2_off;
+		Ref<Texture2D> light_1_icon;
+		Ref<Texture2D> light_2_icon;
 	} theme_cache;
 
-	void _button_pressed(Node *p_button);
+	void _on_light_1_switch_pressed();
+	void _on_light_2_switch_pressed();
 	void _update_rotation();
 
 protected:

+ 2 - 5
editor/plugins/style_box_editor_plugin.cpp

@@ -110,14 +110,11 @@ StyleBoxPreview::StyleBoxPreview() {
 	set_anchors_and_offsets_preset(PRESET_FULL_RECT);
 
 	grid_preview = memnew(Button);
+	// This theme variation works better than the normal theme because there's no focus highlight.
+	grid_preview->set_theme_type_variation("PreviewLightButton");
 	grid_preview->set_toggle_mode(true);
 	grid_preview->connect("toggled", callable_mp(this, &StyleBoxPreview::_grid_preview_toggled));
 	grid_preview->set_pressed(grid_preview_enabled);
-	grid_preview->set_flat(true);
-	grid_preview->add_theme_style_override("normal", memnew(StyleBoxEmpty));
-	grid_preview->add_theme_style_override("hover", memnew(StyleBoxEmpty));
-	grid_preview->add_theme_style_override("focus", memnew(StyleBoxEmpty));
-	grid_preview->add_theme_style_override("pressed", memnew(StyleBoxEmpty));
 	add_child(grid_preview);
 }