diff --git a/src/control_panel.cpp b/src/control_panel.cpp index a243553..4ee6851 100644 --- a/src/control_panel.cpp +++ b/src/control_panel.cpp @@ -7,12 +7,22 @@ ControlPanel::ControlPanel() { void ControlPanel::init(sf::Vector2f size) { $gui.position(0, size.y, size.x, WINDOW_HEIGHT - size.y); - $gui.layout("[buttons|code]"); + $gui.layout( + "[pause |*%(200, 400)code|_]" + "[step |_|_]" + "[play |_|_]" + "[restart|_|_]" + ); for(auto& [name, cell] : $gui.cells()) { auto id = $gui.entity(name); $gui.set(id, {}); $gui.set(id, {guecs::to_wstring(name)}); + if(name != "code") { + $gui.set(id, {[name](auto) { + fmt::println("CLICKED {}", name); + }}); + } } $gui.init(); @@ -24,3 +34,7 @@ void ControlPanel::render(sf::RenderTarget& window) { void ControlPanel::update(Chip8& vm) { } + +bool ControlPanel::mouse(float x, float y, guecs::Modifiers mods) { + return $gui.mouse(x, y, mods); +} diff --git a/src/control_panel.hpp b/src/control_panel.hpp index 86931ef..9cbeb97 100644 --- a/src/control_panel.hpp +++ b/src/control_panel.hpp @@ -12,4 +12,5 @@ struct ControlPanel { void init(sf::Vector2f size); void render(sf::RenderTarget& window); void update(Chip8& vm); + bool mouse(float x, float y, guecs::Modifiers mods); }; diff --git a/src/display.cpp b/src/display.cpp index 359a532..440b3d2 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -42,6 +42,10 @@ void Display::handle_inputs(Chip8& vm) { } else if(const auto* key = event->getIf()) { vm.handle_keyboard(key->scancode, false); } + + if(const auto* ev = event->getIf()) { + $control.mouse(ev->position.x, ev->position.y, {1 << guecs::ModBit::left}); + } } }