2021-03-13 19:30:26 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
/* theme_editor_preview.cpp */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
|
|
|
|
|
|
|
#include "theme_editor_preview.h"
|
|
|
|
|
2022-02-12 01:46:22 +00:00
|
|
|
#include "core/config/project_settings.h"
|
2021-03-13 19:30:26 +00:00
|
|
|
#include "core/input/input.h"
|
|
|
|
#include "core/math/math_funcs.h"
|
2022-02-12 01:46:22 +00:00
|
|
|
#include "editor/editor_node.h"
|
2023-08-13 00:33:39 +00:00
|
|
|
#include "editor/editor_string_names.h"
|
2024-01-15 12:14:55 +00:00
|
|
|
#include "editor/themes/editor_scale.h"
|
2022-02-12 01:46:22 +00:00
|
|
|
#include "scene/gui/button.h"
|
2022-11-19 11:45:49 +00:00
|
|
|
#include "scene/gui/check_box.h"
|
2022-07-31 18:14:15 +00:00
|
|
|
#include "scene/gui/check_button.h"
|
2022-02-12 01:46:22 +00:00
|
|
|
#include "scene/gui/color_picker.h"
|
2023-04-07 16:59:49 +00:00
|
|
|
#include "scene/gui/color_rect.h"
|
|
|
|
#include "scene/gui/margin_container.h"
|
2022-02-12 01:46:22 +00:00
|
|
|
#include "scene/gui/progress_bar.h"
|
2023-04-07 16:59:49 +00:00
|
|
|
#include "scene/gui/scroll_container.h"
|
|
|
|
#include "scene/gui/tab_container.h"
|
2022-11-19 11:45:49 +00:00
|
|
|
#include "scene/gui/text_edit.h"
|
|
|
|
#include "scene/gui/tree.h"
|
2022-02-12 01:46:22 +00:00
|
|
|
#include "scene/resources/packed_scene.h"
|
2022-08-08 16:29:36 +00:00
|
|
|
#include "scene/theme/theme_db.h"
|
2021-03-13 19:30:26 +00:00
|
|
|
|
2021-12-29 20:31:13 +00:00
|
|
|
constexpr double REFRESH_TIMER = 1.5;
|
|
|
|
|
2021-03-13 19:30:26 +00:00
|
|
|
void ThemeEditorPreview::set_preview_theme(const Ref<Theme> &p_theme) {
|
|
|
|
preview_content->set_theme(p_theme);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ThemeEditorPreview::add_preview_overlay(Control *p_overlay) {
|
|
|
|
preview_overlay->add_child(p_overlay);
|
|
|
|
p_overlay->hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ThemeEditorPreview::_propagate_redraw(Control *p_at) {
|
|
|
|
p_at->notification(NOTIFICATION_THEME_CHANGED);
|
2021-12-06 13:02:34 +00:00
|
|
|
p_at->update_minimum_size();
|
2022-08-13 21:21:24 +00:00
|
|
|
p_at->queue_redraw();
|
2021-03-13 19:30:26 +00:00
|
|
|
for (int i = 0; i < p_at->get_child_count(); i++) {
|
|
|
|
Control *a = Object::cast_to<Control>(p_at->get_child(i));
|
|
|
|
if (a) {
|
|
|
|
_propagate_redraw(a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ThemeEditorPreview::_refresh_interval() {
|
|
|
|
// In case the project settings have changed.
|
|
|
|
preview_bg->set_color(GLOBAL_GET("rendering/environment/defaults/default_clear_color"));
|
|
|
|
|
|
|
|
_propagate_redraw(preview_bg);
|
|
|
|
_propagate_redraw(preview_content);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ThemeEditorPreview::_preview_visibility_changed() {
|
2021-12-29 20:31:13 +00:00
|
|
|
set_process(is_visible_in_tree());
|
2021-03-13 19:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ThemeEditorPreview::_picker_button_cbk() {
|
|
|
|
picker_overlay->set_visible(picker_button->is_pressed());
|
2021-11-21 10:39:46 +00:00
|
|
|
if (picker_button->is_pressed()) {
|
|
|
|
_reset_picker_overlay();
|
|
|
|
}
|
2021-03-13 19:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Control *ThemeEditorPreview::_find_hovered_control(Control *p_parent, Vector2 p_mouse_position) {
|
|
|
|
Control *found = nullptr;
|
|
|
|
|
2021-07-16 18:32:58 +00:00
|
|
|
for (int i = p_parent->get_child_count() - 1; i >= 0; i--) {
|
2021-03-13 19:30:26 +00:00
|
|
|
Control *cc = Object::cast_to<Control>(p_parent->get_child(i));
|
|
|
|
if (!cc || !cc->is_visible()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Rect2 crect = cc->get_rect();
|
|
|
|
if (crect.has_point(p_mouse_position)) {
|
|
|
|
// Check if there is a child control under mouse.
|
|
|
|
if (cc->get_child_count() > 0) {
|
|
|
|
found = _find_hovered_control(cc, p_mouse_position - cc->get_position());
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there are no applicable children, use the control itself.
|
|
|
|
if (!found) {
|
|
|
|
found = cc;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ThemeEditorPreview::_draw_picker_overlay() {
|
|
|
|
if (!picker_button->is_pressed()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-07-16 18:32:58 +00:00
|
|
|
picker_overlay->draw_rect(Rect2(Vector2(0.0, 0.0), picker_overlay->get_size()), theme_cache.preview_picker_overlay_color);
|
2021-03-13 19:30:26 +00:00
|
|
|
if (hovered_control) {
|
|
|
|
Rect2 highlight_rect = hovered_control->get_global_rect();
|
|
|
|
highlight_rect.position = picker_overlay->get_global_transform().affine_inverse().xform(highlight_rect.position);
|
2021-07-16 18:32:58 +00:00
|
|
|
picker_overlay->draw_style_box(theme_cache.preview_picker_overlay, highlight_rect);
|
2021-03-13 19:30:26 +00:00
|
|
|
|
2021-07-16 18:32:58 +00:00
|
|
|
String highlight_name = hovered_control->get_theme_type_variation();
|
|
|
|
if (highlight_name == StringName()) {
|
|
|
|
highlight_name = hovered_control->get_class_name();
|
|
|
|
}
|
|
|
|
|
|
|
|
Rect2 highlight_label_rect = highlight_rect;
|
2022-05-09 09:47:10 +00:00
|
|
|
highlight_label_rect.size = theme_cache.preview_picker_font->get_string_size(highlight_name, HORIZONTAL_ALIGNMENT_LEFT, -1, theme_cache.font_size);
|
2021-07-16 18:32:58 +00:00
|
|
|
|
|
|
|
int margin_top = theme_cache.preview_picker_label->get_margin(SIDE_TOP);
|
|
|
|
int margin_left = theme_cache.preview_picker_label->get_margin(SIDE_LEFT);
|
|
|
|
int margin_bottom = theme_cache.preview_picker_label->get_margin(SIDE_BOTTOM);
|
|
|
|
int margin_right = theme_cache.preview_picker_label->get_margin(SIDE_RIGHT);
|
|
|
|
highlight_label_rect.size.x += margin_left + margin_right;
|
|
|
|
highlight_label_rect.size.y += margin_top + margin_bottom;
|
|
|
|
|
2021-09-29 03:51:34 +00:00
|
|
|
highlight_label_rect.position = highlight_label_rect.position.clamp(Vector2(), picker_overlay->get_size());
|
|
|
|
|
2021-07-16 18:32:58 +00:00
|
|
|
picker_overlay->draw_style_box(theme_cache.preview_picker_label, highlight_label_rect);
|
|
|
|
|
|
|
|
Point2 label_pos = highlight_label_rect.position;
|
|
|
|
label_pos.y += highlight_label_rect.size.y - margin_bottom;
|
|
|
|
label_pos.x += margin_left;
|
2021-11-25 02:58:47 +00:00
|
|
|
picker_overlay->draw_string(theme_cache.preview_picker_font, label_pos, highlight_name, HORIZONTAL_ALIGNMENT_LEFT, -1, theme_cache.font_size);
|
2021-03-13 19:30:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ThemeEditorPreview::_gui_input_picker_overlay(const Ref<InputEvent> &p_event) {
|
|
|
|
if (!picker_button->is_pressed()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ref<InputEventMouseButton> mb = p_event;
|
|
|
|
|
2021-08-13 21:31:57 +00:00
|
|
|
if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT) {
|
2021-03-13 19:30:26 +00:00
|
|
|
if (hovered_control) {
|
2021-07-04 20:42:23 +00:00
|
|
|
StringName theme_type = hovered_control->get_theme_type_variation();
|
2021-03-13 19:30:26 +00:00
|
|
|
if (theme_type == StringName()) {
|
|
|
|
theme_type = hovered_control->get_class_name();
|
|
|
|
}
|
|
|
|
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("control_picked"), theme_type);
|
2021-03-13 19:30:26 +00:00
|
|
|
picker_button->set_pressed(false);
|
|
|
|
picker_overlay->set_visible(false);
|
2021-12-02 14:57:53 +00:00
|
|
|
return;
|
2021-03-13 19:30:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ref<InputEventMouseMotion> mm = p_event;
|
|
|
|
|
|
|
|
if (mm.is_valid()) {
|
|
|
|
Vector2 mp = preview_content->get_local_mouse_position();
|
|
|
|
hovered_control = _find_hovered_control(preview_content, mp);
|
2022-08-13 21:21:24 +00:00
|
|
|
picker_overlay->queue_redraw();
|
2021-03-13 19:30:26 +00:00
|
|
|
}
|
2021-12-02 14:57:53 +00:00
|
|
|
|
|
|
|
// Forward input to the scroll container underneath to allow scrolling.
|
|
|
|
preview_container->gui_input(p_event);
|
2021-03-13 19:30:26 +00:00
|
|
|
}
|
|
|
|
|
2021-07-16 18:32:58 +00:00
|
|
|
void ThemeEditorPreview::_reset_picker_overlay() {
|
|
|
|
hovered_control = nullptr;
|
2022-08-13 21:21:24 +00:00
|
|
|
picker_overlay->queue_redraw();
|
2021-07-16 18:32:58 +00:00
|
|
|
}
|
|
|
|
|
2021-03-13 19:30:26 +00:00
|
|
|
void ThemeEditorPreview::_notification(int p_what) {
|
|
|
|
switch (p_what) {
|
|
|
|
case NOTIFICATION_ENTER_TREE: {
|
|
|
|
if (is_visible_in_tree()) {
|
|
|
|
set_process(true);
|
|
|
|
}
|
|
|
|
|
2024-05-13 14:56:03 +00:00
|
|
|
connect(SceneStringName(visibility_changed), callable_mp(this, &ThemeEditorPreview::_preview_visibility_changed));
|
2023-09-06 14:11:05 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case NOTIFICATION_READY: {
|
|
|
|
List<Ref<Theme>> preview_themes;
|
|
|
|
preview_themes.push_back(ThemeDB::get_singleton()->get_default_theme());
|
|
|
|
ThemeDB::get_singleton()->create_theme_context(preview_root, preview_themes);
|
|
|
|
} break;
|
|
|
|
|
2021-03-13 19:30:26 +00:00
|
|
|
case NOTIFICATION_THEME_CHANGED: {
|
2023-08-13 00:33:39 +00:00
|
|
|
picker_button->set_icon(get_editor_theme_icon(SNAME("ColorPick")));
|
2021-07-16 18:32:58 +00:00
|
|
|
|
2021-07-17 21:22:52 +00:00
|
|
|
theme_cache.preview_picker_overlay = get_theme_stylebox(SNAME("preview_picker_overlay"), SNAME("ThemeEditor"));
|
|
|
|
theme_cache.preview_picker_overlay_color = get_theme_color(SNAME("preview_picker_overlay_color"), SNAME("ThemeEditor"));
|
|
|
|
theme_cache.preview_picker_label = get_theme_stylebox(SNAME("preview_picker_label"), SNAME("ThemeEditor"));
|
2023-08-13 00:33:39 +00:00
|
|
|
theme_cache.preview_picker_font = get_theme_font(SNAME("status_source"), EditorStringName(EditorFonts));
|
2023-09-13 11:14:07 +00:00
|
|
|
theme_cache.font_size = get_theme_default_font_size();
|
2021-03-13 19:30:26 +00:00
|
|
|
} break;
|
2022-02-16 14:17:55 +00:00
|
|
|
|
2021-03-13 19:30:26 +00:00
|
|
|
case NOTIFICATION_PROCESS: {
|
|
|
|
time_left -= get_process_delta_time();
|
|
|
|
if (time_left < 0) {
|
2021-12-29 20:31:13 +00:00
|
|
|
time_left = REFRESH_TIMER;
|
2021-03-13 19:30:26 +00:00
|
|
|
_refresh_interval();
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ThemeEditorPreview::_bind_methods() {
|
|
|
|
ADD_SIGNAL(MethodInfo("control_picked", PropertyInfo(Variant::STRING, "class_name")));
|
|
|
|
}
|
|
|
|
|
|
|
|
ThemeEditorPreview::ThemeEditorPreview() {
|
|
|
|
preview_toolbar = memnew(HBoxContainer);
|
|
|
|
add_child(preview_toolbar);
|
|
|
|
|
|
|
|
picker_button = memnew(Button);
|
|
|
|
preview_toolbar->add_child(picker_button);
|
2023-09-19 16:03:10 +00:00
|
|
|
picker_button->set_theme_type_variation("FlatButton");
|
2021-03-13 19:30:26 +00:00
|
|
|
picker_button->set_toggle_mode(true);
|
2022-08-25 10:42:17 +00:00
|
|
|
picker_button->set_tooltip_text(TTR("Toggle the control picker, allowing to visually select control types for edit."));
|
2021-03-13 19:30:26 +00:00
|
|
|
picker_button->connect("pressed", callable_mp(this, &ThemeEditorPreview::_picker_button_cbk));
|
|
|
|
|
|
|
|
MarginContainer *preview_body = memnew(MarginContainer);
|
|
|
|
preview_body->set_custom_minimum_size(Size2(480, 0) * EDSCALE);
|
|
|
|
preview_body->set_v_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
add_child(preview_body);
|
|
|
|
|
2021-12-02 14:57:53 +00:00
|
|
|
preview_container = memnew(ScrollContainer);
|
2021-03-13 19:30:26 +00:00
|
|
|
preview_body->add_child(preview_container);
|
|
|
|
|
2023-09-06 14:11:05 +00:00
|
|
|
preview_root = memnew(MarginContainer);
|
2021-03-13 19:30:26 +00:00
|
|
|
preview_container->add_child(preview_root);
|
|
|
|
preview_root->set_clip_contents(true);
|
|
|
|
preview_root->set_custom_minimum_size(Size2(450, 0) * EDSCALE);
|
|
|
|
preview_root->set_v_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
preview_root->set_h_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
|
|
|
|
preview_bg = memnew(ColorRect);
|
2022-03-19 00:02:57 +00:00
|
|
|
preview_bg->set_anchors_and_offsets_preset(PRESET_FULL_RECT);
|
2021-03-13 19:30:26 +00:00
|
|
|
preview_bg->set_color(GLOBAL_GET("rendering/environment/defaults/default_clear_color"));
|
|
|
|
preview_root->add_child(preview_bg);
|
|
|
|
|
|
|
|
preview_content = memnew(MarginContainer);
|
2022-02-08 09:14:58 +00:00
|
|
|
preview_content->add_theme_constant_override("margin_right", 4 * EDSCALE);
|
|
|
|
preview_content->add_theme_constant_override("margin_top", 4 * EDSCALE);
|
|
|
|
preview_content->add_theme_constant_override("margin_left", 4 * EDSCALE);
|
|
|
|
preview_content->add_theme_constant_override("margin_bottom", 4 * EDSCALE);
|
2023-10-19 16:05:19 +00:00
|
|
|
preview_root->add_child(preview_content);
|
2021-03-13 19:30:26 +00:00
|
|
|
|
|
|
|
preview_overlay = memnew(MarginContainer);
|
|
|
|
preview_overlay->set_mouse_filter(MOUSE_FILTER_IGNORE);
|
2021-07-16 18:32:58 +00:00
|
|
|
preview_overlay->set_clip_contents(true);
|
2021-03-13 19:30:26 +00:00
|
|
|
preview_body->add_child(preview_overlay);
|
|
|
|
|
|
|
|
picker_overlay = memnew(Control);
|
|
|
|
add_preview_overlay(picker_overlay);
|
2024-05-13 14:56:03 +00:00
|
|
|
picker_overlay->connect(SceneStringName(draw), callable_mp(this, &ThemeEditorPreview::_draw_picker_overlay));
|
|
|
|
picker_overlay->connect(SceneStringName(gui_input), callable_mp(this, &ThemeEditorPreview::_gui_input_picker_overlay));
|
|
|
|
picker_overlay->connect(SceneStringName(mouse_exited), callable_mp(this, &ThemeEditorPreview::_reset_picker_overlay));
|
2021-03-13 19:30:26 +00:00
|
|
|
}
|
|
|
|
|
2022-05-17 20:44:15 +00:00
|
|
|
void DefaultThemeEditorPreview::_notification(int p_what) {
|
|
|
|
switch (p_what) {
|
2022-08-29 09:04:31 +00:00
|
|
|
case NOTIFICATION_ENTER_TREE:
|
2022-05-17 20:44:15 +00:00
|
|
|
case NOTIFICATION_THEME_CHANGED: {
|
2023-08-13 00:33:39 +00:00
|
|
|
test_color_picker_button->set_custom_minimum_size(Size2(0, get_theme_constant(SNAME("color_picker_button_height"), EditorStringName(Editor))));
|
2022-05-17 20:44:15 +00:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-13 19:30:26 +00:00
|
|
|
DefaultThemeEditorPreview::DefaultThemeEditorPreview() {
|
|
|
|
Panel *main_panel = memnew(Panel);
|
|
|
|
preview_content->add_child(main_panel);
|
|
|
|
|
|
|
|
MarginContainer *main_mc = memnew(MarginContainer);
|
2022-02-08 09:14:58 +00:00
|
|
|
main_mc->add_theme_constant_override("margin_right", 4 * EDSCALE);
|
|
|
|
main_mc->add_theme_constant_override("margin_top", 4 * EDSCALE);
|
|
|
|
main_mc->add_theme_constant_override("margin_left", 4 * EDSCALE);
|
|
|
|
main_mc->add_theme_constant_override("margin_bottom", 4 * EDSCALE);
|
2021-03-13 19:30:26 +00:00
|
|
|
preview_content->add_child(main_mc);
|
|
|
|
|
|
|
|
HBoxContainer *main_hb = memnew(HBoxContainer);
|
|
|
|
main_mc->add_child(main_hb);
|
2022-02-08 09:14:58 +00:00
|
|
|
main_hb->add_theme_constant_override("separation", 20 * EDSCALE);
|
2021-03-13 19:30:26 +00:00
|
|
|
|
|
|
|
VBoxContainer *first_vb = memnew(VBoxContainer);
|
|
|
|
main_hb->add_child(first_vb);
|
|
|
|
first_vb->set_h_size_flags(SIZE_EXPAND_FILL);
|
2022-02-08 09:14:58 +00:00
|
|
|
first_vb->add_theme_constant_override("separation", 10 * EDSCALE);
|
2021-03-13 19:30:26 +00:00
|
|
|
|
|
|
|
first_vb->add_child(memnew(Label("Label")));
|
|
|
|
|
|
|
|
first_vb->add_child(memnew(Button("Button")));
|
|
|
|
Button *bt = memnew(Button);
|
|
|
|
bt->set_text(TTR("Toggle Button"));
|
|
|
|
bt->set_toggle_mode(true);
|
|
|
|
bt->set_pressed(true);
|
|
|
|
first_vb->add_child(bt);
|
|
|
|
bt = memnew(Button);
|
|
|
|
bt->set_text(TTR("Disabled Button"));
|
|
|
|
bt->set_disabled(true);
|
|
|
|
first_vb->add_child(bt);
|
|
|
|
Button *tb = memnew(Button);
|
|
|
|
tb->set_flat(true);
|
2023-07-21 00:57:09 +00:00
|
|
|
tb->set_text("Flat Button");
|
2021-03-13 19:30:26 +00:00
|
|
|
first_vb->add_child(tb);
|
|
|
|
|
|
|
|
CheckButton *cb = memnew(CheckButton);
|
|
|
|
cb->set_text("CheckButton");
|
|
|
|
first_vb->add_child(cb);
|
|
|
|
CheckBox *cbx = memnew(CheckBox);
|
|
|
|
cbx->set_text("CheckBox");
|
|
|
|
first_vb->add_child(cbx);
|
|
|
|
|
|
|
|
MenuButton *test_menu_button = memnew(MenuButton);
|
|
|
|
test_menu_button->set_text("MenuButton");
|
|
|
|
test_menu_button->get_popup()->add_item(TTR("Item"));
|
|
|
|
test_menu_button->get_popup()->add_item(TTR("Disabled Item"));
|
|
|
|
test_menu_button->get_popup()->set_item_disabled(1, true);
|
|
|
|
test_menu_button->get_popup()->add_separator();
|
|
|
|
test_menu_button->get_popup()->add_check_item(TTR("Check Item"));
|
|
|
|
test_menu_button->get_popup()->add_check_item(TTR("Checked Item"));
|
|
|
|
test_menu_button->get_popup()->set_item_checked(4, true);
|
|
|
|
test_menu_button->get_popup()->add_separator();
|
|
|
|
test_menu_button->get_popup()->add_radio_check_item(TTR("Radio Item"));
|
|
|
|
test_menu_button->get_popup()->add_radio_check_item(TTR("Checked Radio Item"));
|
|
|
|
test_menu_button->get_popup()->set_item_checked(7, true);
|
2021-06-16 11:39:28 +00:00
|
|
|
test_menu_button->get_popup()->add_separator(TTR("Named Separator"));
|
2021-03-13 19:30:26 +00:00
|
|
|
|
|
|
|
PopupMenu *test_submenu = memnew(PopupMenu);
|
2023-11-28 16:33:04 +00:00
|
|
|
test_menu_button->get_popup()->add_submenu_node_item(TTR("Submenu"), test_submenu);
|
2021-03-13 19:30:26 +00:00
|
|
|
test_submenu->add_item(TTR("Subitem 1"));
|
|
|
|
test_submenu->add_item(TTR("Subitem 2"));
|
|
|
|
first_vb->add_child(test_menu_button);
|
|
|
|
|
|
|
|
OptionButton *test_option_button = memnew(OptionButton);
|
|
|
|
test_option_button->add_item("OptionButton");
|
|
|
|
test_option_button->add_separator();
|
|
|
|
test_option_button->add_item(TTR("Has"));
|
|
|
|
test_option_button->add_item(TTR("Many"));
|
|
|
|
test_option_button->add_item(TTR("Options"));
|
|
|
|
first_vb->add_child(test_option_button);
|
2022-05-17 20:44:15 +00:00
|
|
|
test_color_picker_button = memnew(ColorPickerButton);
|
|
|
|
first_vb->add_child(test_color_picker_button);
|
2021-03-13 19:30:26 +00:00
|
|
|
|
|
|
|
VBoxContainer *second_vb = memnew(VBoxContainer);
|
|
|
|
second_vb->set_h_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
main_hb->add_child(second_vb);
|
2022-02-08 09:14:58 +00:00
|
|
|
second_vb->add_theme_constant_override("separation", 10 * EDSCALE);
|
2021-03-13 19:30:26 +00:00
|
|
|
LineEdit *le = memnew(LineEdit);
|
|
|
|
le->set_text("LineEdit");
|
|
|
|
second_vb->add_child(le);
|
|
|
|
le = memnew(LineEdit);
|
|
|
|
le->set_text(TTR("Disabled LineEdit"));
|
|
|
|
le->set_editable(false);
|
|
|
|
second_vb->add_child(le);
|
|
|
|
TextEdit *te = memnew(TextEdit);
|
|
|
|
te->set_text("TextEdit");
|
|
|
|
te->set_custom_minimum_size(Size2(0, 100) * EDSCALE);
|
|
|
|
second_vb->add_child(te);
|
|
|
|
second_vb->add_child(memnew(SpinBox));
|
|
|
|
|
|
|
|
HBoxContainer *vhb = memnew(HBoxContainer);
|
|
|
|
second_vb->add_child(vhb);
|
|
|
|
vhb->set_custom_minimum_size(Size2(0, 100) * EDSCALE);
|
|
|
|
vhb->add_child(memnew(VSlider));
|
|
|
|
VScrollBar *vsb = memnew(VScrollBar);
|
|
|
|
vsb->set_page(25);
|
|
|
|
vhb->add_child(vsb);
|
|
|
|
vhb->add_child(memnew(VSeparator));
|
|
|
|
VBoxContainer *hvb = memnew(VBoxContainer);
|
|
|
|
vhb->add_child(hvb);
|
2021-11-25 02:58:47 +00:00
|
|
|
hvb->set_alignment(BoxContainer::ALIGNMENT_CENTER);
|
2021-03-13 19:30:26 +00:00
|
|
|
hvb->set_h_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
hvb->add_child(memnew(HSlider));
|
|
|
|
HScrollBar *hsb = memnew(HScrollBar);
|
|
|
|
hsb->set_page(25);
|
|
|
|
hvb->add_child(hsb);
|
|
|
|
HSlider *hs = memnew(HSlider);
|
|
|
|
hs->set_editable(false);
|
|
|
|
hvb->add_child(hs);
|
|
|
|
hvb->add_child(memnew(HSeparator));
|
|
|
|
ProgressBar *pb = memnew(ProgressBar);
|
|
|
|
pb->set_value(50);
|
|
|
|
hvb->add_child(pb);
|
|
|
|
|
|
|
|
VBoxContainer *third_vb = memnew(VBoxContainer);
|
|
|
|
third_vb->set_h_size_flags(SIZE_EXPAND_FILL);
|
2022-02-08 09:14:58 +00:00
|
|
|
third_vb->add_theme_constant_override("separation", 10 * EDSCALE);
|
2021-03-13 19:30:26 +00:00
|
|
|
main_hb->add_child(third_vb);
|
|
|
|
|
|
|
|
TabContainer *tc = memnew(TabContainer);
|
|
|
|
third_vb->add_child(tc);
|
|
|
|
tc->set_custom_minimum_size(Size2(0, 135) * EDSCALE);
|
|
|
|
Control *tcc = memnew(Control);
|
|
|
|
tcc->set_name(TTR("Tab 1"));
|
|
|
|
tc->add_child(tcc);
|
|
|
|
tcc = memnew(Control);
|
|
|
|
tcc->set_name(TTR("Tab 2"));
|
|
|
|
tc->add_child(tcc);
|
|
|
|
tcc = memnew(Control);
|
|
|
|
tcc->set_name(TTR("Tab 3"));
|
|
|
|
tc->add_child(tcc);
|
|
|
|
tc->set_tab_disabled(2, true);
|
|
|
|
|
|
|
|
Tree *test_tree = memnew(Tree);
|
|
|
|
third_vb->add_child(test_tree);
|
|
|
|
test_tree->set_custom_minimum_size(Size2(0, 175) * EDSCALE);
|
|
|
|
|
|
|
|
TreeItem *item = test_tree->create_item();
|
|
|
|
item->set_text(0, "Tree");
|
|
|
|
item = test_tree->create_item(test_tree->get_root());
|
|
|
|
item->set_text(0, "Item");
|
|
|
|
item = test_tree->create_item(test_tree->get_root());
|
|
|
|
item->set_editable(0, true);
|
|
|
|
item->set_text(0, TTR("Editable Item"));
|
|
|
|
TreeItem *sub_tree = test_tree->create_item(test_tree->get_root());
|
|
|
|
sub_tree->set_text(0, TTR("Subtree"));
|
|
|
|
item = test_tree->create_item(sub_tree);
|
|
|
|
item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
|
|
|
|
item->set_editable(0, true);
|
|
|
|
item->set_text(0, "Check Item");
|
|
|
|
item = test_tree->create_item(sub_tree);
|
|
|
|
item->set_cell_mode(0, TreeItem::CELL_MODE_RANGE);
|
|
|
|
item->set_editable(0, true);
|
|
|
|
item->set_range_config(0, 0, 20, 0.1);
|
|
|
|
item->set_range(0, 2);
|
|
|
|
item = test_tree->create_item(sub_tree);
|
|
|
|
item->set_cell_mode(0, TreeItem::CELL_MODE_RANGE);
|
|
|
|
item->set_editable(0, true);
|
|
|
|
item->set_text(0, TTR("Has,Many,Options"));
|
|
|
|
item->set_range(0, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SceneThemeEditorPreview::_reload_scene() {
|
|
|
|
if (loaded_scene.is_null()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (loaded_scene->get_path().is_empty() || !ResourceLoader::exists(loaded_scene->get_path())) {
|
|
|
|
EditorNode::get_singleton()->show_warning(TTR("Invalid path, the PackedScene resource was probably moved or removed."));
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("scene_invalidated"));
|
2021-03-13 19:30:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = preview_content->get_child_count() - 1; i >= 0; i--) {
|
|
|
|
Node *node = preview_content->get_child(i);
|
2022-10-24 21:07:02 +00:00
|
|
|
node->queue_free();
|
2021-03-13 19:30:26 +00:00
|
|
|
preview_content->remove_child(node);
|
|
|
|
}
|
|
|
|
|
2021-06-17 22:03:09 +00:00
|
|
|
Node *instance = loaded_scene->instantiate();
|
2021-03-13 19:30:26 +00:00
|
|
|
if (!instance || !Object::cast_to<Control>(instance)) {
|
|
|
|
EditorNode::get_singleton()->show_warning(TTR("Invalid PackedScene resource, must have a Control node at its root."));
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("scene_invalidated"));
|
2021-03-13 19:30:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
preview_content->add_child(instance);
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("scene_reloaded"));
|
2021-03-13 19:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SceneThemeEditorPreview::_notification(int p_what) {
|
|
|
|
switch (p_what) {
|
2022-08-29 09:04:31 +00:00
|
|
|
case NOTIFICATION_ENTER_TREE:
|
2021-03-13 19:30:26 +00:00
|
|
|
case NOTIFICATION_THEME_CHANGED: {
|
2023-08-13 00:33:39 +00:00
|
|
|
reload_scene_button->set_icon(get_editor_theme_icon(SNAME("Reload")));
|
2021-03-13 19:30:26 +00:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SceneThemeEditorPreview::_bind_methods() {
|
|
|
|
ADD_SIGNAL(MethodInfo("scene_invalidated"));
|
|
|
|
ADD_SIGNAL(MethodInfo("scene_reloaded"));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SceneThemeEditorPreview::set_preview_scene(const String &p_path) {
|
|
|
|
loaded_scene = ResourceLoader::load(p_path);
|
|
|
|
if (loaded_scene.is_null()) {
|
|
|
|
EditorNode::get_singleton()->show_warning(TTR("Invalid file, not a PackedScene resource."));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-06-17 22:03:09 +00:00
|
|
|
Node *instance = loaded_scene->instantiate();
|
2021-03-13 19:30:26 +00:00
|
|
|
if (!instance || !Object::cast_to<Control>(instance)) {
|
|
|
|
EditorNode::get_singleton()->show_warning(TTR("Invalid PackedScene resource, must have a Control node at its root."));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
preview_content->add_child(instance);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
String SceneThemeEditorPreview::get_preview_scene_path() const {
|
|
|
|
if (loaded_scene.is_null()) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
return loaded_scene->get_path();
|
|
|
|
}
|
|
|
|
|
|
|
|
SceneThemeEditorPreview::SceneThemeEditorPreview() {
|
|
|
|
preview_toolbar->add_child(memnew(VSeparator));
|
|
|
|
|
|
|
|
reload_scene_button = memnew(Button);
|
|
|
|
reload_scene_button->set_flat(true);
|
2022-08-25 10:42:17 +00:00
|
|
|
reload_scene_button->set_tooltip_text(TTR("Reload the scene to reflect its most actual state."));
|
2021-03-13 19:30:26 +00:00
|
|
|
preview_toolbar->add_child(reload_scene_button);
|
|
|
|
reload_scene_button->connect("pressed", callable_mp(this, &SceneThemeEditorPreview::_reload_scene));
|
|
|
|
}
|