Advertisement
Janilabo

Untitled

Jan 6th, 2014
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.13 KB | None | 0 0
  1. function ExplodeBox(bx: TBox; rows, columns: integer): TBoxArray;
  2. var
  3.   r, c, w, h, ew, eh, ow, oh, i, x, y: integer;
  4. begin
  5.   if ((rows > 0) and (columns > 0)) then
  6.   begin
  7.     w := ((bx.X2 - bx.X1) + 1);
  8.     h := ((bx.Y2 - bx.Y1) + 1);
  9.     if (rows > h) then
  10.       rows := h;
  11.     if (columns > w) then
  12.       columns := w;
  13.     w := (w div columns);
  14.     h := (h div rows);
  15.     ew := (((bx.X2 - bx.X1) + 1) - (w * columns));
  16.     eh := (((bx.Y2 - bx.Y1) + 1) - (h * rows));
  17.     SetLength(result, (rows * columns));
  18.     y := bx.Y1;
  19.     for r := 0 to (rows - 1) do
  20.     begin
  21.       x := bx.X1;
  22.       if ((eh > 0) and (r < eh)) then
  23.         oh := 1
  24.       else
  25.         oh := 0;
  26.       for c := 0 to (columns - 1) do
  27.       begin
  28.         if ((ew > 0) and (c < ew)) then
  29.           ow := 1
  30.         else
  31.           ow := 0;
  32.         i := ((r * columns) + c);
  33.         result[i].X1 := x;
  34.         result[i].X2 := (x + (w - 1) + ow);
  35.         result[i].Y1 := y;
  36.         result[i].Y2 := (y + (h - 1) + oh);
  37.         x := (Result[i].X2 + 1);
  38.       end;
  39.       y := (result[i].Y2 + 1);
  40.     end;
  41.   end else
  42.     SetLength(result, 0);
  43. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement