Code:
|| SimpleEditableCanvas is a drop target
{define-class public SimpleEditableCanvas {inherits Canvas}
{constructor {default ...}
{construct-super ...}
}
{method public {on-drop e:Drop}:void
{e.accept-drop
{proc {a:any,
x:Distance,
y:Distance,
effect:#DragEffect}:DropResult
|| Only support move
{if {effect.has-effect? "move"} then
{return {DropResultMove action =
{proc {}:void
|| get the dragee option from
|| the object being dropped
let dragee:Dragee = a.dragee
|| compute the new position in the drop
|| container
let (real-x:Distance, real-y:Distance) =
{dragee.get-drop-position x, y, self}
{self.add a, x = real-x, y = real-y}
}}}
else
{return {DropResultNone}}
}
}}
{e.consume}
{super.on-drop e}
}
{method public {on-drag-over e:DragOver}:void
{e.will-accept-drop?
{proc {t:Type,
x:Distance,
y:Distance,
effect:#DragEffect}:DragEffect
|| only supports move
{if {effect.has-effect? "move"} then
{return drag-effect-move}
else
{return drag-effect-none}
}
}}
{e.consume}
{super.on-drag-over e}
}
}
{value let simple-canvas =
{SimpleEditableCanvas
width = 3in,
height = 2in,
background = "beige"}
let simple-canvas-obj =
{Frame
width = 0.5in,
height = 0.25in,
background = "blue",
dragee = {ImageDragee},
{on pp:PointerPress at fr:Frame do
{if pp.click-count == 2 then
def grect:GRect = {fr.get-bounds}
let (goir-x:Distance, goir-y:Distance, goir-root:Graphic) =
{fr.get-origin-in-root}
def (ttdc-new-x:Distance, ttdc-new-y:Distance) =
{fr.transform-to-display-coordinates
grect.lextent, grect.ascent
}
def v:View =
{View
{VBox
margin = 3pt,
"画面左上から (" & goir-x / 1pt & "pt, " & goir-y / 1pt & "pt)",
"ブラウザの左上から (" & ttdc-new-x / 1pt & "pt ," & ttdc-new-y / 1pt & "pt)",
"width = " & grect.width / 1pt & "pt",
"height = " & grect.height / 1pt & "pt"
}}
{v.show}
}
}
}
{simple-canvas.add simple-canvas-obj, x = 1.5in, y = 1in}
{value simple-canvas}
}