Commit 8ef3878b authored by christian's avatar christian

update image-manager

parent 00d015b3
......@@ -3,35 +3,29 @@ function ImageManager(canvasId) {
ImageManager.instance = this;
NONE = 0, MOVING = 1, SCALING = 2, ROTATING = 3;
this.mouseDown = false;
this.mousePrevX = 0;
this.mousePrevY = 0;
this.selectedLayer = null;
this.layerState = NONE;
this.canvasOffsetX = 0;
this.canvasOffsetY = 0;
this.scaleImg = new Image();
this.rotateImg = new Image();
this.scaleImg.src = 'img/resize.png';
this.rotateImg.src = 'img/resize.png';
var canvas = canvasId;
var canvasOffsetX = canvas.offsetLeft;
var canvasOffsetY = canvas.offsetTop;
var context = canvas.getContext('2d');
var layers = new Array();
this.addLayer = function (img,src) {
var layer = new Layer(img,src);
layers.push(layer);
return layer;
this.mouseDown = false;
this.mousePrevX = 0;
this.mousePrevY = 0;
this.selectedLayer = null;
this.layerState = NONE;
this.canvasOffsetX = 0;
this.canvasOffsetY = 0;
this.scaleImg = new Image();
this.rotateImg = new Image();
this.scaleImg.src = 'img/resize.png';
this.rotateImg.src = 'img/resize.png';
var canvas = canvasId;
var canvasOffsetX = canvas.offsetLeft;
var canvasOffsetY = canvas.offsetTop;
var context = canvas.getContext('2d');
var layers = new Array();
this.addLayer = function (img,src) {
var layer = new Layer(img,src);
layers.push(layer);
return layer;
}
this.redraw = function() {
//this.canvasManager.changeShape(false);
// this.canvasManager.changeShape(false);
}
this.getCanvas = function() {
return canvas;
......@@ -43,20 +37,16 @@ function ImageManager(canvasId) {
return layers[i];
}
this.isScalingArea = function (mX, mY, layer) {
//if (layer instanceof TextLayer) {
// return false;
//}
var scaleOffsetX = layer.offsetX + layer.width;
var scaleOffsetY = layer.offsetY + layer.height;
var square = new Square(
var scaleOffsetX = layer.offsetX + layer.width;
var scaleOffsetY = layer.offsetY + layer.height;
var square = new Square(
new Vector(scaleOffsetX - this.scaleImg.width, scaleOffsetY - this.scaleImg.height),
new Vector(scaleOffsetX, scaleOffsetY - this.scaleImg.height),
new Vector(scaleOffsetX, scaleOffsetY),
new Vector(scaleOffsetX - this.scaleImg.width, scaleOffsetY));
square.rotate(layer.angle);
square.alignBottomRight(layer.getSquare().c);
return square.intersect(new Vector(mX, mY));
square.rotate(layer.angle);
square.alignBottomRight(layer.getSquare().c);
return square.intersect(new Vector(mX, mY));
}
}
......@@ -81,8 +71,9 @@ function Layer(img,src) {
this.angle = 0;
this.title = this.src.name;
this.compositeOperation = "source-over";
this.getTitle = function() {
return this.title;
this.getTitle = function() {
return this.title;
}
this.getFileData = function () {
return this.src;
......@@ -93,8 +84,8 @@ function Layer(img,src) {
this.isVisible = function () {
return this.visible;
}
this.toggleVisible = function() {
this.visible = !this.visible;
this.toggleVisible = function() {
this.visible = !this.visible;
}
this.setCompositeOperation = function (compositeOperation) {
this.compositeOperation = compositeOperation;
......@@ -112,12 +103,12 @@ function Layer(img,src) {
this.redraw();
return this.canvas;
}
this.intersect = function(x, y) {
var square = new Square(
new Vector(this.offsetX, this.offsetY),
new Vector(this.offsetX + this.width, this.offsetY),
new Vector(this.offsetX + this.width, this.offsetY + this.height),
new Vector(this.offsetX, this.offsetY + this.height));
this.intersect = function(x, y) {
var square = new Square(
new Vector(this.offsetX, this.offsetY),
new Vector(this.offsetX + this.width, this.offsetY),
new Vector(this.offsetX + this.width, this.offsetY + this.height),
new Vector(this.offsetX, this.offsetY + this.height));
square.rotate(this.angle);
return square.intersect(new Vector(x, y));
......@@ -128,9 +119,7 @@ function Layer(img,src) {
new Vector(this.offsetX + this.width, this.offsetY),
new Vector(this.offsetX + this.width, this.offsetY + this.height),
new Vector(this.offsetX, this.offsetY + this.height));
square.rotate(this.angle);
return square;
}
this.scale = function(width, height) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment