JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
resize controlls are little arrows
[crayon_mockup.git] / main.coffee
index 1f4edfc..48c001b 100644 (file)
@@ -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