Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function drawRuller(element=false){
- cr.control_canvas.getObjects().forEach((el)=>{
- if(el.is_ruller){
- el.remove();
- }
- });
- function createLine(x,y, size=13){
- return new fabric.Line([
- 0, 0,
- 0, 100
- ], {
- left: 0,
- top: 0,
- originX: 'left',
- originY: 'top',
- stroke: "green",
- strokeWidth: 3
- });
- }
- let width = element.width,
- half_width = Math.ceil(width/2),
- height = element.height,
- half_height = Math.ceil(height/2)
- start_point_w = Math.ceil(width/2),
- start_point_h = Math.ceil(height/2),
- offset_x = element.left+half_width,
- offset_y = element.top+half_height,
- lines = [];
- let distance = Math.ceil(half_width/5);
- for(let i=0; i<half_width; i+=distance){
- lines.push(createLine(0,half_width+distance, 13));
- lines.push(createLine(0,half_width-distance, 13));
- }
- const rect = new fabric.Rect({ left: 0, top: 0, width: 300, height: 300, fill: 'rgba(0,0,0,0)' });
- let group = new fabric.Group([...lines, rect],{
- width: 300,
- height: 300,
- top: 100,
- left: 100,
- scaleX: 1,
- scaleY: 1,
- });
- group.is_ruller = true;
- //group.add(...lines);
- window.lines = lines;
- console.log("group", group);
- cr.control_canvas.add(group)
- cr.control_canvas.renderAll();
- }
- drawRuller(cr.control_canvas.getActiveObject());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement