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:
| function TForm1.findObj(x,y:Integer):Integer; var i,z:Integer; begin z:=-1; for i:=0 to High(Obj) do begin if (x >= obj[i].x ) and (y >= obj[i].y ) and (x <= obj[i].x + obj[i].h ) and (y <= obj[i].y + obj[i].w) then begin
z:=i; Break; end end;
result:=z; end;
procedure TForm1.Timer1Timer(Sender: TObject); var i:Integer; begin
Bit.Canvas.Rectangle(0,0,PaintBox1.Width,PaintBox1.Height);
for i:=0 to High(Obj) do begin Bit.Canvas.Pen.Color:=obj[i].FColor; Bit.Canvas.Brush.Color:=obj[i].BColor;
if Obj[i].Visible = True then DrawObjt(Obj[i].typ,obj[i].x,obj[i].y,obj[i].w+obj[i].x,obj[i].y+obj[i].h); end;
PaintBox1.Canvas.Draw(0, 0, Bit); Bit.Canvas.Pen.Color:=clBlack; Bit.Canvas.Brush.Color:=clWhite; end;
procedure TForm1.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin MT:=True; MoveObj:=False; objIndex:=findObj(x,y); StatusBar1.Panels[0].Text:=IntToStr(ObjIndex); if objIndex <= -1 then begin AddObj(x,y,x,y,penS,False); objIndex:=High(obj); end else MoveObj:=True; mx:=x; my:=y; end;
procedure TForm1.PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); begin
if objIndex > -1 then begin if MoveObj = False then begin Obj[objIndex].x:=mx; Obj[objIndex].y:=my;
Obj[objIndex].w:=X-mx; Obj[objIndex].h:=Y-my; end else begin Obj[objIndex].x:=x; Obj[objIndex].y:=y; end;
Obj[objIndex].Visible:=True; end;
end;
procedure TForm1.PaintBox1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin objIndex:=-1; MoveObj:=False; end; |