grid.js 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. define(function(require, exports, module) {
  2. var Rect = require('graphic/rect');
  3. var PatternBrush = require('graphic/patternbrush');
  4. return require('core/class').createClass('Grid', {
  5. base: Rect,
  6. constructor: function( x, y, width, height, gridSize, color1, color2 ) {
  7. this.color1 = color1 || 'white';
  8. this.color2 = color2 || 'lightgray';
  9. this.gridSize = gridSize;
  10. this.callBase(width, height, x, y);
  11. this.draw();
  12. },
  13. draw: function() {
  14. var me = this;
  15. function lazyDraw() {
  16. var paper = me.getPaper();
  17. if( !paper ) {
  18. return setTimeout( lazyDraw, 100 );
  19. }
  20. var size = me.gridSize;
  21. me.fill(new PatternBrush().pipe(function() {
  22. this.setX(0).setY(0);
  23. this.setWidth(size * 2).setHeight(size * 2);
  24. this.addShape(new Rect(size, size).fill(me.color2));
  25. this.addShape(new Rect(size, size, size, size).fill(me.color2));
  26. paper.addResource(this);
  27. }));
  28. }
  29. lazyDraw();
  30. }
  31. });
  32. });