A chip8 emulator for learning old school assembly language game dev.
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.
 
 
 
 
 
 
b8rk/src/control_panel.cpp

69 lines
1.4 KiB

#include "control_panel.hpp"
#include <fmt/xchar.h>
#include "constants.hpp"
ControlPanel::ControlPanel() {
}
void ControlPanel::init(sf::Vector2f size) {
$gui.position(0, size.y, size.x, WINDOW_HEIGHT - size.y);
$gui.layout(
"[Pause |*%(200, 400)code|_]"
"[Step |_|_]"
"[Play |_|_]"
"[Restart|_|_]"
);
for(auto& [name, cell] : $gui.cells()) {
auto id = $gui.entity(name);
$gui.set<guecs::Rectangle>(id, {});
$gui.set<guecs::Text>(id, {guecs::to_wstring(name)});
}
auto id = $gui.entity("Pause");
$gui.set<guecs::Clickable>(id, {[&](auto) {
$paused = true;
}});
id = $gui.entity("Step");
$gui.set<guecs::Clickable>(id, {[&](auto) {
$step = true;
}});
id = $gui.entity("Play");
$gui.set<guecs::Clickable>(id, {[&](auto) {
$paused = false;
}});
id = $gui.entity("Restart");
$gui.set<guecs::Clickable>(id, {[&](auto) {
$restart = true;
}});
$gui.init();
}
void ControlPanel::render(sf::RenderTarget& window) {
$gui.render(window);
}
void ControlPanel::update(Chip8& vm) {
if($restart) {
vm.needs_restart = true;
$restart = false;
return;
}
vm.paused = $paused;
if($step && $paused) {
vm.Cycle();
vm.needs_render = true;
}
$step = false;
}
bool ControlPanel::mouse(float x, float y, guecs::Modifiers mods) {
return $gui.mouse(x, y, mods);
}