You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
1.9 KiB
80 lines
1.9 KiB
#include "sfml/components.hpp"
|
|
#include "sfml/sound.hpp"
|
|
#include "sfml/shaders.hpp"
|
|
#include "sfml/textures.hpp"
|
|
#include "guecs.hpp"
|
|
#include "constants.hpp"
|
|
|
|
constexpr const int WINDOW_WIDTH=300;
|
|
constexpr const int WINDOW_HEIGHT=400;
|
|
|
|
struct Calculator {
|
|
guecs::UI $gui;
|
|
|
|
Calculator() {
|
|
$gui.position(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
|
|
$gui.layout(
|
|
"[readout]"
|
|
"[btn7|btn8|btn9|mult]"
|
|
"[btn4|btn5|btn6|minus]"
|
|
"[btn1|btn2|btn3|plus]"
|
|
"[neg|btn0|dot|eq]");
|
|
}
|
|
|
|
void init() {
|
|
$gui.set<guecs::Background>($gui.MAIN, {});
|
|
|
|
for(auto& [name, cell] : $gui.cells()) {
|
|
auto id = $gui.entity(name);
|
|
$gui.set<guecs::Rectangle>(id, {});
|
|
$gui.set<guecs::Effect>(id, {});
|
|
$gui.set<guecs::Label>(id, {guecs::to_wstring(name)});
|
|
$gui.set<guecs::Clickable>(id, {
|
|
[=](auto, auto) { fmt::println("clicked {}", name); }
|
|
});
|
|
}
|
|
|
|
$gui.init();
|
|
}
|
|
|
|
void render(sf::RenderWindow& window) {
|
|
$gui.render(window);
|
|
// $gui.debug_layout(window);
|
|
}
|
|
|
|
void mouse(float x, float y, bool hover) {
|
|
$gui.mouse(x, y, hover);
|
|
}
|
|
};
|
|
|
|
|
|
int main() {
|
|
sound::init();
|
|
shaders::init();
|
|
textures::init();
|
|
|
|
sf::RenderWindow window(sf::VideoMode({WINDOW_WIDTH, WINDOW_HEIGHT}), "LEL-GUECS Calculator");
|
|
window.setFramerateLimit(FRAME_LIMIT);
|
|
window.setVerticalSyncEnabled(VSYNC);
|
|
|
|
Calculator calc;
|
|
calc.init();
|
|
|
|
while(window.isOpen()) {
|
|
while (const auto event = window.pollEvent()) {
|
|
if(event->is<sf::Event::Closed>()) {
|
|
window.close();
|
|
}
|
|
|
|
if(const auto* mouse = event->getIf<sf::Event::MouseButtonPressed>()) {
|
|
if(mouse->button == sf::Mouse::Button::Left) {
|
|
sf::Vector2f pos = window.mapPixelToCoords(mouse->position);
|
|
calc.mouse(pos.x, pos.y, false);
|
|
}
|
|
}
|
|
}
|
|
|
|
calc.render(window);
|
|
window.display();
|
|
}
|
|
}
|
|
|