mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-11-20 17:39:46 +00:00
Give the Wayland window an Adwaita-like frame
The engine-drawn title bar grew to 48 px with 24x24 window controls, 12 px away from the edge and from each other, all sharing one hover highlight. The controls use textures now (gui/cross, gui/minimize_w, gui/maximize_w and gui/restore_w when maximized) with the vector icons kept as a fallback, and the title is centred in the bar, clamped to the free space between the button groups. The bar now sits inside invisible margins that carry a drop shadow, so the window is resizable from outside the visible frame: the surface is content plus twice SHADOW_MARGIN and xdg_surface.set_window_geometry tells the compositor which part is the window. The shadow follows Adwaita's window shadow: a Gaussian blur of 7 px (sigma 3.5) expanded by 1 px, rgba(0,0,0,0.5) focused and 0.3 in the backdrop, plus a 1 px hairline, symmetric on all four sides - a 16 px wide frame would show a fatter tail than the reference. Margins exist only while the window is decorated by us and not maximized or fullscreen. The engine composes the frame itself: it renders exactly as before, then the backend copies the frame into a texture, clears the surface, draws the shadow and puts the content in place with alpha forced to 1, which keeps the frame opaque without touching a single render pass. Only frames the engine actually drew are cached, and the EGL window is resized before its surface size is asked for, so no frame is composed from a buffer the compositor just replaced - that was the one frame blink after a resize. Resize cursors match GNOME: directional shapes for edges and corners (w/e/n/s/ne/nw/se/sw) instead of the double-headed diagonals, with the extra CursorShape values appended so the existing GLFW indices stay. Measured: window 1123x751 opens as saved, fullscreen round trip returns the same size with the settings untouched, the shadow alpha profile is 0.20/0.10/0.03 at 1/4/7 px from the edge against Adwaita's 0.21/0.095/ 0.055, all four sides equal, menu layout baseline unchanged (706), no errors in the log.
This commit is contained in:
parent
6c2192b5d8
commit
c269d6efb3
11 changed files with 434 additions and 58 deletions
|
|
@ -7,6 +7,7 @@
|
|||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include "graphics/core/Shader.hpp"
|
||||
#include "graphics/core/Font.hpp"
|
||||
#include "graphics/core/Texture.hpp"
|
||||
#include "graphics/ui/GUI.hpp"
|
||||
#include "window/Window.hpp"
|
||||
#include "assets/Assets.hpp"
|
||||
|
|
@ -78,10 +79,19 @@ void draw_window_bar(Engine& engine) {
|
|||
titleLength--;
|
||||
}
|
||||
if (titleLength > 0) {
|
||||
const float textWidth = static_cast<float>(
|
||||
font->calcWidth(title, titleLength)
|
||||
);
|
||||
const float centered = (static_cast<float>(size.x) - textWidth) * 0.5f;
|
||||
const float titleX = std::clamp(
|
||||
centered,
|
||||
titleLeft,
|
||||
std::max(titleLeft, titleRight - textWidth)
|
||||
);
|
||||
batch->setColor(glm::vec4(1.0f, 1.0f, 1.0f, 0.85f));
|
||||
font->draw(
|
||||
*batch, std::wstring_view(title).substr(0, titleLength),
|
||||
static_cast<int>(titleLeft),
|
||||
static_cast<int>(titleX),
|
||||
(height - font->getLineHeight()) / 2,
|
||||
nullptr, 0
|
||||
);
|
||||
|
|
@ -96,15 +106,34 @@ void draw_window_bar(Engine& engine) {
|
|||
const float cy = barHeight * 0.5f;
|
||||
const bool isHovered = hovered == static_cast<int>(i);
|
||||
if (isHovered) {
|
||||
batch->setColor(
|
||||
item.button == DecorationButton::CLOSE
|
||||
? glm::vec4(0.62f, 0.13f, 0.09f, 0.9f)
|
||||
: glm::vec4(1.0f, 1.0f, 1.0f, 0.16f)
|
||||
batch->setColor(glm::vec4(1.0f, 1.0f, 1.0f, 0.16f));
|
||||
const float button = item.width;
|
||||
batch->rect(
|
||||
item.x, (barHeight - button) * 0.5f, item.width, button
|
||||
);
|
||||
batch->rect(x, 0.0f, item.width, barHeight);
|
||||
}
|
||||
const float ink = isHovered ? 1.0f : 0.8f;
|
||||
batch->setColor(glm::vec4(1.0f, 1.0f, 1.0f, ink));
|
||||
const char* iconName =
|
||||
item.button == DecorationButton::CLOSE
|
||||
? "gui/cross"
|
||||
: item.button == DecorationButton::MINIMIZE
|
||||
? "gui/minimize_w"
|
||||
: window.isMaximized() ? "gui/restore_w"
|
||||
: "gui/maximize_w";
|
||||
auto icon = engine.requireAssets().getShared<Texture>(iconName);
|
||||
if (icon != nullptr) {
|
||||
const float iconSize = std::min(
|
||||
16.0f, static_cast<float>(icon->getWidth())
|
||||
);
|
||||
batch->texture(icon.get());
|
||||
batch->rect(
|
||||
cx - iconSize * 0.5f, cy - iconSize * 0.5f, iconSize,
|
||||
iconSize, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, ink
|
||||
);
|
||||
batch->untexture();
|
||||
continue;
|
||||
}
|
||||
if (item.button == DecorationButton::CLOSE) {
|
||||
for (int step = 0; step < 8; step++) {
|
||||
batch->rect(cx - 5.0f + step, cy - 5.0f + step, thickness, thickness);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue