#pragma once #include #include #include #include namespace easy2d { // ============================================================================ // 形状类型 // ============================================================================ enum class ShapeType { Point, Line, Rect, Circle, Triangle, Polygon }; // ============================================================================ // 形状节点 - 用于绘制几何形状 // ============================================================================ class ShapeNode : public Node { public: ShapeNode(); ~ShapeNode() override = default; // ------------------------------------------------------------------------ // 静态创建方法 // ------------------------------------------------------------------------ static Ptr create(); // 点 static Ptr createPoint(const Vec2& pos, const Color& color); // 线 static Ptr createLine(const Vec2& start, const Vec2& end, const Color& color, float width = 1.0f); // 矩形 static Ptr createRect(const Rect& rect, const Color& color, float width = 1.0f); static Ptr createFilledRect(const Rect& rect, const Color& color); // 圆形 static Ptr createCircle(const Vec2& center, float radius, const Color& color, int segments = 32, float width = 1.0f); static Ptr createFilledCircle(const Vec2& center, float radius, const Color& color, int segments = 32); // 三角形 static Ptr createTriangle(const Vec2& p1, const Vec2& p2, const Vec2& p3, const Color& color, float width = 1.0f); static Ptr createFilledTriangle(const Vec2& p1, const Vec2& p2, const Vec2& p3, const Color& color); // 多边形 static Ptr createPolygon(const std::vector& points, const Color& color, float width = 1.0f); static Ptr createFilledPolygon(const std::vector& points, const Color& color); // ------------------------------------------------------------------------ // 属性设置 // ------------------------------------------------------------------------ void setShapeType(ShapeType type) { shapeType_ = type; } ShapeType getShapeType() const { return shapeType_; } void setColor(const Color& color) { color_ = color; } Color getColor() const { return color_; } void setFilled(bool filled) { filled_ = filled; } bool isFilled() const { return filled_; } void setLineWidth(float width) { lineWidth_ = width; } float getLineWidth() const { return lineWidth_; } void setSegments(int segments) { segments_ = segments; } int getSegments() const { return segments_; } // ------------------------------------------------------------------------ // 点设置 // ------------------------------------------------------------------------ void setPoints(const std::vector& points); const std::vector& getPoints() const { return points_; } void addPoint(const Vec2& point); void clearPoints(); Rect getBoundingBox() const override; protected: void onDraw(RenderBackend& renderer) override; void generateRenderCommand(std::vector& commands, int zOrder) override; private: ShapeType shapeType_ = ShapeType::Rect; Color color_ = Colors::White; bool filled_ = false; float lineWidth_ = 1.0f; int segments_ = 32; std::vector points_; }; } // namespace easy2d