Awesome tool.
I'm using it in TypeScript. It would be really cool if some wrote LiterallyCanvas typings, but it's not a huge deal.
I'm trying to create a custom tool. That's what I came up with (it's a simple line from the examples):
class CraneTool {
public LC;
public name: string = "CraneTool";
public strokeWidth = 4;
public optionsStyle = "stroke-width";
public usesSimpleAPI = true;
public currentShape: any;
public begin(x, y, lc) {
this.currentShape = lc.createShape('Line', {
x1: x, y1: y, x2: x, y2: y,
strokeWidth: this.strokeWidth, color: this.LC.getColor('primary')
});
}
public continue(x, y, lc) {
this.currentShape.x2 = x;
this.currentShape.y2 = y;
this.LC.setShapesInProgress([this.currentShape]);
}
public end(x, y, lc) {
this.LC.saveShape(this.currentShape);
}
public willBecomeInactive (lc) { }
public didBecomeActive(lc) { }
constructor(lc: any) {
this.LC = lc;
}
}
And that's how I initialize LiterallyCanvas:
let lc = (<any>window).LC;
let planCanvas = lc.init(document.getElementsByClassName('plan-canvas')[0], { defaultStrokeWidth: 4, backgroundColor: '#fff', toolbarPosition: 'bottom' });
let craneTool: CraneTool = new CraneTool(planCanvas);
let tools = [
{ inst: this, name: 'pencil', el: $("#tool-pencil").parent()[0], tool: new lc.tools.Pencil(planCanvas) },
{ inst: this, name: 'eraser', el: $("#tool-eraser").parent()[0], tool: new lc.tools.Eraser(planCanvas) },
{ inst: this, name: 'rectangle', el: $("#tool-rectangle").parent()[0], tool: new lc.tools.Rectangle(planCanvas) },
{ inst: this, name: 'line', el: $("#tool-line").parent()[0], tool: new lc.tools.Line(planCanvas), },
{ inst: this, name: 'ellipse', el: $("#tool-ellipse").parent()[0], tool: new lc.tools.Ellipse(planCanvas), },
{ inst: this, name: 'text', el: $("#tool-text").parent()[0], tool: new lc.tools.Text(planCanvas), },
{ inst: this, name: 'CraneTool', el: $("#tool-crane").parent()[0], tool: craneTool }
];
var activateTool = (t) => {
planCanvas.setTool(t.tool);
}
tools.forEach((t) => {
t.el.style.cursor = "pointer";
t.el.onclick = (e) => {
e.preventDefault();
activateTool(t);
};
});
activateTool(tools[0]);
Unfortunately, after clicking the crane tool icon, nothing happens - no errors, but nothing can be drawn. Any ideas how this can be done in TypeScript? Maybe somebody implemented LiterallyCanvas in TypeScript in a different way?