From dd8bb6e67e6aa1095b848bef6cdf9bf933ac1ef4 Mon Sep 17 00:00:00 2001 From: Pinchuk Aleksei Date: Thu, 11 Jul 2019 16:27:42 +0300 Subject: [PATCH 001/108] load BMF --- headers/enduro2d/high/_all.hpp | 1 + headers/enduro2d/high/_high.hpp | 2 + headers/enduro2d/high/assets/bmfont_asset.hpp | 21 +++ headers/enduro2d/high/bmfont.hpp | 96 ++++++++++ sources/enduro2d/high/assets/bmfont_asset.cpp | 37 ++++ sources/enduro2d/high/bmfont.cpp | 178 ++++++++++++++++++ 6 files changed, 335 insertions(+) create mode 100644 headers/enduro2d/high/assets/bmfont_asset.hpp create mode 100644 headers/enduro2d/high/bmfont.hpp create mode 100644 sources/enduro2d/high/assets/bmfont_asset.cpp create mode 100644 sources/enduro2d/high/bmfont.cpp diff --git a/headers/enduro2d/high/_all.hpp b/headers/enduro2d/high/_all.hpp index 4c8246a6..8e3cac51 100644 --- a/headers/enduro2d/high/_all.hpp +++ b/headers/enduro2d/high/_all.hpp @@ -24,6 +24,7 @@ #include "assets/text_asset.hpp" #include "assets/texture_asset.hpp" #include "assets/xml_asset.hpp" +#include "assets/bmfont_asset.hpp" #include "components/actor.hpp" #include "components/camera.hpp" diff --git a/headers/enduro2d/high/_high.hpp b/headers/enduro2d/high/_high.hpp index 0cc13c2f..81356c1e 100644 --- a/headers/enduro2d/high/_high.hpp +++ b/headers/enduro2d/high/_high.hpp @@ -36,6 +36,7 @@ namespace e2d class text_asset; class texture_asset; class xml_asset; + class bmfont_asset; class actor; class camera; @@ -68,4 +69,5 @@ namespace e2d class sprite; class starter; class world; + class bmfont; } diff --git a/headers/enduro2d/high/assets/bmfont_asset.hpp b/headers/enduro2d/high/assets/bmfont_asset.hpp new file mode 100644 index 00000000..0dc1bff6 --- /dev/null +++ b/headers/enduro2d/high/assets/bmfont_asset.hpp @@ -0,0 +1,21 @@ +/******************************************************************************* + * This file is part of the "Enduro2D" + * For conditions of distribution and use, see copyright notice in LICENSE.md + * Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com) + ******************************************************************************/ + +#pragma once + +#include "../_high.hpp" + +#include "../library.hpp" +#include "../bmfont.hpp" + +namespace e2d +{ + class bmfont_asset final : public content_asset { + public: + static const char* type_name() noexcept { return "bmfont_asset"; } + static load_async_result load_async(const library& library, str_view address); + }; +} diff --git a/headers/enduro2d/high/bmfont.hpp b/headers/enduro2d/high/bmfont.hpp new file mode 100644 index 00000000..780f40e7 --- /dev/null +++ b/headers/enduro2d/high/bmfont.hpp @@ -0,0 +1,96 @@ +/******************************************************************************* + * This file is part of the "Enduro2D" + * For conditions of distribution and use, see copyright notice in LICENSE.md + * Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com) + ******************************************************************************/ + +#pragma once + +#include "_high.hpp" + +//#include "assets/texture_asset.hpp" + +namespace e2d +{ + class bmfont; + + using bmfont_ptr = std::shared_ptr; + + class bad_bmfont_access final : public exception { + public: + const char* what() const noexcept final { + return "bad bmfont access"; + } + }; + + class bmfont final { + public: + struct char_data { + u32 id; + rect rect; + i16 xoffset; + i16 yoffset; + i16 xadvance; + i16 page; + i16 chnl; + }; + + struct info_data { + struct spacing_data { + i32 horizontal; + i32 vertical; + }; + + struct padding_data { + i16 up; + i16 right; + i16 down; + i16 left; + }; + +// str face; //This is the name of the true type font. + u32 size; //The size of the true type font. +// bool bold; //The font is bold. +// bool italic; //The font is italic. +// str charset; //The name of the OEM charset used (when not unicode). +// bool unicode; //Set to 1 if it is the unicode charset. +// u32 stretchH; //The font height stretch in percentage. 100% means no stretch. +// bool smooth; //Set to 1 if smoothing was turned on. +// u32 aa; //The supersampling level used. 1 means no supersampling was used. + padding_data padding; //The padding for each character (up, right, down, left). TODOPA +// spacing_data spacing; //The spacing for each character (horizontal, vertical). +// u32 outline; //The outline thickness for the characters. + }; + + struct kerning_data { + u32 first; // The first character id. + u32 second; // The second character id. + i32 amount; // How much the x position should be adjusted when drawing the second character immediately following the first. + }; + + struct common_data { + u32 lineHeight; //This is the distance in pixels between each line of text. +// u32 base; //The number of pixels from the absolute top of the line to the base of the characters. +// u32 scaleW; //The width of the texture, normally used to scale the x pos of the character image. +// u32 scaleH; //The height of the texture, normally used to scale the y pos of the character image. + u32 pages; //The number of texture pages included in the font. +// u32 packed; //Set to 1 if the monochrome characters have been packed into each of the texture channels. In this case alphaChnl describes what is stored in each channel. +// u32 alphaChnl; //Set to 0 if the channel holds the glyph data, 1 if it holds the outline, 2 if it holds the glyph and the outline, 3 if its set to zero, and 4 if its set to one. +// u32 redChnl; //Set to 0 if the channel holds the glyph data, 1 if it holds the outline, 2 if it holds the glyph and the outline, 3 if its set to zero, and 4 if its set to one. +// u32 greenChnl; //Set to 0 if the channel holds the glyph data, 1 if it holds the outline, 2 if it holds the glyph and the outline, 3 if its set to zero, and 4 if its set to one. +// u32 blueChnl; //Set to 0 if the channel holds the glyph data, 1 if it holds the outline, 2 if it holds the glyph and the outline, 3 if its set to zero, and 4 if its set to one. + }; + + bmfont() = default; + ~bmfont() noexcept = default; + + static bmfont_ptr create (str_view content); + + protected: + info_data info_; + common_data common_; + std::vector pages_; + std::vector chars_; + std::vector kerning_; + }; +} diff --git a/sources/enduro2d/high/assets/bmfont_asset.cpp b/sources/enduro2d/high/assets/bmfont_asset.cpp new file mode 100644 index 00000000..6c233eef --- /dev/null +++ b/sources/enduro2d/high/assets/bmfont_asset.cpp @@ -0,0 +1,37 @@ +/******************************************************************************* + * This file is part of the "Enduro2D" + * For conditions of distribution and use, see copyright notice in LICENSE.md + * Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com) + ******************************************************************************/ + +#include +#include + +namespace +{ + using namespace e2d; + + class bmfont_asset_loading_exception final : public asset_loading_exception { + const char* what() const noexcept final { + return "shader asset loading exception"; + } + }; +} + +namespace e2d +{ + bmfont_asset::load_async_result bmfont_asset::load_async( + const library& library, str_view address) + { + return library.load_asset_async(address) + .then([](const text_asset::load_result& text_data){ + return the().do_in_main_thread([text_data](){ + auto font = bmfont::create(text_data->content()); + if ( !font ) { + throw bmfont_asset_loading_exception(); + } + return bmfont_asset::create(font); + }); + }); + } +} diff --git a/sources/enduro2d/high/bmfont.cpp b/sources/enduro2d/high/bmfont.cpp new file mode 100644 index 00000000..fd91a18d --- /dev/null +++ b/sources/enduro2d/high/bmfont.cpp @@ -0,0 +1,178 @@ +/******************************************************************************* + * This file is part of the "Enduro2D" + * For conditions of distribution and use, see copyright notice in LICENSE.md + * Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com) + ******************************************************************************/ + +#include +//#include +#include + +namespace e2d +{ + bmfont_ptr bmfont::create (str_view content) { + bmfont_ptr b = std::make_shared(); + std::string s{content.data()}; + std::replace(s.begin(), s.end(), '=', ' '); + std::replace(s.begin(), s.end(), ',', ' '); + + std::string tag; + std::string line; + std::stringstream data_stream(s); + std::vector chars(120); + std::vector kerning(120); + int chars_counter = 0; + int kerning_counter = 0; + while (getline(data_stream, line, '\n')) + { + std::stringstream line_stream(line); + line_stream >> tag; + if (tag == "info") { + //info face="Arial-Black" size=32 bold=0 italic=0 charset="" unicode=0 stretchH=100 smooth=1 aa=1 padding=0,0,0,0 spacing=2,2 + line_stream >> tag; + while (!line_stream.eof()) { + if (tag == "size") { + line_stream >> b->info_.size; + } else if (tag == "padding") { + line_stream >> b->info_.padding.up; + line_stream >> b->info_.padding.right; + line_stream >> b->info_.padding.down; + line_stream >> b->info_.padding.left; + } + +// if (tag == "face") { +// line_stream >> b->info_.face; +// } else if (tag == "size") { +// line_stream >> b->info_.size; +// } else if (tag == "bold") { +// line_stream >> b->info_.bold; +// } else if (tag == "italic") { +// line_stream >> b->info_.italic; +// } else if (tag == "charset") { +// line_stream >> b->info_.charset; +// } else if (tag == "unicode") { +// line_stream >> b->info_.unicode; +// } else if (tag == "stretchH") { +// line_stream >> b->info_.stretchH; +// } else if (tag == "smooth") { +// line_stream >> b->info_.smooth; +// } else if (tag == "aa") { +// line_stream >> b->info_.aa; +// } else if (tag == "padding") { +// line_stream >> b->info_.padding.up +// >> b->info_.padding.right +// >> b->info_.padding.down +// >> b->info_.padding.left; +// } else if (tag == "spacing") { +// line_stream >> b->info_.spacing.horizontal +// >> b->info_.spacing.vertical; +// } + line_stream >> tag; + } + } else if (tag == "common") { + //common lineHeight=54 base=35 scaleW=512 scaleH=512 pages=1 packed=0 + line_stream >> tag; + while (!line_stream.eof()) { + if (tag == "lineHeight") { + line_stream >> b->common_.lineHeight; + } else if (tag == "pages") { + line_stream >> b->common_.pages; + b->pages_.resize( b->common_.pages); + } + line_stream >> tag; + } + } else if (tag == "page") { + //page id=0 file="boundsTestFont.png" + line_stream >> tag; + i32 id{-1}; + while (!line_stream.eof()) { + if (tag == "id") { + line_stream >> id; + } else if (tag == "file") { + std::string file; + line_stream >> file; + //remove "" + file.erase(file.begin()); + file.pop_back(); + b->pages_[id] = file; + } + line_stream >> tag; + } + } else if (tag == "chars") { + //chars count=95 + //this field may not exist! + while (!line_stream.eof()) { + if (tag == "count") { + size_t count; + line_stream >> count; + if ( count > chars.size() ) { + chars.resize(count); + } + } + line_stream >> tag; + } + } else if (tag == "char") { + //char id=123 x=2 y=2 width=38 height=54 xoffset=0 yoffset=-3 xadvance=12 page=0 chnl=0 letter="{" + line_stream >> tag; + i32 id{-1}; + char_data c; + while (!line_stream.eof()) { + if (tag == "id") { + line_stream >> id; + } else if (tag == "x") { + line_stream >> c.rect.position.x; + } else if (tag == "y") { + line_stream >> c.rect.position.y; + } else if (tag == "widht") { + line_stream >> c.rect.size.x; + } else if (tag == "height") { + line_stream >> c.rect.size.y; + } else if (tag == "xoffset") { + line_stream >> c.xoffset; + } else if (tag == "yoffset") { + line_stream >> c.yoffset; + } else if (tag == "xadvance") { + line_stream >> c.xadvance; + } else if (tag == "page") { + line_stream >> c.page; + } + line_stream >> tag; + } + chars[chars_counter++] = c; + } else if (tag == "kernings") { + //kernings count=243 + //this field may not exist! + while (!line_stream.eof()) { + if (tag == "count") { + size_t count; + line_stream >> count; + if ( count > kerning.size() ) { + kerning.resize(count); + } + } + line_stream >> tag; + } + } else if (tag == "kerning") { + //kerning first=86 second=101 amount=-2 + line_stream >> tag; + kerning_data k; + while (!line_stream.eof()) { + if (tag == "first") { + line_stream >> k.first; + } else if (tag == "second") { + line_stream >> k.second; + } else if (tag == "amount") { + line_stream >> k.amount; + } + line_stream >> tag; + } + kerning[kerning_counter++] = k; + } + } + + b->chars_.insert(b->chars_.begin(), chars.begin(), chars.begin()+chars_counter); + b->kerning_.insert(b->kerning_.begin(), kerning.begin(), kerning.begin()+kerning_counter); + + return b; + } +} From 1e8c5d710b1e4c40a195f292369646cc65d2eb45 Mon Sep 17 00:00:00 2001 From: Pinchuk Aleksei Date: Thu, 11 Jul 2019 17:49:53 +0300 Subject: [PATCH 002/108] clean code --- headers/enduro2d/high/bmfont.hpp | 56 +++++++------------------------- sources/enduro2d/high/bmfont.cpp | 53 +++++++----------------------- 2 files changed, 23 insertions(+), 86 deletions(-) diff --git a/headers/enduro2d/high/bmfont.hpp b/headers/enduro2d/high/bmfont.hpp index 780f40e7..e5825288 100644 --- a/headers/enduro2d/high/bmfont.hpp +++ b/headers/enduro2d/high/bmfont.hpp @@ -8,21 +8,12 @@ #include "_high.hpp" -//#include "assets/texture_asset.hpp" - namespace e2d { class bmfont; using bmfont_ptr = std::shared_ptr; - class bad_bmfont_access final : public exception { - public: - const char* what() const noexcept final { - return "bad bmfont access"; - } - }; - class bmfont final { public: struct char_data { @@ -36,11 +27,6 @@ namespace e2d }; struct info_data { - struct spacing_data { - i32 horizontal; - i32 vertical; - }; - struct padding_data { i16 up; i16 right; @@ -48,49 +34,31 @@ namespace e2d i16 left; }; -// str face; //This is the name of the true type font. - u32 size; //The size of the true type font. -// bool bold; //The font is bold. -// bool italic; //The font is italic. -// str charset; //The name of the OEM charset used (when not unicode). -// bool unicode; //Set to 1 if it is the unicode charset. -// u32 stretchH; //The font height stretch in percentage. 100% means no stretch. -// bool smooth; //Set to 1 if smoothing was turned on. -// u32 aa; //The supersampling level used. 1 means no supersampling was used. - padding_data padding; //The padding for each character (up, right, down, left). TODOPA -// spacing_data spacing; //The spacing for each character (horizontal, vertical). -// u32 outline; //The outline thickness for the characters. + u32 size; + padding_data padding; }; struct kerning_data { - u32 first; // The first character id. - u32 second; // The second character id. - i32 amount; // How much the x position should be adjusted when drawing the second character immediately following the first. + u32 first; + u32 second; + i32 amount; }; struct common_data { - u32 lineHeight; //This is the distance in pixels between each line of text. -// u32 base; //The number of pixels from the absolute top of the line to the base of the characters. -// u32 scaleW; //The width of the texture, normally used to scale the x pos of the character image. -// u32 scaleH; //The height of the texture, normally used to scale the y pos of the character image. - u32 pages; //The number of texture pages included in the font. -// u32 packed; //Set to 1 if the monochrome characters have been packed into each of the texture channels. In this case alphaChnl describes what is stored in each channel. -// u32 alphaChnl; //Set to 0 if the channel holds the glyph data, 1 if it holds the outline, 2 if it holds the glyph and the outline, 3 if its set to zero, and 4 if its set to one. -// u32 redChnl; //Set to 0 if the channel holds the glyph data, 1 if it holds the outline, 2 if it holds the glyph and the outline, 3 if its set to zero, and 4 if its set to one. -// u32 greenChnl; //Set to 0 if the channel holds the glyph data, 1 if it holds the outline, 2 if it holds the glyph and the outline, 3 if its set to zero, and 4 if its set to one. -// u32 blueChnl; //Set to 0 if the channel holds the glyph data, 1 if it holds the outline, 2 if it holds the glyph and the outline, 3 if its set to zero, and 4 if its set to one. + u32 line_height; + u32 pages; }; bmfont() = default; ~bmfont() noexcept = default; - static bmfont_ptr create (str_view content); + static bmfont_ptr create(str_view content); - protected: + private: info_data info_; common_data common_; - std::vector pages_; - std::vector chars_; - std::vector kerning_; + vector pages_; + vector chars_; + vector kerning_; }; } diff --git a/sources/enduro2d/high/bmfont.cpp b/sources/enduro2d/high/bmfont.cpp index fd91a18d..dc5c74ba 100644 --- a/sources/enduro2d/high/bmfont.cpp +++ b/sources/enduro2d/high/bmfont.cpp @@ -5,22 +5,21 @@ ******************************************************************************/ #include -//#include #include namespace e2d { bmfont_ptr bmfont::create (str_view content) { bmfont_ptr b = std::make_shared(); - std::string s{content.data()}; + str s{content.data()}; std::replace(s.begin(), s.end(), '=', ' '); std::replace(s.begin(), s.end(), ',', ' '); - std::string tag; - std::string line; + str tag; + str line; std::stringstream data_stream(s); - std::vector chars(120); - std::vector kerning(120); + vector chars(120); + vector kerning(120); int chars_counter = 0; int kerning_counter = 0; while (getline(data_stream, line, '\n')) @@ -39,34 +38,6 @@ namespace e2d line_stream >> b->info_.padding.down; line_stream >> b->info_.padding.left; } - -// if (tag == "face") { -// line_stream >> b->info_.face; -// } else if (tag == "size") { -// line_stream >> b->info_.size; -// } else if (tag == "bold") { -// line_stream >> b->info_.bold; -// } else if (tag == "italic") { -// line_stream >> b->info_.italic; -// } else if (tag == "charset") { -// line_stream >> b->info_.charset; -// } else if (tag == "unicode") { -// line_stream >> b->info_.unicode; -// } else if (tag == "stretchH") { -// line_stream >> b->info_.stretchH; -// } else if (tag == "smooth") { -// line_stream >> b->info_.smooth; -// } else if (tag == "aa") { -// line_stream >> b->info_.aa; -// } else if (tag == "padding") { -// line_stream >> b->info_.padding.up -// >> b->info_.padding.right -// >> b->info_.padding.down -// >> b->info_.padding.left; -// } else if (tag == "spacing") { -// line_stream >> b->info_.spacing.horizontal -// >> b->info_.spacing.vertical; -// } line_stream >> tag; } } else if (tag == "common") { @@ -74,7 +45,7 @@ namespace e2d line_stream >> tag; while (!line_stream.eof()) { if (tag == "lineHeight") { - line_stream >> b->common_.lineHeight; + line_stream >> b->common_.line_height; } else if (tag == "pages") { line_stream >> b->common_.pages; b->pages_.resize( b->common_.pages); @@ -89,7 +60,7 @@ namespace e2d if (tag == "id") { line_stream >> id; } else if (tag == "file") { - std::string file; + str file; line_stream >> file; //remove "" file.erase(file.begin()); @@ -114,11 +85,10 @@ namespace e2d } else if (tag == "char") { //char id=123 x=2 y=2 width=38 height=54 xoffset=0 yoffset=-3 xadvance=12 page=0 chnl=0 letter="{" line_stream >> tag; - i32 id{-1}; - char_data c; + char_data& c = chars[chars_counter++]; while (!line_stream.eof()) { if (tag == "id") { - line_stream >> id; + line_stream >> c.id; } else if (tag == "x") { line_stream >> c.rect.position.x; } else if (tag == "y") { @@ -127,6 +97,7 @@ namespace e2d line_stream >> c.rect.size.x; } else if (tag == "height") { line_stream >> c.rect.size.y; + c.rect.position.y -= c.rect.size.y; } else if (tag == "xoffset") { line_stream >> c.xoffset; } else if (tag == "yoffset") { @@ -138,7 +109,6 @@ namespace e2d } line_stream >> tag; } - chars[chars_counter++] = c; } else if (tag == "kernings") { //kernings count=243 //this field may not exist! @@ -155,7 +125,7 @@ namespace e2d } else if (tag == "kerning") { //kerning first=86 second=101 amount=-2 line_stream >> tag; - kerning_data k; + kerning_data& k = kerning[kerning_counter++]; while (!line_stream.eof()) { if (tag == "first") { line_stream >> k.first; @@ -166,7 +136,6 @@ namespace e2d } line_stream >> tag; } - kerning[kerning_counter++] = k; } } From 1f0e25db91e92003199d81f54c2d7de4c2ff02fe Mon Sep 17 00:00:00 2001 From: Pinchuk Aleksei Date: Fri, 12 Jul 2019 11:53:33 +0300 Subject: [PATCH 003/108] added default value --- headers/enduro2d/high/bmfont.hpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/headers/enduro2d/high/bmfont.hpp b/headers/enduro2d/high/bmfont.hpp index e5825288..023b30e7 100644 --- a/headers/enduro2d/high/bmfont.hpp +++ b/headers/enduro2d/high/bmfont.hpp @@ -17,36 +17,36 @@ namespace e2d class bmfont final { public: struct char_data { - u32 id; + u32 id{0}; rect rect; - i16 xoffset; - i16 yoffset; - i16 xadvance; - i16 page; - i16 chnl; + i16 xoffset{0}; + i16 yoffset{0}; + i16 xadvance{0}; + i16 page{0}; + i16 chnl{0}; }; struct info_data { struct padding_data { - i16 up; - i16 right; - i16 down; - i16 left; + i16 up{0}; + i16 right{0}; + i16 down{0}; + i16 left{0}; }; - u32 size; + u32 size{0}; padding_data padding; }; struct kerning_data { - u32 first; - u32 second; - i32 amount; + u32 first{0}; + u32 second{0}; + i32 amount{0}; }; struct common_data { - u32 line_height; - u32 pages; + u32 line_height{0}; + u32 pages{0}; }; bmfont() = default; From 30331350bd79c38b78708d67ab1523953c294dae Mon Sep 17 00:00:00 2001 From: Pinchuk Aleksei Date: Tue, 16 Jul 2019 18:14:24 +0300 Subject: [PATCH 004/108] draw bm font --- headers/enduro2d/high/_all.hpp | 4 +- headers/enduro2d/high/_high.hpp | 5 +- .../{bmfont_asset.hpp => font_asset.hpp} | 3 +- headers/enduro2d/high/components/label.hpp | 85 ++++++++++++ .../enduro2d/high/systems/label_system.hpp | 22 +++ headers/enduro2d/utils/_all.hpp | 1 + headers/enduro2d/utils/_utils.hpp | 1 + .../{high/bmfont.hpp => utils/font.hpp} | 24 ++-- samples/CMakeLists.txt | 2 + samples/bin/library/font_material.json | 21 +++ samples/sources/sample_07/sample_07.cpp | 127 ++++++++++++++++++ .../{bmfont_asset.cpp => font_asset.cpp} | 8 +- sources/enduro2d/high/components/label.cpp | 52 +++++++ .../enduro2d/high/systems/label_system.cpp | 125 +++++++++++++++++ .../{high/bmfont.cpp => utils/font.cpp} | 54 +++++++- 15 files changed, 509 insertions(+), 25 deletions(-) rename headers/enduro2d/high/assets/{bmfont_asset.hpp => font_asset.hpp} (85%) create mode 100644 headers/enduro2d/high/components/label.hpp create mode 100644 headers/enduro2d/high/systems/label_system.hpp rename headers/enduro2d/{high/bmfont.hpp => utils/font.hpp} (69%) create mode 100644 samples/bin/library/font_material.json create mode 100644 samples/sources/sample_07/sample_07.cpp rename sources/enduro2d/high/assets/{bmfont_asset.cpp => font_asset.cpp} (82%) create mode 100644 sources/enduro2d/high/components/label.cpp create mode 100644 sources/enduro2d/high/systems/label_system.cpp rename sources/enduro2d/{high/bmfont.cpp => utils/font.cpp} (75%) diff --git a/headers/enduro2d/high/_all.hpp b/headers/enduro2d/high/_all.hpp index 8e3cac51..a67813d7 100644 --- a/headers/enduro2d/high/_all.hpp +++ b/headers/enduro2d/high/_all.hpp @@ -24,7 +24,7 @@ #include "assets/text_asset.hpp" #include "assets/texture_asset.hpp" #include "assets/xml_asset.hpp" -#include "assets/bmfont_asset.hpp" +#include "assets/font_asset.hpp" #include "components/actor.hpp" #include "components/camera.hpp" @@ -34,9 +34,11 @@ #include "components/renderer.hpp" #include "components/scene.hpp" #include "components/sprite_renderer.hpp" +#include "components/label.hpp" #include "systems/flipbook_system.hpp" #include "systems/render_system.hpp" +#include "systems/label_system.hpp" #include "address.hpp" #include "asset.hpp" diff --git a/headers/enduro2d/high/_high.hpp b/headers/enduro2d/high/_high.hpp index 81356c1e..35662531 100644 --- a/headers/enduro2d/high/_high.hpp +++ b/headers/enduro2d/high/_high.hpp @@ -36,7 +36,7 @@ namespace e2d class text_asset; class texture_asset; class xml_asset; - class bmfont_asset; + class font_asset; class actor; class camera; @@ -46,9 +46,11 @@ namespace e2d class renderer; class scene; class sprite_renderer; + class label; class flipbook_system; class render_system; + class label_system; template < typename Asset, typename Content > class content_asset; @@ -69,5 +71,4 @@ namespace e2d class sprite; class starter; class world; - class bmfont; } diff --git a/headers/enduro2d/high/assets/bmfont_asset.hpp b/headers/enduro2d/high/assets/font_asset.hpp similarity index 85% rename from headers/enduro2d/high/assets/bmfont_asset.hpp rename to headers/enduro2d/high/assets/font_asset.hpp index 0dc1bff6..b85e895f 100644 --- a/headers/enduro2d/high/assets/bmfont_asset.hpp +++ b/headers/enduro2d/high/assets/font_asset.hpp @@ -9,11 +9,10 @@ #include "../_high.hpp" #include "../library.hpp" -#include "../bmfont.hpp" namespace e2d { - class bmfont_asset final : public content_asset { + class font_asset final : public content_asset { public: static const char* type_name() noexcept { return "bmfont_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 new file mode 100644 index 00000000..0495292d --- /dev/null +++ b/headers/enduro2d/high/components/label.hpp @@ -0,0 +1,85 @@ +/******************************************************************************* + * This file is part of the "Enduro2D" + * For conditions of distribution and use, see copyright notice in LICENSE.md + * Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com) + ******************************************************************************/ + +#pragma once + +#include "../_high.hpp" + +#include "../factory.hpp" +#include "../assets/font_asset.hpp" + +namespace e2d +{ + class label final { + public: + label() = default; + label(const str_view text); + + label& text(const str_view text) noexcept; + const str& text() const noexcept; + + label& dirty(bool dirty) noexcept; + bool dirty() const noexcept; + + label& font(const font_asset::ptr& font) noexcept; + const font_asset::ptr& font() const noexcept; + private: + bool dirty_ = false; + str text_; + font_asset::ptr font_; + }; + + template <> + class factory_loader