home *** CD-ROM | disk | FTP | other *** search
/ ring.yamanashi.ac.jp/pub/pc/freem/action/ / action.zip / baku100.zip / baku100 / Kernel / Sprite.tonyu < prev    next >
Text File  |  2006-06-25  |  7KB  |  264 lines

  1. extends classes.lang.Object;
  2.  
  3. destructor Free() {
  4. }
  5.  
  6. constructor Sprite(){
  7. //constructor Sprite(x,y,p,f){
  8. //   _a=native_init();
  9. //   set(x,y,p,f);
  10. }
  11.  
  12. function setText(x,y,t,c,s) {
  13.    native_setText(x,y,t,c,s);
  14. }
  15.  
  16. native native_textExtent;
  17. function textWidth(t,s) {
  18.    return native_textExtent(0,t,s);
  19. }
  20. function textHeight(t,s) {
  21.    return native_textExtent(1,t,s);
  22. }
  23. native _n_setFont;
  24. function setFont(s,b,i,u) {
  25.   _n_setFont(s,b,i,u);
  26. }
  27.  
  28. function drawText (x,y,t,c,s,z) {
  29.    var ss,cc,zz;
  30.    if (s) ss=s; else ss=12; 
  31.    if (c) cc=c; else c=color(255,255,255);
  32.    native_setText(x,y,t,cc,ss,z);
  33. }
  34.  
  35. function drawLine (x,y,dx,dy,c,z) {
  36.    native_drawLine(x,y,dx,dy,c,z);
  37. }
  38.  
  39. function drawBrokenLine(sx,sy,dx,dy,col,zorder,length){
  40.   var i,nx,ny,space,d;
  41.   d=dist(sx-dx,sy-dy);
  42.   if (d>0 && length>0) {
  43.     space=trunc(d/(length*2));
  44.     nx=(dx-sx)/space;
  45.     ny=(dy-sy)/space;
  46.     for(i=0;i<space;i++){
  47.       drawline(sx+(nx*i),sy+(ny*i),sx+nx*(i+1)-nx/2,sy+ny*(i+1)-ny/2,col,zorder);
  48.     }
  49.     drawline(sx+(nx*i),sy+(ny*i),dx,dy,col,zorder);
  50.   }
  51. }
  52.  
  53. function fillRect (x,y,dx,dy,c,z) {
  54.    native_fillRect(x,y,dx,dy,c,z);
  55. }
  56.  
  57. //function set(x,y,p,f) {
  58. //   if (_a!=0)
  59. //     native_set(1,x,y,p,f);
  60. //}
  61.  
  62. function drawSprite(x,y,p,f,z) {
  63.      native_set(1,x,y,p,f,z);
  64. }
  65.  
  66.  
  67. function freeSprite() {
  68. //   native_free(_a);
  69. //   _a=0;
  70. }
  71.  
  72. function getPatWidth(p) {
  73.    return native_getPWidth(p);
  74. }
  75.  
  76. function getPatHeight(p) {
  77.    return native_getPHeight(p);
  78. }
  79.  
  80. native native_free;
  81. native native_init;
  82. native native_set;
  83. native native_setText;
  84. native native_drawLine;
  85. native native_fillRect;
  86. native native_getPWidth;
  87. native native_getPHeight;
  88.  
  89. native _n_drawMapSprite;
  90. function drawMapSprite(xx,yy,pw,ph) {
  91.    return _n_drawMapSprite (xx,yy,pw,ph);
  92. }
  93. native _n_drawChip;
  94. function drawChip(xx,yy,pp) {
  95.    return _n_drawChip (xx,yy,pp);
  96.  
  97. }
  98.  
  99. native _n_drawDxSprite;
  100. function drawDxSprite(x,y,p,f,z,rt,al,szx,szy) {
  101.    var szyy; szyy=szx; if(szy) szyy=szy;
  102.    _n_drawDxSprite(x,y,p,f,z,rt,al,szx,szyy);
  103. }
  104.  
  105. function drawScreenXY(s) {
  106.    if (s) { setAdjust(0,0); }
  107.    else   { setAdjust($viewX,$viewY); }
  108. }
  109.  
  110. native _n_fillPolygon;
  111. function fillPolygon(x,y,points,col,zOrder) {
  112.   _n_fillPolygon(x,y,points,col,zOrder);
  113. }
  114. native _n_setPolygon;
  115. function setPolygon(index,x,y) {
  116.   _n_setPolygon(index,x,y);
  117. }
  118.  
  119. //-----------extended graphics routine---------------------------
  120. function centerText(x,y,text,col,size[,zOr]) {
  121.   var a,b;
  122.   a=textWidth(text,size);
  123.   b=x-a/2;  // (((bx-ax)-(a))/2)+ax;
  124.   drawText(b,y,text,col,size,zOr);
  125. }
  126.  
  127. function drawVerticalText(ax,ay,text,col,size[,zOr]) {
  128.   var by,length,o_text,o_width,o_height,a;
  129.   by=ay;
  130.   length=text.length();
  131.   for (a=0;a<length;a++) {
  132.     o_text=text.substring(a,a+1);
  133.     o_width=textWidth(o_text,size);
  134.     o_height=textHeight(o_text,size);
  135.     drawText(ax-(o_width/2),by,o_text,col,size,zOr);
  136.     by+=o_height;
  137.   }
  138. }
  139.  
  140. function drawPolygon(x,y,number,size,col,ang[,zOr]) {
  141.   var a,b,c,polygon,ax,ay,bx,by;
  142.   b=360/number;
  143.   c=new Array();
  144.   for (a=0;a<=number;a++) {
  145.     c.add(b*a);
  146.   }
  147.   for (a=0;a<number;a++) {
  148.     ax=x+cos(c.get(a)+ang)*size;
  149.     ay=y+sin(c.get(a)+ang)*size;
  150.     if (a<number) bx=x+cos(c.get(a+1)+ang)*size;
  151.     if (a<number) by=y+sin(c.get(a+1)+ang)*size;
  152.     if (a==number) bx=x+sin(c.get(0)+ang)*size;
  153.     if (a==number) by=y+sin(c.get(0)+ang)*size;
  154.     drawLine(ax,ay,bx,by,col,zOr);
  155.     b+=b;
  156.   }
  157. }
  158.  
  159. function drawRect(rx,ry,sx,sy,col[,zOr]) {
  160.   drawLine(rx,ry,rx,sy,col,zOr);
  161.   drawLine(rx,sy,sx,sy,col,zOr);
  162.   drawLine(sx,sy,sx,ry,col,zOr);
  163.   drawLine(sx,ry,rx,ry,col,zOr);
  164. }
  165.  
  166. function drawRectDx(rx,ry,sx,sy,col,ang[,zOr]) {
  167.   var ax,ay,bx,by,cx,cy,dx,dy;
  168.   $Math.roll(rx+sx/2,ry+sy/2,ang,rx,ry);
  169.   ax=$Math.rx;ay=$Math.ry;
  170.   $Math.roll(rx-sx/2,ry+sy/2,ang,rx,ry);
  171.   bx=$Math.rx;by=$Math.ry;
  172.   $Math.roll(rx-sx/2,ry-sy/2,ang,rx,ry);
  173.   cx=$Math.rx;cy=$Math.ry;
  174.   $Math.roll(rx+sx/2,ry-sy/2,ang,rx,ry);
  175.   dx=$Math.rx;dy=$Math.ry;
  176.   drawLine(ax,ay,bx,by,col,zOr);
  177.   drawLine(bx,by,cx,cy,col,zOr);
  178.   drawLine(cx,cy,dx,dy,col,zOr);
  179.   drawLine(dx,dy,ax,ay,col,zOr);
  180. }
  181.  
  182. function drawTriangle(ax,ay,bx,by,cx,cy,col,angle[,zOr]) {
  183.   var xx,yy,distA,distB,distC,vertexAx,vertexAy,vertexBx;
  184.   var angleA,angleB,angleC,vertexBy,vertexCx,vertexCy;
  185.   xx=(ax+bx+cx)/3;
  186.   yy=(ay+by+cy)/3;
  187.  
  188.   $Math.roll(ax,ay,angle,xx,yy);
  189.   ax=$Math.rx; ay=$Math.ry;
  190.  
  191.   $Math.roll(bx,by,angle,xx,yy);
  192.   bx=$Math.rx; by=$Math.ry;
  193.  
  194.   $Math.roll(cx,cy,angle,xx,yy);
  195.   cx=$Math.rx; cy=$Math.ry;
  196.  
  197.   drawLine(Ax,Ay,Bx,By,col,zOr);
  198.   drawLine(Bx,By,Cx,Cy,col,zOr);
  199.   drawLine(Cx,Cy,Ax,Ay,col,zOr);
  200. }
  201.  
  202.  
  203. function gradationLine(ax,ay,bx,by,col1,col2[,zOr]) {
  204.   var length,r_1,g_1,b_1,r_2,g_2,b_2,o_lengthX,o_lengthY,a;
  205.   length=dist(bx-ax,by-ay); 
  206.   o_lengthX=((bx-ax)/length);
  207.   o_lengthY=((by-ay)/length);
  208.   r_1=getRed(col1);
  209.   g_1=getGreen(col1);
  210.   b_1=getBlue(col1);
  211.   r_2=(getRed(col2)-getRed(col1))/length;
  212.   g_2=(getGreen(col2)-getGreen(col1))/length;
  213.   b_2=(getBlue(col2)-getBlue(col1))/length;
  214.   for (a=0;a<length;a++) {
  215.     drawLine(ax+(o_lengthX*a),ay+(o_lengthY*a),
  216.     ax+(o_lengthX*a)+o_lengthX,
  217.     ay+(o_lengthY*a)+o_lengthY,
  218.     color(r_1+trunc(r_2*a),g_1+trunc(g_2*a),b_1+trunc(b_2*a)),zOr);
  219.   }
  220. }
  221.  
  222. function gradationRect(ax,ay,bx,by,shift,col1,col2[,zOr]) {
  223.   var length,r_1,g_1,b_1,r_2,g_2,b_2,a;
  224.   if (shift==0) length=bx-ax;
  225.   if (shift==1) length=by-ay;
  226.   r_1=getRed(col1);
  227.   g_1=getGreen(col1);
  228.   b_1=getBlue(col1);
  229.   r_2=(getRed(col2)-getRed(col1))/length;
  230.   g_2=(getGreen(col2)-getGreen(col1))/length;
  231.   b_2=(getBlue(col2)-getBlue(col1))/length;
  232.   for (a=0;a<length;a++) {
  233.     if (shift==0) {
  234.       fillRect(ax+a,ay,ax+a+1,by,
  235.       color(r_1+trunc(r_2*a),g_1+trunc(g_2*a),b_1+trunc(b_2*a)),zOr);
  236.     }
  237.     if (shift==1) {
  238.       fillRect(ax,ay+a,bx,ay+a+1,
  239.       color(r_1+trunc(r_2*a),g_1+trunc(g_2*a),b_1+trunc(b_2*a)),zOr);
  240.     }
  241.   }
  242. }
  243.  
  244. function gradationText(ax,ay,text,col1,col2,size[,zOr]) {
  245.   var length,width,o_text,l_text,l_width,r_1,g_1,b_1,r_2,g_2,b_2,a;
  246.   length=text.length();
  247.   r_1=getRed(col1);
  248.   g_1=getGreen(col1);
  249.   b_1=getBlue(col1);
  250.   r_2=(getRed(col2)-getRed(col1))/length;
  251.   g_2=(getGreen(col2)-getGreen(col1))/length;
  252.   b_2=(getBlue(col2)-getBlue(col1))/length;
  253.   width=textWidth(text,size);
  254.   for (a=0;a<length;a++) {
  255.     o_text=text.substring(a,a+1);
  256.     l_text=text.substring(0,a);
  257.     l_width=textWidth(l_text,size);
  258.     drawText(ax+l_width,ay,o_text,
  259.     color(r_1+trunc(r_2*a),g_1+trunc(g_2*a),b_1+trunc(b_2*a)),size,zOr);
  260.   }
  261. }
  262. //-----------end of extended graphics routine---------------------------
  263.  
  264.