Autor Beitrag
Killi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 299

Win*
D6 Prof
BeitragVerfasst: Do 12.02.04 23:14 
Hi!


Ich hab ein TImage ("Pic") auf dem ich mit der Maus grüne Rechtecke ziehe - klappt auch wunderbar, Begrenzungen sind drin (außerhalb von Pic) nur klappt das mit der Begrenzung ZU Rechtecken nicht - d.h. ich will dass man kein Rechteck über ein anderes ziehen kann! Eck-Werte sind in einer StringList gespeichert ("Tables")....hier ein Auszug aus dem Code:


ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
procedure TFMain.PicMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var
   DrawX, DrawY, i: integer;
   tmp: string;
begin
     // Wenn Maus gedrückt, neue Tabelle zeichnen
     if Mausaktiv = True then
     begin
               // Hintergrund wieder löschen...erlaubt "ziehen" des Rechtecks
               Pic.Canvas.Brush.Color:= clWhite;
               Pic.Canvas.FillRect(Rect(MausX,MausY, OldX, OldY));


               // KLAPPT NICHT vvvvvvvvvvvvvvvvvvvvvvvvvvvvv !!!!!
               if checkmove(tLeft, tTop, tRight, tBottom) = True then
               begin
                    // Nicht über Bildschirm raus gehen!
                    if (X > Pic.Width) then
                    begin
                         DrawX:= Pic.Width;
                    end
                    else if (X < 0) then
                    begin
                         DrawX:= 0;
                    end
                    else
                    begin
                         DrawX:= X;
                    end;
                    if (Y > Pic.Height) then
                    begin
                         DrawY:= Pic.Height;
                    end
                    else if (Y < 0) then
                    begin
                         DrawY:= 0;
                    end
                    else
                    begin
                         DrawY:= Y;
                    end;
               end;

               // Koordinaten des TRects "ordnen"
               if MausX > DrawX then
               begin
                    tLeft:= DrawX;
                    tRight:= MausX;
               end
               else
               begin
                    tLeft:= MausX;
                    tRight:= DrawX;
               end;
               if MausY > DrawY then
               begin
                    tTop:= DrawY;
                    tBottom:= MausY;
               end
               else
               begin
                    tTop:= MausY;
                    tBottom:= DrawY;
               end;

               // Neues aktives Rechteck zeichen...
               Pic.Canvas.Brush.Color:= $00BAF8C8;
               Pic.Canvas.Rectangle(Rect(tLeft, tTop, tRight, tBottom));

               // Jetzige Werte speichern, nachher alt -> löschen
               Oldx:= DrawX;
               OldY:= DrawY;
     end;
end;



function TFMain.Checkmove(left2, top2, right2, bottom2 : integer): boolean;
var
   i: integer;
   tmp: string;
   left3, top3, right3, bottom3: integer;
   ok: boolean;
begin
     ok:= True;
          for i:= 0 to Tables.Count - 1 do
          begin
               // Werte splitten
               tmp:= Tables.Strings[i];
               left3:= StrToInt(Copy(tmp, 0, Pos('.', tmp) - 1));

               tmp:= Copy(tmp, Pos('.', tmp) + 1, Length(tmp));
               top3:= StrToInt(Copy(tmp, 0, Pos('.', tmp) - 1));

               tmp:= Copy(tmp, Pos('.', tmp) + 1, Length(tmp));
               right3:= StrToInt(Copy(tmp, 0, Pos('.', tmp) - 1));

               tmp:= Copy(tmp, Pos('.', tmp) + 1, Length(tmp));
               bottom3:= StrToInt(tmp);

               // Prüfen ob Rechtecke sich berühren
               if ((right2 >= left3) and (left2 <= right3) and (top2 >= top3) and (top2 <= bottom3)) then
               begin
                    ok := False;
               end;
          end;

          if ok = False then
          begin
               Result:= False;
          end
          else
          begin
               Result:= True;
          end;
end;


und zwar ist das Ganze recht kompliziert - ich will dass man keine überlappenden Rechtecke hat.....außerdem dass nur der obere Wert blockiert wird wenn man von unten anfängt das R-Eck zu ziehen, nicht der Wert links o. rechts....aber wenn das jetz keiner kapiert isses auch nicht schlimm ;-) helft mir lieber bei meiner berührungsabfrage, da sollte dann nicht weitergezogen werden können!

_________________
----
Life is hard and then you die
rokdd
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 329

Win XP
D6
BeitragVerfasst: Sa 14.02.04 15:16 
hallo,
schönes logikspiel *ggg*.
also ich bin daran gescheitert dass du sowohl bottom2 als auch bottom3 deklinierst in deiner abfrage dann aber schriebst: and (top2 <= bottom3)) ist für mich irgendwie komisch! doer bin ich zu blöd dafür?


rokdd