|
|
|
|
#include "guecs/sfml/components.hpp"
|
|
|
|
|
#include "guecs/ui.hpp"
|
|
|
|
|
#include <fmt/xchar.h>
|
|
|
|
|
#include <deque>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
|
#include "dbc.hpp"
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <filesystem>
|
|
|
|
|
#include <fstream>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include "constants.hpp"
|
|
|
|
|
#include "control_ui.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ControlUI::ControlUI(sf::RenderWindow& presenter, sf::RenderWindow& controller) :
|
|
|
|
|
$presenter(presenter),
|
|
|
|
|
$controller(controller),
|
|
|
|
|
$window_size($presenter.getSize())
|
|
|
|
|
{
|
|
|
|
|
$gui.position(0, 0, CONTROL_WIDTH, CONTROL_HEIGHT);
|
|
|
|
|
$gui.layout(
|
|
|
|
|
"[status|=%(100,100)current]"
|
|
|
|
|
"[docs|=%(100,100)next]"
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ControlUI::config_views(guecs::Entity current, guecs::Entity next) {
|
|
|
|
|
// BUG jank ass bullshit, fix this in lel-guecs
|
|
|
|
|
auto& cur_cell = $gui.cell_for(current);
|
|
|
|
|
$cur_view = std::make_shared<sf::RenderTexture>($presenter.getSize());
|
|
|
|
|
$cur_sprite = std::make_shared<sf::Sprite>($cur_view->getTexture());
|
|
|
|
|
$cur_sprite->setPosition({float(cur_cell.x), float(cur_cell.y)});
|
|
|
|
|
$cur_sprite->setScale({0.3f, 0.3f});
|
|
|
|
|
|
|
|
|
|
auto& next_cell = $gui.cell_for(next);
|
|
|
|
|
$next_view = std::make_shared<sf::RenderTexture>($presenter.getSize());
|
|
|
|
|
$next_sprite = std::make_shared<sf::Sprite>($next_view->getTexture());
|
|
|
|
|
$next_sprite->setPosition({float(next_cell.x), float(next_cell.y)});
|
|
|
|
|
$next_sprite->setScale({0.3f, 0.3f});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ControlUI::init() {
|
|
|
|
|
auto status_id = $gui.entity("status");
|
|
|
|
|
$gui.set<guecs::Text>(status_id, {L""});
|
|
|
|
|
|
|
|
|
|
auto docs_id = $gui.entity("docs");
|
|
|
|
|
$gui.set<guecs::Text>(docs_id, {L"F: fullscreen\nA: win left\nD: win right\nQ: quit"});
|
|
|
|
|
$gui.init();
|
|
|
|
|
|
|
|
|
|
auto current = $gui.entity("current");
|
|
|
|
|
auto next = $gui.entity("next");
|
|
|
|
|
|
|
|
|
|
config_views(current, next);
|
|
|
|
|
|
|
|
|
|
// warning! must come after init so the thing is there
|
|
|
|
|
$status = $gui.get_if<guecs::Text>(status_id);
|
|
|
|
|
dbc::check($status != nullptr, "failed to setup the status text");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline void render_slide(sf::RenderTexture& view, Slide& slide) {
|
|
|
|
|
view.clear();
|
|
|
|
|
slide.render(view);
|
|
|
|
|
view.display();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ControlUI::render(sf::RenderWindow& window, SlideDeck& deck) {
|
|
|
|
|
dbc::check($status != nullptr, "called render before init?");
|
|
|
|
|
|
|
|
|
|
auto pos = $presenter.getPosition();
|
|
|
|
|
auto size = $presenter.getSize();
|
|
|
|
|
|
|
|
|
|
$status->update(fmt::format(L"pos={},{}\nsize={},{}",
|
|
|
|
|
pos.x, pos.y, size.x, size.y));
|
|
|
|
|
|
|
|
|
|
window.clear();
|
|
|
|
|
$gui.render(window);
|
|
|
|
|
|
|
|
|
|
render_slide(*$cur_view, deck.current_slide());
|
|
|
|
|
window.draw(*$cur_sprite);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
render_slide(*$next_view, deck.preview_slide());
|
|
|
|
|
window.draw(*$next_sprite);
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ControlUI::handle_events(std::shared_ptr<SlidesUI> slides, const sf::Event& event) {
|
|
|
|
|
dbc::check($status != nullptr, "handle_events called before init?!");
|
|
|
|
|
|
|
|
|
|
if(event.is<sf::Event::Closed>()) {
|
|
|
|
|
$controller.close();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(const auto* key = event.getIf<sf::Event::KeyPressed>()) {
|
|
|
|
|
auto pos = $presenter.getPosition();
|
|
|
|
|
|
|
|
|
|
using KEY = sf::Keyboard::Scan;
|
|
|
|
|
switch(key->scancode) {
|
|
|
|
|
case KEY::A: {
|
|
|
|
|
pos.x -= $window_size.x;
|
|
|
|
|
$presenter.setPosition(pos);
|
|
|
|
|
} break;
|
|
|
|
|
case KEY::D: {
|
|
|
|
|
pos.x += int($window_size.x);
|
|
|
|
|
$presenter.setPosition(pos);
|
|
|
|
|
} break;
|
|
|
|
|
case KEY::Q:
|
|
|
|
|
$controller.close();
|
|
|
|
|
break;
|
|
|
|
|
case KEY::F:
|
|
|
|
|
if($full_screen) {
|
|
|
|
|
$presenter.setSize({$window_size.x/2, $window_size.y/2});
|
|
|
|
|
$presenter.setMouseCursorVisible(true);
|
|
|
|
|
} else {
|
|
|
|
|
$presenter.setSize($window_size);
|
|
|
|
|
$presenter.setMouseCursorVisible(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$full_screen = !$full_screen;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
slides->handle_events($controller, event);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|