Adding drag and drop to the card game
Open the settings for the Container Icon List part in the Deck Window part and switch to the Drag Drop Spec window. Ensure that canBeDragSource is set to true, canBeDragTarget is set to false, and defaultDragOperations only allows XmMOVE. These settings mean the end user can drag cards from the Deck window, but cannot drop cards in the Deck window. Select OK to accept the changes.
Change the Drag Drop Spec window for the Container Icon Tree part in the Discard Window part so canBeDragSource is false, and the only allowed default drop operation is XmMOVE. These settings allow cards to be dropped on the Discard window, but do not allow cards to be dragged from the Discard window. Select OK to accept the changes.
Test your part again. You should be able to drag cards from the Deck window to the Discard window but not in the other direction.
Save the part.
Open the Composition Editor for the BlackJackPlayerView visual part. Change the container's values for dragDropSpec to allow a drag with a default operation of XmMOVE. You should also allow a drop with a default operation of XmMOVE. Add the Card class to the list of acceptable classes. These settings allow cards to be dragged from a player's hand and dropped in a player's hand. Select OK to accept the changes and then save the part.
Testing the drag and drop support
Select the
BlackJackGameView visual part and then
to test the part. Create two new players. You should be able to drag cards from the deck to each player's hand. Notice the target emphasis between the cards in the player's hand as you drag over them. This emphasis indicates where the drop will occur. You can drop a card so it is at the beginning of the list, somewhere in the middle of the list, or at the end of the list. You should also be able to drag cards from the players' hands to the Discard window.
Last modified date: 06/11/2018