home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 October / Chip_2001-10_cd1.bin / zkuste / delphi / kompon / d123456 / CHEMPLOT.ZIP / Misc / Switch.pas < prev    next >
Pascal/Delphi Source File  |  2000-07-13  |  20KB  |  546 lines

  1. {
  2.   Programm : SWITCH.PAS
  3.   Sprache  : Delphi
  4.   Zweck    : Schalter-Komponente
  5.   Datum    : 15, 16. Feb. 1996
  6.   Autor    : U.Jnr-
  7.  
  8.   This component simulates a luffing switch as used in many electic devices.
  9.   No Bitmaps are used, so it's fully scaleable.
  10.  
  11.   Sorry for comments are in german.
  12.  
  13.   Hint: Why do so many programers hide theire sources? Is this the real
  14.         sense of "share" ?
  15.  
  16.   Greeting from germany - enjoy...
  17. }
  18.  
  19. unit
  20.   Switch;
  21.  
  22. interface
  23.  
  24. uses
  25.   WinTypes, WinProcs, Messages, Classes, Controls, Graphics;
  26. {------------------------------------------------------------------------------}
  27.  
  28. type
  29.   RectArray = array[0..3] of TPoint;               {Vektorarraytyp fnr Rechteck}
  30.   TriArray = array[0..2] of TPoint;                 {Vektorarraytyp fnr Dreieck}
  31.   TSwitchType = (stHor_Rocker, stVert_Rocker, stButton);
  32.  
  33.   TSwitch = class(TCustomControl)
  34.   private
  35.     TopShape: TriArray;                 {Dreieck Vektoren von Schalteroberseite}
  36.     OnShape: RectArray;               {Rechteck Vektoren von Schalterfront "ON"}
  37.     OffShape: RectArray;             {Rechteck Vektoren von Schalterfront "OFF"}
  38.     SideShape: RectArray;                  {Rechteck Vektoren von Schalterseite}
  39.  
  40.     FOnChanged: TNotifyEvent;                        {Verbindung zur Aussenwelt}
  41.     FOnChecked: TNotifyEvent;                        {Verbindung zur Aussenwelt}
  42.     FOnUnChecked: TNotifyEvent;                      {Verbindung zur Aussenwelt}
  43.  
  44.     FCaptionOn: TCaption;                   {Beschriftung Schalterstellung "ON"}
  45.     FCaptionOff: TCaption;                 {Beschriftung Schalterstellung "OFF"}
  46.     FChecked: Boolean;                               {Flag von Schalterstellung}
  47.     FCheckedLeft: Boolean;     {Flag ob "ON" links oder rechts dargestellt wird}
  48.     FSlope: Byte;                            {Neigung (3D Effekt) des Schalters}
  49.     FSideLength: Byte;          {Seitenabstand fnr hervorstehendes Schalterteil}
  50.     FOnColor: TColor;                               {Farbe fnr Frontfl_che "ON"}
  51.     FOffColor: TColor;                             {Farbe fnr Frontfl_che "OFF"}
  52.     FTopColor: TColor;                             {Farbe fnr Schalteroberseite}
  53.     FSideColor: TColor;                                 {Farbe fnr Seitenfl_che}
  54.     FSwitchType: TSwitchType;  {added by MB}
  55.     ALeft: Integer;                        {Linke Anfangsposition des Schalters}
  56.     ATop: Integer;                         {Obere Anfangsposition des Schalters}
  57.     AHeight: Integer;                                       {Hwhe des Schalters}
  58.     AWidth: Integer;                                      {Breite des Schalters}
  59.     LabelLen: Integer;                                {Halbbreite des Schalters}
  60.     LabelOfs: Integer;                       {Halbbreite fnr Spiegeldarstellung}
  61.     Side: Integer;                                 {Tempor_r in Setup verwendet}
  62.  
  63.     procedure WMSetFocus(var Message: TWMSetFocus); message WM_SETFOCUS;
  64.     procedure WMKillFocus(var Message: TWMKillFocus); message WM_KILLFOCUS;
  65.     procedure CallNotifyEvent;
  66.     procedure Setup;
  67.     procedure SetupVert;
  68. {Modified by MJB:}
  69.     procedure Draw_Hor_Rocker;
  70. {Added by MJB:}
  71.     procedure Draw_Vert_Rocker;
  72.     procedure Draw_Button;
  73.  
  74.     procedure SetCaptionOn(Value: TCaption);
  75.     procedure SetCaptionOff(Value: TCaption);
  76.     procedure SetChecked(Value: Boolean);
  77.     procedure SetCheckedLeft(Value: Boolean);
  78.     procedure SetSlope(Value: Byte);
  79.     procedure SetSideLength(Value: Byte);
  80.     procedure SetOnColor(Value: TColor);
  81.     procedure SetOffColor(Value: TColor);
  82.     procedure SetTopColor(Value: TColor);
  83.     procedure SetSideColor(Value: TColor);
  84.     procedure SetSwitchType(Value: TSwitchType);
  85.   public
  86.     constructor Create(AOwner: TComponent); override;
  87.     procedure Paint; override;
  88.     procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  89.     procedure KeyDown(var Key: Word; Shift: TShiftState); override;
  90.   published
  91.     property CaptionOn: TCaption read FCaptionOn write SetCaptionOn;
  92.     property CaptionOff: TCaption read FCaptionOff write SetCaptionOff;
  93.     property Checked: Boolean read FChecked write SetChecked default False;
  94.     property CheckedLeft: Boolean read FCheckedLeft write SetCheckedLeft default True;
  95.     property Slope: Byte read FSlope write SetSlope default 6;
  96.     property SideLength: Byte read FSideLength write SetSideLength default 6;
  97.     property OnColor: TColor read FOnColor write SetOnColor default clRed;
  98.     property OffColor: TColor read FOffColor write SetOffColor default clMaroon;
  99.     property TopColor: TColor read FTopColor write SetTopColor default clSilver;
  100.     property SideColor: TColor read FSideColor write SetSideColor default clSilver;
  101.     property SwitchType: TSwitchType read FSwitchType write SetSwitchType;
  102.     property Font;
  103.     property TabStop;
  104.     property TabOrder;
  105.     property ShowHint;
  106.     property Visible;
  107.  
  108.     property OnClick;
  109.     property OnMouseDown;
  110.     property OnChanged: TNotifyEvent read FOnChanged write FOnChanged;
  111.     property OnChecked: TNotifyEvent read FOnChecked write FOnChecked;
  112.     property OnUnChecked: TNotifyEvent read FOnUnChecked write FOnUnChecked;
  113.   end;
  114. {------------------------------------------------------------------------------}
  115.  
  116. procedure Register;
  117.  
  118. implementation
  119. {------------------------------------------------------------------------------}
  120.  
  121. constructor TSwitch.Create(AOwner: TComponent);
  122. begin
  123.   inherited Create(AOwner);
  124.   Caption:='';
  125.   FCaptionOn:='On';
  126.   FCaptionOff:='Off';
  127.   FSlope:=6;
  128.   FSideLength:=6;
  129.   FChecked:=False;
  130.   FCheckedLeft:=True;
  131.   FOnColor:=clLime;
  132.   FOffColor:=clRed;
  133.   FTopColor:=clSilver;
  134.   FSideColor:=clGray;
  135.   FOnChecked:=nil;
  136.   FOnUnChecked:=nil;
  137.   SetBounds(Left,Top,83,18 + FSlope);
  138.   {Font.Name:='small fonts';
  139.   Font.Size:=7;
  140.   Font.Color:=clBtnText;}
  141. end;
  142. {------------------------------------------------------------------------------}
  143.  
  144. procedure TSwitch.Paint;
  145. begin
  146.   case FSwitchType of
  147.     stHor_Rocker: Draw_Hor_Rocker; {Keine geerbte Methode aufrufen und sofort Schalter zeichnen}
  148.     stVert_Rocker: Draw_Vert_Rocker;
  149.     stButton: Draw_Button;
  150.   end;
  151. end;
  152. {------------------------------------------------------------------------------}
  153.  
  154. procedure TSwitch.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  155. begin
  156.   inherited MouseDown(Button,Shift,X,Y);
  157.   if (Button = mbLeft) then
  158.   begin
  159.     SetFocus;
  160.     if ((LabelLen > 0) and (X > LabelLen)) or
  161.        ((LabelLen < 0) and (X < Abs(LabelLen))) then
  162.     begin    {Nur wenn Mausklick innerhalb des hervorgehobenen Schalterteil ist}
  163.       FChecked:=not FChecked;
  164.       CallNotifyEvent;
  165.       Invalidate;
  166.     end;
  167.   end;
  168. end;
  169. {------------------------------------------------------------------------------}
  170.  
  171. procedure TSwitch.WMSetFocus(var Message: TWMSetFocus);
  172. begin
  173.   Invalidate;
  174. end;
  175. {------------------------------------------------------------------------------}
  176.  
  177. procedure TSwitch.WMKillFocus(var Message: TWMKillFocus);
  178. begin
  179.   Invalidate;
  180. end;
  181. {------------------------------------------------------------------------------}
  182.  
  183. procedure TSwitch.KeyDown(var Key: Word; Shift: TShiftState);
  184. begin
  185.   if Focused and ((Key = VK_Space) or (Key = VK_Return)) then
  186.   begin
  187.     FChecked:=not FChecked;
  188.     CallNotifyEvent;
  189.     Invalidate;
  190.     Click;
  191.   end;
  192. end;
  193. {------------------------------------------------------------------------------}
  194.  
  195. procedure TSwitch.CallNotifyEvent;                       {Au-enwelt informieren}
  196. begin
  197.   if Assigned(FOnChanged) then FOnChanged(Self);
  198.   if FChecked and Assigned(FOnChecked) then FOnChecked(Self) else
  199.   if not FChecked and Assigned(FOnUnChecked) then FOnUnChecked(Self);
  200. end;
  201. {------------------------------------------------------------------------------}
  202. procedure TSwitch.Draw_Hor_Rocker;                                      {Schalter zeichnen}
  203. var
  204.   TW: Integer;
  205.   TH: Integer;
  206. begin
  207.   Setup;                                  {Vektoren fnr Schalterteile berechnen}
  208.   if Focused then Canvas.Rectangle(0,0,Width,AHeight + 1 + 2 * ATop);
  209.  
  210.   Canvas.Pen.Color:=clWhite;                   {Umrandung von Schalter zeichnen}
  211.   Canvas.MoveTo(ALeft - 1,ATop + AHeight + 1);
  212.   Canvas.LineTo(ALeft + AWidth,ATop + AHeight + 1);      {Untere Linie in weiss}
  213.   Canvas.LineTo(ALeft + AWidth,ATop - 2);                {Rechte Linie in weiss}
  214.  
  215.   Canvas.Pen.Color:=clGray;
  216.   Canvas.MoveTo(ALeft + AWidth,ATop - 1);
  217.   Canvas.LineTo(ALeft - 1,ATop - 1);                 {Obere Linie in dunkelgrau}
  218.   Canvas.LineTo(ALeft - 1,ATop + AHeight + 1);       {Linke Linie in dunkelgrau}
  219.  
  220.   Canvas.Pen.Color:=clBlack;                      {Polygonumrandung ist schwarz}
  221.   Canvas.Brush.Style:=bsSolid;                      {Fnllfl_che ist geschlossen}
  222.   Setup;
  223.  
  224.   Canvas.Brush.Color:=FTopColor;
  225.   Canvas.Polygon(TopShape);                         {Top des Schalters zeichnen}
  226.   Canvas.Brush.Color:=FSideColor;
  227.   Canvas.Polygon(SideShape);                      {Seite des Schalters zeichnen}
  228.   if FChecked then Canvas.Brush.Color:=FOnColor
  229.   else Canvas.Brush.Color:=FOffColor;
  230.   Canvas.Polygon(OnShape);                     {On Seite des Schalters zeichnen}
  231.   Canvas.Brush.Color:=FOffColor;
  232.   Canvas.Polygon(OffShape);                   {Off Seite des Schalters zeichnen}
  233.  
  234.   Canvas.Font:=Font;                                  {Gew_hlten Font nbergeben}
  235.   Canvas.Brush.Style:=bsClear;                        {Transparente Textausgabe}
  236.  
  237.   if FChecked then Caption:=FCaptionOn else Caption:=FCaptionOff;
  238.  
  239.   if LabelLen > 0 then TW:=ALeft + ((Abs(LabelLen) - Canvas.TextWidth(Caption)) div 2)
  240.   else TW:=LabelOfs + ((Abs(LabelLen) - Canvas.TextWidth(Caption)) div 2);
  241.   TH:=ATop + ((AHeight - Canvas.TextHeight(Caption)) div 2);
  242.  
  243.   Canvas.TextOut(TW,TH,Caption);
  244. end;
  245. {------------------------------------------------------------------------------}
  246.  
  247. procedure TSwitch.Draw_Vert_Rocker;                                      {Schalter zeichnen}
  248. var
  249.   TW: Integer;
  250.   TH: Integer;
  251. begin
  252.   Setup;                                  {Vektoren fnr Schalterteile berechnen}
  253.   if Focused then Canvas.Rectangle(0,0,Width,AHeight + 1 + 2 * ATop);
  254.   Canvas.Pen.Color:=clWhite;                   {Umrandung von Schalter zeichnen}
  255.   Canvas.MoveTo(ALeft - 1,ATop + AHeight + 1);
  256.   Canvas.LineTo(ALeft + AWidth,ATop + AHeight + 1);      {Untere Linie in weiss}
  257.   Canvas.LineTo(ALeft + AWidth,ATop - 2);                {Rechte Linie in weiss}
  258.  
  259.   Canvas.Pen.Color:=clGray;
  260.   Canvas.MoveTo(ALeft + AWidth,ATop - 1);
  261.   Canvas.LineTo(ALeft - 1,ATop - 1);                 {Obere Linie in dunkelgrau}
  262.   Canvas.LineTo(ALeft - 1,ATop + AHeight + 1);       {Linke Linie in dunkelgrau}
  263.  
  264.   Canvas.Pen.Color:=clBlack;                      {Polygonumrandung ist schwarz}
  265.   Canvas.Brush.Style:=bsSolid;                      {Fnllfl_che ist geschlossen}
  266.   SetupVert;
  267.   Canvas.Brush.Color:=FTopColor;
  268.   Canvas.Polygon(TopShape);                         {Top des Schalters zeichnen}
  269.   Canvas.Brush.Color:=FSideColor;
  270.   Canvas.Polygon(SideShape);                      {Seite des Schalters zeichnen}
  271.   if FChecked then Canvas.Brush.Color:=FOnColor
  272.   else Canvas.Brush.Color:=FOffColor;
  273.   Canvas.Polygon(OnShape);                     {On Seite des Schalters zeichnen}
  274.   Canvas.Brush.Color:=FOffColor;
  275.   Canvas.Polygon(OffShape);                   {Off Seite des Schalters zeichnen}
  276.  
  277.   Canvas.Font:=Font;                                  {Gew_hlten Font nbergeben}
  278.   Canvas.Brush.Style:=bsClear;                        {Transparente Textausgabe}
  279.  
  280.   if FChecked then Caption:=FCaptionOn else Caption:=FCaptionOff;
  281.  
  282.   if LabelLen > 0 then TW:=ALeft + ((Abs(LabelLen) - Canvas.TextWidth(Caption)) div 2)
  283.   else TW:=LabelOfs + ((Abs(LabelLen) - Canvas.TextWidth(Caption)) div 2);
  284.   TH:=ATop + ((AHeight - Canvas.TextHeight(Caption)) div 2);
  285.  
  286.   Canvas.TextOut(TW,TH,Caption);
  287. end;
  288. {------------------------------------------------------------------------------}
  289. procedure TSwitch.Draw_Button;                                      {Schalter zeichnen}
  290. var
  291.   TW: Integer;
  292.   TH: Integer;
  293.   Depth: Integer;
  294. begin
  295.   {Setup;                                  {Vektoren fnr Schalterteile berechnen}
  296.   if Focused then Canvas.Rectangle(0,0,Width,Height);
  297.   Canvas.Pen.Color:=clWhite;                   {Umrandung von Schalter zeichnen}
  298.   Canvas.MoveTo(1, Height-1);
  299.   Canvas.LineTo(Width-1, Height - 1);      {Untere Linie in weiss}
  300.   Canvas.LineTo(Width-1, 1);                {Rechte Linie in weiss}
  301.  
  302.   Canvas.Pen.Color:=clGray;
  303.   Canvas.MoveTo(Width-1, 1);
  304.   Canvas.LineTo(1, 1);                 {Obere Linie in dunkelgrau}
  305.   Canvas.LineTo(1, Height-1);       {Linke Linie in dunkelgrau}
  306.  
  307.   Canvas.Pen.Color:=clBlack;                      {Polygonumrandung ist schwarz}
  308.   Canvas.Brush.Style:=bsSolid;                      {Fnllfl_che ist geschlossen}
  309. {Added / changed by MJB:}
  310.   Canvas.Brush.Color:=FTopColor;
  311.   Canvas.Rectangle(1,1, Width-1, Height-1);
  312.  
  313.   if FChecked then Depth := FSlope div 2 else Depth := FSlope;
  314.  
  315.   Canvas.Brush.Color:=FSideColor;
  316.   Canvas.Ellipse(FSideLength, FSideLength, Width-FSideLength, Height-FSideLength);
  317.   Canvas.Rectangle(Width div 2 - Depth, FSideLength, Width div 2, Height-FSideLength);
  318.  
  319.   if FChecked then
  320.     Canvas.Brush.Color:=FOnColor
  321.    else Canvas.Brush.Color:=FOffColor;
  322.   Canvas.Ellipse(FSideLength- Depth, FSideLength, Width-FSideLength - Depth, Height-FSideLength);
  323.  
  324.   Canvas.Font:=Font;                                  {Gew_hlten Font nbergeben}
  325.   Canvas.Brush.Style:=bsClear;                        {Transparente Textausgabe}
  326.  
  327.   if FChecked then Caption:=FCaptionOn else Caption:=FCaptionOff;
  328.  
  329.   TW:=(Width - Canvas.TextWidth(Caption)) div 2 - Depth;
  330.   TH:=(Height - Canvas.TextHeight(Caption)) div 2;
  331.  
  332.   Canvas.TextOut(TW,TH,Caption);
  333. end;
  334. {------------------------------------------------------------------------------}
  335.  
  336. procedure TSwitch.Setup;                  {Vektoren fnr Schalterteile berechnen}
  337. begin
  338.   ALeft:=2;                {2 Pixel linker Abstand fnr Rahmen und Focusrechteck}
  339.   ATop:=2;                 {2 Pixel oberer Abstand fnr Rahmen und Focusrechteck}
  340.   AHeight:=Height - FSlope - 2 * ATop;   {Schalterhwhe = Height - Ofs - Neigung}
  341.   AWidth:=Width - 2 * ALeft;                  {Schalterbreite = Width - 2 * Ofs}
  342.   LabelLen:=AWidth div 2;
  343.   LabelOfs:=LabelLen + ALeft;
  344.   Side:=FSideLength;
  345.   if (not FChecked and FCheckedLeft) or (not FCheckedLeft and FChecked) then
  346.   begin
  347.     LabelLen:=-LabelLen;
  348.     Side:=-FSideLength;
  349.   end;
  350.   TopShape[0].X:=LabelOfs;          {Vektoren von obere Dreieckfl_che berechnen}
  351.   TopShape[0].Y:=ATop;
  352.   TopShape[1].X:=LabelOfs + LabelLen - Side;
  353.   TopShape[1].Y:=ATop + FSlope;
  354.   TopShape[2].X:=LabelOfs + LabelLen;
  355.   TopShape[2].Y:=ATop;
  356.  
  357.   OnShape[0].X:=LabelOfs - LabelLen;   {Vektoren der "EIN" Frontseite berechnen}
  358.   OnShape[0].Y:=ATop;
  359.   OnShape[1]:=TopShape[0];
  360.   OnShape[2]:=OffShape[3];
  361.   OnShape[3].X:=OnShape[0].X;
  362.   OnShape[3].Y:=ATop + AHeight;
  363.  
  364.   OffShape[0]:=TopShape[0];            {Vektoren der "AUS" Frontseite berechnen}
  365.   OffShape[1]:=TopShape[1];
  366.   OffShape[2].X:=OffShape[1].X;
  367.   OffShape[2].Y:=OffShape[1].Y + AHeight;
  368.   OffShape[3].X:=OffShape[0].X;
  369.   OffShape[3].Y:=ATop + AHeight;
  370.  
  371.   SideShape[0]:=OffShape[1];               {Vektoren der Seitenfl_che berechnen}
  372.   SideShape[1]:=TopShape[2];
  373.   SideShape[2].X:=SideShape[1].X;
  374.   SideShape[2].Y:=ATop + AHeight;
  375.   SideShape[3]:=OffShape[2];
  376. end;
  377. {------------------------------------------------------------------------------}
  378.  
  379. procedure TSwitch.SetupVert;                  {Vektoren fnr Schalterteile berechnen}
  380. begin
  381.   ALeft:=2;                {2 Pixel linker Abstand fnr Rahmen und Focusrechteck}
  382.   ATop:=2;                 {2 Pixel oberer Abstand fnr Rahmen und Focusrechteck}
  383.   AHeight:=Height - FSlope - 2 * ATop;   {Schalterhwhe = Height - Ofs - Neigung}
  384.   AWidth:=Width - 2 * ALeft;                  {Schalterbreite = Width - 2 * Ofs}
  385.   LabelLen:=AWidth div 2;
  386.   LabelOfs:=LabelLen + ALeft;
  387.   Side:=FSideLength;
  388.   if (not FChecked and FCheckedLeft) or (not FCheckedLeft and FChecked) then
  389.   begin
  390.     LabelLen:=-LabelLen;
  391.     Side:=-FSideLength;
  392.   end;
  393.   TopShape[0].Y:=-LabelOfs;          {Vektoren von obere Dreieckfl_che berechnen}
  394.   TopShape[0].X:=ATop;
  395.   TopShape[1].Y:=LabelOfs + LabelLen - Side;
  396.   TopShape[1].X:=ATop + FSlope;
  397.   TopShape[2].Y:=LabelOfs + LabelLen;
  398.   TopShape[2].X:=ATop;
  399.  
  400.   OnShape[0].Y:=LabelOfs - LabelLen;   {Vektoren der "EIN" Frontseite berechnen}
  401.   OnShape[0].X:=ATop;
  402.   OnShape[1]:=TopShape[0];
  403.   OnShape[2]:=OffShape[3];
  404.   OnShape[3].Y:=OnShape[0].Y;
  405.   OnShape[3].X:=ATop + AHeight;
  406.  
  407.   OffShape[0]:=TopShape[0];            {Vektoren der "AUS" Frontseite berechnen}
  408.   OffShape[1]:=TopShape[1];
  409.   OffShape[2].Y:=OffShape[1].Y;
  410.   OffShape[2].X:=OffShape[1].X + AHeight;
  411.   OffShape[3].Y:=OffShape[0].Y;
  412.   OffShape[3].X:=ATop + AHeight;
  413.  
  414.   SideShape[0]:=OffShape[1];               {Vektoren der Seitenfl_che berechnen}
  415.   SideShape[1]:=TopShape[2];
  416.   SideShape[2].Y:=SideShape[1].Y;
  417.   SideShape[2].X:=ATop + AHeight;
  418.   SideShape[3]:=OffShape[2];
  419. end;
  420.  
  421. {------------------------------------------------------------------------------}
  422.  
  423. procedure TSwitch.SetCaptionOn(Value: TCaption);   {Beschriftung "ON" nbergeben}
  424. begin
  425.   if FCaptionOn <> Value then
  426.   begin
  427.     FCaptionOn:=Value;
  428.     Invalidate;
  429.   end;
  430. end;
  431. {------------------------------------------------------------------------------}
  432.  
  433. procedure TSwitch.SetCaptionOff(Value: TCaption); {Beschriftung "OFF" nbergeben}
  434. begin
  435.   if FCaptionOff <> Value then
  436.   begin
  437.     FCaptionOff:=Value;
  438.     Invalidate;
  439.   end;
  440. end;
  441. {------------------------------------------------------------------------------}
  442.  
  443. procedure TSwitch.SetChecked(Value: Boolean);
  444. begin
  445.   if FChecked <> Value then
  446.   begin
  447.     FChecked:=Value;
  448.     CallNotifyEvent;
  449.     Invalidate;
  450.   end;
  451. end;
  452. {------------------------------------------------------------------------------}
  453.  
  454. procedure TSwitch.SetCheckedLeft(Value: Boolean);
  455. begin
  456.   if FCheckedLeft <> Value then
  457.   begin
  458.     FCheckedLeft:=Value;
  459.     Invalidate;
  460.   end;
  461. end;
  462. {------------------------------------------------------------------------------}
  463.  
  464. procedure TSwitch.SetSlope(Value: Byte);
  465. begin
  466.   if FSlope <> Value then
  467.   begin
  468.     if (FSideLength > Value) then
  469.     begin
  470.       FSlope:=Value;
  471.       Invalidate;
  472.     end;
  473.   end;
  474. end;
  475. {------------------------------------------------------------------------------}
  476.  
  477. procedure TSwitch.SetSideLength(Value: Byte);
  478. begin
  479.   if (FSideLength <> Value) and (Value < Width - 4) then
  480.   begin
  481.     if (Value > FSlope) then
  482.     begin
  483.       FSideLength:=Value;
  484.       Invalidate;
  485.     end;
  486.   end;
  487. end;
  488. {------------------------------------------------------------------------------}
  489.  
  490. procedure TSwitch.SetOnColor(Value: TColor);
  491. begin
  492.   if FOnColor <> Value then
  493.   begin
  494.     FOnColor:=Value;
  495.     Invalidate;
  496.   end;
  497. end;
  498. {------------------------------------------------------------------------------}
  499.  
  500. procedure TSwitch.SetOffColor(Value: TColor);
  501. begin
  502.   if FOffColor <> Value then
  503.   begin
  504.     FOffColor:=Value;
  505.     Invalidate;
  506.   end;
  507. end;
  508. {------------------------------------------------------------------------------}
  509.  
  510. procedure TSwitch.SetTopColor(Value: TColor);
  511. begin
  512.   if FTopColor <> Value then
  513.   begin
  514.     FTopColor:=Value;
  515.     Invalidate;
  516.   end;
  517. end;
  518. {------------------------------------------------------------------------------}
  519.  
  520. procedure TSwitch.SetSideColor(Value: TColor);
  521. begin
  522.   if FSideColor <> Value then
  523.   begin
  524.     FSideColor:=Value;
  525.     Invalidate;
  526.   end;
  527. end;
  528. {------------------------------------------------------------------------------}
  529.  
  530. procedure TSwitch.SetSwitchType(Value: TSwitchType);
  531. begin
  532.   FSwitchType := Value;
  533.   Invalidate;
  534. end;
  535. {------------------------------------------------------------------------------}
  536.  
  537. procedure Register;
  538. begin
  539.   RegisterComponents('Samples',[TSwitch]);
  540. end;
  541. {------------------------------------------------------------------------------}
  542.  
  543. initialization
  544. end.
  545.  
  546.