mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-11-23 02:49:46 +00:00
Fix the engine window frame on windows
Four things came out of testing on windows. The window settings were hidden outside of wayland because the check used the backend name, while the bar height matters wherever the engine draws the frame. The window now reports that (hasEngineFrame: barEnabled on wayland, engineFrame on glfw) and the display page asks for it. Only the live resize switch stays wayland specific, since the glfw backend always draws a fresh frame. The simplified mode is gone: when the frame is active and the surface has alpha, the shadow and the outer resize border are always there. The bar and its controls are drawn even when the font is missing: the early return used to make the whole bar invisible while its hit zones kept working. GLFW rewrites the window style on every mode change and dropped the thick frame the native resize border and snapping need, so the frame is set up again after such a change. Windows runs a modal loop while a window border is dragged and the main loop is blocked inside it, which froze the content during a resize. The backend draws and presents a frame from the refresh callback now, and skips the framerate limit there.
This commit is contained in:
parent
4bc81af726
commit
68d4214627
11 changed files with 96 additions and 52 deletions
|
|
@ -66,16 +66,16 @@ function on_open()
|
||||||
"</select>", app.get_setting("display.window-mode"))
|
"</select>", app.get_setting("display.window-mode"))
|
||||||
)
|
)
|
||||||
|
|
||||||
-- these only affect the window frame the native wayland backend draws
|
-- the bar height matters wherever the engine draws the window frame
|
||||||
if app.get_window_backend() == "wayland" then
|
if app.has_engine_window_frame() then
|
||||||
create_checkbox(
|
create_checkbox(
|
||||||
"display.compact-window-bar", "Narrow Window Bar",
|
"display.compact-window-bar", "Narrow Window Bar",
|
||||||
"display.compact-window-bar.tooltip"
|
"display.compact-window-bar.tooltip"
|
||||||
)
|
)
|
||||||
create_checkbox(
|
end
|
||||||
"display.simple-window", "Simple Window",
|
-- live rendering only has the cached frame as its alternative, which is
|
||||||
"display.simple-window.tooltip"
|
-- what the native wayland backend does
|
||||||
)
|
if app.get_window_backend() == "wayland" then
|
||||||
create_checkbox(
|
create_checkbox(
|
||||||
"display.live-resize", "Live Window Resize",
|
"display.live-resize", "Live Window Resize",
|
||||||
"display.live-resize.tooltip"
|
"display.live-resize.tooltip"
|
||||||
|
|
|
||||||
|
|
@ -119,10 +119,8 @@ settings.Clouds quality=Качество облаков
|
||||||
settings.Acoustic effects=Акустические эффекты
|
settings.Acoustic effects=Акустические эффекты
|
||||||
settings.Microphone access=Доступ к микрофону
|
settings.Microphone access=Доступ к микрофону
|
||||||
settings.Narrow Window Bar=Узкая шапка окна
|
settings.Narrow Window Bar=Узкая шапка окна
|
||||||
settings.Simple Window=Простое окно
|
|
||||||
settings.Live Window Resize=Живой ресайз окна
|
settings.Live Window Resize=Живой ресайз окна
|
||||||
settings.display.compact-window-bar.tooltip=Шапка окна высотой 24 px вместо 48 px
|
settings.display.compact-window-bar.tooltip=Шапка окна высотой 24 px вместо 48 px
|
||||||
settings.display.simple-window.tooltip=Без тени и внешней рамки ресайза
|
|
||||||
settings.display.live-resize.tooltip=Перерисовывать содержимое окна при изменении размера (выключено — последний кадр растягивается)
|
settings.display.live-resize.tooltip=Перерисовывать содержимое окна при изменении размера (выключено — последний кадр растягивается)
|
||||||
|
|
||||||
# Управление
|
# Управление
|
||||||
|
|
|
||||||
|
|
@ -40,9 +40,6 @@ void draw_window_bar(Engine& engine) {
|
||||||
}
|
}
|
||||||
auto* batch = engine.getGUI().getBatch2D();
|
auto* batch = engine.getGUI().getBatch2D();
|
||||||
auto font = engine.requireAssets().getShared<Font>(BAR_FONT);
|
auto font = engine.requireAssets().getShared<Font>(BAR_FONT);
|
||||||
if (font == nullptr) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const auto size = window.getSize();
|
const auto size = window.getSize();
|
||||||
const float barHeight = static_cast<float>(height);
|
const float barHeight = static_cast<float>(height);
|
||||||
|
|
||||||
|
|
@ -81,30 +78,35 @@ void draw_window_bar(Engine& engine) {
|
||||||
titleRight = std::min(titleRight, item.x - 8.0f);
|
titleRight = std::min(titleRight, item.x - 8.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const std::wstring title = to_wide(window.getTitle());
|
// the bar and its controls do not need the font, only the title does
|
||||||
const float available = std::max(0.0f, titleRight - titleLeft);
|
if (font != nullptr) {
|
||||||
size_t titleLength = title.size();
|
const std::wstring title = to_wide(window.getTitle());
|
||||||
while (titleLength > 0 && font->calcWidth(title, titleLength) > available) {
|
const float available = std::max(0.0f, titleRight - titleLeft);
|
||||||
titleLength--;
|
size_t titleLength = title.size();
|
||||||
}
|
while (titleLength > 0 &&
|
||||||
if (titleLength > 0) {
|
font->calcWidth(title, titleLength) > available) {
|
||||||
const float textWidth = static_cast<float>(
|
titleLength--;
|
||||||
font->calcWidth(title, titleLength)
|
}
|
||||||
);
|
if (titleLength > 0) {
|
||||||
const float centered = (static_cast<float>(size.x) - textWidth) * 0.5f;
|
const float textWidth = static_cast<float>(
|
||||||
const float titleX = std::clamp(
|
font->calcWidth(title, titleLength)
|
||||||
centered,
|
);
|
||||||
titleLeft,
|
const float centered =
|
||||||
std::max(titleLeft, titleRight - textWidth)
|
(static_cast<float>(size.x) - textWidth) * 0.5f;
|
||||||
);
|
const float titleX = std::clamp(
|
||||||
batch->setColor(glm::vec4(1.0f, 1.0f, 1.0f, 0.85f));
|
centered,
|
||||||
font->draw(
|
titleLeft,
|
||||||
*batch, std::wstring_view(title).substr(0, titleLength),
|
std::max(titleLeft, titleRight - textWidth)
|
||||||
static_cast<int>(titleX),
|
);
|
||||||
(height - font->getLineHeight()) / 2,
|
batch->setColor(glm::vec4(1.0f, 1.0f, 1.0f, 0.85f));
|
||||||
nullptr, 0
|
font->draw(
|
||||||
);
|
*batch, std::wstring_view(title).substr(0, titleLength),
|
||||||
batch->untexture();
|
static_cast<int>(titleX),
|
||||||
|
(height - font->getLineHeight()) / 2,
|
||||||
|
nullptr, 0
|
||||||
|
);
|
||||||
|
batch->untexture();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < buttons.size(); i++) {
|
for (size_t i = 0; i < buttons.size(); i++) {
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,14 @@ WindowControl::Result WindowControl::initialize() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Windows blocks the main loop inside its own modal loop while the user
|
||||||
|
// drags a window border, and asks for a repaint instead: drawing a frame
|
||||||
|
// from there is what keeps the content alive during such a resize.
|
||||||
|
window->setRefreshHandler([this] {
|
||||||
|
engine.renderFrame();
|
||||||
|
engine.getWindow().swapBuffers();
|
||||||
|
});
|
||||||
|
|
||||||
return Result {std::move(window), std::move(input)};
|
return Result {std::move(window), std::move(input)};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,6 @@ SettingsHandler::SettingsHandler(EngineSettings& settings) {
|
||||||
builder.add("window-mode", &settings.display.windowMode);
|
builder.add("window-mode", &settings.display.windowMode);
|
||||||
builder.add("adaptive-menu-fps", &settings.display.adaptiveFpsInMenu);
|
builder.add("adaptive-menu-fps", &settings.display.adaptiveFpsInMenu);
|
||||||
builder.add("compact-window-bar", &settings.display.compactWindowBar);
|
builder.add("compact-window-bar", &settings.display.compactWindowBar);
|
||||||
builder.add("simple-window", &settings.display.simpleWindow);
|
|
||||||
builder.add("live-resize", &settings.display.liveResize);
|
builder.add("live-resize", &settings.display.liveResize);
|
||||||
|
|
||||||
builder.addSection("camera");
|
builder.addSection("camera");
|
||||||
|
|
|
||||||
|
|
@ -229,6 +229,11 @@ static int l_open_url(lua::State* L) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// @brief Whether the engine draws the window frame itself
|
||||||
|
static int l_has_engine_window_frame(lua::State* L) {
|
||||||
|
return lua::pushboolean(L, engine->getWindow().hasEngineFrame());
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief Name of the windowing backend ("glfw" or "wayland")
|
/// @brief Name of the windowing backend ("glfw" or "wayland")
|
||||||
static int l_get_window_backend(lua::State* L) {
|
static int l_get_window_backend(lua::State* L) {
|
||||||
return lua::pushstring(L, engine->getWindow().getBackendName());
|
return lua::pushstring(L, engine->getWindow().getBackendName());
|
||||||
|
|
@ -508,6 +513,7 @@ const luaL_Reg applib[] = {
|
||||||
{"open_url", lua::wrap<l_open_url>},
|
{"open_url", lua::wrap<l_open_url>},
|
||||||
/// window
|
/// window
|
||||||
{"get_window_backend", lua::wrap<l_get_window_backend>},
|
{"get_window_backend", lua::wrap<l_get_window_backend>},
|
||||||
|
{"has_engine_window_frame", lua::wrap<l_has_engine_window_frame>},
|
||||||
{"focus", lua::wrap<l_focus>},
|
{"focus", lua::wrap<l_focus>},
|
||||||
{"set_title", lua::wrap<l_set_title>},
|
{"set_title", lua::wrap<l_set_title>},
|
||||||
{"quit", lua::wrap<l_quit>},
|
{"quit", lua::wrap<l_quit>},
|
||||||
|
|
|
||||||
|
|
@ -40,8 +40,6 @@ struct DisplaySettings {
|
||||||
FlagSetting adaptiveFpsInMenu {false};
|
FlagSetting adaptiveFpsInMenu {false};
|
||||||
/// @brief Draw the narrow (24px) window bar instead of the 48px one
|
/// @brief Draw the narrow (24px) window bar instead of the 48px one
|
||||||
FlagSetting compactWindowBar {false};
|
FlagSetting compactWindowBar {false};
|
||||||
/// @brief Draw the window without the shadow and the resize border
|
|
||||||
FlagSetting simpleWindow {false};
|
|
||||||
/// @brief Render the window content every frame while it is resized
|
/// @brief Render the window content every frame while it is resized
|
||||||
FlagSetting liveResize {true};
|
FlagSetting liveResize {true};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <stack>
|
#include <stack>
|
||||||
|
#include <functional>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
@ -72,6 +73,29 @@ public:
|
||||||
return empty;
|
return empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief Whether the engine draws the window frame itself here
|
||||||
|
///
|
||||||
|
/// The bar height and its buttons only mean something when it does, and
|
||||||
|
/// the window settings are only shown where that is the case.
|
||||||
|
/// @brief Handler the windowing system calls when it wants a repaint
|
||||||
|
///
|
||||||
|
/// Windows runs a modal loop while the user drags a window border and the
|
||||||
|
/// main loop is blocked inside it, so the only way to keep the content
|
||||||
|
/// alive during such a resize is to draw a frame from the message loop.
|
||||||
|
using RefreshHandler = std::function<void()>;
|
||||||
|
|
||||||
|
void setRefreshHandler(RefreshHandler handler) {
|
||||||
|
refreshHandler = std::move(handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
const RefreshHandler& getRefreshHandler() const {
|
||||||
|
return refreshHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool hasEngineFrame() const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
virtual const char* getBackendName() const = 0;
|
virtual const char* getBackendName() const = 0;
|
||||||
|
|
||||||
virtual int getDecorationHeight() const {
|
virtual int getDecorationHeight() const {
|
||||||
|
|
@ -118,6 +142,7 @@ protected:
|
||||||
std::stack<glm::vec4> scissorStack;
|
std::stack<glm::vec4> scissorStack;
|
||||||
glm::vec4 scissorArea {};
|
glm::vec4 scissorArea {};
|
||||||
WindowMode mode = WindowMode::WINDOWED;
|
WindowMode mode = WindowMode::WINDOWED;
|
||||||
|
RefreshHandler refreshHandler;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace display {
|
namespace display {
|
||||||
|
|
|
||||||
|
|
@ -307,7 +307,7 @@ public:
|
||||||
void swapBuffers() override {
|
void swapBuffers() override {
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
resetScissor();
|
resetScissor();
|
||||||
if (framerate > 0) {
|
if (framerate > 0 && !inRefreshCallback) {
|
||||||
auto elapsedTime = time() - prevSwap;
|
auto elapsedTime = time() - prevSwap;
|
||||||
auto frameTime = 1.0 / framerate;
|
auto frameTime = 1.0 / framerate;
|
||||||
if (elapsedTime < frameTime) {
|
if (elapsedTime < frameTime) {
|
||||||
|
|
@ -361,6 +361,13 @@ public:
|
||||||
return hoveredButton;
|
return hoveredButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool hasEngineFrame() const override {
|
||||||
|
return engineFrame;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @brief Set while a frame is drawn from the refresh callback
|
||||||
|
bool inRefreshCallback = false;
|
||||||
|
|
||||||
bool ownsCursor() const override {
|
bool ownsCursor() const override {
|
||||||
return frameCursorActive;
|
return frameCursorActive;
|
||||||
}
|
}
|
||||||
|
|
@ -739,8 +746,9 @@ private:
|
||||||
|
|
||||||
void applyDecoration() {
|
void applyDecoration() {
|
||||||
if (engineFrame) {
|
if (engineFrame) {
|
||||||
// frame_setup_native() owns the window style, GLFW would drop the
|
// GLFW rewrites the window style on every mode change and drops
|
||||||
// thick frame the native resize border and snapping need
|
// the thick frame the native resize border and snapping need
|
||||||
|
frame_setup_native(window, &frame_hit_test, this);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
glfwSetWindowAttrib(window, GLFW_DECORATED, GLFW_TRUE);
|
glfwSetWindowAttrib(window, GLFW_DECORATED, GLFW_TRUE);
|
||||||
|
|
@ -904,6 +912,12 @@ static void create_standard_cursors() {
|
||||||
static void refresh_callback(GLFWwindow* window) {
|
static void refresh_callback(GLFWwindow* window) {
|
||||||
auto handler = static_cast<GLFWWindow*>(glfwGetWindowUserPointer(window));
|
auto handler = static_cast<GLFWWindow*>(glfwGetWindowUserPointer(window));
|
||||||
handler->setShouldRefresh();
|
handler->setShouldRefresh();
|
||||||
|
const auto& refresh = handler->getRefreshHandler();
|
||||||
|
if (refresh) {
|
||||||
|
handler->inRefreshCallback = true;
|
||||||
|
refresh();
|
||||||
|
handler->inRefreshCallback = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setup_callbacks(GLFWwindow* window) {
|
static void setup_callbacks(GLFWwindow* window) {
|
||||||
|
|
|
||||||
|
|
@ -281,8 +281,7 @@ void WaylandWindow::setMaximized(bool enabled) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int WaylandWindow::marginSize() const {
|
int WaylandWindow::marginSize() const {
|
||||||
if (!barEnabled || !shadowEnabled ||
|
if (!barEnabled || !shadowEnabled) {
|
||||||
(settings != nullptr && settings->simpleWindow.get())) {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (fullscreen || maximized || Window::mode != WindowMode::WINDOWED) {
|
if (fullscreen || maximized || Window::mode != WindowMode::WINDOWED) {
|
||||||
|
|
@ -307,14 +306,6 @@ void WaylandWindow::updateSettings() {
|
||||||
if (settings == nullptr) {
|
if (settings == nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const bool simple = settings->simpleWindow.get();
|
|
||||||
if (simple != simpleWindowSetting) {
|
|
||||||
simpleWindowSetting = simple;
|
|
||||||
// The surface size depends on whether the frame around the content is
|
|
||||||
// drawn at all, so the egl window and the toplevel geometry change.
|
|
||||||
resize(size.x, size.y);
|
|
||||||
setShouldRefresh();
|
|
||||||
}
|
|
||||||
const bool compactBar = settings->compactWindowBar.get();
|
const bool compactBar = settings->compactWindowBar.get();
|
||||||
if (compactBar != compactBarSetting) {
|
if (compactBar != compactBarSetting) {
|
||||||
compactBarSetting = compactBar;
|
compactBarSetting = compactBar;
|
||||||
|
|
|
||||||
|
|
@ -114,6 +114,10 @@ class WaylandWindow : public Window {
|
||||||
void focus() override;
|
void focus() override;
|
||||||
void setTitle(const std::string& title) override;
|
void setTitle(const std::string& title) override;
|
||||||
const std::string& getTitle() const override;
|
const std::string& getTitle() const override;
|
||||||
|
bool hasEngineFrame() const override {
|
||||||
|
return barEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
const char* getBackendName() const override {
|
const char* getBackendName() const override {
|
||||||
return "wayland";
|
return "wayland";
|
||||||
}
|
}
|
||||||
|
|
@ -133,7 +137,6 @@ class WaylandWindow : public Window {
|
||||||
static constexpr int SHADOW_MARGIN = 10;
|
static constexpr int SHADOW_MARGIN = 10;
|
||||||
static constexpr int RESIZE_GRAB_EXTRA = 2;
|
static constexpr int RESIZE_GRAB_EXTRA = 2;
|
||||||
bool shadowEnabled = false;
|
bool shadowEnabled = false;
|
||||||
bool simpleWindowSetting = false;
|
|
||||||
bool compactBarSetting = false;
|
bool compactBarSetting = false;
|
||||||
GLuint shadowProgram = 0;
|
GLuint shadowProgram = 0;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue