Figured out the easiest way to set a panel to be centered, but a lot of these config things need to be unified and cleaned up.

This commit is contained in:
Zed A. Shaw 2025-01-16 23:07:18 -05:00
parent 269af02993
commit fc61ef42ac
6 changed files with 48 additions and 33 deletions

View file

@ -13,7 +13,6 @@
#include <io.h>
#endif
using namespace fmt;
SFMLRender::SFMLRender() :
@ -33,6 +32,8 @@ SFMLRender::SFMLRender() :
$ui_text.setFillColor(ColorValue::LIGHT_MID);
sf::Glyph glyph = $font.getGlyph($config.ui_base_char, $config.ui_font_size, false);
$text_bounds = glyph.bounds;
$cells_w = std::ceil($config.video_x / $text_bounds.width);
$cells_h = std::ceil($config.video_y / $text_bounds.height);
}
sf::Sprite &SFMLRender::get_text_sprite(wchar_t tile) {
@ -57,6 +58,14 @@ void SFMLRender::clear_cache() {
$ui_text.setFont($font);
}
void SFMLRender::center_panel(Panel &panel) {
int cell_center_x = ($cells_w - panel.width) / 2;
int cell_center_y = ($cells_h - panel.height) / 2;
panel.x = cell_center_x * $text_bounds.width;
panel.y = cell_center_y * $text_bounds.height;
}
void SFMLRender::resize_grid(int new_size, Panel &panel_out) {
auto glyph = $font.getGlyph($config.bg_tile, new_size, false);
int view_x = std::ceil(($config.video_x - panel_out.x) / glyph.bounds.width);