selection = null
svg_ns = 'http://www.w3.org/2000/svg'
cur_tool = null
+cur_tool_name = null
mouse = x: 0, y: 0, buttons: [0,0,0]
class Tool
class EditTool extends Tool
constructor: (args) ->
super args
- toolbar.append $ "<span>Oops, the edit tool isn't implemented yet</span>"
+ args.tool_options.append $ "<span>Oops, the edit tool isn't implemented yet</span>"
class DeleteTool extends Tool
constructor: (args) ->
super args
- toolbar.append $ "<span>Oops, the delete isn't implemented yet</span>"
+ args.tool_options.append $ "<span>To delete: click on a line below</span>"
+ click: (x, y) ->
+ $svg.find('path:hover').remove()
+ return false
update_path = (path, flags) ->
d = ''
# called automatically on domcontentloaded
init = ->
- tool_buttons =
- draw: button_text: 'draw', factory: DrawTool
- edit: button_text: 'edit', factory: EditTool
- delete: button_text: 'delete', factory: DeleteTool
$container = $ '.crayon_mockup'
$toolbar = $ '<div class="toolbar"><span>Tools:</span></div>'
- for k, t of tool_buttons
- t.element = $ "<span class=\"button\"></span>"
- t.element.text t.button_text
- $toolbar.append t.element
- do (t) ->
- t.element.click ->
- if cur_tool?
- cur_tool.disable()
- ($toolbar.find '.button').removeClass 'disabled'
- $tool_options.empty()
- cur_tool = new t.factory button: t.element, tool_options: $tool_options
$tool_options = $ '<div class="tool_options"></div>'
$container.append $toolbar
$container.append $tool_options
svg.setAttribute 'viewBox', "0 0 #{width} #{height}"
$svg = $ svg
$container.append $svg
- cur_tool = new TutorialTool tool_options: $tool_options
+
+ tool_buttons =
+ tutorial: default: true, factory: TutorialTool
+ draw: button_text: 'draw', factory: DrawTool
+ edit: button_text: 'edit', factory: EditTool
+ delete: button_text: 'delete', factory: DeleteTool
+ for k, t of tool_buttons
+ if t.button_text?
+ t.button = $ "<span class=\"button\"></span>"
+ t.button.text t.button_text
+ $toolbar.append t.button
+ do (k, t) ->
+ activate = ->
+ if cur_tool?
+ cur_tool.disable()
+ $container.removeClass "#{cur_tool_name}_tool"
+ ($toolbar.find '.button').removeClass 'disabled'
+ cur_tool_name = k
+ $container.addClass "#{cur_tool_name}_tool"
+ $tool_options.empty()
+ cur_tool = new t.factory button: t.button, tool_options: $tool_options
+ if t.button?
+ t.button.click activate
+ if t.default
+ activate()
+
$svg.mousedown (e) ->
offset = $svg.offset()
if cur_tool?