aboutsummaryrefslogtreecommitdiff
path: root/assets/canvas-runtime.js
diff options
context:
space:
mode:
authorhwc4872012-03-21 16:29:02 -0700
committerhwc4872012-03-21 16:29:02 -0700
commitc919442392a9406aeca6764f67e4875ee0a6370a (patch)
treef948f1bde08be00b96e77ff04a6598fd7e40ed02 /assets/canvas-runtime.js
parent3f6c49bff64a9a765c16d2bd21994f57b557a94b (diff)
downloadninja-c919442392a9406aeca6764f67e4875ee0a6370a.tar.gz
fixes for Runtime line object.
Diffstat (limited to 'assets/canvas-runtime.js')
-rw-r--r--assets/canvas-runtime.js97
1 files changed, 97 insertions, 0 deletions
diff --git a/assets/canvas-runtime.js b/assets/canvas-runtime.js
index 5ea2a85f..87aac71f 100644
--- a/assets/canvas-runtime.js
+++ b/assets/canvas-runtime.js
@@ -830,6 +830,103 @@ function RuntimeRectangle()
830} 830}
831 831
832/////////////////////////////////////////////////////////////////////// 832///////////////////////////////////////////////////////////////////////
833// Class RuntimeLine
834///////////////////////////////////////////////////////////////////////
835function RuntimeLine()
836{
837 this.inheritedFrom = RuntimeGeomObj;
838 this.inheritedFrom();
839
840 this.import = function( jObj )
841 {
842 this._xOffset = jObj.xoff;
843 this._yOffset = jObj.yoff;
844 this._width = jObj.width;
845 this._height = jObj.height;
846 this._xAdj = jObj.xAdj;
847 this._yAdj = jObj.yAdj;
848 this._strokeWidth = jObj.strokeWidth;
849 this._slope = jObj.slope;
850 this._strokeStyle = jObj.strokeStyle;
851 this._strokeColor = jObj.strokeColor;
852 var strokeMaterialName = jObj.strokeMat;
853 this.importMaterials( jObj.materials );
854 }
855
856 this.render = function()
857 {
858 // get the world
859 var world = this.getWorld();
860 if (!world) throw( "null world in buildBuffers" );
861
862 // get the context
863 var ctx = world.get2DContext();
864 if (!ctx) return;
865
866 // set up the stroke style
867 var lineWidth = this._strokeWidth,
868 w = this._width,
869 h = this._height;
870
871 var c,
872 gradient,
873 colors,
874 len,
875 n,
876 position,
877 cs;
878
879 ctx.beginPath();
880 ctx.lineWidth = lineWidth;
881 if (this._strokeColor) {
882 if(this._strokeColor.gradientMode) {
883 if(this._strokeColor.gradientMode === "radial") {
884 gradient = ctx.createRadialGradient(w/2, h/2, 0, w/2, h/2, Math.max(w/2, h/2));
885 } else {
886 gradient = ctx.createLinearGradient(0, h/2, w, h/2);
887 }
888 colors = this._strokeColor.color;
889
890 len = colors.length;
891
892 for(n=0; n<len; n++) {
893 position = colors[n].position/100;
894 cs = colors[n].value;
895 gradient.addColorStop(position, "rgba(" + cs.r + "," + cs.g + "," + cs.b + "," + cs.a + ")");
896 }
897
898 ctx.strokeStyle = gradient;
899
900 } else {
901 c = "rgba(" + 255*this._strokeColor[0] + "," + 255*this._strokeColor[1] + "," + 255*this._strokeColor[2] + "," + this._strokeColor[3] + ")";
902 ctx.strokeStyle = c;
903 }
904
905 // get the points
906 var p0, p1;
907 if(this._slope === "vertical") {
908 p0 = [0.5*w, 0];
909 p1 = [0.5*w, h];
910 } else if(this._slope === "horizontal") {
911 p0 = [0, 0.5*h];
912 p1 = [w, 0.5*h];
913 } else if(this._slope > 0) {
914 p0 = [this._xAdj, this._yAdj];
915 p1 = [w - this._xAdj, h - this._yAdj];
916 } else {
917 p0 = [this._xAdj, h - this._yAdj];
918 p1 = [w - this._xAdj, this._yAdj];
919 }
920
921 // draw the line
922 ctx.moveTo( p0[0], p0[1] );
923 ctx.lineTo( p1[0], p1[1] );
924 ctx.stroke();
925 }
926 }
927}
928
929///////////////////////////////////////////////////////////////////////
833// Class RuntimeOval 930// Class RuntimeOval
834/////////////////////////////////////////////////////////////////////// 931///////////////////////////////////////////////////////////////////////
835function RuntimeOval() 932function RuntimeOval()