summaryrefslogtreecommitdiffstats
path: root/editor/plugins/material_editor_plugin.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/plugins/material_editor_plugin.cpp')
-rw-r--r--editor/plugins/material_editor_plugin.cpp94
1 files changed, 45 insertions, 49 deletions
diff --git a/editor/plugins/material_editor_plugin.cpp b/editor/plugins/material_editor_plugin.cpp
index 404711e074..e24172e761 100644
--- a/editor/plugins/material_editor_plugin.cpp
+++ b/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();