-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mudin Ibrahim
committed
Sep 14, 2019
1 parent
8bf38ff
commit fd63707
Showing
13 changed files
with
215 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,5 +9,6 @@ build | |
build/ | ||
lib | ||
lib/ | ||
demo/index.html | ||
dev/index.html | ||
demo/ | ||
dev/index.html | ||
dev/draw.html |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<!-- <link rel="stylesheet" href="index.css"> --> | ||
</head> | ||
<body> | ||
<div class="toolbar"> | ||
Indoorjs Free Draw | ||
</div> | ||
<div class="context"> | ||
<div class="sidebar"> | ||
<div id="drawing-mode-options"> | ||
<label for="drawing-line-width">Line width:</label> | ||
<span class="info">30</span | ||
><input type="range" value="30" min="0" max="150" id="drawing-line-width" /><br /> | ||
|
||
<label for="drawing-color">Line color:</label> | ||
<input type="color" value="#005E7A" id="drawing-color" /><br /> | ||
|
||
<button id="clear-canvas" class="btn btn-info">Clear</button> | ||
</div> | ||
</div> | ||
<div class="my-canvas"></div> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* eslint-disable no-undef */ | ||
import * as Indoor from '../src/Indoor.js'; | ||
|
||
import './index.css'; | ||
|
||
const canvasEl = document.querySelector('.my-canvas'); | ||
const drawingColorEl = document.querySelector('#drawing-color'); | ||
const drawingLineWidthEl = document.querySelector('#drawing-line-width'); | ||
const clearEl = document.querySelector('#clear-canvas'); | ||
|
||
const canvas = new Indoor.Canvas(canvasEl, {}); | ||
|
||
function oninput() { | ||
canvas.setLineWidth(parseInt(this.value, 10) || 1); | ||
} | ||
|
||
drawingLineWidthEl.addEventListener('input', oninput, false); | ||
|
||
drawingColorEl.onchange = function onchange() { | ||
canvas.setColor(this.value); | ||
}; | ||
|
||
clearEl.onclick = function onclick() { | ||
canvas.clear(); | ||
}; | ||
|
||
window.canv = canvas; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import Base from '../core/Base'; | ||
|
||
export class Canvas extends Base { | ||
constructor(container, options) { | ||
super(options); | ||
|
||
this.container = container; | ||
|
||
const canvas = document.createElement('canvas'); | ||
this.container.appendChild(canvas); | ||
canvas.setAttribute('id', 'indoorjs-canvas'); | ||
|
||
canvas.width = this.width || this.container.clientWidth; | ||
canvas.height = this.height || this.container.clientHeight; | ||
|
||
this.canvas = new fabric.Canvas(canvas, { | ||
isDrawingMode: true, | ||
freeDrawingCursor: 'none', | ||
freeDrawingLineWidth: this.lineWidth | ||
}); | ||
|
||
this.setLineWidth(this.lineWidth || 10); | ||
|
||
this.addCursor(); | ||
} | ||
|
||
addCursor() { | ||
const canvas = this.canvas; | ||
const cursorCanvas = document.createElement('canvas'); | ||
this.canvas.wrapperEl.appendChild(cursorCanvas); | ||
cursorCanvas.setAttribute('id', 'indoorjs-cursor-canvas'); | ||
cursorCanvas.style.position = 'absolute'; | ||
cursorCanvas.style.top = '0'; | ||
cursorCanvas.style.pointerEvents = 'none'; | ||
cursorCanvas.width = this.width || this.container.clientWidth; | ||
cursorCanvas.height = this.height || this.container.clientHeight; | ||
|
||
this.cursor = new fabric.StaticCanvas(cursorCanvas); | ||
const cursorOpacity = 0.5; | ||
const mousecursor = new fabric.Circle({ | ||
left: -1000, | ||
top: -1000, | ||
radius: canvas.freeDrawingBrush.width / 2, | ||
fill: `rgba(255,0,0,${cursorOpacity})`, | ||
stroke: 'black', | ||
originX: 'center', | ||
originY: 'center' | ||
}); | ||
|
||
this.cursor.add(mousecursor); | ||
this.mousecursor = mousecursor; | ||
|
||
canvas.on('mouse:move', evt => { | ||
const mouse = canvas.getPointer(evt.e); | ||
mousecursor | ||
.set({ | ||
top: mouse.y, | ||
left: mouse.x | ||
}) | ||
.setCoords() | ||
.canvas.renderAll(); | ||
}); | ||
|
||
canvas.on('mouse:out', () => { | ||
// put circle off screen | ||
mousecursor | ||
.set({ | ||
left: -1000, | ||
top: -1000 | ||
}) | ||
.setCoords() | ||
.canvas.renderAll(); | ||
}); | ||
} | ||
|
||
setColor(color) { | ||
this.canvas.freeDrawingBrush.color = color; | ||
|
||
if (!this.mousecursor) return; | ||
|
||
this.mousecursor | ||
.set({ | ||
left: 100, | ||
top: 100, | ||
fill: color | ||
}) | ||
.setCoords() | ||
.canvas.renderAll(); | ||
} | ||
|
||
setLineWidth(width) { | ||
this.lineWidth = width; | ||
this.canvas.freeDrawingBrush.width = width; | ||
|
||
if (!this.mousecursor) return; | ||
|
||
this.mousecursor | ||
.set({ | ||
left: 100, | ||
top: 100, | ||
radius: width / 2 | ||
}) | ||
.setCoords() | ||
.canvas.renderAll(); | ||
} | ||
|
||
clear() { | ||
this.canvas.clear(); | ||
} | ||
} | ||
|
||
export const canvas = (container, options) => new Canvas(container, options); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './Canvas.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters