mirror of
https://github.com/idrawjs/idraw
synced 2026-05-24 10:08:34 +00:00
feat: clear code for @idraw/core
This commit is contained in:
parent
a8e7ddbeac
commit
3bf2ea751d
2 changed files with 41 additions and 41 deletions
|
|
@ -67,20 +67,20 @@ class Board {
|
|||
return this[_ctx];
|
||||
}
|
||||
|
||||
createContext(canvas: HTMLCanvasElement) {
|
||||
const opts = this[_opts];
|
||||
canvas.width = opts.contextWidth * opts.devicePixelRatio;
|
||||
canvas.height = opts.contextHeight * opts.devicePixelRatio;
|
||||
return new Context(canvas.getContext('2d') as CanvasRenderingContext2D, this[_opts]);
|
||||
}
|
||||
// createContext(canvas: HTMLCanvasElement) {
|
||||
// const opts = this[_opts];
|
||||
// canvas.width = opts.contextWidth * opts.devicePixelRatio;
|
||||
// canvas.height = opts.contextHeight * opts.devicePixelRatio;
|
||||
// return new Context(canvas.getContext('2d') as CanvasRenderingContext2D, this[_opts]);
|
||||
// }
|
||||
|
||||
createCanvas() {
|
||||
const opts = this[_opts];
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = opts.contextWidth * opts.devicePixelRatio;
|
||||
canvas.height = opts.contextHeight * opts.devicePixelRatio;
|
||||
return canvas;
|
||||
}
|
||||
// createCanvas() {
|
||||
// const opts = this[_opts];
|
||||
// const canvas = document.createElement('canvas');
|
||||
// canvas.width = opts.contextWidth * opts.devicePixelRatio;
|
||||
// canvas.height = opts.contextHeight * opts.devicePixelRatio;
|
||||
// return canvas;
|
||||
// }
|
||||
|
||||
scale(scaleRatio: number): TypeScreenContext {
|
||||
if (scaleRatio > 0) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { TypeData, TypeElement, TypeElemDesc } from '@idraw/types';
|
||||
import { TypeData, TypeElement } from '@idraw/types';
|
||||
import Board from '@idraw/board';
|
||||
import util from '@idraw/util';
|
||||
import { LoaderEvent, TypeLoadData, TypeLoaderEventArgMap } from './loader-event';
|
||||
|
|
@ -21,7 +21,7 @@ export default class Loader {
|
|||
|
||||
private _opts: Options;
|
||||
private _event: LoaderEvent;
|
||||
private _patternMap: {[uuid: string]: CanvasPattern} = {}
|
||||
// private _patternMap: {[uuid: string]: CanvasPattern} = {}
|
||||
private _currentLoadData: TypeLoadData = {};
|
||||
private _currentUUIDQueue: string[] = [];
|
||||
private _storageLoadData: TypeLoadData = {};
|
||||
|
|
@ -77,33 +77,33 @@ export default class Loader {
|
|||
return null;
|
||||
}
|
||||
|
||||
getPattern(
|
||||
elem: TypeElement<keyof TypeElemDesc>,
|
||||
opts?: {
|
||||
forceUpdate: boolean
|
||||
}
|
||||
): null | CanvasPattern {
|
||||
if (this._patternMap[elem.uuid] ) {
|
||||
if (!(opts && opts.forceUpdate === true)) {
|
||||
return this._patternMap[elem.uuid];
|
||||
}
|
||||
}
|
||||
const item = this._currentLoadData[elem.uuid];
|
||||
if (item?.status === 'loaded') {
|
||||
const board = this._opts.board;
|
||||
const tempCanvas = board.createCanvas();
|
||||
const tempCtx = board.createContext(tempCanvas);
|
||||
const image = this.getContent(elem.uuid);
|
||||
tempCtx.drawImage(image, elem.x, elem.y, elem.w, elem.h);
|
||||
// getPattern(
|
||||
// elem: TypeElement<keyof TypeElemDesc>,
|
||||
// opts?: {
|
||||
// forceUpdate: boolean
|
||||
// }
|
||||
// ): null | CanvasPattern {
|
||||
// if (this._patternMap[elem.uuid] ) {
|
||||
// if (!(opts && opts.forceUpdate === true)) {
|
||||
// return this._patternMap[elem.uuid];
|
||||
// }
|
||||
// }
|
||||
// const item = this._currentLoadData[elem.uuid];
|
||||
// if (item?.status === 'loaded') {
|
||||
// const board = this._opts.board;
|
||||
// const tempCanvas = board.createCanvas();
|
||||
// const tempCtx = board.createContext(tempCanvas);
|
||||
// const image = this.getContent(elem.uuid);
|
||||
// tempCtx.drawImage(image, elem.x, elem.y, elem.w, elem.h);
|
||||
|
||||
const canvas = board.createCanvas();
|
||||
const ctx = board.createContext(canvas);
|
||||
const pattern = ctx.createPattern(tempCanvas, 'no-repeat');
|
||||
if (pattern) this._patternMap[elem.uuid] = pattern;
|
||||
return pattern;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
// const canvas = board.createCanvas();
|
||||
// const ctx = board.createContext(canvas);
|
||||
// const pattern = ctx.createPattern(tempCanvas, 'no-repeat');
|
||||
// if (pattern) this._patternMap[elem.uuid] = pattern;
|
||||
// return pattern;
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
|
||||
private _resetLoadData(data: TypeData): [string[], TypeLoadData] {
|
||||
const loadData: TypeLoadData = {};
|
||||
|
|
|
|||
Loading…
Reference in a new issue