Autor Beitrag
Raezor
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 54

Status:
Administrator des Mondes
BeitragVerfasst: So 18.03.07 21:21 
Ich bewege mit den Pfeiltasten ein Shape1.
In der Form habe ich aber noch eine Shape2.
Wenn ich nun mit den Pfeiltasten SHape1 über SHape2 schiebe,
soll die anwendung geschlossen werden (close;)

Wie geht das?

ausblenden Quelltext
1:
if Shape1 über Shape2 than close;					
jakobwenzel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1889
Erhaltene Danke: 1

XP home, ubuntu
BDS 2006 Prof
BeitragVerfasst: So 18.03.07 21:24 
Ich gehe jetzt mal davon aus, dass du als Shape ein Rechteck hast, sonst funktioniert das so nicht.
Wenn ja, musst du für jeden Eckpunkt des einen Shapes prüfen, ob er im anderen Shape liegt. Das machst du, mit der Funktion PtInRect.

PS: www.deppenapostroph.de/

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: So 18.03.07 22:01 
Wenn die Shape gleich groß sind müsste es doch eigentlich reichen Top und Left auf "gleich" zu prüfen.

_________________
Blackheart666
Der Irrsinn ist bei Einzelnen etwas Seltenes, - aber bei Gruppen, Parteien, Völkern, Zeiten die Regel. (Friedrich Nietzsche)
Dragonclaw
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 196

Windows Vista
Delphi 7 Prof.
BeitragVerfasst: So 18.03.07 22:41 
Hallo,

das Ganze geht relativ einfach über IntersectRect().

In deinem Fall:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
var 
  Overlay: TRect;
begin
  if IntersectRect(Overlay, Shape1.BoundsRect, Shape2.BoundsRect) then close;
end;
Raezor Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 54

Status:
Administrator des Mondes
BeitragVerfasst: Mo 19.03.07 13:04 
@ Dragondings: werde ich mal versuchen, doch wem soll ich den Quellcode geben?
Danniolo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 693



BeitragVerfasst: Mo 19.03.07 14:30 
Welche Form hat dein Shape denn?
Wenn es ein Rechteck ist geht es wie oben bereits beschrieben ganz einfach.
Ist es aber ein Kreis wird's etwas schwieriger.
Raezor Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 54

Status:
Administrator des Mondes
BeitragVerfasst: Mo 19.03.07 14:48 
Ich wollte doch nur wissen, wo ich den quellcode hinkopieren soll!
Habe ihn in einen Timer gelegt und es geht.

(Ein Rechteck)
UGrohne
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Veteran
Beiträge: 5502
Erhaltene Danke: 220

Windows 8 , Server 2012
D7 Pro, VS.NET 2012 (C#)
BeitragVerfasst: Mo 19.03.07 14:57 
user profile iconRaezor hat folgendes geschrieben:
Ich wollte doch nur wissen, wo ich den quellcode hinkopieren soll!
Habe ihn in einen Timer gelegt und es geht.

(Ein Rechteck)

Du verwendest doch wahrscheinlich das Event OnKeyDown zum Verschieben des Shapes. Wieso fügst Du die Überprüfung nicht direkt in dieses Event ein, also hinter Deinen Verschiebecode? Dann wird genau dann geprüft, wenn sich die Vorgaben geändert haben (Shape wird verschoben). Somit verschwendest Du keine Rechenzeit mit unnötigen Prozeduren, die durch die Verwendung des Timers aufgerufen werden.
lotus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 19

XP MediaCenter
Delphi 2005 Personal
BeitragVerfasst: Mo 19.03.07 20:11 
Hi!!

Die Funktion IntersectRect ist ziemlich cool! :D
Aber: Ich habe 2 Images, die einen transparenten Hintergrund haben; und die Funktion soll nur auslösen, wenn
sich die nicht-transparenten Teile berühren.

Hab schonmal was versucht, da waren aber dann zuviele for-Schleifen und irgendwann ist das Programm zum Stillstand gekommen :lol:

Wisst ihr, wei man das besser machen könnte?

_________________
Das leben ist zu kostbar um es dem Schicksal zu überlassen! - Deus X Machina
UGrohne
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Veteran
Beiträge: 5502
Erhaltene Danke: 220

Windows 8 , Server 2012
D7 Pro, VS.NET 2012 (C#)
BeitragVerfasst: Di 20.03.07 07:25 
Da hilft Dir auch wieder InterSectRect. Ziehe einfach den Rand von den Shapes ab und Du bist fertig. In etwa so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
var 
  Overlay: TRect;
  R1,R2:TRect;
begin
  R1 := Shape1.BoundsRect;
  R1.Left := R1.Left + 10;
  R1.Top := R1.Top +10;
  R1.Width := R1.Width - 10;
  R1.Height := R1.Height - 10;

  R2 := Shape2.BoundsRect;
  R2.Left := R2.Left + 10;
  R2.Top := R2.Top +10;
  R2.Width := R2.Width - 10;
  R2.Height := R2.Height - 10;

  if IntersectRect(Overlay, R1, R2) then 
    //Mach irgendwas hier
end;