📄 mmgauge.pas
字号:
{========================================================================}
{= (c) 1995-98 SwiftSoft Ronald Dittrich =}
{========================================================================}
{= All Rights Reserved =}
{========================================================================}
{= D 01099 Dresden = Tel.: +0351-8012255 =}
{= Loewenstr.7a = info@swiftsoft.de =}
{========================================================================}
{= Actual versions on http://www.swiftsoft.de/mmtools.html =}
{========================================================================}
{= This code is for reference purposes only and may not be copied or =}
{= distributed in any format electronic or otherwise except one copy =}
{= for backup purposes. =}
{= =}
{= No Delphi Component Kit or Component individually or in a collection=}
{= subclassed or otherwise from the code in this unit, or associated =}
{= .pas, .dfm, .dcu, .asm or .obj files may be sold or distributed =}
{= without express permission from SwiftSoft. =}
{= =}
{= For more licence informations please refer to the associated =}
{= HelpFile. =}
{========================================================================}
{= $Date: 15.02.98 - 15:32:59 $ =}
{========================================================================}
unit MMGauge;
{$I COMPILER.INC}
interface
uses
{$IFDEF WIN32}
Windows,
{$ELSE}
WinTypes,
WinProcs,
{$ENDIF}
Classes,
Controls,
Graphics,
Menus,
MMObj;
type
TMMGaugeKind = (gkText,gkHorizontalBar,gkVerticalBar,gkPie,gkNeedle);
const
{$IFDEF CBUILDER3} {$EXTERNALSYM defWidth } {$ENDIF}
defWidth = 150;
{$IFDEF CBUILDER3} {$EXTERNALSYM defHeight } {$ENDIF}
defHeight = 18;
{$IFDEF CBUILDER3} {$EXTERNALSYM defKind } {$ENDIF}
defKind = gkHorizontalBar;
{$IFDEF CBUILDER3} {$EXTERNALSYM defShowText } {$ENDIF}
defShowText = True;
{$IFDEF CBUILDER3} {$EXTERNALSYM defForeColor } {$ENDIF}
defForeColor = clActiveCaption;
{$IFDEF CBUILDER3} {$EXTERNALSYM defBackColor } {$ENDIF}
defBackColor = clWhite;
{$IFDEF CBUILDER3} {$EXTERNALSYM defMinValue } {$ENDIF}
defMinValue = 0;
{$IFDEF CBUILDER3} {$EXTERNALSYM defMaxValue } {$ENDIF}
defMaxValue = 100;
{$IFDEF CBUILDER3} {$EXTERNALSYM defProgress } {$ENDIF}
defProgress = 0;
{$IFDEF CBUILDER3} {$EXTERNALSYM defBWText } {$ENDIF}
defBWText = False;
type
{-- TMMCustomGauge --------------------------------------------------}
TMMCustomGauge = class(TMMGraphicControl)
private
FMinValue : Longint;
FMaxValue : Longint;
FCurValue : Longint;
FKind : TMMGaugeKind;
FShowText : Boolean;
FForeColor : TColor;
FBackColor : TColor;
FBWText : Boolean;
FCaption : string;
procedure SetGaugeKind(Value: TMMGaugeKind);
procedure SetShowText(Value: Boolean);
procedure SetForeColor(Value: TColor);
procedure SetBackColor(Value: TColor);
procedure SetMinValue(Value: Longint);
procedure SetMaxValue(Value: Longint);
procedure SetProgress(Value: Longint);
procedure SetCaption(const Value: string);
procedure SetBWText(Value: Boolean);
function GetPercentDone: LongInt;
protected
procedure Paint; override;
procedure PaintImage(Canvas: TCanvas; R: TRect); virtual;
procedure PaintText(Canvas: TCanvas; R: TRect); virtual;
procedure PaintAsBar(Canvas: TCanvas; R: TRect; Horz: Boolean); virtual;
procedure PaintAsPie(Canvas: TCanvas; R: TRect); virtual;
procedure PaintAsNeedle(Canvas: TCanvas; R: TRect); virtual;
procedure PaintAsNothing(Canvas: TCanvas; R: TRect); virtual;
public
constructor Create(AOwner: TComponent); override;
procedure AddProgress(Value: Longint);
property PercentDone: Longint read GetPercentDone;
protected
property Width default defWidth;
property Height default defHeight;
property Kind: TMMGaugeKind read FKind write SetGaugeKind default defKind;
property ShowText: Boolean read FShowText write SetShowText default defShowText;
property ForeColor: TColor read FForeColor write SetForeColor default defForeColor;
property BackColor: TColor read FBackColor write SetBackColor default defBackColor;
property MinValue: Longint read FMinValue write SetMinValue default defMinValue;
property MaxValue: Longint read FMaxValue write SetMaxValue default defMaxValue;
property Progress: Longint read FCurValue write SetProgress default defProgress;
property Caption: string read FCaption write SetCaption;
property BWText: Boolean read FBWText write SetBWText default defBWText;
end;
{-- TMMGauge --------------------------------------------------------}
TMMGauge = class(TMMCustomGauge)
published
property Kind;
property ShowText;
property ForeColor;
property BackColor;
property MinValue;
property MaxValue;
property Progress;
property Caption;
property BWText;
property Align;
property Enabled;
property Font;
property Bevel;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property Visible;
end;
implementation
uses
SysUtils,
MMUtils;
{------------------------------------------------------------------------}
{ This function solves for x in the equation "x is y% of z". }
function SolveForX(Y, Z: Longint): Longint;
begin
Result := Trunc(Z*(Y*0.01));
end;
{------------------------------------------------------------------------}
{ This function solves for y in the equation "x is y% of z". }
function SolveForY(X, Z: Longint): Longint;
begin
if Z = 0 then
Result := 0
else
Result := Trunc((X*100.0)/Z);
end;
{== TMMCustomGauge ======================================================}
constructor TMMCustomGauge.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FKind := defKind;
FShowText := defShowText;
FForeColor := defForeColor;
FBackColor := defBackColor;
FMinValue := defMinValue;
FMaxValue := defMaxValue;
FCurValue := defProgress;
FBWText := defBWText;
Width := defWidth;
Height := defHeight;
ErrorCode := ComponentRegistered(InitCode, Self, ClassName);
if (ErrorCode <> 0) then RegisterFailed(InitCode, Self , ClassName);
end;
{-- TMMCustomGauge ------------------------------------------------------}
procedure TMMCustomGauge.SetGaugeKind(Value: TMMGaugeKind);
begin
if Value <> FKind then
begin
FKind := Value;
Invalidate;
end;
end;
{-- TMMCustomGauge ------------------------------------------------------}
procedure TMMCustomGauge.SetShowText(Value: Boolean);
begin
if Value <> FShowText then
begin
FShowText := Value;
Invalidate;
end;
end;
{-- TMMCustomGauge ------------------------------------------------------}
procedure TMMCustomGauge.SetForeColor(Value: TColor);
begin
if Value <> FForeColor then
begin
FForeColor := Value;
Invalidate;
end;
end;
{-- TMMCustomGauge ------------------------------------------------------}
procedure TMMCustomGauge.SetBackColor(Value: TColor);
begin
if Value <> FBackColor then
begin
FBackColor := Value;
Invalidate;
end;
end;
{-- TMMCustomGauge ------------------------------------------------------}
procedure TMMCustomGauge.SetMinValue(Value: Longint);
begin
Value := MinMax(Value,-MaxInt,MaxValue);
if Value <> FMinValue then
begin
FMinValue := Value;
Invalidate;
end;
end;
{-- TMMCustomGauge ------------------------------------------------------}
procedure TMMCustomGauge.SetMaxValue(Value: Longint);
begin
Value := MinMax(Value,MinValue,MaxInt);
if Value <> FMaxValue then
begin
FMaxValue := Value;
Invalidate;
end;
end;
{-- TMMCustomGauge ------------------------------------------------------}
procedure TMMCustomGauge.SetProgress(Value: Longint);
var
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -