/* * Copyright 2016 - 2021 Gary Talent (gary@drinkingtea.net). All rights reserved. */ #include #include #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(); ui->update(); return 16; } static ox::Error run(ox::UniquePtr fs) noexcept { oxRequireM(ctx, core::init(std::move(fs), "NostalgiaStudio")); core::setWindowTitle(ctx.get(), "Nostalgia Studio"); core::setEventHandler(ctx.get(), eventHandler); ox::UniquePtr ui; try { ui = ox::make_unique(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(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(err); }