Repository navigation
Expand file tree
/
Copy pathGrid.json
More file actions
160 lines (160 loc) · 8.5 KB
/
Copy pathGrid.json
File metadata and controls
160 lines (160 loc) · 8.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
{
"cls": "Grid",
"description": "<h3>A grid divides a space into cells, puts things into groups. Like scattering a handful of peas on the chessboard, we can simplify the description of a state by clarifying its context. A grid thus help us interpret spaces and restate forms.</h3>",
"extend": "Rectangle",
"file": "Grid.coffee",
"funcs": [
{
"description": "<h2>Create a new Grid. Like a Rectangle, a Grid's area are defined by two Vectors.</h2>",
"eg": "<p><code>new Grid()</code> <code>new Grid(1,2,3)</code> <code>new Grid([2,4])</code> <code>new Grid({x:3, y:6, z:9}).to(1,2,3)</code></p>",
"name": "Grid",
"param": [
"<p><code>args</code> Similar to Pair constructor, use comma-separated values, an array, or an object as parameters to specify the first point. As a shortcut to <code>to()</code>, you can also pass 4 or 6 values to set both anchor and <code>p1</code> points directly as a 2d or 3d vector.</p>"
],
"pname": "",
"return": "<p>a new Grid object</p>"
},
{
"description": "<h2>Describe this grid as a text string</h2>",
"name": "toString",
"param": [],
"pname": "",
"return": "<p>\"Grid width, height, columns, rows, cell\" text</p>"
},
{
"description": "<h2>Initiate a grid</h2>",
"eg": "<p><code>grid.create(100,50)</code> <code>grid.create( 10,10, \"stretch\",\"stretch\")</code> <code>grid.create( 20,20, \"flex\",\"fix\")</code></p>",
"name": "init",
"param": [
"<p><code>x</code> a value to specify cell width (if <code>xtype</code> parameter is \"fix\" or \"flex\") or column count (if <code>xtype</code> parameter is \"stretch\")</p>",
"<p><code>y</code> a value to specify cell height (if <code>ytype</code> parameter is \"fix\" or \"flex\") or row count (if <code>ytype</code> parameter is \"stretch\")</p>",
"<p><code>xtype, ytype</code> a string to specify how columns and rows should be calculated. Use \"fix\" to specify exact cell width or height in pixels, \"flex\" to specify ideal cell width or height in pixels (which allows for flexible rounding to rows or columns), \"stretch\" to specify number of rows or columns only</p>"
],
"pname": "x, y, xtype='fix', ytype='fix'",
"return": "<p>this grid</p>"
},
{
"demo": "grid.generate",
"description": "<h2>Define a callback function for cell creation. This will loop through each cell in the grid and call the callback function.</h2>",
"name": "generate",
"param": [
"<p><code>callback</code> a callback function with these parameters <code>( cell_size, cell_position, cell_row, cell_column, cell_type )</code></p>"
],
"pname": "callback",
"return": "<p>this grid</p>"
},
{
"description": "<h2>Generate the grid by looping through each cell</h2>",
"name": "create",
"param": [],
"pname": ""
},
{
"description": "<h2>Get the cell's size as a Vector</h2>",
"name": "getCellSize",
"param": [],
"pname": "",
"return": "<p>a cloned <code>cell.size</code> property as Vector</p>"
},
{
"description": "<h2>Give a column and a row, get a rectangle which indicates the cell position and size</h2>",
"eg": "<p><code>grid.cellToRectangle(2, 3)</code>, <code>grid.cellToRectangle(2, 5, true)</code></p>",
"name": "cellToRectangle",
"param": [
"<p><code>c, r</code> column and row index, respectively</p>",
"<p><code>allowOutofBound</code> a boolean value to set if the returned rectangle can be outside of the grid</p>"
],
"pname": "c, r, allowOutofBound=false",
"return": "<p>a Rectangle</p>"
},
{
"description": "<h2>Give a x,y position, get the corresponding cell on the grid.</h2>",
"eg": "<p><code>grid.positionToCell( 100, 50 )</code>, <code>grid.positionToCell( [100, 50] )</code>, <code>grid.positionToCell( pt )</code>,</p>",
"name": "positionToCell",
"param": [
"<p><code>args</code> 0-3 comma-separated values, or as an array, or a Point object.</p>"
],
"pname": "args",
"return": "<p>a Vector object whose <code>x</code> is the column index and <code>y</code> is the row index</p>"
},
{
"description": "<h2>Reset the layout and its cell states</h2>",
"name": "resetLayout",
"param": [
"<p><code>callback</code> a function with these parameters ( this_grid, cell_row, cell_column ). This will get called after each cell's reset.</p>"
],
"pname": "callback",
"return": "<p>this grid</p>"
},
{
"demo": "grid.occupy",
"description": "<h2>Mark a certain area in the grid layout as occupied</h2>",
"eg": "<p><code>grid.occupy(0,0, 5,3)</code></p>",
"name": "occupy",
"param": [
"<p><code>x, y</code> column and row index</p>",
"<p><code>w</code> column width</p>",
"<p><code>h</code> row size</p>",
"<p><code>occupy</code> a boolean value to set if this cell should be occupied. Defaults to <code>true</code></p>"
],
"pname": "x, y, w, h, occupy=true",
"return": "<p>this grid</p>"
},
{
"description": "<h2>Check a certain area in the grid is unoccupied</h2>",
"eg": "<p><code>grid.canFit(0,0, 5,3)</code></p>",
"name": "canFit",
"param": [
"<p><code>x, y</code> column and row index</p>",
"<p><code>w</code> column width</p>",
"<p><code>h</code> row size</p>"
],
"pname": "x, y, w, h",
"return": "<p>a boolean value where <code>true</code> means the area is unoccupied</p>"
},
{
"description": "<h2>Fit this area as much as possible within the grid's free ceels</h2>",
"name": "fit",
"param": [
"<p><code>cols</code> number of columns</p>",
"<p><code>rows</code> number of rows</p>"
],
"pname": "cols, rows",
"return": "<p>an object with properties <code>row</code> and <code>column</code> to specify the top left position, <code>columnSize</code> and <code>rowSize</code> to specify the resulting size in grid units, and <code>bound</code> which is the actual area as a Rectangle object.</p>"
},
{
"description": "<h2>Given a cell's position, get an array of the neighboring cells that surround it</h2>",
"eg": "<p><code>grid.neighbors( 3, 2 )</code>, <code>(grid.neighbors(3, 2))[Const.top_right]</code></p>",
"name": "neighbors",
"param": [
"<p><code>c</code> column index</p>",
"<p><code>r</code> row index</p>"
],
"pname": "c, r",
"return": "<p>an array of neighbors starting from top-left going clockwise. The array values can be Vectors whose <code>x</code> is column index and <code>y</code> is row index, or <code>false</code> if the neighbor cell is out of bounds. You may access the cells semantically by using Const.top_right etc.</p>"
}
],
"props": [
{
"description": "<h2>grid cell settings as an object with <code>.type</code> property which defines the grid type such as \"fix-fix\", and <code>.size</code> property which stores the cell size as a Vector object.</h2>",
"name": "cell",
"param": []
},
{
"description": "<h2>property to specify number of rows in the grid</h2>",
"name": "rows",
"param": []
},
{
"description": "<h2>property to specify number of columns in the grid</h2>",
"name": "columns",
"param": []
},
{
"description": "<h2>property to store layout and cell states</h2>",
"name": "layout",
"param": []
}
],
"statics": []
}