在页面上动态定义节点(html控件)、拖动、以及节点连线

◆页面(draw3.aspx)

1@ Page language="c#" Codebehind="draw3.aspx.cs" AutoEventWireup="false" Inherits="CTest.draw3" 
  1<html>
  2<head>
  3<title>draw</title>
  4<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR"/>
  5<meta content="C#" name="CODE_LANGUAGE"/>
  6<meta content="JavaScript" name="vs_defaultClientScript"/>
  7<meta content=" http://schemas.microsoft.com/intellisense/ie5 " name="vs_targetSchema"/>
  8<script language="javascript" src="jsgraphics.js" type="text/javascript"></script>
  9</head>
 10<body ms_positioning="GridLayout">
 11<form id="Form1" method="post" runat="server">
 12<asp:datalist id="DataList1" runat="server" style="Z-INDEX: 101; LEFT: 16px; POSITION: absolute; TOP: 392px" width="80%">
 13<itemtemplate>
 14<asp:textbox id="TextSelItem" runat="server" width="70%"></asp:textbox><div id="SelItemCoordinate" runat="server"><font>坐标:(</font>
 15<asp:textbox id="TextSelItemX" runat="server" width="30px">0</asp:textbox><font>,</font>
 16<asp:textbox id="TextSelItemY" runat="server" width="30px">0</asp:textbox><font>)</font></div>
 17</itemtemplate>
 18</asp:datalist>
 19<div id="parentdiv" ms_positioning="GridLayout" nowrap="" runat="server" style="Z-INDEX: 102; LEFT: 16px; WIDTH: 640px; POSITION: absolute; TOP: 40px; HEIGHT: 300px; BACKGROUND-COLOR: aliceblue"></div>
 20<asp:textbox id="TextOper" runat="server" style="Z-INDEX: 103; LEFT: 16px; POSITION: absolute; TOP: 8px" width="24px">1</asp:textbox>  <asp:radiobuttonlist autopostback="True" id="RadioButtonList1" repeatdirection="Horizontal" runat="server" style="Z-INDEX: 104; LEFT: 16px; POSITION: absolute; TOP: 352px" width="448px">
 21<asp:listitem selected="True" value="0">定义节点</asp:listitem>
 22<asp:listitem value="1">节点位置排放</asp:listitem>
 23<asp:listitem value="2">节点间连线</asp:listitem>
 24</asp:radiobuttonlist><asp:button id="Button2" runat="server" style="Z-INDEX: 105; LEFT: 544px; POSITION: absolute; TOP: 8px" text="JustRefresh"></asp:button>
 25<asp:textbox id="TextAnswer" runat="server" style="Z-INDEX: 106; LEFT: 48px; POSITION: absolute; TOP: 8px" width="480px"></asp:textbox><input id="hidTag" name="Hidden1" runat="server" style="Z-INDEX: 107; LEFT: 480px; POSITION: absolute; TOP: 352px" type="hidden"/>
 26<asp:textbox id="TextBox1" runat="server" style="Z-INDEX: 108; LEFT: 700px; POSITION: absolute; TOP: 104px"></asp:textbox></form>
 27<script>   
 28//被拖动的对象   
 29var Obj=''   
 30  
 31var startObj="";   
 32  
 33//被拖动对象的最初坐标位置   
 34var pLeft,pTop;   
 35  
 36//起点坐标,终点坐标   
 37var startLeft,startTop,endLeft,EndTop;   
 38  
 39var jg = new jsGraphics("parentdiv");   
 40  
 41var clientWidth = document.all("parentdiv").clientWidth;   
 42var clientHeight = document.all("parentdiv").clientHeight;   
 43var clientLeft = document.all("parentdiv").style.pixelLeft;   
 44var clientTop = document.all("parentdiv").style.pixelTop;   
 45  
 46//document.all("TextBox1").value = clientWidth + "," + clientHeight + "," + clientLeft + "," + clientTop;   
 47//按下鼠标时   
 48function MDown(Object)   
 49{   
 50Obj=Object.id   
 51//捕获对象   
 52document.all(Obj).setCapture();   
 53  
 54//获得对象的最初坐标位置   
 55pLeft = document.all(Obj).style.pixelLeft;   
 56pTop = document.all(Obj).style.pixelTop;   
 57  
 58if (document.all("TextOper").value == 2)   
 59{   
 60startLeft = document.all(Obj).style.pixelLeft + 10;   
 61startTop = document.all(Obj).style.pixelTop + 10;   
 62document.all("TextOper").value = 3;   
 63startObj = Obj;   
 64}   
 65else if (document.all("TextOper").value == 3)   
 66{   
 67if(Obj != startObj)   
 68{   
 69endLeft = document.all(Obj).style.pixelLeft + 10;   
 70endTop = document.all(Obj).style.pixelTop + 10;   
 71document.all("TextOper").value = 2;   
 72  
 73jg.setColor("blue");   
 74jg.drawLine(startLeft,startTop,endLeft,endTop);   
 75jg.paint("parentdiv");   
 76document.all("TextAnswer").value = document.all("TextAnswer").value + startObj + "--" + Obj + " | ";   
 77startObj = "";   
 78}   
 79else   
 80{   
 81document.all("TextOper").value = 3;   
 82}   
 83}   
 84  
 85pX=event.x-document.all(Obj).style.pixelLeft;   
 86pY=event.y-document.all(Obj).style.pixelTop;   
 87  
 88}   
 89  
 90function MMove()   
 91{   
 92if (event.button == 1 && document.all("hidTag").value != "2")   
 93{   
 94//对象的移动位置   
 95if(Obj!='')   
 96{   
 97if ((event.x)< (clientWidth + clientLeft - 20) && (event.x) > (clientLeft + 20))   
 98{   
 99document.all(Obj).style.left=event.x-pX;   
100}   
101  
102if ((event.y) < (clientHeight + clientTop - 10) && (event.y) > (clientTop + 20))   
103{   
104document.all(Obj).style.top=event.y-pY;   
105}   
106}   
107}   
108  
109} 
110
111function MUp()   
112{   
113if(Obj!='')   
114{   
115var index = Obj.replace("MoveDiv","");   
116var txtXid = "DataList1__ctl" + index + "_TextSelItemX";   
117var txtYid = "DataList1__ctl" + index + "_TextSelItemY";   
118document.all[txtXid].value = document.all(Obj).style.pixelLeft;   
119document.all[txtYid].value = document.all(Obj).style.pixelTop;   
120//释放对象   
121  
122document.all(Obj).releaseCapture();   
123if (document.all("TextOper").value != 1)   
124{   
125//还原到最初按下鼠标时的位置   
126document.all(Obj).style.pixelLeft = pLeft;   
127document.all(Obj).style.pixelTop = pTop;   
128}   
129Obj='';   
130} 
131
132}   
133  
134document.onmouseup=MUp;   
135document.onmousemove=MMove;   
136  
137function CancelContextMenu()   
138{   
139event.cancelBubble = true;   
140event.returnValue = false;   
141}   
142document.oncontextmenu = CancelContextMenu;   
143</script>
144</body>
145</html>

