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

  1. unit JwSmile;
  2.  
  3. {
  4.         **   VERSION History   **
  5.    Version     Date     Notes
  6.     v1.00  - 01APR99    Original Release
  7. }
  8.  
  9. {    TJwSmile....  This is just one of those things that HAD to be done.  I set myself out to
  10. create the ultimate in useless components, mainly to practice making the darling little things.
  11. This component is free... such as it is... and is open to total use without any warrentee whatsoever.
  12. If you actually use this, please send me a note at Coockoo@hotmail.com ... I'm trying to become famous
  13. here!
  14.                     -Joseph, aka The Admiral}
  15.  
  16. //  Created By:
  17. //    Joseph Wilcock
  18. //    Coockoo@hotmail.com
  19. //    http://msnhomepages.talkcity.com/RedmondAve/coockoo/
  20.  
  21.  
  22. interface
  23.  
  24. uses SysUtils, Classes, Graphics, Controls;
  25.  
  26. type
  27.     TJwSmileEyes = ( jseSolid, jseOpenEyed, jseBoggled );
  28.     TJwSmileMouth = ( jsmBigOpen, jsmSmallOpen, jsmBigSmile, jsmSmallSmile,
  29.                       jsmWimpySmile, jsmFrown, jsmLine, jsmCocky );
  30.  
  31.     TJwSmile = Class( TGraphicControl )
  32.       private
  33.         FSmileKind: TJwSmileMouth;
  34.         FEyeKind: TJwSmileEyes;
  35.  
  36.         {Many of these attributes were there just so I could play with the image in
  37.         design-time.  They really don't change the overall effect that much, but
  38.         they do give it a little varations...}
  39.         FEyeWidth: Integer;
  40.         FBorderSize: Byte;
  41.         FSmileSize: Byte;
  42.         FEyeSize: Byte;
  43.  
  44.         FBackColor: TColor;
  45.         FBackBrushStyle: TBrushStyle;
  46.         FEyeBackColor: TColor;
  47.         FEyeBackBrushStyle: TBrushStyle;
  48.         FMouthBackColor: TColor;
  49.         FMouthBackBrushStyle: TBrushStyle;
  50.         FMouthForeColor: TColor;
  51.  
  52.         Function MinInt( Value1, Value2: LongInt ): LongInt;
  53.         Procedure Paint; override;
  54.  
  55.         Procedure SetSmileKind( Value: TJwSmileMouth );
  56.         Procedure SetEyeKind( Value: TJwSmileEyes );
  57.         Procedure SetBorderSize( Value: Byte );
  58.         Procedure SetSmileSize( Value: Byte );
  59.         Procedure SetEyeSize( Value: Byte );
  60.         Procedure SetBackColor( Value: TColor );
  61.         Procedure SetBackBrushStyle( Value: TBrushStyle );
  62.         Procedure SetEyeBackColor( Value: TColor );
  63.         Procedure SetEyeBackBrushStyle( Value: TBrushStyle );
  64.         Procedure SetMouthBackColor( Value: TColor );
  65.         Procedure SetMouthBackBrushStyle( Value: TBrushStyle );
  66.         Procedure SetMouthForeColor( Value: TColor );
  67.         Procedure SetEyeWidth( Value: Integer );
  68.       protected
  69.  
  70.       public
  71.         Constructor Create( AOwner: TComponent ); override;
  72.       published
  73.         Property SmileKind: TJwSmileMouth
  74.           Read FSmileKind
  75.           Write SetSmileKind
  76.           default jsmBigSmile;
  77.         Property EyeKind: TJwSmileEyes
  78.           Read FEyeKind
  79.           Write SetEyeKind
  80.           default jseSolid;
  81.  
  82.         Property BorderSize: Byte
  83.           Read FBorderSize
  84.           Write SetBorderSize
  85.           default 5;
  86.         Property SmileBorderSize: Byte
  87.           Read FSmileSize
  88.           Write SetSmileSize
  89.           default 7;
  90.         Property EyeBorderSize: Byte
  91.           Read FEyeSize
  92.           Write SetEyeSize
  93.           default 1;
  94.         Property EyeWidth: Integer
  95.           Read FEyeWidth
  96.           Write SetEyeWidth
  97.           default 25;
  98.  
  99.         Property Background: TColor
  100.           Read FBackColor
  101.           Write SetBackColor
  102.           default clYellow;
  103.         Property BackgroundBrush: TBrushStyle
  104.           Read FBackBrushStyle
  105.           Write SetBackBrushStyle
  106.           default bsSolid;
  107.         Property EyeBackgroundColor: TColor
  108.           Read FEyeBackColor
  109.           Write SetEyeBackColor
  110.           default clWhite;
  111.         Property EyeBackgroundBrushStyle: TBrushStyle
  112.           Read FEyeBackBrushStyle
  113.           Write SetEyeBackBrushStyle
  114.           default bsSolid;
  115.         Property MouthBackgroundColor: TColor
  116.           Read FMouthBackColor
  117.           Write SetMouthBackColor
  118.           default clBlack;
  119.         Property MouthBackgroundBrushStyle: TBrushStyle
  120.           Read FMouthBackBrushStyle
  121.           Write SetMouthBackBrushStyle
  122.           default bsSolid;
  123.         Property MouthForegroundColor: TColor
  124.           Read FMouthForeColor
  125.           Write SetMouthForeColor
  126.           default clBlack;
  127.  
  128.         Property Align;
  129.         Property ShowHint;
  130.         Property ParentShowHint;
  131.         Property Visible;
  132.         Property OnClick;
  133.         Property OnDblClick;
  134.         Property OnMouseDown;
  135.         Property OnMouseMove;
  136.         Property OnMouseUp;
  137.         Property Anchors;
  138.       end;
  139.  
  140. procedure Register;
  141.  
  142. implementation
  143.  
  144. Procedure Register;
  145. begin
  146.   RegisterComponents( 'JwTools', [TJwSmile] );
  147. end;
  148.  
  149. Constructor TJwSmile.Create( AOwner: TComponent );
  150. begin
  151.   Inherited Create( AOwner );
  152.   Width := 100;
  153.   Height := 100;
  154.  
  155.   FSmileKind := jsmBigSmile;;
  156.   FEyeKind := jseSolid;
  157.  
  158.   FEyeWidth := 25;
  159.   FBorderSize := 5;
  160.   FSmileSize := 7;
  161.   FEyeSize := 1;
  162.  
  163.   FBackColor := clYellow;
  164.   FBackBrushStyle := bsSolid;
  165.   FEyeBackColor := clBlack;
  166.   FEyeBackBrushStyle := bsSolid;
  167.   FMouthBackColor := clBlack;
  168.   FMouthBackBrushStyle := bsSolid;
  169.   FMouthForeColor := clBlack;
  170.  
  171. end;
  172.  
  173. Function TJwSmile.MinInt( Value1, Value2: LongInt ): LongInt;
  174. begin
  175.   if Value1 < Value2 then
  176.     Result := Value1
  177.   else
  178.     Result := Value2;
  179. end;
  180.  
  181. Procedure TJwSmile.Paint;
  182. var
  183.   MWidth, Quarter, Half, Fifth, Sixth: LongInt;
  184. begin
  185.   MWidth := MinInt( Width, Height );
  186. {  Width := MWidth;
  187.   Height := MWidth; This causes some problems with Align:Client!!!}
  188.   Half := MWidth div 2;
  189.   Quarter := MWidth div 4;
  190.   Fifth := MWidth div 5;
  191.   Sixth := MWidth div 6;
  192.   with Canvas do
  193.     begin
  194.       {Main "body"}
  195.       Brush.Style := FBackBrushStyle;
  196.       Brush.Color := FBackColor;
  197.       Ellipse( FBorderSize, FBorderSize, MWidth-FBorderSize, MWidth-FBorderSize );
  198.       Brush.Style := bsClear;
  199.       Pen.Width := FBorderSize;
  200.       Pen.Color := FMouthBackColor;
  201.       {Outline}
  202.       Ellipse( FBorderSize, FBorderSize, MWidth-FBorderSize, MWidth-FBorderSize );
  203.  
  204.       {Draw the Mouth}
  205.       Pen.Width := FSmileSize;
  206.       Pen.Color := FMouthForeColor;
  207.       Brush.Style := FMouthBackBrushStyle;
  208.       Brush.Color := FMouthBackColor;
  209.       Case FSmileKind of
  210.          jsmBigOpen: Ellipse( Sixth, Half, MWidth-Sixth, MWidth-Sixth );
  211.        jsmSmallOpen: Ellipse( Half-Fifth, Half, Half+Fifth, MWidth-Sixth );
  212.         jsmBigSmile: Arc( Fifth, Fifth, MWidth-Fifth, MWidth-Fifth,
  213.                           Quarter, Half, MWidth-Quarter, Half );
  214.       jsmSmallSmile: Arc( Fifth, Fifth, MWidth-Fifth, MWidth-Fifth,
  215.                           fifth, MWidth-Fifth, MWidth-Fifth, MWidth-Fifth );
  216.       jsmWimpySmile: Arc( Quarter, Quarter, MWidth-Quarter, MWidth-Quarter,
  217.                           Quarter, MWidth-Quarter, MWidth-Quarter, MWidth-Quarter );
  218.            jsmFrown: begin
  219.                      MoveTo( Fifth, MWidth-Fifth );
  220.                      LineTo( MWidth-Fifth, MWidth-Fifth );
  221.                      end;
  222.             jsmLine: begin
  223.                      MoveTo( Quarter, MWidth-Quarter );
  224.                      LineTo( MWidth-Quarter, MWidth-Quarter );
  225.                      end;
  226.            jsmCocky: begin
  227.                      MoveTo( Quarter, MWidth-Fifth );
  228.                      LineTo( MWidth-Quarter, MWidth-Quarter );
  229.                      end;
  230.       end;
  231.  
  232.       {Now the eyes}
  233.       Pen.Width := FEyeSize;
  234.       Brush.Style := FEyeBackBrushStyle;
  235.       Brush.Color := FEyeBackColor;
  236.       Case FEyeKind of
  237.          jseSolid: begin
  238.              Ellipse( Quarter, Quarter, Quarter+FEyeWidth, Quarter+FEyeWidth );
  239.              Ellipse( MWidth-Quarter-FEyeWidth, Quarter,
  240.                       MWidth-Quarter, Quarter+FEyeWidth );
  241.                    end;
  242.        jseOpenEyed: begin
  243.              Ellipse( Quarter, Quarter, Quarter+FEyeWidth, Quarter+FEyeWidth );
  244.              Ellipse( MWidth-Quarter-FEyeWidth, Quarter,
  245.                       MWidth-Quarter, Quarter+FEyeWidth );
  246.              Brush.Color := clBlack;
  247.              Ellipse( Quarter+FEyeWidth div 4, Quarter+FEyeWidth div 4,
  248.                       Quarter+FEyeWidth-FEyeWidth div 4, Quarter+FEyeWidth-FEyeWidth div 4 );
  249.              Ellipse( MWidth-Quarter-FEyeWidth+FEyeWidth div 4, Quarter+FEyeWidth div 4,
  250.                       MWidth-Quarter-FEyeWidth div 4, Quarter+FEyeWidth-FEyeWidth div 4 );
  251.                    end;
  252.         jseBoggled: begin
  253.              Ellipse( Quarter, Quarter, Quarter+FEyeWidth, Quarter+FEyeWidth );
  254.              Ellipse( MWidth-Quarter-FEyeWidth, Quarter,
  255.                       MWidth-Quarter, Quarter+FEyeWidth );
  256.              Brush.Color := clBlack;
  257.              Ellipse( Quarter+FEyeWidth div 8, Quarter+FEyeWidth div 8,
  258.                       Quarter+FEyeWidth div 2, Quarter+FEyeWidth div 2 );
  259.              Ellipse( MWidth-Quarter-FEyeWidth div 2, Quarter+FEyeWidth div 2,
  260.                       MWidth-Quarter-FEyeWidth div 8, Quarter+FEyeWidth-FEyeWidth div 8 );
  261.                    end;
  262.       end;
  263.     end;
  264. end;
  265.  
  266. Procedure TJwSmile.SetSmileKind( Value: TJwSmileMouth );
  267. begin
  268.   if FSmileKind <> Value then
  269.     begin
  270.       FSmileKind := Value;
  271.       Invalidate;
  272.     end;
  273. end;
  274.  
  275. Procedure TJwSmile.SetEyeKind( Value: TJwSmileEyes );
  276. begin
  277.   if FEyeKind <> Value then
  278.     begin
  279.       FEyeKind := Value;
  280.       Invalidate;
  281.     end;
  282. end;
  283.  
  284. Procedure TJwSmile.SetBorderSize( Value: Byte );
  285. begin
  286.   if FBorderSize <> Value then
  287.     begin
  288.       FBorderSize := Value;
  289.       Invalidate;
  290.     end;
  291. end;
  292.  
  293. Procedure TJwSmile.SetSmileSize( Value: Byte );
  294. begin
  295.   if FSmileSize <> Value then
  296.     begin
  297.       FSmileSize := Value;
  298.       Invalidate;
  299.     end;
  300. end;
  301.  
  302. Procedure TJwSmile.SetEyeSize( Value: Byte );
  303. begin
  304.   if FEyeSize <> Value then
  305.     begin
  306.       FEyeSize := Value;
  307.       Invalidate;
  308.     end;
  309. end;
  310.  
  311. Procedure TJwSmile.SetBackColor( Value: TColor );
  312. begin
  313.   if FBackColor <> Value then
  314.     begin
  315.       FBackColor := Value;
  316.       Invalidate;
  317.     end;
  318. end;
  319.  
  320. Procedure TJwSmile.SetBackBrushStyle( Value: TBrushStyle );
  321. begin
  322.   if FBackBrushStyle <> Value then
  323.     begin
  324.       FBackBrushStyle := Value;
  325.       Invalidate;
  326.     end;
  327. end;
  328.  
  329. Procedure TJwSmile.SetEyeBackColor( Value: TColor );
  330. begin
  331.   if FEyeBackColor <> Value then
  332.     begin
  333.       FEyeBackColor := Value;
  334.       Invalidate;
  335.     end;
  336. end;
  337.  
  338. Procedure TJwSmile.SetEyeBackBrushStyle( Value: TBrushStyle );
  339. begin
  340.   if FEyeBackBrushStyle <> Value then
  341.     begin
  342.       FEyeBackBrushStyle := Value;
  343.       Invalidate;
  344.     end;
  345. end;
  346.  
  347. Procedure TJwSmile.SetMouthBackColor( Value: TColor );
  348. begin
  349.   if FMouthBackColor <> Value then
  350.     begin
  351.       FMouthBackColor := Value;
  352.       InValidate;
  353.     end;
  354. end;
  355.  
  356. Procedure TJwSmile.SetMouthBackBrushStyle( Value: TBrushStyle );
  357. begin
  358.   if FMouthBackBrushStyle <> Value then
  359.     begin
  360.       FMouthBackBrushStyle := Value;
  361.       InValidate;
  362.     end;
  363. end;
  364.  
  365. Procedure TJwSmile.SetMouthForeColor( Value: TColor );
  366. begin
  367.   if FMouthForeColor <> Value then
  368.     begin
  369.       FMouthForeColor := Value;
  370.       InValidate;
  371.     end;
  372. end;
  373.  
  374. Procedure TJwSmile.SetEyeWidth( Value: Integer );
  375. begin
  376.   if FEyeWidth <> Value then
  377.     begin
  378.       FEyeWidth := Value;
  379.       Invalidate;
  380.     end;
  381. end;
  382.  
  383. end.
  384.  
  385.  
  386.