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:
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
@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
]
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:
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