Skip to content

Commit

Permalink
Renderer buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
trethaller committed Aug 4, 2013
1 parent f2978b8 commit 7b94c64
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 31 deletions.
4 changes: 2 additions & 2 deletions index.html
Expand Up @@ -14,8 +14,8 @@
<div>
<div class="document-view">
</div>
<div id="tools">
</div>
<div id="tools"></div>
<div id="renderers"></div>

<div><pre id="status-bar"></pre></div>
</div>
Expand Down
28 changes: 23 additions & 5 deletions js/app.coffee
Expand Up @@ -6,10 +6,12 @@ class Document
Editor = {
brush: null
tiling: true
renderer: GammaRenderer
#renderer: GammaRenderer
renderer: NormalRenderer
targetValue: 1.0
}

Renderers = [GammaRenderer, NormalRenderer]
Tools = [RoundBrush, Picker]
Editor.tool = RoundBrush.createTool(Editor)

Expand Down Expand Up @@ -56,8 +58,9 @@ class DocumentView
e.preventDefault()
if e.which is 1
self.drawing = true
Editor.tool.beginDraw()
self.onDraw(getCanvasCoords(e))
coords = getCanvasCoords(e)
Editor.tool.beginDraw(coords)
self.onDraw(coords)

if e.which is 2
self.panning = true
Expand All @@ -66,7 +69,7 @@ class DocumentView

$container.mouseup (e)->
if e.which is 1
Editor.tool.endDraw()
Editor.tool.endDraw(getCanvasCoords(e))
self.drawing = false

if e.which is 2
Expand Down Expand Up @@ -148,6 +151,8 @@ getPenPressure = () ->
status = (txt)->
$('#status-bar').text(txt)

view = null

createToolsUI = ($container)->
$container.empty()
Tools.forEach (b)->
Expand All @@ -158,6 +163,18 @@ createToolsUI = ($container)->
status("Active brush set to #{name}")
$container.append($btn)

createRenderersUI = ($container)->
$container.empty()
Renderers.forEach (r)->
name = r.description.name
$btn = $('<button/>').attr({'class':'btn'}).text(name)
$btn.click (e)->
Editor.renderer = r
view.reRender()
view.rePaint()
status("Renderer set to #{name}")
$container.append($btn)

$(document).ready ()->
doc = new Document(512, 512)
fillLayer doc.layer, (x,y)->
Expand All @@ -167,7 +184,8 @@ $(document).ready ()->
(Math.round(y*40) % 2) * 0.1

createToolsUI($('#tools'))
createRenderersUI($('#renderers'))

view = new DocumentView($('.document-view'), doc)
view.rePaint()
view.reRender()
view.rePaint()
41 changes: 33 additions & 8 deletions js/app.js

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

12 changes: 9 additions & 3 deletions js/core.coffee
Expand Up @@ -135,6 +135,9 @@ Bezier =
return new Vec2 f3(pts[0].x, pts[1].x, pts[2].x, t), f3(pts[0].y, pts[1].y, pts[2].y, t)

GammaRenderer = (()->
description =
name: "Height map"

properties =
gamma: 1.0

Expand Down Expand Up @@ -166,12 +169,15 @@ GammaRenderer = (()->
}
}`

return {properties, renderLayer}
return {description, properties, renderLayer}
)();

NormalRenderer = (()->
description =
name: "Normal map"

properties =
gain: 2.0
gain: 4.0

sample = (res, x, y)->
return "var #{res} = fb[ ((#{y} + height) % height) * width + ((#{x} + width) % width) ];\n"
Expand Down Expand Up @@ -211,7 +217,7 @@ NormalRenderer = (()->

renderLayer = eval(str);

return {properties, renderLayer}
return {description, properties, renderLayer}
)();

`
Expand Down
14 changes: 11 additions & 3 deletions js/core.js

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

10 changes: 5 additions & 5 deletions js/tools.coffee
Expand Up @@ -31,11 +31,11 @@ class StepBrush
@lastpos = pos
return rect

beginDraw: () ->
beginDraw: (pos) ->
@drawing = true
@accumulator = 0
@nsteps = 0
endDraw: () ->
endDraw: (pos) ->
@lastpos = null
@drawing = false
console.log("#{@nsteps} steps drawn")
Expand All @@ -55,8 +55,8 @@ Picker = (()->
properties: {}

createTool: (env)->
beginDraw: ()->;
endDraw: ()->;
beginDraw: (pos)->;
endDraw: (pos)->;
move: ()->;
draw: (layer, pos, intensity) ->
env.targetValue = layer.getAt(pos)
Expand All @@ -75,7 +75,7 @@ RoundBrush = (()->

hardness:
name: "Hardness"
value: 1.0
value: 0.0
range: [0.0, 10.0]

size:
Expand Down
10 changes: 5 additions & 5 deletions js/tools.js

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

0 comments on commit 7b94c64

Please sign in to comment.