2023-07-26 12:24:18 +02:00
|
|
|
#include "./main_screen.hpp"
|
|
|
|
|
|
|
|
#include <imgui/imgui.h>
|
|
|
|
|
2023-07-26 20:09:57 +02:00
|
|
|
#include <SDL3/SDL.h>
|
|
|
|
|
2023-07-26 12:24:18 +02:00
|
|
|
#include <memory>
|
|
|
|
|
2023-08-28 15:33:36 +02:00
|
|
|
MainScreen::MainScreen(SDL_Renderer* renderer_, std::string save_path, std::string save_password, std::vector<std::string> plugins) :
|
2023-07-26 20:09:57 +02:00
|
|
|
renderer(renderer_),
|
|
|
|
rmm(cr),
|
2023-07-29 20:51:32 +02:00
|
|
|
mts(rmm),
|
2023-08-28 15:33:36 +02:00
|
|
|
tc(save_path, save_password),
|
2023-07-29 20:39:31 +02:00
|
|
|
ad(tc),
|
2023-07-26 20:09:57 +02:00
|
|
|
tcm(cr, tc, tc),
|
|
|
|
tmm(rmm, cr, tcm, tc, tc),
|
|
|
|
ttm(rmm, cr, tcm, tc, tc),
|
2023-08-02 19:24:51 +02:00
|
|
|
mmil(rmm),
|
2023-10-14 15:59:32 +02:00
|
|
|
tam(rmm, cr, conf),
|
2023-07-28 18:03:45 +02:00
|
|
|
sdlrtu(renderer_),
|
2023-07-29 20:07:59 +02:00
|
|
|
cg(conf, rmm, cr, sdlrtu)
|
2023-07-26 20:09:57 +02:00
|
|
|
{
|
2023-07-26 12:55:50 +02:00
|
|
|
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>("ConfigModelI", "host", &conf);
|
|
|
|
g_provideInstance<Contact3Registry>("Contact3Registry", "host", &cr);
|
|
|
|
g_provideInstance<RegistryMessageModel>("RegistryMessageModel", "host", &rmm);
|
|
|
|
|
|
|
|
g_provideInstance<ToxI>("ToxI", "host", &tc);
|
|
|
|
g_provideInstance<ToxEventProviderI>("ToxEventProviderI", "host", &tc);
|
2023-08-03 13:05:19 +02:00
|
|
|
g_provideInstance<ToxContactModel2>("ToxContactModel2", "host", &tcm);
|
2023-07-26 12:55:50 +02:00
|
|
|
|
|
|
|
// TODO: pm?
|
|
|
|
|
|
|
|
// graphics
|
|
|
|
g_provideInstance("ImGuiContext", "host", ImGui::GetCurrentContext());
|
2023-07-26 20:09:57 +02:00
|
|
|
g_provideInstance<TextureUploaderI>("TextureUploaderI", "host", &sdlrtu);
|
2023-07-26 12:55:50 +02:00
|
|
|
}
|
|
|
|
|
2023-08-03 13:05:19 +02:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-26 12:55:50 +02:00
|
|
|
conf.dump();
|
2023-07-26 12:24:18 +02:00
|
|
|
}
|
|
|
|
|
2023-07-26 20:09:57 +02:00
|
|
|
MainScreen::~MainScreen(void) {
|
|
|
|
}
|
|
|
|
|
2023-07-30 15:10:26 +02:00
|
|
|
bool MainScreen::handleEvent(SDL_Event& e) {
|
2023-10-18 14:23:27 +02:00
|
|
|
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()
|
|
|
|
}
|
|
|
|
|
2023-07-30 15:10:26 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-07-26 12:24:18 +02:00
|
|
|
Screen* MainScreen::poll(bool& quit) {
|
2023-07-26 12:55:50 +02:00
|
|
|
auto new_time = std::chrono::high_resolution_clock::now();
|
|
|
|
const float time_delta {std::chrono::duration<float, std::chrono::seconds::period>(new_time - last_time).count()};
|
|
|
|
last_time = new_time;
|
|
|
|
|
|
|
|
quit = !tc.iterate();
|
|
|
|
|
2023-08-19 21:42:47 +02:00
|
|
|
tcm.iterate(time_delta);
|
|
|
|
|
2023-10-14 15:59:32 +02:00
|
|
|
tam.iterate();
|
|
|
|
|
2023-07-26 12:55:50 +02:00
|
|
|
pm.tick(time_delta);
|
|
|
|
|
2023-07-29 20:51:32 +02:00
|
|
|
mts.iterate();
|
|
|
|
|
2023-07-28 18:03:45 +02:00
|
|
|
cg.render();
|
|
|
|
|
2023-08-28 14:06:27 +02:00
|
|
|
if constexpr (false) {
|
2023-09-29 18:15:18 +02:00
|
|
|
ImGui::ShowDemoWindow();
|
2023-07-26 12:55:50 +02:00
|
|
|
}
|
2023-07-26 12:24:18 +02:00
|
|
|
|
2023-07-29 20:07:59 +02:00
|
|
|
#if 0
|
2023-07-26 20:09:57 +02:00
|
|
|
{ // texture tests
|
|
|
|
const size_t width = 8;
|
|
|
|
const size_t height = 8;
|
|
|
|
#define W 0xff, 0xff, 0xff, 0xff
|
|
|
|
#define B 0x00, 0x00, 0x00, 0xff
|
|
|
|
#define P 0xff, 0x00, 0xff, 0xff
|
|
|
|
static uint8_t raw_pixel[width*height*4] {
|
|
|
|
P, W, W, W, W, W, W, P,
|
|
|
|
W, W, W, W, W, W, W, W,
|
|
|
|
W, W, W, W, W, W, W, W,
|
|
|
|
W, W, W, B, B, W, W, W,
|
|
|
|
W, W, W, B, B, W, W, W,
|
|
|
|
W, W, W, W, W, W, W, W,
|
|
|
|
W, W, W, W, W, W, W, W,
|
|
|
|
P, W, W, W, W, W, W, P,
|
|
|
|
};
|
|
|
|
|
|
|
|
static uint64_t texture = sdlrtu.uploadRGBA(raw_pixel, width, height);
|
|
|
|
|
|
|
|
if (ImGui::Begin("test texture")) {
|
|
|
|
ImGui::Text("test texture windoajsdf");
|
|
|
|
|
|
|
|
ImGui::Image(reinterpret_cast<void*>(texture), {width*10, height*10});
|
|
|
|
}
|
|
|
|
ImGui::End();
|
|
|
|
}
|
2023-07-29 20:07:59 +02:00
|
|
|
#endif
|
2023-07-26 20:09:57 +02:00
|
|
|
|
2023-07-26 12:24:18 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|