Skip to content

Commit

Permalink
v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Rowell authored and Eric Rowell committed Jul 26, 2017
1 parent da61db4 commit ccfb21a
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 215 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Concrete
Concrete is a lightweight Html5 Canvas framework that enables hit detection, layer support, pixel ratio management, exports, and downloads
Concrete is a lightweight, fast Html5 Canvas framework that enables hit detection, layering, multi-buffering for lightning fast performance, pixel ratio support, and download support

As the creator of KineticJS, author of HTML5 Canvas Cookbook, founder of HTML5CanvasTutorials.com, founder of MeteorCharts, and the lead data visualization engineer at Platfora, I've identified a handful of features that just about every HTML5 Canvas project needs. Concrete packages up these features into a lightweight framework of about 600 lines of JavaScript, including documentation.
As the creator of KineticJS, author of HTML5 Canvas Cookbook, founder of HTML5CanvasTutorials.com, founder of MeteorCharts, and the principal data visualization engineer at Platfora and Workday, I've identified a handful of features that just about every HTML5 Canvas project needs. Concrete packages up these features into a lightweight framework of about 600 lines of JavaScript, including documentation.

# Examples & Documentation

Expand Down
91 changes: 27 additions & 64 deletions build/concrete.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* Concrete v1.0.1
* A lightweight Html5 Canvas framework that enables hit detection, layer support,
* pixel ratio management, exports, and downloads
* Release Date: 3-8-2017
* Concrete v2.0.0
* A lightweight Html5 Canvas framework that enables hit detection, layering, multi buffering,
* pixel ratio management, exports, and image downloads
* Release Date: 7-26-2017
* https://github.com/ericdrowell/concrete
* Licensed under the MIT or GPL Version 2 licenses.
*
Expand Down Expand Up @@ -55,23 +55,18 @@
if (!config) {
config = {};
}
this.width = 0;
this.height = 0;

this.container = config.container;
this.layers = [];
this.id = idCounter++;

this.container = document.createElement('div');
this.container.className = 'concrete-container';
this.container.style.display = 'inline-block';
this.container.style.position = 'relative';

if (config.width && config.height) {
this.setSize(config.width, config.height);
}
this.scene = new Concrete.Scene();

this.setSize(config.width || 0, config.height || 0);


// clear container
config.container.innerHTML = '';
config.container.appendChild(this.container);
config.container.appendChild(this.scene.canvas);

Concrete.viewports.push(this);
};
Expand All @@ -86,7 +81,6 @@
this.layers.push(layer);
layer.setSize(layer.width || this.width, layer.height || this.height);
layer.viewport = this;
this.container.appendChild(layer.container);
return this;
},
/**
Expand All @@ -98,8 +92,7 @@
setSize: function(width, height) {
this.width = width;
this.height = height;
this.container.style.width = this.width + 'px';
this.container.style.height = this.height + 'px';
this.scene.setSize(width, height);
return this;
},
/**
Expand All @@ -123,28 +116,6 @@

return null;
},
/**
* convert viewport into a Concrete scene
* @param {Object} config
* @param {Number} config.pixelRatio - typically 1 or 2
* @returns {Concrete.Scene}
*/
toScene: function(config) {
if (!config) {
config = {};
}
var scene = new Concrete.Scene({
pixelRatio: config.pixelRatio,
width: this.width,
height: this.height
});

this.layers.forEach(function(layer) {
scene.context.drawImage(layer.scene.canvas, 0, 0, layer.width, layer.height);
});

return scene;
},
/**
* get viewport index from all Concrete viewports
* @returns {Integer}
Expand Down Expand Up @@ -173,8 +144,23 @@
layer.destroy();
});

// clear dom
this.container.innerHTML = '';

// remove self from viewports array
Concrete.viewports.splice(this.getIndex(), 1);
},
/**
* composite all layers onto visible canvas
*/
render: function() {
var scene = this.scene;

scene.clear();

this.layers.forEach(function(layer) {
scene.context.drawImage(layer.scene.canvas, 0, 0, layer.width, layer.height);
});
}
};

Expand All @@ -201,13 +187,6 @@
this.hit = new Concrete.Hit();
this.scene = new Concrete.Scene();

