Now using a simple text size grid system for laying out the GUI.
This commit is contained in:
parent
fda281be1d
commit
58a5a415ec
2 changed files with 37 additions and 15 deletions
|
@ -7,6 +7,9 @@
|
||||||
constexpr int FPS=30;
|
constexpr int FPS=30;
|
||||||
constexpr int X_DIM = 1920 / 2;
|
constexpr int X_DIM = 1920 / 2;
|
||||||
constexpr int Y_DIM = 1080 / 2;
|
constexpr int Y_DIM = 1080 / 2;
|
||||||
|
constexpr int TEXT_SIZE = 48;
|
||||||
|
constexpr int Y_LINES = 23;
|
||||||
|
constexpr int X_ROWS = 48;
|
||||||
|
|
||||||
class SFMLGui {
|
class SFMLGui {
|
||||||
sf::ContextSettings settings;
|
sf::ContextSettings settings;
|
||||||
|
@ -31,7 +34,7 @@ public:
|
||||||
void handle_events();
|
void handle_events();
|
||||||
void update_entities();
|
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_setup();
|
||||||
void ImGui_update();
|
void ImGui_update();
|
||||||
|
|
47
sfmltest.cpp
47
sfmltest.cpp
|
@ -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) {
|
sf::Vector2f position{step_x * x, step_y * y * 2};
|
||||||
// hp text
|
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SFMLGui::write_text(int x, int y, const char *content) {
|
||||||
|
sf::Vector2f position = translate(x,y);
|
||||||
sf::Text text;
|
sf::Text text;
|
||||||
text.setFont(font);
|
text.setFont(font);
|
||||||
text.setString(content);
|
text.setString(content);
|
||||||
text.setCharacterSize(48);
|
text.setCharacterSize(TEXT_SIZE);
|
||||||
text.setFillColor(sf::Color(100, 250, 50));
|
text.setFillColor(sf::Color(100, 250, 50));
|
||||||
text.setPosition(position);
|
text.setPosition(position);
|
||||||
window.draw(text);
|
window.draw(text);
|
||||||
|
@ -91,22 +100,32 @@ void SFMLGui::write_text(sf::Vector2f position, const char *content) {
|
||||||
void SFMLGui::update_entities() {
|
void SFMLGui::update_entities() {
|
||||||
window.clear();
|
window.clear();
|
||||||
|
|
||||||
background.setPosition(0, 0);
|
sf::RectangleShape face_box(translate(X_ROWS/4, Y_LINES/2));
|
||||||
window.draw(background);
|
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});
|
sf::RectangleShape hp_bar(translate(32,2));
|
||||||
hp_bar.setPosition({18, 434});
|
hp_bar.setPosition(translate(2,21));
|
||||||
hp_bar.setFillColor(sf::Color(100, 250, 50));
|
hp_bar.setFillColor(sf::Color(100, 250, 50));
|
||||||
window.draw(hp_bar);
|
window.draw(hp_bar);
|
||||||
|
|
||||||
// hp text
|
sf::RectangleShape hp_box(translate(44,2));
|
||||||
write_text({60, 363}, "100");
|
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
|
// rounds text
|
||||||
write_text({305, 363}, "222");
|
write_text(9, 18, "Rounds 333");
|
||||||
// streaks text
|
// // streaks text
|
||||||
write_text({540, 363}, "333");
|
write_text(21, 18, "Streaks 444");
|
||||||
// deaths text
|
// // deaths text
|
||||||
write_text({757, 363}, "444");
|
write_text(33, 18, "Deaths 555");
|
||||||
|
|
||||||
if(show_build_log) {
|
if(show_build_log) {
|
||||||
ImGui_update();
|
ImGui_update();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue