Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Filesystem Header and Add Centered "Hello SFML" Text #2

Merged
merged 15 commits into from
Jan 22, 2024
Merged
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,11 @@ Note: If you've already cloned this repo without using `--recursive` flag, just
```

- You should find the executables under `build/bin`

## License

This project is released under MIT license. See [LICENSE.md](LICENSE.md) for details. Note that this does not cover any of the submodules located under [vendor](vendors/) and assets located under [resources](resources/).

- [sfml](vendors/sfml/) is covered under [Zlib](vendors/sfml/license.md) license.

- [FiraCode-Regular.ttf](resourcs/FiraCode-Regular.ttf) is covered under [OFL-1.1](https://github.com/tonsky/FiraCode/blob/master/LICENSE) license.
Binary file added resources/FiraCode-Regular.ttf
Binary file not shown.
Binary file removed resources/sfml-project-template.png
Binary file not shown.
51 changes: 43 additions & 8 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
#include <SFML/Graphics.hpp>
#include <filesystem>
#include <iostream>
#include "Version.hpp"

static void modifyCurrentWorkingDirectory();
static void setupVersionTexts(sf::RenderWindow &window, sf::Font &font, sf::Text &templateVersion, sf::Text &sfmlVersion);

int main()
{
modifyCurrentWorkingDirectory();

const auto clearColor = sf::Color(234, 240, 206);
auto title = "Template-" + GetTemplateVersion() + "/SFML-" + GetSFMLVersion();
sf::RenderWindow window(sf::VideoMode(640, 360), title, sf::Style::Close);

sf::Texture texture;
sf::Sprite sprite;
sf::Font font;
sf::Text sfmlVersion;
sf::Text templateVersion;

if (texture.loadFromFile("resources/sfml-project-template.png"))
if (font.loadFromFile("resources/FiraCode-Regular.ttf"))
{
sprite.setTexture(texture);
sprite.setOrigin({(float)texture.getSize().x / 2, (float)texture.getSize().y / 2});
sprite.setPosition((float)window.getSize().x / 2, (float)window.getSize().y / 2);
setupVersionTexts(window, font, templateVersion, sfmlVersion);
}

while (window.isOpen())
Expand All @@ -31,14 +34,46 @@ int main()
}
}

window.clear();
window.draw(sprite);
window.clear(clearColor);
window.draw(templateVersion);
window.draw(sfmlVersion);
window.display();
}

return 0;
}

void setupVersionTexts(sf::RenderWindow &window, sf::Font &font, sf::Text &templateVersion, sf::Text &sfmlVersion)
{
auto windowCenter = sf::Vector2f(window.getSize().x * 0.5f, window.getSize().y * 0.5f);
const auto characterSize = 65;
const auto outlineThickness = 4.f;
const auto fillColor = sf::Color(63, 51, 77);
const auto outlineColor = sf::Color(192, 197, 193);

templateVersion.setFont(font);
templateVersion.setString("Template-v" + GetTemplateVersion());
templateVersion.setCharacterSize(characterSize);
templateVersion.setFillColor(fillColor);
templateVersion.setOutlineColor(outlineColor);
templateVersion.setOutlineThickness(outlineThickness);

auto textRect = templateVersion.getLocalBounds();
templateVersion.setOrigin(textRect.left + textRect.width * 0.5f, textRect.top + textRect.height * 0.5f);
templateVersion.setPosition(windowCenter - sf::Vector2f(0.f, textRect.height));

sfmlVersion.setFont(font);
sfmlVersion.setString("SFML-v" + GetSFMLVersion());
sfmlVersion.setCharacterSize(characterSize);
sfmlVersion.setFillColor(fillColor);
sfmlVersion.setOutlineColor(outlineColor);
sfmlVersion.setOutlineThickness(outlineThickness);

textRect = sfmlVersion.getLocalBounds();
sfmlVersion.setOrigin(textRect.left + textRect.width * 0.5f, textRect.top + textRect.height * 0.5f);
sfmlVersion.setPosition(windowCenter + sf::Vector2f(0.f, textRect.height));
}

void modifyCurrentWorkingDirectory()
{
while (!std::filesystem::exists("resources"))
Expand Down