22 May 2013

Drag'n'drop in R3GUI

Back to using this blog (before I move somewhere else again)!
Let's start with something simple: @GrahamChiu was interested to see how to do drag'n'drop in R3GUI. Here is it:

Some explanation

DRAGGER is style used for dragging. It's simple box, but you can use anything you want.

Dragger / on-click

You need to define ON-CLICK actor to catch MOUSE-DOWN event:
on-click: [
    if arg/type = 'down [
        return init-drag face arg/offset
    ]
]
This will initialize and return the dragging object.

Dragger / on-drag

You also need to add ON-DRAG actor to process movement:
on-drag: [
    face/gob/offset: arg/offset - arg/base
    show face/gob
]
Argument for this actor is the drag object defined in ON-CLICK actor with INIT-DRAG function. The drag object holds original position and new offset (and also some other fields that are not interesting for this simple tutorial).

Dropper / on-drop

For faces that accept our DRAGGER face we need to implement ON-DROP actor:
on-drop: [
    append-content face arg/face
    return true
]
This actor just adds our DRAGGER face to target panel and returns TRUE to indicate everything went well.

Notes

If you drop the DRAGGER on face that has no ON-DROP defined, DRAGGER will return to original position automatically.

Conclusion

As you can see, it's fairly easy. Feel free to ask about details!

1 comment:

Anonymous said...

af am dating disasters http://loveepicentre.com/articles/ drake is dating
bi men dating [url=http://loveepicentre.com/faq/]funny dating disasters[/url] on-line dating
new dating free site in 2008 [url=http://loveepicentre.com/success_stories/]dating service in mobile al[/url] inkado dating [url=http://loveepicentre.com/user/babylove/]babylove[/url] african dating