Grid now maintains aspect ratio on scale
Muuuch better. Less jank.
This commit is contained in:
parent
8483bc384c
commit
c6a5b0458e
|
@ -5,11 +5,13 @@
|
||||||
Vector
|
Vector
|
||||||
){
|
){
|
||||||
|
|
||||||
Engine.Shape.Puller = function(x, y, width, height, points, polygons){
|
Engine.Shape.Puller = function(width, height, json){
|
||||||
var i, ref, point, poly;
|
var i, ref, point, poly;
|
||||||
|
|
||||||
this.pos = new Vector(x, y);
|
this.pos = new Vector(0, 0);
|
||||||
this.size = new Vector(width, height);
|
this.size = new Vector(width, height);
|
||||||
|
this.heightRatio = json.data.width / json.data.height;
|
||||||
|
this.widthRatio = json.data.ar;
|
||||||
|
|
||||||
this.resize(width, height, true);
|
this.resize(width, height, true);
|
||||||
|
|
||||||
|
@ -17,19 +19,19 @@ Engine.Shape.Puller = function(x, y, width, height, points, polygons){
|
||||||
this.points = [];
|
this.points = [];
|
||||||
this.polygons = [];
|
this.polygons = [];
|
||||||
|
|
||||||
for (i = 0; i < points.length; i++) {
|
for (i = 0; i < json.points.length; i++) {
|
||||||
point = new Point(
|
point = new Point(
|
||||||
points[i].id,
|
json.points[i].id,
|
||||||
points[i].x,
|
json.points[i].x,
|
||||||
points[i].y,
|
json.points[i].y,
|
||||||
this.size
|
this.size
|
||||||
);
|
);
|
||||||
ref[point.id] = point;
|
ref[point.id] = point;
|
||||||
this.points.push(point);
|
this.points.push(point);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < polygons.length; i++) {
|
for (i = 0; i < json.polygons.length; i++) {
|
||||||
poly = polygons[i];
|
poly = json.polygons[i];
|
||||||
this.polygons.push(new Polygon(
|
this.polygons.push(new Polygon(
|
||||||
ref[poly.points[0]],
|
ref[poly.points[0]],
|
||||||
ref[poly.points[1]],
|
ref[poly.points[1]],
|
||||||
|
@ -49,14 +51,21 @@ Engine.Shape.Puller.prototype = {
|
||||||
sizeOffset: 100,
|
sizeOffset: 100,
|
||||||
|
|
||||||
resize: function(width, height, sizeOnly){
|
resize: function(width, height, sizeOnly){
|
||||||
var halfOffset = this.sizeOffset / 2,
|
var len, p, newWidth, newHeight;
|
||||||
len, p;
|
|
||||||
|
|
||||||
this.size.x = width + this.sizeOffset;
|
newHeight = height + this.sizeOffset;
|
||||||
this.size.y = height + this.sizeOffset;
|
newWidth = this.size.y * this.heightRatio;
|
||||||
|
|
||||||
this.pos.x = -(width / 2 + halfOffset);
|
if (newWidth < width) {
|
||||||
this.pos.y = -(height / 2 + halfOffset);
|
newWidth = width + this.sizeOffset;
|
||||||
|
newHeight = newWidth * this.widthRatio;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.size.y = newHeight;
|
||||||
|
this.size.x = newWidth;
|
||||||
|
|
||||||
|
this.pos.x = -(newWidth / 2);
|
||||||
|
this.pos.y = -(newHeight / 2);
|
||||||
|
|
||||||
if (sizeOnly) {
|
if (sizeOnly) {
|
||||||
return this;
|
return this;
|
||||||
|
|
|
@ -137,14 +137,7 @@ Engine = Base.extend({
|
||||||
Logo.Polygons
|
Logo.Polygons
|
||||||
);
|
);
|
||||||
|
|
||||||
this.grid = new Engine.Shape.Puller(
|
this.grid = new Engine.Shape.Puller(this.width, this.height, Grid);
|
||||||
-(this.width / 2),
|
|
||||||
-(this.height / 2),
|
|
||||||
this.width,
|
|
||||||
this.height,
|
|
||||||
Grid.points,
|
|
||||||
Grid.polygons
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function(){
|
render: function(){
|
||||||
|
|
Loading…
Reference in New Issue