X-Git-Url: https://jasonwoof.com/gitweb/?p=crayon_mockup.git;a=blobdiff_plain;f=auto.coffee;fp=auto.coffee;h=6d391e8b87da9cafbb93b92c73ed809ac132725d;hp=9fc709fbe75c07962b04029401fae5e67d69623e;hb=f5cf60eac3cbdb1eb1fe12833509418f33fe9b83;hpb=81ebf177e50d343cf0a7236278c618a39a9253ae diff --git a/auto.coffee b/auto.coffee index 9fc709f..6d391e8 100644 --- a/auto.coffee +++ b/auto.coffee @@ -9,6 +9,7 @@ $tool_options = null # jquery object for tool options line 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 @@ -137,12 +138,15 @@ class DrawTool extends Tool class EditTool extends Tool constructor: (args) -> super args - toolbar.append $ "Oops, the edit tool isn't implemented yet" + args.tool_options.append $ "Oops, the edit tool isn't implemented yet" class DeleteTool extends Tool constructor: (args) -> super args - toolbar.append $ "Oops, the delete isn't implemented yet" + args.tool_options.append $ "To delete: click on a line below" + click: (x, y) -> + $svg.find('path:hover').remove() + return false update_path = (path, flags) -> d = '' @@ -160,23 +164,8 @@ switch_to_tool = (tool_class) -> # 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 = $ '
Tools:
' - for k, t of tool_buttons - t.element = $ "" - 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 = $ '
' $container.append $toolbar $container.append $tool_options @@ -186,7 +175,32 @@ init = -> 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 = $ "" + 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?