Permalink
Browse files

Enable tiling drawing

  • Loading branch information...
trethaller committed Aug 3, 2013
1 parent c74303b commit 35e45ecfa4518b69aab7359f1247a24090a3c139
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
@@ -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

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -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

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit 35e45ec

Please sign in to comment.