forked from Dynamitos/Seele
Compare commits
9
Commits
d33533474c
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c57ca4efe6 | ||
|
|
28a76ed404 | ||
|
|
6e1cccdb40 | ||
|
|
949a6738bd | ||
|
|
1f7e7e0541 | ||
|
|
1e34f0e67b | ||
|
|
803531c608 | ||
|
|
c5c66f8cf3 | ||
|
|
499407d366 |
No files matched your search
+79
-26
@@ -1,5 +1,27 @@
|
|||||||
import lldb
|
import lldb
|
||||||
|
|
||||||
|
def _member(valobj, name):
|
||||||
|
# GetChildMemberWithName does not search base classes reliably across
|
||||||
|
# LLDB versions; walk base classes explicitly, mirroring the working
|
||||||
|
# gdb _base_cast/_member in Seele.py.
|
||||||
|
child = valobj.GetChildMemberWithName(name)
|
||||||
|
if child.IsValid():
|
||||||
|
return child
|
||||||
|
t = valobj.GetType()
|
||||||
|
seen = set()
|
||||||
|
while t.IsValid() and t not in seen:
|
||||||
|
seen.add(t)
|
||||||
|
for i in range(t.GetNumBases()):
|
||||||
|
base = t.GetBaseClass(i)
|
||||||
|
if base.IsValid():
|
||||||
|
sub = valobj.GetBaseClassWithName(base.GetName())
|
||||||
|
if sub.IsValid():
|
||||||
|
child = sub.GetChildMemberWithName(name)
|
||||||
|
if child.IsValid():
|
||||||
|
return child
|
||||||
|
t = t.GetBaseClass(0) if t.GetNumBases() > 0 else None
|
||||||
|
return None
|
||||||
|
|
||||||
def Array_SummaryProvider(valobj, internal_dict):
|
def Array_SummaryProvider(valobj, internal_dict):
|
||||||
size = valobj.GetChildMemberWithName('arraySize').GetValueAsUnsigned(0)
|
size = valobj.GetChildMemberWithName('arraySize').GetValueAsUnsigned(0)
|
||||||
return f"Array(size={size})"
|
return f"Array(size={size})"
|
||||||
@@ -65,8 +87,8 @@ class ListSyntheticProvider:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def Tree_SummaryProvider(valobj, internal_dict):
|
def Tree_SummaryProvider(valobj, internal_dict):
|
||||||
size = valobj.GetChildMemberWithName('_size').GetValueAsUnsigned(0)
|
size = _member(valobj, '_size')
|
||||||
return f"Tree(size={size})"
|
return f"Tree(size={size.GetValueAsUnsigned(0) if size and size.IsValid() else '?'})"
|
||||||
|
|
||||||
class TreeSyntheticProvider:
|
class TreeSyntheticProvider:
|
||||||
def __init__(self, valobj, internal_dict):
|
def __init__(self, valobj, internal_dict):
|
||||||
@@ -87,28 +109,35 @@ class TreeSyntheticProvider:
|
|||||||
return None
|
return None
|
||||||
# Collect all nodes via in-order traversal, then return the one at `index`
|
# Collect all nodes via in-order traversal, then return the one at `index`
|
||||||
nodes = []
|
nodes = []
|
||||||
|
if self.root and self.root.IsValid():
|
||||||
self._collect(self.root, nodes)
|
self._collect(self.root, nodes)
|
||||||
if index >= len(nodes):
|
if index >= len(nodes):
|
||||||
return None
|
return None
|
||||||
return nodes[index].GetChildMemberWithName('data')
|
data = nodes[index].GetChildMemberWithName('data')
|
||||||
|
return data if data.IsValid() else None
|
||||||
|
|
||||||
def _collect(self, node, out):
|
def _collect(self, node, out):
|
||||||
if not node.IsValid():
|
if not node.IsValid():
|
||||||
return
|
return
|
||||||
self._collect(node.GetChildMemberWithName('leftChild'), out)
|
left = node.GetChildMemberWithName('leftChild')
|
||||||
|
if left.IsValid():
|
||||||
|
self._collect(left.Dereference(), out)
|
||||||
out.append(node)
|
out.append(node)
|
||||||
self._collect(node.GetChildMemberWithName('rightChild'), out)
|
right = node.GetChildMemberWithName('rightChild')
|
||||||
|
if right.IsValid():
|
||||||
|
self._collect(right.Dereference(), out)
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
self.root = self.valobj.GetChildMemberWithName('root')
|
self.root = _member(self.valobj, 'root')
|
||||||
self.size = self.valobj.GetChildMemberWithName('_size').GetValueAsUnsigned(0)
|
size = _member(self.valobj, '_size')
|
||||||
|
self.size = size.GetValueAsUnsigned(0) if size and size.IsValid() else 0
|
||||||
|
|
||||||
def has_children(self):
|
def has_children(self):
|
||||||
return True
|
return self.size > 0
|
||||||
|
|
||||||
def Set_SummaryProvider(valobj, internal_dict):
|
def Set_SummaryProvider(valobj, internal_dict):
|
||||||
size = valobj.GetChildMemberWithName('_size').GetValueAsUnsigned(0)
|
size = _member(valobj, '_size')
|
||||||
return f"Set(size={size})"
|
return f"Set(size={size.GetValueAsUnsigned(0) if size and size.IsValid() else '?'})"
|
||||||
|
|
||||||
class SetSyntheticProvider:
|
class SetSyntheticProvider:
|
||||||
def __init__(self, valobj, internal_dict):
|
def __init__(self, valobj, internal_dict):
|
||||||
@@ -128,28 +157,39 @@ class SetSyntheticProvider:
|
|||||||
if index < 0 or index >= self.size:
|
if index < 0 or index >= self.size:
|
||||||
return None
|
return None
|
||||||
nodes = []
|
nodes = []
|
||||||
self._collect(self.root, nodes)
|
# Start from pseudoRoot: the splay tree's actual structure is
|
||||||
|
# connected via pseudoRoot.leftChild, not the `root` pointer.
|
||||||
|
if self.pseudoRoot and self.pseudoRoot.IsValid():
|
||||||
|
left = self.pseudoRoot.GetChildMemberWithName('leftChild')
|
||||||
|
if left.IsValid():
|
||||||
|
self._collect(left.Dereference(), nodes)
|
||||||
if index >= len(nodes):
|
if index >= len(nodes):
|
||||||
return None
|
return None
|
||||||
return nodes[index].GetChildMemberWithName('data')
|
data = nodes[index].GetChildMemberWithName('data')
|
||||||
|
return data if data.IsValid() else None
|
||||||
|
|
||||||
def _collect(self, node, out):
|
def _collect(self, node, out):
|
||||||
if not node.IsValid():
|
if not node.IsValid():
|
||||||
return
|
return
|
||||||
self._collect(node.GetChildMemberWithName('leftChild'), out)
|
left = node.GetChildMemberWithName('leftChild')
|
||||||
|
if left.IsValid():
|
||||||
|
self._collect(left.Dereference(), out)
|
||||||
out.append(node)
|
out.append(node)
|
||||||
self._collect(node.GetChildMemberWithName('rightChild'), out)
|
right = node.GetChildMemberWithName('rightChild')
|
||||||
|
if right.IsValid():
|
||||||
|
self._collect(right.Dereference(), out)
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
self.root = self.valobj.GetChildMemberWithName('root')
|
self.pseudoRoot = _member(self.valobj, 'pseudoRoot')
|
||||||
self.size = self.valobj.GetChildMemberWithName('_size').GetValueAsUnsigned(0)
|
size = _member(self.valobj, '_size')
|
||||||
|
self.size = size.GetValueAsUnsigned(0) if size and size.IsValid() else 0
|
||||||
|
|
||||||
def has_children(self):
|
def has_children(self):
|
||||||
return True
|
return self.size > 0
|
||||||
|
|
||||||
def Map_SummaryProvider(valobj, internal_dict):
|
def Map_SummaryProvider(valobj, internal_dict):
|
||||||
size = valobj.GetChildMemberWithName('_size').GetValueAsUnsigned(0)
|
size = _member(valobj, '_size')
|
||||||
return f"Map(size={size})"
|
return f"Map(size={size.GetValueAsUnsigned(0) if size and size.IsValid() else '?'})"
|
||||||
|
|
||||||
class MapSyntheticProvider:
|
class MapSyntheticProvider:
|
||||||
def __init__(self, valobj, internal_dict):
|
def __init__(self, valobj, internal_dict):
|
||||||
@@ -169,24 +209,37 @@ class MapSyntheticProvider:
|
|||||||
if index < 0 or index >= self.size:
|
if index < 0 or index >= self.size:
|
||||||
return None
|
return None
|
||||||
nodes = []
|
nodes = []
|
||||||
self._collect(self.root, nodes)
|
# Start from pseudoRoot: the splay tree's actual structure is
|
||||||
|
# connected via pseudoRoot.leftChild, not the `root` pointer.
|
||||||
|
if self.pseudoRoot and self.pseudoRoot.IsValid():
|
||||||
|
left = self.pseudoRoot.GetChildMemberWithName('leftChild')
|
||||||
|
if left.IsValid():
|
||||||
|
self._collect(left.Dereference(), nodes)
|
||||||
if index >= len(nodes):
|
if index >= len(nodes):
|
||||||
return None
|
return None
|
||||||
return nodes[index].GetChildMemberWithName('data')
|
# Map stores Pair<K, V> in node.data; return the pair so the
|
||||||
|
# debugger can show key/value members (Pair is a plain struct).
|
||||||
|
data = nodes[index].GetChildMemberWithName('data')
|
||||||
|
return data if data.IsValid() else None
|
||||||
|
|
||||||
def _collect(self, node, out):
|
def _collect(self, node, out):
|
||||||
if not node.IsValid():
|
if not node.IsValid():
|
||||||
return
|
return
|
||||||
self._collect(node.GetChildMemberWithName('leftChild'), out)
|
left = node.GetChildMemberWithName('leftChild')
|
||||||
|
if left.IsValid():
|
||||||
|
self._collect(left.Dereference(), out)
|
||||||
out.append(node)
|
out.append(node)
|
||||||
self._collect(node.GetChildMemberWithName('rightChild'), out)
|
right = node.GetChildMemberWithName('rightChild')
|
||||||
|
if right.IsValid():
|
||||||
|
self._collect(right.Dereference(), out)
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
self.root = self.valobj.GetChildMemberWithName('root')
|
self.pseudoRoot = _member(self.valobj, 'pseudoRoot')
|
||||||
self.size = self.valobj.GetChildMemberWithName('_size').GetValueAsUnsigned(0)
|
size = _member(self.valobj, '_size')
|
||||||
|
self.size = size.GetValueAsUnsigned(0) if size and size.IsValid() else 0
|
||||||
|
|
||||||
def has_children(self):
|
def has_children(self):
|
||||||
return True
|
return self.size > 0
|
||||||
|
|
||||||
def Vector_SummaryProvider(valobj, internal_dict):
|
def Vector_SummaryProvider(valobj, internal_dict):
|
||||||
# Get the template parameters to determine vector length
|
# Get the template parameters to determine vector length
|
||||||
|
|||||||
@@ -359,7 +359,9 @@ struct CookTorrance : IBRDF
|
|||||||
const float MAX_REFLECTION_LOD = 4;
|
const float MAX_REFLECTION_LOD = 4;
|
||||||
float3 prefilteredColor = pLightEnv.prefilteredMap.SampleLevel(pLightEnv.irradianceSampler, r, roughness * MAX_REFLECTION_LOD).xyz;
|
float3 prefilteredColor = pLightEnv.prefilteredMap.SampleLevel(pLightEnv.irradianceSampler, r, roughness * MAX_REFLECTION_LOD).xyz;
|
||||||
|
|
||||||
float2 envBRDF = pLightEnv.brdfLUT.Sample(pLightEnv.lutSampler, float2(max(dot(normal, viewDir_WS), 0), roughness)).rg;
|
// brdfLUT has no mip levels and is indexed analytically (N·V, roughness) with no screen
|
||||||
|
// derivatives, so implicit LOD is unavailable (GLCompute/Ray) and meaningless: use level 0.
|
||||||
|
float2 envBRDF = pLightEnv.brdfLUT.SampleLevel(pLightEnv.lutSampler, float2(max(dot(normal, viewDir_WS), 0), roughness), 0).rg;
|
||||||
float3 specular = prefilteredColor * (F * envBRDF.x + envBRDF.y);
|
float3 specular = prefilteredColor * (F * envBRDF.x + envBRDF.y);
|
||||||
|
|
||||||
return (k_d * diffuse + specular) * ambientOcclusion;
|
return (k_d * diffuse + specular) * ambientOcclusion;
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ struct DrawCallOffsets
|
|||||||
};
|
};
|
||||||
#ifdef RAY_TRACING
|
#ifdef RAY_TRACING
|
||||||
// Shader record buffers are accessed via a different mechanism and don't use descriptor set bindings
|
// Shader record buffers are accessed via a different mechanism and don't use descriptor set bindings
|
||||||
layout(set = 15, shaderRecordEXT)
|
layout(shaderRecordEXT)
|
||||||
#else
|
#else
|
||||||
layout(push_constant)
|
layout(push_constant)
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ void miss(inout RayPayload p)
|
|||||||
// p.shading.normal = -WorldRayDirection();
|
// p.shading.normal = -WorldRayDirection();
|
||||||
// p.shading.normalLight = -WorldRayDirection();
|
// p.shading.normalLight = -WorldRayDirection();
|
||||||
// p.material.color = float4(0, 0, 0, 0);
|
// p.material.color = float4(0, 0, 0, 0);
|
||||||
p.light = float3(pRayTracingParams.skyBox.Sample(pRayTracingParams.skyBoxSampler, WorldRayDirection()).xyz);
|
// miss shaders (GLCompute) can't do ImplicitLod (mip) sampling; use a fixed level
|
||||||
|
p.light = float3(pRayTracingParams.skyBox.SampleLevel(pRayTracingParams.skyBoxSampler, WorldRayDirection(), 0).xyz);
|
||||||
p.hit = false;
|
p.hit = false;
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,13 @@
|
|||||||
#include "PlayView.h"
|
#include "PlayView.h"
|
||||||
|
#include "Scene/Scene.h"
|
||||||
#include "Window/Window.h"
|
#include "Window/Window.h"
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
using namespace Seele;
|
using namespace Seele;
|
||||||
|
|
||||||
PlayView::PlayView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo& createInfo, std::string dllPath, bool useMeshCulling)
|
PlayView::PlayView(Gfx::PGraphics graphics, PWindow window, PScene scene, const ViewportCreateInfo& createInfo, bool useMeshCulling)
|
||||||
: GameView(graphics, window, createInfo, dllPath) {
|
: GameView(graphics, window, scene, createInfo) {
|
||||||
getGlobals().useDepthCulling = useMeshCulling;
|
getGlobals().useDepthCulling = useMeshCulling;
|
||||||
renderTimestamp = graphics->createTimestampQuery(2, "RenderTimestamp");
|
renderTimestamp = graphics->createTimestampQuery(2, "RenderTimestamp");
|
||||||
queryThread = std::thread([&]() {
|
queryThread = std::thread([&]() {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
namespace Seele {
|
namespace Seele {
|
||||||
class PlayView : public GameView {
|
class PlayView : public GameView {
|
||||||
public:
|
public:
|
||||||
PlayView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo& createInfo, std::string dllPath, bool useMeshCulling);
|
PlayView(Gfx::PGraphics graphics, PWindow window, PScene scene, const ViewportCreateInfo& createInfo, bool useMeshCulling);
|
||||||
virtual ~PlayView();
|
virtual ~PlayView();
|
||||||
virtual void beginUpdate() override;
|
virtual void beginUpdate() override;
|
||||||
virtual void update() override;
|
virtual void update() override;
|
||||||
|
|||||||
+15
-7
@@ -3,7 +3,9 @@
|
|||||||
#include "Graphics/StaticMeshVertexData.h"
|
#include "Graphics/StaticMeshVertexData.h"
|
||||||
#include "Graphics/Vulkan/Graphics.h"
|
#include "Graphics/Vulkan/Graphics.h"
|
||||||
#include "PlayView.h"
|
#include "PlayView.h"
|
||||||
#include "Window/WindowManager.h"
|
#include "Scene/Scene.h"
|
||||||
|
#include "System/SystemGraph.h"
|
||||||
|
#include "Window/Application.h"
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
#include <random>
|
#include <random>
|
||||||
|
|
||||||
@@ -32,7 +34,14 @@ int main(int argc, char** argv) {
|
|||||||
vd->init(graphics);
|
vd->init(graphics);
|
||||||
getGlobals().useRayTracing = true;
|
getGlobals().useRayTracing = true;
|
||||||
|
|
||||||
OWindowManager windowManager = new WindowManager();
|
// The benchmark is a worldless host: it builds a plain Scene + SystemGraph
|
||||||
|
// (no game binary) and hands ownership to the Application, which then steps
|
||||||
|
// it once per frame and lets the views render it. The view renders the
|
||||||
|
// non-owning application->scene() handle.
|
||||||
|
OApplication application = new Application();
|
||||||
|
OScene scene = new Scene(graphics);
|
||||||
|
OSystemGraph systemGraph = new SystemGraph();
|
||||||
|
application->attachWorld(std::move(scene), std::move(systemGraph));
|
||||||
AssetRegistry::init("Assets", graphics);
|
AssetRegistry::init("Assets", graphics);
|
||||||
vd->commitMeshes();
|
vd->commitMeshes();
|
||||||
WindowCreateInfo mainWindowInfo = {
|
WindowCreateInfo mainWindowInfo = {
|
||||||
@@ -41,7 +50,7 @@ int main(int argc, char** argv) {
|
|||||||
.title = "Benchmark",
|
.title = "Benchmark",
|
||||||
.preferredFormat = Gfx::SE_FORMAT_B8G8R8A8_SRGB,
|
.preferredFormat = Gfx::SE_FORMAT_B8G8R8A8_SRGB,
|
||||||
};
|
};
|
||||||
auto window = windowManager->addWindow(graphics, mainWindowInfo);
|
auto window = application->addWindow(graphics, mainWindowInfo);
|
||||||
ViewportCreateInfo sceneViewInfo = {
|
ViewportCreateInfo sceneViewInfo = {
|
||||||
.dimensions =
|
.dimensions =
|
||||||
{
|
{
|
||||||
@@ -49,11 +58,10 @@ int main(int argc, char** argv) {
|
|||||||
.offset = {0, 0},
|
.offset = {0, 0},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
OGameView sceneView = new PlayView(graphics, window, sceneViewInfo, binaryPath.generic_string(), useDepthCulling);
|
OGameView sceneView = new PlayView(graphics, window, application->scene(), sceneViewInfo, useDepthCulling);
|
||||||
sceneView->setFocused();
|
|
||||||
|
|
||||||
while (windowManager->isActive()) {
|
while (application->isActive()) {
|
||||||
windowManager->render();
|
application->render();
|
||||||
}
|
}
|
||||||
graphics->waitDeviceIdle();
|
graphics->waitDeviceIdle();
|
||||||
vd->destroy();
|
vd->destroy();
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
#include "Graphics/Shader.h"
|
#include "Graphics/Shader.h"
|
||||||
#include "Material/Material.h"
|
#include "Material/Material.h"
|
||||||
#include "Material/ShaderExpression.h"
|
#include "Material/ShaderExpression.h"
|
||||||
#include "Window/WindowManager.h"
|
#include "Window/Application.h"
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|||||||
@@ -3,4 +3,6 @@ add_subdirectory(Window/)
|
|||||||
|
|
||||||
target_sources(Editor
|
target_sources(Editor
|
||||||
PRIVATE
|
PRIVATE
|
||||||
main.cpp)
|
main.cpp
|
||||||
|
ComponentRegistry.h
|
||||||
|
ComponentRegistry.cpp)
|
||||||
@@ -184,9 +184,14 @@ void InspectorView::mouseButtonCallback(MouseButton button, InputAction action,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InspectorView::scrollCallback(double xOffset, double yOffset) {
|
void InspectorView::scrollCallback(double xPos, double yPos, double xScroll, double yScroll) {
|
||||||
|
// The UI system's scroll() currently takes only the delta (no cursor position);
|
||||||
|
// xPos/yPos are the view-local cursor coords, carried for the future the UI system
|
||||||
|
// needs per-element scroll targeting.
|
||||||
|
(void)xPos;
|
||||||
|
(void)yPos;
|
||||||
if (uiPass != nullptr) {
|
if (uiPass != nullptr) {
|
||||||
uiPass->scroll(Vector2(xOffset, yOffset));
|
uiPass->scroll(Vector2(xScroll, yScroll));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ class InspectorView : public View {
|
|||||||
virtual void keyCallback(KeyCode code, InputAction action, uint32_t modifier) override;
|
virtual void keyCallback(KeyCode code, InputAction action, uint32_t modifier) override;
|
||||||
virtual void mouseMoveCallback(double xPos, double yPos) override;
|
virtual void mouseMoveCallback(double xPos, double yPos) override;
|
||||||
virtual void mouseButtonCallback(MouseButton button, InputAction action, uint32_t modifier) override;
|
virtual void mouseButtonCallback(MouseButton button, InputAction action, uint32_t modifier) override;
|
||||||
virtual void scrollCallback(double xOffset, double yOffset) override;
|
virtual void scrollCallback(double xPos, double yPos, double xScroll, double yScroll) override;
|
||||||
virtual void fileCallback(int count, const char** paths) override;
|
virtual void fileCallback(int count, const char** paths) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -7,8 +7,8 @@
|
|||||||
using namespace Seele;
|
using namespace Seele;
|
||||||
using namespace Seele::Editor;
|
using namespace Seele::Editor;
|
||||||
|
|
||||||
PlayView::PlayView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo& createInfo, std::filesystem::path dllPath)
|
PlayView::PlayView(Gfx::PGraphics graphics, PWindow window, PScene scene, const ViewportCreateInfo& createInfo)
|
||||||
: GameView(graphics, window, createInfo, dllPath) {}
|
: GameView(graphics, window, scene, createInfo) {}
|
||||||
|
|
||||||
PlayView::~PlayView() {}
|
PlayView::~PlayView() {}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ namespace Seele {
|
|||||||
namespace Editor {
|
namespace Editor {
|
||||||
class PlayView : public GameView {
|
class PlayView : public GameView {
|
||||||
public:
|
public:
|
||||||
PlayView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo& createInfo, std::filesystem::path dllPath);
|
PlayView(Gfx::PGraphics graphics, PWindow window, PScene scene, const ViewportCreateInfo& createInfo);
|
||||||
virtual ~PlayView();
|
virtual ~PlayView();
|
||||||
virtual void beginUpdate() override;
|
virtual void beginUpdate() override;
|
||||||
virtual void update() override;
|
virtual void update() override;
|
||||||
|
|||||||
@@ -50,6 +50,6 @@ void SceneView::mouseButtonCallback(MouseButton button, InputAction action, KeyM
|
|||||||
cameraSystem.mouseButtonCallback(button, action);
|
cameraSystem.mouseButtonCallback(button, action);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneView::scrollCallback(double, double) {}
|
void SceneView::scrollCallback(double, double, double, double) {}
|
||||||
|
|
||||||
void SceneView::fileCallback(int, const char**) {}
|
void SceneView::fileCallback(int, const char**) {}
|
||||||
@@ -32,7 +32,7 @@ class SceneView : public View {
|
|||||||
virtual void keyCallback(KeyCode code, InputAction action, KeyModifierFlags modifier) override;
|
virtual void keyCallback(KeyCode code, InputAction action, KeyModifierFlags modifier) override;
|
||||||
virtual void mouseMoveCallback(double xPos, double yPos) override;
|
virtual void mouseMoveCallback(double xPos, double yPos) override;
|
||||||
virtual void mouseButtonCallback(MouseButton button, InputAction action, KeyModifierFlags modifier) override;
|
virtual void mouseButtonCallback(MouseButton button, InputAction action, KeyModifierFlags modifier) override;
|
||||||
virtual void scrollCallback(double xOffset, double yOffset) override;
|
virtual void scrollCallback(double xPos, double yPos, double xScroll, double yScroll) override;
|
||||||
virtual void fileCallback(int count, const char** paths) override;
|
virtual void fileCallback(int count, const char** paths) override;
|
||||||
};
|
};
|
||||||
DEFINE_REF(SceneView)
|
DEFINE_REF(SceneView)
|
||||||
|
|||||||
+24
-19
@@ -10,8 +10,13 @@
|
|||||||
#include "Material/Material.h"
|
#include "Material/Material.h"
|
||||||
#include "Graphics/Vulkan/Graphics.h"
|
#include "Graphics/Vulkan/Graphics.h"
|
||||||
#include "Graphics/StaticMeshVertexData.h"
|
#include "Graphics/StaticMeshVertexData.h"
|
||||||
|
#include "System/SystemGraph.h"
|
||||||
#include "Window/PlayView.h"
|
#include "Window/PlayView.h"
|
||||||
#include "Window/WindowManager.h"
|
#include "System/CameraUpdater.h"
|
||||||
|
#include "System/FluidUpdater.h"
|
||||||
|
#include "System/LightGather.h"
|
||||||
|
#include "System/MeshUpdater.h"
|
||||||
|
#include "Window/Application.h"
|
||||||
#include "Window/InspectorView.h"
|
#include "Window/InspectorView.h"
|
||||||
#include "Scene/Scene.h" // OScene/Scene - the InspectorView's entity pane needs a live scene
|
#include "Scene/Scene.h" // OScene/Scene - the InspectorView's entity pane needs a live scene
|
||||||
#include "Component/Transform.h"
|
#include "Component/Transform.h"
|
||||||
@@ -136,7 +141,6 @@ int main(int argc, char** argv) {
|
|||||||
StaticMeshVertexData* vd = StaticMeshVertexData::getInstance();
|
StaticMeshVertexData* vd = StaticMeshVertexData::getInstance();
|
||||||
vd->init(graphics);
|
vd->init(graphics);
|
||||||
|
|
||||||
OWindowManager windowManager = new WindowManager();
|
|
||||||
AssetRegistry::init(sourcePath / "Assets", graphics);
|
AssetRegistry::init(sourcePath / "Assets", graphics);
|
||||||
AssetImporter::init(graphics);
|
AssetImporter::init(graphics);
|
||||||
AssetImporter::importFont(FontImportArgs{
|
AssetImporter::importFont(FontImportArgs{
|
||||||
@@ -164,6 +168,12 @@ int main(int argc, char** argv) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
getThreadPool().waitIdle();
|
getThreadPool().waitIdle();
|
||||||
|
// The world (Scene + SystemGraph) and the game binary are owned by the
|
||||||
|
// Application from here on. `loadGame` dlopen's the .so, lets the game
|
||||||
|
// populate the scene+graph, and appends the editor's own systems. Views
|
||||||
|
// below only render the non-owning application->scene() handle.
|
||||||
|
OApplication application = new Application();
|
||||||
|
application->loadGame(graphics, sourcePath, gameName);
|
||||||
vd->commitMeshes();
|
vd->commitMeshes();
|
||||||
WindowCreateInfo mainWindowInfo = {
|
WindowCreateInfo mainWindowInfo = {
|
||||||
.width = 1920,
|
.width = 1920,
|
||||||
@@ -171,19 +181,15 @@ int main(int argc, char** argv) {
|
|||||||
.title = "SeeleEngine",
|
.title = "SeeleEngine",
|
||||||
.preferredFormat = Gfx::SE_FORMAT_B8G8R8A8_SRGB,
|
.preferredFormat = Gfx::SE_FORMAT_B8G8R8A8_SRGB,
|
||||||
};
|
};
|
||||||
auto window = windowManager->addWindow(graphics, mainWindowInfo);
|
auto window = application->addWindow(graphics, mainWindowInfo);
|
||||||
// ViewportCreateInfo sceneViewInfo = {
|
ViewportCreateInfo sceneViewInfo = {
|
||||||
// .dimensions =
|
.dimensions =
|
||||||
// {
|
{
|
||||||
// .size = {1920, 1080},
|
.size = {1920, 1080},
|
||||||
// .offset = {0, 0},
|
.offset = {0, 0},
|
||||||
// },
|
},
|
||||||
// };
|
};
|
||||||
// OGameView sceneView = new Editor::PlayView(graphics, window, sceneViewInfo, binaryPath);
|
OGameView sceneView = new Editor::PlayView(graphics, window, application->scene(), sceneViewInfo);
|
||||||
// sceneView->setFocused();
|
|
||||||
// The windowed editor path has no pre-existing scene; the InspectorView's entity
|
|
||||||
// pane needs one to enumerate. Create a fresh Scene on the live (windowed) device.
|
|
||||||
OScene scene = new Scene(graphics);
|
|
||||||
OInspectorView inspectorView = new Editor::InspectorView(graphics, window,
|
OInspectorView inspectorView = new Editor::InspectorView(graphics, window,
|
||||||
ViewportCreateInfo{
|
ViewportCreateInfo{
|
||||||
.dimensions =
|
.dimensions =
|
||||||
@@ -192,12 +198,11 @@ int main(int argc, char** argv) {
|
|||||||
.offset = {0, 0},
|
.offset = {0, 0},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
/* scene = */ scene);
|
/* scene = */ application->scene());
|
||||||
|
|
||||||
inspectorView->setFocused();
|
|
||||||
window->show();
|
window->show();
|
||||||
while (windowManager->isActive() && getGlobals().running) {
|
while (application->isActive() && getGlobals().running) {
|
||||||
windowManager->render();
|
application->render();
|
||||||
}
|
}
|
||||||
graphics->waitDeviceIdle();
|
graphics->waitDeviceIdle();
|
||||||
Material::destroy();
|
Material::destroy();
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
#include "FontAsset.h"
|
#include "FontAsset.h"
|
||||||
#include "Graphics/Graphics.h"
|
#include "Graphics/Graphics.h"
|
||||||
#include "Graphics/Mesh.h"
|
#include "Graphics/Mesh.h"
|
||||||
#include "Window/WindowManager.h"
|
#include "Window/Application.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "TextureAsset.h"
|
#include "TextureAsset.h"
|
||||||
#include "Graphics/Graphics.h"
|
#include "Graphics/Graphics.h"
|
||||||
#include "Graphics/Texture.h"
|
#include "Graphics/Texture.h"
|
||||||
#include "Window/WindowManager.h"
|
#include "Window/Application.h"
|
||||||
#include "ktx.h"
|
#include "ktx.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
|||||||
@@ -61,6 +61,10 @@ class Graphics {
|
|||||||
virtual void endRenderPass() = 0;
|
virtual void endRenderPass() = 0;
|
||||||
virtual void waitDeviceIdle() = 0;
|
virtual void waitDeviceIdle() = 0;
|
||||||
|
|
||||||
|
// Invalidate per-render-pass framebuffers cached on resize (their attachments are
|
||||||
|
// recreated each resize). Default no-op; the Vulkan backend overrides it.
|
||||||
|
virtual void invalidateFramebuffers() {}
|
||||||
|
|
||||||
virtual void executeCommands(ORenderCommand commands) = 0;
|
virtual void executeCommands(ORenderCommand commands) = 0;
|
||||||
virtual void executeCommands(Array<ORenderCommand> commands) = 0;
|
virtual void executeCommands(Array<ORenderCommand> commands) = 0;
|
||||||
virtual void executeCommands(OComputeCommand commands) = 0;
|
virtual void executeCommands(OComputeCommand commands) = 0;
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class Window : public Gfx::Window {
|
|||||||
virtual void setKeyCallback(std::function<void(KeyCode, InputAction, KeyModifier)> callback) override;
|
virtual void setKeyCallback(std::function<void(KeyCode, InputAction, KeyModifier)> callback) override;
|
||||||
virtual void setMouseMoveCallback(std::function<void(double, double)> callback) override;
|
virtual void setMouseMoveCallback(std::function<void(double, double)> callback) override;
|
||||||
virtual void setMouseButtonCallback(std::function<void(MouseButton, InputAction, KeyModifier)> callback) override;
|
virtual void setMouseButtonCallback(std::function<void(MouseButton, InputAction, KeyModifier)> callback) override;
|
||||||
virtual void setScrollCallback(std::function<void(double, double)> callback) override;
|
virtual void setScrollCallback(std::function<void(double x, double y, double xScroll, double yScroll)> callback) override;
|
||||||
virtual void setFileCallback(std::function<void(int, const char**)> callback) override;
|
virtual void setFileCallback(std::function<void(int, const char**)> callback) override;
|
||||||
virtual void setCloseCallback(std::function<void()> callback) override;
|
virtual void setCloseCallback(std::function<void()> callback) override;
|
||||||
virtual void setResizeCallback(std::function<void(uint32, uint32)> callback) override;
|
virtual void setResizeCallback(std::function<void(uint32, uint32)> callback) override;
|
||||||
@@ -37,7 +37,7 @@ class Window : public Gfx::Window {
|
|||||||
void keyPress(KeyCode code, InputAction action, KeyModifier modifier);
|
void keyPress(KeyCode code, InputAction action, KeyModifier modifier);
|
||||||
void mouseMove(double x, double y);
|
void mouseMove(double x, double y);
|
||||||
void mouseButton(MouseButton button, InputAction action, KeyModifier modifier);
|
void mouseButton(MouseButton button, InputAction action, KeyModifier modifier);
|
||||||
void scroll(double x, double y);
|
void scroll(double x, double y, double xScroll, double yScroll);
|
||||||
void fileDrop(int num, const char** files);
|
void fileDrop(int num, const char** files);
|
||||||
void close();
|
void close();
|
||||||
void resize(int width, int height);
|
void resize(int width, int height);
|
||||||
@@ -57,7 +57,7 @@ class Window : public Gfx::Window {
|
|||||||
std::function<void(KeyCode, InputAction, KeyModifier)> keyCallback;
|
std::function<void(KeyCode, InputAction, KeyModifier)> keyCallback;
|
||||||
std::function<void(double, double)> mouseMoveCallback;
|
std::function<void(double, double)> mouseMoveCallback;
|
||||||
std::function<void(MouseButton, InputAction, KeyModifier)> mouseButtonCallback;
|
std::function<void(MouseButton, InputAction, KeyModifier)> mouseButtonCallback;
|
||||||
std::function<void(double, double)> scrollCallback;
|
std::function<void(double x, double y, double xScroll, double yScroll)> scrollCallback;
|
||||||
std::function<void(int, const char**)> fileCallback;
|
std::function<void(int, const char**)> fileCallback;
|
||||||
std::function<void()> closeCallback;
|
std::function<void()> closeCallback;
|
||||||
std::function<void(uint32, uint32)> resizeCallback;
|
std::function<void(uint32, uint32)> resizeCallback;
|
||||||
|
|||||||
@@ -44,7 +44,9 @@ void glfwMouseButtonCallback(GLFWwindow* handle, int button, int action, int mod
|
|||||||
|
|
||||||
void glfwScrollCallback(GLFWwindow* handle, double xoffset, double yoffset) {
|
void glfwScrollCallback(GLFWwindow* handle, double xoffset, double yoffset) {
|
||||||
Window* window = (Window*)glfwGetWindowUserPointer(handle);
|
Window* window = (Window*)glfwGetWindowUserPointer(handle);
|
||||||
window->scroll(xoffset, yoffset);
|
double x = 0.0, y = 0.0;
|
||||||
|
glfwGetCursorPos(handle, &x, &y);
|
||||||
|
window->scroll(x, y, xoffset, yoffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
void glfwFileCallback(GLFWwindow* handle, int count, const char** paths) {
|
void glfwFileCallback(GLFWwindow* handle, int count, const char** paths) {
|
||||||
@@ -127,7 +129,7 @@ void Window::setMouseMoveCallback(std::function<void(double, double)> callback)
|
|||||||
|
|
||||||
void Window::setMouseButtonCallback(std::function<void(MouseButton, InputAction, KeyModifier)> callback) { mouseButtonCallback = callback; }
|
void Window::setMouseButtonCallback(std::function<void(MouseButton, InputAction, KeyModifier)> callback) { mouseButtonCallback = callback; }
|
||||||
|
|
||||||
void Window::setScrollCallback(std::function<void(double, double)> callback) { scrollCallback = callback; }
|
void Window::setScrollCallback(std::function<void(double x, double y, double xScroll, double yScroll)> callback) { scrollCallback = callback; }
|
||||||
|
|
||||||
void Window::setFileCallback(std::function<void(int, const char**)> callback) { fileCallback = callback; }
|
void Window::setFileCallback(std::function<void(int, const char**)> callback) { fileCallback = callback; }
|
||||||
|
|
||||||
@@ -141,7 +143,7 @@ void Window::mouseMove(double x, double y) { mouseMoveCallback(x, y); }
|
|||||||
|
|
||||||
void Window::mouseButton(MouseButton button, InputAction action, KeyModifier modifier) { mouseButtonCallback(button, action, modifier); }
|
void Window::mouseButton(MouseButton button, InputAction action, KeyModifier modifier) { mouseButtonCallback(button, action, modifier); }
|
||||||
|
|
||||||
void Window::scroll(double x, double y) { scrollCallback(x, y); }
|
void Window::scroll(double x, double y, double xScroll, double yScroll) { scrollCallback(x, y, xScroll, yScroll); }
|
||||||
|
|
||||||
void Window::fileDrop(int num, const char** files) { fileCallback(num, files); }
|
void Window::fileDrop(int num, const char** files) { fileCallback(num, files); }
|
||||||
|
|
||||||
|
|||||||
@@ -475,32 +475,39 @@ void BasePass::render() {
|
|||||||
void BasePass::endFrame() {}
|
void BasePass::endFrame() {}
|
||||||
|
|
||||||
void BasePass::publishOutputs() {
|
void BasePass::publishOutputs() {
|
||||||
|
// Size intermediates to the *view* (viewport), not the full window framebuffer. A split
|
||||||
|
// window (e.g. the editor's 50/50 game/inspector layout) renders each view into its own
|
||||||
|
// half-width slice; the shared framebuffers must match that slice or the renderArea (the
|
||||||
|
// view's half) ends up a window into an over-wide attachment, clipping the image.
|
||||||
|
uint32 viewWidth = viewport->getWidth();
|
||||||
|
uint32 viewHeight = viewport->getHeight();
|
||||||
|
|
||||||
basePassDepth = graphics->createTexture2D(TextureCreateInfo{
|
basePassDepth = graphics->createTexture2D(TextureCreateInfo{
|
||||||
.format = Gfx::SE_FORMAT_D32_SFLOAT,
|
.format = Gfx::SE_FORMAT_D32_SFLOAT,
|
||||||
.width = viewport->getOwner()->getFramebufferWidth(),
|
.width = viewWidth,
|
||||||
.height = viewport->getOwner()->getFramebufferHeight(),
|
.height = viewHeight,
|
||||||
.usage = Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
|
.usage = Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
|
||||||
});
|
});
|
||||||
|
|
||||||
basePassColor = graphics->createTexture2D(TextureCreateInfo{
|
basePassColor = graphics->createTexture2D(TextureCreateInfo{
|
||||||
.format = Gfx::SE_FORMAT_R32G32B32A32_SFLOAT,
|
.format = Gfx::SE_FORMAT_R32G32B32A32_SFLOAT,
|
||||||
.width = viewport->getOwner()->getFramebufferWidth(),
|
.width = viewWidth,
|
||||||
.height = viewport->getOwner()->getFramebufferHeight(),
|
.height = viewHeight,
|
||||||
.usage = Gfx::SE_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
|
.usage = Gfx::SE_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
|
||||||
});
|
});
|
||||||
|
|
||||||
msBasePassDepth = graphics->createTexture2D(TextureCreateInfo{
|
msBasePassDepth = graphics->createTexture2D(TextureCreateInfo{
|
||||||
.format = Gfx::SE_FORMAT_D32_SFLOAT,
|
.format = Gfx::SE_FORMAT_D32_SFLOAT,
|
||||||
.width = viewport->getOwner()->getFramebufferWidth(),
|
.width = viewWidth,
|
||||||
.height = viewport->getOwner()->getFramebufferHeight(),
|
.height = viewHeight,
|
||||||
.samples = Gfx::SE_SAMPLE_COUNT_4_BIT,
|
.samples = Gfx::SE_SAMPLE_COUNT_4_BIT,
|
||||||
.usage = Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | Gfx::SE_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT,
|
.usage = Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | Gfx::SE_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT,
|
||||||
});
|
});
|
||||||
|
|
||||||
msBasePassColor = graphics->createTexture2D(TextureCreateInfo{
|
msBasePassColor = graphics->createTexture2D(TextureCreateInfo{
|
||||||
.format = Gfx::SE_FORMAT_R32G32B32A32_SFLOAT,
|
.format = Gfx::SE_FORMAT_R32G32B32A32_SFLOAT,
|
||||||
.width = viewport->getOwner()->getFramebufferWidth(),
|
.width = viewWidth,
|
||||||
.height = viewport->getOwner()->getFramebufferHeight(),
|
.height = viewHeight,
|
||||||
.samples = Gfx::SE_SAMPLE_COUNT_4_BIT, // todo: configure
|
.samples = Gfx::SE_SAMPLE_COUNT_4_BIT, // todo: configure
|
||||||
.usage = Gfx::SE_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | Gfx::SE_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT,
|
.usage = Gfx::SE_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | Gfx::SE_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
using namespace Seele;
|
using namespace Seele;
|
||||||
|
|
||||||
UIPass::UIPass(Gfx::PGraphics graphics, UI::PSystem system) : RenderPass(graphics), system(system), passSize(0, 0) {
|
UIPass::UIPass(Gfx::PGraphics graphics, UI::PSystem system) : RenderPass(graphics), system(system) {
|
||||||
elementBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{.name = "RenderStyleElements"});
|
elementBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{.name = "RenderStyleElements"});
|
||||||
|
|
||||||
uiDescriptorLayout = graphics->createDescriptorLayout("pParams");
|
uiDescriptorLayout = graphics->createDescriptorLayout("pParams");
|
||||||
@@ -119,8 +119,8 @@ void UIPass::publishOutputs() {}
|
|||||||
void UIPass::createRenderPass() {
|
void UIPass::createRenderPass() {
|
||||||
TextureCreateInfo depthBufferInfo = {
|
TextureCreateInfo depthBufferInfo = {
|
||||||
.format = Gfx::SE_FORMAT_D32_SFLOAT,
|
.format = Gfx::SE_FORMAT_D32_SFLOAT,
|
||||||
.width = viewport->getWidth(),
|
.width = viewport->getOwner()->getFramebufferWidth(),
|
||||||
.height = viewport->getHeight(),
|
.height = viewport->getOwner()->getFramebufferHeight(),
|
||||||
.usage = Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
|
.usage = Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -134,14 +134,10 @@ void UIPass::createRenderPass() {
|
|||||||
Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
|
Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
|
||||||
colorAttachment.clear.color = {{1.0f, 1.0f, 1.0f, 1.0f}};
|
colorAttachment.clear.color = {{1.0f, 1.0f, 1.0f, 1.0f}};
|
||||||
|
|
||||||
// the render pass encodes the viewport size, and Vulkan requires a fresh pass object when
|
Gfx::RenderTargetLayout layout = Gfx::RenderTargetLayout{
|
||||||
// that changes. Re-run createRenderPass() from beginFrame on a viewport resize; the
|
.colorAttachments = {colorAttachment},
|
||||||
// pipeline is recreated here from scratch (it embeds renderPass and is size-independent
|
.depthAttachment = depthAttachment,
|
||||||
// otherwise).
|
};
|
||||||
if (passSize.x != viewport->getWidth() || passSize.y != viewport->getHeight()) {
|
|
||||||
passSize = UVector2(viewport->getWidth(), viewport->getHeight());
|
|
||||||
createRenderPass();
|
|
||||||
}
|
|
||||||
Array<Gfx::SubPassDependency> dependency = {
|
Array<Gfx::SubPassDependency> dependency = {
|
||||||
{
|
{
|
||||||
.srcSubpass = ~0U,
|
.srcSubpass = ~0U,
|
||||||
|
|||||||
@@ -70,7 +70,6 @@ class UIPass : public RenderPass {
|
|||||||
Gfx::PGraphicsPipeline uiPipeline;
|
Gfx::PGraphicsPipeline uiPipeline;
|
||||||
|
|
||||||
UI::PSystem system;
|
UI::PSystem system;
|
||||||
UVector2 passSize; // last viewport size the render pass was created at; recreate on resize
|
|
||||||
Array<UI::UIRender> renderElements;
|
Array<UI::UIRender> renderElements;
|
||||||
Array<RenderElementStyle> elements;
|
Array<RenderElementStyle> elements;
|
||||||
Gfx::OShaderBuffer elementBuffer;
|
Gfx::OShaderBuffer elementBuffer;
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ void Command::beginRenderPass(PRenderPass renderPass, PFramebuffer framebuffer)
|
|||||||
.pNext = nullptr,
|
.pNext = nullptr,
|
||||||
.renderPass = renderPass->getHandle(),
|
.renderPass = renderPass->getHandle(),
|
||||||
.framebuffer = framebuffer->getHandle(),
|
.framebuffer = framebuffer->getHandle(),
|
||||||
.renderArea = framebuffer->getRenderArea(),
|
.renderArea = renderPass->getRenderArea(),
|
||||||
.clearValueCount = (uint32)renderPass->getClearValueCount(),
|
.clearValueCount = (uint32)renderPass->getClearValueCount(),
|
||||||
.pClearValues = renderPass->getClearValues(),
|
.pClearValues = renderPass->getClearValues(),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -68,10 +68,6 @@ Framebuffer::Framebuffer(PGraphics graphics, PRenderPass renderPass, Gfx::Render
|
|||||||
.layers = 1,
|
.layers = 1,
|
||||||
};
|
};
|
||||||
VK_CHECK(vkCreateFramebuffer(graphics->getDevice(), &createInfo, nullptr, &handle));
|
VK_CHECK(vkCreateFramebuffer(graphics->getDevice(), &createInfo, nullptr, &handle));
|
||||||
renderArea = VkRect2D{
|
|
||||||
.offset = {0, 0},
|
|
||||||
.extent = {width, height},
|
|
||||||
};
|
|
||||||
hash = CRC::Calculate(&description, sizeof(FramebufferDescription), CRC::CRC_32());
|
hash = CRC::Calculate(&description, sizeof(FramebufferDescription), CRC::CRC_32());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,11 +22,9 @@ class Framebuffer {
|
|||||||
virtual ~Framebuffer();
|
virtual ~Framebuffer();
|
||||||
constexpr VkFramebuffer getHandle() const { return handle; }
|
constexpr VkFramebuffer getHandle() const { return handle; }
|
||||||
constexpr uint32 getHash() const { return hash; }
|
constexpr uint32 getHash() const { return hash; }
|
||||||
constexpr VkRect2D getRenderArea() const { return renderArea; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint32 hash;
|
uint32 hash;
|
||||||
VkRect2D renderArea;
|
|
||||||
PGraphics graphics;
|
PGraphics graphics;
|
||||||
VkFramebuffer handle;
|
VkFramebuffer handle;
|
||||||
Gfx::RenderTargetLayout layout;
|
Gfx::RenderTargetLayout layout;
|
||||||
|
|||||||
@@ -234,10 +234,9 @@ Gfx::OViewport Graphics::createViewport(Gfx::PWindow owner, const ViewportCreate
|
|||||||
return new Viewport(owner, viewportInfo);
|
return new Viewport(owner, viewportInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
Gfx::ORenderPass Graphics::createRenderPass(Gfx::RenderTargetLayout layout, Array<Gfx::SubPassDependency> dependencies, URect,
|
Gfx::ORenderPass Graphics::createRenderPass(Gfx::RenderTargetLayout layout, Array<Gfx::SubPassDependency> dependencies, URect renderArea,
|
||||||
std::string name, Array<uint32> viewMasks, Array<uint32> correlationMasks) {
|
std::string name, Array<uint32> viewMasks, Array<uint32> correlationMasks) {
|
||||||
// todo: re-introduce render area to renderpass
|
return new RenderPass(this, std::move(layout), std::move(dependencies), renderArea, name, std::move(viewMasks), std::move(correlationMasks));
|
||||||
return new RenderPass(this, std::move(layout), std::move(dependencies), name, std::move(viewMasks), std::move(correlationMasks));
|
|
||||||
}
|
}
|
||||||
void Graphics::beginRenderPass(Gfx::PRenderPass renderPass) {
|
void Graphics::beginRenderPass(Gfx::PRenderPass renderPass) {
|
||||||
PRenderPass rp = renderPass.cast<RenderPass>();
|
PRenderPass rp = renderPass.cast<RenderPass>();
|
||||||
@@ -263,6 +262,10 @@ void Graphics::waitDeviceIdle() {
|
|||||||
getGraphicsCommands()->refreshCommands();
|
getGraphicsCommands()->refreshCommands();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Graphics::invalidateFramebuffers() {
|
||||||
|
allocatedFramebuffers.clear();
|
||||||
|
}
|
||||||
|
|
||||||
void Graphics::executeCommands(Gfx::ORenderCommand commands) {
|
void Graphics::executeCommands(Gfx::ORenderCommand commands) {
|
||||||
Array<Gfx::ORenderCommand> commandArray;
|
Array<Gfx::ORenderCommand> commandArray;
|
||||||
commandArray.add(std::move(commands));
|
commandArray.add(std::move(commands));
|
||||||
@@ -1009,7 +1012,7 @@ void Graphics::pickPhysicalDevice() {
|
|||||||
shaderFloatControls = true;
|
shaderFloatControls = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rayTracingEnabled = rayTracingPipelineSupport && accelerationStructureSupport && hostOperationsSupport && deviceAddressSupport &&
|
rayTracingEnabled = false && rayTracingPipelineSupport && accelerationStructureSupport && hostOperationsSupport && deviceAddressSupport &&
|
||||||
descriptorIndexingSupport && spirv14Support && shaderFloatControls;
|
descriptorIndexingSupport && spirv14Support && shaderFloatControls;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ class Graphics : public Gfx::Graphics {
|
|||||||
virtual void beginRenderPass(Gfx::PRenderPass renderPass) override;
|
virtual void beginRenderPass(Gfx::PRenderPass renderPass) override;
|
||||||
virtual void endRenderPass() override;
|
virtual void endRenderPass() override;
|
||||||
virtual void waitDeviceIdle() override;
|
virtual void waitDeviceIdle() override;
|
||||||
|
virtual void invalidateFramebuffers() override;
|
||||||
|
|
||||||
virtual void executeCommands(Gfx::ORenderCommand commands) override;
|
virtual void executeCommands(Gfx::ORenderCommand commands) override;
|
||||||
virtual void executeCommands(Array<Gfx::ORenderCommand> commands) override;
|
virtual void executeCommands(Array<Gfx::ORenderCommand> commands) override;
|
||||||
|
|||||||
@@ -9,9 +9,13 @@
|
|||||||
using namespace Seele;
|
using namespace Seele;
|
||||||
using namespace Seele::Vulkan;
|
using namespace Seele::Vulkan;
|
||||||
|
|
||||||
RenderPass::RenderPass(PGraphics graphics, Gfx::RenderTargetLayout _layout, Array<Gfx::SubPassDependency> _dependencies, std::string name,
|
RenderPass::RenderPass(PGraphics graphics, Gfx::RenderTargetLayout _layout, Array<Gfx::SubPassDependency> _dependencies, URect _renderArea, std::string name,
|
||||||
Array<uint32> viewMasks, Array<uint32> correlationMasks)
|
Array<uint32> viewMasks, Array<uint32> correlationMasks)
|
||||||
: Gfx::RenderPass(std::move(_layout), std::move(_dependencies)), graphics(graphics), name(name) {
|
: Gfx::RenderPass(std::move(_layout), std::move(_dependencies)), graphics(graphics), name(name) {
|
||||||
|
renderArea = {
|
||||||
|
.offset = { (int32)_renderArea.offset.x, (int32)_renderArea.offset.y },
|
||||||
|
.extent = { _renderArea.size.x, _renderArea.size.y },
|
||||||
|
};
|
||||||
subpassContents = VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS;
|
subpassContents = VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS;
|
||||||
Array<VkAttachmentDescription2> attachments;
|
Array<VkAttachmentDescription2> attachments;
|
||||||
Array<VkAttachmentReference2> inputRefs;
|
Array<VkAttachmentReference2> inputRefs;
|
||||||
|
|||||||
@@ -2,13 +2,14 @@
|
|||||||
#include "Graphics.h"
|
#include "Graphics.h"
|
||||||
#include "Resources.h"
|
#include "Resources.h"
|
||||||
#include "Graphics/RenderTarget.h"
|
#include "Graphics/RenderTarget.h"
|
||||||
|
#include <vulkan/vulkan_core.h>
|
||||||
|
|
||||||
namespace Seele {
|
namespace Seele {
|
||||||
namespace Vulkan {
|
namespace Vulkan {
|
||||||
|
|
||||||
class RenderPass : public Gfx::RenderPass {
|
class RenderPass : public Gfx::RenderPass {
|
||||||
public:
|
public:
|
||||||
RenderPass(PGraphics graphics, Gfx::RenderTargetLayout layout, Array<Gfx::SubPassDependency> dependencies, std::string name,
|
RenderPass(PGraphics graphics, Gfx::RenderTargetLayout layout, Array<Gfx::SubPassDependency> dependencies, URect renderArea, std::string name,
|
||||||
Array<uint32> viewMasks = {}, Array<uint32> correlationMasks = {});
|
Array<uint32> viewMasks = {}, Array<uint32> correlationMasks = {});
|
||||||
virtual ~RenderPass();
|
virtual ~RenderPass();
|
||||||
uint32 getFramebufferHash();
|
uint32 getFramebufferHash();
|
||||||
@@ -17,6 +18,7 @@ class RenderPass : public Gfx::RenderPass {
|
|||||||
constexpr size_t getClearValueCount() const { return clearValues.size(); }
|
constexpr size_t getClearValueCount() const { return clearValues.size(); }
|
||||||
constexpr VkClearValue* getClearValues() const { return clearValues.data(); }
|
constexpr VkClearValue* getClearValues() const { return clearValues.data(); }
|
||||||
constexpr VkSubpassContents getSubpassContents() const { return subpassContents; }
|
constexpr VkSubpassContents getSubpassContents() const { return subpassContents; }
|
||||||
|
constexpr VkRect2D getRenderArea() const { return renderArea; }
|
||||||
constexpr const std::string& getName() const { return name; }
|
constexpr const std::string& getName() const { return name; }
|
||||||
constexpr PRenderPassHandle getCommandHandle() const { return renderPass; }
|
constexpr PRenderPassHandle getCommandHandle() const { return renderPass; }
|
||||||
|
|
||||||
|
|||||||
@@ -107,7 +107,12 @@ void glfwMouseButtonCallback(GLFWwindow* handle, int button, int action, int mod
|
|||||||
|
|
||||||
void glfwScrollCallback(GLFWwindow* handle, double xoffset, double yoffset) {
|
void glfwScrollCallback(GLFWwindow* handle, double xoffset, double yoffset) {
|
||||||
auto* window = static_cast<Seele::Vulkan::Window*>(glfwGetWindowUserPointer(handle));
|
auto* window = static_cast<Seele::Vulkan::Window*>(glfwGetWindowUserPointer(handle));
|
||||||
window->scroll(xoffset, yoffset);
|
// GLFW's scroll callback does NOT give the cursor position, but per-view routing
|
||||||
|
// needs it (scroll is spatial, like a mouse move). Query the current cursor pos
|
||||||
|
// synchronously — it is stable between events and this is the only source we have.
|
||||||
|
double x = 0.0, y = 0.0;
|
||||||
|
glfwGetCursorPos(handle, &x, &y);
|
||||||
|
window->scroll(x, y, xoffset, yoffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
void glfwFileCallback(GLFWwindow* handle, int count, const char** paths) {
|
void glfwFileCallback(GLFWwindow* handle, int count, const char** paths) {
|
||||||
@@ -257,7 +262,7 @@ void Seele::Vulkan::Window::setMouseMoveCallback(std::function<void(double, doub
|
|||||||
|
|
||||||
void Seele::Vulkan::Window::setMouseButtonCallback(std::function<void(MouseButton, InputAction, KeyModifierFlags)> callback) { mouseButtonCallback = callback; }
|
void Seele::Vulkan::Window::setMouseButtonCallback(std::function<void(MouseButton, InputAction, KeyModifierFlags)> callback) { mouseButtonCallback = callback; }
|
||||||
|
|
||||||
void Seele::Vulkan::Window::setScrollCallback(std::function<void(double, double)> callback) { scrollCallback = callback; }
|
void Seele::Vulkan::Window::setScrollCallback(std::function<void(double x, double y, double xScroll, double yScroll)> callback) { scrollCallback = callback; }
|
||||||
|
|
||||||
void Seele::Vulkan::Window::setFileCallback(std::function<void(int, const char**)> callback) { fileCallback = callback; }
|
void Seele::Vulkan::Window::setFileCallback(std::function<void(int, const char**)> callback) { fileCallback = callback; }
|
||||||
|
|
||||||
@@ -271,7 +276,7 @@ void Seele::Vulkan::Window::mouseMove(double x, double y) { mouseMoveCallback(x,
|
|||||||
|
|
||||||
void Seele::Vulkan::Window::mouseButton(MouseButton button, InputAction action, KeyModifierFlags modifier) { mouseButtonCallback(button, action, modifier); }
|
void Seele::Vulkan::Window::mouseButton(MouseButton button, InputAction action, KeyModifierFlags modifier) { mouseButtonCallback(button, action, modifier); }
|
||||||
|
|
||||||
void Seele::Vulkan::Window::scroll(double x, double y) { scrollCallback(x, y); }
|
void Seele::Vulkan::Window::scroll(double x, double y, double xScroll, double yScroll) { scrollCallback(x, y, xScroll, yScroll); }
|
||||||
|
|
||||||
void Seele::Vulkan::Window::fileDrop(int num, const char** files) { fileCallback(num, files); }
|
void Seele::Vulkan::Window::fileDrop(int num, const char** files) { fileCallback(num, files); }
|
||||||
|
|
||||||
@@ -291,6 +296,12 @@ void Seele::Vulkan::Window::resize(int width, int height) {
|
|||||||
framebufferWidth = extent.width;
|
framebufferWidth = extent.width;
|
||||||
framebufferHeight = extent.height;
|
framebufferHeight = extent.height;
|
||||||
createSwapChain();
|
createSwapChain();
|
||||||
|
// The swapchain size changed and the views will be re-laid-out by resizeCallback below,
|
||||||
|
// which rebuilds each pass's intermediate textures at the new (view) size. Any cached
|
||||||
|
// framebuffers from the previous size are now stale (their handle-only hash also changed)
|
||||||
|
// and must be dropped before the next render, or the pass would bind an over-wide
|
||||||
|
// framebuffer whose renderArea is a sub-slice of it.
|
||||||
|
graphics->invalidateFramebuffers();
|
||||||
resizeCallback(width, height);
|
resizeCallback(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ class Window : public Gfx::Window {
|
|||||||
virtual void setKeyCallback(std::function<void(KeyCode, InputAction, KeyModifierFlags)> callback) override;
|
virtual void setKeyCallback(std::function<void(KeyCode, InputAction, KeyModifierFlags)> callback) override;
|
||||||
virtual void setMouseMoveCallback(std::function<void(double, double)> callback) override;
|
virtual void setMouseMoveCallback(std::function<void(double, double)> callback) override;
|
||||||
virtual void setMouseButtonCallback(std::function<void(MouseButton, InputAction, KeyModifierFlags)> callback) override;
|
virtual void setMouseButtonCallback(std::function<void(MouseButton, InputAction, KeyModifierFlags)> callback) override;
|
||||||
virtual void setScrollCallback(std::function<void(double, double)> callback) override;
|
virtual void setScrollCallback(std::function<void(double x, double y, double xScroll, double yScroll)> callback) override;
|
||||||
virtual void setFileCallback(std::function<void(int, const char**)> callback) override;
|
virtual void setFileCallback(std::function<void(int, const char**)> callback) override;
|
||||||
virtual void setCloseCallback(std::function<void()> callback) override;
|
virtual void setCloseCallback(std::function<void()> callback) override;
|
||||||
virtual void setResizeCallback(std::function<void(uint32, uint32)> callback) override;
|
virtual void setResizeCallback(std::function<void(uint32, uint32)> callback) override;
|
||||||
@@ -28,7 +28,7 @@ class Window : public Gfx::Window {
|
|||||||
void keyPress(KeyCode code, InputAction action, KeyModifierFlags modifier);
|
void keyPress(KeyCode code, InputAction action, KeyModifierFlags modifier);
|
||||||
void mouseMove(double x, double y);
|
void mouseMove(double x, double y);
|
||||||
void mouseButton(MouseButton button, InputAction action, KeyModifierFlags modifier);
|
void mouseButton(MouseButton button, InputAction action, KeyModifierFlags modifier);
|
||||||
void scroll(double x, double y);
|
void scroll(double x, double y, double xScroll, double yScroll);
|
||||||
void fileDrop(int num, const char** files);
|
void fileDrop(int num, const char** files);
|
||||||
void close();
|
void close();
|
||||||
void resize(int width, int height);
|
void resize(int width, int height);
|
||||||
@@ -64,7 +64,7 @@ class Window : public Gfx::Window {
|
|||||||
std::function<void(KeyCode, InputAction, KeyModifierFlags)> keyCallback;
|
std::function<void(KeyCode, InputAction, KeyModifierFlags)> keyCallback;
|
||||||
std::function<void(double, double)> mouseMoveCallback;
|
std::function<void(double, double)> mouseMoveCallback;
|
||||||
std::function<void(MouseButton, InputAction, KeyModifierFlags)> mouseButtonCallback;
|
std::function<void(MouseButton, InputAction, KeyModifierFlags)> mouseButtonCallback;
|
||||||
std::function<void(double, double)> scrollCallback;
|
std::function<void(double x, double y, double xScroll, double yScroll)> scrollCallback;
|
||||||
std::function<void(int, const char**)> fileCallback;
|
std::function<void(int, const char**)> fileCallback;
|
||||||
std::function<void()> closeCallback;
|
std::function<void()> closeCallback;
|
||||||
std::function<void(uint32, uint32)> resizeCallback;
|
std::function<void(uint32, uint32)> resizeCallback;
|
||||||
|
|||||||
@@ -18,7 +18,10 @@ class Window {
|
|||||||
virtual void setKeyCallback(std::function<void(KeyCode, InputAction, KeyModifierFlags)> callback) = 0;
|
virtual void setKeyCallback(std::function<void(KeyCode, InputAction, KeyModifierFlags)> callback) = 0;
|
||||||
virtual void setMouseMoveCallback(std::function<void(double, double)> callback) = 0;
|
virtual void setMouseMoveCallback(std::function<void(double, double)> callback) = 0;
|
||||||
virtual void setMouseButtonCallback(std::function<void(MouseButton, InputAction, KeyModifierFlags)> callback) = 0;
|
virtual void setMouseButtonCallback(std::function<void(MouseButton, InputAction, KeyModifierFlags)> callback) = 0;
|
||||||
virtual void setScrollCallback(std::function<void(double, double)> callback) = 0;
|
// The scroll callback carries the cursor POSITION (x, y) in addition to the scroll
|
||||||
|
// deltas. Position is required for per-view routing (a scroll is a spatial event,
|
||||||
|
// exactly like a mouse move).
|
||||||
|
virtual void setScrollCallback(std::function<void(double x, double y, double xScroll, double yScroll)> callback) = 0;
|
||||||
virtual void setFileCallback(std::function<void(int, const char**)> callback) = 0;
|
virtual void setFileCallback(std::function<void(int, const char**)> callback) = 0;
|
||||||
virtual void setCloseCallback(std::function<void()> callback) = 0;
|
virtual void setCloseCallback(std::function<void()> callback) = 0;
|
||||||
virtual void setResizeCallback(std::function<void(uint32, uint32)> callback) = 0;
|
virtual void setResizeCallback(std::function<void(uint32, uint32)> callback) = 0;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include "Graphics/Shader.h"
|
#include "Graphics/Shader.h"
|
||||||
#include "MaterialInstance.h"
|
#include "MaterialInstance.h"
|
||||||
#include "Serialization/Serialization.h"
|
#include "Serialization/Serialization.h"
|
||||||
#include "Window/WindowManager.h"
|
#include "Window/Application.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
using namespace Seele;
|
using namespace Seele;
|
||||||
|
|||||||
@@ -13,6 +13,13 @@ struct Rect {
|
|||||||
struct URect {
|
struct URect {
|
||||||
UVector2 size = UVector2(0);
|
UVector2 size = UVector2(0);
|
||||||
UVector2 offset = UVector2(0);
|
UVector2 offset = UVector2(0);
|
||||||
|
// Half-open containment test for a window/client-space point (used for per-view input
|
||||||
|
// hit-testing). Right/bottom edges are exclusive, matching how the column layout in
|
||||||
|
// Window::onResize tiles the window without seams or double-hits at shared edges.
|
||||||
|
bool contains(double x, double y) const {
|
||||||
|
return x >= static_cast<double>(offset.x) && x < static_cast<double>(offset.x + size.x) &&
|
||||||
|
y >= static_cast<double>(offset.y) && y < static_cast<double>(offset.y + size.y);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
struct Rect3D {
|
struct Rect3D {
|
||||||
Vector size = Vector(0);
|
Vector size = Vector(0);
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ target_sources(Engine
|
|||||||
FlexLayout.cpp
|
FlexLayout.cpp
|
||||||
System.h
|
System.h
|
||||||
System.cpp
|
System.cpp
|
||||||
|
Widgets.h
|
||||||
)
|
)
|
||||||
|
|
||||||
target_sources(Engine
|
target_sources(Engine
|
||||||
@@ -16,6 +17,7 @@ target_sources(Engine
|
|||||||
Element.h
|
Element.h
|
||||||
FlexLayout.h
|
FlexLayout.h
|
||||||
System.h
|
System.h
|
||||||
|
Widgets.h
|
||||||
)
|
)
|
||||||
|
|
||||||
add_subdirectory(Style/)
|
add_subdirectory(Style/)
|
||||||
|
|||||||
@@ -0,0 +1,90 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "UI/Element/Div.h"
|
||||||
|
#include "UI/Element/Text.h"
|
||||||
|
#include "UI/Style/Class.h"
|
||||||
|
|
||||||
|
namespace Seele {
|
||||||
|
namespace UI {
|
||||||
|
// An accordion: a collapsible section with a header that toggles the body.
|
||||||
|
// HTML analog: <details><summary>
|
||||||
|
//
|
||||||
|
// The Accordion is a vertical container with a header (a clickable label)
|
||||||
|
// and a body (arbitrary children). The body's visibility is toggled by the
|
||||||
|
// owning view in response to the header's onClick. The Accordion itself does
|
||||||
|
// not track open/closed state — the view does.
|
||||||
|
//
|
||||||
|
// Usage:
|
||||||
|
// auto* header = new Text<Font_Arial, Text_SM>("Section Title");
|
||||||
|
// auto* body = new Div<FlexCol>(UI::Attributes{});
|
||||||
|
// auto* acc = new Accordion<>(UI::Attributes{}, OElement(header), OElement(body));
|
||||||
|
// // The view owns the "open" state and toggles body's visibility:
|
||||||
|
// // if (clicked) { bodyVisible = !bodyVisible; acc->setBodyVisible(bodyVisible); }
|
||||||
|
template<StyleClass... classes>
|
||||||
|
class Accordion : public Div<classes...> {
|
||||||
|
public:
|
||||||
|
using Div<classes...>::attr;
|
||||||
|
using Div<classes...>::style;
|
||||||
|
using Div<classes...>::markDirty;
|
||||||
|
using Div<classes...>::getTheme;
|
||||||
|
using Div<classes...>::children;
|
||||||
|
|
||||||
|
Accordion(Attributes attr, OElement header, OElement body)
|
||||||
|
: Div<classes...>(std::move(attr), std::initializer_list<OElement>{}) {
|
||||||
|
_header = PElement(header);
|
||||||
|
_body = PElement(body);
|
||||||
|
|
||||||
|
children.add(std::move(header));
|
||||||
|
children.add(std::move(body));
|
||||||
|
if (children.size() >= 2) {
|
||||||
|
children.back()->setParent(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
style.backgroundColor = Vector(0.10f, 0.10f, 0.12f);
|
||||||
|
style.gap = 0;
|
||||||
|
|
||||||
|
if (_header != nullptr) {
|
||||||
|
auto* h = _header.getHandle();
|
||||||
|
if (h != nullptr) {
|
||||||
|
auto& hs = h->getStyle();
|
||||||
|
hs.backgroundColor = Vector(0.14f, 0.14f, 0.16f);
|
||||||
|
hs.paddingLeft = 12;
|
||||||
|
hs.paddingRight = 12;
|
||||||
|
hs.paddingTop = 8;
|
||||||
|
hs.paddingBottom = 8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
virtual ~Accordion() override {}
|
||||||
|
|
||||||
|
void setBodyVisible(bool visible) {
|
||||||
|
if (_body != nullptr) {
|
||||||
|
auto* b = _body.getHandle();
|
||||||
|
if (b != nullptr) {
|
||||||
|
b->getStyle().display = visible ? Display::Flex : Display::Hidden;
|
||||||
|
b->markDirty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bool isBodyVisible() const {
|
||||||
|
if (_body == nullptr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
auto* b = _body.getHandle();
|
||||||
|
return b != nullptr && b->getStyle().display == Display::Flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
PElement getHeader() const { return _header; }
|
||||||
|
PElement getBody() const { return _body; }
|
||||||
|
|
||||||
|
void applyStyle(Style parentStyle, const Theme& theme) override {
|
||||||
|
Div<classes...>::applyStyle(parentStyle, theme);
|
||||||
|
style.backgroundColor = Vector(0.10f, 0.10f, 0.12f);
|
||||||
|
style.gap = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
PElement _header;
|
||||||
|
PElement _body;
|
||||||
|
};
|
||||||
|
} // namespace UI
|
||||||
|
} // namespace Seele
|
||||||
@@ -4,6 +4,17 @@ target_sources(Engine
|
|||||||
Text.h
|
Text.h
|
||||||
Button.h
|
Button.h
|
||||||
Panel.h
|
Panel.h
|
||||||
|
Checkbox.h
|
||||||
|
ToggleSwitch.h
|
||||||
|
Radio.h
|
||||||
|
SelectBox.h
|
||||||
|
InputField.h
|
||||||
|
Slider.h
|
||||||
|
Progressbar.h
|
||||||
|
TabBar.h
|
||||||
|
Tooltip.h
|
||||||
|
Accordion.h
|
||||||
|
HR.h
|
||||||
)
|
)
|
||||||
|
|
||||||
target_sources(Engine
|
target_sources(Engine
|
||||||
@@ -13,4 +24,15 @@ target_sources(Engine
|
|||||||
Text.h
|
Text.h
|
||||||
Button.h
|
Button.h
|
||||||
Panel.h
|
Panel.h
|
||||||
|
Checkbox.h
|
||||||
|
ToggleSwitch.h
|
||||||
|
Radio.h
|
||||||
|
SelectBox.h
|
||||||
|
InputField.h
|
||||||
|
Slider.h
|
||||||
|
Progressbar.h
|
||||||
|
TabBar.h
|
||||||
|
Tooltip.h
|
||||||
|
Accordion.h
|
||||||
|
HR.h
|
||||||
)
|
)
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "UI/Element/Div.h"
|
||||||
|
#include "UI/Style/Class.h"
|
||||||
|
|
||||||
|
namespace Seele {
|
||||||
|
namespace UI {
|
||||||
|
// A checkbox: a square indicator + optional label.
|
||||||
|
// HTML analog: <input type="checkbox">
|
||||||
|
//
|
||||||
|
// Usage:
|
||||||
|
// auto* cb = new Checkbox<>();
|
||||||
|
// // per-frame: cb->setChecked(viewState.flag)
|
||||||
|
//
|
||||||
|
// Pure display widget. The view drives checked state via setChecked().
|
||||||
|
// The checkbox does NOT handle its own onClick — the view wires the
|
||||||
|
// toggle logic via attr.onClick on the owning container.
|
||||||
|
template<StyleClass... classes>
|
||||||
|
class Checkbox : public Div<classes...> {
|
||||||
|
public:
|
||||||
|
using Div<classes...>::attr;
|
||||||
|
using Div<classes...>::style;
|
||||||
|
using Div<classes...>::markDirty;
|
||||||
|
using Div<classes...>::getTheme;
|
||||||
|
using Div<classes...>::children;
|
||||||
|
|
||||||
|
Checkbox(Attributes attr = Attributes{}, std::initializer_list<OElement> children = {})
|
||||||
|
: Div<classes...>(std::move(attr), children) {
|
||||||
|
style.height = 20;
|
||||||
|
style.width = 20;
|
||||||
|
}
|
||||||
|
virtual ~Checkbox() override {}
|
||||||
|
|
||||||
|
void setChecked(bool checked) {
|
||||||
|
_checked = checked;
|
||||||
|
markDirty();
|
||||||
|
}
|
||||||
|
bool isChecked() const { return _checked; }
|
||||||
|
|
||||||
|
void setHovered(bool hovered) override { _hovered = hovered; }
|
||||||
|
void setFocused(bool focused) override { _focused = focused; }
|
||||||
|
bool isFocusable() const override { return attr.focusable; }
|
||||||
|
|
||||||
|
void applyStyle(Style parentStyle, const Theme& theme) override {
|
||||||
|
Div<classes...>::applyStyle(parentStyle, theme);
|
||||||
|
}
|
||||||
|
|
||||||
|
// The System calls applyOverrides() during style() after applyStyle.
|
||||||
|
// We use it to reflect checked/hover/focus in the background color.
|
||||||
|
void applyOverrides() override {
|
||||||
|
const Theme& th = getTheme();
|
||||||
|
if (_checked) {
|
||||||
|
style.backgroundColor = th.color(ColorToken::Green);
|
||||||
|
} else if (_hovered) {
|
||||||
|
style.backgroundColor = Vector(0.22f, 0.24f, 0.28f);
|
||||||
|
} else if (_focused) {
|
||||||
|
style.backgroundColor = Vector(0.20f, 0.22f, 0.26f);
|
||||||
|
} else {
|
||||||
|
style.backgroundColor = Vector(0.14f, 0.14f, 0.16f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool _checked = false;
|
||||||
|
bool _hovered = false;
|
||||||
|
bool _focused = false;
|
||||||
|
};
|
||||||
|
} // namespace UI
|
||||||
|
} // namespace Seele
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "UI/Element/Div.h"
|
||||||
|
#include "UI/Style/Class.h"
|
||||||
|
|
||||||
|
namespace Seele {
|
||||||
|
namespace UI {
|
||||||
|
// A horizontal rule: a thin decorative divider line.
|
||||||
|
// HTML analog: <hr>
|
||||||
|
//
|
||||||
|
// A simple 1px tall element with a subtle background color. No interactivity.
|
||||||
|
template<StyleClass... classes>
|
||||||
|
class HR : public Div<classes...> {
|
||||||
|
public:
|
||||||
|
using Div<classes...>::attr;
|
||||||
|
using Div<classes...>::style;
|
||||||
|
|
||||||
|
HR(Attributes attr = Attributes{}, std::initializer_list<OElement> children = {})
|
||||||
|
: Div<classes...>(std::move(attr), children) {
|
||||||
|
style.height = 1;
|
||||||
|
style.backgroundColor = Vector(0.25f, 0.25f, 0.28f);
|
||||||
|
style.marginTop = 8;
|
||||||
|
style.marginBottom = 8;
|
||||||
|
}
|
||||||
|
virtual ~HR() override {}
|
||||||
|
|
||||||
|
void applyStyle(Style parentStyle, const Theme& theme) override {
|
||||||
|
Div<classes...>::applyStyle(parentStyle, theme);
|
||||||
|
style.height = 1;
|
||||||
|
style.backgroundColor = Vector(0.25f, 0.25f, 0.28f);
|
||||||
|
style.marginTop = 8;
|
||||||
|
style.marginBottom = 8;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} // namespace UI
|
||||||
|
} // namespace Seele
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "UI/Element/Div.h"
|
||||||
|
#include "UI/Element/Text.h"
|
||||||
|
#include "UI/Style/Class.h"
|
||||||
|
|
||||||
|
namespace Seele {
|
||||||
|
namespace UI {
|
||||||
|
// A text input field: a box that displays a placeholder (when empty) or a
|
||||||
|
// text value (when non-empty). The actual text editing (key handling, cursor,
|
||||||
|
// IME) is the owning view's responsibility — the view intercepts key events
|
||||||
|
// and calls setValue() with the updated text.
|
||||||
|
//
|
||||||
|
// HTML analog: <input type="text">
|
||||||
|
//
|
||||||
|
// Usage:
|
||||||
|
// auto* field = new InputField<Font_Arial, Text_SM>(UI::Attributes{}, "Enter name...");
|
||||||
|
// // per-frame: field->setValue(viewState.inputText);
|
||||||
|
template<StyleClass... classes>
|
||||||
|
class InputField : public Div<classes...> {
|
||||||
|
public:
|
||||||
|
using Div<classes...>::attr;
|
||||||
|
using Div<classes...>::style;
|
||||||
|
using Div<classes...>::markDirty;
|
||||||
|
using Div<classes...>::getTheme;
|
||||||
|
using Div<classes...>::children;
|
||||||
|
|
||||||
|
InputField(Attributes attr, std::string placeholder = "")
|
||||||
|
: Div<classes...>(std::move(attr), std::initializer_list<OElement>{}) {
|
||||||
|
attr.focusable = true;
|
||||||
|
_placeholder = std::move(placeholder);
|
||||||
|
|
||||||
|
auto* t = new Text<classes...>(_placeholder);
|
||||||
|
children.add(OElement(t));
|
||||||
|
children.back()->setParent(this);
|
||||||
|
_text = PElement(t);
|
||||||
|
|
||||||
|
style.paddingLeft = 12;
|
||||||
|
style.paddingRight = 12;
|
||||||
|
style.paddingTop = 8;
|
||||||
|
style.paddingBottom = 8;
|
||||||
|
style.backgroundColor = Vector(0.10f, 0.10f, 0.12f);
|
||||||
|
}
|
||||||
|
virtual ~InputField() override {}
|
||||||
|
|
||||||
|
void setValue(std::string value) {
|
||||||
|
_value = std::move(value);
|
||||||
|
markDirty();
|
||||||
|
}
|
||||||
|
std::string getValue() const { return _value; }
|
||||||
|
std::string getPlaceholder() const { return _placeholder; }
|
||||||
|
|
||||||
|
void setFocused(bool focused) override {
|
||||||
|
_focused = focused;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setHovered(bool hovered) override { _hovered = hovered; }
|
||||||
|
bool isFocusable() const override { return attr.focusable; }
|
||||||
|
|
||||||
|
void applyStyle(Style parentStyle, const Theme& theme) override {
|
||||||
|
Div<classes...>::applyStyle(parentStyle, theme);
|
||||||
|
}
|
||||||
|
|
||||||
|
void applyOverrides() override {
|
||||||
|
const Theme& th = getTheme();
|
||||||
|
if (_focused) {
|
||||||
|
style.backgroundColor = Vector(0.14f, 0.15f, 0.18f);
|
||||||
|
} else if (_hovered) {
|
||||||
|
style.backgroundColor = Vector(0.12f, 0.12f, 0.14f);
|
||||||
|
} else {
|
||||||
|
style.backgroundColor = Vector(0.10f, 0.10f, 0.12f);
|
||||||
|
}
|
||||||
|
// Switch between placeholder (dimmed) and value (full color) display.
|
||||||
|
if (_text == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto* t = dynamic_cast<Text<classes...>*>(_text.getHandle());
|
||||||
|
if (t == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (_value.empty()) {
|
||||||
|
t->setText(_placeholder);
|
||||||
|
style.textColor = th.color(ColorToken::Gray600);
|
||||||
|
} else {
|
||||||
|
t->setText(_value);
|
||||||
|
style.textColor = th.color(ColorToken::White);
|
||||||
|
}
|
||||||
|
markDirty();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string _placeholder;
|
||||||
|
std::string _value;
|
||||||
|
bool _focused = false;
|
||||||
|
bool _hovered = false;
|
||||||
|
PElement _text;
|
||||||
|
};
|
||||||
|
} // namespace UI
|
||||||
|
} // namespace Seele
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "UI/Element/Div.h"
|
||||||
|
#include "UI/Style/Class.h"
|
||||||
|
|
||||||
|
namespace Seele {
|
||||||
|
namespace UI {
|
||||||
|
// A progress bar: a horizontal bar that fills proportionally to a 0.0-1.0 value.
|
||||||
|
// HTML analog: <progress>
|
||||||
|
//
|
||||||
|
// Usage:
|
||||||
|
// auto* bar = new Progressbar<>();
|
||||||
|
// // per-frame: bar->setValue(fraction) // 0.0 - 1.0
|
||||||
|
//
|
||||||
|
// Pure display widget. The bar's background is a lerp between a dimmed
|
||||||
|
// "empty" color and an accent "full" color, giving a visual fill effect.
|
||||||
|
template<StyleClass... classes>
|
||||||
|
class Progressbar : public Div<classes...> {
|
||||||
|
public:
|
||||||
|
using Div<classes...>::attr;
|
||||||
|
using Div<classes...>::style;
|
||||||
|
using Div<classes...>::markDirty;
|
||||||
|
using Div<classes...>::getTheme;
|
||||||
|
|
||||||
|
Progressbar(Attributes attr = Attributes{}, std::initializer_list<OElement> children = {})
|
||||||
|
: Div<classes...>(std::move(attr), children) {
|
||||||
|
style.height = 8;
|
||||||
|
}
|
||||||
|
virtual ~Progressbar() override {}
|
||||||
|
|
||||||
|
void setValue(float value) {
|
||||||
|
_value = value < 0.0f ? 0.0f : (value > 1.0f ? 1.0f : value);
|
||||||
|
markDirty();
|
||||||
|
}
|
||||||
|
float getValue() const { return _value; }
|
||||||
|
|
||||||
|
void applyStyle(Style parentStyle, const Theme& theme) override {
|
||||||
|
Div<classes...>::applyStyle(parentStyle, theme);
|
||||||
|
}
|
||||||
|
|
||||||
|
void applyOverrides() override {
|
||||||
|
const Theme& th = getTheme();
|
||||||
|
// Lerp between empty (dimmed) and full (green) based on value.
|
||||||
|
Vector empty(0.14f, 0.14f, 0.16f);
|
||||||
|
Vector full = th.color(ColorToken::Green);
|
||||||
|
float v = _value;
|
||||||
|
style.backgroundColor = Vector(
|
||||||
|
empty.x + (full.x - empty.x) * v,
|
||||||
|
empty.y + (full.y - empty.y) * v,
|
||||||
|
empty.z + (full.z - empty.z) * v);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
float _value = 0.0f;
|
||||||
|
};
|
||||||
|
} // namespace UI
|
||||||
|
} // namespace Seele
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "UI/Element/Div.h"
|
||||||
|
#include "UI/Style/Class.h"
|
||||||
|
|
||||||
|
namespace Seele {
|
||||||
|
namespace UI {
|
||||||
|
// A radio button: a circular indicator + optional label.
|
||||||
|
// HTML analog: <input type="radio">
|
||||||
|
//
|
||||||
|
// Usage:
|
||||||
|
// auto* r1 = new Radio<>();
|
||||||
|
// auto* r2 = new Radio<>();
|
||||||
|
// // per-frame: r1->setSelected(viewState.choice == 0)
|
||||||
|
// // r2->setSelected(viewState.choice == 1)
|
||||||
|
//
|
||||||
|
// Pure display widget. The view owns the selection state and drives
|
||||||
|
// setSelected() on each radio in the group.
|
||||||
|
template<StyleClass... classes>
|
||||||
|
class Radio : public Div<classes...> {
|
||||||
|
public:
|
||||||
|
using Div<classes...>::attr;
|
||||||
|
using Div<classes...>::style;
|
||||||
|
using Div<classes...>::markDirty;
|
||||||
|
using Div<classes...>::getTheme;
|
||||||
|
|
||||||
|
Radio(Attributes attr = Attributes{}, std::initializer_list<OElement> children = {})
|
||||||
|
: Div<classes...>(std::move(attr), children) {
|
||||||
|
style.height = 20;
|
||||||
|
style.width = 20;
|
||||||
|
}
|
||||||
|
virtual ~Radio() override {}
|
||||||
|
|
||||||
|
void setSelected(bool selected) {
|
||||||
|
_selected = selected;
|
||||||
|
markDirty();
|
||||||
|
}
|
||||||
|
bool isSelected() const { return _selected; }
|
||||||
|
|
||||||
|
void setHovered(bool hovered) override { _hovered = hovered; }
|
||||||
|
void setFocused(bool focused) override { _focused = focused; }
|
||||||
|
bool isFocusable() const override { return attr.focusable; }
|
||||||
|
|
||||||
|
void applyStyle(Style parentStyle, const Theme& theme) override {
|
||||||
|
Div<classes...>::applyStyle(parentStyle, theme);
|
||||||
|
}
|
||||||
|
|
||||||
|
void applyOverrides() override {
|
||||||
|
const Theme& th = getTheme();
|
||||||
|
if (_selected) {
|
||||||
|
style.backgroundColor = th.color(ColorToken::Blue);
|
||||||
|
} else if (_hovered) {
|
||||||
|
style.backgroundColor = Vector(0.22f, 0.24f, 0.28f);
|
||||||
|
} else if (_focused) {
|
||||||
|
style.backgroundColor = Vector(0.20f, 0.22f, 0.26f);
|
||||||
|
} else {
|
||||||
|
style.backgroundColor = Vector(0.14f, 0.14f, 0.16f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool _selected = false;
|
||||||
|
bool _hovered = false;
|
||||||
|
bool _focused = false;
|
||||||
|
};
|
||||||
|
} // namespace UI
|
||||||
|
} // namespace Seele
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "UI/Element/Div.h"
|
||||||
|
#include "UI/Element/Text.h"
|
||||||
|
#include "UI/Style/Class.h"
|
||||||
|
|
||||||
|
namespace Seele {
|
||||||
|
namespace UI {
|
||||||
|
// A select box (dropdown): a clickable box that displays the current selection.
|
||||||
|
// HTML analog: <select>
|
||||||
|
//
|
||||||
|
// The dropdown list is a SEPARATE element tree managed by the owning view.
|
||||||
|
// The SelectBox is the trigger: it displays the current selection and an
|
||||||
|
// arrow indicator. The view toggles the dropdown list's visibility in
|
||||||
|
// response to onClick and updates the selection when the user picks an item.
|
||||||
|
//
|
||||||
|
// Usage (pass the font/size classes via the template pack):
|
||||||
|
// auto* sel = new SelectBox<Font_Arial, Text_SM>(UI::Attributes{}, "Option A");
|
||||||
|
// // per-frame: sel->setSelection("Option B"); sel->setOpen(true/false)
|
||||||
|
template<StyleClass... classes>
|
||||||
|
class SelectBox : public Div<classes...> {
|
||||||
|
public:
|
||||||
|
using Div<classes...>::attr;
|
||||||
|
using Div<classes...>::style;
|
||||||
|
using Div<classes...>::markDirty;
|
||||||
|
using Div<classes...>::getTheme;
|
||||||
|
using Div<classes...>::children;
|
||||||
|
|
||||||
|
SelectBox(Attributes attr, std::string selection = "")
|
||||||
|
: Div<classes...>(std::move(attr), std::initializer_list<OElement>{}) {
|
||||||
|
attr.focusable = true;
|
||||||
|
_selection = std::move(selection);
|
||||||
|
|
||||||
|
// Display text: the current selection + a down-arrow indicator.
|
||||||
|
auto* t = new Text<classes...>(_selection + " ▾");
|
||||||
|
children.add(OElement(t));
|
||||||
|
children.back()->setParent(this);
|
||||||
|
_text = PElement(t);
|
||||||
|
|
||||||
|
style.paddingLeft = 12;
|
||||||
|
style.paddingRight = 12;
|
||||||
|
style.paddingTop = 8;
|
||||||
|
style.paddingBottom = 8;
|
||||||
|
style.backgroundColor = Vector(0.14f, 0.14f, 0.16f);
|
||||||
|
}
|
||||||
|
virtual ~SelectBox() override {}
|
||||||
|
|
||||||
|
void setSelection(std::string selection) {
|
||||||
|
_selection = std::move(selection);
|
||||||
|
if (_text != nullptr) {
|
||||||
|
if (auto* t = dynamic_cast<Text<classes...>*>(_text.getHandle())) {
|
||||||
|
t->setText(_selection + " ▾");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
markDirty();
|
||||||
|
}
|
||||||
|
std::string getSelection() const { return _selection; }
|
||||||
|
|
||||||
|
void setOpen(bool open) {
|
||||||
|
_open = open;
|
||||||
|
markDirty();
|
||||||
|
}
|
||||||
|
bool isOpen() const { return _open; }
|
||||||
|
|
||||||
|
void setHovered(bool hovered) override { _hovered = hovered; }
|
||||||
|
void setFocused(bool focused) override { _focused = focused; }
|
||||||
|
bool isFocusable() const override { return attr.focusable; }
|
||||||
|
|
||||||
|
void applyStyle(Style parentStyle, const Theme& theme) override {
|
||||||
|
Div<classes...>::applyStyle(parentStyle, theme);
|
||||||
|
}
|
||||||
|
|
||||||
|
void applyOverrides() override {
|
||||||
|
const Theme& th = getTheme();
|
||||||
|
if (_open) {
|
||||||
|
style.backgroundColor = Vector(0.18f, 0.19f, 0.22f);
|
||||||
|
style.textColor = th.color(ColorToken::White);
|
||||||
|
} else if (_hovered) {
|
||||||
|
style.backgroundColor = Vector(0.18f, 0.19f, 0.22f);
|
||||||
|
style.textColor = th.color(ColorToken::Gray400);
|
||||||
|
} else if (_focused) {
|
||||||
|
style.backgroundColor = Vector(0.16f, 0.17f, 0.20f);
|
||||||
|
style.textColor = th.color(ColorToken::Gray500);
|
||||||
|
} else {
|
||||||
|
style.backgroundColor = Vector(0.14f, 0.14f, 0.16f);
|
||||||
|
style.textColor = th.color(ColorToken::Gray400);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string _selection;
|
||||||
|
bool _open = false;
|
||||||
|
bool _hovered = false;
|
||||||
|
bool _focused = false;
|
||||||
|
PElement _text;
|
||||||
|
};
|
||||||
|
} // namespace UI
|
||||||
|
} // namespace Seele
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "UI/Element/Div.h"
|
||||||
|
#include "UI/Style/Class.h"
|
||||||
|
|
||||||
|
namespace Seele {
|
||||||
|
namespace UI {
|
||||||
|
// A slider: a horizontal track with a fill bar that reflects a 0.0-1.0 value.
|
||||||
|
// HTML analog: <input type="range">
|
||||||
|
//
|
||||||
|
// Usage:
|
||||||
|
// auto* slider = new Slider<>();
|
||||||
|
// // per-frame: slider->setValue(viewState.volume) // 0.0 - 1.0
|
||||||
|
//
|
||||||
|
// Pure display widget. The slider's background is a lerp between a dimmed
|
||||||
|
// "track" color and an accent "fill" color based on the value, giving a
|
||||||
|
// visual fill effect. Mouse drag handling is the owning view's job.
|
||||||
|
template<StyleClass... classes>
|
||||||
|
class Slider : public Div<classes...> {
|
||||||
|
public:
|
||||||
|
using Div<classes...>::attr;
|
||||||
|
using Div<classes...>::style;
|
||||||
|
using Div<classes...>::markDirty;
|
||||||
|
using Div<classes...>::getTheme;
|
||||||
|
|
||||||
|
Slider(Attributes attr = Attributes{}, std::initializer_list<OElement> children = {})
|
||||||
|
: Div<classes...>(std::move(attr), children) {
|
||||||
|
attr.focusable = true;
|
||||||
|
style.height = 8;
|
||||||
|
}
|
||||||
|
virtual ~Slider() override {}
|
||||||
|
|
||||||
|
void setValue(float value) {
|
||||||
|
_value = value < 0.0f ? 0.0f : (value > 1.0f ? 1.0f : value);
|
||||||
|
markDirty();
|
||||||
|
}
|
||||||
|
float getValue() const { return _value; }
|
||||||
|
|
||||||
|
void setHovered(bool hovered) override { _hovered = hovered; }
|
||||||
|
void setFocused(bool focused) override { _focused = focused; }
|
||||||
|
bool isFocusable() const override { return attr.focusable; }
|
||||||
|
|
||||||
|
void applyStyle(Style parentStyle, const Theme& theme) override {
|
||||||
|
Div<classes...>::applyStyle(parentStyle, theme);
|
||||||
|
}
|
||||||
|
|
||||||
|
void applyOverrides() override {
|
||||||
|
const Theme& th = getTheme();
|
||||||
|
if (_focused || _hovered) {
|
||||||
|
style.backgroundColor = th.color(ColorToken::Blue);
|
||||||
|
} else {
|
||||||
|
// Lerp between track (dimmed) and accent (blue) for fill effect.
|
||||||
|
Vector track(0.18f, 0.18f, 0.20f);
|
||||||
|
Vector accent = th.color(ColorToken::Blue);
|
||||||
|
float v = _value;
|
||||||
|
style.backgroundColor = Vector(
|
||||||
|
track.x + (accent.x - track.x) * v,
|
||||||
|
track.y + (accent.y - track.y) * v,
|
||||||
|
track.z + (accent.z - track.z) * v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
float _value = 0.0f;
|
||||||
|
bool _hovered = false;
|
||||||
|
bool _focused = false;
|
||||||
|
};
|
||||||
|
} // namespace UI
|
||||||
|
} // namespace Seele
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "UI/Element/Div.h"
|
||||||
|
#include "UI/Element/Button.h"
|
||||||
|
#include "UI/Style/Class.h"
|
||||||
|
|
||||||
|
namespace Seele {
|
||||||
|
namespace UI {
|
||||||
|
// A tab bar: a horizontal row of tab buttons. One tab is highlighted as active.
|
||||||
|
// HTML analog: <ul role="tablist">
|
||||||
|
//
|
||||||
|
// Usage:
|
||||||
|
// auto* tab1 = new Button<>(UI::Attributes{});
|
||||||
|
// auto* tab2 = new Button<>(UI::Attributes{});
|
||||||
|
// auto* tabs = new TabBar<>(UI::Attributes{}, {OElement(tab1), OElement(tab2)});
|
||||||
|
// // per-frame: tabs->setActiveTab(0)
|
||||||
|
//
|
||||||
|
// The tab bar takes a fixed set of Button children at construction (the
|
||||||
|
// fixed-children constraint). The active tab gets an accent color; the
|
||||||
|
// others get a dimmed color. The view handles onClick on each button to
|
||||||
|
// change the active tab.
|
||||||
|
template<StyleClass... classes>
|
||||||
|
class TabBar : public Div<classes...> {
|
||||||
|
public:
|
||||||
|
using Div<classes...>::attr;
|
||||||
|
using Div<classes...>::style;
|
||||||
|
using Div<classes...>::markDirty;
|
||||||
|
using Div<classes...>::getTheme;
|
||||||
|
using Div<classes...>::children;
|
||||||
|
|
||||||
|
TabBar(Attributes attr, std::initializer_list<OElement> tabs)
|
||||||
|
: Div<classes...>(std::move(attr), tabs) {
|
||||||
|
style.direction = FlexDirection::Row;
|
||||||
|
style.gap = 4;
|
||||||
|
}
|
||||||
|
virtual ~TabBar() override {}
|
||||||
|
|
||||||
|
void setActiveTab(int index) {
|
||||||
|
_activeTab = index;
|
||||||
|
markDirty();
|
||||||
|
}
|
||||||
|
int getActiveTab() const { return _activeTab; }
|
||||||
|
|
||||||
|
void applyStyle(Style parentStyle, const Theme& theme) override {
|
||||||
|
Div<classes...>::applyStyle(parentStyle, theme);
|
||||||
|
style.direction = FlexDirection::Row;
|
||||||
|
style.gap = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
void applyOverrides() override {
|
||||||
|
const Theme& th = getTheme();
|
||||||
|
int i = 0;
|
||||||
|
for (auto& child : children) {
|
||||||
|
if (child == nullptr) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
auto& cs = child->getStyle();
|
||||||
|
if (i == _activeTab) {
|
||||||
|
cs.backgroundColor = th.color(ColorToken::Blue);
|
||||||
|
cs.textColor = th.color(ColorToken::White);
|
||||||
|
} else {
|
||||||
|
cs.backgroundColor = Vector(0.14f, 0.14f, 0.16f);
|
||||||
|
cs.textColor = th.color(ColorToken::Gray500);
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
int _activeTab = 0;
|
||||||
|
};
|
||||||
|
} // namespace UI
|
||||||
|
} // namespace Seele
|
||||||
@@ -0,0 +1,108 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "UI/Element/Div.h"
|
||||||
|
#include "UI/Element/Text.h"
|
||||||
|
#include "UI/Style/Class.h"
|
||||||
|
|
||||||
|
namespace Seele {
|
||||||
|
namespace UI {
|
||||||
|
// A toggle switch: a pill-shaped on/off switch with an optional label.
|
||||||
|
// HTML analog: <input type="checkbox"> styled as a switch (iOS-style)
|
||||||
|
//
|
||||||
|
// Usage:
|
||||||
|
// auto* toggle = new ToggleSwitch<Font_Arial, Text_SM>(UI::Attributes{}, "Wi-Fi");
|
||||||
|
// // per-frame: toggle->setOn(viewState.wifi)
|
||||||
|
//
|
||||||
|
// The toggle is a Div containing a label Text and an indicator pill.
|
||||||
|
// The pill's background shifts between off (dimmed) and on (green) based
|
||||||
|
// on the `on` state. The knob is a child div positioned to the left (off)
|
||||||
|
// or right (on).
|
||||||
|
template<StyleClass... classes>
|
||||||
|
class ToggleSwitch : public Div<classes...> {
|
||||||
|
public:
|
||||||
|
using Div<classes...>::attr;
|
||||||
|
using Div<classes...>::style;
|
||||||
|
using Div<classes...>::markDirty;
|
||||||
|
using Div<classes...>::getTheme;
|
||||||
|
using Div<classes...>::children;
|
||||||
|
|
||||||
|
ToggleSwitch(Attributes attr = Attributes{}, std::string label = "")
|
||||||
|
: Div<classes...>(std::move(attr), std::initializer_list<OElement>{}) {
|
||||||
|
// Build the label (if any)
|
||||||
|
if (!label.empty()) {
|
||||||
|
auto* lbl = new Text<classes...>(label);
|
||||||
|
children.add(OElement(lbl));
|
||||||
|
children.back()->setParent(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build the toggle pill: a rounded indicator (60x28)
|
||||||
|
auto* pill = new Div<>(UI::Attributes{});
|
||||||
|
{
|
||||||
|
auto& ps = pill->getStyle();
|
||||||
|
ps.width = 60;
|
||||||
|
ps.height = 28;
|
||||||
|
ps.backgroundColor = Vector(0.20f, 0.20f, 0.22f);
|
||||||
|
}
|
||||||
|
_pill = PElement(pill);
|
||||||
|
children.add(OElement(pill));
|
||||||
|
children.back()->setParent(this);
|
||||||
|
|
||||||
|
// Build the knob: a circle inside the pill (20x20)
|
||||||
|
auto* knob = new Div<>(UI::Attributes{});
|
||||||
|
{
|
||||||
|
auto& ks = knob->getStyle();
|
||||||
|
ks.width = 20;
|
||||||
|
ks.height = 20;
|
||||||
|
ks.backgroundColor = Vector(0.70f, 0.70f, 0.72f);
|
||||||
|
ks.left = 4;
|
||||||
|
ks.position = Position::Absolute;
|
||||||
|
}
|
||||||
|
_knob = PElement(knob);
|
||||||
|
children.add(OElement(knob));
|
||||||
|
children.back()->setParent(this);
|
||||||
|
|
||||||
|
style.height = 28;
|
||||||
|
}
|
||||||
|
virtual ~ToggleSwitch() override {}
|
||||||
|
|
||||||
|
void setOn(bool on) {
|
||||||
|
_on = on;
|
||||||
|
markDirty();
|
||||||
|
}
|
||||||
|
bool isOn() const { return _on; }
|
||||||
|
|
||||||
|
void setHovered(bool hovered) override { _hovered = hovered; }
|
||||||
|
|
||||||
|
void applyStyle(Style parentStyle, const Theme& theme) override {
|
||||||
|
Div<classes...>::applyStyle(parentStyle, theme);
|
||||||
|
}
|
||||||
|
|
||||||
|
void applyOverrides() override {
|
||||||
|
const Theme& th = getTheme();
|
||||||
|
if (_pill != nullptr) {
|
||||||
|
auto* p = _pill.getHandle();
|
||||||
|
if (p != nullptr) {
|
||||||
|
if (_on) {
|
||||||
|
p->getStyle().backgroundColor = th.color(ColorToken::Green);
|
||||||
|
} else {
|
||||||
|
p->getStyle().backgroundColor = Vector(0.20f, 0.20f, 0.22f);
|
||||||
|
}
|
||||||
|
p->markDirty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (_knob != nullptr) {
|
||||||
|
auto* k = _knob.getHandle();
|
||||||
|
if (k != nullptr) {
|
||||||
|
k->getStyle().left = _on ? 36 : 4;
|
||||||
|
k->markDirty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool _on = false;
|
||||||
|
bool _hovered = false;
|
||||||
|
PElement _pill;
|
||||||
|
PElement _knob;
|
||||||
|
};
|
||||||
|
} // namespace UI
|
||||||
|
} // namespace Seele
|
||||||
@@ -0,0 +1,100 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "UI/Element/Div.h"
|
||||||
|
#include "UI/Element/Text.h"
|
||||||
|
#include "UI/Style/Class.h"
|
||||||
|
|
||||||
|
namespace Seele {
|
||||||
|
namespace UI {
|
||||||
|
// A tooltip: an element that shows a tooltip bubble when hovered.
|
||||||
|
// HTML analog: title="..." attribute / CSS :hover tooltip
|
||||||
|
//
|
||||||
|
// The Tooltip wraps a child element and, when the child is hovered, shows
|
||||||
|
// a floating label with the tooltip text. The tooltip is rendered as a
|
||||||
|
// child element (a Text with a dark background) that is hidden until hover.
|
||||||
|
//
|
||||||
|
// Usage:
|
||||||
|
// auto* target = new Button<>(UI::Attributes{});
|
||||||
|
// auto* tip = new Tooltip<>(UI::Attributes{}, OElement(target), "Helpful info");
|
||||||
|
//
|
||||||
|
// NOTE: the tooltip child is added to the tree at construction. Its position
|
||||||
|
// is set by the view (absolute positioning) — the Tooltip itself does not
|
||||||
|
// compute the tooltip's position.
|
||||||
|
template<StyleClass... classes>
|
||||||
|
class Tooltip : public Div<classes...> {
|
||||||
|
public:
|
||||||
|
using Div<classes...>::attr;
|
||||||
|
using Div<classes...>::style;
|
||||||
|
using Div<classes...>::markDirty;
|
||||||
|
using Div<classes...>::getTheme;
|
||||||
|
using Div<classes...>::children;
|
||||||
|
|
||||||
|
Tooltip(Attributes attr, OElement target, std::string text)
|
||||||
|
: Div<classes...>(std::move(attr), std::initializer_list<OElement>{}) {
|
||||||
|
// Wrap the target
|
||||||
|
children.add(std::move(target));
|
||||||
|
if (children.size() > 0) {
|
||||||
|
children.back()->setParent(this);
|
||||||
|
}
|
||||||
|
_tipText = std::move(text);
|
||||||
|
|
||||||
|
// Build the tooltip bubble: a dark panel with the text
|
||||||
|
auto* bubble = new Text<classes...>(_tipText);
|
||||||
|
{
|
||||||
|
auto& bs = bubble->getStyle();
|
||||||
|
bs.backgroundColor = Vector(0.05f, 0.05f, 0.06f);
|
||||||
|
bs.paddingLeft = 8;
|
||||||
|
bs.paddingRight = 8;
|
||||||
|
bs.paddingTop = 4;
|
||||||
|
bs.paddingBottom = 4;
|
||||||
|
bs.display = Display::Hidden;
|
||||||
|
}
|
||||||
|
_bubble = PElement(bubble);
|
||||||
|
children.add(OElement(bubble));
|
||||||
|
children.back()->setParent(this);
|
||||||
|
}
|
||||||
|
virtual ~Tooltip() override {}
|
||||||
|
|
||||||
|
void setText(std::string text) {
|
||||||
|
_tipText = std::move(text);
|
||||||
|
if (_bubble != nullptr) {
|
||||||
|
if (auto* t = dynamic_cast<Text<classes...>*>(_bubble.getHandle())) {
|
||||||
|
t->setText(_tipText);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
markDirty();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setHovered(bool hovered) override {
|
||||||
|
_hovered = hovered;
|
||||||
|
if (_bubble != nullptr) {
|
||||||
|
if (auto* b = dynamic_cast<Element*>(_bubble.getHandle())) {
|
||||||
|
if (b != nullptr) {
|
||||||
|
b->getStyle().display = hovered ? Display::Flex : Display::Hidden;
|
||||||
|
b->markDirty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void applyStyle(Style parentStyle, const Theme& theme) override {
|
||||||
|
Div<classes...>::applyStyle(parentStyle, theme);
|
||||||
|
}
|
||||||
|
|
||||||
|
void applyOverrides() override {
|
||||||
|
const Theme& th = getTheme();
|
||||||
|
if (_bubble != nullptr) {
|
||||||
|
if (auto* b = dynamic_cast<Text<classes...>*>(_bubble.getHandle())) {
|
||||||
|
if (b != nullptr) {
|
||||||
|
b->getStyle().textColor = th.color(ColorToken::White);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string _tipText;
|
||||||
|
PElement _bubble;
|
||||||
|
bool _hovered = false;
|
||||||
|
};
|
||||||
|
} // namespace UI
|
||||||
|
} // namespace Seele
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
#pragma once
|
||||||
|
// Seele UI: reusable component library.
|
||||||
|
//
|
||||||
|
// HTML-analog widgets built on the existing Element/Div/Text/Button base.
|
||||||
|
// All components are header-only template classes (matching the existing
|
||||||
|
// Button/Text/Div/Panel pattern). No .cpp files are needed.
|
||||||
|
//
|
||||||
|
// Design constraint: "children fixed at construction" — the UI tree's
|
||||||
|
// structure is immutable at runtime. Dynamic content (dropdown options,
|
||||||
|
// tab pages, scrollable items) is pre-allocated as a fixed pool at
|
||||||
|
// construction and driven per-frame by the owning view via setter methods
|
||||||
|
// (setText, setValue, setChecked, setVisible, etc.).
|
||||||
|
//
|
||||||
|
// Interaction model: the only sanctioned input path is Element::attr.onClick
|
||||||
|
// (delivered by System::processInput on click-release). Components that
|
||||||
|
// need to react to clicks expose the Button/Div onClick handler; the owning
|
||||||
|
// view reads state in its per-frame update() and calls the component's
|
||||||
|
// setters to reflect the new state.
|
||||||
|
|
||||||
|
// Form controls
|
||||||
|
#include "UI/Element/Checkbox.h"
|
||||||
|
#include "UI/Element/ToggleSwitch.h"
|
||||||
|
#include "UI/Element/Radio.h"
|
||||||
|
#include "UI/Element/SelectBox.h"
|
||||||
|
#include "UI/Element/InputField.h"
|
||||||
|
#include "UI/Element/Slider.h"
|
||||||
|
|
||||||
|
// Display / navigation
|
||||||
|
#include "UI/Element/Progressbar.h"
|
||||||
|
#include "UI/Element/TabBar.h"
|
||||||
|
#include "UI/Element/Tooltip.h"
|
||||||
|
#include "UI/Element/Accordion.h"
|
||||||
|
#include "UI/Element/HR.h"
|
||||||
@@ -0,0 +1,162 @@
|
|||||||
|
// Syntax-check TU for the new UI widget components.
|
||||||
|
// Instantiates each component with template args to force full template
|
||||||
|
// instantiation, then references key members to ensure they exist.
|
||||||
|
#include "UI/Widgets.h"
|
||||||
|
#include "UI/Element/Button.h"
|
||||||
|
#include "UI/Element/Div.h"
|
||||||
|
#include "UI/Element/Text.h"
|
||||||
|
#include "UI/Style/Fonts.h"
|
||||||
|
|
||||||
|
using namespace Seele;
|
||||||
|
using namespace Seele::UI;
|
||||||
|
|
||||||
|
// A translation-unit-level function that exercises every new widget type.
|
||||||
|
// The compiler must fully instantiate each template here.
|
||||||
|
void widget_smoke_test() {
|
||||||
|
// --- Checkbox ---
|
||||||
|
{
|
||||||
|
auto* cb = new Checkbox<Font_Arial, Text_SM>();
|
||||||
|
cb->setChecked(true);
|
||||||
|
(void)cb->isChecked();
|
||||||
|
cb->setHovered(true);
|
||||||
|
cb->setFocused(true);
|
||||||
|
cb->applyOverrides();
|
||||||
|
(void)cb->style;
|
||||||
|
(void)cb->attr;
|
||||||
|
(void)cb->children;
|
||||||
|
cb->markDirty();
|
||||||
|
delete cb;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- ToggleSwitch ---
|
||||||
|
{
|
||||||
|
auto* ts = new ToggleSwitch<Font_Arial, Text_SM>(UI::Attributes{}, "Wi-Fi");
|
||||||
|
ts->setOn(true);
|
||||||
|
(void)ts->isOn();
|
||||||
|
ts->setHovered(true);
|
||||||
|
ts->applyOverrides();
|
||||||
|
(void)ts->style;
|
||||||
|
(void)ts->attr;
|
||||||
|
(void)ts->children;
|
||||||
|
ts->markDirty();
|
||||||
|
delete ts;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Radio ---
|
||||||
|
{
|
||||||
|
auto* r1 = new Radio<Font_Arial, Text_SM>();
|
||||||
|
r1->setSelected(true);
|
||||||
|
(void)r1->isSelected();
|
||||||
|
r1->applyOverrides();
|
||||||
|
(void)r1->style;
|
||||||
|
(void)r1->attr;
|
||||||
|
r1->markDirty();
|
||||||
|
delete r1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- SelectBox ---
|
||||||
|
{
|
||||||
|
auto* sel = new SelectBox<Font_Arial, Text_SM>(UI::Attributes{}, "Option A");
|
||||||
|
sel->setSelection("Option B");
|
||||||
|
(void)sel->getSelection();
|
||||||
|
sel->setOpen(true);
|
||||||
|
(void)sel->isOpen();
|
||||||
|
sel->applyOverrides();
|
||||||
|
(void)sel->style;
|
||||||
|
(void)sel->attr;
|
||||||
|
(void)sel->children;
|
||||||
|
sel->markDirty();
|
||||||
|
delete sel;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- InputField ---
|
||||||
|
{
|
||||||
|
auto* input = new InputField<Font_Arial, Text_SM>(UI::Attributes{}, "Enter name...");
|
||||||
|
input->setValue("hello");
|
||||||
|
(void)input->getValue();
|
||||||
|
(void)input->getPlaceholder();
|
||||||
|
input->setFocused(true);
|
||||||
|
input->applyOverrides();
|
||||||
|
(void)input->style;
|
||||||
|
(void)input->attr;
|
||||||
|
(void)input->children;
|
||||||
|
input->markDirty();
|
||||||
|
delete input;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Slider ---
|
||||||
|
{
|
||||||
|
auto* slider = new Slider<Font_Arial, Text_SM>();
|
||||||
|
slider->setValue(0.75f);
|
||||||
|
(void)slider->getValue();
|
||||||
|
slider->applyOverrides();
|
||||||
|
(void)slider->style;
|
||||||
|
(void)slider->attr;
|
||||||
|
slider->markDirty();
|
||||||
|
delete slider;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Progressbar ---
|
||||||
|
{
|
||||||
|
auto* bar = new Progressbar<Font_Arial, Text_SM>();
|
||||||
|
bar->setValue(0.5f);
|
||||||
|
(void)bar->getValue();
|
||||||
|
bar->applyOverrides();
|
||||||
|
(void)bar->style;
|
||||||
|
(void)bar->attr;
|
||||||
|
bar->markDirty();
|
||||||
|
delete bar;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- TabBar ---
|
||||||
|
{
|
||||||
|
auto* tab1 = new Button<Font_Arial, Text_SM>(UI::Attributes{});
|
||||||
|
auto* tab2 = new Button<Font_Arial, Text_SM>(UI::Attributes{});
|
||||||
|
auto* tabs = new TabBar<>(UI::Attributes{}, {OElement(tab1), OElement(tab2)});
|
||||||
|
tabs->setActiveTab(0);
|
||||||
|
(void)tabs->getActiveTab();
|
||||||
|
tabs->applyOverrides();
|
||||||
|
(void)tabs->style;
|
||||||
|
(void)tabs->attr;
|
||||||
|
(void)tabs->children;
|
||||||
|
tabs->markDirty();
|
||||||
|
delete tabs;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Tooltip ---
|
||||||
|
{
|
||||||
|
auto* target = new Button<Font_Arial, Text_SM>(UI::Attributes{});
|
||||||
|
auto* tip = new Tooltip<Font_Arial, Text_SM>(UI::Attributes{}, OElement(target), "Helpful");
|
||||||
|
tip->setHovered(true);
|
||||||
|
tip->applyOverrides();
|
||||||
|
(void)tip->style;
|
||||||
|
(void)tip->attr;
|
||||||
|
(void)tip->children;
|
||||||
|
tip->markDirty();
|
||||||
|
delete tip;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Accordion ---
|
||||||
|
{
|
||||||
|
auto* header = new Text<Font_Arial, Text_SM>("Section");
|
||||||
|
auto* body = new Div<>(UI::Attributes{});
|
||||||
|
auto* acc = new Accordion<>(UI::Attributes{}, OElement(header), OElement(body));
|
||||||
|
acc->setBodyVisible(false);
|
||||||
|
(void)acc->isBodyVisible();
|
||||||
|
(void)acc->getHeader();
|
||||||
|
(void)acc->getBody();
|
||||||
|
(void)acc->style;
|
||||||
|
(void)acc->attr;
|
||||||
|
(void)acc->children;
|
||||||
|
acc->markDirty();
|
||||||
|
delete acc;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- HR ---
|
||||||
|
{
|
||||||
|
auto* hr = new HR<Font_Arial, Text_SM>();
|
||||||
|
(void)hr->style;
|
||||||
|
(void)hr->attr;
|
||||||
|
delete hr;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
#include "Application.h"
|
||||||
|
#include "Graphics/Enums.h"
|
||||||
|
#include "Graphics/Graphics.h"
|
||||||
|
#include "System/SystemGraph.h"
|
||||||
|
#include "Scene/Scene.h"
|
||||||
|
#include "Game.h"
|
||||||
|
#include "System/KeyboardInput.h"
|
||||||
|
#include "System/FluidUpdater.h"
|
||||||
|
#include "System/LightGather.h"
|
||||||
|
#include "System/MeshUpdater.h"
|
||||||
|
#include "System/CameraUpdater.h"
|
||||||
|
#ifdef WIN32
|
||||||
|
#include "Platform/Windows/GameInterface.h"
|
||||||
|
#else
|
||||||
|
#include "Platform/Linux/GameInterface.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
using namespace Seele;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
// Library extension per platform (mirrors the editor's old binary-path logic).
|
||||||
|
const char* libraryExtension() {
|
||||||
|
#ifdef WIN32
|
||||||
|
return "dll";
|
||||||
|
#elif __APPLE__
|
||||||
|
return "dylib";
|
||||||
|
#else
|
||||||
|
return "so";
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
Application::Application() : graphics(nullptr), scene_(nullptr), graph_(nullptr), gameInterface(nullptr) {}
|
||||||
|
|
||||||
|
Application::~Application() {
|
||||||
|
if (gameInterface != nullptr) {
|
||||||
|
delete gameInterface; // ~GameInterface dlclose()s + destroys the Game instance
|
||||||
|
gameInterface = nullptr;
|
||||||
|
}
|
||||||
|
// `scene_` and `graph_` are OwningPtr: their destructors free the Scene and
|
||||||
|
// (via the moved-in OSystemBase entries) every System.
|
||||||
|
}
|
||||||
|
|
||||||
|
void Application::loadGame(Gfx::PGraphics graphics, const std::filesystem::path& sourcePath, const std::string& gameName) {
|
||||||
|
this->graphics = graphics;
|
||||||
|
|
||||||
|
// The world is created exactly once, owned by the Application. `loadGame` is
|
||||||
|
// the single setup point (called once per process) — no null guards needed.
|
||||||
|
scene_ = OScene(new Scene(graphics));
|
||||||
|
graph_ = OSystemGraph(new SystemGraph());
|
||||||
|
|
||||||
|
// Resolve the game binary and load it (dlopen) once.
|
||||||
|
std::filesystem::path binaryPath = sourcePath / "bin" / (gameName + "." + libraryExtension());
|
||||||
|
GameInterface* interface = new GameInterface(binaryPath);
|
||||||
|
interface->reload();
|
||||||
|
gameInterface = interface;
|
||||||
|
|
||||||
|
// Let the game populate the Scene + SystemGraph we own, then append the
|
||||||
|
// editor's own systems. This used to live in the editor's main.cpp; it now
|
||||||
|
// lives here so the world has a single owner and a single setup point.
|
||||||
|
interface->getGame()->setupScene(scene_, graph_);
|
||||||
|
// Keep a non-owning handle to the input sink so the focused game view can forward
|
||||||
|
// keyboard/pointer events into it (which then feed Component::KeyboardInput entities).
|
||||||
|
// Ownership stays with graph_ (the OSystemBase in its Array owns the real object).
|
||||||
|
System::OSystemBase sink = new System::KeyboardInput(scene_); // graph_'s Array owns it
|
||||||
|
keyboardInput_ = PKeyboardInput(static_cast<System::KeyboardInput*>(*sink)); // non-owning: graph_'s Array owns it
|
||||||
|
graph_->addSystem(std::move(sink));
|
||||||
|
graph_->addSystem(new System::FluidUpdater(scene_));
|
||||||
|
graph_->addSystem(new System::LightGather(scene_));
|
||||||
|
graph_->addSystem(new System::MeshUpdater(scene_));
|
||||||
|
graph_->addSystem(new System::CameraUpdater(scene_));
|
||||||
|
}
|
||||||
|
|
||||||
|
OWindow Application::addWindow(Gfx::PGraphics graphics, const WindowCreateInfo& createInfo) {
|
||||||
|
OWindow window = new Window(this, graphics->createWindow(createInfo));
|
||||||
|
windows.add(window);
|
||||||
|
return window;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Application::attachWorld(OScene scene, OSystemGraph graph) {
|
||||||
|
// Worldless hosts (benchmark) build their own world and hand ownership in;
|
||||||
|
// the Application's owning members take it via move so the frame loop can
|
||||||
|
// step it and the views can render it.
|
||||||
|
scene_ = std::move(scene);
|
||||||
|
graph_ = std::move(graph);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Application::render() {
|
||||||
|
// Step the world exactly ONCE per frame, independent of how many windows
|
||||||
|
// are open. The old code re-ran the graph inside the per-window loop, which
|
||||||
|
// double-simulated with two windows. Views below only render the world.
|
||||||
|
graph_->run(Gfx::getCurrentFrameDelta());
|
||||||
|
for (auto& window : windows) {
|
||||||
|
window->pollInputs();
|
||||||
|
if (window->isPaused())
|
||||||
|
continue;
|
||||||
|
window->render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Application::notifyWindowClosed(PWindow window) { windows.remove(window); }
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "Containers/Array.h"
|
||||||
|
#include "System/SystemGraph.h"
|
||||||
|
#include "Window.h"
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
|
namespace Seele {
|
||||||
|
DECLARE_NAME_REF(Gfx, Graphics)
|
||||||
|
DECLARE_REF(Scene)
|
||||||
|
class Game;
|
||||||
|
class GameInterface;
|
||||||
|
namespace System {
|
||||||
|
class KeyboardInput;
|
||||||
|
}
|
||||||
|
typedef ::Seele::RefPtr<Seele::System::KeyboardInput> PKeyboardInput;
|
||||||
|
|
||||||
|
// The long-lived top-level application object.
|
||||||
|
//
|
||||||
|
// Owns the *world*: the single Scene, the single SystemGraph (the running
|
||||||
|
// simulation) and the loaded game binary (GameInterface). There is exactly one
|
||||||
|
// of these per process, and it steps the simulation exactly once per frame --
|
||||||
|
// regardless of how many windows/views observe the scene. Views hold a
|
||||||
|
// non-owning PScene and only render; they never own the world.
|
||||||
|
//
|
||||||
|
// This is the old "WindowManager", renamed so its true responsibilities
|
||||||
|
// (windowing + world ownership + the frame loop) are named honestly.
|
||||||
|
class Application {
|
||||||
|
public:
|
||||||
|
Application();
|
||||||
|
~Application();
|
||||||
|
|
||||||
|
// Loads the game binary (dlopen) and lets it populate the Scene +
|
||||||
|
// SystemGraph it owns, then appends the editor's own systems. Called once,
|
||||||
|
// by the embedding host (the editor / benchmark main). `graphics` is needed
|
||||||
|
// to construct the Scene; `sourcePath`/`gameName` resolve the .so.
|
||||||
|
void loadGame(Gfx::PGraphics graphics, const std::filesystem::path& sourcePath, const std::string& gameName);
|
||||||
|
|
||||||
|
// Window management
|
||||||
|
OWindow addWindow(Gfx::PGraphics graphics, const WindowCreateInfo& createInfo);
|
||||||
|
void notifyWindowClosed(PWindow window);
|
||||||
|
bool isActive() const { return getGlobals().running && windows.size(); }
|
||||||
|
|
||||||
|
// Per-frame driver: steps the world ONCE, then renders every window.
|
||||||
|
void render();
|
||||||
|
|
||||||
|
// Non-owning handles so views can render the shared world.
|
||||||
|
PScene scene() const { return scene_; }
|
||||||
|
PSystemGraph systemGraph() const { return graph_; }
|
||||||
|
|
||||||
|
// The world's input sink: the System::KeyboardInput that the focused game
|
||||||
|
// view forwards keyboard/pointer events into (which then feed Component::
|
||||||
|
// KeyboardInput entities, e.g. the FlyCam). Null until loadGame() has run.
|
||||||
|
PKeyboardInput keyboardInput() const { return keyboardInput_; }
|
||||||
|
|
||||||
|
// Worldless hosts (e.g. the GPU-timing benchmark, which has no game binary)
|
||||||
|
// build their own world and hand ownership in; the owning members take it via
|
||||||
|
// move so the frame loop can step `graph_` and views can render `scene_`.
|
||||||
|
void attachWorld(OScene scene, OSystemGraph graph);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Array<PWindow> windows;
|
||||||
|
Gfx::PGraphics graphics;
|
||||||
|
OScene scene_;
|
||||||
|
OSystemGraph graph_;
|
||||||
|
PKeyboardInput keyboardInput_ = nullptr; // non-owning: the OSystemBase in graph_ owns it
|
||||||
|
GameInterface* gameInterface = nullptr; // owned by Application (dlclose'd in dtor)
|
||||||
|
};
|
||||||
|
DEFINE_REF(Application)
|
||||||
|
} // namespace Seele
|
||||||
@@ -6,8 +6,8 @@ target_sources(Engine
|
|||||||
View.cpp
|
View.cpp
|
||||||
Window.cpp
|
Window.cpp
|
||||||
Window.h
|
Window.h
|
||||||
WindowManager.h
|
Application.h
|
||||||
WindowManager.cpp)
|
Application.cpp)
|
||||||
|
|
||||||
target_sources(Engine
|
target_sources(Engine
|
||||||
PUBLIC FILE_SET HEADERS
|
PUBLIC FILE_SET HEADERS
|
||||||
@@ -15,4 +15,4 @@ target_sources(Engine
|
|||||||
GameView.h
|
GameView.h
|
||||||
View.h
|
View.h
|
||||||
Window.h
|
Window.h
|
||||||
WindowManager.h)
|
Application.h)
|
||||||
@@ -4,25 +4,21 @@
|
|||||||
#include "Graphics/RenderPass/BasePass.h"
|
#include "Graphics/RenderPass/BasePass.h"
|
||||||
#include "Graphics/RenderPass/CachedDepthPass.h"
|
#include "Graphics/RenderPass/CachedDepthPass.h"
|
||||||
#include "Graphics/RenderPass/DepthCullingPass.h"
|
#include "Graphics/RenderPass/DepthCullingPass.h"
|
||||||
#include "Graphics/RenderPass/FluidRenderPass.h"
|
|
||||||
#include "Graphics/RenderPass/LightCullingPass.h"
|
#include "Graphics/RenderPass/LightCullingPass.h"
|
||||||
#include "Graphics/RenderPass/RayTracingPass.h"
|
#include "Graphics/RenderPass/RayTracingPass.h"
|
||||||
#include "Graphics/RenderPass/ShadowPass.h"
|
#include "Graphics/RenderPass/ShadowPass.h"
|
||||||
#include "Graphics/RenderPass/SimulationComputePass.h"
|
|
||||||
#include "Graphics/RenderPass/SurfaceExtractPass.h"
|
|
||||||
#include "Graphics/RenderPass/ToneMappingPass.h"
|
#include "Graphics/RenderPass/ToneMappingPass.h"
|
||||||
#include "Graphics/RenderPass/VisibilityPass.h"
|
#include "Graphics/RenderPass/VisibilityPass.h"
|
||||||
#include "System/CameraUpdater.h"
|
|
||||||
#include "System/FluidUpdater.h"
|
|
||||||
#include "System/LightGather.h"
|
|
||||||
#include "System/MeshUpdater.h"
|
|
||||||
#include "Window/Window.h"
|
#include "Window/Window.h"
|
||||||
#include "Scene/LightEnvironment.h"
|
#include "Scene/LightEnvironment.h"
|
||||||
|
|
||||||
using namespace Seele;
|
using namespace Seele;
|
||||||
|
|
||||||
GameView::GameView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo& createInfo, std::filesystem::path dllPath)
|
GameView::GameView(Gfx::PGraphics graphics, PWindow window, PScene scene, const ViewportCreateInfo& createInfo)
|
||||||
: View(graphics, window, createInfo, "Game"), graphics(graphics), scene(new Scene(graphics)), gameInterface(dllPath) {
|
: View(graphics, window, createInfo, "Game"), graphics(graphics), scene(scene) {
|
||||||
|
// The Application (which owns the world) is reached via the Window that owns this View.
|
||||||
|
// The input sink is null until loadGame() runs; the callbacks above null-guard for that.
|
||||||
|
keyboardSystem = window->app()->keyboardInput();
|
||||||
reloadGame();
|
reloadGame();
|
||||||
renderGraph.addPass(new CachedDepthPass(graphics, scene));
|
renderGraph.addPass(new CachedDepthPass(graphics, scene));
|
||||||
renderGraph.addPass(new DepthCullingPass(graphics, scene));
|
renderGraph.addPass(new DepthCullingPass(graphics, scene));
|
||||||
@@ -56,7 +52,6 @@ void GameView::update() {
|
|||||||
for (VertexData* vd : VertexData::getList()) {
|
for (VertexData* vd : VertexData::getList()) {
|
||||||
vd->resetMeshData();
|
vd->resetMeshData();
|
||||||
}
|
}
|
||||||
systemGraph->run(updateTime);
|
|
||||||
scene->update(updateTime);
|
scene->update(updateTime);
|
||||||
for (VertexData* vd : VertexData::getList()) {
|
for (VertexData* vd : VertexData::getList()) {
|
||||||
vd->createDescriptors();
|
vd->createDescriptors();
|
||||||
@@ -94,29 +89,31 @@ void GameView::applyArea(URect) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GameView::reloadGame() {
|
void GameView::reloadGame() {
|
||||||
gameInterface.reload();
|
|
||||||
|
|
||||||
systemGraph = new SystemGraph();
|
|
||||||
gameInterface.getGame()->setupScene(scene, systemGraph);
|
|
||||||
System::OKeyboardInput keyInput = new System::KeyboardInput(scene);
|
|
||||||
keyboardSystem = keyInput;
|
|
||||||
systemGraph->addSystem(std::move(keyInput));
|
|
||||||
systemGraph->addSystem(new System::FluidUpdater(scene));
|
|
||||||
systemGraph->addSystem(new System::LightGather(scene));
|
|
||||||
systemGraph->addSystem(new System::MeshUpdater(scene));
|
|
||||||
systemGraph->addSystem(new System::CameraUpdater(scene));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameView::keyCallback(KeyCode code, InputAction action, KeyModifierFlags modifier) {
|
void GameView::keyCallback(KeyCode code, InputAction action, KeyModifierFlags modifier) {
|
||||||
|
if (keyboardSystem != nullptr) {
|
||||||
keyboardSystem->keyCallback(code, action, modifier);
|
keyboardSystem->keyCallback(code, action, modifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameView::mouseMoveCallback(double xPos, double yPos) { keyboardSystem->mouseCallback(xPos, yPos); }
|
|
||||||
|
|
||||||
void GameView::mouseButtonCallback(MouseButton button, InputAction action, KeyModifierFlags modifier) {
|
|
||||||
keyboardSystem->mouseButtonCallback(button, action, modifier);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameView::scrollCallback(double xScroll, double yScroll) { keyboardSystem->scrollCallback(xScroll, yScroll); }
|
void GameView::mouseMoveCallback(double xPos, double yPos) {
|
||||||
|
if (keyboardSystem != nullptr) {
|
||||||
|
keyboardSystem->mouseCallback(xPos, yPos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameView::mouseButtonCallback(MouseButton button, InputAction action, KeyModifierFlags modifier) {
|
||||||
|
if (keyboardSystem != nullptr) {
|
||||||
|
keyboardSystem->mouseButtonCallback(button, action, modifier);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameView::scrollCallback(double xPos, double yPos, double xScroll, double yScroll) {
|
||||||
|
// The input sink has no cursor-position concept; it only consumes the deltas.
|
||||||
|
if (keyboardSystem != nullptr) {
|
||||||
|
keyboardSystem->scrollCallback(xScroll, yScroll);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void GameView::fileCallback(int, const char**) {}
|
void GameView::fileCallback(int, const char**) {}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
#include "Scene/Scene.h"
|
#include "Scene/Scene.h"
|
||||||
#include "System/KeyboardInput.h"
|
#include "System/KeyboardInput.h"
|
||||||
#include "Window/View.h"
|
#include "Window/View.h"
|
||||||
|
#include "Window/Application.h"
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#include "Platform/Windows/GameInterface.h" // TODO
|
#include "Platform/Windows/GameInterface.h" // TODO
|
||||||
@@ -12,7 +13,7 @@
|
|||||||
namespace Seele {
|
namespace Seele {
|
||||||
class GameView : public View {
|
class GameView : public View {
|
||||||
public:
|
public:
|
||||||
GameView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo& createInfo, std::filesystem::path dllPath);
|
GameView(Gfx::PGraphics graphics, PWindow window, PScene scene, const ViewportCreateInfo& createInfo);
|
||||||
virtual ~GameView();
|
virtual ~GameView();
|
||||||
virtual void beginUpdate() override;
|
virtual void beginUpdate() override;
|
||||||
virtual void update() override;
|
virtual void update() override;
|
||||||
@@ -26,19 +27,17 @@ class GameView : public View {
|
|||||||
protected:
|
protected:
|
||||||
virtual void applyArea(URect rect) override;
|
virtual void applyArea(URect rect) override;
|
||||||
Gfx::PGraphics graphics;
|
Gfx::PGraphics graphics;
|
||||||
OScene scene;
|
PScene scene;
|
||||||
GameInterface gameInterface;
|
|
||||||
RenderGraph renderGraph;
|
RenderGraph renderGraph;
|
||||||
RenderGraph rayTracingGraph;
|
RenderGraph rayTracingGraph;
|
||||||
|
|
||||||
OSystemGraph systemGraph;
|
|
||||||
System::PKeyboardInput keyboardSystem;
|
System::PKeyboardInput keyboardSystem;
|
||||||
float updateTime = 0;
|
float updateTime = 0;
|
||||||
|
|
||||||
virtual void keyCallback(KeyCode code, InputAction action, KeyModifierFlags modifier) override;
|
virtual void keyCallback(KeyCode code, InputAction action, KeyModifierFlags modifier) override;
|
||||||
virtual void mouseMoveCallback(double xPos, double yPos) override;
|
virtual void mouseMoveCallback(double xPos, double yPos) override;
|
||||||
virtual void mouseButtonCallback(MouseButton button, InputAction action, KeyModifierFlags modifier) override;
|
virtual void mouseButtonCallback(MouseButton button, InputAction action, KeyModifierFlags modifier) override;
|
||||||
virtual void scrollCallback(double xOffset, double yOffset) override;
|
virtual void scrollCallback(double xPos, double yPos, double xScroll, double yScroll) override;
|
||||||
virtual void fileCallback(int count, const char** paths) override;
|
virtual void fileCallback(int count, const char** paths) override;
|
||||||
};
|
};
|
||||||
DEFINE_REF(GameView)
|
DEFINE_REF(GameView)
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ View::View(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo& vi
|
|||||||
: graphics(graphics), createInfo(viewportInfo), owner(window), name(name) {
|
: graphics(graphics), createInfo(viewportInfo), owner(window), name(name) {
|
||||||
viewport = graphics->createViewport(owner->getGfxHandle(), viewportInfo);
|
viewport = graphics->createViewport(owner->getGfxHandle(), viewportInfo);
|
||||||
owner->addView(this);
|
owner->addView(this);
|
||||||
setFocused();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
View::~View() {}
|
View::~View() {}
|
||||||
@@ -20,6 +19,4 @@ void View::resize(URect area) {
|
|||||||
applyArea(area);
|
applyArea(area);
|
||||||
}
|
}
|
||||||
|
|
||||||
void View::setFocused() { owner->setFocused(this); }
|
|
||||||
|
|
||||||
const std::string& View::getName() { return name; }
|
const std::string& View::getName() { return name; }
|
||||||
@@ -16,7 +16,6 @@ class View {
|
|||||||
virtual void prepareRender() = 0;
|
virtual void prepareRender() = 0;
|
||||||
virtual void render() = 0;
|
virtual void render() = 0;
|
||||||
void resize(URect area);
|
void resize(URect area);
|
||||||
void setFocused();
|
|
||||||
|
|
||||||
const std::string& getName();
|
const std::string& getName();
|
||||||
|
|
||||||
@@ -31,7 +30,7 @@ class View {
|
|||||||
virtual void keyCallback(KeyCode code, InputAction action, uint32_t modifier) = 0;
|
virtual void keyCallback(KeyCode code, InputAction action, uint32_t modifier) = 0;
|
||||||
virtual void mouseMoveCallback(double xPos, double yPos) = 0;
|
virtual void mouseMoveCallback(double xPos, double yPos) = 0;
|
||||||
virtual void mouseButtonCallback(MouseButton button, InputAction action, uint32_t modifier) = 0;
|
virtual void mouseButtonCallback(MouseButton button, InputAction action, uint32_t modifier) = 0;
|
||||||
virtual void scrollCallback(double xOffset, double yOffset) = 0;
|
virtual void scrollCallback(double xPos, double yPos, double xScroll, double yScroll) = 0;
|
||||||
virtual void fileCallback(int count, const char** paths) = 0;
|
virtual void fileCallback(int count, const char** paths) = 0;
|
||||||
friend class Window;
|
friend class Window;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
#include "Window.h"
|
#include "Window.h"
|
||||||
#include "WindowManager.h"
|
#include "Application.h"
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
using namespace Seele;
|
using namespace Seele;
|
||||||
|
|
||||||
Window::Window(PWindowManager owner, Gfx::OWindow handle) : owner(owner), gfxHandle(std::move(handle)) {
|
Window::Window(PApplication owner, Gfx::OWindow handle) : owner(owner), gfxHandle(std::move(handle)) {
|
||||||
gfxHandle->setResizeCallback([this](uint32 w, uint32 h) { onResize(w, h); });
|
gfxHandle->setResizeCallback([this](uint32 w, uint32 h) { onResize(w, h); });
|
||||||
|
installInputCallbacks();
|
||||||
}
|
}
|
||||||
|
|
||||||
Window::~Window() {}
|
Window::~Window() {}
|
||||||
@@ -28,23 +29,95 @@ void Window::render() {
|
|||||||
|
|
||||||
Gfx::PWindow Window::getGfxHandle() { return gfxHandle; }
|
Gfx::PWindow Window::getGfxHandle() { return gfxHandle; }
|
||||||
|
|
||||||
void Window::setFocused(PView view) {
|
// The one-shot input dispatchers. Bound ONCE in the ctor (not per focus change), so the
|
||||||
auto keyFunction = std::bind(&View::keyCallback, view.getHandle(), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
|
// GLFW layer always talks to a stable `Window::on*` that routes per-event. This is the
|
||||||
auto mouseMoveFunction = std::bind(&View::mouseMoveCallback, view.getHandle(), std::placeholders::_1, std::placeholders::_2);
|
// replacement for the old setFocused rebind, which silently made the last-constructed view
|
||||||
auto mouseButtonFunction =
|
// the sole input target.
|
||||||
std::bind(&View::mouseButtonCallback, view.getHandle(), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
|
void Window::installInputCallbacks() {
|
||||||
auto scrollFunction = std::bind(&View::scrollCallback, view.getHandle(), std::placeholders::_1, std::placeholders::_2);
|
gfxHandle->setKeyCallback([this](KeyCode code, InputAction action, KeyModifierFlags modifier) { onKeyPress(code, action, modifier); });
|
||||||
auto fileFunction = std::bind(&View::fileCallback, view.getHandle(), std::placeholders::_1, std::placeholders::_2);
|
gfxHandle->setMouseMoveCallback([this](double x, double y) { onMouseMove(x, y); });
|
||||||
gfxHandle->setKeyCallback(keyFunction);
|
gfxHandle->setMouseButtonCallback([this](MouseButton button, InputAction action, KeyModifierFlags modifier) { onMouseButton(button, action, modifier); });
|
||||||
gfxHandle->setMouseMoveCallback(mouseMoveFunction);
|
gfxHandle->setScrollCallback([this](double x, double y, double xScroll, double yScroll) { onScroll(x, y, xScroll, yScroll); });
|
||||||
gfxHandle->setMouseButtonCallback(mouseButtonFunction);
|
gfxHandle->setFileCallback([this](int count, const char** paths) {
|
||||||
gfxHandle->setScrollCallback(scrollFunction);
|
// File drops have no cursor-position meaning for per-view routing; deliver to the
|
||||||
gfxHandle->setFileCallback(fileFunction);
|
// keyboard-focus owner (or the first view as a fallback) -- a drop is a user action
|
||||||
|
// aimed at "the app", not a specific pane.
|
||||||
|
if (keyboardFocus != nullptr) {
|
||||||
|
keyboardFocus->fileCallback(count, paths);
|
||||||
|
} else if (views.size() > 0) {
|
||||||
|
views[0]->fileCallback(count, paths);
|
||||||
|
}
|
||||||
|
});
|
||||||
gfxHandle->setCloseCallback([this]() {
|
gfxHandle->setCloseCallback([this]() {
|
||||||
owner->notifyWindowClosed(this);
|
owner->notifyWindowClosed(this);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SPATIAL pointer routing. `x`/`y` are window/client coords (GLFW gives these). We hit-test
|
||||||
|
// every view's on-screen rect and deliver to the view(s) under the cursor, in view-local
|
||||||
|
// coords (window pos minus the rect origin). The layout is a flat, non-overlapping column
|
||||||
|
// split (see onResize), so at most ONE view can be under the cursor -- but we loop anyway so
|
||||||
|
// a future overlapping layout (dockable panes) keeps working without changes here.
|
||||||
|
//
|
||||||
|
// Coordinate offset is the crux: GLFW hands us window-absolute coords, but views (the UI
|
||||||
|
// system, the 3D camera rig) consume VIEW-LOCAL coords. The old code passed raw window
|
||||||
|
// coords, which only "worked" for the left-anchored (x=0) inspector. The offset below is
|
||||||
|
// what makes per-view input correct for ANY rect origin.
|
||||||
|
void Window::onMouseMove(double x, double y) {
|
||||||
|
lastPointerX = x;
|
||||||
|
lastPointerY = y;
|
||||||
|
for (auto& view : views) {
|
||||||
|
URect rect = view->viewport->getRenderArea();
|
||||||
|
if (rect.contains(x, y)) {
|
||||||
|
view->mouseMoveCallback(x - static_cast<double>(rect.offset.x), y - static_cast<double>(rect.offset.y));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::onMouseButton(MouseButton button, InputAction action, KeyModifierFlags modifier) {
|
||||||
|
// GLFW gives us the button+action but NOT the cursor position, so we hit-test using the
|
||||||
|
// last known pointer location (kept in sync by onMouseMove). For a column layout the
|
||||||
|
// pointer is effectively static between a move and the next press, so this is accurate.
|
||||||
|
lastClickedView = nullptr;
|
||||||
|
for (auto& view : views) {
|
||||||
|
URect rect = view->viewport->getRenderArea();
|
||||||
|
if (rect.contains(lastPointerX, lastPointerY)) {
|
||||||
|
lastClickedView = view;
|
||||||
|
view->mouseButtonCallback(button, action, modifier);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// CLICK-TO-FOCUS: a press (not a hover, not a release) inside a view gives that view
|
||||||
|
// the keyboard. This is the only sane keyboard-ownership rule -- the keyboard has no
|
||||||
|
// position, so focus must be an explicit user gesture, never construction order.
|
||||||
|
if (action == InputAction::PRESS && lastClickedView != nullptr) {
|
||||||
|
keyboardFocus = lastClickedView;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::onScroll(double x, double y, double xScroll, double yScroll) {
|
||||||
|
// The scroll callback now carries the cursor position (x, y) — see the Gfx::Window
|
||||||
|
// signature. Scroll is a spatial event, so route it exactly like a mouse move.
|
||||||
|
for (auto& view : views) {
|
||||||
|
URect rect = view->viewport->getRenderArea();
|
||||||
|
if (rect.contains(x, y)) {
|
||||||
|
view->scrollCallback(x - static_cast<double>(rect.offset.x), y - static_cast<double>(rect.offset.y), xScroll, yScroll);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FOCUS-based keyboard routing: a key event has no position, so it goes to exactly one
|
||||||
|
// owner (keyboardFocus) -- the view last clicked into. With no focus, the event is dropped
|
||||||
|
// (better than sending it to an arbitrary view).
|
||||||
|
void Window::onKeyPress(KeyCode code, InputAction action, KeyModifierFlags modifier) {
|
||||||
|
if (keyboardFocus != nullptr) {
|
||||||
|
keyboardFocus->keyCallback(code, action, static_cast<uint32_t>(modifier));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::setKeyboardFocus(PView view) {
|
||||||
|
keyboardFocus = view;
|
||||||
|
}
|
||||||
|
|
||||||
void Window::onResize(uint32 width, uint32 height) {
|
void Window::onResize(uint32 width, uint32 height) {
|
||||||
// one column per view, in registration order. 2 views = a 50/50 split.
|
// one column per view, in registration order. 2 views = a 50/50 split.
|
||||||
const uint32 n = views.size();
|
const uint32 n = views.size();
|
||||||
|
|||||||
@@ -3,24 +3,56 @@
|
|||||||
#include "View.h"
|
#include "View.h"
|
||||||
|
|
||||||
namespace Seele {
|
namespace Seele {
|
||||||
DECLARE_REF(WindowManager)
|
DECLARE_REF(Application)
|
||||||
// The logical window, with the graphics proxy
|
// The logical window, with the graphics proxy
|
||||||
class Window {
|
class Window {
|
||||||
public:
|
public:
|
||||||
Window(PWindowManager owner, Gfx::OWindow handle);
|
Window(PApplication owner, Gfx::OWindow handle);
|
||||||
~Window();
|
~Window();
|
||||||
void show() { gfxHandle->show(); }
|
void show() { gfxHandle->show(); }
|
||||||
void addView(PView view);
|
void addView(PView view);
|
||||||
void pollInputs();
|
void pollInputs();
|
||||||
void render();
|
void render();
|
||||||
Gfx::PWindow getGfxHandle();
|
Gfx::PWindow getGfxHandle();
|
||||||
void setFocused(PView view);
|
// The Application that owns this window (non-owning). Views use this to reach
|
||||||
|
// the world's services (e.g. the input sink) without a global lookup.
|
||||||
|
PApplication app() const { return owner; }
|
||||||
|
void setKeyboardFocus(PView view);
|
||||||
void onResize(uint32 width, uint32 height);
|
void onResize(uint32 width, uint32 height);
|
||||||
constexpr bool isPaused() const { return gfxHandle->isPaused(); }
|
constexpr bool isPaused() const { return gfxHandle->isPaused(); }
|
||||||
constexpr bool shouldClose() const { return gfxHandle->shouldClose(); }
|
constexpr bool shouldClose() const { return gfxHandle->shouldClose(); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
PWindowManager owner;
|
// Install the one-shot per-event dispatchers. `gfxHandle->pollInput()` fires the
|
||||||
|
// GLFW callbacks into these; they route each event to the right view(s). Bound ONCE
|
||||||
|
// here (not per setFocused) so the "last view wins" rebind bug is gone for good.
|
||||||
|
void installInputCallbacks();
|
||||||
|
|
||||||
|
// Pointer (mouse/scroll) routing: SPATIAL. The position is window/client coords; we
|
||||||
|
// hit-test every view's on-screen rect (already valid via onResize) and deliver to the
|
||||||
|
// view(s) under the cursor, in VIEW-LOCAL coords (window pos minus the rect origin).
|
||||||
|
// This is what makes the game viewport and the inspector independently usable.
|
||||||
|
void onMouseMove(double x, double y);
|
||||||
|
void onMouseButton(MouseButton button, InputAction action, KeyModifierFlags modifier);
|
||||||
|
void onScroll(double x, double y, double xScroll, double yScroll);
|
||||||
|
|
||||||
|
// Keyboard routing: FOCUS. A key event has no position, so it goes to exactly one
|
||||||
|
// owner -- keyboardFocus -- which is set by clicking into a view (see onMouseButton).
|
||||||
|
void onKeyPress(KeyCode code, InputAction action, KeyModifierFlags modifier);
|
||||||
|
|
||||||
|
// The window's keyboard focus owner (click-to-focus). Null until the user clicks a
|
||||||
|
// view; a key event with no focus is dropped.
|
||||||
|
PView keyboardFocus = nullptr;
|
||||||
|
|
||||||
|
// GLFW's mouse-button callback does not carry a cursor position, so pointer hit-testing
|
||||||
|
// for press/release uses the last known pointer location (kept fresh by onMouseMove).
|
||||||
|
// For a static column layout the pointer does not move between a move event and the
|
||||||
|
// following press, so this is accurate in practice.
|
||||||
|
double lastPointerX = 0.0;
|
||||||
|
double lastPointerY = 0.0;
|
||||||
|
PView lastClickedView = nullptr;
|
||||||
|
|
||||||
|
PApplication owner;
|
||||||
Array<PView> views;
|
Array<PView> views;
|
||||||
Gfx::OWindow gfxHandle;
|
Gfx::OWindow gfxHandle;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
#include "WindowManager.h"
|
|
||||||
#include "Graphics/Graphics.h"
|
|
||||||
|
|
||||||
using namespace Seele;
|
|
||||||
|
|
||||||
WindowManager::WindowManager() {}
|
|
||||||
|
|
||||||
WindowManager::~WindowManager() {}
|
|
||||||
|
|
||||||
OWindow WindowManager::addWindow(Gfx::PGraphics graphics, const WindowCreateInfo& createInfo) {
|
|
||||||
OWindow window = new Window(this, graphics->createWindow(createInfo));
|
|
||||||
windows.add(window);
|
|
||||||
return window;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WindowManager::render() {
|
|
||||||
for (auto& window : windows) {
|
|
||||||
window->pollInputs();
|
|
||||||
if (window->isPaused())
|
|
||||||
continue;
|
|
||||||
window->render();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void WindowManager::notifyWindowClosed(PWindow window) { windows.remove(window); }
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "Containers/Array.h"
|
|
||||||
#include "Window.h"
|
|
||||||
|
|
||||||
namespace Seele {
|
|
||||||
DECLARE_NAME_REF(Gfx, Graphics)
|
|
||||||
class WindowManager {
|
|
||||||
public:
|
|
||||||
WindowManager();
|
|
||||||
~WindowManager();
|
|
||||||
OWindow addWindow(Gfx::PGraphics graphics, const WindowCreateInfo& createInfo);
|
|
||||||
void render();
|
|
||||||
void notifyWindowClosed(PWindow window);
|
|
||||||
bool isActive() const { return getGlobals().running && windows.size(); }
|
|
||||||
|
|
||||||
private:
|
|
||||||
Array<PWindow> windows;
|
|
||||||
};
|
|
||||||
DEFINE_REF(WindowManager)
|
|
||||||
} // namespace Seele
|
|
||||||
Reference in new issue
Block a user