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

70 lines
2.0 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;
2023-11-08 23:27:21 +01:00
Window::Window(PWindowManager owner, Gfx::OWindow handle)
2021-11-01 20:25:16 +01:00
: owner(owner)
2023-11-08 23:27:21 +01:00
, gfxHandle(std::move(handle))
2021-01-19 15:30:00 +01:00
{
2023-11-18 11:04:30 +01:00
gfxHandle->setResizeCallback([this](uint32 w, uint32 h) {onResize(w, h); });
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
{
2023-12-02 10:55:00 +01:00
gfxHandle->beginFrame();
for(auto& view : views)
2021-11-01 20:25:16 +01:00
{
2023-12-02 10:55:00 +01:00
view->beginUpdate();
view->update();
view->commitUpdate();
view->prepareRender();
view->render();
2021-11-24 12:10:23 +01:00
}
2023-12-02 10:55:00 +01:00
gfxHandle->endFrame();
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
}
2023-11-18 11:04:30 +01:00
void Window::onResize(uint32 width, uint32 height)
{
for (auto& view : views)
{
// TODO: some sort of layouting algorithm should do this
view->applyArea(URect{
.size = UVector2(width, height),
.offset = UVector2(0, 0),
});
}
}