mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 16:03:29 +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:
parent
b76dfde329
commit
6631f66c2a
236 changed files with 3694 additions and 3670 deletions
|
@ -42,12 +42,12 @@
|
|||
|
||||
/// BOOL ///
|
||||
int AnimationTrackEditBool::get_key_height() const {
|
||||
Ref<Texture2D> checked = get_theme_icon("checked", "CheckBox");
|
||||
Ref<Texture2D> checked = get_theme_icon(SNAME("checked"), SNAME("CheckBox"));
|
||||
return checked->get_height();
|
||||
}
|
||||
|
||||
Rect2 AnimationTrackEditBool::get_key_rect(int p_index, float p_pixels_sec) {
|
||||
Ref<Texture2D> checked = get_theme_icon("checked", "CheckBox");
|
||||
Ref<Texture2D> checked = get_theme_icon(SNAME("checked"), SNAME("CheckBox"));
|
||||
return Rect2(-checked->get_width() / 2, 0, checked->get_width(), get_size().height);
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,7 @@ void AnimationTrackEditBool::draw_key(int p_index, float p_pixels_sec, int p_x,
|
|||
draw_texture(icon, ofs);
|
||||
|
||||
if (p_selected) {
|
||||
Color color = get_theme_color("accent_color", "Editor");
|
||||
Color color = get_theme_color(SNAME("accent_color"), SNAME("Editor"));
|
||||
draw_rect_clipped(Rect2(ofs, icon->get_size()), color, false);
|
||||
}
|
||||
}
|
||||
|
@ -80,14 +80,14 @@ void AnimationTrackEditBool::draw_key(int p_index, float p_pixels_sec, int p_x,
|
|||
/// COLOR ///
|
||||
|
||||
int AnimationTrackEditColor::get_key_height() const {
|
||||
Ref<Font> font = get_theme_font("font", "Label");
|
||||
int font_size = get_theme_font_size("font_size", "Label");
|
||||
Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label"));
|
||||
int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label"));
|
||||
return font->get_height(font_size) * 0.8;
|
||||
}
|
||||
|
||||
Rect2 AnimationTrackEditColor::get_key_rect(int p_index, float p_pixels_sec) {
|
||||
Ref<Font> font = get_theme_font("font", "Label");
|
||||
int font_size = get_theme_font_size("font_size", "Label");
|
||||
Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label"));
|
||||
int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label"));
|
||||
int fh = font->get_height(font_size) * 0.8;
|
||||
return Rect2(-fh / 2, 0, fh, get_size().height);
|
||||
}
|
||||
|
@ -97,8 +97,8 @@ bool AnimationTrackEditColor::is_key_selectable_by_distance() const {
|
|||
}
|
||||
|
||||
void AnimationTrackEditColor::draw_key_link(int p_index, float p_pixels_sec, int p_x, int p_next_x, int p_clip_left, int p_clip_right) {
|
||||
Ref<Font> font = get_theme_font("font", "Label");
|
||||
int font_size = get_theme_font_size("font_size", "Label");
|
||||
Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label"));
|
||||
int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label"));
|
||||
int fh = (font->get_height(font_size) * 0.8);
|
||||
|
||||
fh /= 3;
|
||||
|
@ -167,8 +167,8 @@ void AnimationTrackEditColor::draw_key_link(int p_index, float p_pixels_sec, int
|
|||
void AnimationTrackEditColor::draw_key(int p_index, float p_pixels_sec, int p_x, bool p_selected, int p_clip_left, int p_clip_right) {
|
||||
Color color = get_animation()->track_get_key_value(get_track(), p_index);
|
||||
|
||||
Ref<Font> font = get_theme_font("font", "Label");
|
||||
int font_size = get_theme_font_size("font_size", "Label");
|
||||
Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label"));
|
||||
int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label"));
|
||||
int fh = font->get_height(font_size) * 0.8;
|
||||
|
||||
Rect2 rect(Vector2(p_x - fh / 2, int(get_size().height - fh) / 2), Size2(fh, fh));
|
||||
|
@ -180,7 +180,7 @@ void AnimationTrackEditColor::draw_key(int p_index, float p_pixels_sec, int p_x,
|
|||
draw_rect_clipped(rect, color);
|
||||
|
||||
if (p_selected) {
|
||||
Color accent = get_theme_color("accent_color", "Editor");
|
||||
Color accent = get_theme_color(SNAME("accent_color"), SNAME("Editor"));
|
||||
draw_rect_clipped(rect, accent, false);
|
||||
}
|
||||
}
|
||||
|
@ -206,8 +206,8 @@ int AnimationTrackEditAudio::get_key_height() const {
|
|||
return AnimationTrackEdit::get_key_height();
|
||||
}
|
||||
|
||||
Ref<Font> font = get_theme_font("font", "Label");
|
||||
int font_size = get_theme_font_size("font_size", "Label");
|
||||
Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label"));
|
||||
int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label"));
|
||||
return int(font->get_height(font_size) * 1.5);
|
||||
}
|
||||
|
||||
|
@ -239,8 +239,8 @@ Rect2 AnimationTrackEditAudio::get_key_rect(int p_index, float p_pixels_sec) {
|
|||
|
||||
return Rect2(0, 0, len * p_pixels_sec, get_size().height);
|
||||
} else {
|
||||
Ref<Font> font = get_theme_font("font", "Label");
|
||||
int font_size = get_theme_font_size("font_size", "Label");
|
||||
Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label"));
|
||||
int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label"));
|
||||
int fh = font->get_height(font_size) * 0.8;
|
||||
return Rect2(0, 0, fh, get_size().height);
|
||||
}
|
||||
|
@ -303,8 +303,8 @@ void AnimationTrackEditAudio::draw_key(int p_index, float p_pixels_sec, int p_x,
|
|||
return;
|
||||
}
|
||||
|
||||
Ref<Font> font = get_theme_font("font", "Label");
|
||||
int font_size = get_theme_font_size("font_size", "Label");
|
||||
Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label"));
|
||||
int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label"));
|
||||
float fh = int(font->get_height(font_size) * 1.5);
|
||||
Rect2 rect = Rect2(from_x, (get_size().height - fh) / 2, to_x - from_x, fh);
|
||||
draw_rect(rect, Color(0.25, 0.25, 0.25));
|
||||
|
@ -330,20 +330,20 @@ void AnimationTrackEditAudio::draw_key(int p_index, float p_pixels_sec, int p_x,
|
|||
RS::get_singleton()->canvas_item_add_multiline(get_canvas_item(), lines, color);
|
||||
|
||||
if (p_selected) {
|
||||
Color accent = get_theme_color("accent_color", "Editor");
|
||||
Color accent = get_theme_color(SNAME("accent_color"), SNAME("Editor"));
|
||||
draw_rect(rect, accent, false);
|
||||
}
|
||||
} else {
|
||||
Ref<Font> font = get_theme_font("font", "Label");
|
||||
int font_size = get_theme_font_size("font_size", "Label");
|
||||
Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label"));
|
||||
int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label"));
|
||||
int fh = font->get_height(font_size) * 0.8;
|
||||
Rect2 rect(Vector2(p_x, int(get_size().height - fh) / 2), Size2(fh, fh));
|
||||
|
||||
Color color = get_theme_color("font_color", "Label");
|
||||
Color color = get_theme_color(SNAME("font_color"), SNAME("Label"));
|
||||
draw_rect(rect, color);
|
||||
|
||||
if (p_selected) {
|
||||
Color accent = get_theme_color("accent_color", "Editor");
|
||||
Color accent = get_theme_color(SNAME("accent_color"), SNAME("Editor"));
|
||||
draw_rect(rect, accent, false);
|
||||
}
|
||||
}
|
||||
|
@ -367,8 +367,8 @@ int AnimationTrackEditSpriteFrame::get_key_height() const {
|
|||
return AnimationTrackEdit::get_key_height();
|
||||
}
|
||||
|
||||
Ref<Font> font = get_theme_font("font", "Label");
|
||||
int font_size = get_theme_font_size("font_size", "Label");
|
||||
Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label"));
|
||||
int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label"));
|
||||
return int(font->get_height(font_size) * 2);
|
||||
}
|
||||
|
||||
|
@ -435,8 +435,8 @@ Rect2 AnimationTrackEditSpriteFrame::get_key_rect(int p_index, float p_pixels_se
|
|||
|
||||
size = size.floor();
|
||||
|
||||
Ref<Font> font = get_theme_font("font", "Label");
|
||||
int font_size = get_theme_font_size("font_size", "Label");
|
||||
Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label"));
|
||||
int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label"));
|
||||
int height = int(font->get_height(font_size) * 2);
|
||||
int width = height * size.width / size.height;
|
||||
|
||||
|
@ -526,8 +526,8 @@ void AnimationTrackEditSpriteFrame::draw_key(int p_index, float p_pixels_sec, in
|
|||
region.size = texture->get_size();
|
||||
}
|
||||
|
||||
Ref<Font> font = get_theme_font("font", "Label");
|
||||
int font_size = get_theme_font_size("font_size", "Label");
|
||||
Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label"));
|
||||
int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label"));
|
||||
int height = int(font->get_height(font_size) * 2);
|
||||
|
||||
int width = height * region.size.width / region.size.height;
|
||||
|
@ -542,7 +542,7 @@ void AnimationTrackEditSpriteFrame::draw_key(int p_index, float p_pixels_sec, in
|
|||
return;
|
||||
}
|
||||
|
||||
Color accent = get_theme_color("accent_color", "Editor");
|
||||
Color accent = get_theme_color(SNAME("accent_color"), SNAME("Editor"));
|
||||
Color bg = accent;
|
||||
bg.a = 0.15;
|
||||
|
||||
|
@ -570,8 +570,8 @@ int AnimationTrackEditSubAnim::get_key_height() const {
|
|||
return AnimationTrackEdit::get_key_height();
|
||||
}
|
||||
|
||||
Ref<Font> font = get_theme_font("font", "Label");
|
||||
int font_size = get_theme_font_size("font_size", "Label");
|
||||
Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label"));
|
||||
int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label"));
|
||||
return int(font->get_height(font_size) * 1.5);
|
||||
}
|
||||
|
||||
|
@ -599,8 +599,8 @@ Rect2 AnimationTrackEditSubAnim::get_key_rect(int p_index, float p_pixels_sec) {
|
|||
|
||||
return Rect2(0, 0, len * p_pixels_sec, get_size().height);
|
||||
} else {
|
||||
Ref<Font> font = get_theme_font("font", "Label");
|
||||
int font_size = get_theme_font_size("font_size", "Label");
|
||||
Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label"));
|
||||
int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label"));
|
||||
int fh = font->get_height(font_size) * 0.8;
|
||||
return Rect2(0, 0, fh, get_size().height);
|
||||
}
|
||||
|
@ -654,13 +654,13 @@ void AnimationTrackEditSubAnim::draw_key(int p_index, float p_pixels_sec, int p_
|
|||
return;
|
||||
}
|
||||
|
||||
Ref<Font> font = get_theme_font("font", "Label");
|
||||
int font_size = get_theme_font_size("font_size", "Label");
|
||||
Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label"));
|
||||
int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label"));
|
||||
int fh = font->get_height(font_size) * 1.5;
|
||||
|
||||
Rect2 rect(from_x, int(get_size().height - fh) / 2, to_x - from_x, fh);
|
||||
|
||||
Color color = get_theme_color("font_color", "Label");
|
||||
Color color = get_theme_color(SNAME("font_color"), SNAME("Label"));
|
||||
Color bg = color;
|
||||
bg.r = 1 - color.r;
|
||||
bg.g = 1 - color.g;
|
||||
|
@ -703,20 +703,20 @@ void AnimationTrackEditSubAnim::draw_key(int p_index, float p_pixels_sec, int p_
|
|||
}
|
||||
|
||||
if (p_selected) {
|
||||
Color accent = get_theme_color("accent_color", "Editor");
|
||||
Color accent = get_theme_color(SNAME("accent_color"), SNAME("Editor"));
|
||||
draw_rect(rect, accent, false);
|
||||
}
|
||||
} else {
|
||||
Ref<Font> font = get_theme_font("font", "Label");
|
||||
int font_size = get_theme_font_size("font_size", "Label");
|
||||
Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label"));
|
||||
int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label"));
|
||||
int fh = font->get_height(font_size) * 0.8;
|
||||
Rect2 rect(Vector2(p_x, int(get_size().height - fh) / 2), Size2(fh, fh));
|
||||
|
||||
Color color = get_theme_color("font_color", "Label");
|
||||
Color color = get_theme_color(SNAME("font_color"), SNAME("Label"));
|
||||
draw_rect(rect, color);
|
||||
|
||||
if (p_selected) {
|
||||
Color accent = get_theme_color("accent_color", "Editor");
|
||||
Color accent = get_theme_color(SNAME("accent_color"), SNAME("Editor"));
|
||||
draw_rect(rect, accent, false);
|
||||
}
|
||||
}
|
||||
|
@ -729,12 +729,12 @@ void AnimationTrackEditSubAnim::set_node(Object *p_object) {
|
|||
//// VOLUME DB ////
|
||||
|
||||
int AnimationTrackEditVolumeDB::get_key_height() const {
|
||||
Ref<Texture2D> volume_texture = get_theme_icon("ColorTrackVu", "EditorIcons");
|
||||
Ref<Texture2D> volume_texture = get_theme_icon(SNAME("ColorTrackVu"), SNAME("EditorIcons"));
|
||||
return volume_texture->get_height() * 1.2;
|
||||
}
|
||||
|
||||
void AnimationTrackEditVolumeDB::draw_bg(int p_clip_left, int p_clip_right) {
|
||||
Ref<Texture2D> volume_texture = get_theme_icon("ColorTrackVu", "EditorIcons");
|
||||
Ref<Texture2D> volume_texture = get_theme_icon(SNAME("ColorTrackVu"), SNAME("EditorIcons"));
|
||||
int tex_h = volume_texture->get_height();
|
||||
|
||||
int y_from = (get_size().height - tex_h) / 2;
|
||||
|
@ -745,7 +745,7 @@ void AnimationTrackEditVolumeDB::draw_bg(int p_clip_left, int p_clip_right) {
|
|||
}
|
||||
|
||||
void AnimationTrackEditVolumeDB::draw_fg(int p_clip_left, int p_clip_right) {
|
||||
Ref<Texture2D> volume_texture = get_theme_icon("ColorTrackVu", "EditorIcons");
|
||||
Ref<Texture2D> volume_texture = get_theme_icon(SNAME("ColorTrackVu"), SNAME("EditorIcons"));
|
||||
int tex_h = volume_texture->get_height();
|
||||
int y_from = (get_size().height - tex_h) / 2;
|
||||
int db0 = y_from + (24 / 80.0) * tex_h;
|
||||
|
@ -780,12 +780,12 @@ void AnimationTrackEditVolumeDB::draw_key_link(int p_index, float p_pixels_sec,
|
|||
to_x = p_clip_right;
|
||||
}
|
||||
|
||||
Ref<Texture2D> volume_texture = get_theme_icon("ColorTrackVu", "EditorIcons");
|
||||
Ref<Texture2D> volume_texture = get_theme_icon(SNAME("ColorTrackVu"), SNAME("EditorIcons"));
|
||||
int tex_h = volume_texture->get_height();
|
||||
|
||||
int y_from = (get_size().height - tex_h) / 2;
|
||||
|
||||
Color color = get_theme_color("font_color", "Label");
|
||||
Color color = get_theme_color(SNAME("font_color"), SNAME("Label"));
|
||||
color.a *= 0.7;
|
||||
|
||||
draw_line(Point2(from_x, y_from + h * tex_h), Point2(to_x, y_from + h_n * tex_h), color, 2);
|
||||
|
@ -806,8 +806,8 @@ void AnimationTrackEditTypeAudio::_preview_changed(ObjectID p_which) {
|
|||
}
|
||||
|
||||
int AnimationTrackEditTypeAudio::get_key_height() const {
|
||||
Ref<Font> font = get_theme_font("font", "Label");
|
||||
int font_size = get_theme_font_size("font_size", "Label");
|
||||
Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label"));
|
||||
int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label"));
|
||||
return int(font->get_height(font_size) * 1.5);
|
||||
}
|
||||
|
||||
|
@ -871,8 +871,8 @@ void AnimationTrackEditTypeAudio::draw_key(int p_index, float p_pixels_sec, int
|
|||
}
|
||||
}
|
||||
|
||||
Ref<Font> font = get_theme_font("font", "Label");
|
||||
int font_size = get_theme_font_size("font_size", "Label");
|
||||
Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label"));
|
||||
int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label"));
|
||||
float fh = int(font->get_height(font_size) * 1.5);
|
||||
|
||||
float len = stream->get_length();
|
||||
|
@ -947,7 +947,7 @@ void AnimationTrackEditTypeAudio::draw_key(int p_index, float p_pixels_sec, int
|
|||
|
||||
RS::get_singleton()->canvas_item_add_multiline(get_canvas_item(), lines, color);
|
||||
|
||||
Color cut_color = get_theme_color("accent_color", "Editor");
|
||||
Color cut_color = get_theme_color(SNAME("accent_color"), SNAME("Editor"));
|
||||
cut_color.a = 0.7;
|
||||
if (start_ofs > 0 && pixel_begin > p_clip_left) {
|
||||
draw_rect(Rect2(pixel_begin, rect.position.y, 1, rect.size.y), cut_color);
|
||||
|
@ -957,7 +957,7 @@ void AnimationTrackEditTypeAudio::draw_key(int p_index, float p_pixels_sec, int
|
|||
}
|
||||
|
||||
if (p_selected) {
|
||||
Color accent = get_theme_color("accent_color", "Editor");
|
||||
Color accent = get_theme_color(SNAME("accent_color"), SNAME("Editor"));
|
||||
draw_rect(rect, accent, false);
|
||||
}
|
||||
}
|
||||
|
@ -1143,8 +1143,8 @@ int AnimationTrackEditTypeAnimation::get_key_height() const {
|
|||
return AnimationTrackEdit::get_key_height();
|
||||
}
|
||||
|
||||
Ref<Font> font = get_theme_font("font", "Label");
|
||||
int font_size = get_theme_font_size("font_size", "Label");
|
||||
Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label"));
|
||||
int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label"));
|
||||
return int(font->get_height(font_size) * 1.5);
|
||||
}
|
||||
|
||||
|
@ -1172,8 +1172,8 @@ Rect2 AnimationTrackEditTypeAnimation::get_key_rect(int p_index, float p_pixels_
|
|||
|
||||
return Rect2(0, 0, len * p_pixels_sec, get_size().height);
|
||||
} else {
|
||||
Ref<Font> font = get_theme_font("font", "Label");
|
||||
int font_size = get_theme_font_size("font_size", "Label");
|
||||
Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label"));
|
||||
int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label"));
|
||||
int fh = font->get_height(font_size) * 0.8;
|
||||
return Rect2(0, 0, fh, get_size().height);
|
||||
}
|
||||
|
@ -1227,13 +1227,13 @@ void AnimationTrackEditTypeAnimation::draw_key(int p_index, float p_pixels_sec,
|
|||
return;
|
||||
}
|
||||
|
||||
Ref<Font> font = get_theme_font("font", "Label");
|
||||
int font_size = get_theme_font_size("font_size", "Label");
|
||||
Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label"));
|
||||
int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label"));
|
||||
int fh = font->get_height(font_size) * 1.5;
|
||||
|
||||
Rect2 rect(from_x, int(get_size().height - fh) / 2, to_x - from_x, fh);
|
||||
|
||||
Color color = get_theme_color("font_color", "Label");
|
||||
Color color = get_theme_color(SNAME("font_color"), SNAME("Label"));
|
||||
Color bg = color;
|
||||
bg.r = 1 - color.r;
|
||||
bg.g = 1 - color.g;
|
||||
|
@ -1276,20 +1276,20 @@ void AnimationTrackEditTypeAnimation::draw_key(int p_index, float p_pixels_sec,
|
|||
}
|
||||
|
||||
if (p_selected) {
|
||||
Color accent = get_theme_color("accent_color", "Editor");
|
||||
Color accent = get_theme_color(SNAME("accent_color"), SNAME("Editor"));
|
||||
draw_rect(rect, accent, false);
|
||||
}
|
||||
} else {
|
||||
Ref<Font> font = get_theme_font("font", "Label");
|
||||
int font_size = get_theme_font_size("font_size", "Label");
|
||||
Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label"));
|
||||
int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label"));
|
||||
int fh = font->get_height(font_size) * 0.8;
|
||||
Rect2 rect(Vector2(p_x, int(get_size().height - fh) / 2), Size2(fh, fh));
|
||||
|
||||
Color color = get_theme_color("font_color", "Label");
|
||||
Color color = get_theme_color(SNAME("font_color"), SNAME("Label"));
|
||||
draw_rect(rect, color);
|
||||
|
||||
if (p_selected) {
|
||||
Color accent = get_theme_color("accent_color", "Editor");
|
||||
Color accent = get_theme_color(SNAME("accent_color"), SNAME("Editor"));
|
||||
draw_rect(rect, accent, false);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue