Skip to content

Commit

Permalink
new age core
Browse files Browse the repository at this point in the history
  • Loading branch information
theshock committed Feb 5, 2012
1 parent 1857636 commit 9994fe5
Show file tree
Hide file tree
Showing 7 changed files with 2,749 additions and 8,312 deletions.
97 changes: 22 additions & 75 deletions Source/LibCanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,89 +17,36 @@ provides: LibCanvas
...
*/

var LibCanvas = this.LibCanvas = declare(
/** @lends LibCanvas.prototype */
{
var LibCanvas = this.LibCanvas = declare({
name: 'LibCanvas',

own: {
Buffer: function (width, height, withCtx) {
var a = Array.pickFrom(arguments), zero = (width == null || width === true);
if (zero || width.width == null || width.height == null) {
width = zero ? 0 : a[0];
height = zero ? 0 : a[1];
withCtx = zero ? a[0] : a[2];
} else {
withCtx = !!height;
height = width.height;
width = width.width
}
Buffer: function () {
return LibCanvas.buffer.apply( LibCanvas, arguments );
},
buffer: function (width, height, withCtx) {
var size, a = slice.call(arguments), last = a[a.length-1];

withCtx = (typeof last === 'boolean' ? a.pop() : false);

size = Size(a.length == 1 ? a[0] : a);

var canvas = atom.dom
.create("canvas", {
width : width,
height : height
}).get();
var canvas = atom.dom.create("canvas", {
width : size.width,
height : size.height
}).first;

if (withCtx) canvas.ctx = canvas.getContext('2d-libcanvas');
return canvas;
},
isLibCanvas: function (elem) {
return elem && elem instanceof Canvas2D;
},
namespace: function (namespace) {
var current;
Array.from(arguments).forEach(function (namespace) {
current = LibCanvas;
namespace.split('.').forEach(function(part){
if (current[part] == null) current[part] = {};
current = current[part];
});
});
return current;
},
extract: function (to) {
to = to || atom.global;

for (var i in {Shapes: 1, Behaviors: 1, Utils: 1}) {
for (var k in LibCanvas[i]) {
to[k] = LibCanvas[i][k];
}
}
for (i in {Point: 1, Animation: 1, Processors: 1, Context2D: 1}) {
to[i] = LibCanvas[i];
to = to || global;
for (var k in LibCanvas.Shapes) {
to[k] = LibCanvas.Shapes[k];
}
to.Point = LibCanvas.Point;
to.Size = LibCanvas.Size;
return to;
},

get invoker () {
if (this._invoker == null) {
this._invoker = new Invoker().invoke();
}
return this._invoker;
}
},
proto: {
/**
* @constructs
* @returns {LibCanvas.Canvas2D}
*/
initialize: function() {
return Canvas2D.factory(arguments);
}
}
});

LibCanvas.Animation = {};
LibCanvas.Behaviors = {};
LibCanvas.Engines = {};
LibCanvas.Inner = {};
LibCanvas.Processors = {};
LibCanvas.Scene = {};
LibCanvas.Shapes = {};
LibCanvas.Ui = {};
LibCanvas.Utils = {};

var
Inner = LibCanvas.Inner,
Processors = LibCanvas.Processors,
Buffer = LibCanvas.Buffer,
Scene = LibCanvas.Scene;
});
4 changes: 2 additions & 2 deletions Source/Utils/Canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ provides: Utils.Canvas
...
*/

atom.extend(HTMLCanvasElement,
atom.append(HTMLCanvasElement,
/** @lends HTMLCanvasElement */
{
/** @private */
Expand All @@ -36,7 +36,7 @@ atom.extend(HTMLCanvasElement,
}
});

atom.implement(HTMLCanvasElement,
atom.append(HTMLCanvasElement.prototype,
/** @lends HTMLCanvasElement.prototype */
{
getOriginalContext: HTMLCanvasElement.prototype.getContext,
Expand Down
4 changes: 2 additions & 2 deletions Source/Utils/Image.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ provides: Utils.Image
...
*/
// <image> tag
atom.implement(HTMLImageElement, {
atom.append(HTMLImageElement.prototype, {
// наверное, лучше использовать createPattern
createSprite: function (rect) {
if (rect.width <= 0 || rect.height <= 0) {
Expand Down Expand Up @@ -106,7 +106,7 @@ atom.implement(HTMLImageElement, {
}
});
// mixin from image
atom.implement(HTMLCanvasElement, {
atom.append(HTMLCanvasElement.prototype, {
createSprite : HTMLImageElement.prototype.createSprite,
sprite : HTMLImageElement.prototype.sprite,
isLoaded : function () { return true; },
Expand Down
4 changes: 2 additions & 2 deletions Source/Utils/Math.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ provides: Utils.Math

var degreesCache = {}, d360;

atom.implement(Number, {
atom.core.append(Number.prototype, {
/**
* Cast degrees to radians
* (90).degree() == Math.PI/2
Expand Down Expand Up @@ -82,7 +82,7 @@ provides: Utils.Math

})();

atom.extend(Math, {
atom.core.append(Math, {
hypotenuse: function (cathetus1, cathetus2) {
return (cathetus1*cathetus1 + cathetus2*cathetus2).sqrt();
},
Expand Down
188 changes: 0 additions & 188 deletions Source/Utils/Trace.js

This file was deleted.

9 changes: 9 additions & 0 deletions Source/overall.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,17 @@ authors:
// 'use strict';

var undefined,
/** @global {Object} global */
global = this,
/** @global {Function} slice */
slice = [].slice,
/** @global {Function} declare */
declare = atom.declare,
/** @global {Function} Registry */
Registry = atom.Registry,
/** @global {Function} Events */
Events = atom.Events,
/** @global {Function} Settings */
Settings = atom.Settings;
/*** [Code] ***/

Expand Down
Loading

0 comments on commit 9994fe5

Please sign in to comment.