◆代码文件(draw3.aspx.cs)
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace CTest
{
///

1<summary>   
2/// draw 的摘要说明。   
3/// </summary>

public class draw3 : System.Web.UI.Page
{
protected System.Web.UI.HtmlControls.HtmlGenericControl parentdiv;
protected System.Web.UI.WebControls.RadioButtonList RadioButtonList1;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.TextBox TextOper;
protected System.Web.UI.WebControls.TextBox TextAnswer;
protected System.Web.UI.HtmlControls.HtmlInputHidden hidTag;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.DataList DataList1;

private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if (!IsPostBack)
{
this.AddDiv(6);

}
}

#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);

}

///

1<summary>   
2/// 设计器支持所需的方法 - 不要使用代码编辑器修改   
3/// 此方法的内容。   
4/// </summary>

private void InitializeComponent()
{
this.DataList1.ItemDataBound += new System.Web.UI.WebControls.DataListItemEventHandler(this.DataList1_ItemDataBound);
this.RadioButtonList1.SelectedIndexChanged += new System.EventHandler(this.RadioButtonList1_SelectedIndexChanged);
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void AddDiv(int n)
{
string [] strAry = new string[n];
DataList1.DataSource = strAry;
DataList1.DataBind();
}
private void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
TextBox txt = new TextBox();
HtmlGenericControl div = new HtmlGenericControl();

txt=(TextBox)e.Item.Controls[2].Controls[1];
txt.Text = "10";

txt=(TextBox)e.Item.Controls[2].Controls[3];
txt.Text = (10 + 30*e.Item.ItemIndex).ToString();

div = (HtmlGenericControl)e.Item.Controls[2];
div.Style.Add("display","none");
}

private void RadioButtonList1_SelectedIndexChanged(object sender, System.EventArgs e)
{

switch(RadioButtonList1.SelectedIndex)
{
case 0:
this.DataList1.Style.Add("display","inline");
this.TextOper.Text = "1";
break;
case 1:
this.DataList1.Style.Add("display","inline");
this.TextOper.Text = "1";
this.hidTag.Value = "1";
break;
case 2:
this.DataList1.Style.Add("display","none");
this.TextOper.Text = "2";
this.hidTag.Value = "2";
break;
}
showSelItems();
}

