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

57 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;
2024-06-09 12:20:04 +02:00
Window::Window(PWindowManager owner, Gfx::OWindow handle) : owner(owner), gfxHandle(std::move(handle)) {
gfxHandle->setResizeCallback([this](uint32 w, uint32 h) { onResize(w, h); });
2021-01-19 15:30:00 +01:00
}
2024-06-09 12:20:04 +02:00
Window::~Window() {}
2021-01-19 15:30:00 +01:00
2024-06-09 12:20:04 +02:00
void Window::addView(PView view) { views.add(view); }
2021-01-19 15:30:00 +01:00
2024-06-09 12:20:04 +02:00
void Window::pollInputs() { gfxHandle->pollInput(); }
2023-12-28 21:42:18 +01:00
2024-06-09 12:20:04 +02:00
void Window::render() {
2023-12-02 10:55:00 +01:00
gfxHandle->beginFrame();
2024-06-09 12:20:04 +02:00
for (auto& view : views) {
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
}
2024-06-09 12:20:04 +02:00
Gfx::PWindow Window::getGfxHandle() { return gfxHandle; }
void Window::setFocused(PView view) {
2021-01-19 15:30:00 +01:00
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);
2024-06-09 12:20:04 +02: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);
2026-03-09 22:27:59 +01:00
gfxHandle->setCloseCallback([this]() {
owner->notifyWindowClosed(this);
});
2021-01-19 15:30:00 +01:00
}
2023-11-18 11:04:30 +01:00
2024-06-09 12:20:04 +02:00
void Window::onResize(uint32 width, uint32 height) {
for (auto& view : views) {
2023-11-18 11:04:30 +01:00
// TODO: some sort of layouting algorithm should do this
2023-12-28 21:42:18 +01:00
view->resize(URect{
2023-11-18 11:04:30 +01:00
.size = UVector2(width, height),
.offset = UVector2(0, 0),
2024-06-09 12:20:04 +02:00
});
2023-11-18 11:04:30 +01:00
}
}