Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

feat: Add conditional MSDF/SystemFont support and fix WebPreviewServer

esengine734f89bcd731
diff --git a/src/esengine/editor/panels/AssetGridItem.cpp b/src/esengine/editor/panels/AssetGridItem.cpp
index ad0dffc08..2d6653b63 100644
--- a/src/esengine/editor/panels/AssetGridItem.cpp
+++ b/src/esengine/editor/panels/AssetGridItem.cpp
@@ -11,10 +11,15 @@
#include "AssetGridItem.hpp"
#include "../../ui/UIContext.hpp"
-#include "../../ui/font/MSDFFont.hpp"
#include "../../ui/icons/Icons.hpp"
#include "../../ui/rendering/UIBatchRenderer.hpp"
+#if ES_FEATURE_SDF_FONT
+#include "../../ui/font/MSDFFont.hpp"
+#endif
+
+#include "../../ui/font/SystemFont.hpp"
+
#include <chrono>
namespace esengine::editor {
@@ -46,7 +51,8 @@ const char* getAssetTypeIcon(AssetType type) {
}
}
-std::string truncateText(const std::string& text, ui::MSDFFont& font, f32 fontSize, f32 maxWidth) {
+template<typename FontType>
+std::string truncateText(const std::string& text, FontType& font, f32 fontSize, f32 maxWidth) {
glm::vec2 textSize = font.measureText(text, fontSize);
if (textSize.x <= maxWidth) {
return text;
@@ -162,7 +168,14 @@ void AssetGridItem::render(ui::UIBatchRenderer& renderer) {
renderer.drawRoundedRect(iconBounds, thumbnailBg, ui::CornerRadii::all(4.0f));
renderer.drawRoundedRectOutline(iconBounds, thumbnailBorder, ui::CornerRadii::all(4.0f), 1.0f);
+#if ES_FEATURE_SDF_FONT
ui::MSDFFont* iconFont = ctx->getIconMSDFFont();
+ ui::MSDFFont* font = ctx->getDefaultMSDFFont();
+#else
+ ui::SystemFont* iconFont = ctx->getIconSystemFont();
+ ui::SystemFont* font = ctx->getDefaultSystemFont();
+#endif
+
if (iconFont) {
glm::vec4 iconColor = getAssetTypeColor(entry_.type);
const char* icon = getAssetTypeIcon(entry_.type);
@@ -170,7 +183,6 @@ void AssetGridItem::render(ui::UIBatchRenderer& renderer) {
ui::HAlign::Center, ui::VAlign::Center);
}
- ui::MSDFFont* font = ctx->getDefaultMSDFFont();
if (font) {
f32 labelWidth = bounds.width - 8.0f;
ui::Rect labelBounds{
diff --git a/src/esengine/editor/panels/OutputLogPanel.cpp b/src/esengine/editor/panels/OutputLogPanel.cpp
index 75c2ef81a..d520618b7 100644
--- a/src/esengine/editor/panels/OutputLogPanel.cpp
+++ b/src/esengine/editor/panels/OutputLogPanel.cpp
@@ -19,6 +19,8 @@
#include "../../ui/font/MSDFFont.hpp"
#endif
+#include "../../ui/font/SystemFont.hpp"
+
namespace esengine::editor {
// =============================================================================
@@ -105,6 +107,10 @@ void OutputLogPanel::render(ui::UIBatchRenderer& renderer) {
#if ES_FEATURE_SDF_FONT
ui::MSDFFont* iconFont = ctx->getIconMSDFFont();
ui::MSDFFont* textFont = ctx->getDefaultMSDFFont();
+#else
+ ui::SystemFont* iconFont = ctx->getIconSystemFont();
+ ui::SystemFont* textFont = ctx->getDefaultSystemFont();
+#endif
if (iconFont) {
if (clearHovered_) {
@@ -169,7 +175,6 @@ void OutputLogPanel::render(ui::UIBatchRenderer& renderer) {
renderer.popClipRect();
}
-#endif
}
// =============================================================================
diff --git a/src/esengine/editor/panels/SceneViewPanel.cpp b/src/esengine/editor/panels/SceneViewPanel.cpp
index 88ef38fba..f7bb722fe 100644
--- a/src/esengine/editor/panels/SceneViewPanel.cpp
+++ b/src/esengine/editor/panels/SceneViewPanel.cpp
@@ -24,6 +24,8 @@
#include "../../ui/font/MSDFFont.hpp"
#endif
+#include "../../ui/font/SystemFont.hpp"
+
#include <glad/glad.h>
#include <cstdio>
#include <vector>
@@ -1015,6 +1017,9 @@ void SceneViewPanel::renderStats(ui::UIBatchRenderer& renderer) {
#if ES_FEATURE_SDF_FONT
ui::MSDFFont* font = ctx->getDefaultMSDFFont();
+#else
+ ui::SystemFont* font = ctx->getDefaultSystemFont();
+#endif
if (!font) return;
RenderPipeline::Stats stats{};
@@ -1086,7 +1091,6 @@ void SceneViewPanel::renderStats(ui::UIBatchRenderer& renderer) {
snprintf(buffer, sizeof(buffer), "Visible: %u Culled: %u", stats.visible_items, stats.culled_items);
renderer.drawText(buffer, glm::vec2(x, y), *font, fontSize, labelColor);
-#endif
}
// =============================================================================
diff --git a/src/esengine/editor/preview/WebPreviewServer.cpp b/src/esengine/editor/preview/WebPreviewServer.cpp
new file mode 100644
index 000000000..e9357f599
--- /dev/null
+++ b/src/esengine/editor/preview/WebPreviewServer.cpp
@@ -0,0 +1,154 @@
+/**
+ * @file WebPreviewServer.cpp
+ * @brief Local HTTP server for web preview implementation
+ *
+ * @author ESEngine Team
+ * @date 2026
+ *
+ * @copyright Copyright (c) 2026 ESEngine Team
+ * Licensed under the MIT License.
+ */
+
+#include "WebPreviewServer.hpp"
+#include "../../core/Log.hpp"
+
+#include <sstream>
+#include <filesystem>
+
+#ifdef ES_PLATFORM_WINDOWS
+#include <shellapi.h>
+#else
+#include <unistd.h>
+#include <signal.h>
+#include <sys/wait.h>
+#include <cstdlib>
+#endif
+
+namespace esengine {
+namespace editor {
+
+// =============================================================================
+// Destructor
+// =============================================================================
+
+WebPreviewServer::~WebPreviewServer() {
+ stop();
+}
+
+// =============================================================================
+// Public Methods
+// =============================================================================
+
+bool WebPreviewServer::start(const std::string& directory, u16 port) {
+ if (running_) {
+ ES_LOG_WARN("WebPreviewServer already running on port {}", port_);
+ return false;
+ }
+
+ if (!std::filesystem::exists(directory)) {
+ ES_LOG_ERROR("Web build directory does not exist: {}. Please build the web version first.", directory);
+ return false;
+ }
+
+ directory_ = directory;
+ port_ = port;
+
+#ifdef ES_PLATFORM_WINDOWS
+ std::stringstream cmd;
+ cmd << "python -m http.server " << port << " --directory \"" << directory << "\"";
+
+ STARTUPINFOA si = {};
+ si.cb = sizeof(si);
+ si.dwFlags = STARTF_USESHOWWINDOW;
+ si.wShowWindow = SW_HIDE;
+
+ PROCESS_INFORMATION pi = {};
+
+ std::string cmdStr = cmd.str();
+ if (!CreateProcessA(
+ nullptr,
+ const_cast<char*>(cmdStr.c_str()),
+ nullptr,
+ nullptr,
+ FALSE,
+ CREATE_NO_WINDOW,
+ nullptr,
+ directory.c_str(),
+ &si,
+ &pi
+ )) {
+ ES_LOG_ERROR("Failed to start HTTP server: error code {}", GetLastError());
+ return false;
+ }
+
+ processHandle_ = pi.hProcess;
+ threadHandle_ = pi.hThread;
+#else
+ pid_ = fork();
+ if (pid_ < 0) {
+ ES_LOG_ERROR("Failed to fork process for HTTP server");
+ return false;
+ }
+
+ if (pid_ == 0) {
+ std::string portStr = std::to_string(port);
+ execlp("python3", "python3", "-m", "http.server", portStr.c_str(),
+ "--directory", directory.c_str(), nullptr);
+ execlp("python", "python", "-m", "http.server", portStr.c_str(),
+ "--directory", directory.c_str(), nullptr);
+ _exit(1);
+ }
+#endif
+
+ running_ = true;
+ ES_LOG_INFO("HTTP server started on port {} serving {}", port_, directory_);
+ return true;
+}
+
+void WebPreviewServer::stop() {
+ if (!running_) {
+ return;
+ }
+
+#ifdef ES_PLATFORM_WINDOWS
+ if (processHandle_) {
+ TerminateProcess(processHandle_, 0);
+ CloseHandle(processHandle_);
+ processHandle_ = nullptr;
+ }
+ if (threadHandle_) {
+ CloseHandle(threadHandle_);
+ threadHandle_ = nullptr;
+ }
+#else
+ if (pid_ > 0) {
+ kill(pid_, SIGTERM);
+ waitpid(pid_, nullptr, 0);
+ pid_ = 0;
+ }
+#endif
+
+ running_ = false;
+ ES_LOG_INFO("HTTP server stopped");
+}
+
+std::string WebPreviewServer::getUrl() const {
+ std::stringstream ss;
+ ss << "http://localhost:" << port_ << "/";
+ return ss.str();
+}
+
+void WebPreviewServer::openInBrowser(const std::string& url) {
+#ifdef ES_PLATFORM_WINDOWS
+ ShellExecuteA(nullptr, "open", url.c_str(), nullptr, nullptr, SW_SHOWNORMAL);
+#elif defined(__APPLE__)
+ std::string cmd = "open \"" + url + "\"";
+ std::system(cmd.c_str());
+#else
+ std::string cmd = "xdg-open \"" + url + "\"";
+ std::system(cmd.c_str());
+#endif
+}
+
+} // namespace editor
+} // namespace esengine
diff --git a/src/esengine/editor/preview/WebPreviewServer.hpp b/src/esengine/editor/preview/WebPreviewServer.hpp
new file mode 100644
index 000000000..22decf62c
--- /dev/null
+++ b/src/esengine/editor/preview/WebPreviewServer.hpp
@@ -0,0 +1,54 @@
+/**
+ * @file WebPreviewServer.hpp
+ * @brief Local HTTP server for web preview
+ *
+ * @author ESEngine Team
+ * @date 2026
+ *
+ * @copyright Copyright (c) 2026 ESEngine Team
+ * Licensed under the MIT License.
+ */
+#pragma once
+
+#include "../../core/Types.hpp"
+#include <string>
+
+#ifdef ES_PLATFORM_WINDOWS
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#endif
+
+namespace esengine {
+namespace editor {
+
+class WebPreviewServer {
+public:
+ WebPreviewServer() = default;
+ ~WebPreviewServer();
+
+ WebPreviewServer(const WebPreviewServer&) = delete;
+ WebPreviewServer& operator=(const WebPreviewServer&) = delete;
+
+ bool start(const std::string& directory, u16 port = 8080);
+ void stop();
+ bool isRunning() const { return running_; }
+ u16 getPort() const { return port_; }
+ std::string getUrl() const;
+
+ static void openInBrowser(const std::string& url);
+
+private:
+ bool running_ = false;
+ u16 port_ = 8080;
+ std::string directory_;
+
+#ifdef ES_PLATFORM_WINDOWS
+ HANDLE processHandle_ = nullptr;
+ HANDLE threadHandle_ = nullptr;
+#else
+ pid_t pid_ = 0;
+#endif
+};
+
+} // namespace editor
+} // namespace esengine
diff --git a/src/esengine/editor/widgets/DrawerPanel.cpp b/src/esengine/editor/widgets/DrawerPanel.cpp
index 0a013417b..690ab9149 100644
--- a/src/esengine/editor/widgets/DrawerPanel.cpp
+++ b/src/esengine/editor/widgets/DrawerPanel.cpp
@@ -13,12 +13,14 @@
#include "../../ui/UIContext.hpp"
#include "../../ui/rendering/UIBatchRenderer.hpp"
#include "../../ui/icons/Icons.hpp"
-#include "../../math/Math.hpp"
#if ES_FEATURE_SDF_FONT
#include "../../ui/font/MSDFFont.hpp"
#endif
+#include "../../ui/font/SystemFont.hpp"
+#include "../../math/Math.hpp"
+
namespace esengine::editor {
// =============================================================================
@@ -137,6 +139,10 @@ void DrawerPanel::render(ui::UIBatchRenderer& renderer) {
#if ES_FEATURE_SDF_FONT
ui::MSDFFont* iconFont = ctx->getIconMSDFFont();
ui::MSDFFont* textFont = ctx->getDefaultMSDFFont();
+#else
+ ui::SystemFont* iconFont = ctx->getIconSystemFont();
+ ui::SystemFont* textFont = ctx->getDefaultSystemFont();
+#endif
f32 headerCenterY = bounds.y + HEADER_HEIGHT * 0.5f;
@@ -175,7 +181,6 @@ void DrawerPanel::render(ui::UIBatchRenderer& renderer) {
ui::HAlign::Center, ui::VAlign::Center);
}
}
-#endif
if (content_) {
content_->renderTree(renderer);
diff --git a/src/esengine/editor/widgets/EditorToolbar.cpp b/src/esengine/editor/widgets/EditorToolbar.cpp
index 41498aa8f..03a012299 100644
--- a/src/esengine/editor/widgets/EditorToolbar.cpp
+++ b/src/esengine/editor/widgets/EditorToolbar.cpp
@@ -18,6 +18,8 @@
#include "../../ui/font/MSDFFont.hpp"
#endif
+#include "../../ui/font/SystemFont.hpp"
+
namespace esengine::editor {
namespace icons = ui::icons;
@@ -53,6 +55,20 @@ void EditorToolbar::stop() {
}
}
+void EditorToolbar::startWebPreview(const std::string& directory) {
+ if (previewServer_.isRunning()) {
+ previewServer_.stop();
+ }
+ if (previewServer_.start(directory)) {
+ WebPreviewServer::openInBrowser(previewServer_.getUrl());
+ onWebPreview.publish();
+ }
+}
+
+void EditorToolbar::stopWebPreview() {
+ previewServer_.stop();
+}
+
// =============================================================================
// Layout
// =============================================================================
@@ -88,6 +104,9 @@ void EditorToolbar::render(ui::UIBatchRenderer& renderer) {
#if ES_FEATURE_SDF_FONT
ui::MSDFFont* iconFont = ctx->getIconMSDFFont();
+#else
+ ui::SystemFont* iconFont = ctx->getIconSystemFont();
+#endif
if (!iconFont) return;
auto drawButton = [&](const ButtonState& btn, const std::string& icon, bool active, const glm::vec4& activeBg) {
@@ -99,11 +118,14 @@ void EditorToolbar::render(ui::UIBatchRenderer& renderer) {
bool playing = state_ == PlayState::Playing;
bool paused = state_ == PlayState::Paused;
+ bool previewing = previewServer_.isRunning();
+
+ constexpr glm::vec4 previewingBg{0.180f, 0.545f, 0.341f, 1.0f};
drawButton(playButton_, icons::Play, playing, playingBg);
drawButton(pauseButton_, icons::Pause, paused, pausedBg);
drawButton(stopButton_, icons::Square, false, buttonBg);
-#endif
+ drawButton(webPreviewButton_, icons::Globe, previewing, previewingBg);
}
// =============================================================================
@@ -136,6 +158,11 @@ bool EditorToolbar::onMouseDown(const ui::MouseButtonEvent& event) {
return true;
}
+ if (webPreviewButton_.bounds.contains(event.x, event.y)) {
+ onWebPreview.publish();
+ return true;
+ }
+
return false;
}
@@ -143,6 +170,7 @@ bool EditorToolbar::onMouseMove(const ui::MouseMoveEvent& event) {
playButton_.hovered = playButton_.bounds.contains(event.x, event.y);
pauseButton_.hovered = pauseButton_.bounds.contains(event.x, event.y);
stopButton_.hovered = stopButton_.bounds.contains(event.x, event.y);
+ webPreviewButton_.hovered = webPreviewButton_.bounds.contains(event.x, event.y);
return false;
}
@@ -156,6 +184,7 @@ void EditorToolbar::updateButtonBounds() {
constexpr f32 buttonSize = 28.0f;
constexpr f32 buttonGap = 4.0f;
constexpr f32 groupWidth = buttonSize * 3 + buttonGap * 2;
+ constexpr f32 padding = 8.0f;
f32 centerX = bounds.x + bounds.width * 0.5f;
f32 startX = centerX - groupWidth * 0.5f;
@@ -164,6 +193,9 @@ void EditorToolbar::updateButtonBounds() {
playButton_.bounds = ui::Rect{startX, centerY, buttonSize, buttonSize};
pauseButton_.bounds = ui::Rect{startX + buttonSize + buttonGap, centerY, buttonSize, buttonSize};
stopButton_.bounds = ui::Rect{startX + (buttonSize + buttonGap) * 2, centerY, buttonSize, buttonSize};
+
+ f32 rightX = bounds.x + bounds.width - padding - buttonSize;
+ webPreviewButton_.bounds = ui::Rect{rightX, centerY, buttonSize, buttonSize};
}
} // namespace esengine::editor
diff --git a/src/esengine/editor/widgets/SceneToolbar.cpp b/src/esengine/editor/widgets/SceneToolbar.cpp
index e58382d00..13b532a60 100644
--- a/src/esengine/editor/widgets/SceneToolbar.cpp
+++ b/src/esengine/editor/widgets/SceneToolbar.cpp
@@ -18,6 +18,8 @@
#include "../../ui/font/MSDFFont.hpp"
#endif
+#include "../../ui/font/SystemFont.hpp"
+
namespace esengine::editor {
namespace icons = ui::icons;
@@ -93,6 +95,9 @@ void SceneToolbar::render(ui::UIBatchRenderer& renderer) {
#if ES_FEATURE_SDF_FONT
ui::MSDFFont* iconFont = ctx->getIconMSDFFont();
+#else
+ ui::SystemFont* iconFont = ctx->getIconSystemFont();
+#endif
if (!iconFont) return;
auto drawButton = [&](const ui::Rect& btnBounds, const char* icon, bool active, bool hovered) {
@@ -119,7 +124,6 @@ void SceneToolbar::render(ui::UIBatchRenderer& renderer) {
drawButton(scaleButtonBounds_, icons::Scale3d, gizmoMode_ == GizmoMode::Scale, hoveredButton_ == 6);
drawButton(stats_button_bounds_, icons::Info, stats_visible_, hoveredButton_ == 7);
-#endif
}
// =============================================================================
diff --git a/src/esengine/editor/widgets/StatusBar.cpp b/src/esengine/editor/widgets/StatusBar.cpp
index 8c697fec6..6891ce423 100644
--- a/src/esengine/editor/widgets/StatusBar.cpp
+++ b/src/esengine/editor/widgets/StatusBar.cpp
@@ -19,6 +19,8 @@
#include "../../ui/font/MSDFFont.hpp"
#endif
+#include "../../ui/font/SystemFont.hpp"
+
namespace esengine::editor {
// =============================================================================
@@ -70,6 +72,10 @@ void StatusBar::render(ui::UIBatchRenderer& renderer) {
#if ES_FEATURE_SDF_FONT
ui::MSDFFont* iconFont = ctx->getIconMSDFFont();
ui::MSDFFont* textFont = ctx->getDefaultMSDFFont();
+#else
+ ui::SystemFont* iconFont = ctx->getIconSystemFont();
+ ui::SystemFont* textFont = ctx->getDefaultSystemFont();
+#endif
if (assetsButton_.bounds.width > 0) {
glm::vec4 btnBg = assetsDrawerOpen_ ? activeBg : assetsBtnBg;
@@ -195,7 +201,6 @@ void StatusBar::render(ui::UIBatchRenderer& renderer) {
renderer.drawTextInBounds("Saved", saveTextBounds, *textFont, 11.0f, textColor,
ui::HAlign::Left, ui::VAlign::Center);
}
-#endif
}
// =============================================================================