private void showSelItems()
{
string html = "";
string txtValue ="";
string txtX = "";
string txtY = "";
TextBox txt = new TextBox();
HtmlGenericControl div = new HtmlGenericControl();

for(int i=0;i

  1<datalist1.items.count;i++) if(txtvalue.length="" txt="(TextBox)DataList1.Items[i].Controls[1];" txtvalue="txt.Text.TrimStart().TrimEnd();" txtx="txt.Text.Trim();" txty="txt.Text.Trim();" {="">0)   
  2html += "<div id='MoveDiv"+ i.ToString() +"' ms_positioning="FlowLayout" onmousedown="MDown(this)" style='Z-INDEX: 105; LEFT: " + txtX + "px; CURSOR: hand; POSITION: absolute; TOP: "+ txtY +"px; BORDER-RIGHT: darkgreen 3px double; BORDER-TOP: darkgreen 3px double; BORDER-LEFT: darkgreen 3px double; BORDER-BOTTOM: darkgreen 3px double; BACKGROUND-COLOR: FloralWhite'> "+txtValue+" </div>";   
  3else if(this.RadioButtonList1.SelectedIndex&gt;0)   
  4txt.Visible = false;   
  5else   
  6txt.Visible = true;   
  7  
  8div = (HtmlGenericControl)DataList1.Items[i].Controls[2];   
  9if(this.RadioButtonList1.SelectedIndex&gt;0 &amp;&amp; txtValue.Length&gt;0)   
 10div.Style.Add("display","inline");   
 11else   
 12div.Style.Add("display","none");   
 13}   
 14this.parentdiv.InnerHtml =html;   
 15} 
 16
 17}   
 18}   
 19  
 20********************************************************************************   
 21◆脚本文件(jsGraphics.js)   
 22  
 23var jg_ihtm, jg_ie, jg_fast, jg_dom, jg_moz,   
 24jg_n4 = (document.layers &amp;&amp; typeof document.classes != "undefined"); 
 25
 26  
 27function chkDHTM(x, i)   
 28{   
 29x = document.body || null;   
 30jg_ie = x &amp;&amp; typeof x.insertAdjacentHTML != "undefined";   
 31jg_dom = (x &amp;&amp; !jg_ie &amp;&amp;   
 32typeof x.appendChild != "undefined" &amp;&amp;   
 33typeof document.createRange != "undefined" &amp;&amp;   
 34typeof (i = document.createRange()).setStartBefore != "undefined" &amp;&amp;   
 35typeof i.createContextualFragment != "undefined");   
 36jg_ihtm = !jg_ie &amp;&amp; !jg_dom &amp;&amp; x &amp;&amp; typeof x.innerHTML != "undefined";   
 37jg_fast = jg_ie &amp;&amp; document.all &amp;&amp; !window.opera;   
 38jg_moz = jg_dom &amp;&amp; typeof x.style.MozOpacity != "undefined";   
 39} 
 40
 41  
 42function pntDoc()   
 43{   
 44this.wnd.document.write(jg_fast? this.htmRpc() : this.htm);   
 45this.htm = '';   
 46} 
 47
 48  
 49function pntCnvDom()   
 50{   
 51var x = document.createRange();   
 52x.setStartBefore(this.cnv);   
 53x = x.createContextualFragment(jg_fast? this.htmRpc() : this.htm);   
 54this.cnv.appendChild(x);   
 55this.htm = '';   
 56} 
 57
 58  
 59function pntCnvIe()   
 60{   
 61this.cnv.insertAdjacentHTML("BeforeEnd", jg_fast? this.htmRpc() : this.htm);   
 62this.htm = '';   
 63} 
 64
 65  
 66function pntCnvIhtm()   
 67{   
 68this.cnv.innerHTML += this.htm;   
 69this.htm = '';   
 70} 
 71
 72  
 73function pntCnv()   
 74{   
 75this.htm = '';   
 76} 
 77
 78  
 79function mkDiv(x, y, w, h)   
 80{   
 81this.htm += '<div style="position:absolute;'+   
 82'left:' + x + 'px;'+   
 83'top:' + y + 'px;'+   
 84'width:' + w + 'px;'+   
 85'height:' + h + 'px;'+   
 86'clip:rect(0,'+w+'px,'+h+'px,0);'+   
 87'background-color:' + this.color +   
 88(!jg_moz? ';overflow:hidden' : '')+   
 89';">&lt;\/div&gt;';   
 90} 
 91
 92  
 93function mkDivIe(x, y, w, h)   
 94{   
 95this.htm += '%%'+this.color+';'+x+';'+y+';'+w+';'+h+';';   
 96} 
 97
 98  
 99function mkDivPrt(x, y, w, h)   
