Graphics
SnappyLine.gif (938 bytes) Snappy Line  Lab Report
Demonstration of line drawing/snapping and rubber banding
contributed by Gordon Whittam
ScreenSnappyLine.gif (10741 bytes)

Purpose
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

Software Requirements
Windows 95
Delphi 3/4 (to recompile)
LineTestProject.EXE

Hardware Requirements
VGA display

Procedure

  1. Double click on the LineTestProject.EXE icon to start the program.
  2. Select the Not Drawing button to toggle to Drawing mode.
  3. Click and drag to draw lines. Lines will either snap to another, which is in the cursor rectangle, or start and finish at the X and Y co-ordinates                                                                                      
  4. Use the trackbar to select and erase lines.                                                                                                                                                    
  5. Measure angles between pairs of interconnected lines by: Clicking 'Measure Angle' then selecting, first the junction of the two lines and then the ends.

Discussion
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.)

Conclusions
SnappyLine shows how to use draw lines and label them using the LogFont API call to draw text at any angle.


Keywords
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

Download
Delphi 3 Source and EXE (135 KB):  SnappyLine.ZIP

Updated source code may be available from Gordon Whittam via the following link:
ftp://members.aol.com/gwhit41980/programs/linetest.zip

Thank you, Gordon, for this excellent example.


Updated 02/26/05


since 6 Dec 1998