1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
unit AdminServerHealthBarGraph;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, AuxFuncs, StdCtrls, ExtCtrls, PNGImage, TntForms, TntStdCtrls,
TntExtCtrls, myx_admin_public_interface;
type
TAdminServerHealthBarGraphFrame = class(TTntFrame)
ValueImg: TTntImage;
MainPnl: TTntPanel;
EmptyImg: TTntImage;
ValueLbl: TTntLabel;
MaxLbl: TTntLabel;
CaptionPnl: TTntPanel;
CaptionLbl: TTntLabel;
constructor Create(AOwner: TComponent;
GraphCaption: WideString = '';
DisplayGraphCaption: integer = 0;
ValueCaption: WideString = '';
MaxCaption: WideString = '';
MinValue: Double = 0; MaxValue: Double = 100;
ValueUnit: MYX_HEALTH_GRAPH_VALUE_UNIT = MYX_HGVU_COUNT); reintroduce;
destructor Destroy; override;
procedure SetValue(value: double);
procedure SetMaxValue(MaxValue: double);
procedure FrameResize(Sender: TObject);
procedure TntFrameDblClick(Sender: TObject);
function GetValueCaption(ValueCaption: WideString; value: double): WideString;
private
FEmptyPNGImg,
FFilledPNGImg: TPNGObject;
FMinValue: Double;
FMaxValue: Double;
FValue: Double;
public
ValueUnit: MYX_HEALTH_GRAPH_VALUE_UNIT;
ValueCaption,
MaxCaption: WideString;
end;
implementation
{$R *.dfm}
uses
PNGTools;
constructor TAdminServerHealthBarGraphFrame.Create(AOwner: TComponent;
GraphCaption: WideString;
DisplayGraphCaption: integer;
ValueCaption: WideString;
MaxCaption: WideString;
MinValue: Double; MaxValue: Double;
ValueUnit: MYX_HEALTH_GRAPH_VALUE_UNIT);
begin
inherited Create(AOwner);
FEmptyPNGImg := LoadPNGImageFromResource('health_bar_empty', EmptyImg);
FFilledPNGImg := LoadPNGImageFromResource('health_bar_filled', ValueImg);
ValueImg.Width:=0;
self.ValueCaption:=ValueCaption;
self.MaxCaption:=MaxCaption;
ValueLbl.Caption:='';
MaxLbl.Caption:='';
FMinValue:=MinValue;
FMaxValue:=MaxValue;
self.ValueUnit:=ValueUnit;
CaptionLbl.Caption:=GraphCaption+':';
if(DisplayGraphCaption=0)then
CaptionPnl.Width:=0;
end;
destructor TAdminServerHealthBarGraphFrame.Destroy;
begin
FEmptyPNGImg.Free;
FFilledPNGImg.Free;
inherited Destroy;
end;
procedure TAdminServerHealthBarGraphFrame.SetValue(value: double);
begin
if value > FMaxValue then
value := FMaxValue;
ValueLbl.Caption:=GetValueCaption(ValueCaption, Value);
ValueImg.Width := Round((value - FMinValue) / (FMaxValue - FMinValue) * EmptyImg.Width);
FValue := value;
end;
function TAdminServerHealthBarGraphFrame.GetValueCaption(ValueCaption: WideString; value: double): WideString;
var s: WideString;
begin
case ValueUnit of
MYX_HGVU_PERCENTAGE:
if(Trunc(value)=value)then
s:=ValueCaption+' '+FormatFloat('##0', value)+' %'
else
s:=ValueCaption+' '+FormatFloat('##0.0', value)+' %';
MYX_HGVU_COUNT:
if(Trunc(value)=value)then
s:=ValueCaption+' '+FormatFloat('###,###,##0', value)
else
s:=ValueCaption+' '+FormatFloat('###,###,##0.00', value);
MYX_HGVU_BYTE:
s:=ValueCaption+' '+FormatFileSize(value);
MYX_HGVU_SECONDS:
if(Trunc(value)=value)then
s:=ValueCaption+' '+FormatFloat('###,###,##0', value)+' s'
else
s:=ValueCaption+' '+FormatFloat('###,###,##0.00', value)+' s';
end;
Result:=s;
end;
procedure TAdminServerHealthBarGraphFrame.SetMaxValue(MaxValue: double);
begin
MaxLbl.Caption:=GetValueCaption(MaxCaption, MaxValue);
FMaxValue:=MaxValue;
if FMaxValue = 0 then
FMaxValue := 1;
SetValue(FValue);
end;
procedure TAdminServerHealthBarGraphFrame.FrameResize(Sender: TObject);
begin
SetValue(FValue);
end;
procedure TAdminServerHealthBarGraphFrame.TntFrameDblClick(
Sender: TObject);
begin
if(Assigned(OnDblClick))then
OnDblClick(self);
end;
end.
|