2021-01-19 15:30:00 +01:00
|
|
|
#include "Window.h"
|
|
|
|
|
#include <functional>
|
|
|
|
|
|
2021-09-29 22:12:56 +02:00
|
|
|
using namespace Seele;
|
|
|
|
|
|
|
|
|
|
Window::Window(Gfx::PWindow handle)
|
2021-01-19 15:30:00 +01:00
|
|
|
: gfxHandle(handle)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
windowView->worker = std::thread(&Window::viewWorker, this, windowView);
|
|
|
|
|
views.add(windowView);
|
2021-01-19 15:30:00 +01:00
|
|
|
}
|
|
|
|
|
|
2021-09-29 22:12:56 +02:00
|
|
|
void 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-01-19 15:30:00 +01:00
|
|
|
{
|
2021-09-29 22:12:56 +02:00
|
|
|
{
|
|
|
|
|
std::lock_guard lock(windowView->workerMutex);
|
2021-10-01 19:55:04 +02:00
|
|
|
windowView->view->prepareRender();
|
2021-09-29 22:12:56 +02:00
|
|
|
}
|
2021-10-01 19:55:04 +02:00
|
|
|
windowView->view->render();
|
2021-01-19 15:30:00 +01:00
|
|
|
}
|
|
|
|
|
gfxHandle->endFrame();
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
auto mouseButtonFunction = std::bind(&View::mouseButtonCallback, view.getHandle(), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
|
|
|
|
|
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-09-29 22:12:56 +02:00
|
|
|
|
|
|
|
|
|
2021-10-12 14:20:30 +02:00
|
|
|
void Window::viewWorker(WindowView* windowView)
|
2021-09-29 22:12:56 +02:00
|
|
|
{
|
|
|
|
|
while(true)
|
|
|
|
|
{
|
|
|
|
|
windowView->view->beginFrame();
|
2021-10-01 19:55:04 +02:00
|
|
|
windowView->view->update();
|
2021-09-29 22:12:56 +02:00
|
|
|
std::lock_guard lock(windowView->workerMutex);
|
2021-10-01 19:55:04 +02:00
|
|
|
windowView->view->endFrame();
|
2021-09-29 22:12:56 +02:00
|
|
|
}
|
|
|
|
|
}
|