|
|
@ -5,25 +5,80 @@ |
|
|
|
#include <deque> |
|
|
|
#include <deque> |
|
|
|
#include <iostream> |
|
|
|
#include <iostream> |
|
|
|
#include <nlohmann/json.hpp> |
|
|
|
#include <nlohmann/json.hpp> |
|
|
|
|
|
|
|
#include "dbc.hpp" |
|
|
|
|
|
|
|
#include <memory> |
|
|
|
|
|
|
|
|
|
|
|
constexpr const int WINDOW_WIDTH=1280; |
|
|
|
constexpr const int WINDOW_WIDTH=1280; |
|
|
|
constexpr const int WINDOW_HEIGHT=720; |
|
|
|
constexpr const int WINDOW_HEIGHT=720; |
|
|
|
constexpr const int FRAME_LIMIT=60; |
|
|
|
constexpr const int FRAME_LIMIT=60; |
|
|
|
constexpr const bool VSYNC=true; |
|
|
|
constexpr const bool VSYNC=true; |
|
|
|
|
|
|
|
|
|
|
|
using std::string, std::wstring; |
|
|
|
using std::string, std::wstring, std::shared_ptr, std::make_shared; |
|
|
|
using nlohmann::json; |
|
|
|
using nlohmann::json; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct Slide { |
|
|
|
|
|
|
|
guecs::UI $gui; |
|
|
|
|
|
|
|
wstring $title; |
|
|
|
|
|
|
|
wstring $content; |
|
|
|
|
|
|
|
bool $initialized = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Slide(const string& title, const string& content) : |
|
|
|
|
|
|
|
$title(guecs::to_wstring(title)), |
|
|
|
|
|
|
|
$content(guecs::to_wstring(content)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void init(lel::Cell& cell) { |
|
|
|
|
|
|
|
if(!$initialized) { |
|
|
|
|
|
|
|
$initialized = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$gui.position(cell.x, cell.y, cell.w, cell.h); |
|
|
|
|
|
|
|
$gui.layout( |
|
|
|
|
|
|
|
"[=*%(300,200)title|_|_]" |
|
|
|
|
|
|
|
"[_|_|_]" |
|
|
|
|
|
|
|
"[=*%(300,300)content|_|_]" |
|
|
|
|
|
|
|
"[_|_|_]" |
|
|
|
|
|
|
|
"[_|_|_]"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto title = $gui.entity("title"); |
|
|
|
|
|
|
|
$gui.set<guecs::Text>(title, { |
|
|
|
|
|
|
|
$title, 124}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto content = $gui.entity("content"); |
|
|
|
|
|
|
|
$gui.set<guecs::Text>(content, { |
|
|
|
|
|
|
|
$content, |
|
|
|
|
|
|
|
56, guecs::THEME.TEXT_COLOR, 20}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$gui.init(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void render(sf::RenderWindow& window) { |
|
|
|
|
|
|
|
$gui.render(window); |
|
|
|
|
|
|
|
// $gui.debug_layout(window);
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using SlideDeck = std::vector<Slide>; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct SlidesUI { |
|
|
|
struct SlidesUI { |
|
|
|
guecs::UI $gui; |
|
|
|
guecs::UI $gui; |
|
|
|
|
|
|
|
shared_ptr<SlideDeck> $slides = nullptr; |
|
|
|
|
|
|
|
size_t $current = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SlidesUI(shared_ptr<SlideDeck> slides) { |
|
|
|
|
|
|
|
dbc::check(slides != nullptr, "slides is null"); |
|
|
|
|
|
|
|
dbc::check(slides->size() > 0, "slide deck is empy"); |
|
|
|
|
|
|
|
$slides = slides; |
|
|
|
|
|
|
|
$current = 0; |
|
|
|
|
|
|
|
|
|
|
|
SlidesUI() { |
|
|
|
|
|
|
|
$gui.position(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT); |
|
|
|
$gui.position(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT); |
|
|
|
$gui.layout( |
|
|
|
$gui.layout( |
|
|
|
"[t_left|t_center|t_right]" |
|
|
|
"[t_left|t_center|t_right]" |
|
|
|
"[m_left|*%(300,200)title|_|_|m_right]" |
|
|
|
"[m_left|*%(300,400)slide|_|_|m_right]" |
|
|
|
|
|
|
|
"[_|_|_|_|_]" |
|
|
|
"[_|_|_|_|_]" |
|
|
|
"[_|_|_|_|_]" |
|
|
|
"[_|*%(300,300)content|_|_|_]" |
|
|
|
|
|
|
|
"[_|_|_|_|_]" |
|
|
|
"[_|_|_|_|_]" |
|
|
|
"[_|_|_|_|_]" |
|
|
|
"[_|_|_|_|_]" |
|
|
|
"[b_left|b_center|b_right]" |
|
|
|
"[b_left|b_center|b_right]" |
|
|
@ -35,37 +90,66 @@ struct SlidesUI { |
|
|
|
bg.set_color(guecs::THEME.BG_COLOR_DARK); |
|
|
|
bg.set_color(guecs::THEME.BG_COLOR_DARK); |
|
|
|
$gui.set<guecs::Background>($gui.MAIN, bg); |
|
|
|
$gui.set<guecs::Background>($gui.MAIN, bg); |
|
|
|
|
|
|
|
|
|
|
|
auto title = $gui.entity("title"); |
|
|
|
show_slide(); |
|
|
|
$gui.set<guecs::Text>(title, { |
|
|
|
|
|
|
|
L"Title Thing\n", 124}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto content = $gui.entity("content"); |
|
|
|
|
|
|
|
$gui.set<guecs::Text>(content, { |
|
|
|
|
|
|
|
L"* Sample 2\n" |
|
|
|
|
|
|
|
L"* Sample 3\n", |
|
|
|
|
|
|
|
56, guecs::THEME.TEXT_COLOR, 20}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$gui.init(); |
|
|
|
$gui.init(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void set_data(json& data) { |
|
|
|
Slide& current() { |
|
|
|
(void)data; |
|
|
|
return $slides->at($current); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void next_slide() { |
|
|
|
|
|
|
|
if($current < $slides->size() - 1) { |
|
|
|
|
|
|
|
$current++; |
|
|
|
|
|
|
|
show_slide(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void prev_slide() { |
|
|
|
|
|
|
|
if($current > 0) { |
|
|
|
|
|
|
|
$current--; |
|
|
|
|
|
|
|
show_slide(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void show_slide() { |
|
|
|
|
|
|
|
auto& slide = current(); |
|
|
|
|
|
|
|
auto& cell = $gui.cell_for("slide"); |
|
|
|
|
|
|
|
slide.init(cell); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void render(sf::RenderWindow& window) { |
|
|
|
void render(sf::RenderWindow& window) { |
|
|
|
$gui.render(window); |
|
|
|
$gui.render(window); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto& slide = current(); |
|
|
|
|
|
|
|
slide.render(window); |
|
|
|
|
|
|
|
|
|
|
|
// $gui.debug_layout(window);
|
|
|
|
// $gui.debug_layout(window);
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void mouse(float x, float y, guecs::Modifiers mods) { |
|
|
|
void mouse(float x, float y, guecs::Modifiers mods) { |
|
|
|
$gui.mouse(x, y, mods); |
|
|
|
$gui.mouse(x, y, mods); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(mods.test(guecs::ModBit::left)) { |
|
|
|
|
|
|
|
next_slide(); |
|
|
|
|
|
|
|
} else if(mods.test(guecs::ModBit::right)) { |
|
|
|
|
|
|
|
prev_slide(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
json parse_slides(const std::string& md_file) { |
|
|
|
shared_ptr<SlideDeck> parse_slides(const string& md_file) { |
|
|
|
|
|
|
|
shared_ptr<SlideDeck> slides = make_shared<SlideDeck>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < 10; i++) { |
|
|
|
|
|
|
|
slides->emplace_back(fmt::format("Title {}", i),"content"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
(void)md_file; |
|
|
|
(void)md_file; |
|
|
|
return {}; |
|
|
|
|
|
|
|
|
|
|
|
return slides; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int main() { |
|
|
|
int main() { |
|
|
@ -77,9 +161,8 @@ int main() { |
|
|
|
window.setVerticalSyncEnabled(VSYNC); |
|
|
|
window.setVerticalSyncEnabled(VSYNC); |
|
|
|
|
|
|
|
|
|
|
|
auto data = parse_slides("some_bullshit.md"); |
|
|
|
auto data = parse_slides("some_bullshit.md"); |
|
|
|
SlidesUI slides; |
|
|
|
SlidesUI slides(data); |
|
|
|
slides.init(); |
|
|
|
slides.init(); |
|
|
|
slides.set_data(data); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while(window.isOpen()) { |
|
|
|
while(window.isOpen()) { |
|
|
|
while (const auto event = window.pollEvent()) { |
|
|
|
while (const auto event = window.pollEvent()) { |
|
|
@ -88,9 +171,12 @@ int main() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(const auto* mouse = event->getIf<sf::Event::MouseButtonPressed>()) { |
|
|
|
if(const auto* mouse = event->getIf<sf::Event::MouseButtonPressed>()) { |
|
|
|
if(mouse->button == sf::Mouse::Button::Left) { |
|
|
|
|
|
|
|
sf::Vector2f pos = window.mapPixelToCoords(mouse->position); |
|
|
|
sf::Vector2f pos = window.mapPixelToCoords(mouse->position); |
|
|
|
slides.mouse(pos.x, pos.y, {}); |
|
|
|
|
|
|
|
|
|
|
|
if(mouse->button == sf::Mouse::Button::Left) { |
|
|
|
|
|
|
|
slides.mouse(pos.x, pos.y, {1 << guecs::ModBit::left}); |
|
|
|
|
|
|
|
} else if(mouse->button == sf::Mouse::Button::Right) { |
|
|
|
|
|
|
|
slides.mouse(pos.x, pos.y, {1 << guecs::ModBit::right}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|