Skip to content

Instantly share code, notes, and snippets.

@hvgotcodes
Created March 7, 2012 01:35
Show Gist options
  • Save hvgotcodes/1990324 to your computer and use it in GitHub Desktop.
Save hvgotcodes/1990324 to your computer and use it in GitHub Desktop.
sc_require('sudoku/views/cell');
Sudoku.BoardSurface = SC.CompositeSurface.extend({
backgroundColor: "#268bd2",
contentBinding: SC.Binding.oneWay('Sudoku.cellsController.arrangedObjects'),
contentDidChange: function(){
console.log('cells changed, triggering rendering');
this.triggerRendering();
}.observes('content'),
init: function(){
sc_super();
SC.Binding.flushPendingChanges();
var subsurfaces = this.get('subsurfaces'),
content = this.get('content'),
index = 0;
if(!content) return;
for (var i = 0; i < 9; i++) {
for (var j = 0; j < 9; j++) {
var height = this._cellHeight,
width = this._cellWidth,
x, y, surface,
cellValue = content.objectAt(index);
x = i * width;
y = j * height;
surface = Sudoku.CellSurface.create({
i: i,
j: j,
content: cellValue
});
surface.set('frame', SC.MakeRect(x, y, width, height));
subsurfaces.pushObject(surface);
index++;
}
}
},
updateLayout: function() {
var frame = this.getPath('supersurface.frame'),
w = Math.round(frame[2] / 2) - Math.round(594/2),
h = 50;
this.set('frame', SC.MakeRect(w, h, 594, 594));
this._cellWidth = 594 / 9;
this._cellHeight = 594 / 9;
},
// updateDisplay: function() {
// console.log('board update display');
// // console.log('SC.ContainerSurface#updateDisplay()');
// var subsurfaces = this.get('subsurfaces');
// if (subsurfaces) subsurfaces.invoke('updateDisplay');
// }
});
Sudoku.BoardSurface.MAX_WIDTH = 594;
Sudoku.BoardSurface.MAX_Height = 594;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment