Click here to Skip to main content
15,887,214 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Wordle 848 ---- Not bad for a Sunday! Pin
Cp-Coder15-Oct-23 1:44
Cp-Coder15-Oct-23 1:44 
GeneralRe: Wordle 848 - 4 4 me Pin
pkfox15-Oct-23 9:37
professionalpkfox15-Oct-23 9:37 
GeneralRe: Wordle 848 Pin
jmaida15-Oct-23 10:25
jmaida15-Oct-23 10:25 
GeneralSomething a little different... Pin
Graeme_Grant14-Oct-23 14:42
mvaGraeme_Grant14-Oct-23 14:42 
GeneralRe: Something a little different... Pin
jthompson1215-Oct-23 9:02
jthompson1215-Oct-23 9:02 
Generalslow day. so may as well share another victory Pin
honey the codewitch14-Oct-23 13:03
mvahoney the codewitch14-Oct-23 13:03 
GeneralRe: slow day. so may as well share another victory Pin
Gary R. Wheeler15-Oct-23 10:56
Gary R. Wheeler15-Oct-23 10:56 
PraiseHeck yeah, I broke through! Pin
honey the codewitch14-Oct-23 6:18
mvahoney the codewitch14-Oct-23 6:18 
I've been struggling to create a relatively easy way to create shapes in an in memory SVG document (not parsing from XML but working with the end data structures directly)

The idea is that you can build SVGs dynamically without generating and then parsing XML, and then I can use that to handle all my draws for my UI library. One advantage of this is I'll be able to make a web based visual designer where all my controls are drawn on the designer surface using <svg> elements. It also makes for very pretty and flexible drawing.

The trouble is SVG has a LOT of data for any given operation. Now normally, you can kind of lean on the XML to rapidly type in all the stuff you need, but to do so in C++ requires significantly more effort because you're manipulating data structures instead of just going <path d="10 23 M 0 180 L...

I finally took my inspiration from .NET's StringBuilder class. I shamelessly stole the basic idea and applied it to building paths. Since a shape is essentially just a series of paths with associated style information 80% of the effort is in building the paths themselves.

And I wound up with this slick little class that does all the heavy lifting.

It has been a good morning.


C++
class svg_path_builder final {
    void* (*m_allocator)(size_t);
    void* (*m_reallocator)(void*, size_t);
    void (*m_deallocator)(void*);
    float* m_begin;
    size_t m_size;
    size_t m_capacity;
    rectf m_cp;
    void do_free();
    void do_copy(const svg_path_builder& rhs);
    void do_move(svg_path_builder& rhs);
    gfx_result add_point(pointf pt);
    gfx_result move_to_impl(pointf pt);
    gfx_result line_to_impl(pointf pt);
    gfx_result cubic_bezier_to_impl(pointf pt, const rectf& cp);
   public:
    svg_path_builder(void*(allocator)(size_t) = ::malloc, void*(reallocator)(void*, size_t) = ::realloc, void(deallocator)(void*) = ::free);
    svg_path_builder(const svg_path_builder& rhs);
    svg_path_builder& operator=(const svg_path_builder& rhs);
    svg_path_builder(svg_path_builder&& rhs);
    svg_path_builder& operator=(svg_path_builder&& rhs);
    ~svg_path_builder();
    size_t size() const;
    void clear(bool keep_capacity=true);
    size_t capacity() const;
    float* begin();
    float* end();
    const float* cbegin() const;
    const float* cend() const;
    gfx_result move_to(pointf location, bool relative=false);
    gfx_result line_to(pointf location, bool relative=false);
    gfx_result cubic_bezier_to(pointf location, const rectf& control_points, bool relative=false);
    gfx_result quad_bezier_to(pointf location, pointf control_point,bool relative=false);
    gfx_result arc_to(pointf location, sizef radius, float x_angle, bool large_arc, svg_sweep_direction sweep_direction, bool relative=false);
    svg_path* to_path(bool closed = false, const svg_transform* xform = nullptr) const;
};

Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx
And my IoT UI/User Experience library here:
https://honeythecodewitch.com/uix

GeneralRe: Heck yeah, I broke through! Pin
Toad B.14-Oct-23 11:00
professionalToad B.14-Oct-23 11:00 
GeneralRe: Heck yeah, I broke through! Pin
jmaida14-Oct-23 11:54
jmaida14-Oct-23 11:54 
GeneralRe: Heck yeah, I broke through! Pin
honey the codewitch14-Oct-23 11:55
mvahoney the codewitch14-Oct-23 11:55 
Generalworldle 631 3/6 Pin
jmaida13-Oct-23 19:19
jmaida13-Oct-23 19:19 
GeneralWordle 847 Pin
Sandeep Mewara13-Oct-23 18:48
mveSandeep Mewara13-Oct-23 18:48 
GeneralRe: Wordle 847 4/6 Pin
jmaida13-Oct-23 19:15
jmaida13-Oct-23 19:15 
GeneralRe: Wordle 847 Pin
OriginalGriff13-Oct-23 19:39
mveOriginalGriff13-Oct-23 19:39 
GeneralRe: Wordle 847 Pin
Amarnath S13-Oct-23 20:12
professionalAmarnath S13-Oct-23 20:12 
GeneralRe: Wordle 847 Pin
ChandraRam13-Oct-23 21:56
ChandraRam13-Oct-23 21:56 
GeneralRe: Wordle 847 - 3 4 me Pin
pkfox13-Oct-23 23:16
professionalpkfox13-Oct-23 23:16 
GeneralRe: Wordle 847 2/6 Pin
StarNamer@work14-Oct-23 0:31
professionalStarNamer@work14-Oct-23 0:31 
GeneralRe: Wordle 847 Pin
Cp-Coder14-Oct-23 1:19
Cp-Coder14-Oct-23 1:19 
GeneralRe: Wordle 847 Pin
GuyThiebaut14-Oct-23 1:43
professionalGuyThiebaut14-Oct-23 1:43 
Generalworldle 630 3/6 Pin
jmaida13-Oct-23 16:40
jmaida13-Oct-23 16:40 
GeneralLanguage? Pin
Slow Eddie13-Oct-23 10:59
professionalSlow Eddie13-Oct-23 10:59 
GeneralRe: Language? Pin
Mike Hankey13-Oct-23 11:22
mveMike Hankey13-Oct-23 11:22 
GeneralRe: Language? Pin
Edward Aymami13-Oct-23 19:27
Edward Aymami13-Oct-23 19:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.