Mega Code Archive

 
Categories / Delphi / Examples
 

Blockcooordscalc

procedure TDrawStyleObj.SetupBlockCoords(blocksX, blocksY: Integer; fullExtent: Integer); {set up a two-dimensional array of TRect items to hold coordinate values for all of the blocks in an image/bitmap component according to the number of 'blocks across' and 'blocks down' the user has chosen} var fullWidth, sectionWidth, fullHeight, sectionHeight: Integer; xIndex, yIndex, xValue, yValue: Integer; begin fullWidth := fullExtent; sectionWidth := Round(fullWidth / blocksX); fullHeight := fullExtent; sectionHeight := Round(fullHeight / blocksY); xValue := 0; yValue := 0; for yIndex := 1 to blocksY do begin for xIndex := 1 to blocksX do begin blockArray[xIndex, yIndex].Left := xValue; blockArray[xIndex, yIndex].Right := xValue + sectionWidth; blockArray[xIndex, yIndex].Top := yValue; blockArray[xIndex, yIndex].Bottom := yValue + sectionHeight; xValue := xValue + sectionWidth; end; xValue := 0; yValue := yValue + sectionHeight; end; end;