Which method do I need to change in Cuis, class PasteUpMorph to have a dropped morph to snap to a 10 by 10 pixel grid?

有帮助吗?

解决方案

Open the Method Finder: World / Open / Message Names Enter 'drop' in the text box. Click (search) . First message shown is #acceptDroppingMorph:event: We are lucky! At the end of the implementation in PasteUpMorph add:

p := aMorph morphPosition.
p := (p x roundTo: 10) @ (p y roundTo: 10).
aMorph morphPosition: p.

That's it. Maybe instead of the World you want to use a morph of your own, then you can add a DragAndDropAreaMorph to the world, and it that class add this method:

acceptDroppingMorph: aMorph event: evt
    | p |
    super
        acceptDroppingMorph: aMorph
        event: evt.
    p := aMorph morphPosition.
    p := (p x roundTo: 10) @ (p y roundTo: 10).
    aMorph morphPosition: p
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top