|
|
@ -33,26 +33,28 @@ struct MapTileBuilder { |
|
|
|
sf::Glyph $glyph; |
|
|
|
sf::Glyph $glyph; |
|
|
|
sf::Font $font{FONT_FILE_NAME}; |
|
|
|
sf::Font $font{FONT_FILE_NAME}; |
|
|
|
std::shared_ptr<sf::RenderTexture> $render = nullptr; |
|
|
|
std::shared_ptr<sf::RenderTexture> $render = nullptr; |
|
|
|
sf::Vector2u $size; |
|
|
|
sf::Vector2i $size; |
|
|
|
sf::Vector2u $image_size; |
|
|
|
sf::Vector2i $image_size; |
|
|
|
sf::RenderTexture $temp_render; |
|
|
|
sf::RenderTexture $temp_render; |
|
|
|
|
|
|
|
|
|
|
|
MapTileBuilder(size_t x, size_t y) : |
|
|
|
MapTileBuilder(size_t x, size_t y) : |
|
|
|
$size(x, y), |
|
|
|
$size(x, y), |
|
|
|
$image_size($size.x * TILE_COUNT, $size.y * TILE_COUNT), |
|
|
|
$image_size($size.x * TILE_COUNT, $size.y * TILE_COUNT), |
|
|
|
$temp_render($size) |
|
|
|
$temp_render({(unsigned int)$size.x, (unsigned int)$size.y}) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$font.setSmooth(false); |
|
|
|
$font.setSmooth(false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void best_size(wchar_t for_char) { |
|
|
|
void best_size(wchar_t for_char, bool centered) { |
|
|
|
|
|
|
|
float factor = centered ? 0.8f : 1.0f; |
|
|
|
|
|
|
|
sf::Vector2i adjusted_size = {int($size.x * factor), int($size.y * factor)}; |
|
|
|
$font_size = 20; // reset the size
|
|
|
|
$font_size = 20; // reset the size
|
|
|
|
// fit the glyph in our box height
|
|
|
|
// fit the glyph in our box height
|
|
|
|
auto temp = $font.getGlyph(for_char, $font_size, false); |
|
|
|
auto temp = $font.getGlyph(for_char, $font_size, false); |
|
|
|
auto temp_size = $font_size; |
|
|
|
auto temp_size = $font_size; |
|
|
|
|
|
|
|
|
|
|
|
while(temp.textureRect.size.y < int($size.y) |
|
|
|
while(temp.textureRect.size.y <= adjusted_size.y |
|
|
|
&& temp.textureRect.size.x < int($size.x)) |
|
|
|
&& temp.textureRect.size.x <= adjusted_size.x) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$glyph = temp; |
|
|
|
$glyph = temp; |
|
|
|
$font_size = temp_size; |
|
|
|
$font_size = temp_size; |
|
|
@ -79,6 +81,7 @@ struct MapTileBuilder { |
|
|
|
void run(MapConfig& config) { |
|
|
|
void run(MapConfig& config) { |
|
|
|
sf::Vector2u crop{$size.x * (unsigned int)config.it.width, $size.y * (unsigned int)config.it.y}; |
|
|
|
sf::Vector2u crop{$size.x * (unsigned int)config.it.width, $size.y * (unsigned int)config.it.y}; |
|
|
|
$render = std::make_shared<sf::RenderTexture>(crop); |
|
|
|
$render = std::make_shared<sf::RenderTexture>(crop); |
|
|
|
|
|
|
|
$render->clear({0,0,0,0}); |
|
|
|
|
|
|
|
|
|
|
|
$render->setSmooth(false); |
|
|
|
$render->setSmooth(false); |
|
|
|
sf::Vector2f cell_pos{0.0f,0.0f}; |
|
|
|
sf::Vector2f cell_pos{0.0f,0.0f}; |
|
|
@ -93,7 +96,7 @@ struct MapTileBuilder { |
|
|
|
wchar_t display_char = config.map[it.y][it.x]; |
|
|
|
wchar_t display_char = config.map[it.y][it.x]; |
|
|
|
std::wstring content{display_char}; |
|
|
|
std::wstring content{display_char}; |
|
|
|
|
|
|
|
|
|
|
|
best_size(display_char); |
|
|
|
best_size(display_char, is_centered); |
|
|
|
|
|
|
|
|
|
|
|
sf::Text icon{$font, content, $font_size}; |
|
|
|
sf::Text icon{$font, content, $font_size}; |
|
|
|
icon.setFillColor({0, 0, 0, 255}); |
|
|
|
icon.setFillColor({0, 0, 0, 255}); |
|
|
@ -105,16 +108,15 @@ struct MapTileBuilder { |
|
|
|
sf::Sprite sprite{font_texture, $glyph.textureRect}; |
|
|
|
sf::Sprite sprite{font_texture, $glyph.textureRect}; |
|
|
|
auto t_size = $glyph.textureRect.size; |
|
|
|
auto t_size = $glyph.textureRect.size; |
|
|
|
|
|
|
|
|
|
|
|
dbc::check(int($size.x - t_size.x) > 0, "font too big on x"); |
|
|
|
dbc::check($size.x - t_size.x >= 0, "font too big on x"); |
|
|
|
dbc::check(int($size.y - t_size.y) > 0, "font too big on y"); |
|
|
|
dbc::check($size.y - t_size.y >= 0, "font too big on y"); |
|
|
|
|
|
|
|
|
|
|
|
if(is_centered) { |
|
|
|
if(is_centered) { |
|
|
|
sf::Vector2f center{ |
|
|
|
sf::Vector2f center{ |
|
|
|
(float($size.x) - float(t_size.x)) / 2.0f, |
|
|
|
float(($size.x - t_size.x) / 2), |
|
|
|
(float($size.y) - float(t_size.y)) / 2.0f}; |
|
|
|
float(($size.y - t_size.y) / 2)}; |
|
|
|
|
|
|
|
|
|
|
|
sf::Vector2f scale{float($size.x) / float(t_size.x) * 0.8f, float($size.y) / float(t_size.y) * 0.8f}; |
|
|
|
sprite.setScale({1.0f, 1.0f}); |
|
|
|
sprite.setScale(scale); |
|
|
|
|
|
|
|
sprite.setPosition({cell_pos.x + center.x, cell_pos.y + center.y}); |
|
|
|
sprite.setPosition({cell_pos.x + center.x, cell_pos.y + center.y}); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
sf::Vector2f scale{float($size.x) / float(t_size.x), float($size.y) / float(t_size.y)}; |
|
|
|
sf::Vector2f scale{float($size.x) / float(t_size.x), float($size.y) / float(t_size.y)}; |
|
|
|