xamarin.formsxamarin.uwpurhosharpurho3d

how can i implement drag and drop in urho 3d view?


I have added 3d view objects using urhosharp for my xamarin uwp/ios/android project . The only event that work is touch event, but i also want to use drag and drop so that the objects can move to different locations within the 3D view. Any suggestions?

https://us.v-cdn.net/5019960/uploads/editor/ni/u16pg79v2m62.png


Solution

  • Haven't used urhosharp yet , but here are some suggestions about using of drag and drop, not sure if it helps here for you.

    urhosharp: Basic Actions

    From document of urhosharp , there is some bascic actions explains,but no drag and drop in it.Maybe you can do it by combining actions and drag methods on each platform. But this requires you to try.


    UWP: reference link here

    Here's an overview of what you need to do to enable drag and drop in your app:

    1. Enable dragging on an element by setting its CanDrag property to true.
    2. Build the data package. The system handles images and text automatically, but for other content, you'll need to handle the DragStarted and DragCompleted events and use them to construct your own data package.
    3. Enable dropping by setting the AllowDrop property to true on all the elements that can receive dropped content.
    4. Handle the DragOver event to let the system know what type of drag operations the element can receive.
    5. Process the Drop event to receive the dropped content.

    Code example:

    <Grid AllowDrop="True" DragOver="Grid_DragOver" Drop="Grid_Drop"
          Background="LightBlue" Margin="10,10,10,353">
        <TextBlock>Drop anywhere in the blue area</TextBlock>
    </Grid>
    
    private void Grid_DragOver(object sender, DragEventArgs e)
    {
        e.AcceptedOperation = DataPackageOperation.Copy;
    }
    

    IOS: reference link here

    With drag and drop in iOS, users can drag items from one onscreen location to another using continuous gestures. A drag-and-drop activity can take place in a single app, or it can start in one app and end in another.

    1. Use drag items to convey data representation promises between a source app and a destination app.
    2. Adopt drag interaction APIs to provide items for dragging.
    3. Adopt drop interaction APIs to selectively consume dragged content.
    4. Demonstrates how to enable drag and drop for a UIImageView instance.

    Code of example:

    func customEnableDragging(on view: UIView, dragInteractionDelegate: UIDragInteractionDelegate) {
        let dragInteraction = UIDragInteraction(delegate: dragInteractionDelegate)
        view.addInteraction(dragInteraction)
    }
    
    func dragInteraction(_ interaction: UIDragInteraction, itemsForBeginning session: UIDragSession) -> [UIDragItem] {
        // Cast to NSString is required for NSItemProviderWriting support.
        let stringItemProvider = NSItemProvider(object: "Hello World" as NSString)
        return [
            UIDragItem(itemProvider: stringItemProvider)
        ]
    }
    

    Here is a sample for Xamarin IOS.

    Or you can using UIPanGestureRecognizer in IOS to move view.Here is Walkthrough: Using Touch in Xamarin.iOS.All you need to do is let view.center follow panGesture to change.


    Android: reference link here

    With the Android drag/drop framework, you can allow your users to move data from one View to another using a graphical drag and drop gesture. The framework includes a drag event class, drag listeners, and helper methods and classes.

    There are basically four steps or states in the drag and drop process:

    1. Started:In response to the user's gesture to begin a drag, your application calls startDrag() to tell the system to start a drag.
    2. Continuing:The user continues the drag.
    3. Dropped:The user releases the drag shadow within the bounding box of a View that can accept the data.
    4. Ended:After the user releases the drag shadow, and after the system sends out (if necessary) a drag event with action type ACTION_DROP, the system sends out a drag event with action type ACTION_DRAG_ENDED to indicate that the drag operation is over.

    Table. DragEvent action types: enter image description here

    Or in Android can use onTouchEvent to move view, need to calculate position of the view.Walkthrough - Using Touch in Android

    The main thing is to handle pressing and moving two messages, overloading onTouchEvent. Mathematical knowledge (translation): Record the coordinate point when ACTION_DOWN, and calculate the translation amount according to the current position and the position when pressed at ACTION_MOVE. Refresh the control, causing the control to redraw, and move the coordinates of the upper left corner of the drawing when redrawing.


    Here also has a discussion about Drag & Drop in Xamarin forms.It may be helpful.