import * as scrawl from '../source/scrawl.js';
import { reportSpeed } from './utilities.js';
Related files:
import * as scrawl from '../source/scrawl.js';
import { reportSpeed } from './utilities.js';
All the functionality required to set up this sort of editor is managed in the canvas-scene-editor.js
module
import { initializeCanvasSceneEditor } from './modules/canvas-scene-editor.js';
const sceneCanvas = scrawl.library.canvas['scene-canvas'];
sceneCanvas.set({
label: 'A demonstration of a simple design system.',
description: 'The entitys in this canvas can be positioned, sized, copied and styled using mouse UI and keyboard input.',
});
const {
/* eslint-disable-next-line */
killSceneEditor,
sceneLayer,
addControllerAttributes,
setGuiControlChars,
} = initializeCanvasSceneEditor({
sceneCanvas,
domEntityEditor: '#scene-canvas-dahsboard',
sceneDimensions: 1000,
}, scrawl);
const getRandomPosition = () => {
const x = Math.floor(Math.random() * 800) + 100;
const y = Math.floor(Math.random() * 800) + 100;
return [x, y];
}
Add some entitys that we want to control
scrawl.makeBlock({
name: 'block-entity-1',
group: sceneLayer.name,
start: getRandomPosition(),
handle: ['center', 'center'],
dimensions: [100, 50],
fillStyle: 'blue',
lineWidth: 3,
strokeStyle: 'orange',
method: 'fillThenDraw',
The entity’s hover, click and drag-drop functionality
...addControllerAttributes,
}).clone({
name: 'block-entity-2',
start: getRandomPosition(),
}).clone({
name: 'block-entity-3',
start: getRandomPosition(),
}).clone({
name: 'block-entity-4',
start: getRandomPosition(),
});
scrawl.makeWheel({
name: 'wheel-entity-1',
group: sceneLayer.name,
start: getRandomPosition(),
handle: ['center', 'center'],
radius: 50,
includeCenter: true,
fillStyle: 'green',
lineWidth: 3,
strokeStyle: 'orange',
method: 'fillThenDraw',
...addControllerAttributes,
}).clone({
name: 'wheel-entity-2',
start: getRandomPosition(),
}).clone({
name: 'wheel-entity-3',
start: getRandomPosition(),
}).clone({
name: 'wheel-entity-4',
start: getRandomPosition(),
});
scrawl.makePicture({
name: 'picture-entity-1',
group: sceneLayer.name,
imageSource: 'img/iris.png',
dimensions: [150, 150],
start: getRandomPosition(),
handle: ['center', 'center'],
copyDimensions: ['100%', '100%'],
copyStart: [0, 0],
lineWidth: 4,
strokeStyle: 'gold',
method: 'drawThenFill',
...addControllerAttributes,
}).clone({
name: 'picture-entity-2',
start: getRandomPosition(),
});
scrawl.makeLabel({
name: 'label-entity-1',
group: sceneLayer.name,
text: 'Hello',
fontString: '40px serif',
start: getRandomPosition(),
handle: ['center', 'center'],
...addControllerAttributes,
}).clone({
name: 'label-entity-2',
start: getRandomPosition(),
}).clone({
name: 'label-entity-3',
start: getRandomPosition(),
}).clone({
name: 'label-entity-4',
start: getRandomPosition(),
});
Most interaction is handled in the modules; the only thing we need to do here is give users the opportunity to update their keyboard character choices for manipulating the GUI controls
const button = document.querySelector('#update-keyboard-shortcuts-action');
const buttonClickAction = () => {
const keys = window.prompt('To change the keyboard settings to move, scale and rotate selected entitys, enter the desired characters (11 in total) in the order MOVE-DELTA, MOVE-UP, MOVE-LEFT, MOVE-DOWN, MOVE-RIGHT, SCALE-DELTA, SCALE-GROW, SCALE-SHRINK, ROTATE-DELTA, ROTATE-CLOCKWISE, ROTATE-ANTI-CLOCKWISE (with no spaces or separating commas etc, though the comma key can be used as a shortcut). Character case will be ignored.', 'QWASDBNMGJH');
setGuiControlChars(keys);
};
/** @ts-expect-error */
button.onclick = buttonClickAction;
Function to display frames-per-second data, and other information relevant to the demo
const report = reportSpeed('#reportmessage');
Create the Display cycle animation
scrawl.makeRender({
name: "demo-animation",
afterShow: report,
});
console.log(scrawl.library);