Skip to content

Commit

Permalink
daisy
Browse files Browse the repository at this point in the history
  • Loading branch information
YuhangGe authored and YuhangGe committed May 7, 2012
1 parent 445c720 commit 5d8b0fb
Show file tree
Hide file tree
Showing 14 changed files with 126 additions and 114 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -2,6 +2,7 @@
adb/
build/
data/
tools/

build.bat
.hgignore
1 change: 1 addition & 0 deletions bug&todo&tip.txt
Expand Up @@ -8,6 +8,7 @@ bug:

2������Ƥ����Ƕ��Ⱥ��᲻����ȷ���ơ������ڴ�������ע��˵����

4. ��firefox����˫��ʱ���������˫���ڹ���ϻ�ʧЧ����firefox���治�ܴ���doubleclick�¼����������mousedownʱ������λ�øı��������chrome��ie9����û��������⡣������firefox��bug����

todo:

Expand Down
4 changes: 2 additions & 2 deletions css/editor.css
Expand Up @@ -9,8 +9,8 @@
.sn-caret {
position: absolute;
display: block;
width: 1px;
background: transparent;
width: 5px;
background: rgba(0,0,255,0.1);/* transparent; */
left: 0px;
top: 0px;
padding: 0px;
Expand Down
2 changes: 1 addition & 1 deletion css/style.css
Expand Up @@ -198,7 +198,7 @@ a:hover{
font-size: 23px;
border : 1px solid white;
padding: 1px 5px 1px;
-webkit-border-radius : 5px;
border-radius : 5px;
}

#col-3 .edit-left .switch-current{
Expand Down
2 changes: 1 addition & 1 deletion js/editor/clipboard.js
Expand Up @@ -130,7 +130,7 @@
window.clipboardData.setData("text", this.inner_text);
}
} else if(type === 'image') {

return;
}

}
Expand Down
60 changes: 32 additions & 28 deletions js/editor/doodle.js
Expand Up @@ -20,7 +20,7 @@
top : 0,
height : 0,
width : 0
}
};
if(this.points.length !== 0)
this._calc();
}
Expand Down Expand Up @@ -82,6 +82,7 @@
Daisy._Doodle.prototype = {
_calc : function() {
this.boundary = $.getPointsBound(this.points, Math.round(this.pen_width));
//$.log(this.boundary);
},
drawEraser : function(ctx) {
ctx.save();
Expand All @@ -107,25 +108,25 @@
*/
addEraserIfIn : function(eraser) {
var n_e = null;
if(this._isEraserIn(eraser.points) && this.eraser_list.indexOf(eraser)<0) {
if(this._isEraserIn(eraser.points) && this.eraser_list.indexOf(eraser) < 0) {
n_e = new Daisy._Doodle.create(Daisy._Doodle.Type.ERASER, eraser.pen_width, "", [], eraser._copyPoints());
this.eraser_list.push(n_e);
}
return n_e;
},
addEraser : function(eraser){
addEraser : function(eraser) {
this.eraser_list.push(eraser);
},
removeEraser : function(eraser){
this.eraser_list.splice(this.eraser_list.indexOf(eraser),1);
removeEraser : function(eraser) {
this.eraser_list.splice(this.eraser_list.indexOf(eraser), 1);
},
addTmpEraser : function(eraser){
if(this._isEraserIn(eraser.points) && this.eraser_list.indexOf(eraser)<0) {
addTmpEraser : function(eraser) {
if(this._isEraserIn(eraser.points) && this.eraser_list.indexOf(eraser) < 0) {
this.eraser_list.push(eraser);
}
},
removeTmpEraser : function(eraser){
this.eraser_list.splice(this.eraser_list.indexOf(eraser),1);
removeTmpEraser : function(eraser) {
this.eraser_list.splice(this.eraser_list.indexOf(eraser), 1);
},
getBoundary : function() {
return this.boundary;
Expand Down Expand Up @@ -178,15 +179,15 @@
if(not_calc !== true)
this._calc();
},
rotateScale : function(relay_point, rotate, scale){
rotateScale : function(relay_point, rotate, scale) {
this.pre_points = this.points;
this.pre_pw = this.pen_width;
for(var i = 0; i < this.eraser_list.length; i++) {
var e = this.eraser_list[i];
e.pre_points = e.points;
e.pre_pw = e.pen_width;
}

this.editRotateScale(relay_point, rotate, scale);
},
_copyPoints : function() {
Expand All @@ -199,7 +200,7 @@
}
return c_ps;
},
move : function(dx, dy){
move : function(dx, dy) {
for(var i = 0; i < this.points.length; i++) {
this.points[i].x += dx;
this.points[i].y += dy;
Expand Down Expand Up @@ -232,7 +233,6 @@
}

Daisy._ImageDoodle = function(img_src, matrix, e_list) {
$.log('new img')
this.base(Daisy._Doodle.Type.IMAGE, [], "black", 5, e_list);
this.image = new Image();
if(matrix != null)
Expand Down Expand Up @@ -269,18 +269,22 @@
draw : function(ctx, d_ctx, m_ctx) {
if(!this.img_loaded)
return;
var b = this.boundary, l = b.left, t = b.top, w = b.width, h = b.height;
d_ctx.clearRect(0, 0, d_ctx.canvas.width, d_ctx.canvas.height);
this._doDraw(d_ctx, l, t, w, h);
this.drawEraser(d_ctx);
w += (l > 0 ? 0 : l);
h += (t > 0 ? 0 : t);
var b = this.boundary, l = b.left, t = b.top, w = b.width, h = b.height, mw = d_ctx.canvas.width, mh = d_ctx.canvas.height;
//$.log(b)
d_ctx.clearRect(0, 0, mw, mh);
this._doDraw(d_ctx);
this.drawEraser(d_ctx);
w = l > 0 ? (l + w < mw ? w : mw - l) : w + l;
h = t > 0 ? (t + h < mh ? h : mh - t) : h + t;
//下面的操作是防止drawImage参数不合法抛异常。
l = l > 0 ? l : 0;
t = t > 0 ? t : 0;
w = w > 0 ? w : 0;
h = h > 0 ? h : 0;
w = w > 0 ? w : 1;
h = h > 0 ? h : 1;
//$.log("%d,%d,%d,%d", l, t, w,h);

ctx.drawImage(d_ctx.canvas, l, t, w, h, l, t, w, h);

},
_doDraw : function(ctx) {
ctx.save();
Expand Down Expand Up @@ -310,16 +314,16 @@
}
this._calc();
},
move : function(dx,dy){
move : function(dx, dy) {
this.matrix[2] += dx;
this.matrix[5] += dy;
for(var i = 0; i < this.eraser_list.length; i++) {
this.eraser_list[i].move(dx, dy);
}
this._calc();
},
rotateScale : function(relay_point, rotate, scale){
rotateScale : function(relay_point, rotate, scale) {

this.pre_matrix = $.copyArray(this.matrix);
for(var i = 0; i < this.eraser_list.length; i++) {
var e = this.eraser_list[i];
Expand Down Expand Up @@ -351,7 +355,7 @@
for(var i = 0; i < this.eraser_list.length; i++) {
this.eraser_list[i].editRotateScale(relay_point, rotate, scale, true);
}
if(not_calc!==true){
if(not_calc !== true) {
this._calc();
}
},
Expand All @@ -373,7 +377,7 @@
// ctx.restore();
return;
},
_calc : function(){
_calc : function() {
return;
}
}
Expand Down Expand Up @@ -661,7 +665,7 @@
*/
if(this.eraser_list.length > 0) {
var b = this.boundary, l = b.left, t = b.top, w = b.width, h = b.height;
m_ctx.clearRect(0,0,m_ctx.canvas.width,m_ctx.canvas.height);
m_ctx.clearRect(0, 0, m_ctx.canvas.width, m_ctx.canvas.height);
for(var i = 0; i < this.list.length; i++) {
this.list[i].draw(m_ctx, d_ctx, m_ctx);
}
Expand Down
9 changes: 6 additions & 3 deletions js/editor/doodle_edit.js
Expand Up @@ -80,7 +80,12 @@
}
},
isPointIn : function(p) {
return p.x >= this.points[0].x && p.x <= this.points[1].x && p.y >= this.points[0].y && p.y <= this.points[2].y;
var ps = this.points;
return p.x >= Math.min(ps[0].x,ps[1].x,ps[2].x,ps[3].x)
&& p.x <= Math.max(ps[0].x,ps[1].x,ps[2].x,ps[3].x)
&& p.y >= Math.min(ps[0].y,ps[1].y,ps[2].y,ps[3].y)
&& p.y <= Math.max(ps[0].y,ps[1].y,ps[2].y,ps[3].y);
//return p.x >= this.points[0].x && p.x <= this.points[1].x && p.y >= this.points[0].y && p.y <= this.points[2].y;
},
isPointInClose : function(p) {
return p.x >= this.points[1].x - this.CANCEL_BTN.width / 2 && p.x <= this.points[1].x + this.CANCEL_BTN.width / 2 && p.y >= this.points[1].y - this.CANCEL_BTN.height / 2 && p.y <= this.points[1].y + this.CANCEL_BTN.height / 2;
Expand Down Expand Up @@ -144,11 +149,9 @@
if(this.select_doodle === null) {
return;
}

if(this.edit_doodle.isPointInClose(point)) {
this.__doodle_close__ = true;
} else if(this.edit_doodle.isPointInRotate(point)) {
//$.log('i r')
this.__doodle_rotate__ = true;
this.select_doodle.editStart(point);
this.edit_doodle.editStart(point);
Expand Down
15 changes: 10 additions & 5 deletions js/editor/editor.js
Expand Up @@ -228,10 +228,13 @@
y : not_scale ? y : Math.round((y - this.padding_top) / this.render.scale)
}
},
_getEventPoint : function(e, not_scale) {
_getEventPoint : function(e, is_chrome, not_scale) {
var x = 0, y = 0;
//$.log(e);
if( typeof e.offsetX !== 'undefined') {
if(is_chrome){
var off = $.getOffset(this.container);
x = e.x - off.left + this.container.scrollLeft + document.body.scrollLeft;
y = e.y - off.top + this.container.scrollTop + document.body.scrollTop;
}else if( typeof e.offsetX !== 'undefined') {
x = e.offsetX;
y = e.offsetY;
} else if( typeof e.x !== 'undefined') {
Expand All @@ -242,8 +245,10 @@
} else {
throw "no x in event(_getEventPoint)";
}
if(y < 0)
y = 0;
if(e.target === this.caret && !is_chrome){
x += this.caret.offsetLeft;
y += this.caret.offsetTop;
}
return {
x : not_scale ? x : Math.round(x / this.render.scale),
y : not_scale ? y : Math.round((y - this.padding_top) / this.render.scale)
Expand Down

0 comments on commit 5d8b0fb

Please sign in to comment.