?
Solved

Delphi 7 - How to make a collision detection on a movable panel...

Posted on 2011-03-13
2
Medium Priority
?
1,099 Views
Last Modified: 2012-05-11
Thanks to the other guy in this thread (here) I was able to make a panel movable the way I wanted it, but now I also need it to detect and stop upon collision.

As a sample, I inserted a third panel in the form called panel3, when I hover panel1 into it, I need it to stop, not proceed. In fact, I need it to stop when it hits any edge of the form (no matter what size that is). how can I proceed?

The sample source is attached, thanks.

Edit: As an example of what I mean, if panel1 hits the edge of the form on the left side, it can still move top, bottom and right, as if it was a real wall.
movablepanel.zip
0
Comment
Question by:John86a
2 Comments
 
LVL 24

Accepted Solution

by:
jimyX earned 2000 total points
ID: 35125036
Please check this out:
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
    if MDown then
    begin
      GetCursorPos(NPnt);
      if (Panel1.Top < Panel3.Height) then
        Panel1.Top := Panel3.Height;
      if (Panel1.Left < 0) then
        Panel1.Left := 0;

      Panel1.Left := Panel1.Left - OPnt.X + NPnt.X;

      if (Panel1.Top + Panel1.Height >= ClientHeight) then
        Panel1.Top := ClientHeight-Panel1.Height;
      if (Panel1.Left + Panel1.Width >= ClientWidth) then
        Panel1.Left := ClientWidth-Panel1.Width;

      Panel1.Top := Panel1.Top - OPnt.Y + NPnt.Y;

      OPnt := NPnt;
    end;
end;

Open in new window

movablepanel-updated.zip
0
 

Author Closing Comment

by:John86a
ID: 35125472
That works out well, thank you very much.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
When you discover the power of the R programming language, you are going to wonder how you ever lived without it! Learn why the language merits a place in your programming arsenal.
Introduction to Processes
Loops Section Overview

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question