mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 16:03:29 +00:00
Merge pull request #111111 from bruvzg/outl_warn
[Label] Add MSDF pixel range/outline configuration warning.
This commit is contained in:
commit
2b1fa0f10c
1 changed files with 40 additions and 0 deletions
|
@ -657,6 +657,43 @@ PackedStringArray Label::get_configuration_warnings() const {
|
|||
}
|
||||
}
|
||||
|
||||
Ref<FontFile> ff = font;
|
||||
if (ff.is_valid() && ff->is_multichannel_signed_distance_field()) {
|
||||
bool has_settings = settings.is_valid();
|
||||
int font_size = settings.is_valid() ? settings->get_font_size() : theme_cache.font_size;
|
||||
int outline_size = has_settings ? settings->get_outline_size() : theme_cache.font_outline_size;
|
||||
Vector<LabelSettings::StackedOutlineData> stacked_outline_datas = has_settings ? settings->get_stacked_outline_data() : Vector<LabelSettings::StackedOutlineData>();
|
||||
Vector<LabelSettings::StackedShadowData> stacked_shadow_datas = has_settings ? settings->get_stacked_shadow_data() : Vector<LabelSettings::StackedShadowData>();
|
||||
int max_outline_draw_size = outline_size;
|
||||
if (stacked_outline_datas.size() != 0) {
|
||||
int draw_iterations = stacked_outline_datas.size();
|
||||
for (int j = 0; j < draw_iterations; j++) {
|
||||
int stacked_outline_size = stacked_outline_datas[j].size;
|
||||
if (stacked_outline_size <= 0) {
|
||||
continue;
|
||||
}
|
||||
max_outline_draw_size += stacked_outline_size;
|
||||
}
|
||||
}
|
||||
if (stacked_shadow_datas.size() != 0) {
|
||||
int draw_iterations = stacked_shadow_datas.size();
|
||||
for (int j = 0; j < draw_iterations; j++) {
|
||||
LabelSettings::StackedShadowData stacked_shadow_data = stacked_shadow_datas[j];
|
||||
if (stacked_shadow_data.outline_size > 0) {
|
||||
max_outline_draw_size = MAX(max_outline_draw_size, stacked_shadow_data.outline_size);
|
||||
}
|
||||
}
|
||||
}
|
||||
float scale = (float)font_size / (float)ff->get_msdf_size();
|
||||
float ol = (float)max_outline_draw_size / scale / 4.0;
|
||||
float pxr = (float)ff->get_msdf_pixel_range() / 2.0 - 1.0;
|
||||
float r_pxr = (ol + 1.0) * 2.0;
|
||||
|
||||
if (ol > pxr) {
|
||||
warnings.push_back(vformat(RTR("MSDF font pixel range is too small, some outlines/shadows will not render. Set MSDF pixel range to be at least %d to render all outlines/shadows."), Math::ceil(r_pxr)));
|
||||
}
|
||||
}
|
||||
|
||||
return warnings;
|
||||
}
|
||||
|
||||
|
@ -857,6 +894,7 @@ void Label::_notification(int p_what) {
|
|||
case NOTIFICATION_THEME_CHANGED: {
|
||||
font_dirty = true;
|
||||
queue_redraw();
|
||||
update_configuration_warnings();
|
||||
} break;
|
||||
|
||||
case NOTIFICATION_RESIZED: {
|
||||
|
@ -1070,6 +1108,7 @@ void Label::set_text(const String &p_string) {
|
|||
void Label::_invalidate() {
|
||||
font_dirty = true;
|
||||
queue_redraw();
|
||||
update_configuration_warnings();
|
||||
}
|
||||
|
||||
void Label::set_label_settings(const Ref<LabelSettings> &p_settings) {
|
||||
|
@ -1082,6 +1121,7 @@ void Label::set_label_settings(const Ref<LabelSettings> &p_settings) {
|
|||
settings->connect_changed(callable_mp(this, &Label::_invalidate), CONNECT_REFERENCE_COUNTED);
|
||||
}
|
||||
_invalidate();
|
||||
update_configuration_warnings();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue