#include #include #include #include #include "panels/asset_browser_panel.hpp" #include "panels/inspector_panel.hpp" #include "panels/scene_hierarchy_panel.hpp" #include "panels/viewport_panel.hpp" class Editor : public sophia::Application { public: Editor() : Application{{.width = 750, .height = 1000, .name = "Editor"}} {} void onCreate() override { std::cout << "Editor created" << std::endl; debugUI().show(); textures.emplace_back("Checker", createCheckerTexture()); sophia::SceneHandle sceneHandle = scenes().create(); sophia::Scene& scene = scenes().get(sceneHandle); createDemoScene(scene); panels().emplace(scene, selected); panels().emplace(selected, textures); panels().emplace(); sophia::RenderTargetHandle sceneTarget = resources().create(); sceneViews().create({.scene = sceneHandle, .target = sceneTarget}); panels().emplace(ui(), sceneTarget, scene, selected); panels().setDefaultLayout( {.left = {"Scene Hierarchy"}, .right = {"Inspector", "Frame Stats", "PanelRegistry"}, .bottom = {"Asset Browser", "Console"}, .center = {"Viewport"}}); } void onUpdate(const sophia::FrameInfo& frameInfo) override {} private: void createDemoScene(sophia::Scene& scene) { scene.createCamera("Main Camera"); sophia::Entity checker = scene.createEntity("Checker"); checker.getComponent().position = {-1.5f, 0.f, 0.f}; checker.addComponent(sophia::SpriteComponent{ .texture = textures[0].second, .size = {2.f, 2.f}}); sophia::Entity red = scene.createEntity("Red"); red.getComponent().position = {1.f, -0.5f, 0.f}; red.addComponent(sophia::SpriteComponent{ .color = {0.9f, 0.25f, 0.25f, 1.f}, .size = {2.f, 2.f}}); // Drawn over "Red" because of its higher sort order. sophia::Entity blue = scene.createEntity("Blue (translucent)"); blue.getComponent().position = {1.75f, 0.25f, 0.f}; blue.addComponent( sophia::SpriteComponent{.color = {0.25f, 0.45f, 0.95f, 0.6f}, .size = {2.f, 2.f}, .sortOrder = 1}); } sophia::TextureHandle createCheckerTexture() { constexpr sophia::u32 SIZE = 8; std::vector pixels(SIZE * SIZE * 4); for (sophia::u32 y = 0; y < SIZE; y++) { for (sophia::u32 x = 0; x < SIZE; x++) { sophia::u8 value = ((x + y) % 2 == 0) ? 230 : 60; sophia::u8* pixel = &pixels[(y * SIZE + x) * 4]; pixel[0] = pixel[1] = pixel[2] = value; pixel[3] = 255; } } return resources().create(SIZE, SIZE, std::move(pixels)); } sophia::Entity selected; InspectorPanel::TextureList textures; }; SOPHIA_MAIN(Editor)