mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 18:47:35 +00:00
updated pixi to v2
This commit is contained in:
parent
a5b3d2f671
commit
58b83f7297
95 changed files with 44677 additions and 3522 deletions
88
app/Lib/Vendor/src/pixi/utils/Detector.js
vendored
Normal file
88
app/Lib/Vendor/src/pixi/utils/Detector.js
vendored
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
/**
|
||||
* @author Mat Groves http://matgroves.com/ @Doormat23
|
||||
*/
|
||||
|
||||
/**
|
||||
* This helper function will automatically detect which renderer you should be using.
|
||||
* WebGL is the preferred renderer as it is a lot faster. If webGL is not supported by
|
||||
* the browser then this function will return a canvas renderer
|
||||
*
|
||||
* @method autoDetectRenderer
|
||||
* @for PIXI
|
||||
* @static
|
||||
* @param width=800 {Number} the width of the renderers view
|
||||
* @param height=600 {Number} the height of the renderers view
|
||||
*
|
||||
* @param [options] {Object} The optional renderer parameters
|
||||
* @param [options.view] {HTMLCanvasElement} the canvas to use as a view, optional
|
||||
* @param [options.transparent=false] {Boolean} If the render view is transparent, default false
|
||||
* @param [options.antialias=false] {Boolean} sets antialias (only applicable in chrome at the moment)
|
||||
* @param [options.preserveDrawingBuffer=false] {Boolean} enables drawing buffer preservation, enable this if you need to call toDataUrl on the webgl context
|
||||
* @param [options.resolution=1] {Number} the resolution of the renderer retina would be 2
|
||||
*
|
||||
*/
|
||||
PIXI.autoDetectRenderer = function(width, height, options)
|
||||
{
|
||||
if(!width)width = 800;
|
||||
if(!height)height = 600;
|
||||
|
||||
// BORROWED from Mr Doob (mrdoob.com)
|
||||
var webgl = ( function () { try {
|
||||
var canvas = document.createElement( 'canvas' );
|
||||
return !! window.WebGLRenderingContext && ( canvas.getContext( 'webgl' ) || canvas.getContext( 'experimental-webgl' ) );
|
||||
} catch( e ) {
|
||||
return false;
|
||||
}
|
||||
} )();
|
||||
|
||||
if( webgl )
|
||||
{
|
||||
return new PIXI.WebGLRenderer(width, height, options);
|
||||
}
|
||||
|
||||
return new PIXI.CanvasRenderer(width, height, options);
|
||||
};
|
||||
|
||||
/**
|
||||
* This helper function will automatically detect which renderer you should be using.
|
||||
* This function is very similar to the autoDetectRenderer function except that is will return a canvas renderer for android.
|
||||
* Even thought both android chrome supports webGL the canvas implementation perform better at the time of writing.
|
||||
* This function will likely change and update as webGL performance improves on these devices.
|
||||
*
|
||||
* @method autoDetectRecommendedRenderer
|
||||
* @for PIXI
|
||||
* @static
|
||||
* @param width=800 {Number} the width of the renderers view
|
||||
* @param height=600 {Number} the height of the renderers view
|
||||
*
|
||||
* @param [options] {Object} The optional renderer parameters
|
||||
* @param [options.view] {HTMLCanvasElement} the canvas to use as a view, optional
|
||||
* @param [options.transparent=false] {Boolean} If the render view is transparent, default false
|
||||
* @param [options.antialias=false] {Boolean} sets antialias (only applicable in chrome at the moment)
|
||||
* @param [options.preserveDrawingBuffer=false] {Boolean} enables drawing buffer preservation, enable this if you need to call toDataUrl on the webgl context
|
||||
* @param [options.resolution=1] {Number} the resolution of the renderer retina would be 2
|
||||
*
|
||||
*/
|
||||
PIXI.autoDetectRecommendedRenderer = function(width, height, options)
|
||||
{
|
||||
if(!width)width = 800;
|
||||
if(!height)height = 600;
|
||||
|
||||
// BORROWED from Mr Doob (mrdoob.com)
|
||||
var webgl = ( function () { try {
|
||||
var canvas = document.createElement( 'canvas' );
|
||||
return !! window.WebGLRenderingContext && ( canvas.getContext( 'webgl' ) || canvas.getContext( 'experimental-webgl' ) );
|
||||
} catch( e ) {
|
||||
return false;
|
||||
}
|
||||
} )();
|
||||
|
||||
var isAndroid = /Android/i.test(navigator.userAgent);
|
||||
|
||||
if( webgl && !isAndroid)
|
||||
{
|
||||
return new PIXI.WebGLRenderer(width, height, options);
|
||||
}
|
||||
|
||||
return new PIXI.CanvasRenderer(width, height, options);
|
||||
};
|
||||
284
app/Lib/Vendor/src/pixi/utils/EventTarget.js
vendored
Normal file
284
app/Lib/Vendor/src/pixi/utils/EventTarget.js
vendored
Normal file
|
|
@ -0,0 +1,284 @@
|
|||
/**
|
||||
* @author Mat Groves http://matgroves.com/ @Doormat23
|
||||
* @author Chad Engler https://github.com/englercj @Rolnaaba
|
||||
*/
|
||||
|
||||
/**
|
||||
* Originally based on https://github.com/mrdoob/eventtarget.js/ from mr Doob.
|
||||
* Currently takes inspiration from the nodejs EventEmitter, EventEmitter3, and smokesignals
|
||||
*/
|
||||
|
||||
/**
|
||||
* Mixins event emitter functionality to a class
|
||||
*
|
||||
* @class EventTarget
|
||||
* @example
|
||||
* function MyEmitter() {}
|
||||
*
|
||||
* PIXI.EventTarget.mixin(MyEmitter.prototype);
|
||||
*
|
||||
* var em = new MyEmitter();
|
||||
* em.emit('eventName', 'some data', 'some more data', {}, null, ...);
|
||||
*/
|
||||
PIXI.EventTarget = {
|
||||
/**
|
||||
* Backward compat from when this used to be a function
|
||||
*/
|
||||
call: function callCompat(obj) {
|
||||
if(obj) {
|
||||
obj = obj.prototype || obj;
|
||||
PIXI.EventTarget.mixin(obj);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Mixes in the properties of the EventTarget prototype onto another object
|
||||
*
|
||||
* @method mixin
|
||||
* @param object {Object} The obj to mix into
|
||||
*/
|
||||
mixin: function mixin(obj) {
|
||||
/**
|
||||
* Return a list of assigned event listeners.
|
||||
*
|
||||
* @method listeners
|
||||
* @param eventName {String} The events that should be listed.
|
||||
* @return {Array} An array of listener functions
|
||||
*/
|
||||
obj.listeners = function listeners(eventName) {
|
||||
this._listeners = this._listeners || {};
|
||||
|
||||
return this._listeners[eventName] ? this._listeners[eventName].slice() : [];
|
||||
};
|
||||
|
||||
/**
|
||||
* Emit an event to all registered event listeners.
|
||||
*
|
||||
* @method emit
|
||||
* @alias dispatchEvent
|
||||
* @param eventName {String} The name of the event.
|
||||
* @return {Boolean} Indication if we've emitted an event.
|
||||
*/
|
||||
obj.emit = obj.dispatchEvent = function emit(eventName, data) {
|
||||
this._listeners = this._listeners || {};
|
||||
|
||||
//backwards compat with old method ".emit({ type: 'something' })"
|
||||
if(typeof eventName === 'object') {
|
||||
data = eventName;
|
||||
eventName = eventName.type;
|
||||
}
|
||||
|
||||
//ensure we are using a real pixi event
|
||||
if(!data || data.__isEventObject !== true) {
|
||||
data = new PIXI.Event(this, eventName, data);
|
||||
}
|
||||
|
||||
//iterate the listeners
|
||||
if(this._listeners && this._listeners[eventName]) {
|
||||
var listeners = this._listeners[eventName].slice(0),
|
||||
length = listeners.length,
|
||||
fn = listeners[0],
|
||||
i;
|
||||
|
||||
for(i = 0; i < length; fn = listeners[++i]) {
|
||||
//call the event listener
|
||||
fn.call(this, data);
|
||||
|
||||
//if "stopImmediatePropagation" is called, stop calling sibling events
|
||||
if(data.stoppedImmediate) {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
//if "stopPropagation" is called then don't bubble the event
|
||||
if(data.stopped) {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
//bubble this event up the scene graph
|
||||
if(this.parent && this.parent.emit) {
|
||||
this.parent.emit.call(this.parent, eventName, data);
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Register a new EventListener for the given event.
|
||||
*
|
||||
* @method on
|
||||
* @alias addEventListener
|
||||
* @param eventName {String} Name of the event.
|
||||
* @param callback {Functon} fn Callback function.
|
||||
*/
|
||||
obj.on = obj.addEventListener = function on(eventName, fn) {
|
||||
this._listeners = this._listeners || {};
|
||||
|
||||
(this._listeners[eventName] = this._listeners[eventName] || [])
|
||||
.push(fn);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Add an EventListener that's only called once.
|
||||
*
|
||||
* @method once
|
||||
* @param eventName {String} Name of the event.
|
||||
* @param callback {Function} Callback function.
|
||||
*/
|
||||
obj.once = function once(eventName, fn) {
|
||||
this._listeners = this._listeners || {};
|
||||
|
||||
var self = this;
|
||||
function onceHandlerWrapper() {
|
||||
fn.apply(self.off(eventName, onceHandlerWrapper), arguments);
|
||||
}
|
||||
onceHandlerWrapper._originalHandler = fn;
|
||||
|
||||
return this.on(eventName, onceHandlerWrapper);
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove event listeners.
|
||||
*
|
||||
* @method off
|
||||
* @alias removeEventListener
|
||||
* @param eventName {String} The event we want to remove.
|
||||
* @param callback {Function} The listener that we need to find.
|
||||
*/
|
||||
obj.off = obj.removeEventListener = function off(eventName, fn) {
|
||||
this._listeners = this._listeners || {};
|
||||
|
||||
if(!this._listeners[eventName])
|
||||
return this;
|
||||
|
||||
var list = this._listeners[eventName],
|
||||
i = fn ? list.length : 0;
|
||||
|
||||
while(i-- > 0) {
|
||||
if(list[i] === fn || list[i]._originalHandler === fn) {
|
||||
list.splice(i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
if(list.length === 0) {
|
||||
delete this._listeners[eventName];
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove all listeners or only the listeners for the specified event.
|
||||
*
|
||||
* @method removeAllListeners
|
||||
* @param eventName {String} The event you want to remove all listeners for.
|
||||
*/
|
||||
obj.removeAllListeners = function removeAllListeners(eventName) {
|
||||
this._listeners = this._listeners || {};
|
||||
|
||||
if(!this._listeners[eventName])
|
||||
return this;
|
||||
|
||||
delete this._listeners[eventName];
|
||||
|
||||
return this;
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates an homogenous object for tracking events so users can know what to expect.
|
||||
*
|
||||
* @class Event
|
||||
* @extends Object
|
||||
* @constructor
|
||||
* @param target {Object} The target object that the event is called on
|
||||
* @param name {String} The string name of the event that was triggered
|
||||
* @param data {Object} Arbitrary event data to pass along
|
||||
*/
|
||||
PIXI.Event = function(target, name, data) {
|
||||
//for duck typing in the ".on()" function
|
||||
this.__isEventObject = true;
|
||||
|
||||
/**
|
||||
* Tracks the state of bubbling propagation. Do not
|
||||
* set this directly, instead use `event.stopPropagation()`
|
||||
*
|
||||
* @property stopped
|
||||
* @type Boolean
|
||||
* @private
|
||||
* @readOnly
|
||||
*/
|
||||
this.stopped = false;
|
||||
|
||||
/**
|
||||
* Tracks the state of sibling listener propagation. Do not
|
||||
* set this directly, instead use `event.stopImmediatePropagation()`
|
||||
*
|
||||
* @property stoppedImmediate
|
||||
* @type Boolean
|
||||
* @private
|
||||
* @readOnly
|
||||
*/
|
||||
this.stoppedImmediate = false;
|
||||
|
||||
/**
|
||||
* The original target the event triggered on.
|
||||
*
|
||||
* @property target
|
||||
* @type Object
|
||||
* @readOnly
|
||||
*/
|
||||
this.target = target;
|
||||
|
||||
/**
|
||||
* The string name of the event that this represents.
|
||||
*
|
||||
* @property type
|
||||
* @type String
|
||||
* @readOnly
|
||||
*/
|
||||
this.type = name;
|
||||
|
||||
/**
|
||||
* The data that was passed in with this event.
|
||||
*
|
||||
* @property data
|
||||
* @type Object
|
||||
* @readOnly
|
||||
*/
|
||||
this.data = data;
|
||||
|
||||
//backwards compat with older version of events
|
||||
this.content = data;
|
||||
|
||||
/**
|
||||
* The timestamp when the event occurred.
|
||||
*
|
||||
* @property timeStamp
|
||||
* @type Number
|
||||
* @readOnly
|
||||
*/
|
||||
this.timeStamp = Date.now();
|
||||
};
|
||||
|
||||
/**
|
||||
* Stops the propagation of events up the scene graph (prevents bubbling).
|
||||
*
|
||||
* @method stopPropagation
|
||||
*/
|
||||
PIXI.Event.prototype.stopPropagation = function stopPropagation() {
|
||||
this.stopped = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Stops the propagation of events to sibling listeners (no longer calls any listeners).
|
||||
*
|
||||
* @method stopImmediatePropagation
|
||||
*/
|
||||
PIXI.Event.prototype.stopImmediatePropagation = function stopImmediatePropagation() {
|
||||
this.stoppedImmediate = true;
|
||||
};
|
||||
168
app/Lib/Vendor/src/pixi/utils/Polyk.js
vendored
Normal file
168
app/Lib/Vendor/src/pixi/utils/Polyk.js
vendored
Normal file
|
|
@ -0,0 +1,168 @@
|
|||
/*
|
||||
PolyK library
|
||||
url: http://polyk.ivank.net
|
||||
Released under MIT licence.
|
||||
|
||||
Copyright (c) 2012 Ivan Kuckir
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
This is an amazing lib!
|
||||
|
||||
Slightly modified by Mat Groves (matgroves.com);
|
||||
*/
|
||||
|
||||
/**
|
||||
* Based on the Polyk library http://polyk.ivank.net released under MIT licence.
|
||||
* This is an amazing lib!
|
||||
* Slightly modified by Mat Groves (matgroves.com);
|
||||
* @class PolyK
|
||||
*/
|
||||
PIXI.PolyK = {};
|
||||
|
||||
/**
|
||||
* Triangulates shapes for webGL graphic fills.
|
||||
*
|
||||
* @method Triangulate
|
||||
*/
|
||||
PIXI.PolyK.Triangulate = function(p)
|
||||
{
|
||||
var sign = true;
|
||||
|
||||
var n = p.length >> 1;
|
||||
if(n < 3) return [];
|
||||
|
||||
var tgs = [];
|
||||
var avl = [];
|
||||
for(var i = 0; i < n; i++) avl.push(i);
|
||||
|
||||
i = 0;
|
||||
var al = n;
|
||||
while(al > 3)
|
||||
{
|
||||
var i0 = avl[(i+0)%al];
|
||||
var i1 = avl[(i+1)%al];
|
||||
var i2 = avl[(i+2)%al];
|
||||
|
||||
var ax = p[2*i0], ay = p[2*i0+1];
|
||||
var bx = p[2*i1], by = p[2*i1+1];
|
||||
var cx = p[2*i2], cy = p[2*i2+1];
|
||||
|
||||
var earFound = false;
|
||||
if(PIXI.PolyK._convex(ax, ay, bx, by, cx, cy, sign))
|
||||
{
|
||||
earFound = true;
|
||||
for(var j = 0; j < al; j++)
|
||||
{
|
||||
var vi = avl[j];
|
||||
if(vi === i0 || vi === i1 || vi === i2) continue;
|
||||
|
||||
if(PIXI.PolyK._PointInTriangle(p[2*vi], p[2*vi+1], ax, ay, bx, by, cx, cy)) {
|
||||
earFound = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(earFound)
|
||||
{
|
||||
tgs.push(i0, i1, i2);
|
||||
avl.splice((i+1)%al, 1);
|
||||
al--;
|
||||
i = 0;
|
||||
}
|
||||
else if(i++ > 3*al)
|
||||
{
|
||||
// need to flip flip reverse it!
|
||||
// reset!
|
||||
if(sign)
|
||||
{
|
||||
tgs = [];
|
||||
avl = [];
|
||||
for(i = 0; i < n; i++) avl.push(i);
|
||||
|
||||
i = 0;
|
||||
al = n;
|
||||
|
||||
sign = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// window.console.log("PIXI Warning: shape too complex to fill");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tgs.push(avl[0], avl[1], avl[2]);
|
||||
return tgs;
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks whether a point is within a triangle
|
||||
*
|
||||
* @method _PointInTriangle
|
||||
* @param px {Number} x coordinate of the point to test
|
||||
* @param py {Number} y coordinate of the point to test
|
||||
* @param ax {Number} x coordinate of the a point of the triangle
|
||||
* @param ay {Number} y coordinate of the a point of the triangle
|
||||
* @param bx {Number} x coordinate of the b point of the triangle
|
||||
* @param by {Number} y coordinate of the b point of the triangle
|
||||
* @param cx {Number} x coordinate of the c point of the triangle
|
||||
* @param cy {Number} y coordinate of the c point of the triangle
|
||||
* @private
|
||||
* @return {Boolean}
|
||||
*/
|
||||
PIXI.PolyK._PointInTriangle = function(px, py, ax, ay, bx, by, cx, cy)
|
||||
{
|
||||
var v0x = cx-ax;
|
||||
var v0y = cy-ay;
|
||||
var v1x = bx-ax;
|
||||
var v1y = by-ay;
|
||||
var v2x = px-ax;
|
||||
var v2y = py-ay;
|
||||
|
||||
var dot00 = v0x*v0x+v0y*v0y;
|
||||
var dot01 = v0x*v1x+v0y*v1y;
|
||||
var dot02 = v0x*v2x+v0y*v2y;
|
||||
var dot11 = v1x*v1x+v1y*v1y;
|
||||
var dot12 = v1x*v2x+v1y*v2y;
|
||||
|
||||
var invDenom = 1 / (dot00 * dot11 - dot01 * dot01);
|
||||
var u = (dot11 * dot02 - dot01 * dot12) * invDenom;
|
||||
var v = (dot00 * dot12 - dot01 * dot02) * invDenom;
|
||||
|
||||
// Check if point is in triangle
|
||||
return (u >= 0) && (v >= 0) && (u + v < 1);
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks whether a shape is convex
|
||||
*
|
||||
* @method _convex
|
||||
* @private
|
||||
* @return {Boolean}
|
||||
*/
|
||||
PIXI.PolyK._convex = function(ax, ay, bx, by, cx, cy, sign)
|
||||
{
|
||||
return ((ay-by)*(cx-bx) + (bx-ax)*(cy-by) >= 0) === sign;
|
||||
};
|
||||
213
app/Lib/Vendor/src/pixi/utils/Utils.js
vendored
Normal file
213
app/Lib/Vendor/src/pixi/utils/Utils.js
vendored
Normal file
|
|
@ -0,0 +1,213 @@
|
|||
/**
|
||||
* @author Mat Groves http://matgroves.com/ @Doormat23
|
||||
*/
|
||||
|
||||
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
|
||||
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
|
||||
|
||||
// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
|
||||
|
||||
// MIT license
|
||||
|
||||
/**
|
||||
* A polyfill for requestAnimationFrame
|
||||
* You can actually use both requestAnimationFrame and requestAnimFrame,
|
||||
* you will still benefit from the polyfill
|
||||
*
|
||||
* @method requestAnimationFrame
|
||||
*/
|
||||
|
||||
/**
|
||||
* A polyfill for cancelAnimationFrame
|
||||
*
|
||||
* @method cancelAnimationFrame
|
||||
*/
|
||||
(function(window) {
|
||||
var lastTime = 0;
|
||||
var vendors = ['ms', 'moz', 'webkit', 'o'];
|
||||
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
|
||||
window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
|
||||
window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'] ||
|
||||
window[vendors[x] + 'CancelRequestAnimationFrame'];
|
||||
}
|
||||
|
||||
if (!window.requestAnimationFrame) {
|
||||
window.requestAnimationFrame = function(callback) {
|
||||
var currTime = new Date().getTime();
|
||||
var timeToCall = Math.max(0, 16 - (currTime - lastTime));
|
||||
var id = window.setTimeout(function() { callback(currTime + timeToCall); },
|
||||
timeToCall);
|
||||
lastTime = currTime + timeToCall;
|
||||
return id;
|
||||
};
|
||||
}
|
||||
|
||||
if (!window.cancelAnimationFrame) {
|
||||
window.cancelAnimationFrame = function(id) {
|
||||
clearTimeout(id);
|
||||
};
|
||||
}
|
||||
|
||||
window.requestAnimFrame = window.requestAnimationFrame;
|
||||
})(this);
|
||||
|
||||
/**
|
||||
* Converts a hex color number to an [R, G, B] array
|
||||
*
|
||||
* @method hex2rgb
|
||||
* @param hex {Number}
|
||||
*/
|
||||
PIXI.hex2rgb = function(hex) {
|
||||
return [(hex >> 16 & 0xFF) / 255, ( hex >> 8 & 0xFF) / 255, (hex & 0xFF)/ 255];
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a color as an [R, G, B] array to a hex number
|
||||
*
|
||||
* @method rgb2hex
|
||||
* @param rgb {Array}
|
||||
*/
|
||||
PIXI.rgb2hex = function(rgb) {
|
||||
return ((rgb[0]*255 << 16) + (rgb[1]*255 << 8) + rgb[2]*255);
|
||||
};
|
||||
|
||||
/**
|
||||
* A polyfill for Function.prototype.bind
|
||||
*
|
||||
* @method bind
|
||||
*/
|
||||
if (typeof Function.prototype.bind !== 'function') {
|
||||
Function.prototype.bind = (function () {
|
||||
return function (thisArg) {
|
||||
var target = this, i = arguments.length - 1, boundArgs = [];
|
||||
if (i > 0)
|
||||
{
|
||||
boundArgs.length = i;
|
||||
while (i--) boundArgs[i] = arguments[i + 1];
|
||||
}
|
||||
|
||||
if (typeof target !== 'function') throw new TypeError();
|
||||
|
||||
function bound() {
|
||||
var i = arguments.length, args = new Array(i);
|
||||
while (i--) args[i] = arguments[i];
|
||||
args = boundArgs.concat(args);
|
||||
return target.apply(this instanceof bound ? this : thisArg, args);
|
||||
}
|
||||
|
||||
bound.prototype = (function F(proto) {
|
||||
if (proto) F.prototype = proto;
|
||||
if (!(this instanceof F)) return new F();
|
||||
})(target.prototype);
|
||||
|
||||
return bound;
|
||||
};
|
||||
})();
|
||||
}
|
||||
|
||||
/**
|
||||
* A wrapper for ajax requests to be handled cross browser
|
||||
*
|
||||
* @class AjaxRequest
|
||||
* @constructor
|
||||
*/
|
||||
PIXI.AjaxRequest = function()
|
||||
{
|
||||
var activexmodes = ['Msxml2.XMLHTTP.6.0', 'Msxml2.XMLHTTP.3.0', 'Microsoft.XMLHTTP']; //activeX versions to check for in IE
|
||||
|
||||
if (window.ActiveXObject)
|
||||
{ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
|
||||
for (var i=0; i<activexmodes.length; i++)
|
||||
{
|
||||
try{
|
||||
return new window.ActiveXObject(activexmodes[i]);
|
||||
}
|
||||
catch(e) {
|
||||
//suppress error
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (window.XMLHttpRequest) // if Mozilla, Safari etc
|
||||
{
|
||||
return new window.XMLHttpRequest();
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
/*
|
||||
PIXI.packColorRGBA = function(r, g, b, a)//r, g, b, a)
|
||||
{
|
||||
// console.log(r, b, c, d)
|
||||
return (Math.floor((r)*63) << 18) | (Math.floor((g)*63) << 12) | (Math.floor((b)*63) << 6);// | (Math.floor((a)*63))
|
||||
// i = i | (Math.floor((a)*63));
|
||||
// return i;
|
||||
// var r = (i / 262144.0 ) / 64;
|
||||
// var g = (i / 4096.0)%64 / 64;
|
||||
// var b = (i / 64.0)%64 / 64;
|
||||
// var a = (i)%64 / 64;
|
||||
|
||||
// console.log(r, g, b, a);
|
||||
// return i;
|
||||
|
||||
};
|
||||
*/
|
||||
/*
|
||||
PIXI.packColorRGB = function(r, g, b)//r, g, b, a)
|
||||
{
|
||||
return (Math.floor((r)*255) << 16) | (Math.floor((g)*255) << 8) | (Math.floor((b)*255));
|
||||
};
|
||||
|
||||
PIXI.unpackColorRGB = function(r, g, b)//r, g, b, a)
|
||||
{
|
||||
return (Math.floor((r)*255) << 16) | (Math.floor((g)*255) << 8) | (Math.floor((b)*255));
|
||||
};
|
||||
*/
|
||||
|
||||
/**
|
||||
* Checks whether the Canvas BlendModes are supported by the current browser
|
||||
*
|
||||
* @method canUseNewCanvasBlendModes
|
||||
* @return {Boolean} whether they are supported
|
||||
*/
|
||||
PIXI.canUseNewCanvasBlendModes = function()
|
||||
{
|
||||
if (typeof document === 'undefined') return false;
|
||||
var canvas = document.createElement('canvas');
|
||||
canvas.width = 1;
|
||||
canvas.height = 1;
|
||||
var context = canvas.getContext('2d');
|
||||
context.fillStyle = '#000';
|
||||
context.fillRect(0,0,1,1);
|
||||
context.globalCompositeOperation = 'multiply';
|
||||
context.fillStyle = '#fff';
|
||||
context.fillRect(0,0,1,1);
|
||||
return context.getImageData(0,0,1,1).data[0] === 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Given a number, this function returns the closest number that is a power of two
|
||||
* this function is taken from Starling Framework as its pretty neat ;)
|
||||
*
|
||||
* @method getNextPowerOfTwo
|
||||
* @param number {Number}
|
||||
* @return {Number} the closest number that is a power of two
|
||||
*/
|
||||
PIXI.getNextPowerOfTwo = function(number)
|
||||
{
|
||||
if (number > 0 && (number & (number - 1)) === 0) // see: http://goo.gl/D9kPj
|
||||
return number;
|
||||
else
|
||||
{
|
||||
var result = 1;
|
||||
while (result < number) result <<= 1;
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
PIXI.isPowerOfTwo = function(width, height)
|
||||
{
|
||||
return (width > 0 && (width & (width - 1)) === 0 && height > 0 && (height & (height - 1)) === 0);
|
||||
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue