X-Git-Url: https://jasonwoof.com/gitweb/?p=crayon_mockup.git;a=blobdiff_plain;f=main.coffee;h=48c001bbfe75e01ab198a10da786d2256f6fb316;hp=3ed08db238cf25e350972065ca6660d996341d05;hb=e5023e73a42f8c36d006e9c2c650b6001b5b17f7;hpb=67a786e6d0b589a4ae7e2833d3f1d5d1963a5edc diff --git a/main.coffee b/main.coffee index 3ed08db..48c001b 100644 --- a/main.coffee +++ b/main.coffee @@ -97,24 +97,24 @@ class Control extends Visible dy = xy.y - @y return dx * dx + dy * dy -class ControlPoint extends Control +class ControlNWSE extends Control constructor: (args) -> super args @css_class = 'control_point' - @el = json_to_svg circle: - cx: @x + 1 - cy: @y + 1 - r: 6 + @el = json_to_svg path: + d: @make_path() class: 'control_point normal' @svg.appendChild @el + make_path: -> + # / return "M#{@x + 5} #{@y - 5}v6l-2-2-4 4 2 2h-6v-6l2 2 4-4-2-2z" + return "M#{@x - 5} #{@y - 5}h6l-2 2 4 4 2 -2v6h-6l2-2-4-4-2 2z" destruct: -> super() if @el? @svg.removeChild @el move: (args) -> super args - @el.setAttribute 'cx', @x - @el.setAttribute 'cy', @y + @el.setAttribute 'd', @make_path() class Widget extends Visible #sub-classes are expected to implement all of these: @@ -198,12 +198,14 @@ class RectWidget extends Widget prox = PROX_MAX - 1 return prox resize: (wh) -> + dw = wh.w - @width + dh = wh.h - @height @width = wh.w - @el.setAttribute 'width', @width + @el.setAttribute 'width', @width - 2 @height = wh.h - @el.setAttribute 'height', @height + @el.setAttribute 'height', @height - 2 if @controls.length > 1 - @controls[1].move x: @x + @width, y: @y + @height + @controls[1].move x: @controls[1].x + dw, y: @controls[1].y + dh make_controls: (args) -> # create controls, return them console.log 'make_controls' if @controls.length > 0 @@ -211,10 +213,10 @@ class RectWidget extends Widget @kill_controls() w = @ @controls = [ - new ControlPoint svg: @svg, x: @x, y: @y, done: args.done, drag: (dxy) -> + new ControlNWSE svg: @svg, x: @x - 7, y: @y - 7, done: args.done, drag: (dxy) -> w.resize w: w.width - dxy.x, h: w.height - dxy.y w.move x: w.x + dxy.x, y: w.y + dxy.y - new ControlPoint svg: @svg, x: @x + @width, y: @y + @height, done: args.done, drag: (dxy) -> + new ControlNWSE svg: @svg, x: @x + @width + 7, y: @y + @height + 7, done: args.done, drag: (dxy) -> w.resize w: w.width + dxy.x, h: w.height + dxy.y ] return @controls @@ -235,7 +237,7 @@ init = -> ] svg.appendChild json_to_svg style: type: 'text/css' - contents: '.box.normal,.box.selected{filter: url(#crayon)}' + contents: '.box.normal{filter: url(#crayon)}' # create canvas border svg.appendChild json_to_svg rect: @@ -397,10 +399,9 @@ init = -> w.drag x: rel_x, y: rel_y else hit = closest_in_layers xy - return unless hit? - return if hit.s is hovered - if hovered + if hovered and hovered isnt hit?.s hovered.set_hover false + return unless hit? hovered = hit.s hovered.set_hover true return