#include "./main_screen.hpp" #include #include #include MainScreen::MainScreen(SDL_Renderer* renderer_, std::string save_path, std::string save_password, std::vector plugins) : renderer(renderer_), rmm(cr), mts(rmm), tc(save_path, save_password), tpi(tc.getTox()), ad(tc), tcm(cr, tc, tc), tmm(rmm, cr, tcm, tc, tc), ttm(rmm, cr, tcm, tc, tc), mmil(rmm), tam(rmm, cr, conf), sdlrtu(renderer_), cg(conf, rmm, cr, sdlrtu), sw(conf), tuiu(tc, conf), tdch(tpi) { tel.subscribeAll(tc); conf.set("tox", "save_file_path", save_path); { // name stuff auto name = tc.toxSelfGetName(); if (name.empty()) { name = "tomato"; } conf.set("tox", "name", name); tc.setSelfName(name); // TODO: this is ugly } // TODO: remove std::cout << "own address: " << tc.toxSelfGetAddressStr() << "\n"; { // setup plugin instances g_provideInstance("ConfigModelI", "host", &conf); g_provideInstance("Contact3Registry", "host", &cr); g_provideInstance("RegistryMessageModel", "host", &rmm); g_provideInstance("ToxI", "host", &tc); g_provideInstance("ToxPrivateI", "host", &tpi); g_provideInstance("ToxEventProviderI", "host", &tc); g_provideInstance("ToxContactModel2", "host", &tcm); // TODO: pm? // graphics g_provideInstance("ImGuiContext", "host", ImGui::GetCurrentContext()); g_provideInstance("TextureUploaderI", "host", &sdlrtu); } for (const auto& ppath : plugins) { if (!pm.add(ppath)) { std::cerr << "MS error: loading plugin '" << ppath << "' failed!\n"; // thow? assert(false && "failed to load plugin"); } } conf.dump(); } MainScreen::~MainScreen(void) { } bool MainScreen::handleEvent(SDL_Event& e) { if (e.type == SDL_EVENT_DROP_FILE) { std::cout << "DROP FILE: " << e.drop.file << "\n"; cg.sendFilePath(e.drop.file); return true; // TODO: forward return succ from sendFilePath() } return false; } Screen* MainScreen::render(float time_delta, bool& quit) { quit = !tc.iterate(); tcm.iterate(time_delta); tam.iterate(); // HACK: render the tomato main window first, with proper flags set. // flags need to be set the first time begin() is called. // and plugins are run before the main cg is run. { // TODO: maybe render cg earlier? or move the main window out of cg? constexpr auto bg_window_flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoBringToFrontOnFocus; ImGui::Begin("tomato", nullptr, bg_window_flags); ImGui::End(); } pm.tick(time_delta); tdch.tick(time_delta); mts.iterate(); cg.render(); sw.render(); tuiu.render(); tdch.render(); if constexpr (false) { ImGui::ShowDemoWindow(); } return nullptr; } Screen* MainScreen::tick(float time_delta, bool& quit) { _min_tick_interval = std::min( tc.toxIterationInterval()/1000.f, 0.03f // HACK: 30ms upper bound, should be the same as tox but will change ); return nullptr; }