mirror of
https://github.com/konvajs/konva.git
synced 2025-10-15 12:34:52 +08:00
Add new property imageSmoothingEnabled
to the layer. some ts fixes.
This commit is contained in:
@@ -35,6 +35,9 @@ export abstract class BaseLayer extends Container<Group | Shape> {
|
||||
super(config);
|
||||
this.on('visibleChange', this._checkVisibility);
|
||||
this._checkVisibility();
|
||||
|
||||
this.on('imageSmoothingEnabledChange', this._checkSmooth);
|
||||
this._checkSmooth();
|
||||
}
|
||||
// for nodejs?
|
||||
createPNGStream() {
|
||||
@@ -206,6 +209,10 @@ export abstract class BaseLayer extends Container<Group | Shape> {
|
||||
this.canvas._canvas.style.display = 'none';
|
||||
}
|
||||
}
|
||||
|
||||
_checkSmooth() {
|
||||
this.getContext()._context.imageSmoothingEnabled = this.imageSmoothingEnabled();
|
||||
}
|
||||
/**
|
||||
* get/set width of layer.getter return width of stage. setter doing nothing.
|
||||
* if you want change width use `stage.width(value);`
|
||||
@@ -275,10 +282,30 @@ export abstract class BaseLayer extends Container<Group | Shape> {
|
||||
}
|
||||
|
||||
clearBeforeDraw: GetSet<boolean, this>;
|
||||
imageSmoothingEnabled: GetSet<boolean, this>;
|
||||
}
|
||||
|
||||
BaseLayer.prototype.nodeType = 'BaseLayer';
|
||||
|
||||
/**
|
||||
* get/set imageSmoothingEnabled flag
|
||||
* For more info see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/imageSmoothingEnabled
|
||||
* @name Konva.BaseLayer#imageSmoothingEnabled
|
||||
* @method
|
||||
* @param {Boolean} imageSmoothingEnabled
|
||||
* @returns {Boolean}
|
||||
* @example
|
||||
* // get imageSmoothingEnabled flag
|
||||
* var imageSmoothingEnabled = layer.imageSmoothingEnabled();
|
||||
*
|
||||
* // disable clear before draw
|
||||
* layer.imageSmoothingEnabled(false);
|
||||
*
|
||||
* // enable clear before draw
|
||||
* layer.imageSmoothingEnabled(true);
|
||||
*/
|
||||
Factory.addGetterSetter(BaseLayer, 'imageSmoothingEnabled', true);
|
||||
|
||||
/**
|
||||
* get/set clearBeforeDraw flag which determines if the layer is cleared or not
|
||||
* before drawing
|
||||
|
@@ -62,7 +62,8 @@ var CONTEXT_PROPERTIES = [
|
||||
'textAlign',
|
||||
'textBaseline',
|
||||
'globalAlpha',
|
||||
'globalCompositeOperation'
|
||||
'globalCompositeOperation',
|
||||
'imageSmoothingEnabled'
|
||||
];
|
||||
|
||||
// TODO: document all context methods
|
||||
|
@@ -31,6 +31,7 @@ export class FastLayer extends BaseLayer {
|
||||
}
|
||||
_setCanvasSize(width, height) {
|
||||
this.canvas.setSize(width, height);
|
||||
this._checkSmooth();
|
||||
}
|
||||
hitGraphEnabled() {
|
||||
return false;
|
||||
|
@@ -16,7 +16,7 @@ import { Shape } from './Shape';
|
||||
* var group = new Konva.Group();
|
||||
*/
|
||||
export class Group extends Container<Group | Shape> {
|
||||
_validateAdd(child: Group | Shape) {
|
||||
_validateAdd(child: Node) {
|
||||
var type = child.getType();
|
||||
if (type !== 'Group' && type !== 'Shape') {
|
||||
Util.throw('You may only add groups and shapes to groups.');
|
||||
|
@@ -53,6 +53,7 @@ export class Layer extends BaseLayer {
|
||||
_setCanvasSize(width, height) {
|
||||
this.canvas.setSize(width, height);
|
||||
this.hitCanvas.setSize(width, height);
|
||||
this._checkSmooth();
|
||||
}
|
||||
_validateAdd(child) {
|
||||
var type = child.getType();
|
||||
|
@@ -157,7 +157,8 @@ var ABSOLUTE_OPACITY = 'absoluteOpacity',
|
||||
].join(SPACE),
|
||||
SCALE_CHANGE_STR = ['scaleXChange.konva', 'scaleYChange.konva'].join(SPACE);
|
||||
|
||||
const emptyChildren: Collection<Node> = new Collection();
|
||||
// TODO: can we remove children from node?
|
||||
const emptyChildren: Collection<any> = new Collection();
|
||||
|
||||
let idCounter = 1;
|
||||
|
||||
@@ -183,7 +184,7 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
||||
} = {};
|
||||
attrs: any = {};
|
||||
index = 0;
|
||||
parent: Container<Node> | undefined = undefined;
|
||||
parent: Container<Node> | null = null;
|
||||
_cache: Map<string, any> = new Map<string, any>();
|
||||
_lastPos: Point = null;
|
||||
_attrsAffectingSize!: string[];
|
||||
|
Reference in New Issue
Block a user