Mega Code Archive

 
Categories / Delphi / Examples
 

Drawblockdottedlines

procedure TDrawStyleObj.DrawBarDots(blocksX, blocksY, imgWidth, imgHeight: Integer); {set up dotted lines in the 'drawing area' of the form (ie the image component) according the number of blocks defined. Later we can then facilitate some degree of 'snapping' to these lines when bars are added. This procedure is called every time the user makes a change in either of the two 'blocks' Combo Boxes...} var fullwidth, fullheight: Integer; dotLineSpaceAcross, dotLineSpaceDown, x, y: Integer; blocksAcross, blocksDown: Integer; begin FillDrawArea; blocksAcross := blocksX; blocksDown := blocksY; fullwidth := imgWidth; fullheight := imgHeight; {substitute relevant object for NewStyleForm.DrawArea below if re-used code...} with NewStyleForm.DrawArea do begin Canvas.Pen.Color := clBlack; Canvas.Pen.Width := 1; Canvas.Pen.Style := psDot; dotLineSpaceAcross := Round(fullWidth / blocksAcross); dotLineSpaceDown := Round(fullWidth / blocksDown); x := dotLineSpaceAcross; y := 0; while (x < (fullWidth - 1)) do begin Canvas.MoveTo(x, y); Canvas.LineTo(x, fullHeight); x := x + dotLineSpaceAcross; end; x := 0; y := dotLineSpaceDown; while (y < (fullHeight - 2)) do begin Canvas.MoveTo(x, y); Canvas.LineTo(fullHeight, y); y := y + dotLineSpaceDown; end; end; end;