Results 1 to 5 of 5

Thread: Drag Drop problem....

  1. #1

    Thread Starter
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    8,047

    Drag Drop problem....

    In the image below, I want to drag, for example, a Blue Command Button (near top) and place it ON the Green Command Button you see along one of the paths (not in the BASE area). I currently have all command button (Blue, Orange, Green, etc) set to be dragged to any position on the form. The 'normal' event would be drop one of the buttons on the 'pink' circles around the board, but if one of those pink circles is 'occupied' by another command button, I want to know that I have dropped it there. Of course, when 'trying' to drop a button on another one, the move won't take place as the 'target' is somewhere on the FORM.

    What approach should I use to be able to 'hit' another command button (and subsequently send that button back to its base---I'll figure that out later, but first need to know how to do such a 'hit', while keeping the capability to drop anywhere on the form (of course, that 'anywhere' would be one of the pink circles)).

    Name:  Capture.jpg
Views: 78
Size:  53.1 KB

    EDIT: each 'set' of colored command buttons are in image arrays (GreenPlayer(1), GreenPlayer(2), etc---four in each array).
    Sam I am (as well as Confused at times).

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    22,865

    Re: Drag Drop problem....

    This demo uses lightweight UserControls instead of fat and stupid CommandButton controls. This not only saves a ton of "weight" but also lets you bury a lot of housekeeping within the UserControl and out of the Form module code.

    This one doesn't "snap" on drag collisions, but that should be simple enough to add.

    • Any of the controls here is allowed to be dragged. You could also have some that are only targets and do not drag around if desired.
    • While being dragged a control turns yellow. Once it "hits" another control it turns magenta and turns the control collided with red. Drag it off the collided control and it goes back to yellow until the mouse button is released.
    • After one or more "hits" you can click on the "Clear" menu item to reset all controls to their idle colors.


    While being dragged, a control instance raises an event asking its Parent's logic to perform hit tests against the other controls. The Parent needs to do this, because it "knows about" the set of controls to be tested for hits.

    In theory, the dragged instance could spelunk the Parent's Controls array for controls to hit test against and just do that itself. The controls would need to be "tagged" in some way to be recognized, but you could do it if you wanted.

    Normally the Parent wants to know if a hit occurs though, if only to do things like enable "Clear." So you'd probably want to raise a "been hit" event anyway.


    Most graphical games probably shouldn't use controls at all though and just draw everything.
    Attached Files Attached Files

  3. #3

    Thread Starter
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    8,047

    Re: Drag Drop problem....

    Great demo, dilettante....thanks a lot.

    Going to take me some time to implement this (for one, UNDERSTANDING it all, and two, implementing what happens when Hit (I won't be changing colors, but will want to move the target to a certain location on the screen).

    You certainly have a deep understanding of VB6, for sure...You've assisted me several times in the past with your examples.

    Thanks

    Sam
    Sam I am (as well as Confused at times).

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Posts
    22,865

    Re: Drag Drop problem....

    Well it isn't really that exotic. You need to break it down and examine the steps.

    All it is really doing is handling control dragging, but while doing that compares the dragged control's "rectangle" with those of all the other control instances for intersection. The GDI call helps by doing the comparisons but you could also check the positions by brute force code too.

    To snap in place instead of changing colors you could stop comparing at the first "hit" then cancel dragging and move the dragged control to that "hit" rectangle.

  5. #5
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    6,520

    Re: Drag Drop problem....

    Quote Originally Posted by dilettante View Post
    Most graphical games probably shouldn't use controls at all though and just draw everything.
    I'll co-sign this. Like this cannot be overstated. You can get away with it for very simple games or simple engines but it much better in the long run to avoid using Controls to implement game elements.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width