Skip to content

Commit

Permalink
继续优化
Browse files Browse the repository at this point in the history
  • Loading branch information
anlun214 committed Jun 26, 2017
1 parent ad903e9 commit 6c1e2f0
Show file tree
Hide file tree
Showing 16 changed files with 122 additions and 191 deletions.
13 changes: 5 additions & 8 deletions annie/display/DisplayObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,8 @@ namespace annie {
}
}
/**
* 获取或者设置显示对象在父级里的x方向的宽,如果你要同时获取款高
* 之前需要使用getWH或者setWH 现已废弃
* 获取或者设置显示对象在父级里的x方向的宽,不到必要不要用此属性获取高
* 如果你要同时获取款高,建议使用getWH()方法获取宽和高
* @property width
* @public
* @since 1.0.3
Expand All @@ -547,8 +547,8 @@ namespace annie {
}
}
/**
* 获取或者设置显示对象在父级里的y方向的高
* 之前需要使用getWH或者setWH 现已废弃
* 获取或者设置显示对象在父级里的y方向的高,不到必要不要用此属性获取高
* 如果你要同时获取款高,建议使用getWH()方法获取宽和高
* @property height
* @public
* @since 1.0.3
Expand All @@ -574,10 +574,7 @@ namespace annie {
*/
public getWH():{width:number,height:number}{
let s = this;
if(s._instanceType=="annie.MovieClip") {
s.update(false, false, false);
s._updateInfo.UM = true;
}
s.update(true, false, false);
let dr = s.getDrawRect();
return {width:dr.width,height:dr.height};
}
Expand Down
2 changes: 1 addition & 1 deletion annie/display/Shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ namespace annie {
* @public
* @since 1.0.2
*/
public changeColor(infoObj: any): void {
public changeColor(infoObj: any): void{
let s = this;
let cLen: number = s._command.length;
let c = s._command;
Expand Down
87 changes: 0 additions & 87 deletions annie/events/UIEvent.ts

This file was deleted.

2 changes: 1 addition & 1 deletion annie/net/URLLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace annie {
let s = this;
if (s._req) {
s._req.abort();
s._req = null;
// s._req = null;
}
}

Expand Down
121 changes: 65 additions & 56 deletions annie/ui/DrawingBoard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,25 @@ namespace annieUI {
* @since 1.1.1
*/
export class DrawingBoard extends annie.Bitmap {
protected context:CanvasRenderingContext2D=null;
protected context: CanvasRenderingContext2D = null;
private _isMouseDown: boolean = false;

/**
* 绘画半径
* @property drawRadius
* @type {number}
* @public
* @since 1.1.1
*/
public get drawRadius():number{
public get drawRadius(): number {
return this._drawRadius;
};
public set drawRadius(value:number){
this._drawRadius=value;

public set drawRadius(value: number) {
this._drawRadius = value;
}
protected _drawRadius:number=50;

protected _drawRadius: number = 50;
/**
* 绘画颜色, 可以是任何的颜色类型
* @property drawColor
Expand All @@ -38,15 +41,15 @@ namespace annieUI {
* @since
* @type {any}
*/
public drawColor:any="#000";
public drawColor: any = "#ffffff";
/**
* 背景色 可以是任何的颜色类型
* @property bgColor
* @type {any}
* @public
* @since 1.1.1
*/
public bgColor:any="";
public bgColor: any = "";
/**
* 画板宽
* @property drawWidth
Expand All @@ -55,7 +58,7 @@ namespace annieUI {
* @public
* @since 1.1.1
*/
public drawWidth:number=0;
public drawWidth: number = 0;
/**
* 画板高
* @property drawHeight
Expand All @@ -64,13 +67,14 @@ namespace annieUI {
* @public
* @since 1.1.1
*/
public drawHeight:number=0;
public drawHeight: number = 0;
//总步数数据
protected totalStepList:any=[];
protected totalStepList: any = [];
//单步数据
protected addStepObj:any;
protected addStepObj: any;
//当前步数所在的id
protected currentStepId:number=0;
protected currentStepId: number = 0;

/**
* 构造函数
* @method DrawingBoard
Expand All @@ -79,18 +83,18 @@ namespace annieUI {
* @param bgColor 背景色 默认透明
* @since 1.1.1
*/
constructor(width: number, height: number,bgColor: any="") {
constructor(width: number, height: number, bgColor: any = "") {
super();
var s = this;
var bd=document.createElement("canvas");
bd.width=width;
bd.height=height;
s.context=bd.getContext("2d");
var bd = document.createElement("canvas");
bd.width = width;
bd.height = height;
s.context = bd.getContext("2d");
s.context.lineCap = "round";
s.context.lineJoin = "round";
s.bitmapData=bd;
s.drawHeight=height;
s.drawWidth=width;
s.bitmapData = bd;
s.drawHeight = height;
s.drawWidth = width;
s.reset(bgColor);
var mouseDown = s.onMouseDown.bind(s);
var mouseMove = s.onMouseMove.bind(s);
Expand All @@ -99,99 +103,104 @@ namespace annieUI {
s.addEventListener(annie.MouseEvent.MOUSE_MOVE, mouseMove);
s.addEventListener(annie.MouseEvent.MOUSE_UP, mouseUp);
}
private onMouseDown(e:annie.MouseEvent): void {

private onMouseDown(e: annie.MouseEvent): void {
var s = this;
var ctx = s.context;
ctx.beginPath();
ctx.strokeStyle = s.drawColor;
ctx.lineWidth = s._drawRadius;
let lx:number=e.localX >> 0;
let ly:number=e.localY >> 0;
let lx: number = e.localX >> 0;
let ly: number = e.localY >> 0;
ctx.moveTo(lx, ly);
s._isMouseDown = true;
s.addStepObj={};
s.addStepObj.c=s.drawColor;
s.addStepObj.r=s._drawRadius;
s.addStepObj.sx=lx;
s.addStepObj.sy=ly;
s.addStepObj.ps=[];
s.addStepObj = {};
s.addStepObj.c = s.drawColor;
s.addStepObj.r = s._drawRadius;
s.addStepObj.sx = lx;
s.addStepObj.sy = ly;
s.addStepObj.ps = [];
};
private onMouseUp(e:annie.MouseEvent):void {
let s=this;

private onMouseUp(e: annie.MouseEvent): void {
let s = this;
s._isMouseDown = false;
if(s.addStepObj.ps.length>0) {
if (s.addStepObj.ps.length > 0) {
s.currentStepId++;
s.totalStepList.push(s.addStepObj);
}
};
private onMouseMove(e:annie.MouseEvent):void{

private onMouseMove(e: annie.MouseEvent): void {
var s = this;
if (s._isMouseDown) {
var ctx = s.context;
let lx:number=e.localX >> 0;
let ly:number=e.localY >> 0;
let lx: number = e.localX >> 0;
let ly: number = e.localY >> 0;
ctx.lineTo(lx, ly);
ctx.stroke();
s.addStepObj.ps.push(lx,ly);
s.addStepObj.ps.push(lx, ly);
}
};

/**
* 重置画板
* @method reset
* @param bgColor
* @public
* @since 1.1.1
*/
public reset(bgColor:any=""):void{
let s=this;
if(bgColor!=""){
s.bgColor=bgColor;
public reset(bgColor: any = ""): void {
let s = this;
if (bgColor != "") {
s.bgColor = bgColor;
}
if (s.bgColor != "") {
s.context.fillStyle = s.bgColor;
s.context.fillRect(0, 0, s.bitmapData.width, s.bitmapData.height);
} else {
s.context.clearRect(0, 0, s.bitmapData.width, s.bitmapData.height);
}
s.currentStepId=0;
s.totalStepList=[];
s.currentStepId = 0;
s.totalStepList = [];
}

/**
* 撤销步骤
* @method cancel
* @param {number} step 撤销几步 0则全部撤销,等同于reset
* @public
* @since 1.1.1
*/
public cancel(step:number=0):boolean{
let s=this;
if(step==0){
public cancel(step: number = 0): boolean {
let s = this;
if (step == 0) {
s.reset();
}else{
if(s.currentStepId-step>=0){
s.currentStepId-=step;
s.totalStepList.splice(s.currentStepId,step);
} else {
if (s.currentStepId - step >= 0) {
s.currentStepId -= step;
s.totalStepList.splice(s.currentStepId, step);
if (s.bgColor != "") {
s.context.fillStyle = s.bgColor;
s.context.fillRect(0, 0, s.bitmapData.width, s.bitmapData.height);
} else {
s.context.clearRect(0, 0, s.bitmapData.width, s.bitmapData.height);
}
let len:number=s.totalStepList.length;
for(let i=0;i<len;i++){
let len: number = s.totalStepList.length;
for (let i = 0; i < len; i++) {
var ctx = s.context;
ctx.beginPath();
ctx.strokeStyle = s.totalStepList[i].c;
ctx.lineWidth = s.totalStepList[i].r;
ctx.moveTo(s.totalStepList[i].sx, s.totalStepList[i].sy);
let ps:any=s.totalStepList.ps;
let pLen:number=ps.length;
for(let m=0;m<pLen;m+=2){
ctx.lineTo(ps[m], ps[m+1]);
let ps: any = s.totalStepList[i].ps;
let pLen: number = ps.length;
for (let m = 0; m < pLen; m += 2) {
ctx.lineTo(ps[m], ps[m + 1]);
ctx.stroke();
}
}
}else{
} else {
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion annie/ui/FlipBook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ namespace annieUI {
if((s.timerArg0<3&&s.currPage>0)||(s.timerArg0>2&&s.currPage<=s.totalPage-2)){
s.state = "start";
s.flushPage();
// e.updateAfterEvent();
e.updateAfterEvent();
s.dispatchEvent("onFlipStart");
}
}
Expand Down
Loading

0 comments on commit 6c1e2f0

Please sign in to comment.