Skip to content

Commit

Permalink
LibCanvas wrapped in overall.js, all names used in short way
Browse files Browse the repository at this point in the history
  • Loading branch information
theshock committed Jul 20, 2011
1 parent ff56a17 commit e77f926
Show file tree
Hide file tree
Showing 60 changed files with 705 additions and 870 deletions.
2 changes: 1 addition & 1 deletion Packager
Submodule Packager updated 1 files
+8 −12 packager.php
4 changes: 2 additions & 2 deletions Source/Animation/Sprite.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ provides: Animation.Sprite
...
*/

LibCanvas.Animation.Sprite = atom.Class({
Implements: [atom.Class.Events],
LibCanvas.Animation.Sprite = Class({
Implements: [Class.Events],
sprites : null,

initialize: function () {
Expand Down
13 changes: 6 additions & 7 deletions Source/Behaviors/Animatable.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ provides: Behaviors.Animatable
...
*/

(function (LibCanvas) {
var Animatable = LibCanvas.Behaviors.Animatable = function () {

var TF = LibCanvas.Inner.TimingFunctions,
Color = LibCanvas.Utils.Color;
var TF = TimingFunctions;

LibCanvas.Behaviors.Animatable = atom.Class({
Implements: [LibCanvas.Invoker.AutoChoose],
return Class({
Implements: [ Invoker.AutoChoose ],

initialize: atom.Class.hiddenMethod(function (element) {
initialize: Class.hiddenMethod(function (element) {
this['animate.element'] = element;
this['animate.func'] = atom.typeOf(element) == 'function';
}),
Expand Down Expand Up @@ -142,4 +141,4 @@ LibCanvas.Behaviors.Animatable = atom.Class({
}
});

})(LibCanvas);
}();
8 changes: 4 additions & 4 deletions Source/Behaviors/Clickable.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ provides: Behaviors.Clickable
...
*/

new function () {
var Clickable = LibCanvas.Behaviors.Clickable = function () {

var setValFn = function (object, name, val) {
return function () {
Expand All @@ -29,8 +29,8 @@ var setValFn = function (object, name, val) {
};

// Should extends drawable, implements mouseListener
LibCanvas.Behaviors.Clickable = atom.Class({
Implements: [LibCanvas.Behaviors.MouseListener],
return Class({
Implements: [ MouseListener ],

clickable : function () {
this.listenMouse();
Expand All @@ -46,4 +46,4 @@ LibCanvas.Behaviors.Clickable = atom.Class({
}
});

};
}();
28 changes: 14 additions & 14 deletions Source/Behaviors/Draggable.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,7 @@ provides: Behaviors.Draggable
...
*/

new function () {

LibCanvas.Behaviors.Draggable = atom.Class({
Extends: LibCanvas.Behaviors.MouseListener,

draggable : function (stopDrag) {
if (! ('draggable.isDraggable' in this) ) {
this.addEvent('libcanvasSet', initDraggable);
}
this['draggable.isDraggable'] = !stopDrag;
return this;
}
});
var Draggable = LibCanvas.Behaviors.Draggable = function () {

var isDraggable = function (elem, started) {
return elem['draggable.isDraggable'] && (!started || elem['draggable.mouse']);
Expand Down Expand Up @@ -75,4 +63,16 @@ var initDraggable = function () {
});
};

};
return Class({
Extends: MouseListener,

draggable : function (stopDrag) {
if (! ('draggable.isDraggable' in this) ) {
this.addEvent('libcanvasSet', initDraggable);
}
this['draggable.isDraggable'] = !stopDrag;
return this;
}
});

}();
12 changes: 6 additions & 6 deletions Source/Behaviors/Drawable.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ provides: Behaviors.Drawable
...
*/

new function () {
var Drawable = LibCanvas.Behaviors.Drawable = function () {

var start = function () {
this.libcanvas.addElement(this);
Expand All @@ -29,8 +29,8 @@ var stop = function () {
return 'removeEvent';
};

LibCanvas.Behaviors.Drawable = atom.Class({
Implements: [atom.Class.Events],
return Class({
Implements: [Class.Events],
libcanvasIsReady: false,
setLibcanvas : function (libcanvas) {
if (this.libcanvas) {
Expand Down Expand Up @@ -81,8 +81,8 @@ LibCanvas.Behaviors.Drawable = atom.Class({
.removeEvent('libcanvasSet', start)
.addEvent('libcanvasSet', stop);
},
update : atom.Class.abstractMethod,
draw : atom.Class.abstractMethod
update : Class.abstractMethod,
draw : Class.abstractMethod
});

};
}();
4 changes: 2 additions & 2 deletions Source/Behaviors/DrawableSprite.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ provides: Behaviors.DrawableSprite
...
*/

LibCanvas.Behaviors.DrawableSprite = atom.Class({
Extends: LibCanvas.Behaviors.Drawable,
var DrawableSprite = LibCanvas.Behaviors.DrawableSprite = Class({
Extends: Drawable,

draw: function () {
this.libcanvas.ctx.drawImage( this.sprite, this.shape );
Expand Down
2 changes: 1 addition & 1 deletion Source/Behaviors/Droppable.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ provides: Behaviors.Droppable
...
*/

LibCanvas.Behaviors.Droppable = atom.Class({
var Droppable = LibCanvas.Behaviors.Droppable = Class({
drops : null,
drop : function (obj) {
if (this.drops === null) {
Expand Down
2 changes: 1 addition & 1 deletion Source/Behaviors/Linkable.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ provides: Behaviors.Linkable
...
*/

LibCanvas.Behaviors.Linkable = atom.Class({
var Linkable = LibCanvas.Behaviors.Linkable = Class({
links : null,
moveLinks : function (move) {
(this.links || []).forEach(function (elem) {
Expand Down
2 changes: 1 addition & 1 deletion Source/Behaviors/MouseListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ events:
*/

// Should extends LibCanvas.Behaviors.Drawable
LibCanvas.Behaviors.MouseListener = atom.Class({
var MouseListener = LibCanvas.Behaviors.MouseListener = Class({
listenMouse : function (stopListen) {
return this.addEvent('libcanvasSet', function () {
var command = stopListen ? "unsubscribe" : "subscribe";
Expand Down
6 changes: 3 additions & 3 deletions Source/Behaviors/Moveable.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ provides: Behaviors.Moveable
...
*/
LibCanvas.Behaviors.Moveable = atom.Class({
var Moveable = LibCanvas.Behaviors.Moveable = Class({
stopMoving : function () {
var anim = this['moveTo.animation'];
if (anim) anim.stop();
return this;
},
moveTo : function (point, speed, fn) { // speed == pixels per sec
this.stopMoving();
point = LibCanvas.Point(point);
point = Point(point);
var diff = this.getCoords().diff(point), shape = this.getShape();
if (!speed) {
shape.move(diff);
Expand All @@ -35,7 +35,7 @@ LibCanvas.Behaviors.Moveable = atom.Class({
}
var distance = Math.hypotenuse(diff.x, diff.y), prev = 0;

this['moveTo.animation'] = new LibCanvas.Behaviors.Animatable(function (change) {
this['moveTo.animation'] = new Animatable(function (change) {
shape.move({
x : diff.x * (change - prev),
y : diff.y * (change - prev)
Expand Down
27 changes: 12 additions & 15 deletions Source/Core/Canvas2D.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,11 @@ provides: Canvas2D
...
*/

LibCanvas.Canvas2D = atom.Class({
var Canvas2D = LibCanvas.Canvas2D = Class({
Extends: LibCanvas,
Implements: [
LibCanvas.Inner.FrameRenderer,
LibCanvas.Inner.FpsMeter,
LibCanvas.Inner.DownloadingProgress,
atom.Class.Events,
atom.Class.Options
FrameRenderer,Inner.FpsMeter, DownloadingProgress,
Class.Events, Class.Options
],

Generators: {
Expand Down Expand Up @@ -63,7 +60,7 @@ LibCanvas.Canvas2D = atom.Class({
.appendTo(this.wrapper);
},
invoker: function () {
return new LibCanvas.Invoker({
return new Invoker({
context: this,
defaultPriority: 10,
fpsLimit: this.options.fps
Expand Down Expand Up @@ -182,7 +179,7 @@ LibCanvas.Canvas2D = atom.Class({
return this;
},

createProjectBuffer: atom.Class.protectedMethod(function () {
createProjectBuffer: Class.protectedMethod(function () {
if (this.options.backBuffer == 'off') {
this.elem = this.origElem;
this.ctx = this.origCtx;
Expand All @@ -193,11 +190,11 @@ LibCanvas.Canvas2D = atom.Class({
return this;
}),

addClearer: atom.Class.protectedMethod(function () {
addClearer: Class.protectedMethod(function () {
var clear = this.options.clear;
if (clear) {
this.addProcessor('pre',
new LibCanvas.Processors.Clearer(
new Processors.Clearer(
typeof clear === 'string' ? clear : null
)
);
Expand All @@ -216,25 +213,25 @@ LibCanvas.Canvas2D = atom.Class({
},
listenMouse : function (elem) {
this._mouse = LibCanvas.isLibCanvas(elem) ? elem.mouse
: new LibCanvas.Mouse(this, /* preventDefault */elem);
: new Mouse(this, /* preventDefault */elem);
return this;
},
getKey : function (key) {
return this.keyboard.keyState(key);
},
listenKeyboard : function (elem) {
this._keyboard = LibCanvas.isLibCanvas(elem) ? elem.keyboard
: new LibCanvas.Keyboard(/* preventDefault */elem);
: new Keyboard(/* preventDefault */elem);
return this;
},
createBuffer : function (width, height) {
return LibCanvas.Buffer.apply(LibCanvas,
return Buffer.apply(LibCanvas,
arguments.length ? arguments :
Array.collect(this.origElem, ['width', 'height'])
);
},
createShaper : function (options) {
var shaper = new LibCanvas.Ui.Shaper(this, options);
var shaper = new Shaper(this, options);
this.addElement(shaper);
return shaper;
},
Expand Down Expand Up @@ -325,7 +322,7 @@ LibCanvas.Canvas2D = atom.Class({
z = null;
}
options = atom.extend({ name: name }, options || {});
var layer = this._layers[name] = new LibCanvas.Layer(this, this.options, options);
var layer = this._layers[name] = new Layer(this, this.options, options);
layer._layers = this._layers;
layer.zIndex = z;
layer.origElem.atom.attr({ 'data-layer-name': name });
Expand Down
27 changes: 11 additions & 16 deletions Source/Core/Context2D.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,7 @@ provides: Context2D
...
*/

(function (LibCanvas) {

var Point = LibCanvas.Point,
Shapes = LibCanvas.namespace('Shapes'),
Circle = Shapes.Circle,
Rectangle = Shapes.Rectangle;

var Context2D = LibCanvas.Context2D = function () {

var office = {
all : function (type, style) {
Expand All @@ -47,7 +41,7 @@ var office = {
return args.length ? Rectangle(args) : this.rectangle;
},
fillStroke : function (type, args) {
if (args.length >= 1 && args[0] instanceof LibCanvas.Shape) {
if (args.length >= 1 && args[0] instanceof Shape) {
if (args[1]) this.save().set(type + 'Style', args[1]);
args[0].draw(this, type);
if (args[1]) this.restore();
Expand Down Expand Up @@ -84,8 +78,8 @@ var accessors = {};
})
});

LibCanvas.Context2D = atom.Class({
Implements: [atom.Class(accessors)],
var Context2D = Class({
Implements: [Class(accessors)],

initialize : function (canvas) {
if (canvas instanceof CanvasRenderingContext2D) {
Expand Down Expand Up @@ -145,7 +139,7 @@ LibCanvas.Context2D = atom.Class({
var args = [canvas, 0, 0];
if (resize) args.push(width, height);

var clone = LibCanvas.Buffer(width, height, true);
var clone = Buffer(width, height, true);
clone.ctx.original('drawImage', args);
return clone;
},
Expand Down Expand Up @@ -533,10 +527,10 @@ LibCanvas.Context2D = atom.Class({
},
projectiveImage : function (arg) {
// test
new LibCanvas.Inner.ProjectiveTexture(arg.image)
new ProjectiveTexture(arg.image)
.setContext(this.ctx2d)
.setQuality(arg.patchSize, arg.limit)
.render(new Shapes.Polygon(Array.collect(arg, [0, 1, 3, 2])));
.render(new Polygon(Array.collect(arg, [0, 1, 3, 2])));
return this;
},

Expand Down Expand Up @@ -690,8 +684,9 @@ var fixGradient = function (grad) {
return grad;
};

LibCanvas.Context2D.office = office;
Context2D.office = office;

HTMLCanvasElement.addContext('2d-libcanvas', LibCanvas.Context2D);
HTMLCanvasElement.addContext('2d-libcanvas', Context2D);

})(LibCanvas);
return Context2D;
}();
Loading

0 comments on commit e77f926

Please sign in to comment.