Permalink
Browse files

Fix: Resurrect non tiling mode

  • Loading branch information...
1 parent 6ffdd51 commit 7ae5eea0adb691b1990eea74a47c5f8948622852 @trethaller committed Aug 11, 2013
Showing with 79 additions and 46 deletions.
  1. +2 −0 index.html
  2. +4 −7 js/app.coffee
  3. +3 −6 js/app.js
  4. +36 −18 js/core.coffee
  5. +8 −5 js/core.js
  6. +12 −7 js/tools.coffee
  7. +14 −3 js/tools.js
View
2 index.html
@@ -30,6 +30,8 @@
<div class="properties"></div>
</div>
</div>
+ <pre id="status-bar">
+ </pre>
</div>
<!--[if IE]>
View
11 js/app.coffee
@@ -175,7 +175,7 @@ class DocumentView
for yoff in [-1,0,1]
dirtyRects.push(r.offset(new Vec2(xoff * layerRect.width, yoff * layerRect.height)))
else
- dirtyRects.push(r)
+ dirtyRects.push(r.intersect(layerRect))
dirtyRects = dirtyRects
.map((r)->r.intersect(layerRect))
@@ -331,7 +331,7 @@ refresh = ()->
editor = null
-toolsProperties = new PropertyPanel '#tools > .properties'
+toolsProperties = null
createToolsButtons = ($container)->
@@ -390,11 +390,6 @@ loadGradient = (name, url)->
imageObj.src = url
# --
-
-_.templateSettings = {
- interpolate : /\{\{(.+?)\}\}/g
-};
-
loadGradient('g1', 'img/gradient-1.png')
@@ -409,9 +404,11 @@ $(window).keyup (e)->
$(document).ready ()->
+ toolsProperties = new PropertyPanel '#tools > .properties'
editor = new Editor()
editor.createDoc(512, 512)
+
createToolsButtons($('#tools > .buttons'))
createRenderersButtons($('#renderers > .buttons'))
createPalette($('#palette'))
View
9 js/app.js
@@ -225,7 +225,7 @@ DocumentView = (function() {
}
}
} else {
- dirtyRects.push(r);
+ dirtyRects.push(r.intersect(layerRect));
}
dirtyRects = dirtyRects.map(function(r) {
return r.intersect(layerRect);
@@ -428,7 +428,7 @@ refresh = function() {
editor = null;
-toolsProperties = new PropertyPanel('#tools > .properties');
+toolsProperties = null;
createToolsButtons = function($container) {
$container.empty();
@@ -510,10 +510,6 @@ loadGradient = function(name, url) {
return imageObj.src = url;
};
-_.templateSettings = {
- interpolate: /\{\{(.+?)\}\}/g
-};
-
loadGradient('g1', 'img/gradient-1.png');
$(window).keydown(function(e) {
@@ -529,6 +525,7 @@ $(window).keyup(function(e) {
});
$(document).ready(function() {
+ toolsProperties = new PropertyPanel('#tools > .properties');
editor = new Editor();
editor.createDoc(512, 512);
createToolsButtons($('#tools > .buttons'));
View
54 js/core.coffee
@@ -163,6 +163,7 @@ GammaRenderer = (()->
var offset = iy * width;
for(var ix=minX; ix<=maxX; ++ix) {
var fval = fb[offset + ix];
+ fval = fval > 1.0 ? 1.0 : (fval < -1.0 ? -1.0 : fval)
var val = Math.round(Math.pow((fval + 1.0) * 0.5, gamma) * 255.0);
destBuffer[offset + ix] =
(val) | (val << 8) | (val << 16) | 0xff000000;
@@ -310,30 +311,31 @@ genBlendFunc = (args, expression)->
}
}
})"
- #console.log("Generating blend function", str)
return eval(str)
-genBrushFunc = (args, brushExp, blendExp)->
- blendExp = blendExp
+genBrushFunc = (opts)->
+ blendExp = opts.blendExp
.replace(/{dst}/g, "dstData[dsti]")
.replace(/{src}/g, "_tmp")
- brushExp = brushExp
+ brushExp = opts.brushExp
.replace(/{out}/g, "_tmp")
- str = "
- (function (rect, dstFb, #{args}) {
- var sw = Math.round(rect.width);
- var sh = Math.round(rect.height);
- var invw = 2.0 / (rect.width - 1);
- var invh = 2.0 / (rect.height - 1);
- var offx = -(rect.x % 1.0) * invw - 1.0;
- var offy = -(rect.y % 1.0) * invh - 1.0;
- var fbw = dstFb.width;
- var fbh = dstFb.height;
+ str = "(function (rect, dstFb, #{opts.args}) {
+ var invw = 2.0 / (rect.width - 1);
+ var invh = 2.0 / (rect.height - 1);
+ var offx = -(rect.x % 1.0) * invw - 1.0;
+ var offy = -(rect.y % 1.0) * invh - 1.0;
+ var fbw = dstFb.width;
+ var fbh = dstFb.height;
+ var dstData = dstFb.getBuffer();"
+
+ str += if opts.tiling then "
var minx = Math.floor(rect.x) + fbw;
var miny = Math.floor(rect.y) + fbh;
- var dstData = dstFb.getBuffer();
+ var sw = Math.round(rect.width);
+ var sh = Math.round(rect.height);
+
for(var sy=0; sy<sh; ++sy) {
var y = sy * invh + offy;
for(var sx=0; sx<sw; ++sx) {
@@ -343,10 +345,26 @@ genBrushFunc = (args, brushExp, blendExp)->
#{brushExp};
#{blendExp};
}
- }
- })"
- return eval(str)
+ }"
+ else "
+ var minx = Math.floor(Math.max(0, -rect.x));
+ var miny = Math.floor(Math.max(0, -rect.y));
+ var sw = Math.round(Math.min(rect.width, fbw - rect.x));
+ var sh = Math.round(Math.min(rect.height, fbh - rect.y));
+ for(var sy=miny; sy<sh; ++sy) {
+ var dsti = (Math.floor(rect.y) + sy) * dstFb.width + Math.floor(rect.x) + minx;
+ var y = sy * invh + offy;
+ for(var sx=minx; sx<sw; ++sx) {
+ var x = sx * invw + offx;
+ var _tmp = 0.0;
+ #{brushExp};
+ #{blendExp};
+ ++dsti;
+ }
+ }"
+ str += "});"
+ return eval(str)
getRoundBrushFunc = (hardness) ->
hardnessPlus1 = hardness + 1.0
View
13 js/core.js
@@ -261,6 +261,7 @@ GammaRenderer = (function() {
var offset = iy * width;
for(var ix=minX; ix<=maxX; ++ix) {
var fval = fb[offset + ix];
+ fval = fval > 1.0 ? 1.0 : (fval < -1.0 ? -1.0 : fval)
var val = Math.round(Math.pow((fval + 1.0) * 0.5, gamma) * 255.0);
destBuffer[offset + ix] =
(val) | (val << 8) | (val << 16) | 0xff000000;
@@ -371,11 +372,13 @@ genBlendFunc = function(args, expression) {
return eval(str);
};
-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 sw = Math.round(rect.width); var sh = Math.round(rect.height); var invw = 2.0 / (rect.width - 1); var invh = 2.0 / (rect.height - 1); var offx = -(rect.x % 1.0) * invw - 1.0; var offy = -(rect.y % 1.0) * invh - 1.0; var fbw = dstFb.width; var fbh = dstFb.height; var minx = Math.floor(rect.x) + fbw; var miny = Math.floor(rect.y) + fbh; var dstData = dstFb.getBuffer(); for(var sy=0; sy<sh; ++sy) { var y = sy * invh + offy; for(var sx=0; sx<sw; ++sx) { var x = sx * invw + offx; var dsti = ((sy + miny) % fbh) * fbw + ((sx + minx) % fbw); var _tmp = 0.0; " + brushExp + "; " + blendExp + "; } } })";
+genBrushFunc = function(opts) {
+ var blendExp, brushExp, str;
+ blendExp = opts.blendExp.replace(/{dst}/g, "dstData[dsti]").replace(/{src}/g, "_tmp");
+ brushExp = opts.brushExp.replace(/{out}/g, "_tmp");
+ str = "(function (rect, dstFb, " + opts.args + ") { var invw = 2.0 / (rect.width - 1); var invh = 2.0 / (rect.height - 1); var offx = -(rect.x % 1.0) * invw - 1.0; var offy = -(rect.y % 1.0) * invh - 1.0; var fbw = dstFb.width; var fbh = dstFb.height; var dstData = dstFb.getBuffer();";
+ str += opts.tiling ? " var minx = Math.floor(rect.x) + fbw; var miny = Math.floor(rect.y) + fbh; var sw = Math.round(rect.width); var sh = Math.round(rect.height); for(var sy=0; sy<sh; ++sy) { var y = sy * invh + offy; for(var sx=0; sx<sw; ++sx) { var x = sx * invw + offx; var dsti = ((sy + miny) % fbh) * fbw + ((sx + minx) % fbw); var _tmp = 0.0; " + brushExp + "; " + blendExp + "; } }" : " var minx = Math.floor(Math.max(0, -rect.x)); var miny = Math.floor(Math.max(0, -rect.y)); var sw = Math.round(Math.min(rect.width, fbw - rect.x)); var sh = Math.round(Math.min(rect.height, fbh - rect.y)); for(var sy=miny; sy<sh; ++sy) { var dsti = (Math.floor(rect.y) + sy) * dstFb.width + Math.floor(rect.x) + minx; var y = sy * invh + offy; for(var sx=minx; sx<sw; ++sx) { var x = sx * invw + offx; var _tmp = 0.0; " + brushExp + "; " + blendExp + "; ++dsti; } }";
+ str += "});";
return eval(str);
};
View
19 js/tools.coffee
@@ -5,6 +5,7 @@ class StepBrush
accumulator: 0.0
stepSize: 4.0
nsteps: 0
+ tiling: false
drawStep: (layer, pos, intensity, rect)->
fb = layer.getBuffer()
@@ -15,7 +16,7 @@ class StepBrush
move: (pos, pressure) ->;
draw: (layer, pos, pressure) ->
- wpos = pos.wrap(layer.width, layer.height)
+ wpos = if @tiling then pos.wrap(layer.width, layer.height) else pos
rect = new Rect(wpos.x, wpos.y, 1, 1)
intensity = pressure
if @lastpos?
@@ -26,7 +27,8 @@ class StepBrush
@accumulator += @stepSize
pt = @lastpos
.add(dir.scale(@accumulator))
- .wrap(layer.width, layer.height)
+ if @tiling
+ pt = pt.wrap(layer.width, layer.height)
@drawStep(layer, pt, intensity, rect)
++@nsteps
@accumulator -= length
@@ -128,21 +130,24 @@ RoundBrush = (()->
createTool = (env)->
sb = new StepBrush()
sb.stepSize = self.get('stepSize')
+ sb.tiling = env.get('tiling')
size = self.get('size')
hardness = Math.pow(self.get('hardness'), 2.0) * 8.0;
hardnessPlus1 = hardness + 1.0
- func = genBrushFunc("intensity, target, h, hp1",
- "var d = Math.min(1.0, Math.max(0.0, (Math.sqrt(x*x + y*y) * hp1 - h)));
- {out} = Math.cos(d * Math.PI) * 0.5 + 0.5;",
- BlendModes[self.get('blendMode')])
+ func = genBrushFunc {
+ args: "intensity, target, h, hp1"
+ tiling: env.get('tiling')
+ blendExp: BlendModes[self.get('blendMode')]
+ brushExp: "var d = Math.min(1.0, Math.max(0.0, (Math.sqrt(x*x + y*y) * hp1 - h)));
+ {out} = Math.cos(d * Math.PI) * 0.5 + 0.5;"
+ }
sb.drawStep = (layer, pos, intensity, rect)->
r = new Rect(
pos.x - size * 0.5,
pos.y - size * 0.5,
size, size)
-
func(r, layer, intensity * self.get('intensity'), env.get('targetValue'), hardness, hardnessPlus1)
rect.extend(r.round())
return sb
View
17 js/tools.js
@@ -16,6 +16,8 @@ StepBrush = (function() {
StepBrush.prototype.nsteps = 0;
+ StepBrush.prototype.tiling = false;
+
StepBrush.prototype.drawStep = function(layer, pos, intensity, rect) {
var fb;
fb = layer.getBuffer();
@@ -31,7 +33,7 @@ StepBrush = (function() {
StepBrush.prototype.draw = function(layer, pos, pressure) {
var delt, dir, intensity, length, pt, rect, wpos;
- wpos = pos.wrap(layer.width, layer.height);
+ wpos = this.tiling ? pos.wrap(layer.width, layer.height) : pos;
rect = new Rect(wpos.x, wpos.y, 1, 1);
intensity = pressure;
if (this.lastpos != null) {
@@ -40,7 +42,10 @@ StepBrush = (function() {
dir = delt.scale(1.0 / length);
while (this.accumulator + this.stepSize <= length) {
this.accumulator += this.stepSize;
- pt = this.lastpos.add(dir.scale(this.accumulator)).wrap(layer.width, layer.height);
+ pt = this.lastpos.add(dir.scale(this.accumulator));
+ if (this.tiling) {
+ pt = pt.wrap(layer.width, layer.height);
+ }
this.drawStep(layer, pt, intensity, rect);
++this.nsteps;
}
@@ -156,10 +161,16 @@ RoundBrush = (function() {
var func, hardness, hardnessPlus1, sb, size;
sb = new StepBrush();
sb.stepSize = self.get('stepSize');
+ sb.tiling = env.get('tiling');
size = self.get('size');
hardness = Math.pow(self.get('hardness'), 2.0) * 8.0;
hardnessPlus1 = hardness + 1.0;
- func = genBrushFunc("intensity, target, h, hp1", "var d = Math.min(1.0, Math.max(0.0, (Math.sqrt(x*x + y*y) * hp1 - h))); {out} = Math.cos(d * Math.PI) * 0.5 + 0.5;", BlendModes[self.get('blendMode')]);
+ func = genBrushFunc({
+ args: "intensity, target, h, hp1",
+ tiling: env.get('tiling'),
+ blendExp: BlendModes[self.get('blendMode')],
+ brushExp: "var d = Math.min(1.0, Math.max(0.0, (Math.sqrt(x*x + y*y) * hp1 - h))); {out} = Math.cos(d * Math.PI) * 0.5 + 0.5;"
+ });
sb.drawStep = function(layer, pos, intensity, rect) {
var r;
r = new Rect(pos.x - size * 0.5, pos.y - size * 0.5, size, size);

0 comments on commit 7ae5eea

Please sign in to comment.