Starting implementation of UI framework
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
target_sources(SeeleEngine
|
||||
PRIVATE
|
||||
InspectorView.h
|
||||
InspectorView.cpp
|
||||
RenderPath.h
|
||||
RenderPath.cpp
|
||||
SceneView.h
|
||||
SceneView.cpp
|
||||
SceneRenderPath.h
|
||||
SceneRenderPath.cpp
|
||||
View.h
|
||||
View.cpp
|
||||
Window.cpp
|
||||
Window.h
|
||||
WindowManager.h
|
||||
WindowManager.cpp)
|
||||
@@ -0,0 +1,26 @@
|
||||
#include "InspectorView.h"
|
||||
using namespace Seele;
|
||||
|
||||
InspectorView::InspectorView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &createInfo)
|
||||
: View(graphics, window, createInfo)
|
||||
{
|
||||
}
|
||||
|
||||
InspectorView::~InspectorView()
|
||||
{
|
||||
}
|
||||
|
||||
void InspectorView::beginFrame()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void InspectorView::render()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void InspectorView::endFrame()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
#include "View.h"
|
||||
#include "UI/UIRenderPath.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
class InspectorView : public View
|
||||
{
|
||||
public:
|
||||
InspectorView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &createInfo);
|
||||
virtual ~InspectorView();
|
||||
virtual void beginFrame();
|
||||
virtual void render();
|
||||
virtual void endFrame();
|
||||
|
||||
private:
|
||||
PUIComponent root;
|
||||
};
|
||||
} // namespace Seele
|
||||
@@ -0,0 +1,17 @@
|
||||
#include "RenderPath.h"
|
||||
#include "Graphics/GraphicsResources.h"
|
||||
|
||||
Seele::RenderPath::RenderPath(Gfx::PGraphics graphics, Gfx::PViewport target)
|
||||
: graphics(graphics), target(target)
|
||||
{
|
||||
}
|
||||
|
||||
Seele::RenderPath::~RenderPath()
|
||||
{
|
||||
}
|
||||
|
||||
void Seele::RenderPath::applyArea(URect newArea)
|
||||
{
|
||||
target->resize(newArea.size.x, newArea.size.y);
|
||||
target->move(newArea.offset.x, newArea.offset.y);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
#include "Graphics/Graphics.h"
|
||||
namespace Seele
|
||||
{
|
||||
//A renderpath is a general Renderer for a view.
|
||||
class RenderPath
|
||||
{
|
||||
public:
|
||||
RenderPath(Gfx::PGraphics graphics, Gfx::PViewport target);
|
||||
virtual ~RenderPath();
|
||||
virtual void applyArea(URect area);
|
||||
virtual void init() = 0;
|
||||
virtual void beginFrame() = 0;
|
||||
virtual void render() = 0;
|
||||
virtual void endFrame() = 0;
|
||||
|
||||
protected:
|
||||
Gfx::PGraphics graphics;
|
||||
Gfx::PViewport target;
|
||||
};
|
||||
DEFINE_REF(RenderPath);
|
||||
} // namespace Seele
|
||||
@@ -0,0 +1,42 @@
|
||||
#include "SceneRenderPath.h"
|
||||
#include "Scene/Scene.h"
|
||||
#include "Material/Material.h"
|
||||
#include "Asset/AssetRegistry.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
SceneRenderPath::SceneRenderPath(PScene scene, Gfx::PGraphics graphics, Gfx::PViewport target, PCameraActor source)
|
||||
: RenderPath(graphics, target)
|
||||
, scene(scene)
|
||||
{
|
||||
basePass = new BasePass(scene, graphics, target, source);
|
||||
}
|
||||
|
||||
SceneRenderPath::~SceneRenderPath()
|
||||
{
|
||||
}
|
||||
|
||||
void SceneRenderPath::setTargetScene(PScene newScene)
|
||||
{
|
||||
scene = newScene;
|
||||
}
|
||||
|
||||
void SceneRenderPath::init()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SceneRenderPath::beginFrame()
|
||||
{
|
||||
basePass->beginFrame();
|
||||
}
|
||||
|
||||
void SceneRenderPath::render()
|
||||
{
|
||||
basePass->render();
|
||||
}
|
||||
|
||||
void SceneRenderPath::endFrame()
|
||||
{
|
||||
basePass->endFrame();
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
#include "RenderPath.h"
|
||||
#include "Graphics/RenderPass/BasePass.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
DECLARE_REF(Scene);
|
||||
DECLARE_REF(CameraActor);
|
||||
class SceneRenderPath : public RenderPath
|
||||
{
|
||||
public:
|
||||
SceneRenderPath(PScene scene, Gfx::PGraphics graphics, Gfx::PViewport target, PCameraActor source);
|
||||
virtual ~SceneRenderPath();
|
||||
void setTargetScene(PScene scene);
|
||||
virtual void init();
|
||||
virtual void beginFrame();
|
||||
virtual void render();
|
||||
virtual void endFrame();
|
||||
|
||||
protected:
|
||||
PScene scene;
|
||||
UPBasePass basePass;
|
||||
};
|
||||
} // namespace Seele
|
||||
@@ -0,0 +1,79 @@
|
||||
#include "SceneView.h"
|
||||
#include "SceneRenderPath.h"
|
||||
#include "Scene/Scene.h"
|
||||
#include "Window.h"
|
||||
#include "Scene/Actor/CameraActor.h"
|
||||
#include "Scene/Components/CameraComponent.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
Seele::SceneView::SceneView(Gfx::PGraphics graphics, PWindow owner, const ViewportCreateInfo &createInfo)
|
||||
: View(graphics, owner, createInfo)
|
||||
{
|
||||
scene = new Scene(graphics);
|
||||
activeCamera = new CameraActor();
|
||||
scene->addActor(activeCamera);
|
||||
renderer = new SceneRenderPath(scene, graphics, viewport, activeCamera);
|
||||
}
|
||||
|
||||
Seele::SceneView::~SceneView()
|
||||
{
|
||||
}
|
||||
|
||||
void SceneView::beginFrame()
|
||||
{
|
||||
View::beginFrame();
|
||||
scene->tick(0);//TODO: update in separate thread
|
||||
}
|
||||
|
||||
void SceneView::keyCallback(KeyCode code, InputAction action, KeyModifier modifier)
|
||||
{
|
||||
if(action != InputAction::RELEASE)
|
||||
{
|
||||
if(code == KeyCode::KEY_W)
|
||||
{
|
||||
activeCamera->getCameraComponent()->moveOrigin(1);
|
||||
}
|
||||
if(code == KeyCode::KEY_S)
|
||||
{
|
||||
activeCamera->getCameraComponent()->moveOrigin(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool mouseDown = false;
|
||||
|
||||
void SceneView::mouseMoveCallback(double xPos, double yPos)
|
||||
{
|
||||
static double prevXPos = 0.0f, prevYPos = 0.0f;
|
||||
double deltaX = prevXPos - xPos;
|
||||
double deltaY = prevYPos - yPos;
|
||||
prevXPos = xPos;
|
||||
prevYPos = yPos;
|
||||
if(mouseDown)
|
||||
{
|
||||
activeCamera->getCameraComponent()->mouseMove((float)deltaX, (float)deltaY);
|
||||
}
|
||||
}
|
||||
|
||||
void SceneView::mouseButtonCallback(MouseButton button, InputAction action, KeyModifier modifier)
|
||||
{
|
||||
if(button == MouseButton::MOUSE_BUTTON_1 && action != InputAction::RELEASE)
|
||||
{
|
||||
mouseDown = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
mouseDown = false;
|
||||
}
|
||||
}
|
||||
|
||||
void SceneView::scrollCallback(double xOffset, double yOffset)
|
||||
{
|
||||
activeCamera->getCameraComponent()->mouseScroll(yOffset);
|
||||
}
|
||||
|
||||
void SceneView::fileCallback(int count, const char** paths)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
#include "View.h"
|
||||
namespace Seele
|
||||
{
|
||||
DECLARE_REF(Scene);
|
||||
DECLARE_REF(CameraActor);
|
||||
class SceneView : public View
|
||||
{
|
||||
public:
|
||||
SceneView(Gfx::PGraphics graphics, PWindow owner, const ViewportCreateInfo &createInfo);
|
||||
~SceneView();
|
||||
virtual void beginFrame();
|
||||
PScene getScene() const { return scene; }
|
||||
private:
|
||||
PScene scene;
|
||||
PCameraActor activeCamera;
|
||||
virtual void keyCallback(KeyCode code, InputAction action, KeyModifier modifier) override;
|
||||
virtual void mouseMoveCallback(double xPos, double yPos) override;
|
||||
virtual void mouseButtonCallback(MouseButton button, InputAction action, KeyModifier modifier) override;
|
||||
virtual void scrollCallback(double xOffset, double yOffset) override;
|
||||
virtual void fileCallback(int count, const char** paths) override;
|
||||
};
|
||||
DEFINE_REF(SceneView);
|
||||
} // namespace Seele
|
||||
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
#include "View.h"
|
||||
#include "Window.h"
|
||||
|
||||
Seele::View::View(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &viewportInfo)
|
||||
: graphics(graphics), owner(window)
|
||||
{
|
||||
viewport = graphics->createViewport(owner->getGfxHandle(), viewportInfo);
|
||||
}
|
||||
|
||||
Seele::View::~View()
|
||||
{
|
||||
}
|
||||
|
||||
void Seele::View::beginFrame()
|
||||
{
|
||||
renderer->beginFrame();
|
||||
}
|
||||
|
||||
void Seele::View::render()
|
||||
{
|
||||
renderer->render();
|
||||
}
|
||||
|
||||
void Seele::View::endFrame()
|
||||
{
|
||||
renderer->endFrame();
|
||||
}
|
||||
|
||||
void Seele::View::applyArea(URect area)
|
||||
{
|
||||
renderer->applyArea(area);
|
||||
}
|
||||
|
||||
void View::setFocused()
|
||||
{
|
||||
owner->setFocused(this);
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
#include "RenderPath.h"
|
||||
namespace Seele
|
||||
{
|
||||
DECLARE_REF(Window);
|
||||
// A view is a part of the window, which can be anything from a viewport to an editor
|
||||
class View
|
||||
{
|
||||
public:
|
||||
View(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &createInfo);
|
||||
virtual ~View();
|
||||
virtual void beginFrame();
|
||||
virtual void render();
|
||||
virtual void endFrame();
|
||||
void applyArea(URect area);
|
||||
void setFocused();
|
||||
|
||||
protected:
|
||||
Gfx::PGraphics graphics;
|
||||
Gfx::PViewport viewport;
|
||||
PWindow owner;
|
||||
PRenderPath renderer;
|
||||
|
||||
virtual void keyCallback(KeyCode code, InputAction action, KeyModifier modifier) = 0;
|
||||
virtual void mouseMoveCallback(double xPos, double yPos) = 0;
|
||||
virtual void mouseButtonCallback(MouseButton button, InputAction action, KeyModifier modifier) = 0;
|
||||
virtual void scrollCallback(double xOffset, double yOffset) = 0;
|
||||
virtual void fileCallback(int count, const char** paths) = 0;
|
||||
friend class Window;
|
||||
};
|
||||
|
||||
DEFINE_REF(View)
|
||||
} // namespace Seele
|
||||
@@ -0,0 +1,62 @@
|
||||
#include "Window.h"
|
||||
#include <functional>
|
||||
|
||||
Seele::Window::Window(Gfx::PWindow handle)
|
||||
: gfxHandle(handle)
|
||||
{
|
||||
}
|
||||
|
||||
Seele::Window::~Window()
|
||||
{
|
||||
}
|
||||
|
||||
void Seele::Window::addView(PView view)
|
||||
{
|
||||
viewports.add(view);
|
||||
}
|
||||
|
||||
void Seele::Window::beginFrame()
|
||||
{
|
||||
gfxHandle->beginFrame();
|
||||
for (auto view : viewports)
|
||||
{
|
||||
view->beginFrame();
|
||||
}
|
||||
}
|
||||
|
||||
void Seele::Window::render()
|
||||
{
|
||||
for (auto view : viewports)
|
||||
{
|
||||
view->render();
|
||||
}
|
||||
}
|
||||
|
||||
void Seele::Window::endFrame()
|
||||
{
|
||||
gfxHandle->endFrame();
|
||||
for (auto view : viewports)
|
||||
{
|
||||
view->endFrame();
|
||||
}
|
||||
}
|
||||
|
||||
Gfx::PWindow Seele::Window::getGfxHandle()
|
||||
{
|
||||
return gfxHandle;
|
||||
}
|
||||
|
||||
void Window::setFocused(PView view)
|
||||
{
|
||||
focusedView = 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);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
#include "Graphics/GraphicsResources.h"
|
||||
#include "View.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
// The logical window, with the graphics proxy
|
||||
class Window
|
||||
{
|
||||
public:
|
||||
Window(Gfx::PWindow handle);
|
||||
~Window();
|
||||
void addView(PView view);
|
||||
void beginFrame();
|
||||
void render();
|
||||
void endFrame();
|
||||
Gfx::PWindow getGfxHandle();
|
||||
void setFocused(PView view);
|
||||
|
||||
private:
|
||||
Array<PView> viewports;
|
||||
PView focusedView;
|
||||
Gfx::PWindow gfxHandle;
|
||||
};
|
||||
DEFINE_REF(Window);
|
||||
} // namespace Seele
|
||||
@@ -0,0 +1,59 @@
|
||||
#include "WindowManager.h"
|
||||
#include "Graphics/Vulkan/VulkanGraphics.h"
|
||||
|
||||
Gfx::PGraphics WindowManager::graphics;
|
||||
|
||||
Seele::WindowManager::WindowManager()
|
||||
{
|
||||
graphics = new Vulkan::Graphics();
|
||||
GraphicsInitializer initializer;
|
||||
graphics->init(initializer);
|
||||
TextureCreateInfo info;
|
||||
info.width = 4096;
|
||||
info.height = 4096;
|
||||
Gfx::PTexture2D testTexture = graphics->createTexture2D(info);
|
||||
UniformBufferCreateInfo uniformInitializer;
|
||||
uniformInitializer.resourceData.size = 4096;
|
||||
uniformInitializer.resourceData.data = new uint8[4096];
|
||||
for (int i = 0; i < 4096; ++i)
|
||||
{
|
||||
uniformInitializer.resourceData.data[i] = (uint8)i;
|
||||
}
|
||||
Gfx::PUniformBuffer testUniform = graphics->createUniformBuffer(uniformInitializer);
|
||||
}
|
||||
|
||||
Seele::WindowManager::~WindowManager()
|
||||
{
|
||||
}
|
||||
|
||||
PWindow Seele::WindowManager::addWindow(const WindowCreateInfo &createInfo)
|
||||
{
|
||||
Gfx::PWindow handle = graphics->createWindow(createInfo);
|
||||
PWindow window = new Window(handle);
|
||||
windows.add(window);
|
||||
return window;
|
||||
}
|
||||
|
||||
void Seele::WindowManager::beginFrame()
|
||||
{
|
||||
for (auto window : windows)
|
||||
{
|
||||
window->beginFrame();
|
||||
}
|
||||
}
|
||||
|
||||
void WindowManager::render()
|
||||
{
|
||||
for(auto window : windows)
|
||||
{
|
||||
window->render();
|
||||
}
|
||||
}
|
||||
|
||||
void Seele::WindowManager::endFrame()
|
||||
{
|
||||
for (auto window : windows)
|
||||
{
|
||||
window->endFrame();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
#include "Graphics/GraphicsResources.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "Containers/Array.h"
|
||||
#include "Window.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
class WindowManager
|
||||
{
|
||||
public:
|
||||
WindowManager();
|
||||
~WindowManager();
|
||||
PWindow addWindow(const WindowCreateInfo &createInfo);
|
||||
void beginFrame();
|
||||
void render();
|
||||
void endFrame();
|
||||
static Gfx::PGraphics getGraphics()
|
||||
{
|
||||
return graphics;
|
||||
}
|
||||
inline bool isActive() const
|
||||
{
|
||||
return windows.size();
|
||||
}
|
||||
|
||||
private:
|
||||
Array<PWindow> windows;
|
||||
static Gfx::PGraphics graphics;
|
||||
};
|
||||
DEFINE_REF(WindowManager);
|
||||
} // namespace Seele
|
||||
Reference in New Issue
Block a user