2021-01-19 15:30:00 +01:00
|
|
|
#include "Window.h"
|
2021-11-01 20:25:16 +01:00
|
|
|
#include "WindowManager.h"
|
2021-01-19 15:30:00 +01:00
|
|
|
#include <functional>
|
|
|
|
|
|
2021-09-29 22:12:56 +02:00
|
|
|
using namespace Seele;
|
|
|
|
|
|
2021-11-01 20:25:16 +01:00
|
|
|
Window::Window(PWindowManager owner, Gfx::PWindow handle)
|
|
|
|
|
: owner(owner)
|
|
|
|
|
, gfxHandle(handle)
|
2021-01-19 15:30:00 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-29 22:12:56 +02:00
|
|
|
Window::~Window()
|
2021-01-19 15:30:00 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-29 22:12:56 +02:00
|
|
|
void Window::addView(PView view)
|
2021-01-19 15:30:00 +01:00
|
|
|
{
|
2021-09-29 22:12:56 +02:00
|
|
|
WindowView* windowView = new WindowView();
|
|
|
|
|
windowView->view = view;
|
2021-11-13 19:28:18 +01:00
|
|
|
windowView->updateFinished = Event(view->name);
|
2021-10-23 00:22:35 +02:00
|
|
|
//windowView->worker = std::thread(&Window::viewWorker, this, windowView);
|
2021-11-11 20:12:50 +01:00
|
|
|
views.add(windowView);
|
|
|
|
|
viewWorker(views.size() - 1);
|
2021-01-19 15:30:00 +01:00
|
|
|
}
|
|
|
|
|
|
2021-11-01 20:25:16 +01:00
|
|
|
MainJob Window::render()
|
2021-01-19 15:30:00 +01:00
|
|
|
{
|
|
|
|
|
gfxHandle->beginFrame();
|
2021-09-29 22:12:56 +02:00
|
|
|
for(auto& windowView : views)
|
2021-11-01 20:25:16 +01:00
|
|
|
{
|
|
|
|
|
co_await windowView->updateFinished;
|
2021-11-14 20:36:53 +01:00
|
|
|
windowView->updateFinished.reset();
|
2021-10-23 00:22:35 +02:00
|
|
|
{
|
2022-01-12 14:40:26 +01:00
|
|
|
std::scoped_lock lock(windowView->workerMutex);
|
2021-10-23 00:22:35 +02:00
|
|
|
windowView->view->prepareRender();
|
|
|
|
|
}
|
2021-10-01 19:55:04 +02:00
|
|
|
windowView->view->render();
|
2021-01-19 15:30:00 +01:00
|
|
|
}
|
2021-11-24 12:10:23 +01:00
|
|
|
for(auto& windowView : views)
|
|
|
|
|
{
|
|
|
|
|
co_await windowView->view->renderFinished();
|
2021-12-02 13:00:03 +01:00
|
|
|
windowView->view->resetRender();
|
2021-11-24 12:10:23 +01:00
|
|
|
}
|
2021-01-19 15:30:00 +01:00
|
|
|
gfxHandle->endFrame();
|
2021-12-15 00:05:42 +01:00
|
|
|
if(owner->isActive())
|
|
|
|
|
{
|
|
|
|
|
render();
|
|
|
|
|
}
|
|
|
|
|
co_return;
|
2021-01-19 15:30:00 +01:00
|
|
|
}
|
|
|
|
|
|
2021-09-29 22:12:56 +02:00
|
|
|
Gfx::PWindow Window::getGfxHandle()
|
2021-01-19 15:30:00 +01:00
|
|
|
{
|
|
|
|
|
return gfxHandle;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Window::setFocused(PView view)
|
|
|
|
|
{
|
|
|
|
|
auto keyFunction = std::bind(&View::keyCallback, view.getHandle(), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
|
|
|
|
|
auto mouseMoveFunction = std::bind(&View::mouseMoveCallback, view.getHandle(), std::placeholders::_1, std::placeholders::_2);
|
2021-12-02 13:00:03 +01:00
|
|
|
auto mouseButtonFunction = std::bind(&View::mouseButtonCallback, view.getHandle() , std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
|
2021-01-19 15:30:00 +01:00
|
|
|
auto scrollFunction = std::bind(&View::scrollCallback, view.getHandle(), std::placeholders::_1, std::placeholders::_2);
|
|
|
|
|
auto fileFunction = std::bind(&View::fileCallback, view.getHandle(), std::placeholders::_1, std::placeholders::_2);
|
|
|
|
|
gfxHandle->setKeyCallback(keyFunction);
|
|
|
|
|
gfxHandle->setMouseMoveCallback(mouseMoveFunction);
|
|
|
|
|
gfxHandle->setMouseButtonCallback(mouseButtonFunction);
|
|
|
|
|
gfxHandle->setScrollCallback(scrollFunction);
|
|
|
|
|
gfxHandle->setFileCallback(fileFunction);
|
2021-11-01 20:25:16 +01:00
|
|
|
gfxHandle->setCloseCallback([this](){
|
|
|
|
|
owner->notifyWindowClosed(this);
|
|
|
|
|
});
|
2021-01-19 15:30:00 +01:00
|
|
|
}
|
2021-09-29 22:12:56 +02:00
|
|
|
|
2021-11-11 20:12:50 +01:00
|
|
|
Job Window::viewWorker(size_t viewIndex)
|
2021-09-29 22:12:56 +02:00
|
|
|
{
|
2021-11-11 20:12:50 +01:00
|
|
|
WindowView* windowView = views[viewIndex];
|
2022-02-14 16:29:26 +01:00
|
|
|
co_await windowView->view->beginUpdate();
|
|
|
|
|
co_await windowView->view->update();
|
2021-09-29 22:12:56 +02:00
|
|
|
{
|
2022-01-12 14:40:26 +01:00
|
|
|
std::scoped_lock lock(windowView->workerMutex);
|
2021-11-11 20:12:50 +01:00
|
|
|
windowView->view->commitUpdate();
|
2021-09-29 22:12:56 +02:00
|
|
|
}
|
2021-11-13 19:28:18 +01:00
|
|
|
//std::cout << "Update completed" << std::endl;
|
2021-11-11 20:12:50 +01:00
|
|
|
windowView->updateFinished.raise();
|
|
|
|
|
// enqueue next frame update
|
|
|
|
|
viewWorker(viewIndex);
|
|
|
|
|
co_return;
|
2021-09-29 22:12:56 +02:00
|
|
|
}
|