IndustrialStuff: formatting of AdvLed unit.

git-svn-id: trunk@43313 -
This commit is contained in:
juha 2013-10-23 22:52:36 +00:00
parent bef40f8589
commit 9164f8170a

View File

@ -25,10 +25,9 @@ type
// property types // property types
TLedBitmap = Graphics.TPicture; TLedBitmap = Graphics.TPicture;
// TLedKind = (lkRedLight, lkGreenLight, lkBlueLight, lkYellowLight, // TLedKind = (lkRedLight, lkGreenLight, lkBlueLight, lkYellowLight, lkPurpleLight, lkBulb, lkCustom);
// lkPurpleLight, lkBulb, lkCustom); TLedKind = (lkRedLight, lkGreenLight, lkYellowLight, lkBulb, lkCustom);
TLedKind = (lkRedLight, lkGreenLight,lkYellowLight, lkBulb, lkCustom); TLedState = (lsDisabled, lsOff, lsOn);
TLedState = (lsDisabled,lsOff, lsOn);
TAdvLedGlyphs = array[TLedState] of TLedBitmap; TAdvLedGlyphs = array[TLedState] of TLedBitmap;
TLedStateEvent = procedure(Sender: TObject; AState: TLedState) of object; TLedStateEvent = procedure(Sender: TObject; AState: TLedState) of object;
@ -50,7 +49,6 @@ type
procedure SetBlink(const Value: Boolean); procedure SetBlink(const Value: Boolean);
function StoredGlyph(const Index: Integer): Boolean; function StoredGlyph(const Index: Integer): Boolean;
procedure SelectLedBitmap(const LedKind: TLedKind); procedure SelectLedBitmap(const LedKind: TLedKind);
procedure SetStateInternal(const Value: TLedState);
function BitmapToDraw: TLedBitmap; function BitmapToDraw: TLedBitmap;
procedure BitmapNeeded; procedure BitmapNeeded;
procedure DoTimer(Sender: TObject); procedure DoTimer(Sender: TObject);
@ -58,7 +56,6 @@ type
protected protected
FlipFLop : Boolean; FlipFLop : Boolean;
{ procedure Paint; override; }
procedure DoChange(AState: TLedState); dynamic; procedure DoChange(AState: TLedState); dynamic;
procedure Loaded; override; procedure Loaded; override;
public public
@ -168,7 +165,6 @@ begin
if (csDesigning in ComponentState) then BitmapNeeded; if (csDesigning in ComponentState) then BitmapNeeded;
end; end;
// destroy control // destroy control
destructor TAdvLed.Destroy; destructor TAdvLed.Destroy;
begin begin
@ -178,12 +174,12 @@ begin
FGlyphs[lsDisabled].Free; FGlyphs[lsDisabled].Free;
inherited Destroy; inherited Destroy;
end; end;
// loaded // loaded
procedure TAdvLed.Loaded; procedure TAdvLed.Loaded;
begin begin
Try Try
If (csDesigning in ComponentState) Then Exit ; If (csDesigning in ComponentState) Then Exit ;
// Load Bitmap if necessary // Load Bitmap if necessary
BitmapNeeded; BitmapNeeded;
Finally Finally
@ -194,10 +190,13 @@ end;
// timer // timer
procedure TAdvLed.DoTimer(Sender: TObject); procedure TAdvLed.DoTimer(Sender: TObject);
begin begin
if FlipFlop then SetState(lsOn ) if FlipFlop then
else SetState(lsoff); SetState(lsOn )
FlipFlop := Not FlipFlop; else
SetState(lsoff);
FlipFlop := Not FlipFlop;
end; end;
// trigger OnChangeEvent // trigger OnChangeEvent
procedure TAdvLed.DoChange(AState: TLedState); procedure TAdvLed.DoChange(AState: TLedState);
begin begin
@ -205,15 +204,16 @@ begin
FOnChange(Self, AState); FOnChange(Self, AState);
invalidate; invalidate;
end; end;
// if bitmap is empty, load it // if bitmap is empty, load it
procedure TAdvLed.BitmapNeeded; procedure TAdvLed.BitmapNeeded;
begin begin
if (FGlyphs[lsOn].Bitmap.Empty) or (FGlyphs[lsOff].Bitmap.Empty) or if (FGlyphs[lsOn].Bitmap.Empty) or (FGlyphs[lsOff].Bitmap.Empty) or
(FGlyphs[lsDisabled].Bitmap.Empty) then (FGlyphs[lsDisabled].Bitmap.Empty) then
begin begin
SelectLedBitmap(FKind); SelectLedBitmap(FKind);
Picture.Assign(BitmapToDraw); Picture.Assign(BitmapToDraw);
end; end;
end; end;
procedure TAdvLed.SelectLedBitmap(const LedKind: TLedKind); procedure TAdvLed.SelectLedBitmap(const LedKind: TLedKind);
@ -224,12 +224,9 @@ const
'LEDBLUEOFF', 'LEDYELLOWOFF', 'LEDPURPLEOFF', 'LEDBULBOFF' ,''); 'LEDBLUEOFF', 'LEDYELLOWOFF', 'LEDPURPLEOFF', 'LEDBULBOFF' ,'');
DisabledBitmaps: array[TLedKind] of string = ('LEDREDOFF', 'LEDGREENOFF', DisabledBitmaps: array[TLedKind] of string = ('LEDREDOFF', 'LEDGREENOFF',
'LEDBLUEOFF', 'LEDYELLOWOFF', 'LEDPURPLEOFF', 'LEDBULBOFF' ,''); } 'LEDBLUEOFF', 'LEDYELLOWOFF', 'LEDPURPLEOFF', 'LEDBULBOFF' ,''); }
OnBitmaps: array[TLedKind] of string = ('RED', 'GREEN', 'YELLOW', OnBitmaps: array[TLedKind] of string = ('RED', 'GREEN', 'YELLOW', 'BULBON', '');
'BULBON', ''); OffBitmaps: array[TLedKind] of string = ('BLACK', 'BLACK', 'BLACK','BULBOFF', '');
OffBitmaps: array[TLedKind] of string = ('BLACK', 'BLACK', DisabledBitmaps: array[TLedKind] of string = ('BLACK', 'BLACK', 'BLACK','BULBOFF' ,'');
'BLACK','BULBOFF' ,'');
DisabledBitmaps: array[TLedKind] of string = ('BLACK', 'BLACK',
'BLACK','BULBOFF' ,'');
begin begin
if LedKind <> lkCustom then if LedKind <> lkCustom then
begin begin
@ -238,14 +235,6 @@ begin
FGlyphs[lsDisabled].LoadFromResourceName(HInstance, DisabledBitmaps[LedKind]); FGlyphs[lsDisabled].LoadFromResourceName(HInstance, DisabledBitmaps[LedKind]);
end; end;
end; end;
// set led state internal
procedure TAdvLed.SetStateInternal(const Value: TLedState);
begin
FState := Value;
if not (csLoading in ComponentState) then
DoChange(FState);
Picture.Assign(BitmapToDraw);
end;
// set led kind // set led kind
procedure TAdvLed.SetKind(const Value: TLedKind); procedure TAdvLed.SetKind(const Value: TLedKind);
@ -253,19 +242,20 @@ begin
if FKind <> Value then if FKind <> Value then
begin begin
FKind := Value; FKind := Value;
SelectLedBitmap(FKind); SelectLedBitmap(FKind);
Picture.Assign(BitmapToDraw); Picture.Assign(BitmapToDraw);
end; end;
end; end;
// set led state // set led state
procedure TAdvLed.SetState(const Value: TLedState); procedure TAdvLed.SetState(const Value: TLedState);
begin begin
SetStateInternal(Value); FState := Value;
if not (csLoading in ComponentState) then
DoChange(FState);
Picture.Assign(BitmapToDraw);
end; end;
function TAdvLed.GetGlyph(const Index: Integer): TLedBitmap; function TAdvLed.GetGlyph(const Index: Integer): TLedBitmap;
begin begin
case Index of case Index of
@ -276,15 +266,16 @@ begin
Result := nil; Result := nil;
end; end;
end; end;
procedure TAdvLed.GlyphChanged(Sender: TObject );
procedure TAdvLed.GlyphChanged(Sender: TObject );
begin begin
// if (csDesigning in ComponentState) then Picture.Assign(Sender as TPicture); // if (csDesigning in ComponentState) then Picture.Assign(Sender as TPicture);
if (csDesigning in ComponentState) then if (csDesigning in ComponentState) then
begin begin
if Sender = FGlyphs[lsDisabled] then FState := lsDisabled; if Sender = FGlyphs[lsDisabled] then FState := lsDisabled;
if Sender = FGlyphs[lsOff] then FState := lsOff; if Sender = FGlyphs[lsOff] then FState := lsOff;
if Sender = FGlyphs[lsOn] then FState := lsOn; if Sender = FGlyphs[lsOn] then FState := lsOn;
Picture.Assign(Sender as TPicture); Picture.Assign(Sender as TPicture);
end; end;
end; end;
@ -297,7 +288,7 @@ begin
0: FGlyphs[lsDisabled].Assign(Value); 0: FGlyphs[lsDisabled].Assign(Value);
1: FGlyphs[lsOff].Assign(Value); 1: FGlyphs[lsOff].Assign(Value);
2: FGlyphs[lsOn].Assign(Value); 2: FGlyphs[lsOn].Assign(Value);
end; end;
end; end;
Picture.Assign(BitmapToDraw); Picture.Assign(BitmapToDraw);
end; end;