Added UI component, resource & system. Now renders on screen and live reloads
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include "src/Resource/ResourceManager.h"
|
||||
#include "src/Rendering/Textures/Material.h"
|
||||
#include "src/Resource/Model.h"
|
||||
#include "src/Resource/UI.h"
|
||||
|
||||
using namespace Nuake;
|
||||
|
||||
@@ -94,6 +95,13 @@ Ref<Model> ResourceLoader::LoadModel(const std::string& path)
|
||||
return model;
|
||||
}
|
||||
|
||||
Ref<UIResource> ResourceLoader::LoadUI(const std::string& path)
|
||||
{
|
||||
auto uiResource = CreateRef<UIResource>(path);
|
||||
uiResource->ID = UUID();
|
||||
return uiResource;
|
||||
}
|
||||
|
||||
UUID ResourceLoader::ReadUUID(json j)
|
||||
{
|
||||
if (j.contains("UUID"))
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace Nuake
|
||||
{
|
||||
class Material;
|
||||
class Model;
|
||||
class UIResource;
|
||||
|
||||
class ResourceLoader
|
||||
{
|
||||
@@ -21,6 +22,7 @@ namespace Nuake
|
||||
|
||||
static Ref<Material> LoadMaterial(const std::string& path);
|
||||
static Ref<Model> LoadModel(const std::string& path);
|
||||
static Ref<UIResource> LoadUI(const std::string& path);
|
||||
|
||||
private:
|
||||
static UUID ReadUUID(json j);
|
||||
|
||||
72
Nuake/src/Resource/UI.cpp
Normal file
72
Nuake/src/Resource/UI.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
#include "UI.h"
|
||||
#include "Engine.h"
|
||||
#include "src/FileSystem/FileSystem.h"
|
||||
#include "src/Rendering/Buffers/Framebuffer.h"
|
||||
#include "src/UI/NuakeUI.h"
|
||||
#include "src/UI/Parsers/CanvasParser.h"
|
||||
#include "src/UI/UIInputManager.h"
|
||||
|
||||
|
||||
using namespace Nuake;
|
||||
using namespace NuakeUI;
|
||||
|
||||
MyInputManager* UIResource::inputManager = nullptr;
|
||||
|
||||
UIResource::UIResource(const std::string& path) :
|
||||
filePath(path)
|
||||
{
|
||||
const Vector2 defaultSize = { 1280, 720 };
|
||||
framebuffer = CreateRef<FrameBuffer>(true, defaultSize);
|
||||
framebuffer->SetTexture(CreateRef<Texture>(defaultSize, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE));
|
||||
|
||||
if (!inputManager)
|
||||
{
|
||||
inputManager = new MyInputManager(*Engine::GetCurrentWindow());
|
||||
}
|
||||
|
||||
CanvasParser parser;
|
||||
canvas = parser.Parse(FileSystem::RelativeToAbsolute(path));
|
||||
canvas->SetInputManager(inputManager);
|
||||
canvas->ComputeLayout(defaultSize);
|
||||
}
|
||||
|
||||
void UIResource::Draw()
|
||||
{
|
||||
framebuffer->Bind();
|
||||
{
|
||||
RenderCommand::Clear();
|
||||
|
||||
if (canvas)
|
||||
{
|
||||
canvas->Draw();
|
||||
}
|
||||
}
|
||||
framebuffer->Unbind();
|
||||
}
|
||||
|
||||
void UIResource::Resize(const Vector2& size)
|
||||
{
|
||||
framebuffer->QueueResize(size);
|
||||
canvas->ComputeLayout(size);
|
||||
}
|
||||
|
||||
void UIResource::Reload()
|
||||
{
|
||||
if (!FileSystem::FileExists(filePath))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CanvasParser parser;
|
||||
canvas = parser.Parse(FileSystem::RelativeToAbsolute(filePath));
|
||||
if (canvas)
|
||||
{
|
||||
canvas->SetInputManager(inputManager);
|
||||
canvas->ComputeLayout(framebuffer->GetSize());
|
||||
}
|
||||
}
|
||||
|
||||
Ref<Texture> UIResource::GetOutputTexture() const
|
||||
{
|
||||
return framebuffer->GetTexture();
|
||||
}
|
||||
35
Nuake/src/Resource/UI.h
Normal file
35
Nuake/src/Resource/UI.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
#include "Resource.h"
|
||||
#include "src/Core/Core.h"
|
||||
#include "src/Core/Maths.h"
|
||||
|
||||
namespace NuakeUI
|
||||
{
|
||||
class Canvas;
|
||||
}
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
class FrameBuffer;
|
||||
class MyInputManager;
|
||||
class Texture;
|
||||
|
||||
class UIResource : public Resource
|
||||
{
|
||||
public:
|
||||
UIResource(const std::string& path);
|
||||
~UIResource() = default;
|
||||
|
||||
void Draw();
|
||||
void Resize(const Vector2& size);
|
||||
void Reload();
|
||||
|
||||
Ref<Texture> GetOutputTexture() const;
|
||||
|
||||
private:
|
||||
Ref<NuakeUI::Canvas> canvas;
|
||||
Ref<FrameBuffer> framebuffer;
|
||||
static MyInputManager* inputManager;
|
||||
std::string filePath;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user