Permalink
Browse files

Add palette slider

  • Loading branch information...
1 parent 40c30ba commit 8ca25532bf13cd6aaee8da4a88aadf45a7e1b4fb @trethaller committed Aug 6, 2013
Showing with 106 additions and 17 deletions.
  1. +2 −0 index.html
  2. +47 −10 js/app.coffee
  3. +56 −3 js/app.js
  4. +0 −2 js/tools.coffee
  5. +1 −2 js/tools.js
View
@@ -20,10 +20,12 @@
<div class="buttons"></div>
<div class="properties"></div>
</div>
+ <div id="commands"></div>
<div class="row">
<div class="document-view span8">
</div>
<div id="tools" class="span4">
+ <div id="palette"></div>
<div class="buttons"></div>
<div class="properties"></div>
</div>
View
@@ -16,6 +16,7 @@ Editor = Backbone.Model.extend({
})
editor = new Editor {
+ doc: null
tool: null
renderer: null
tiling: true
@@ -24,6 +25,16 @@ editor = new Editor {
Renderers = [GammaRenderer, NormalRenderer]
Tools = [RoundBrush, Picker]
+Commands = [
+ {
+ name: "Fill"
+ func: (doc)->
+ val = editor.get('targetValue')
+ fillLayer doc.layer, (x,y)->
+ return val
+ refresh()
+ },
+]
class DocumentView
drawing: false
@@ -159,13 +170,18 @@ getPenPressure = () ->
return 1.0
# ---
-
+
+
status = (txt)->
$('#status-bar').text(txt)
view = null
+refresh = ()->
+ view.reRender()
+ view.rePaint()
+
PropertyView = Backbone.View.extend
className: "property"
@@ -234,6 +250,8 @@ editor.on 'change:renderer', ()->
view.reRender()
view.rePaint()
+
+
createToolsButtons = ($container)->
$container.empty()
Tools.forEach (b)->
@@ -252,23 +270,42 @@ createRenderersButtons = ($container)->
editor.set('renderer', r)
$container.append($btn)
+createCommandsButtons = ($container)->
+ Commands.forEach (cmd)->
+ $btn = $('<button/>').
+ attr({'class':'btn'}).
+ text(cmd.name).
+ appendTo($container)
+ $btn.click (e)->
+ cmd.func(editor.get('doc'))
+
+createPalette = ($container)->
+ $slider = $('<div/>').slider({
+ min: -1.0
+ max: 1.0
+ value: 0
+ step: 0.005
+ change: (evt, ui)->
+ editor.set('targetValue', ui.value)
+ }).appendTo($container)
+
+ editor.on 'change:targetValue', ()->
+ $slider.slider
+ value: editor.get('targetValue')
+
$(document).ready ()->
doc = new Document(512, 512)
-
- '''
- fillLayer doc.layer, (x,y)->
- x += 1.0
- y += 1.0
- return (Math.round(x*40) % 2) * 0.1 -
- (Math.round(y*40) % 2) * 0.1
- '''
fillLayer doc.layer, (x,y)->
return -1
view = new DocumentView($('.document-view'), doc)
createToolsButtons($('#tools > .buttons'))
createRenderersButtons($('#renderers > .buttons'))
-
+ createPalette($('#palette'))
+ createCommandsButtons($('#commands'))
+
+ editor.set('doc', doc)
editor.set('tool', RoundBrush)
editor.set('renderer', GammaRenderer)
+ editor.set('targetValue', 0.0)
View

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

Oops, something went wrong.
View
@@ -39,8 +39,6 @@ class StepBrush
endDraw: (pos) ->
@lastpos = null
@drawing = false
- console.log("#{@nsteps} steps drawn")
-
BlendModes =
add: "{dst} += {src} * intensity"
View

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

Oops, something went wrong.

0 comments on commit 8ca2553

Please sign in to comment.