66 lines
1.5 KiB
C++
66 lines
1.5 KiB
C++
/*
|
|
* Copyright 2016 - 2021 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
|
*/
|
|
|
|
#include <ox/std/trace.hpp>
|
|
|
|
#include <nostalgia/core/core.hpp>
|
|
|
|
#include "studioapp.hpp"
|
|
|
|
namespace nostalgia {
|
|
|
|
class StudioUIDrawer: public core::Drawer {
|
|
private:
|
|
StudioUI *m_ui = nullptr;
|
|
public:
|
|
explicit StudioUIDrawer(StudioUI *ui) noexcept: m_ui(ui) {
|
|
}
|
|
protected:
|
|
void draw(core::Context*) noexcept final {
|
|
m_ui->draw();
|
|
}
|
|
};
|
|
|
|
static int eventHandler(core::Context *ctx) noexcept {
|
|
auto ui = ctx->customData<StudioUI>();
|
|
ui->update();
|
|
return 16;
|
|
}
|
|
|
|
static ox::Error run(ox::UniquePtr<ox::FileSystem> fs) noexcept {
|
|
oxRequireM(ctx, core::init(std::move(fs), "NostalgiaStudio"));
|
|
core::setWindowTitle(ctx.get(), "Nostalgia Studio");
|
|
core::setEventHandler(ctx.get(), eventHandler);
|
|
ox::UniquePtr<StudioUI> ui;
|
|
try {
|
|
ui = ox::make_unique<StudioUI>(ctx.get());
|
|
} catch (ox::Exception &ex) {
|
|
return ex.toError();
|
|
}
|
|
StudioUIDrawer drawer(ui.get());
|
|
ctx->setCustomData(ui.get());
|
|
ctx->drawers.emplace_back(&drawer);
|
|
return core::run(ctx.get());
|
|
}
|
|
|
|
static ox::Error run(int argc, const char **argv) noexcept {
|
|
ox::trace::init();
|
|
if (argc >= 2) {
|
|
const auto path = argv[1];
|
|
oxRequireM(fs, core::loadRomFs(path));
|
|
return run(std::move(fs));
|
|
} else {
|
|
return run(ox::UniquePtr<ox::FileSystem>(nullptr));
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
int main(int argc, const char **argv) {
|
|
ox::trace::init();
|
|
const auto err = nostalgia::run(argc, argv);
|
|
oxAssert(err, "Something went wrong...");
|
|
return static_cast<int>(err);
|
|
}
|