Skip to content
Browse files

Enable tiling drawing

  • Loading branch information...
1 parent c74303b commit 35e45ecfa4518b69aab7359f1247a24090a3c139 @trethaller committed Aug 3, 2013
Showing with 57 additions and 20 deletions.
  1. +16 −4 js/app.coffee
  2. +24 −7 js/app.js
  3. +12 −8 js/core.coffee
  4. +5 −1 js/core.js
View
20 js/app.coffee
@@ -95,19 +95,31 @@ class DocumentView
@backContext.drawImage(@canvas, 0, 0)
onDraw: (pos)->
+ self = this
+
pressure = getPenPressure()
dirtyRects = []
+ tiling = true
layer = @doc.layer
brush = Editor.tool
layerRect = layer.getRect()
- rect = brush.draw(layer, pos, pressure).round().intersect(layerRect)
- if not rect.isEmpty()
- dirtyRects.push(rect)
+
+ r = brush.draw(layer, pos, pressure).round()
- self = this
+ if tiling
+ for xoff in [-1,0,1]
+ for yoff in [-1,0,1]
+ dirtyRects.push(r.offset(new Vec2(xoff * layerRect.width, yoff * layerRect.height)))
+ else
+ dirtyRects.push(r)
+
+ dirtyRects = dirtyRects
+ .map((r)->r.intersect(layerRect))
+ .filter((r)->not r.isEmpty())
+ status(dirtyRects.length)
if true
#setTimeout (()->
Editor.renderer.renderLayer(layer, self, dirtyRects)
View
31 js/app.js
@@ -130,22 +130,39 @@ DocumentView = (function() {
};
DocumentView.prototype.onDraw = function(pos) {
- var brush, dirtyRects, layer, layerRect, pressure, rect, self, _i, _len, _results;
+ var brush, dirtyRects, layer, layerRect, pressure, r, rect, self, tiling, xoff, yoff, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _results;
+ self = this;
pressure = getPenPressure();
dirtyRects = [];
+ tiling = true;
layer = this.doc.layer;
brush = Editor.tool;
layerRect = layer.getRect();
- rect = brush.draw(layer, pos, pressure).round().intersect(layerRect);
- if (!rect.isEmpty()) {
- dirtyRects.push(rect);
+ r = brush.draw(layer, pos, pressure).round();
+ if (tiling) {
+ _ref = [-1, 0, 1];
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ xoff = _ref[_i];
+ _ref1 = [-1, 0, 1];
+ for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
+ yoff = _ref1[_j];
+ dirtyRects.push(r.offset(new Vec2(xoff * layerRect.width, yoff * layerRect.height)));
+ }
+ }
+ } else {
+ dirtyRects.push(r);
}
- self = this;
+ dirtyRects = dirtyRects.map(function(r) {
+ return r.intersect(layerRect);
+ }).filter(function(r) {
+ return !r.isEmpty();
+ });
+ status(dirtyRects.length);
if (true) {
Editor.renderer.renderLayer(layer, self, dirtyRects);
_results = [];
- for (_i = 0, _len = dirtyRects.length; _i < _len; _i++) {
- rect = dirtyRects[_i];
+ for (_k = 0, _len2 = dirtyRects.length; _k < _len2; _k++) {
+ rect = dirtyRects[_k];
_results.push(self.backContext.drawImage(self.canvas, rect.x, rect.y, rect.width + 1, rect.height + 1, rect.x, rect.y, rect.width + 1, rect.height + 1));
}
return _results;
View
20 js/core.coffee
@@ -59,6 +59,9 @@ class Rect
ret.extend(rect.bottomRight())
return ret
+ offset: (vec)->
+ return new Rect(@x+vec.x, @y+vec.y, @width, @height)
+
isEmpty: ()->
return @width<=0 or @height<=0
@@ -217,22 +220,23 @@ genBrushFunc = (args, brushExp, blendExp)->
str = "
(function (rect, dstFb, #{args}) {
- var minx = Math.max(0, -rect.x);
- var miny = Math.max(0, -rect.y);
- var sw = Math.min(rect.width, dstFb.width - rect.x);
- var sh = Math.min(rect.height, dstFb.height - rect.y);
+ var minx = rect.x;
+ var miny = rect.y;
+ var sw = rect.width;
+ var sh = rect.height;
var invw = 2.0 / (rect.width - 1);
var invh = 2.0 / (rect.height - 1);
+ var fbw = dstFb.width;
+ var fbh = dstFb.height;
var dstData = dstFb.getBuffer();
- for(var sy=miny; sy<sh; ++sy) {
- var dsti = (rect.y + sy) * dstFb.width + rect.x + minx;
+ for(var sy=0; sy<sh; ++sy) {
var y = sy * invh - 1.0;
- for(var sx=minx; sx<sw; ++sx) {
+ for(var sx=0; sx<sw; ++sx) {
var x = sx * invw - 1.0;
+ var dsti = (((sy + miny) + fbh) % fbh) * fbw + (((sx + minx) + fbw) % fbw);
var _tmp = 0.0;
#{brushExp};
#{blendExp};
- ++dsti;
}
}
})"
View
6 js/core.js
@@ -118,6 +118,10 @@ Rect = (function() {
return ret;
};
+ Rect.prototype.offset = function(vec) {
+ return new Rect(this.x + vec.x, this.y + vec.y, this.width, this.height);
+ };
+
Rect.prototype.isEmpty = function() {
return this.width <= 0 || this.height <= 0;
};
@@ -285,7 +289,7 @@ genBrushFunc = function(args, brushExp, blendExp) {
var str;
blendExp = blendExp.replace(/{dst}/g, "dstData[dsti]").replace(/{src}/g, "_tmp");
brushExp = brushExp.replace(/{out}/g, "_tmp");
- str = " (function (rect, dstFb, " + args + ") { var minx = Math.max(0, -rect.x); var miny = Math.max(0, -rect.y); var sw = Math.min(rect.width, dstFb.width - rect.x); var sh = Math.min(rect.height, dstFb.height - rect.y); var invw = 2.0 / (rect.width - 1); var invh = 2.0 / (rect.height - 1); var dstData = dstFb.getBuffer(); for(var sy=miny; sy<sh; ++sy) { var dsti = (rect.y + sy) * dstFb.width + rect.x + minx; var y = sy * invh - 1.0; for(var sx=minx; sx<sw; ++sx) { var x = sx * invw - 1.0; var _tmp = 0.0; " + brushExp + "; " + blendExp + "; ++dsti; } } })";
+ str = " (function (rect, dstFb, " + args + ") { var minx = rect.x; var miny = rect.y; var sw = rect.width; var sh = rect.height; var invw = 2.0 / (rect.width - 1); var invh = 2.0 / (rect.height - 1); var fbw = dstFb.width; var fbh = dstFb.height; var dstData = dstFb.getBuffer(); for(var sy=0; sy<sh; ++sy) { var y = sy * invh - 1.0; for(var sx=0; sx<sw; ++sx) { var x = sx * invw - 1.0; var dsti = (((sy + miny) + fbh) % fbh) * fbw + (((sx + minx) + fbw) % fbw); var _tmp = 0.0; " + brushExp + "; " + blendExp + "; } } })";
return eval(str);
};

0 comments on commit 35e45ec

Please sign in to comment.
Something went wrong with that request. Please try again.