Skip to content

Commit

Permalink
Flatten brush !
Browse files Browse the repository at this point in the history
  • Loading branch information
trethaller committed Sep 1, 2013
1 parent 88a2ce5 commit a8784ec
Show file tree
Hide file tree
Showing 7 changed files with 236 additions and 75 deletions.
26 changes: 22 additions & 4 deletions out/js/teztura-core.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

133 changes: 96 additions & 37 deletions out/js/teztura.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/app.coffee
Expand Up @@ -211,7 +211,7 @@ $(document).ready ()->
#loadGradient('g2', 'img/gradient-2.png')

Renderers = [GammaRenderer, NormalRenderer, GradientRenderer]
Tools = [RoundBrush, Picker]
Tools = [RoundBrush, Picker, FlattenBrush]

toolsProperties = new PropertyPanel '#tools > .properties'
editor = new Editor()
Expand All @@ -224,7 +224,7 @@ $(document).ready ()->
createCommandsButtons($('#commands'))

editor.set('preset', {
tools: [RoundBrush, Picker]
tools: [RoundBrush, FlattenBrush]
})
editor.set('renderer', GammaRenderer)

20 changes: 15 additions & 5 deletions src/core/core.coffee
Expand Up @@ -22,6 +22,16 @@ class Layer
getNormalAt: (pos)->
p = pos.round()
fb = @data.fbuffer
px = Math.round(pos.x)
py = Math.round(pos.y)
sx1 = fb[ py * @width + ((px-1)%@width) ]
sx2 = fb[ py * @width + ((px+1)%@width) ]
sy1 = fb[ ((py+1) % @height) * @width + px ]
sy2 = fb[ ((py-1) % @height) * @width + px ]
xvec = new Vec3(2, 0, sx2 - sx1)
yvec = new Vec3(0, 2, sy1 - sy2)
norm = xvec.cross(yvec).normalized()
return norm

getCopy: (rect)->
srcData = @data.buffer
Expand Down Expand Up @@ -112,14 +122,14 @@ genBrushFunc = (opts)->
brushExp = opts.brushExp
.replace(/{out}/g, "_tmp")

str = "(function (rect, dstFb, #{opts.args}) {
str = "(function (rect, layer, #{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();"
var fbw = layer.width;
var fbh = layer.height;
var dstData = layer.getBuffer();"

str += if opts.tiling then "
var minx = Math.floor(rect.x) + fbw;
Expand All @@ -143,7 +153,7 @@ genBrushFunc = (opts)->
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 dsti = (Math.floor(rect.y) + sy) * layer.width + Math.floor(rect.x) + minx;
var y = sy * invh + offy;
for(var sx=minx; sx<sw; ++sx) {
var x = sx * invw + offx;
Expand Down
4 changes: 4 additions & 0 deletions src/core/vec.coffee
Expand Up @@ -27,6 +27,8 @@ class Vec2
return new Vec2(
(@x % w + w) % w,
(@y % h + h) % h)
toString: ->
return @x + ", " + @y

class Vec3
constructor: (@x, @y, @z) ->;
Expand All @@ -50,3 +52,5 @@ class Vec3
dot: (v)->
return @x+v.x + @y+v.y + @z+v.z

toString: ->
return @x + ", " + @y + ", " + @z
6 changes: 3 additions & 3 deletions src/document-view.coffee
Expand Up @@ -58,13 +58,13 @@ class DocumentView
@drawing = true
@actionDirtyRect = null
coords = getCanvasCoords(e)
editor.getToolObject().beginDraw(coords)
editor.getToolObject().beginDraw(doc.layer, coords)
doc.beginEdit()
@onDraw(coords, getPressure())

if e.which is 2
@panning = true
local.panningStart = getCoords(e)
local.panningStart = getPenCoords(e)
local.offsetStart = @offset.clone()

$container.mouseup (e)=>
Expand All @@ -84,7 +84,7 @@ class DocumentView
@onDraw(getCanvasCoords(e), getPressure())

if @panning
curPos = getCoords(e)
curPos = getPenCoords(e)
o = local.offsetStart.add(curPos.sub(local.panningStart))
@offset = o
@rePaint()
Expand Down

0 comments on commit a8784ec

Please sign in to comment.