ma1uta

Untitled

Aug 19th, 2013
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Point(e, t) {
  2.     if (!e) e = 0;
  3.     if (!t) t = 0;
  4.     this.x = e;
  5.     this.y = t
  6. }
  7.  
  8. function Rectangle(e, t, n, r) {
  9.     this.x = e;
  10.     this.y = t;
  11.     this.width = n;
  12.     this.height = r
  13. }
  14.  
  15. function Transform() {
  16.     this._obj = null;
  17.     this._mdirty = false;
  18.     this._vdirty = false;
  19.     this._tmat = mat4.create();
  20.     this._imat = mat4.create();
  21.     this._atmat = mat4.create();
  22.     this._aimat = mat4.create();
  23.     this._cmat = mat4.create();
  24.     this._cvec = vec4.create();
  25.     this._cID = true;
  26.     this._scaleX = 1;
  27.     this._scaleY = 1;
  28.     this._scaleZ = 1;
  29.     this._rotationX = 0;
  30.     this._rotationY = 0;
  31.     this._rotationZ = 0
  32. }
  33.  
  34. function EventDispatcher() {
  35.     this.lsrs = {};
  36.     this.cals = {}
  37. }
  38.  
  39. function Event(e, t) {
  40.     if (!t) t = false;
  41.     this.type = e;
  42.     this.target = null;
  43.     this.currentTarget = null;
  44.     this.bubbles = t
  45. }
  46.  
  47. function MouseEvent(e, t) {
  48.     Event.call(this, e, t)
  49. }
  50.  
  51. function KeyboardEvent(e, t) {
  52.     Event.call(this, e, t);
  53.     this.altKey = false;
  54.     this.ctrlKey = false;
  55.     this.shiftKey = false;
  56.     this.keyCode = 0;
  57.     this.charCode = 0
  58. }
  59.  
  60. function DisplayObject() {
  61.     EventDispatcher.call(this);
  62.     this.visible = true;
  63.     this.parent = null;
  64.     this.stage = null;
  65.     this.transform = new Transform;
  66.     this.transform._obj = this;
  67.     this.blendMode = BlendMode.NORMAL;
  68.     this.x = 0;
  69.     this.y = 0;
  70.     this.z = 0;
  71.     this._brect = new Rectangle(0, 0, 0, 0);
  72.     this._temp = new Float32Array(2);
  73.     this._temp2 = new Float32Array(2);
  74.     this._tempm = mat4.create();
  75.     this._atsEv = new Event(Event.ADDED_TO_STAGE);
  76.     this._rfsEv = new Event(Event.REMOVED_FROM_STAGE);
  77.     this._atsEv.target = this._rfsEv.target = this
  78. }
  79.  
  80. function InteractiveObject() {
  81.     DisplayObject.call(this);
  82.     this.buttonMode = false;
  83.     this.mouseEnabled = true
  84. }
  85.  
  86. function DisplayObjectContainer() {
  87.     InteractiveObject.call(this);
  88.     this.numChildren = 0;
  89.     this.mouseChildren = true;
  90.     this._children = [];
  91.     this._brect2 = new Rectangle(0, 0, 0, 0)
  92. }
  93.  
  94. function BitmapData(e) {
  95.     this.width = 0;
  96.     this.height = 0;
  97.     this.rect = null;
  98.     this.loader = new EventDispatcher;
  99.     this._texture = gl.createTexture();
  100.     this._rwidth = 0;
  101.     this._rheight = 0;
  102.     this._tcBuffer = gl.createBuffer();
  103.     this._vBuffer = gl.createBuffer();
  104.     this._loaded = false;
  105.     this._opEv = new Event(Event.OPEN);
  106.     this._pgEv = new Event(Event.PROGRESS);
  107.     this._cpEv = new Event(Event.COMPLETE);
  108.     this._opEv.target = this._pgEv.target = this._cpEv.target = this.loader;
  109.     if (e == null) return;
  110.     var t = document.createElement("img");
  111.     var n = this;
  112.     t.onload = function (e) {
  113.         n._initFromImg(t, t.width, t.height);
  114.         n.loader.dispatchEvent(n._cpEv)
  115.     };
  116.     t.src = e
  117. }
  118.  
  119. function Bitmap(e) {
  120.     DisplayObject.call(this);
  121.     this.bitmapData = e
  122. }
  123.  
  124. function Stage(e) {
  125.     DisplayObjectContainer.call(this);
  126.     document.body.style.margin = "0";
  127.     this.stage = this;
  128.     this.stageWidth = 0;
  129.     this.stageHeight = 0;
  130.     this.focus = null;
  131.     this._focii = [null, null, null];
  132.     this._mousefocus = null;
  133.     this._useHand = false;
  134.     this._knM = false;
  135.     this._mstack = new Stage._MStack;
  136.     this._cmstack = new Stage._CMStack;
  137.     this._sprg = null;
  138.     this._pmat = mat4.create([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1]);
  139.     this._umat = mat4.create([2, 0, 0, 0, 0, -2, 0, 0, 0, 0, 2, 0, -1, 1, 0, 1]);
  140.     this._smat = mat4.create([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, .001, 0, 0, 0, 0, 1]);
  141.     this._efEv = new Event(Event.ENTER_FRAME);
  142.     this._rsEv = new Event(Event.RESIZE);
  143.     this._mcEvs = [new MouseEvent(MouseEvent.CLICK, true), new MouseEvent(MouseEvent.MIDDLE_CLICK, true), new MouseEvent(MouseEvent.RIGHT_CLICK, true)];
  144.     this._mdEvs = [new MouseEvent(MouseEvent.MOUSE_DOWN, true), new MouseEvent(MouseEvent.MIDDLE_MOUSE_DOWN, true), new MouseEvent(MouseEvent.RIGHT_MOUSE_DOWN, true)];
  145.     this._muEvs = [new MouseEvent(MouseEvent.MOUSE_UP, true), new MouseEvent(MouseEvent.MIDDLE_MOUSE_UP, true), new MouseEvent(MouseEvent.RIGHT_MOUSE_UP, true)];
  146.     this._mmoEv = new MouseEvent(MouseEvent.MOUSE_MOVE, true);
  147.     this._movEv = new MouseEvent(MouseEvent.MOUSE_OVER, true);
  148.     this._mouEv = new MouseEvent(MouseEvent.MOUSE_OUT, true);
  149.     this._kdEv = new KeyboardEvent(KeyboardEvent.KEY_DOWN, true);
  150.     this._kuEv = new KeyboardEvent(KeyboardEvent.KEY_UP, true);
  151.     this._smd = [false, false, false];
  152.     this._smu = [false, false, false];
  153.     this._smm = false;
  154.     this._srs = false;
  155.     this._canvas = this.canvas = document.getElementById(e);
  156.     Stage._main = this;
  157.     var t = {
  158.         alpha: true,
  159.         antialias: true,
  160.         depth: true,
  161.         premultipliedAlpha: true
  162.     };
  163.     var n = this.canvas;
  164.     gl = n.getContext("webgl", t);
  165.     if (!gl) gl = n.getContext("experimental-webgl", t);
  166.     if (!gl) alert("Could not initialize WebGL. Try to update your browser or graphic drivers.");
  167.     n.style["-webkit-user-select"] = "none";
  168.     n.addEventListener("contextmenu", Stage._ctxt, false);
  169.     n.addEventListener("dragstart", Stage._blck, false);
  170.     if (Stage._isTD()) {
  171.         n.addEventListener("touchstart", Stage._onTD, false);
  172.         n.addEventListener("touchmove", Stage._onTM, false);
  173.         n.addEventListener("touchend", Stage._onTU, false);
  174.         n.addEventListener("touchstart", Stage._blck, false);
  175.         n.addEventListener("touchmove", Stage._blck, false);
  176.         n.addEventListener("touchend", Stage._blck, false)
  177.     } else {
  178.         n.addEventListener("mousedown", Stage._onMD, false);
  179.         n.addEventListener("mousemove", Stage._onMM, false);
  180.         n.addEventListener("mouseup", Stage._onMU, false)
  181.     }
  182.     document.addEventListener("keydown", Stage._onKD, false);
  183.     document.addEventListener("keyup", Stage._onKU, false);
  184.     document.addEventListener("keydown", Stage._blck, false);
  185.     document.addEventListener("keyup", Stage._blck, false);
  186.     window.addEventListener("resize", Stage._onRS, false);
  187.     this._initShaders();
  188.     this._initBuffers();
  189.     gl.clearColor(0, 0, 0, 0);
  190.     gl.enable(gl.BLEND);
  191.     gl.blendEquation(gl.FUNC_ADD);
  192.     gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  193.     gl.enable(gl.DEPTH_TEST);
  194.     gl.depthFunc(gl.LEQUAL);
  195.     this._resize();
  196.     this._srs = true;
  197.     _requestAF(Stage._tick)
  198. }
  199.  
  200. function Graphics() {
  201.     this._px = 0;
  202.     this._py = 0;
  203.     this._uls = [];
  204.     this._cvs = [];
  205.     this._tgs = [];
  206.     this._elems = [];
  207.     this._duls = [];
  208.     this._dcvs = [];
  209.     this._dtgs = {};
  210.     this._minx = Number.POSITIVE_INFINITY;
  211.     this._miny = this._minx;
  212.     this._maxx = Number.NEGATIVE_INFINITY;
  213.     this._maxy = this._maxx;
  214.     this._sminx = Number.POSITIVE_INFINITY;
  215.     this._sminy = this._sminx;
  216.     this._smaxx = Number.NEGATIVE_INFINITY;
  217.     this._smaxy = this._smaxx;
  218.     this._brect = new Rectangle(0, 0, 0, 0);
  219.     this._clstyle = new LineStyle(1, 0, 1);
  220.     this._cfstyle = new FillStyle(16711680, 1);
  221.     this._bdata = null;
  222.     this._ftype = 0;
  223.     this._empty = true;
  224.     this._lvbuf = gl ? gl.createBuffer() : null;
  225.     this._lvval = new Float32Array(18);
  226.     this._lused = 0;
  227.     this._ltotal = 1;
  228.     this._ldirty = false;
  229.     this._lsegment = null;
  230.     if (gl) this._sendLBuffers()
  231. }
  232.  
  233. function ULSegment(e, t, n) {
  234.     this.vbuf = n;
  235.     this.offset = 0;
  236.     this.count = 0;
  237.     this.color = new Float32Array(4);
  238.     this.update(e, t)
  239. }
  240.  
  241. function UTgs(e, t) {
  242.     this.key = e + "-" + t;
  243.     this.vrt = new Float32Array(3 * e);
  244.     this.ind = new Uint16Array(3 * t);
  245.     this.uvt = new Float32Array(2 * e);
  246.     this.useTex = false;
  247.     this.emptyUVT = false;
  248.     this.color = new Float32Array(4);
  249.     this._bdata = null;
  250.     this.vbuf = gl.createBuffer();
  251.     Stage._setBF(this.vbuf);
  252.     gl.bufferData(gl.ARRAY_BUFFER, this.vrt, gl.STATIC_DRAW);
  253.     this.ibuf = gl.createBuffer();
  254.     Stage._setEBF(this.ibuf);
  255.     gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, this.ind, gl.STATIC_DRAW);
  256.     this.tbuf = gl.createBuffer();
  257.     Stage._setBF(this.tbuf);
  258.     gl.bufferData(gl.ARRAY_BUFFER, this.uvt, gl.STATIC_DRAW)
  259. }
  260.  
  261. function FillStyle(e, t) {
  262.     this.color = 0;
  263.     this.alpha = 1;
  264.     this.colARR = new Float32Array(4);
  265.     this.Set(e, t)
  266. }
  267.  
  268. function LineStyle(e, t, n) {
  269.     FillStyle.call(this);
  270.     this.color = t;
  271.     this.alpha = n;
  272.     this.thickness = e;
  273.     this.Set(e, t, n)
  274. }
  275.  
  276. function Sprite() {
  277.     DisplayObjectContainer.call(this);
  278.     this.graphics = new Graphics
  279. }
  280.  
  281. function TextFormat(e, t, n, r, i, s, o) {
  282.     this.font = e ? e : "Times new Roman";
  283.     this.size = t ? t : 12;
  284.     this.color = n ? n : 0;
  285.     this.bold = r ? r : false;
  286.     this.italic = i ? i : false;
  287.     this.align = s ? s : TextFormatAlign.LEFT;
  288.     this.leading = o ? o : 0;
  289.     this.maxW = 0;
  290.     this.data = {
  291.         image: null,
  292.         tw: 0,
  293.         th: 0,
  294.         rw: 0,
  295.         rh: 0
  296.     }
  297. }
  298.  
  299. function TextField() {
  300.     InteractiveObject.call(this);
  301.     this._wordWrap = false;
  302.     this._textW = 0;
  303.     this._textH = 0;
  304.     this._areaW = 100;
  305.     this._areaH = 100;
  306.     this._text = "";
  307.     this._tForm = new TextFormat;
  308.     this._rwidth = 0;
  309.     this._rheight = 0;
  310.     this._texture = gl.createTexture();
  311.     this._tcArray = new Float32Array([0, 0, 0, 0, 0, 0, 0, 0]);
  312.     this._tcBuffer = gl.createBuffer();
  313.     Stage._setBF(this._tcBuffer);
  314.     gl.bufferData(gl.ARRAY_BUFFER, this._tcArray, gl.STATIC_DRAW);
  315.     this._fArray = new Float32Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
  316.     this._vBuffer = gl.createBuffer();
  317.     Stage._setBF(this._vBuffer);
  318.     gl.bufferData(gl.ARRAY_BUFFER, this._fArray, gl.STATIC_DRAW);
  319.     this._brect.x = this._brect.y = 0
  320. }
  321. window._requestAF = function () {
  322.     return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function (e, t) {
  323.         window.setTimeout(e, 1e3 / 60)
  324.     }
  325. }();
  326. "use strict";
  327. var vec4 = {};
  328. var mat4 = {};
  329. vec4.create = function () {
  330.     var e = new Float32Array(4);
  331.     return e
  332. };
  333. mat4.create = function (e) {
  334.     var t = new Float32Array(16);
  335.     t[0] = t[5] = t[10] = t[15] = 1;
  336.     if (e) mat4.set(e, t);
  337.     return t
  338. };
  339. vec4.add = function (e, t, n) {
  340.     n[0] = e[0] + t[0];
  341.     n[1] = e[1] + t[1];
  342.     n[2] = e[2] + t[2];
  343.     n[3] = e[3] + t[3]
  344. };
  345. vec4.set = function (e, t) {
  346.     t[0] = e[0];
  347.     t[1] = e[1];
  348.     t[2] = e[2];
  349.     t[3] = e[3]
  350. };
  351. mat4.set = function (e, t) {
  352.     t[0] = e[0];
  353.     t[1] = e[1];
  354.     t[2] = e[2];
  355.     t[3] = e[3];
  356.     t[4] = e[4];
  357.     t[5] = e[5];
  358.     t[6] = e[6];
  359.     t[7] = e[7];
  360.     t[8] = e[8];
  361.     t[9] = e[9];
  362.     t[10] = e[10];
  363.     t[11] = e[11];
  364.     t[12] = e[12];
  365.     t[13] = e[13];
  366.     t[14] = e[14];
  367.     t[15] = e[15]
  368. };
  369. mat4.multiply = function (e, t, n) {
  370.     var r = e[0],
  371.         i = e[1],
  372.         s = e[2],
  373.         o = e[3],
  374.         u = e[4],
  375.         a = e[5],
  376.         f = e[6],
  377.         l = e[7],
  378.         c = e[8],
  379.         h = e[9],
  380.         p = e[10],
  381.         d = e[11],
  382.         v = e[12],
  383.         m = e[13],
  384.         g = e[14],
  385.         y = e[15];
  386.     var b = t[0],
  387.         w = t[1],
  388.         E = t[2],
  389.         S = t[3];
  390.     n[0] = b * r + w * u + E * c + S * v;
  391.     n[1] = b * i + w * a + E * h + S * m;
  392.     n[2] = b * s + w * f + E * p + S * g;
  393.     n[3] = b * o + w * l + E * d + S * y;
  394.     b = t[4];
  395.     w = t[5];
  396.     E = t[6];
  397.     S = t[7];
  398.     n[4] = b * r + w * u + E * c + S * v;
  399.     n[5] = b * i + w * a + E * h + S * m;
  400.     n[6] = b * s + w * f + E * p + S * g;
  401.     n[7] = b * o + w * l + E * d + S * y;
  402.     b = t[8];
  403.     w = t[9];
  404.     E = t[10];
  405.     S = t[11];
  406.     n[8] = b * r + w * u + E * c + S * v;
  407.     n[9] = b * i + w * a + E * h + S * m;
  408.     n[10] = b * s + w * f + E * p + S * g;
  409.     n[11] = b * o + w * l + E * d + S * y;
  410.     b = t[12];
  411.     w = t[13];
  412.     E = t[14];
  413.     S = t[15];
  414.     n[12] = b * r + w * u + E * c + S * v;
  415.     n[13] = b * i + w * a + E * h + S * m;
  416.     n[14] = b * s + w * f + E * p + S * g;
  417.     n[15] = b * o + w * l + E * d + S * y;
  418.     return n
  419. };
  420. mat4.inverse = function (e, t) {
  421.     var n = e[0],
  422.         r = e[1],
  423.         i = e[2],
  424.         s = e[3],
  425.         o = e[4],
  426.         u = e[5],
  427.         a = e[6],
  428.         f = e[7],
  429.         l = e[8],
  430.         c = e[9],
  431.         h = e[10],
  432.         p = e[11],
  433.         d = e[12],
  434.         v = e[13],
  435.         m = e[14],
  436.         g = e[15],
  437.         y = n * u - r * o,
  438.         b = n * a - i * o,
  439.         w = n * f - s * o,
  440.         E = r * a - i * u,
  441.         S = r * f - s * u,
  442.         x = i * f - s * a,
  443.         T = l * v - c * d,
  444.         N = l * m - h * d,
  445.         C = l * g - p * d,
  446.         k = c * m - h * v,
  447.         L = c * g - p * v,
  448.         A = h * g - p * m,
  449.         O = y * A - b * L + w * k + E * C - S * N + x * T;
  450.     if (!O) {
  451.         return null
  452.     }
  453.     O = 1 / O;
  454.     t[0] = (u * A - a * L + f * k) * O;
  455.     t[1] = (i * L - r * A - s * k) * O;
  456.     t[2] = (v * x - m * S + g * E) * O;
  457.     t[3] = (h * S - c * x - p * E) * O;
  458.     t[4] = (a * C - o * A - f * N) * O;
  459.     t[5] = (n * A - i * C + s * N) * O;
  460.     t[6] = (m * w - d * x - g * b) * O;
  461.     t[7] = (l * x - h * w + p * b) * O;
  462.     t[8] = (o * L - u * C + f * T) * O;
  463.     t[9] = (r * C - n * L - s * T) * O;
  464.     t[10] = (d * S - v * w + g * y) * O;
  465.     t[11] = (c * w - l * S - p * y) * O;
  466.     t[12] = (u * N - o * k - a * T) * O;
  467.     t[13] = (n * k - r * N + i * T) * O;
  468.     t[14] = (v * b - d * E - m * y) * O;
  469.     t[15] = (l * E - c * b + h * y) * O;
  470.     return t
  471. };
  472. mat4.multiplyVec2 = function (e, t, n) {
  473.     if (n == null) n = t;
  474.     var r = t[0],
  475.         i = t[1];
  476.     n[0] = r * e[0] + i * e[4] + e[12];
  477.     n[1] = r * e[1] + i * e[5] + e[13]
  478. };
  479. mat4.multiplyVec4 = function (e, t, n) {
  480.     var r = t[0],
  481.         i = t[1],
  482.         s = t[2],
  483.         o = t[3];
  484.     n[0] = e[0] * r + e[4] * r + e[8] * r + e[12] * r;
  485.     n[1] = e[1] * i + e[5] * i + e[9] * i + e[13] * i;
  486.     n[2] = e[2] * s + e[6] * s + e[10] * s + e[14] * s;
  487.     n[3] = e[3] * o + e[7] * o + e[11] * o + e[15] * o
  488. };
  489. Point.prototype.clone = function () {
  490.     return new Point(this.x, this.y)
  491. };
  492. Point.prototype.setTo = function (e, t) {
  493.     this.x = e;
  494.     this.y = t
  495. };
  496. Point.prototype.copyFrom = function (e) {
  497.     this.x = e.x;
  498.     this.y = e.y
  499. };
  500. Point.distance = function (e, t) {
  501.     return Point._distance(e.x, e.y, t.x, t.y)
  502. };
  503. Point._distance = function (e, t, n, r) {
  504.     return Math.sqrt((n - e) * (n - e) + (r - t) * (r - t))
  505. };
  506. Rectangle.prototype.containsPoint = function (e) {
  507.     return this.contains(e.x, e.y)
  508. };
  509. Rectangle.prototype.contains = function (e, t) {
  510.     return e >= this.x && e <= this.x + this.width && t >= this.y && t <= this.y + this.height
  511. };
  512. Rectangle.prototype.clone = function () {
  513.     return new Rectangle(this.x, this.y, this.width, this.height)
  514. };
  515. Rectangle.prototype.copyFrom = function (e) {
  516.     this.x = e.x;
  517.     this.y = e.y;
  518.     this.width = e.width;
  519.     this.height = e.height
  520. };
  521. Rectangle.prototype.union = function (e) {
  522.     var t = this.clone();
  523.     t._unionWith(e);
  524.     return t
  525. };
  526. Rectangle.prototype.intersection = function (e) {
  527.     var t = Math.max(this.x, e.x);
  528.     var n = Math.max(this.y, e.y);
  529.     var r = Math.min(this.x + this.width, e.x + e.width);
  530.     var i = Math.min(this.y + this.height, e.y + e.height);
  531.     return new Rectangle(t, n, r - t, i - n)
  532. };
  533. Rectangle.prototype.intersects = function (e) {
  534.     if (e.y + e.height < this.y || e.x > this.x + this.width || e.y > this.y + this.height || e.x + e.width < this.x) return false;
  535.     return true
  536. };
  537. Rectangle._temp = new Float32Array(2);
  538. Rectangle.prototype._unionWith = function (e) {
  539.     this._unionWP(e.x, e.y);
  540.     this._unionWP(e.x + e.width, e.y + e.height)
  541. };
  542. Rectangle.prototype._unionWP = function (e, t) {
  543.     var n = Math.min(this.x, e);
  544.     var r = Math.min(this.y, t);
  545.     this.width = Math.max(this.x + this.width, e) - n;
  546.     this.height = Math.max(this.y + this.height, t) - r;
  547.     this.x = n;
  548.     this.y = r
  549. };
  550. Rectangle.prototype._setP = function (e, t) {
  551.     this.x = e;
  552.     this.y = t;
  553.     this.width = this.height = 0
  554. };
  555. Rectangle.prototype._setAndTransform = function (e, t) {
  556.     var n = Rectangle._temp;
  557.     var r = mat4.multiplyVec2;
  558.     n[0] = e.x;
  559.     n[1] = e.y;
  560.     r(t, n);
  561.     this._setP(n[0], n[1]);
  562.     n[0] = e.x + e.width;
  563.     n[1] = e.y;
  564.     r(t, n);
  565.     this._unionWP(n[0], n[1]);
  566.     n[0] = e.x;
  567.     n[1] = e.y + e.height;
  568.     r(t, n);
  569.     this._unionWP(n[0], n[1]);
  570.     n[0] = e.x + e.width;
  571.     n[1] = e.y + e.height;
  572.     r(t, n);
  573.     this._unionWP(n[0], n[1])
  574. };
  575. Transform.prototype._getTMat = function () {
  576.     var e = this._obj;
  577.     var t = this._tmat;
  578.     this._checkMat();
  579.     t[12] = e.x;
  580.     t[13] = e.y;
  581.     t[14] = e.z;
  582.     return t
  583. };
  584. Transform.prototype._getIMat = function () {
  585.     mat4.inverse(this._getTMat(), this._imat);
  586.     return this._imat
  587. };
  588. Transform.prototype._valsToMat = function () {
  589.     var e = this._tmat;
  590.     var t = this._scaleX;
  591.     var n = this._scaleY;
  592.     var r = this._scaleZ;
  593.     var i = -.01745329252;
  594.     var s = this._rotationX * i;
  595.     var o = this._rotationY * i;
  596.     var u = this._rotationZ * i;
  597.     var a = Math.cos(s),
  598.         f = Math.cos(o),
  599.         l = Math.cos(u);
  600.     var c = Math.sin(s),
  601.         h = Math.sin(o),
  602.         p = Math.sin(u);
  603.     e[0] = f * l * t;
  604.     e[1] = -f * p * t;
  605.     e[2] = h * t;
  606.     e[4] = (a * p + c * h * l) * n;
  607.     e[5] = (a * l - c * h * p) * n;
  608.     e[6] = -c * f * n;
  609.     e[8] = (c * p - a * h * l) * r;
  610.     e[9] = (c * l + a * h * p) * r;
  611.     e[10] = a * f * r
  612. };
  613. Transform.prototype._matToVals = function () {
  614.     var e = this._tmat;
  615.     var t = e[0],
  616.         n = e[1],
  617.         r = e[2],
  618.         i = e[4],
  619.         s = e[5],
  620.         o = e[6],
  621.         u = e[8],
  622.         a = e[9],
  623.         f = e[10];
  624.     this._scaleX = Math.sqrt(t * t + n * n + r * r);
  625.     this._scaleY = Math.sqrt(i * i + s * s + o * o);
  626.     this._scaleZ = Math.sqrt(u * u + a * a + f * f);
  627.     var l = 1 / this._scaleX,
  628.         c = 1 / this._scaleY,
  629.         h = 1 / this._scaleZ;
  630.     t *= l;
  631.     n *= l;
  632.     r *= l;
  633.     i *= c;
  634.     s *= c;
  635.     o *= c;
  636.     u *= h;
  637.     a *= h;
  638.     f *= h;
  639.     var p = -57.29577951308;
  640.     this._rotationX = p * Math.atan2(-o, f);
  641.     this._rotationY = p * Math.atan2(r, Math.sqrt(o * o + f * f));
  642.     this._rotationZ = p * Math.atan2(-n, t)
  643. };
  644. Transform.prototype._checkVals = function () {
  645.     if (this._vdirty) {
  646.         this._matToVals();
  647.         this._vdirty = false
  648.     }
  649. };
  650. Transform.prototype._checkMat = function () {
  651.     if (this._mdirty) {
  652.         this._valsToMat();
  653.         this._mdirty = false
  654.     }
  655. };
  656. Transform.prototype._setOPos = function (e) {
  657.     var e = this._tmat;
  658.     this._obj.x = e[12];
  659.     this._obj.y = e[13];
  660.     this._obj.z = e[14]
  661. };
  662. Transform.prototype._checkColorID = function () {
  663.     var e = this._cmat;
  664.     var t = this._cvec;
  665.     this._cID = e[15] == 1 && e[0] == 1 && e[1] == 0 && e[2] == 0 && e[3] == 0 && e[4] == 0 && e[5] == 1 && e[6] == 0 && e[7] == 0 && e[8] == 0 && e[9] == 0 && e[10] == 1 && e[11] == 0 && e[12] == 0 && e[13] == 0 && e[14] == 0 && e[15] == 1 && t[0] == 0 && t[1] == 0 && t[2] == 0 && t[3] == 0
  666. };
  667. Transform.prototype._setMat3 = function (e) {
  668.     var t = this._tmat;
  669.     t[0] = e[0];
  670.     t[1] = e[1];
  671.     t[4] = e[3];
  672.     t[5] = e[4];
  673.     t[12] = e[6];
  674.     t[13] = e[7]
  675. };
  676. Transform.prototype._getMat3 = function (e) {
  677.     var t = this._tmat;
  678.     e[0] = t[0];
  679.     e[1] = t[1];
  680.     e[3] = t[4];
  681.     e[4] = t[5];
  682.     e[6] = t[12];
  683.     e[7] = t[13]
  684. };
  685. Transform.prototype._setCMat5 = function (e) {
  686.     var t = this._cmat,
  687.         n = this._cvec;
  688.     for (var r = 0; r < 4; r++) {
  689.         n[r] = e[20 + r];
  690.         for (var i = 0; i < 4; i++) t[4 * r + i] = e[5 * r + i]
  691.     }
  692. };
  693. Transform.prototype._getCMat5 = function (e) {
  694.     var t = this._cmat,
  695.         n = this._cvec;
  696.     e[24] = 1;
  697.     for (var r = 0; r < 4; r++) {
  698.         e[20 + r] = n[r];
  699.         for (var i = 0; i < 4; i++) e[5 * r + i] = t[4 * r + i]
  700.     }
  701. };
  702. Transform.prototype.__defineSetter__("matrix", function (e) {
  703.     this._checkMat();
  704.     this._setMat3(e);
  705.     this._setOPos();
  706.     this._vdirty = true
  707. });
  708. Transform.prototype.__defineGetter__("matrix", function () {
  709.     this._checkMat();
  710.     var e = new Float32Array(9);
  711.     this._getMat3(e);
  712.     return e
  713. });
  714. Transform.prototype.__defineSetter__("matrix3D", function (e) {
  715.     this._checkMat();
  716.     mat4.set(e, this._tmat);
  717.     this._setOPos();
  718.     this._vdirty = true
  719. });
  720. Transform.prototype.__defineGetter__("matrix3D", function () {
  721.     this._checkMat();
  722.     return mat4.create(this._getTMat())
  723. });
  724. Transform.prototype.__defineSetter__("colorTransform", function (e) {
  725.     this._setCMat5(e);
  726.     this._checkColorID()
  727. });
  728. Transform.prototype.__defineGetter__("colorTransform", function () {
  729.     var e = new Float32Array(25);
  730.     this._getCMat5(e);
  731.     return e
  732. });
  733. EventDispatcher.efbc = [];
  734. EventDispatcher.prototype.hasEventListener = function (e) {
  735.     var t = this.lsrs[e];
  736.     if (t == null) return false;
  737.     return t.length > 0
  738. };
  739. EventDispatcher.prototype.addEventListener = function (e, t) {
  740.     this.addEventListener2(e, t, null)
  741. };
  742. EventDispatcher.prototype.addEventListener2 = function (e, t, n) {
  743.     if (this.lsrs[e] == null) {
  744.         this.lsrs[e] = [];
  745.         this.cals[e] = []
  746.     }
  747.     this.lsrs[e].push(t);
  748.     this.cals[e].push(n);
  749.     if (e == Event.ENTER_FRAME) {
  750.         var r = EventDispatcher.efbc;
  751.         if (r.indexOf(this) < 0) r.push(this)
  752.     }
  753. };
  754. EventDispatcher.prototype.removeEventListener = function (e, t) {
  755.     var n = this.lsrs[e];
  756.     if (n == null) return;
  757.     var r = n.indexOf(t);
  758.     if (r < 0) return;
  759.     var i = this.cals[e];
  760.     n.splice(r, 1);
  761.     i.splice(r, 1);
  762.     if (e == Event.ENTER_FRAME && n.length == 0) {
  763.         var s = EventDispatcher.efbc;
  764.         s.splice(s.indexOf(this), 1)
  765.     }
  766. };
  767. EventDispatcher.prototype.dispatchEvent = function (e) {
  768.     var t = this.lsrs[e.type];
  769.     if (t == null) return;
  770.     var n = this.cals[e.type];
  771.     for (var r = 0; r < t.length; r++) {
  772.         e.currentTarget = this;
  773.         if (e.target == null) e.target = this;
  774.         if (n[r] == null) t[r](e);
  775.         else t[r].call(n[r], e)
  776.     }
  777. };
  778. Event.ENTER_FRAME = "enterFrame";
  779. Event.RESIZE = "resize";
  780. Event.ADDED_TO_STAGE = "addedToStage";
  781. Event.REMOVED_FROM_STAGE = "removedFromStage";
  782. Event.CHANGE = "change";
  783. Event.OPEN = "open";
  784. Event.PROGRESS = "progress";
  785. Event.COMPLETE = "complete";
  786. MouseEvent.prototype = new Event;
  787. MouseEvent.CLICK = "click";
  788. MouseEvent.MOUSE_MOVE = "mouseMove";
  789. MouseEvent.MOUSE_DOWN = "mouseDown";
  790. MouseEvent.MOUSE_UP = "mouseUp";
  791. MouseEvent.MOUSE_OVER = "mouseOver";
  792. MouseEvent.MOUSE_OUT = "mouseOut";
  793. MouseEvent.MIDDLE_CLICK = "middleClick";
  794. MouseEvent.MIDDLE_MOUSE_DOWN = "middleMouseDown";
  795. MouseEvent.MIDDLE_MOUSE_UP = "middleMouseUp";
  796. MouseEvent.RIGHT_CLICK = "rightClick";
  797. MouseEvent.RIGHT_MOUSE_DOWN = "rightMouseDown";
  798. MouseEvent.RIGHT_MOUSE_UP = "rightMouseUp";
  799. KeyboardEvent.prototype = new Event;
  800. KeyboardEvent.prototype._setFromDom = function (e) {
  801.     this.altKey = e.altKey;
  802.     this.ctrlKey = e.ctrlKey;
  803.     this.shiftKey = e.ShiftKey;
  804.     this.keyCode = e.keyCode;
  805.     this.charCode = e.charCode
  806. };
  807. KeyboardEvent.KEY_DOWN = "keyDown";
  808. KeyboardEvent.KEY_UP = "keyUp";
  809. var BlendMode = {
  810.     NORMAL: "normal",
  811.     ADD: "add",
  812.     SUBTRACT: "subtract",
  813.     MULTIPLY: "multiply",
  814.     SCREEN: "screen",
  815.     ERASE: "erase",
  816.     ALPHA: "alpha"
  817. };
  818. DisplayObject.prototype = new EventDispatcher;
  819. DisplayObject.prototype.dispatchEvent = function (e) {
  820.     EventDispatcher.prototype.dispatchEvent.call(this, e);
  821.     if (e.bubbles && this.parent != null) this.parent.dispatchEvent(e)
  822. };
  823. DisplayObject.prototype.globalToLocal = function (e) {
  824.     var t = this._temp;
  825.     t[0] = e.x;
  826.     t[1] = e.y;
  827.     mat4.multiplyVec2(this._getAIMat(), t);
  828.     return new Point(t[0], t[1])
  829. };
  830. DisplayObject.prototype.localToGlobal = function (e) {
  831.     var t = this._temp;
  832.     t[0] = e.x;
  833.     t[1] = e.y;
  834.     mat4.multiplyVec2(this._getATMat(), t);
  835.     return new Point(t[0], t[1])
  836. };
  837. DisplayObject.prototype.hitTestPoint = function (e) {
  838.     var t = this._temp2;
  839.     t[0] = e.x;
  840.     t[1] = e.y;
  841.     mat4.multiplyVec2(this._getAIMat(), t);
  842.     mat4.multiplyVec2(this.transform._getTMat(), t);
  843.     return this._htpLocal(t)
  844. };
  845. DisplayObject.prototype.hitTestObject = function (e) {
  846.     var t = this._getRect(false);
  847.     var n = e._getRect(false);
  848.     if (!t || !n) return false;
  849.     var r = this._getATMat();
  850.     var i = e._getATMat();
  851.     var s = t.clone(),
  852.         o = n.clone();
  853.     s._setAndTransform(t, r);
  854.     o._setAndTransform(n, i);
  855.     return s.intersects(o)
  856. };
  857. DisplayObject.prototype.getRect = function (e) {
  858.     return this._makeRect(false, e)
  859. };
  860. DisplayObject.prototype.getBounds = function (e) {
  861.     return this._makeRect(true, e)
  862. };
  863. DisplayObject.prototype._makeRect = function (e, t) {
  864.     var n = this._getRect(e);
  865.     var r = this._tempm;
  866.     mat4.multiply(this._getATMat(), t._getAIMat(), r);
  867.     var i = new Rectangle(6710886.4, 6710886.4, 0, 0);
  868.     if (n) i._setAndTransform(n, r);
  869.     return i
  870. };
  871. DisplayObject.prototype._htpLocal = function (e) {
  872.     var t = this._temp;
  873.     mat4.multiplyVec2(this.transform._getIMat(), e, t);
  874.     var n = this._getRect();
  875.     if (n == null) return false;
  876.     return n.contains(t[0], t[1])
  877. };
  878. DisplayObject.prototype._moveMouse = function (e, t, n) {
  879.     return null
  880. };
  881. DisplayObject.prototype._getRect = function (e) {
  882.     return this._brect
  883. };
  884. DisplayObject.prototype._setStage = function (e) {
  885.     var t = this.stage;
  886.     this.stage = e;
  887.     if (t == null && e != null) this.dispatchEvent(this._atsEv);
  888.     if (t != null && e == null) this.dispatchEvent(this._rfsEv)
  889. };
  890. DisplayObject.prototype._preRender = function (e) {
  891.     var t = this.transform._getTMat();
  892.     e._mstack.push(t);
  893.     e._cmstack.push(this.transform._cmat, this.transform._cvec, this.transform._cID, this.blendMode)
  894. };
  895. DisplayObject.prototype._render = function (e) {};
  896. DisplayObject.prototype._renderAll = function (e) {
  897.     if (!this.visible) return;
  898.     this._preRender(e);
  899.     this._render(e);
  900.     e._mstack.pop();
  901.     e._cmstack.pop()
  902. };
  903. DisplayObject.prototype._getATMat = function () {
  904.     if (this.parent == null) return this.transform._getTMat();
  905.     mat4.multiply(this.parent.transform._getTMat(), this.transform._getTMat(), this.transform._atmat);
  906.     return this.transform._atmat
  907. };
  908. DisplayObject.prototype._getAIMat = function () {
  909.     if (this.parent == null) return this.transform._getIMat();
  910.     mat4.multiply(this.transform._getIMat(), this.parent._getAIMat(), this.transform._aimat);
  911.     return this.transform._aimat
  912. };
  913. DisplayObject.prototype._getMouse = function () {
  914.     var e = this._temp;
  915.     e[0] = Stage._mouseX;
  916.     e[1] = Stage._mouseY;
  917.     mat4.multiplyVec2(this._getAIMat(), e);
  918.     return e
  919. };
  920. this.dp = DisplayObject.prototype;
  921. dp.ds = dp.__defineSetter__;
  922. dp.dg = dp.__defineGetter__;
  923. dp.ds("scaleX", function (e) {
  924.     this.transform._checkVals();
  925.     this.transform._scaleX = e;
  926.     this.transform._mdirty = true
  927. });
  928. dp.ds("scaleY", function (e) {
  929.     this.transform._checkVals();
  930.     this.transform._scaleY = e;
  931.     this.transform._mdirty = true
  932. });
  933. dp.ds("scaleZ", function (e) {
  934.     this.transform._checkVals();
  935.     this.transform._scaleZ = e;
  936.     this.transform._mdirty = true
  937. });
  938. dp.dg("scaleX", function () {
  939.     this.transform._checkVals();
  940.     return this.transform._scaleX
  941. });
  942. dp.dg("scaleY", function () {
  943.     this.transform._checkVals();
  944.     return this.transform._scaleY
  945. });
  946. dp.dg("scaleZ", function () {
  947.     this.transform._checkVals();
  948.     return this.transform._scaleZ
  949. });
  950. dp.ds("rotationX", function (e) {
  951.     this.transform._checkVals();
  952.     this.transform._rotationX = e;
  953.     this.transform._mdirty = true
  954. });
  955. dp.ds("rotationY", function (e) {
  956.     this.transform._checkVals();
  957.     this.transform._rotationY = e;
  958.     this.transform._mdirty = true
  959. });
  960. dp.ds("rotationZ", function (e) {
  961.     this.transform._checkVals();
  962.     this.transform._rotationZ = e;
  963.     this.transform._mdirty = true
  964. });
  965. dp.ds("rotation", function (e) {
  966.     this.transform._checkVals();
  967.     this.transform._rotationZ = e;
  968.     this.transform._mdirty = true
  969. });
  970. dp.dg("rotationX", function () {
  971.     this.transform._checkVals();
  972.     return this.transform._rotationX
  973. });
  974. dp.dg("rotationY", function () {
  975.     this.transform._checkVals();
  976.     return this.transform._rotationY
  977. });
  978. dp.dg("rotationZ", function () {
  979.     this.transform._checkVals();
  980.     return this.transform._rotationZ
  981. });
  982. dp.dg("rotation", function () {
  983.     this.transform._checkVals();
  984.     return this.transform._rotationZ
  985. });
  986. dp.ds("alpha", function (e) {
  987.     this.transform._cmat[15] = e;
  988.     this.transform._checkColorID()
  989. });
  990. dp.dg("alpha", function () {
  991.     return this.transform._cmat[15]
  992. });
  993. dp.dg("mouseX", function () {
  994.     return this._getMouse()[0]
  995. });
  996. dp.dg("mouseY", function () {
  997.     return this._getMouse()[1]
  998. });
  999. delete dp.ds;
  1000. delete dp.dg;
  1001. delete this.dp;
  1002. InteractiveObject.prototype = new DisplayObject;
  1003. InteractiveObject.prototype._moveMouse = function (e, t, n) {
  1004.     if (!n || !this.visible || !this.mouseEnabled) return null;
  1005.     var r = this._getRect();
  1006.     if (r == null) return null;
  1007.     var i = this._temp;
  1008.     i[0] = e;
  1009.     i[1] = t;
  1010.     mat4.multiplyVec2(this.transform._getIMat(), i);
  1011.     if (r.contains(i[0], i[1])) return this;
  1012.     return null
  1013. };
  1014. DisplayObjectContainer.prototype = new InteractiveObject;
  1015. DisplayObjectContainer.prototype.addChild = function (e) {
  1016.     this._children.push(e);
  1017.     e.parent = this;
  1018.     e._setStage(this.stage);
  1019.     ++this.numChildren
  1020. };
  1021. DisplayObjectContainer.prototype.removeChild = function (e) {
  1022.     var t = this._children.indexOf(e);
  1023.     this._children.splice(t, 1);
  1024.     e.parent = null;
  1025.     e._setStage(null);
  1026.     --this.numChildren
  1027. };
  1028. DisplayObjectContainer.prototype.removeChildAt = function (e) {
  1029.     this.removeChild(this._children[e])
  1030. };
  1031. DisplayObjectContainer.prototype.contains = function (e) {
  1032.     return this._children.indexOf(e) >= 0
  1033. };
  1034. DisplayObjectContainer.prototype.getChildIndex = function (e) {
  1035.     return this._children.indexOf(e)
  1036. };
  1037. DisplayObjectContainer.prototype.setChildIndex = function (e, t) {
  1038.     var n = this._children.indexOf(e);
  1039.     if (t > n) {
  1040.         for (var r = n + 1; r <= t; r++) this._children[r - 1] = this._children[r];
  1041.         this._children[t] = e
  1042.     } else if (t < n) {
  1043.         for (var r = n - 1; r >= t; r--) this._children[r + 1] = this._children[r];
  1044.         this._children[t] = e
  1045.     }
  1046. };
  1047. DisplayObjectContainer.prototype.getChildAt = function (e) {
  1048.     return this._children[e]
  1049. };
  1050. DisplayObjectContainer.prototype._render = function (e) {
  1051.     for (var t = 0; t < this.numChildren; t++) this._children[t]._renderAll(e)
  1052. };
  1053. DisplayObjectContainer.prototype._moveMouse = function (e, t, n) {
  1054.     if (!n || !this.visible || !this.mouseChildren && !this.mouseEnabled) return null;
  1055.     var r = this._temp;
  1056.     r[0] = e;
  1057.     r[1] = t;
  1058.     mat4.multiplyVec2(this.transform._getIMat(), r);
  1059.     var i = r[0],
  1060.         s = r[1];
  1061.     var o = n;
  1062.     var u = null;
  1063.     var a = this.numChildren - 1;
  1064.     for (var f = a; f > -1; f--) {
  1065.         var l = this._children[f]._moveMouse(i, s, o);
  1066.         if (l != null) {
  1067.             u = l;
  1068.             break
  1069.         }
  1070.     }
  1071.     if (!this.mouseChildren && u != null) return this;
  1072.     return u
  1073. };
  1074. DisplayObjectContainer.prototype._htpLocal = function (e) {
  1075.     var t = this._temp;
  1076.     mat4.multiplyVec2(this.transform._getIMat(), e, t);
  1077.     var n = this._children.length;
  1078.     for (var r = 0; r < n; r++) {
  1079.         var i = this._children[r];
  1080.         if (i.visible)
  1081.             if (i._htpLocal(t)) return true
  1082.     }
  1083.     return false
  1084. };
  1085. DisplayObjectContainer.prototype._setStage = function (e) {
  1086.     InteractiveObject.prototype._setStage.call(this, e);
  1087.     for (var t = 0; t < this.numChildren; t++) this._children[t]._setStage(e)
  1088. };
  1089. DisplayObjectContainer.prototype._getRect = function (e) {
  1090.     if (this.numChildren == 0) return null;
  1091.     var t = null;
  1092.     var n = this._brect2;
  1093.     for (var r = 0; r < this.numChildren; r++) {
  1094.         var i = this._children[r];
  1095.         var s = i._getRect(e);
  1096.         if (!i.visible || s == null) continue;
  1097.         if (t == null) {
  1098.             t = this._brect;
  1099.             t._setAndTransform(s, i.transform._getTMat())
  1100.         } else {
  1101.             n._setAndTransform(s, i.transform._getTMat());
  1102.             t._unionWith(n)
  1103.         }
  1104.     }
  1105.     return t
  1106. };
  1107. BitmapData.empty = function (e, t) {
  1108.     var n = new BitmapData(null);
  1109.     n._initFromImg(null, e, t);
  1110.     return n
  1111. };
  1112. BitmapData.prototype.setPixels = function (e, t) {
  1113.     Stage._setTEX(this._texture);
  1114.     gl.texSubImage2D(gl.TEXTURE_2D, 0, e.x, e.y, e.width, e.height, gl.RGBA, gl.UNSIGNED_BYTE, t);
  1115.     gl.generateMipmap(gl.TEXTURE_2D)
  1116. };
  1117. BitmapData.prototype.getPixels = function (e, t) {
  1118.     if (!t) t = new Uint8Array(e.width * e.height * 4);
  1119.     this._setTexAsFB();
  1120.     gl.readPixels(e.x, e.y, e.width, e.height, gl.RGBA, gl.UNSIGNED_BYTE, t);
  1121.     Stage._main._setFramebuffer(null, Stage._main.stageWidth, Stage._main.stageHeight, false);
  1122.     return t
  1123. };
  1124. BitmapData.prototype.draw = function (e) {
  1125.     this._setTexAsFB();
  1126.     e._render(Stage._main);
  1127.     Stage._main._setFramebuffer(null, Stage._main.stageWidth, Stage._main.stageHeight, false);
  1128.     Stage._setTEX(this._texture);
  1129.     gl.generateMipmap(gl.TEXTURE_2D)
  1130. };
  1131. BitmapData.prototype._setTexAsFB = function () {
  1132.     if (BitmapData._fbo == null) BitmapData._fbo = gl.createFramebuffer();
  1133.     Stage._main._setFramebuffer(BitmapData._fbo, this.width, this.height, true);
  1134.     gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this._texture, 0)
  1135. };
  1136. BitmapData.prototype._initFromImg = function (e, t, n) {
  1137.     this._loaded = true;
  1138.     this.width = t;
  1139.     this.height = n;
  1140.     this._rwidth = BitmapData._nhpot(t);
  1141.     this._rheight = BitmapData._nhpot(n);
  1142.     this.rect = new Rectangle(0, 0, t, n);
  1143.     var r = t / this._rwidth;
  1144.     var i = n / this._rheight;
  1145.     Stage._setBF(this._tcBuffer);
  1146.     gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([0, 0, r, 0, 0, i, r, i]), gl.STATIC_DRAW);
  1147.     Stage._setBF(this._vBuffer);
  1148.     gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([0, 0, 0, t, 0, 0, 0, n, 0, t, n, 0]), gl.STATIC_DRAW);
  1149.     var s = BitmapData._canv;
  1150.     s.width = this._rwidth;
  1151.     s.height = this._rheight;
  1152.     var o = BitmapData._ctx;
  1153.     if (e != null) o.drawImage(e, 0, 0);
  1154.     var u = o.getImageData(0, 0, this._rwidth, this._rheight);
  1155.     Stage._setTEX(this._texture);
  1156.     gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, u);
  1157.     gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
  1158.     gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR);
  1159.     gl.generateMipmap(gl.TEXTURE_2D)
  1160. };
  1161. BitmapData._canv = document.createElement("canvas");
  1162. BitmapData._ctx = BitmapData._canv.getContext("2d");
  1163. BitmapData._ipot = function (e) {
  1164.     return (e & e - 1) == 0
  1165. };
  1166. BitmapData._nhpot = function (e) {
  1167.     --e;
  1168.     for (var t = 1; t < 32; t <<= 1) e = e | e >> t;
  1169.     return e + 1
  1170. };
  1171. Bitmap.prototype = new InteractiveObject;
  1172. Bitmap.prototype._getRect = function () {
  1173.     return this.bitmapData.rect
  1174. };
  1175. Bitmap.prototype._render = function (e) {
  1176.     var t = this.bitmapData;
  1177.     if (!t._loaded) return;
  1178.     gl.uniformMatrix4fv(e._sprg.tMatUniform, false, e._mstack.top());
  1179.     e._cmstack.update();
  1180.     Stage._setVC(t._vBuffer);
  1181.     Stage._setTC(t._tcBuffer);
  1182.     Stage._setUT(1);
  1183.     Stage._setTEX(t._texture);
  1184.     Stage._setEBF(e._unitIBuffer);
  1185.     gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0)
  1186. };
  1187. var gl;
  1188. Stage.prototype = new DisplayObjectContainer;
  1189. Stage._mouseX = 0;
  1190. Stage._mouseY = 0;
  1191. Stage._curBF = null;
  1192. Stage._curEBF = null;
  1193. Stage._curVC = null;
  1194. Stage._curTC = null;
  1195. Stage._curUT = -1;
  1196. Stage._curTEX = null;
  1197. Stage._curBMD = "normal";
  1198. Stage._setBF = function (e) {
  1199.     if (Stage._curBF != e) {
  1200.         gl.bindBuffer(gl.ARRAY_BUFFER, e);
  1201.         Stage._curBF = e
  1202.     }
  1203. };
  1204. Stage._setEBF = function (e) {
  1205.     if (Stage._curEBF != e) {
  1206.         gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, e);
  1207.         Stage._curEBF = e
  1208.     }
  1209. };
  1210. Stage._setVC = function (e) {
  1211.     if (Stage._curVC != e) {
  1212.         gl.bindBuffer(gl.ARRAY_BUFFER, e);
  1213.         gl.vertexAttribPointer(Stage._main._sprg.vpa, 3, gl.FLOAT, false, 0, 0);
  1214.         Stage._curVC = Stage._curBF = e
  1215.     }
  1216. };
  1217. Stage._setTC = function (e) {
  1218.     if (Stage._curTC != e) {
  1219.         gl.bindBuffer(gl.ARRAY_BUFFER, e);
  1220.         gl.vertexAttribPointer(Stage._main._sprg.tca, 2, gl.FLOAT, false, 0, 0);
  1221.         Stage._curTC = Stage._curBF = e
  1222.     }
  1223. };
  1224. Stage._setUT = function (e) {
  1225.     if (Stage._curUT != e) {
  1226.         gl.uniform1i(Stage._main._sprg.useTex, e);
  1227.         Stage._curUT = e
  1228.     }
  1229. };
  1230. Stage._setTEX = function (e) {
  1231.     if (Stage._curTEX != e) {
  1232.         gl.bindTexture(gl.TEXTURE_2D, e);
  1233.         Stage._curTEX = e
  1234.     }
  1235. };
  1236. Stage._setBMD = function (e) {
  1237.     if (Stage._curBMD != e) {
  1238.         if (e == BlendMode.NORMAL) {
  1239.             gl.blendEquation(gl.FUNC_ADD);
  1240.             gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA)
  1241.         } else if (e == BlendMode.MULTIPLY) {
  1242.             gl.blendEquation(gl.FUNC_ADD);
  1243.             gl.blendFunc(gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA)
  1244.         } else if (e == BlendMode.ADD) {
  1245.             gl.blendEquation(gl.FUNC_ADD);
  1246.             gl.blendFunc(gl.ONE, gl.ONE)
  1247.         } else if (e == BlendMode.SUBTRACT) {
  1248.             gl.blendEquationSeparate(gl.FUNC_REVERSE_SUBTRACT, gl.FUNC_ADD);
  1249.             gl.blendFunc(gl.ONE, gl.ONE)
  1250.         } else if (e == BlendMode.SCREEN) {
  1251.             gl.blendEquation(gl.FUNC_ADD);
  1252.             gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_COLOR)
  1253.         } else if (e == BlendMode.ERASE) {
  1254.             gl.blendEquation(gl.FUNC_ADD);
  1255.             gl.blendFunc(gl.ZERO, gl.ONE_MINUS_SRC_ALPHA)
  1256.         } else if (e == BlendMode.ALPHA) {
  1257.             gl.blendEquation(gl.FUNC_ADD);
  1258.             gl.blendFunc(gl.ZERO, gl.SRC_ALPHA)
  1259.         }
  1260.         Stage._curBMD = e
  1261.     }
  1262. };
  1263. Stage._okKeys = [112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 13, 16, 18, 27];
  1264. Stage._isTD = function () {
  1265.     return !!("ontouchstart" in window)
  1266. };
  1267. Stage._ctxt = function (e) {
  1268.     if (Stage._main.hasEventListener(MouseEvent.RIGHT_CLICK)) e.preventDefault()
  1269. };
  1270. Stage._onTD = function (e) {
  1271.     Stage._setStageMouse(e);
  1272.     Stage._main._smd[0] = true;
  1273.     Stage._main._knM = true
  1274. };
  1275. Stage._onTM = function (e) {
  1276.     Stage._setStageMouse(e);
  1277.     Stage._main._smm = true;
  1278.     Stage._main._knM = true
  1279. };
  1280. Stage._onTU = function (e) {
  1281.     Stage._main._smu[0] = true;
  1282.     Stage._main._knM = true
  1283. };
  1284. Stage._onMD = function (e) {
  1285.     Stage._setStageMouse(e);
  1286.     Stage._main._smd[e.button] = true;
  1287.     Stage._main._knM = true
  1288. };
  1289. Stage._onMM = function (e) {
  1290.     Stage._setStageMouse(e);
  1291.     Stage._main._smm = true;
  1292.     Stage._main._knM = true
  1293. };
  1294. Stage._onMU = function (e) {
  1295.     Stage._main._smu[e.button] = true;
  1296.     Stage._main._knM = true
  1297. };
  1298. Stage._onKD = function (e) {
  1299.     var t = Stage._main;
  1300.     t._kdEv._setFromDom(e);
  1301.     if (t.focus && t.focus.stage) t.focus.dispatchEvent(t._kdEv);
  1302.     else t.dispatchEvent(t._kdEv)
  1303. };
  1304. Stage._onKU = function (e) {
  1305.     var t = Stage._main;
  1306.     t._kuEv._setFromDom(e);
  1307.     if (t.focus && t.focus.stage) t.focus.dispatchEvent(t._kuEv);
  1308.     else t.dispatchEvent(t._kuEv)
  1309. };
  1310. Stage._blck = function (e) {
  1311.     if (e.keyCode != null) {
  1312.         if (Stage._okKeys.indexOf(e.keyCode) == -1) e.preventDefault()
  1313.     } else e.preventDefault()
  1314. };
  1315. Stage._onRS = function (e) {
  1316.     Stage._main._srs = true
  1317. };
  1318. Stage.prototype._resize = function () {
  1319.     var e = window.innerWidth;
  1320.     var t = window.innerHeight;
  1321.     this.stageWidth = e;
  1322.     this.stageHeight = t;
  1323.     this._canvas.width = e;
  1324.     this._canvas.height = t;
  1325.     this._setFramebuffer(null, e, t, false)
  1326. };
  1327. Stage.prototype._getShader = function (e, t, n) {
  1328.     var r;
  1329.     if (n) r = e.createShader(e.FRAGMENT_SHADER);
  1330.     else r = e.createShader(e.VERTEX_SHADER);
  1331.     e.shaderSource(r, t);
  1332.     e.compileShader(r);
  1333.     if (!e.getShaderParameter(r, e.COMPILE_STATUS)) {
  1334.         alert(e.getShaderInfoLog(r));
  1335.         return null
  1336.     }
  1337.     return r
  1338. };
  1339. Stage.prototype._initShaders = function () {
  1340.     var e = "           precision mediump float;            varying vec2 texCoord;                      uniform sampler2D uSampler;         uniform vec4 color;         uniform bool useTex;                        uniform mat4 cMat;          uniform vec4 cVec;                      void main(void) {               vec4 c = useTex ? texture2D(uSampler, texCoord) : color;                c = (cMat*c)+cVec;\n                c.xyz *= c.w;\n             gl_FragColor = c;           }";
  1341.     var t = "           attribute vec3 verPos;          attribute vec2 texPos;                      uniform mat4 tMat;                      varying vec2 texCoord;                      void main(void) {               gl_Position = tMat * vec4(verPos, 1.0);             texCoord = texPos;          }";
  1342.     var n = this._getShader(gl, e, true);
  1343.     var r = this._getShader(gl, t, false);
  1344.     this._sprg = gl.createProgram();
  1345.     gl.attachShader(this._sprg, r);
  1346.     gl.attachShader(this._sprg, n);
  1347.     gl.linkProgram(this._sprg);
  1348.     if (!gl.getProgramParameter(this._sprg, gl.LINK_STATUS)) {
  1349.         alert("Could not initialise shaders")
  1350.     }
  1351.     gl.useProgram(this._sprg);
  1352.     this._sprg.vpa = gl.getAttribLocation(this._sprg, "verPos");
  1353.     this._sprg.tca = gl.getAttribLocation(this._sprg, "texPos");
  1354.     gl.enableVertexAttribArray(this._sprg.tca);
  1355.     gl.enableVertexAttribArray(this._sprg.vpa);
  1356.     this._sprg.tMatUniform = gl.getUniformLocation(this._sprg, "tMat");
  1357.     this._sprg.cMatUniform = gl.getUniformLocation(this._sprg, "cMat");
  1358.     this._sprg.cVecUniform = gl.getUniformLocation(this._sprg, "cVec");
  1359.     this._sprg.samplerUniform = gl.getUniformLocation(this._sprg, "uSampler");
  1360.     this._sprg.useTex = gl.getUniformLocation(this._sprg, "useTex");
  1361.     this._sprg.color = gl.getUniformLocation(this._sprg, "color")
  1362. };
  1363. Stage.prototype._initBuffers = function () {
  1364.     this._unitIBuffer = gl.createBuffer();
  1365.     Stage._setEBF(this._unitIBuffer);
  1366.     gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array([0, 1, 2, 1, 2, 3]), gl.STATIC_DRAW)
  1367. };
  1368. Stage.prototype._setFramebuffer = function (e, t, n, r) {
  1369.     this._mstack.clear();
  1370.     this._mstack.push(this._pmat, 0);
  1371.     if (r) {
  1372.         this._umat[5] = 2;
  1373.         this._umat[13] = -1
  1374.     } else {
  1375.         this._umat[5] = -2;
  1376.         this._umat[13] = 1
  1377.     }
  1378.     this._mstack.push(this._umat);
  1379.     this._smat[0] = 1 / t;
  1380.     this._smat[5] = 1 / n;
  1381.     this._mstack.push(this._smat);
  1382.     gl.bindFramebuffer(gl.FRAMEBUFFER, e);
  1383.     gl.viewport(0, 0, t, n)
  1384. };
  1385. Stage._setStageMouse = function (e) {
  1386.     var t = e;
  1387.     if (e.type == "touchstart" || e.type == "touchmove" || e.type == "touchend") t = e.touches.item(0);
  1388.     var n = t.clientX;
  1389.     var r = t.clientY;
  1390.     Stage._mouseX = n;
  1391.     Stage._mouseY = r
  1392. };
  1393. Stage.prototype._drawScene = function () {
  1394.     if (this._srs) {
  1395.         this._resize();
  1396.         this.dispatchEvent(this._rsEv);
  1397.         this._srs = false
  1398.     }
  1399.     gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
  1400.     if (this._knM) {
  1401.         var e = this._moveMouse(Stage._mouseX, Stage._mouseY, true);
  1402.         var t = this._mousefocus || this,
  1403.             n = e || this;
  1404.         if (e != this._mousefocus) {
  1405.             if (t != this) {
  1406.                 var r = this._mouEv;
  1407.                 r.target = t;
  1408.                 t.dispatchEvent(r)
  1409.             }
  1410.             if (n != this) {
  1411.                 r = this._movEv;
  1412.                 r.target = n;
  1413.                 n.dispatchEvent(r)
  1414.             }
  1415.         }
  1416.         var i = this._smd,
  1417.             s = this._smu;
  1418.         for (var o = 0; o < 3; o++) {
  1419.             this._mcEvs[o].target = this._mdEvs[o].target = this._muEvs[o].target = n;
  1420.             if (i[o]) {
  1421.                 n.dispatchEvent(this._mdEvs[o]);
  1422.                 this._focii[o] = this.focus = e
  1423.             }
  1424.             if (s[o]) {
  1425.                 n.dispatchEvent(this._muEvs[o]);
  1426.                 if (e == this._focii[o]) n.dispatchEvent(this._mcEvs[o])
  1427.             }
  1428.             i[o] = s[o] = false
  1429.         }
  1430.         this._mmoEv.target = n;
  1431.         if (this._smm) {
  1432.             n.dispatchEvent(this._mmoEv)
  1433.         }
  1434.         this._smm = false;
  1435.         this._mousefocus = e;
  1436.         var u = false,
  1437.             a = n;
  1438.         while (a.parent != null) {
  1439.             u |= a.buttonMode;
  1440.             a = a.parent
  1441.         }
  1442.         if (u != this._useHand) this._canvas.style.cursor = u ? "pointer" : "default";
  1443.         this._useHand = u
  1444.     }
  1445.     var f = EventDispatcher.efbc;
  1446.     var r = this._efEv;
  1447.     for (var o = 0; o < f.length; o++) {
  1448.         r.target = f[o];
  1449.         f[o].dispatchEvent(r)
  1450.     }
  1451.     this._renderAll(this)
  1452. };
  1453. Stage._tick = function () {
  1454.     _requestAF(Stage._tick);
  1455.     Stage.prototype._drawScene.call(Stage._main)
  1456. };
  1457. Stage._MStack = function () {
  1458.     this.mats = [];
  1459.     this.size = 1;
  1460.     for (var e = 0; e < 30; e++) this.mats.push(mat4.create())
  1461. };
  1462. Stage._MStack.prototype.clear = function () {
  1463.     this.size = 1
  1464. };
  1465. Stage._MStack.prototype.push = function (e) {
  1466.     var t = this.size++;
  1467.     mat4.multiply(this.mats[t - 1], e, this.mats[t])
  1468. };
  1469. Stage._MStack.prototype.pop = function () {
  1470.     this.size--
  1471. };
  1472. Stage._MStack.prototype.top = function () {
  1473.     return this.mats[this.size - 1]
  1474. };
  1475. Stage._CMStack = function () {
  1476.     this.mats = [];
  1477.     this.vecs = [];
  1478.     this.isID = [];
  1479.     this.bmds = [];
  1480.     this.lnnm = [];
  1481.     this.size = 1;
  1482.     this.dirty = true;
  1483.     for (var e = 0; e < 30; e++) {
  1484.         this.mats.push(mat4.create());
  1485.         this.vecs.push(new Float32Array(4));
  1486.         this.isID.push(true);
  1487.         this.bmds.push(BlendMode.NORMAL);
  1488.         this.lnnm.push(0)
  1489.     }
  1490. };
  1491. Stage._CMStack.prototype.push = function (e, t, n, r) {
  1492.     var i = this.size++;
  1493.     this.isID[i] = n;
  1494.     if (n) {
  1495.         mat4.set(this.mats[i - 1], this.mats[i]);
  1496.         vec4.set(this.vecs[i - 1], this.vecs[i])
  1497.     } else {
  1498.         mat4.multiply(this.mats[i - 1], e, this.mats[i]);
  1499.         mat4.multiplyVec4(this.mats[i - 1], t, this.vecs[i]);
  1500.         vec4.add(this.vecs[i - 1], this.vecs[i], this.vecs[i])
  1501.     } if (!n) this.dirty = true;
  1502.     this.bmds[i] = r;
  1503.     this.lnnm[i] = r == BlendMode.NORMAL ? this.lnnm[i - 1] : i
  1504. };
  1505. Stage._CMStack.prototype.update = function () {
  1506.     if (this.dirty) {
  1507.         var e = Stage._main,
  1508.             t = this.size - 1;
  1509.         gl.uniformMatrix4fv(e._sprg.cMatUniform, false, this.mats[t]);
  1510.         gl.uniform4fv(e._sprg.cVecUniform, this.vecs[t]);
  1511.         this.dirty = false
  1512.     }
  1513.     var n = this.lnnm[this.size - 1];
  1514.     Stage._setBMD(this.bmds[n])
  1515. };
  1516. Stage._CMStack.prototype.pop = function () {
  1517.     if (!this.isID[this.size - 1]) this.dirty = true;
  1518.     this.size--
  1519. };
  1520. Graphics.prototype._render = function (e) {
  1521.     gl.uniformMatrix4fv(e._sprg.tMatUniform, false, e._mstack.top());
  1522.     e._cmstack.update();
  1523.     if (this._ldirty) {
  1524.         Stage._setBF(this._lvbuf);
  1525.         gl.bufferSubData(gl.ARRAY_BUFFER, 0, this._lvval);
  1526.         this._ldirty = false
  1527.     }
  1528.     var t = this._elems;
  1529.     for (var n = 0; n < t.length; n++) t[n].render(e)
  1530. };
  1531. Graphics.prototype._sendLBuffers = function () {
  1532.     Stage._setBF(this._lvbuf);
  1533.     gl.bufferData(gl.ARRAY_BUFFER, this._lvval, gl.STATIC_DRAW)
  1534. };
  1535. Graphics.prototype._newLineSegment = function () {
  1536.     var e;
  1537.     if (this._duls.length == 0) e = new ULSegment(this._lused, this._clstyle.colARR, this._lvbuf);
  1538.     else {
  1539.         e = this._duls.pop();
  1540.         e.update(this._lused, this._clstyle.colARR)
  1541.     }
  1542.     this._uls.push(e);
  1543.     this._elems.push(e);
  1544.     return e
  1545. };
  1546. Graphics.prototype._checkLineAvail = function (e) {
  1547.     var t = this._ltotal;
  1548.     if (t - this._lused < e) {
  1549.         t = Math.max(t + e, 2 * t);
  1550.         var n = this._lvval;
  1551.         var r = new Float32Array(18 * t);
  1552.         for (var i = 0; i < n.length; i++) r[i] = n[i];
  1553.         this._ltotal = t;
  1554.         this._lvval = r;
  1555.         this._sendLBuffers()
  1556.     }
  1557. };
  1558. Graphics.prototype._putLine = function (e, t, n, r) {
  1559.     this._updateSBounds(e, t);
  1560.     this._updateSBounds(n, r);
  1561.     if (this._lsegment == null) this._lsegment = this._newLineSegment();
  1562.     this._checkLineAvail(1);
  1563.     var i = .5 * this._clstyle.thickness / this.len(e - n, t - r);
  1564.     var s = i * (t - r);
  1565.     var o = -i * (e - n);
  1566.     var u = this._lvval;
  1567.     var a = this._lused * 18;
  1568.     u[a++] = e + s;
  1569.     u[a++] = t + o;
  1570.     a++;
  1571.     u[a++] = e - s;
  1572.     u[a++] = t - o;
  1573.     a++;
  1574.     u[a++] = n + s;
  1575.     u[a++] = r + o;
  1576.     a++;
  1577.     u[a++] = e - s;
  1578.     u[a++] = t - o;
  1579.     a++;
  1580.     u[a++] = n + s;
  1581.     u[a++] = r + o;
  1582.     a++;
  1583.     u[a++] = n - s;
  1584.     u[a++] = r - o;
  1585.     a++;
  1586.     this._ldirty = true;
  1587.     this._lused++;
  1588.     this._lsegment.count++;
  1589.     this._empty = false
  1590. };
  1591. Graphics.prototype.lineStyle = function (e, t, n) {
  1592.     if (!t) t = 0;
  1593.     if (!n) n = 1;
  1594.     if (t != this._clstyle.color || n != this._clstyle.alpha) this._lsegment = null;
  1595.     this._clstyle.Set(e, t, n)
  1596. };
  1597. Graphics.prototype.beginFill = function (e, t) {
  1598.     this._ftype = 0;
  1599.     if (!t) t = 1;
  1600.     this._cfstyle.Set(e, t)
  1601. };
  1602. Graphics.prototype.beginBitmapFill = function (e) {
  1603.     this._ftype = 1;
  1604.     this._bdata = e
  1605. };
  1606. Graphics.prototype.endFill = function () {};
  1607. Graphics.prototype.moveTo = function (e, t) {
  1608.     this._px = e;
  1609.     this._py = t
  1610. };
  1611. Graphics.prototype.lineTo = function (e, t) {
  1612.     this._putLine(this._px, this._py, e, t);
  1613.     this._px = e;
  1614.     this._py = t
  1615. };
  1616. Graphics.prototype.len = function (e, t) {
  1617.     return Math.sqrt(e * e + t * t)
  1618. };
  1619. Graphics.prototype.curveTo = function (e, t, n, r) {
  1620.     var i = this._px,
  1621.         s = this._py,
  1622.         o = .666666;
  1623.     this.cubicCurveTo(i + o * (e - i), s + o * (t - s), n + o * (e - n), r + o * (t - r), n, r)
  1624. };
  1625. Graphics.prototype.cubicCurveTo = function (e, t, n, r, i, s) {
  1626.     this._checkLineAvail(40);
  1627.     if (this._lsegment == null) this._lsegment = this._newLineSegment();
  1628.     var o, u, a, f, l, c, h, p, d, v, m, g, y, b, w, E, S, x, T, N, C, k, L, A;
  1629.     var O = .5 * this._clstyle.thickness;
  1630.     var M, _, D, P, H;
  1631.     o = this._px;
  1632.     u = this._py;
  1633.     y = e - o;
  1634.     b = t - u;
  1635.     w = n - e;
  1636.     E = r - t;
  1637.     S = i - n;
  1638.     x = s - r;
  1639.     step = 1 / 40;
  1640.     var B, j, F, I;
  1641.     var q = this._lvval;
  1642.     var R = this._lused * 18;
  1643.     for (var U = 0; U < 41; U++) {
  1644.         var z = U * step;
  1645.         a = o + z * y;
  1646.         f = u + z * b;
  1647.         l = e + z * w;
  1648.         c = t + z * E;
  1649.         h = n + z * S;
  1650.         p = r + z * x;
  1651.         T = l - a;
  1652.         N = c - f;
  1653.         C = h - l;
  1654.         k = p - c;
  1655.         d = a + z * T;
  1656.         v = f + z * N;
  1657.         m = l + z * C;
  1658.         g = c + z * k;
  1659.         L = m - d;
  1660.         A = g - v;
  1661.         P = d + z * L;
  1662.         H = v + z * A;
  1663.         M = O / this.len(L, A);
  1664.         _ = M * A;
  1665.         D = -M * L;
  1666.         this._updateSBounds(P, H);
  1667.         if (U > 0) {
  1668.             q[R++] = B + F;
  1669.             q[R++] = j + I;
  1670.             R++;
  1671.             q[R++] = B - F;
  1672.             q[R++] = j - I;
  1673.             R++;
  1674.             q[R++] = P + _;
  1675.             q[R++] = H + D;
  1676.             R++;
  1677.             q[R++] = B - F;
  1678.             q[R++] = j - I;
  1679.             R++;
  1680.             q[R++] = P + _;
  1681.             q[R++] = H + D;
  1682.             R++;
  1683.             q[R++] = P - _;
  1684.             q[R++] = H - D;
  1685.             R++
  1686.         }
  1687.         B = P;
  1688.         j = H;
  1689.         F = _;
  1690.         I = D
  1691.     }
  1692.     this._px = i;
  1693.     this._py = s;
  1694.     this._ldirty = true;
  1695.     this._lused += 40;
  1696.     this._lsegment.count += 40;
  1697.     this._empty = false
  1698. };
  1699. Graphics.prototype.drawCircle = function (e, t, n) {
  1700.     this.drawEllipse(e, t, n * 2, n * 2)
  1701. };
  1702. Graphics.prototype.drawEllipse = function (e, t, n, r) {
  1703.     var i = Math.PI / 16;
  1704.     var s = n * .5;
  1705.     var o = r * .5;
  1706.     var u = Graphics._eVrt;
  1707.     var a = 0;
  1708.     for (var f = 0; f < 2 * Math.PI; f += i) {
  1709.         u[a++] = e + Math.cos(f) * s;
  1710.         u[a++] = t + Math.sin(f) * o
  1711.     }
  1712.     this.drawTriangles(u, Graphics._eInd)
  1713. };
  1714. Graphics.prototype.drawRect = function (e, t, n, r) {
  1715.     var i = Graphics._rVrt;
  1716.     i[0] = i[4] = e;
  1717.     i[1] = i[3] = t;
  1718.     i[2] = i[6] = e + n;
  1719.     i[5] = i[7] = t + r;
  1720.     this.drawTriangles(i, Graphics._rInd)
  1721. };
  1722. Graphics.prototype.drawRoundRect = function (e, t, n, r, i, s) {
  1723.     var o = Graphics._rrVrt;
  1724.     var u = Math.PI / 14;
  1725.     if (!s) s = i;
  1726.     var a = i * .5;
  1727.     var f = s * .5;
  1728.     var l = 0;
  1729.     var c = e + a;
  1730.     var h = t + f;
  1731.     for (var p = -Math.PI; p <= Math.PI; p += u) {
  1732.         if (l == 16) c += n - i;
  1733.         if (l == 32) h += r - s;
  1734.         if (l == 48) c -= n - i;
  1735.         if (l > 0 && (l & 15) == 0) p -= u;
  1736.         o[l++] = c + Math.cos(p) * a;
  1737.         o[l++] = h + Math.sin(p) * f
  1738.     }
  1739.     this.drawTriangles(o, Graphics._rrInd)
  1740. };
  1741. Graphics.prototype.drawTriangles = function (e, t, n) {
  1742.     this._drawTGS(e, t, n, 2)
  1743. };
  1744. Graphics.prototype.drawTriangles3D = function (e, t, n) {
  1745.     this._drawTGS(e, t, n, 3)
  1746. };
  1747. Graphics.prototype._drawTGS = function (e, t, n, r) {
  1748.     this._lsegment = null;
  1749.     var i = Math.floor(e.length / r);
  1750.     var s = Math.floor(t.length / 3);
  1751.     var o = i + "-" + s;
  1752.     var u;
  1753.     var a = this._dtgs[o];
  1754.     if (a && a.length > 0) u = a.pop();
  1755.     else u = new UTgs(i, s);
  1756.     var f = 0;
  1757.     if (r == 2)
  1758.         for (var l = 0; l < e.length; l += 2) {
  1759.             var c = e[l];
  1760.             var h = e[l + 1];
  1761.             u.vrt[f++] = c;
  1762.             u.vrt[f++] = h;
  1763.             f++;
  1764.             this._updateBounds(c, h)
  1765.         }
  1766.     if (r == 3)
  1767.         for (var l = 0; l < e.length; l += 3) {
  1768.             var c = e[l];
  1769.             var h = e[l + 1];
  1770.             var p = e[l + 2];
  1771.             u.vrt[f++] = c;
  1772.             u.vrt[f++] = h;
  1773.             u.vrt[f++] = p;
  1774.             this._updateBounds(c, h)
  1775.         }
  1776.     if (this._ftype == 1) {
  1777.         if (n != null)
  1778.             for (var l = 0; l < n.length; l++) u.uvt[l] = n[l];
  1779.         else u.emptyUVT = true
  1780.     }
  1781.     for (var l = 0; l < t.length; l++) u.ind[l] = t[l];
  1782.     if (this._ftype == 1) {
  1783.         u.useTex = true;
  1784.         u._bdata = this._bdata
  1785.     } else {
  1786.         u.useTex = false;
  1787.         u.SetColor(this._cfstyle.colARR)
  1788.     }
  1789.     u.updateData();
  1790.     this._tgs.push(u);
  1791.     this._elems.push(u);
  1792.     this._empty = false
  1793. };
  1794. Graphics.prototype.clear = function () {
  1795.     this._duls = this._uls;
  1796.     this._dcvs = this._cvs;
  1797.     for (var e = 0; e < this._tgs.length; e++) {
  1798.         var t = this._tgs[e];
  1799.         if (this._dtgs[t.key] == null) this._dtgs[t.key] = [];
  1800.         this._dtgs[t.key].push(t)
  1801.     }
  1802.     this._uls = [];
  1803.     this._cvs = [];
  1804.     this._tgs = [];
  1805.     this._elems = [];
  1806.     this._ftype = 0;
  1807.     this._empty = true;
  1808.     this._minx = this._sminx = this._miny = this._sminy = Number.POSITIVE_INFINITY;
  1809.     this._maxx = this._smaxx = this._maxy = this._smaxy = Number.NEGATIVE_INFINITY;
  1810.     this._lused = 0;
  1811.     this._lsegment = null
  1812. };
  1813. Graphics.prototype._getRect = function (e) {
  1814.     if (this._empty) return null;
  1815.     var t = this._tgs.length != 0;
  1816.     var n = this._uls.length != 0 || this._cvs.length != 0;
  1817.     if (!e && !t) return null;
  1818.     var r = this._brect;
  1819.     var i = this._sminx,
  1820.         s = this._sminy,
  1821.         o = this._smaxx,
  1822.         u = this._smaxy;
  1823.     if (t) {
  1824.         r._setP(this._minx, this._miny);
  1825.         r._unionWP(this._maxx, this._maxy);
  1826.         if (n && e) {
  1827.             r._unionWP(i, s);
  1828.             r._unionWP(o, u)
  1829.         }
  1830.         return r
  1831.     }
  1832.     r._setP(i, s);
  1833.     r._unionWP(o, u);
  1834.     return r
  1835. };
  1836. Graphics.prototype._hits = function (e, t) {
  1837.     if (this._empty) return false;
  1838.     if (e < this._minx || e > this._maxx || t < this._miny || t > this._maxy) return false;
  1839.     return true
  1840. };
  1841. Graphics.prototype._updateBounds = function (e, t) {
  1842.     e < this._minx ? this._minx = e : e > this._maxx ? this._maxx = e : 0;
  1843.     t < this._miny ? this._miny = t : t > this._maxy ? this._maxy = t : 0
  1844. };
  1845. Graphics.prototype._updateSBounds = function (e, t) {
  1846.     e < this._sminx ? this._sminx = e : e > this._smaxx ? this._smaxx = e : 0;
  1847.     t < this._sminy ? this._sminy = t : t > this._smaxy ? this._smaxy = t : 0
  1848. };
  1849. Graphics._makeConvexInd = function (e) {
  1850.     var t = [];
  1851.     for (var n = 1; n < e - 1; n++) t.push(0, n, n + 1);
  1852.     return t
  1853. };
  1854. Graphics._rVrt = [0, 0, 0, 0, 0, 0, 0, 0];
  1855. Graphics._rInd = [0, 1, 2, 1, 2, 3];
  1856. Graphics._eVrt = [];
  1857. for (var i = 0; i < 32; i++) Graphics._eVrt.push(0, 0);
  1858. Graphics._eInd = Graphics._makeConvexInd(32);
  1859. Graphics._rrVrt = [];
  1860. for (var i = 0; i < 32; i++) Graphics._rrVrt.push(0, 0);
  1861. Graphics._rrInd = Graphics._makeConvexInd(32);
  1862. ULSegment.prototype.update = function (e, t) {
  1863.     this.count = 0;
  1864.     this.offset = e;
  1865.     var n = this.color;
  1866.     n[0] = t[0];
  1867.     n[1] = t[1];
  1868.     n[2] = t[2];
  1869.     n[3] = t[3]
  1870. };
  1871. ULSegment.prototype.render = function (e) {
  1872.     Stage._setUT(0);
  1873.     gl.uniform4fv(e._sprg.color, this.color);
  1874.     Stage._setVC(this.vbuf);
  1875.     Stage._setTC(this.vbuf);
  1876.     gl.drawArrays(gl.TRIANGLES, 6 * this.offset, 6 * this.count)
  1877. };
  1878. UTgs.prototype.SetColor = function (e) {
  1879.     var t = this.color;
  1880.     t[0] = e[0];
  1881.     t[1] = e[1];
  1882.     t[2] = e[2];
  1883.     t[3] = e[3]
  1884. };
  1885. UTgs.prototype._hits = function (e, t) {
  1886.     return e > this._minx && e < this._maxx && t > this._miny && t < this._maxy
  1887. };
  1888. UTgs.prototype.updateData = function () {
  1889.     Stage._setBF(this.vbuf);
  1890.     gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.vrt);
  1891.     Stage._setEBF(this.ibuf);
  1892.     gl.bufferSubData(gl.ELEMENT_ARRAY_BUFFER, 0, this.ind);
  1893.     Stage._setBF(this.tbuf);
  1894.     gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.uvt)
  1895. };
  1896. UTgs.prototype.render = function (e) {
  1897.     if (this.useTex) {
  1898.         if (this._bdata._loaded == false) return;
  1899.         if (this.emptyUVT) {
  1900.             this.emptyUVT = false;
  1901.             var t = 1 / this._bdata._rwidth,
  1902.                 n = 1 / this._bdata._rheight;
  1903.             for (var r = 0; r < this.uvt.length; r++) {
  1904.                 this.uvt[2 * r] = t * this.vrt[3 * r];
  1905.                 this.uvt[2 * r + 1] = n * this.vrt[3 * r + 1]
  1906.             }
  1907.             this.updateData()
  1908.         }
  1909.         Stage._setUT(1);
  1910.         Stage._setTEX(this._bdata._texture)
  1911.     } else {
  1912.         Stage._setUT(0);
  1913.         gl.uniform4fv(e._sprg.color, this.color)
  1914.     }
  1915.     Stage._setTC(this.tbuf);
  1916.     Stage._setVC(this.vbuf);
  1917.     Stage._setEBF(this.ibuf);
  1918.     gl.drawElements(gl.TRIANGLES, this.ind.length, gl.UNSIGNED_SHORT, 0)
  1919. };
  1920. UTgs.prototype.clear = function () {
  1921.     gl.deleteBuffer(this.vbuf);
  1922.     gl.deleteBuffer(this.ibuf);
  1923.     gl.deleteBuffer(this.tbuf)
  1924. };
  1925. FillStyle.prototype.Set = function (e, t) {
  1926.     this.color = e;
  1927.     this.alpha = t;
  1928.     var n = this.colARR;
  1929.     n[0] = (e >> 16 & 255) * .0039215686;
  1930.     n[1] = (e >> 8 & 255) * .0039215686;
  1931.     n[2] = (e & 255) * .0039215686;
  1932.     n[3] = t
  1933. };
  1934. LineStyle.prototype = new FillStyle;
  1935. LineStyle.prototype.Set = function (e, t, n) {
  1936.     this.thickness = e;
  1937.     FillStyle.prototype.Set.call(this, t, n)
  1938. };
  1939. Sprite.prototype = new DisplayObjectContainer;
  1940. Sprite.prototype._render = function (e) {
  1941.     if (!this.graphics._empty) this.graphics._render(e);
  1942.     DisplayObjectContainer.prototype._render.call(this, e)
  1943. };
  1944. Sprite.prototype._moveMouse = function (e, t, n) {
  1945.     if (!n || !this.visible || !this.mouseChildren && !this.mouseEnabled) return null;
  1946.     var r = DisplayObjectContainer.prototype._moveMouse.call(this, e, t, n);
  1947.     if (r != null) return r;
  1948.     if (!this.mouseEnabled) return null;
  1949.     var i = this._temp;
  1950.     if (this.graphics._hits(i[0], i[1])) return this;
  1951.     return null
  1952. };
  1953. Sprite.prototype._getRect = function (e) {
  1954.     var t;
  1955.     var n = DisplayObjectContainer.prototype._getRect.call(this, e);
  1956.     var r = this.graphics._getRect(e);
  1957.     if (n != null && r != null) n._unionWith(r);
  1958.     if (n != null) t = n;
  1959.     else t = r;
  1960.     return t
  1961. };
  1962. Sprite.prototype._htpLocal = function (e) {
  1963.     var t = this._temp;
  1964.     mat4.multiplyVec2(this._getIMat(), e, t);
  1965.     if (this.graphics._hits(t[0], t[1])) return true;
  1966.     return DisplayObjectContainer.prototype._htpLocal.call(this, e)
  1967. };
  1968. var TextFormatAlign = {
  1969.     LEFT: "left",
  1970.     CENTER: "center",
  1971.     RIGHT: "right",
  1972.     JUSTIFY: "justify"
  1973. };
  1974. TextFormat.prototype.clone = function () {
  1975.     return new TextFormat(this.font, this.size, this.color, this.bold, this.italic, this.align, this.leading)
  1976. };
  1977. TextFormat.prototype.set = function (e) {
  1978.     this.font = e.font;
  1979.     this.size = e.size;
  1980.     this.color = e.color;
  1981.     this.bold = e.bold;
  1982.     this.italic = e.italic;
  1983.     this.align = e.align;
  1984.     this.leading = e.leading
  1985. };
  1986. TextFormat.prototype.getImageData = function (e, t) {
  1987.     var n = TextFormat._canvas;
  1988.     var r = TextFormat._context;
  1989.     var i = this.data;
  1990.     n.width = i.rw = this._nhpt(t._areaW);
  1991.     n.height = i.rh = this._nhpt(t._areaH);
  1992.     var s = this.color;
  1993.     var o = s >> 16 & 255;
  1994.     var u = s >> 8 & 255;
  1995.     var a = s & 255;
  1996.     r.textBaseline = "top";
  1997.     r.fillStyle = "rgb(" + o + "," + u + "," + a + ")";
  1998.     r.font = (this.italic ? "italic " : "") + (this.bold ? "bold " : "") + this.size + "px " + this.font;
  1999.     this.maxW = 0;
  2000.     var f = e.split("\n");
  2001.     var l = 0;
  2002.     var c = 0;
  2003.     var h = this.size * 1.25;
  2004.     for (var p = 0; p < f.length; p++) {
  2005.         var d = this.renderPar(f[p], c, h, r, t);
  2006.         l += d;
  2007.         c += d * (h + this.leading)
  2008.     }
  2009.     if (this.align == TextFormatAlign.JUSTIFY) this.maxW = Math.max(this.maxW, t._areaW);
  2010.     i.image = n;
  2011.     i.tw = this.maxW;
  2012.     i.th = (h + this.leading) * l - this.leading;
  2013.     return i
  2014. };
  2015. TextFormat.prototype.renderPar = function (e, t, n, r, i) {
  2016.     var s;
  2017.     if (i._wordWrap) s = e.split(" ");
  2018.     else s = [e];
  2019.     var o = r.measureText(" ").width;
  2020.     var u = 0;
  2021.     var a = i._areaW;
  2022.     var f = 0;
  2023.     var l = [
  2024.         []
  2025.     ];
  2026.     var c = [];
  2027.     for (var h = 0; h < s.length; h++) {
  2028.         var p = s[h];
  2029.         var d = r.measureText(p).width;
  2030.         if (u + d <= a || u == 0) {
  2031.             l[f].push(p);
  2032.             u += d + o
  2033.         } else {
  2034.             c.push(a - u + o);
  2035.             l.push([]);
  2036.             f++;
  2037.             u = 0;
  2038.             h--
  2039.         }
  2040.     }
  2041.     c.push(a - u + o);
  2042.     for (var h = 0; h < l.length; h++) {
  2043.         var v = l[h];
  2044.         while (v[v.length - 1] == "") {
  2045.             v.pop();
  2046.             c[h] += o
  2047.         }
  2048.         this.maxW = Math.max(this.maxW, a - c[h]);
  2049.         var m, g = t + (n + this.leading) * h;
  2050.         u = 0, m = o;
  2051.         if (this.align == TextFormatAlign.CENTER) u = c[h] * .5;
  2052.         if (this.align == TextFormatAlign.RIGHT) u = c[h];
  2053.         if (this.align == TextFormatAlign.JUSTIFY) m = o + c[h] / (v.length - 1);
  2054.         for (var y = 0; y < v.length; y++) {
  2055.             var p = v[y];
  2056.             r.fillText(p, u, g);
  2057.             var d = r.measureText(p).width;
  2058.             if (h < l.length - 1) u += d + m;
  2059.             else {
  2060.                 u += d + o
  2061.             }
  2062.         }
  2063.     }
  2064.     return f + 1
  2065. };
  2066. TextFormat.prototype._nhpt = function (e) {
  2067.     --e;
  2068.     for (var t = 1; t < 32; t <<= 1) e = e | e >> t;
  2069.     return e + 1
  2070. };
  2071. TextFormat._canvas = document.createElement("canvas");
  2072. TextFormat._context = TextFormat._canvas.getContext("2d");
  2073. TextField.prototype = new InteractiveObject;
  2074. TextField.prototype.setTextFormat = function (e) {
  2075.     this._tForm.set(e);
  2076.     this._update()
  2077. };
  2078. TextField.prototype.getTextFormat = function (e) {
  2079.     return this._tForm.clone()
  2080. };
  2081. TextField.prototype._update = function () {
  2082.     var e = this._brect.width = this._areaW;
  2083.     var t = this._brect.height = this._areaH;
  2084.     if (e == 0 || t == 0) return;
  2085.     var n = this._tForm.getImageData(this._text, this);
  2086.     this._textW = n.tw;
  2087.     this._textH = n.th;
  2088.     if (n.rw != this._rwidth || n.rh != this._rheight) {
  2089.         gl.deleteTexture(this._texture);
  2090.         this._texture = gl.createTexture()
  2091.     }
  2092.     Stage._setTEX(this._texture);
  2093.     gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, n.image);
  2094.     gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
  2095.     gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR);
  2096.     gl.generateMipmap(gl.TEXTURE_2D);
  2097.     this._rwidth = n.rw;
  2098.     this._rheight = n.rh;
  2099.     var r = e / n.rw;
  2100.     var i = t / n.rh;
  2101.     var s = this._tcArray;
  2102.     s[2] = s[6] = r;
  2103.     s[5] = s[7] = i;
  2104.     Stage._setBF(this._tcBuffer);
  2105.     gl.vertexAttribPointer(Stage._main._sprg.tca, 2, gl.FLOAT, false, 0, 0);
  2106.     gl.bufferSubData(gl.ARRAY_BUFFER, 0, s);
  2107.     var o = this._fArray;
  2108.     o[3] = o[9] = e;
  2109.     o[7] = o[10] = t;
  2110.     Stage._setBF(this._vBuffer);
  2111.     gl.vertexAttribPointer(Stage._main._sprg.vpa, 3, gl.FLOAT, false, 0, 0);
  2112.     gl.bufferSubData(gl.ARRAY_BUFFER, 0, o)
  2113. };
  2114. TextField.prototype._render = function (e) {
  2115.     if (this._areaW == 0 || this._areaH == 0) return;
  2116.     gl.uniformMatrix4fv(e._sprg.tMatUniform, false, e._mstack.top());
  2117.     e._cmstack.update();
  2118.     Stage._setVC(this._vBuffer);
  2119.     Stage._setTC(this._tcBuffer);
  2120.     Stage._setUT(1);
  2121.     Stage._setTEX(this._texture);
  2122.     Stage._setEBF(e._unitIBuffer);
  2123.     gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0)
  2124. };
  2125. this.tp = TextField.prototype;
  2126. tp.ds = tp.__defineSetter__;
  2127. tp.dg = tp.__defineGetter__;
  2128. tp.dg("textWidth", function () {
  2129.     return this._textW
  2130. });
  2131. tp.dg("textHeight", function () {
  2132.     return this._textH
  2133. });
  2134. tp.ds("wordWrap", function (e) {
  2135.     this._wordWrap = e;
  2136.     this._update()
  2137. });
  2138. tp.dg("wordWrap", function () {
  2139.     return this._wordWrap
  2140. });
  2141. tp.ds("width", function (e) {
  2142.     this._areaW = Math.max(0, e);
  2143.     this._update()
  2144. });
  2145. tp.dg("width", function () {
  2146.     return this._areaW
  2147. });
  2148. tp.ds("height", function (e) {
  2149.     this._areaH = Math.max(0, e);
  2150.     this._update()
  2151. });
  2152. tp.dg("height", function () {
  2153.     return this._areaH
  2154. });
  2155. tp.ds("text", function (e) {
  2156.     this._text = e.toString();
  2157.     this._update()
  2158. });
  2159. tp.dg("text", function () {
  2160.     return this._text
  2161. });
  2162. delete tp.ds;
  2163. delete tp.dg;
  2164. delete this.tp
Advertisement
Add Comment
Please, Sign In to add comment