Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Heck yeah, I broke through!

Heck yeah, I broke through!

Scheduled Pinned Locked Moved The Lounge
csharpc++graphicsdesignxml
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    honey the codewitch
    wrote on last edited by
    #1

    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.

    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_resu

    T J 2 Replies Last reply
    0
    • H honey the codewitch

      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.

      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_resu

      T Offline
      T Offline
      Toad B
      wrote on last edited by
      #2

      From a 67 year old VB.net novice to a real Pro... Thanks for the inspiration.

      1 Reply Last reply
      0
      • H honey the codewitch

        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.

        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_resu

        J Offline
        J Offline
        jmaida
        wrote on last edited by
        #3

        are u doing all the math for shapes inside your code? looks that way

        "A little time, a little trouble, your better day" Badfinger

        H 1 Reply Last reply
        0
        • J jmaida

          are u doing all the math for shapes inside your code? looks that way

          "A little time, a little trouble, your better day" Badfinger

          H Offline
          H Offline
          honey the codewitch
          wrote on last edited by
          #4

          Yeah

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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups