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:
| var img: TImage; bmp: TBitmap; Form1: TForm1; touching: boolean; px, py, tx, ty, scale: double;
procedure TForm1.Redraw; var mx, my, nx1, ny1, nx2, ny2, m, s: integer; begin mx := round(scale * px) + bmp.Width div 2; my := round(scale * py) + bmp.Height div 2;
nx1 := round(mx - scale * img.Width / 2); ny1 := round(my - scale * img.Height / 2); nx2 := round(nx1 + scale * img.Width); ny2 := round(ny1 + scale * img.Height);
if ny2 < PBox.Height then begin inc(ny1, PBox.Height - ny2); py := py + (PBox.Height - ny2) / scale; ny2 := PBox.Height; end;
if nx2 < PBox.Width then begin inc(nx1, PBox.Width - nx2); px := px + (PBox.Width - nx2) / scale; nx2 := PBox.Width; end;
if nx1 > 0 then begin if nx2 = PBox.Width then begin px := px - nx1 / 2; dec(nx2, nx1 div 2); dec(nx1, nx1 div 2); end else begin dec(nx2, nx1); px := px - nx1 / scale; nx1 := 0; end; end;
if ny1 > 0 then begin if ny2 = PBox.Height then begin py := py - ny1 / 2; dec(ny2, ny1 div 2); dec(ny1, ny1 div 2); end else begin dec(ny2, ny1); py := py - ny1 / scale; ny1 := 0; end; end;
bmp.Canvas.Rectangle(-1, -1, bmp.Width, bmp.Height); bmp.Canvas.StretchDraw(Rect(nx1, ny1, nx2, ny2), img.Picture.Bitmap);
s := round((bmp.Width * bmp.Width) / (2 * scale * img.Width)); m := round(bmp.Width * (0.5 - px / img.Width)); bmp.Canvas.Rectangle(m - s, bmp.Height - 7, m + s, bmp.Height - 2);
s := round((bmp.Height * bmp.Height) / (2 * scale * img.Height)); m := round(bmp.Height * (0.5 - py / img.Height)); bmp.Canvas.Rectangle(bmp.Width - 7, m - s, bmp.Width - 2, m + s);
if scale >= 1 then bmp.Canvas.TextOut(0, 0, FormatFloat('scale: 0.0', scale)) else bmp.Canvas.TextOut(0, 0, FormatFloat('scale: 1/0.0', 1/scale));
PBox.Canvas.Draw(0, 0, bmp); end; |