89 lines
2.1 KiB
C++
89 lines
2.1 KiB
C++
#pragma once
|
|
#include <JUI/Base/Widget.hpp>
|
|
|
|
|
|
namespace JUI {
|
|
|
|
/// An invisible, point-like widget which is used to attach decorator-type widgets at a given point.
|
|
/// For example: The CurveSegment Widget uses two Anchors for it's endpoints.
|
|
class Anchor : public Widget {
|
|
public:
|
|
Anchor() : Widget() {
|
|
|
|
}
|
|
explicit Anchor(Widget* parent) : Anchor() {
|
|
Parent(parent);
|
|
};
|
|
explicit Anchor(Widget* parent, const UDim2& position) : Anchor(parent) {
|
|
Position(position);
|
|
Size({0_px, 0_px});
|
|
}
|
|
|
|
void Update(float elapsed) override {
|
|
|
|
}
|
|
|
|
void Draw() override {
|
|
Color4 debug_color = Colors::Red;
|
|
float debug_size = 4;
|
|
|
|
J2D::FillCircle(debug_color, GetAbsolutePosition(), debug_size, 5);
|
|
}
|
|
|
|
Vector2 Point() { return GetAbsolutePosition(); }
|
|
protected:
|
|
private:
|
|
};
|
|
|
|
class Decorator : public Widget {
|
|
public:
|
|
Decorator() : Widget(){
|
|
|
|
}
|
|
explicit Decorator(Widget* parent) : Decorator() {
|
|
Parent(parent);
|
|
}
|
|
|
|
};
|
|
|
|
class ArrowDecorator : public Decorator {
|
|
public:
|
|
explicit ArrowDecorator(Widget* parent, Anchor* a, Anchor* b) : Decorator() {
|
|
Parent(parent);
|
|
origin = a;
|
|
goal = b;
|
|
}
|
|
|
|
|
|
void Draw() override {
|
|
using namespace J3ML;
|
|
Color4 line_color = Colors::Green;
|
|
float line_size = 4;
|
|
|
|
J2D::DrawLine(line_color, origin->Point(), goal->Point(), line_size);
|
|
|
|
Vector2 lookback_dir = goal->Point() - origin->Point();
|
|
|
|
Rotation angle = lookback_dir.AimedAngle();
|
|
|
|
angle += 10_degrees;
|
|
|
|
Vector2 fan_vector_left = (Math::Cos(angle), Math::Sin(angle));
|
|
|
|
Vector2 tri_polys[3] = {
|
|
origin->Point(),
|
|
|
|
};
|
|
|
|
J2D::FillTriangle(line_color);
|
|
|
|
//J2D::FillTriangle();
|
|
}
|
|
protected:
|
|
Anchor* origin;
|
|
Anchor* goal;
|
|
private:
|
|
|
|
};
|
|
}
|