Add some debug boxes around the fonts to figure out why they aren't vertically centered.

Zed A. Shaw 3 weeks ago
parent 45ad16c010
commit 6b9c67beec
  1. 20
      combat_ui.cpp
  2. 1
      combat_ui.hpp
  3. 12
      tests/matrix.cpp

@ -16,7 +16,6 @@ namespace gui {
}
void CombatUI::render() {
for(auto& [name, cell] : $layout.cells) {
sf::RectangleShape button;
button.setPosition({float(cell.x + 10), float(cell.y + 10)});
@ -28,9 +27,20 @@ namespace gui {
sf::Text label($font, name);
auto bounds = label.getLocalBounds();
auto inner_cell = lel::center(bounds.size.x, bounds.size.y, cell);
label.setPosition({float(inner_cell.x), float(inner_cell.y)});
fmt::println("CENTER w/h={},{} vs bounds={},{}",
cell.w, cell.h, bounds.size.x, bounds.size.y);
auto label_cell = lel::center(bounds.size.x, bounds.size.y, cell);
label.setPosition({float(label_cell.x), float(label_cell.y)});
$labels.push_back(label);
sf::RectangleShape label_box;
label_box.setPosition({float(label_cell.x), float(label_cell.y)});
label_box.setSize({float(label_cell.w), float(label_cell.h)});
label_box.setFillColor({10, 10, 10});
label_box.setOutlineColor({100,100,100});
label_box.setOutlineThickness(1.0);
$label_boxes.insert_or_assign("Z" + name, label_box);
}
}
@ -39,6 +49,10 @@ namespace gui {
window.draw(shape);
}
for(auto& [name, shape] : $label_boxes) {
window.draw(shape);
}
for(auto& label : $labels) {
window.draw(label);
}

@ -17,6 +17,7 @@ namespace gui {
GameLevel $level;
sf::Font $font;
std::unordered_map<std::string, sf::RectangleShape> $shapes;
std::unordered_map<std::string, sf::RectangleShape> $label_boxes;
std::vector<sf::Text> $labels;
CombatUI(GameLevel level);

@ -87,7 +87,7 @@ inline void random_matrix(Matrix &out) {
}
TEST_CASE("thrash matrix iterators", "[matrix]") {
for(int count = 0; count < Random::uniform<int>(10,30); count++) {
for(int count = 0; count < 5; count++) {
size_t width = Random::uniform<size_t>(1, 100);
size_t height = Random::uniform<size_t>(1, 100);
@ -128,7 +128,7 @@ TEST_CASE("thrash box distance iterators", "[matrix:distance]") {
}
TEST_CASE("thrash box iterators", "[matrix]") {
for(int count = 0; count < 20; count++) {
for(int count = 0; count < 5; count++) {
size_t width = Random::uniform<size_t>(1, 25);
size_t height = Random::uniform<size_t>(1, 33);
@ -159,7 +159,7 @@ TEST_CASE("thrash box iterators", "[matrix]") {
}
TEST_CASE("thrash compass iterators", "[matrix:compass]") {
for(int count = 0; count < 20; count++) {
for(int count = 0; count < 5; count++) {
size_t width = Random::uniform<size_t>(1, 25);
size_t height = Random::uniform<size_t>(1, 33);
@ -225,7 +225,7 @@ TEST_CASE("prototype line algorithm", "[matrix:line]") {
}
TEST_CASE("prototype circle algorithm", "[matrix:circle]") {
for(int count = 0; count < 2; count++) {
for(int count = 0; count < 5; count++) {
size_t width = Random::uniform<size_t>(10, 13);
size_t height = Random::uniform<size_t>(10, 15);
int pos_mod = Random::uniform<int>(-3,3);
@ -279,7 +279,7 @@ TEST_CASE("viewport iterator", "[matrix:viewport]") {
}
TEST_CASE("random rectangle", "[matrix:rando_rect]") {
for(int i = 0; i < 10; i++) {
for(int i = 0; i < 5; i++) {
shared_ptr<Map> map = make_map();
map->invert_space();
auto wall_copy = map->walls();
@ -303,7 +303,7 @@ TEST_CASE("random rectangle", "[matrix:rando_rect]") {
}
TEST_CASE("standard rectangle", "[matrix:rectangle]") {
for(int i = 0; i < 20; i++) {
for(int i = 0; i < 5; i++) {
shared_ptr<Map> map = make_map();
auto wall_copy = map->walls();

Loading…
Cancel
Save