Now using a simple text size grid system for laying out the GUI.

master
Zed A. Shaw 3 months ago
parent fda281be1d
commit 58a5a415ec
  1. 5
      sfmlgui.hpp
  2. 47
      sfmltest.cpp

@ -7,6 +7,9 @@
constexpr int FPS=30;
constexpr int X_DIM = 1920 / 2;
constexpr int Y_DIM = 1080 / 2;
constexpr int TEXT_SIZE = 48;
constexpr int Y_LINES = 23;
constexpr int X_ROWS = 48;
class SFMLGui {
sf::ContextSettings settings;
@ -31,7 +34,7 @@ public:
void handle_events();
void update_entities();
void write_text(sf::Vector2f position, const char *content);
void write_text(int x, int y, const char *content);
void ImGui_setup();
void ImGui_update();

@ -76,13 +76,22 @@ void SFMLGui::handle_events() {
}
}
sf::Vector2f translate(int x, int y) {
float step_x = X_DIM / TEXT_SIZE;
float step_y = (Y_DIM - 12) / TEXT_SIZE;
void SFMLGui::write_text(sf::Vector2f position, const char *content) {
// hp text
sf::Vector2f position{step_x * x, step_y * y * 2};
return position;
}
void SFMLGui::write_text(int x, int y, const char *content) {
sf::Vector2f position = translate(x,y);
sf::Text text;
text.setFont(font);
text.setString(content);
text.setCharacterSize(48);
text.setCharacterSize(TEXT_SIZE);
text.setFillColor(sf::Color(100, 250, 50));
text.setPosition(position);
window.draw(text);
@ -91,22 +100,32 @@ void SFMLGui::write_text(sf::Vector2f position, const char *content) {
void SFMLGui::update_entities() {
window.clear();
background.setPosition(0, 0);
window.draw(background);
sf::RectangleShape face_box(translate(X_ROWS/4, Y_LINES/2));
face_box.setPosition(translate(X_ROWS/3+2,2));
face_box.setOutlineColor(sf::Color(50, 200, 25));
face_box.setOutlineThickness(10);
face_box.setFillColor(sf::Color(200, 250, 200));
window.draw(face_box);
sf::RectangleShape hp_bar({1920/2 - 18*2, 45.0f});
hp_bar.setPosition({18, 434});
sf::RectangleShape hp_bar(translate(32,2));
hp_bar.setPosition(translate(2,21));
hp_bar.setFillColor(sf::Color(100, 250, 50));
window.draw(hp_bar);
// hp text
write_text({60, 363}, "100");
sf::RectangleShape hp_box(translate(44,2));
hp_box.setPosition(translate(2,21));
hp_box.setOutlineColor(sf::Color(100, 200, 50));
hp_box.setOutlineThickness(10);
hp_box.setFillColor(sf::Color::Transparent);
window.draw(hp_box);
write_text(2, 18, "HP 222");
// rounds text
write_text({305, 363}, "222");
// streaks text
write_text({540, 363}, "333");
// deaths text
write_text({757, 363}, "444");
write_text(9, 18, "Rounds 333");
// // streaks text
write_text(21, 18, "Streaks 444");
// // deaths text
write_text(33, 18, "Deaths 555");
if(show_build_log) {
ImGui_update();

Loading…
Cancel
Save