CDSizer.pas
上传用户:wanyu_2000
上传日期:2021-02-21
资源大小:527k
文件大小:11k
源码类别:

DVD

开发平台:

Delphi

  1. {-----------------------------------------------------------------------------
  2.  Unit Name: CDSizer
  3.  Author:    Dancemammal
  4.  Purpose:   Visual guide to CD / DVD Usage
  5.  History:   First Code Release
  6. -----------------------------------------------------------------------------}
  7. unit CDSizer;
  8. interface
  9. uses Classes, Controls, Forms, Graphics, Messages, SysUtils, 
  10.      WinProcs, WinTypes;
  11.      { Unit-wide declarations }
  12.      { type }
  13.      { . . . }
  14.      { var }
  15.      { . . . }
  16. type
  17.   TCDSize = class(TGraphicControl)
  18.     private
  19.       { Private fields of TCDSize }
  20.         { Storage for property BarColour }
  21.         FBarColour : TColor;
  22.         { Storage for property IsHorizontal }
  23.         FIsHorizontal : Boolean;
  24.         { Storage for property MaxCDSize }
  25.         FMaxCDSize : Integer;
  26.         { Storage for property MaxMemory }
  27.         FMaxMemory : Integer;
  28.         { Storage for property OverBurnColour }
  29.         FOverBurnColour : TColor;
  30.         { Storage for property PercentShaded }
  31.         FMEMShaded : Integer;
  32.         { Storage for property TickColour }
  33.         FTickColour : TColor;
  34.         { Pointer to application's OnOverBurn handler, if any }
  35.         FOnOverBurn : TNotifyEvent;
  36.         { Storage for property BarColour }
  37.         FMEMBarColour : TColor;
  38.         FGap : Integer;
  39.       { Private methods of TCDSize }
  40.         { Method to set variable and property values and create objects }
  41.         procedure AutoInitialize;
  42.         { Method to free any objects created by AutoInitialize }
  43.         procedure AutoDestroy;
  44.         { Read method for property BarColour }
  45.         function GetBarColour : TColor;
  46.         { Write method for property BarColour }
  47.         procedure SetBarColour(Value : TColor);
  48.         { Read method for property BarColour }
  49.         function GetMemBarColour : TColor;
  50.         { Write method for property BarColour }
  51.         procedure SetMemBarColour(Value : TColor);
  52.         { Read method for property MaxCDSize }
  53.         function GetMaxCDSize : Integer;
  54.         { Write method for property MaxCDSize }
  55.         procedure SetMaxCDSize(Value : Integer);
  56.         { Read method for property MaxMemory }
  57.         function GetMaxMemory : Integer;
  58.         { Write method for property MaxMemory }
  59.         procedure SetMaxMemory(Value : Integer);
  60.         { Read method for property OverBurnColour }
  61.         function GetOverBurnColour : TColor;
  62.         { Write method for property OverBurnColour }
  63.         procedure SetOverBurnColour(Value : TColor);
  64.         { Write method for property PercentShaded }
  65.         procedure SetPercentShaded(Value : Integer);
  66.         { Read method for property TickColour }
  67.         function GetTickColour : TColor;
  68.         { Write method for property TickColour }
  69.         procedure SetTickColour(Value : TColor);
  70.     protected
  71.       { Protected fields of TCDSize }
  72.         TickCount : double;
  73.       { Protected methods of TCDSize }
  74.         { Method to generate OnOverBurn event }
  75.         procedure OverBurn(Sender : TObject); virtual;
  76.         procedure Paint; override;
  77.     public
  78.       { Public fields and properties of TCDSize }
  79.         { Orientation of the progress bar (read-only) }
  80.         property IsHorizontal : Boolean read FIsHorizontal;
  81.       { Public methods of TCDSize }
  82.         constructor Create(AOwner: TComponent); override;
  83.         destructor Destroy; override;
  84.     published
  85.       property Align;
  86.       { Published properties of TCDSize }
  87.         property OnOverBurn : TNotifyEvent read FOnOverBurn write FOnOverBurn;
  88.         property BarColour : TColor
  89.              read GetBarColour write SetBarColour
  90.              default clSilver;
  91.         property MemBarColour : TColor
  92.              read GetMemBarColour write SetMemBarColour
  93.              default clSilver;
  94.         Property ProgressGap : Integer read FGap write FGap default 2;
  95.         property Height default 20;
  96.         { CD Max Size }
  97.         property MaxCDSize : Integer
  98.              read GetMaxCDSize write SetMaxCDSize
  99.              default 650;
  100.         property MaxMemory : Integer
  101.              read GetMaxMemory write SetMaxMemory
  102.              default 750;
  103.         { Colour After Size }
  104.         property OverBurnColour : TColor
  105.              read GetOverBurnColour write SetOverBurnColour
  106.              default clRed;
  107.         { Percentage of the progress bar shaded }
  108.         property MemShaded : Integer
  109.              read FMEMShaded write SetPercentShaded
  110.              default 0;
  111.         property TickColour : TColor
  112.              read GetTickColour write SetTickColour
  113.              default clBlack;
  114.         property Width default 90;
  115.   end;
  116. implementation
  117. { Method to set variable and property values and create objects }
  118. procedure TCDSize.AutoInitialize;
  119. begin
  120.      TickCount := 5.0;
  121.      FBarColour := clSilver;
  122.      Height := 20;
  123.      FMaxCDSize := 650;
  124.      FMaxMemory := 750;
  125.      FOverBurnColour := clRed;
  126.      FMEMShaded := 0;
  127.      FTickColour := clBlack;
  128.      Width := 90;
  129. end; { of AutoInitialize }
  130. { Method to free any objects created by AutoInitialize }
  131. procedure TCDSize.AutoDestroy;
  132. begin
  133.      { No objects from AutoInitialize to free }
  134. end; { of AutoDestroy }
  135. { Read method for property BarColour }
  136. function TCDSize.GetBarColour : TColor;
  137. begin
  138.      Result := FBarColour;
  139. end;
  140. { Write method for property BarColour }
  141. procedure TCDSize.SetBarColour(Value : TColor);
  142. begin
  143.      FBarColour := Value;
  144.      { If changing this property affects the appearance of
  145.        the component, call Invalidate here so the image will be
  146.        updated. }
  147.       Invalidate;
  148. end;
  149. function TCDSize.GetMemBarColour : TColor;
  150. begin
  151.      Result := FMEMBarColour;
  152. end;
  153. { Write method for property BarColour }
  154. procedure TCDSize.SetMemBarColour(Value : TColor);
  155. begin
  156.      FMEMBarColour := Value;
  157.      { If changing this property affects the appearance of
  158.        the component, call Invalidate here so the image will be
  159.        updated. }
  160.       Invalidate;
  161. end;
  162. { Read method for property MaxCDSize }
  163. function TCDSize.GetMaxCDSize : Integer;
  164. begin
  165.      Result := FMaxCDSize;
  166. end;
  167. { Write method for property MaxCDSize }
  168. procedure TCDSize.SetMaxCDSize(Value : Integer);
  169. begin
  170.      FMaxCDSize := Value;
  171.      { If changing this property affects the appearance of
  172.        the component, call Invalidate here so the image will be
  173.        updated. }
  174.      { Invalidate; }
  175. end;
  176. { Read method for property MaxMemory }
  177. function TCDSize.GetMaxMemory : Integer;
  178. begin
  179.      Result := FMaxMemory;
  180. end;
  181. { Write method for property MaxMemory }
  182. procedure TCDSize.SetMaxMemory(Value : Integer);
  183. begin
  184.      FMaxMemory := Value;
  185.      { If changing this property affects the appearance of
  186.        the component, call Invalidate here so the image will be
  187.        updated. }
  188.      { Invalidate; }
  189. end;
  190. { Read method for property OverBurnColour }
  191. function TCDSize.GetOverBurnColour : TColor;
  192. begin
  193.      Result := FOverBurnColour;
  194. end;
  195. { Write method for property OverBurnColour }
  196. procedure TCDSize.SetOverBurnColour(Value : TColor);
  197. begin
  198.      FOverBurnColour := Value;
  199.      { If changing this property affects the appearance of
  200.        the component, call Invalidate here so the image will be
  201.        updated. }
  202.      { Invalidate; }
  203. end;
  204. { Write method for property PercentShaded }
  205. procedure TCDSize.SetPercentShaded(Value : Integer);
  206. begin
  207.      FMEMShaded := Value;
  208.      if FMEMShaded < 0 then
  209.           FMEMShaded := 0
  210.      else
  211.           if FMEMShaded > FMaxMemory then
  212.                FMEMShaded := FMaxMemory;
  213.      { Update the display of the component }
  214.      Invalidate
  215. end;
  216. { Read method for property TickColour }
  217. function TCDSize.GetTickColour : TColor;
  218. begin
  219.      Result := FTickColour;
  220. end;
  221. { Write method for property TickColour }
  222. procedure TCDSize.SetTickColour(Value : TColor);
  223. begin
  224.      FTickColour := Value;
  225.      { If changing this property affects the appearance of
  226.        the component, call Invalidate here so the image will be
  227.        updated. }
  228.      { Invalidate; }
  229. end;
  230. { Method to generate OnOverBurn event }
  231. procedure TCDSize.OverBurn(Sender : TObject);
  232. begin
  233.      { Has the application assigned a method to the event, whether
  234.        via the Object Inspector or a run-time assignment?  If so,
  235.        execute that method }
  236.      if Assigned(FOnOverBurn) then
  237.         FOnOverBurn(Sender);
  238. end;
  239. constructor TCDSize.Create(AOwner: TComponent);
  240. begin
  241.      { Call the Create method of the parent class }
  242.      inherited Create(AOwner);
  243.      { Set the initial values of variables and properties using }
  244.      { AutoInitialize procedure, generated by Component Create  }
  245.      AutoInitialize;
  246.      { Code to perform other tasks when the component is created }
  247. end;
  248. destructor TCDSize.Destroy;
  249. begin
  250.      { AutoDestroy, which is generated by Component Create, frees any   }
  251.      { objects created by AutoInitialize.                               }
  252.      AutoDestroy;
  253.      { Here, free any other dynamic objects that the component methods  }
  254.      { created but have not yet freed.  Also perform any other clean-up }
  255.      { operations needed before the component is destroyed.             }
  256.      { Last, free the component by calling the Destroy method of the    }
  257.      { parent class.                                                    }
  258.      inherited Destroy;
  259. end;
  260. procedure TCDSize.Paint;
  261. var
  262.    TickNumber :integer;
  263.    TickIndex :Integer;
  264.    Divisor :Integer;
  265. begin
  266.      { Determine orientation; store it so it will
  267.        be available in the IsHorizontal property }
  268.      FIsHorizontal := (Width >= Height);
  269.      Divisor := 10;
  270.      if FMaxMemory > 1000 then Divisor := 100;
  271.      TickNumber := round(FMaxMemory / Divisor);
  272.      TickCount := (width / (FMaxMemory / Divisor));
  273.      { Draw the framing rectangle }
  274.      Canvas.Brush.Color := clWhite;
  275.      Canvas.Pen.Width := 0;
  276.      Canvas.Rectangle(0, 0, Width, Height);
  277.     { Draw the Main cd mem bar within }
  278.     Canvas.Brush.Color := FBarColour;
  279.     Canvas.Rectangle(0, 0, Round(Width * (FMaxCDSize/FMaxMemory))+1,(Height div 2));
  280.      { Draw the progress bar within }
  281.      if (FMEMShaded > FMaxCDSize) then
  282.      Canvas.Brush.Color := FOverBurnColour
  283.      else
  284.       Canvas.Brush.Color := FMEMBarColour;
  285.      Canvas.Pen.Width := 0;
  286.      if FIsHorizontal then
  287.           Canvas.Rectangle(2, FGap, Round(Width * (FMEMShaded/FMaxMemory))+1, (Height div 2)- FGap)
  288.      else
  289.           Canvas.Rectangle(FGap, FGap, Width, Round(Height * (FMEMShaded/FMaxMemory))-FGap);
  290.     Canvas.Pen.Width := 1;
  291.     Canvas.Pen.Color := TickColour;
  292.     Canvas.Font.Color := TickColour;
  293.     Canvas.Brush.Style := bsClear;
  294.     for TickIndex := 1 to TickNumber do
  295.     begin
  296.     Canvas.MoveTo(round(TickIndex * TickCount),0);
  297.     If (TickIndex mod 5) = 0 then   // every 5
  298.     begin
  299.     If (TickIndex mod 10) = 0 then
  300.     begin
  301.     Canvas.LineTo(round(TickIndex * TickCount),Height);  //every 10
  302.     canvas.TextOut(round(TickIndex * TickCount)-20,(Height div 2)+2,inttostr(TickIndex*Divisor)+' mb');
  303.     end
  304.     else
  305.     Canvas.LineTo(round(TickIndex * TickCount),(Height div 2)+3);
  306.     end
  307.     else
  308.     Canvas.LineTo(round(TickIndex * TickCount),(Height div 2));
  309.     end;
  310.      if (FMEMShaded > FMaxCDSize) then
  311.         if assigned(FOnOverBurn) then FOnOverBurn(nil);
  312. end;
  313. end.