this.container = document.createElement('div');
this.container.className = 'concrete-layer';
this.container.style.display = 'inline-block';
this.container.style.position = 'absolute';
this.container.appendChild(this.hit.canvas);
this.container.appendChild(this.scene.canvas);

if (config.x && config.y) {
this.setPosition(config.x, config.y);
}
Expand All @@ -225,9 +204,7 @@
*/
setPosition: function(x, y) {
this.x = x;
this.container.style.left = x + 'px';
this.y = y;
this.container.style.top = y + 'px';
return this;
},
/**
Expand All @@ -238,9 +215,7 @@
*/
setSize: function(width, height) {
this.width = width;
this.container.style.width = width + 'px';
this.height = height;
this.container.style.height = height + 'px';
this.scene.setSize(width, height);
this.hit.setSize(width, height);
return this;
Expand All @@ -258,8 +233,6 @@
// swap
layers[index] = layers[index+1];
layers[index+1] = this;

viewport.container.insertBefore(this.container, viewport.container.children[index+2]);
}

return this;
Expand All @@ -277,8 +250,6 @@
// swap
layers[index] = layers[index-1];
layers[index-1] = this;

viewport.container.insertBefore(this.container, viewport.container.children[index-1]);
}

return this;
Expand All @@ -294,8 +265,6 @@

layers.splice(index, 1);
layers.push(this);

viewport.container.appendChild(this.container);
},
/**
* move to bottom
Expand All @@ -309,8 +278,6 @@
layers.splice(index, 1);
layers.unshift(this);

viewport.container.insertBefore(this.container, viewport.container.firstChild);

return this;
},
/**
Expand Down Expand Up @@ -338,9 +305,6 @@
destroy: function() {
// remove self from layers array
this.viewport.layers.splice(this.getIndex(), 1);

// remove self from dom
this.viewport.container.removeChild(this.container);
}
};

Expand All @@ -366,7 +330,6 @@
this.canvas = document.createElement('canvas');
this.canvas.className = 'concrete-scene-canvas';
this.canvas.style.display = 'inline-block';
this.canvas.style.position = 'absolute';
this.context = this.canvas.getContext('2d');

if (config.width && config.height) {
Expand Down
10 changes: 5 additions & 5 deletions build/concrete.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion examples/three-circles.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
circles.forEach(function(circle) {
drawSceneCircle(circle);
});
viewport.render();
}

function drawHitCircles() {
Expand Down Expand Up @@ -223,6 +224,7 @@
if (circle) {
circle.layer.moveUp();
}
viewport.render();
});

document.getElementById('moveDown').addEventListener('click', function() {
Expand All @@ -231,6 +233,7 @@
if (circle) {
circle.layer.moveDown();
}
viewport.render();
});

document.getElementById('moveToTop').addEventListener('click', function() {
Expand All @@ -239,6 +242,7 @@
if (circle) {
circle.layer.moveToTop();
}
viewport.render();
});

document.getElementById('moveToBottom').addEventListener('click', function() {
Expand All @@ -247,6 +251,7 @@
if (circle) {
circle.layer.moveToBottom();
}
viewport.render();
});

document.getElementById('destroy').addEventListener('click', function() {
Expand All @@ -255,10 +260,11 @@
if (circle) {
circle.layer.destroy();
}
viewport.render();
});

document.getElementById('download').addEventListener('click', function() {
viewport.toScene().download({
viewport.scene.download({
fileName: 'three-circles.png'
});
});
Expand Down
4 changes: 2 additions & 2 deletions license.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Concrete v@@VERSION
* A lightweight Html5 Canvas framework that enables hit detection, layer support,
* pixel ratio management, exports, and downloads
* A lightweight Html5 Canvas framework that enables hit detection, layering, multi buffering,
* pixel ratio management, exports, and image downloads
* Release Date: @@DATE
* https://github.com/ericdrowell/concrete
* Licensed under the MIT or GPL Version 2 licenses.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "concrete",
"version": "1.0.1",
"version": "2.0.0",
"devDependencies": {
"chai": "^3.4.1",
"gulp": "^3.9.0",
Expand Down
Loading

0 comments on commit ccfb21a

Please sign in to comment.