From 49ee8b4966a0cf10b2c1960c910a25da5cddc6c7 Mon Sep 17 00:00:00 2001 From: VAN BOSSUYT Nicolas Date: Sun, 3 Mar 2024 12:46:46 +0100 Subject: [PATCH] karm-gfx: Renamed the plot familly of functions. --- src/libs/karm-gfx/context.cpp | 62 ++++++----------------------------- src/libs/karm-gfx/context.h | 14 +++----- src/libs/karm-ui/host.h | 6 ++-- src/libs/karm-ui/input.cpp | 6 ++-- src/libs/karm-ui/layout.cpp | 13 ++++---- src/libs/karm-ui/scroll.cpp | 4 +-- src/libs/karm-ui/view.cpp | 7 ++-- 7 files changed, 31 insertions(+), 81 deletions(-) diff --git a/src/libs/karm-gfx/context.cpp b/src/libs/karm-gfx/context.cpp index b2470c68a51..fa870e861a7 100644 --- a/src/libs/karm-gfx/context.cpp +++ b/src/libs/karm-gfx/context.cpp @@ -372,14 +372,14 @@ void Context::fill(Math::Vec2f baseline, Str str) { /* --- Debug ---------------------------------------------------------------- */ -void Context::debugPlot(Math::Vec2i point, Color color) { +void Context::plot(Math::Vec2i point, Color color) { point = applyOrigin(point); if (clip().contains(point)) { mutPixels().blend(point, color); } } -void Context::debugLine(Math::Edgei edge, Color color) { +void Context::plot(Math::Edgei edge, Color color) { isize dx = Math::abs(edge.ex - edge.sx); isize sx = edge.sx < edge.ex ? 1 : -1; @@ -389,7 +389,7 @@ void Context::debugLine(Math::Edgei edge, Color color) { isize err = dx + dy, e2; for (;;) { - debugPlot({edge.sx, edge.sy}, color); + plot(edge.start, color); if (edge.sx == edge.ex and edge.sy == edge.ey) break; e2 = 2 * err; @@ -404,59 +404,17 @@ void Context::debugLine(Math::Edgei edge, Color color) { } } -void Context::debugRect(Math::Recti rect, Color color) { +void Context::plot(Math::Recti rect, Color color) { rect = {rect.xy, rect.wh - 1}; - debugLine({rect.topStart(), rect.topEnd()}, color); - debugLine({rect.topEnd(), rect.bottomEnd()}, color); - debugLine({rect.bottomEnd(), rect.bottomStart()}, color); - debugLine({rect.bottomStart(), rect.topStart()}, color); + plot(Math::Edgei{rect.topStart(), rect.topEnd()}, color); + plot(Math::Edgei{rect.topEnd(), rect.bottomEnd()}, color); + plot(Math::Edgei{rect.bottomEnd(), rect.bottomStart()}, color); + plot(Math::Edgei{rect.bottomStart(), rect.topStart()}, color); } -void Context::debugArrow(Math::Vec2i from, Math::Vec2i to, Color color) { - isize const SIZE = 16; - - Math::Vec2i dir = to - from; - Math::Vec2i perp = {-dir.y, dir.x}; - - f64 len = dir.len(); - f64 scale = SIZE / len; - - Math::Vec2i p1 = to - dir * scale; - Math::Vec2i p2 = p1 + perp * scale; - Math::Vec2i p3 = p1 - perp * scale; - - debugLine({from, to}, color); - debugLine({to, p2}, color); - debugLine({to, p3}, color); -} - -void Context::debugDoubleArrow(Math::Vec2i from, Math::Vec2i to, Color color) { - isize const SIZE = 8; - - Math::Vec2f dir = (to - from).cast(); - Math::Vec2f perp = {-dir.y, dir.x}; - - f64 len = dir.len(); - f64 scale = SIZE / len; - - Math::Vec2i p1 = (to - dir * scale).cast(); - Math::Vec2i p2 = (p1 + perp * scale).cast(); - Math::Vec2i p3 = (p1 - perp * scale).cast(); - - Math::Vec2i p4 = (from + dir * scale).cast(); - Math::Vec2i p5 = (p4 + perp * scale).cast(); - Math::Vec2i p6 = (p4 - perp * scale).cast(); - - debugLine({from, to}, color); - debugLine({to, p2}, color); - debugLine({to, p3}, color); - debugLine({from, p5}, color); - debugLine({from, p6}, color); -} - -void Context::debugTrace(Gfx::Color color) { +void Context::plot(Gfx::Color color) { for (auto edge : _rast.shape()) { - debugLine(edge.cast(), color); + plot(edge.cast(), color); } } diff --git a/src/libs/karm-gfx/context.h b/src/libs/karm-gfx/context.h index df24453e3a5..bbdfdd89902 100644 --- a/src/libs/karm-gfx/context.h +++ b/src/libs/karm-gfx/context.h @@ -250,22 +250,16 @@ struct Context { // non-antialiased shapes and lines. // Plot a point. - void debugPlot(Math::Vec2i point, Color color); + void plot(Math::Vec2i point, Color color); // Draw a line. - void debugLine(Math::Edgei edge, Color color); + void plot(Math::Edgei edge, Color color); // Draw a rectangle. - void debugRect(Math::Recti rect, Color color); - - // Draw an arrow. - void debugArrow(Math::Vec2i from, Math::Vec2i to, Color color); - - // Draw a double arrow. - void debugDoubleArrow(Math::Vec2i from, Math::Vec2i to, Color color); + void plot(Math::Recti rect, Color color); // Draw the current path as a polygon. - void debugTrace(Gfx::Color color); + void plot(Gfx::Color color); /* --- Paths ------------------------------------------------------------ */ diff --git a/src/libs/karm-ui/host.h b/src/libs/karm-ui/host.h index b9bff43ddb0..b6e63fbc868 100644 --- a/src/libs/karm-ui/host.h +++ b/src/libs/karm-ui/host.h @@ -83,11 +83,11 @@ struct PerfGraph { g.strokeStyle(Gfx::stroke(Gfx::WHITE.withOpacity(0.5)).withAlign(Gfx::INSIDE_ALIGN)); g.stroke(Math::Edgei{0, (isize)(FRAME_TIME * 1000 * 2), 256, (isize)(FRAME_TIME * 1000 * 2)}); - for (usize i = 0; i < 256; ++i) { + for (isize i = 0; i < 256; ++i) { auto e = _records[(_index + i) % 256]; - g.debugRect( - {(isize)i, 0, 1, (isize)e.duration().toMSecs() * 2}, + g.plot( + Math::Recti{i, 0, 1, (isize)e.duration().toMSecs() * 2}, e.color()); } diff --git a/src/libs/karm-ui/input.cpp b/src/libs/karm-ui/input.cpp index 7e96639aeb9..fc7dff9452f 100644 --- a/src/libs/karm-ui/input.cpp +++ b/src/libs/karm-ui/input.cpp @@ -299,13 +299,13 @@ struct Input : public View { // g.fill(baseline, _text); if (debugShowLayoutBounds) { - g.debugLine( - { + g.plot( + Math::Edgei{ bound().topStart() + m.baseline.cast(), bound().topEnd() + m.baseline.cast(), }, Gfx::PINK); - g.debugRect(bound(), Gfx::CYAN); + g.plot(bound(), Gfx::CYAN); } g.restore(); diff --git a/src/libs/karm-ui/layout.cpp b/src/libs/karm-ui/layout.cpp index d92bc9b83f7..bd239d07a48 100644 --- a/src/libs/karm-ui/layout.cpp +++ b/src/libs/karm-ui/layout.cpp @@ -25,9 +25,9 @@ struct Empty : public View { void paint(Gfx::Context &g, Math::Recti) override { if (debugShowEmptyBounds) { auto b = bound(); - g.debugRect(b, Gfx::WHITE.withOpacity(0.2)); - g.debugLine({b.topStart(), b.bottomEnd()}, Gfx::WHITE.withOpacity(0.2)); - g.debugLine({b.topEnd(), b.bottomStart()}, Gfx::WHITE.withOpacity(0.2)); + g.plot(b, Gfx::WHITE.withOpacity(0.2)); + g.plot(Math::Edgei{b.topStart(), b.bottomEnd()}, Gfx::WHITE.withOpacity(0.2)); + g.plot(Math::Edgei{b.topEnd(), b.bottomStart()}, Gfx::WHITE.withOpacity(0.2)); } } }; @@ -239,7 +239,7 @@ struct Spacing : public ProxyNode { void paint(Gfx::Context &g, Math::Recti r) override { child().paint(g, r); if (debugShowLayoutBounds) { - g.debugRect(child().bound(), Gfx::LIME); + g.plot(child().bound(), Gfx::LIME); } } @@ -275,9 +275,8 @@ struct AspectRatio : public ProxyNode { void paint(Gfx::Context &g, Math::Recti r) override { child().paint(g, r); - if (debugShowLayoutBounds) { - g.debugRect(child().bound(), Gfx::INDIGO); - } + if (debugShowLayoutBounds) + g.plot(child().bound(), Gfx::INDIGO); } Math::Vec2i size(Math::Vec2i s, Layout::Hint) override { diff --git a/src/libs/karm-ui/scroll.cpp b/src/libs/karm-ui/scroll.cpp index 95c0a9e1c4e..6b306c98c40 100644 --- a/src/libs/karm-ui/scroll.cpp +++ b/src/libs/karm-ui/scroll.cpp @@ -30,12 +30,12 @@ struct Scroll : public ProxyNode { child().paint(g, r); if (debugShowScrollBounds) - g.debugRect(child().bound(), Gfx::PINK); + g.plot(child().bound(), Gfx::PINK); g.restore(); if (debugShowScrollBounds) - g.debugRect(_bound, Gfx::CYAN); + g.plot(_bound, Gfx::CYAN); } void event(Sys::Event &e) override { diff --git a/src/libs/karm-ui/view.cpp b/src/libs/karm-ui/view.cpp index 15ab7046bc4..dd6eb2b1b6b 100644 --- a/src/libs/karm-ui/view.cpp +++ b/src/libs/karm-ui/view.cpp @@ -229,12 +229,11 @@ struct Text : public View { void paint(Gfx::Context &g, Math::Recti) override { g.save(); g.clip(bound()); - // g.debugRect(bound(), Gfx::PINK); g.origin(bound().xy); _text.paint(g); g.restore(); if (debugShowLayoutBounds) - g.debugRect(bound(), Gfx::CYAN); + g.plot(bound(), Gfx::CYAN); } void layout(Math::Recti bound) override { @@ -300,7 +299,7 @@ struct Icon : public View { g.fillStyle(_color.unwrap()); g.fill(bound().topStart(), _icon); if (debugShowLayoutBounds) - g.debugRect(bound(), Gfx::CYAN); + g.plot(bound(), Gfx::CYAN); g.restore(); } @@ -338,7 +337,7 @@ struct Image : public View { } if (debugShowLayoutBounds) - g.debugRect(bound(), Gfx::CYAN); + g.plot(bound(), Gfx::CYAN); } Math::Vec2i size(Math::Vec2i, Layout::Hint) override {