Files
Seele/src/Engine/Window/Window.cpp
T

60 lines
1.7 KiB
C++
Raw Normal View History

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
{
2022-04-15 23:45:44 +02:00
views.add(view);
2021-01-19 15:30:00 +01:00
}
2022-04-15 23:45:44 +02:00
void Window::render()
2021-01-19 15:30:00 +01:00
{
2022-04-15 23:45:44 +02:00
while(owner->isActive())
2021-11-01 20:25:16 +01:00
{
2022-04-15 23:45:44 +02:00
gfxHandle->beginFrame();
for(auto& view : views)
2021-10-23 00:22:35 +02:00
{
2022-04-15 23:45:44 +02:00
view->beginUpdate();
view->update();
view->commitUpdate();
view->prepareRender();
view->render();
}
gfxHandle->endFrame();
2021-11-24 12:10:23 +01:00
}
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
}