|
|
|
@ -3,6 +3,48 @@ |
|
|
|
|
#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::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() { |
|
|
|
@ -10,6 +52,28 @@ int main() { |
|
|
|
|
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(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|