diff --git a/headers/enduro2d/high/assets/font_asset.hpp b/headers/enduro2d/high/assets/font_asset.hpp index b263fe6b..33567fac 100644 --- a/headers/enduro2d/high/assets/font_asset.hpp +++ b/headers/enduro2d/high/assets/font_asset.hpp @@ -14,7 +14,7 @@ namespace e2d { class font_asset final : public content_asset { public: - static const char* type_name() noexcept { return "bmfont_asset"; } + static const char* type_name() noexcept { return "font_asset"; } static load_async_result load_async(const library& library, str_view address); }; } diff --git a/headers/enduro2d/high/components/label.hpp b/headers/enduro2d/high/components/label.hpp index b589ed66..29327218 100644 --- a/headers/enduro2d/high/components/label.hpp +++ b/headers/enduro2d/high/components/label.hpp @@ -52,48 +52,24 @@ namespace e2d label& valigh(valigns value) noexcept; [[nodiscard]] valigns valign() const noexcept; - label& char_width(f32 value) noexcept; - f32 char_width() const noexcept; - - label& char_edge(f32 value) noexcept; - f32 char_edge() const noexcept; + label& glyph_dilate(f32 value) noexcept; + [[nodiscard]] f32 glyph_dilate() const noexcept; label& outline_width(f32 value) noexcept; - f32 outline_width() const noexcept; - - label& outline_edge(f32 value) noexcept; - f32 outline_edge() const noexcept; + [[nodiscard]] f32 outline_width() const noexcept; label& outline_color(const color32& value) noexcept; - color32 outline_color() const noexcept; - - label& shadow_width(f32 value) noexcept; - f32 shadow_width() const noexcept; - - label& shadow_edge(f32 value) noexcept; - f32 shadow_edge() const noexcept; - - label& shadow_offset(const v2f& value) noexcept; - v2f shadow_offset() const noexcept; - - label& shadow_color(const color32& value) noexcept; - color32 shadow_color() const noexcept; + [[nodiscard]] const color32& outline_color() const noexcept; private: str32 text_; font_asset::ptr font_; color32 tint_ = color32::white(); f32 width_ = 0.f; - haligns halign_ = haligns::left; + haligns halign_ = haligns::center; valigns valign_ = valigns::baseline; - f32 char_width_ = 0.f; - f32 char_edge_ = 0.f; - f32 outline_width_ = 0.5f; - f32 outline_edge_ = 0.1f; + f32 glyph_dilate_ = 0.f; + f32 outline_width_ = 0.f; color32 outline_color_ = color32::white(); - f32 shadow_width_ = 0.f; - f32 shadow_edge_ = 0.f; - v2f shadow_offset_ = v2f::zero(); - color32 shadow_color_ = color32::white(); }; template <> @@ -184,22 +160,13 @@ namespace e2d return valign_; } - inline label& label::char_width(f32 value) noexcept { - char_width_ = value; + inline label& label::glyph_dilate(f32 value) noexcept { + glyph_dilate_ = value; return *this; } - inline f32 label::char_width() const noexcept { - return char_width_; - } - - inline label& label::char_edge(f32 value) noexcept { - char_edge_ = value; - return *this; - } - - inline f32 label::char_edge() const noexcept { - return char_edge_; + inline f32 label::glyph_dilate() const noexcept { + return glyph_dilate_; } inline label& label::outline_width(f32 value) noexcept { @@ -211,57 +178,12 @@ namespace e2d return outline_width_; } - inline label& label::outline_edge(f32 value) noexcept { - outline_edge_ = value; - return *this; - } - - inline f32 label::outline_edge() const noexcept { - return outline_edge_; - } - inline label& label::outline_color(const color32& value) noexcept { outline_color_ = value; return *this; } - inline color32 label::outline_color() const noexcept { + inline const color32& label::outline_color() const noexcept { return outline_color_; } - - inline label& label::shadow_width(f32 value) noexcept { - shadow_width_ = value; - return *this; - } - - inline f32 label::shadow_width() const noexcept { - return shadow_width_; - } - - inline label& label::shadow_edge(f32 value) noexcept { - shadow_edge_ = value; - return *this; - } - - inline f32 label::shadow_edge() const noexcept { - return shadow_edge_; - } - - inline label& label::shadow_offset(const v2f& value) noexcept { - shadow_offset_ = value; - return *this; - } - - inline v2f label::shadow_offset() const noexcept { - return shadow_offset_; - } - - inline label& label::shadow_color(const color32& value) noexcept { - shadow_color_ = value; - return *this; - } - - inline color32 label::shadow_color() const noexcept { - return shadow_color_; - } } diff --git a/sources/enduro2d/high/components/label.cpp b/sources/enduro2d/high/components/label.cpp index cc39607a..3b7baa27 100644 --- a/sources/enduro2d/high/components/label.cpp +++ b/sources/enduro2d/high/components/label.cpp @@ -43,15 +43,9 @@ namespace e2d "width" : { "type" : "number" }, "halign" : { "$ref": "#/definitions/haligns" }, "valign" : { "$ref": "#/definitions/valigns" }, - "char_width" : { "type" : "number" }, - "char_edge" : { "type" : "number" }, + "glyph_dilate" : { "type" : "number" }, "outline_width" : { "type" : "number" }, - "outline_edge" : { "type" : "number" }, - "outline_color" : { "$ref": "#/common_definitions/color" }, - "shadow_width" : { "type" : "number" }, - "shadow_edge" : { "type" : "number" }, - "shadow_offset" : { "$ref": "#/common_definitions/v2" }, - "shadow_color" : { "$ref": "#/common_definitions/color" } + "outline_color" : { "$ref": "#/common_definitions/color" } }, "definitions" : { "haligns" : { @@ -137,22 +131,13 @@ namespace e2d component.valigh(valign); } - if ( ctx.root.HasMember("char_width") ) { - f32 char_width = component.char_width(); - if ( !json_utils::try_parse_value(ctx.root["char_width"], char_width) ) { - the().error("LABEL: Incorrect formatting of 'char_width' property"); + if ( ctx.root.HasMember("glyph_dilate") ) { + f32 glyph_dilate = component.glyph_dilate(); + if ( !json_utils::try_parse_value(ctx.root["glyph_dilate"], glyph_dilate) ) { + the().error("LABEL: Incorrect formatting of 'glyph_dilate' property"); return false; } - component.char_width(char_width); - } - - if ( ctx.root.HasMember("char_edge") ) { - f32 char_edge = component.char_edge(); - if ( !json_utils::try_parse_value(ctx.root["char_edge"], char_edge) ) { - the().error("LABEL: Incorrect formatting of 'char_edge' property"); - return false; - } - component.char_edge(char_edge); + component.glyph_dilate(glyph_dilate); } if ( ctx.root.HasMember("outline_width") ) { @@ -164,15 +149,6 @@ namespace e2d component.outline_width(outline_width); } - if ( ctx.root.HasMember("outline_edge") ) { - f32 outline_edge = component.outline_edge(); - if ( !json_utils::try_parse_value(ctx.root["outline_edge"], outline_edge) ) { - the().error("LABEL: Incorrect formatting of 'outline_edge' property"); - return false; - } - component.outline_edge(outline_edge); - } - if ( ctx.root.HasMember("outline_color") ) { color32 outline_color = component.outline_color(); if ( !json_utils::try_parse_value(ctx.root["outline_color"], outline_color) ) { @@ -182,42 +158,6 @@ namespace e2d component.outline_color(outline_color); } - if ( ctx.root.HasMember("shadow_width") ) { - f32 shadow_width = component.shadow_width(); - if ( !json_utils::try_parse_value(ctx.root["shadow_width"], shadow_width) ) { - the().error("LABEL: Incorrect formatting of 'shadow_width' property"); - return false; - } - component.shadow_width(shadow_width); - } - - if ( ctx.root.HasMember("shadow_edge") ) { - f32 shadow_edge = component.shadow_edge(); - if ( !json_utils::try_parse_value(ctx.root["shadow_edge"], shadow_edge) ) { - the().error("LABEL: Incorrect formatting of 'shadow_edge' property"); - return false; - } - component.shadow_edge(shadow_edge); - } - - if ( ctx.root.HasMember("shadow_offset") ) { - v2f shadow_offset = component.shadow_offset(); - if ( !json_utils::try_parse_value(ctx.root["shadow_offset"], shadow_offset) ) { - the().error("LABEL: Incorrect formatting of 'shadow_offset' property"); - return false; - } - component.shadow_offset(shadow_offset); - } - - if ( ctx.root.HasMember("shadow_color") ) { - color32 shadow_color = component.shadow_color(); - if ( !json_utils::try_parse_value(ctx.root["shadow_color"], shadow_color) ) { - the().error("LABEL: Incorrect formatting of 'shadow_color' property"); - return false; - } - component.shadow_color(shadow_color); - } - return true; } diff --git a/sources/enduro2d/high/systems/label_system.cpp b/sources/enduro2d/high/systems/label_system.cpp index bad2a4c7..17065466 100644 --- a/sources/enduro2d/high/systems/label_system.cpp +++ b/sources/enduro2d/high/systems/label_system.cpp @@ -274,26 +274,18 @@ namespace e2d return; } - vec2 shadow_offset = l.shadow_offset(); - shadow_offset.x /= texture_p->content()->size().x; - shadow_offset.y /= texture_p->content()->size().y; - shadow_offset.x = -shadow_offset.x; - color oc(l.outline_color()); - color sc(l.shadow_color()); + const f32 glyph_dilate = math::clamp(l.glyph_dilate(), -1.f, 1.0f); + const f32 outline_width = math::clamp(l.outline_width(), 0.f, 1.f - glyph_dilate); + const v4f outline_color = make_vec4(color(l.outline_color())); + r.properties(render::property_block() .sampler("u_texture", render::sampler_state() .texture(texture_p->content()) .min_filter(render::sampler_min_filter::linear) .mag_filter(render::sampler_mag_filter::linear)) - .property("u_char_width", l.char_width()) - .property("u_char_edge", l.char_edge()) - .property("u_outline_width", l.outline_width()) - .property("u_outline_edge", l.outline_edge()) - .property("u_outline_color", make_vec4(oc.r, oc.g, oc.b, oc.a)) - .property("u_shadow_width", l.shadow_width()) - .property("u_shadow_edge", l.shadow_edge()) - .property("u_shadow_offset", shadow_offset) - .property("u_shadow_color", make_vec4(sc.r, sc.g, sc.b, sc.a))); + .property("u_glyph_dilate", glyph_dilate) + .property("u_outline_width", outline_width) + .property("u_outline_color", outline_color)); } });