2025-12-11 16:05:41 +03:00
# pragma once
# include "CanvasComponent.hpp"
# include "Helpers/SCollision.hpp"
# include <Helpers/Serializers.hpp>
# include <include/core/SkPath.h>
# include <include/core/SkPathBuilder.h>
2025-12-13 13:03:27 +03:00
struct BrushStrokeCanvasComponentPoint {
2025-12-11 16:05:41 +03:00
Vector2f pos ;
float width ;
template < typename Archive > void serialize ( Archive & a ) {
a ( pos , width ) ;
}
} ;
2025-12-13 13:03:27 +03:00
class BrushStrokeCanvasComponent : public CanvasComponent {
2025-12-11 16:05:41 +03:00
public :
constexpr static float DRAW_MINIMUM_LIMIT = 0.3 ;
2025-12-15 15:36:42 +03:00
virtual CanvasComponentType get_type ( ) const override ;
2025-12-13 13:03:27 +03:00
virtual void save ( cereal : : PortableBinaryOutputArchive & a ) const override ;
virtual void load ( cereal : : PortableBinaryInputArchive & a ) override ;
2025-12-11 16:05:41 +03:00
virtual void save_file ( cereal : : PortableBinaryOutputArchive & a ) const override ;
virtual void load_file ( cereal : : PortableBinaryInputArchive & a , VersionNumber version ) override ;
2025-12-29 19:57:36 +03:00
virtual std : : unique_ptr < CanvasComponent > get_data_copy ( ) const override ;
2026-01-27 16:55:09 +03:00
virtual void change_stroke_color ( const Vector4f & newStrokeColor ) override ;
virtual std : : optional < Vector4f > get_stroke_color ( ) const override ;
2025-12-11 16:05:41 +03:00
struct Data {
2026-01-27 16:55:09 +03:00
std : : shared_ptr < std : : vector < BrushStrokeCanvasComponentPoint > > points = std : : make_shared < std : : vector < BrushStrokeCanvasComponentPoint > > ( ) ; // It's a pointer here since brush strokes cant be edited
2025-12-11 16:05:41 +03:00
Vector4f color ;
bool hasRoundCaps ;
2026-01-27 16:55:09 +03:00
} d ;
2025-12-11 16:05:41 +03:00
2025-12-15 15:36:42 +03:00
virtual void set_data_from ( const CanvasComponent & other ) override ;
2025-12-13 13:03:27 +03:00
private :
2026-02-07 18:49:56 +03:00
virtual void draw ( SkCanvas * canvas , const DrawData & drawData , const std : : shared_ptr < void > & predrawData ) const override ;
virtual bool accurate_draw ( SkCanvas * canvas , const DrawData & drawData , const CoordSpaceHelper & coords , const std : : shared_ptr < void > & predrawData ) const override ;
virtual std : : shared_ptr < void > get_predraw_data_accurate ( const DrawData & drawData , const CoordSpaceHelper & coords ) const override ;
2025-12-11 16:05:41 +03:00
virtual void initialize_draw_data ( DrawingProgram & drawP ) override ;
2025-12-13 13:03:27 +03:00
virtual bool collides_within_coords ( const SCollision : : ColliderCollection < float > & checkAgainst ) const override ;
2025-12-11 16:05:41 +03:00
void create_collider ( ) ;
2026-02-08 13:27:18 +03:00
bool should_draw_extra ( const DrawData & drawData , const CoordSpaceHelper & coords ) const override ;
2025-12-11 16:05:41 +03:00
virtual SCollision : : AABB < float > get_obj_coord_bounds ( ) const override ;
std : : shared_ptr < SkPath > brushPath ;
SCollision : : AABB < float > bounds ;
std : : array < std : : shared_ptr < SkPath > , 2 > brushPathLOD ;
2025-12-13 13:03:27 +03:00
2026-02-12 15:31:07 +03:00
std : : vector < BrushStrokeCanvasComponentPoint > every_nth_point_include_front_and_back ( const std : : vector < BrushStrokeCanvasComponentPoint > & pts , size_t n ) const ;
2025-12-11 16:05:41 +03:00
void add_precheck_aabb_level ( size_t level , const std : : vector < SCollision : : BVHContainer < float > > & levelArray ) ;
std : : vector < SCollision : : AABB < float > > precheckAABBLevels ;
2026-02-12 15:31:07 +03:00
void create_triangles ( const std : : function < bool ( Vector2f , Vector2f , Vector2f ) > & passTriangleFunc , const std : : vector < BrushStrokeCanvasComponentPoint > & smoothedPoints , size_t skipVertexCount , std : : shared_ptr < SkPathBuilder > bPath ) const ;
std : : vector < size_t > get_wedge_indices ( const std : : vector < BrushStrokeCanvasComponentPoint > & points ) const ;
std : : vector < BrushStrokeCanvasComponentPoint > smooth_points ( size_t beginIndex , size_t endIndex , unsigned numOfDivisions ) const ;
std : : vector < BrushStrokeCanvasComponentPoint > smooth_points_avg ( size_t beginIndex , size_t endIndex , unsigned numOfDivisions ) const ;
2025-12-11 16:05:41 +03:00
} ;