diff --git a/Graphics/private/Canvas.cpp b/Graphics/private/Canvas.cpp index bc29a17..82a2cc5 100644 --- a/Graphics/private/Canvas.cpp +++ b/Graphics/private/Canvas.cpp @@ -82,6 +82,19 @@ void Canvas::frame(RectF rec, const RGBA& col, halnf round) { // nvgFill(mContext->vg); } +void Canvas::line(Vec2F start, Vec2F end, const RGBA& col, halnf thickness) { + start += mOrigin; + end += mOrigin; + + nvgBeginPath(mContext->vg); + nvgFillColor(mContext->vg, { col.r, col.g, col.b, col.a}); + nvgMoveTo(mContext->vg, start.x, start.y); + nvgLineTo(mContext->vg, end.x, end.y); + nvgStrokeWidth(mContext->vg, thickness); + nvgStrokeColor(mContext->vg, { col.r, col.g, col.b, col.a }); + nvgStroke(mContext->vg); +} + void Canvas::circle(Vec2F pos, halnf size, const RGBA& col) { pos += mOrigin; diff --git a/Graphics/public/Graphics.hpp b/Graphics/public/Graphics.hpp index f854d3f..afbc325 100644 --- a/Graphics/public/Graphics.hpp +++ b/Graphics/public/Graphics.hpp @@ -75,6 +75,7 @@ namespace tp { void circle(Vec2F pos, halnf size, const RGBA& col); void text(const char*, const RectF&, halnf size, Align, halnf padding, const RGBA&); void colorWheel(const RectF& rec, const ColorWheel& colorWheel); + void line(Vec2F start, Vec2F end, const RGBA& col, halnf thickness); ImageHandle createImageFromTextId(ualni id, Vec2F size); void updateTextureID(ImageHandle handle, ualni id); diff --git a/Math/public/Mat.hpp b/Math/public/Mat.hpp index 2483284..97e73c1 100644 --- a/Math/public/Mat.hpp +++ b/Math/public/Mat.hpp @@ -465,8 +465,15 @@ namespace tp { } // Matrix Properties + MVec toGlobal(const MVec &in) const { return i * in.x + j * in.y; } + + Mat toGlobal(const Mat &in) const { return {toGlobal(in.i), toGlobal(in.j)}; } + + MVec toLocal(const MVec &in) const { return transform(in); } + MVec transform(const MVec& in) const { return MVec(i.x * in.x + i.y * in.y, j.x * in.x + j.y * in.y); } + // ??? Mat transform(const Mat& in) const { Mat out; out.i.x = i.x * in.i.x + j.x * in.i.y; diff --git a/Math/public/Rect.hpp b/Math/public/Rect.hpp index a03655e..47ab3ef 100644 --- a/Math/public/Rect.hpp +++ b/Math/public/Rect.hpp @@ -70,6 +70,29 @@ namespace tp { return *this; } + Rect& adjust(tp::halnf left, tp::halnf bottom, tp::halnf right, tp::halnf top) { + x += left; + y += bottom; + size.x += -left + right; + size.y += -bottom + top; + return *this; + } + + Rect adjusted(tp::halnf left, tp::halnf bottom, tp::halnf right, tp::halnf top) const { + return Rect(*this).adjust(left, bottom, right, top); + } + + [[nodiscard]] halnf left() const { return x; } + [[nodiscard]] halnf bottom() { return y; } + [[nodiscard]] halnf top() { return y + size.y; } + [[nodiscard]] halnf right() { return x + size.x; } + + static Rect fromPoints(const Vec2& p1, const Vec2& p2) { + tp::Vec2F min = {tp::min(p1.x, p2.x), tp::min(p1.y, p2.y)}; + tp::Vec2F max = {tp::max(p1.x, p2.x), tp::max(p1.y, p2.y)}; + return { min, max - min }; + } + bool operator==(const Rect& rect) const { return (pos == rect.pos && size == rect.size); } bool isEnclosedIn(const Rect& rect, bool aParent = false) const { @@ -184,13 +207,23 @@ namespace tp { } void expand(const Vec2& point) { - pos.x = min(point.x, pos.x); - pos.y = min(point.y, pos.y); + if (point.x < x) { + size.x += x - point.x; + x = point.x; + } - auto p = pos + size; - p.x = max(point.x, p.x); - p.y = max(point.y, p.y); - size = p - pos; + if (point.y < y) { + size.y += y - point.y; + y = point.y; + } + + if (point.x > x + size.x) { + size.x = point.x - x; + } + + if (point.y > y + size.y) { + size.y = point.y - y; + } } void expand(const Rect& rect) { diff --git a/Widgets/public/WidgetApplication.hpp b/Widgets/public/WidgetApplication.hpp index 8f6c697..7bf6fbe 100644 --- a/Widgets/public/WidgetApplication.hpp +++ b/Widgets/public/WidgetApplication.hpp @@ -10,6 +10,7 @@ namespace tp { WidgetApplication() = default; void setRoot(Widget* widget); + virtual void debugUI(); private: void processFrame(EventHandler* eventHandler, halnf deltaTime) override; @@ -17,8 +18,6 @@ namespace tp { void drawFrame(Canvas* canvas) override; bool forceNewFrame() override ; - private: - void debugUI(); private: halnf mDebugSplitFactor = 0.7;