Note that there are some explanatory texts on larger screens.

plurals
  1. POFabricJS - How to dragging an object in Shape filled object?
    primarykey
    data
    text
    <p>Im trying to drawing line Shape (fabric.Line).</p> <p>and then after drawn shape. it filled image.</p> <p>When finished drawing an shape, I want to drag an filled image (inside Shape)</p> <p>Here is the jsfiddle >> <a href="http://jsfiddle.net/dTpVw/" rel="nofollow">http://jsfiddle.net/dTpVw/</a></p> <pre><code>var canvas = new fabric.Canvas('c', { selection:false }); var mode = "add"; var currentShape; canvas.observe("mouse:move", function (event) { var pos = canvas.getPointer(event.e); if (mode === "edit" &amp;&amp; currentShape) { if (currentShape.type === "line") { currentShape.set({ x2 : pos.x, y2 : pos.y }); canvas.renderAll(); } else if (currentShape.type === "polygon") { var points = currentShape.get("points"); points[points.length - 1].x = pos.x - currentShape.get("left"); points[points.length - 1].y = pos.y - currentShape.get("top"); currentShape.set({ points : points }); canvas.renderAll(); } } }); canvas.observe("mouse:down", function (event) { var pos = canvas.getPointer(event.e); if (mode === "add") { var polygon = new fabric.Line([ pos.x, pos.y, pos.x + 2, pos.y + 2 ], { fill : 'red' }); currentShape = polygon; canvas.add(currentShape); mode = "edit"; } else if (mode === "edit" &amp;&amp; currentShape &amp;&amp; currentShape.type === "line") { // replace line with polygon canvas.remove(currentShape); var points = []; points.push({ x : currentShape.x1 - pos.x, y : currentShape.y1 - pos.y }); points.push({ x : currentShape.x2 - pos.x, y : currentShape.y2 - pos.y }); points.push({ x : currentShape.x2 - pos.x + 5, y : currentShape.y2 - pos.y + 5 }); var polygon = new fabric.Polygon(points, { fill : 'blue', left : pos.x, top : pos.y, opacity: 0.5 // 투명도 적용 }); canvas.add(polygon); Spolygon = polygon; currentShape = polygon; canvas.renderAll(); } else if (mode === "edit" &amp;&amp; currentShape &amp;&amp; currentShape.type === "polygon") { var points = currentShape.get("points"); points.push({ x : pos.x - currentShape.get("left"), y : pos.y - currentShape.get("top") }); currentShape.set({ points : points }); canvas.renderAll(); } }); function loadPattern(url) { fabric.util.loadImage(url, function(img) { console.log(Spolygon); Spolygon.fill = new fabric.Pattern({ source : img, repeat : 'repeat' }); canvas.renderAll(); }); Spolygon.hasControls = false; // Spolygon.selectable = false; Spolygon.hasRotatingPoint = false; Spolygon.lockMovementX = true; Spolygon.lockMovementY = true; } function dblClickHandler(event) { currentShape.setCoords(); mode ="add2"; loadPattern('http://fabricjs.com/assets/retina_wood.png'); }; fabric.util.addListener(fabric.document, 'dblclick', dblClickHandler); //fabric.util.removeListener(canvas.upperCanvasEl, 'dblclick', dblClickHandler); </code></pre> <p>Thank you for reading my question... Please someone help me T_T</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload