diff options
Diffstat (limited to 'assets/canvas-runtime.js')
-rw-r--r-- | assets/canvas-runtime.js | 201 |
1 files changed, 201 insertions, 0 deletions
diff --git a/assets/canvas-runtime.js b/assets/canvas-runtime.js index af860b95..c0c4ccfc 100644 --- a/assets/canvas-runtime.js +++ b/assets/canvas-runtime.js | |||
@@ -378,6 +378,10 @@ NinjaCvsRt.GLRuntime = Object.create(Object.prototype, { | |||
378 | obj.importJSON( jObj ); | 378 | obj.importJSON( jObj ); |
379 | break; | 379 | break; |
380 | 380 | ||
381 | case 5: //subpath (created by pen tool) | ||
382 | obj = Object.create(NinjaCvsRt.RuntimeSubPath, {_materials: { value:[], writable:true}}); | ||
383 | obj.importJSON (jObj ); | ||
384 | break; | ||
381 | default: | 385 | default: |
382 | throw new Error( "Attempting to load unrecognized object type: " + type ); | 386 | throw new Error( "Attempting to load unrecognized object type: " + type ); |
383 | break; | 387 | break; |
@@ -1804,3 +1808,200 @@ NinjaCvsRt.RuntimePlasmaMaterial = Object.create(NinjaCvsRt.RuntimeMaterial, { | |||
1804 | }); | 1808 | }); |
1805 | 1809 | ||
1806 | 1810 | ||
1811 | |||
1812 | // ************************************************************************** | ||
1813 | // Runtime for the pen tool path | ||
1814 | // ************************************************************************** | ||
1815 | NinjaCvsRt.AnchorPoint = Object.create(Object.prototype, { | ||
1816 | ///////////////////////////////////////// | ||
1817 | // Instance variables | ||
1818 | ///////////////////////////////////////// | ||
1819 | _x: {value: 0.0, writable: true}, | ||
1820 | _y: {value: 0.0, writable: true}, | ||
1821 | _z: {value: 0.0, writable: true}, | ||
1822 | |||
1823 | _prevX: {value: 0.0, writable: true}, | ||
1824 | _prevY: {value: 0.0, writable: true}, | ||
1825 | _prevZ: {value: 0.0, writable: true}, | ||
1826 | |||
1827 | _nextX: {value: 0.0, writable: true}, | ||
1828 | _nextY: {value: 0.0, writable: true}, | ||
1829 | _nextZ: {value: 0.0, writable: true}, | ||
1830 | |||
1831 | // *********** setters ************ | ||
1832 | setPos: { | ||
1833 | value: function(x,y,z){ | ||
1834 | this._x = x; | ||
1835 | this._y = y; | ||
1836 | this._z = z; | ||
1837 | } | ||
1838 | }, | ||
1839 | |||
1840 | setPrevPos: { | ||
1841 | value: function (x, y, z) { | ||
1842 | this._prevX = x; | ||
1843 | this._prevY = y; | ||
1844 | this._prevZ = z; | ||
1845 | } | ||
1846 | }, | ||
1847 | |||
1848 | setNextPos: { | ||
1849 | value: function (x, y, z) { | ||
1850 | this._nextX = x; | ||
1851 | this._nextY = y; | ||
1852 | this._nextZ = z; | ||
1853 | } | ||
1854 | }, | ||
1855 | |||
1856 | // *************** getters ****************** | ||
1857 | // (add as needed) | ||
1858 | getPosX: { | ||
1859 | value: function () { | ||
1860 | return this._x; | ||
1861 | } | ||
1862 | }, | ||
1863 | |||
1864 | getPosY: { | ||
1865 | value: function () { | ||
1866 | return this._y; | ||
1867 | } | ||
1868 | }, | ||
1869 | |||
1870 | getPosZ: { | ||
1871 | value: function () { | ||
1872 | return this._z; | ||
1873 | } | ||
1874 | }, | ||
1875 | |||
1876 | getPrevX: { | ||
1877 | value: function () { | ||
1878 | return this._prevX; | ||
1879 | } | ||
1880 | }, | ||
1881 | |||
1882 | getPrevY: { | ||
1883 | value: function () { | ||
1884 | return this._prevY; | ||
1885 | } | ||
1886 | }, | ||
1887 | |||
1888 | getPrevZ: { | ||
1889 | value: function () { | ||
1890 | return this._prevZ; | ||
1891 | } | ||
1892 | }, | ||
1893 | |||
1894 | getNextX: { | ||
1895 | value: function () { | ||
1896 | return this._nextX; | ||
1897 | } | ||
1898 | }, | ||
1899 | |||
1900 | getNextY: { | ||
1901 | value: function () { | ||
1902 | return this._nextY; | ||
1903 | } | ||
1904 | }, | ||
1905 | |||
1906 | getNextZ: { | ||
1907 | value: function () { | ||
1908 | return this._nextZ; | ||
1909 | } | ||
1910 | } | ||
1911 | }); | ||
1912 | |||
1913 | NinjaCvsRt.RuntimeSubPath = Object.create(NinjaCvsRt.RuntimeGeomObj, { | ||
1914 | // array of anchor points | ||
1915 | _Anchors: { value: null, writable: true }, | ||
1916 | |||
1917 | //path properties | ||
1918 | _isClosed: {value: false, writable: true}, | ||
1919 | _strokeWidth: {value: 0, writable: true}, | ||
1920 | _strokeColor: {value: null, writable: true}, | ||
1921 | _fillColor: {value: null, writable: true}, | ||
1922 | |||
1923 | importJSON: { | ||
1924 | value: function(jo) { | ||
1925 | if (this.geomType()!== jo.geomType){ | ||
1926 | return; | ||
1927 | } | ||
1928 | //the geometry for this object | ||
1929 | this._Anchors = []; | ||
1930 | var i=0; | ||
1931 | for (i=0;i<jo.anchors.length;i++){ | ||
1932 | var newAnchor = new NinjaCvsRt.AnchorPoint(); | ||
1933 | var ipAnchor = jo.anchors[i]; | ||
1934 | newAnchor.setPos(ipAnchor._x, ipAnchor._y, ipAnchor._z); | ||
1935 | newAnchor.setPrevPos(ipAnchor._prevX, ipAnchor._prevY, ipAnchor._prevZ); | ||
1936 | newAnchor.setNextPos(ipAnchor._nextX, ipAnchor._nextY, ipAnchor._nextZ); | ||
1937 | this._Anchors.push(newAnchor); | ||
1938 | } | ||
1939 | this._isClosed = jo.isClosed; | ||
1940 | |||
1941 | //stroke appearance properties | ||
1942 | this._strokeWidth = jo.strokeWidth; | ||
1943 | this._strokeColor = jo.strokeColor; | ||
1944 | this._fillColor = jo.fillColor; | ||
1945 | } | ||
1946 | }, | ||
1947 | |||
1948 | render: { | ||
1949 | value: function() { | ||
1950 | // get the world | ||
1951 | var world = this.getWorld(); | ||
1952 | if (!world) { | ||
1953 | throw( "null world in subpath render" ); | ||
1954 | return; | ||
1955 | } | ||
1956 | |||
1957 | // get the context | ||
1958 | var ctx = world.get2DContext(); | ||
1959 | if (!ctx) { | ||
1960 | throw( "null world in subpath render" ); | ||
1961 | return; | ||
1962 | } | ||
1963 | |||
1964 | ctx.save(); | ||
1965 | ctx.lineWidth = this._strokeWidth; | ||
1966 | ctx.strokeStyle = "black"; | ||
1967 | if (this._strokeColor) { | ||
1968 | var strokeColorStr = "rgba("+parseInt(255*this._strokeColor[0])+","+parseInt(255*this._strokeColor[1])+","+parseInt(255*this._strokeColor[2])+","+this._strokeColor[3]+")"; | ||
1969 | ctx.strokeStyle = strokeColorStr; | ||
1970 | } | ||
1971 | |||
1972 | ctx.fillStyle = "white"; | ||
1973 | if (this._fillColor){ | ||
1974 | var fillColorStr = "rgba("+parseInt(255*this._fillColor[0])+","+parseInt(255*this._fillColor[1])+","+parseInt(255*this._fillColor[2])+","+this._fillColor[3]+")"; | ||
1975 | ctx.fillStyle = fillColorStr; | ||
1976 | } | ||
1977 | var lineCap = ['butt','round','square']; | ||
1978 | ctx.lineCap = lineCap[1]; | ||
1979 | var lineJoin = ['round','bevel','miter']; | ||
1980 | ctx.lineJoin = lineJoin[0]; | ||
1981 | |||
1982 | var numAnchors = this._Anchors.length; | ||
1983 | if (numAnchors>1) { | ||
1984 | ctx.beginPath(); | ||
1985 | var prevAnchor = this._Anchors[0]; | ||
1986 | ctx.moveTo(prevAnchor.getPosX(),prevAnchor.getPosY()); | ||
1987 | for (var i = 1; i < numAnchors; i++) { | ||
1988 | var currAnchor = this._Anchors[i]; | ||
1989 | ctx.bezierCurveTo(prevAnchor.getNextX(),prevAnchor.getNextY(), currAnchor.getPrevX(), currAnchor.getPrevY(), currAnchor.getPosX(), currAnchor.getPosY()); | ||
1990 | prevAnchor = currAnchor; | ||
1991 | } | ||
1992 | if (this._isClosed === true) { | ||
1993 | var currAnchor = this._Anchors[0]; | ||
1994 | ctx.bezierCurveTo(prevAnchor.getNextX(),prevAnchor.getNextY(), currAnchor.getPrevX(), currAnchor.getPrevY(), currAnchor.getPosX(), currAnchor.getPosY()); | ||
1995 | prevAnchor = currAnchor; | ||
1996 | ctx.fill(); | ||
1997 | } | ||
1998 | ctx.stroke(); | ||
1999 | } | ||
2000 | ctx.restore(); | ||
2001 | } | ||
2002 | } | ||
2003 | });// ************************************************************************** | ||
2004 | // END runtime for the pen tool path | ||
2005 | // ************************************************************************** | ||
2006 | |||
2007 | |||