|Snappy Line||Lab Report|
|Demonstration of line drawing/snapping and rubber
contributed by Gordon Whittam
With the SnappyLine program you can draw "free" lines, which are lines that snap to each other and measure angles. Lines can be highlighted with the trackbar and erased when the trackbar is released. SnappyLine also demonstrates the creation of a LogFont for drawing the text dimensions at any angle.
Materials and Equipment
Delphi 3/4 (to recompile)
The LineTestUnit.PAS unit contains the basic drawing functions. ProFuncUnit.Pas contains the text alignment AlignAngleText and SetStatusPanelText procedures.
The program uses a number of math functions and demonstrates how to align dimension text with a vector. Rubber banding of lines is also demonstrated.
The scroll bar is used to highlight the indexed line and delete the selected line, OnMouseUp. The scroll bar isn't the best choice for this function -- separate up and down buttons would have been a better choice. It's been left in as much to show why it's a poor choice for this function.
The LineTest.RES file contains a user defined cursor that is used while drawing. (Note: Always use a name for a .RES file that is not the same as the .RES file for any form. If you do, working with the form in the IDE can overwrite such a .RES file.)
SnappyLine shows how to use draw lines and label them using the LogFont API call to draw text at any angle.
AlignAngleText procedure, LogFont API call, Line rubber banding, Canvas.MoveTo, Canvas.LineTo, Canvas.FillRect, Canvas.Pen.Mode, user-defined cursor, .RES file, Screen.Cursors, OnMouseDown, OnMouseMove, OnMouseUp, PtInRect, MessageBeep, TStatusBar
Delphi 3 Source and EXE (135 KB): SnappyLine.ZIP
Updated source code may be available from Gordon Whittam via the following link:
Thank you, Gordon, for this excellent example.
since 6 Dec 1998