100{   
101this.htm += '<div style="position:absolute;'+   
102'border-left:' + w + 'px solid ' + this.color + ';'+   
103'left:' + x + 'px;'+   
104'top:' + y + 'px;'+   
105'width:0px;'+   
106'height:' + h + 'px;'+   
107'clip:rect(0,'+w+'px,'+h+'px,0);'+   
108'background-color:' + this.color +   
109(!jg_moz? ';overflow:hidden' : '')+   
110';">&lt;\/div&gt;';   
111} 
112
113  
114function mkLyr(x, y, w, h)   
115{   
116this.htm += '<layer '+="" 'bgcolor="' + this.color + '" 'height="' + h + '" 'left="' + x + '" 'top="' + y + '" 'width="' + w + '">&lt;\/layer&gt;\n';   
117} 
118
119  
120var regex = /%%([^;]+);([^;]+);([^;]+);([^;]+);([^;]+);/g;   
121function htmRpc()   
122{   
123return this.htm.replace(   
124regex,   
125'<div style="overflow:hidden;position:absolute;background-color:'+   
126'$1;left:$2;top:$3;width:$4;height:$5"></div>\n');   
127} 
128
129  
130function htmPrtRpc()   
131{   
132return this.htm.replace(   
133regex,   
134'<div style="overflow:hidden;position:absolute;background-color:'+   
135'$1;left:$2;top:$3;width:$4;height:$5;border-left:$4px solid $1"></div>\n');   
136} 
137
138  
139function mkLin(x1, y1, x2, y2)   
140{   
141if (x1 &gt; x2)   
142{   
143var _x2 = x2;   
144var _y2 = y2;   
145x2 = x1;   
146y2 = y1;   
147x1 = _x2;   
148y1 = _y2;   
149}   
150var dx = x2-x1, dy = Math.abs(y2-y1),   
151x = x1, y = y1,   
152yIncr = (y1 &gt; y2)? -1 : 1; 
153
154if (dx &gt;= dy)   
155{   
156var pr = dy&lt;&lt;1,   
157pru = pr - (dx&lt;&lt;1),   
158p = pr-dx,   
159ox = x;   
160while ((dx--) &gt; 0)   
161{   
162++x;   
163if (p &gt; 0)   
164{   
165this.mkDiv(ox, y, x-ox, 1);   
166y += yIncr;   
167p += pru;   
168ox = x;   
169}   
170else p += pr;   
171}   
172this.mkDiv(ox, y, x2-ox+1, 1);   
173} 
174
175else   
176{   
177var pr = dx&lt;&lt;1,   
178pru = pr - (dy&lt;&lt;1),   
179p = pr-dy,   
180oy = y;   
181if (y2 &lt;= y1)   
182{   
183while ((dy--) &gt; 0)   
184{   
185if (p &gt; 0)   
186{   
187this.mkDiv(x++, y, 1, oy-y+1);   
188y += yIncr;   
189p += pru;   
190oy = y;   
191}   
192else   
193{   
194y += yIncr;   
195p += pr;   
196}   
197}   
198this.mkDiv(x2, y2, 1, oy-y2+1);   
199}   
200else   
201{   
202while ((dy--) &gt; 0)   
203{   
204y += yIncr;   
205if (p &gt; 0)   
206{   
207this.mkDiv(x++, oy, 1, y-oy);   
208p += pru;   
209oy = y;   
210}   
211else p += pr;   
212}   
213this.mkDiv(x2, oy, 1, y2-oy+1);   
214}   
215}   
216} 
217
218  
219function mkLin2D(x1, y1, x2, y2)   
220{   
221if (x1 &gt; x2)   
222{   
223var _x2 = x2;   
224var _y2 = y2;   
225x2 = x1;   
226y2 = y1;   
227x1 = _x2;   
228y1 = _y2;   
229}   
230var dx = x2-x1, dy = Math.abs(y2-y1),   
231x = x1, y = y1,   
232yIncr = (y1 &gt; y2)? -1 : 1; 
233
234var s = this.stroke;   
235if (dx &gt;= dy)   
236{   
237if (s-3 &gt; 0)   
238{   
239var _s = (s*dx*Math.sqrt(1+dy*dy/(dx*dx))-dx-(s&gt;&gt;1)*dy) / dx;   
240_s = (!(s-4)? Math.ceil(_s) : Math.round(_s)) + 1;   
241}   
242else var _s = s;   
243var ad = Math.ceil(s/2); 
244
245var pr = dy&lt;&lt;1,   
246pru = pr - (dx&lt;&lt;1),   
247p = pr-dx,   
248ox = x;   
249while ((dx--) &gt; 0)   
250{   
251++x;   
252if (p &gt; 0)   
253{   
254this.mkDiv(ox, y, x-ox+ad, _s);   
255y += yIncr;   
256p += pru;   
257ox = x;   
258}   
259else p += pr;   
260}   
261this.mkDiv(ox, y, x2-ox+ad+1, _s);   
262} 
263
264else   
265{   
266if (s-3 &gt; 0)   
267{   
268var _s = (s*dy*Math.sqrt(1+dx*dx/(dy*dy))-(s&gt;&gt;1)*dx-dy) / dy;   
269_s = (!(s-4)? Math.ceil(_s) : Math.round(_s)) + 1;   
270}   
271else var _s = s;   
272var ad = Math.round(s/2); 
273
274var pr = dx&lt;&lt;1,   
275pru = pr - (dy&lt;&lt;1),   
276p = pr-dy,   
277oy = y;   
278if (y2 &lt;= y1)   
279{   
280++ad;   
281while ((dy--) &gt; 0)   
282{   
283if (p &gt; 0)   
284{   
285this.mkDiv(x++, y, _s, oy-y+ad);   
286y += yIncr;   
287p += pru;   
288oy = y;   
289}   
290else   
291{   
292y += yIncr;   
293p += pr;   
294}   
295}   
296this.mkDiv(x2, y2, _s, oy-y2+ad);   
297}   
298else   
299{   
300while ((dy--) &gt; 0)   
301{   
302y += yIncr;   
303if (p &gt; 0)   
304{   
305this.mkDiv(x++, oy, _s, y-oy+ad);   
306p += pru;   
307oy = y;   
308}   
309else p += pr;   
310}   
311this.mkDiv(x2, oy, _s, y2-oy+ad+1);   
312}   
313}   
314} 
315
316  
317function mkLinDott(x1, y1, x2, y2)   
318{   
319if (x1 &gt; x2)   
320{   
321var _x2 = x2;   
322var _y2 = y2;   
323x2 = x1;   
324y2 = y1;   
325x1 = _x2;   
326y1 = _y2;   
327}   
328var dx = x2-x1, dy = Math.abs(y2-y1),   
329x = x1, y = y1,   
330yIncr = (y1 &gt; y2)? -1 : 1,   
331drw = true;   
332if (dx &gt;= dy)   
333{   
334var pr = dy&lt;&lt;1,   
335pru = pr - (dx&lt;&lt;1),   
336p = pr-dx;   
337while ((dx--) &gt; 0)   
338{   
339if (drw) this.mkDiv(x, y, 1, 1);   
340drw = !drw;   
341if (p &gt; 0)   
342{   
343y += yIncr;   
344p += pru;   
345}   
346else p += pr;   
347++x;   
348}   
349if (drw) this.mkDiv(x, y, 1, 1);   
350} 
351
352else   
353{   
354var pr = dx&lt;&lt;1,   
355pru = pr - (dy&lt;&lt;1),   
356p = pr-dy;   
357while ((dy--) &gt; 0)   
358{   
359if (drw) this.mkDiv(x, y, 1, 1);   
360drw = !drw;   
361y += yIncr;   
362if (p &gt; 0)   
363{   
364++x;   
365p += pru;   
366}   
367else p += pr;   
368}   
369if (drw) this.mkDiv(x, y, 1, 1);   
370}   
371} 
372
373  
374function mkOv(left, top, width, height)   
375{   
376var a = width&gt;&gt;1, b = height&gt;&gt;1,   
377wod = width&amp;1, hod = (height&amp;1)+1,   
378cx = left+a, cy = top+b,   
379x = 0, y = b,   
380ox = 0, oy = b,   
381aa = (a*a)&lt;&lt;1, bb = (b*b)&lt;&lt;1,   
382st = (aa&gt;&gt;1)*(1-(b&lt;&lt;1)) + bb,   
383tt = (bb&gt;&gt;1) - aa*((b&lt;&lt;1)-1),   
384w, h;   
385while (y &gt; 0)   
386{   
387if (st &lt; 0)   
388{   
389st += bb*((x&lt;&lt;1)+3);   
390tt += (bb&lt;&lt;1)*(++x);   
391}   
392else if (tt &lt; 0)   
393{   
394st += bb*((x&lt;&lt;1)+3) - (aa&lt;&lt;1)*(y-1);   
395tt += (bb&lt;&lt;1)*(++x) - aa*(((y--)&lt;&lt;1)-3);   
396w = x-ox;   
397h = oy-y;   
398if (w&amp;2 &amp;&amp; h&amp;2)   
399{   
400this.mkOvQds(cx, cy, -x+2, ox+wod, -oy, oy-1+hod, 1, 1);   
401this.mkOvQds(cx, cy, -x+1, x-1+wod, -y-1, y+hod, 1, 1);   
402}   
403else this.mkOvQds(cx, cy, -x+1, ox+wod, -oy, oy-h+hod, w, h);   
404ox = x;   
405oy = y;   
406}   
407else   
408{   
409tt -= aa*((y&lt;&lt;1)-3);   
410st -= (aa&lt;&lt;1)*(--y);   
411}   
412}   
413this.mkDiv(cx-a, cy-oy, a-ox+1, (oy&lt;&lt;1)+hod);   
414this.mkDiv(cx+ox+wod, cy-oy, a-ox+1, (oy&lt;&lt;1)+hod);   
415} 
416
417  
418function mkOv2D(left, top, width, height)   
419{   
420var s = this.stroke;   
421width += s-1;   
422height += s-1;   
423var a = width&gt;&gt;1, b = height&gt;&gt;1,   
424wod = width&amp;1, hod = (height&amp;1)+1,   
425cx = left+a, cy = top+b,   
426x = 0, y = b,   
427aa = (a*a)&lt;&lt;1, bb = (b*b)&lt;&lt;1,   
428st = (aa&gt;&gt;1)*(1-(b&lt;&lt;1)) + bb,   
429tt = (bb&gt;&gt;1) - aa*((b&lt;&lt;1)-1); 
430
431if (s-4 &lt; 0 &amp;&amp; (!(s-2) || width-51 &gt; 0 &amp;&amp; height-51 &gt; 0))   
432{   
433var ox = 0, oy = b,   
434w, h,   
435pxl, pxr, pxt, pxb, pxw;   
436while (y &gt; 0)   
437{   
438if (st &lt; 0)   
439{   
440st += bb*((x&lt;&lt;1)+3);   
441tt += (bb&lt;&lt;1)*(++x);   
442}   
443else if (tt &lt; 0)   
444{   
445st += bb*((x&lt;&lt;1)+3) - (aa&lt;&lt;1)*(y-1);   
446tt += (bb&lt;&lt;1)*(++x) - aa*(((y--)&lt;&lt;1)-3);   
447w = x-ox;   
448h = oy-y; 
449
450if (w-1)   
451{   
452pxw = w+1+(s&amp;1);   
453h = s;   
454}   
455else if (h-1)   
456{   
457pxw = s;   
458h += 1+(s&amp;1);   
459}   
460else pxw = h = s;   
461this.mkOvQds(cx, cy, -x+1, ox-pxw+w+wod, -oy, -h+oy+hod, pxw, h);   
462ox = x;   
463oy = y;   
464}   
465else   
466{   
467tt -= aa*((y&lt;&lt;1)-3);   
468st -= (aa&lt;&lt;1)*(--y);   
469}   
470}   
471this.mkDiv(cx-a, cy-oy, s, (oy&lt;&lt;1)+hod);   
472this.mkDiv(cx+a+wod-s+1, cy-oy, s, (oy&lt;&lt;1)+hod);   
473} 
474
475else   
476{   
477var _a = (width-((s-1)&lt;&lt;1))&gt;&gt;1,   
478_b = (height-((s-1)&lt;&lt;1))&gt;&gt;1,   
479_x = 0, _y = _b,   
480_aa = (_a*_a)&lt;&lt;1, _bb = (_b*_b)&lt;&lt;1,   
481_st = (_aa&gt;&gt;1)*(1-(_b&lt;&lt;1)) + _bb,   
482_tt = (_bb&gt;&gt;1) - _aa*((_b&lt;&lt;1)-1), 
483
484pxl = new Array(),   
485pxt = new Array(),   
486_pxb = new Array();   
487pxl[0] = 0;   
488pxt[0] = b;   
489_pxb[0] = _b-1;   
490while (y &gt; 0)   
491{   
492if (st &lt; 0)   
493{   
494st += bb*((x&lt;&lt;1)+3);   
495tt += (bb&lt;&lt;1)*(++x);   
496pxl[pxl.length] = x;   
497pxt[pxt.length] = y;   
498}   
499else if (tt &lt; 0)   
500{   
501st += bb*((x&lt;&lt;1)+3) - (aa&lt;&lt;1)*(y-1);   
502tt += (bb&lt;&lt;1)*(++x) - aa*(((y--)&lt;&lt;1)-3);   
503pxl[pxl.length] = x;   
504pxt[pxt.length] = y;   
505}   
506else   
507{   
508tt -= aa*((y&lt;&lt;1)-3);   
509st -= (aa&lt;&lt;1)*(--y);   
510} 
511
512if (_y &gt; 0)   
513{   
514if (_st &lt; 0)   
515{   
516_st += _bb*((_x&lt;&lt;1)+3);   
517_tt += (_bb&lt;&lt;1)*(++_x);   
518_pxb[_pxb.length] = _y-1;   
519}   
520else if (_tt &lt; 0)   
521{   
522_st += _bb*((_x&lt;&lt;1)+3) - (_aa&lt;&lt;1)*(_y-1);   
523_tt += (_bb&lt;&lt;1)*(++_x) - _aa*(((_y--)&lt;&lt;1)-3);   
524_pxb[_pxb.length] = _y-1;   
525}   
526else   
527{   
528_tt -= _aa*((_y&lt;&lt;1)-3);   
529_st -= (_aa&lt;&lt;1)*(--_y);   
530_pxb[_pxb.length-1]--;   
531}   
532}   
533} 
534
535var ox = 0, oy = b,   
536_oy = _pxb[0],   
537l = pxl.length,   
538w, h;   
539for (var i = 0; i &lt; l; i++)   
540{   
541if (typeof _pxb[i] != "undefined")   
542{   
543if (_pxb[i] &lt; _oy || pxt[i] &lt; oy)   
544{   
545x = pxl[i];   
546this.mkOvQds(cx, cy, -x+1, ox+wod, -oy, _oy+hod, x-ox, oy-_oy);   
547ox = x;   
548oy = pxt[i];   
549_oy = _pxb[i];   
550}   
551}   
552else   
553{   
554x = pxl[i];   
555this.mkDiv(cx-x+1, cy-oy, 1, (oy&lt;&lt;1)+hod);   
556this.mkDiv(cx+ox+wod, cy-oy, 1, (oy&lt;&lt;1)+hod);   
557ox = x;   
558oy = pxt[i];   
559}   
560}   
561this.mkDiv(cx-a, cy-oy, 1, (oy&lt;&lt;1)+hod);   
562this.mkDiv(cx+ox+wod, cy-oy, 1, (oy&lt;&lt;1)+hod);   
563}   
564} 
565
566  
567function mkOvDott(left, top, width, height)   
568{   
569var a = width&gt;&gt;1, b = height&gt;&gt;1,   
570wod = width&amp;1, hod = height&amp;1,   
571cx = left+a, cy = top+b,   
572x = 0, y = b,   
573aa2 = (a*a)&lt;&lt;1, aa4 = aa2&lt;&lt;1, bb = (b*b)&lt;&lt;1,   
574st = (aa2&gt;&gt;1)*(1-(b&lt;&lt;1)) + bb,   
575tt = (bb&gt;&gt;1) - aa2*((b&lt;&lt;1)-1),   
576drw = true;   
577while (y &gt; 0)   
578{   
579if (st &lt; 0)   
580{   
581st += bb*((x&lt;&lt;1)+3);   
582tt += (bb&lt;&lt;1)*(++x);   
583}   
584else if (tt &lt; 0)   
585{   
586st += bb*((x&lt;&lt;1)+3) - aa4*(y-1);   
587tt += (bb&lt;&lt;1)*(++x) - aa2*(((y--)&lt;&lt;1)-3);   
588}   
589else   
590{   
591tt -= aa2*((y&lt;&lt;1)-3);   
592st -= aa4*(--y);   
593}   
594if (drw) this.mkOvQds(cx, cy, -x, x+wod, -y, y+hod, 1, 1);   
595drw = !drw;   
596}   
597} 
598
599  
600function mkRect(x, y, w, h)   
601{   
602var s = this.stroke;   
603this.mkDiv(x, y, w, s);   
604this.mkDiv(x+w, y, s, h);   
605this.mkDiv(x, y+h, w+s, s);   
606this.mkDiv(x, y+s, s, h-s);   
607} 
608
609  
610function mkRectDott(x, y, w, h)   
611{   
612this.drawLine(x, y, x+w, y);   
613this.drawLine(x+w, y, x+w, y+h);   
614this.drawLine(x, y+h, x+w, y+h);   
615this.drawLine(x, y, x, y+h);   
616} 
617
618  
619function jsgFont()   
620{   
621this.PLAIN = 'font-weight:normal;';   
622this.BOLD = 'font-weight:bold;';   
623this.ITALIC = 'font-style:italic;';   
624this.ITALIC_BOLD = this.ITALIC + this.BOLD;   
625this.BOLD_ITALIC = this.ITALIC_BOLD;   
626}   
627var Font = new jsgFont(); 
628
629  
630function jsgStroke()   
631{   
632this.DOTTED = -1;   
633}   
634var Stroke = new jsgStroke(); 
635
636  
637function jsGraphics(id, wnd)   
638{   
639this.setColor = new Function('arg', 'this.color = arg.toLowerCase();'); 
640
641this.setStroke = function(x)   
642{   
643this.stroke = x;   
644if (!(x+1))   
645{   
646this.drawLine = mkLinDott;   
647this.mkOv = mkOvDott;   
648this.drawRect = mkRectDott;   
649}   
650else if (x-1 &gt; 0)   
651{   
652this.drawLine = mkLin2D;   
653this.mkOv = mkOv2D;   
654this.drawRect = mkRect;   
655}   
656else   
657{   
658this.drawLine = mkLin;   
659this.mkOv = mkOv;   
660this.drawRect = mkRect;   
661}   
662}; 
663
664  
665this.setPrintable = function(arg)   
666{   
667this.printable = arg;   
668if (jg_fast)   
669{   
670this.mkDiv = mkDivIe;   
671this.htmRpc = arg? htmPrtRpc : htmRpc;   
672}   
673else this.mkDiv = jg_n4? mkLyr : arg? mkDivPrt : mkDiv;   
674}; 
675
676  
677this.setFont = function(fam, sz, sty)   
678{   
679this.ftFam = fam;   
680this.ftSz = sz;   
681this.ftSty = sty || Font.PLAIN;   
682}; 
683
684  
685this.drawPolyline = this.drawPolyLine = function(x, y, s)   
686{   
687for (var i=0 ; i<x.length-1 )="" -="1)" ;="" =="" a="(w" function(left,="" function(x,="" h)="" h);="" i++="" this.drawellipse="this.drawOval" this.drawline(x[i],="" this.drawline(x[x.length-1],="" this.drawpolygon="function(x," this.drawpolyline(x,="" this.fillellipse="this.fillOval" this.fillrect="function(x," this.mkdiv(x,="" this.mkov(x,="" top,="" var="" w,="" x[0],="" x[i+1],="" y)="" y);="" y,="" y[0]);="" y[i+1]);="" y[i],="" y[x.length-1],="" {="" };="">&gt;1, b = (h -= 1)&gt;&gt;1,   
688wod = (w&amp;1)+1, hod = (h&amp;1)+1,   
689cx = left+a, cy = top+b,   
690x = 0, y = b,   
691ox = 0, oy = b,   
692aa2 = (a*a)&lt;&lt;1, aa4 = aa2&lt;&lt;1, bb = (b*b)&lt;&lt;1,   
693st = (aa2&gt;&gt;1)*(1-(b&lt;&lt;1)) + bb,   
694tt = (bb&gt;&gt;1) - aa2*((b&lt;&lt;1)-1),   
695pxl, dw, dh;   
696if (w+1) while (y &gt; 0)   
697{   
698if (st &lt; 0)   
699{   
700st += bb*((x&lt;&lt;1)+3);   
701tt += (bb&lt;&lt;1)*(++x);   
702}   
703else if (tt &lt; 0)   
704{   
705st += bb*((x&lt;&lt;1)+3) - aa4*(y-1);   
706pxl = cx-x;   
707dw = (x&lt;&lt;1)+wod;   
708tt += (bb&lt;&lt;1)*(++x) - aa2*(((y--)&lt;&lt;1)-3);   
709dh = oy-y;   
710this.mkDiv(pxl, cy-oy, dw, dh);   
711this.mkDiv(pxl, cy+oy-dh+hod, dw, dh);   
712ox = x;   
713oy = y;   
714}   
715else   
716{   
717tt -= aa2*((y&lt;&lt;1)-3);   
718st -= aa4*(--y);   
719}   
720}   
721this.mkDiv(cx-a, cy-oy, w+1, (oy&lt;&lt;1)+hod);   
722}; 
723
724this.fillPolygon = function(array_x, array_y)   
725{   
726var i;   
727var y;   
728var miny, maxy;   
729var x1, y1;   
730var x2, y2;   
731var ind1, ind2;   
732var ints; 
733
734var n = array_x.length; 
735
736if (!n) return; 
737
738  
739miny = array_y[0];   
740maxy = array_y[0];   
741for (i = 1; i &lt; n; i++)   
742{   
743if (array_y[i] &lt; miny)   
744miny = array_y[i]; 
745
746if (array_y[i] &gt; maxy)   
747maxy = array_y[i];   
748}   
749for (y = miny; y &lt;= maxy; y++)   
750{   
751var polyInts = new Array();   
752ints = 0;   
753for (i = 0; i &lt; n; i++)   
754{   
755if (!i)   
756{   
757ind1 = n-1;   
758ind2 = 0;   
759}   
760else   
761{   
762ind1 = i-1;   
763ind2 = i;   
764}   
765y1 = array_y[ind1];   
766y2 = array_y[ind2];   
767if (y1 &lt; y2)   
768{   
769x1 = array_x[ind1];   
770x2 = array_x[ind2];   
771}   
772else if (y1 &gt; y2)   
773{   
774y2 = array_y[ind1];   
775y1 = array_y[ind2];   
776x2 = array_x[ind1];   
777x1 = array_x[ind2];   
778}   
779else continue; 
780
781if ((y &gt;= y1) &amp;&amp; (y &lt; y2))   
782polyInts[ints++] = Math.round((y-y1) * (x2-x1) / (y2-y1) + x1); 
783
784else if ((y == maxy) &amp;&amp; (y &gt; y1) &amp;&amp; (y &lt;= y2))   
785polyInts[ints++] = Math.round((y-y1) * (x2-x1) / (y2-y1) + x1);   
786}   
787polyInts.sort(integer_compare); 
788
789for (i = 0; i &lt; ints; i+=2)   
790{   
791w = polyInts[i+1]-polyInts[i]   
792this.mkDiv(polyInts[i], y, polyInts[i+1]-polyInts[i]+1, 1);   
793}   
794}   
795}; 
796
797  
798this.drawString = function(txt, x, y)   
799{   
800this.htm += '<div style="position:absolute;white-space:nowrap;'+   
801'left:' + x + 'px;'+   
802'top:' + y + 'px;'+   
803'font-family:' + this.ftFam + ';'+   
804'font-size:' + this.ftSz + ';'+   
805'color:' + this.color + ';' + this.ftSty + '">'+   
806txt +   
807'&lt;\/div&gt;';   
808} 
809
810  
811this.drawImage = function(imgSrc, x, y, w, h)   
812{   
813this.htm += '<div style="position:absolute;'+   
814'left:' + x + 'px;'+   
815'top:' + y + 'px;'+   
816'width:' + w + ';'+   
817'height:' + h + ';">'+   
818'<img height="' + h + '" src="' + imgSrc + '" width="' + w + '"/>'+   
819'&lt;\/div&gt;';   
820} 
821
822  
823this.clear = function()   
824{   
825this.htm = "";   
826if (this.cnv) this.cnv.innerHTML = this.defhtm;   
827}; 
828
829  
830this.mkOvQds = function(cx, cy, xl, xr, yt, yb, w, h)   
831{   
832this.mkDiv(xr+cx, yt+cy, w, h);   
833this.mkDiv(xr+cx, yb+cy, w, h);   
834this.mkDiv(xl+cx, yb+cy, w, h);   
835this.mkDiv(xl+cx, yt+cy, w, h);   
836}; 
837
838this.setStroke(1);   
839this.setFont('verdana,geneva,helvetica,sans-serif', String.fromCharCode(0x31, 0x32, 0x70, 0x78), Font.PLAIN);   
840this.color = '#000000';   
841this.htm = '';   
842this.wnd = wnd || window; 
843
844if (!(jg_ie || jg_dom || jg_ihtm)) chkDHTM();   
845if (typeof id != 'string' || !id) this.paint = pntDoc;   
846else   
847{   
848this.cnv = document.all? (this.wnd.document.all[id] || null)   
849: document.getElementById? (this.wnd.document.getElementById(id) || null)   
850: null;   
851this.defhtm = (this.cnv &amp;&amp; this.cnv.innerHTML)? this.cnv.innerHTML : '';   
852this.paint = jg_dom? pntCnvDom : jg_ie? pntCnvIe : jg_ihtm? pntCnvIhtm : pntCnv;   
853} 
854
855this.setPrintable(false);   
856} 
857
858function integer_compare(x,y)   
859{   
860return (x &lt; y) ? -1 : ((x &gt; y)*1);   
861}</div></div></x.length-1></layer></div></div></datalist1.items.count;i++)>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus