⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 paint.js

📁 TurboCWCShop v1.6.7 is make in the Utility-LAYer Framework.
💻 JS
📖 第 1 页 / 共 2 页
字号:
				{
					var numLen=(numWidth+numHeight)/2;
					numWidth=numLen;
					numHeight=numLen;
				}	
				objActive.style.width=numWidth;
				objActive.style.height=numHeight;
				break;
			case "line":
				var numWidth=numX-numBaseX;
				var numHeight=numY-numBaseY;
				if(objEvent.shiftKey)
				{
					if(numHeight!=0)
					{
						var numRate=Math.abs(numWidth/numHeight);
						if(numRate<0.333)numWidth=0;
						else if(numRate>3)numHeight=0;
						else
						{
							var numLen=(Math.abs(numWidth)+Math.abs(numHeight))/2;
							if(numWidth<0)numWidth=-numLen;
							else numWidth=numLen;
							if(numHeight<0)numHeight=-numLen;
							else numHeight=numLen;
						}
					}
				}
				if(objPaint.IEVersion<5.5)
				{
					numWidth=Math.abs(numWidth);
					numHeight=Math.abs(numHeight);
				}
				objActive.to=new Array(numWidth+'px',numHeight+'px').join();
				break;
			case "polyline":
				if(objEvent.shiftKey)
				{
					var numLen=arrBasePos.length;
					var numBeforeX=parseFloat(arrBasePos[numLen-2]);
					var numBeforeY=parseFloat(arrBasePos[numLen-1]);
					var numWidth=numX-numBeforeX;
					var numHeight=numY-numBeforeY;
					if(numHeight!=0)
					{
						var numRate=Math.abs(numWidth/numHeight);
						if(numRate<0.333)numWidth=0;
						else if(numRate>3)numHeight=0;
						else
						{
							var numLen=(Math.abs(numWidth)+Math.abs(numHeight))/2;
							if(numWidth<0)numWidth=-numLen;
							else numWidth=numLen;
							if(numHeight<0)numHeight=-numLen;
							else numHeight=numLen;
						}
						numX=numBeforeX+numWidth;
						numY=numBeforeY+numHeight;
					}
				}
				var arrNew=arrBasePos.concat(numX+'px',numY+'px');
				objActive.points.value=arrNew.join();
				if(objEvent.ctrlKey||objPaint.Beeline==1||objPaint.Polygon==1){
					objPaint.SavedPos[0]=numX;
					objPaint.SavedPos[1]=numY;
				}else{
					arrBasePos=arrNew;
					objPaint.BasePos=arrBasePos;
				}
				break;
			case "image":
				var numWidth=Math.abs(numX-numBaseX);
				var numHeight=Math.abs(numY-numBaseY);
				objActive.style.width=numWidth;
				objActive.style.height=numHeight;
				break;
			case "arc":
				var numWidth=Math.abs(numX-numBaseX);
				var numHeight=Math.abs(numY-numBaseY);
				objActive.style.width=numWidth;
				objActive.style.height=numHeight;
				break;
			default:
				return false;
		}
	}
	else if(objEvent.button==1)ETSOOPaint_OnMouseDown(objEvent);
}
//定义的画图工具
ETSOOPaint.AllTools={
	MOVE: 'paint/move.gif',
	OVAL: 'paint/oval.gif',
	RECT: 'paint/rect.gif',
	ROUNDRECT: 'paint/roundrect.gif',
	LINE: 'paint/line.gif',
	POLYLINE: 'paint/polyline.gif',
	IMAGE: 'paint/image.gif',
	ARC: 'paint/arc.gif',
	UNDO: 'undo.gif',
	UNDODISABLED: 'undodisabled.gif',
	REDO: 'redo.gif',
	REDODISABLED: 'redodisabled.gif'
}
//画图对象
ETSOOPaint.ActivePaint=null;
//获得坐标
ETSOOPaint.GetPos=function(objEvent){
	var arrPos=ETSOOPaint.ActivePaint.Pos;
	var numX=objEvent.clientX+document.body.scrollLeft;
	if(numX<arrPos[0])numX=arrPos[0];
	if(numX>arrPos[0]+arrPos[2])numX=arrPos[0]+arrPos[2];
	if(numY<arrPos[1])numY=arrPos[1];
	if(numY>arrPos[1]+arrPos[3])numY=arrPos[1]+arrPos[3];
	var numY=objEvent.clientY+document.body.scrollTop;
	return [numX,numY];
}
//属性设置
ETSOOPaint.prototype.DrawColor="#000000";
ETSOOPaint.prototype.DrawSize=1;
ETSOOPaint.prototype.FillColor="#FFFFFF";
ETSOOPaint.prototype.Opacity=1;
ETSOOPaint.prototype.Circle=0;
ETSOOPaint.prototype.Square=0;
ETSOOPaint.prototype.Beeline=0;
//画图区域
ETSOOPaint.prototype.PaintArea=null;
//图片路径
ETSOOPaint.prototype.Path="/ETSOOBase/EOEditor/Images/";
//编辑坐标
ETSOOPaint.prototype.Pos=[];
//保存的坐标
ETSOOPaint.prototype.SavedPos=[];
//原始坐标
ETSOOPaint.prototype.BasePos=[];
//现在的坐标
ETSOOPaint.prototype.CurrentPos=[];
//绘图类型
ETSOOPaint.prototype.Type=null;
//目前活动对象
ETSOOPaint.prototype.ActiveTarget=null;
//Flag值
ETSOOPaint.prototype.Flag=0;
//IE版本,IE5处理单位不为px,为pt
ETSOOPaint.prototype.IEVersion=ETSOOGetBrowserVersion();
//起用的工具数组,ID,Title
ETSOOPaint.prototype.Tools=[];
//工具条背景颜色
ETSOOPaint.prototype.BgColor="buttonface";
//创建画图区域
ETSOOPaint.prototype.Init=function(objToolArea){
	var strPath=this.Path;
	var strBgColor=this.BgColor;
	var arrAllTools=ETSOOPaint.AllTools;
	var arrTools=this.Tools;
	var numLen=arrTools.length;
	var strTools='<table cellspacing="0" cellpadding="0" style="border-collapse: collapse" bgcolor="'+strBgColor+'"><tr>';
	for(var numI=0;numI<numLen;numI+=2){
		var strId=arrTools[numI];
		var strTitle=arrTools[numI+1];
		var strSrc=strPath+arrAllTools[strId];
		strTools+='<td align="center" style="padding:2px">';
		strTools+='<img src="'+strSrc+'" id="'+strId+'" style="border:1px solid '+strBgColor+'" title="'+strTitle+'"';
		strTools+=' onmouseover="ETSOOPaint.ToolMouseOver(this)" onmouseout="ETSOOPaint.ToolMouseOut(this)" onclick="ETSOOPaint.ToolMouseClick(this)" onmouseup="ETSOOPaint.ToolMouseOver(this)">';
		strTools+='</td>';
	}
	strTools+='</tr></table>';
	objToolArea.innerHTML=strTools;
	ETSOOPaint.ActivePaint=this;
	ETSOOPaint.ActiveTool("MOVE");
	ETSOOPaint.ActiveTool("REDO",-1);
	ETSOOPaint.ActiveTool("UNDO",-1);
}
//工具条鼠标经过
ETSOOPaint.ToolMouseOver=function(objE){
	var strClassName=objE.className;
	if(strClassName!="Active"&&strClassName!="Disabled"){
		with(objE.style){
			borderLeft="1px solid buttonhighlight";
			borderTop="1px solid buttonhighlight";
			borderRight="1px solid buttonshadow";
			borderBottom="1px solid buttonshadow";
			backgroundColor="";
		}
	}
}
//鼠标移出
ETSOOPaint.ToolMouseOut=function(objE){
	var strClassName=objE.className;
	if(strClassName!="Active"&&strClassName!="Disabled"){
		var strBgColor=ETSOOPaint.ActivePaint.BgColor;
		with(objE.style){
			border="1px solid "+strBgColor;
			backgroundColor="";
		}
	}
}
//鼠标按下
ETSOOPaint.ToolMouseClick=function(objE){
	var strClassName=objE.className;
	if(strClassName!="Active"&&strClassName!="Disabled"){
		with(objE.style){
			borderLeft="1px solid buttonshadow";
			borderTop="1px solid buttonshadow";
			borderRight="1px solid buttonhighlight";
			borderBottom="1px solid buttonhighlight";
			backgroundColor="#FFFFFF";
		}
		var objPaint=ETSOOPaint.ActivePaint;
		var blnNoActive=false;
		var strId=objE.id;
		if(strId=="UNDO"||strId=="REDO")blnNoActive=true;
		if(!blnNoActive){
			var strBaseType=objPaint.Type;
			if(strBaseType){
				var objBase=document.getElementById(strBaseType);
				with(objBase){
					className="";
					ETSOOPaint.ToolMouseOut(objBase);
				}
			}
			objPaint.Type=strId;
			objE.className="Active";
			ETSOOPaint.DrawClear();
		}else{
			ETSOOPaint.ToolMouseOut(objE);
			ETSOOPaint.DoAction(strId);
		}
	}
}
//激活对象
ETSOOPaint.ActiveTool=function(strId,numType){
	if(numType==null)numType=1;
	var objT=document.getElementById(strId);
	if(objT){
		if(numType==1)this.ToolMouseClick(objT);
		else{
			this.ToolMouseOut(objT);
			var strSrc=objT.src;
			if(numType==-1){
				if(strSrc.indexof("disabled.gif")==-1)strSrc=strSrc.replace(".gif","disabled.gif");
			}else if(numType==0){
				if(strSrc.indexof("disabled.gif")!=-1)strSrc=strSrc.replace("disabled.gif",".gif");
			}
			objT.src=strSrc;
		}
	}
}
//快捷键
ETSOOPaint.QuickKey=function(objEvent){
	if(objEvent==null)objEvent=window.event;
	var numKeyCode=objEvent.keyCode;
	var objE=objEvent.srcElement;
	var objPaint=ETSOOPaint.ActivePaint;
	var objActiveTarget=objPaint.ActiveTarget;
	if(objActiveTarget){
		var numD=4;
		var numLeft=objActiveTarget.style.pixelLeft;
		var numTop=objActiveTarget.style.pixelTop;
		if(objEvent.shiftKey)numD=1;
		if(!objEvent.ctrlKey&&!objEvent.altKey&&!objEvent.shiftKey){
			var blnSet=true;
			switch(numKeyCode){
				case 27: //ESC
					objActiveTarget.removeNode(true);
					break;
				case 37:
					objActiveTarget.style.pixelLeft=numLeft-numD;
					break;
				case 38:
					objActiveTarget.style.pixelTop=numTop-numD;
					break;
				case 39:
					objActiveTarget.style.pixelLeft=numLeft+numD;
					break;
				case 40:
					objActiveTarget.style.pixelTop=numTop+numD;
					break;
				case 46: //Delete
					objActiveTarget.removeNode(true);
					break;
				default:
					blnSet=false;
			}
			if(blnSet)objPaint.History.Add();
		}
	}
	if(objE.type!="text"&&objE.nodeName!="TEXTAREA"){
		if(!objEvent.shiftKey&&!objEvent.ctrlKey&&!objEvent.altKey){
			switch(numKeyCode){
				case 86:
					ETSOOPaint.ActiveTool("MOVE");
					break;
				case 79:
					ETSOOPaint.ActiveTool("OVAL");
					break;
				case 82:
					ETSOOPaint.ActiveTool("RECT");
					break;
				case 78:
					ETSOOPaint.ActiveTool("ROUNDRECT");
					break;
				case 76:
					ETSOOPaint.ActiveTool("LINE");
					break;
				case 80:
					ETSOOPaint.ActiveTool("POLYLINE");
					break;
				case 73:
					ETSOOPaint.ActiveTool("IMAGE");
					break;
				case 65:
					ETSOOPaint.ActiveTool("ARC");
					break;
			}
		}
		else if(!objEvent.shiftKey&&!objEvent.altKey&&objEvent.ctrlKey){
			switch(numKeyCode){
				case 90:
					ETSOOPaint.DoAction("UNDO");
					break;
				case 89:
					ETSOOPaint.DoAction("REDO");
					break;
			}
		}
	}
}
//保存历史纪录
ETSOOPaint.History=function(objField){
	this.Field=objField;
	this.Data=[];
	this.Position=0;
	this.Add=function(){
		var objField=this.Field;
		var numPos=this.Position;
		var numLen=this.Data.length;
		
		var strContent=objField.innerHTML;
		if(this.Data[numPos]!=strContent){
			numPos++;
			for(var numI=0;numI<numLen-numPos;numI++){
				this.Data.pop();
			}
			this.Data[numPos]=strContent;
			numLen=numPos+1;
			this.Position=numPos;
		}
		ETSOOPaint._SetRedoUndo(numLen,numPos);
	}
	this.Go=function(numStep){
		var objField=this.Field;
		var blnValid=false;
		var numLen=this.Data.length;
		var numPos=this.Position;
		numPos+=numStep;
		if(numStep>0){
			if(numPos<=numLen-1)blnValid=true;
		}else{
			if(numPos>=0)blnValid=true;
		}
		if(blnValid){
			this.Position=numPos;
			objField.innerHTML=this.Data[this.Position];
			
			ETSOOPaint._SetRedoUndo(numLen,numPos);
		}
	}
}
//设置撤销重做状态
ETSOOPaint._SetRedoUndo=function(numLen,numPos){
	var numType=-1;
	if(numLen>1&&numPos>0)numType=0;
	ETSOOPaint.ActiveTool("UNDO",numType);
	var numType=-1;
	if(numPos<numLen-1)numType=0;	
	ETSOOPaint.ActiveTool("REDO",numType);
}
//处理命令
ETSOOPaint.DoAction=function(strId){
	var objPaint=ETSOOPaint.ActivePaint;
	switch(strId){
		case "REDO":
			objPaint.History.Go(1);
			break;
		case "UNDO":
			objPaint.History.Go(-1);
			break;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -