home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 December / Chip_2001-12_cd1.bin / zkuste / delphi / kolekce / d345 / JWTOOL.ZIP / jwtool / JwLinez.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  2001-09-29  |  7.2 KB  |  232 lines

  1. unit Jwlinez;
  2.  
  3. {
  4.         **   VERSION History   **
  5.    Version     Date     Notes
  6.     v1.00  - 01APR99    Original Release
  7. }
  8.  
  9. {
  10.    JwLinez is actually the first compoenent that I have ever written.  I highly
  11. suggest anyone who want to make a component, and are just starting, make a
  12. real simple component like this one that does  a few simple thing.  And over
  13. time, add more and more functionality.
  14.    This component is just a line draw.  Something that I would otherwise have
  15. to do during runtime, but have decided to make available at design time.
  16. }
  17.  
  18. //  Created By:
  19. //    Joseph Wilcock
  20. //    Coockoo@hotmail.com
  21. //    http://msnhomepages.talkcity.com/RedmondAve/coockoo/
  22.  
  23. interface
  24.  
  25. uses
  26.   SysUtils, {$IFDEF WIN32} Windows, {$ELSE} WinProcs, WinTypes, {$ENDIF}
  27.   Messages, Classes, Graphics, Controls, Forms, Dialogs;
  28.  
  29. type
  30.   TJwLineStyle = ( jlTop, jlBottom, jlRight, jlLeft, jlTopLeft, jlRightTo, jlRectangle );
  31.  
  32.   TJwLinez = Class( TGraphicControl )
  33.     private
  34.       FJwLineStyle: TJwLineStyle;
  35.       FThisPenStyle: TPenStyle;
  36.       FThisPenWidth: Byte;
  37.       FThisLineColor: TColor;
  38.       FDouble: Boolean;
  39.  
  40.       Procedure SetJwLineStyle( Value: TJwLineStyle );
  41.       Procedure SetThisPenStyle( Value: TPenStyle );
  42.       Procedure SetThisPenWidth( Value: Byte );
  43.       Procedure SetThisLineColor( Value: TColor );
  44.       Procedure SetDouble( Value: Boolean );
  45.  
  46.       Procedure Paint; Override;
  47.     protected
  48.       { Protected declarations }
  49.     public
  50.       { Public declarations }
  51.       Constructor Create( AOwner: TComponent ); override;
  52.     published
  53.       { Published declarations }
  54.       Property JwLineStyle: TJwLineStyle
  55.         Read FJwLineStyle
  56.         Write SetJwLineStyle
  57.         default jlTop;
  58.  
  59.       Property ThisPenStyle: TPenStyle
  60.         Read FThisPenStyle
  61.         Write SetThisPenStyle
  62.         Default psSolid;
  63.  
  64.       Property ThisPenWidth: Byte
  65.         Read FThisPenWidth
  66.         Write SetThisPenWidth
  67.         Default 1;
  68.  
  69.       Property ThisLineColor: TColor
  70.         Read FThisLineColor
  71.         Write SetThisLineColor
  72.         Default clBlack;
  73.  
  74.       Property Double: Boolean
  75.         Read FDouble
  76.         Write SetDouble
  77.         Default False;
  78.  
  79.       Property Anchors;
  80.     end;
  81.  
  82. procedure Register;
  83.  
  84. implementation
  85.  
  86.  
  87. procedure Register;
  88. begin
  89.   RegisterComponents('JwTools', [TJwLinez]);
  90. end;
  91.  
  92. Constructor TJwLinez.Create( AOwner: TComponent );
  93. begin
  94.   Inherited Create( AOwner );
  95.   Width := 100;
  96.   Height := 100;
  97.   FJwLineStyle := jlTop;
  98.   FThisPenStyle := psSolid;
  99.   FThisPenWidth := 1;
  100.   FThisLineColor := clBlack;
  101.   FDouble := False;
  102. end;
  103.  
  104. Procedure TJwLinez.SetJwLineStyle( Value: TJwLineStyle );
  105. begin
  106.   if FJwLineStyle <> Value then
  107.     begin
  108.       FJwLineStyle := Value;
  109.       Invalidate;
  110.     end;
  111. end;
  112.  
  113. Procedure TJwLinez.SetThisPenStyle( Value: TPenStyle );
  114. begin
  115.   if FThisPenStyle <> Value then
  116.     begin
  117.       FThisPenStyle := Value;
  118.       Invalidate;
  119.     end;
  120. end;
  121.  
  122. Procedure TJwLinez.SetThisPenWidth( Value: Byte );
  123. begin
  124.   if FThisPenWidth <> Value then
  125.     begin
  126.       FThisPenWidth := Value;
  127.       Invalidate;
  128.     end;
  129. end;
  130.  
  131. Procedure TJwLinez.SetThisLineColor( Value: TColor );
  132. begin
  133.   if FThisLineColor <> Value then
  134.     begin
  135.       FThisLineColor := Value;
  136.       Invalidate;
  137.     end;
  138. end;
  139.  
  140. Procedure TJwLinez.SetDouble( Value: Boolean );
  141. begin
  142.   if FDouble <> Value then
  143.     begin
  144.       FDouble := Value;
  145.       Invalidate;
  146.     end;
  147. end;
  148.  
  149. Procedure TJwLinez.Paint;
  150. begin
  151.   with Canvas do
  152.     begin
  153.       Pen.Width := FThisPenWidth;
  154.       Pen.Style := FThisPenStyle;
  155.       Pen.Color := FThisLineColor;
  156.       case FJwLineStyle of
  157.             jlTop: begin
  158.                      MoveTo( FThisPenWidth, FThisPenWidth );
  159.                      LineTo( Width-FThisPenWidth, FThisPenWidth );
  160.                    end;
  161.          jlBottom: begin
  162.                      MoveTo( FThisPenWidth, Height-FThisPenWidth );
  163.                      LineTo( Width-FThisPenWidth, Height-FThisPenWidth );
  164.                    end;
  165.           jlRight: begin
  166.                      MoveTo( Width-FThisPenWidth, FThisPenWidth );
  167.                      LineTo( Width-FThisPenWidth, Height-FThisPenWidth );
  168.                    end;
  169.            jlLeft: begin
  170.                      MoveTo( FThisPenWidth, FThisPenWidth );
  171.                      LineTo( FThisPenWidth, Height-FThisPenWidth );
  172.                    end;
  173.         jlTopLeft: begin
  174.                      MoveTo( FThisPenWidth, FThisPenWidth );
  175.                      LineTo( Width-FThisPenWidth, Height-FThisPenWidth );
  176.                    end;
  177.         jlRightTo: begin
  178.                      MoveTo( FThisPenWidth, Height-FThisPenWidth );
  179.                      LineTo( Width-FThisPenWidth, FThisPenWidth );
  180.                    end;
  181.        jlRectangle:begin
  182.                      MoveTo( FThisPenWidth, FThisPenWidth );
  183.                      LineTo( Width-FThisPenWidth, FThisPenWidth );
  184.                      LineTo( Width-FThisPenWidth, Height-FThisPenWidth );
  185.                      LineTo( FThisPenWidth, Height-FThisPenWidth );
  186.                      LineTo( FThisPenWidth, FThisPenWidth );
  187.                    end;
  188.       end;
  189.     if FDouble then
  190.       begin
  191.         case FJwLineStyle of
  192.               jlTop: begin
  193.                        MoveTo( FThisPenWidth, FThisPenWidth+(FThisPenWidth*2) );
  194.                        LineTo( FThisPenWidth+Width, FThisPenWidth+(FThisPenWidth*2) );
  195.                      end;
  196.            jlBottom: begin
  197.                        MoveTo( FThisPenWidth, Height-FThisPenWidth-(FThisPenWidth*2) );
  198.                        LineTo( Width-FThisPenWidth, Height-FThisPenWidth-(FThisPenWidth*2) );
  199.                      end;
  200.             jlRight: begin
  201.                        MoveTo( Width-FThisPenWidth-(FThisPenWidth*2), FThisPenWidth );
  202.                        LineTo( Width-FThisPenWidth-(FThisPenWidth*2), Height-FThisPenWidth );
  203.                      end;
  204.              jlLeft: begin
  205.                        MoveTo( FThisPenWidth+(FThisPenWidth*2), FThisPenWidth );
  206.                        LineTo( FThisPenWidth+(FThisPenWidth*2), FThisPenWidth+Height );
  207.                      end;
  208.           jlTopLeft: begin
  209.                        MoveTo( FThisPenWidth, FThisPenWidth+(FThisPenWidth*2) );
  210.                        LineTo( FThisPenWidth+Width, FThisPenWidth+Height+(FThisPenWidth*2) );
  211.                      end;
  212.           jlRightTo: begin
  213.                        MoveTo( FThisPenWidth, FThisPenWidth+Height+(FThisPenWidth*2) );
  214.                        LineTo( FThisPenWidth+Width, FThisPenWidth+(FThisPenWidth*2) );
  215.                      end;
  216.          jlRectangle:begin
  217.                        MoveTo( FThisPenWidth+(FThisPenWidth*2), FThisPenWidth+(FThisPenWidth*2) );
  218.                        LineTo( Width-(FThisPenWidth*2)-FThisPenWidth, FThisPenWidth+(FThisPenWidth*2) );
  219.                        LineTo( Width-(FThisPenWidth*2)-FThisPenWidth, Height-(FThisPenWidth*2)-FThisPenWidth );
  220.                        LineTo( FThisPenWidth+(FThisPenWidth*2), Height-(FThisPenWidth*2)-FThisPenWidth );
  221.                        LineTo( FThisPenWidth+(FThisPenWidth*2), FThisPenWidth+(FThisPenWidth*2) );
  222.                      end;
  223.  
  224.         end;
  225.       end;
  226.     end;
  227. end;
  228.  
  229.  
  230.  
  231. end.
  232.