fix paste fix graduation

This commit is contained in:
mkwiser
2014-09-21 15:16:32 +08:00
parent dfaee05a79
commit d65f230e0f
3 changed files with 54 additions and 14 deletions

View File

@@ -12,7 +12,9 @@ define(
var commandList = require('../menu/commandList');
var lang = require('common/lang');
var modeSupport = require('../mode/support');
var pathAdjust = require('graphics/pathAdjust');
var computeBoundingBox = require('graphics/computeBoundingBox');
/**
* 右键点击处理
@@ -26,6 +28,21 @@ define(
else if (e.command == 'paste') {
var shapes = this.getClipBoard();
if(shapes) {
var bound = computeBoundingBox.computePath.apply(null,
shapes.map(function(shape){
return shape.points;
})
);
// 需要根据坐标原点以及缩放换算成鼠标位置移动
var origin = this.axis;
var pos = e.pos;
var scale = this.render.camera.scale;
var x = (pos.x - origin.x) / scale;
var y = (origin.y - pos.y) / scale;
shapes.forEach(function(shape) {
pathAdjust(shape.points, 1, 1, x - bound.x, y - bound.y - bound.height);
});
this.setShapes(shapes);
this.setMode('shapes', shapes);
this.fire('change');

View File

@@ -57,8 +57,9 @@ define(
) {
return;
}
console.time('refresh');
me.scale(ratio, e);
console.timeEnd('refresh');
});
}
}

View File

@@ -18,6 +18,7 @@ define(
*/
function drawGraduation(ctx, config) {
var x = Math.round(config.x);
var y = Math.round(config.y);
@@ -68,22 +69,16 @@ define(
ctx.fillStyle = ctx.strokeStyle;
// 横轴线
var textOffset = thickness - 8; // 文本偏移
for(var axis = x, i = 0; axis < width; i++, axis += markSize) {
ctx.moveTo(axis, thickness - (i % 5 ? markHeight : 2 * markHeight));
ctx.lineTo(axis, thickness);
if (0 == i % 10) {
ctx.fillText( gap * i, axis, textOffset);
}
}
for(var axis = x, i = 0; axis > thickness; i++, axis -= markSize) {
ctx.moveTo(axis, thickness - (i % 5 ? markHeight : 2 * markHeight));
ctx.lineTo(axis, thickness);
if (0 == i % 10) {
ctx.fillText( -gap * i, axis, textOffset);
}
}
@@ -92,19 +87,46 @@ define(
for(var axis = y, i = 0; axis > thickness; i++, axis -= markSize) {
ctx.moveTo(thickness - (i % 5 ? markHeight : 2 * markHeight), axis);
ctx.lineTo(thickness, axis);
if (0 == i % 10) {
ctx.fillText(gap * i, textOffset, axis);
}
}
for(var axis = y, i = 0; axis < height; i++, axis += markSize) {
ctx.moveTo(thickness - (i % 5 ? markHeight : 2 * markHeight), axis);
ctx.lineTo(thickness, axis);
}
// 绘制轴线文字这里由于canvas不支持小字体因此进行缩放后绘制
ctx.scale(0.8, 0.8);
var textOffset = thickness - 8; // 文本偏移
for(var axis = x, i = 0; axis < width; i++, axis += markSize) {
if (0 == i % 10) {
ctx.fillText( -gap * i, 0, axis);
ctx.fillText( gap * i, axis * 1.25 - 3, textOffset * 1.25);
}
}
for(var axis = x, i = 0; axis > thickness; i++, axis -= markSize) {
if (0 == i % 10) {
ctx.fillText( -gap * i, axis * 1.25 - 3, textOffset * 1.25);
}
}
// 纵轴线
var textOffset = 0; // 文本偏移
for(var axis = y, i = 0; axis > thickness; i++, axis -= markSize) {
if (0 == i % 10) {
ctx.fillText(gap * i, textOffset * 1.25, axis * 1.25 + 3);
}
}
for(var axis = y, i = 0; axis < height; i++, axis += markSize) {
if (0 == i % 10) {
ctx.fillText( -gap * i, textOffset * 1.25, axis * 1.25 + 3);
}
}
ctx.scale(1.25, 1.25);
ctx.stroke();
}