|
|
|
@ -12,8 +12,10 @@ |
|
|
|
#include "constants.hpp" |
|
|
|
#include "constants.hpp" |
|
|
|
#include "control_ui.hpp" |
|
|
|
#include "control_ui.hpp" |
|
|
|
|
|
|
|
|
|
|
|
ControlUI::ControlUI(sf::RenderWindow& presenter) : |
|
|
|
|
|
|
|
|
|
|
|
ControlUI::ControlUI(sf::RenderWindow& presenter, sf::RenderWindow& controller) : |
|
|
|
$presenter(presenter), |
|
|
|
$presenter(presenter), |
|
|
|
|
|
|
|
$controller(controller), |
|
|
|
$window_size($presenter.getSize()) |
|
|
|
$window_size($presenter.getSize()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$gui.position(0, 0, CONTROL_WIDTH, CONTROL_HEIGHT); |
|
|
|
$gui.position(0, 0, CONTROL_WIDTH, CONTROL_HEIGHT); |
|
|
|
@ -23,29 +25,46 @@ ControlUI::ControlUI(sf::RenderWindow& presenter) : |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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() { |
|
|
|
void ControlUI::init() { |
|
|
|
auto status_id = $gui.entity("status"); |
|
|
|
auto status_id = $gui.entity("status"); |
|
|
|
$gui.set<guecs::Text>(status_id, {L""}); |
|
|
|
$gui.set<guecs::Text>(status_id, {L""}); |
|
|
|
|
|
|
|
|
|
|
|
auto docs_id = $gui.entity("docs"); |
|
|
|
auto docs_id = $gui.entity("docs"); |
|
|
|
$gui.set<guecs::Text>(docs_id, {L"F: fullscreen\nA: win left\nD: win right\nQ: quit"}); |
|
|
|
$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 current = $gui.entity("current"); |
|
|
|
$gui.set<guecs::Rectangle>(current, {}); |
|
|
|
|
|
|
|
$gui.set<guecs::Text>(current, {L"Current Slide"}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto next = $gui.entity("next"); |
|
|
|
auto next = $gui.entity("next"); |
|
|
|
$gui.set<guecs::Rectangle>(next, {}); |
|
|
|
|
|
|
|
$gui.set<guecs::Text>(next, {L"Next Slide"}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$gui.init(); |
|
|
|
config_views(current, next); |
|
|
|
|
|
|
|
|
|
|
|
// warning! must come after init so the thing is there
|
|
|
|
// warning! must come after init so the thing is there
|
|
|
|
$status = $gui.get_if<guecs::Text>(status_id); |
|
|
|
$status = $gui.get_if<guecs::Text>(status_id); |
|
|
|
dbc::check($status != nullptr, "failed to setup the status text"); |
|
|
|
dbc::check($status != nullptr, "failed to setup the status text"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void ControlUI::render(sf::RenderWindow& window) { |
|
|
|
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?"); |
|
|
|
dbc::check($status != nullptr, "called render before init?"); |
|
|
|
|
|
|
|
|
|
|
|
auto pos = $presenter.getPosition(); |
|
|
|
auto pos = $presenter.getPosition(); |
|
|
|
@ -53,16 +72,24 @@ void ControlUI::render(sf::RenderWindow& window) { |
|
|
|
|
|
|
|
|
|
|
|
$status->update(fmt::format(L"pos={},{}\nsize={},{}", |
|
|
|
$status->update(fmt::format(L"pos={},{}\nsize={},{}", |
|
|
|
pos.x, pos.y, size.x, size.y)); |
|
|
|
pos.x, pos.y, size.x, size.y)); |
|
|
|
window.clear(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
window.clear(); |
|
|
|
$gui.render(window); |
|
|
|
$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(sf::RenderWindow& controller, const sf::Event& event) { |
|
|
|
void ControlUI::handle_events(std::shared_ptr<SlidesUI> slides, const sf::Event& event) { |
|
|
|
dbc::check($status != nullptr, "handle_events called before init?!"); |
|
|
|
dbc::check($status != nullptr, "handle_events called before init?!"); |
|
|
|
|
|
|
|
|
|
|
|
if(event.is<sf::Event::Closed>()) { |
|
|
|
if(event.is<sf::Event::Closed>()) { |
|
|
|
controller.close(); |
|
|
|
$controller.close(); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -80,19 +107,21 @@ void ControlUI::handle_events(sf::RenderWindow& controller, const sf::Event& eve |
|
|
|
$presenter.setPosition(pos); |
|
|
|
$presenter.setPosition(pos); |
|
|
|
} break; |
|
|
|
} break; |
|
|
|
case KEY::Q: |
|
|
|
case KEY::Q: |
|
|
|
controller.close(); |
|
|
|
$controller.close(); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case KEY::F: |
|
|
|
case KEY::F: |
|
|
|
if($full_screen) { |
|
|
|
if($full_screen) { |
|
|
|
$presenter.setSize({$window_size.x/2, $window_size.y/2}); |
|
|
|
$presenter.setSize({$window_size.x/2, $window_size.y/2}); |
|
|
|
|
|
|
|
$presenter.setMouseCursorVisible(true); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
$presenter.setSize($window_size); |
|
|
|
$presenter.setSize($window_size); |
|
|
|
|
|
|
|
$presenter.setMouseCursorVisible(false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$full_screen = !$full_screen; |
|
|
|
$full_screen = !$full_screen; |
|
|
|
break; |
|
|
|
break; |
|
|
|
default: |
|
|
|
default: |
|
|
|
break; |
|
|
|
slides->handle_events($controller, event); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|