add debug GUI render mode (F8)

This commit is contained in:
MihailRis
2025-03-11 00:39:59 +03:00
parent a74a4fcf53
commit 5af6b91b22
18 changed files with 93 additions and 29 deletions
+2
View File
@@ -68,3 +68,5 @@ inline const std::string LAYOUTS_FOLDER = "layouts";
inline const std::string SOUNDS_FOLDER = "sounds"; inline const std::string SOUNDS_FOLDER = "sounds";
inline const std::string MODELS_FOLDER = "models"; inline const std::string MODELS_FOLDER = "models";
inline const std::string SKELETONS_FOLDER = "skeletons"; inline const std::string SKELETONS_FOLDER = "skeletons";
inline const std::string FONT_DEFAULT = "normal";
+3
View File
@@ -163,6 +163,9 @@ void Engine::updateHotkeys() {
if (Events::jpressed(keycode::F2)) { if (Events::jpressed(keycode::F2)) {
saveScreenshot(); saveScreenshot();
} }
if (Events::jpressed(keycode::F8)) {
gui->toggleDebug();
}
if (Events::jpressed(keycode::F11)) { if (Events::jpressed(keycode::F11)) {
settings.display.fullscreen.toggle(); settings.display.fullscreen.toggle();
} }
+6 -1
View File
@@ -142,7 +142,7 @@ void Batch2D::rect(
bool flippedY, bool flippedY,
glm::vec4 tint glm::vec4 tint
) { ) {
if (index + 6*B2D_VERTEX_SIZE >= capacity) { if (index + 6 * B2D_VERTEX_SIZE >= capacity) {
flush(); flush();
} }
setPrimitive(DrawPrimitive::triangle); setPrimitive(DrawPrimitive::triangle);
@@ -230,6 +230,11 @@ void Batch2D::rect(
} }
void Batch2D::lineRect(float x, float y, float w, float h) { void Batch2D::lineRect(float x, float y, float w, float h) {
if (index + 8 * B2D_VERTEX_SIZE >= capacity) {
flush();
}
setPrimitive(DrawPrimitive::line);
vertex(x, y, 0.0f, 0.0f, color.r, color.g, color.b, color.a); vertex(x, y, 0.0f, 0.0f, color.r, color.g, color.b, color.a);
vertex(x, y+h, 0.0f, 1.0f, color.r, color.g, color.b, color.a); vertex(x, y+h, 0.0f, 1.0f, color.r, color.g, color.b, color.a);
+5 -1
View File
@@ -48,10 +48,14 @@ public:
void sprite(float x, float y, float w, float h, float skew, int atlasRes, int index, glm::vec4 tint); void sprite(float x, float y, float w, float h, float skew, int atlasRes, int index, glm::vec4 tint);
void point(float x, float y, float r, float g, float b, float a); void point(float x, float y, float r, float g, float b, float a);
void setColor(glm::vec4 color) { void setColor(const glm::vec4& color) {
this->color = color; this->color = color;
} }
void setColor(int r, int g, int b, int a=255) {
this->color = glm::vec4(r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f);
}
void resetColor() { void resetColor() {
this->color = glm::vec4(1.0f); this->color = glm::vec4(1.0f);
} }
+2 -1
View File
@@ -10,6 +10,7 @@
#include "graphics/core/Batch3D.hpp" #include "graphics/core/Batch3D.hpp"
#include "graphics/core/Shader.hpp" #include "graphics/core/Shader.hpp"
#include "presets/NotePreset.hpp" #include "presets/NotePreset.hpp"
#include "constants.hpp"
TextsRenderer::TextsRenderer( TextsRenderer::TextsRenderer(
Batch3D& batch, const Assets& assets, const Frustum& frustum Batch3D& batch, const Assets& assets, const Frustum& frustum
@@ -44,7 +45,7 @@ void TextsRenderer::renderNote(
} }
opacity = preset.xrayOpacity; opacity = preset.xrayOpacity;
} }
const auto& font = assets.require<Font>("normal"); const auto& font = assets.require<Font>(FONT_DEFAULT);
glm::vec3 xvec = note.getAxisX(); glm::vec3 xvec = note.getAxisX();
glm::vec3 yvec = note.getAxisY(); glm::vec3 yvec = note.getAxisY();
+41 -3
View File
@@ -11,14 +11,15 @@
#include "frontend/UiDocument.hpp" #include "frontend/UiDocument.hpp"
#include "frontend/locale.hpp" #include "frontend/locale.hpp"
#include "graphics/core/Batch2D.hpp" #include "graphics/core/Batch2D.hpp"
#include "graphics/core/LineBatch.hpp"
#include "graphics/core/Shader.hpp" #include "graphics/core/Shader.hpp"
#include "graphics/core/Font.hpp"
#include "graphics/core/DrawContext.hpp" #include "graphics/core/DrawContext.hpp"
#include "window/Events.hpp" #include "window/Events.hpp"
#include "window/Window.hpp" #include "window/Window.hpp"
#include "window/input.hpp" #include "window/input.hpp"
#include "window/Camera.hpp" #include "window/Camera.hpp"
#include <iostream>
#include <algorithm> #include <algorithm>
#include <utility> #include <utility>
@@ -238,6 +239,39 @@ void GUI::draw(const DrawContext& pctx, const Assets& assets) {
if (hover) { if (hover) {
Window::setCursor(hover->getCursor()); Window::setCursor(hover->getCursor());
} }
if (hover && debug) {
auto pos = hover->calcPos();
const auto& id = hover->getId();
if (!id.empty()) {
auto& font = assets.require<Font>(FONT_DEFAULT);
auto text = util::str2wstr_utf8(id);
int width = font.calcWidth(text);
int height = font.getLineHeight();
batch2D->untexture();
batch2D->setColor(0, 0, 0);
batch2D->rect(pos.x, pos.y, width, height);
batch2D->resetColor();
font.draw(*batch2D, text, pos.x, pos.y, nullptr, 0);
}
batch2D->untexture();
auto node = hover->getParent();
while (node) {
auto pos = node->calcPos();
auto size = node->getSize();
batch2D->setColor(0, 0, 255);
batch2D->lineRect(pos.x, pos.y, size.x-1, size.y-1);
node = node->getParent();
}
// debug draw
auto size = hover->getSize();
batch2D->setColor(0, 255, 0);
batch2D->lineRect(pos.x, pos.y, size.x-1, size.y-1);
}
} }
std::shared_ptr<UINode> GUI::getFocused() const { std::shared_ptr<UINode> GUI::getFocused() const {
@@ -252,8 +286,8 @@ void GUI::add(std::shared_ptr<UINode> node) {
container->add(std::move(node)); container->add(std::move(node));
} }
void GUI::remove(std::shared_ptr<UINode> node) noexcept { void GUI::remove(UINode* node) noexcept {
container->remove(std::move(node)); container->remove(node);
} }
void GUI::store(const std::string& name, std::shared_ptr<UINode> node) { void GUI::store(const std::string& name, std::shared_ptr<UINode> node) {
@@ -297,3 +331,7 @@ void GUI::setDoubleClickDelay(float delay) {
float GUI::getDoubleClickDelay() const { float GUI::getDoubleClickDelay() const {
return doubleClickDelay; return doubleClickDelay;
} }
void GUI::toggleDebug() {
debug = !debug;
}
+9 -1
View File
@@ -14,6 +14,7 @@ class DrawContext;
class Assets; class Assets;
class Camera; class Camera;
class Batch2D; class Batch2D;
class LineBatch;
/* /*
Some info about padding and margin. Some info about padding and margin.
@@ -73,6 +74,7 @@ namespace gui {
float doubleClickTimer = 0.0f; float doubleClickTimer = 0.0f;
float doubleClickDelay = 0.5f; float doubleClickDelay = 0.5f;
bool doubleClicked = false; bool doubleClicked = false;
bool debug = false;
void actMouse(float delta); void actMouse(float delta);
void actFocused(); void actFocused();
@@ -113,7 +115,11 @@ namespace gui {
void add(std::shared_ptr<UINode> node); void add(std::shared_ptr<UINode> node);
/// @brief Remove node from the main container /// @brief Remove node from the main container
void remove(std::shared_ptr<UINode> node) noexcept; void remove(UINode* node) noexcept;
void remove(const std::shared_ptr<UINode>& node) noexcept {
return remove(node.get());
}
/// @brief Store node in the GUI nodes dictionary /// @brief Store node in the GUI nodes dictionary
/// (does not add node to the main container) /// (does not add node to the main container)
@@ -144,5 +150,7 @@ namespace gui {
void setDoubleClickDelay(float delay); void setDoubleClickDelay(float delay);
float getDoubleClickDelay() const; float getDoubleClickDelay() const;
void toggleDebug();
}; };
} }
+3 -3
View File
@@ -172,11 +172,11 @@ void Container::add(const std::shared_ptr<UINode>& node, glm::vec2 pos) {
add(node); add(node);
} }
void Container::remove(const std::shared_ptr<UINode>& selected) { void Container::remove(UINode* selected) {
selected->setParent(nullptr); selected->setParent(nullptr);
nodes.erase(std::remove_if(nodes.begin(), nodes.end(), nodes.erase(std::remove_if(nodes.begin(), nodes.end(),
[selected](const std::shared_ptr<UINode>& node) { [selected](const std::shared_ptr<UINode>& node) {
return node == selected; return node.get() == selected;
} }
), nodes.end()); ), nodes.end());
refresh(); refresh();
@@ -185,7 +185,7 @@ void Container::remove(const std::shared_ptr<UINode>& selected) {
void Container::remove(const std::string& id) { void Container::remove(const std::string& id) {
for (auto& node : nodes) { for (auto& node : nodes) {
if (node->getId() == id) { if (node->getId() == id) {
return remove(node); return remove(node.get());
} }
} }
} }
+1 -1
View File
@@ -32,7 +32,7 @@ namespace gui {
virtual void add(const std::shared_ptr<UINode>& node); virtual void add(const std::shared_ptr<UINode>& node);
virtual void add(const std::shared_ptr<UINode>& node, glm::vec2 pos); virtual void add(const std::shared_ptr<UINode>& node, glm::vec2 pos);
virtual void clear(); virtual void clear();
virtual void remove(const std::shared_ptr<UINode>& node); virtual void remove(UINode* node);
virtual void remove(const std::string& id); virtual void remove(const std::string& id);
virtual void scrolled(int value) override; virtual void scrolled(int value) override;
virtual void setScrollable(bool flag); virtual void setScrollable(bool flag);
+1 -1
View File
@@ -207,7 +207,7 @@ void SlotView::draw(const DrawContext& pctx, const Assets& assets) {
drawItemIcon(batch, stack, item, assets, tint, pos); drawItemIcon(batch, stack, item, assets, tint, pos);
if (stack.getCount() > 1 || stack.getFields() != nullptr) { if (stack.getCount() > 1 || stack.getFields() != nullptr) {
const auto& font = assets.require<Font>("normal"); const auto& font = assets.require<Font>(FONT_DEFAULT);
drawItemInfo(batch, stack, item, font, pos); drawItemInfo(batch, stack, item, font, pos);
} }
} }
+3 -2
View File
@@ -1,6 +1,7 @@
#pragma once #pragma once
#include "UINode.hpp" #include "UINode.hpp"
#include "constants.hpp"
class Font; class Font;
struct FontStylesScheme; struct FontStylesScheme;
@@ -61,8 +62,8 @@ namespace gui {
std::unique_ptr<FontStylesScheme> styles; std::unique_ptr<FontStylesScheme> styles;
public: public:
Label(const std::string& text, std::string fontName="normal"); Label(const std::string& text, std::string fontName=FONT_DEFAULT);
Label(const std::wstring& text, std::string fontName="normal"); Label(const std::wstring& text, std::string fontName=FONT_DEFAULT);
virtual ~Label(); virtual ~Label();
+2 -2
View File
@@ -55,7 +55,7 @@ void Menu::setPage(const std::string &name, bool history) {
void Menu::setPage(Page page, bool history) { void Menu::setPage(Page page, bool history) {
if (current.panel) { if (current.panel) {
Container::remove(current.panel); Container::remove(current.panel.get());
if (history && !current.temporal) { if (history && !current.temporal) {
pageStack.push(current); pageStack.push(current);
} }
@@ -104,7 +104,7 @@ void Menu::clearHistory() {
void Menu::reset() { void Menu::reset() {
clearHistory(); clearHistory();
if (current.panel) { if (current.panel) {
Container::remove(current.panel); Container::remove(current.panel.get());
current = Page {"", nullptr}; current = Page {"", nullptr};
} }
} }
+1 -1
View File
@@ -63,7 +63,7 @@ void Panel::add(const std::shared_ptr<UINode> &node) {
fullRefresh(); fullRefresh();
} }
void Panel::remove(const std::shared_ptr<UINode> &node) { void Panel::remove(UINode* node) {
Container::remove(node); Container::remove(node);
fullRefresh(); fullRefresh();
} }
+3 -3
View File
@@ -7,14 +7,14 @@ namespace gui {
class Panel : public Container { class Panel : public Container {
protected: protected:
Orientation orientation = Orientation::vertical; Orientation orientation = Orientation::vertical;
glm::vec4 padding {2.0f}; glm::vec4 padding;
float interval = 2.0f; float interval = 2.0f;
int minLength = 0; int minLength = 0;
int maxLength = 0; int maxLength = 0;
public: public:
Panel( Panel(
glm::vec2 size, glm::vec2 size,
glm::vec4 padding=glm::vec4(2.0f), glm::vec4 padding=glm::vec4(0.0f),
float interval=2.0f float interval=2.0f
); );
virtual ~Panel(); virtual ~Panel();
@@ -25,7 +25,7 @@ namespace gui {
Orientation getOrientation() const; Orientation getOrientation() const;
virtual void add(const std::shared_ptr<UINode>& node) override; virtual void add(const std::shared_ptr<UINode>& node) override;
virtual void remove(const std::shared_ptr<UINode>& node) override; virtual void remove(UINode* node) override;
virtual void refresh() override; virtual void refresh() override;
virtual void fullRefresh() override; virtual void fullRefresh() override;
+2 -1
View File
@@ -5,6 +5,7 @@
#include "graphics/core/DrawContext.hpp" #include "graphics/core/DrawContext.hpp"
#include "assets/Assets.hpp" #include "assets/Assets.hpp"
#include "util/stringutil.hpp" #include "util/stringutil.hpp"
#include "constants.hpp"
using namespace gui; using namespace gui;
@@ -37,7 +38,7 @@ void Plotter::draw(const DrawContext& pctx, const Assets& assets) {
} }
int current_point = static_cast<int>(points[index % dmwidth]); int current_point = static_cast<int>(points[index % dmwidth]);
auto font = assets.get<Font>("normal"); auto font = assets.get<Font>(FONT_DEFAULT);
for (int y = 0; y < dmheight; y += labelsInterval) { for (int y = 0; y < dmheight; y += labelsInterval) {
std::wstring string; std::wstring string;
if (current_point/16 == y/labelsInterval) { if (current_point/16 == y/labelsInterval) {
+1 -1
View File
@@ -266,7 +266,7 @@ void UINode::moveInto(
) { ) {
auto parent = node->getParent(); auto parent = node->getParent();
if (auto container = dynamic_cast<Container*>(parent)) { if (auto container = dynamic_cast<Container*>(parent)) {
container->remove(node); container->remove(node.get());
} }
if (parent) { if (parent) {
parent->scrolled(0); parent->scrolled(0);
+1 -1
View File
@@ -96,7 +96,7 @@ static int l_node_destruct(lua::State* L) {
engine->getGUI()->postRunnable([node]() { engine->getGUI()->postRunnable([node]() {
auto parent = node->getParent(); auto parent = node->getParent();
if (auto container = dynamic_cast<Container*>(parent)) { if (auto container = dynamic_cast<Container*>(parent)) {
container->remove(node); container->remove(node.get());
} }
}); });
return 0; return 0;
+7 -6
View File
@@ -33,14 +33,15 @@ glm::mat4 Camera::getProjection() const {
constexpr float epsilon = 1e-6f; // 0.000001 constexpr float epsilon = 1e-6f; // 0.000001
float aspect_ratio = this->aspect; float aspect_ratio = this->aspect;
if (std::fabs(aspect_ratio) < epsilon) { if (std::fabs(aspect_ratio) < epsilon) {
aspect_ratio = (float)Window::width / (float)Window::height; aspect_ratio = Window::width / static_cast<float>(Window::height);
} }
if (perspective) if (perspective) {
return glm::perspective(fov * zoom, aspect_ratio, near, far); return glm::perspective(fov * zoom, aspect_ratio, near, far);
else if (flipped) } else if (flipped) {
return glm::ortho(0.0f, fov * aspect_ratio, fov, 0.0f); return glm::ortho(-0.5f, fov * aspect_ratio-0.5f, fov, 0.0f);
else } else {
return glm::ortho(0.0f, fov * aspect_ratio, 0.0f, fov); return glm::ortho(-0.5f, fov * aspect_ratio-0.5f, 0.0f, fov);
}
} }
glm::mat4 Camera::getView(bool pos) const { glm::mat4 Camera::getView(bool pos) const {