mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-11-23 10:59:45 +00:00
draw window decorations with the engine GUI
The bar used to be drawn by the Wayland backend with its own shader, bitmap font and textures, straight into the engine's GL frame. That leaked GL state (the batch caches bound textures, so the engine kept sampling the backend texture and all text turned into solid white rectangles) and it duplicated fonts and styling. Now the backend only owns the behaviour: hit zones, cursor shapes, click interception and the compositor requests (move, resize, minimize, maximize/restore, close). The bar itself is drawn by the engine in WindowBar.cpp through the regular Batch2D/Font path, so it looks like the rest of the UI. Window gained getTitle(), getDecorationHeight() and getDecorationHoveredButton(); GLFW keeps the defaults, so X11 and Windows are unaffected. The backend's decoration drawing (bitmap font, shader, quad batches) is removed: WaylandBar.cpp went from 630 to 140 lines. Fixes found while debugging: - GlStateGuard was defined but never used after the file split, so the stretched frame left its texture bound and broke text rendering after a window mode change; it is now applied around the cache capture and the stretched frame; - takeScreenshot() now reads the front buffer and restores the read buffer afterwards.
This commit is contained in:
parent
b934e033b3
commit
3b337241f5
11 changed files with 890 additions and 1187 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
#include "Engine.hpp"
|
#include "Engine.hpp"
|
||||||
|
#include "WindowBar.hpp"
|
||||||
|
|
||||||
#ifndef GLEW_STATIC
|
#ifndef GLEW_STATIC
|
||||||
#define GLEW_STATIC
|
#define GLEW_STATIC
|
||||||
|
|
@ -313,6 +314,7 @@ void Engine::renderFrame() {
|
||||||
|
|
||||||
DrawContext ctx(nullptr, *window, nullptr);
|
DrawContext ctx(nullptr, *window, nullptr);
|
||||||
gui->draw(ctx, *assets->getStorage());
|
gui->draw(ctx, *assets->getStorage());
|
||||||
|
draw_window_bar(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::saveSettings() {
|
void Engine::saveSettings() {
|
||||||
|
|
|
||||||
88
src/engine/WindowBar.cpp
Normal file
88
src/engine/WindowBar.cpp
Normal file
|
|
@ -0,0 +1,88 @@
|
||||||
|
#include "WindowBar.hpp"
|
||||||
|
|
||||||
|
#include "Engine.hpp"
|
||||||
|
#include "graphics/core/Batch2D.hpp"
|
||||||
|
#include "graphics/core/Font.hpp"
|
||||||
|
#include "graphics/ui/GUI.hpp"
|
||||||
|
#include "window/Window.hpp"
|
||||||
|
#include "assets/Assets.hpp"
|
||||||
|
|
||||||
|
#include <codecvt>
|
||||||
|
#include <locale>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
std::wstring to_wide(const std::string& text) {
|
||||||
|
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
|
||||||
|
return converter.from_bytes(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr const char* BAR_FONT = "normal";
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw_window_bar(Engine& engine) {
|
||||||
|
auto& window = engine.getWindow();
|
||||||
|
const int height = window.getDecorationHeight();
|
||||||
|
if (height <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto* batch = engine.getGUI().getBatch2D();
|
||||||
|
auto font = engine.requireAssets().getShared<Font>(BAR_FONT);
|
||||||
|
if (batch == nullptr || font == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const auto size = window.getSize();
|
||||||
|
const float barHeight = static_cast<float>(height);
|
||||||
|
|
||||||
|
batch->begin();
|
||||||
|
batch->setColor(glm::vec4(0.0f, 0.0f, 0.0f, 0.82f));
|
||||||
|
batch->rect(0.0f, 0.0f, size.x, barHeight);
|
||||||
|
batch->setColor(glm::vec4(1.0f, 1.0f, 1.0f, 0.10f));
|
||||||
|
batch->rect(0.0f, barHeight - 1.0f, size.x, 1.0f);
|
||||||
|
|
||||||
|
const std::wstring title = to_wide(window.getTitle());
|
||||||
|
const int textX = static_cast<int>(barHeight * 0.4f);
|
||||||
|
const int textY = (height - font->getLineHeight()) / 2;
|
||||||
|
batch->setColor(glm::vec4(1.0f, 1.0f, 1.0f, 0.85f));
|
||||||
|
font->draw(*batch, title, textX, textY, nullptr, 0);
|
||||||
|
batch->untexture();
|
||||||
|
|
||||||
|
const float button = barHeight;
|
||||||
|
const int hovered = window.getDecorationHoveredButton();
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
const float x = size.x - button * (i + 1);
|
||||||
|
const float cx = x + button * 0.5f;
|
||||||
|
const float cy = barHeight * 0.5f;
|
||||||
|
if (hovered == i) {
|
||||||
|
batch->setColor(
|
||||||
|
i == 0 ? glm::vec4(0.62f, 0.13f, 0.09f, 0.9f)
|
||||||
|
: glm::vec4(1.0f, 1.0f, 1.0f, 0.16f)
|
||||||
|
);
|
||||||
|
batch->rect(x, 0.0f, button, barHeight - 1.0f);
|
||||||
|
}
|
||||||
|
const float ink = hovered == i ? 1.0f : 0.8f;
|
||||||
|
const float thickness = 2.0f;
|
||||||
|
batch->setColor(glm::vec4(1.0f, 1.0f, 1.0f, ink));
|
||||||
|
if (i == 0) {
|
||||||
|
for (int s = 0; s < 8; s++) {
|
||||||
|
batch->rect(cx - 5.0f + s, cy - 5.0f + s, thickness, thickness);
|
||||||
|
batch->rect(cx + 3.0f - s, cy - 5.0f + s, thickness, thickness);
|
||||||
|
}
|
||||||
|
} else if (i == 1 && !window.isMaximized()) {
|
||||||
|
batch->rect(cx - 6.0f, cy - 6.0f, 12.0f, thickness);
|
||||||
|
batch->rect(cx - 6.0f, cy + 4.0f, 12.0f, thickness);
|
||||||
|
batch->rect(cx - 6.0f, cy - 6.0f, thickness, 12.0f);
|
||||||
|
batch->rect(cx + 4.0f, cy - 6.0f, thickness, 12.0f);
|
||||||
|
} else if (i == 1) {
|
||||||
|
batch->rect(cx - 7.0f, cy + 1.0f, 11.0f, thickness);
|
||||||
|
batch->rect(cx - 7.0f, cy + 1.0f, thickness, 6.0f);
|
||||||
|
batch->rect(cx + 2.0f, cy + 1.0f, thickness, 6.0f);
|
||||||
|
batch->rect(cx - 7.0f, cy + 5.0f, 11.0f, thickness);
|
||||||
|
batch->rect(cx - 2.0f, cy - 5.0f, 9.0f, thickness);
|
||||||
|
batch->rect(cx - 2.0f, cy - 5.0f, thickness, 6.0f);
|
||||||
|
batch->rect(cx + 5.0f, cy - 5.0f, thickness, 6.0f);
|
||||||
|
} else {
|
||||||
|
batch->rect(cx - 6.0f, cy - 1.0f, 12.0f, thickness);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
batch->flush();
|
||||||
|
}
|
||||||
5
src/engine/WindowBar.hpp
Normal file
5
src/engine/WindowBar.hpp
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
class Engine;
|
||||||
|
|
||||||
|
void draw_window_bar(Engine& engine);
|
||||||
|
|
@ -123,6 +123,10 @@ namespace gui {
|
||||||
/// @param assets active assets storage
|
/// @param assets active assets storage
|
||||||
void draw(const DrawContext& pctx, Assets& assets);
|
void draw(const DrawContext& pctx, Assets& assets);
|
||||||
|
|
||||||
|
Batch2D* getBatch2D() {
|
||||||
|
return batch2D.get();
|
||||||
|
}
|
||||||
|
|
||||||
void postAct();
|
void postAct();
|
||||||
|
|
||||||
/// @brief Add element to the main container
|
/// @brief Add element to the main container
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,16 @@ public:
|
||||||
|
|
||||||
virtual void setTitle(const std::string& title) = 0;
|
virtual void setTitle(const std::string& title) = 0;
|
||||||
|
|
||||||
|
virtual const std::string& getTitle() const = 0;
|
||||||
|
|
||||||
|
virtual int getDecorationHeight() const {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual int getDecorationHoveredButton() const {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
virtual bool isIconSupported() const = 0;
|
virtual bool isIconSupported() const = 0;
|
||||||
|
|
||||||
virtual void setIcon(const ImageData* image) = 0;
|
virtual void setIcon(const ImageData* image) = 0;
|
||||||
|
|
|
||||||
|
|
@ -360,7 +360,14 @@ public:
|
||||||
glfwFocusWindow(window);
|
glfwFocusWindow(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string title;
|
||||||
|
|
||||||
|
const std::string& getTitle() const override {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
void setTitle(const std::string& title) override {
|
void setTitle(const std::string& title) override {
|
||||||
|
this->title = title;
|
||||||
glfwSetWindowTitle(window, title.c_str());
|
glfwSetWindowTitle(window, title.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,262 +5,16 @@
|
||||||
static constexpr int BAR_HEIGHT = 30;
|
static constexpr int BAR_HEIGHT = 30;
|
||||||
static constexpr int BAR_BUTTON = 30;
|
static constexpr int BAR_BUTTON = 30;
|
||||||
static constexpr int BAR_EDGE = 5;
|
static constexpr int BAR_EDGE = 5;
|
||||||
static constexpr int BAR_ICON_SIZE = 16;
|
const std::string& WaylandWindow::getTitle() const {
|
||||||
static constexpr int BAR_FONT_W = 8;
|
return title;
|
||||||
static constexpr int BAR_FONT_H = 8;
|
|
||||||
static constexpr int BAR_GLYPHS = 159;
|
|
||||||
|
|
||||||
static const uint8_t BAR_FONT[BAR_GLYPHS][BAR_FONT_H] {
|
|
||||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
|
||||||
{0x00, 0x60, 0x60, 0x60, 0x60, 0x00, 0x60, 0x60},
|
|
||||||
{0x00, 0x50, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00},
|
|
||||||
{0x00, 0x14, 0x14, 0x7e, 0x28, 0xfe, 0x28, 0x68},
|
|
||||||
{0x00, 0x10, 0x78, 0x70, 0x78, 0x7c, 0x1c, 0x78},
|
|
||||||
{0x00, 0x62, 0xf4, 0xfc, 0x6b, 0x1f, 0x17, 0x23},
|
|
||||||
{0x00, 0x38, 0x60, 0x30, 0x7a, 0xde, 0x6c, 0x7e},
|
|
||||||
{0x00, 0x40, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00},
|
|
||||||
{0x20, 0x60, 0x60, 0x40, 0x40, 0x60, 0x60, 0x20},
|
|
||||||
{0x40, 0x60, 0x20, 0x20, 0x20, 0x20, 0x60, 0x40},
|
|
||||||
{0x00, 0x20, 0xf0, 0x70, 0xf0, 0x20, 0x00, 0x00},
|
|
||||||
{0x00, 0x00, 0x00, 0x10, 0x10, 0x7e, 0x10, 0x10},
|
|
||||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x40},
|
|
||||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00},
|
|
||||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x60},
|
|
||||||
{0x00, 0x20, 0x20, 0x60, 0x40, 0x40, 0xc0, 0x80},
|
|
||||||
{0x00, 0x38, 0x6c, 0xcc, 0xcc, 0xcc, 0x6c, 0x38},
|
|
||||||
{0x00, 0x70, 0x30, 0x30, 0x30, 0x30, 0x30, 0x7c},
|
|
||||||
{0x00, 0x78, 0x18, 0x18, 0x18, 0x30, 0x60, 0x7c},
|
|
||||||
{0x00, 0x78, 0x18, 0x18, 0x38, 0x1c, 0x1c, 0xf8},
|
|
||||||
{0x00, 0x18, 0x38, 0x78, 0x58, 0xd8, 0xfc, 0x18},
|
|
||||||
{0x00, 0x78, 0x40, 0x40, 0x78, 0x0c, 0x0c, 0x78},
|
|
||||||
{0x00, 0x38, 0x60, 0x40, 0xf8, 0x6c, 0x6c, 0x38},
|
|
||||||
{0x00, 0xfc, 0x18, 0x18, 0x18, 0x30, 0x30, 0x60},
|
|
||||||
{0x00, 0x78, 0x6c, 0x6c, 0x78, 0x6c, 0x6c, 0x78},
|
|
||||||
{0x00, 0x78, 0xc8, 0xcc, 0x7c, 0x0c, 0x18, 0x70},
|
|
||||||
{0x00, 0x00, 0x00, 0x60, 0x60, 0x00, 0x60, 0x60},
|
|
||||||
{0x00, 0x00, 0x00, 0x60, 0x60, 0x00, 0x60, 0x60},
|
|
||||||
{0x00, 0x00, 0x00, 0x06, 0x3c, 0x60, 0x3c, 0x06},
|
|
||||||
{0x00, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x7e, 0x00},
|
|
||||||
{0x00, 0x00, 0x00, 0x60, 0x3c, 0x0e, 0x3c, 0x60},
|
|
||||||
{0x00, 0x70, 0x18, 0x30, 0x60, 0x00, 0x60, 0x60},
|
|
||||||
{0x00, 0x1e, 0x63, 0x5d, 0x55, 0x57, 0x5e, 0x62},
|
|
||||||
{0x00, 0x38, 0x38, 0x78, 0x6c, 0x6c, 0xfe, 0xc6},
|
|
||||||
{0x00, 0x78, 0x6c, 0x6c, 0x7c, 0x6c, 0x6c, 0x7c},
|
|
||||||
{0x00, 0x3c, 0x64, 0xc0, 0xc0, 0xc0, 0x64, 0x3c},
|
|
||||||
{0x00, 0x7c, 0x6e, 0x66, 0x66, 0x66, 0x6e, 0x7c},
|
|
||||||
{0x00, 0x7c, 0x60, 0x60, 0x78, 0x60, 0x60, 0x7c},
|
|
||||||
{0x00, 0x7c, 0x60, 0x60, 0x78, 0x60, 0x60, 0x60},
|
|
||||||
{0x00, 0x3c, 0x62, 0xc0, 0xce, 0xc6, 0x66, 0x3e},
|
|
||||||
{0x00, 0x66, 0x66, 0x66, 0x7e, 0x66, 0x66, 0x66},
|
|
||||||
{0x00, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60},
|
|
||||||
{0x00, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60},
|
|
||||||
{0x00, 0x6e, 0x7c, 0x78, 0x70, 0x78, 0x6c, 0x66},
|
|
||||||
{0x00, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x7c},
|
|
||||||
{0x00, 0x63, 0x77, 0x77, 0x7f, 0x7f, 0x6b, 0x63},
|
|
||||||
{0x00, 0x66, 0x76, 0x76, 0x7e, 0x7e, 0x6e, 0x6e},
|
|
||||||
{0x00, 0x3c, 0x66, 0xc6, 0xc6, 0xc6, 0x66, 0x3c},
|
|
||||||
{0x00, 0x7c, 0x6c, 0x6c, 0x7c, 0x60, 0x60, 0x60},
|
|
||||||
{0x00, 0x3c, 0x66, 0xc6, 0xc6, 0xc6, 0x66, 0x3c},
|
|
||||||
{0x00, 0x78, 0x6c, 0x6c, 0x78, 0x6c, 0x6c, 0x66},
|
|
||||||
{0x00, 0x78, 0x68, 0x60, 0x78, 0x0c, 0x4c, 0x78},
|
|
||||||
{0x00, 0xfc, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30},
|
|
||||||
{0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x6c, 0x3c},
|
|
||||||
{0x00, 0xc6, 0xc6, 0x6c, 0x6c, 0x78, 0x38, 0x38},
|
|
||||||
{0x00, 0xcc, 0xcc, 0x7d, 0x7f, 0x77, 0x73, 0x33},
|
|
||||||
{0x00, 0xcc, 0x6c, 0x38, 0x38, 0x38, 0x6c, 0xc6},
|
|
||||||
{0x00, 0xcc, 0x6c, 0x78, 0x38, 0x30, 0x30, 0x30},
|
|
||||||
{0x00, 0xfc, 0x1c, 0x18, 0x30, 0x70, 0x60, 0xfc},
|
|
||||||
{0x70, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x70},
|
|
||||||
{0x00, 0x80, 0xc0, 0x40, 0x40, 0x60, 0x20, 0x20},
|
|
||||||
{0xe0, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0xe0},
|
|
||||||
{0x00, 0x38, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00},
|
|
||||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
|
||||||
{0x00, 0x40, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00},
|
|
||||||
{0x00, 0x00, 0x00, 0x78, 0x08, 0x78, 0xd8, 0x78},
|
|
||||||
{0x40, 0x40, 0x40, 0x78, 0x6c, 0x4c, 0x6c, 0x78},
|
|
||||||
{0x00, 0x00, 0x00, 0x78, 0x60, 0xc0, 0x60, 0x78},
|
|
||||||
{0x0c, 0x0c, 0x0c, 0x7c, 0xcc, 0xcc, 0xcc, 0x7c},
|
|
||||||
{0x00, 0x00, 0x00, 0x78, 0xcc, 0xfc, 0xc0, 0x7c},
|
|
||||||
{0x70, 0x60, 0x60, 0xf0, 0x60, 0x60, 0x60, 0x60},
|
|
||||||
{0x00, 0x00, 0x00, 0x7c, 0xcc, 0xcc, 0xcc, 0x7c},
|
|
||||||
{0x40, 0x40, 0x40, 0x78, 0x6c, 0x4c, 0x4c, 0x4c},
|
|
||||||
{0x40, 0x40, 0x00, 0x40, 0x40, 0x40, 0x40, 0x40},
|
|
||||||
{0x40, 0x40, 0x00, 0x40, 0x40, 0x40, 0x40, 0x40},
|
|
||||||
{0x40, 0x40, 0x40, 0x4c, 0x78, 0x70, 0x78, 0x4c},
|
|
||||||
{0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40},
|
|
||||||
{0x00, 0x00, 0x00, 0x7f, 0x6d, 0x4d, 0x4d, 0x4d},
|
|
||||||
{0x00, 0x00, 0x00, 0x78, 0x6c, 0x4c, 0x4c, 0x4c},
|
|
||||||
{0x00, 0x00, 0x00, 0x78, 0xcc, 0xcc, 0xcc, 0x78},
|
|
||||||
{0x00, 0x00, 0x00, 0x78, 0x6c, 0x4c, 0x6c, 0x78},
|
|
||||||
{0x00, 0x00, 0x00, 0x7c, 0xcc, 0xcc, 0xcc, 0x7c},
|
|
||||||
{0x00, 0x00, 0x00, 0x78, 0x60, 0x40, 0x40, 0x40},
|
|
||||||
{0x00, 0x00, 0x00, 0x78, 0xe0, 0x78, 0x18, 0xf8},
|
|
||||||
{0x00, 0x00, 0x60, 0xf0, 0x60, 0x60, 0x60, 0x70},
|
|
||||||
{0x00, 0x00, 0x00, 0x4c, 0x4c, 0x4c, 0x6c, 0x7c},
|
|
||||||
{0x00, 0x00, 0x00, 0xcc, 0x48, 0x78, 0x70, 0x30},
|
|
||||||
{0x00, 0x00, 0x00, 0xdb, 0x5b, 0x7e, 0x7e, 0x76},
|
|
||||||
{0x00, 0x00, 0x00, 0xd8, 0x78, 0x30, 0x78, 0xc8},
|
|
||||||
{0x00, 0x00, 0x00, 0xcc, 0x48, 0x78, 0x78, 0x30},
|
|
||||||
{0x00, 0x00, 0x00, 0xf8, 0x38, 0x30, 0x60, 0xf8},
|
|
||||||
{0x18, 0x30, 0x30, 0x70, 0x30, 0x30, 0x30, 0x18},
|
|
||||||
{0x00, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40},
|
|
||||||
{0x70, 0x30, 0x30, 0x18, 0x30, 0x30, 0x30, 0x70},
|
|
||||||
{0x00, 0x00, 0x00, 0x00, 0x72, 0x1c, 0x00, 0x00},
|
|
||||||
{0x00, 0x38, 0x38, 0x78, 0x6c, 0x6c, 0xfe, 0xc6},
|
|
||||||
{0x00, 0x7c, 0x60, 0x60, 0x7c, 0x6c, 0x6c, 0x7c},
|
|
||||||
{0x00, 0x78, 0x6c, 0x6c, 0x7c, 0x6c, 0x6c, 0x7c},
|
|
||||||
{0x00, 0x7c, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60},
|
|
||||||
{0x00, 0x3e, 0x36, 0x36, 0x36, 0x26, 0x66, 0xff},
|
|
||||||
{0x00, 0x7c, 0x60, 0x60, 0x78, 0x60, 0x60, 0x7c},
|
|
||||||
{0x00, 0x64, 0x35, 0x3f, 0x3f, 0x3f, 0x64, 0xc4},
|
|
||||||
{0x00, 0x78, 0x0c, 0x0c, 0x38, 0x0c, 0x0c, 0xf8},
|
|
||||||
{0x00, 0x6e, 0x6e, 0x7e, 0x7e, 0x76, 0x76, 0x66},
|
|
||||||
{0x00, 0x6e, 0x6e, 0x7e, 0x7e, 0x76, 0x76, 0x66},
|
|
||||||
{0x00, 0x66, 0x6c, 0x78, 0x78, 0x7c, 0x6c, 0x66},
|
|
||||||
{0x00, 0x3e, 0x36, 0x36, 0x36, 0x36, 0x66, 0xc6},
|
|
||||||
{0x00, 0x63, 0x77, 0x77, 0x7f, 0x7f, 0x6b, 0x63},
|
|
||||||
{0x00, 0x66, 0x66, 0x66, 0x7e, 0x66, 0x66, 0x66},
|
|
||||||
{0x00, 0x3c, 0x66, 0xc6, 0xc6, 0xc6, 0x66, 0x3c},
|
|
||||||
{0x00, 0x7e, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66},
|
|
||||||
{0x00, 0x7c, 0x6c, 0x6c, 0x7c, 0x60, 0x60, 0x60},
|
|
||||||
{0x00, 0x3c, 0x64, 0xc0, 0xc0, 0xc0, 0x64, 0x3c},
|
|
||||||
{0x00, 0xfc, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30},
|
|
||||||
{0x00, 0xc6, 0x6c, 0x7c, 0x38, 0x38, 0x30, 0x70},
|
|
||||||
{0x00, 0x18, 0x7e, 0x7b, 0xd9, 0x7b, 0x7e, 0x18},
|
|
||||||
{0x00, 0xcc, 0x6c, 0x38, 0x38, 0x38, 0x6c, 0xc6},
|
|
||||||
{0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7f},
|
|
||||||
{0x00, 0x66, 0x66, 0x66, 0x7e, 0x06, 0x06, 0x06},
|
|
||||||
{0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7f},
|
|
||||||
{0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7f},
|
|
||||||
{0x00, 0x70, 0xf0, 0x30, 0x3e, 0x3b, 0x3b, 0x3e},
|
|
||||||
{0x00, 0x61, 0x61, 0x61, 0x7d, 0x6d, 0x6d, 0x7d},
|
|
||||||
{0x00, 0x60, 0x60, 0x60, 0x7c, 0x6c, 0x6c, 0x7c},
|
|
||||||
{0x00, 0x70, 0xf8, 0x0c, 0x7c, 0x0c, 0x1c, 0x78},
|
|
||||||
{0x00, 0x67, 0x6c, 0x78, 0x78, 0x78, 0x6c, 0x67},
|
|
||||||
{0x00, 0x7c, 0x6c, 0x6c, 0x7c, 0x3c, 0x6c, 0x6c},
|
|
||||||
{0x00, 0x00, 0x00, 0x78, 0x08, 0x78, 0xd8, 0x78},
|
|
||||||
{0x38, 0x40, 0xc0, 0xf8, 0xec, 0xcc, 0x6c, 0x78},
|
|
||||||
{0x00, 0x00, 0x00, 0x78, 0x58, 0x78, 0x48, 0x78},
|
|
||||||
{0x00, 0x00, 0x00, 0x78, 0x40, 0x40, 0x40, 0x40},
|
|
||||||
{0x00, 0x00, 0x00, 0x3c, 0x2c, 0x6c, 0x6c, 0xfe},
|
|
||||||
{0x00, 0x00, 0x00, 0x78, 0xcc, 0xfc, 0xc0, 0x7c},
|
|
||||||
{0x00, 0x00, 0x00, 0x6b, 0x3e, 0x3e, 0x7f, 0xc9},
|
|
||||||
{0x00, 0x00, 0x00, 0x70, 0x18, 0x70, 0x18, 0xf0},
|
|
||||||
{0x00, 0x00, 0x00, 0x5c, 0x7c, 0x7c, 0x6c, 0x6c},
|
|
||||||
{0x00, 0x30, 0x00, 0x5c, 0x7c, 0x7c, 0x6c, 0x6c},
|
|
||||||
{0x00, 0x00, 0x00, 0x58, 0x70, 0x70, 0x78, 0x4c},
|
|
||||||
{0x00, 0x00, 0x00, 0x7c, 0x6c, 0x6c, 0x6c, 0xcc},
|
|
||||||
{0x00, 0x00, 0x00, 0x6e, 0x6e, 0x7e, 0x7e, 0x46},
|
|
||||||
{0x00, 0x00, 0x00, 0x4c, 0x4c, 0x7c, 0x4c, 0x4c},
|
|
||||||
{0x00, 0x00, 0x00, 0x78, 0xcc, 0xcc, 0xcc, 0x78},
|
|
||||||
{0x00, 0x00, 0x00, 0x7c, 0x4c, 0x4c, 0x4c, 0x4c},
|
|
||||||
{0x00, 0x00, 0x00, 0x78, 0x6c, 0x4c, 0x6c, 0x78},
|
|
||||||
{0x00, 0x00, 0x00, 0x78, 0x60, 0xc0, 0x60, 0x78},
|
|
||||||
{0x00, 0x00, 0x00, 0xf8, 0x30, 0x30, 0x30, 0x30},
|
|
||||||
{0x00, 0x00, 0x00, 0xcc, 0x48, 0x78, 0x78, 0x30},
|
|
||||||
{0x08, 0x08, 0x08, 0x7f, 0x7b, 0xc9, 0x7b, 0x7f},
|
|
||||||
{0x00, 0x00, 0x00, 0xd8, 0x78, 0x30, 0x78, 0xc8},
|
|
||||||
{0x00, 0x00, 0x00, 0x4c, 0x4c, 0x4c, 0x4c, 0x7c},
|
|
||||||
{0x00, 0x00, 0x00, 0xd8, 0xd8, 0x78, 0x18, 0x18},
|
|
||||||
{0x00, 0x00, 0x00, 0x4d, 0x4d, 0x4d, 0x4d, 0x7f},
|
|
||||||
{0x00, 0x00, 0x00, 0x4d, 0x4d, 0x4d, 0x4d, 0x7f},
|
|
||||||
{0x00, 0x00, 0x00, 0xf0, 0x30, 0x3c, 0x34, 0x3c},
|
|
||||||
{0x00, 0x00, 0x00, 0x43, 0x43, 0x7b, 0x4f, 0x7b},
|
|
||||||
{0x00, 0x00, 0x00, 0x40, 0x40, 0x78, 0x48, 0x78},
|
|
||||||
{0x00, 0x00, 0x00, 0x70, 0x18, 0x78, 0x18, 0x70},
|
|
||||||
{0x00, 0x00, 0x00, 0x4e, 0x5b, 0x79, 0x5b, 0x4e},
|
|
||||||
{0x00, 0x00, 0x00, 0x78, 0x58, 0x78, 0x78, 0xd8},
|
|
||||||
};
|
|
||||||
|
|
||||||
static int bar_glyph_index(uint32_t codepoint) {
|
|
||||||
if (codepoint >= 32 && codepoint < 127) {
|
|
||||||
return static_cast<int>(codepoint) - 32;
|
|
||||||
}
|
|
||||||
if (codepoint >= 0x410 && codepoint <= 0x44F) {
|
|
||||||
return 95 + static_cast<int>(codepoint - 0x410);
|
|
||||||
}
|
|
||||||
if (codepoint == 0x401) {
|
|
||||||
return 95 + 6;
|
|
||||||
}
|
|
||||||
if (codepoint == 0x451) {
|
|
||||||
return 95 + 37;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::vector<uint32_t> decode_utf8(const std::string& text) {
|
int WaylandWindow::getDecorationHeight() const {
|
||||||
std::vector<uint32_t> codepoints;
|
return barVisible() ? BAR_HEIGHT : 0;
|
||||||
for (size_t i = 0; i < text.size();) {
|
|
||||||
const uint8_t byte = static_cast<uint8_t>(text[i]);
|
|
||||||
uint32_t codepoint = byte;
|
|
||||||
size_t length = 1;
|
|
||||||
if ((byte & 0xE0) == 0xC0) {
|
|
||||||
codepoint = byte & 0x1F;
|
|
||||||
length = 2;
|
|
||||||
} else if ((byte & 0xF0) == 0xE0) {
|
|
||||||
codepoint = byte & 0x0F;
|
|
||||||
length = 3;
|
|
||||||
} else if ((byte & 0xF8) == 0xF0) {
|
|
||||||
codepoint = byte & 0x07;
|
|
||||||
length = 4;
|
|
||||||
}
|
|
||||||
if (i + length > text.size()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
for (size_t k = 1; k < length; k++) {
|
|
||||||
codepoint =
|
|
||||||
(codepoint << 6) | (static_cast<uint8_t>(text[i + k]) & 0x3F);
|
|
||||||
}
|
|
||||||
codepoints.push_back(codepoint);
|
|
||||||
i += length;
|
|
||||||
}
|
|
||||||
return codepoints;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int WaylandWindow::getDecorationHoveredButton() const {
|
||||||
static void push_quad(
|
return hoveredButton;
|
||||||
std::vector<float>& target, float x, float y, float w, float h, float u0,
|
|
||||||
float v0, float u1, float v1, const glm::vec4& color
|
|
||||||
) {
|
|
||||||
const float x1 = x + w;
|
|
||||||
const float y1 = y + h;
|
|
||||||
const float vertices[] {
|
|
||||||
x, y, u0, v0, color.r, color.g, color.b, color.a,
|
|
||||||
x1, y, u1, v0, color.r, color.g, color.b, color.a,
|
|
||||||
x, y1, u0, v1, color.r, color.g, color.b, color.a,
|
|
||||||
x1, y, u1, v0, color.r, color.g, color.b, color.a,
|
|
||||||
x1, y1, u1, v1, color.r, color.g, color.b, color.a,
|
|
||||||
x, y1, u0, v1, color.r, color.g, color.b, color.a
|
|
||||||
};
|
|
||||||
target.insert(target.end(), vertices, vertices + 48);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool WaylandWindow::isIconSupported() const {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WaylandWindow::setIcon(const ImageData* image) {
|
|
||||||
if (image == nullptr || image->getData() == nullptr) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
iconWidth = static_cast<int>(image->getWidth());
|
|
||||||
iconHeight = static_cast<int>(image->getHeight());
|
|
||||||
if (iconWidth <= 0 || iconHeight <= 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const size_t pixels = static_cast<size_t>(iconWidth) * iconHeight;
|
|
||||||
const bool alpha = image->getFormat() == ImageFormat::RGBA8888;
|
|
||||||
iconPixels.resize(pixels * 4);
|
|
||||||
for (size_t i = 0; i < pixels; i++) {
|
|
||||||
iconPixels[i * 4] = image->getData()[i * (alpha ? 4 : 3)];
|
|
||||||
iconPixels[i * 4 + 1] = image->getData()[i * (alpha ? 4 : 3) + 1];
|
|
||||||
iconPixels[i * 4 + 2] = image->getData()[i * (alpha ? 4 : 3) + 2];
|
|
||||||
iconPixels[i * 4 + 3] = alpha ? image->getData()[i * 4 + 3] : 255;
|
|
||||||
}
|
|
||||||
if (barIconTexture != 0) {
|
|
||||||
glDeleteTextures(1, &barIconTexture);
|
|
||||||
barIconTexture = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaylandWindow::enableOwnDecorations() {
|
void WaylandWindow::enableOwnDecorations() {
|
||||||
|
|
@ -275,234 +29,6 @@ bool WaylandWindow::barVisible() const {
|
||||||
return barEnabled && !fullscreen && Window::mode != WindowMode::BORDERLESS;
|
return barEnabled && !fullscreen && Window::mode != WindowMode::BORDERLESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaylandWindow::initBarRenderer() {
|
|
||||||
if (barProgram != 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
static const char* vertexSource =
|
|
||||||
"#version 330 core\n"
|
|
||||||
"layout(location = 0) in vec2 aPos;\n"
|
|
||||||
"layout(location = 1) in vec2 aUv;\n"
|
|
||||||
"layout(location = 2) in vec4 aColor;\n"
|
|
||||||
"uniform vec2 uViewport;\n"
|
|
||||||
"out vec2 vUv;\n"
|
|
||||||
"out vec4 vColor;\n"
|
|
||||||
"void main() {\n"
|
|
||||||
" vec2 ndc = vec2(aPos.x / uViewport.x * 2.0 - 1.0,"
|
|
||||||
" 1.0 - aPos.y / uViewport.y * 2.0);\n"
|
|
||||||
" gl_Position = vec4(ndc, 0.0, 1.0);\n"
|
|
||||||
" vUv = aUv;\n"
|
|
||||||
" vColor = aColor;\n"
|
|
||||||
"}\n";
|
|
||||||
static const char* fragmentSource =
|
|
||||||
"#version 330 core\n"
|
|
||||||
"in vec2 vUv;\n"
|
|
||||||
"in vec4 vColor;\n"
|
|
||||||
"out vec4 outColor;\n"
|
|
||||||
"uniform sampler2D uTexture;\n"
|
|
||||||
"uniform int uMode;\n"
|
|
||||||
"void main() {\n"
|
|
||||||
" if (uMode == 1) {\n"
|
|
||||||
" outColor = vec4(vColor.rgb,"
|
|
||||||
" vColor.a * texture(uTexture, vUv).r);\n"
|
|
||||||
" } else if (uMode == 2) {\n"
|
|
||||||
" outColor = texture(uTexture, vUv) * vColor;\n"
|
|
||||||
" } else {\n"
|
|
||||||
" outColor = vColor;\n"
|
|
||||||
" }\n"
|
|
||||||
"}\n";
|
|
||||||
barProgram = compile_program(vertexSource, fragmentSource);
|
|
||||||
barViewportLoc = glGetUniformLocation(barProgram, "uViewport");
|
|
||||||
barTextureLoc = glGetUniformLocation(barProgram, "uTexture");
|
|
||||||
barModeLoc = glGetUniformLocation(barProgram, "uMode");
|
|
||||||
glGenVertexArrays(1, &barVao);
|
|
||||||
glGenBuffers(1, &barVbo);
|
|
||||||
glBindVertexArray(barVao);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, barVbo);
|
|
||||||
glEnableVertexAttribArray(0);
|
|
||||||
glVertexAttribPointer(
|
|
||||||
0, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(float), nullptr
|
|
||||||
);
|
|
||||||
glEnableVertexAttribArray(1);
|
|
||||||
glVertexAttribPointer(
|
|
||||||
1, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(float),
|
|
||||||
reinterpret_cast<void*>(2 * sizeof(float))
|
|
||||||
);
|
|
||||||
glEnableVertexAttribArray(2);
|
|
||||||
glVertexAttribPointer(
|
|
||||||
2, 4, GL_FLOAT, GL_FALSE, 8 * sizeof(float),
|
|
||||||
reinterpret_cast<void*>(4 * sizeof(float))
|
|
||||||
);
|
|
||||||
glBindVertexArray(0);
|
|
||||||
glGenTextures(1, &barFontTexture);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, barFontTexture);
|
|
||||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
|
||||||
std::vector<uint8_t> pixels(BAR_GLYPHS * BAR_FONT_W * BAR_FONT_H, 0);
|
|
||||||
for (int glyph = 0; glyph < BAR_GLYPHS; glyph++) {
|
|
||||||
for (int y = 0; y < BAR_FONT_H; y++) {
|
|
||||||
for (int x = 0; x < BAR_FONT_W; x++) {
|
|
||||||
if (BAR_FONT[glyph][y] & (1 << (7 - x))) {
|
|
||||||
pixels[y * BAR_GLYPHS * BAR_FONT_W + glyph * BAR_FONT_W + x] =
|
|
||||||
255;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
glTexImage2D(
|
|
||||||
GL_TEXTURE_2D, 0, GL_R8, BAR_GLYPHS * BAR_FONT_W, BAR_FONT_H, 0,
|
|
||||||
GL_RED, GL_UNSIGNED_BYTE, pixels.data()
|
|
||||||
);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WaylandWindow::initBarIconTexture() {
|
|
||||||
if (iconPixels.empty() || barIconTexture != 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
glGenTextures(1, &barIconTexture);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, barIconTexture);
|
|
||||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
|
||||||
glTexImage2D(
|
|
||||||
GL_TEXTURE_2D, 0, GL_RGBA8, iconWidth, iconHeight, 0, GL_RGBA,
|
|
||||||
GL_UNSIGNED_BYTE, iconPixels.data()
|
|
||||||
);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WaylandWindow::barDrawText(
|
|
||||||
float x, float y, const std::vector<uint32_t>& codepoints, int maxChars,
|
|
||||||
const glm::vec4& color
|
|
||||||
) {
|
|
||||||
const float step = 1.0f / static_cast<float>(BAR_GLYPHS * BAR_FONT_W);
|
|
||||||
float cursor = x;
|
|
||||||
for (int i = 0; i < static_cast<int>(codepoints.size()) && i < maxChars; i++) {
|
|
||||||
const int index = bar_glyph_index(codepoints[i]);
|
|
||||||
if (index >= 0) {
|
|
||||||
push_quad(
|
|
||||||
barText, cursor, y, BAR_FONT_W, BAR_FONT_H,
|
|
||||||
index * BAR_FONT_W * step, 0.0f,
|
|
||||||
(index * BAR_FONT_W + BAR_FONT_W) * step, 1.0f, color
|
|
||||||
);
|
|
||||||
}
|
|
||||||
cursor += BAR_FONT_W;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void WaylandWindow::barDrawBatch(const std::vector<float>& data, int mode, GLuint texture) {
|
|
||||||
if (data.empty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
glUniform1i(barModeLoc, mode);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, texture);
|
|
||||||
glBufferData(
|
|
||||||
GL_ARRAY_BUFFER, data.size() * sizeof(float), data.data(),
|
|
||||||
GL_STREAM_DRAW
|
|
||||||
);
|
|
||||||
glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(data.size() / 8));
|
|
||||||
}
|
|
||||||
|
|
||||||
void WaylandWindow::barFlush() {
|
|
||||||
glUseProgram(barProgram);
|
|
||||||
glUniform2f(
|
|
||||||
barViewportLoc, static_cast<float>(size.x), static_cast<float>(size.y)
|
|
||||||
);
|
|
||||||
glDisable(GL_DEPTH_TEST);
|
|
||||||
glDisable(GL_CULL_FACE);
|
|
||||||
glDisable(GL_SCISSOR_TEST);
|
|
||||||
glEnable(GL_BLEND);
|
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
||||||
glBindVertexArray(barVao);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, barVbo);
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
|
||||||
glUniform1i(barTextureLoc, 0);
|
|
||||||
barDrawBatch(barRects, 0, barFontTexture);
|
|
||||||
barDrawBatch(barIcons, 2, barIconTexture);
|
|
||||||
barDrawBatch(barText, 1, barFontTexture);
|
|
||||||
glBindVertexArray(0);
|
|
||||||
glDisable(GL_BLEND);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WaylandWindow::drawBar() {
|
|
||||||
if (!barVisible()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
initBarRenderer();
|
|
||||||
initBarIconTexture();
|
|
||||||
barRects.clear();
|
|
||||||
barText.clear();
|
|
||||||
barIcons.clear();
|
|
||||||
|
|
||||||
const float width = static_cast<float>(size.x);
|
|
||||||
const float height = static_cast<float>(BAR_HEIGHT);
|
|
||||||
const glm::vec4 background(0.16f, 0.16f, 0.17f, 1.0f);
|
|
||||||
const glm::vec4 border(0.09f, 0.09f, 0.10f, 1.0f);
|
|
||||||
const glm::vec4 ink(0.87f, 0.87f, 0.88f, 1.0f);
|
|
||||||
const glm::vec4 hover(0.27f, 0.27f, 0.29f, 1.0f);
|
|
||||||
const glm::vec4 closeHover(0.72f, 0.16f, 0.11f, 1.0f);
|
|
||||||
|
|
||||||
push_quad(barRects, 0, 0, width, height, 0, 0, 0, 0, background);
|
|
||||||
push_quad(barRects, 0, height - 1, width, 1, 0, 0, 0, 0, border);
|
|
||||||
|
|
||||||
float textX = 10.0f;
|
|
||||||
if (barIconTexture != 0 && iconWidth > 0) {
|
|
||||||
push_quad(
|
|
||||||
barIcons, 7, (height - BAR_ICON_SIZE) * 0.5f, BAR_ICON_SIZE,
|
|
||||||
BAR_ICON_SIZE, 0, 1, 1, 0, glm::vec4(1.0f)
|
|
||||||
);
|
|
||||||
textX = 7 + BAR_ICON_SIZE + 8;
|
|
||||||
}
|
|
||||||
const float buttonsX = width - BAR_BUTTON * 3;
|
|
||||||
const int maxChars =
|
|
||||||
static_cast<int>((buttonsX - 8 - textX) / BAR_FONT_W);
|
|
||||||
if (maxChars > 0) {
|
|
||||||
barDrawText(
|
|
||||||
textX, (height - BAR_FONT_H) * 0.5f, decode_utf8(title),
|
|
||||||
maxChars, ink
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++) {
|
|
||||||
const float bx = width - BAR_BUTTON * (i + 1);
|
|
||||||
if (hoveredButton == i) {
|
|
||||||
push_quad(
|
|
||||||
barRects, bx, 0, BAR_BUTTON, height - 1, 0, 0, 0, 0,
|
|
||||||
i == 0 ? closeHover : hover
|
|
||||||
);
|
|
||||||
}
|
|
||||||
const float cx = bx + BAR_BUTTON * 0.5f;
|
|
||||||
const float cy = height * 0.5f;
|
|
||||||
if (i == 0) {
|
|
||||||
for (int s = 0; s < 7; s++) {
|
|
||||||
push_quad(barRects, cx - 4 + s, cy - 4 + s, 1.6f, 1.6f, 0, 0, 0, 0, ink);
|
|
||||||
push_quad(barRects, cx + 3 - s, cy - 4 + s, 1.6f, 1.6f, 0, 0, 0, 0, ink);
|
|
||||||
}
|
|
||||||
} else if (i == 1 && !maximized) {
|
|
||||||
push_quad(barRects, cx - 4.5f, cy - 4.5f, 9, 1.6f, 0, 0, 0, 0, ink);
|
|
||||||
push_quad(barRects, cx - 4.5f, cy + 2.9f, 9, 1.6f, 0, 0, 0, 0, ink);
|
|
||||||
push_quad(barRects, cx - 4.5f, cy - 4.5f, 1.6f, 9, 0, 0, 0, 0, ink);
|
|
||||||
push_quad(barRects, cx + 2.9f, cy - 4.5f, 1.6f, 9, 0, 0, 0, 0, ink);
|
|
||||||
} else if (i == 1) {
|
|
||||||
push_quad(barRects, cx - 3.5f, cy - 5.5f, 8, 1.4f, 0, 0, 0, 0, ink);
|
|
||||||
push_quad(barRects, cx + 3.1f, cy - 5.5f, 1.4f, 5.5f, 0, 0, 0, 0, ink);
|
|
||||||
push_quad(barRects, cx - 5.5f, cy - 1.2f, 8, 1.4f, 0, 0, 0, 0, ink);
|
|
||||||
push_quad(barRects, cx - 5.5f, cy - 1.2f, 1.4f, 6.2f, 0, 0, 0, 0, ink);
|
|
||||||
push_quad(barRects, cx + 1.1f, cy - 1.2f, 1.4f, 6.2f, 0, 0, 0, 0, ink);
|
|
||||||
push_quad(barRects, cx - 5.5f, cy + 3.6f, 8, 1.4f, 0, 0, 0, 0, ink);
|
|
||||||
} else {
|
|
||||||
push_quad(barRects, cx - 5, cy - 0.8f, 10, 1.6f, 0, 0, 0, 0, ink);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
barFlush();
|
|
||||||
}
|
|
||||||
|
|
||||||
int WaylandWindow::barButtonAt(double x, double y) const {
|
int WaylandWindow::barButtonAt(double x, double y) const {
|
||||||
if (!barVisible() || y < 0.0 || y >= BAR_HEIGHT) {
|
if (!barVisible() || y < 0.0 || y >= BAR_HEIGHT) {
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,78 @@
|
||||||
debug::Logger waylandLogger("window");
|
debug::Logger waylandLogger("window");
|
||||||
|
|
||||||
|
|
||||||
|
GlStateGuard::GlStateGuard() {
|
||||||
|
glGetIntegerv(GL_CURRENT_PROGRAM, &values[0]);
|
||||||
|
glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &values[1]);
|
||||||
|
glGetIntegerv(GL_ACTIVE_TEXTURE, &values[2]);
|
||||||
|
glGetIntegerv(GL_TEXTURE_BINDING_2D, &values[3]);
|
||||||
|
glGetIntegerv(GL_UNPACK_ALIGNMENT, &values[4]);
|
||||||
|
glGetIntegerv(GL_BLEND_SRC_RGB, &values[5]);
|
||||||
|
glGetIntegerv(GL_BLEND_DST_RGB, &values[6]);
|
||||||
|
glGetIntegerv(GL_BLEND_SRC_ALPHA, &values[7]);
|
||||||
|
glGetIntegerv(GL_BLEND_DST_ALPHA, &values[8]);
|
||||||
|
glGetIntegerv(GL_BLEND_EQUATION_RGB, &values[9]);
|
||||||
|
glGetIntegerv(GL_BLEND_EQUATION_ALPHA, &values[10]);
|
||||||
|
glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &values[11]);
|
||||||
|
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &values[12]);
|
||||||
|
glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &values[13]);
|
||||||
|
glGetIntegerv(GL_DEPTH_WRITEMASK, &values[14]);
|
||||||
|
glGetIntegerv(GL_VIEWPORT, viewport);
|
||||||
|
glGetIntegerv(GL_COLOR_WRITEMASK, colorMask);
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
attribFlags[i] = glIsEnabled(GL_VERTEX_ATTRIB_ARRAY_ENABLED + i);
|
||||||
|
glGetVertexAttribiv(i, GL_VERTEX_ATTRIB_ARRAY_SIZE, &attribs[i][0]);
|
||||||
|
glGetVertexAttribiv(i, GL_VERTEX_ATTRIB_ARRAY_TYPE, &attribs[i][1]);
|
||||||
|
glGetVertexAttribiv(i, GL_VERTEX_ATTRIB_ARRAY_NORMALIZED, &attribs[i][2]);
|
||||||
|
glGetVertexAttribiv(i, GL_VERTEX_ATTRIB_ARRAY_STRIDE, &attribs[i][3]);
|
||||||
|
glGetVertexAttribiv(i, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, &attribs[i][5]);
|
||||||
|
void* pointer = nullptr;
|
||||||
|
glGetVertexAttribPointerv(i, GL_VERTEX_ATTRIB_ARRAY_POINTER, &pointer);
|
||||||
|
attribs[i][6] = static_cast<GLint>(reinterpret_cast<intptr_t>(pointer));
|
||||||
|
}
|
||||||
|
flags[0] = glIsEnabled(GL_BLEND);
|
||||||
|
flags[1] = glIsEnabled(GL_DEPTH_TEST);
|
||||||
|
flags[2] = glIsEnabled(GL_CULL_FACE);
|
||||||
|
flags[3] = glIsEnabled(GL_SCISSOR_TEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
GlStateGuard::~GlStateGuard() {
|
||||||
|
glUseProgram(values[0]);
|
||||||
|
glBindVertexArray(values[1]);
|
||||||
|
glActiveTexture(values[2]);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, values[3]);
|
||||||
|
glPixelStorei(GL_UNPACK_ALIGNMENT, values[4]);
|
||||||
|
glBlendFuncSeparate(values[5], values[6], values[7], values[8]);
|
||||||
|
glBlendEquationSeparate(values[9], values[10]);
|
||||||
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, values[12]);
|
||||||
|
glBindFramebuffer(GL_READ_FRAMEBUFFER, values[13]);
|
||||||
|
glDepthMask(values[14]);
|
||||||
|
glColorMask(colorMask[0], colorMask[1], colorMask[2], colorMask[3]);
|
||||||
|
glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
|
||||||
|
const GLenum cap[] {GL_BLEND, GL_DEPTH_TEST, GL_CULL_FACE, GL_SCISSOR_TEST};
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
if (flags[i]) {
|
||||||
|
glEnable(cap[i]);
|
||||||
|
} else {
|
||||||
|
glDisable(cap[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, static_cast<GLuint>(attribs[i][5]));
|
||||||
|
glVertexAttribPointer(
|
||||||
|
i, attribs[i][0], static_cast<GLenum>(attribs[i][1]),
|
||||||
|
attribs[i][2], attribs[i][3],
|
||||||
|
reinterpret_cast<void*>(static_cast<intptr_t>(attribs[i][6]))
|
||||||
|
);
|
||||||
|
if (attribFlags[i]) {
|
||||||
|
glEnableVertexAttribArray(i);
|
||||||
|
} else {
|
||||||
|
glDisableVertexAttribArray(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, static_cast<GLuint>(values[11]));
|
||||||
|
}
|
||||||
|
|
||||||
GLuint compile_program(const char* vertexSource, const char* fragmentSource) {
|
GLuint compile_program(const char* vertexSource, const char* fragmentSource) {
|
||||||
GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
|
GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
|
||||||
glShaderSource(vertexShader, 1, &vertexSource, nullptr);
|
glShaderSource(vertexShader, 1, &vertexSource, nullptr);
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,17 @@ const wl_data_device_listener& data_device_listener();
|
||||||
const xdg_surface_listener& surface_listener();
|
const xdg_surface_listener& surface_listener();
|
||||||
const xdg_toplevel_listener& toplevel_listener();
|
const xdg_toplevel_listener& toplevel_listener();
|
||||||
|
|
||||||
|
struct GlStateGuard {
|
||||||
|
GLint values[16] {};
|
||||||
|
GLint attribs[3][7] {};
|
||||||
|
GLint viewport[4] {};
|
||||||
|
GLint colorMask[4] {};
|
||||||
|
GLboolean flags[6] {};
|
||||||
|
GLboolean attribFlags[3] {};
|
||||||
|
GlStateGuard();
|
||||||
|
~GlStateGuard();
|
||||||
|
};
|
||||||
|
|
||||||
GLuint compile_program(const char* vertexSource, const char* fragmentSource);
|
GLuint compile_program(const char* vertexSource, const char* fragmentSource);
|
||||||
|
|
||||||
extern debug::Logger waylandLogger;
|
extern debug::Logger waylandLogger;
|
||||||
|
|
|
||||||
|
|
@ -43,21 +43,6 @@ WaylandWindow::~WaylandWindow() {
|
||||||
if (stretchVao) {
|
if (stretchVao) {
|
||||||
glDeleteVertexArrays(1, &stretchVao);
|
glDeleteVertexArrays(1, &stretchVao);
|
||||||
}
|
}
|
||||||
if (barFontTexture) {
|
|
||||||
glDeleteTextures(1, &barFontTexture);
|
|
||||||
}
|
|
||||||
if (barIconTexture) {
|
|
||||||
glDeleteTextures(1, &barIconTexture);
|
|
||||||
}
|
|
||||||
if (barProgram) {
|
|
||||||
glDeleteProgram(barProgram);
|
|
||||||
}
|
|
||||||
if (barVbo) {
|
|
||||||
glDeleteBuffers(1, &barVbo);
|
|
||||||
}
|
|
||||||
if (barVao) {
|
|
||||||
glDeleteVertexArrays(1, &barVao);
|
|
||||||
}
|
|
||||||
if (state.dataDevice) {
|
if (state.dataDevice) {
|
||||||
wl_data_device_destroy(state.dataDevice);
|
wl_data_device_destroy(state.dataDevice);
|
||||||
}
|
}
|
||||||
|
|
@ -109,7 +94,6 @@ void WaylandWindow::swapBuffers() {
|
||||||
} else {
|
} else {
|
||||||
cacheContent();
|
cacheContent();
|
||||||
}
|
}
|
||||||
drawBar();
|
|
||||||
requestFrame();
|
requestFrame();
|
||||||
eglSwapBuffers(eglDisplay, eglSurface);
|
eglSwapBuffers(eglDisplay, eglSurface);
|
||||||
resetScissor();
|
resetScissor();
|
||||||
|
|
@ -363,12 +347,16 @@ void WaylandWindow::resetScissor() {
|
||||||
|
|
||||||
std::unique_ptr<ImageData> WaylandWindow::takeScreenshot() {
|
std::unique_ptr<ImageData> WaylandWindow::takeScreenshot() {
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
|
GLint readBuffer = 0;
|
||||||
|
glGetIntegerv(GL_READ_BUFFER, &readBuffer);
|
||||||
|
glReadBuffer(GL_FRONT);
|
||||||
auto data = std::make_unique<ubyte[]>(size.x * size.y * 3);
|
auto data = std::make_unique<ubyte[]>(size.x * size.y * 3);
|
||||||
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||||
glReadPixels(0, 0, size.x, size.y, GL_RGB, GL_UNSIGNED_BYTE, data.get());
|
glReadPixels(0, 0, size.x, size.y, GL_RGB, GL_UNSIGNED_BYTE, data.get());
|
||||||
return std::make_unique<ImageData>(
|
return std::make_unique<ImageData>(
|
||||||
ImageFormat::RGB888, size.x, size.y, data.release()
|
ImageFormat::RGB888, size.x, size.y, data.release()
|
||||||
);
|
);
|
||||||
|
glReadBuffer(static_cast<GLenum>(readBuffer));
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaylandWindow::setFramerate(int framerate) {
|
void WaylandWindow::setFramerate(int framerate) {
|
||||||
|
|
@ -445,6 +433,7 @@ void WaylandWindow::resizeCache(int width, int height) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaylandWindow::cacheContent() {
|
void WaylandWindow::cacheContent() {
|
||||||
|
GlStateGuard state;
|
||||||
if (stretchProgram == 0) {
|
if (stretchProgram == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -460,6 +449,7 @@ void WaylandWindow::cacheContent() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaylandWindow::drawStretched() {
|
void WaylandWindow::drawStretched() {
|
||||||
|
GlStateGuard state;
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
glViewport(0, 0, size.x, size.y);
|
glViewport(0, 0, size.x, size.y);
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
|
|
|
||||||
|
|
@ -37,24 +37,10 @@ static inline bool resizeLogging = getenv("VOXEL_LOG_RESIZE") != nullptr;
|
||||||
bool barEnabled = false;
|
bool barEnabled = false;
|
||||||
bool fullscreen = false;
|
bool fullscreen = false;
|
||||||
std::string title = "VoxelCore";
|
std::string title = "VoxelCore";
|
||||||
std::vector<uint8_t> iconPixels;
|
|
||||||
int iconWidth = 0;
|
|
||||||
int iconHeight = 0;
|
|
||||||
int hoveredButton = -1;
|
int hoveredButton = -1;
|
||||||
double lastBarPress = 0.0;
|
double lastBarPress = 0.0;
|
||||||
double pointerX = 0.0;
|
double pointerX = 0.0;
|
||||||
double pointerY = 0.0;
|
double pointerY = 0.0;
|
||||||
GLuint barProgram = 0;
|
|
||||||
GLuint barVao = 0;
|
|
||||||
GLuint barVbo = 0;
|
|
||||||
GLuint barFontTexture = 0;
|
|
||||||
GLuint barIconTexture = 0;
|
|
||||||
GLint barViewportLoc = -1;
|
|
||||||
GLint barTextureLoc = -1;
|
|
||||||
GLint barModeLoc = -1;
|
|
||||||
std::vector<float> barRects;
|
|
||||||
std::vector<float> barText;
|
|
||||||
std::vector<float> barIcons;
|
|
||||||
bool frameOnCallback = false;
|
bool frameOnCallback = false;
|
||||||
double frameInterval = 0.0;
|
double frameInterval = 0.0;
|
||||||
double nextFrameTime = 0.0;
|
double nextFrameTime = 0.0;
|
||||||
|
|
@ -111,10 +97,18 @@ glm::vec4 scissorArea {};
|
||||||
WindowMode getMode() const override;
|
WindowMode getMode() const override;
|
||||||
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;
|
||||||
|
int getDecorationHeight() const override;
|
||||||
|
int getDecorationHoveredButton() const override;
|
||||||
|
|
||||||
|
bool isIconSupported() const override {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setIcon(const ImageData*) override {
|
||||||
|
}
|
||||||
void setFullscreen(bool enabled);
|
void setFullscreen(bool enabled);
|
||||||
void setMaximized(bool enabled);
|
void setMaximized(bool enabled);
|
||||||
bool isIconSupported() const override;
|
|
||||||
void setIcon(const ImageData* image) override;
|
|
||||||
void resize(int width, int height);
|
void resize(int width, int height);
|
||||||
void onConfigure(int32_t width, int32_t height, wl_array* states);
|
void onConfigure(int32_t width, int32_t height, wl_array* states);
|
||||||
void applyConfigure();
|
void applyConfigure();
|
||||||
|
|
@ -129,13 +123,7 @@ glm::vec4 scissorArea {};
|
||||||
void drawStretched();
|
void drawStretched();
|
||||||
void enableOwnDecorations();
|
void enableOwnDecorations();
|
||||||
bool barVisible() const;
|
bool barVisible() const;
|
||||||
void initBarRenderer();
|
int barButtonAt(double x, double y) const;
|
||||||
void initBarIconTexture();
|
|
||||||
void barDrawText( float x, float y, const std::vector<uint32_t>& codepoints, int maxChars, const glm::vec4& color );
|
|
||||||
void barDrawBatch(const std::vector<float>& data, int mode, GLuint texture);
|
|
||||||
void barFlush();
|
|
||||||
void drawBar();
|
|
||||||
int barButtonAt(double x, double y) const;
|
|
||||||
uint32_t barEdgeAt(double x, double y) const;
|
uint32_t barEdgeAt(double x, double y) const;
|
||||||
static CursorShape edgeCursor(uint32_t edges);
|
static CursorShape edgeCursor(uint32_t edges);
|
||||||
bool handleBarMotion(double x, double y);
|
bool handleBarMotion(double x, double y);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue