[nostalgia/studio] Start on ImGui version of Studio
This commit is contained in:
@@ -6,38 +6,59 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
#include <QQuickWindow>
|
||||
#include <ox/clargs/clargs.hpp>
|
||||
#include <ox/std/trace.hpp>
|
||||
#include <qdark/theme.hpp>
|
||||
#include "mainwindow.hpp"
|
||||
|
||||
using namespace nostalgia::studio;
|
||||
#include <nostalgia/core/core.hpp>
|
||||
|
||||
int main(int argc, char **args) {
|
||||
#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 *ctx) noexcept final {
|
||||
m_ui->draw(ctx);
|
||||
}
|
||||
};
|
||||
|
||||
static int eventHandler(core::Context *ctx) noexcept {
|
||||
auto ui = ctx->customData<StudioUI>();
|
||||
ui->update(ctx);
|
||||
return 16;
|
||||
}
|
||||
|
||||
static ox::Error run(ox::FileSystem *fs) noexcept {
|
||||
oxRequireM(ctx, core::init(fs));
|
||||
core::setWindowTitle(ctx.get(), "Nostalgia Studio");
|
||||
core::setEventHandler(ctx.get(), eventHandler);
|
||||
StudioUI ui;
|
||||
StudioUIDrawer drawer(&ui);
|
||||
ctx->setCustomData(&ui);
|
||||
ctx->drawers.emplace_back(&drawer);
|
||||
return core::run(ctx.get());
|
||||
}
|
||||
|
||||
static ox::Error run(int argc, const char **argv) noexcept {
|
||||
ox::trace::init();
|
||||
// get profile path from command args
|
||||
ox::ClArgs clargs(argc, const_cast<const char**>(args));
|
||||
QString argProfilePath = clargs.getString("profile", ":/profiles/nostalgia-studio.json").c_str();
|
||||
QApplication app(argc, args);
|
||||
// load theme
|
||||
if constexpr(ox::defines::OS != ox::defines::OS::Darwin) {
|
||||
qdark::load(&app);
|
||||
}
|
||||
// force QtQuick to use OpenGL (https://doc.qt.io/qt-6/quick-changes-qt6.html#changes-to-qquickwidget)
|
||||
#if QT_VERSION >= 0x060000
|
||||
QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGLRhi);
|
||||
#endif
|
||||
// open window
|
||||
try {
|
||||
MainWindow w(argProfilePath);
|
||||
app.setApplicationName(w.windowTitle());
|
||||
w.show();
|
||||
QObject::connect(&app, &QApplication::aboutToQuit, &w, &MainWindow::onExit);
|
||||
return app.exec();
|
||||
} catch (const ox::Error &err) {
|
||||
oxPanic(err, "Unhandled ox::Error");
|
||||
if (argc >= 2) {
|
||||
const auto path = argv[1];
|
||||
oxRequire(fs, core::loadRomFs(path));
|
||||
return run(fs.get());
|
||||
} else {
|
||||
return run(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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user