Skip to content

Commit

Permalink
add grid system
Browse files Browse the repository at this point in the history
  • Loading branch information
phi-jp committed Mar 30, 2015
1 parent 0822714 commit 04f2642
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 7 deletions.
33 changes: 33 additions & 0 deletions build/tmlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -2811,6 +2811,39 @@ tm.define("tm.util.Flow", {
});


/*
* グリッドシステム
*/
tm.define("tm.util.GridSystem", {
width: 640, // 幅
col: 12, // 列数

init: function(width, col) {
if (typeof arguments[0] === 'object') {
var param = arguments[0];
width = param.width;
col = param.col;
}

this.width = width;
this.col = col;
this.unitWidth = this.width/this.col;
},

// スパン指定で値を取得(負数もok)
span: function(index) {
index += this.col;
index %= this.col;

return this.unitWidth * index;
},

// 真ん中
center: function() {
return this.unitWidth * (this.col/2);
},
});

/*
* vector2.js
*/
Expand Down
15 changes: 8 additions & 7 deletions build/tmlib.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ module.exports = function(grunt) {
"src/util/querystring.js",
"src/util/type.js",
"src/util/flow.js",
"src/util/gridsystem.js",

"src/geom/vector2.js",
"src/geom/vector3.js",
Expand Down
32 changes: 32 additions & 0 deletions src/util/gridsystem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* グリッドシステム
*/
tm.define("tm.util.GridSystem", {
width: 640, // 幅
col: 12, // 列数

init: function(width, col) {
if (typeof arguments[0] === 'object') {
var param = arguments[0];
width = param.width;
col = param.col;
}

this.width = width;
this.col = col;
this.unitWidth = this.width/this.col;
},

// スパン指定で値を取得(負数もok)
span: function(index) {
index += this.col;
index %= this.col;

return this.unitWidth * index;
},

// 真ん中
center: function() {
return this.unitWidth * (this.col/2);
},
});
1 change: 1 addition & 0 deletions test/testhelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"src/util/querystring.js",
"src/util/type.js",
"src/util/flow.js",
"src/util/gridsystem.js",
],
"geom": [
"src/geom/vector2.js",
Expand Down

0 comments on commit 04f2642

Please sign in to comment.