svgdotjs / svg.shapes.js

A shapes plugin for the SVG.js library
36 stars 18 forks source link

Use Shapes with draw plugin #4

Open rajkaran opened 5 years ago

rajkaran commented 5 years ago

How can I use shapes in conjunction with draw plugin. I want to draw a pentagon with mouse movement, similar to other basic shapes.

Is there a way to do it?

Fuzzyma commented 5 years ago

You can create a plugin for the draw plugin to handle other shapes. But for this to work, you would need to change the type of an element created by the shapes plugin. Usually, the type is the tag name. So a svg.js polygon object has the property type:polygon. The draw plugin picks that up and loads the polygon extension to draw a polygon. But thats not what you want. You want to draw a custom shape. So, register an extension for say "star" and change the type of the created polygon to star so that draw loads the correct plugin. Now you can handle the drawing process.

oooor you just spawn a shape with a predefined size and make it resizable. That might be easier...

rajkaran commented 5 years ago

I did tried to follow the discussion on issue https://github.com/svgdotjs/svg.draw.js/issues/9

But couldn't make it work. I was trying to avoid reading source code, seems like i will have to do that...