You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-05 12:10:55 +00:00
Optimize StringName usage
* Added a new macro SNAME() that constructs and caches a local stringname. * Subsequent usages use the cached version. * Since these use a global static variable, a second refcounter of static usages need to be kept for cleanup time. * Replaced all theme usages by this new macro. * Replace all signal emission usages by this new macro. * Replace all call_deferred usages by this new macro. This is part of ongoing work to optimize GUI and the editor.
This commit is contained in:
@@ -43,10 +43,10 @@ void AudioStreamEditor::_notification(int p_what) {
|
||||
}
|
||||
|
||||
if (p_what == NOTIFICATION_THEME_CHANGED || p_what == NOTIFICATION_ENTER_TREE) {
|
||||
_play_button->set_icon(get_theme_icon("MainPlay", "EditorIcons"));
|
||||
_stop_button->set_icon(get_theme_icon("Stop", "EditorIcons"));
|
||||
_preview->set_color(get_theme_color("dark_color_2", "Editor"));
|
||||
set_color(get_theme_color("dark_color_1", "Editor"));
|
||||
_play_button->set_icon(get_theme_icon(SNAME("MainPlay"), SNAME("EditorIcons")));
|
||||
_stop_button->set_icon(get_theme_icon(SNAME("Stop"), SNAME("EditorIcons")));
|
||||
_preview->set_color(get_theme_color(SNAME("dark_color_2"), SNAME("Editor")));
|
||||
set_color(get_theme_color(SNAME("dark_color_1"), SNAME("Editor")));
|
||||
|
||||
_indicator->update();
|
||||
_preview->update();
|
||||
@@ -86,7 +86,7 @@ void AudioStreamEditor::_draw_preview() {
|
||||
}
|
||||
|
||||
Vector<Color> color;
|
||||
color.push_back(get_theme_color("contrast_color_2", "Editor"));
|
||||
color.push_back(get_theme_color(SNAME("contrast_color_2"), SNAME("Editor")));
|
||||
|
||||
RS::get_singleton()->canvas_item_add_multiline(_preview->get_canvas_item(), lines, color);
|
||||
}
|
||||
@@ -109,25 +109,25 @@ void AudioStreamEditor::_play() {
|
||||
// '_pausing' variable indicates that we want to pause the audio player, not stop it. See '_on_finished()'.
|
||||
_pausing = true;
|
||||
_player->stop();
|
||||
_play_button->set_icon(get_theme_icon("MainPlay", "EditorIcons"));
|
||||
_play_button->set_icon(get_theme_icon(SNAME("MainPlay"), SNAME("EditorIcons")));
|
||||
set_process(false);
|
||||
} else {
|
||||
_player->play(_current);
|
||||
_play_button->set_icon(get_theme_icon("Pause", "EditorIcons"));
|
||||
_play_button->set_icon(get_theme_icon(SNAME("Pause"), SNAME("EditorIcons")));
|
||||
set_process(true);
|
||||
}
|
||||
}
|
||||
|
||||
void AudioStreamEditor::_stop() {
|
||||
_player->stop();
|
||||
_play_button->set_icon(get_theme_icon("MainPlay", "EditorIcons"));
|
||||
_play_button->set_icon(get_theme_icon(SNAME("MainPlay"), SNAME("EditorIcons")));
|
||||
_current = 0;
|
||||
_indicator->update();
|
||||
set_process(false);
|
||||
}
|
||||
|
||||
void AudioStreamEditor::_on_finished() {
|
||||
_play_button->set_icon(get_theme_icon("MainPlay", "EditorIcons"));
|
||||
_play_button->set_icon(get_theme_icon(SNAME("MainPlay"), SNAME("EditorIcons")));
|
||||
if (!_pausing) {
|
||||
_current = 0;
|
||||
_indicator->update();
|
||||
@@ -145,11 +145,11 @@ void AudioStreamEditor::_draw_indicator() {
|
||||
Rect2 rect = _preview->get_rect();
|
||||
float len = stream->get_length();
|
||||
float ofs_x = _current / len * rect.size.width;
|
||||
const Color color = get_theme_color("accent_color", "Editor");
|
||||
const Color color = get_theme_color(SNAME("accent_color"), SNAME("Editor"));
|
||||
_indicator->draw_line(Point2(ofs_x, 0), Point2(ofs_x, rect.size.height), color, Math::round(2 * EDSCALE));
|
||||
_indicator->draw_texture(
|
||||
get_theme_icon("TimelineIndicator", "EditorIcons"),
|
||||
Point2(ofs_x - get_theme_icon("TimelineIndicator", "EditorIcons")->get_width() * 0.5, 0),
|
||||
get_theme_icon(SNAME("TimelineIndicator"), SNAME("EditorIcons")),
|
||||
Point2(ofs_x - get_theme_icon(SNAME("TimelineIndicator"), SNAME("EditorIcons"))->get_width() * 0.5, 0),
|
||||
color);
|
||||
|
||||
_current_label->set_text(String::num(_current, 2).pad_decimals(2) + " /");
|
||||
@@ -243,14 +243,14 @@ AudioStreamEditor::AudioStreamEditor() {
|
||||
_current_label = memnew(Label);
|
||||
_current_label->set_align(Label::ALIGN_RIGHT);
|
||||
_current_label->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||
_current_label->add_theme_font_override("font", EditorNode::get_singleton()->get_gui_base()->get_theme_font("status_source", "EditorFonts"));
|
||||
_current_label->add_theme_font_size_override("font_size", EditorNode::get_singleton()->get_gui_base()->get_theme_font_size("status_source_size", "EditorFonts"));
|
||||
_current_label->add_theme_font_override("font", EditorNode::get_singleton()->get_gui_base()->get_theme_font(SNAME("status_source"), SNAME("EditorFonts")));
|
||||
_current_label->add_theme_font_size_override("font_size", EditorNode::get_singleton()->get_gui_base()->get_theme_font_size(SNAME("status_source_size"), SNAME("EditorFonts")));
|
||||
_current_label->set_modulate(Color(1, 1, 1, 0.5));
|
||||
hbox->add_child(_current_label);
|
||||
|
||||
_duration_label = memnew(Label);
|
||||
_duration_label->add_theme_font_override("font", EditorNode::get_singleton()->get_gui_base()->get_theme_font("status_source", "EditorFonts"));
|
||||
_duration_label->add_theme_font_size_override("font_size", EditorNode::get_singleton()->get_gui_base()->get_theme_font_size("status_source_size", "EditorFonts"));
|
||||
_duration_label->add_theme_font_override("font", EditorNode::get_singleton()->get_gui_base()->get_theme_font(SNAME("status_source"), SNAME("EditorFonts")));
|
||||
_duration_label->add_theme_font_size_override("font_size", EditorNode::get_singleton()->get_gui_base()->get_theme_font_size(SNAME("status_source_size"), SNAME("EditorFonts")));
|
||||
hbox->add_child(_duration_label);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user