Skip to content

Commit

Permalink
Use coloured outlines for debug rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelOtter committed Oct 8, 2024
1 parent ec51fe1 commit ec233a3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/scene/include/growl/scene/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class Node : public InputProcessor, public Entity {
std::unique_ptr<ScriptingRef> bound_script_obj = nullptr;
DebugRendering debug_rendering = DebugRendering::OFF;
bool debug_mouseover = false;
int depth = 0;

void computeLocalTransform();
void drawChildren(Batch& batch, float parent_alpha);
Expand Down
13 changes: 11 additions & 2 deletions src/scene/src/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "growl/core/api/api.h"
#include "growl/core/error.h"
#include "growl/core/graphics/batch.h"
#include "growl/core/graphics/color.h"
#include "growl/core/input/event.h"
#include "growl/core/scripting/script.h"
#include "growl/scene/scene.h"
Expand All @@ -15,13 +16,19 @@

using Growl::API;
using Growl::Batch;
using Growl::Color;
using Growl::Error;
using Growl::InputMouseEvent;
using Growl::Node;
using Growl::Script;

#ifdef GROWL_IMGUI
static const char* debug_rendering_options[]{"Off", "On", "Mouseover"};
static const Color debug_rendering_colors[]{
{1, 0, 0, .5f}, {0, 1, 0, .5f}, {0, 1, 1, .5f},
{1, 0, 1, .5f}, {1, 1, 0, .5f},
};
static constexpr int DEBUG_RENDERING_COLORS_COUNT = 5;
#endif

std::string& Node::getLabel() {
Expand All @@ -30,6 +37,7 @@ std::string& Node::getLabel() {

Node* Node::addChild(std::unique_ptr<Node> node) {
node->parent = this;
node->depth = this->depth + 1;
children.emplace_back(std::move(node));
return children.back().get();
}
Expand Down Expand Up @@ -130,8 +138,9 @@ void Node::draw(Batch& batch, float parent_alpha) {
if (debug_rendering == DebugRendering::ON ||
(debug_rendering == DebugRendering::MOUSEOVER && debug_mouseover)) {
Color c = batch.getColor();
batch.setColor(1, 1, 1, 0.25f);
batch.drawRect(0, 0, getWidth(), getHeight(), local_transform);
batch.setColor(
debug_rendering_colors[depth % DEBUG_RENDERING_COLORS_COUNT]);
batch.drawRect(0, 0, getWidth(), getHeight(), local_transform, 5.f);
batch.setColor(c);
}
}
Expand Down

0 comments on commit ec233a3

Please sign in to comment.